Adding experimental distance culling

Also fix or partially MF_NOTHINK errors (crab enemy)
**MAY BE UNSTABLE** - fixed some things, probably broke some others, the save/load code is a nightmare!
This commit is contained in:
Louis authored and Ashnal committed 2020-02-17 02:08:15 -05:00
1 parent 586cb358ba
commit c5f569eedc
6 files changed
+228 -68

No files matched your search

+35 -2
View File
@@ -5639,9 +5639,9 @@ static void RunSimulations()
int numToSimulate = targetsimtic - simtic;
// record steadyplayers' real game position and their simulated position
if (numToSimulate > 0)
if (numToSimulate > 0) // only touch objects if we're definitely going to simulate and rewind!
{
// record steadyplayers' real game position and their simulated position
for (int i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] && players[i].mo && i != consoleplayer)
@@ -5663,6 +5663,39 @@ static void RunSimulations()
}
}
}
// and cull distant thinkers if enabled
if (cv_simulateculldistance.value > 0)
{
thinker_t* current;
fixed_t minDistance = cv_simulateculldistance.value << FRACBITS;
mobj_t* playerMos[MAXPLAYERS];
int numPlayers = 0;
int i;
for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] && players[i].mo)
{
playerMos[numPlayers++] = players[i].mo;
}
}
for (current = thlist[THINK_MOBJ].next; current != &thlist[THINK_MOBJ]; current = current->next)
{
for (i = 0; i < numPlayers; i++)
{
if (P_AproxDistance(playerMos[i]->x - ((mobj_t*)current)->x, playerMos[i]->y - ((mobj_t*)current)->y) < minDistance)
break;
}
if (i == numPlayers)
{
// cull this mobj
((mobj_t*)current)->isculled = true;
}
}
}
}
// simulate the rest o da future
+4
View File
@@ -479,6 +479,9 @@ consvar_t cv_simulate = { "simulate", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0
static CV_PossibleValue_t simulateTics_cons_t[] = { {0, "MIN"}, {MAXSIMULATIONS - 1, "MAX"}, {0, NULL} };
consvar_t cv_simulatetics = { "simulatetics", "MAX", 0, simulateTics_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL };
static CV_PossibleValue_t simulateculldistance_cons_t[] = { {0, "MIN"}, {10000, "MAX"}, {0, NULL} };
consvar_t cv_simulateculldistance = { "simulateculldistance", "MIN", 0, simulateculldistance_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL };
static CV_PossibleValue_t netdelay_cons_t[] = { {0, "MIN"}, {250, "MAX"}, {0, NULL} };
consvar_t cv_netdelay = { "netdelay", "0", 0, netdelay_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL };
@@ -660,6 +663,7 @@ void D_RegisterServerCommands(void)
CV_RegisterVar(&cv_simulate);
CV_RegisterVar(&cv_simulatetics);
CV_RegisterVar(&cv_simulateculldistance);
CV_RegisterVar(&cv_netdelay);
CV_RegisterVar(&cv_netjitter);
CV_RegisterVar(&cv_netsmoothing);
+1
View File
@@ -150,6 +150,7 @@ extern consvar_t cv_showping;
extern consvar_t cv_simulate;
extern consvar_t cv_simulatetics;
extern consvar_t cv_simulateculldistance;
extern consvar_t cv_netdelay;
extern consvar_t cv_netjitter;
extern consvar_t cv_netsmoothing;
+2
View File
@@ -375,6 +375,8 @@ typedef struct mobj_s
boolean colorized; // Whether the mobj uses the rainbow colormap
boolean isculled; // Whether the mobj is being culled during simulations
// WARNING: New fields must be added separately to savegame and Lua.
} mobj_t;
+183 -66
View File
@@ -886,6 +886,11 @@ static void P_LocalUnArchiveWorld(void)
sectors[i].preciplist = preservedSectors[i].preciplist;
sectors[i].touching_preciplist = preservedSectors[i].touching_preciplist;
if (sectors[i].thinglist == (mobj_t*)0xDDDDDDDD)
{
continue;
}
// restore preserved local stuff (tbh I don't really know what this is lol)
sectors[i].lightlist = preservedSectors[i].lightlist;
sectors[i].numlights = preservedSectors[i].numlights;
@@ -2193,61 +2198,6 @@ static inline void SaveWhatThinker(const thinker_t *th, const UINT8 type)
*/
//
// P_LocalArchiveThinkers
// Archives the world's thinkers locally. Used for within-level savestates
//
static void P_LocalArchiveThinkers(void)
{
int i, j;
const thinker_t* thinker;
mobj_t* savedMobj;
executor_t* savedExecutor;
UINT8* original = save_p;
WRITEUINT32(save_p, ARCHIVEBLOCK_THINKERS);
for (i = 0; i < NUM_THINKERLISTS; i++)
{
for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next)
{
actionf_p1 acp1 = thinker->function.acp1;
// find the associated special def
for (j = 0; j < sizeof(specialDefs) / sizeof(specialDefs[0]); j++)
{
if (acp1 == specialDefs[j].action)
break;
}
if (j == sizeof(specialDefs) / sizeof(specialDefs[0]))
continue;
WRITEUINT8(save_p, j);
WRITEMEM(save_p, thinker, specialDefs[j].size);
// relink saved pointers with saved mobjnums
#define RELINK(var) if (var != NULL) var = (mobj_t*)(var->mobjnum)
if (j == tc_mobj)
{
savedMobj = &((mobj_t*)save_p)[-1];
RELINK(savedMobj->tracer);
RELINK(savedMobj->target);
RELINK(savedMobj->hnext);
RELINK(savedMobj->hprev);
}
if (j == tc_executor)
{
savedExecutor = &((executor_t*)save_p)[-1];
RELINK(savedExecutor->caller);
}
}
#undef RELINK
WRITEUINT8(save_p, 0xFF); // next list (or end)
}
}
//
// P_NetArchiveThinkers
//
@@ -3262,6 +3212,92 @@ typedef struct
#define HASHLOC(x, y, z) (((x>>4)-(y>>8)+(z>>12)-(x>>16)+(y>>20)-(z>>24)+(x>>28)-(y>>24)+(z>>20)-(x>>16)+(y>>8)-(z>>4)) & 0x7FFF)
#define MAXNUMMOBJSBYLOC 15
//
// P_LocalArchiveThinkers
// Archives the world's thinkers locally. Used for within-level savestates
//
static void P_LocalArchiveThinkers(void)
{
int i, j;
size_t s;
const thinker_t* thinker;
mobj_t* savedMobj;
executor_t* savedExecutor;
UINT8* original = save_p;
WRITEUINT32(save_p, ARCHIVEBLOCK_THINKERS);
for (i = 0; i < NUM_THINKERLISTS; i++)
{
#define RELINK(var) if (var != NULL) var = (mobj_t*)(var->mobjnum)
for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next)
{
actionf_p1 acp1 = thinker->function.acp1;
// find the associated special def
for (j = 0; j < sizeof(specialDefs) / sizeof(specialDefs[0]); j++)
{
if (acp1 == specialDefs[j].action)
break;
}
if (j == sizeof(specialDefs) / sizeof(specialDefs[0]))
continue;
WRITEUINT8(save_p, j);
WRITEMEM(save_p, thinker, specialDefs[j].size);
// relink saved pointers with saved mobjnums
if (j == tc_mobj)
{
savedMobj = &((mobj_t*)save_p)[-1];
RELINK(savedMobj->tracer);
RELINK(savedMobj->target);
RELINK(savedMobj->hnext);
RELINK(savedMobj->hprev);
}
if (j == tc_executor)
{
savedExecutor = &((executor_t*)save_p)[-1];
RELINK(savedExecutor->caller);
}
}
WRITEUINT8(save_p, 0xFF); // next list (or end)
}
// now write the nothinkers...
// turns out that MF_NOTHINKs aren't in thinker lists lol....
// makes sense, but doesn't make life easier. I just wanted an object list. Ah well.
for (s = 0; s < numsectors; s++)
{
mobj_t* thing = sectors[s].thinglist;
while (thing)
{
if (thing->flags & MF_NOTHINK)
{
// archive this thing
WRITEUINT8(save_p, tc_mobj);
WRITEMEM(save_p, thing, specialDefs[tc_mobj].size);
savedMobj = &((mobj_t*)save_p)[-1];
RELINK(savedMobj->tracer);
RELINK(savedMobj->target);
RELINK(savedMobj->hnext);
RELINK(savedMobj->hprev);
}
thing = thing->snext;
}
}
#undef RELINK
WRITEUINT8(save_p, 0xFF);
}
static void P_LocalUnArchiveThinkers()
{
thinker_t *thinker;
@@ -3269,8 +3305,8 @@ static void P_LocalUnArchiveThinkers()
UINT8 tclass;
UINT8 restoreExecutors = false;
INT32 i, j, list;
int skyviewid = -1;
int skycenterid = -1;
int skyviewid = 0;
int skycenterid = 0;
thinker_t newthinkers[NUM_THINKERLISTS] = { 0 };
static thinker_t* thinkersbytype[tc_end][16384];
static int numthinkersbytype[tc_end];
@@ -3340,8 +3376,24 @@ static void P_LocalUnArchiveThinkers()
// clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity
for (i = 0; i < (int)numsectors; i++)
{
mobj_t* thing = sectors[i].thinglist, *next;
sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = sectors[i].fadecolormapdata = NULL;
// clear nothinkers too
while (thing)
{
next = thing->snext;
if (thing->flags & MF_NOTHINK)
{
thing->thinker.references = 0; // hope this is ok...
P_RemoveMobj(thing);
}
thing = next;
}
}
// read in saved thinkers
for (list = 0; list < NUM_THINKERLISTS; list++)
{
@@ -3418,9 +3470,12 @@ static void P_LocalUnArchiveThinkers()
// detach any playing sounds from this object if we can (still need to work on doing this properly!)
S_DetachChannelsFromOrigin((mobj_t*)newthinker);
// unlink it from the old list
newthinker->prev->next = newthinker->next;
newthinker->next->prev = newthinker->prev;
// unlink it from the old list (if it's not a nothinker)
if (!(tclass == tc_mobj && (((mobj_t*)newthinker)->flags & MF_NOTHINK)))
{
newthinker->prev->next = newthinker->next;
newthinker->next->prev = newthinker->prev;
}
}
else
{
@@ -3447,6 +3502,8 @@ static void P_LocalUnArchiveThinkers()
case tc_mobj:
{
mobj_t* mobj = (mobj_t*)newthinker;
// link global and player pointers
if (mobj->type == MT_REDFLAG)
{
redflag = mobj;
@@ -3501,10 +3558,13 @@ static void P_LocalUnArchiveThinkers()
}
// relink into the new thinker list
newthinker->prev = newthinkers[list].prev;
newthinker->next = &newthinkers[list];
newthinker->prev->next = newthinker;
newthinker->next->prev = newthinker;
if (!(tclass == tc_mobj && (((mobj_t*)newthinker)->flags & MF_NOTHINK)))
{
newthinker->prev = newthinkers[list].prev;
newthinker->next = &newthinkers[list];
newthinker->prev->next = newthinker;
newthinker->next->prev = newthinker;
}
if (tclass == tc_mobj)
{
@@ -3519,6 +3579,29 @@ static void P_LocalUnArchiveThinkers()
}
}
// collect nothinkers as well
for (;;)
{
tclass = READUINT8(save_p);
if (tclass == 0xFF)
break; // next list
mobj = Z_Calloc(sizeof(mobj_t), PU_LEVEL, NULL);
READMEM(save_p, mobj, specialDefs[tclass].size);
mobjByNum[mobj->mobjnum] = mobj;
mobj->bnext = NULL;
mobj->bprev = NULL;
mobj->snext = NULL;
mobj->sprev = NULL;
mobj->subsector = NULL;
mobj->touching_sectorlist = NULL;
P_SetThingPosition(mobj);
// we just spawner a nothinker so it doesn't go in a thinker list, let it run wild??
}
// delete everything remaining in the list that hasn't been linked
for (i = 0; i < NUM_THINKERLISTS; i++)
{
@@ -3582,6 +3665,25 @@ static void P_LocalUnArchiveThinkers()
RELINK(mobj->hprev);
}
// and for nothinkers
for (i = 0; i < (int)numsectors; i++)
{
mobj_t* thing = sectors[i].thinglist;
while (thing)
{
if (thing->flags & MF_NOTHINK)
{
RELINK(thing->tracer);
RELINK(thing->target);
RELINK(thing->hnext);
RELINK(thing->hprev);
}
thing = thing->snext;
}
}
// restore player pointers (the above doesn't always seem to work perhaps because playeringame is false?
for (int i = 0; i < MAXPLAYERS; i++)
{
@@ -4623,7 +4725,8 @@ void P_SaveGameState(savestate_t* savestate)
{
mobj_t* mobj;
thinker_t* th;
int i = 1;
size_t s = 0;
int mobjnum = 1;
UINT64 time = I_GetTimeUs();
@@ -4642,7 +4745,21 @@ void P_SaveGameState(savestate_t* savestate)
mobj = (mobj_t *)th;
if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER)
continue;
mobj->mobjnum = i++;
mobj->mobjnum = mobjnum++;
}
// including nothinkers...
for (s = 0; s < numsectors; s++)
{
mobj_t* thing = sectors[s].thinglist;
while (thing)
{
if (thing->flags & MF_NOTHINK)
{
thing->mobjnum = mobjnum++;
}
thing = thing->snext;
}
}
P_NetArchiveMisc();
+3
View File
@@ -332,6 +332,9 @@ static inline void P_RunThinkers(void)
#ifdef PARANOIA
I_Assert(currentthinker->function.acp1 != NULL);
#endif
if (currentthinker->function.acp1 == P_MobjThinker && issimulation && ((mobj_t*)currentthinker)->isculled)
continue; // apply distance culling
currentthinker->function.acp1(currentthinker);
}
}