From bb592b24363304903e89952196af1a96dc622d12 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 30 Dec 2014 04:37:56 +1100 Subject: [PATCH] Added the waypoint system to the modules Also fleshed out entity_api.cpp, but that's just filler. --- rsc/scripts/setup_server.lua | 10 +++++ server/entities/entity_api.cpp | 44 +++++++++++++++++++ server/linit.cpp | 2 + server/waypoints/waypoint_system_api.cpp | 55 ++++++++++++++++++++++++ server/waypoints/waypoint_system_api.hpp | 34 +++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 server/waypoints/waypoint_system_api.cpp create mode 100644 server/waypoints/waypoint_system_api.hpp diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index d39656f..e07af12 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -3,6 +3,16 @@ print("Lua script check") mapMaker = require "map_maker" mapSaver = require "map_saver" roomSystem = require "room_system" +waypointSystem = require "waypoint_system" + +local function dumpTable(t) + print(t) + for k, v in pairs(t) do + print("",k,v) + end +end + +dumpTable(waypointSystem) --NOTE: room 0 is the first that the client asks for, therefore it must exist local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld") diff --git a/server/entities/entity_api.cpp b/server/entities/entity_api.cpp index 84c1a63..a7f71bd 100644 --- a/server/entities/entity_api.cpp +++ b/server/entities/entity_api.cpp @@ -23,7 +23,51 @@ #include "entity.hpp" +static int setRoomIndex(lua_State* L) { + Entity* entity = static_cast(lua_touserdata(L, 1)); + entity->SetRoomIndex(lua_tointeger(L, 2)); + return 0; +} + +static int setOrigin(lua_State* L) { + Entity* entity = static_cast(lua_touserdata(L, 1)); + entity->SetOrigin({lua_tonumber(L, 2), lua_tonumber(L, 3)}); + return 0; +} + +static int setMotion(lua_State* L) { + Entity* entity = static_cast(lua_touserdata(L, 1)); + entity->SetMotion({lua_tonumber(L, 2), lua_tonumber(L, 3)}); + return 0; +} + +static int getRoomIndex(lua_State* L) { + Entity* entity = static_cast(lua_touserdata(L, 1)); + lua_pushinteger(L, entity->GetRoomIndex()); + return 1; +} + +static int getOrigin(lua_State* L) { + Entity* entity = static_cast(lua_touserdata(L, 1)); + lua_pushnumber(L, entity->GetOrigin().x); + lua_pushnumber(L, entity->GetOrigin().y); + return 2; +} + +static int getMotion(lua_State* L) { + Entity* entity = static_cast(lua_touserdata(L, 1)); + lua_pushnumber(L, entity->GetOrigin().x); + lua_pushnumber(L, entity->GetOrigin().y); + return 2; +} + static const luaL_Reg entityLib[] = { + {"SetRoomIndex", setRoomIndex}, + {"SetOrigin", setOrigin}, + {"SetMotion", setMotion}, + {"GetRoomIndex", getRoomIndex}, + {"GetOrigin", getOrigin}, + {"GetMotion", getMotion}, {nullptr, nullptr} }; diff --git a/server/linit.cpp b/server/linit.cpp index 1030490..d4ab6e6 100644 --- a/server/linit.cpp +++ b/server/linit.cpp @@ -42,6 +42,7 @@ #include "map_system_api.hpp" #include "room_system_api.hpp" +#include "waypoint_system_api.hpp" //these libs are loaded by lua.c and are readily available to any Lua program static const luaL_Reg loadedlibs[] = { @@ -64,6 +65,7 @@ static const luaL_Reg loadedlibs[] = { static const luaL_Reg preloadedlibs[] = { {TORTUGA_MAP_SYSTEM_API, openMapSystemAPI}, {TORTUGA_ROOM_SYSTEM_API, openRoomSystemAPI}, + {TORTUGA_WAYPOINT_SYSTEM_API, openWaypointSystemAPI}, {NULL, NULL} }; diff --git a/server/waypoints/waypoint_system_api.cpp b/server/waypoints/waypoint_system_api.cpp new file mode 100644 index 0000000..a16f6ea --- /dev/null +++ b/server/waypoints/waypoint_system_api.cpp @@ -0,0 +1,55 @@ +/* Copyright: (c) Kayne Ruse 2013-2015 + * + * 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 "waypoint_system_api.hpp" + +//all waypoint API headers +#include "waypoint_api.hpp" +#include "waypoint_manager_api.hpp" + +//useful "globals" +//... + +//This mimics linit.c to create a nested collection of all waypoint modules. +static const luaL_Reg funcs[] = { + {nullptr, nullptr} +}; + +static const luaL_Reg libs[] = { + {"Waypoint", openWaypointAPI}, + {"WaypointManager", openWaypointManagerAPI}, + {nullptr, nullptr} +}; + +int openWaypointSystemAPI(lua_State* L) { + //create the table + luaL_newlibtable(L, libs); + + //push the "global" functions + luaL_setfuncs(L, funcs, 0); + + //push the substable + for (const luaL_Reg* lib = libs; lib->func; lib++) { + lib->func(L); + lua_setfield(L, -2, lib->name); + } + return 1; +} diff --git a/server/waypoints/waypoint_system_api.hpp b/server/waypoints/waypoint_system_api.hpp new file mode 100644 index 0000000..d651a1f --- /dev/null +++ b/server/waypoints/waypoint_system_api.hpp @@ -0,0 +1,34 @@ +/* Copyright: (c) Kayne Ruse 2013-2015 + * + * 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 WAYPOINTSYSTEMAPI_HPP_ +#define WAYPOINTSYSTEMAPI_HPP_ + +#if defined(__MINGW32__) + #include "lua/lua.hpp" +#else + #include "lua.hpp" +#endif + +#define TORTUGA_WAYPOINT_SYSTEM_API "waypoint_system" +LUAMOD_API int openWaypointSystemAPI(lua_State* L); + +#endif \ No newline at end of file