Files
fs2open.github.com/code/scripting/api/objs/gamestate.cpp
T
BMagnu 272d6261c4 Generic Lua Multiplayer RPC (#4835)
* Add automatic lua obj serialization function dispatch

* Implement fundamental and object de/serialization

* Proper default case for package deserialization

* Add No Multi func

* Add Serialization part

* Fix max encoding size for userdata

* Implement exception handling

* Start Implementing lua RPC

* Prepare waitAsync for RPC

* Add packet order enforcing and forwarding

* Add RPC registry

* Make RPCs callable

* Add waitRPC

* Add serializers

* Fix GCC error

* Explicitly specify lua_net_exception

* Fix Warnings

* Replace Seriliaze fundamental with cross-platform data types

* Appease Clang

* Prevent serialization CTD on invalid objects

* Actually use the temporaries assigned

* Fix OSWPT shadow

* Fix table deserialize order

* Incorporate Feedback

* Fix Warnigs

* ix WArnings 2

* Add sanity checks for OSWPT wing serialization

* Multi Bump

* Forgot we have american-style dates there
2023-03-28 03:07:03 +09:00

70 lines
1.7 KiB
C++

//
//
#include "gamestate.h"
#include "network/multi.h"
#include "network/multimsgs.h"
#include "network/multiutil.h"
namespace scripting {
namespace api {
gamestate_h::gamestate_h() { sdx = -1; }
gamestate_h::gamestate_h(int n_state) { sdx = n_state; }
bool gamestate_h::IsValid() { return (sdx > -1 && sdx < Num_gs_state_text); }
int gamestate_h::Get() { return sdx; }
void gamestate_h::serialize(lua_State* /*L*/, const scripting::ade_table_entry& /*tableEntry*/, const luacpp::LuaValue& value, ubyte* data, int& packet_size) {
gamestate_h event;
value.getValue(l_GameState.Get(&event));
ADD_INT(event.sdx);
}
void gamestate_h::deserialize(lua_State* /*L*/, const scripting::ade_table_entry& /*tableEntry*/, char* data_ptr, ubyte* data, int& offset) {
int index;
GET_INT(index);
new(data_ptr) gamestate_h(index);
}
ADE_OBJ(l_GameState, gamestate_h, "gamestate", "Game state");
ADE_FUNC(__tostring, l_GameState, NULL, "Game state name", "string", "Game state name, or empty string if handle is invalid")
{
gamestate_h *gh = NULL;
if(!ade_get_args(L, "o", l_GameState.GetPtr(&gh)))
return ade_set_error(L, "s", "");
if(!gh->IsValid())
return ade_set_error(L, "s", "");
return ade_set_args(L, "s", GS_state_text[gh->Get()]);
}
ADE_VIRTVAR(Name, l_GameState,"string", "Game state name", "string", "Game state name, or empty string if handle is invalid")
{
gamestate_h *gh = NULL;
const char* n_name = nullptr;
if(!ade_get_args(L, "o|s", l_GameState.GetPtr(&gh), &n_name))
return ade_set_error(L, "s", "");
if(!gh->IsValid())
return ade_set_error(L, "s", "");
int sdx = gh->Get();
if(ADE_SETTING_VAR)
{
Error(LOCATION, "Can't set game state names at this time");
}
return ade_set_args(L, "s", GS_state_text[sdx]);
}
}
}