Files
RustRaptor/raptor/src/shadow.cpp
T
raptorreplica 214789fe87 Fork the vendored engine into the playable replica
Engine changes vs the vendored upstream (full ledger in
docs/upstream-patches.md):

- Assets: replace the encrypted FILE000N.GLB archives with a catalog of
  pre-decrypted loose files (data/INDEX); GLB_SlotItems() drives
  mission-pack / registered-version detection; payloads never run the
  GLB cipher at runtime.
- Platform: Linux/SDL2/ALSA only; Android, MSVC/MinGW, macOS packaging,
  bundled Windows SDL2 SDKs and the ENDOOM exit screen are gone;
  EXIT_Error now prints before exiting.
- Rendering: decouple presentation from simulation -- sim stays at the
  original 70/3 Hz, frames render interpolated at display rate (player,
  map scroll, enemies, shots, bonuses, anims, shadows); menus keep 70 Hz
  pacing; vsync with a delay-guard fallback.
- QoL: borderless window mode (Video/borderless), no menu cursor
  snapping onto default buttons.

Fix four regressions from the render split:

- Shield bars never redrew: RAP_ThinkStats latches g_oldshield each sim
  step before RAP_DisplayStats' dirty check could fire. Bars now draw
  unconditionally per rendered frame; g_oldsuper deleted, g_oldshield
  kept as sim-side damage-detection state only.
- Dying ships despawned without exploding: the render loop never called
  ANIMS_DisplayHigh(); most air-death explosions register HIGH_AIR.
  Restored between the player and enemy shots, as upstream orders it.
- Laser turret broke: reusing doneflag as a draw marker (it is
  hit/retire game state, and the turret retire path never frees its
  shot) hid the beam on hitting ticks and leaked one SHOTS pool slot
  per fire until no weapon could shoot. S_LINE tracers now carry an age
  counter: one Think pass, every render of their birth step, purged at
  the top of the next Think.
- Muzzle flash was cleared per rendered frame, making it invisible at
  display refresh rates; now cleared once per simulation step.
2026-08-26 18:45:07 +10:00

257 lines
6.1 KiB
C++

#include <stdint.h>
#include "common.h"
#include "gfxapi.h"
#include "rap.h"
#include "windows.h"
#include "glbapi.h"
#include "entypes.h"
char sdtablemem[516];
char *sdtable;
typedef struct
{
int item;
int x;
int y;
}SHADOW;
#define MAX_SHADOWS 50
#define MAX_GSHADOWS 25
SHADOW shads[MAX_SHADOWS];
SHADOW gshads[MAX_GSHADOWS];
int num_shadows, num_gshadows;
static SHADOW prev_shads[MAX_SHADOWS];
static SHADOW prev_gshads[MAX_GSHADOWS];
static int prev_num_shadows, prev_num_gshadows;
/***************************************************************************
SHADOW_Snapshot () - Latches this simulation step's shadows as previous
positions for interpolated display
***************************************************************************/
void
SHADOW_Snapshot(
void
)
{
memcpy(prev_shads, shads, sizeof(shads));
memcpy(prev_gshads, gshads, sizeof(gshads));
prev_num_shadows = num_shadows;
prev_num_gshadows = num_gshadows;
}
#define MAXZ 1280;
/***************************************************************************
SHADOW_Draw () - Draws AIR shadows in 3D perspective
***************************************************************************/
void
SHADOW_Draw(
char *pic, // INPUT : pointer to sprite data
int x, // INPUT : x position of sprite
int y // INPUT : y position of sprite
)
{
GFX_PIC *h = (GFX_PIC*)pic;
GFX_SPRITE *ah;
int lx, ly, oldsy, sx, sy, ox, oy, x2, y2, oldy, drawflag;
x -= 10;
y += 20;
oldy = oldsy = -1;
G3D_x = x;
G3D_y = y;
G3D_z = MAXZ;
GFX_3DPoint();
ox = G3D_screenx;
oy = G3D_screeny;
G3D_x = ox + LE_LONG(h->width) - 1;
G3D_y = oy + LE_LONG(h->height) - 1;
G3D_z = MAXZ;
GFX_3DPoint();
lx = G3D_screenx - ox + 1;
ly = G3D_screenx - oy + 1;
if (!GFX_ClipLines(0, &ox, &oy, &lx, &ly))
return;
pic += sizeof(GFX_PIC);
ah = (GFX_SPRITE*)pic;
while (LE_LONG(ah->offset) != -1)
{
pic += sizeof(GFX_SPRITE);
ox = LE_LONG(ah->x) + x;
oy = LE_LONG(ah->y) + y;
x2 = ox + LE_LONG(ah->length) - 1;
y2 = oy + 1;
G3D_x = ox;
G3D_y = oy;
G3D_z = MAXZ;
GFX_3DPoint();
sx = G3D_screenx;
sy = G3D_screeny;
G3D_x = x2;
G3D_y = y2;
G3D_z = MAXZ;
GFX_3DPoint();
lx = G3D_screenx - sx + 1;
if (sy > SCREENHEIGHT)
return;
drawflag = 1;
if (LE_LONG(ah->y) != oldy && oldsy == sy)
drawflag = 0;
if (drawflag)
{
ly = 1;
if (GFX_ClipLines(0, &sx, &sy, &lx, &ly))
GFX_Shade(displaybuffer + sx + ylookup[sy], lx, sdtable);
oldy = LE_LONG(ah->y);
}
oldsy = sy;
pic += LE_LONG(ah->length);
ah = (GFX_SPRITE*)pic;
}
}
/***************************************************************************
SHADOW_Init() - Allocate memory and set 3D view
***************************************************************************/
void
SHADOW_Init(
void
)
{
sdtable = sdtablemem;
sdtable = (char*)(((intptr_t)sdtable + 255) & ~255);
GFX_3D_SetView(160, 100, 1000);
}
/***************************************************************************
SHADOW_MakeShades() - Make shade tables
***************************************************************************/
void
SHADOW_MakeShades(
void
)
{
GFX_MakeLightTable(palette, sdtable, -6);
}
/***************************************************************************
SHADOW_Add() - Add a Air ship shadow
***************************************************************************/
void
SHADOW_Add(
int item, // INPUT : GLB item
int x, // INPUT : x position
int y // INPUT : y position
)
{
SHADOW *cur;
cur = &shads[num_shadows];
if (num_shadows < MAX_SHADOWS)
{
cur->item = item;
cur->x = x;
cur->y = y;
num_shadows++;
}
}
/***************************************************************************
SHADOW_GAdd() - Adds Ground shadow
***************************************************************************/
void
SHADOW_GAdd(
int item, // INPUT : GLB item
int x, // INPUT : x position
int y // INPUT : y position
)
{
SHADOW *cur;
cur = &gshads[num_gshadows];
if (num_gshadows < MAX_GSHADOWS)
{
cur->item = item;
cur->x = x - 3;
cur->y = y + 4;
num_gshadows++;
}
}
/***************************************************************************
SHADOW_DisplaySky () - Display Sky Shadows
***************************************************************************/
void
SHADOW_DisplaySky(
void
)
{
char *pic;
int i;
int ix, iy;
if (opt_detail < 1)
return;
for (i = 0; i < num_shadows; i++)
{
ix = (i < prev_num_shadows) ? GFX_InterpCoord(shads[i].x, prev_shads[i].x) : shads[i].x;
iy = (i < prev_num_shadows) ? GFX_InterpCoord(shads[i].y, prev_shads[i].y) : shads[i].y;
pic = GLB_GetItem(shads[i].item);
SHADOW_Draw(pic, ix, iy);
}
}
/***************************************************************************
SHADOW_DisplayGround() - Display Ground Shadows
***************************************************************************/
void
SHADOW_DisplayGround(
void
)
{
char *pic;
int i;
int ix, iy;
if (opt_detail < 1)
return;
for (i = 0; i < num_gshadows; i++)
{
ix = (i < prev_num_gshadows) ? GFX_InterpCoord(gshads[i].x, prev_gshads[i].x) : gshads[i].x;
iy = (i < prev_num_gshadows) ? GFX_InterpCoord(gshads[i].y, prev_gshads[i].y) : gshads[i].y;
pic = GLB_GetItem(gshads[i].item);
GFX_ShadeShape(DARK, (char*)pic, ix, iy);
}
}