From 8c9d071c7a554579b0204b829a7057a76f88f589 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 1 Jul 2014 01:03:03 +1000 Subject: [PATCH 01/10] Minor tweaks --- client/in_combat.hpp | 2 -- client/in_world.cpp | 20 ++++++++++++++++---- common/gameplay/character_data.hpp | 6 +++++- server/server_application.cpp | 29 +++++++++++++++++++---------- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/client/in_combat.hpp b/client/in_combat.hpp index d345037..6b31bc6 100644 --- a/client/in_combat.hpp +++ b/client/in_combat.hpp @@ -75,14 +75,12 @@ protected: //Network handlers void HandlePacket(SerialPacket* const); void HandleDisconnect(SerialPacket* const); - //TODO: more network handlers //Server control void RequestSynchronize(); void SendPlayerUpdate(); void RequestDisconnect(); void RequestShutdown(); - //TODO: more //shared parameters ConfigUtility& config; diff --git a/client/in_world.cpp b/client/in_world.cpp index 4557a9b..5301aa8 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -24,9 +24,10 @@ #include "channels.hpp" #include "utility.hpp" +#include #include #include -#include +#include //------------------------- //Public access members @@ -106,6 +107,8 @@ void InWorld::Update(double delta) { it.second.Update(delta); } + //TODO: Check collisions here + //update the camera if(localCharacter) { camera.x = localCharacter->origin.x - camera.marginX; @@ -288,15 +291,20 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) { //create the character object CharacterData& character = characterMap[argPacket->characterIndex]; - //set the members + //fill out the character's members character.handle = argPacket->handle; character.avatar = argPacket->avatar; + character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4); + character.bounds = {CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}; + character.roomIndex = argPacket->roomIndex; character.origin = argPacket->origin; character.motion = argPacket->motion; + character.stats = argPacket->stats; + //bookkeeping code character.CorrectSprite(); //catch this client's player object @@ -316,6 +324,7 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) { void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { //TODO: authenticate when own character is being deleted (linked to a TODO in the server) + //catch this client's player object if (argPacket->characterIndex == characterIndex) { characterIndex = -1; @@ -327,6 +336,7 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) { void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) { if (characterMap.find(argPacket->characterIndex) == characterMap.end()) { + std::cout << "Warning: HandleCharacterUpdate() is passing to HandleCharacterNew()" << std::endl; HandleCharacterNew(argPacket); return; } @@ -364,6 +374,8 @@ void InWorld::RequestSynchronize() { newPacket.clientIndex = clientIndex; newPacket.accountIndex = accountIndex; + //TODO: location, range for sync request + network.SendTo(Channels::SERVER, &newPacket); } @@ -374,7 +386,7 @@ void InWorld::SendPlayerUpdate() { newPacket.type = SerialPacketType::CHARACTER_UPDATE; newPacket.characterIndex = characterIndex; - //handle, avatar + //NOTE: omitting the handle and avatar here newPacket.accountIndex = accountIndex; newPacket.roomIndex = localCharacter->roomIndex; newPacket.origin = localCharacter->origin; @@ -435,7 +447,7 @@ void InWorld::UpdateMap() { //prune distant regions for (std::list::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) { - //check if the region is outside off this area + //check if the region is outside of this area if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) { //clunky, but the alternative was time consuming diff --git a/common/gameplay/character_data.hpp b/common/gameplay/character_data.hpp index 46452b4..fd9f553 100644 --- a/common/gameplay/character_data.hpp +++ b/common/gameplay/character_data.hpp @@ -38,6 +38,10 @@ constexpr double CHARACTER_WALKING_SPEED = 140.0; constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); +//the bounding boxes for the characters +constexpr double CHARACTER_BOUNDS_WIDTH = 32.0; +constexpr double CHARACTER_BOUNDS_HEIGHT = 32.0; + struct CharacterData { //metadata int owner; @@ -48,7 +52,6 @@ struct CharacterData { int roomIndex = 0; Vector2 origin = {0.0,0.0}; Vector2 motion = {0.0,0.0}; - Vector2 bounds = {0.0,0.0}; //base statistics Statistics stats; @@ -65,6 +68,7 @@ struct CharacterData { //active gameplay members //NOTE: these are lost when unloaded #ifdef GRAPHICS + Vector2 bounds = {0.0,0.0}; SpriteSheet sprite; #endif bool inCombat = false; diff --git a/server/server_application.cpp b/server/server_application.cpp index d9d763e..901706f 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -141,7 +141,8 @@ void ServerApplication::Proc() { HandlePacket(packetBuffer); } //update the internals - //TODO: update the internals i.e. player positions + //BUG: #30 Update the internals i.e. player positions + //give the computer a break SDL_Delay(10); } @@ -269,6 +270,16 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) { void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { //TODO: authenticate who is disconnecting/kicking + /*Pseudocode: + if sender's account index -> client index -> address == sender's address then + continue + end + if sender's account index -> admin == true OR sender's account index -> mod == true then + continue + end + if neither of the above is true, then output a warning to the console, and return + */ + //forward to the specified client network.SendTo( @@ -296,6 +307,12 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) { void ServerApplication::HandleShutdown(SerialPacket* const argPacket) { //TODO: authenticate who is shutting the server down + /*Pseudocode: + if sender's account -> admin is not true then + print a warning + return + end + */ //end the server running = false; @@ -399,15 +416,7 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) return; } - /* TODO: rewrite this design flaw, read more - * Slaving the client to the server here is a terrible idea, instead there - * needs to be a utility function to update and send the server-side character - * to the clients. - * - * Other things to consider include functionality to reequip the character, - * apply status effects and to change the stats as well. These should all be - * handled server-side. - */ + //accept client-side logic character->roomIndex = argPacket->roomIndex; character->origin = argPacket->origin; character->motion = argPacket->motion; From 8df1ecd8044d7724ee31b8be91572b3e3ff43513 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 1 Jul 2014 22:04:45 +1000 Subject: [PATCH 02/10] This hack for the collision map was a terrible idea I'm committing these changes before undoing these, and coding it properly. --- common/map/region.cpp | 4 ++-- common/map/region.hpp | 6 +++--- common/map/region_api.cpp | 1 + common/network/packet/serial_packet_base.hpp | 2 +- common/network/serial/serial.hpp | 21 +++++++++++++++----- common/network/serial/serial_region.cpp | 4 ++++ rsc/scripts/setup_server.lua | 10 +++++----- server/server_application.cpp | 18 ++++++++++++----- 8 files changed, 45 insertions(+), 21 deletions(-) diff --git a/common/map/region.cpp b/common/map/region.cpp index 8de957b..7fbe38c 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -30,11 +30,11 @@ Region::Region(int argX, int argY): x(argX), y(argY) { if (x != snapToBase(REGION_WIDTH, x) || y != snapToBase(REGION_HEIGHT, y)) { throw(std::invalid_argument("Region location is off grid")); } - memset(tiles, 0, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t)); + memset(tiles, 0, REGION_WIDTH*REGION_HEIGHT*(REGION_DEPTH+1)*sizeof(type_t)); } Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) { - memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t)); + memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*(REGION_DEPTH+1)*sizeof(type_t)); } Region::type_t Region::SetTile(int x, int y, int z, type_t v) { diff --git a/common/map/region.hpp b/common/map/region.hpp index 74fc013..7b578fa 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -22,8 +22,8 @@ #ifndef REGION_HPP_ #define REGION_HPP_ -constexpr int REGION_WIDTH = 20; -constexpr int REGION_HEIGHT = 20; +constexpr int REGION_WIDTH = 21; +constexpr int REGION_HEIGHT = 21; constexpr int REGION_DEPTH = 3; class Region { @@ -45,7 +45,7 @@ private: const int x; const int y; - type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH]; + type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH+1]; }; #endif diff --git a/common/map/region_api.cpp b/common/map/region_api.cpp index fdff4f7..ead6ef2 100644 --- a/common/map/region_api.cpp +++ b/common/map/region_api.cpp @@ -85,6 +85,7 @@ static int onUnload(lua_State* L) { return 0; } +//TODO: wrappers for the collision map static const luaL_Reg regionLib[] = { {"SetTile",setTile}, {"GetTile",getTile}, diff --git a/common/network/packet/serial_packet_base.hpp b/common/network/packet/serial_packet_base.hpp index 156d1e5..2f82092 100644 --- a/common/network/packet/serial_packet_base.hpp +++ b/common/network/packet/serial_packet_base.hpp @@ -30,7 +30,7 @@ #include "SDL/SDL_net.h" -constexpr int NETWORK_VERSION = 20140607; +constexpr int NETWORK_VERSION = 20140701; constexpr int PACKET_STRING_SIZE = 100; struct SerialPacketBase { diff --git a/common/network/serial/serial.hpp b/common/network/serial/serial.hpp index 02d5dba..f69743a 100644 --- a/common/network/serial/serial.hpp +++ b/common/network/serial/serial.hpp @@ -27,6 +27,8 @@ #include "region.hpp" #include "statistics.hpp" +#include + //Primary interface functions void serializePacket(SerialPacketBase*, void* dest); void deserializePacket(SerialPacketBase*, void* src); @@ -53,13 +55,22 @@ void deserializeRegionContent(RegionPacket*, void*); void deserializeServer(ServerPacket*, void*); void deserializeStatistics(Statistics*, void*); -/* DOCS: Keep the PACKET_BUFFER_SIZE up to date +/* DOCS: Keep these macros, including PACKET_BUFFER_SIZE up to date * DOCS: REGION_CONTENT is currently the largest type of packet, read more - * map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t) - * map format: sizeof(int) * 3 - * metadata: sizeof(SerialPacket::Type) + * REGION_FORMAT + * This is the space for the region's metadata; the X and Y position, the map index and the SerialPacketType + * REGION_FOOTPRINT + * This is the theoretical size of the map's tile data in memory, but it doesn't take the collision map into account + * COLLISION_FOOTPRINT + * This is the space in the packet for the collision map, stored as a bit array + * PACKET_BUFFER_SIZE + * This is the tital size of the packet being sent between the server and the clients */ -constexpr int PACKET_BUFFER_SIZE = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 3 + sizeof(SerialPacketType); +constexpr int REGION_FORMAT = sizeof(int) * 3 + sizeof(SerialPacketType); +constexpr int REGION_FOOTPRINT = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t); +constexpr int COLLISION_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0); + +constexpr int PACKET_BUFFER_SIZE = REGION_FORMAT + REGION_FOOTPRINT + COLLISION_FOOTPRINT; #endif \ No newline at end of file diff --git a/common/network/serial/serial_region.cpp b/common/network/serial/serial_region.cpp index 31145bd..d4dc563 100644 --- a/common/network/serial/serial_region.cpp +++ b/common/network/serial/serial_region.cpp @@ -49,6 +49,8 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) { } } } + + //TODO: serialize collision map } void deserializeRegionFormat(RegionPacket* packet, void* buffer) { @@ -80,4 +82,6 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) { } } } + + //TODO: deserialize collision map } \ No newline at end of file diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index 6bc65f0..e589a18 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -1,4 +1,4 @@ -print("Lua script check (./rsc)") +print("Lua script check") --uber lazy declarations function square(x) return x*x end @@ -33,10 +33,10 @@ end newRoom = RoomMgr.CreateRoom("overworld") pager = Room.GetPager(newRoom) regionTable = { - RegionPager.GetRegion(pager, 0, 0), - RegionPager.GetRegion(pager, 0, -20), - RegionPager.GetRegion(pager, -20, 0), - RegionPager.GetRegion(pager, -20, -20) + RegionPager.GetRegion(pager, Region.GetWidth() * 0, Region.GetHeight() * 0), + RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() * 0), + RegionPager.GetRegion(pager, Region.GetWidth() * 0, Region.GetHeight() *-1), + RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() *-1) } print("Finished the lua script") \ No newline at end of file diff --git a/server/server_application.cpp b/server/server_application.cpp index 901706f..16bb8e4 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -113,12 +113,20 @@ void ServerApplication::Init(int argc, char** argv) { //debug output //------------------------- + //TODO: put these outputs into the client too +#define OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl; + std::cout << "Internal sizes:" << std::endl; - std::cout << "\tTile Size: " << sizeof(Region::type_t) << std::endl; - std::cout << "\tRegion Format: " << REGION_WIDTH << ", " << REGION_HEIGHT << ", " << REGION_DEPTH << std::endl; - std::cout << "\tRegion Content Footprint: " << REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) << std::endl; - std::cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << std::endl; - std::cout << "\tMAX_PACKET_SIZE: " << MAX_PACKET_SIZE << std::endl; + + OUTPUT_VAR(sizeof(Region::type_t)); + OUTPUT_VAR(sizeof(Region)); + OUTPUT_VAR(REGION_FORMAT); + OUTPUT_VAR(REGION_FOOTPRINT); + OUTPUT_VAR(COLLISION_FOOTPRINT); + OUTPUT_VAR(PACKET_BUFFER_SIZE); + OUTPUT_VAR(MAX_PACKET_SIZE); + +#undef OUTPUT_VAR //------------------------- //finalize the startup From 8ed308e89aa0c7dc3ea0e23c529fbdcce38db02d Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 1 Jul 2014 22:55:43 +1000 Subject: [PATCH 03/10] Switched the hack for the bitset I've also added acessors and mutators to the Region and RegionPagerBase classes. --- common/map/region.cpp | 12 ++++++++++-- common/map/region.hpp | 16 +++++++++++++++- common/map/region_pager_base.cpp | 10 ++++++++++ common/map/region_pager_base.hpp | 4 ++++ common/network/serial/serial.hpp | 25 ++++++++----------------- server/server_application.cpp | 21 ++++++++++++--------- 6 files changed, 59 insertions(+), 29 deletions(-) diff --git a/common/map/region.cpp b/common/map/region.cpp index 7fbe38c..1f75df8 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -30,11 +30,11 @@ Region::Region(int argX, int argY): x(argX), y(argY) { if (x != snapToBase(REGION_WIDTH, x) || y != snapToBase(REGION_HEIGHT, y)) { throw(std::invalid_argument("Region location is off grid")); } - memset(tiles, 0, REGION_WIDTH*REGION_HEIGHT*(REGION_DEPTH+1)*sizeof(type_t)); + memset(tiles, 0, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t)); } Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) { - memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*(REGION_DEPTH+1)*sizeof(type_t)); + memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t)); } Region::type_t Region::SetTile(int x, int y, int z, type_t v) { @@ -44,3 +44,11 @@ Region::type_t Region::SetTile(int x, int y, int z, type_t v) { Region::type_t Region::GetTile(int x, int y, int z) { return tiles[x][y][z]; } + +bool Region::SetSolid(int x, int y, bool b) { + return solid[x * REGION_WIDTH + y] = b; +} + +bool Region::GetSolid(int x, int y) { + return solid[x * REGION_WIDTH + y]; +} \ No newline at end of file diff --git a/common/map/region.hpp b/common/map/region.hpp index 7b578fa..3617482 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -22,10 +22,17 @@ #ifndef REGION_HPP_ #define REGION_HPP_ +#include +#include + +//the region's storage format constexpr int REGION_WIDTH = 21; constexpr int REGION_HEIGHT = 21; constexpr int REGION_DEPTH = 3; +//the size of the solid map +constexpr int REGION_SOLID = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0); + class Region { public: typedef unsigned char type_t; @@ -38,6 +45,9 @@ public: type_t SetTile(int x, int y, int z, type_t v); type_t GetTile(int x, int y, int z); + bool SetSolid(int x, int y, bool b); + bool GetSolid(int x, int y); + //accessors int GetX() const { return x; } int GetY() const { return y; } @@ -45,7 +55,11 @@ private: const int x; const int y; - type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH+1]; + type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH]; + std::bitset solid; }; +//the memory footprint of the tile and solid data; not including any metadata +constexpr int REGION_FOOTPRINT = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + REGION_SOLID; + #endif diff --git a/common/map/region_pager_base.cpp b/common/map/region_pager_base.cpp index a8ad76f..fbe633d 100644 --- a/common/map/region_pager_base.cpp +++ b/common/map/region_pager_base.cpp @@ -36,6 +36,16 @@ Region::type_t RegionPagerBase::GetTile(int x, int y, int z) { return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z); } +bool RegionPagerBase::SetSolid(int x, int y, int b) { + Region* ptr = GetRegion(x, y); + return ptr->SetSolid(x - ptr->GetX(), y - ptr->GetY(), b); +} + +bool RegionPagerBase::GetSolid(int x, int y) { + Region* ptr = GetRegion(x, y); + return ptr->GetSolid(x - ptr->GetX(), y - ptr->GetY()); +} + Region* RegionPagerBase::GetRegion(int x, int y) { //get the region by various means Region* ptr = nullptr; diff --git a/common/map/region_pager_base.hpp b/common/map/region_pager_base.hpp index 004faa4..53bb097 100644 --- a/common/map/region_pager_base.hpp +++ b/common/map/region_pager_base.hpp @@ -35,6 +35,10 @@ public: virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v); virtual Region::type_t GetTile(int x, int y, int z); + //solid manipulation + virtual bool SetSolid(int x, int y, int b); + virtual bool GetSolid(int x, int y); + //region manipulation virtual Region* GetRegion(int x, int y); virtual Region* FindRegion(int x, int y); diff --git a/common/network/serial/serial.hpp b/common/network/serial/serial.hpp index f69743a..2a948bd 100644 --- a/common/network/serial/serial.hpp +++ b/common/network/serial/serial.hpp @@ -27,8 +27,6 @@ #include "region.hpp" #include "statistics.hpp" -#include - //Primary interface functions void serializePacket(SerialPacketBase*, void* dest); void deserializePacket(SerialPacketBase*, void* src); @@ -55,22 +53,15 @@ void deserializeRegionContent(RegionPacket*, void*); void deserializeServer(ServerPacket*, void*); void deserializeStatistics(Statistics*, void*); -/* DOCS: Keep these macros, including PACKET_BUFFER_SIZE up to date - * DOCS: REGION_CONTENT is currently the largest type of packet, read more - * REGION_FORMAT - * This is the space for the region's metadata; the X and Y position, the map index and the SerialPacketType - * REGION_FOOTPRINT - * This is the theoretical size of the map's tile data in memory, but it doesn't take the collision map into account - * COLLISION_FOOTPRINT - * This is the space in the packet for the collision map, stored as a bit array - * PACKET_BUFFER_SIZE - * This is the tital size of the packet being sent between the server and the clients +/* DOCS: Keep PACKET_BUFFER_SIZE up to date + * DOCS: SerialPacketType::REGION_CONTENT is currently the largest type of packet, read more + * The metadata used are: + * SerialPacketType + * room index + * X & Y positon + * The rest is taken up by the Regions's content. */ -constexpr int REGION_FORMAT = sizeof(int) * 3 + sizeof(SerialPacketType); -constexpr int REGION_FOOTPRINT = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t); -constexpr int COLLISION_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0); - -constexpr int PACKET_BUFFER_SIZE = REGION_FORMAT + REGION_FOOTPRINT + COLLISION_FOOTPRINT; +constexpr int PACKET_BUFFER_SIZE = sizeof(SerialPacketType) + sizeof(int) * 3 + REGION_FOOTPRINT; #endif \ No newline at end of file diff --git a/server/server_application.cpp b/server/server_application.cpp index 16bb8e4..41671bf 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -114,19 +114,22 @@ void ServerApplication::Init(int argc, char** argv) { //------------------------- //TODO: put these outputs into the client too -#define OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl; + //TODO: enable/disable these with a switch +#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl; std::cout << "Internal sizes:" << std::endl; - OUTPUT_VAR(sizeof(Region::type_t)); - OUTPUT_VAR(sizeof(Region)); - OUTPUT_VAR(REGION_FORMAT); - OUTPUT_VAR(REGION_FOOTPRINT); - OUTPUT_VAR(COLLISION_FOOTPRINT); - OUTPUT_VAR(PACKET_BUFFER_SIZE); - OUTPUT_VAR(MAX_PACKET_SIZE); + DEBUG_OUTPUT_VAR(sizeof(Region::type_t)); + DEBUG_OUTPUT_VAR(sizeof(Region)); + DEBUG_OUTPUT_VAR(REGION_WIDTH); + DEBUG_OUTPUT_VAR(REGION_HEIGHT); + DEBUG_OUTPUT_VAR(REGION_DEPTH); + DEBUG_OUTPUT_VAR(REGION_SOLID); + DEBUG_OUTPUT_VAR(REGION_FOOTPRINT); + DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE); + DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE); -#undef OUTPUT_VAR +#undef DEBUG_OUTPUT_VAR //------------------------- //finalize the startup From 93480be68544f935503aad73636d3bf087055a1a Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 2 Jul 2014 00:47:37 +1000 Subject: [PATCH 04/10] Solid data is moving from the server to the client, read more The APIs have access to the solid data, and I fixed a bug: Basically, the template parameter for std::bitset expects an integer representing the number of bits to hold, but I initially misread it as the number of bytes. This has been corrected. I've also added a sandy beach to the generated island. I'm tempted to start working on some simple generators soon. --- common/map/region.cpp | 1 + common/map/region.hpp | 12 +++++++----- common/map/region_api.cpp | 16 ++++++++++++++++ common/map/region_pager_api.cpp | 16 ++++++++++++++++ common/network/serial/serial_region.cpp | 10 ++++++---- rsc/scripts/setup_server.lua | 9 ++++++--- server/server_application.cpp | 2 +- 7 files changed, 53 insertions(+), 13 deletions(-) diff --git a/common/map/region.cpp b/common/map/region.cpp index 1f75df8..c4fb712 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -35,6 +35,7 @@ Region::Region(int argX, int argY): x(argX), y(argY) { Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) { memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t)); + solid = rhs.solid; } Region::type_t Region::SetTile(int x, int y, int z, type_t v) { diff --git a/common/map/region.hpp b/common/map/region.hpp index 3617482..0571c09 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -26,12 +26,12 @@ #include //the region's storage format -constexpr int REGION_WIDTH = 21; -constexpr int REGION_HEIGHT = 21; +constexpr int REGION_WIDTH = 20; +constexpr int REGION_HEIGHT = 20; constexpr int REGION_DEPTH = 3; //the size of the solid map -constexpr int REGION_SOLID = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0); +constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0); class Region { public: @@ -51,15 +51,17 @@ public: //accessors int GetX() const { return x; } int GetY() const { return y; } + + std::bitset* GetSolidBitset() { return &solid; } private: const int x; const int y; type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH]; - std::bitset solid; + std::bitset solid; }; //the memory footprint of the tile and solid data; not including any metadata -constexpr int REGION_FOOTPRINT = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + REGION_SOLID; +constexpr int REGION_FOOTPRINT = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + REGION_SOLID_FOOTPRINT; #endif diff --git a/common/map/region_api.cpp b/common/map/region_api.cpp index ead6ef2..014a873 100644 --- a/common/map/region_api.cpp +++ b/common/map/region_api.cpp @@ -37,6 +37,20 @@ static int getTile(lua_State* L) { return 1; } +static int setSolid(lua_State* L) { + Region* region = reinterpret_cast(lua_touserdata(L, 1)); + bool ret = region->SetSolid(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_toboolean(L, 4)); + lua_pushboolean(L, ret); + return 1; +} + +static int getSolid(lua_State* L) { + Region* region = reinterpret_cast(lua_touserdata(L, 1)); + bool ret = region->GetSolid(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1); + lua_pushboolean(L, ret); + return 1; +} + static int getX(lua_State* L) { Region* region = reinterpret_cast(lua_touserdata(L, 1)); lua_pushinteger(L, region->GetX()); @@ -89,6 +103,8 @@ static int onUnload(lua_State* L) { static const luaL_Reg regionLib[] = { {"SetTile",setTile}, {"GetTile",getTile}, + {"SetSolid",setSolid}, + {"GetSolid",getSolid}, {"GetX",getX}, {"GetY",getY}, {"GetWidth",getWidth}, diff --git a/common/map/region_pager_api.cpp b/common/map/region_pager_api.cpp index f38d1e2..40c4d76 100644 --- a/common/map/region_pager_api.cpp +++ b/common/map/region_pager_api.cpp @@ -43,6 +43,20 @@ static int getTile(lua_State* L) { return 1; } +static int setSolid(lua_State* L) { + RegionPagerLua* pager = reinterpret_cast(lua_touserdata(L, 1)); + bool ret = pager->SetSolid(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_toboolean(L, 4)); + lua_pushboolean(L, ret); + return 1; +} + +static int getSolid(lua_State* L) { + RegionPagerLua* pager = reinterpret_cast(lua_touserdata(L, 1)); + bool ret = pager->GetSolid(lua_tointeger(L, 2), lua_tointeger(L, 3)); + lua_pushboolean(L, ret); + return 1; +} + static int getRegion(lua_State* L) { RegionPagerLua* pager = reinterpret_cast(lua_touserdata(L, 1)); Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3)); @@ -94,6 +108,8 @@ static int unloadRegion(lua_State* L) { static const luaL_Reg pagerlib[] = { {"SetTile", setTile}, {"GetTile", getTile}, + {"SetSolid", setSolid}, + {"GetSolid", getSolid}, {"GetRegion", getRegion}, {"SetDirectory", setDirectory}, {"GetDirectory", getDirectory}, diff --git a/common/network/serial/serial_region.cpp b/common/network/serial/serial_region.cpp index d4dc563..5aec454 100644 --- a/common/network/serial/serial_region.cpp +++ b/common/network/serial/serial_region.cpp @@ -40,7 +40,7 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) { SERIALIZE(buffer, &packet->x, sizeof(int)); SERIALIZE(buffer, &packet->y, sizeof(int)); - //content + //tiles for (register int i = 0; i < REGION_WIDTH; i++) { for (register int j = 0; j < REGION_HEIGHT; j++) { for (register int k = 0; k < REGION_DEPTH; k++) { @@ -50,7 +50,8 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) { } } - //TODO: serialize collision map + //solids + SERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT); } void deserializeRegionFormat(RegionPacket* packet, void* buffer) { @@ -73,7 +74,7 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) { //an object to work on packet->region = new Region(packet->x, packet->y); - //content + //tiles for (register int i = 0; i < REGION_WIDTH; i++) { for (register int j = 0; j < REGION_HEIGHT; j++) { for (register int k = 0; k < REGION_DEPTH; k++) { @@ -83,5 +84,6 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) { } } - //TODO: deserialize collision map + //solids + DESERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT); } \ No newline at end of file diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index e589a18..582cacf 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -19,10 +19,13 @@ Region.OnCreate = function(region) local ret = Region.hcOnCreate(region) --best practices for i = 1, Region.GetWidth() do for j = 1, Region.GetHeight() do - if distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) > 10 then - Region.SetTile(region, i, j, 1, water) - else + local dist = distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) + if dist < 10 then Region.SetTile(region, i, j, 1, plains) + elseif dist < 12 then + Region.SetTile(region, i, j, 1, sand) + else + Region.SetTile(region, i, j, 1, water) end end end diff --git a/server/server_application.cpp b/server/server_application.cpp index 41671bf..7396cda 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -124,7 +124,7 @@ void ServerApplication::Init(int argc, char** argv) { DEBUG_OUTPUT_VAR(REGION_WIDTH); DEBUG_OUTPUT_VAR(REGION_HEIGHT); DEBUG_OUTPUT_VAR(REGION_DEPTH); - DEBUG_OUTPUT_VAR(REGION_SOLID); + DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT); DEBUG_OUTPUT_VAR(REGION_FOOTPRINT); DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE); DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE); From bac493c96bb6248b3b6112aee3b242e9ab755e2b Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 2 Jul 2014 21:59:26 +1000 Subject: [PATCH 05/10] Rearranged the debug output --- client/client_application.cpp | 60 ++++++++++++++++++++++++++++++++--- client/main.cpp | 2 -- server/main.cpp | 6 +--- server/server_application.cpp | 7 ++-- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/client/client_application.cpp b/client/client_application.cpp index 06f0bc6..95f529c 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -25,6 +25,7 @@ #include #include +#include //------------------------- //Scene headers @@ -44,24 +45,71 @@ //------------------------- void ClientApplication::Init(int argc, char** argv) { + std::cout << "Beginning " << argv[0] << std::endl; + //load the prerequisites config.Load("rsc\\config.cfg"); + //------------------------- + //Initialize the APIs + //------------------------- + //initialize SDL if (SDL_Init(SDL_INIT_VIDEO)) { throw(std::runtime_error("Failed to initialize SDL")); } - int w = config.Int("client.screen.w"); - int h = config.Int("client.screen.h"); - int f = config.Bool("client.screen.f") ? SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN : SDL_HWSURFACE|SDL_DOUBLEBUF; - - BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f); + std::cout << "Initialized SDL" << std::endl; //initialize SDL_net if (SDLNet_Init()) { throw(std::runtime_error("Failed to initialize SDL_net")); } network.Open(0); + std::cout << "Initialized SDL_net" << std::endl; + + //------------------------- + //Setup the screen + //------------------------- + + int w = config.Int("client.screen.w"); + int h = config.Int("client.screen.h"); + int f = config.Bool("client.screen.f") ? SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN : SDL_HWSURFACE|SDL_DOUBLEBUF; + + BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f); + std::cout << "Initialized the screen" << std::endl; + + //------------------------- + //debug output + //------------------------- + + //TODO: enable/disable these with a switch +#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl; + + std::cout << "Internal sizes:" << std::endl; + + DEBUG_OUTPUT_VAR(sizeof(Region::type_t)); + DEBUG_OUTPUT_VAR(sizeof(Region)); + DEBUG_OUTPUT_VAR(REGION_WIDTH); + DEBUG_OUTPUT_VAR(REGION_HEIGHT); + DEBUG_OUTPUT_VAR(REGION_DEPTH); + DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT); + DEBUG_OUTPUT_VAR(REGION_FOOTPRINT); + DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE); + DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE); + +#undef DEBUG_OUTPUT_VAR + + //------------------------- + //finalize the startup + //------------------------- + + std::cout << "Startup completed successfully" << std::endl; + + //------------------------- + //debugging + //------------------------- + + //... } void ClientApplication::Proc() { @@ -100,9 +148,11 @@ void ClientApplication::Proc() { } void ClientApplication::Quit() { + std::cout << "Shutting down" << std::endl; network.Close(); SDLNet_Quit(); SDL_Quit(); + std::cout << "Clean exit" << std::endl; } //------------------------- diff --git a/client/main.cpp b/client/main.cpp index 9ec652c..156adff 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -27,7 +27,6 @@ using namespace std; int main(int argc, char** argv) { - cout << "Beginning client" << endl; try { ClientApplication app; app.Init(argc, argv); @@ -38,6 +37,5 @@ int main(int argc, char** argv) { cerr << "Fatal exception thrown: " << e.what() << endl; return 1; } - cout << "Clean exit" << endl; return 0; } diff --git a/server/main.cpp b/server/main.cpp index 288e10f..5c01971 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -21,15 +21,12 @@ */ #include "server_application.hpp" -#include "SDL/SDL.h" - #include #include using namespace std; int main(int argc, char** argv) { - cout << "Beginning server" << endl; try { ServerApplication app; app.Init(argc, argv); @@ -37,9 +34,8 @@ int main(int argc, char** argv) { app.Quit(); } catch(exception& e) { - cerr << "Fatal error: " << e.what() << endl; + cerr << "Fatal exception thrown: " << e.what() << endl; return 1; } - cout << "Clean exit" << endl; return 0; } \ No newline at end of file diff --git a/server/server_application.cpp b/server/server_application.cpp index 7396cda..7ccfb15 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -35,9 +35,9 @@ void ServerApplication::Init(int argc, char** argv) { //NOTE: I might need to rearrange the init process so that lua & SQL can interact with the map system as needed. - std::cout << "Beginning startup" << std::endl; + std::cout << "Beginning " << argv[0] << std::endl; - //initial setup + //load the prerequisites config.Load("rsc\\config.cfg"); //------------------------- @@ -113,7 +113,6 @@ void ServerApplication::Init(int argc, char** argv) { //debug output //------------------------- - //TODO: put these outputs into the client too //TODO: enable/disable these with a switch #define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl; @@ -178,7 +177,7 @@ void ServerApplication::Quit() { SDLNet_Quit(); SDL_Quit(); - std::cout << "Shutdown finished" << std::endl; + std::cout << "Clean exit" << std::endl; } //------------------------- From 82b1b589dc9bf03efb57f068889de94ff423cc15 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 3 Jul 2014 00:23:43 +1000 Subject: [PATCH 06/10] Moved some files around --- client/character_data.cpp | 61 ++++++++++++++++ client/character_data.hpp | 71 +++++++++++++++++++ client/makefile | 2 +- common/gameplay/character_defines.hpp | 33 +++++++++ .../{sanity_check.cpp => combat_defines.hpp} | 20 +++--- common/gameplay/makefile | 4 +- common/network/packet/combat_packet.hpp | 4 +- common/network/serial/serial_combat.cpp | 4 +- .../characters}/character_data.cpp | 0 .../characters}/character_data.hpp | 0 .../combat}/combat_data.hpp | 20 +----- .../enemies}/enemy_data.hpp | 10 --- 12 files changed, 184 insertions(+), 45 deletions(-) create mode 100644 client/character_data.cpp create mode 100644 client/character_data.hpp create mode 100644 common/gameplay/character_defines.hpp rename common/gameplay/{sanity_check.cpp => combat_defines.hpp} (72%) rename {common/gameplay => server/characters}/character_data.cpp (100%) rename {common/gameplay => server/characters}/character_data.hpp (100%) rename {common/gameplay => server/combat}/combat_data.hpp (84%) rename {common/gameplay => server/enemies}/enemy_data.hpp (88%) diff --git a/client/character_data.cpp b/client/character_data.cpp new file mode 100644 index 0000000..81e4c75 --- /dev/null +++ b/client/character_data.cpp @@ -0,0 +1,61 @@ +/* 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) { + origin += motion * delta * CHARACTER_WALKING_MOD; + } + else if (motion != 0) { + origin += motion * delta; + } + sprite.Update(delta); +} + +void CharacterData::DrawTo(SDL_Surface* const dest, int camX, int camY) { + sprite.DrawTo(dest, origin.x - camX, origin.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); + } +} diff --git a/client/character_data.hpp b/client/character_data.hpp new file mode 100644 index 0000000..ec8f12d --- /dev/null +++ b/client/character_data.hpp @@ -0,0 +1,71 @@ +/* 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 CHARACTERDATA_HPP_ +#define CHARACTERDATA_HPP_ + +//components +#include "character_defines.hpp" +#include "vector2.hpp" +#include "statistics.hpp" + +//graphics +#include "sprite_sheet.hpp" + +//std namespace +#include +#include + +//TODO: encapsulate this +struct CharacterData { + //metadata + int owner; + std::string handle; + std::string avatar; + + //members + SpriteSheet sprite; + + //world position + int roomIndex = 0; + Vector2 origin = {0.0,0.0}; + Vector2 motion = {0.0,0.0}; + Vector2 bounds = {0.0,0.0}; + + //base statistics + Statistics stats; + + //TODO: gameplay components: equipment, items, buffs, debuffs + + //methods + void Update(double delta); + + void DrawTo(SDL_Surface* const, int camX, int camY); + void CorrectSprite(); + + //active gameplay members + //NOTE: these are lost when unloaded + bool inCombat = false; + int atbGauge = 0; + //TODO: stored command +}; + +#endif diff --git a/client/makefile b/client/makefile index 947b822..9a2a0ca 100644 --- a/client/makefile +++ b/client/makefile @@ -1,7 +1,7 @@ #config INCLUDES+=. ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/gameplay/character_defines.hpp b/common/gameplay/character_defines.hpp new file mode 100644 index 0000000..76d80c9 --- /dev/null +++ b/common/gameplay/character_defines.hpp @@ -0,0 +1,33 @@ +/* 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 CHARACTERDEFINES_HPP_ +#define CHARACTERDEFINES_HPP_ + +//the speeds that the characters move +constexpr double CHARACTER_WALKING_SPEED = 140.0; +constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); + +//the bounding boxes for the characters +constexpr double CHARACTER_BOUNDS_WIDTH = 32.0; +constexpr double CHARACTER_BOUNDS_HEIGHT = 32.0; + +#endif diff --git a/common/gameplay/sanity_check.cpp b/common/gameplay/combat_defines.hpp similarity index 72% rename from common/gameplay/sanity_check.cpp rename to common/gameplay/combat_defines.hpp index 8669811..0771561 100644 --- a/common/gameplay/sanity_check.cpp +++ b/common/gameplay/combat_defines.hpp @@ -19,13 +19,15 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#include "character_data.hpp" -#include "combat_data.hpp" -#include "enemy_data.hpp" -#include "statistics.hpp" +#ifndef COMBATDEFINES_HPP_ +#define COMBATDEFINES_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. -*/ \ No newline at end of file +#define COMBAT_MAX_CHARACTERS 16 +#define COMBAT_MAX_ENEMIES 16 + +enum class TerrainType { + NONE = 0, + GRASSLANDS, +}; + +#endif diff --git a/common/gameplay/makefile b/common/gameplay/makefile index 3be52be..9013447 100644 --- a/common/gameplay/makefile +++ b/common/gameplay/makefile @@ -1,7 +1,7 @@ #config -INCLUDES+=. ../utilities ../graphics +INCLUDES+=. LIBS+= -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) diff --git a/common/network/packet/combat_packet.hpp b/common/network/packet/combat_packet.hpp index ea27e8f..6b068df 100644 --- a/common/network/packet/combat_packet.hpp +++ b/common/network/packet/combat_packet.hpp @@ -24,13 +24,13 @@ #include "serial_packet_base.hpp" -#include "combat_data.hpp" +#include "combat_defines.hpp" struct CombatPacket : SerialPacketBase { //identify the combat instance int combatIndex; int difficulty; - CombatData::Terrain terrainType; + TerrainType terrainType; //combatants int characterArray[COMBAT_MAX_CHARACTERS]; diff --git a/common/network/serial/serial_combat.cpp b/common/network/serial/serial_combat.cpp index 268d580..318779f 100644 --- a/common/network/serial/serial_combat.cpp +++ b/common/network/serial/serial_combat.cpp @@ -29,7 +29,7 @@ void serializeCombat(CombatPacket* packet, void* buffer) { //identify the combat instance SERIALIZE(buffer, &packet->combatIndex, sizeof(int)); SERIALIZE(buffer, &packet->difficulty, sizeof(int)); - SERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain)); + SERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType)); //combatants SERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS); @@ -49,7 +49,7 @@ void deserializeCombat(CombatPacket* packet, void* buffer) { //identify the combat instance DESERIALIZE(buffer, &packet->combatIndex, sizeof(int)); DESERIALIZE(buffer, &packet->difficulty, sizeof(int)); - DESERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain)); + DESERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType)); //combatants DESERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS); diff --git a/common/gameplay/character_data.cpp b/server/characters/character_data.cpp similarity index 100% rename from common/gameplay/character_data.cpp rename to server/characters/character_data.cpp diff --git a/common/gameplay/character_data.hpp b/server/characters/character_data.hpp similarity index 100% rename from common/gameplay/character_data.hpp rename to server/characters/character_data.hpp diff --git a/common/gameplay/combat_data.hpp b/server/combat/combat_data.hpp similarity index 84% rename from common/gameplay/combat_data.hpp rename to server/combat/combat_data.hpp index b170e5f..683e66f 100644 --- a/common/gameplay/combat_data.hpp +++ b/server/combat/combat_data.hpp @@ -23,31 +23,18 @@ #define COMBATDATA_HPP_ #include "vector2.hpp" +#include "combat_defines.hpp" //gameplay members #include "character_data.hpp" #include "enemy_data.hpp" -//graphics -#ifdef GRAPHICS - #include "sprite_sheet.hpp" -#endif - //std namespace #include #include #include -#define COMBAT_MAX_CHARACTERS 12 -#define COMBAT_MAX_ENEMIES 12 - struct CombatData { - enum class Terrain { - //TODO: types of combat terrains - NONE = 0, - GRASSLANDS, - }; - typedef std::chrono::steady_clock Clock; std::array characterArray; @@ -60,11 +47,6 @@ 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/server/enemies/enemy_data.hpp similarity index 88% rename from common/gameplay/enemy_data.hpp rename to server/enemies/enemy_data.hpp index 533add6..ab1ef89 100644 --- a/common/gameplay/enemy_data.hpp +++ b/server/enemies/enemy_data.hpp @@ -25,11 +25,6 @@ #include "vector2.hpp" #include "statistics.hpp" -//graphics -#ifdef GRAPHICS - #include "sprite_sheet.hpp" -#endif - //std namespace #include @@ -45,11 +40,6 @@ struct EnemyData { //active gameplay members //NOTE: these are lost when unloaded -#ifdef GRAPHICS - SpriteSheet sprite; - Vector2 origin = {0.0,0.0}; - Vector2 bounds = {0.0,0.0}; -#endif int tableIndex; int atbGauge = 0; }; From 4dd4b37fc081a4bed037aadc41c68d319b0dbdd8 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 3 Jul 2014 00:55:54 +1000 Subject: [PATCH 07/10] It now builds cleanly, but I cut a few code stubs --- .../combat_data.hpp | 34 +++++--- .../chunk_data.hpp => client/enemy_data.hpp | 35 ++++---- common/gameplay/character_defines.hpp | 2 + common/gameplay/combat_defines.hpp | 1 + server/combat/makefile | 2 +- server/enemies/enemy_factory_generic.cpp | 34 -------- server/enemies/enemy_factory_interface.hpp | 49 ------------ server/linit.cpp | 2 - server/makefile | 1 - server/mapgen/generator_api.cpp | 79 ------------------- server/mapgen/generator_api.hpp | 30 ------- server/mapgen/generators/base_generator.cpp | 36 --------- server/mapgen/generators/base_generator.hpp | 54 ------------- server/mapgen/generators/caves_generator.cpp | 30 ------- server/mapgen/generators/caves_generator.hpp | 36 --------- .../mapgen/generators/forests_generator.cpp | 30 ------- .../mapgen/generators/forests_generator.hpp | 36 --------- server/mapgen/generators/makefile | 37 --------- .../mapgen/generators/overworld_generator.cpp | 30 ------- .../mapgen/generators/overworld_generator.hpp | 36 --------- server/mapgen/generators/ruins_generator.cpp | 30 ------- server/mapgen/generators/ruins_generator.hpp | 36 --------- server/mapgen/generators/towers_generator.cpp | 30 ------- server/mapgen/generators/towers_generator.hpp | 36 --------- server/mapgen/makefile | 38 --------- server/mapgen/map_type.hpp | 34 -------- server/mapgen/terrain_type.hpp | 40 ---------- server/rooms/room_api.cpp | 7 -- server/rooms/room_data.hpp | 3 - server/rooms/room_manager.cpp | 29 +------ server/rooms/room_manager.hpp | 2 +- server/rooms/room_mgr_api.cpp | 12 +-- 32 files changed, 49 insertions(+), 842 deletions(-) rename server/enemies/enemy_factory_generic.hpp => client/combat_data.hpp (62%) rename server/mapgen/chunk_data.hpp => client/enemy_data.hpp (69%) delete mode 100644 server/enemies/enemy_factory_generic.cpp delete mode 100644 server/enemies/enemy_factory_interface.hpp delete mode 100644 server/mapgen/generator_api.cpp delete mode 100644 server/mapgen/generator_api.hpp delete mode 100644 server/mapgen/generators/base_generator.cpp delete mode 100644 server/mapgen/generators/base_generator.hpp delete mode 100644 server/mapgen/generators/caves_generator.cpp delete mode 100644 server/mapgen/generators/caves_generator.hpp delete mode 100644 server/mapgen/generators/forests_generator.cpp delete mode 100644 server/mapgen/generators/forests_generator.hpp delete mode 100644 server/mapgen/generators/makefile delete mode 100644 server/mapgen/generators/overworld_generator.cpp delete mode 100644 server/mapgen/generators/overworld_generator.hpp delete mode 100644 server/mapgen/generators/ruins_generator.cpp delete mode 100644 server/mapgen/generators/ruins_generator.hpp delete mode 100644 server/mapgen/generators/towers_generator.cpp delete mode 100644 server/mapgen/generators/towers_generator.hpp delete mode 100644 server/mapgen/makefile delete mode 100644 server/mapgen/map_type.hpp delete mode 100644 server/mapgen/terrain_type.hpp diff --git a/server/enemies/enemy_factory_generic.hpp b/client/combat_data.hpp similarity index 62% rename from server/enemies/enemy_factory_generic.hpp rename to client/combat_data.hpp index 5a63078..683e66f 100644 --- a/server/enemies/enemy_factory_generic.hpp +++ b/client/combat_data.hpp @@ -19,24 +19,34 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef ENEMYFACTORYGENERIC_HPP_ -#define ENEMYFACTORYGENERIC_HPP_ +#ifndef COMBATDATA_HPP_ +#define COMBATDATA_HPP_ -#include "enemy_factory_interface.hpp" +#include "vector2.hpp" +#include "combat_defines.hpp" +//gameplay members +#include "character_data.hpp" #include "enemy_data.hpp" -#include +//std namespace +#include +#include +#include -//DOCS: Not really intended for use, but rather for copying and tweaking -class EnemyFactoryGeneric : public EnemyFactoryInterface { -public: - EnemyFactoryGeneric(); - ~EnemyFactoryGeneric() noexcept override; +struct CombatData { + typedef std::chrono::steady_clock Clock; - void Generate(std::list* container) override; -private: - //TODO: hold the parameters specified by the room + std::array characterArray; + std::array enemyArray; + + //world interaction + int mapIndex = 0; + Vector2 origin = {0.0,0.0}; + Vector2 bounds = {0.0,0.0}; + + //time interval + Clock::time_point lastTick = Clock::now(); }; #endif diff --git a/server/mapgen/chunk_data.hpp b/client/enemy_data.hpp similarity index 69% rename from server/mapgen/chunk_data.hpp rename to client/enemy_data.hpp index c0c1621..ab1ef89 100644 --- a/server/mapgen/chunk_data.hpp +++ b/client/enemy_data.hpp @@ -19,26 +19,29 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CHUNKDATA_HPP_ -#define CHUNKDATA_HPP_ +#ifndef ENEMYDATA_HPP_ +#define ENEMYDATA_HPP_ -#include "terrain_type.hpp" +#include "vector2.hpp" +#include "statistics.hpp" -#include +//std namespace +#include -struct ChunkData { - enum class Moddable { - LOCKED, //do not change - HARD, //minor changes - SOFT, //major changes - CLEAR, //untouched - }; +struct EnemyData { + //metadata + std::string handle; + std::string avatar; - TerrainType type; -// int fountainCount; - Moddable mod; + //gameplay + Statistics stats; + + //TODO: gameplay components: equipment, items, buffs, debuffs, rewards + + //active gameplay members + //NOTE: these are lost when unloaded + int tableIndex; + int atbGauge = 0; }; -static_assert(std::is_pod::value, "ChunkData is not a POD"); - #endif diff --git a/common/gameplay/character_defines.hpp b/common/gameplay/character_defines.hpp index 76d80c9..1daa1b4 100644 --- a/common/gameplay/character_defines.hpp +++ b/common/gameplay/character_defines.hpp @@ -22,6 +22,8 @@ #ifndef CHARACTERDEFINES_HPP_ #define CHARACTERDEFINES_HPP_ +#include + //the speeds that the characters move constexpr double CHARACTER_WALKING_SPEED = 140.0; constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); diff --git a/common/gameplay/combat_defines.hpp b/common/gameplay/combat_defines.hpp index 0771561..db6421c 100644 --- a/common/gameplay/combat_defines.hpp +++ b/common/gameplay/combat_defines.hpp @@ -28,6 +28,7 @@ enum class TerrainType { NONE = 0, GRASSLANDS, + //etc. }; #endif diff --git a/server/combat/makefile b/server/combat/makefile index 68368e7..4d71462 100644 --- a/server/combat/makefile +++ b/server/combat/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../../common/gameplay ../../common/utilities +INCLUDES+=. ../../common/gameplay ../../common/utilities ../characters ../enemies LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/server/enemies/enemy_factory_generic.cpp b/server/enemies/enemy_factory_generic.cpp deleted file mode 100644 index e8dd647..0000000 --- a/server/enemies/enemy_factory_generic.cpp +++ /dev/null @@ -1,34 +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. -*/ -#include "enemy_factory_generic.hpp" - -EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() { - //EMPTY -} - -EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept { - //EMPTY -} - -void EnemyFactoryGeneric::Generate(std::list* container) { - //TODO: fill this out -} \ No newline at end of file diff --git a/server/enemies/enemy_factory_interface.hpp b/server/enemies/enemy_factory_interface.hpp deleted file mode 100644 index 8e97e78..0000000 --- a/server/enemies/enemy_factory_interface.hpp +++ /dev/null @@ -1,49 +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 ENEMYFACTORYINTERFACE_HPP_ -#define ENEMYFACTORYINTERFACE_HPP_ - -#include "enemy_data.hpp" -#include "map_type.hpp" - -#include - -//NOTE: Based on biome, world difficulty, etc. -class EnemyFactoryInterface { -public: - EnemyFactoryInterface() = default; - virtual ~EnemyFactoryInterface() = default; - - virtual void Generate(std::list* container) = 0; - - //control the difficulty of the room - MapType SetType(MapType t) { return type = t; } - MapType GetType() { return type; } - - int SetDifficulty(int d) { return difficulty = d; } - int GetDifficulty() { return difficulty; } -protected: - MapType type; - int difficulty = 0; -}; - -#endif diff --git a/server/linit.cpp b/server/linit.cpp index 8108a49..1d79c96 100644 --- a/server/linit.cpp +++ b/server/linit.cpp @@ -40,7 +40,6 @@ #include "region_pager_api.hpp" #include "room_api.hpp" #include "room_mgr_api.hpp" -#include "generator_api.hpp" //these libs are loaded by lua.c and are readily available to any Lua program static const luaL_Reg loadedlibs[] = { @@ -61,7 +60,6 @@ static const luaL_Reg loadedlibs[] = { {TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI}, {TORTUGA_ROOM_NAME, openRoomAPI}, {TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI}, - {TORTUGA_GENRATOR_NAME, openGeneratorAPI}, {NULL, NULL} }; diff --git a/server/makefile b/server/makefile index 642dec3..3d0de76 100644 --- a/server/makefile +++ b/server/makefile @@ -20,7 +20,6 @@ all: $(OBJ) $(OUT) $(MAKE) -C characters $(MAKE) -C combat $(MAKE) -C enemies - $(MAKE) -C mapgen $(MAKE) -C rooms $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) diff --git a/server/mapgen/generator_api.cpp b/server/mapgen/generator_api.cpp deleted file mode 100644 index f3cc84f..0000000 --- a/server/mapgen/generator_api.cpp +++ /dev/null @@ -1,79 +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. -*/ -#include "generator_api.hpp" - -#include "base_generator.hpp" - -static int getMapType(lua_State* L) { - BaseGenerator* ptr = reinterpret_cast(lua_touserdata(L, 1)); - switch(ptr->GetMapType()) { - case MapType::NONE: - lua_pushstring(L, "none"); - break; - case MapType::OVERWORLD: - lua_pushstring(L, "overworld"); - break; - case MapType::RUINS: - lua_pushstring(L, "ruins"); - break; - case MapType::TOWERS: - lua_pushstring(L, "towers"); - break; - case MapType::FORESTS: - lua_pushstring(L, "forests"); - break; - case MapType::CAVES: - lua_pushstring(L, "caves"); - break; - } - return 1; -} - -static int getChunk(lua_State* L) { - BaseGenerator* ptr = reinterpret_cast(lua_touserdata(L, 1)); - ChunkData* chunk = ptr->GetChunk(lua_tointeger(L, 2), lua_tointeger(L, 3)); - lua_pushlightuserdata(L, reinterpret_cast(chunk)); - return 1; -} - -static int getMapWidth(lua_State* L) { - lua_pushinteger(L, MAP_WIDTH); - return 1; -} - -static int getMapHeight(lua_State* L) { - lua_pushinteger(L, MAP_HEIGHT); - return 1; -} - -static const luaL_Reg generatorLib[] = { - {"GetMapType", getMapType}, - {"GetChunk", getChunk}, - {"GetMapWidth", getMapWidth}, - {"GetMapHeight", getMapHeight}, - {nullptr, nullptr} -}; - -LUAMOD_API int openGeneratorAPI(lua_State* L) { - luaL_newlib(L, generatorLib); - return 1; -} diff --git a/server/mapgen/generator_api.hpp b/server/mapgen/generator_api.hpp deleted file mode 100644 index 78c24c2..0000000 --- a/server/mapgen/generator_api.hpp +++ /dev/null @@ -1,30 +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 GENERATORAPI_HPP_ -#define GENERATORAPI_HPP_ - -#include "lua/lua.hpp" - -#define TORTUGA_GENRATOR_NAME "Generator" -LUAMOD_API int openGeneratorAPI(lua_State* L); - -#endif \ No newline at end of file diff --git a/server/mapgen/generators/base_generator.cpp b/server/mapgen/generators/base_generator.cpp deleted file mode 100644 index 9afab6b..0000000 --- a/server/mapgen/generators/base_generator.cpp +++ /dev/null @@ -1,36 +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. -*/ -#include "base_generator.hpp" - -BaseGenerator::BaseGenerator(MapType t) { - mapType = t; - for (int i = 0; i < MAP_WIDTH; i++) { - for (int j = 0; j < MAP_HEIGHT; j++) { - chunks[i][j].type = TerrainType::NONE; - chunks[i][j].mod = ChunkData::Moddable::CLEAR; - } - } -} - -BaseGenerator::~BaseGenerator() { - // -} \ No newline at end of file diff --git a/server/mapgen/generators/base_generator.hpp b/server/mapgen/generators/base_generator.hpp deleted file mode 100644 index 6d629cd..0000000 --- a/server/mapgen/generators/base_generator.hpp +++ /dev/null @@ -1,54 +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 BASEGENERATOR_HPP_ -#define BASEGENERATOR_HPP_ - -#include "map_type.hpp" -#include "chunk_data.hpp" - -#include "lua/lua.hpp" - -constexpr int MAP_WIDTH = 256; -constexpr int MAP_HEIGHT = 256; - -class BaseGenerator { -public: - virtual ~BaseGenerator(); - - //accessors and mutators - virtual ChunkData* GetChunk(int x, int y) { return &chunks[x][y]; } - - MapType GetMapType() { return mapType; } - - lua_State* SetLuaState(lua_State* L) { return luaState = L; } - lua_State* GetLuaState() { return luaState; } - -protected: - BaseGenerator() = delete; - BaseGenerator(MapType t); - - ChunkData chunks[MAP_WIDTH][MAP_HEIGHT]; - MapType mapType = MapType::NONE; - lua_State* luaState = nullptr; -}; - -#endif diff --git a/server/mapgen/generators/caves_generator.cpp b/server/mapgen/generators/caves_generator.cpp deleted file mode 100644 index 0019bf5..0000000 --- a/server/mapgen/generators/caves_generator.cpp +++ /dev/null @@ -1,30 +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. -*/ -#include "caves_generator.hpp" - -CavesGenerator::CavesGenerator() : BaseGenerator(MapType::CAVES) { - // -} - -CavesGenerator::~CavesGenerator() { - // -} \ No newline at end of file diff --git a/server/mapgen/generators/caves_generator.hpp b/server/mapgen/generators/caves_generator.hpp deleted file mode 100644 index 062a86d..0000000 --- a/server/mapgen/generators/caves_generator.hpp +++ /dev/null @@ -1,36 +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 CAVESGENERATOR_HPP_ -#define CAVESGENERATOR_HPP_ - -#include "base_generator.hpp" - -class CavesGenerator : public BaseGenerator { -public: - CavesGenerator(); - ~CavesGenerator(); - -private: - // -}; - -#endif diff --git a/server/mapgen/generators/forests_generator.cpp b/server/mapgen/generators/forests_generator.cpp deleted file mode 100644 index cbff079..0000000 --- a/server/mapgen/generators/forests_generator.cpp +++ /dev/null @@ -1,30 +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. -*/ -#include "forests_generator.hpp" - -ForestsGenerator::ForestsGenerator() : BaseGenerator(MapType::FORESTS) { - // -} - -ForestsGenerator::~ForestsGenerator() { - // -} \ No newline at end of file diff --git a/server/mapgen/generators/forests_generator.hpp b/server/mapgen/generators/forests_generator.hpp deleted file mode 100644 index 459428f..0000000 --- a/server/mapgen/generators/forests_generator.hpp +++ /dev/null @@ -1,36 +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 FORESTSGENERATOR_HPP_ -#define FORESTSGENERATOR_HPP_ - -#include "base_generator.hpp" - -class ForestsGenerator : public BaseGenerator { -public: - ForestsGenerator(); - ~ForestsGenerator(); - -private: - // -}; - -#endif diff --git a/server/mapgen/generators/makefile b/server/mapgen/generators/makefile deleted file mode 100644 index 3e4ed5b..0000000 --- a/server/mapgen/generators/makefile +++ /dev/null @@ -1,37 +0,0 @@ -#config -INCLUDES+=. .. -LIBS+= -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) - -#source -CXXSRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) - -#output -OUTDIR=../.. -OUT=$(addprefix $(OUTDIR)/,server.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/server/mapgen/generators/overworld_generator.cpp b/server/mapgen/generators/overworld_generator.cpp deleted file mode 100644 index 7bcd1c5..0000000 --- a/server/mapgen/generators/overworld_generator.cpp +++ /dev/null @@ -1,30 +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. -*/ -#include "overworld_generator.hpp" - -OverworldGenerator::OverworldGenerator() : BaseGenerator(MapType::OVERWORLD) { - // -} - -OverworldGenerator::~OverworldGenerator() { - // -} \ No newline at end of file diff --git a/server/mapgen/generators/overworld_generator.hpp b/server/mapgen/generators/overworld_generator.hpp deleted file mode 100644 index 63fd418..0000000 --- a/server/mapgen/generators/overworld_generator.hpp +++ /dev/null @@ -1,36 +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 OVERWORLDGENERATOR_HPP_ -#define OVERWORLDGENERATOR_HPP_ - -#include "base_generator.hpp" - -class OverworldGenerator : public BaseGenerator { -public: - OverworldGenerator(); - ~OverworldGenerator(); - -private: - // -}; - -#endif diff --git a/server/mapgen/generators/ruins_generator.cpp b/server/mapgen/generators/ruins_generator.cpp deleted file mode 100644 index 164de89..0000000 --- a/server/mapgen/generators/ruins_generator.cpp +++ /dev/null @@ -1,30 +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. -*/ -#include "ruins_generator.hpp" - -RuinsGenerator::RuinsGenerator() : BaseGenerator(MapType::RUINS) { - // -} - -RuinsGenerator::~RuinsGenerator() { - // -} \ No newline at end of file diff --git a/server/mapgen/generators/ruins_generator.hpp b/server/mapgen/generators/ruins_generator.hpp deleted file mode 100644 index fbc0518..0000000 --- a/server/mapgen/generators/ruins_generator.hpp +++ /dev/null @@ -1,36 +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 RUINSGENERATOR_HPP_ -#define RUINSGENERATOR_HPP_ - -#include "base_generator.hpp" - -class RuinsGenerator : public BaseGenerator { -public: - RuinsGenerator(); - ~RuinsGenerator(); - -private: - // -}; - -#endif diff --git a/server/mapgen/generators/towers_generator.cpp b/server/mapgen/generators/towers_generator.cpp deleted file mode 100644 index ad50a09..0000000 --- a/server/mapgen/generators/towers_generator.cpp +++ /dev/null @@ -1,30 +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. -*/ -#include "towers_generator.hpp" - -TowersGenerator::TowersGenerator() : BaseGenerator(MapType::TOWERS) { - // -} - -TowersGenerator::~TowersGenerator() { - // -} \ No newline at end of file diff --git a/server/mapgen/generators/towers_generator.hpp b/server/mapgen/generators/towers_generator.hpp deleted file mode 100644 index 48a29bb..0000000 --- a/server/mapgen/generators/towers_generator.hpp +++ /dev/null @@ -1,36 +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 TOWERSGENERATOR_HPP_ -#define TOWERSGENERATOR_HPP_ - -#include "base_generator.hpp" - -class TowersGenerator : public BaseGenerator { -public: - TowersGenerator(); - ~TowersGenerator(); - -private: - // -}; - -#endif diff --git a/server/mapgen/makefile b/server/mapgen/makefile deleted file mode 100644 index 9a44bb4..0000000 --- a/server/mapgen/makefile +++ /dev/null @@ -1,38 +0,0 @@ -#config -INCLUDES+=. generators -LIBS+= -CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) - -#source -CXXSRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) - -#output -OUTDIR=.. -OUT=$(addprefix $(OUTDIR)/,server.a) - -#targets -all: $(OBJ) $(OUT) - ar -crs $(OUT) $(OBJ) - $(MAKE) -C generators - -$(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/server/mapgen/map_type.hpp b/server/mapgen/map_type.hpp deleted file mode 100644 index e56b924..0000000 --- a/server/mapgen/map_type.hpp +++ /dev/null @@ -1,34 +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 MAPTYPE_HPP_ -#define MAPTYPE_HPP_ - -enum class MapType { - NONE, - OVERWORLD, - RUINS, - TOWERS, - FORESTS, - CAVES, -}; - -#endif \ No newline at end of file diff --git a/server/mapgen/terrain_type.hpp b/server/mapgen/terrain_type.hpp deleted file mode 100644 index aadfaa9..0000000 --- a/server/mapgen/terrain_type.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 TERRAINTYPE_HPP_ -#define TERRAINTYPE_HPP_ - -enum class TerrainType { - //default: something's wrong - NONE = 0, - - //standard overworld - PLAINS, - GRASS, - DIRT, - SAND, - WATER, - - //not used - LAST, -}; - -#endif diff --git a/server/rooms/room_api.cpp b/server/rooms/room_api.cpp index 3f217a8..2f1d103 100644 --- a/server/rooms/room_api.cpp +++ b/server/rooms/room_api.cpp @@ -29,12 +29,6 @@ static int getPager(lua_State* L) { return 1; } -static int getGenerator(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_pushlightuserdata(L, reinterpret_cast(room->generator)); - return 1; -} - static int onCreate(lua_State* L) { //TODO: onCreate() return 0; @@ -49,7 +43,6 @@ static int onUnload(lua_State* L) { static const luaL_Reg roomLib[] = { {"GetPager",getPager}, - {"GetGenerator",getGenerator}, {"OnCreate", onCreate}, {"OnUnload", onUnload}, {nullptr, nullptr} diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp index 660e057..4f1b669 100644 --- a/server/rooms/room_data.hpp +++ b/server/rooms/room_data.hpp @@ -23,14 +23,11 @@ #define ROOMDATA_HPP_ //map system -#include "map_type.hpp" #include "region_pager_lua.hpp" -#include "base_generator.hpp" struct RoomData { //members RegionPagerLua pager; - BaseGenerator* generator = nullptr; //TODO: collision map //TODO: NPCs? diff --git a/server/rooms/room_manager.cpp b/server/rooms/room_manager.cpp index 3e4ec87..81e83a5 100644 --- a/server/rooms/room_manager.cpp +++ b/server/rooms/room_manager.cpp @@ -21,41 +21,19 @@ */ #include "room_manager.hpp" -//the generator types -#include "overworld_generator.hpp" -#include "ruins_generator.hpp" -#include "towers_generator.hpp" -#include "forests_generator.hpp" -#include "caves_generator.hpp" - #include //------------------------- //public access methods //------------------------- -RoomData* RoomManager::CreateRoom(MapType mapType) { +RoomData* RoomManager::CreateRoom() { //create the room RoomData* newRoom = new RoomData(); - //create the generator, use a lambda because I'm lazy - newRoom->generator = [mapType]() -> BaseGenerator* { - switch(mapType) { - //BUG: Not having a map type results in an overworld generator by default - case MapType::NONE: - case MapType::OVERWORLD: return new OverworldGenerator(); - case MapType::RUINS: return new RuinsGenerator(); - case MapType::TOWERS: return new TowersGenerator(); - case MapType::FORESTS: return new ForestsGenerator(); - case MapType::CAVES: return new CavesGenerator(); - } - throw(std::runtime_error("Failed to set the room's generator")); - }(); - //set the state if (luaState) { newRoom->pager.SetLuaState(luaState); - newRoom->generator->SetLuaState(luaState); } //register the room @@ -91,15 +69,12 @@ void RoomManager::UnloadRoom(int uid) { lua_pop(luaState, 1); //free the memory - delete room->generator; delete room; roomMap.erase(uid); } RoomData* RoomManager::GetRoom(int uid) { - RoomData* ptr = FindRoom(uid); - if (ptr) return ptr; - return CreateRoom(MapType::NONE); + return FindRoom(uid); } RoomData* RoomManager::FindRoom(int uid) { diff --git a/server/rooms/room_manager.hpp b/server/rooms/room_manager.hpp index 02c5b32..71c2bbf 100644 --- a/server/rooms/room_manager.hpp +++ b/server/rooms/room_manager.hpp @@ -36,7 +36,7 @@ public: ~RoomManager() = default; //public access methods - RoomData* CreateRoom(MapType); + RoomData* CreateRoom(); void UnloadRoom(int uid); RoomData* GetRoom(int uid); diff --git a/server/rooms/room_mgr_api.cpp b/server/rooms/room_mgr_api.cpp index 9907896..3c96f4e 100644 --- a/server/rooms/room_mgr_api.cpp +++ b/server/rooms/room_mgr_api.cpp @@ -46,18 +46,8 @@ static int createRoom(lua_State* L) { lua_gettable(L, LUA_REGISTRYINDEX); RoomManager* roomMgr = reinterpret_cast(lua_touserdata(L, -1)); - //determine the specified room type - MapType mapType = [L]() -> MapType { - if (std::string("overworld") == lua_tostring(L, -2)) return MapType::OVERWORLD; - if (std::string("ruins") == lua_tostring(L, -2)) return MapType::RUINS; - if (std::string("towers") == lua_tostring(L, -2)) return MapType::TOWERS; - if (std::string("forests") == lua_tostring(L, -2)) return MapType::FORESTS; - if (std::string("caves") == lua_tostring(L, -2)) return MapType::CAVES; - return MapType::NONE; - }(); - //create the room - RoomData* newRoom = roomMgr->CreateRoom(mapType); + RoomData* newRoom = roomMgr->CreateRoom(); //return the new room lua_pushlightuserdata(L, newRoom); From 28d083cba4896d084c96c58e707543e7a89a96fa Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 3 Jul 2014 01:41:58 +1000 Subject: [PATCH 08/10] Hammered out server-side issues, read more * Removed the client-only code from CharacterData, including the .cpp file * Removed CombatManager and EnemyManager instanciation --- client/character_data.hpp | 2 +- common/ui/menu_bar.hpp | 1 + server/characters/character_data.cpp | 67 ---------------------------- server/characters/character_data.hpp | 26 +---------- server/client_data.hpp | 1 + server/rooms/room_manager.cpp | 1 + server/server_application.cpp | 19 ++------ server/server_application.hpp | 14 +----- 8 files changed, 12 insertions(+), 119 deletions(-) delete mode 100644 server/characters/character_data.cpp diff --git a/client/character_data.hpp b/client/character_data.hpp index ec8f12d..8756346 100644 --- a/client/character_data.hpp +++ b/client/character_data.hpp @@ -34,7 +34,7 @@ #include #include -//TODO: encapsulate this +//TODO: encapsulate this and the server version struct CharacterData { //metadata int owner; diff --git a/common/ui/menu_bar.hpp b/common/ui/menu_bar.hpp index fdaf45c..e4dd392 100644 --- a/common/ui/menu_bar.hpp +++ b/common/ui/menu_bar.hpp @@ -36,6 +36,7 @@ * This class needs a rewrite. */ +//TODO: This thing is fucking terrible, fix it and the button class class MenuBar { public: MenuBar() = default; diff --git a/server/characters/character_data.cpp b/server/characters/character_data.cpp deleted file mode 100644 index 9824c79..0000000 --- a/server/characters/character_data.cpp +++ /dev/null @@ -1,67 +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. -*/ -#include "character_data.hpp" - -void CharacterData::Update(double delta) { - if (motion.x && motion.y) { - origin += motion * delta * CHARACTER_WALKING_MOD; - } - else if (motion != 0) { - origin += motion * delta; - } -#ifdef GRAPHICS - sprite.Update(delta); -#endif -} - -#ifdef GRAPHICS - -void CharacterData::DrawTo(SDL_Surface* const dest, int camX, int camY) { - sprite.DrawTo(dest, origin.x - camX, origin.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/server/characters/character_data.hpp b/server/characters/character_data.hpp index fd9f553..5650e36 100644 --- a/server/characters/character_data.hpp +++ b/server/characters/character_data.hpp @@ -22,26 +22,15 @@ #ifndef CHARACTERDATA_HPP_ #define CHARACTERDATA_HPP_ +//components +#include "character_defines.hpp" #include "vector2.hpp" #include "statistics.hpp" -//graphics -#ifdef GRAPHICS - #include "sprite_sheet.hpp" -#endif - //std namespace #include #include -//the speeds that the characters move -constexpr double CHARACTER_WALKING_SPEED = 140.0; -constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); - -//the bounding boxes for the characters -constexpr double CHARACTER_BOUNDS_WIDTH = 32.0; -constexpr double CHARACTER_BOUNDS_HEIGHT = 32.0; - struct CharacterData { //metadata int owner; @@ -58,19 +47,8 @@ struct CharacterData { //TODO: gameplay components: equipment, items, buffs, 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 - Vector2 bounds = {0.0,0.0}; - SpriteSheet sprite; -#endif bool inCombat = false; int atbGauge = 0; //TODO: stored command diff --git a/server/client_data.hpp b/server/client_data.hpp index 7410b08..4a9c5bc 100644 --- a/server/client_data.hpp +++ b/server/client_data.hpp @@ -26,6 +26,7 @@ struct ClientData { IPaddress address = {0,0}; + //TODO: ping system? }; #endif diff --git a/server/rooms/room_manager.cpp b/server/rooms/room_manager.cpp index 81e83a5..5560050 100644 --- a/server/rooms/room_manager.cpp +++ b/server/rooms/room_manager.cpp @@ -75,6 +75,7 @@ void RoomManager::UnloadRoom(int uid) { RoomData* RoomManager::GetRoom(int uid) { return FindRoom(uid); + //TODO: expand this to auto-create the room } RoomData* RoomManager::FindRoom(int uid) { diff --git a/server/server_application.cpp b/server/server_application.cpp index 7396cda..0a4ebc0 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -21,8 +21,11 @@ */ #include "server_application.hpp" -#include "sql_utility.hpp" +//for PACKET_BUFFER_SIZE #include "serial.hpp" + +//utility functions +#include "sql_utility.hpp" #include "utility.hpp" #include @@ -80,9 +83,7 @@ void ServerApplication::Init(int argc, char** argv) { accountMgr.SetDatabase(database); characterMgr.SetDatabase(database); - combatMgr.SetLuaState(luaState); roomMgr.SetLuaState(luaState); - enemyMgr.SetLuaState(luaState); std::cout << "Internal managers set" << std::endl; @@ -355,12 +356,6 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) { network.SendTo(&argPacket->srcAddress, static_cast(&newPacket)); } -//------------------------- -//combat management -//------------------------- - -//TODO: combat management - //------------------------- //Character Management //------------------------- @@ -439,12 +434,6 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket) PumpPacket(argPacket); } -//------------------------- -//enemy management -//------------------------- - -//TODO: enemy management - //------------------------- //mismanagement //------------------------- diff --git a/server/server_application.hpp b/server/server_application.hpp index ca2129b..c5d0c1d 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -22,12 +22,10 @@ #ifndef SERVERAPPLICATION_HPP_ #define SERVERAPPLICATION_HPP_ -//server specific stuff +//server specific stuff, mostly managers +#include "client_data.hpp" #include "account_manager.hpp" #include "character_manager.hpp" -#include "client_data.hpp" -#include "combat_manager.hpp" -#include "enemy_manager.hpp" #include "room_manager.hpp" //common utilities @@ -67,17 +65,11 @@ private: //map management void HandleRegionRequest(RegionPacket* const); - //combat management - //TODO: combat management - //character management void HandleCharacterNew(CharacterPacket* const); void HandleCharacterDelete(CharacterPacket* const); void HandleCharacterUpdate(CharacterPacket* const); - //enemy management - //TODO: enemy management - //mismanagement void HandleSynchronize(ClientPacket* const); @@ -99,8 +91,6 @@ private: //managers AccountManager accountMgr; CharacterManager characterMgr; - CombatManager combatMgr; - EnemyManager enemyMgr; RoomManager roomMgr; //misc From 36d30ce39bca167229b9075a7d3c338dded7be6d Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 3 Jul 2014 02:01:53 +1000 Subject: [PATCH 09/10] Moved the scenes into a subdirectory --- client/combat_data.hpp | 1 + client/enemy_data.hpp | 1 + client/makefile | 5 ++-- client/{ => scenes}/base_scene.cpp | 0 client/{ => scenes}/base_scene.hpp | 0 client/{ => scenes}/clean_up.cpp | 0 client/{ => scenes}/clean_up.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/scenes/makefile | 37 +++++++++++++++++++++++++++ client/{ => scenes}/options_menu.cpp | 0 client/{ => scenes}/options_menu.hpp | 0 client/{ => scenes}/splash_screen.cpp | 0 client/{ => scenes}/splash_screen.hpp | 0 20 files changed, 42 insertions(+), 2 deletions(-) rename client/{ => scenes}/base_scene.cpp (100%) rename client/{ => scenes}/base_scene.hpp (100%) rename client/{ => scenes}/clean_up.cpp (100%) rename client/{ => scenes}/clean_up.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%) create mode 100644 client/scenes/makefile rename client/{ => scenes}/options_menu.cpp (100%) rename client/{ => scenes}/options_menu.hpp (100%) rename client/{ => scenes}/splash_screen.cpp (100%) rename client/{ => scenes}/splash_screen.hpp (100%) diff --git a/client/combat_data.hpp b/client/combat_data.hpp index 683e66f..1d6eb70 100644 --- a/client/combat_data.hpp +++ b/client/combat_data.hpp @@ -34,6 +34,7 @@ #include #include +//NOTE: This is a placeholder, since it'd break to client too much to remove it struct CombatData { typedef std::chrono::steady_clock Clock; diff --git a/client/enemy_data.hpp b/client/enemy_data.hpp index ab1ef89..6cd85f5 100644 --- a/client/enemy_data.hpp +++ b/client/enemy_data.hpp @@ -28,6 +28,7 @@ //std namespace #include +//NOTE: This is a placeholder, since it'd break to client too much to remove it struct EnemyData { //metadata std::string handle; diff --git a/client/makefile b/client/makefile index 9a2a0ca..97d8949 100644 --- a/client/makefile +++ b/client/makefile @@ -1,6 +1,6 @@ #config -INCLUDES+=. ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities -LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua +INCLUDES+=. scenes ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities +LIBS+=client.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source @@ -16,6 +16,7 @@ OUT=$(addprefix $(OUTDIR)/,client) #targets all: $(OBJ) $(OUT) + $(MAKE) -C scenes $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(OBJ): | $(OBJDIR) diff --git a/client/base_scene.cpp b/client/scenes/base_scene.cpp similarity index 100% rename from client/base_scene.cpp rename to client/scenes/base_scene.cpp diff --git a/client/base_scene.hpp b/client/scenes/base_scene.hpp similarity index 100% rename from client/base_scene.hpp rename to client/scenes/base_scene.hpp diff --git a/client/clean_up.cpp b/client/scenes/clean_up.cpp similarity index 100% rename from client/clean_up.cpp rename to client/scenes/clean_up.cpp diff --git a/client/clean_up.hpp b/client/scenes/clean_up.hpp similarity index 100% rename from client/clean_up.hpp rename to client/scenes/clean_up.hpp diff --git a/client/in_combat.cpp b/client/scenes/in_combat.cpp similarity index 100% rename from client/in_combat.cpp rename to client/scenes/in_combat.cpp diff --git a/client/in_combat.hpp b/client/scenes/in_combat.hpp similarity index 100% rename from client/in_combat.hpp rename to client/scenes/in_combat.hpp diff --git a/client/in_world.cpp b/client/scenes/in_world.cpp similarity index 100% rename from client/in_world.cpp rename to client/scenes/in_world.cpp diff --git a/client/in_world.hpp b/client/scenes/in_world.hpp similarity index 100% rename from client/in_world.hpp rename to client/scenes/in_world.hpp diff --git a/client/lobby_menu.cpp b/client/scenes/lobby_menu.cpp similarity index 100% rename from client/lobby_menu.cpp rename to client/scenes/lobby_menu.cpp diff --git a/client/lobby_menu.hpp b/client/scenes/lobby_menu.hpp similarity index 100% rename from client/lobby_menu.hpp rename to client/scenes/lobby_menu.hpp diff --git a/client/main_menu.cpp b/client/scenes/main_menu.cpp similarity index 100% rename from client/main_menu.cpp rename to client/scenes/main_menu.cpp diff --git a/client/main_menu.hpp b/client/scenes/main_menu.hpp similarity index 100% rename from client/main_menu.hpp rename to client/scenes/main_menu.hpp diff --git a/client/scenes/makefile b/client/scenes/makefile new file mode 100644 index 0000000..4e050c7 --- /dev/null +++ b/client/scenes/makefile @@ -0,0 +1,37 @@ +#config +INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet ../../common/network/serial ../../common/ui ../../common/utilities +LIBS+= +CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) + +#source +CXXSRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) + +#output +OUTDIR=.. +OUT=$(addprefix $(OUTDIR)/,client.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/options_menu.cpp b/client/scenes/options_menu.cpp similarity index 100% rename from client/options_menu.cpp rename to client/scenes/options_menu.cpp diff --git a/client/options_menu.hpp b/client/scenes/options_menu.hpp similarity index 100% rename from client/options_menu.hpp rename to client/scenes/options_menu.hpp diff --git a/client/splash_screen.cpp b/client/scenes/splash_screen.cpp similarity index 100% rename from client/splash_screen.cpp rename to client/scenes/splash_screen.cpp diff --git a/client/splash_screen.hpp b/client/scenes/splash_screen.hpp similarity index 100% rename from client/splash_screen.hpp rename to client/scenes/splash_screen.hpp From e946a0741de3a68b74af4a74f2689ac8344f5486 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 4 Jul 2014 00:55:12 +1000 Subject: [PATCH 10/10] Encapsulated the Character class --- client/{character_data.cpp => character.cpp} | 8 +- client/{character_data.hpp => character.hpp} | 71 +++++--- client/client_application.cpp | 6 +- client/client_application.hpp | 8 +- client/combat_data.hpp | 53 ------ client/enemy_data.hpp | 48 ------ client/scenes/clean_up.cpp | 12 +- client/scenes/clean_up.hpp | 12 +- client/scenes/in_combat.cpp | 8 +- client/scenes/in_combat.hpp | 12 +- client/scenes/in_world.cpp | 163 ++++++++----------- client/scenes/in_world.hpp | 11 +- 12 files changed, 143 insertions(+), 269 deletions(-) rename client/{character_data.cpp => character.cpp} (89%) rename client/{character_data.hpp => character.hpp} (58%) delete mode 100644 client/combat_data.hpp delete mode 100644 client/enemy_data.hpp diff --git a/client/character_data.cpp b/client/character.cpp similarity index 89% rename from client/character_data.cpp rename to client/character.cpp index 81e4c75..eaa38d8 100644 --- a/client/character_data.cpp +++ b/client/character.cpp @@ -19,9 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#include "character_data.hpp" +#include "character.hpp" -void CharacterData::Update(double delta) { +void Character::Update(double delta) { if (motion.x && motion.y) { origin += motion * delta * CHARACTER_WALKING_MOD; } @@ -31,11 +31,11 @@ void CharacterData::Update(double delta) { sprite.Update(delta); } -void CharacterData::DrawTo(SDL_Surface* const dest, int camX, int camY) { +void Character::DrawTo(SDL_Surface* const dest, int camX, int camY) { sprite.DrawTo(dest, origin.x - camX, origin.y - camY); } -void CharacterData::CorrectSprite() { +void Character::CorrectSprite() { //NOTE: These must correspond to the sprite sheet in use if (motion.y > 0) { sprite.SetYIndex(0); diff --git a/client/character_data.hpp b/client/character.hpp similarity index 58% rename from client/character_data.hpp rename to client/character.hpp index 8756346..ca2d9a4 100644 --- a/client/character_data.hpp +++ b/client/character.hpp @@ -19,8 +19,8 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CHARACTERDATA_HPP_ -#define CHARACTERDATA_HPP_ +#ifndef CHARACTER_HPP_ +#define CHARACTER_HPP_ //components #include "character_defines.hpp" @@ -34,38 +34,61 @@ #include #include -//TODO: encapsulate this and the server version -struct CharacterData { +class Character { +public: + Character() = default; + ~Character() = default; + + void Update(double delta); + + //graphics + void DrawTo(SDL_Surface* const, int camX, int camY); + void CorrectSprite(); + SpriteSheet* GetSprite() { return &sprite; } + + //gameplay + Statistics* GetStats() { return &stats; } + + //accessors and mutators + //metadata - int owner; - std::string handle; - std::string avatar; + int SetOwner(int i) { return owner = i; } + int GetOwner() { return owner; } + std::string SetHandle(std::string s) { return handle = s; } + std::string GetHandle() const { return handle; } + std::string SetAvatar(std::string s) { return avatar = s; } + std::string GetAvatar() const { return avatar; } - //members + //position + Vector2 SetOrigin(Vector2 v) { return origin = v; } + Vector2 GetOrigin() const { return origin; } + Vector2 SetMotion(Vector2 v) { return motion = v; } + Vector2 GetMotion() const { return motion; } + Vector2 SetBounds(Vector2 v) { return bounds = v; } + Vector2 GetBounds() const { return bounds; } + +private: + //graphics SpriteSheet sprite; - //world position - int roomIndex = 0; - Vector2 origin = {0.0,0.0}; - Vector2 motion = {0.0,0.0}; - Vector2 bounds = {0.0,0.0}; - //base statistics Statistics stats; //TODO: gameplay components: equipment, items, buffs, debuffs - //methods - void Update(double delta); + //metadata + int owner; + std::string handle; + std::string avatar; - void DrawTo(SDL_Surface* const, int camX, int camY); - void CorrectSprite(); - - //active gameplay members - //NOTE: these are lost when unloaded - bool inCombat = false; - int atbGauge = 0; - //TODO: stored command + //position + Vector2 origin = {0.0,0.0}; + Vector2 motion = {0.0,0.0}; + Vector2 bounds = {CHARACTER_BOUNDS_WIDTH,CHARACTER_BOUNDS_HEIGHT}; }; +//tmp +#include +typedef std::map CharacterMap; + #endif diff --git a/client/client_application.cpp b/client/client_application.cpp index 95f529c..991cfd6 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -177,13 +177,13 @@ void ClientApplication::LoadScene(SceneList sceneIndex) { activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex); break; case SceneList::INWORLD: - activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap); + activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &characterMap); break; case SceneList::INCOMBAT: - activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap); + activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &characterMap); break; case SceneList::CLEANUP: - activeScene = new CleanUp(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap); + activeScene = new CleanUp(&config, &network, &clientIndex, &accountIndex, &characterIndex, &characterMap); 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 54df4ff..2efb742 100644 --- a/client/client_application.hpp +++ b/client/client_application.hpp @@ -27,9 +27,7 @@ #include "config_utility.hpp" #include "udp_network_utility.hpp" -#include "character_data.hpp" -#include "combat_data.hpp" -#include "enemy_data.hpp" +#include "character.hpp" #include @@ -56,9 +54,7 @@ private: int accountIndex = -1; int characterIndex = -1; - std::map combatMap; - std::map characterMap; - std::map enemyMap; + CharacterMap characterMap; }; #endif diff --git a/client/combat_data.hpp b/client/combat_data.hpp deleted file mode 100644 index 1d6eb70..0000000 --- a/client/combat_data.hpp +++ /dev/null @@ -1,53 +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 COMBATDATA_HPP_ -#define COMBATDATA_HPP_ - -#include "vector2.hpp" -#include "combat_defines.hpp" - -//gameplay members -#include "character_data.hpp" -#include "enemy_data.hpp" - -//std namespace -#include -#include -#include - -//NOTE: This is a placeholder, since it'd break to client too much to remove it -struct CombatData { - typedef std::chrono::steady_clock Clock; - - std::array characterArray; - std::array enemyArray; - - //world interaction - int mapIndex = 0; - Vector2 origin = {0.0,0.0}; - Vector2 bounds = {0.0,0.0}; - - //time interval - Clock::time_point lastTick = Clock::now(); -}; - -#endif diff --git a/client/enemy_data.hpp b/client/enemy_data.hpp deleted file mode 100644 index 6cd85f5..0000000 --- a/client/enemy_data.hpp +++ /dev/null @@ -1,48 +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 ENEMYDATA_HPP_ -#define ENEMYDATA_HPP_ - -#include "vector2.hpp" -#include "statistics.hpp" - -//std namespace -#include - -//NOTE: This is a placeholder, since it'd break to client too much to remove it -struct EnemyData { - //metadata - std::string handle; - std::string avatar; - - //gameplay - Statistics stats; - - //TODO: gameplay components: equipment, items, buffs, debuffs, rewards - - //active gameplay members - //NOTE: these are lost when unloaded - int tableIndex; - int atbGauge = 0; -}; - -#endif diff --git a/client/scenes/clean_up.cpp b/client/scenes/clean_up.cpp index f504e16..42ab69c 100644 --- a/client/scenes/clean_up.cpp +++ b/client/scenes/clean_up.cpp @@ -35,18 +35,14 @@ CleanUp::CleanUp( int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex, - std::map* argCombatMap, - std::map* argCharacterMap, - std::map* argEnemyMap + CharacterMap* argCharacterMap ): config(*argConfig), network(*argNetwork), clientIndex(*argClientIndex), accountIndex(*argAccountIndex), characterIndex(*argCharacterIndex), - combatMap(*argCombatMap), - characterMap(*argCharacterMap), - enemyMap(*argEnemyMap) + characterMap(*argCharacterMap) { //setup the utility objects image.LoadSurface(config["dir.interface"] + "button_menu.bmp"); @@ -69,9 +65,9 @@ CleanUp::CleanUp( clientIndex = -1; accountIndex = -1; characterIndex = -1; - combatMap.clear(); +// combatMap.clear(); characterMap.clear(); - enemyMap.clear(); +// enemyMap.clear(); //auto return startTick = std::chrono::steady_clock::now(); diff --git a/client/scenes/clean_up.hpp b/client/scenes/clean_up.hpp index 5618cc7..5586f5c 100644 --- a/client/scenes/clean_up.hpp +++ b/client/scenes/clean_up.hpp @@ -34,9 +34,7 @@ #include "config_utility.hpp" #include "frame_rate.hpp" -#include "combat_data.hpp" -#include "character_data.hpp" -#include "enemy_data.hpp" +#include "character.hpp" //client #include "base_scene.hpp" @@ -53,9 +51,7 @@ public: int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex, - std::map* argCombatMap, - std::map* argCharacterMap, - std::map* argEnemyMap + CharacterMap* argCharacterMap ); ~CleanUp(); @@ -79,9 +75,7 @@ protected: int& clientIndex; int& accountIndex; int& characterIndex; - std::map& combatMap; - std::map& characterMap; - std::map& enemyMap; + CharacterMap& characterMap; //graphics Image image; diff --git a/client/scenes/in_combat.cpp b/client/scenes/in_combat.cpp index 3d8b2f3..68c1bec 100644 --- a/client/scenes/in_combat.cpp +++ b/client/scenes/in_combat.cpp @@ -36,18 +36,14 @@ InCombat::InCombat( int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex, - std::map* argCombatMap, - std::map* argCharacterMap, - std::map* argEnemyMap + CharacterMap* argCharacterMap ): config(*argConfig), network(*argNetwork), clientIndex(*argClientIndex), accountIndex(*argAccountIndex), characterIndex(*argCharacterIndex), - combatMap(*argCombatMap), - characterMap(*argCharacterMap), - enemyMap(*argEnemyMap) + characterMap(*argCharacterMap) { /* //setup the utility objects buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); diff --git a/client/scenes/in_combat.hpp b/client/scenes/in_combat.hpp index 6b31bc6..6a84851 100644 --- a/client/scenes/in_combat.hpp +++ b/client/scenes/in_combat.hpp @@ -34,9 +34,7 @@ #include "config_utility.hpp" #include "frame_rate.hpp" -#include "combat_data.hpp" -#include "character_data.hpp" -#include "enemy_data.hpp" +#include "character.hpp" //client #include "base_scene.hpp" @@ -50,9 +48,7 @@ public: int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex, - std::map* argCombatMap, - std::map* argCharacterMap, - std::map* argEnemyMap + CharacterMap* argCharacterMap ); ~InCombat(); @@ -88,9 +84,7 @@ protected: int& clientIndex; int& accountIndex; int& characterIndex; - std::map& combatMap; - std::map& characterMap; - std::map& enemyMap; + CharacterMap& characterMap; //graphics //TODO: graphics diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 5301aa8..4f997a0 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -39,15 +39,13 @@ InWorld::InWorld( int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex, - std::map* argCombatMap, - std::map* argCharacterMap + CharacterMap* argCharacterMap ): config(*argConfig), network(*argNetwork), clientIndex(*argClientIndex), accountIndex(*argAccountIndex), characterIndex(*argCharacterIndex), - combatMap(*argCombatMap), characterMap(*argCharacterMap) { //setup the utility objects @@ -111,8 +109,8 @@ void InWorld::Update(double delta) { //update the camera if(localCharacter) { - camera.x = localCharacter->origin.x - camera.marginX; - camera.y = localCharacter->origin.y - camera.marginY; + camera.x = localCharacter->GetOrigin().x - camera.marginX; + camera.y = localCharacter->GetOrigin().y - camera.marginY; } //check the map @@ -178,77 +176,60 @@ void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) { } void InWorld::KeyDown(SDL_KeyboardEvent const& key) { - switch(key.keysym.sym) { - //player movement - case SDLK_LEFT: - if (localCharacter) { - localCharacter->motion.x -= CHARACTER_WALKING_SPEED; - localCharacter->CorrectSprite(); - SendPlayerUpdate(); - } - break; - - case SDLK_RIGHT: - if (localCharacter) { - localCharacter->motion.x += CHARACTER_WALKING_SPEED; - localCharacter->CorrectSprite(); - SendPlayerUpdate(); - } - break; - - case SDLK_UP: - if (localCharacter) { - localCharacter->motion.y -= CHARACTER_WALKING_SPEED; - localCharacter->CorrectSprite(); - SendPlayerUpdate(); - } - break; - - case SDLK_DOWN: - if (localCharacter) { - localCharacter->motion.y += CHARACTER_WALKING_SPEED; - localCharacter->CorrectSprite(); - SendPlayerUpdate(); - } - break; + if (!localCharacter) { + return; } + + //player movement + Vector2 motion = localCharacter->GetMotion(); + switch(key.keysym.sym) { + case SDLK_LEFT: + motion.x -= CHARACTER_WALKING_SPEED; + break; + case SDLK_RIGHT: + motion.x += CHARACTER_WALKING_SPEED; + break; + case SDLK_UP: + motion.y -= CHARACTER_WALKING_SPEED; + break; + case SDLK_DOWN: + motion.y += CHARACTER_WALKING_SPEED; + break; + default: + return; + } + localCharacter->SetMotion(motion); + localCharacter->CorrectSprite(); + SendPlayerUpdate(); } void InWorld::KeyUp(SDL_KeyboardEvent const& key) { - switch(key.keysym.sym) { - //player movement - case SDLK_LEFT: - if (localCharacter) { - localCharacter->motion.x += CHARACTER_WALKING_SPEED; - localCharacter->CorrectSprite(); - SendPlayerUpdate(); - } - break; - - case SDLK_RIGHT: - if (localCharacter) { - localCharacter->motion.x -= CHARACTER_WALKING_SPEED; - localCharacter->CorrectSprite(); - SendPlayerUpdate(); - } - break; - - case SDLK_UP: - if (localCharacter) { - localCharacter->motion.y += CHARACTER_WALKING_SPEED; - localCharacter->CorrectSprite(); - SendPlayerUpdate(); - } - break; - - case SDLK_DOWN: - if (localCharacter) { - localCharacter->motion.y -= CHARACTER_WALKING_SPEED; - localCharacter->CorrectSprite(); - SendPlayerUpdate(); - } - break; + if (!localCharacter) { + return; } + + //player movement + Vector2 motion = localCharacter->GetMotion(); + switch(key.keysym.sym) { + //NOTE: The use of min/max here are to prevent awkward movements + case SDLK_LEFT: + motion.x = std::min(motion.x + CHARACTER_WALKING_SPEED, 0.0); + break; + case SDLK_RIGHT: + motion.x = std::max(motion.x - CHARACTER_WALKING_SPEED, 0.0); + break; + case SDLK_UP: + motion.y = std::min(motion.y + CHARACTER_WALKING_SPEED, 0.0); + break; + case SDLK_DOWN: + motion.y = std::max(motion.y - CHARACTER_WALKING_SPEED, 0.0); + break; + default: + return; + } + localCharacter->SetMotion(motion); + localCharacter->CorrectSprite(); + SendPlayerUpdate(); } //------------------------- @@ -289,36 +270,35 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) { } //create the character object - CharacterData& character = characterMap[argPacket->characterIndex]; + Character& newCharacter = characterMap[argPacket->characterIndex]; //fill out the character's members - character.handle = argPacket->handle; - character.avatar = argPacket->avatar; + newCharacter.SetHandle(argPacket->handle); + newCharacter.SetAvatar(argPacket->avatar); - character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4); - character.bounds = {CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}; + newCharacter.GetSprite()->LoadSurface(config["dir.sprites"] + newCharacter.GetAvatar(), 4, 4); - character.roomIndex = argPacket->roomIndex; - character.origin = argPacket->origin; - character.motion = argPacket->motion; + newCharacter.SetOrigin(argPacket->origin); + newCharacter.SetMotion(argPacket->motion); - character.stats = argPacket->stats; + (*newCharacter.GetStats()) = argPacket->stats; //bookkeeping code - character.CorrectSprite(); + newCharacter.CorrectSprite(); //catch this client's player object if (argPacket->accountIndex == accountIndex && !localCharacter) { characterIndex = argPacket->characterIndex; - localCharacter = &character; + localCharacter = &newCharacter; //setup the camera + //TODO: move this? 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->GetSprite()->GetImage()->GetClipW() / 2); + camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); } } @@ -341,13 +321,12 @@ void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) { return; } - CharacterData& character = characterMap[argPacket->characterIndex]; + Character& character = characterMap[argPacket->characterIndex]; //other characters moving if (argPacket->characterIndex != characterIndex) { - character.roomIndex = argPacket->roomIndex; - character.origin = argPacket->origin; - character.motion = argPacket->motion; + character.SetOrigin(argPacket->origin); + character.SetMotion(argPacket->motion); character.CorrectSprite(); } } @@ -388,10 +367,10 @@ void InWorld::SendPlayerUpdate() { newPacket.characterIndex = characterIndex; //NOTE: omitting the handle and avatar here newPacket.accountIndex = accountIndex; - newPacket.roomIndex = localCharacter->roomIndex; - newPacket.origin = localCharacter->origin; - newPacket.motion = localCharacter->motion; - newPacket.stats = localCharacter->stats; + newPacket.roomIndex = 0; //TODO: room index + newPacket.origin = localCharacter->GetOrigin(); + newPacket.motion = localCharacter->GetMotion(); + newPacket.stats = *localCharacter->GetStats(); //TODO: gameplay components: equipment, items, buffs, debuffs diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 156d35e..34ce942 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -38,8 +38,7 @@ #include "config_utility.hpp" #include "frame_rate.hpp" -#include "combat_data.hpp" -#include "character_data.hpp" +#include "character.hpp" //client #include "base_scene.hpp" @@ -56,8 +55,7 @@ public: int* const argClientIndex, int* const argAccountIndex, int* const argCharacterIndex, - std::map* argCombatMap, - std::map* argCharacterMap + CharacterMap* argCharacterMap ); ~InWorld(); @@ -101,8 +99,7 @@ protected: int& clientIndex; int& accountIndex; int& characterIndex; - std::map& combatMap; - std::map& characterMap; + CharacterMap& characterMap; //graphics Image buttonImage; @@ -124,7 +121,7 @@ protected: FrameRate fps; //game - CharacterData* localCharacter = nullptr; + Character* localCharacter = nullptr; }; #endif