Add beforesimdraw and aftersimdraw events

These fire just after RenderBegin (read: really early) and just before RenderEnd (read: really late, but before the zoom window is drawn), respectively.

Lua graphics calls now also decide whether they should draw using simulation graphics or user interface graphics based on which event is being handled. This fixes element graphics functions being unable to draw with graphics calls.
This commit is contained in:
Tamás Bálint Misius 2023-12-24 13:37:54 +01:00
parent ccd7bef1ed
commit c5b72b213b
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
14 changed files with 199 additions and 277 deletions

View File

@ -1697,3 +1697,13 @@ void GameController::RemoveCustomGOLType(const ByteString &identifier)
{ {
gameModel->RemoveCustomGOLType(identifier); gameModel->RemoveCustomGOLType(identifier);
} }
void GameController::BeforeSimDraw()
{
commandInterface->HandleEvent(BeforeSimDrawEvent{});
}
void GameController::AfterSimDraw()
{
commandInterface->HandleEvent(AfterSimDrawEvent{});
}

View File

@ -196,4 +196,7 @@ public:
bool GetMouseClickRequired(); bool GetMouseClickRequired();
void RemoveCustomGOLType(const ByteString &identifier); void RemoveCustomGOLType(const ByteString &identifier);
void BeforeSimDraw();
void AfterSimDraw();
}; };

View File

@ -1,22 +1,30 @@
#pragma once #pragma once
#include "common/String.h" #include "common/String.h"
#include <variant> #include <variant>
#include <cstdint>
enum EventTraits : uint32_t
{
eventTraitNone = UINT32_C(0x00000000),
eventTraitSimRng = UINT32_C(0x00000001),
eventTraitSimGraphics = UINT32_C(0x00000002),
};
struct TextInputEvent struct TextInputEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
String text; String text;
}; };
struct TextEditingEvent struct TextEditingEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
String text; String text;
}; };
struct KeyEvent struct KeyEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
int key; int key;
int scan; int scan;
bool repeat; bool repeat;
@ -27,17 +35,17 @@ struct KeyEvent
struct KeyPressEvent : public KeyEvent struct KeyPressEvent : public KeyEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
}; };
struct KeyReleaseEvent : public KeyEvent struct KeyReleaseEvent : public KeyEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
}; };
struct MouseDownEvent struct MouseDownEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
int x; int x;
int y; int y;
unsigned int button; unsigned int button;
@ -45,7 +53,7 @@ struct MouseDownEvent
struct MouseUpEvent struct MouseUpEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
int x; int x;
int y; int y;
unsigned int button; unsigned int button;
@ -54,7 +62,7 @@ struct MouseUpEvent
struct MouseMoveEvent struct MouseMoveEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
int x; int x;
int y; int y;
int dx; int dx;
@ -63,7 +71,7 @@ struct MouseMoveEvent
struct MouseWheelEvent struct MouseWheelEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
int x; int x;
int y; int y;
int d; int d;
@ -71,27 +79,37 @@ struct MouseWheelEvent
struct TickEvent struct TickEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
}; };
struct BlurEvent struct BlurEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
}; };
struct CloseEvent struct CloseEvent
{ {
static constexpr bool simEvent = false; static constexpr EventTraits traits = eventTraitNone;
}; };
struct BeforeSimEvent struct BeforeSimEvent
{ {
static constexpr bool simEvent = true; static constexpr EventTraits traits = eventTraitSimRng;
}; };
struct AfterSimEvent struct AfterSimEvent
{ {
static constexpr bool simEvent = true; static constexpr EventTraits traits = eventTraitSimRng;
};
struct BeforeSimDrawEvent
{
static constexpr EventTraits traits = eventTraitSimGraphics;
};
struct AfterSimDrawEvent
{
static constexpr EventTraits traits = eventTraitSimGraphics;
}; };
using GameControllerEvent = std::variant< using GameControllerEvent = std::variant<
@ -107,5 +125,7 @@ using GameControllerEvent = std::variant<
BlurEvent, BlurEvent,
CloseEvent, CloseEvent,
BeforeSimEvent, BeforeSimEvent,
AfterSimEvent AfterSimEvent,
BeforeSimDrawEvent,
AfterSimDrawEvent
>; >;

View File

@ -2119,6 +2119,7 @@ void GameView::OnDraw()
auto &sd = SimulationData::Ref(); auto &sd = SimulationData::Ref();
std::unique_lock lk(sd.elementGraphicsMx); std::unique_lock lk(sd.elementGraphicsMx);
ren->clearScreen(); ren->clearScreen();
c->BeforeSimDraw();
ren->RenderBegin(); ren->RenderBegin();
ren->SetSample(c->PointTranslate(currentMouse)); ren->SetSample(c->PointTranslate(currentMouse));
if (showBrush && selectMode == SelectNone && (!zoomEnabled || zoomCursorFixed) && activeBrush && (isMouseDown || (currentMouse.X >= 0 && currentMouse.X < XRES && currentMouse.Y >= 0 && currentMouse.Y < YRES))) if (showBrush && selectMode == SelectNone && (!zoomEnabled || zoomCursorFixed) && activeBrush && (isMouseDown || (currentMouse.X >= 0 && currentMouse.X < XRES && currentMouse.Y >= 0 && currentMouse.Y < YRES)))
@ -2224,6 +2225,7 @@ void GameView::OnDraw()
} }
} }
c->AfterSimDraw();
ren->RenderEnd(); ren->RenderEnd();
std::copy_n(ren->Data(), ren->Size().X * ren->Size().Y, g->Data()); std::copy_n(ren->Data(), ren->Size().X * ren->Size().Y, g->Data());

View File

@ -313,31 +313,6 @@ int luatpt_getelement(lua_State *l)
return 1; return 1;
} }
int luatpt_drawtext(lua_State* l)
{
int textx, texty, textred, textgreen, textblue, textalpha;
textx = luaL_optint(l, 1, 0);
texty = luaL_optint(l, 2, 0);
auto string = tpt_lua_optString(l, 3, "");
textred = luaL_optint(l, 4, 255);
textgreen = luaL_optint(l, 5, 255);
textblue = luaL_optint(l, 6, 255);
textalpha = luaL_optint(l, 7, 255);
if (textx<0 || texty<0 || textx>=WINDOWW || texty>=WINDOWH)
return luaL_error(l, "Screen coordinates out of range (%d,%d)", textx, texty);
if (textred<0) textred = 0;
if (textred>255) textred = 255;
if (textgreen<0) textgreen = 0;
if (textgreen>255) textgreen = 255;
if (textblue<0) textblue = 0;
if (textblue>255) textblue = 255;
if (textalpha<0) textalpha = 0;
if (textalpha>255) textalpha = 255;
luacon_g->BlendText({ textx, texty }, string, RGBA<uint8_t>(textred, textgreen, textblue, textalpha));
return 0;
}
int luatpt_create(lua_State* l) int luatpt_create(lua_State* l)
{ {
auto &sd = SimulationData::CRef(); auto &sd = SimulationData::CRef();
@ -875,136 +850,6 @@ int luatpt_get_property(lua_State* l)
return luaL_error(l, "Particle does not exist"); return luaL_error(l, "Particle does not exist");
} }
int luatpt_drawpixel(lua_State* l)
{
int x, y, r, g, b, a;
x = luaL_optint(l, 1, 0);
y = luaL_optint(l, 2, 0);
r = luaL_optint(l, 3, 255);
g = luaL_optint(l, 4, 255);
b = luaL_optint(l, 5, 255);
a = luaL_optint(l, 6, 255);
if (x<0 || y<0 || x>=WINDOWW || y>=WINDOWH)
return luaL_error(l, "Screen coordinates out of range (%d,%d)", x, y);
if (r<0) r = 0;
else if (r>255) r = 255;
if (g<0) g = 0;
else if (g>255) g = 255;
if (b<0) b = 0;
else if (b>255) b = 255;
if (a<0) a = 0;
else if (a>255) a = 255;
luacon_g->BlendPixel({ x, y }, RGBA<uint8_t>(r, g, b, a));
return 0;
}
int luatpt_drawrect(lua_State* l)
{
int x, y, w, h, r, g, b, a;
x = luaL_optint(l, 1, 0);
y = luaL_optint(l, 2, 0);
w = luaL_optint(l, 3, 10)+1;
h = luaL_optint(l, 4, 10)+1;
r = luaL_optint(l, 5, 255);
g = luaL_optint(l, 6, 255);
b = luaL_optint(l, 7, 255);
a = luaL_optint(l, 8, 255);
if (x<0 || y<0 || x>=WINDOWW || y>=WINDOWH)
return luaL_error(l, "Screen coordinates out of range (%d,%d)", x, y);
if(x+w > WINDOWW)
w = WINDOWW-x;
if(y+h > WINDOWH)
h = WINDOWH-y;
if (r<0) r = 0;
else if (r>255) r = 255;
if (g<0) g = 0;
else if (g>255) g = 255;
if (b<0) b = 0;
else if (b>255) b = 255;
if (a<0) a = 0;
else if (a>255) a = 255;
if (a == 255)
{
luacon_g->DrawRect(RectSized(Vec2{ x, y }, Vec2{ w, h }), RGB<uint8_t>(r, g, b));
}
else
{
luacon_g->BlendRect(RectSized(Vec2{ x, y }, Vec2{ w, h }), RGBA<uint8_t>(r, g, b, a));
}
return 0;
}
int luatpt_fillrect(lua_State* l)
{
int x,y,w,h,r,g,b,a;
x = luaL_optint(l, 1, 0)+1;
y = luaL_optint(l, 2, 0)+1;
w = luaL_optint(l, 3, 10)-1;
h = luaL_optint(l, 4, 10)-1;
r = luaL_optint(l, 5, 255);
g = luaL_optint(l, 6, 255);
b = luaL_optint(l, 7, 255);
a = luaL_optint(l, 8, 255);
if (x<0 || y<0 || x>=WINDOWW || y>=WINDOWH)
return luaL_error(l, "Screen coordinates out of range (%d,%d)", x, y);
if(x+w > WINDOWW)
w = WINDOWW-x;
if(y+h > WINDOWH)
h = WINDOWH-y;
if (r<0) r = 0;
else if (r>255) r = 255;
if (g<0) g = 0;
else if (g>255) g = 255;
if (b<0) b = 0;
else if (b>255) b = 255;
if (a<0) a = 0;
else if (a>255) a = 255;
if (a == 255)
{
luacon_g->DrawFilledRect(RectSized(Vec2{ x, y }, Vec2{ w, h }), RGB<uint8_t>(r, g, b));
}
else
{
luacon_g->BlendFilledRect(RectSized(Vec2{ x, y }, Vec2{ w, h }), RGBA<uint8_t>(r, g, b, a));
}
return 0;
}
int luatpt_drawline(lua_State* l)
{
int x1,y1,x2,y2,r,g,b,a;
x1 = luaL_optint(l, 1, 0);
y1 = luaL_optint(l, 2, 0);
x2 = luaL_optint(l, 3, 10);
y2 = luaL_optint(l, 4, 10);
r = luaL_optint(l, 5, 255);
g = luaL_optint(l, 6, 255);
b = luaL_optint(l, 7, 255);
a = luaL_optint(l, 8, 255);
//Don't need to check coordinates, as they are checked in blendpixel
if (r<0) r = 0;
else if (r>255) r = 255;
if (g<0) g = 0;
else if (g>255) g = 255;
if (b<0) b = 0;
else if (b>255) b = 255;
if (a<0) a = 0;
else if (a>255) a = 255;
if (a == 255)
{
luacon_g->DrawLine({ x1, y1 }, { x2, y2 }, RGB<uint8_t>(r, g, b));
}
else
{
luacon_g->BlendLine({ x1, y1 }, { x2, y2 }, RGBA<uint8_t>(r, g, b, a));
}
return 0;
}
int luatpt_textwidth(lua_State* l) int luatpt_textwidth(lua_State* l)
{ {
auto string = tpt_lua_optString(l, 1, ""); auto string = tpt_lua_optString(l, 1, "");

View File

@ -72,7 +72,7 @@ void LuaButton::triggerAction()
{ {
lua_rawgeti(l, LUA_REGISTRYINDEX, actionFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, actionFunction);
lua_rawgeti(l, LUA_REGISTRYINDEX, owner_ref); lua_rawgeti(l, LUA_REGISTRYINDEX, owner_ref);
if (tpt_lua_pcall(l, 1, 0, 0, false)) if (tpt_lua_pcall(l, 1, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }

View File

@ -71,7 +71,7 @@ void LuaCheckbox::triggerAction()
lua_rawgeti(l, LUA_REGISTRYINDEX, actionFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, actionFunction);
lua_rawgeti(l, LUA_REGISTRYINDEX, owner_ref); lua_rawgeti(l, LUA_REGISTRYINDEX, owner_ref);
lua_pushboolean(l, checkbox->GetChecked()); lua_pushboolean(l, checkbox->GetChecked());
if (tpt_lua_pcall(l, 2, 0, 0, false)) if (tpt_lua_pcall(l, 2, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }

View File

@ -3,6 +3,7 @@
#include "simulation/ElementDefs.h" #include "simulation/ElementDefs.h"
#include "common/String.h" #include "common/String.h"
#include "LuaCompat.h" #include "LuaCompat.h"
#include <variant>
class GameModel; class GameModel;
class GameController; class GameController;
@ -14,8 +15,6 @@ class Renderer;
extern GameModel * luacon_model; extern GameModel * luacon_model;
extern GameController * luacon_controller; extern GameController * luacon_controller;
extern Simulation * luacon_sim; extern Simulation * luacon_sim;
extern Graphics * luacon_g;
extern Renderer * luacon_ren;
extern bool *luacon_currentCommand; extern bool *luacon_currentCommand;
extern String *luacon_lastError; extern String *luacon_lastError;
@ -49,8 +48,6 @@ int luacon_transitionwrite(lua_State* l);
//tpt. api //tpt. api
int luatpt_getelement(lua_State *l); int luatpt_getelement(lua_State *l);
int luatpt_drawtext(lua_State* l);
int luatpt_create(lua_State* l); int luatpt_create(lua_State* l);
int luatpt_setpause(lua_State* l); int luatpt_setpause(lua_State* l);
@ -83,14 +80,6 @@ int luatpt_set_elecmap(lua_State* l);
int luatpt_get_elecmap(lua_State* l); int luatpt_get_elecmap(lua_State* l);
int luatpt_drawpixel(lua_State* l);
int luatpt_drawrect(lua_State* l);
int luatpt_fillrect(lua_State* l);
int luatpt_drawline(lua_State* l);
int luatpt_textwidth(lua_State* l); int luatpt_textwidth(lua_State* l);
int luatpt_get_name(lua_State* l); int luatpt_get_name(lua_State* l);

View File

@ -75,8 +75,8 @@
GameModel * luacon_model; GameModel * luacon_model;
GameController * luacon_controller; GameController * luacon_controller;
Simulation * luacon_sim; Simulation * luacon_sim;
Graphics * luacon_g; static Graphics *luacon_g{};
Renderer * luacon_ren; static Renderer *luacon_ren{};
bool *luacon_currentCommand; bool *luacon_currentCommand;
String *luacon_lastError; String *luacon_lastError;
@ -179,12 +179,12 @@ static int osExit(lua_State *l)
return 0; return 0;
} }
static bool inSimEvent = false; static EventTraits eventTraits = eventTraitNone;
static int mathRandom(lua_State *l) static int mathRandom(lua_State *l)
{ {
// only thing that matters is that the rng not be luacon_sim->rng when !inSimEvent // only thing that matters is that the rng not be luacon_sim->rng when !(eventTraits & eventTraitSimRng)
auto &rng = inSimEvent ? luacon_sim->rng : interfaceRng; auto &rng = (eventTraits & eventTraitSimRng) ? luacon_sim->rng : interfaceRng;
int lower, upper; int lower, upper;
switch (lua_gettop(l)) switch (lua_gettop(l))
{ {
@ -326,7 +326,6 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
//Old TPT API //Old TPT API
int currentElementMeta, currentElement; int currentElementMeta, currentElement;
const static struct luaL_Reg tptluaapi [] = { const static struct luaL_Reg tptluaapi [] = {
{"drawtext", &luatpt_drawtext},
{"create", &luatpt_create}, {"create", &luatpt_create},
{"set_pause", &luatpt_setpause}, {"set_pause", &luatpt_setpause},
{"toggle_pause", &luatpt_togglepause}, {"toggle_pause", &luatpt_togglepause},
@ -343,10 +342,6 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
{"get_wallmap", &luatpt_get_wallmap}, {"get_wallmap", &luatpt_get_wallmap},
{"set_elecmap", &luatpt_set_elecmap}, {"set_elecmap", &luatpt_set_elecmap},
{"get_elecmap", &luatpt_get_elecmap}, {"get_elecmap", &luatpt_get_elecmap},
{"drawpixel", &luatpt_drawpixel},
{"drawrect", &luatpt_drawrect},
{"fillrect", &luatpt_fillrect},
{"drawline", &luatpt_drawline},
{"textwidth", &luatpt_textwidth}, {"textwidth", &luatpt_textwidth},
{"get_name", &luatpt_get_name}, {"get_name", &luatpt_get_name},
{"delete", &luatpt_delete}, {"delete", &luatpt_delete},
@ -531,7 +526,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
initLegacyProps(); initLegacyProps();
if (luaL_loadbuffer(l, (const char *)eventcompat_lua, eventcompat_lua_size, "@[built-in eventcompat.lua]") || tpt_lua_pcall(l, 0, 0, 0, false)) if (luaL_loadbuffer(l, (const char *)eventcompat_lua, eventcompat_lua_size, "@[built-in eventcompat.lua]") || tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
{ {
throw std::runtime_error(ByteString("failed to load built-in eventcompat: ") + tpt_lua_toByteString(l, -1)); throw std::runtime_error(ByteString("failed to load built-in eventcompat: ") + tpt_lua_toByteString(l, -1));
} }
@ -558,7 +553,7 @@ void LuaScriptInterface::Init()
{ {
if (Platform::FileExists("autorun.lua")) if (Platform::FileExists("autorun.lua"))
{ {
if(luaL_loadfile(l, "autorun.lua") || tpt_lua_pcall(l, 0, 0, 0, false)) if(luaL_loadfile(l, "autorun.lua") || tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
Log(CommandInterface::LogError, luacon_geterror()); Log(CommandInterface::LogError, luacon_geterror());
else else
Log(CommandInterface::LogWarning, "Loaded autorun.lua"); Log(CommandInterface::LogWarning, "Loaded autorun.lua");
@ -697,7 +692,7 @@ static int beginMessageBox(lua_State* l)
cb->Push(l); cb->Push(l);
if (lua_isfunction(l, -1)) if (lua_isfunction(l, -1))
{ {
if (tpt_lua_pcall(l, 0, 0, 0, false)) if (tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
{ {
luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); luacon_ci->Log(CommandInterface::LogError, luacon_geterror());
} }
@ -721,7 +716,7 @@ static int beginThrowError(lua_State* l)
cb->Push(l); cb->Push(l);
if (lua_isfunction(l, -1)) if (lua_isfunction(l, -1))
{ {
if (tpt_lua_pcall(l, 0, 0, 0, false)) if (tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
{ {
luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); luacon_ci->Log(CommandInterface::LogError, luacon_geterror());
} }
@ -756,7 +751,7 @@ static int beginInput(lua_State* l)
{ {
lua_pushnil(l); lua_pushnil(l);
} }
if (tpt_lua_pcall(l, 1, 0, 0, false)) if (tpt_lua_pcall(l, 1, 0, 0, eventTraitNone))
{ {
luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); luacon_ci->Log(CommandInterface::LogError, luacon_geterror());
} }
@ -788,7 +783,7 @@ static int beginConfirm(lua_State *l)
if (lua_isfunction(l, -1)) if (lua_isfunction(l, -1))
{ {
lua_pushboolean(l, result); lua_pushboolean(l, result);
if (tpt_lua_pcall(l, 1, 0, 0, false)) if (tpt_lua_pcall(l, 1, 0, 0, eventTraitNone))
{ {
luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); luacon_ci->Log(CommandInterface::LogError, luacon_geterror());
} }
@ -3485,7 +3480,7 @@ static int luaUpdateWrapper(UPDATE_FUNC_ARGS)
lua_pushinteger(luacon_ci->l, y); lua_pushinteger(luacon_ci->l, y);
lua_pushinteger(luacon_ci->l, surround_space); lua_pushinteger(luacon_ci->l, surround_space);
lua_pushinteger(luacon_ci->l, nt); lua_pushinteger(luacon_ci->l, nt);
callret = tpt_lua_pcall(luacon_ci->l, 5, 1, 0, true); callret = tpt_lua_pcall(luacon_ci->l, 5, 1, 0, eventTraitSimRng);
if (callret) if (callret)
luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); luacon_ci->Log(CommandInterface::LogError, luacon_geterror());
if(lua_isboolean(luacon_ci->l, -1)){ if(lua_isboolean(luacon_ci->l, -1)){
@ -3531,7 +3526,7 @@ static int luaGraphicsWrapper(GRAPHICS_FUNC_ARGS)
lua_pushinteger(luacon_ci->l, *colr); lua_pushinteger(luacon_ci->l, *colr);
lua_pushinteger(luacon_ci->l, *colg); lua_pushinteger(luacon_ci->l, *colg);
lua_pushinteger(luacon_ci->l, *colb); lua_pushinteger(luacon_ci->l, *colb);
callret = tpt_lua_pcall(luacon_ci->l, 4, 10, 0, false); callret = tpt_lua_pcall(luacon_ci->l, 4, 10, 0, eventTraitSimGraphics);
if (callret) if (callret)
{ {
luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); luacon_ci->Log(CommandInterface::LogError, luacon_geterror());
@ -3585,7 +3580,7 @@ static void luaCreateWrapper(ELEMENT_CREATE_FUNC_ARGS)
lua_pushinteger(luacon_ci->l, y); lua_pushinteger(luacon_ci->l, y);
lua_pushinteger(luacon_ci->l, t); lua_pushinteger(luacon_ci->l, t);
lua_pushinteger(luacon_ci->l, v); lua_pushinteger(luacon_ci->l, v);
if (tpt_lua_pcall(luacon_ci->l, 5, 0, 0, true)) if (tpt_lua_pcall(luacon_ci->l, 5, 0, 0, eventTraitSimRng))
{ {
luacon_ci->Log(CommandInterface::LogError, "In create func: " + luacon_geterror()); luacon_ci->Log(CommandInterface::LogError, "In create func: " + luacon_geterror());
lua_pop(luacon_ci->l, 1); lua_pop(luacon_ci->l, 1);
@ -3611,7 +3606,7 @@ static bool luaCreateAllowedWrapper(ELEMENT_CREATE_ALLOWED_FUNC_ARGS)
lua_pushinteger(luacon_ci->l, x); lua_pushinteger(luacon_ci->l, x);
lua_pushinteger(luacon_ci->l, y); lua_pushinteger(luacon_ci->l, y);
lua_pushinteger(luacon_ci->l, t); lua_pushinteger(luacon_ci->l, t);
if (tpt_lua_pcall(luacon_ci->l, 4, 1, 0, true)) if (tpt_lua_pcall(luacon_ci->l, 4, 1, 0, eventTraitSimRng))
{ {
luacon_ci->Log(CommandInterface::LogError, "In create allowed: " + luacon_geterror()); luacon_ci->Log(CommandInterface::LogError, "In create allowed: " + luacon_geterror());
lua_pop(luacon_ci->l, 1); lua_pop(luacon_ci->l, 1);
@ -3641,7 +3636,7 @@ static void luaChangeTypeWrapper(ELEMENT_CHANGETYPE_FUNC_ARGS)
lua_pushinteger(luacon_ci->l, y); lua_pushinteger(luacon_ci->l, y);
lua_pushinteger(luacon_ci->l, from); lua_pushinteger(luacon_ci->l, from);
lua_pushinteger(luacon_ci->l, to); lua_pushinteger(luacon_ci->l, to);
if (tpt_lua_pcall(luacon_ci->l, 5, 0, 0, true)) if (tpt_lua_pcall(luacon_ci->l, 5, 0, 0, eventTraitSimRng))
{ {
luacon_ci->Log(CommandInterface::LogError, "In change type: " + luacon_geterror()); luacon_ci->Log(CommandInterface::LogError, "In change type: " + luacon_geterror());
lua_pop(luacon_ci->l, 1); lua_pop(luacon_ci->l, 1);
@ -3663,7 +3658,7 @@ static bool luaCtypeDrawWrapper(CTYPEDRAW_FUNC_ARGS)
lua_pushinteger(luacon_ci->l, i); lua_pushinteger(luacon_ci->l, i);
lua_pushinteger(luacon_ci->l, t); lua_pushinteger(luacon_ci->l, t);
lua_pushinteger(luacon_ci->l, v); lua_pushinteger(luacon_ci->l, v);
if (tpt_lua_pcall(luacon_ci->l, 3, 1, 0, true)) if (tpt_lua_pcall(luacon_ci->l, 3, 1, 0, eventTraitSimRng))
{ {
luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); luacon_ci->Log(CommandInterface::LogError, luacon_geterror());
lua_pop(luacon_ci->l, 1); lua_pop(luacon_ci->l, 1);
@ -4088,12 +4083,15 @@ int LuaScriptInterface::elements_exists(lua_State * l)
return 1; return 1;
} }
static int graphics_drawPixel(lua_State *L);
void LuaScriptInterface::initGraphicsAPI() void LuaScriptInterface::initGraphicsAPI()
{ {
//Methods //Methods
struct luaL_Reg graphicsAPIMethods [] = { struct luaL_Reg graphicsAPIMethods [] = {
{"textSize", graphics_textSize}, {"textSize", graphics_textSize},
{"drawText", graphics_drawText}, {"drawText", graphics_drawText},
{"drawPixel", graphics_drawPixel},
{"drawLine", graphics_drawLine}, {"drawLine", graphics_drawLine},
{"drawRect", graphics_drawRect}, {"drawRect", graphics_drawRect},
{"fillRect", graphics_fillRect}, {"fillRect", graphics_fillRect},
@ -4126,6 +4124,35 @@ int LuaScriptInterface::graphics_textSize(lua_State * l)
return 2; return 2;
} }
static std::variant<Graphics *, Renderer *> currentGraphics()
{
if (eventTraits & eventTraitSimGraphics)
{
return luacon_ren;
}
return luacon_g;
}
static int graphics_drawPixel(lua_State *L)
{
auto x = luaL_optint(L, 1, 0);
auto y = luaL_optint(L, 2, 0);
auto r = luaL_optint(L, 3, 255);
auto g = luaL_optint(L, 4, 255);
auto b = luaL_optint(L, 5, 255);
auto a = luaL_optint(L, 6, 255);
if (r < 0 ) r = 0 ;
else if (r > 255) r = 255;
if (g < 0 ) g = 0 ;
else if (g > 255) g = 255;
if (b < 0 ) b = 0 ;
else if (b > 255) b = 255;
if (a < 0 ) a = 0 ;
else if (a > 255) a = 255;
luacon_g->BlendPixel({ x, y }, RGBA<uint8_t>(r, g, b, a));
return 0;
}
int LuaScriptInterface::graphics_drawText(lua_State * l) int LuaScriptInterface::graphics_drawText(lua_State * l)
{ {
int x = lua_tointeger(l, 1); int x = lua_tointeger(l, 1);
@ -4145,7 +4172,9 @@ int LuaScriptInterface::graphics_drawText(lua_State * l)
if (a<0) a = 0; if (a<0) a = 0;
else if (a>255) a = 255; else if (a>255) a = 255;
luacon_g->BlendText({ x, y }, text, RGBA<uint8_t>(r, g, b, a)); std::visit([x, y, r, g, b, a, &text](auto p) {
p->BlendText({ x, y }, text, RGBA<uint8_t>(r, g, b, a));
}, currentGraphics());
return 0; return 0;
} }
@ -4169,14 +4198,16 @@ int LuaScriptInterface::graphics_drawLine(lua_State * l)
if (a<0) a = 0; if (a<0) a = 0;
else if (a>255) a = 255; else if (a>255) a = 255;
if (a == 255) std::visit([x1, y1, x2, y2, r, g, b, a](auto p) {
{ if (a == 255)
luacon_g->DrawLine({ x1, y1 }, { x2, y2 }, RGB<uint8_t>(r, g, b)); {
} p->DrawLine({ x1, y1 }, { x2, y2 }, RGB<uint8_t>(r, g, b));
else }
{ else
luacon_g->BlendLine({ x1, y1 }, { x2, y2 }, RGBA<uint8_t>(r, g, b, a)); {
} p->BlendLine({ x1, y1 }, { x2, y2 }, RGBA<uint8_t>(r, g, b, a));
}
}, currentGraphics());
return 0; return 0;
} }
@ -4200,14 +4231,16 @@ int LuaScriptInterface::graphics_drawRect(lua_State * l)
if (a<0) a = 0; if (a<0) a = 0;
else if (a>255) a = 255; else if (a>255) a = 255;
if (a == 255) std::visit([x, y, width, height, r, g, b, a](auto p) {
{ if (a == 255)
luacon_g->DrawRect(RectSized(Vec2{ x, y }, Vec2{ width, height }), RGB<uint8_t>(r, g, b)); {
} p->DrawRect(RectSized(Vec2{ x, y }, Vec2{ width, height }), RGB<uint8_t>(r, g, b));
else }
{ else
luacon_g->BlendRect(RectSized(Vec2{ x, y }, Vec2{ width, height }), RGBA<uint8_t>(r, g, b, a)); {
} p->BlendRect(RectSized(Vec2{ x, y }, Vec2{ width, height }), RGBA<uint8_t>(r, g, b, a));
}
}, currentGraphics());
return 0; return 0;
} }
@ -4231,14 +4264,16 @@ int LuaScriptInterface::graphics_fillRect(lua_State * l)
if (a<0) a = 0; if (a<0) a = 0;
else if (a>255) a = 255; else if (a>255) a = 255;
if (a == 255) std::visit([x, y, width, height, r, g, b, a](auto p) {
{ if (a == 255)
luacon_g->DrawFilledRect(RectSized(Vec2{ x, y }, Vec2{ width, height }), RGB<uint8_t>(r, g, b)); {
} p->DrawFilledRect(RectSized(Vec2{ x, y }, Vec2{ width, height }), RGB<uint8_t>(r, g, b));
else }
{ else
luacon_g->BlendFilledRect(RectSized(Vec2{ x, y }, Vec2{ width, height }), RGBA<uint8_t>(r, g, b, a)); {
} p->BlendFilledRect(RectSized(Vec2{ x, y }, Vec2{ width, height }), RGBA<uint8_t>(r, g, b, a));
}
}, currentGraphics());
return 0; return 0;
} }
@ -4262,7 +4297,9 @@ int LuaScriptInterface::graphics_drawCircle(lua_State * l)
if (a<0) a = 0; if (a<0) a = 0;
else if (a>255) a = 255; else if (a>255) a = 255;
luacon_g->BlendEllipse({ x, y }, { abs(rx), abs(ry) }, RGBA<uint8_t>(r, g, b, a)); std::visit([x, y, rx, ry, r, g, b, a](auto p) {
p->BlendEllipse({ x, y }, { abs(rx), abs(ry) }, RGBA<uint8_t>(r, g, b, a));
}, currentGraphics());
return 0; return 0;
} }
@ -4286,7 +4323,9 @@ int LuaScriptInterface::graphics_fillCircle(lua_State * l)
if (a<0) a = 0; if (a<0) a = 0;
else if (a>255) a = 255; else if (a>255) a = 255;
luacon_g->BlendFilledEllipse({ x, y }, { abs(rx), abs(ry) }, RGBA<uint8_t>(r, g, b, a)); std::visit([x, y, rx, ry, r, g, b, a](auto p) {
p->BlendFilledEllipse({ x, y }, { abs(rx), abs(ry) }, RGBA<uint8_t>(r, g, b, a));
}, currentGraphics());
return 0; return 0;
} }
@ -4322,6 +4361,10 @@ int LuaScriptInterface::graphics_getHexColor(lua_State * l)
int LuaScriptInterface::graphics_setClipRect(lua_State * l) int LuaScriptInterface::graphics_setClipRect(lua_State * l)
{ {
if (eventTraits & eventTraitSimGraphics)
{
return luaL_error(l, "simulation graphics do not support clip rects");
}
int x = luaL_optinteger(l, 1, 0); int x = luaL_optinteger(l, 1, 0);
int y = luaL_optinteger(l, 2, 0); int y = luaL_optinteger(l, 2, 0);
int w = luaL_optinteger(l, 3, WINDOWW); int w = luaL_optinteger(l, 3, WINDOWW);
@ -4544,19 +4587,21 @@ void LuaScriptInterface::initEventAPI()
}; };
luaL_register(l, "event", eventAPIMethods); luaL_register(l, "event", eventAPIMethods);
lua_pushinteger(l, VariantIndex<GameControllerEvent, TextInputEvent >()); lua_setfield(l, -2, "textinput" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, TextInputEvent >()); lua_setfield(l, -2, "textinput" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, TextEditingEvent>()); lua_setfield(l, -2, "textediting"); lua_pushinteger(l, VariantIndex<GameControllerEvent, TextEditingEvent >()); lua_setfield(l, -2, "textediting" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, KeyPressEvent >()); lua_setfield(l, -2, "keypress" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, KeyPressEvent >()); lua_setfield(l, -2, "keypress" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, KeyReleaseEvent >()); lua_setfield(l, -2, "keyrelease" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, KeyReleaseEvent >()); lua_setfield(l, -2, "keyrelease" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, MouseDownEvent >()); lua_setfield(l, -2, "mousedown" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, MouseDownEvent >()); lua_setfield(l, -2, "mousedown" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, MouseUpEvent >()); lua_setfield(l, -2, "mouseup" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, MouseUpEvent >()); lua_setfield(l, -2, "mouseup" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, MouseMoveEvent >()); lua_setfield(l, -2, "mousemove" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, MouseMoveEvent >()); lua_setfield(l, -2, "mousemove" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, MouseWheelEvent >()); lua_setfield(l, -2, "mousewheel" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, MouseWheelEvent >()); lua_setfield(l, -2, "mousewheel" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, TickEvent >()); lua_setfield(l, -2, "tick" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, TickEvent >()); lua_setfield(l, -2, "tick" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, BlurEvent >()); lua_setfield(l, -2, "blur" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, BlurEvent >()); lua_setfield(l, -2, "blur" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, CloseEvent >()); lua_setfield(l, -2, "close" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, CloseEvent >()); lua_setfield(l, -2, "close" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, BeforeSimEvent >()); lua_setfield(l, -2, "beforesim" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, BeforeSimEvent >()); lua_setfield(l, -2, "beforesim" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, AfterSimEvent >()); lua_setfield(l, -2, "aftersim" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, AfterSimEvent >()); lua_setfield(l, -2, "aftersim" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, BeforeSimDrawEvent>()); lua_setfield(l, -2, "beforesimdraw");
lua_pushinteger(l, VariantIndex<GameControllerEvent, AfterSimDrawEvent >()); lua_setfield(l, -2, "aftersimdraw" );
lua_pop(l, 1); lua_pop(l, 1);
@ -4692,10 +4737,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::visit([](auto &event) { int callret = tpt_lua_pcall(l, numArgs, 1, 0, std::visit([](auto &event) {
return event.simEvent; return event.traits;
}, event); }, event));
int callret = tpt_lua_pcall(l, numArgs, 1, 0, simEvent);
if (callret) if (callret)
{ {
if (luacon_geterror() == "Error: Script not responding") if (luacon_geterror() == "Error: Script not responding")
@ -4842,7 +4886,7 @@ int LuaScriptInterface::Command(String command)
else else
{ {
lastCode = ""; lastCode = "";
ret = tpt_lua_pcall(l, 0, LUA_MULTRET, 0, false); ret = tpt_lua_pcall(l, 0, LUA_MULTRET, 0, eventTraitNone);
if (ret) if (ret)
{ {
lastError = luacon_geterror(); lastError = luacon_geterror();
@ -5177,7 +5221,7 @@ int tpt_lua_loadstring(lua_State *L, const ByteString &str)
int tpt_lua_dostring(lua_State *L, const ByteString &str) int tpt_lua_dostring(lua_State *L, const ByteString &str)
{ {
return tpt_lua_loadstring(L, str) || tpt_lua_pcall(L, 0, LUA_MULTRET, 0, false); return tpt_lua_loadstring(L, str) || tpt_lua_pcall(L, 0, LUA_MULTRET, 0, eventTraitNone);
} }
bool tpt_lua_equalsString(lua_State *L, int index, const char *data, size_t size) bool tpt_lua_equalsString(lua_State *L, int index, const char *data, size_t size)
@ -5185,25 +5229,25 @@ bool tpt_lua_equalsString(lua_State *L, int index, const char *data, size_t size
return lua_isstring(L, index) && lua_objlen(L, index) == size && !memcmp(lua_tostring(L, index), data, size); return lua_isstring(L, index) && lua_objlen(L, index) == size && !memcmp(lua_tostring(L, index), data, size);
} }
int tpt_lua_pcall(lua_State *L, int numArgs, int numResults, int errorFunc, bool simEvent) int tpt_lua_pcall(lua_State *L, int numArgs, int numResults, int errorFunc, EventTraits newEventTraits)
{ {
auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface); auto *luacon_ci = static_cast<LuaScriptInterface *>(commandInterface);
luacon_ci->luaExecutionStart = Platform::GetTime(); luacon_ci->luaExecutionStart = Platform::GetTime();
struct AtReturn struct AtReturn
{ {
bool oldInSimEvent; EventTraits oldEventTraits;
AtReturn(bool newInSimEvent) AtReturn(EventTraits newEventTraits)
{ {
oldInSimEvent = inSimEvent; oldEventTraits = eventTraits;
inSimEvent = newInSimEvent; eventTraits = newEventTraits;
} }
~AtReturn() ~AtReturn()
{ {
inSimEvent = oldInSimEvent; eventTraits = oldEventTraits;
} }
} atReturn(simEvent); } atReturn(newEventTraits);
return lua_pcall(L, numArgs, numResults, errorFunc); return lua_pcall(L, numArgs, numResults, errorFunc);
} }

View File

@ -252,5 +252,4 @@ bool tpt_lua_equalsLiteral(lua_State *L, int index, const char (&lit)[N])
return tpt_lua_equalsString(L, index, lit, N - 1U); return tpt_lua_equalsString(L, index, lit, N - 1U);
} }
int tpt_lua_pcall(lua_State *L, int numArgs, int numResults, int errorFunc, bool simEvent); int tpt_lua_pcall(lua_State *L, int numArgs, int numResults, int errorFunc, EventTraits eventTraits);

View File

@ -71,7 +71,7 @@ void LuaSlider::triggerOnValueChanged()
lua_rawgeti(l, LUA_REGISTRYINDEX, onValueChangedFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, onValueChangedFunction);
lua_rawgeti(l, LUA_REGISTRYINDEX, owner_ref); lua_rawgeti(l, LUA_REGISTRYINDEX, owner_ref);
lua_pushinteger(l, slider->GetValue()); lua_pushinteger(l, slider->GetValue());
if (tpt_lua_pcall(l, 2, 0, 0, false)) if (tpt_lua_pcall(l, 2, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }

View File

@ -59,7 +59,7 @@ void LuaTextbox::triggerOnTextChanged()
{ {
lua_rawgeti(l, LUA_REGISTRYINDEX, onTextChangedFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, onTextChangedFunction);
lua_rawgeti(l, LUA_REGISTRYINDEX, owner_ref); lua_rawgeti(l, LUA_REGISTRYINDEX, owner_ref);
if (tpt_lua_pcall(l, 1, 0, 0, false)) if (tpt_lua_pcall(l, 1, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_optString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_optString(l, -1));
} }

View File

@ -207,7 +207,7 @@ void LuaWindow::triggerOnInitialized()
if(onInitializedFunction) if(onInitializedFunction)
{ {
lua_rawgeti(l, LUA_REGISTRYINDEX, onInitializedFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, onInitializedFunction);
if(tpt_lua_pcall(l, 0, 0, 0, false)) if(tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -219,7 +219,7 @@ void LuaWindow::triggerOnExit()
if(onExitFunction) if(onExitFunction)
{ {
lua_rawgeti(l, LUA_REGISTRYINDEX, onExitFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, onExitFunction);
if(tpt_lua_pcall(l, 0, 0, 0, false)) if(tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -232,7 +232,7 @@ void LuaWindow::triggerOnTick(float dt)
{ {
lua_rawgeti(l, LUA_REGISTRYINDEX, onTickFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, onTickFunction);
lua_pushnumber(l, dt); lua_pushnumber(l, dt);
if(tpt_lua_pcall(l, 1, 0, 0, false)) if(tpt_lua_pcall(l, 1, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -244,7 +244,7 @@ void LuaWindow::triggerOnDraw()
if(onDrawFunction) if(onDrawFunction)
{ {
lua_rawgeti(l, LUA_REGISTRYINDEX, onDrawFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, onDrawFunction);
if(tpt_lua_pcall(l, 0, 0, 0, false)) if(tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -256,7 +256,7 @@ void LuaWindow::triggerOnFocus()
if(onFocusFunction) if(onFocusFunction)
{ {
lua_rawgeti(l, LUA_REGISTRYINDEX, onFocusFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, onFocusFunction);
if(tpt_lua_pcall(l, 0, 0, 0, false)) if(tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -268,7 +268,7 @@ void LuaWindow::triggerOnBlur()
if(onBlurFunction) if(onBlurFunction)
{ {
lua_rawgeti(l, LUA_REGISTRYINDEX, onBlurFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, onBlurFunction);
if(tpt_lua_pcall(l, 0, 0, 0, false)) if(tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -280,7 +280,7 @@ void LuaWindow::triggerOnTryExit()
if(onTryExitFunction) if(onTryExitFunction)
{ {
lua_rawgeti(l, LUA_REGISTRYINDEX, onTryExitFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, onTryExitFunction);
if(tpt_lua_pcall(l, 0, 0, 0, false)) if(tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -292,7 +292,7 @@ void LuaWindow::triggerOnTryOkay()
if(onTryOkayFunction) if(onTryOkayFunction)
{ {
lua_rawgeti(l, LUA_REGISTRYINDEX, onTryOkayFunction); lua_rawgeti(l, LUA_REGISTRYINDEX, onTryOkayFunction);
if(tpt_lua_pcall(l, 0, 0, 0, false)) if(tpt_lua_pcall(l, 0, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -308,7 +308,7 @@ void LuaWindow::triggerOnMouseMove(int x, int y, int dx, int dy)
lua_pushinteger(l, y); lua_pushinteger(l, y);
lua_pushinteger(l, dx); lua_pushinteger(l, dx);
lua_pushinteger(l, dy); lua_pushinteger(l, dy);
if(tpt_lua_pcall(l, 4, 0, 0, false)) if(tpt_lua_pcall(l, 4, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -323,7 +323,7 @@ void LuaWindow::triggerOnMouseDown(int x, int y, unsigned button)
lua_pushinteger(l, x); lua_pushinteger(l, x);
lua_pushinteger(l, y); lua_pushinteger(l, y);
lua_pushinteger(l, button); lua_pushinteger(l, button);
if(tpt_lua_pcall(l, 3, 0, 0, false)) if(tpt_lua_pcall(l, 3, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -338,7 +338,7 @@ void LuaWindow::triggerOnMouseUp(int x, int y, unsigned button)
lua_pushinteger(l, x); lua_pushinteger(l, x);
lua_pushinteger(l, y); lua_pushinteger(l, y);
lua_pushinteger(l, button); lua_pushinteger(l, button);
if(tpt_lua_pcall(l, 3, 0, 0, false)) if(tpt_lua_pcall(l, 3, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -353,7 +353,7 @@ void LuaWindow::triggerOnMouseWheel(int x, int y, int d)
lua_pushinteger(l, x); lua_pushinteger(l, x);
lua_pushinteger(l, y); lua_pushinteger(l, y);
lua_pushinteger(l, d); lua_pushinteger(l, d);
if(tpt_lua_pcall(l, 3, 0, 0, false)) if(tpt_lua_pcall(l, 3, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -370,7 +370,7 @@ void LuaWindow::triggerOnKeyPress(int key, int scan, bool repeat, bool shift, bo
lua_pushboolean(l, shift); lua_pushboolean(l, shift);
lua_pushboolean(l, ctrl); lua_pushboolean(l, ctrl);
lua_pushboolean(l, alt); lua_pushboolean(l, alt);
if(tpt_lua_pcall(l, 5, 0, 0, false)) if(tpt_lua_pcall(l, 5, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }
@ -387,7 +387,7 @@ void LuaWindow::triggerOnKeyRelease(int key, int scan, bool repeat, bool shift,
lua_pushboolean(l, shift); lua_pushboolean(l, shift);
lua_pushboolean(l, ctrl); lua_pushboolean(l, ctrl);
lua_pushboolean(l, alt); lua_pushboolean(l, alt);
if(tpt_lua_pcall(l, 5, 0, 0, false)) if(tpt_lua_pcall(l, 5, 0, 0, eventTraitNone))
{ {
ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1)); ci->Log(CommandInterface::LogError, tpt_lua_toString(l, -1));
} }

View File

@ -246,3 +246,13 @@ function tpt.getscript(id, name, run)
end end
tpt.installScriptManager() tpt.installScriptManager()
end end
tpt.drawpixel = gfx.drawPixel
function tpt.drawrect(x, y, w, h, r, g, b, a)
gfx.drawRect(x, y, w + 1, h + 1, r, g, b, a)
end
function tpt.fillrect(x, y, w, h, r, g, b, a)
gfx.fillRect(x + 1, y + 1, w - 1, h - 1, r, g, b, a)
end
tpt.drawline = gfx.drawLine
tpt.drawtext = gfx.drawText