Removed the shared parameters structure (read more)
I've also stopped using a separate branch for sharing the CharacterData structre. This commit won't build, mostly because I need to refactor InWorld to handle the loss of the PlayerCharacter class. I should probably rename SQL's tables too.
This commit is contained in:
@@ -25,10 +25,18 @@
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
InCombat::InCombat(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, SharedParameters* const argParams):
|
||||
InCombat::InCombat(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex
|
||||
):
|
||||
config(*argConfig),
|
||||
network(*argNetwork),
|
||||
params(*argParams)
|
||||
clientIndex(*argClientIndex),
|
||||
accountIndex(*argAccountIndex),
|
||||
characterIndex(*argCharacterIndex)
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -53,6 +61,13 @@ void InCombat::FrameEnd() {
|
||||
//
|
||||
}
|
||||
|
||||
void InCombat::RenderFrame() {
|
||||
SDL_FillRect(GetScreen(), 0, 0);
|
||||
Render(GetScreen());
|
||||
SDL_Flip(GetScreen());
|
||||
fps.Calculate();
|
||||
}
|
||||
|
||||
void InCombat::Render(SDL_Surface* const screen) {
|
||||
//
|
||||
}
|
||||
@@ -62,7 +77,9 @@ void InCombat::Render(SDL_Surface* const screen) {
|
||||
//-------------------------
|
||||
|
||||
void InCombat::QuitEvent() {
|
||||
//
|
||||
//exit the game AND the server
|
||||
RequestDisconnect();
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
}
|
||||
|
||||
void InCombat::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
@@ -89,6 +106,14 @@ void InCombat::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
//
|
||||
}
|
||||
|
||||
void InCombat::HandlePacket(SerialPacket& packet) {
|
||||
//
|
||||
}
|
||||
//-------------------------
|
||||
//Network handlers
|
||||
//-------------------------
|
||||
|
||||
//TODO: network handlers
|
||||
|
||||
//-------------------------
|
||||
//Server control
|
||||
//-------------------------
|
||||
|
||||
//TODO: server control
|
||||
|
||||
+36
-10
@@ -22,25 +22,33 @@
|
||||
#ifndef INCOMBAT_HPP_
|
||||
#define INCOMBAT_HPP_
|
||||
|
||||
//graphics & utilities
|
||||
#include "image.hpp"
|
||||
#include "raster_font.hpp"
|
||||
#include "button.hpp"
|
||||
#include "config_utility.hpp"
|
||||
#include "shared_parameters.hpp"
|
||||
|
||||
//network
|
||||
#include "udp_network_utility.hpp"
|
||||
#include "serial_packet.hpp"
|
||||
#include "serial.hpp"
|
||||
|
||||
//graphics
|
||||
#include "image.hpp"
|
||||
#include "raster_font.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
//common
|
||||
#include "config_utility.hpp"
|
||||
#include "frame_rate.hpp"
|
||||
|
||||
//client
|
||||
#include "base_scene.hpp"
|
||||
|
||||
class InCombat : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
InCombat(ConfigUtility* const, UDPNetworkUtility* const, SharedParameters* const);
|
||||
InCombat(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex
|
||||
);
|
||||
~InCombat();
|
||||
|
||||
protected:
|
||||
@@ -48,6 +56,7 @@ protected:
|
||||
void FrameStart();
|
||||
void Update(double delta);
|
||||
void FrameEnd();
|
||||
void RenderFrame();
|
||||
void Render(SDL_Surface* const);
|
||||
|
||||
//Event handlers
|
||||
@@ -59,12 +68,29 @@ protected:
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//Network handlers
|
||||
void HandlePacket(SerialPacket&);
|
||||
void HandlePacket(SerialPacket);
|
||||
void HandleDisconnect(SerialPacket);
|
||||
//TODO: more
|
||||
|
||||
//Server control
|
||||
void SendPlayerUpdate();
|
||||
void RequestDisconnect();
|
||||
void RequestShutdown();
|
||||
//TOOD: more
|
||||
|
||||
//shared parameters
|
||||
ConfigUtility& config;
|
||||
UDPNetworkUtility& network;
|
||||
SharedParameters& params;
|
||||
int& clientIndex;
|
||||
int& accountIndex;
|
||||
int& characterIndex;
|
||||
|
||||
//graphics
|
||||
//TODO: graphics
|
||||
|
||||
//UI
|
||||
//TODO: UI
|
||||
FrameRate fps;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+30
-22
@@ -31,10 +31,18 @@
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, SharedParameters* const argParams):
|
||||
InWorld::InWorld(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex
|
||||
):
|
||||
config(*argConfig),
|
||||
network(*argNetwork),
|
||||
params(*argParams)
|
||||
clientIndex(*argClientIndex),
|
||||
accountIndex(*argAccountIndex),
|
||||
characterIndex(*argCharacterIndex)
|
||||
{
|
||||
//setup the utility objects
|
||||
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||
@@ -66,9 +74,9 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet
|
||||
SerialPacket packet;
|
||||
char buffer[PACKET_STRING_SIZE];
|
||||
packet.meta.type = SerialPacket::Type::SYNCHRONIZE;
|
||||
packet.clientInfo.clientIndex = params.clientIndex;
|
||||
packet.clientInfo.accountIndex = params.accountIndex;
|
||||
packet.clientInfo.characterIndex = params.characterIndex;
|
||||
packet.clientInfo.clientIndex = clientIndex;
|
||||
packet.clientInfo.accountIndex = accountIndex;
|
||||
packet.clientInfo.characterIndex = characterIndex;
|
||||
serialize(&packet, buffer);
|
||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
||||
|
||||
@@ -272,9 +280,9 @@ void InWorld::HandlePacket(SerialPacket packet) {
|
||||
|
||||
void InWorld::HandleDisconnect(SerialPacket packet) {
|
||||
network.Unbind(Channels::SERVER);
|
||||
params.clientIndex = -1;
|
||||
params.accountIndex = -1;
|
||||
params.characterIndex = -1;
|
||||
clientIndex = -1;
|
||||
accountIndex = -1;
|
||||
characterIndex = -1;
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
}
|
||||
|
||||
@@ -292,7 +300,7 @@ void InWorld::HandleCharacterUpdate(SerialPacket packet) {
|
||||
}
|
||||
|
||||
//update only if the message didn't originate from here
|
||||
if (packet.characterInfo.clientIndex != params.clientIndex) {
|
||||
if (packet.characterInfo.clientIndex != clientIndex) {
|
||||
playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position);
|
||||
playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion);
|
||||
}
|
||||
@@ -312,8 +320,8 @@ void InWorld::HandleCharacterNew(SerialPacket packet) {
|
||||
playerCharacters[packet.characterInfo.characterIndex].ResetDirection();
|
||||
|
||||
//catch this client's player object
|
||||
if (packet.characterInfo.characterIndex == params.characterIndex && !localCharacter) {
|
||||
localCharacter = &playerCharacters[params.characterIndex];
|
||||
if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) {
|
||||
localCharacter = &playerCharacters[characterIndex];
|
||||
|
||||
//setup the camera
|
||||
camera.width = GetScreen()->w;
|
||||
@@ -330,8 +338,8 @@ void InWorld::HandleCharacterDelete(SerialPacket packet) {
|
||||
playerCharacters.erase(packet.characterInfo.characterIndex);
|
||||
|
||||
//catch this client's player object
|
||||
if (packet.characterInfo.characterIndex == params.characterIndex) {
|
||||
params.characterIndex = -1;
|
||||
if (packet.characterInfo.characterIndex == characterIndex) {
|
||||
characterIndex = -1;
|
||||
localCharacter = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -346,9 +354,9 @@ void InWorld::SendPlayerUpdate() {
|
||||
|
||||
//pack the packet
|
||||
packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
|
||||
packet.characterInfo.clientIndex = params.clientIndex;
|
||||
packet.characterInfo.accountIndex = params.accountIndex;
|
||||
packet.characterInfo.characterIndex = params.characterIndex;
|
||||
packet.characterInfo.clientIndex = clientIndex;
|
||||
packet.characterInfo.accountIndex = accountIndex;
|
||||
packet.characterInfo.characterIndex = characterIndex;
|
||||
packet.characterInfo.position = localCharacter->GetPosition();
|
||||
packet.characterInfo.motion = localCharacter->GetMotion();
|
||||
|
||||
@@ -362,9 +370,9 @@ void InWorld::RequestDisconnect() {
|
||||
|
||||
//send a disconnect request
|
||||
packet.meta.type = SerialPacket::Type::DISCONNECT;
|
||||
packet.clientInfo.clientIndex = params.clientIndex;
|
||||
packet.clientInfo.accountIndex = params.accountIndex;
|
||||
packet.clientInfo.characterIndex = params.characterIndex;
|
||||
packet.clientInfo.clientIndex = clientIndex;
|
||||
packet.clientInfo.accountIndex = accountIndex;
|
||||
packet.clientInfo.characterIndex = characterIndex;
|
||||
serialize(&packet, buffer);
|
||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
||||
}
|
||||
@@ -375,9 +383,9 @@ void InWorld::RequestShutDown() {
|
||||
|
||||
//send a shutdown request
|
||||
packet.meta.type = SerialPacket::Type::SHUTDOWN;
|
||||
packet.clientInfo.clientIndex = params.clientIndex;
|
||||
packet.clientInfo.accountIndex = params.accountIndex;
|
||||
packet.clientInfo.characterIndex = params.characterIndex;
|
||||
packet.clientInfo.clientIndex = clientIndex;
|
||||
packet.clientInfo.accountIndex = accountIndex;
|
||||
packet.clientInfo.characterIndex = characterIndex;
|
||||
serialize(&packet, buffer);
|
||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
|
||||
//client
|
||||
#include "base_scene.hpp"
|
||||
#include "shared_parameters.hpp"
|
||||
|
||||
//STL
|
||||
#include <map>
|
||||
@@ -52,7 +51,13 @@
|
||||
class InWorld : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
InWorld(ConfigUtility* const, UDPNetworkUtility* const, SharedParameters* const);
|
||||
InWorld(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex
|
||||
);
|
||||
~InWorld();
|
||||
|
||||
protected:
|
||||
@@ -91,7 +96,9 @@ protected:
|
||||
//shared parameters
|
||||
ConfigUtility& config;
|
||||
UDPNetworkUtility& network;
|
||||
SharedParameters& params;
|
||||
int& clientIndex;
|
||||
int& accountIndex;
|
||||
int& characterIndex;
|
||||
|
||||
//graphics
|
||||
Image buttonImage;
|
||||
@@ -114,7 +121,7 @@ protected:
|
||||
FrameRate fps;
|
||||
|
||||
//game
|
||||
PlayerCharacter* localCharacter = nullptr;
|
||||
CharacterData* localCharacter = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,10 +30,18 @@
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, SharedParameters* const argParams):
|
||||
LobbyMenu::LobbyMenu(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex
|
||||
):
|
||||
config(*argConfig),
|
||||
network(*argNetwork),
|
||||
params(*argParams)
|
||||
clientIndex(*argClientIndex),
|
||||
accountIndex(*argAccountIndex),
|
||||
characterIndex(*argCharacterIndex)
|
||||
{
|
||||
//setup the utility objects
|
||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||
@@ -220,9 +228,9 @@ void LobbyMenu::HandlePacket(SerialPacket packet) {
|
||||
}
|
||||
break;
|
||||
case SerialPacket::Type::JOIN_RESPONSE:
|
||||
params.clientIndex = packet.clientInfo.clientIndex;
|
||||
params.accountIndex = packet.clientInfo.accountIndex;
|
||||
params.characterIndex = packet.clientInfo.characterIndex;
|
||||
clientIndex = packet.clientInfo.clientIndex;
|
||||
accountIndex = packet.clientInfo.accountIndex;
|
||||
characterIndex = packet.clientInfo.characterIndex;
|
||||
network.Bind(&packet.meta.srcAddress, Channels::SERVER);
|
||||
SetNextScene(SceneList::INWORLD);
|
||||
break;
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "raster_font.hpp"
|
||||
#include "button.hpp"
|
||||
#include "config_utility.hpp"
|
||||
#include "shared_parameters.hpp"
|
||||
|
||||
//network
|
||||
#include "udp_network_utility.hpp"
|
||||
@@ -43,7 +42,13 @@
|
||||
class LobbyMenu : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
LobbyMenu(ConfigUtility* const, UDPNetworkUtility* const, SharedParameters* const);
|
||||
LobbyMenu(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex
|
||||
);
|
||||
~LobbyMenu();
|
||||
|
||||
protected:
|
||||
@@ -65,7 +70,9 @@ protected:
|
||||
//shared parameters
|
||||
ConfigUtility& config;
|
||||
UDPNetworkUtility& network;
|
||||
SharedParameters& params;
|
||||
int& clientIndex;
|
||||
int& accountIndex;
|
||||
int& characterIndex;
|
||||
|
||||
//members
|
||||
Image image;
|
||||
|
||||
Reference in New Issue
Block a user