From c575ee9ce15a31c8123979593d85f870c310bc60 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 24 May 2014 01:48:35 +1000 Subject: [PATCH 01/19] Committing todo.txt --- todo.txt | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 todo.txt diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..8182392 --- /dev/null +++ b/todo.txt @@ -0,0 +1,39 @@ +* I need to keep the documentation up to date. Namely, the GDD is getting out of date. +* How many lookups is the map system using? +* Hook the serial packet to the network utility +* I completely forgot about status ailments + +--Battle System-- + +TODO + +--Requirements-- + +The enemies need AI scripts +The scripts need to be able to generate other enemies (frog king). +The characters need a flag to show if they're in a combat instance or not, to signify of they should be unloaded client-side +On each game loop, the server should envoke each combat instance's update function + Each combat instance invokes each enemy's and character's update functions + These update functions increase the ATB guagues + if an ATB guage is full + than the stored command is executed + the players issue their commands during the build up + if there isn't a command ready, then the player is still choosing + for the enemies, the stored commands are driven by scripts, so when the enemies need to attack, their attached scripts are called. + after the commands are called, the ATB is reset to 0. + etc... + +--Enemy API-- + +enemyTables -- The global store of enemy tables. Only accessed by C++ code (unless you want to break something). + +enemy.new(parameters) -- return a new enemy object + +table.logic: the AI logic. If null, do nothing +table.ref: reference to the enemy itself, for use by API functions, set by constructor? + +combat -- the combat API +combat.new(mapIndex, x, y) -- return combat instance's index +combat.pushenemy(c, enemy) -- return the enemy's position +combat.popenemy(c, position) -- + From 1dd8042d3d31df84b98a106111513310abe7072b Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 26 May 2014 00:49:31 +1000 Subject: [PATCH 02/19] Added some structures to SerialPacket, and serial.cpp I've also created the Statistics structure for simplicity. --- common/network/serial.cpp | 95 ++++++++++++++++++++++++++++ common/network/serial.hpp | 8 +-- common/network/serial_packet.hpp | 102 ++++++++++++++++++++++--------- common/statistics.hpp | 42 +++++++++++++ server/character_data.hpp | 16 +---- server/character_management.cpp | 30 ++++----- server/enemy_data.hpp | 19 ++---- todo.txt | 11 ++-- 8 files changed, 243 insertions(+), 80 deletions(-) create mode 100644 common/statistics.hpp diff --git a/common/network/serial.cpp b/common/network/serial.cpp index af527ef..310bfff 100644 --- a/common/network/serial.cpp +++ b/common/network/serial.cpp @@ -22,6 +22,7 @@ #include "serial.hpp" #include "map_allocator.hpp" +#include "statistics.hpp" #include @@ -59,6 +60,7 @@ void serializeClient(SerialPacket* packet, char* buffer) { //texts SERIALIZE(buffer, packet->clientInfo.username, PACKET_STRING_SIZE); + //TODO: password SERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE); SERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE); } @@ -91,6 +93,35 @@ void serializeRegionContent(SerialPacket* packet, char* buffer) { } } +void serializeCombat(SerialPacket* packet, char* buffer) { + SERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type)); + + //integers + SERIALIZE(buffer, &packet->combatInfo.combatIndex, sizeof(int)); + SERIALIZE(buffer, &packet->combatInfo.difficulty, sizeof(int)); + //TODO: more comabat info +} + +void serializeStatistics(Statistics* stats, char* buffer) { + //integers + SERIALIZE(buffer, &stats->level, sizeof(int)); + SERIALIZE(buffer, &stats->exp, sizeof(int)); + SERIALIZE(buffer, &stats->maxHP, sizeof(int)); + SERIALIZE(buffer, &stats->health, sizeof(int)); + SERIALIZE(buffer, &stats->maxMP, sizeof(int)); + SERIALIZE(buffer, &stats->mana, sizeof(int)); + SERIALIZE(buffer, &stats->attack, sizeof(int)); + SERIALIZE(buffer, &stats->defence, sizeof(int)); + SERIALIZE(buffer, &stats->intelligence, sizeof(int)); + SERIALIZE(buffer, &stats->resistance, sizeof(int)); + SERIALIZE(buffer, &stats->speed, sizeof(int)); + + //floats + SERIALIZE(buffer, &stats->accuracy, sizeof(float)); + SERIALIZE(buffer, &stats->evasion, sizeof(float)); + SERIALIZE(buffer, &stats->luck, sizeof(float)); +} + void serializeCharacter(SerialPacket* packet, char* buffer) { SERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type)); @@ -108,6 +139,22 @@ void serializeCharacter(SerialPacket* packet, char* buffer) { SERIALIZE(buffer, &packet->characterInfo.position.y, sizeof(double)); SERIALIZE(buffer, &packet->characterInfo.motion.x, sizeof(double)); SERIALIZE(buffer, &packet->characterInfo.motion.y, sizeof(double)); + + //stats structure + serializeStatistics(&packet->characterInfo.stats, buffer); + buffer += sizeof(Statistics); +} + +void serializeEnemy(SerialPacket* packet, char* buffer) { + SERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type)); + + //texts + SERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE); + SERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE); + + //stats structure + serializeStatistics(&packet->characterInfo.stats, buffer); + buffer += sizeof(Statistics); } //------------------------- @@ -137,6 +184,7 @@ void deserializeClient(SerialPacket* packet, char* buffer) { //texts DESERIALIZE(buffer, packet->clientInfo.username, PACKET_STRING_SIZE); + //TODO: password DESERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE); DESERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE); } @@ -176,6 +224,37 @@ void deserializeRegionContent(SerialPacket* packet, char* buffer) { } } + +void deserializeCombat(SerialPacket* packet, char* buffer) { + DESERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type)); + + //integers + DESERIALIZE(buffer, &packet->combatInfo.combatIndex, sizeof(int)); + DESERIALIZE(buffer, &packet->combatInfo.difficulty, sizeof(int)); + //TODO: more comabat info +} + + +void deserializeStatistics(Statistics* stats, char* buffer) { + //integers + DESERIALIZE(buffer, &stats->level, sizeof(int)); + DESERIALIZE(buffer, &stats->exp, sizeof(int)); + DESERIALIZE(buffer, &stats->maxHP, sizeof(int)); + DESERIALIZE(buffer, &stats->health, sizeof(int)); + DESERIALIZE(buffer, &stats->maxMP, sizeof(int)); + DESERIALIZE(buffer, &stats->mana, sizeof(int)); + DESERIALIZE(buffer, &stats->attack, sizeof(int)); + DESERIALIZE(buffer, &stats->defence, sizeof(int)); + DESERIALIZE(buffer, &stats->intelligence, sizeof(int)); + DESERIALIZE(buffer, &stats->resistance, sizeof(int)); + DESERIALIZE(buffer, &stats->speed, sizeof(int)); + + //floats + DESERIALIZE(buffer, &stats->accuracy, sizeof(float)); + DESERIALIZE(buffer, &stats->evasion, sizeof(float)); + DESERIALIZE(buffer, &stats->luck, sizeof(float)); +} + void deserializeCharacter(SerialPacket* packet, char* buffer) { DESERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type)); @@ -193,6 +272,22 @@ void deserializeCharacter(SerialPacket* packet, char* buffer) { DESERIALIZE(buffer, &packet->characterInfo.position.y, sizeof(double)); DESERIALIZE(buffer, &packet->characterInfo.motion.x, sizeof(double)); DESERIALIZE(buffer, &packet->characterInfo.motion.y, sizeof(double)); + + //stats structure + deserializeStatistics(&packet->characterInfo.stats, buffer); + buffer += sizeof(Statistics); +} + +void deserializeEnemy(SerialPacket* packet, char* buffer) { + DESERIALIZE(buffer, &packet->meta.type, sizeof(SerialPacket::Type)); + + //texts + DESERIALIZE(buffer, packet->clientInfo.handle, PACKET_STRING_SIZE); + DESERIALIZE(buffer, packet->clientInfo.avatar, PACKET_STRING_SIZE); + + //stats structure + deserializeStatistics(&packet->characterInfo.stats, buffer); + buffer += sizeof(Statistics); } //------------------------- diff --git a/common/network/serial.hpp b/common/network/serial.hpp index 609b1f3..29b9c2d 100644 --- a/common/network/serial.hpp +++ b/common/network/serial.hpp @@ -28,11 +28,11 @@ * NOTE: REGION_CONTENT is currently the largest type of packet * map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t) * map format: sizeof(int) * 3 - * metadata: sizeof(metadata) + * metadata: sizeof(SerialPacket::Type) */ -#define PACKET_BUFFER_SIZE REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 3 + sizeof(SerialPacket::Metadata) +#define PACKET_BUFFER_SIZE REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 3 + sizeof(SerialPacket::Type) -void serialize(SerialPacket* const, void*); -void deserialize(SerialPacket* const, void*); +void serialize(SerialPacket* const, void* dest); +void deserialize(SerialPacket* const, void* src); #endif diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index 3b8c4e5..662985a 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -24,53 +24,80 @@ #include "vector2.hpp" #include "region.hpp" +#include "statistics.hpp" #include "SDL/SDL_net.h" -#define NETWORK_VERSION 20140512 -#define PACKET_STRING_SIZE 100 +#define NETWORK_VERSION 20140526 -#pragma pack(push, 0) +//maximum string size; don't use std::string +#define PACKET_STRING_SIZE 100 union SerialPacket { //types of packets + //TODO: readd the value definitions enum class Type { //default: there is something wrong NONE = 0, - //not used - PING = 1, - PONG = 2, + //keep alive + PING, + PONG, - //TODO: rejection message - - //Searching for a server to join - BROADCAST_REQUEST = 3, - BROADCAST_RESPONSE = 4, + //searching for a server to join + BROADCAST_REQUEST, + BROADCAST_RESPONSE, + BROADCAST_REJECTION, //try to join the server - JOIN_REQUEST = 5, - JOIN_RESPONSE = 6, + JOIN_REQUEST, + JOIN_RESPONSE, + JOIN_REJECTION, //mass update - SYNCHRONIZE = 7, + SYNCHRONIZE, //disconnect from the server - DISCONNECT = 8, + DISCONNECT, //shut down the server - SHUTDOWN = 9, + SHUTDOWN, //map data - REGION_REQUEST = 10, - REGION_CONTENT = 11, + REGION_REQUEST, + REGION_CONTENT, + REGION_REJECTION, - //Character movement, etc. - CHARACTER_NEW = 12, - CHARACTER_DELETE = 13, - CHARACTER_UPDATE = 14, + //character data + CHARACTER_NEW, + CHARACTER_DELETE, + CHARACTER_UPDATE, - //TODO: combat packets + CHARACTER_STATS_REQUEST, + CHARACTER_STATS_RESPONSE, + + CHARACTER_REJECTION, + + //enemy data + ENEMY_NEW, + ENEMY_DELETE, + ENEMY_UPDATE, + + ENEMY_STATS_REQUEST, + ENEMY_STATS_RESPONSE, + + ENEMY_REJECTION, + + //combat data + COMBAT_ENTER, + COMBAT_EXIT, + + COMBAT_REJECTION, + + //more packet types go here + + //not used + LAST, }; //metadata on the packet itself @@ -79,7 +106,7 @@ union SerialPacket { IPaddress srcAddress; }meta; - //information about the server + //info about the server struct ServerInformation { Metadata meta; int networkVersion; @@ -87,18 +114,19 @@ union SerialPacket { int playerCount; }serverInfo; - //information about the client + //info about the client struct ClientInformation { Metadata meta; int clientIndex; int accountIndex; int characterIndex; char username[PACKET_STRING_SIZE]; + //TODO: password char handle[PACKET_STRING_SIZE]; char avatar[PACKET_STRING_SIZE]; }clientInfo; - //map data + //info about a region struct RegionInformation { Metadata meta; int mapIndex; @@ -106,7 +134,16 @@ union SerialPacket { Region* region; }regionInfo; - //information about a character + //info about a combat scenario + struct CombatInformation { + Metadata meta; + int combatIndex; + int difficulty; + //TODO: background image, based on terrain type + //TODO: array of combatants + }combatInfo; + + //info about a character struct CharacterInformation { Metadata meta; int clientIndex; @@ -117,8 +154,17 @@ union SerialPacket { int mapIndex; Vector2 position; Vector2 motion; + Statistics stats; }characterInfo; + //info about an enemy + struct EnemyInformation { + Metadata meta; + char handle[PACKET_STRING_SIZE]; + char avatar[PACKET_STRING_SIZE]; + Statistics stats; + }enemyInfo; + //defaults SerialPacket() { meta.type = Type::NONE; @@ -126,6 +172,4 @@ union SerialPacket { } }; -#pragma pack(pop) - #endif diff --git a/common/statistics.hpp b/common/statistics.hpp new file mode 100644 index 0000000..71020ae --- /dev/null +++ b/common/statistics.hpp @@ -0,0 +1,42 @@ +/* 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 STATISTICS_HPP_ +#define STATISTICS_HPP_ + +struct Statistics { + int level = 0; + int exp = 0; + int maxHP = 0; + int health = 0; + int maxMP = 0; + int mana = 0; + int attack = 0; + int defence = 0; + int intelligence = 0; + int resistance = 0; + int speed = 0; + float accuracy = 0.0; + float evasion = 0.0; + float luck = 0.0; +}; + +#endif \ No newline at end of file diff --git a/server/character_data.hpp b/server/character_data.hpp index 2db2bb0..4da307f 100644 --- a/server/character_data.hpp +++ b/server/character_data.hpp @@ -25,6 +25,7 @@ //POD members #include "bbox.hpp" #include "vector2.hpp" +#include "statistics.hpp" #include @@ -40,20 +41,7 @@ struct CharacterData { Vector2 motion = {0.0,0.0}; //base statistics - int level = 0; - int exp = 0; - int maxHP = 0; - int health = 0; - int maxMP = 0; - int mana = 0; - int attack = 0; - int defence = 0; - int intelligence = 0; - int resistance = 0; - int speed = 0; - float accuracy = 0.0; - float evasion = 0.0; - float luck = 0.0; + Statistics stats; //TODO: equipment //TODO: items diff --git a/server/character_management.cpp b/server/character_management.cpp index 58fb6b2..3835448 100644 --- a/server/character_management.cpp +++ b/server/character_management.cpp @@ -29,6 +29,7 @@ //Define the queries //------------------------- +//TODO: save and load the statistics static const char* CREATE_CHARACTER = "INSERT INTO PlayerCharacters (owner, handle, avatar) VALUES (?, ?, ?);"; static const char* LOAD_CHARACTER = "SELECT * FROM PlayerCharacters WHERE handle = ?;"; static const char* SAVE_CHARACTER = "UPDATE OR FAIL PlayerCharacters SET mapIndex = ?2, positionX = ?3, positionY = ?4 WHERE uid = ?1;"; @@ -38,6 +39,7 @@ static const char* DELETE_CHARACTER = "DELETE FROM PlayerCharacters WHERE uid = //Define the methods //------------------------- +//TODO: default stats as a parameter int ServerApplication::CreateCharacter(int owner, std::string handle, std::string avatar) { //Create the character, failing if it exists sqlite3_stmt* statement = nullptr; @@ -121,20 +123,20 @@ int ServerApplication::LoadCharacter(int owner, std::string handle, std::string newChar.position.y = (double)sqlite3_column_int(statement, 7); //statistics - newChar.level = sqlite3_column_int(statement, 8); - newChar.exp = sqlite3_column_int(statement, 9); - newChar.maxHP = sqlite3_column_int(statement, 10); - newChar.health = sqlite3_column_int(statement, 11); - newChar.maxMP = sqlite3_column_int(statement, 12); - newChar.mana = sqlite3_column_int(statement, 13); - newChar.attack = sqlite3_column_int(statement, 14); - newChar.defence = sqlite3_column_int(statement, 15); - newChar.intelligence = sqlite3_column_int(statement, 16); - newChar.resistance = sqlite3_column_int(statement, 17); - newChar.speed = sqlite3_column_int(statement, 18); - newChar.accuracy = sqlite3_column_double(statement, 19); - newChar.evasion = sqlite3_column_double(statement, 20); - newChar.luck = sqlite3_column_double(statement, 21); + newChar.stats.level = sqlite3_column_int(statement, 8); + newChar.stats.exp = sqlite3_column_int(statement, 9); + newChar.stats.maxHP = sqlite3_column_int(statement, 10); + newChar.stats.health = sqlite3_column_int(statement, 11); + newChar.stats.maxMP = sqlite3_column_int(statement, 12); + newChar.stats.mana = sqlite3_column_int(statement, 13); + newChar.stats.attack = sqlite3_column_int(statement, 14); + newChar.stats.defence = sqlite3_column_int(statement, 15); + newChar.stats.intelligence = sqlite3_column_int(statement, 16); + newChar.stats.resistance = sqlite3_column_int(statement, 17); + newChar.stats.speed = sqlite3_column_int(statement, 18); + newChar.stats.accuracy = sqlite3_column_double(statement, 19); + newChar.stats.evasion = sqlite3_column_double(statement, 20); + newChar.stats.luck = sqlite3_column_double(statement, 21); //TODO: equipment diff --git a/server/enemy_data.hpp b/server/enemy_data.hpp index 4d562fb..48a5fa4 100644 --- a/server/enemy_data.hpp +++ b/server/enemy_data.hpp @@ -22,6 +22,8 @@ #ifndef ENEMYDATA_HPP_ #define ENEMYDATA_HPP_ +#include "statistics.hpp" + #include struct EnemyData { @@ -29,21 +31,8 @@ struct EnemyData { std::string handle; std::string avatar; - //statistics - int level = 0; - int exp = 0; - int maxHP = 0; - int health = 0; - int maxMP = 0; - int mana = 0; - int attack = 0; - int defence = 0; - int intelligence = 0; - int resistance = 0; - int speed = 0; - float accuracy = 0.0; - float evasion = 0.0; - float luck = 0.0; + //gameplay + Statistics stats; //TODO: equipment //TODO: items diff --git a/todo.txt b/todo.txt index 8182392..61ceec5 100644 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,10 @@ -* I need to keep the documentation up to date. Namely, the GDD is getting out of date. -* How many lookups is the map system using? -* Hook the serial packet to the network utility -* I completely forgot about status ailments +TODO: I need to keep the documentation up to date. Namely, the GDD is getting out of date. +TODO: How many lookups is the map system using? +TODO: Hook the serial packet to the network utility +TODO: I completely forgot about status ailments +TODO: Time delay for requesting region packets +TODO: command line parameters overriding config.cfg settings +TODO: inplementing SerialPacket in NetworkUtility --Battle System-- From 7b76e072312c2f98b18463f637b39efdd7dbd148 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 26 May 2014 01:08:10 +1000 Subject: [PATCH 03/19] Hooked up the new serial code, nothing broke --- common/network/serial.cpp | 68 ++++++++++++++++++++++++++++---- common/network/serial_packet.hpp | 13 +++--- 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/common/network/serial.cpp b/common/network/serial.cpp index 310bfff..81aecea 100644 --- a/common/network/serial.cpp +++ b/common/network/serial.cpp @@ -296,20 +296,29 @@ void deserializeEnemy(SerialPacket* packet, char* buffer) { void serialize(SerialPacket* packet, void* buffer) { switch(packet->meta.type) { - //No extra data + //no extra data case SerialPacket::Type::NONE: case SerialPacket::Type::PING: case SerialPacket::Type::PONG: case SerialPacket::Type::BROADCAST_REQUEST: + + //all rejections + case SerialPacket::Type::BROADCAST_REJECTION: + case SerialPacket::Type::JOIN_REJECTION: + case SerialPacket::Type::REGION_REJECTION: + case SerialPacket::Type::CHARACTER_REJECTION: + case SerialPacket::Type::ENEMY_REJECTION: + case SerialPacket::Type::COMBAT_REJECTION: + serializeType(packet, reinterpret_cast(buffer)); break; - //Server info + //server info case SerialPacket::Type::BROADCAST_RESPONSE: serializeServer(packet, reinterpret_cast(buffer)); break; - //Client info + //client info case SerialPacket::Type::JOIN_REQUEST: case SerialPacket::Type::JOIN_RESPONSE: case SerialPacket::Type::SYNCHRONIZE: @@ -327,12 +336,29 @@ void serialize(SerialPacket* packet, void* buffer) { serializeRegionContent(packet, reinterpret_cast(buffer)); break; - //Character info + //combat info + case SerialPacket::Type::COMBAT_ENTER: + case SerialPacket::Type::COMBAT_EXIT: + serializeCombat(packet, reinterpret_cast(buffer)); + break; + + //character info case SerialPacket::Type::CHARACTER_NEW: case SerialPacket::Type::CHARACTER_DELETE: case SerialPacket::Type::CHARACTER_UPDATE: + case SerialPacket::Type::CHARACTER_STATS_REQUEST: + case SerialPacket::Type::CHARACTER_STATS_RESPONSE: serializeCharacter(packet, reinterpret_cast(buffer)); break; + + //enemy info + case SerialPacket::Type::ENEMY_NEW: + case SerialPacket::Type::ENEMY_DELETE: + case SerialPacket::Type::ENEMY_UPDATE: + case SerialPacket::Type::ENEMY_STATS_REQUEST: + case SerialPacket::Type::ENEMY_STATS_RESPONSE: + serializeEnemy(packet, reinterpret_cast(buffer)); + break; } } @@ -340,20 +366,29 @@ void deserialize(SerialPacket* packet, void* buffer) { //find the type, so that you can actually deserialize the packet! deserializeType(packet, reinterpret_cast(buffer)); switch(packet->meta.type) { - //No extra data + //no extra data case SerialPacket::Type::NONE: case SerialPacket::Type::PING: case SerialPacket::Type::PONG: case SerialPacket::Type::BROADCAST_REQUEST: + + //all rejections + case SerialPacket::Type::BROADCAST_REJECTION: + case SerialPacket::Type::JOIN_REJECTION: + case SerialPacket::Type::REGION_REJECTION: + case SerialPacket::Type::CHARACTER_REJECTION: + case SerialPacket::Type::ENEMY_REJECTION: + case SerialPacket::Type::COMBAT_REJECTION: + //NOTHING break; - //Server info + //server info case SerialPacket::Type::BROADCAST_RESPONSE: deserializeServer(packet, reinterpret_cast(buffer)); break; - //Client info + //client info case SerialPacket::Type::JOIN_REQUEST: case SerialPacket::Type::JOIN_RESPONSE: case SerialPacket::Type::SYNCHRONIZE: @@ -371,11 +406,28 @@ void deserialize(SerialPacket* packet, void* buffer) { deserializeRegionContent(packet, reinterpret_cast(buffer)); break; - //Character info + //combat info + case SerialPacket::Type::COMBAT_ENTER: + case SerialPacket::Type::COMBAT_EXIT: + serializeCombat(packet, reinterpret_cast(buffer)); + break; + + //character info case SerialPacket::Type::CHARACTER_NEW: case SerialPacket::Type::CHARACTER_DELETE: case SerialPacket::Type::CHARACTER_UPDATE: + case SerialPacket::Type::CHARACTER_STATS_REQUEST: + case SerialPacket::Type::CHARACTER_STATS_RESPONSE: deserializeCharacter(packet, reinterpret_cast(buffer)); break; + + //enemy info + case SerialPacket::Type::ENEMY_NEW: + case SerialPacket::Type::ENEMY_DELETE: + case SerialPacket::Type::ENEMY_UPDATE: + case SerialPacket::Type::ENEMY_STATS_REQUEST: + case SerialPacket::Type::ENEMY_STATS_RESPONSE: + serializeEnemy(packet, reinterpret_cast(buffer)); + break; } } \ No newline at end of file diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index 662985a..8729674 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -68,6 +68,12 @@ union SerialPacket { REGION_CONTENT, REGION_REJECTION, + //combat data + COMBAT_ENTER, + COMBAT_EXIT, + + COMBAT_REJECTION, + //character data CHARACTER_NEW, CHARACTER_DELETE, @@ -88,12 +94,6 @@ union SerialPacket { ENEMY_REJECTION, - //combat data - COMBAT_ENTER, - COMBAT_EXIT, - - COMBAT_REJECTION, - //more packet types go here //not used @@ -141,6 +141,7 @@ union SerialPacket { int difficulty; //TODO: background image, based on terrain type //TODO: array of combatants + //TODO: rewards }combatInfo; //info about a character From c2eb08bd5ef1dfc496fac5510d2419724ba32f80 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 26 May 2014 02:08:07 +1000 Subject: [PATCH 04/19] Restructured the common/ directory, and simplified the build process --- client/makefile | 10 ++---- client/scenes/makefile | 10 ++---- common/gameplay/makefile | 37 +++++++++++++++++++++++ common/{ => gameplay}/statistics.hpp | 0 common/graphics/makefile | 6 ---- common/makefile | 14 +++------ common/map/makefile | 8 +---- common/network/makefile | 8 +---- common/network/serial_packet.hpp | 2 +- common/script/makefile | 8 +---- common/ui/makefile | 6 ---- common/{ => utilities}/bbox.hpp | 0 common/{ => utilities}/config_utility.cpp | 0 common/{ => utilities}/config_utility.hpp | 0 common/{ => utilities}/frame_rate.hpp | 0 common/utilities/makefile | 37 +++++++++++++++++++++++ common/{ => utilities}/sql_utility.cpp | 0 common/{ => utilities}/sql_utility.hpp | 0 common/{ => utilities}/utility.cpp | 0 common/{ => utilities}/utility.hpp | 0 common/{ => utilities}/vector2.hpp | 0 makefile | 1 - server/makefile | 8 +---- 23 files changed, 88 insertions(+), 67 deletions(-) create mode 100644 common/gameplay/makefile rename common/{ => gameplay}/statistics.hpp (100%) rename common/{ => utilities}/bbox.hpp (100%) rename common/{ => utilities}/config_utility.cpp (100%) rename common/{ => utilities}/config_utility.hpp (100%) rename common/{ => utilities}/frame_rate.hpp (100%) create mode 100644 common/utilities/makefile rename common/{ => utilities}/sql_utility.cpp (100%) rename common/{ => utilities}/sql_utility.hpp (100%) rename common/{ => utilities}/utility.cpp (100%) rename common/{ => utilities}/utility.hpp (100%) rename common/{ => utilities}/vector2.hpp (100%) diff --git a/client/makefile b/client/makefile index 56a4184..e9c2091 100644 --- a/client/makefile +++ b/client/makefile @@ -1,17 +1,14 @@ #config -INCLUDES+=. scenes ../common ../common/graphics ../common/map ../common/network ../common/ui -LIBS+=libclient.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3 +INCLUDES+=. scenes ../common ../common/gameplay ../common/graphics ../common/map ../common/network ../common/ui ../common/utilities +LIBS+=libclient.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) -CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) -CSRC=$(wildcard *.c) #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o)) #output OUTDIR=../out @@ -35,9 +32,6 @@ $(OUTDIR): $(OBJDIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< -$(OBJDIR)/%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - clean: $(RM) *.o *.a *.exe diff --git a/client/scenes/makefile b/client/scenes/makefile index c0c815b..b436dff 100644 --- a/client/scenes/makefile +++ b/client/scenes/makefile @@ -1,17 +1,14 @@ #config -INCLUDES+=. .. ../../common ../../common/graphics ../../common/map ../../common/network ../../common/ui -LIBS+= +INCLUDES+=. .. ../../common ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/ui ../../common/utilities +LIBS+=libclient.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) -CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) -CSRC=$(wildcard *.c) #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o)) #output OUTDIR=.. @@ -34,9 +31,6 @@ $(OUTDIR): $(OBJDIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< -$(OBJDIR)/%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - clean: $(RM) *.o *.a *.exe diff --git a/common/gameplay/makefile b/common/gameplay/makefile new file mode 100644 index 0000000..e86cb16 --- /dev/null +++ b/common/gameplay/makefile @@ -0,0 +1,37 @@ +#config +INCLUDES+=. .. +LIBS+= +CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) + +#source +CXXSRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) + +#output +OUTDIR=../.. +OUT=$(addprefix $(OUTDIR)/,libcommon.a) + +#targets +all: $(OBJ) $(OUT) + ar -crs $(OUT) $(OBJ) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all diff --git a/common/statistics.hpp b/common/gameplay/statistics.hpp similarity index 100% rename from common/statistics.hpp rename to common/gameplay/statistics.hpp diff --git a/common/graphics/makefile b/common/graphics/makefile index c1b2927..343f0f1 100644 --- a/common/graphics/makefile +++ b/common/graphics/makefile @@ -2,16 +2,13 @@ INCLUDES+=. .. ../map LIBS+= CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) -CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) -CSRC=$(wildcard *.c) #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o)) #output OUTDIR=../.. @@ -34,9 +31,6 @@ $(OUTDIR): $(OBJDIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< -$(OBJDIR)/%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - clean: $(RM) *.o *.a *.exe diff --git a/common/makefile b/common/makefile index 645ac13..3acd152 100644 --- a/common/makefile +++ b/common/makefile @@ -1,30 +1,29 @@ #config -INCLUDES+=. +INCLUDES+=. .. LIBS+= CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) -CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) -CSRC=$(wildcard *.c) #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o)) #output -OUTDIR=.. +OUTDIR=../.. OUT=$(addprefix $(OUTDIR)/,libcommon.a) #targets all: $(OBJ) $(OUT) ar -crs $(OUT) $(OBJ) + $(MAKE) -C gameplay $(MAKE) -C graphics $(MAKE) -C map - $(MAKE) -C script $(MAKE) -C network + $(MAKE) -C script $(MAKE) -C ui + $(MAKE) -C utilities $(OBJ): | $(OBJDIR) @@ -39,9 +38,6 @@ $(OUTDIR): $(OBJDIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< -$(OBJDIR)/%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - clean: $(RM) *.o *.a *.exe diff --git a/common/map/makefile b/common/map/makefile index c2cdfb3..1f25da1 100644 --- a/common/map/makefile +++ b/common/map/makefile @@ -1,17 +1,14 @@ #config -INCLUDES+=. .. ../graphics +INCLUDES+=. .. ../utilities LIBS+= CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) -CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) -CSRC=$(wildcard *.c) #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o)) #output OUTDIR=../.. @@ -34,9 +31,6 @@ $(OUTDIR): $(OBJDIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< -$(OBJDIR)/%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - clean: $(RM) *.o *.a *.exe diff --git a/common/network/makefile b/common/network/makefile index c1b2927..b5ac556 100644 --- a/common/network/makefile +++ b/common/network/makefile @@ -1,17 +1,14 @@ #config -INCLUDES+=. .. ../map +INCLUDES+=. .. ../gameplay ../map ../utilities LIBS+= CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) -CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) -CSRC=$(wildcard *.c) #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o)) #output OUTDIR=../.. @@ -34,9 +31,6 @@ $(OUTDIR): $(OBJDIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< -$(OBJDIR)/%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - clean: $(RM) *.o *.a *.exe diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index 8729674..1dd94a6 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -35,7 +35,7 @@ union SerialPacket { //types of packets - //TODO: readd the value definitions + //TODO: read the value definitions enum class Type { //default: there is something wrong NONE = 0, diff --git a/common/script/makefile b/common/script/makefile index c1b2927..7f9288d 100644 --- a/common/script/makefile +++ b/common/script/makefile @@ -1,17 +1,14 @@ #config -INCLUDES+=. .. ../map +INCLUDES+=. .. ../map ../utilities LIBS+= CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) -CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) -CSRC=$(wildcard *.c) #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o)) #output OUTDIR=../.. @@ -34,9 +31,6 @@ $(OUTDIR): $(OBJDIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< -$(OBJDIR)/%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - clean: $(RM) *.o *.a *.exe diff --git a/common/ui/makefile b/common/ui/makefile index c2cdfb3..95166fd 100644 --- a/common/ui/makefile +++ b/common/ui/makefile @@ -2,16 +2,13 @@ INCLUDES+=. .. ../graphics LIBS+= CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) -CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) -CSRC=$(wildcard *.c) #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o)) #output OUTDIR=../.. @@ -34,9 +31,6 @@ $(OUTDIR): $(OBJDIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< -$(OBJDIR)/%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - clean: $(RM) *.o *.a *.exe diff --git a/common/bbox.hpp b/common/utilities/bbox.hpp similarity index 100% rename from common/bbox.hpp rename to common/utilities/bbox.hpp diff --git a/common/config_utility.cpp b/common/utilities/config_utility.cpp similarity index 100% rename from common/config_utility.cpp rename to common/utilities/config_utility.cpp diff --git a/common/config_utility.hpp b/common/utilities/config_utility.hpp similarity index 100% rename from common/config_utility.hpp rename to common/utilities/config_utility.hpp diff --git a/common/frame_rate.hpp b/common/utilities/frame_rate.hpp similarity index 100% rename from common/frame_rate.hpp rename to common/utilities/frame_rate.hpp diff --git a/common/utilities/makefile b/common/utilities/makefile new file mode 100644 index 0000000..e86cb16 --- /dev/null +++ b/common/utilities/makefile @@ -0,0 +1,37 @@ +#config +INCLUDES+=. .. +LIBS+= +CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) + +#source +CXXSRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) + +#output +OUTDIR=../.. +OUT=$(addprefix $(OUTDIR)/,libcommon.a) + +#targets +all: $(OBJ) $(OUT) + ar -crs $(OUT) $(OBJ) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all diff --git a/common/sql_utility.cpp b/common/utilities/sql_utility.cpp similarity index 100% rename from common/sql_utility.cpp rename to common/utilities/sql_utility.cpp diff --git a/common/sql_utility.hpp b/common/utilities/sql_utility.hpp similarity index 100% rename from common/sql_utility.hpp rename to common/utilities/sql_utility.hpp diff --git a/common/utility.cpp b/common/utilities/utility.cpp similarity index 100% rename from common/utility.cpp rename to common/utilities/utility.cpp diff --git a/common/utility.hpp b/common/utilities/utility.hpp similarity index 100% rename from common/utility.hpp rename to common/utilities/utility.hpp diff --git a/common/vector2.hpp b/common/utilities/vector2.hpp similarity index 100% rename from common/vector2.hpp rename to common/utilities/vector2.hpp diff --git a/makefile b/makefile index 3315bc2..27fd80e 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,3 @@ -#TODO: The build process needs revising #for use on Windows: #MKDIR=mkdir diff --git a/server/makefile b/server/makefile index 9686a1c..5bfd158 100644 --- a/server/makefile +++ b/server/makefile @@ -1,17 +1,14 @@ #config -INCLUDES+=. ../common ../common/map ../common/script ../common/network +INCLUDES+=. ../common ../common/gameplay ../common/map ../common/network ../common/script ../common/utilities LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3 CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) -CFLAGS+=-DDEBUG $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) -CSRC=$(wildcard *.c) #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) -OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o)) #output OUTDIR=../out @@ -34,9 +31,6 @@ $(OUTDIR): $(OBJDIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< -$(OBJDIR)/%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - clean: $(RM) *.o *.a *.exe From a47e76845f7e378a52cf3fc79c7ea95823da9faa Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 26 May 2014 02:21:56 +1000 Subject: [PATCH 05/19] Removed common/ from the build process, and the DEBUG flag The common/ directory is empty, only containing more directories to be built, and the DEBUG flag isn't being used. --- client/makefile | 4 ++-- client/scenes/makefile | 4 ++-- common/gameplay/makefile | 4 ++-- common/graphics/makefile | 4 ++-- common/makefile | 33 +-------------------------------- common/map/makefile | 4 ++-- common/network/makefile | 4 ++-- common/script/makefile | 4 ++-- common/ui/makefile | 4 ++-- common/utilities/makefile | 4 ++-- server/makefile | 4 ++-- 11 files changed, 21 insertions(+), 52 deletions(-) diff --git a/client/makefile b/client/makefile index e9c2091..f049556 100644 --- a/client/makefile +++ b/client/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. scenes ../common ../common/gameplay ../common/graphics ../common/map ../common/network ../common/ui ../common/utilities +INCLUDES+=. scenes ../common/gameplay ../common/graphics ../common/map ../common/network ../common/ui ../common/utilities LIBS+=libclient.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/client/scenes/makefile b/client/scenes/makefile index b436dff..d09de2e 100644 --- a/client/scenes/makefile +++ b/client/scenes/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. .. ../../common ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/ui ../../common/utilities +INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/ui ../../common/utilities LIBS+=libclient.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/gameplay/makefile b/common/gameplay/makefile index e86cb16..9013447 100644 --- a/common/gameplay/makefile +++ b/common/gameplay/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. .. +INCLUDES+=. LIBS+= -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/graphics/makefile b/common/graphics/makefile index 343f0f1..afcde11 100644 --- a/common/graphics/makefile +++ b/common/graphics/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. .. ../map +INCLUDES+=. ../map LIBS+= -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/makefile b/common/makefile index 3acd152..0e48688 100644 --- a/common/makefile +++ b/common/makefile @@ -1,22 +1,4 @@ -#config -INCLUDES+=. .. -LIBS+= -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) - -#source -CXXSRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) - -#output -OUTDIR=../.. -OUT=$(addprefix $(OUTDIR)/,libcommon.a) - -#targets -all: $(OBJ) $(OUT) - ar -crs $(OUT) $(OBJ) +all: $(MAKE) -C gameplay $(MAKE) -C graphics $(MAKE) -C map @@ -25,19 +7,6 @@ all: $(OBJ) $(OUT) $(MAKE) -C ui $(MAKE) -C utilities -$(OBJ): | $(OBJDIR) - -$(OUT): | $(OUTDIR) - -$(OBJDIR): - mkdir $(OBJDIR) - -$(OUTDIR): - mkdir $(OUTDIR) - -$(OBJDIR)/%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - clean: $(RM) *.o *.a *.exe diff --git a/common/map/makefile b/common/map/makefile index 1f25da1..769709e 100644 --- a/common/map/makefile +++ b/common/map/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. .. ../utilities +INCLUDES+=. ../utilities LIBS+= -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/network/makefile b/common/network/makefile index b5ac556..7053c0f 100644 --- a/common/network/makefile +++ b/common/network/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. .. ../gameplay ../map ../utilities +INCLUDES+=. ../gameplay ../map ../utilities LIBS+= -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/script/makefile b/common/script/makefile index 7f9288d..7cab524 100644 --- a/common/script/makefile +++ b/common/script/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. .. ../map ../utilities +INCLUDES+=. ../map ../utilities LIBS+= -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/ui/makefile b/common/ui/makefile index 95166fd..bd9ffd1 100644 --- a/common/ui/makefile +++ b/common/ui/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. .. ../graphics +INCLUDES+=. ../graphics LIBS+= -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/utilities/makefile b/common/utilities/makefile index e86cb16..9013447 100644 --- a/common/utilities/makefile +++ b/common/utilities/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. .. +INCLUDES+=. LIBS+= -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/server/makefile b/server/makefile index 5bfd158..901f8a6 100644 --- a/server/makefile +++ b/server/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. ../common ../common/gameplay ../common/map ../common/network ../common/script ../common/utilities +INCLUDES+=. ../common/gameplay ../common/map ../common/network ../common/script ../common/utilities LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3 -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) From 0a71f43ef3f4c22aab1794759d1cfded1150b414 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 26 May 2014 17:11:26 +1000 Subject: [PATCH 06/19] Implemented SharedParameters system in the client (read more) Here are more tweaks: * InWorld's quit event now exits to the main menu, bypassing a relayed disconnect message * InWorld's disconnect hander no longer throws exceptions (dropped creation packet bugfix) * CombatData's internals now point to std::pair objects * Enemies are stored in a global list --- client/client_application.cpp | 6 ++-- client/client_application.hpp | 7 ++--- client/scenes/in_combat.cpp | 14 ++++++++- client/scenes/in_combat.hpp | 24 ++++++++++++++- client/scenes/in_world.cpp | 57 ++++++++++++++++------------------- client/scenes/in_world.hpp | 7 ++--- client/scenes/lobby_menu.cpp | 13 ++++---- client/scenes/lobby_menu.hpp | 7 ++--- client/shared_parameters.hpp | 31 +++++++++++++++++++ server/combat_data.hpp | 7 +++-- server/enemy_data.hpp | 2 ++ server/server_application.hpp | 1 + server/server_internals.cpp | 1 + 13 files changed, 119 insertions(+), 58 deletions(-) create mode 100644 client/shared_parameters.hpp diff --git a/client/client_application.cpp b/client/client_application.cpp index 297a903..9f3d395 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -119,13 +119,13 @@ void ClientApplication::LoadScene(SceneList sceneIndex) { activeScene = new OptionsMenu(&config); break; case SceneList::LOBBYMENU: - activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex); + activeScene = new LobbyMenu(&config, &network, ¶ms); break; case SceneList::INWORLD: - activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex); + activeScene = new InWorld(&config, &network, ¶ms); break; case SceneList::INCOMBAT: - activeScene = new InCombat(); + activeScene = new InCombat(&config, &network, ¶ms); break; default: throw(std::logic_error("Failed to recognize the scene index")); diff --git a/client/client_application.hpp b/client/client_application.hpp index b6b3b31..07155ae 100644 --- a/client/client_application.hpp +++ b/client/client_application.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 @@ -25,6 +25,7 @@ #include "scene_list.hpp" #include "base_scene.hpp" +#include "shared_parameters.hpp" #include "config_utility.hpp" #include "udp_network_utility.hpp" @@ -47,9 +48,7 @@ private: //shared parameters ConfigUtility config; UDPNetworkUtility network; - int clientIndex = -1; - int accountIndex = -1; - int characterIndex = -1; + SharedParameters params; }; #endif diff --git a/client/scenes/in_combat.cpp b/client/scenes/in_combat.cpp index 1d70713..b0d69ec 100644 --- a/client/scenes/in_combat.cpp +++ b/client/scenes/in_combat.cpp @@ -25,7 +25,11 @@ //Public access members //------------------------- -InCombat::InCombat() { +InCombat::InCombat(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, SharedParameters* const argParams): + config(*argConfig), + network(*argNetwork), + params(*argParams) +{ // } @@ -57,6 +61,10 @@ void InCombat::Render(SDL_Surface* const screen) { //Event handlers //------------------------- +void InCombat::QuitEvent() { + // +} + void InCombat::MouseMotion(SDL_MouseMotionEvent const& motion) { // } @@ -80,3 +88,7 @@ void InCombat::KeyDown(SDL_KeyboardEvent const& key) { void InCombat::KeyUp(SDL_KeyboardEvent const& key) { // } + +void InCombat::HandlePacket(SerialPacket& packet) { + // +} \ No newline at end of file diff --git a/client/scenes/in_combat.hpp b/client/scenes/in_combat.hpp index b08a53d..c9d58f3 100644 --- a/client/scenes/in_combat.hpp +++ b/client/scenes/in_combat.hpp @@ -22,12 +22,25 @@ #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" + +//client #include "base_scene.hpp" class InCombat : public BaseScene { public: //Public access members - InCombat(); + InCombat(ConfigUtility* const, UDPNetworkUtility* const, SharedParameters* const); ~InCombat(); protected: @@ -38,11 +51,20 @@ protected: void Render(SDL_Surface* const); //Event handlers + void QuitEvent(); void MouseMotion(SDL_MouseMotionEvent const&); void MouseButtonDown(SDL_MouseButtonEvent const&); void MouseButtonUp(SDL_MouseButtonEvent const&); void KeyDown(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&); + + //Network handlers + void HandlePacket(SerialPacket&); + + //shared parameters + ConfigUtility& config; + UDPNetworkUtility& network; + SharedParameters& params; }; #endif diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 28e7ce5..86619ff 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -31,12 +31,10 @@ //Public access members //------------------------- -InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex): +InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, SharedParameters* const argParams): config(*argConfig), network(*argNetwork), - clientIndex(*argClientIndex), - accountIndex(*argAccountIndex), - characterIndex(*argCharacterIndex) + params(*argParams) { //setup the utility objects buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); @@ -68,9 +66,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 = clientIndex; - packet.clientInfo.accountIndex = accountIndex; - packet.clientInfo.characterIndex = characterIndex; + packet.clientInfo.clientIndex = params.clientIndex; + packet.clientInfo.accountIndex = params.accountIndex; + packet.clientInfo.characterIndex = params.characterIndex; serialize(&packet, buffer); network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); @@ -151,6 +149,7 @@ void InWorld::Render(SDL_Surface* const screen) { void InWorld::QuitEvent() { //exit the game AND the server RequestDisconnect(); + SetNextScene(SceneList::MAINMENU); } void InWorld::MouseMotion(SDL_MouseMotionEvent const& motion) { @@ -273,17 +272,15 @@ void InWorld::HandlePacket(SerialPacket packet) { void InWorld::HandleDisconnect(SerialPacket packet) { network.Unbind(Channels::SERVER); - clientIndex = -1; - accountIndex = -1; - characterIndex = -1; + params.clientIndex = -1; + params.accountIndex = -1; + params.characterIndex = -1; SetNextScene(SceneList::MAINMENU); } void InWorld::HandleRegionContent(SerialPacket packet) { //replace existing regions - if (regionPager.FindRegion(packet.regionInfo.x, packet.regionInfo.y)) { - regionPager.UnloadRegion(packet.regionInfo.x, packet.regionInfo.y); - } + regionPager.UnloadRegion(packet.regionInfo.x, packet.regionInfo.y); regionPager.PushRegion(packet.regionInfo.region); packet.regionInfo.region = nullptr; } @@ -295,7 +292,7 @@ void InWorld::HandleCharacterUpdate(SerialPacket packet) { } //update only if the message didn't originate from here - if (packet.characterInfo.clientIndex != clientIndex) { + if (packet.characterInfo.clientIndex != params.clientIndex) { playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position); playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion); } @@ -308,14 +305,15 @@ void InWorld::HandleCharacterNew(SerialPacket packet) { } //TODO: set the player's handle + //TODO: use a reference, don't use a lookup for every call playerCharacters[packet.characterInfo.characterIndex].GetSprite()->LoadSurface(config["dir.sprites"] + packet.characterInfo.avatar, 4, 4); playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position); playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion); playerCharacters[packet.characterInfo.characterIndex].ResetDirection(); //catch this client's player object - if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) { - localCharacter = &playerCharacters[characterIndex]; + if (packet.characterInfo.characterIndex == params.characterIndex && !localCharacter) { + localCharacter = &playerCharacters[params.characterIndex]; //setup the camera camera.width = GetScreen()->w; @@ -327,16 +325,13 @@ void InWorld::HandleCharacterNew(SerialPacket packet) { } void InWorld::HandleCharacterDelete(SerialPacket packet) { - //TODO: authenticate - if (playerCharacters.find(packet.characterInfo.characterIndex) == playerCharacters.end()) { - throw(std::runtime_error("Cannot delete non-existant characters")); - } + //TODO: authenticate when own character is being deleted playerCharacters.erase(packet.characterInfo.characterIndex); //catch this client's player object - if (packet.characterInfo.characterIndex == characterIndex) { - characterIndex = -1; + if (packet.characterInfo.characterIndex == params.characterIndex) { + params.characterIndex = -1; localCharacter = nullptr; } } @@ -351,9 +346,9 @@ void InWorld::SendPlayerUpdate() { //pack the packet packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE; - packet.characterInfo.clientIndex = clientIndex; - packet.characterInfo.accountIndex = accountIndex; - packet.characterInfo.characterIndex = characterIndex; + packet.characterInfo.clientIndex = params.clientIndex; + packet.characterInfo.accountIndex = params.accountIndex; + packet.characterInfo.characterIndex = params.characterIndex; packet.characterInfo.position = localCharacter->GetPosition(); packet.characterInfo.motion = localCharacter->GetMotion(); @@ -367,9 +362,9 @@ void InWorld::RequestDisconnect() { //send a disconnect request packet.meta.type = SerialPacket::Type::DISCONNECT; - packet.clientInfo.clientIndex = clientIndex; - packet.clientInfo.accountIndex = accountIndex; - packet.clientInfo.characterIndex = characterIndex; + packet.clientInfo.clientIndex = params.clientIndex; + packet.clientInfo.accountIndex = params.accountIndex; + packet.clientInfo.characterIndex = params.characterIndex; serialize(&packet, buffer); network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); } @@ -380,9 +375,9 @@ void InWorld::RequestShutDown() { //send a shutdown request packet.meta.type = SerialPacket::Type::SHUTDOWN; - packet.clientInfo.clientIndex = clientIndex; - packet.clientInfo.accountIndex = accountIndex; - packet.clientInfo.characterIndex = characterIndex; + packet.clientInfo.clientIndex = params.clientIndex; + packet.clientInfo.accountIndex = params.accountIndex; + packet.clientInfo.characterIndex = params.characterIndex; serialize(&packet, buffer); network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); } diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 0b30f5f..74fb233 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -45,6 +45,7 @@ //client #include "base_scene.hpp" #include "player_character.hpp" +#include "shared_parameters.hpp" //STL #include @@ -52,7 +53,7 @@ class InWorld : public BaseScene { public: //Public access members - InWorld(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const, int* const); + InWorld(ConfigUtility* const, UDPNetworkUtility* const, SharedParameters* const); ~InWorld(); protected: @@ -91,9 +92,7 @@ protected: //shared parameters ConfigUtility& config; UDPNetworkUtility& network; - int& clientIndex; - int& accountIndex; - int& characterIndex; + SharedParameters& params; //graphics Image buttonImage; diff --git a/client/scenes/lobby_menu.cpp b/client/scenes/lobby_menu.cpp index cd5a50d..9cd68b5 100644 --- a/client/scenes/lobby_menu.cpp +++ b/client/scenes/lobby_menu.cpp @@ -30,12 +30,10 @@ //Public access members //------------------------- -LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex): +LobbyMenu::LobbyMenu(ConfigUtility* const argConfig, UDPNetworkUtility* const argNetwork, SharedParameters* const argParams): config(*argConfig), network(*argNetwork), - clientIndex(*argClientIndex), - accountIndex(*argAccountIndex), - characterIndex(*argCharacterIndex) + params(*argParams) { //setup the utility objects image.LoadSurface(config["dir.interface"] + "button_menu.bmp"); @@ -94,6 +92,7 @@ void LobbyMenu::FrameEnd() { } void LobbyMenu::Render(SDL_Surface* const screen) { + //TODO: this needs rewriting //TODO: I need a proper UI system for the entire client and the editor //UI search.DrawTo(screen); @@ -221,9 +220,9 @@ void LobbyMenu::HandlePacket(SerialPacket packet) { } break; case SerialPacket::Type::JOIN_RESPONSE: - clientIndex = packet.clientInfo.clientIndex; - accountIndex = packet.clientInfo.accountIndex; - characterIndex = packet.clientInfo.characterIndex; + params.clientIndex = packet.clientInfo.clientIndex; + params.accountIndex = packet.clientInfo.accountIndex; + params.characterIndex = packet.clientInfo.characterIndex; network.Bind(&packet.meta.srcAddress, Channels::SERVER); SetNextScene(SceneList::INWORLD); break; diff --git a/client/scenes/lobby_menu.hpp b/client/scenes/lobby_menu.hpp index 7b6c8a9..efd7b0b 100644 --- a/client/scenes/lobby_menu.hpp +++ b/client/scenes/lobby_menu.hpp @@ -27,6 +27,7 @@ #include "raster_font.hpp" #include "button.hpp" #include "config_utility.hpp" +#include "shared_parameters.hpp" //network #include "udp_network_utility.hpp" @@ -42,7 +43,7 @@ class LobbyMenu : public BaseScene { public: //Public access members - LobbyMenu(ConfigUtility* const, UDPNetworkUtility* const, int* const, int* const, int* const); + LobbyMenu(ConfigUtility* const, UDPNetworkUtility* const, SharedParameters* const); ~LobbyMenu(); protected: @@ -64,9 +65,7 @@ protected: //shared parameters ConfigUtility& config; UDPNetworkUtility& network; - int& clientIndex; - int& accountIndex; - int& characterIndex; + SharedParameters& params; //members Image image; diff --git a/client/shared_parameters.hpp b/client/shared_parameters.hpp new file mode 100644 index 0000000..5963789 --- /dev/null +++ b/client/shared_parameters.hpp @@ -0,0 +1,31 @@ +/* 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_ + +struct SharedParameters { + int clientIndex = -1; + int accountIndex = -1; + int characterIndex = -1; +}; + +#endif diff --git a/server/combat_data.hpp b/server/combat_data.hpp index df75325..4fe73d2 100644 --- a/server/combat_data.hpp +++ b/server/combat_data.hpp @@ -30,13 +30,14 @@ #include #include +#include struct CombatData { typedef std::chrono::steady_clock Clock; - //combatants - std::list characterList; - std::list enemyList; + //combatants, point to the std::map's internal pairs + std::list*> characterList; + std::list*> enemyList; //world interaction int mapIndex = 0; diff --git a/server/enemy_data.hpp b/server/enemy_data.hpp index 48a5fa4..16f3f21 100644 --- a/server/enemy_data.hpp +++ b/server/enemy_data.hpp @@ -43,6 +43,8 @@ struct EnemyData { //NOTE: these are lost when unloaded int tableIndex; int atbGauge = 0; + + static int uidCounter; }; #endif diff --git a/server/server_application.hpp b/server/server_application.hpp index 398c8b4..c8453ac 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -106,6 +106,7 @@ private: std::map accountMap; std::map characterMap; std::map combatMap; + std::map enemyMap; //maps //TODO: I need to handle multiple map objects diff --git a/server/server_internals.cpp b/server/server_internals.cpp index abd16e8..f8624eb 100644 --- a/server/server_internals.cpp +++ b/server/server_internals.cpp @@ -33,6 +33,7 @@ int ClientData::uidCounter = 0; int CombatData::uidCounter = 0; +int EnemyData::uidCounter = 0; //------------------------- //Define the public members From 9620826d65092acd71f829491f7d6accbfb98930 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 26 May 2014 17:29:15 +1000 Subject: [PATCH 07/19] Moved the server's data containers into common/gameplay --- {server => common/gameplay}/account_data.hpp | 0 {server => common/gameplay}/character_data.hpp | 0 {server => common/gameplay}/client_data.hpp | 0 {server => common/gameplay}/combat_data.hpp | 0 {server => common/gameplay}/enemy_data.hpp | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {server => common/gameplay}/account_data.hpp (100%) rename {server => common/gameplay}/character_data.hpp (100%) rename {server => common/gameplay}/client_data.hpp (100%) rename {server => common/gameplay}/combat_data.hpp (100%) rename {server => common/gameplay}/enemy_data.hpp (100%) diff --git a/server/account_data.hpp b/common/gameplay/account_data.hpp similarity index 100% rename from server/account_data.hpp rename to common/gameplay/account_data.hpp diff --git a/server/character_data.hpp b/common/gameplay/character_data.hpp similarity index 100% rename from server/character_data.hpp rename to common/gameplay/character_data.hpp diff --git a/server/client_data.hpp b/common/gameplay/client_data.hpp similarity index 100% rename from server/client_data.hpp rename to common/gameplay/client_data.hpp diff --git a/server/combat_data.hpp b/common/gameplay/combat_data.hpp similarity index 100% rename from server/combat_data.hpp rename to common/gameplay/combat_data.hpp diff --git a/server/enemy_data.hpp b/common/gameplay/enemy_data.hpp similarity index 100% rename from server/enemy_data.hpp rename to common/gameplay/enemy_data.hpp From d903c0df30b5b5a69749c3cb179ee367b57a68fb Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 26 May 2014 17:42:55 +1000 Subject: [PATCH 08/19] Removed the UID counters from the data containers --- common/gameplay/character_data.hpp | 5 +++++ common/gameplay/client_data.hpp | 1 - common/gameplay/combat_data.hpp | 2 -- common/gameplay/enemy_data.hpp | 2 -- server/server_application.hpp | 3 +++ server/server_connections.cpp | 6 +++--- server/server_internals.cpp | 8 -------- 7 files changed, 11 insertions(+), 16 deletions(-) diff --git a/common/gameplay/character_data.hpp b/common/gameplay/character_data.hpp index 4da307f..642c34a 100644 --- a/common/gameplay/character_data.hpp +++ b/common/gameplay/character_data.hpp @@ -28,6 +28,11 @@ #include "statistics.hpp" #include +#include + +//the speeds that the characters move +constexpr double CHARACTER_WALKING_SPEED = 140; +constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); struct CharacterData { //metadata diff --git a/common/gameplay/client_data.hpp b/common/gameplay/client_data.hpp index d67a1ea..7410b08 100644 --- a/common/gameplay/client_data.hpp +++ b/common/gameplay/client_data.hpp @@ -26,7 +26,6 @@ struct ClientData { IPaddress address = {0,0}; - static int uidCounter; }; #endif diff --git a/common/gameplay/combat_data.hpp b/common/gameplay/combat_data.hpp index 4fe73d2..c76520b 100644 --- a/common/gameplay/combat_data.hpp +++ b/common/gameplay/combat_data.hpp @@ -46,8 +46,6 @@ struct CombatData { //time interval Clock::time_point lastTick = Clock::now(); - - static int uidCounter; }; #endif diff --git a/common/gameplay/enemy_data.hpp b/common/gameplay/enemy_data.hpp index 16f3f21..48a5fa4 100644 --- a/common/gameplay/enemy_data.hpp +++ b/common/gameplay/enemy_data.hpp @@ -43,8 +43,6 @@ struct EnemyData { //NOTE: these are lost when unloaded int tableIndex; int atbGauge = 0; - - static int uidCounter; }; #endif diff --git a/server/server_application.hpp b/server/server_application.hpp index c8453ac..0437e1b 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -117,6 +117,9 @@ private: //misc bool running = true; ConfigUtility config; + int clientUID = 0; + int combatUID = 0; + int enemyUID = 0; }; #endif diff --git a/server/server_connections.cpp b/server/server_connections.cpp index 4b3bf0f..0027b6c 100644 --- a/server/server_connections.cpp +++ b/server/server_connections.cpp @@ -47,7 +47,7 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) { newClient.address = packet.meta.srcAddress; //load the user account - int accountIndex = LoadUserAccount(packet.clientInfo.username, ClientData::uidCounter); + int accountIndex = LoadUserAccount(packet.clientInfo.username, clientUID); if (accountIndex < 0) { //TODO: send rejection packet std::cerr << "Error: Account already loaded: " << accountIndex << std::endl; @@ -65,7 +65,7 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) { //send the client their info packet.meta.type = SerialPacket::Type::JOIN_RESPONSE; - packet.clientInfo.clientIndex = ClientData::uidCounter; + packet.clientInfo.clientIndex = clientUID; packet.clientInfo.accountIndex = accountIndex; packet.clientInfo.characterIndex = characterIndex; @@ -85,7 +85,7 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) { //TODO: don't send anything to a certain client until they send the OK (the sync packet? or ignore client side?) //finished this routine - clientMap[ClientData::uidCounter++] = newClient; + clientMap[clientUID++] = newClient; std::cout << "Connect, total: " << clientMap.size() << std::endl; } diff --git a/server/server_internals.cpp b/server/server_internals.cpp index f8624eb..d75c9c3 100644 --- a/server/server_internals.cpp +++ b/server/server_internals.cpp @@ -27,14 +27,6 @@ #include #include -//------------------------- -//Define the various UIDs -//------------------------- - -int ClientData::uidCounter = 0; -int CombatData::uidCounter = 0; -int EnemyData::uidCounter = 0; - //------------------------- //Define the public members //------------------------- From 1bde0ed3f75384f3fe6cd27b95404c8fe9f47315 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 26 May 2014 18:35:38 +1000 Subject: [PATCH 09/19] Began unifying the server and client side character classes This commit won't build --- client/player_character.cpp | 117 ----------------------------- client/player_character.hpp | 67 ----------------- client/scenes/in_world.hpp | 3 +- client/shared_parameters.hpp | 9 +++ common/gameplay/character_data.hpp | 2 +- 5 files changed, 11 insertions(+), 187 deletions(-) delete mode 100644 client/player_character.cpp delete mode 100644 client/player_character.hpp diff --git a/client/player_character.cpp b/client/player_character.cpp deleted file mode 100644 index 8e20c92..0000000 --- a/client/player_character.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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. -*/ -#include "player_character.hpp" - -#define WALKING_SPEED 140 - -void PlayerCharacter::Update(double delta) { - if (diagonal) { - constexpr double d = 1.0/sqrt(2); - position += motion * delta * d; - } - else { - position += motion * delta; - } - sprite.Update(delta); -} - -void PlayerCharacter::AdjustDirection(Direction direction) { - //shift the movement in this direction - switch(direction) { - case Direction::NORTH: - if (motion.y >= 0) { - motion.y -= WALKING_SPEED; - } - break; - case Direction::SOUTH: - if (motion.y <= 0) { - motion.y += WALKING_SPEED; - } - break; - case Direction::WEST: - if (motion.x >= 0) { - motion.x -= WALKING_SPEED; - } - break; - case Direction::EAST: - if (motion.x <= 0) { - motion.x += WALKING_SPEED; - } - break; - } - //face the correct direction - ResetDirection(); -} - -void PlayerCharacter::FaceDirection(Direction direction) { - //this function depends on the format of the sprite sheets - switch(direction) { - case Direction::NORTH: - sprite.SetYIndex(1); - break; - case Direction::SOUTH: - sprite.SetYIndex(0); - break; - case Direction::WEST: - sprite.SetYIndex(2); - break; - case Direction::EAST: - sprite.SetYIndex(3); - break; - } -} - -void PlayerCharacter::ResetDirection() { - //base the direction on the character's movement - if (motion.y > 0) { - FaceDirection(Direction::SOUTH); - } - else if (motion.y < 0) { - FaceDirection(Direction::NORTH); - } - else if (motion.x > 0) { - FaceDirection(Direction::EAST); - } - else if (motion.x < 0) { - FaceDirection(Direction::WEST); - } - ResetSpeed(); -} - -void PlayerCharacter::ResetSpeed() { - //diagonal - if (motion.x != 0 && motion.y != 0) { - sprite.SetDelay(0.1); - diagonal = true; - } - //cardinal - else if (motion != 0) { - sprite.SetDelay(0.1); - diagonal = false; - } - //not moving - else { - sprite.SetDelay(0); - sprite.SetXIndex(0); - diagonal = false; - } -} diff --git a/client/player_character.hpp b/client/player_character.hpp deleted file mode 100644 index 9dde742..0000000 --- a/client/player_character.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * 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 PLAYERCHARACTER_HPP_ -#define PLAYERCHARACTER_HPP_ - -#include "vector2.hpp" -#include "sprite_sheet.hpp" - -//TODO: correct the PlayerCharacter class and it's movement system -class PlayerCharacter { -public: - enum class Direction { - NORTH, SOUTH, EAST, WEST - }; - - PlayerCharacter() = default; - ~PlayerCharacter() = default; - - void Update(double delta); - - void DrawTo(SDL_Surface* const dest, int camX, int camY) { sprite.DrawTo(dest, position.x - camX, position.y - camY); } - - //clunky code results in smooth movement and controls - void AdjustDirection(Direction); - void FaceDirection(Direction); - void ResetDirection(); - void ResetSpeed(); - - //accessors and mutators - Vector2 SetPosition(Vector2 v) { return position = v; } - Vector2 ShiftPosition(Vector2 v) { return position += v; } - Vector2 GetPosition() { return position; } - - Vector2 SetMotion(Vector2 v) { return motion = v; } - Vector2 ShiftMotion(Vector2 v) { return motion += v; } - Vector2 GetMotion() { return motion; } - - SpriteSheet* GetSprite() { return &sprite; } -private: - Vector2 position; - Vector2 motion; - SpriteSheet sprite; - - //for moving diagonally - bool diagonal = false; -}; - -#endif diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 74fb233..d0c7047 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -44,7 +44,6 @@ //client #include "base_scene.hpp" -#include "player_character.hpp" #include "shared_parameters.hpp" //STL @@ -98,6 +97,7 @@ protected: Image buttonImage; RasterFont font; TileSheet tileSheet; + //TODO: sprites //map RegionPager regionPager; @@ -114,7 +114,6 @@ protected: FrameRate fps; //game - std::map playerCharacters; PlayerCharacter* localCharacter = nullptr; }; diff --git a/client/shared_parameters.hpp b/client/shared_parameters.hpp index 5963789..3a38a9c 100644 --- a/client/shared_parameters.hpp +++ b/client/shared_parameters.hpp @@ -22,10 +22,19 @@ #ifndef SHAREDPARAMETERS_HPP_ #define SHAREDPARAMETERS_HPP_ +#include "character_data.hpp" +#include "enemy_data.hpp" + +#include + struct SharedParameters { int clientIndex = -1; int accountIndex = -1; int characterIndex = -1; + + std::map characterMap; + std::map combatMap; + std::map enemyMap; }; #endif diff --git a/common/gameplay/character_data.hpp b/common/gameplay/character_data.hpp index 642c34a..8d75293 100644 --- a/common/gameplay/character_data.hpp +++ b/common/gameplay/character_data.hpp @@ -31,7 +31,7 @@ #include //the speeds that the characters move -constexpr double CHARACTER_WALKING_SPEED = 140; +constexpr double CHARACTER_WALKING_SPEED = 140.0; constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); struct CharacterData { From 5893342ad82e65c363fbe80ccb7619f1f83b3462 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 27 May 2014 22:24:30 +1000 Subject: [PATCH 10/19] 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. --- client/client_application.cpp | 6 ++-- client/client_application.hpp | 14 +++++++-- client/scenes/in_combat.cpp | 37 +++++++++++++++++++---- client/scenes/in_combat.hpp | 46 ++++++++++++++++++++++------ client/scenes/in_world.cpp | 52 ++++++++++++++++++-------------- client/scenes/in_world.hpp | 15 ++++++--- client/scenes/lobby_menu.cpp | 18 ++++++++--- client/scenes/lobby_menu.hpp | 13 ++++++-- client/shared_parameters.hpp | 40 ------------------------ common/network/serial_packet.hpp | 2 ++ rsc/scripts/setup_server.sql | 1 + 11 files changed, 149 insertions(+), 95 deletions(-) delete mode 100644 client/shared_parameters.hpp diff --git a/client/client_application.cpp b/client/client_application.cpp index 9f3d395..0f5e45e 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -119,13 +119,13 @@ void ClientApplication::LoadScene(SceneList sceneIndex) { activeScene = new OptionsMenu(&config); break; case SceneList::LOBBYMENU: - activeScene = new LobbyMenu(&config, &network, ¶ms); + activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex); break; case SceneList::INWORLD: - activeScene = new InWorld(&config, &network, ¶ms); + activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex); break; case SceneList::INCOMBAT: - activeScene = new InCombat(&config, &network, ¶ms); + activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex); break; default: throw(std::logic_error("Failed to recognize the scene index")); diff --git a/client/client_application.hpp b/client/client_application.hpp index 07155ae..46680bb 100644 --- a/client/client_application.hpp +++ b/client/client_application.hpp @@ -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 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 characterMap; + std::map combatMap; + std::map enemyMap; }; #endif diff --git a/client/scenes/in_combat.cpp b/client/scenes/in_combat.cpp index b0d69ec..243df51 100644 --- a/client/scenes/in_combat.cpp +++ b/client/scenes/in_combat.cpp @@ -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) { - // -} \ No newline at end of file +//------------------------- +//Network handlers +//------------------------- + +//TODO: network handlers + +//------------------------- +//Server control +//------------------------- + +//TODO: server control diff --git a/client/scenes/in_combat.hpp b/client/scenes/in_combat.hpp index c9d58f3..2bbc28f 100644 --- a/client/scenes/in_combat.hpp +++ b/client/scenes/in_combat.hpp @@ -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 diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 86619ff..8e2cc26 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -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); } diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index d0c7047..48b34bb 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -44,7 +44,6 @@ //client #include "base_scene.hpp" -#include "shared_parameters.hpp" //STL #include @@ -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 diff --git a/client/scenes/lobby_menu.cpp b/client/scenes/lobby_menu.cpp index 9cd68b5..161e329 100644 --- a/client/scenes/lobby_menu.cpp +++ b/client/scenes/lobby_menu.cpp @@ -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; diff --git a/client/scenes/lobby_menu.hpp b/client/scenes/lobby_menu.hpp index efd7b0b..d386b21 100644 --- a/client/scenes/lobby_menu.hpp +++ b/client/scenes/lobby_menu.hpp @@ -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; diff --git a/client/shared_parameters.hpp b/client/shared_parameters.hpp deleted file mode 100644 index 3a38a9c..0000000 --- a/client/shared_parameters.hpp +++ /dev/null @@ -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 - -struct SharedParameters { - int clientIndex = -1; - int accountIndex = -1; - int characterIndex = -1; - - std::map characterMap; - std::map combatMap; - std::map enemyMap; -}; - -#endif diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index 1dd94a6..e97c711 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -72,6 +72,8 @@ union SerialPacket { COMBAT_ENTER, COMBAT_EXIT, + COMBAT_UPDATE, + COMBAT_REJECTION, //character data diff --git a/rsc/scripts/setup_server.sql b/rsc/scripts/setup_server.sql index 1167c3c..d43c592 100644 --- a/rsc/scripts/setup_server.sql +++ b/rsc/scripts/setup_server.sql @@ -1,3 +1,4 @@ +--TODO: Rename the SQL's tables, for consistency ------------------------- --Server ------------------------- From 6b38501c27bee2f834aa4954dbce98d0d40a3a1c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 27 May 2014 23:25:07 +1000 Subject: [PATCH 11/19] Added the GRAPHICS flag, to simplify the gameplay structures --- client/makefile | 2 +- client/scenes/in_world.hpp | 3 +++ client/scenes/lobby_menu.cpp | 4 ++++ client/scenes/lobby_menu.hpp | 1 + client/scenes/makefile | 2 +- common/gameplay/character_data.hpp | 9 +++++++++ common/gameplay/combat_data.hpp | 13 +++++++++++++ common/gameplay/enemy_data.hpp | 10 ++++++++++ 8 files changed, 42 insertions(+), 2 deletions(-) diff --git a/client/makefile b/client/makefile index f049556..2c055e4 100644 --- a/client/makefile +++ b/client/makefile @@ -1,7 +1,7 @@ #config INCLUDES+=. scenes ../common/gameplay ../common/graphics ../common/map ../common/network ../common/ui ../common/utilities LIBS+=libclient.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS #source CXXSRC=$(wildcard *.cpp) diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 48b34bb..8b3c149 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -42,6 +42,9 @@ #include "config_utility.hpp" #include "frame_rate.hpp" +#include "character_data.hpp" +#include "combat_data.hpp" + //client #include "base_scene.hpp" diff --git a/client/scenes/lobby_menu.cpp b/client/scenes/lobby_menu.cpp index 161e329..8bd5671 100644 --- a/client/scenes/lobby_menu.cpp +++ b/client/scenes/lobby_menu.cpp @@ -210,6 +210,10 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) { // } +//------------------------- +//Network handlers +//------------------------- + void LobbyMenu::HandlePacket(SerialPacket packet) { switch(packet.meta.type) { case SerialPacket::Type::BROADCAST_RESPONSE: { diff --git a/client/scenes/lobby_menu.hpp b/client/scenes/lobby_menu.hpp index d386b21..9c858cb 100644 --- a/client/scenes/lobby_menu.hpp +++ b/client/scenes/lobby_menu.hpp @@ -65,6 +65,7 @@ protected: void KeyDown(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&); + //Network handlers void HandlePacket(SerialPacket); //shared parameters diff --git a/client/scenes/makefile b/client/scenes/makefile index d09de2e..81d7685 100644 --- a/client/scenes/makefile +++ b/client/scenes/makefile @@ -1,7 +1,7 @@ #config INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/ui ../../common/utilities LIBS+=libclient.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS #source CXXSRC=$(wildcard *.cpp) diff --git a/common/gameplay/character_data.hpp b/common/gameplay/character_data.hpp index 8d75293..9c8602a 100644 --- a/common/gameplay/character_data.hpp +++ b/common/gameplay/character_data.hpp @@ -27,6 +27,12 @@ #include "vector2.hpp" #include "statistics.hpp" +//graphics +#ifdef GRAPHICS + #include "sprite_sheet.hpp" +#endif + +//std namespace #include #include @@ -55,6 +61,9 @@ struct CharacterData { //active gameplay members //NOTE: these are lost when unloaded +#ifdef GRAPHICS + SpriteSheet sprite; +#endif BBox bbox = {0,0,0,0}; bool inCombat = false; int atbGauge = 0; diff --git a/common/gameplay/combat_data.hpp b/common/gameplay/combat_data.hpp index c76520b..a013577 100644 --- a/common/gameplay/combat_data.hpp +++ b/common/gameplay/combat_data.hpp @@ -22,12 +22,20 @@ #ifndef COMBATDATA_HPP_ #define COMBATDATA_HPP_ +//POD members #include "vector2.hpp" #include "bbox.hpp" +//gameplay members #include "character_data.hpp" #include "enemy_data.hpp" +//graphics +#ifdef GRAPHICS + #include "sprite_sheet.hpp" +#endif + +//std namespace #include #include #include @@ -46,6 +54,11 @@ struct CombatData { //time interval Clock::time_point lastTick = Clock::now(); + + //graphics +#ifdef GRAPHICS + SpriteSheet sprite; +#endif }; #endif diff --git a/common/gameplay/enemy_data.hpp b/common/gameplay/enemy_data.hpp index 48a5fa4..d0edd0a 100644 --- a/common/gameplay/enemy_data.hpp +++ b/common/gameplay/enemy_data.hpp @@ -22,8 +22,15 @@ #ifndef ENEMYDATA_HPP_ #define ENEMYDATA_HPP_ +//gameplay #include "statistics.hpp" +//graphics +#ifdef GRAPHICS + #include "sprite_sheet.hpp" +#endif + +//std namespace #include struct EnemyData { @@ -41,6 +48,9 @@ struct EnemyData { //active gameplay members //NOTE: these are lost when unloaded +#ifdef GRAPHICS + SpriteSheet sprite; +#endif int tableIndex; int atbGauge = 0; }; From b86d3935714d99eec3cbc91224e75c2bdc57847d Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 27 May 2014 23:28:29 +1000 Subject: [PATCH 12/19] Moved the scenes up one directory level, subdirs no longer needed --- client/{scenes => }/base_scene.cpp | 0 client/{scenes => }/base_scene.hpp | 0 client/{scenes => }/in_combat.cpp | 0 client/{scenes => }/in_combat.hpp | 0 client/{scenes => }/in_world.cpp | 0 client/{scenes => }/in_world.hpp | 0 client/{scenes => }/lobby_menu.cpp | 0 client/{scenes => }/lobby_menu.hpp | 0 client/{scenes => }/main_menu.cpp | 0 client/{scenes => }/main_menu.hpp | 0 client/makefile | 5 ++-- client/{scenes => }/options_menu.cpp | 0 client/{scenes => }/options_menu.hpp | 0 client/scenes/makefile | 37 --------------------------- client/{scenes => }/splash_screen.cpp | 0 client/{scenes => }/splash_screen.hpp | 0 16 files changed, 2 insertions(+), 40 deletions(-) rename client/{scenes => }/base_scene.cpp (100%) rename client/{scenes => }/base_scene.hpp (100%) rename client/{scenes => }/in_combat.cpp (100%) rename client/{scenes => }/in_combat.hpp (100%) rename client/{scenes => }/in_world.cpp (100%) rename client/{scenes => }/in_world.hpp (100%) rename client/{scenes => }/lobby_menu.cpp (100%) rename client/{scenes => }/lobby_menu.hpp (100%) rename client/{scenes => }/main_menu.cpp (100%) rename client/{scenes => }/main_menu.hpp (100%) rename client/{scenes => }/options_menu.cpp (100%) rename client/{scenes => }/options_menu.hpp (100%) delete mode 100644 client/scenes/makefile rename client/{scenes => }/splash_screen.cpp (100%) rename client/{scenes => }/splash_screen.hpp (100%) diff --git a/client/scenes/base_scene.cpp b/client/base_scene.cpp similarity index 100% rename from client/scenes/base_scene.cpp rename to client/base_scene.cpp diff --git a/client/scenes/base_scene.hpp b/client/base_scene.hpp similarity index 100% rename from client/scenes/base_scene.hpp rename to client/base_scene.hpp diff --git a/client/scenes/in_combat.cpp b/client/in_combat.cpp similarity index 100% rename from client/scenes/in_combat.cpp rename to client/in_combat.cpp diff --git a/client/scenes/in_combat.hpp b/client/in_combat.hpp similarity index 100% rename from client/scenes/in_combat.hpp rename to client/in_combat.hpp diff --git a/client/scenes/in_world.cpp b/client/in_world.cpp similarity index 100% rename from client/scenes/in_world.cpp rename to client/in_world.cpp diff --git a/client/scenes/in_world.hpp b/client/in_world.hpp similarity index 100% rename from client/scenes/in_world.hpp rename to client/in_world.hpp diff --git a/client/scenes/lobby_menu.cpp b/client/lobby_menu.cpp similarity index 100% rename from client/scenes/lobby_menu.cpp rename to client/lobby_menu.cpp diff --git a/client/scenes/lobby_menu.hpp b/client/lobby_menu.hpp similarity index 100% rename from client/scenes/lobby_menu.hpp rename to client/lobby_menu.hpp diff --git a/client/scenes/main_menu.cpp b/client/main_menu.cpp similarity index 100% rename from client/scenes/main_menu.cpp rename to client/main_menu.cpp diff --git a/client/scenes/main_menu.hpp b/client/main_menu.hpp similarity index 100% rename from client/scenes/main_menu.hpp rename to client/main_menu.hpp diff --git a/client/makefile b/client/makefile index 2c055e4..bba3c67 100644 --- a/client/makefile +++ b/client/makefile @@ -1,6 +1,6 @@ #config -INCLUDES+=. scenes ../common/gameplay ../common/graphics ../common/map ../common/network ../common/ui ../common/utilities -LIBS+=libclient.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua +INCLUDES+=. ../common/gameplay ../common/graphics ../common/map ../common/network ../common/ui ../common/utilities +LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS #source @@ -16,7 +16,6 @@ OUT=$(addprefix $(OUTDIR)/,client) #targets all: $(OBJ) $(OUT) - $(MAKE) -C scenes $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(OBJ): | $(OBJDIR) diff --git a/client/scenes/options_menu.cpp b/client/options_menu.cpp similarity index 100% rename from client/scenes/options_menu.cpp rename to client/options_menu.cpp diff --git a/client/scenes/options_menu.hpp b/client/options_menu.hpp similarity index 100% rename from client/scenes/options_menu.hpp rename to client/options_menu.hpp diff --git a/client/scenes/makefile b/client/scenes/makefile deleted file mode 100644 index 81d7685..0000000 --- a/client/scenes/makefile +++ /dev/null @@ -1,37 +0,0 @@ -#config -INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/ui ../../common/utilities -LIBS+=libclient.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS - -#source -CXXSRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) - -#output -OUTDIR=.. -OUT=$(addprefix $(OUTDIR)/,libclient.a) - -#targets -all: $(OBJ) $(OUT) - ar -crs $(OUT) $(OBJ) - -$(OBJ): | $(OBJDIR) - -$(OUT): | $(OUTDIR) - -$(OBJDIR): - mkdir $(OBJDIR) - -$(OUTDIR): - mkdir $(OUTDIR) - -$(OBJDIR)/%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -clean: - $(RM) *.o *.a *.exe - -rebuild: clean all diff --git a/client/scenes/splash_screen.cpp b/client/splash_screen.cpp similarity index 100% rename from client/scenes/splash_screen.cpp rename to client/splash_screen.cpp diff --git a/client/scenes/splash_screen.hpp b/client/splash_screen.hpp similarity index 100% rename from client/scenes/splash_screen.hpp rename to client/splash_screen.hpp From 967f0653a14a20509f3f341900520b8157dc230e Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 27 May 2014 23:59:42 +1000 Subject: [PATCH 13/19] Threaded the tables through the scenes --- client/client_application.cpp | 4 ++-- client/client_application.hpp | 2 +- client/in_combat.cpp | 10 ++++++++-- client/in_combat.hpp | 12 +++++++++++- client/in_world.cpp | 29 ++++++++++++++++++++--------- client/in_world.hpp | 8 ++++++-- 6 files changed, 48 insertions(+), 17 deletions(-) diff --git a/client/client_application.cpp b/client/client_application.cpp index 0f5e45e..cbf2f68 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -122,10 +122,10 @@ void ClientApplication::LoadScene(SceneList sceneIndex) { activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex); break; case SceneList::INWORLD: - activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex); + activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap); break; case SceneList::INCOMBAT: - activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex); + activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap); break; default: throw(std::logic_error("Failed to recognize the scene index")); diff --git a/client/client_application.hpp b/client/client_application.hpp index 46680bb..54df4ff 100644 --- a/client/client_application.hpp +++ b/client/client_application.hpp @@ -56,8 +56,8 @@ private: int accountIndex = -1; int characterIndex = -1; - std::map characterMap; std::map combatMap; + std::map characterMap; std::map enemyMap; }; diff --git a/client/in_combat.cpp b/client/in_combat.cpp index 243df51..c8321d5 100644 --- a/client/in_combat.cpp +++ b/client/in_combat.cpp @@ -30,13 +30,19 @@ InCombat::InCombat( UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, - int* const argCharacterIndex + int* const argCharacterIndex, + std::map* argCombatMap, + std::map* argCharacterMap, + std::map* argEnemyMap ): config(*argConfig), network(*argNetwork), clientIndex(*argClientIndex), accountIndex(*argAccountIndex), - characterIndex(*argCharacterIndex) + characterIndex(*argCharacterIndex), + combatMap(*argCombatMap), + characterMap(*argCharacterMap), + enemyMap(*argEnemyMap) { // } diff --git a/client/in_combat.hpp b/client/in_combat.hpp index 2bbc28f..dbd802b 100644 --- a/client/in_combat.hpp +++ b/client/in_combat.hpp @@ -36,6 +36,10 @@ #include "config_utility.hpp" #include "frame_rate.hpp" +#include "combat_data.hpp" +#include "character_data.hpp" +#include "enemy_data.hpp" + //client #include "base_scene.hpp" @@ -47,7 +51,10 @@ public: UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, - int* const argCharacterIndex + int* const argCharacterIndex, + std::map* argCombatMap, + std::map* argCharacterMap, + std::map* argEnemyMap ); ~InCombat(); @@ -84,6 +91,9 @@ protected: int& clientIndex; int& accountIndex; int& characterIndex; + std::map& combatMap; + std::map& characterMap; + std::map& enemyMap; //graphics //TODO: graphics diff --git a/client/in_world.cpp b/client/in_world.cpp index 8e2cc26..d43ad14 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -36,13 +36,17 @@ InWorld::InWorld( UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, - int* const argCharacterIndex + int* const argCharacterIndex, + std::map* argCombatMap, + std::map* argCharacterMap ): config(*argConfig), network(*argNetwork), clientIndex(*argClientIndex), accountIndex(*argAccountIndex), - characterIndex(*argCharacterIndex) + characterIndex(*argCharacterIndex), + combatMap(*argCombatMap), + characterMap(*argCharacterMap), { //setup the utility objects buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); @@ -108,14 +112,21 @@ void InWorld::Update(double delta) { //update the characters for (auto& it : playerCharacters) { - it.second.Update(delta); + if (it.second.motion.x && it.second.motion.y) { + //TODO: refactor this into a method + it.second.position += it.second.motion * CHARACTER_WALKING_SPEED * CHARACTER_WALKING_MOD; + } + else if (it.second.motion != 0) { + it.second.position += it.second.motion * CHARACTER_WALKING_SPEED; + } + //TODO: SPRITE: fix sprite } //TODO: sort the players and entities by Y position //update the camera if(localCharacter) { - camera.x = localCharacter->GetPosition().x - camera.marginX; - camera.y = localCharacter->GetPosition().y - camera.marginY; + camera.x = localCharacter->position.x - camera.marginX; + camera.y = localCharacter->position.y - camera.marginY; } //check the map @@ -327,8 +338,8 @@ void InWorld::HandleCharacterNew(SerialPacket packet) { camera.width = GetScreen()->w; camera.height = GetScreen()->h; //center on the player's character - camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2); - camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); + camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite->GetImage()->GetClipW() / 2); + camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite->GetImage()->GetClipH() / 2); } } @@ -357,8 +368,8 @@ void InWorld::SendPlayerUpdate() { packet.characterInfo.clientIndex = clientIndex; packet.characterInfo.accountIndex = accountIndex; packet.characterInfo.characterIndex = characterIndex; - packet.characterInfo.position = localCharacter->GetPosition(); - packet.characterInfo.motion = localCharacter->GetMotion(); + packet.characterInfo.position = localCharacter->position; + packet.characterInfo.motion = localCharacter->motion; serialize(&packet, buffer); network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); diff --git a/client/in_world.hpp b/client/in_world.hpp index 8b3c149..60a96a8 100644 --- a/client/in_world.hpp +++ b/client/in_world.hpp @@ -42,8 +42,8 @@ #include "config_utility.hpp" #include "frame_rate.hpp" -#include "character_data.hpp" #include "combat_data.hpp" +#include "character_data.hpp" //client #include "base_scene.hpp" @@ -59,7 +59,9 @@ public: UDPNetworkUtility* const argNetwork, int* const argClientIndex, int* const argAccountIndex, - int* const argCharacterIndex + int* const argCharacterIndex, + std::map* argCombatMap, + std::map* argCharacterMap ); ~InWorld(); @@ -102,6 +104,8 @@ protected: int& clientIndex; int& accountIndex; int& characterIndex; + std::map& combatMap; + std::map& characterMap; //graphics Image buttonImage; From 519b8a1e367d4cf0a3ed3a98dc73b16a9a440786 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 28 May 2014 00:25:58 +1000 Subject: [PATCH 14/19] Entire project is building cleanly again, but characters are static --- client/in_combat.cpp | 2 +- client/in_world.cpp | 57 +++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/client/in_combat.cpp b/client/in_combat.cpp index c8321d5..85afe25 100644 --- a/client/in_combat.cpp +++ b/client/in_combat.cpp @@ -84,7 +84,7 @@ void InCombat::Render(SDL_Surface* const screen) { void InCombat::QuitEvent() { //exit the game AND the server - RequestDisconnect(); +// RequestDisconnect(); SetNextScene(SceneList::MAINMENU); } diff --git a/client/in_world.cpp b/client/in_world.cpp index d43ad14..ec2d69c 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -46,7 +46,7 @@ InWorld::InWorld( accountIndex(*argAccountIndex), characterIndex(*argCharacterIndex), combatMap(*argCombatMap), - characterMap(*argCharacterMap), + characterMap(*argCharacterMap) { //setup the utility objects buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); @@ -111,13 +111,13 @@ void InWorld::Update(double delta) { } //update the characters - for (auto& it : playerCharacters) { + for (auto& it : characterMap) { if (it.second.motion.x && it.second.motion.y) { //TODO: refactor this into a method - it.second.position += it.second.motion * CHARACTER_WALKING_SPEED * CHARACTER_WALKING_MOD; + it.second.position += it.second.motion * delta * CHARACTER_WALKING_MOD; } else if (it.second.motion != 0) { - it.second.position += it.second.motion * CHARACTER_WALKING_SPEED; + it.second.position += it.second.motion * delta; } //TODO: SPRITE: fix sprite } @@ -151,8 +151,9 @@ void InWorld::Render(SDL_Surface* const screen) { } //draw characters - for (auto& it : playerCharacters) { - it.second.DrawTo(screen, camera.x, camera.y); + for (auto& it : characterMap) { + //TODO: refactor this + it.second.sprite.DrawTo(screen, it.second.position.x - camera.x, it.second.position.y - camera.y); } //draw UI @@ -200,28 +201,28 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) { //player movement case SDLK_LEFT: if (localCharacter) { - localCharacter->AdjustDirection(PlayerCharacter::Direction::WEST); + localCharacter->motion.x -= CHARACTER_WALKING_SPEED; SendPlayerUpdate(); } break; case SDLK_RIGHT: if (localCharacter) { - localCharacter->AdjustDirection(PlayerCharacter::Direction::EAST); + localCharacter->motion.x += CHARACTER_WALKING_SPEED; SendPlayerUpdate(); } break; case SDLK_UP: if (localCharacter) { - localCharacter->AdjustDirection(PlayerCharacter::Direction::NORTH); + localCharacter->motion.y -= CHARACTER_WALKING_SPEED; SendPlayerUpdate(); } break; case SDLK_DOWN: if (localCharacter) { - localCharacter->AdjustDirection(PlayerCharacter::Direction::SOUTH); + localCharacter->motion.y += CHARACTER_WALKING_SPEED; SendPlayerUpdate(); } break; @@ -233,28 +234,28 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) { //player movement case SDLK_LEFT: if (localCharacter) { - localCharacter->AdjustDirection(PlayerCharacter::Direction::EAST); + localCharacter->motion.x += CHARACTER_WALKING_SPEED; SendPlayerUpdate(); } break; case SDLK_RIGHT: if (localCharacter) { - localCharacter->AdjustDirection(PlayerCharacter::Direction::WEST); + localCharacter->motion.x -= CHARACTER_WALKING_SPEED; SendPlayerUpdate(); } break; case SDLK_UP: if (localCharacter) { - localCharacter->AdjustDirection(PlayerCharacter::Direction::SOUTH); + localCharacter->motion.y += CHARACTER_WALKING_SPEED; SendPlayerUpdate(); } break; case SDLK_DOWN: if (localCharacter) { - localCharacter->AdjustDirection(PlayerCharacter::Direction::NORTH); + localCharacter->motion.y -= CHARACTER_WALKING_SPEED; SendPlayerUpdate(); } break; @@ -305,48 +306,50 @@ void InWorld::HandleRegionContent(SerialPacket packet) { } void InWorld::HandleCharacterUpdate(SerialPacket packet) { - if (playerCharacters.find(packet.characterInfo.characterIndex) == playerCharacters.end()) { + if (characterMap.find(packet.characterInfo.characterIndex) == characterMap.end()) { HandleCharacterNew(packet); return; } //update only if the message didn't originate from here if (packet.characterInfo.clientIndex != clientIndex) { - playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position); - playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion); + characterMap[packet.characterInfo.characterIndex].position = packet.characterInfo.position; + characterMap[packet.characterInfo.characterIndex].motion = packet.characterInfo.motion; } - playerCharacters[packet.characterInfo.characterIndex].ResetDirection(); + //TODO: refactor this +// characterMap[packet.characterInfo.characterIndex].ResetDirection(); } void InWorld::HandleCharacterNew(SerialPacket packet) { - if (playerCharacters.find(packet.characterInfo.characterIndex) != playerCharacters.end()) { + if (characterMap.find(packet.characterInfo.characterIndex) != characterMap.end()) { throw(std::runtime_error("Cannot create duplicate characters")); } //TODO: set the player's handle //TODO: use a reference, don't use a lookup for every call - playerCharacters[packet.characterInfo.characterIndex].GetSprite()->LoadSurface(config["dir.sprites"] + packet.characterInfo.avatar, 4, 4); - playerCharacters[packet.characterInfo.characterIndex].SetPosition(packet.characterInfo.position); - playerCharacters[packet.characterInfo.characterIndex].SetMotion(packet.characterInfo.motion); - playerCharacters[packet.characterInfo.characterIndex].ResetDirection(); + characterMap[packet.characterInfo.characterIndex].sprite.LoadSurface(config["dir.sprites"] + packet.characterInfo.avatar, 4, 4); + characterMap[packet.characterInfo.characterIndex].position = packet.characterInfo.position; + characterMap[packet.characterInfo.characterIndex].motion = packet.characterInfo.motion; + //TODO: refactor this +// characterMap[packet.characterInfo.characterIndex].ResetDirection(); //catch this client's player object if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) { - localCharacter = &playerCharacters[characterIndex]; + localCharacter = &characterMap[characterIndex]; //setup the camera camera.width = GetScreen()->w; camera.height = GetScreen()->h; //center on the player's character - camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite->GetImage()->GetClipW() / 2); - camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite->GetImage()->GetClipH() / 2); + camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite.GetImage()->GetClipW() / 2); + camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite.GetImage()->GetClipH() / 2); } } void InWorld::HandleCharacterDelete(SerialPacket packet) { //TODO: authenticate when own character is being deleted - playerCharacters.erase(packet.characterInfo.characterIndex); + characterMap.erase(packet.characterInfo.characterIndex); //catch this client's player object if (packet.characterInfo.characterIndex == characterIndex) { From 6428b02d858eb775cd663778feb594fe6901d9c7 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 28 May 2014 21:07:11 +1000 Subject: [PATCH 15/19] Refactored some code from InWorld into methods in CharacterData --- client/in_combat.hpp | 2 +- client/in_world.cpp | 18 ++------ common/gameplay/character_data.cpp | 67 ++++++++++++++++++++++++++++++ common/gameplay/character_data.hpp | 7 ++++ common/gameplay/makefile | 4 +- common/gameplay/sanity_check.cpp | 15 +++++++ 6 files changed, 96 insertions(+), 17 deletions(-) create mode 100644 common/gameplay/character_data.cpp create mode 100644 common/gameplay/sanity_check.cpp diff --git a/client/in_combat.hpp b/client/in_combat.hpp index dbd802b..44e91ee 100644 --- a/client/in_combat.hpp +++ b/client/in_combat.hpp @@ -83,7 +83,7 @@ protected: void SendPlayerUpdate(); void RequestDisconnect(); void RequestShutdown(); - //TOOD: more + //TODO: more //shared parameters ConfigUtility& config; diff --git a/client/in_world.cpp b/client/in_world.cpp index ec2d69c..ecddb90 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -112,14 +112,7 @@ void InWorld::Update(double delta) { //update the characters for (auto& it : characterMap) { - if (it.second.motion.x && it.second.motion.y) { - //TODO: refactor this into a method - it.second.position += it.second.motion * delta * CHARACTER_WALKING_MOD; - } - else if (it.second.motion != 0) { - it.second.position += it.second.motion * delta; - } - //TODO: SPRITE: fix sprite + it.second.Update(delta); } //TODO: sort the players and entities by Y position @@ -152,8 +145,7 @@ void InWorld::Render(SDL_Surface* const screen) { //draw characters for (auto& it : characterMap) { - //TODO: refactor this - it.second.sprite.DrawTo(screen, it.second.position.x - camera.x, it.second.position.y - camera.y); + it.second.DrawTo(screen, camera.x, camera.y); } //draw UI @@ -316,8 +308,7 @@ void InWorld::HandleCharacterUpdate(SerialPacket packet) { characterMap[packet.characterInfo.characterIndex].position = packet.characterInfo.position; characterMap[packet.characterInfo.characterIndex].motion = packet.characterInfo.motion; } - //TODO: refactor this -// characterMap[packet.characterInfo.characterIndex].ResetDirection(); + characterMap[packet.characterInfo.characterIndex].CorrectSprite(); } void InWorld::HandleCharacterNew(SerialPacket packet) { @@ -330,8 +321,7 @@ void InWorld::HandleCharacterNew(SerialPacket packet) { characterMap[packet.characterInfo.characterIndex].sprite.LoadSurface(config["dir.sprites"] + packet.characterInfo.avatar, 4, 4); characterMap[packet.characterInfo.characterIndex].position = packet.characterInfo.position; characterMap[packet.characterInfo.characterIndex].motion = packet.characterInfo.motion; - //TODO: refactor this -// characterMap[packet.characterInfo.characterIndex].ResetDirection(); + characterMap[packet.characterInfo.characterIndex].CorrectSprite(); //catch this client's player object if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) { diff --git a/common/gameplay/character_data.cpp b/common/gameplay/character_data.cpp new file mode 100644 index 0000000..e86706c --- /dev/null +++ b/common/gameplay/character_data.cpp @@ -0,0 +1,67 @@ +/* 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. +*/ +#include "character_data.hpp" + +void CharacterData::Update(double delta) { + if (motion.x && motion.y) { + position += motion * delta * CHARACTER_WALKING_MOD; + } + else if (motion != 0) { + position += motion * delta; + } +#ifdef GRAPHICS + sprite.Update(delta); +#endif +} + +#ifdef GRAPHICS + +void CharacterData::DrawTo(SDL_Surface* const dest, int camX, int camY) { + sprite.DrawTo(dest, position.x - camX, position.y - camY); +} + +void CharacterData::CorrectSprite() { + //NOTE: These must correspond to the sprite sheet in use + if (motion.y > 0) { + sprite.SetYIndex(0); + } + else if (motion.y < 0) { + sprite.SetYIndex(1); + } + else if (motion.x > 0) { + sprite.SetYIndex(3); + } + else if (motion.x < 0) { + sprite.SetYIndex(2); + } + + //animation + if (motion != 0) { + sprite.SetDelay(0.1); + } + else { + sprite.SetDelay(0); + sprite.SetXIndex(0); + } +} + +#endif \ No newline at end of file diff --git a/common/gameplay/character_data.hpp b/common/gameplay/character_data.hpp index 9c8602a..128fe16 100644 --- a/common/gameplay/character_data.hpp +++ b/common/gameplay/character_data.hpp @@ -59,6 +59,13 @@ struct CharacterData { //TODO: buffs //TODO: debuffs + //methods + void Update(double delta); +#ifdef GRAPHICS + void DrawTo(SDL_Surface* const, int camX, int camY); + void CorrectSprite(); +#endif + //active gameplay members //NOTE: these are lost when unloaded #ifdef GRAPHICS diff --git a/common/gameplay/makefile b/common/gameplay/makefile index 9013447..3be52be 100644 --- a/common/gameplay/makefile +++ b/common/gameplay/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. +INCLUDES+=. ../utilities ../graphics LIBS+= -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS #source CXXSRC=$(wildcard *.cpp) diff --git a/common/gameplay/sanity_check.cpp b/common/gameplay/sanity_check.cpp new file mode 100644 index 0000000..a7db44c --- /dev/null +++ b/common/gameplay/sanity_check.cpp @@ -0,0 +1,15 @@ +#include "account_data.hpp" +#include "character_data.hpp" +#include "client_data.hpp" +#include "combat_data.hpp" +#include "enemy_data.hpp" +#include "statistics.hpp" + +/* DOCS: Sanity check, read more + * Since most/all of the files in this directory are header files, I've created + * this source file as a "sanity check", to ensure that the above header files + * are written correctly via make. + * + * Oddly enough, I'm pretty sure this is the first directory compiled in a + * clean build. +*/ \ No newline at end of file From de7da8110271322a6b6527dfb41f4f1870f51154 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 28 May 2014 22:16:36 +1000 Subject: [PATCH 16/19] Solved a few items on the TODO list --- client/in_world.cpp | 56 +++++++++++++++---------- client/in_world.hpp | 4 +- client/lobby_menu.cpp | 4 +- rsc/scripts/setup_server.sql | 72 ++++++++++++--------------------- server/account_management.cpp | 8 ++-- server/character_management.cpp | 8 ++-- server/server_connections.cpp | 2 + 7 files changed, 74 insertions(+), 80 deletions(-) diff --git a/client/in_world.cpp b/client/in_world.cpp index ecddb90..6914681 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -73,16 +73,8 @@ InWorld::InWorld( //TODO: add the tilesheet to the map system? tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15); - //TODO: move this into it's own function //request a sync - SerialPacket packet; - char buffer[PACKET_STRING_SIZE]; - packet.meta.type = SerialPacket::Type::SYNCHRONIZE; - packet.clientInfo.clientIndex = clientIndex; - packet.clientInfo.accountIndex = accountIndex; - packet.clientInfo.characterIndex = characterIndex; - serialize(&packet, buffer); - network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); + RequestSynchronize(); //debug // RequestRegion(0, 0); @@ -114,7 +106,6 @@ void InWorld::Update(double delta) { for (auto& it : characterMap) { it.second.Update(delta); } - //TODO: sort the players and entities by Y position //update the camera if(localCharacter) { @@ -145,6 +136,7 @@ void InWorld::Render(SDL_Surface* const screen) { //draw characters for (auto& it : characterMap) { + //TODO: drawing order according to Y position it.second.DrawTo(screen, camera.x, camera.y); } @@ -316,20 +308,29 @@ void InWorld::HandleCharacterNew(SerialPacket packet) { throw(std::runtime_error("Cannot create duplicate characters")); } - //TODO: set the player's handle - //TODO: use a reference, don't use a lookup for every call - characterMap[packet.characterInfo.characterIndex].sprite.LoadSurface(config["dir.sprites"] + packet.characterInfo.avatar, 4, 4); - characterMap[packet.characterInfo.characterIndex].position = packet.characterInfo.position; - characterMap[packet.characterInfo.characterIndex].motion = packet.characterInfo.motion; - characterMap[packet.characterInfo.characterIndex].CorrectSprite(); + //create the character object + CharacterData& character = characterMap[packet.characterInfo.characterIndex]; + + //set the members + character.handle = packet.characterInfo.handle; + character.avatar = packet.characterInfo.avatar; + character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4); + character.mapIndex = packet.characterInfo.mapIndex; + character.position = packet.characterInfo.position; + character.motion = packet.characterInfo.motion; + character.stats = packet.characterInfo.stats; + + character.CorrectSprite(); //catch this client's player object if (packet.characterInfo.characterIndex == characterIndex && !localCharacter) { - localCharacter = &characterMap[characterIndex]; + localCharacter = &character; //setup the camera + //TODO: can't change the screen size camera.width = GetScreen()->w; camera.height = GetScreen()->h; + //center on the player's character camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite.GetImage()->GetClipW() / 2); camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite.GetImage()->GetClipH() / 2); @@ -337,21 +338,34 @@ void InWorld::HandleCharacterNew(SerialPacket packet) { } void InWorld::HandleCharacterDelete(SerialPacket packet) { - //TODO: authenticate when own character is being deleted - - characterMap.erase(packet.characterInfo.characterIndex); - + //TODO: authenticate when own character is being deleted (linked to a TODO in the server) //catch this client's player object if (packet.characterInfo.characterIndex == characterIndex) { characterIndex = -1; localCharacter = nullptr; } + + characterMap.erase(packet.characterInfo.characterIndex); } //------------------------- //Server control //------------------------- +void InWorld::RequestSynchronize() { + SerialPacket packet; + char buffer[PACKET_STRING_SIZE]; + + //request a sync + packet.meta.type = SerialPacket::Type::SYNCHRONIZE; + packet.clientInfo.clientIndex = clientIndex; + packet.clientInfo.accountIndex = accountIndex; + packet.clientInfo.characterIndex = characterIndex; + + serialize(&packet, buffer); + network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); +} + void InWorld::SendPlayerUpdate() { SerialPacket packet; char buffer[PACKET_BUFFER_SIZE]; diff --git a/client/in_world.hpp b/client/in_world.hpp index 60a96a8..2062d3e 100644 --- a/client/in_world.hpp +++ b/client/in_world.hpp @@ -90,6 +90,7 @@ protected: void HandleRegionContent(SerialPacket); //Server control + void RequestSynchronize(); void SendPlayerUpdate(); void RequestDisconnect(); void RequestShutDown(); @@ -111,7 +112,6 @@ protected: Image buttonImage; RasterFont font; TileSheet tileSheet; - //TODO: sprites //map RegionPager regionPager; @@ -119,7 +119,7 @@ protected: //UI Button disconnectButton; Button shutDownButton; - //TODO: Fix the camera + //TODO: Review the camera struct { int x = 0, y = 0; int width = 0, height = 0; diff --git a/client/lobby_menu.cpp b/client/lobby_menu.cpp index 8bd5671..cf7732d 100644 --- a/client/lobby_menu.cpp +++ b/client/lobby_menu.cpp @@ -100,8 +100,8 @@ void LobbyMenu::FrameEnd() { } void LobbyMenu::Render(SDL_Surface* const screen) { - //TODO: this needs rewriting //TODO: I need a proper UI system for the entire client and the editor + //UI search.DrawTo(screen); join.DrawTo(screen); @@ -127,7 +127,7 @@ void LobbyMenu::Render(SDL_Surface* const screen) { font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h); } - //ping? + //TODO: ping/delay? } } diff --git a/rsc/scripts/setup_server.sql b/rsc/scripts/setup_server.sql index d43c592..9ea5498 100644 --- a/rsc/scripts/setup_server.sql +++ b/rsc/scripts/setup_server.sql @@ -1,57 +1,18 @@ ---TODO: Rename the SQL's tables, for consistency -------------------------- ---Server -------------------------- - -CREATE TABLE IF NOT EXISTS UserAccounts ( +CREATE TABLE IF NOT EXISTS Accounts ( uid INTEGER PRIMARY KEY AUTOINCREMENT, username varchar(100) UNIQUE, --TODO: server-client security -- password varchar(100), blacklisted BIT DEFAULT 0, - whitelisted BIT DEFAULT 1 --- TODO: moderator + whitelisted BIT DEFAULT 1, + administrator BIT DEFAULT 0 ); -------------------------- ---Items -------------------------- - -CREATE TABLE IF NOT EXISTS MundaneItems ( - --metadata - uid INTEGER PRIMARY KEY AUTOINCREMENT, - itemID INTEGER, - stackSize INTEGER DEFAULT 0, - owner INTEGER REFERENCES PlayerCharacters(uid) -); - -CREATE TABLE IF NOT EXISTS Consumables ( - --metadata - uid INTEGER PRIMARY KEY AUTOINCREMENT, - itemID INTEGER, - stackSize INTEGER DEFAULT 0, - owner INTEGER REFERENCES PlayerCharacters(uid) - --holds all consumable items info (food, potions, etc.) -); - -CREATE TABLE IF NOT EXISTS Equipment ( - --metadata - uid INTEGER PRIMARY KEY AUTOINCREMENT, - itemID INTEGER, - owner INTEGER REFERENCES PlayerCharacters(uid) - --hold all equipment info - --stat mods, special effects, etc. -); - -------------------------- ---Players -------------------------- - -CREATE TABLE IF NOT EXISTS PlayerCharacters ( +CREATE TABLE IF NOT EXISTS Characters ( uid INTEGER PRIMARY KEY AUTOINCREMENT, --metadata - owner INTEGER REFERENCES UserAccounts(uid), + owner INTEGER REFERENCES Accounts(uid), handle varchar(100) UNIQUE, avatar varchar(100), birth timestamp NOT NULL DEFAULT (datetime()), @@ -78,8 +39,25 @@ CREATE TABLE IF NOT EXISTS PlayerCharacters ( luck REAL DEFAULT 0.0, --equipment - weapon INTEGER REFERENCES Equipment(uid), - helmet INTEGER REFERENCES Equipment(uid), - armour INTEGER REFERENCES Equipment(uid) + weapon INTEGER REFERENCES WornEquipment(uid), + helmet INTEGER REFERENCES WornEquipment(uid), + armour INTEGER REFERENCES WornEquipment(uid) --etc. ); + +CREATE TABLE IF NOT EXISTS InventoryItems ( + --metadata + uid INTEGER PRIMARY KEY AUTOINCREMENT, + itemID INTEGER, --type + stackSize INTEGER DEFAULT 0, + owner INTEGER REFERENCES Characters(uid) +); + +CREATE TABLE IF NOT EXISTS WornEquipment ( + --metadata + uid INTEGER PRIMARY KEY AUTOINCREMENT, + itemID INTEGER, --type + owner INTEGER REFERENCES Characters(uid) + --hold all equipment info + --stat mods, special effects, etc. +); \ No newline at end of file diff --git a/server/account_management.cpp b/server/account_management.cpp index 734244f..cca3630 100644 --- a/server/account_management.cpp +++ b/server/account_management.cpp @@ -29,10 +29,10 @@ //Define the queries //------------------------- -static const char* CREATE_USER_ACCOUNT = "INSERT INTO UserAccounts (username) VALUES (?);"; -static const char* LOAD_USER_ACCOUNT = "SELECT * FROM UserAccounts WHERE username = ?;"; -static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL UserAccounts SET blacklisted = ?2, whitelisted = ?3 WHERE uid = ?1;"; -static const char* DELETE_USER_ACCOUNT = "DELETE FROM UserAccounts WHERE uid = ?;"; +static const char* CREATE_USER_ACCOUNT = "INSERT INTO Accounts (username) VALUES (?);"; +static const char* LOAD_USER_ACCOUNT = "SELECT * FROM Accounts WHERE username = ?;"; +static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL Accounts SET blacklisted = ?2, whitelisted = ?3 WHERE uid = ?1;"; +static const char* DELETE_USER_ACCOUNT = "DELETE FROM Accounts WHERE uid = ?;"; //------------------------- //Define the methods diff --git a/server/character_management.cpp b/server/character_management.cpp index 3835448..fe7de3e 100644 --- a/server/character_management.cpp +++ b/server/character_management.cpp @@ -30,10 +30,10 @@ //------------------------- //TODO: save and load the statistics -static const char* CREATE_CHARACTER = "INSERT INTO PlayerCharacters (owner, handle, avatar) VALUES (?, ?, ?);"; -static const char* LOAD_CHARACTER = "SELECT * FROM PlayerCharacters WHERE handle = ?;"; -static const char* SAVE_CHARACTER = "UPDATE OR FAIL PlayerCharacters SET mapIndex = ?2, positionX = ?3, positionY = ?4 WHERE uid = ?1;"; -static const char* DELETE_CHARACTER = "DELETE FROM PlayerCharacters WHERE uid = ?;"; +static const char* CREATE_CHARACTER = "INSERT INTO Characters (owner, handle, avatar) VALUES (?, ?, ?);"; +static const char* LOAD_CHARACTER = "SELECT * FROM Characters WHERE handle = ?;"; +static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET mapIndex = ?2, positionX = ?3, positionY = ?4 WHERE uid = ?1;"; +static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;"; //------------------------- //Define the methods diff --git a/server/server_connections.cpp b/server/server_connections.cpp index 0027b6c..1e771c3 100644 --- a/server/server_connections.cpp +++ b/server/server_connections.cpp @@ -106,6 +106,8 @@ void ServerApplication::HandleSynchronize(SerialPacket packet) { newPacket.characterInfo.mapIndex = it.second.mapIndex; newPacket.characterInfo.position = it.second.position; newPacket.characterInfo.motion = it.second.motion; + newPacket.characterInfo.stats = it.second.stats; + serialize(&newPacket, buffer); network.Send(&clientMap[packet.clientInfo.clientIndex].address, buffer, PACKET_BUFFER_SIZE); } From 7b3bf24e5d7eb4df6b247836951cdae19510677d Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 28 May 2014 23:22:00 +1000 Subject: [PATCH 17/19] Refactored UDPNetworkUtility, and tied it to SerialPacket --- client/client_application.cpp | 2 +- client/in_combat.hpp | 2 - client/in_world.cpp | 27 ++-- client/in_world.hpp | 2 - client/lobby_menu.cpp | 22 +--- client/lobby_menu.hpp | 2 - common/network/serial_packet.hpp | 2 +- common/network/udp_network_utility.cpp | 164 ++++++++++++++++++------- common/network/udp_network_utility.hpp | 39 +++--- server/server_application.hpp | 2 - server/server_connections.cpp | 24 +--- server/server_internals.cpp | 10 +- 12 files changed, 166 insertions(+), 132 deletions(-) diff --git a/client/client_application.cpp b/client/client_application.cpp index cbf2f68..cb225c6 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -56,7 +56,7 @@ void ClientApplication::Init(int argc, char** argv) { if (SDLNet_Init()) { throw(std::runtime_error("Failed to initialize SDL_net")); } - network.Open(0, PACKET_BUFFER_SIZE); + network.Open(0); } void ClientApplication::Proc() { diff --git a/client/in_combat.hpp b/client/in_combat.hpp index 44e91ee..ebd34c7 100644 --- a/client/in_combat.hpp +++ b/client/in_combat.hpp @@ -24,8 +24,6 @@ //network #include "udp_network_utility.hpp" -#include "serial_packet.hpp" -#include "serial.hpp" //graphics #include "image.hpp" diff --git a/client/in_world.cpp b/client/in_world.cpp index 6914681..0caddff 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -96,9 +96,7 @@ void InWorld::Update(double delta) { SerialPacket packet; //suck in all waiting packets - while(network.Receive()) { - deserialize(&packet, network.GetInData()); - packet.meta.srcAddress = network.GetInPacket()->address; + while(network.Receive(&packet)) { HandlePacket(packet); } @@ -354,7 +352,6 @@ void InWorld::HandleCharacterDelete(SerialPacket packet) { void InWorld::RequestSynchronize() { SerialPacket packet; - char buffer[PACKET_STRING_SIZE]; //request a sync packet.meta.type = SerialPacket::Type::SYNCHRONIZE; @@ -362,13 +359,11 @@ void InWorld::RequestSynchronize() { packet.clientInfo.accountIndex = accountIndex; packet.clientInfo.characterIndex = characterIndex; - serialize(&packet, buffer); - network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); + network.SendTo(Channels::SERVER, &packet); } void InWorld::SendPlayerUpdate() { SerialPacket packet; - char buffer[PACKET_BUFFER_SIZE]; //pack the packet packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE; @@ -378,47 +373,43 @@ void InWorld::SendPlayerUpdate() { packet.characterInfo.position = localCharacter->position; packet.characterInfo.motion = localCharacter->motion; - serialize(&packet, buffer); - network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); + network.SendTo(Channels::SERVER, &packet); } void InWorld::RequestDisconnect() { SerialPacket packet; - char buffer[PACKET_BUFFER_SIZE]; //send a disconnect request packet.meta.type = SerialPacket::Type::DISCONNECT; packet.clientInfo.clientIndex = clientIndex; packet.clientInfo.accountIndex = accountIndex; packet.clientInfo.characterIndex = characterIndex; - serialize(&packet, buffer); - network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); + + network.SendTo(Channels::SERVER, &packet); } void InWorld::RequestShutDown() { SerialPacket packet; - char buffer[PACKET_BUFFER_SIZE]; //send a shutdown request packet.meta.type = SerialPacket::Type::SHUTDOWN; packet.clientInfo.clientIndex = clientIndex; packet.clientInfo.accountIndex = accountIndex; packet.clientInfo.characterIndex = characterIndex; - serialize(&packet, buffer); - network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); + + network.SendTo(Channels::SERVER, &packet); } void InWorld::RequestRegion(int mapIndex, int x, int y) { SerialPacket packet; - char buffer[PACKET_BUFFER_SIZE]; //pack the region's data packet.meta.type = SerialPacket::Type::REGION_REQUEST; packet.regionInfo.mapIndex = mapIndex; packet.regionInfo.x = x; packet.regionInfo.y = y; - serialize(&packet, buffer); - network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); + + network.SendTo(Channels::SERVER, &packet); } //------------------------- diff --git a/client/in_world.hpp b/client/in_world.hpp index 2062d3e..c245e75 100644 --- a/client/in_world.hpp +++ b/client/in_world.hpp @@ -29,8 +29,6 @@ //networking #include "udp_network_utility.hpp" -#include "serial_packet.hpp" -#include "serial.hpp" //graphics #include "image.hpp" diff --git a/client/lobby_menu.cpp b/client/lobby_menu.cpp index cf7732d..f411ba6 100644 --- a/client/lobby_menu.cpp +++ b/client/lobby_menu.cpp @@ -86,11 +86,9 @@ void LobbyMenu::FrameStart() { } void LobbyMenu::Update(double delta) { - //suck in all waiting packets + //suck in and process all waiting packets SerialPacket packet; - while(network.Receive()) { - deserialize(&packet, network.GetInData()); - packet.meta.srcAddress = network.GetInPacket()->address; + while(network.Receive(&packet)) { HandlePacket(packet); } } @@ -149,14 +147,10 @@ void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) { void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { if (search.MouseButtonUp(button) == Button::State::HOVER) { - //the vars - SerialPacket packet; - char buffer[PACKET_BUFFER_SIZE]; - //broadcast to the network, or a specific server + SerialPacket packet; packet.meta.type = SerialPacket::Type::BROADCAST_REQUEST; - serialize(&packet, buffer); - network.Send(config["server.host"].c_str(), config.Int("server.port"), buffer, PACKET_BUFFER_SIZE); + network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet); //reset the server list serverInfo.clear(); @@ -164,19 +158,15 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { } else if (join.MouseButtonUp(button) == Button::State::HOVER && selection != nullptr && selection->compatible) { - //the vars - SerialPacket packet; - char buffer[PACKET_BUFFER_SIZE]; - //pack the packet + SerialPacket packet; packet.meta.type = SerialPacket::Type::JOIN_REQUEST; strncpy(packet.clientInfo.username, config["client.username"].c_str(), PACKET_STRING_SIZE); strncpy(packet.clientInfo.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE); strncpy(packet.clientInfo.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE); //join the selected server - serialize(&packet, buffer); - network.Send(&selection->address, buffer, PACKET_BUFFER_SIZE); + network.SendTo(&selection->address, &packet); selection = nullptr; } diff --git a/client/lobby_menu.hpp b/client/lobby_menu.hpp index 9c858cb..02a20b9 100644 --- a/client/lobby_menu.hpp +++ b/client/lobby_menu.hpp @@ -30,8 +30,6 @@ //network #include "udp_network_utility.hpp" -#include "serial_packet.hpp" -#include "serial.hpp" //client #include "base_scene.hpp" diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index e97c711..8b648a8 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/network/udp_network_utility.cpp b/common/network/udp_network_utility.cpp index 5f828c7..5fb669e 100644 --- a/common/network/udp_network_utility.cpp +++ b/common/network/udp_network_utility.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 @@ -21,34 +21,33 @@ */ #include "udp_network_utility.hpp" +#include "serial.hpp" + #include -void UDPNetworkUtility::Open(int port, int packSize) { - if (!(socket = SDLNet_UDP_Open(port))) { - Close(); - throw(std::runtime_error("Failed to open a UDP socket")); - } +//DOCS: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network +//NOTE: don't confuse SerialPacket with UDPpacket - if (!(packOut = SDLNet_AllocPacket(packSize))) { +void UDPNetworkUtility::Open(int port) { + socket = SDLNet_UDP_Open(port); + packet = SDLNet_AllocPacket(PACKET_BUFFER_SIZE); + if (!socket || !packet) { Close(); - throw(std::runtime_error("Failed to allocate the out packet")); - } - - if (!(packIn = SDLNet_AllocPacket(packSize))) { - Close(); - throw(std::runtime_error("Failed to allocate the in packet")); + throw(std::runtime_error("Failed to open UDPNetworkUtility")); } } void UDPNetworkUtility::Close() { SDLNet_UDP_Close(socket); - SDLNet_FreePacket(packOut); - SDLNet_FreePacket(packIn); + SDLNet_FreePacket(packet); socket = nullptr; - packOut = nullptr; - packIn = nullptr; + packet = nullptr; } +//------------------------- +//bind to a channel +//------------------------- + int UDPNetworkUtility::Bind(const char* ip, int port, int channel) { IPaddress add; if (SDLNet_ResolveHost(&add, ip, port) == -1) { @@ -61,7 +60,7 @@ int UDPNetworkUtility::Bind(const char* ip, int port, int channel) { int UDPNetworkUtility::Bind(IPaddress* add, int channel) { int ret = SDLNet_UDP_Bind(socket, channel, add); - if (ret == -1) { + if (ret < 0) { throw(std::runtime_error("Failed to bind to a channel")); } @@ -72,25 +71,29 @@ void UDPNetworkUtility::Unbind(int channel) { SDLNet_UDP_Unbind(socket, channel); } -int UDPNetworkUtility::Send(const char* ip, int port, void* data, int len) { +//------------------------- +//send a buffer +//------------------------- + +int UDPNetworkUtility::SendTo(const char* ip, int port, void* data, int len) { IPaddress add; if (SDLNet_ResolveHost(&add, ip, port) == -1) { throw(std::runtime_error("Failed to resolve a host")); } - Send(&add, data, len); + SendTo(&add, data, len); } -int UDPNetworkUtility::Send(IPaddress* add, void* data, int len) { - if (len > packOut->maxlen) { - throw(std::runtime_error("Failed to copy the data into the packet")); +int UDPNetworkUtility::SendTo(IPaddress* add, void* data, int len) { + if (len > packet->maxlen) { + throw(std::runtime_error("The buffer is to large for the UDPpacket")); } - memset(packOut->data, 0, packOut->maxlen); - memcpy(packOut->data, data, len); - packOut->len = len; - packOut->address = *add; + memset(packet->data, 0, packet->maxlen); + memcpy(packet->data, data, len); + packet->len = len; + packet->address = *add; - int ret = SDLNet_UDP_Send(socket, -1, packOut); + int ret = SDLNet_UDP_Send(socket, -1, packet); if (ret <= 0) { throw(std::runtime_error("Failed to send a packet")); @@ -99,15 +102,15 @@ int UDPNetworkUtility::Send(IPaddress* add, void* data, int len) { return ret; } -int UDPNetworkUtility::Send(int channel, void* data, int len) { - if (len > packOut->maxlen) { - throw(std::runtime_error("Failed to copy the data into the packet")); +int UDPNetworkUtility::SendTo(int channel, void* data, int len) { + if (len > packet->maxlen) { + throw(std::runtime_error("The buffer is to large for the UDPpacket")); } - memset(packOut->data, 0, packOut->maxlen); - memcpy(packOut->data, data, len); - packOut->len = len; + memset(packet->data, 0, packet->maxlen); + memcpy(packet->data, data, len); + packet->len = len; - int ret = SDLNet_UDP_Send(socket, channel, packOut); + int ret = SDLNet_UDP_Send(socket, channel, packet); if (ret <= 0) { throw(std::runtime_error("Failed to send a packet")); @@ -116,29 +119,30 @@ int UDPNetworkUtility::Send(int channel, void* data, int len) { return ret; } -int UDPNetworkUtility::SendAll(void* data, int len) { - if (len > packOut->maxlen) { - throw(std::runtime_error("Failed to copy the data into the packet")); +int UDPNetworkUtility::SendToAllChannels(void* data, int len) { + if (len > packet->maxlen) { + throw(std::runtime_error("The buffer is to large for the UDPpacket")); } - memset(packOut->data, 0, packOut->maxlen); - memcpy(packOut->data, data, len); - packOut->len = len; + memset(packet->data, 0, packet->maxlen); + memcpy(packet->data, data, len); + packet->len = len; int sent = 0; //send to all bound channels for (int i = 0; i < SDLNET_MAX_UDPCHANNELS; i++) { if (SDLNet_UDP_GetPeerAddress(socket, i)) { - sent += SDLNet_UDP_Send(socket, i, packOut); + sent += SDLNet_UDP_Send(socket, i, packet); } } return sent; } +//TODO: put a void* and int* parameter list here int UDPNetworkUtility::Receive() { - memset(packIn->data, 0, packIn->maxlen); - int ret = SDLNet_UDP_Recv(socket, packIn); + memset(packet->data, 0, packet->maxlen); + int ret = SDLNet_UDP_Recv(socket, packet); if (ret < 0) { throw(std::runtime_error("Unknown network error occured")); @@ -146,3 +150,75 @@ int UDPNetworkUtility::Receive() { return ret; } + +//------------------------- +//send a SerialPacket +//------------------------- + +int UDPNetworkUtility::SendTo(const char* ip, int port, SerialPacket* serialPacket) { + IPaddress add; + if (SDLNet_ResolveHost(&add, ip, port) == -1) { + throw(std::runtime_error("Failed to resolve a host")); + } + + SendTo(&add, serialPacket); +} + +int UDPNetworkUtility::SendTo(IPaddress* add, SerialPacket* serialPacket) { + memset(packet->data, 0, packet->maxlen); + serialize(serialPacket, packet->data); + packet->len = PACKET_BUFFER_SIZE; + packet->address = *add; + + int ret = SDLNet_UDP_Send(socket, -1, packet); + + if (ret <= 0) { + throw(std::runtime_error("Failed to send a packet")); + } + + return ret; +} + +int UDPNetworkUtility::SendTo(int channel, SerialPacket* serialPacket) { + memset(packet->data, 0, packet->maxlen); + serialize(serialPacket, packet->data); + packet->len = PACKET_BUFFER_SIZE; + + int ret = SDLNet_UDP_Send(socket, channel, packet); + + if (ret <= 0) { + throw(std::runtime_error("Failed to send a packet")); + } + + return ret; +} + +int UDPNetworkUtility::SendToAllChannels(SerialPacket* serialPacket) { + memset(packet->data, 0, packet->maxlen); + serialize(serialPacket, packet->data); + packet->len = PACKET_BUFFER_SIZE; + + int sent = 0; + + //send to all bound channels + for (int i = 0; i < SDLNET_MAX_UDPCHANNELS; i++) { + if (SDLNet_UDP_GetPeerAddress(socket, i)) { + sent += SDLNet_UDP_Send(socket, i, packet); + } + } + + return sent; +} + +int UDPNetworkUtility::Receive(SerialPacket* serialPacket) { + memset(packet->data, 0, packet->maxlen); + int ret = SDLNet_UDP_Recv(socket, packet); + deserialize(serialPacket, packet->data); + serialPacket->meta.srcAddress = packet->address; + + if (ret < 0) { + throw(std::runtime_error("Unknown network error occured")); + } + + return ret; +} \ No newline at end of file diff --git a/common/network/udp_network_utility.hpp b/common/network/udp_network_utility.hpp index 9ba7842..4ebdd98 100644 --- a/common/network/udp_network_utility.hpp +++ b/common/network/udp_network_utility.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 @@ -24,12 +24,14 @@ #include "SDL/SDL_net.h" +#include "serial_packet.hpp" + class UDPNetworkUtility { public: UDPNetworkUtility() = default; ~UDPNetworkUtility() = default; - void Open(int port, int packSize); + void Open(int port); void Close(); //bind to a channel @@ -41,31 +43,30 @@ public: return SDLNet_UDP_GetPeerAddress(socket, channel); } - int Send(const char* ip, int port, void* data, int len); - int Send(IPaddress* add, void* data, int len); - int Send(int channel, void* data, int len); - int SendAll(void* data, int len); + //send a buffer + int SendTo(const char* ip, int port, void* data, int len); + int SendTo(IPaddress* add, void* data, int len); + int SendTo(int channel, void* data, int len); + int SendToAllChannels(void* data, int len); int Receive(); - void* GetOutData() const { - return reinterpret_cast(packOut->data); - }; - void* GetInData() const { - return reinterpret_cast(packIn->data); - }; - UDPpacket* GetOutPacket() const { - return packOut; - } - UDPpacket* GetInPacket() const { - return packIn; + //send a SerialPacket + int SendTo(const char* ip, int port, SerialPacket* serialPacket); + int SendTo(IPaddress* add, SerialPacket* serialPacket); + int SendTo(int channel, SerialPacket* serialPacket); + int SendToAllChannels(SerialPacket* serialPacket); + int Receive(SerialPacket* serialPacket); + + //accessors + UDPpacket* GetPacket() const { + return packet; } UDPsocket GetSocket() const { return socket; } private: UDPsocket socket = nullptr; - UDPpacket* packOut = nullptr; - UDPpacket* packIn = nullptr; + UDPpacket* packet = nullptr; }; #endif diff --git a/server/server_application.hpp b/server/server_application.hpp index 0437e1b..cbc7511 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -35,9 +35,7 @@ #include "region_pager.hpp" //networking -#include "serial_packet.hpp" #include "udp_network_utility.hpp" -#include "serial.hpp" //common #include "config_utility.hpp" diff --git a/server/server_connections.cpp b/server/server_connections.cpp index 1e771c3..11e99ce 100644 --- a/server/server_connections.cpp +++ b/server/server_connections.cpp @@ -36,9 +36,7 @@ void ServerApplication::HandleBroadcastRequest(SerialPacket packet) { packet.serverInfo.playerCount = characterMap.size(); //bounce this packet - char buffer[PACKET_BUFFER_SIZE]; - serialize(&packet, buffer); - network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE); + network.SendTo(&packet.meta.srcAddress, &packet); } void ServerApplication::HandleJoinRequest(SerialPacket packet) { @@ -70,9 +68,7 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) { packet.clientInfo.characterIndex = characterIndex; //bounce this packet - char buffer[PACKET_BUFFER_SIZE]; - serialize(&packet, buffer); - network.Send(&newClient.address, buffer, PACKET_BUFFER_SIZE); + network.SendTo(&newClient.address, &packet); //send the new character to all clients packet.meta.type = SerialPacket::Type::CHARACTER_NEW; @@ -94,7 +90,6 @@ void ServerApplication::HandleSynchronize(SerialPacket packet) { //send all the server's data to this client SerialPacket newPacket; - char buffer[PACKET_BUFFER_SIZE]; //characters newPacket.meta.type = SerialPacket::Type::CHARACTER_UPDATE; @@ -108,8 +103,7 @@ void ServerApplication::HandleSynchronize(SerialPacket packet) { newPacket.characterInfo.motion = it.second.motion; newPacket.characterInfo.stats = it.second.stats; - serialize(&newPacket, buffer); - network.Send(&clientMap[packet.clientInfo.clientIndex].address, buffer, PACKET_BUFFER_SIZE); + network.SendTo(&clientMap[packet.clientInfo.clientIndex].address, &newPacket); } } @@ -117,9 +111,7 @@ void ServerApplication::HandleDisconnect(SerialPacket packet) { //TODO: authenticate who is disconnecting/kicking //forward to the specified client - char buffer[PACKET_BUFFER_SIZE]; - serialize(&packet, buffer); - network.Send(&clientMap[accountMap[packet.clientInfo.accountIndex].clientIndex].address, buffer, PACKET_BUFFER_SIZE); + network.SendTo(&clientMap[accountMap[packet.clientInfo.accountIndex].clientIndex].address, &packet); //unload client and server-side characters for (std::map::iterator it = characterMap.begin(); it != characterMap.end(); /* EMPTY */ ) { @@ -175,17 +167,13 @@ void ServerApplication::HandleRegionRequest(SerialPacket packet) { packet.regionInfo.region = regionPager.GetRegion(packet.regionInfo.x, packet.regionInfo.y); //send the content - char buffer[PACKET_BUFFER_SIZE]; - serialize(&packet, buffer); - network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE); + network.SendTo(&packet.meta.srcAddress, &packet); } void ServerApplication::PumpPacket(SerialPacket packet) { //NOTE: I don't really like this, but it'll do for now - char buffer[PACKET_BUFFER_SIZE]; - serialize(&packet, buffer); for (auto& it : clientMap) { - network.Send(&it.second.address, buffer, PACKET_BUFFER_SIZE); + network.SendTo(&it.second.address, &packet); } } diff --git a/server/server_internals.cpp b/server/server_internals.cpp index d75c9c3..1cfeb4c 100644 --- a/server/server_internals.cpp +++ b/server/server_internals.cpp @@ -22,6 +22,7 @@ #include "server_application.hpp" #include "sql_utility.hpp" +#include "serial.hpp" #include #include @@ -52,7 +53,7 @@ void ServerApplication::Init(int argc, char** argv) { if (SDLNet_Init()) { throw(std::runtime_error("Failed to initialize SDL_net")); } - network.Open(config.Int("server.port"), PACKET_BUFFER_SIZE); + network.Open(config.Int("server.port")); std::cout << "Initialized SDL_net" << std::endl; //Init SQL @@ -119,12 +120,7 @@ void ServerApplication::Proc() { SerialPacket packet; while(running) { //suck in the waiting packets & process them - while(network.Receive()) { - //get the packet - deserialize(&packet, network.GetInData()); - //cache the source address - packet.meta.srcAddress = network.GetInPacket()->address; - //we need to go deeper + while(network.Receive(&packet)) { HandlePacket(packet); } //update the internals From de902d2d3d49072ffa42e696858ab12c65a4bec3 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 28 May 2014 23:39:31 +1000 Subject: [PATCH 18/19] Bumped the network version --- client/in_world.cpp | 2 +- common/network/serial_packet.hpp | 65 +++++++++++++++----------------- todo.txt | 3 -- 3 files changed, 32 insertions(+), 38 deletions(-) diff --git a/client/in_world.cpp b/client/in_world.cpp index 0caddff..f0348bd 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -325,7 +325,7 @@ void InWorld::HandleCharacterNew(SerialPacket packet) { localCharacter = &character; //setup the camera - //TODO: can't change the screen size + //TODO: can't change the screen size? camera.width = GetScreen()->w; camera.height = GetScreen()->h; diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index 8b648a8..27de13b 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -28,73 +28,70 @@ #include "SDL/SDL_net.h" -#define NETWORK_VERSION 20140526 - -//maximum string size; don't use std::string +#define NETWORK_VERSION 20140528 #define PACKET_STRING_SIZE 100 union SerialPacket { //types of packets - //TODO: read the value definitions enum class Type { //default: there is something wrong NONE = 0, //keep alive - PING, - PONG, + PING = 1, + PONG = 2, //searching for a server to join - BROADCAST_REQUEST, - BROADCAST_RESPONSE, - BROADCAST_REJECTION, + BROADCAST_REQUEST = 3, + BROADCAST_RESPONSE = 4, + BROADCAST_REJECTION = 5, //try to join the server - JOIN_REQUEST, - JOIN_RESPONSE, - JOIN_REJECTION, + JOIN_REQUEST = 6, + JOIN_RESPONSE = 7, + JOIN_REJECTION = 8, //mass update - SYNCHRONIZE, + SYNCHRONIZE = 9, //disconnect from the server - DISCONNECT, + DISCONNECT = 10, //shut down the server - SHUTDOWN, + SHUTDOWN = 11, //map data - REGION_REQUEST, - REGION_CONTENT, - REGION_REJECTION, + REGION_REQUEST = 12, + REGION_CONTENT = 13, + REGION_REJECTION = 14, //combat data - COMBAT_ENTER, - COMBAT_EXIT, + COMBAT_ENTER = 15, + COMBAT_EXIT = 16, - COMBAT_UPDATE, + COMBAT_UPDATE = 17, - COMBAT_REJECTION, + COMBAT_REJECTION = 18, //character data - CHARACTER_NEW, - CHARACTER_DELETE, - CHARACTER_UPDATE, + CHARACTER_NEW = 19, + CHARACTER_DELETE = 20, + CHARACTER_UPDATE = 21, - CHARACTER_STATS_REQUEST, - CHARACTER_STATS_RESPONSE, + CHARACTER_STATS_REQUEST = 22, + CHARACTER_STATS_RESPONSE = 23, - CHARACTER_REJECTION, + CHARACTER_REJECTION = 24, //enemy data - ENEMY_NEW, - ENEMY_DELETE, - ENEMY_UPDATE, + ENEMY_NEW = 25, + ENEMY_DELETE = 26, + ENEMY_UPDATE = 27, - ENEMY_STATS_REQUEST, - ENEMY_STATS_RESPONSE, + ENEMY_STATS_REQUEST = 28, + ENEMY_STATS_RESPONSE = 29, - ENEMY_REJECTION, + ENEMY_REJECTION = 30, //more packet types go here diff --git a/todo.txt b/todo.txt index 61ceec5..f03386a 100644 --- a/todo.txt +++ b/todo.txt @@ -1,10 +1,7 @@ TODO: I need to keep the documentation up to date. Namely, the GDD is getting out of date. -TODO: How many lookups is the map system using? -TODO: Hook the serial packet to the network utility TODO: I completely forgot about status ailments TODO: Time delay for requesting region packets TODO: command line parameters overriding config.cfg settings -TODO: inplementing SerialPacket in NetworkUtility --Battle System-- From bf922ec5985c031a5b73b6140579a6625ea18b7b Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 29 May 2014 00:16:49 +1000 Subject: [PATCH 19/19] Updated the license headers It only took me 5 months. --- client/base_scene.cpp | 2 +- client/base_scene.hpp | 2 +- client/channels.hpp | 21 +++++++++++++++++++++ client/client_application.cpp | 2 +- client/in_combat.cpp | 2 +- client/in_combat.hpp | 2 +- client/in_world.cpp | 2 +- client/in_world.hpp | 2 +- client/lobby_menu.cpp | 2 +- client/lobby_menu.hpp | 2 +- client/main.cpp | 2 +- client/main_menu.cpp | 2 +- client/main_menu.hpp | 2 +- client/options_menu.cpp | 2 +- client/options_menu.hpp | 2 +- client/scene_list.hpp | 2 +- client/splash_screen.cpp | 2 +- client/splash_screen.hpp | 2 +- common/gameplay/sanity_check.cpp | 21 +++++++++++++++++++++ common/graphics/image.cpp | 2 +- common/graphics/image.hpp | 2 +- common/graphics/sprite_sheet.cpp | 2 +- common/graphics/sprite_sheet.hpp | 2 +- common/ui/button.cpp | 2 +- common/ui/button.hpp | 2 +- common/ui/menu_bar.cpp | 2 +- common/ui/menu_bar.hpp | 2 +- common/ui/raster_font.cpp | 2 +- common/ui/raster_font.hpp | 2 +- common/utilities/config_utility.cpp | 2 +- common/utilities/config_utility.hpp | 2 +- common/utilities/utility.cpp | 2 +- common/utilities/utility.hpp | 2 +- common/utilities/vector2.hpp | 2 +- server/main.cpp | 2 +- 35 files changed, 75 insertions(+), 33 deletions(-) diff --git a/client/base_scene.cpp b/client/base_scene.cpp index 19753a0..48512ec 100644 --- a/client/base_scene.cpp +++ b/client/base_scene.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/base_scene.hpp b/client/base_scene.hpp index 44dfab8..a4bfd88 100644 --- a/client/base_scene.hpp +++ b/client/base_scene.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/channels.hpp b/client/channels.hpp index 92695cd..2fe04a7 100644 --- a/client/channels.hpp +++ b/client/channels.hpp @@ -1,3 +1,24 @@ +/* Copyright: (c) Kayne Ruse 2013, 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 CHANNELS_HPP_ #define CHANNELS_HPP_ diff --git a/client/client_application.cpp b/client/client_application.cpp index cb225c6..ebc9f18 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/in_combat.cpp b/client/in_combat.cpp index 85afe25..f20f765 100644 --- a/client/in_combat.cpp +++ b/client/in_combat.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/in_combat.hpp b/client/in_combat.hpp index ebd34c7..15df345 100644 --- a/client/in_combat.hpp +++ b/client/in_combat.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/in_world.cpp b/client/in_world.cpp index f0348bd..9822a2a 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/in_world.hpp b/client/in_world.hpp index c245e75..038d22c 100644 --- a/client/in_world.hpp +++ b/client/in_world.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/lobby_menu.cpp b/client/lobby_menu.cpp index f411ba6..fa1925e 100644 --- a/client/lobby_menu.cpp +++ b/client/lobby_menu.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/lobby_menu.hpp b/client/lobby_menu.hpp index 02a20b9..2360705 100644 --- a/client/lobby_menu.hpp +++ b/client/lobby_menu.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/main.cpp b/client/main.cpp index 18adf3f..9ec652c 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/main_menu.cpp b/client/main_menu.cpp index d5b2064..b5d633e 100644 --- a/client/main_menu.cpp +++ b/client/main_menu.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/main_menu.hpp b/client/main_menu.hpp index 9c06a0d..3816482 100644 --- a/client/main_menu.hpp +++ b/client/main_menu.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/options_menu.cpp b/client/options_menu.cpp index 414d94c..bc8290c 100644 --- a/client/options_menu.cpp +++ b/client/options_menu.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/options_menu.hpp b/client/options_menu.hpp index bc05e1f..94008d3 100644 --- a/client/options_menu.hpp +++ b/client/options_menu.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/scene_list.hpp b/client/scene_list.hpp index 2953289..a124237 100644 --- a/client/scene_list.hpp +++ b/client/scene_list.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/splash_screen.cpp b/client/splash_screen.cpp index dd9697b..a363a2c 100644 --- a/client/splash_screen.cpp +++ b/client/splash_screen.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/client/splash_screen.hpp b/client/splash_screen.hpp index f24a1c6..2b2000b 100644 --- a/client/splash_screen.hpp +++ b/client/splash_screen.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/gameplay/sanity_check.cpp b/common/gameplay/sanity_check.cpp index a7db44c..529cd0f 100644 --- a/common/gameplay/sanity_check.cpp +++ b/common/gameplay/sanity_check.cpp @@ -1,3 +1,24 @@ +/* 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. +*/ #include "account_data.hpp" #include "character_data.hpp" #include "client_data.hpp" diff --git a/common/graphics/image.cpp b/common/graphics/image.cpp index 474b76d..3b4f99b 100644 --- a/common/graphics/image.cpp +++ b/common/graphics/image.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/graphics/image.hpp b/common/graphics/image.hpp index eb684bb..462e565 100644 --- a/common/graphics/image.hpp +++ b/common/graphics/image.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/graphics/sprite_sheet.cpp b/common/graphics/sprite_sheet.cpp index 39a669c..7726484 100644 --- a/common/graphics/sprite_sheet.cpp +++ b/common/graphics/sprite_sheet.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/graphics/sprite_sheet.hpp b/common/graphics/sprite_sheet.hpp index a82148b..8ecaa5b 100644 --- a/common/graphics/sprite_sheet.hpp +++ b/common/graphics/sprite_sheet.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/ui/button.cpp b/common/ui/button.cpp index 8d7eff9..59b0ae2 100644 --- a/common/ui/button.cpp +++ b/common/ui/button.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/ui/button.hpp b/common/ui/button.hpp index ae69ec1..2fe2faa 100644 --- a/common/ui/button.hpp +++ b/common/ui/button.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/ui/menu_bar.cpp b/common/ui/menu_bar.cpp index a6af861..2670e32 100644 --- a/common/ui/menu_bar.cpp +++ b/common/ui/menu_bar.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/ui/menu_bar.hpp b/common/ui/menu_bar.hpp index 81fbe4a..fdaf45c 100644 --- a/common/ui/menu_bar.hpp +++ b/common/ui/menu_bar.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/ui/raster_font.cpp b/common/ui/raster_font.cpp index bde074d..5005f7f 100644 --- a/common/ui/raster_font.cpp +++ b/common/ui/raster_font.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/ui/raster_font.hpp b/common/ui/raster_font.hpp index 0c4cb77..c3c1ddd 100644 --- a/common/ui/raster_font.hpp +++ b/common/ui/raster_font.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/utilities/config_utility.cpp b/common/utilities/config_utility.cpp index a66c730..02970b1 100644 --- a/common/utilities/config_utility.cpp +++ b/common/utilities/config_utility.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/utilities/config_utility.hpp b/common/utilities/config_utility.hpp index 3de540f..6e944ef 100644 --- a/common/utilities/config_utility.hpp +++ b/common/utilities/config_utility.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/utilities/utility.cpp b/common/utilities/utility.cpp index 38c79ef..75871b4 100644 --- a/common/utilities/utility.cpp +++ b/common/utilities/utility.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/utilities/utility.hpp b/common/utilities/utility.hpp index 7e380b7..aea01ef 100644 --- a/common/utilities/utility.hpp +++ b/common/utilities/utility.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/common/utilities/vector2.hpp b/common/utilities/vector2.hpp index c898c02..a165018 100644 --- a/common/utilities/vector2.hpp +++ b/common/utilities/vector2.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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 diff --git a/server/main.cpp b/server/main.cpp index 4da6edf..288e10f 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 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