From 6c3ed1ec9c09e5cf4f79cc8b5a093e66357b217f Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 7 Jun 2009 03:13:55 +0000 Subject: [PATCH] More light crap git-svn-id: https://svn.eduke32.com/eduke32@1410 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/engine.c | 38 +++++++++++--------- polymer/eduke32/build/src/polymer.c | 55 +++++++++++++++++++---------- polymer/eduke32/source/actors.c | 20 ++++++----- polymer/eduke32/source/duke3d.h | 1 + polymer/eduke32/source/savegame.c | 16 ++++++++- 5 files changed, 86 insertions(+), 44 deletions(-) diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 98a2f08c3..ac12bd7cf 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -10380,15 +10380,18 @@ int32_t sectorofwall(int16_t theline) // int32_t getceilzofslope(int16_t sectnum, int32_t dax, int32_t day) { - int32_t dx, dy, i, j; - walltype *wal; - if (!(sector[sectnum].ceilingstat&2)) return(sector[sectnum].ceilingz); - wal = &wall[sector[sectnum].wallptr]; - dx = wall[wal->point2].x-wal->x; dy = wall[wal->point2].y-wal->y; - i = (nsqrtasm(dx*dx+dy*dy)<<5); if (i == 0) return(sector[sectnum].ceilingz); - j = dmulscale3(dx,day-wal->y,-dy,dax-wal->x); - return(sector[sectnum].ceilingz+(scale(sector[sectnum].ceilingheinum,j>>1,i)<<1)); + + { + int32_t dx, dy, i, j; + walltype *wal; + + wal = &wall[sector[sectnum].wallptr]; + dx = wall[wal->point2].x-wal->x; dy = wall[wal->point2].y-wal->y; + i = (nsqrtasm(dx*dx+dy*dy)<<5); if (i == 0) return(sector[sectnum].ceilingz); + j = dmulscale3(dx,day-wal->y,-dy,dax-wal->x); + return(sector[sectnum].ceilingz+(scale(sector[sectnum].ceilingheinum,j>>1,i)<<1)); + } } @@ -10397,15 +10400,18 @@ int32_t getceilzofslope(int16_t sectnum, int32_t dax, int32_t day) // int32_t getflorzofslope(int16_t sectnum, int32_t dax, int32_t day) { - int32_t dx, dy, i, j; - walltype *wal; - if (!(sector[sectnum].floorstat&2)) return(sector[sectnum].floorz); - wal = &wall[sector[sectnum].wallptr]; - dx = wall[wal->point2].x-wal->x; dy = wall[wal->point2].y-wal->y; - i = (nsqrtasm(dx*dx+dy*dy)<<5); if (i == 0) return(sector[sectnum].floorz); - j = dmulscale3(dx,day-wal->y,-dy,dax-wal->x); - return(sector[sectnum].floorz+(scale(sector[sectnum].floorheinum,j>>1,i)<<1)); + + { + int32_t dx, dy, i, j; + walltype *wal; + + wal = &wall[sector[sectnum].wallptr]; + dx = wall[wal->point2].x-wal->x; dy = wall[wal->point2].y-wal->y; + i = (nsqrtasm(dx*dx+dy*dy)<<5); if (i == 0) return(sector[sectnum].floorz); + j = dmulscale3(dx,day-wal->y,-dy,dax-wal->x); + return(sector[sectnum].floorz+(scale(sector[sectnum].floorheinum,j>>1,i)<<1)); + } } diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index 019bca384..8e3e13bc9 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -4147,8 +4147,6 @@ static void polymer_removelight(int16_t lighti) { int32_t i; - // XXX: might need to store a list of affected planes in the light record - // if this loop ends up consuming too much cycles i = prlights[lighti].planecnt-1; while (i >= 0) { @@ -4241,23 +4239,21 @@ static void polymer_addplanelight(_prplane* plane, int16_t lighti) return; i = 0; - while (i < PR_MAXLIGHTS) + do { - if ((plane->lights[i] != -1) && (prlights[plane->lights[i]].priority >= prlights[lighti].priority)) - break; + if ((plane->lights[i] != -1) && (prlights[plane->lights[i]].priority < prlights[lighti].priority)) + { i++; continue; } - if (plane->lights[i] == -1) - { + if (plane->lights[i] != -1) memmove(&plane->lights[i+1], &plane->lights[i], sizeof(int16_t) * (PR_MAXLIGHTS - (i+1))); - plane->lights[i] = lighti; - plane->lightcount++; - prlights[lighti].myplanes[prlights[lighti].planecnt] = plane; - prlights[lighti].planecnt++; - return; - } - i++; + plane->lights[i] = lighti; + plane->lightcount++; + prlights[lighti].myplanes[prlights[lighti].planecnt] = plane; + prlights[lighti].planecnt++; + return; } + while (i < PR_MAXLIGHTS); } static inline void polymer_deleteplanelight(_prplane* plane, int16_t lighti) @@ -4265,7 +4261,7 @@ static inline void polymer_deleteplanelight(_prplane* plane, int16_t lighti) int16_t i; i = 0; - while (i < PR_MAXLIGHTS) + do { if (plane->lights[i] == lighti) { @@ -4277,6 +4273,7 @@ static inline void polymer_deleteplanelight(_prplane* plane, int16_t lighti) } i++; } + while (i < PR_MAXLIGHTS); } static int32_t polymer_planeinlight(_prplane* plane, _prlight* light) @@ -4296,22 +4293,24 @@ static int32_t polymer_planeinlight(_prplane* plane, _prlight* light) i = 0; - while (i < 3) + do { j = k = l = 0; - while (j < plane->vertcount) + do { if (plane->buffer[(j * 5) + i] > (lightpos[i] + light->range)) k++; if (plane->buffer[(j * 5) + i] < (lightpos[i] - light->range)) l++; j++; } + while (j < plane->vertcount); if ((k == plane->vertcount) || (l == plane->vertcount)) return 0; i++; } + while (i < 3); return 1; } @@ -4420,12 +4419,14 @@ static void polymer_processspotlight(_prlight* light) } } + static inline void polymer_culllight(int16_t lighti) { _prlight* light; int32_t front; int32_t back; int32_t i; + int32_t j; _prsector *s; _prwall *w; sectortype *sec; @@ -4448,10 +4449,19 @@ static inline void polymer_culllight(int16_t lighti) polymer_pokesector(sectorqueue[front]); + j = 0; + if (polymer_planeinlight(&s->floor, light)) { + // this lets us skip the polymer_planeinlight check for the ceiling when we know it will pass + // I doubt this saves us much but it might be faster on complex sectors than the loop + if (!light->radius && + ((light->z - getceilzofslope(light->sector, light->x, light->y)) >> 4) < light->range) + j++; + polymer_addplanelight(&s->floor, lighti); } - if (polymer_planeinlight(&s->ceil, light)) { + + if (j /*|| polymer_planeinlight(&s->ceil, light)*/) { polymer_addplanelight(&s->ceil, lighti); } @@ -4460,14 +4470,21 @@ static inline void polymer_culllight(int16_t lighti) { w = prwalls[sec->wallptr + i]; + j = 0; + if (polymer_planeinlight(&w->wall, light)) { polymer_addplanelight(&w->wall, lighti); + j++; } + if (polymer_planeinlight(&w->over, light)) { polymer_addplanelight(&w->over, lighti); + j++; } + + // assume the light hits the middle section if it hits the top and bottom if (wallvisible(light->x, light->y, sec->wallptr + i) && - polymer_planeinlight(&w->mask, light)) { + (j == 2 || polymer_planeinlight(&w->mask, light))) { if ((w->mask.vertcount == 4) && (w->mask.buffer[(0 * 5) + 1] >= w->mask.buffer[(3 * 5) + 1]) && (w->mask.buffer[(1 * 5) + 1] >= w->mask.buffer[(2 * 5) + 1])) diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index eb58574c6..68f416a30 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -601,7 +601,7 @@ inline void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, i mylight.color[1] = (color>>8)&255; mylight.color[2] = (color>>16)&255; mylight.radius = radius; - mylight.range = range; + ActorExtra[srcsprite].maxrange = mylight.range = range; mylight.priority = priority; @@ -612,8 +612,12 @@ inline void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, i } s->z -= zoffset; - if (Bmemcmp(&sprite[srcsprite], ActorExtra[srcsprite].lightptr, sizeof(int32_t) * 3)) + if (range > ActorExtra[srcsprite].maxrange || + Bmemcmp(&sprite[srcsprite], ActorExtra[srcsprite].lightptr, sizeof(int32_t) * 3)) { + if (range > ActorExtra[srcsprite].maxrange) + ActorExtra[srcsprite].maxrange = range; + Bmemcpy(ActorExtra[srcsprite].lightptr, &sprite[srcsprite], sizeof(int32_t) * 3); ActorExtra[srcsprite].lightptr->sector = s->sectnum; ActorExtra[srcsprite].lightptr->flags.invalidate = 1; @@ -665,7 +669,7 @@ static void G_MoveZombieActors(void) case FLOORFLAME__STATIC: case FIREBARREL__STATIC: case FIREVASE__STATIC: - G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_MAX_GAME); + G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_HIGH_GAME); break; case ATOMICHEALTH__STATIC: G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), 2048, 128+(128<<8)+(255<<16),PR_LIGHT_PRIO_HIGH_GAME); @@ -677,7 +681,7 @@ static void G_MoveZombieActors(void) if (ActorExtra[i].floorz - ActorExtra[i].ceilingz < 128) break; if (s->z > ActorExtra[i].floorz+2048) break; */ - G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_MAX_GAME); + G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_HIGH_GAME); break; case BURNING__STATIC: case BURNING2__STATIC: @@ -685,7 +689,7 @@ static void G_MoveZombieActors(void) if (ActorExtra[i].floorz - ActorExtra[i].ceilingz < 128) break; if (s->z > ActorExtra[i].floorz + 2048) break; */ - G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_MAX_GAME); + G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_HIGH_GAME); break; case EXPLOSION2__STATIC: @@ -2250,7 +2254,7 @@ CLEAR_THE_BOLT: case FLOORFLAME__STATIC: case FIREBARREL__STATIC: case FIREVASE__STATIC: - G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_MAX_GAME); + G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_HIGH_GAME); case EXPLODINGBARREL__STATIC: case WOODENHORSE__STATIC: case HORSEONSIDE__STATIC: @@ -3470,7 +3474,7 @@ static void G_MoveActors(void) if (ActorExtra[i].floorz - ActorExtra[i].ceilingz < 128) break; if (s->z > ActorExtra[i].floorz+2048) break; */ - G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_MAX_GAME); + G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_HIGH_GAME); break; case DUCK__STATIC: @@ -5225,7 +5229,7 @@ static void G_MoveMisc(void) // STATNUM 5 if (ActorExtra[i].floorz - ActorExtra[i].ceilingz < 128) break; if (s->z > ActorExtra[i].floorz + 2048) break; */ - G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_MAX_GAME); + G_AddGameLight(0, i, ((s->yrepeat*tilesizy[s->picnum])<<1), LIGHTRAD, 255+(95<<8),PR_LIGHT_PRIO_HIGH_GAME); break; case EXPLOSION2__STATIC: diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index 311c1dcc1..a90d52ff4 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -549,6 +549,7 @@ typedef struct { #ifdef POLYMER int16_t lightId; int16_t lightcount; // how many tics until light is killed + int16_t maxrange; _prlight *lightptr; #endif } ActorData_t; diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 74c9605e9..f55720ea0 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -587,8 +587,22 @@ int32_t G_LoadPlayer(int32_t spot) G_ResetTimers(); #ifdef POLYMER - if (getrendermode() >= 4) + if (getrendermode() == 4) + { + int32_t i = 0; + polymer_loadboard(); + while (i < MAXSPRITES) + { + if (ActorExtra[i].lightptr) + { + polymer_deletelight(ActorExtra[i].lightId); + ActorExtra[i].lightptr = NULL; + ActorExtra[i].lightId = -1; + } + i++; + } + } #endif return(0);