mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-24 21:31:46 +00:00
Merge branch 'lua-colorlib-get-sector-translation' into 'next'
Add v.getSectorColormap and P_GetSectorLightLevelAt See merge request STJr/SRB2!2230
This commit is contained in:
commit
7cabf43e85
8 changed files with 92 additions and 52 deletions
|
@ -214,7 +214,6 @@ static const struct {
|
||||||
{META_PATCH, "patch_t"},
|
{META_PATCH, "patch_t"},
|
||||||
{META_COLORMAP, "colormap"},
|
{META_COLORMAP, "colormap"},
|
||||||
{META_EXTRACOLORMAP,"extracolormap_t"},
|
{META_EXTRACOLORMAP,"extracolormap_t"},
|
||||||
{META_LIGHTTABLE, "lighttable_t"},
|
|
||||||
{META_CAMERA, "camera_t"},
|
{META_CAMERA, "camera_t"},
|
||||||
|
|
||||||
{META_ACTION, "action"},
|
{META_ACTION, "action"},
|
||||||
|
@ -2088,6 +2087,28 @@ static int lib_pCeilingzAtPos(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int lib_pGetSectorLightLevelAt(lua_State *L)
|
||||||
|
{
|
||||||
|
boolean has_sector = false;
|
||||||
|
sector_t *sector = NULL;
|
||||||
|
if (!lua_isnoneornil(L, 1))
|
||||||
|
{
|
||||||
|
has_sector = true;
|
||||||
|
sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR));
|
||||||
|
}
|
||||||
|
fixed_t x = luaL_checkfixed(L, 2);
|
||||||
|
fixed_t y = luaL_checkfixed(L, 3);
|
||||||
|
fixed_t z = luaL_checkfixed(L, 4);
|
||||||
|
INLEVEL
|
||||||
|
if (has_sector && !sector)
|
||||||
|
return LUA_ErrInvalid(L, "sector_t");
|
||||||
|
if (sector)
|
||||||
|
lua_pushinteger(L, P_GetLightLevelFromSectorAt(sector, x, y, z));
|
||||||
|
else
|
||||||
|
lua_pushinteger(L, P_GetSectorLightLevelAt(x, y, z));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int lib_pGetSectorColormapAt(lua_State *L)
|
static int lib_pGetSectorColormapAt(lua_State *L)
|
||||||
{
|
{
|
||||||
boolean has_sector = false;
|
boolean has_sector = false;
|
||||||
|
@ -4397,6 +4418,7 @@ static luaL_Reg lib[] = {
|
||||||
{"P_RadiusAttack",lib_pRadiusAttack},
|
{"P_RadiusAttack",lib_pRadiusAttack},
|
||||||
{"P_FloorzAtPos",lib_pFloorzAtPos},
|
{"P_FloorzAtPos",lib_pFloorzAtPos},
|
||||||
{"P_CeilingzAtPos",lib_pCeilingzAtPos},
|
{"P_CeilingzAtPos",lib_pCeilingzAtPos},
|
||||||
|
{"P_GetSectorLightLevelAt",lib_pGetSectorLightLevelAt},
|
||||||
{"P_GetSectorColormapAt",lib_pGetSectorColormapAt},
|
{"P_GetSectorColormapAt",lib_pGetSectorColormapAt},
|
||||||
{"P_DoSpring",lib_pDoSpring},
|
{"P_DoSpring",lib_pDoSpring},
|
||||||
{"P_TouchSpecialThing",lib_pTouchSpecialThing},
|
{"P_TouchSpecialThing",lib_pTouchSpecialThing},
|
||||||
|
|
|
@ -419,8 +419,7 @@ enum extracolormap_e {
|
||||||
extracolormap_fade_alpha,
|
extracolormap_fade_alpha,
|
||||||
extracolormap_fade_color,
|
extracolormap_fade_color,
|
||||||
extracolormap_fade_start,
|
extracolormap_fade_start,
|
||||||
extracolormap_fade_end,
|
extracolormap_fade_end
|
||||||
extracolormap_colormap
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *const extracolormap_opt[] = {
|
static const char *const extracolormap_opt[] = {
|
||||||
|
@ -436,7 +435,6 @@ static const char *const extracolormap_opt[] = {
|
||||||
"fade_color",
|
"fade_color",
|
||||||
"fade_start",
|
"fade_start",
|
||||||
"fade_end",
|
"fade_end",
|
||||||
"colormap",
|
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
static int extracolormap_get(lua_State *L)
|
static int extracolormap_get(lua_State *L)
|
||||||
|
@ -444,6 +442,9 @@ static int extracolormap_get(lua_State *L)
|
||||||
extracolormap_t *exc = *((extracolormap_t **)luaL_checkudata(L, 1, META_EXTRACOLORMAP));
|
extracolormap_t *exc = *((extracolormap_t **)luaL_checkudata(L, 1, META_EXTRACOLORMAP));
|
||||||
enum extracolormap_e field = luaL_checkoption(L, 2, NULL, extracolormap_opt);
|
enum extracolormap_e field = luaL_checkoption(L, 2, NULL, extracolormap_opt);
|
||||||
|
|
||||||
|
if (!exc)
|
||||||
|
return LUA_ErrInvalid(L, "extracolormap_t");
|
||||||
|
|
||||||
switch (field)
|
switch (field)
|
||||||
{
|
{
|
||||||
case extracolormap_red:
|
case extracolormap_red:
|
||||||
|
@ -488,9 +489,6 @@ static int extracolormap_get(lua_State *L)
|
||||||
case extracolormap_fade_end:
|
case extracolormap_fade_end:
|
||||||
lua_pushinteger(L, exc->fadeend);
|
lua_pushinteger(L, exc->fadeend);
|
||||||
break;
|
break;
|
||||||
case extracolormap_colormap:
|
|
||||||
LUA_PushUserdata(L, exc->colormap, META_LIGHTTABLE);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -515,6 +513,9 @@ static int extracolormap_set(lua_State *L)
|
||||||
extracolormap_t *exc = *((extracolormap_t **)luaL_checkudata(L, 1, META_EXTRACOLORMAP));
|
extracolormap_t *exc = *((extracolormap_t **)luaL_checkudata(L, 1, META_EXTRACOLORMAP));
|
||||||
enum extracolormap_e field = luaL_checkoption(L, 2, NULL, extracolormap_opt);
|
enum extracolormap_e field = luaL_checkoption(L, 2, NULL, extracolormap_opt);
|
||||||
|
|
||||||
|
if (!exc)
|
||||||
|
return LUA_ErrInvalid(L, "extracolormap_t");
|
||||||
|
|
||||||
UINT8 r = R_GetRgbaR(exc->rgba);
|
UINT8 r = R_GetRgbaR(exc->rgba);
|
||||||
UINT8 g = R_GetRgbaG(exc->rgba);
|
UINT8 g = R_GetRgbaG(exc->rgba);
|
||||||
UINT8 b = R_GetRgbaB(exc->rgba);
|
UINT8 b = R_GetRgbaB(exc->rgba);
|
||||||
|
@ -584,8 +585,6 @@ static int extracolormap_set(lua_State *L)
|
||||||
return luaL_error(L, "fade end %d out of range (0 - 31)", val);
|
return luaL_error(L, "fade end %d out of range (0 - 31)", val);
|
||||||
exc->fadeend = val;
|
exc->fadeend = val;
|
||||||
break;
|
break;
|
||||||
case extracolormap_colormap:
|
|
||||||
return luaL_error(L, LUA_QL("extracolormap_t") " field " LUA_QS " should not be set directly.", extracolormap_opt[field]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef val
|
#undef val
|
||||||
|
@ -599,46 +598,9 @@ static int extracolormap_set(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lighttable_get(lua_State *L)
|
|
||||||
{
|
|
||||||
void **userdata;
|
|
||||||
|
|
||||||
lighttable_t *table = *((lighttable_t **)luaL_checkudata(L, 1, META_LIGHTTABLE));
|
|
||||||
UINT32 row = luaL_checkinteger(L, 2);
|
|
||||||
if (row < 1 || row > 34)
|
|
||||||
return luaL_error(L, "lighttable row %d out of range (1 - %d)", row, 34);
|
|
||||||
|
|
||||||
userdata = lua_newuserdata(L, sizeof(void *));
|
|
||||||
*userdata = &table[256 * (row - 1)];
|
|
||||||
luaL_getmetatable(L, META_COLORMAP);
|
|
||||||
lua_setmetatable(L, -2);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lighttable_len(lua_State *L)
|
|
||||||
{
|
|
||||||
lua_pushinteger(L, NUM_PALETTE_ENTRIES);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LUA_ColorLib(lua_State *L)
|
int LUA_ColorLib(lua_State *L)
|
||||||
{
|
{
|
||||||
luaL_newmetatable(L, META_EXTRACOLORMAP);
|
LUA_RegisterUserdataMetatable(L, META_EXTRACOLORMAP, extracolormap_get, extracolormap_set, NULL);
|
||||||
lua_pushcfunction(L, extracolormap_get);
|
|
||||||
lua_setfield(L, -2, "__index");
|
|
||||||
|
|
||||||
lua_pushcfunction(L, extracolormap_set);
|
|
||||||
lua_setfield(L, -2, "__newindex");
|
|
||||||
lua_pop(L, 1);
|
|
||||||
|
|
||||||
luaL_newmetatable(L, META_LIGHTTABLE);
|
|
||||||
lua_pushcfunction(L, lighttable_get);
|
|
||||||
lua_setfield(L, -2, "__index");
|
|
||||||
|
|
||||||
lua_pushcfunction(L, lighttable_len);
|
|
||||||
lua_setfield(L, -2, "__len");
|
|
||||||
lua_pop(L, 1);
|
|
||||||
|
|
||||||
luaL_register(L, "color", color_lib);
|
luaL_register(L, "color", color_lib);
|
||||||
|
|
||||||
|
|
|
@ -1164,6 +1164,45 @@ static int libd_getStringColormap(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int libd_getSectorColormap(lua_State *L)
|
||||||
|
{
|
||||||
|
boolean has_sector = false;
|
||||||
|
sector_t *sector = NULL;
|
||||||
|
if (!lua_isnoneornil(L, 1))
|
||||||
|
{
|
||||||
|
has_sector = true;
|
||||||
|
sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR));
|
||||||
|
}
|
||||||
|
fixed_t x = luaL_checkfixed(L, 2);
|
||||||
|
fixed_t y = luaL_checkfixed(L, 3);
|
||||||
|
fixed_t z = luaL_checkfixed(L, 4);
|
||||||
|
int lightlevel = luaL_optinteger(L, 5, 255);
|
||||||
|
UINT8 *colormap = NULL;
|
||||||
|
extracolormap_t *exc = NULL;
|
||||||
|
|
||||||
|
INLEVEL
|
||||||
|
HUDONLY
|
||||||
|
|
||||||
|
if (has_sector && !sector)
|
||||||
|
return LUA_ErrInvalid(L, "sector_t");
|
||||||
|
|
||||||
|
if (sector)
|
||||||
|
exc = P_GetColormapFromSectorAt(sector, x, y, z);
|
||||||
|
else
|
||||||
|
exc = P_GetSectorColormapAt(x, y, z);
|
||||||
|
|
||||||
|
if (exc)
|
||||||
|
colormap = exc->colormap;
|
||||||
|
else
|
||||||
|
colormap = colormaps;
|
||||||
|
|
||||||
|
lightlevel = 255 - min(max(lightlevel, 0), 255);
|
||||||
|
lightlevel >>= 3;
|
||||||
|
|
||||||
|
LUA_PushUserdata(L, colormap + (lightlevel * 256), META_COLORMAP);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int libd_fadeScreen(lua_State *L)
|
static int libd_fadeScreen(lua_State *L)
|
||||||
{
|
{
|
||||||
huddrawlist_h list;
|
huddrawlist_h list;
|
||||||
|
@ -1310,6 +1349,7 @@ static luaL_Reg lib_draw[] = {
|
||||||
{"getSprite2Patch", libd_getSprite2Patch},
|
{"getSprite2Patch", libd_getSprite2Patch},
|
||||||
{"getColormap", libd_getColormap},
|
{"getColormap", libd_getColormap},
|
||||||
{"getStringColormap", libd_getStringColormap},
|
{"getStringColormap", libd_getStringColormap},
|
||||||
|
{"getSectorColormap", libd_getSectorColormap},
|
||||||
// drawing
|
// drawing
|
||||||
{"draw", libd_draw},
|
{"draw", libd_draw},
|
||||||
{"drawScaled", libd_drawScaled},
|
{"drawScaled", libd_drawScaled},
|
||||||
|
|
|
@ -86,7 +86,6 @@ extern boolean ignoregameinputs;
|
||||||
#define META_PATCH "PATCH_T*"
|
#define META_PATCH "PATCH_T*"
|
||||||
#define META_COLORMAP "COLORMAP"
|
#define META_COLORMAP "COLORMAP"
|
||||||
#define META_EXTRACOLORMAP "EXTRACOLORMAP_T*"
|
#define META_EXTRACOLORMAP "EXTRACOLORMAP_T*"
|
||||||
#define META_LIGHTTABLE "LIGHTTABLE_T*"
|
|
||||||
#define META_CAMERA "CAMERA_T*"
|
#define META_CAMERA "CAMERA_T*"
|
||||||
|
|
||||||
#define META_ACTION "ACTIONF_T*"
|
#define META_ACTION "ACTIONF_T*"
|
||||||
|
|
|
@ -947,6 +947,8 @@ void LUA_InvalidateLevel(void)
|
||||||
LUA_InvalidateUserdata(§ors[i]);
|
LUA_InvalidateUserdata(§ors[i]);
|
||||||
LUA_InvalidateUserdata(§ors[i].lines);
|
LUA_InvalidateUserdata(§ors[i].lines);
|
||||||
LUA_InvalidateUserdata(§ors[i].tags);
|
LUA_InvalidateUserdata(§ors[i].tags);
|
||||||
|
if (sectors[i].extra_colormap)
|
||||||
|
LUA_InvalidateUserdata(sectors[i].extra_colormap);
|
||||||
if (sectors[i].ffloors)
|
if (sectors[i].ffloors)
|
||||||
{
|
{
|
||||||
for (rover = sectors[i].ffloors; rover; rover = rover->next)
|
for (rover = sectors[i].ffloors; rover; rover = rover->next)
|
||||||
|
|
|
@ -446,7 +446,9 @@ boolean PIT_PushableMoved(mobj_t *thing);
|
||||||
|
|
||||||
boolean P_DoSpring(mobj_t *spring, mobj_t *object);
|
boolean P_DoSpring(mobj_t *spring, mobj_t *object);
|
||||||
|
|
||||||
INT32 P_GetSectorLightAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z);
|
INT32 P_GetSectorLightNumAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z);
|
||||||
|
INT32 P_GetLightLevelFromSectorAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z);
|
||||||
|
INT32 P_GetSectorLightLevelAt(fixed_t x, fixed_t y, fixed_t z);
|
||||||
extracolormap_t *P_GetColormapFromSectorAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z);
|
extracolormap_t *P_GetColormapFromSectorAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z);
|
||||||
extracolormap_t *P_GetSectorColormapAt(fixed_t x, fixed_t y, fixed_t z);
|
extracolormap_t *P_GetSectorColormapAt(fixed_t x, fixed_t y, fixed_t z);
|
||||||
|
|
||||||
|
|
17
src/p_map.c
17
src/p_map.c
|
@ -5079,7 +5079,7 @@ fixed_t P_CeilingzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height)
|
||||||
return ceilingz;
|
return ceilingz;
|
||||||
}
|
}
|
||||||
|
|
||||||
INT32 P_GetSectorLightAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z)
|
INT32 P_GetSectorLightNumAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z)
|
||||||
{
|
{
|
||||||
if (!sector->numlights)
|
if (!sector->numlights)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -5098,10 +5098,23 @@ INT32 P_GetSectorLightAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z)
|
||||||
return light;
|
return light;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INT32 P_GetLightLevelFromSectorAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z)
|
||||||
|
{
|
||||||
|
if (sector->numlights)
|
||||||
|
return *sector->lightlist[P_GetSectorLightNumAt(sector, x, y, z)].lightlevel;
|
||||||
|
else
|
||||||
|
return sector->lightlevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT32 P_GetSectorLightLevelAt(fixed_t x, fixed_t y, fixed_t z)
|
||||||
|
{
|
||||||
|
return P_GetLightLevelFromSectorAt(R_PointInSubsector(x, y)->sector, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
extracolormap_t *P_GetColormapFromSectorAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z)
|
extracolormap_t *P_GetColormapFromSectorAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z)
|
||||||
{
|
{
|
||||||
if (sector->numlights)
|
if (sector->numlights)
|
||||||
return *sector->lightlist[P_GetSectorLightAt(sector, x, y, z)].extra_colormap;
|
return *sector->lightlist[P_GetSectorLightNumAt(sector, x, y, z)].extra_colormap;
|
||||||
else
|
else
|
||||||
return sector->extra_colormap;
|
return sector->extra_colormap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2126,7 +2126,7 @@ static void R_ProjectSprite(mobj_t *thing)
|
||||||
|
|
||||||
if (thing->subsector->sector->numlights)
|
if (thing->subsector->sector->numlights)
|
||||||
{
|
{
|
||||||
light = P_GetSectorLightAt(thing->subsector->sector, interp.x, interp.y, splat ? gz : gzt);
|
light = P_GetSectorLightNumAt(thing->subsector->sector, interp.x, interp.y, splat ? gz : gzt);
|
||||||
|
|
||||||
INT32 lightnum = (*thing->subsector->sector->lightlist[light].lightlevel >> LIGHTSEGSHIFT);
|
INT32 lightnum = (*thing->subsector->sector->lightlist[light].lightlevel >> LIGHTSEGSHIFT);
|
||||||
if (lightnum < 0)
|
if (lightnum < 0)
|
||||||
|
|
Loading…
Reference in a new issue