Deduplicate base LuaScript sprite verts

This commit is contained in:
ROllerozxa 2026-06-05 21:43:09 +02:00
commit 0ad08adab8
4 changed files with 26 additions and 44 deletions

View file

@ -389,26 +389,6 @@ plua_foreach(lua_State *L, const int index, void (*cb)(lua_State*, int, void*),
} }
} }
static struct lua_vert base[4] = {
{
(tvec3){.5f,.5f,0.f},
(tvec2){.5f, 1.f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}, {
(tvec3){-.5f,.5f,0.f},
(tvec2){0.f, 1.f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}, {
(tvec3){-.5f,-.5f,0.f},
(tvec2){0.f, .5f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}, {
(tvec3){.5f,-.5f,0.f},
(tvec2){.5f, .5f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}
};
static int static int
my_writer(lua_State *L, const void *contents, size_t size, void *ud) my_writer(lua_State *L, const void *contents, size_t size, void *ud)
{ {
@ -1561,7 +1541,7 @@ escript::add_static_sprite(float x, float y, float r, float w, float h, int bx,
tmath_sincos(r, &sn, &cs); tmath_sincos(r, &sn, &cs);
for (int ix=0; ix<4; ix++) { for (int ix=0; ix<4; ix++) {
_b[n*4+ix] = base[ix]; _b[n*4+ix] = sprite_base[ix];
_b[n*4+ix].pos.x *= w; _b[n*4+ix].pos.x *= w;
_b[n*4+ix].pos.y *= h; _b[n*4+ix].pos.y *= h;
@ -1585,7 +1565,7 @@ escript::add_static_sprite(float x, float y, float r, float w, float h, int bx,
} }
} else { } else {
for (int ix=0; ix<4; ix++) { for (int ix=0; ix<4; ix++) {
_b[n*4+ix] = base[ix]; _b[n*4+ix] = sprite_base[ix];
_b[n*4+ix].pos.x *= w; _b[n*4+ix].pos.x *= w;
_b[n*4+ix].pos.y *= h; _b[n*4+ix].pos.y *= h;

View file

@ -1,5 +1,25 @@
#include "lua.hh" #include "lua.hh"
struct lua_vert sprite_base[4] = {
{
(tvec3){.5f,.5f,0.f},
(tvec2){.5f, 1.f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}, {
(tvec3){-.5f,.5f,0.f},
(tvec2){0.f, 1.f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}, {
(tvec3){-.5f,-.5f,0.f},
(tvec2){0.f, .5f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}, {
(tvec3){.5f,-.5f,0.f},
(tvec2){.5f, .5f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}
};
bool lua_push_stuff(lua_State *Lsrc, lua_State *Ldst, int pos) bool lua_push_stuff(lua_State *Lsrc, lua_State *Ldst, int pos)
{ {
if (lua_isnumber(Lsrc, pos)) { if (lua_isnumber(Lsrc, pos)) {

View file

@ -44,6 +44,8 @@ struct lua_vert {
tvec4 color; tvec4 color;
}; };
extern struct lua_vert sprite_base[4];
/* /*
* Recursive function to push stuff! * Recursive function to push stuff!
* Can currently handle: * Can currently handle:

View file

@ -2,26 +2,6 @@
#include "escript.hh" #include "escript.hh"
#include "receiver.hh" #include "receiver.hh"
struct lua_vert base[4] = {
{
(tvec3){.5f,.5f,0.f},
(tvec2){.5f, 1.f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}, {
(tvec3){-.5f,.5f,0.f},
(tvec2){0.f, 1.f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}, {
(tvec3){-.5f,-.5f,0.f},
(tvec2){0.f, .5f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}, {
(tvec3){.5f,-.5f,0.f},
(tvec2){.5f, .5f},
(tvec4){0.f, 0.f, 0.f, 0.f},
}
};
static uint32_t static uint32_t
upper_power_of_two(uint32_t v) upper_power_of_two(uint32_t v)
{ {
@ -399,7 +379,7 @@ static int l_this_draw_sprite(lua_State *L)
tmath_sincos(r, &sn, &cs); tmath_sincos(r, &sn, &cs);
for (int ix=0; ix<4; ix++) { for (int ix=0; ix<4; ix++) {
_b[n*4+ix] = base[ix]; _b[n*4+ix] = sprite_base[ix];
_b[n*4+ix].pos.x *= w; _b[n*4+ix].pos.x *= w;
_b[n*4+ix].pos.y *= h; _b[n*4+ix].pos.y *= h;
@ -428,7 +408,7 @@ static int l_this_draw_sprite(lua_State *L)
} }
} else { } else {
for (int ix=0; ix<4; ix++) { for (int ix=0; ix<4; ix++) {
_b[n*4+ix] = base[ix]; _b[n*4+ix] = sprite_base[ix];
_b[n*4+ix].pos.x *= w; _b[n*4+ix].pos.x *= w;
_b[n*4+ix].pos.y *= h; _b[n*4+ix].pos.y *= h;