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:
Kayne Ruse
2014-05-27 22:24:30 +10:00
parent ac4a264f12
commit 5893342ad8
11 changed files with 149 additions and 95 deletions
+3 -3
View File
@@ -119,13 +119,13 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
activeScene = new OptionsMenu(&config);
break;
case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&config, &network, &params);
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex);
break;
case SceneList::INWORLD:
activeScene = new InWorld(&config, &network, &params);
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex);
break;
case SceneList::INCOMBAT:
activeScene = new InCombat(&config, &network, &params);
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex);
break;
default:
throw(std::logic_error("Failed to recognize the scene index"));
+12 -2
View File
@@ -25,9 +25,13 @@
#include "scene_list.hpp"
#include "base_scene.hpp"
#include "shared_parameters.hpp"
#include "config_utility.hpp"
#include "udp_network_utility.hpp"
#include "character_data.hpp"
#include "combat_data.hpp"
#include "enemy_data.hpp"
#include <map>
class ClientApplication {
public:
@@ -48,7 +52,13 @@ private:
//shared parameters
ConfigUtility config;
UDPNetworkUtility network;
SharedParameters params;
int clientIndex = -1;
int accountIndex = -1;
int characterIndex = -1;
std::map<int, CharacterData> characterMap;
std::map<int, CombatData> combatMap;
std::map<int, EnemyData> enemyMap;
};
#endif
+31 -6
View File
@@ -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
View File
@@ -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
View File
@@ -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);
}
+11 -4
View File
@@ -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
+13 -5
View File
@@ -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;
+10 -3
View File
@@ -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;
-40
View File
@@ -1,40 +0,0 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef SHAREDPARAMETERS_HPP_
#define SHAREDPARAMETERS_HPP_
#include "character_data.hpp"
#include "enemy_data.hpp"
#include <map>
struct SharedParameters {
int clientIndex = -1;
int accountIndex = -1;
int characterIndex = -1;
std::map<int, CharacterData> characterMap;
std::map<int, CombatData> combatMap;
std::map<int, enemyData> enemyMap;
};
#endif
+2
View File
@@ -72,6 +72,8 @@ union SerialPacket {
COMBAT_ENTER,
COMBAT_EXIT,
COMBAT_UPDATE,
COMBAT_REJECTION,
//character data
+1
View File
@@ -1,3 +1,4 @@
--TODO: Rename the SQL's tables, for consistency
-------------------------
--Server
-------------------------