mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-03-01 00:41:16 +00:00
Lua spriteinfo brightmap support
This commit is contained in:
parent
9c8d6dfaa6
commit
c90d4f8b97
2 changed files with 53 additions and 12 deletions
|
|
@ -266,6 +266,20 @@ static UINT8 GetPivotFrame(lua_State *L, int idx)
|
|||
return frame;
|
||||
}
|
||||
|
||||
static int PushCast(lua_State *L, const char *meta)
|
||||
{
|
||||
// bypass LUA_PushUserdata
|
||||
void **userdata = lua_newuserdata(L, sizeof(void *));
|
||||
|
||||
*userdata = lua_touserdata(L, 1);
|
||||
|
||||
luaL_getmetatable(L, meta);
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
// stack is left with the userdata on top, as if getting it had originally succeeded.
|
||||
return 1;
|
||||
}
|
||||
|
||||
// spriteinfo[]
|
||||
static int lib_getSpriteInfo(lua_State *L)
|
||||
{
|
||||
|
|
@ -454,23 +468,15 @@ static int lib_spriteinfolen(lua_State *L)
|
|||
// spriteinfo_t
|
||||
static int spriteinfo_get(lua_State *L)
|
||||
{
|
||||
spriteinfo_t *sprinfo = *((spriteinfo_t **)luaL_checkudata(L, 1, META_SPRITEINFO));
|
||||
const char *field = luaL_checkstring(L, 2);
|
||||
|
||||
I_Assert(sprinfo != NULL);
|
||||
luaL_checkudata(L, 1, META_SPRITEINFO);
|
||||
|
||||
// push spriteframepivot_t userdata
|
||||
if (fastcmp(field, "pivot"))
|
||||
{
|
||||
// bypass LUA_PushUserdata
|
||||
void **userdata = lua_newuserdata(L, sizeof(void *));
|
||||
*userdata = sprinfo;
|
||||
luaL_getmetatable(L, META_PIVOTLIST);
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
// stack is left with the userdata on top, as if getting it had originally succeeded.
|
||||
return 1;
|
||||
}
|
||||
return PushCast(L, META_PIVOTLIST);
|
||||
else if (fastcmp(field, "brightmap"))
|
||||
return PushCast(L, META_SPRITEBRIGHTLIST);
|
||||
else
|
||||
return luaL_error(L, LUA_QL("spriteinfo_t") " has no field named " LUA_QS, field);
|
||||
|
||||
|
|
@ -640,6 +646,29 @@ static int framepivot_num(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int brightlist_get(lua_State *L)
|
||||
{
|
||||
const spriteinfo_t *sprinfo = *((spriteinfo_t **)luaL_checkudata(L, 1, META_SPRITEBRIGHTLIST));
|
||||
const UINT8 frame = GetPivotFrame(L, 2);
|
||||
|
||||
lua_pushstring(L, sprinfo->bright[frame]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int brightlist_set(lua_State *L)
|
||||
{
|
||||
spriteinfo_t *sprinfo = *((spriteinfo_t **)luaL_checkudata(L, 1, META_SPRITEBRIGHTLIST));
|
||||
|
||||
const UINT8 frame = GetPivotFrame(L, 2);
|
||||
const char *val = luaL_checkstring(L, 3);
|
||||
|
||||
Z_Free(sprinfo->bright[frame]);
|
||||
sprinfo->bright[frame] = Z_StrDup(val);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////
|
||||
// STATE INFO //
|
||||
////////////////
|
||||
|
|
@ -2033,6 +2062,17 @@ int LUA_InfoLib(lua_State *L)
|
|||
lua_setfield(L, -2, "__len");
|
||||
lua_pop(L, 1);
|
||||
|
||||
luaL_newmetatable(L, META_SPRITEBRIGHTLIST);
|
||||
lua_pushcfunction(L, brightlist_get);
|
||||
lua_setfield(L, -2, "__index");
|
||||
|
||||
lua_pushcfunction(L, brightlist_set);
|
||||
lua_setfield(L, -2, "__newindex");
|
||||
|
||||
lua_pushcfunction(L, pivotlist_num);
|
||||
lua_setfield(L, -2, "__len");
|
||||
lua_pop(L, 1);
|
||||
|
||||
luaL_newmetatable(L, META_PRECIPPROPS);
|
||||
lua_pushcfunction(L, precipprops_get);
|
||||
lua_setfield(L, -2, "__index");
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ extern lua_State *gL;
|
|||
#define META_SPRITEINFO "SPRITEINFO_T*"
|
||||
#define META_PIVOTLIST "SPRITEFRAMEPIVOT_T[]"
|
||||
#define META_FRAMEPIVOT "SPRITEFRAMEPIVOT_T*"
|
||||
#define META_SPRITEBRIGHTLIST "SPRITEBRIGHTMAP_T[]"
|
||||
#define META_PRECIPPROPS "PRECIPPROPS_T*"
|
||||
|
||||
#define META_TAGLIST "TAGLIST"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue