Renamed the waypoint system to trogger system
This commit is contained in:
@@ -19,28 +19,28 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "waypoint_api.hpp"
|
||||
#include "trigger_api.hpp"
|
||||
|
||||
#include "waypoint_data.hpp"
|
||||
#include "trigger_data.hpp"
|
||||
|
||||
//origin
|
||||
static int setOrigin(lua_State* L) {
|
||||
WaypointData* waypoint = static_cast<WaypointData*>(lua_touserdata(L, 1));
|
||||
waypoint->SetOrigin(Vector2(lua_tonumber(L, 2), lua_tonumber(L, 3)));
|
||||
TriggerData* trigger = static_cast<TriggerData*>(lua_touserdata(L, 1));
|
||||
trigger->SetOrigin(Vector2(lua_tonumber(L, 2), lua_tonumber(L, 3)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getOrigin(lua_State* L) {
|
||||
WaypointData* waypoint = static_cast<WaypointData*>(lua_touserdata(L, 1));
|
||||
lua_pushnumber(L, waypoint->GetOrigin().x);
|
||||
lua_pushnumber(L, waypoint->GetOrigin().y);
|
||||
TriggerData* trigger = static_cast<TriggerData*>(lua_touserdata(L, 1));
|
||||
lua_pushnumber(L, trigger->GetOrigin().x);
|
||||
lua_pushnumber(L, trigger->GetOrigin().y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
//bounds
|
||||
static int setBoundingBox(lua_State* L) {
|
||||
WaypointData* waypoint = static_cast<WaypointData*>(lua_touserdata(L, 1));
|
||||
waypoint->SetBoundingBox(BoundingBox(
|
||||
TriggerData* trigger = static_cast<TriggerData*>(lua_touserdata(L, 1));
|
||||
trigger->SetBoundingBox(BoundingBox(
|
||||
lua_tonumber(L, 2),
|
||||
lua_tonumber(L, 3),
|
||||
lua_tonumber(L, 4),
|
||||
@@ -50,42 +50,42 @@ static int setBoundingBox(lua_State* L) {
|
||||
}
|
||||
|
||||
static int getBoundingBox(lua_State* L) {
|
||||
WaypointData* waypoint = static_cast<WaypointData*>(lua_touserdata(L, 1));
|
||||
lua_pushnumber(L, waypoint->GetBoundingBox().x);
|
||||
lua_pushnumber(L, waypoint->GetBoundingBox().y);
|
||||
lua_pushnumber(L, waypoint->GetBoundingBox().w);
|
||||
lua_pushnumber(L, waypoint->GetBoundingBox().h);
|
||||
TriggerData* trigger = static_cast<TriggerData*>(lua_touserdata(L, 1));
|
||||
lua_pushnumber(L, trigger->GetBoundingBox().x);
|
||||
lua_pushnumber(L, trigger->GetBoundingBox().y);
|
||||
lua_pushnumber(L, trigger->GetBoundingBox().w);
|
||||
lua_pushnumber(L, trigger->GetBoundingBox().h);
|
||||
return 4;
|
||||
}
|
||||
|
||||
//triggers
|
||||
static int setTriggerReference(lua_State* L) {
|
||||
WaypointData* waypoint = static_cast<WaypointData*>(lua_touserdata(L, 1));
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, waypoint->GetTriggerReference());
|
||||
waypoint->SetTriggerReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
||||
static int setReference(lua_State* L) {
|
||||
TriggerData* trigger = static_cast<TriggerData*>(lua_touserdata(L, 1));
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, trigger->GetScriptReference());
|
||||
trigger->SetScriptReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getTriggerReference(lua_State* L) {
|
||||
WaypointData* waypoint = static_cast<WaypointData*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, waypoint->GetTriggerReference());
|
||||
static int getReference(lua_State* L) {
|
||||
TriggerData* trigger = static_cast<TriggerData*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, trigger->GetScriptReference());
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg waypointLib[] = {
|
||||
static const luaL_Reg triggerLib[] = {
|
||||
{"SetOrigin",setOrigin},
|
||||
{"GetOrigin",getOrigin},
|
||||
|
||||
{"SetBounds",setBoundingBox},
|
||||
{"GetBounds",getBoundingBox},
|
||||
|
||||
{"SetTrigger",setTriggerReference},
|
||||
{"GetTrigger",getTriggerReference},
|
||||
{"SetScript",setReference},
|
||||
{"GetScript",getReference},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int openWaypointAPI(lua_State* L) {
|
||||
luaL_newlib(L, waypointLib);
|
||||
LUAMOD_API int openTriggerAPI(lua_State* L) {
|
||||
luaL_newlib(L, triggerLib);
|
||||
return 1;
|
||||
}
|
||||
@@ -19,12 +19,12 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef WAYPOINTAPI_HPP_
|
||||
#define WAYPOINTAPI_HPP_
|
||||
#ifndef TRIGGERAPI_HPP_
|
||||
#define TRIGGERAPI_HPP_
|
||||
|
||||
#include "lua.hpp"
|
||||
|
||||
#define TORTUGA_WAYPOINT_API "waypoint"
|
||||
LUAMOD_API int openWaypointAPI(lua_State* L);
|
||||
#define TORTUGA_TRIGGER_API "trigger"
|
||||
LUAMOD_API int openTriggerAPI(lua_State* L);
|
||||
|
||||
#endif
|
||||
@@ -19,28 +19,28 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "waypoint_data.hpp"
|
||||
#include "trigger_data.hpp"
|
||||
|
||||
int WaypointData::SetTriggerReference(int i) {
|
||||
return triggerRef = i;
|
||||
int TriggerData::SetScriptReference(int i) {
|
||||
return scriptRef = i;
|
||||
}
|
||||
|
||||
int WaypointData::GetTriggerReference() {
|
||||
return triggerRef;
|
||||
int TriggerData::GetScriptReference() {
|
||||
return scriptRef;
|
||||
}
|
||||
|
||||
BoundingBox WaypointData::SetBoundingBox(BoundingBox b) {
|
||||
BoundingBox TriggerData::SetBoundingBox(BoundingBox b) {
|
||||
return bounds = b;
|
||||
}
|
||||
|
||||
BoundingBox WaypointData::GetBoundingBox() {
|
||||
BoundingBox TriggerData::GetBoundingBox() {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
Vector2 WaypointData::SetOrigin(Vector2 v) {
|
||||
Vector2 TriggerData::SetOrigin(Vector2 v) {
|
||||
return origin = v;
|
||||
}
|
||||
|
||||
Vector2 WaypointData::GetOrigin() {
|
||||
Vector2 TriggerData::GetOrigin() {
|
||||
return origin;
|
||||
}
|
||||
@@ -19,8 +19,8 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef WAYPOINTDATA_HPP_
|
||||
#define WAYPOINTDATA_HPP_
|
||||
#ifndef TRIGGERDATA_HPP_
|
||||
#define TRIGGERDATA_HPP_
|
||||
|
||||
#include "bounding_box.hpp"
|
||||
#include "vector2.hpp"
|
||||
@@ -29,10 +29,10 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
class WaypointData {
|
||||
class TriggerData {
|
||||
public:
|
||||
WaypointData() = default;
|
||||
~WaypointData() = default;
|
||||
TriggerData() = default;
|
||||
~TriggerData() = default;
|
||||
|
||||
Vector2 SetOrigin(Vector2 v);
|
||||
Vector2 GetOrigin();
|
||||
@@ -40,15 +40,15 @@ public:
|
||||
BoundingBox SetBoundingBox(BoundingBox b);
|
||||
BoundingBox GetBoundingBox();
|
||||
|
||||
int SetTriggerReference(int i);
|
||||
int GetTriggerReference();
|
||||
int SetScriptReference(int i);
|
||||
int GetScriptReference();
|
||||
|
||||
private:
|
||||
friend class WaypointManager;
|
||||
friend class TriggerManager;
|
||||
|
||||
Vector2 origin;
|
||||
BoundingBox bounds;
|
||||
int triggerRef = LUA_NOREF;
|
||||
int scriptRef = LUA_NOREF;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -19,47 +19,47 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "waypoint_manager.hpp"
|
||||
#include "trigger_manager.hpp"
|
||||
|
||||
WaypointManager::WaypointManager() {
|
||||
TriggerManager::TriggerManager() {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
WaypointManager::~WaypointManager() {
|
||||
TriggerManager::~TriggerManager() {
|
||||
UnloadAll();
|
||||
}
|
||||
|
||||
int WaypointManager::Create() {
|
||||
int TriggerManager::Create() {
|
||||
//implicitly creates the element
|
||||
WaypointData& waypointData = elementMap[counter];
|
||||
TriggerData& triggerData = elementMap[counter];
|
||||
|
||||
//no real values set
|
||||
waypointData.origin = {0, 0};
|
||||
waypointData.bounds = {0, 0, 0, 0};
|
||||
triggerData.origin = {0, 0};
|
||||
triggerData.bounds = {0, 0, 0, 0};
|
||||
|
||||
return counter++;
|
||||
}
|
||||
|
||||
int WaypointManager::Create(Vector2 origin, BoundingBox bounds) {
|
||||
int TriggerManager::Create(Vector2 origin, BoundingBox bounds) {
|
||||
//implicitly creates the element
|
||||
WaypointData& waypointData = elementMap[counter];
|
||||
TriggerData& triggerData = elementMap[counter];
|
||||
|
||||
waypointData.origin = origin;
|
||||
waypointData.bounds = bounds;
|
||||
triggerData.origin = origin;
|
||||
triggerData.bounds = bounds;
|
||||
|
||||
return counter++;
|
||||
}
|
||||
|
||||
void WaypointManager::Unload(int uid) {
|
||||
void TriggerManager::Unload(int uid) {
|
||||
elementMap.erase(uid);
|
||||
}
|
||||
|
||||
void WaypointManager::UnloadAll() {
|
||||
void TriggerManager::UnloadAll() {
|
||||
elementMap.clear();
|
||||
}
|
||||
|
||||
void WaypointManager::UnloadIf(std::function<bool(std::pair<const int, WaypointData const&>)> fn) {
|
||||
std::map<int, WaypointData>::iterator it = elementMap.begin();
|
||||
void TriggerManager::UnloadIf(std::function<bool(std::pair<const int, TriggerData const&>)> fn) {
|
||||
std::map<int, TriggerData>::iterator it = elementMap.begin();
|
||||
while (it != elementMap.end()) {
|
||||
if (fn(*it)) {
|
||||
it = elementMap.erase(it);
|
||||
@@ -70,8 +70,8 @@ void WaypointManager::UnloadIf(std::function<bool(std::pair<const int, WaypointD
|
||||
}
|
||||
}
|
||||
|
||||
WaypointData* WaypointManager::Get(int uid) {
|
||||
std::map<int, WaypointData>::iterator it = elementMap.find(uid);
|
||||
TriggerData* TriggerManager::Get(int uid) {
|
||||
std::map<int, TriggerData>::iterator it = elementMap.find(uid);
|
||||
|
||||
if (it == elementMap.end()) {
|
||||
return nullptr;
|
||||
@@ -80,19 +80,19 @@ WaypointData* WaypointManager::Get(int uid) {
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
int WaypointManager::GetLoadedCount() {
|
||||
int TriggerManager::GetLoadedCount() {
|
||||
return elementMap.size();
|
||||
}
|
||||
|
||||
std::map<int, WaypointData>* WaypointManager::GetContainer() {
|
||||
std::map<int, TriggerData>* TriggerManager::GetContainer() {
|
||||
return &elementMap;
|
||||
}
|
||||
|
||||
//hooks
|
||||
lua_State* WaypointManager::SetLuaState(lua_State* L) {
|
||||
lua_State* TriggerManager::SetLuaState(lua_State* L) {
|
||||
return lua = L;
|
||||
}
|
||||
|
||||
lua_State* WaypointManager::GetLuaState() {
|
||||
lua_State* TriggerManager::GetLuaState() {
|
||||
return lua;
|
||||
}
|
||||
@@ -19,12 +19,12 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef WAYPOINTMANAGER_HPP_
|
||||
#define WAYPOINTMANAGER_HPP_
|
||||
#ifndef TRIGGERMANAGER_HPP_
|
||||
#define TRIGGERMANAGER_HPP_
|
||||
|
||||
#include "bounding_box.hpp"
|
||||
#include "vector2.hpp"
|
||||
#include "waypoint_data.hpp"
|
||||
#include "trigger_data.hpp"
|
||||
|
||||
#include "lua.hpp"
|
||||
|
||||
@@ -33,10 +33,10 @@
|
||||
#include <string>
|
||||
|
||||
//TODO: (1) rename this system to the "trigger" system
|
||||
class WaypointManager {
|
||||
class TriggerManager {
|
||||
public:
|
||||
WaypointManager();
|
||||
~WaypointManager();
|
||||
TriggerManager();
|
||||
~TriggerManager();
|
||||
|
||||
//common public methods
|
||||
int Create();
|
||||
@@ -44,12 +44,12 @@ public:
|
||||
void Unload(int uid);
|
||||
|
||||
void UnloadAll();
|
||||
void UnloadIf(std::function<bool(std::pair<const int, WaypointData const&>)> fn);
|
||||
void UnloadIf(std::function<bool(std::pair<const int, TriggerData const&>)> fn);
|
||||
|
||||
//accessors & mutators
|
||||
WaypointData* Get(int uid);
|
||||
TriggerData* Get(int uid);
|
||||
int GetLoadedCount();
|
||||
std::map<int, WaypointData>* GetContainer();
|
||||
std::map<int, TriggerData>* GetContainer();
|
||||
|
||||
//hooks
|
||||
lua_State* SetLuaState(lua_State* L);
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
|
||||
private:
|
||||
//members
|
||||
std::map<int, WaypointData> elementMap;
|
||||
std::map<int, TriggerData> elementMap;
|
||||
lua_State* lua = nullptr;
|
||||
int counter = 0;
|
||||
};
|
||||
+11
-11
@@ -19,41 +19,41 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "waypoint_manager_api.hpp"
|
||||
#include "trigger_manager_api.hpp"
|
||||
|
||||
#include "waypoint_manager.hpp"
|
||||
#include "trigger_manager.hpp"
|
||||
|
||||
//TODO: figure out a way to iterate through elements of managers from lua
|
||||
|
||||
static int create(lua_State* L) {
|
||||
WaypointManager* mgr = static_cast<WaypointManager*>(lua_touserdata(L, 1));
|
||||
TriggerManager* mgr = static_cast<TriggerManager*>(lua_touserdata(L, 1));
|
||||
}
|
||||
|
||||
static int unload(lua_State* L) {
|
||||
WaypointManager* mgr = static_cast<WaypointManager*>(lua_touserdata(L, 1));
|
||||
TriggerManager* mgr = static_cast<TriggerManager*>(lua_touserdata(L, 1));
|
||||
}
|
||||
|
||||
static int getWaypoint(lua_State* L) {
|
||||
WaypointManager* mgr = static_cast<WaypointManager*>(lua_touserdata(L, 1));
|
||||
static int getTrigger(lua_State* L) { //TODO: (1) named triggers
|
||||
TriggerManager* mgr = static_cast<TriggerManager*>(lua_touserdata(L, 1));
|
||||
lua_pushlightuserdata(L, mgr->Get(lua_tointeger(L, 2)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getLoadedCount(lua_State* L) {
|
||||
WaypointManager* mgr = static_cast<WaypointManager*>(lua_touserdata(L, 1));
|
||||
TriggerManager* mgr = static_cast<TriggerManager*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, mgr->GetLoadedCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg waypointManagerLib[] = {
|
||||
static const luaL_Reg triggerManagerLib[] = {
|
||||
{"Create",create},
|
||||
{"Unload",unload},
|
||||
{"GetWaypoint",getWaypoint},
|
||||
{"GetTrigger",getTrigger},
|
||||
{"GetCount",getLoadedCount},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
LUAMOD_API int openWaypointManagerAPI(lua_State* L) {
|
||||
luaL_newlib(L, waypointManagerLib);
|
||||
LUAMOD_API int openTriggerManagerAPI(lua_State* L) {
|
||||
luaL_newlib(L, triggerManagerLib);
|
||||
return 1;
|
||||
}
|
||||
@@ -19,12 +19,12 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef WAYPOINTSYSTEMAPI_HPP_
|
||||
#define WAYPOINTSYSTEMAPI_HPP_
|
||||
#ifndef TRIGGERMANAGERAPI_HPP_
|
||||
#define TRIGGERMANAGERAPI_HPP_
|
||||
|
||||
#include "lua.hpp"
|
||||
|
||||
#define TORTUGA_WAYPOINT_SYSTEM_API "waypoint_system"
|
||||
LUAMOD_API int openWaypointSystemAPI(lua_State* L);
|
||||
#define TORTUGA_TRIGGER_MANAGER_API "trigger_manager"
|
||||
LUAMOD_API int openTriggerManagerAPI(lua_State* L);
|
||||
|
||||
#endif
|
||||
@@ -19,27 +19,27 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "waypoint_system_api.hpp"
|
||||
#include "trigger_system_api.hpp"
|
||||
|
||||
//all waypoint API headers
|
||||
#include "waypoint_api.hpp"
|
||||
#include "waypoint_manager_api.hpp"
|
||||
//all trigger API headers
|
||||
#include "trigger_api.hpp"
|
||||
#include "trigger_manager_api.hpp"
|
||||
|
||||
//useful "globals"
|
||||
//...
|
||||
|
||||
//This mimics linit.c to create a nested collection of all waypoint modules.
|
||||
//This mimics linit.c to create a nested collection of all trigger modules.
|
||||
static const luaL_Reg funcs[] = {
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
static const luaL_Reg libs[] = {
|
||||
{"Waypoint", openWaypointAPI},
|
||||
{"WaypointManager", openWaypointManagerAPI},
|
||||
{"Trigger", openTriggerAPI},
|
||||
{"TriggerManager", openTriggerManagerAPI},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
int openWaypointSystemAPI(lua_State* L) {
|
||||
int openTriggerSystemAPI(lua_State* L) {
|
||||
//create the table
|
||||
luaL_newlibtable(L, libs);
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef WAYPOINTMANAGERAPI_HPP_
|
||||
#define WAYPOINTMANAGERAPI_HPP_
|
||||
#ifndef TRIGGERSYSTEMAPI_HPP_
|
||||
#define TRIGGERSYSTEMAPI_HPP_
|
||||
|
||||
#include "lua.hpp"
|
||||
|
||||
#define TORTUGA_WAYPOINT_MANAGER_API "waypoint_manager"
|
||||
LUAMOD_API int openWaypointManagerAPI(lua_State* L);
|
||||
#define TORTUGA_TRIGGER_SYSTEM_API "trigger_system"
|
||||
LUAMOD_API int openTriggerSystemAPI(lua_State* L);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user