From f2d79225a30867cea3c83f5210f440efd7d0d6bb Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 6 Nov 2014 01:54:20 +1100 Subject: [PATCH] Created '*_data.cpp' files, modified API files a bit --- common/map/map_system_api.cpp | 32 +++++++++++++++-- server/accounts/account_data.cpp | 54 ++++++++++++++++++++++++++++ server/accounts/account_data.hpp | 16 ++++----- server/characters/character_data.cpp | 38 ++++++++++++++++++++ server/characters/character_data.hpp | 8 ++--- server/entities/entity.cpp | 53 +++++++++++++++++++++++++++ server/entities/entity.hpp | 16 ++++----- server/makefile | 4 +++ server/monsters/monster_manager.hpp | 8 ++--- server/rooms/room_api.cpp | 14 ++++---- server/rooms/room_api.hpp | 2 +- server/rooms/room_data.cpp | 39 ++++++++++++++++++++ server/rooms/room_data.hpp | 20 +++++++---- server/rooms/room_manager_api.hpp | 2 +- todo.txt | 2 ++ 15 files changed, 268 insertions(+), 40 deletions(-) create mode 100644 server/accounts/account_data.cpp create mode 100644 server/characters/character_data.cpp create mode 100644 server/entities/entity.cpp diff --git a/common/map/map_system_api.cpp b/common/map/map_system_api.cpp index 65c0a10..c3a9cca 100644 --- a/common/map/map_system_api.cpp +++ b/common/map/map_system_api.cpp @@ -26,8 +26,30 @@ #include "region_pager_api.hpp" #include "tile_sheet.hpp" -/* This mimics linit.c to create a nested collection of all map modules. -*/ +//useful "globals" +static int getRegionWidth(lua_State* L) { + lua_pushinteger(L, REGION_WIDTH); + return 1; +} + +static int getRegionHeight(lua_State* L) { + lua_pushinteger(L, REGION_HEIGHT); + return 1; +} + +static int getRegionDepth(lua_State* L) { + lua_pushinteger(L, REGION_DEPTH); + return 1; +} + +//This mimics linit.c to create a nested collection of all map modules. +static const luaL_Reg mapfuncs[] = { + //synonyms + {"GetRegionWidth", getRegionWidth}, + {"GetRegionHeight", getRegionHeight}, + {"GetRegionDepth", getRegionDepth}, + {nullptr, nullptr} +}; static const luaL_Reg maplibs[] = { {"Region", openRegionAPI}, @@ -37,7 +59,13 @@ static const luaL_Reg maplibs[] = { }; int openMapSystemAPI(lua_State* L) { + //create the table luaL_newlibtable(L, maplibs); + + //push the "global" functions + luaL_setfuncs(L, mapfuncs, 0); + + //push the substable for (const luaL_Reg* lib = maplibs; lib->func; lib++) { lua_pushcfunction(L, lib->func); lua_setfield(L, -2, lib->name); diff --git a/server/accounts/account_data.cpp b/server/accounts/account_data.cpp new file mode 100644 index 0000000..4b8b872 --- /dev/null +++ b/server/accounts/account_data.cpp @@ -0,0 +1,54 @@ +/* Copyright: (c) Kayne Ruse 2014 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#include "account_data.hpp" + +int AccountData::SetClientIndex(int i) { + return clientIndex = i; +} + +int AccountData::GetClientIndex() { + return clientIndex; +} + +std::string AccountData::SetUsername(std::string s) { + return username = s; +} + +std::string AccountData::GetUsername() { + return username; +} + +bool AccountData::GetBlackListed() { + return blackListed; +} + +bool AccountData::GetWhiteListed() { + return whiteListed; +} + +bool AccountData::GetModerator() { + return mod; +} + +bool AccountData::GetAdministrator() { + return admin; +} \ No newline at end of file diff --git a/server/accounts/account_data.hpp b/server/accounts/account_data.hpp index d7fb022..4d615a4 100644 --- a/server/accounts/account_data.hpp +++ b/server/accounts/account_data.hpp @@ -30,17 +30,17 @@ public: ~AccountData() = default; //accessors and mutators - int SetClientIndex(int i) { return clientIndex = i; } - int GetClientIndex() { return clientIndex; } + int SetClientIndex(int i); + int GetClientIndex(); - std::string SetUsername(std::string s) { return username = s; } - std::string GetUsername() { return username; } + std::string SetUsername(std::string s); + std::string GetUsername(); //database stuff - bool GetBlackListed() { return blackListed; } - bool GetWhiteListed() { return whiteListed; } - bool GetModerator() { return mod; } - bool GetAdministrator() { return admin; } + bool GetBlackListed(); + bool GetWhiteListed(); + bool GetModerator(); + bool GetAdministrator(); private: friend class AccountManager; diff --git a/server/characters/character_data.cpp b/server/characters/character_data.cpp new file mode 100644 index 0000000..359812c --- /dev/null +++ b/server/characters/character_data.cpp @@ -0,0 +1,38 @@ +/* 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" + +Statistics* CharacterData::GetBaseStats() { + return &baseStats; +} + +int CharacterData::GetOwner() { + return owner; +} + +std::string CharacterData::GetHandle() { + return handle; +} + +std::string CharacterData::GetAvatar() { + return avatar; +} \ No newline at end of file diff --git a/server/characters/character_data.hpp b/server/characters/character_data.hpp index aad302c..400f4cb 100644 --- a/server/characters/character_data.hpp +++ b/server/characters/character_data.hpp @@ -37,12 +37,12 @@ public: ~CharacterData() = default; //accessors and mutators - Statistics* GetBaseStats() { return &baseStats; } + Statistics* GetBaseStats(); //database stuff - int GetOwner() { return owner; } - std::string GetHandle() { return handle; } - std::string GetAvatar() { return avatar; } + int GetOwner(); + std::string GetHandle(); + std::string GetAvatar(); private: friend class CharacterManager; diff --git a/server/entities/entity.cpp b/server/entities/entity.cpp new file mode 100644 index 0000000..d22a5d3 --- /dev/null +++ b/server/entities/entity.cpp @@ -0,0 +1,53 @@ +/* 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 "entity.hpp" + +int Entity::SetEntityIndex(int i) { + return entityIndex = i; +} + +int Entity::SetRoomIndex(int i) { + return roomIndex = i; +} + +Vector2 Entity::SetOrigin(Vector2 v) { + return origin = v; +} + +Vector2 Entity::SetMotion(Vector2 v) { + return motion = v; +} +int Entity::GetEntityIndex() { + return entityIndex; +} + +int Entity::GetRoomIndex() { + return roomIndex; +} + +Vector2 Entity::GetOrigin() { + return origin; +} + +Vector2 Entity::GetMotion() { + return motion; +} \ No newline at end of file diff --git a/server/entities/entity.hpp b/server/entities/entity.hpp index f71b04a..8933c38 100644 --- a/server/entities/entity.hpp +++ b/server/entities/entity.hpp @@ -28,15 +28,15 @@ class Entity { public: //accessors & mutators - int SetEntityIndex(int i) { return entityIndex = i; } - int SetRoomIndex(int i) { return roomIndex = i; } - Vector2 SetOrigin(Vector2 v) { return origin = v; } - Vector2 SetMotion(Vector2 v) { return motion = v; } + int SetEntityIndex(int i); + int SetRoomIndex(int i); + Vector2 SetOrigin(Vector2 v); + Vector2 SetMotion(Vector2 v); - int GetEntityIndex() { return entityIndex; } - int GetRoomIndex() { return roomIndex; } - Vector2 GetOrigin() { return origin; } - Vector2 GetMotion() { return motion; } + int GetEntityIndex(); + int GetRoomIndex(); + Vector2 GetOrigin(); + Vector2 GetMotion(); protected: Entity() = default; diff --git a/server/makefile b/server/makefile index 0d87c3e..2cba03c 100644 --- a/server/makefile +++ b/server/makefile @@ -27,6 +27,10 @@ OUT=$(addprefix $(OUTDIR)/,server) all: $(OUT) $(MAKE) -C accounts $(MAKE) -C characters + $(MAKE) -C clients + $(MAKE) -C doors + $(MAKE) -C entities + $(MAKE) -C monsters $(MAKE) -C rooms $(MAKE) -C server_utilities # $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) diff --git a/server/monsters/monster_manager.hpp b/server/monsters/monster_manager.hpp index 20b7826..8a12fbd 100644 --- a/server/monsters/monster_manager.hpp +++ b/server/monsters/monster_manager.hpp @@ -59,10 +59,10 @@ public: std::map* GetContainer() override; //hooks - sqlite3* SetDatabase(sqlite3* db) override; - sqlite3* GetDatabase() override; - lua_State* SetLuaState(lua_State* L) override; - lua_State* GetLuaState() override; + sqlite3* SetDatabase(sqlite3* db); + sqlite3* GetDatabase(); + lua_State* SetLuaState(lua_State* L); + lua_State* GetLuaState(); private: friend Singleton; diff --git a/server/rooms/room_api.cpp b/server/rooms/room_api.cpp index bc8b1a1..03f5956 100644 --- a/server/rooms/room_api.cpp +++ b/server/rooms/room_api.cpp @@ -23,12 +23,6 @@ #include "room_data.hpp" -static int getPager(lua_State* L) { - RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); - lua_pushlightuserdata(L, reinterpret_cast(room->GetPager()) ); - return 1; -} - static int setRoomName(lua_State* L) { RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); room->SetRoomName(lua_tostring(L, 2)); @@ -53,6 +47,14 @@ static int getTilesetName(lua_State* L) { return 1; } +static int getPager(lua_State* L) { + RoomData* room = reinterpret_cast(lua_touserdata(L, 1)); + lua_pushlightuserdata(L, reinterpret_cast(room->GetPager()) ); + return 1; +} + + + static const luaL_Reg roomLib[] = { {"GetPager",getPager}, {"SetRoomName", setRoomName}, diff --git a/server/rooms/room_api.hpp b/server/rooms/room_api.hpp index 5a1a0c2..060a68d 100644 --- a/server/rooms/room_api.hpp +++ b/server/rooms/room_api.hpp @@ -28,7 +28,7 @@ #include "lua.hpp" #endif -#define TORTUGA_ROOM_NAME "Room" +#define TORTUGA_ROOM_NAME "room" LUAMOD_API int openRoomAPI(lua_State* L); #endif diff --git a/server/rooms/room_data.cpp b/server/rooms/room_data.cpp index cd231b5..7fb9061 100644 --- a/server/rooms/room_data.cpp +++ b/server/rooms/room_data.cpp @@ -21,3 +21,42 @@ */ #include "room_data.hpp" +std::string RoomData::SetRoomName(std::string s) { + return roomName = s; +} + +std::string RoomData::GetRoomName() { + return roomName; +} + +std::string RoomData::SetTilesetName(std::string s) { + return tilesetName = s; +} + +std::string RoomData::GetTilesetName() { + return tilesetName; +} + +RegionPagerLua* RoomData::GetPager() { + return &pager; +} + +std::list* RoomData::GetEntityList() { + return &entityList; +} + +int RoomData::SetLoadReference(int i) { + return loadRef = i; +} + +int RoomData::GetLoadReference() { + return loadRef; +} + +int RoomData::SetUnloadReference(int i) { + return unloadRef = i; +} + +int RoomData::GetUnloadReference() { + return unloadRef; +} \ No newline at end of file diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp index 6586405..65a488d 100644 --- a/server/rooms/room_data.hpp +++ b/server/rooms/room_data.hpp @@ -40,21 +40,29 @@ public: ~RoomData() = default; //accessors and mutators - RegionPagerLua* GetPager() { return &pager; } + std::string SetRoomName(std::string s); + std::string GetRoomName(); - std::string SetRoomName(std::string s) { return roomName = s; } - std::string GetRoomName() { return roomName; } + std::string SetTilesetName(std::string s); + std::string GetTilesetName(); - std::string SetTilesetName(std::string s) { return tilesetName = s; } - std::string GetTilesetName() { return tilesetName; } + RegionPagerLua* GetPager(); + std::list* GetEntityList(); + + //hooks + int SetLoadReference(int); + int GetLoadReference(); + int SetUnloadReference(int); + int GetUnloadReference(); private: friend class RoomManager; //members - RegionPagerLua pager; std::string roomName; std::string tilesetName; + + RegionPagerLua pager; std::list entityList; //lua references diff --git a/server/rooms/room_manager_api.hpp b/server/rooms/room_manager_api.hpp index d8d7b75..8ca0418 100644 --- a/server/rooms/room_manager_api.hpp +++ b/server/rooms/room_manager_api.hpp @@ -28,7 +28,7 @@ #include "lua.hpp" #endif -#define TORTUGA_ROOM_MANAGER_NAME "RoomManager" +#define TORTUGA_ROOM_MANAGER_NAME "room_manager" LUAMOD_API int openRoomManagerAPI(lua_State* L); #endif diff --git a/todo.txt b/todo.txt index d764117..cbef2ec 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,8 @@ TODO: client_manager.cpp TODO: door_manager.cpp TODO: monster_manager.cpp +TODO: *_data.cpp +TODO: reduce friendships TODO: I need a better way to handle the statistics TODO: Fix shoddy movement