- safety commit for displayrooms.

This commit is contained in:
Christoph Oelckers 2020-07-05 16:49:00 +02:00
parent 53f36e5c40
commit 7ead48b9d9
9 changed files with 552 additions and 183 deletions

View file

@ -2,7 +2,6 @@
set( PCH_SOURCES
src/2d_d.cpp
src/2d_r.cpp
src/game_main.cpp
src/actors.cpp
src/actors_r.cpp
src/actors_d.cpp
@ -16,6 +15,7 @@ set( PCH_SOURCES
src/dispatch.cpp
src/flags_d.cpp
src/flags_r.cpp
src/game_misc.cpp
src/gamedef.cpp
src/gameexec.cpp
src/gamevar.cpp

View file

@ -26,6 +26,9 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
*/
//-------------------------------------------------------------------------
// This file collects several functions from the original game.c
// that do not fit any particular category.
#include "ns.h" // Must come before everything else!
#include "duke3d.h"

View file

@ -120,8 +120,7 @@ G_EXTERN int32_t g_animWallCnt;
G_EXTERN int32_t g_animateCnt;
#define animatecnt g_animateCnt
G_EXTERN int32_t numclouds;
G_EXTERN int32_t g_curViewscreen;
#define camsprite g_curViewscreen
G_EXTERN int32_t camsprite;
G_EXTERN int32_t g_frameRate;
G_EXTERN int32_t g_cyclerCnt;
#define numcyclers g_cyclerCnt

View file

@ -27,6 +27,8 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
#include "ns.h"
#include "duke3d.h"
#include "build.h"
#include "v_video.h"
BEGIN_DUKE_NS
@ -168,9 +170,12 @@ void SE40_Draw(int tag, int spnum, int x, int y, int z, int a, int h, int smooth
//
//---------------------------------------------------------------------------
void se40code(int tag, int x, int y, int z, int a, int h, int smoothratio)
void se40code(int x, int y, int z, int a, int h, int smoothratio)
{
int i;
int i, tag;
if (!isRR()) tag = 40;
else if (isRRRA()) tag = 150;
else return;
i = headspritestat[STAT_RAROR];
while (i >= 0)
@ -194,4 +199,428 @@ void se40code(int tag, int x, int y, int z, int a, int h, int smoothratio)
}
//---------------------------------------------------------------------------
//
// split out so it can also be applied to camera views
//
//---------------------------------------------------------------------------
void renderMirror(int cposx, int cposy, int cposz, int cang, int choriz, int smoothratio)
{
if ((gotpic[TILE_MIRROR >> 3] & (1 << (TILE_MIRROR & 7))) > 0)
{
int dst = 0x7fffffff, i = 0;
for (int k = 0; k < mirrorcnt; k++)
{
int j = abs(wall[mirrorwall[k]].x - cposx) + abs(wall[mirrorwall[k]].y - cposy);
if (j < dst) dst = j, i = k;
}
if (wall[mirrorwall[i]].overpicnum == TILE_MIRROR)
{
int tposx, tposy, tposz, tang;
renderPrepareMirror(cposx, cposy, cposz, cang, choriz, mirrorwall[i], &tposx, &tposy, &tang);
int j = g_visibility;
g_visibility = (j >> 1) + (j >> 2);
drawrooms(tposx, tposy, cposz, tang, choriz, mirrorsector[i] + MAXSECTORS);
display_mirror = 1;
fi.animatesprites(tposx, tposy, tang, smoothratio);
display_mirror = 0;
renderDrawMasks();
renderCompleteMirror(); //Reverse screen x-wise in this function
g_visibility = j;
}
gotpic[TILE_MIRROR >> 3] &= ~(1 << (TILE_MIRROR & 7));
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void animatecamsprite(int smoothRatio)
{
if (camsprite < 0)
return;
int spriteNum = camsprite;
auto p = &ps[screenpeek];
auto sp = &sprite[spriteNum];
if (p->newowner >= 0) sp->owner = p->newowner;
if (sp->owner >= 0 && dist(&sprite[p->i], sp) < VIEWSCREEN_ACTIVE_DISTANCE)
{
auto tex = tileGetTexture(sp->picnum);
TileFiles.MakeCanvas(TILE_VIEWSCR, tex->GetDisplayWidth(), tex->GetDisplayHeight());
auto canvas = renderSetTarget(TILE_VIEWSCR);
if (!canvas) return;
screen->RenderTextureView(canvas, [=](IntRect& rect)
{
// fixme: This needs to interpolate the camera's angle. Position is not relevant because cameras do not move.
auto camera = &sprite[sp->owner];
// Note: no ROR or camera here for now - the current setup has no means to detect these things before rendering the scene itself.
drawrooms(camera->x, camera->y, camera->z, camera->ang, 100 + camera->shade, camera->sectnum); // why 'shade'...?
display_mirror = 1; // should really be 'display external view'.
fi.animatesprites(camera->x, camera->y, camera->ang, smoothRatio);
display_mirror = 0;
renderDrawMasks();
});
renderRestoreTarget();
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void setdrugmode(player_struct *p, int oyrepeat)
{
if (!paused)
{
if (p->DrugMode > 0 && !(p->gm & MODE_TYPE) && !ud.pause_on)
{
int var_8c;
if (p->drug_stat[0] == 0)
{
p->drug_stat[1]++;
var_8c = oyrepeat + p->drug_stat[1] * 5000;
if (oyrepeat * 3 < var_8c)
{
renderSetAspect(oyrepeat * 3, yxaspect);
p->drug_aspect = oyrepeat * 3;
p->drug_stat[0] = 2;
}
else
{
renderSetAspect(var_8c, yxaspect);
p->drug_aspect = var_8c;
}
setpal(p);
}
else if (p->drug_stat[0] == 3)
{
p->drug_stat[1]--;
var_8c = oyrepeat + p->drug_stat[1] * 5000;
if (var_8c < oyrepeat)
{
renderSetAspect(oyrepeat, yxaspect);
p->DrugMode = 0;
p->drug_stat[0] = 0;
p->drug_stat[2] = 0;
p->drug_stat[1] = 0;
}
else
{
renderSetAspect(var_8c, yxaspect);
p->drug_aspect = var_8c;
}
setpal(p);
}
else if (p->drug_stat[0] == 2)
{
if (p->drug_stat[2] > 30)
{
p->drug_stat[0] = 1;
}
else
{
p->drug_stat[2]++;
renderSetAspect(p->drug_stat[2] * 500 + oyrepeat * 3, yxaspect);
p->drug_aspect = oyrepeat * 3 + p->drug_stat[2] * 500;
setpal(p);
}
}
else
{
if (p->drug_stat[2] < 1)
{
p->drug_stat[0] = 2;
p->DrugMode--;
if (p->DrugMode == 1)
p->drug_stat[0] = 3;
}
else
{
p->drug_stat[2]--;
renderSetAspect(p->drug_stat[2] * 500 + oyrepeat * 3, yxaspect);
p->drug_aspect = oyrepeat * 3 + p->drug_stat[2] * 500;
setpal(p);
}
}
}
}
else if (p->DrugMode > 0)
{
renderSetAspect(p->drug_aspect, yxaspect);
setpal(p);
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void tag848Hackery(int cposx, int cposy, int cposz, int cang, int choriz, int sect, int smoothratio)
{
short gs, tgsect, nextspr, geosect, geoid;
int spr;
drawrooms(cposx, cposy, cposz, cang, choriz, sect);
fi.animatesprites(cposx, cposy, cang, smoothratio);
renderDrawMasks();
for (gs = 0; gs < geocnt; gs++)
{
tgsect = geosector[gs];
spr = headspritesect[tgsect];
while (spr != -1)
{
nextspr = nextspritesect[spr];
changespritesect((short)spr, geosectorwarp[gs]);
setsprite((short)spr, sprite[spr].x -= geox[gs], sprite[spr].y -= geoy[gs], sprite[spr].z);
spr = nextspr;
}
if (geosector[gs] == sect)
{
geosect = geosectorwarp[gs];
geoid = gs;
}
}
cposx -= geox[geoid];
cposy -= geoy[geoid];
drawrooms(cposx, cposy, cposz, cang, choriz, sect);
cposx += geox[geoid];
cposy += geoy[geoid];
for (gs = 0; gs < geocnt; gs++)
{
tgsect = geosectorwarp[gs];
spr = headspritesect[tgsect];
while (spr != -1)
{
nextspr = nextspritesect[spr];
changespritesect((short)spr, geosector[gs]);
setsprite((short)spr, sprite[spr].x += geox[gs], sprite[spr].y += geoy[gs], sprite[spr].z);
spr = nextspr;
}
}
fi.animatesprites(cposx, cposy, cang, smoothratio);
renderDrawMasks();
for (gs = 0; gs < geocnt; gs++)
{
tgsect = geosector[gs];
spr = headspritesect[tgsect];
while (spr != -1)
{
nextspr = nextspritesect[spr];
changespritesect((short)spr, geosectorwarp2[gs]);
setsprite((short)spr, sprite[spr].x -= geox2[gs], sprite[spr].y -= geoy2[gs], sprite[spr].z);
spr = nextspr;
}
if (geosector[gs] == sect)
{
geosect = geosectorwarp2[gs];
geoid = gs;
}
}
cposx -= geox2[geoid];
cposy -= geoy2[geoid];
drawrooms(cposx, cposy, cposz, cang, choriz, sect);
cposx += geox2[geoid];
cposy += geoy2[geoid];
for (gs = 0; gs < geocnt; gs++)
{
tgsect = geosectorwarp2[gs];
spr = headspritesect[tgsect];
while (spr != -1)
{
nextspr = nextspritesect[spr];
changespritesect((short)spr, geosector[gs]);
setsprite((short)spr, sprite[spr].x += geox2[gs], sprite[spr].y += geoy2[gs], sprite[spr].z);
spr = nextspr;
}
}
fi.animatesprites(cposx, cposy, cang, smoothratio);
renderDrawMasks();
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void displayrooms(short snum, int smoothratio)
{
int cposx, cposy, cposz, dst, j, fz, cz, hz, lz;
short sect, cang, k, choriz, tsect;
struct player_struct* p;
int dx, dy, thoriz, i;
short tang;
int tiltcx, tiltcy, tiltcs = 0; // JBF 20030807
p = &ps[snum];
if (ud.screen_size >= 8) drawbackground();
if (ud.overhead_on == 2 || p->cursectnum == -1)
return;
// Do not light up the fog in RRRA's E2L1. Ideally this should apply to all foggy levels but all others use lookup table hacks for their fog.
if (isRRRA() && fogactive)
{
p->visibility = ud.const_visibility;
}
g_visibility = p->visibility;
smoothratio = min(max(smoothratio, 0), 65536);
if (ud.pause_on || ps[snum].on_crane > -1) smoothratio = 65536;
sect = p->cursectnum;
if (sect < 0 || sect >= MAXSECTORS) return;
dointerpolations(smoothratio);
animatecamsprite(smoothratio);
if (ud.camerasprite >= 0)
{
spritetype* s;
s = &sprite[ud.camerasprite];
if (s->yvel < 0) s->yvel = -100;
else if (s->yvel > 199) s->yvel = 300;
cang = hittype[ud.camerasprite].tempang + mulscale16((int)(((s->ang + 1024 - hittype[ud.camerasprite].tempang) & 2047) - 1024), smoothratio);
se40code(s->x, s->y, s->z, cang, s->yvel, smoothratio);
renderMirror(s->x, s->y, s->z, cang, s->yvel, smoothratio);
drawrooms(s->x, s->y, s->z - (4 << 8), cang, s->yvel, s->sectnum);
fi.animatesprites(s->x, s->y, cang, smoothratio);
renderDrawMasks();
}
else
{
int i = divscale22(1, isRR() ? 64 : sprite[p->i].yrepeat + 28);
if (!isRRRA() || !p->DrugMode)
{
// Fixme: This should get the aspect ratio from the backend, not the current viewport size.
int viewingRange = xs_CRoundToInt(double(i) * tan(r_fov * (pi::pi() / 360.)));
renderSetAspect(mulscale16(viewingRange, viewingrange), yxaspect);
}
else
{
setdrugmode(p, i);
}
renderSetRollAngle(p->orotscrnang + mulscale16(((p->rotscrnang - p->orotscrnang + 1024) & 2047) - 1024, smoothratio));
p->orotscrnang = p->rotscrnang; // JBF: save it for next time
if ((snum == myconnectindex) && (numplayers > 1))
{
cposx = omyx + mulscale16((int)(myx - omyx), smoothratio);
cposy = omyy + mulscale16((int)(myy - omyy), smoothratio);
cposz = omyz + mulscale16((int)(myz - omyz), smoothratio);
cang = omyang + mulscale16((int)(((myang + 1024 - omyang) & 2047) - 1024), smoothratio);
choriz = omyhoriz + omyhorizoff + mulscale16((int)(myhoriz + myhorizoff - omyhoriz - omyhorizoff), smoothratio);
sect = mycursectnum;
}
else
{
cposx = p->oposx + mulscale16((int)(p->posx - p->oposx), smoothratio);
cposy = p->oposy + mulscale16((int)(p->posy - p->oposy), smoothratio);
cposz = p->oposz + mulscale16((int)(p->posz - p->oposz), smoothratio);
cang = p->getoang() + mulscale16((int)(((p->getang() + 1024 - p->getoang()) & 2047) - 1024), smoothratio);
//choriz = p->ohoriz+p->ohorizoff+mulscale16((int)(p->gethorizsum()-p->ohoriz-p->ohorizoff),smoothratio);
choriz = mulscale16((int)(p->gethorizsum()), smoothratio);
}
cang += p->look_ang;
if (p->newowner >= 0)
{
cang = p->getang() + p->getlookang();
choriz = p->gethorizsum();
cposx = p->posx;
cposy = p->posy;
cposz = p->posz;
sect = sprite[p->newowner].sectnum;
smoothratio = 65536L;
}
else if (p->over_shoulder_on == 0)
{
if (cl_viewbob) cposz += p->opyoff + mulscale16((int)(p->pyoff - p->opyoff), smoothratio);
}
else view(p, &cposx, &cposy, &cposz, &sect, cang, choriz);
cz = hittype[p->i].ceilingz;
fz = hittype[p->i].floorz;
if (earthquaketime > 0 && p->on_ground == 1)
{
cposz += 256 - (((earthquaketime) & 1) << 9);
cang += (2 - ((earthquaketime) & 2)) << 2;
}
if (sprite[p->i].pal == 1) cposz -= (18 << 8);
if (p->newowner >= 0)
choriz = 100 + sprite[p->newowner].shade;
else if (p->spritebridge == 0)
{
if (cposz < (p->truecz + (4 << 8))) cposz = cz + (4 << 8);
else if (cposz > (p->truefz - (4 << 8))) cposz = fz - (4 << 8);
}
if (sect >= 0)
{
getzsofslope(sect, cposx, cposy, &cz, &fz);
if (cposz < cz + (4 << 8)) cposz = cz + (4 << 8);
if (cposz > fz - (4 << 8)) cposz = fz - (4 << 8);
}
if (choriz > 299) choriz = 299;
else if (choriz < -99) choriz = -99;
if (isRR() && sector[sect].lotag == 848)
{
tag848Hackery(cposx, cposy, cposz, cang, choriz, sect, smoothratio);
}
else
{
se40code(cposx, cposy, cposz, cang, choriz, smoothratio);
renderMirror(cposx, cposy, cposz, cang, choriz, smoothratio);
drawrooms(cposx, cposy, cposz, cang, choriz, sect);
fi.animatesprites(cposx, cposy, cang, smoothratio);
renderDrawMasks();
}
}
restoreinterpolations();
if (!isRRRA() || !fogactive)
{
if (totalclock < lastvisinc)
{
if (abs(p->visibility - ud.const_visibility) > 8)
p->visibility += (ud.const_visibility - p->visibility) >> 2;
}
else p->visibility = ud.const_visibility;
}
}
END_DUKE_NS

View file

@ -82,20 +82,6 @@ static inline int G_GetForcefieldPicnum(int wallNum)
return tileNum;
}
// Returns the interpolated position of the camera that the player is looking
// through (using a viewscreen). <i> should be the player's ->newowner member.
static inline vec3_t G_GetCameraPosition(int32_t i, int32_t smoothratio)
{
const spritetype *const cs = &sprite[i];
const actor_t *const ca = &actor[i];
vec3_t cam = { ca->bpos.x + mulscale16(cs->x - ca->bpos.x, smoothratio),
ca->bpos.y + mulscale16(cs->y - ca->bpos.y, smoothratio),
ca->bpos.z + mulscale16(cs->z - ca->bpos.z, smoothratio)
};
return cam;
}
EXTERN_INLINE_HEADER int32_t G_CheckPlayerInSector(int32_t sect);
#if defined sector_c_ || !defined DISABLE_INLINING

View file

@ -83,15 +83,11 @@ static void gameTimerHandler(void)
{
ControlInfo noshareinfo;
CONTROL_GetInput(&noshareinfo);
C_RunDelayedCommands();
}
}
// only dispatch commands here when not in a game
if (!(g_player[myconnectindex].ps->gm & MODE_GAME))
OSD_DispatchQueued();
}
void se40code(int tag, int x, int y, int z, int a, int h, int smoothratio);
void se40code(int x, int y, int z, int a, int h, int smoothratio);
void G_HandleMirror(int32_t x, int32_t y, int32_t z, fix16_t a, fix16_t q16horiz, int32_t smoothratio)
{
@ -204,7 +200,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio)
CAMERA(sect) = pPlayer->cursectnum;
dointerpolations(smoothRatio);
G_AnimateCamSprite(smoothRatio);
//G_AnimateCamSprite(smoothRatio);
if (ud.camerasprite >= 0)
{
@ -218,7 +214,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio)
+ mulscale16(((pSprite->ang + 1024 - actor[ud.camerasprite].tempang) & 2047) - 1024, smoothRatio));
if (!RR)
se40code(40, pSprite->x, pSprite->y, pSprite->z, CAMERA(q16ang), fix16_from_int(pSprite->yvel), smoothRatio);
se40code(pSprite->x, pSprite->y, pSprite->z, CAMERA(q16ang), fix16_from_int(pSprite->yvel), smoothRatio);
renderDrawRoomsQ16(pSprite->x, pSprite->y, pSprite->z - ZOFFSET6, CAMERA(q16ang), fix16_from_int(pSprite->yvel), pSprite->sectnum);
fi.animatesprites(pSprite->x, pSprite->y, fix16_to_int(CAMERA(q16ang)), smoothRatio);
@ -384,7 +380,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio)
}
else
{
vec3_t const camVect = G_GetCameraPosition(pPlayer->newowner, smoothRatio);
vec3_t const camVect = { 0,0,0 };// G_GetCameraPosition(pPlayer->newowner, smoothRatio);
// looking through viewscreen
CAMERA(pos) = camVect;
@ -431,7 +427,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio)
CAMERA(q16horiz) = fix16_clamp(CAMERA(q16horiz), F16(HORIZ_MIN), F16(HORIZ_MAX));
G_HandleMirror(CAMERA(pos.x), CAMERA(pos.y), CAMERA(pos.z), CAMERA(q16ang), CAMERA(q16horiz), smoothRatio);
if (!RR || RRRA) se40code(RRRA? 150 : 40, CAMERA(pos.x), CAMERA(pos.y), CAMERA(pos.z), CAMERA(q16ang), CAMERA(q16horiz), smoothRatio);
if (!RR || RRRA) se40code(CAMERA(pos.x), CAMERA(pos.y), CAMERA(pos.z), CAMERA(q16ang), CAMERA(q16horiz), smoothRatio);
// for G_PrintCoords
dr_viewingrange = viewingrange;
@ -1426,7 +1422,7 @@ MAIN_LOOP_RESTART:
G_HandleLocalKeys();
OSD_DispatchQueued();
C_RunDelayedCommands();
char gameUpdate = false;
gameupdatetime.Reset();

View file

@ -179,8 +179,8 @@ void G_ResetTimers(uint8_t keepgtics)
if (!keepgtics)
g_moveThingsCount = 0;
if (g_curViewscreen >= 0)
actor[g_curViewscreen].t_data[0] = 0;
if (camsprite >= 0)
actor[camsprite].t_data[0] = 0;
}
void G_ClearFIFO(void)

View file

@ -844,7 +844,7 @@ static const dataspec_t svgm_anmisc[] =
{ DS_SAVEFN, (void *)&sv_preanimateptrsave, 0, 1 },
{ 0, &g_animatePtr[0], sizeof(g_animatePtr[0]), MAXANIMATES },
{ DS_SAVEFN|DS_LOADFN , (void *)&sv_postanimateptr, 0, 1 },
{ 0, &g_curViewscreen, sizeof(g_curViewscreen), 1 },
{ 0, &camsprite, sizeof(camsprite), 1 },
{ 0, &g_origins[0], sizeof(g_origins[0]), ARRAY_SIZE(g_origins) },
{ 0, &g_spriteDeleteQueuePos, sizeof(g_spriteDeleteQueuePos), 1 },
{ DS_NOCHK, &g_deleteQueueSize, sizeof(g_deleteQueueSize), 1 },

View file

@ -32,49 +32,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_DUKE_NS
void G_AnimateCamSprite(int smoothRatio)
{
if (g_curViewscreen < 0)
return;
int spriteNum = g_curViewscreen;
if (totalclock >= T1(spriteNum) + ud.camera_time)
{
DukePlayer_t const *const pPlayer = g_player[screenpeek].ps;
if (pPlayer->newowner >= 0)
OW(spriteNum) = pPlayer->newowner;
if (OW(spriteNum) >= 0 && dist(&sprite[pPlayer->i], &sprite[spriteNum]) < VIEWSCREEN_ACTIVE_DISTANCE)
{
TileFiles.MakeCanvas(TILE_VIEWSCR, tilesiz[PN(spriteNum)].x, tilesiz[PN(spriteNum)].y);
vec3_t const camera = G_GetCameraPosition(OW(spriteNum), smoothRatio);
int ang = SA(OW(spriteNum));
int const saveMirror = display_mirror;
auto canvas = renderSetTarget(TILE_VIEWSCR);
if (!canvas) return;
screen->RenderTextureView(canvas, [=](IntRect& rect)
{
yax_preparedrawrooms();
drawrooms(camera.x, camera.y, camera.z, ang, 100 + sprite[OW(spriteNum)].shade, SECT(OW(spriteNum)));
display_mirror = 3;
fi.animatesprites(camera.x, camera.y, ang, smoothRatio);
display_mirror = saveMirror;
renderDrawMasks();
});
renderRestoreTarget();
}
T1(spriteNum) = (int32_t) totalclock;
}
}
END_DUKE_NS