Commit e67e5391 authored by Richard Gobeille's avatar Richard Gobeille
Browse files

Duke3d: fix a few polymer lighting bugs, add interpolation to light positions, etc

parent b6740a7b
......@@ -14,11 +14,19 @@ typedef struct s_prplanelist {
#pragma pack(push,1)
typedef struct s_prlight {
int32_t x, y, z, horiz, range;
union {
struct
{
int32_t x, y, z;
};
vec3_t xyz;
vec2_t xy;
};
int32_t horiz, range;
int16_t angle, faderadius, radius, sector;
uint8_t color[3], priority;
int8_t minshade, maxshade;
int16_t tilenum;
int16_t tilenum, owner;
struct {
int emitshadow : 1;
int negative : 1;
......
......@@ -385,6 +385,7 @@ int32_t engineLoadMHK(const char *filename)
light.priority = value;
scriptfile_getsymbol(script, &value);
light.tilenum = value;
light.owner = -1;
light.publicflags.emitshadow = 1;
light.publicflags.negative = 0;
......
This diff is collapsed.
......@@ -146,9 +146,22 @@ EDUKE32_STATIC_ASSERT(sizeof(actor_t) == 96);
typedef struct
{
_prlight *lightptr; // 4b/8b aligned on 96 bytes
vec3_t lightoffset;
int16_t lightId, lightmaxrange; // 4b
uint8_t lightcount, filler[3]; // 4b
int16_t lightrange, olightrange;
int16_t lightang, olightang;
uint8_t lightcount, lightcolidx; // 4b
} practor_t;
// NOTE: T5 is AC_ACTION_ID
#define LIGHTRAD_PICOFS(i) (T5(i) ? *(apScript + T5(i)) + (*(apScript + T5(i) + 2)) * AC_CURFRAME(actor[i].t_data) : 0)
// this is the same crap as in game.c's tspr manipulation. puke.
// XXX: may access tilesizy out-of-bounds by bad user code.
#define LIGHTRAD(s) (sprite[s].yrepeat * tilesiz[sprite[s].picnum + LIGHTRAD_PICOFS(s)].y)
#define LIGHTRAD2(s) ((sprite[s].yrepeat + ((rand() % sprite[s].yrepeat)>>2)) * tilesiz[sprite[s].picnum + LIGHTRAD_PICOFS(s)].y)
#define LIGHTRAD3(s) (sprite[s].yrepeat * tilesiz[sprite[s].picnum].y)
#define LIGHTZOFF(s) ((sprite[s].yrepeat*tilesiz[sprite[s].picnum].y)<<1)
#endif
// note: fields in this struct DO NOT have to be in this order,
......@@ -405,8 +418,9 @@ void A_RadiusDamage(int spriteNum, int blastRadius, int dmg1, int dmg2, int dmg3
void A_SpawnMultiple(int spriteNum, int tileNum, int spawnCnt);
int G_SetInterpolation(int32_t *posptr);
void G_AddGameLight(int lightRadius, int spriteNum, int zOffset, int lightRange, int lightColor, int lightPrio);
void G_DeleteAllLights(void);
void G_AddGameLight(int spriteNum, int sectNum, vec3_t const &offset, int lightRange, int lightRadius, int lightHoriz, uint32_t lightColor, int lightPrio);
void G_InterpolateLights(int smoothratio);
void G_ClearCameraView(DukePlayer_t *ps);
void G_DoInterpolations(int smoothRatio);
void G_MoveWorld(void);
......
......@@ -825,6 +825,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio)
G_DoInterpolations(smoothRatio);
G_AnimateCamSprite(smoothRatio);
G_InterpolateLights(smoothRatio);
if (ud.camerasprite >= 0)
{
......@@ -2700,7 +2701,7 @@ int A_Spawn(int spriteNum, int tileNum)
#ifdef POLYMER
if (pSprite->yrepeat > 32)
{
G_AddGameLight(0, newSprite, ((pSprite->yrepeat*tilesiz[pSprite->picnum].y)<<1), 32768, 255+(95<<8),PR_LIGHT_PRIO_MAX_GAME);
G_AddGameLight(newSprite, pSprite->sectnum, { 0, 0, LIGHTZOFF(spriteNum) }, 32768, 0, 100,255+(95<<8), PR_LIGHT_PRIO_MAX_GAME);
practor[newSprite].lightcount = 2;
}
fallthrough__;
......
......@@ -303,6 +303,7 @@ extern char ror_protectedsectors[MAXSECTORS];
#endif
extern float r_ambientlight;
extern int32_t r_pr_defaultlights;
extern bool g_frameJustDrawn;
extern uint64_t g_lastFrameStartTime;
......
......@@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat;
float r_ambientlight = 1.0, r_ambientlightrecip = 1.0;
int32_t r_pr_defaultlights = 1;
uint32_t cl_cheatmask;
......@@ -1693,6 +1694,8 @@ int32_t registerosdcommands(void)
{ "r_ambientlight", "sets the global map light level",(void *)&r_ambientlight, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
{ "r_pr_defaultlights", "default polymer lights:\n 0: off\n 1: on",(void *)&r_pr_defaultlights, CVAR_BOOL, 0, 1 },
{ "skill","changes the game skill setting", (void *)&ud.m_player_skill, CVAR_INT|CVAR_FUNCPTR|CVAR_NOSAVE/*|CVAR_NOMULTI*/, 0, 5 },
{ "snd_ambience", "ambient sounds" CVAR_BOOL_OPTSTR, (void *)&ud.config.AmbienceToggle, CVAR_BOOL, 0, 1 },
......
......@@ -861,14 +861,9 @@ static int A_ShootCustom(int const spriteNum, int const projecTile, int shootAng
#ifdef POLYMER
if (videoGetRenderMode() == REND_POLYMER && pProj->flashcolor)
{
int32_t x = ((sintable[(pSprite->ang + 512) & 2047]) >> 7), y = ((sintable[(pSprite->ang) & 2047]) >> 7);
pSprite->x += x;
pSprite->y += y;
G_AddGameLight(0, spriteNum, pPlayer->spritezoffset, 8192, pProj->flashcolor, PR_LIGHT_PRIO_MAX_GAME);
vec3_t const offset = { -((sintable[(pSprite->ang+512)&2047])>>7), -((sintable[(pSprite->ang)&2047])>>7), PHEIGHT };
G_AddGameLight(spriteNum, pSprite->sectnum, offset, 8192, 0, 100, pProj->flashcolor, PR_LIGHT_PRIO_MAX_GAME);
practor[spriteNum].lightcount = 2;
pSprite->x -= x;
pSprite->y -= y;
}
#endif // POLYMER
......@@ -1709,15 +1704,9 @@ int A_ShootWithZvel(int const spriteNum, int const projecTile, int const forceZv
case RPG__:
case MORTER__:
{
vec2_t const v = { ((sintable[(pSprite->ang + 512) & 2047]) >> 7),
((sintable[(pSprite->ang) & 2047]) >> 7) };
pSprite->x += v.x;
pSprite->y += v.y;
G_AddGameLight(0, spriteNum, PHEIGHT, 8192, 255 + (95 << 8), PR_LIGHT_PRIO_MAX_GAME);
vec3_t const offset = { -((sintable[(pSprite->ang+512)&2047])>>7), -((sintable[(pSprite->ang)&2047])>>7), PHEIGHT };
G_AddGameLight(spriteNum, pSprite->sectnum, offset, 8192, 0, 100, 255 + (95 << 8), PR_LIGHT_PRIO_MAX_GAME);
practor[spriteNum].lightcount = 2;
pSprite->x -= v.x;
pSprite->y -= v.y;
}
break;
......@@ -2068,16 +2057,10 @@ static void P_FireWeapon(int playerNum)
if (!(PWEAPON(playerNum, pPlayer->curr_weapon, Flags) & WEAPON_NOVISIBLE))
{
#ifdef POLYMER
spritetype *s = &sprite[pPlayer->i];
int32_t x = ((sintable[(s->ang + 512) & 2047]) >> 7), y = ((sintable[(s->ang) & 2047]) >> 7);
s->x += x;
s->y += y;
G_AddGameLight(0, pPlayer->i, pPlayer->spritezoffset, 8192, PWEAPON(playerNum, pPlayer->curr_weapon, FlashColor),
PR_LIGHT_PRIO_MAX_GAME);
auto s = (uspriteptr_t)&sprite[pPlayer->i];
vec3_t const offset = { -((sintable[(s->ang+512)&2047])>>7), -((sintable[(s->ang)&2047])>>7), pPlayer->spritezoffset };
G_AddGameLight(pPlayer->i, pPlayer->cursectnum, offset, 8192, 0, 100, PWEAPON(playerNum, pPlayer->curr_weapon, FlashColor), PR_LIGHT_PRIO_MAX_GAME);
practor[pPlayer->i].lightcount = 2;
s->x -= x;
s->y -= y;
#endif // POLYMER
pPlayer->visibility = 0;
}
......@@ -4204,28 +4187,24 @@ static void P_ProcessWeapon(int playerNum)
}
}
if (PWEAPON(playerNum, pPlayer->curr_weapon, Flags) & WEAPON_GLOWS)
int const maybeGlowingWeapon = pPlayer->last_weapon != -1 ? pPlayer->last_weapon : pPlayer->curr_weapon;
if (PWEAPON(playerNum, maybeGlowingWeapon, Flags) & WEAPON_GLOWS)
{
pPlayer->random_club_frame += 64; // Glowing
#ifdef POLYMER
if (pPlayer->kickback_pic == 0)
{
auto const pSprite = &sprite[pPlayer->i];
int const glowXOffset = ((sintable[(pSprite->ang + 512) & 2047]) >> 7);
int const glowYOffset = ((sintable[(pSprite->ang) & 2047]) >> 7);
int const glowRange = 1024 + (sintable[pPlayer->random_club_frame & 2047] >> 3);
auto const pSprite = &sprite[pPlayer->i];
vec3_t const offset = { -((sintable[(pSprite->ang+512)&2047])>>7), -((sintable[(pSprite->ang)&2047])>>7), pPlayer->spritezoffset };
pSprite->x += glowXOffset;
pSprite->y += glowYOffset;
int const glowRange = (16-klabs(pPlayer->weapon_pos)+(sintable[pPlayer->random_club_frame & 2047]>>10))<<6;
G_AddGameLight(0, pPlayer->i, pPlayer->spritezoffset, max(glowRange, 0),
PWEAPON(playerNum, pPlayer->curr_weapon, FlashColor), PR_LIGHT_PRIO_HIGH_GAME);
G_AddGameLight(pPlayer->i, pPlayer->cursectnum, offset, max(glowRange, 0), 0, 100,
PWEAPON(playerNum, maybeGlowingWeapon, FlashColor), PR_LIGHT_PRIO_HIGH_GAME);
practor[pPlayer->i].lightcount = 2;
pSprite->x -= glowXOffset;
pSprite->y -= glowYOffset;
}
#endif
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment