Make marking events as "sim events" slightly harder to mess up
A sim event being an event that takes place in the context of the simulation. Currently, this simply means that the RNG math.random uses is the sim's rather than the UI's.
This commit is contained in:
parent
0143a0a41f
commit
e20312a672
@ -4,16 +4,19 @@
|
|||||||
|
|
||||||
struct TextInputEvent
|
struct TextInputEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
String text;
|
String text;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TextEditingEvent
|
struct TextEditingEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
String text;
|
String text;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct KeyEvent
|
struct KeyEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
int key;
|
int key;
|
||||||
int scan;
|
int scan;
|
||||||
bool repeat;
|
bool repeat;
|
||||||
@ -24,14 +27,17 @@ struct KeyEvent
|
|||||||
|
|
||||||
struct KeyPressEvent : public KeyEvent
|
struct KeyPressEvent : public KeyEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct KeyReleaseEvent : public KeyEvent
|
struct KeyReleaseEvent : public KeyEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MouseDownEvent
|
struct MouseDownEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
unsigned int button;
|
unsigned int button;
|
||||||
@ -39,6 +45,7 @@ struct MouseDownEvent
|
|||||||
|
|
||||||
struct MouseUpEvent
|
struct MouseUpEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
unsigned int button;
|
unsigned int button;
|
||||||
@ -47,6 +54,7 @@ struct MouseUpEvent
|
|||||||
|
|
||||||
struct MouseMoveEvent
|
struct MouseMoveEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int dx;
|
int dx;
|
||||||
@ -55,6 +63,7 @@ struct MouseMoveEvent
|
|||||||
|
|
||||||
struct MouseWheelEvent
|
struct MouseWheelEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int d;
|
int d;
|
||||||
@ -62,22 +71,27 @@ struct MouseWheelEvent
|
|||||||
|
|
||||||
struct TickEvent
|
struct TickEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BlurEvent
|
struct BlurEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CloseEvent
|
struct CloseEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BeforeSimEvent
|
struct BeforeSimEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AfterSimEvent
|
struct AfterSimEvent
|
||||||
{
|
{
|
||||||
|
static constexpr bool simEvent = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
using GameControllerEvent = std::variant<
|
using GameControllerEvent = std::variant<
|
||||||
|
@ -4672,8 +4672,9 @@ bool LuaScriptInterface::HandleEvent(const GameControllerEvent &event)
|
|||||||
{
|
{
|
||||||
lua_rawgeti(l, -1, i);
|
lua_rawgeti(l, -1, i);
|
||||||
int numArgs = PushGameControllerEvent(l, event);
|
int numArgs = PushGameControllerEvent(l, event);
|
||||||
auto simEvent = std::get_if<BeforeSimEvent>(&event) ||
|
auto simEvent = std::visit([](auto &event) {
|
||||||
std::get_if<AfterSimEvent>(&event);
|
return event.simEvent;
|
||||||
|
}, event);
|
||||||
int callret = tpt_lua_pcall(l, numArgs, 1, 0, simEvent);
|
int callret = tpt_lua_pcall(l, numArgs, 1, 0, simEvent);
|
||||||
if (callret)
|
if (callret)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user