mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-07 22:56:30 -10:00
The current scripting hook is pretty simple and straight forward but it makes a couple of scripting applications harder to implement than needed. For example, a lot of scripts need to do some work every frame for all or some objects. The script needs to manage an internal list of all the objects that are affected by that list which includes removing invalid objects to conserve resources. This effectively mirrors what the engine already does and adds unnecessary overhead. In these changes I added a generic event system which can be used by any part of the code for providing callbacks when a specific event occurs. As an example, I added hooks for the pre- and post-move events to the object class which are called before and after physics are applied to an object. I integrated that feature into the scripting system so now a script can simply register a function as a callback which will be called whenever the target event is executed.
25 lines
411 B
C++
25 lines
411 B
C++
//
|
|
//
|
|
|
|
#include "LuaEventCallback.h"
|
|
#include "scripting/lua/LuaConvert.h"
|
|
|
|
using namespace luacpp;
|
|
|
|
namespace scripting {
|
|
namespace api {
|
|
namespace util {
|
|
|
|
void convert_arg(lua_State* L, luacpp::LuaValueList& out, object* objp)
|
|
{
|
|
LuaValue val;
|
|
ade_set_object_with_breed(L, OBJ_INDEX(objp));
|
|
convert::popValue(L, val);
|
|
|
|
out.push_back(val);
|
|
}
|
|
|
|
} // namespace util
|
|
} // namespace api
|
|
} // namespace scripting
|