diff --git a/doomclassic/doom/constructs.h b/doomclassic/doom/constructs.h index fa8342c4..baad5025 100644 --- a/doomclassic/doom/constructs.h +++ b/doomclassic/doom/constructs.h @@ -911,4 +911,6 @@ ::g->totalmus = 68; ::g->mapmax = 0; - ::g->lastMasocTick = 0; \ No newline at end of file + ::g->lastMasocTick = 0; + + ::g->accumulatedTimeDeltas.resize(100); //GK: For that to be exceeded the game must run more than @3500 or @4000 FPS \ No newline at end of file diff --git a/doomclassic/doom/d_net.cpp b/doomclassic/doom/d_net.cpp index 54f995b4..bb16f3cd 100644 --- a/doomclassic/doom/d_net.cpp +++ b/doomclassic/doom/d_net.cpp @@ -671,7 +671,23 @@ void D_QuitNetGame (void) } //GK: Begin -// +/** +* CalculateInterpolationCheckSkips +* +* Calculate and check if the engine's frameTime is slower than the expected frameTime and if it is accumulate interpolaction check skips in order to not lose any frames +*/ +void CalculateInterpolationCheckSkips(int timeDelta, float expectedFrameMs, int index) { + if (index == 100) { //We only use 100 entries to keep the accumulated FrameTimes, if it run out just skip and start playing the frames + return; + } + ::g->accumulatedTimeDeltas[index] += timeDelta - expectedFrameMs; + if (::g->accumulatedTimeDeltas[index] >= expectedFrameMs) { + ::g->skipTicInterpolationCheck++; + CalculateInterpolationCheckSkips(::g->accumulatedTimeDeltas[index], expectedFrameMs, index + 1); + ::g->accumulatedTimeDeltas[index] = 0; + } +} + // InterpolateTics // // Check if the current tic must run or not. @@ -682,16 +698,7 @@ bool InterpolateTics() { float expectedFrameMs = 1000.0f / cl_engineHz.GetFloat(); ::g->timeDelta = currentTime - ::g->lastTicTime; if (::g->timeDelta >= expectedFrameMs) { - ::g->accumulatedTimeDelta += ::g->timeDelta - expectedFrameMs; - if (::g->accumulatedTimeDelta >= expectedFrameMs) { - ::g->accumulatedTimeDelta2 += ::g->accumulatedTimeDelta - expectedFrameMs; - if (::g->accumulatedTimeDelta2 >= expectedFrameMs) { - ::g->skipTicInterpolationCheck++; - ::g->accumulatedTimeDelta2 = 0; - } - ::g->skipTicInterpolationCheck++; - ::g->accumulatedTimeDelta = 0; - } + CalculateInterpolationCheckSkips(::g->timeDelta, expectedFrameMs, 0); ::g->lastTicTime = currentTime; return true; } diff --git a/doomclassic/doom/doomlib.cpp b/doomclassic/doom/doomlib.cpp index e73b51ea..81c02119 100644 --- a/doomclassic/doom/doomlib.cpp +++ b/doomclassic/doom/doomlib.cpp @@ -466,14 +466,14 @@ void DoomLib::Shutdown() { globaldata[currentplayer] = NULL; //CleanVector(glob->activeceilings); //GK: Contains memory managed by the Zone Memory. Skip //CleanVector(glob->activeplats); //GK: Contains memory managed by the Zone Memory. Skip - CleanVector(glob->intercepts); - CleanVector(glob->drawsegs); + glob->intercepts.clear(); + glob->drawsegs.clear(); CleanVector(glob->sprites); - CleanVector(glob->vissprites); + glob->vissprites.clear(); CleanVector(glob->cpatch); - CleanVector(glob->visplanes); + glob->visplanes.clear(); CleanVector(glob->reverbs); - CleanVector(glob->sector_list); + glob->sector_list.clear(); for (size_t j = 0; j < glob->acts.size(); j++) { CleanVector(glob->acts[j]); } diff --git a/doomclassic/doom/p_local.h b/doomclassic/doom/p_local.h index eee560d8..538f83a9 100644 --- a/doomclassic/doom/p_local.h +++ b/doomclassic/doom/p_local.h @@ -163,7 +163,7 @@ typedef struct #define MAXINTERCEPTS 128 //GK:Not needed //GK:From now on it uses indexed vectors (for now until and if I found something better) -extern std::vector intercepts; +extern std::vector> intercepts; //extern intercept_t* intercept_p; typedef qboolean (*traverser_t) (intercept_t *in); diff --git a/doomclassic/doom/p_map.cpp b/doomclassic/doom/p_map.cpp index 2b1a1459..8f1fe095 100644 --- a/doomclassic/doom/p_map.cpp +++ b/doomclassic/doom/p_map.cpp @@ -571,25 +571,26 @@ void P_AddSecnode(sector_t* s, mobj_t* thing) } } - msecnode_t* tnode = new msecnode_t(); - tnode->visited = 0; - - tnode->m_sector = s; // sector - tnode->m_thing = thing; // mobj - //s->touching_thinglist = tnode; + #if _ITERATOR_DEBUG_LEVEL < 2 if (::g->sector_list.size() == ::g->sector_list.capacity()) { ::g->sector_list.reserve(::g->sector_list.size() + 100); } //::g->specind = 0; - ::g->sector_list.emplace_back(tnode); + msecnode_t* tnode = ::g->sector_list.emplace_back(std::make_unique()).get(); #else if (::g->sector_list.size() == ::g->sector_list.capacity()) { ::g->sector_list.resize(::g->sector_list.size() + 100); } - ::g->sector_list[::g->headsecind] = tnode; + ::g->sector_list[::g->headsecind] = std::make_unique(); + msecnode_t* tnode = ::g->sector_list[::g->headsecind].get(); #endif ::g->headsecind++; + tnode->visited = 0; + + tnode->m_sector = s; // sector + tnode->m_thing = thing; // mobj + //s->touching_thinglist = tnode; //msecnode_t* node; @@ -649,7 +650,7 @@ void P_DelSeclist() { while(!::g->sector_list.empty()) { - msecnode_t* node = ::g->sector_list[::g->headsecind - 1]; + msecnode_t* node = ::g->sector_list[::g->headsecind - 1].get(); ::g->sector_list[::g->headsecind - 1] = NULL; ::g->headsecind--; if (::g->headsecind < 0) { @@ -719,8 +720,9 @@ void P_CreateSecNodeList(mobj_t* thing, fixed_t x, fixed_t y) // finished, delete all nodes where m_thing is still NULL. These // represent the sectors the Thing has vacated. - for (msecnode_t* node : ::g->sector_list) + for (int i = 0; i < ::g->sector_list.size(); i++) { + msecnode_t* node = ::g->sector_list[i].get(); if (node != NULL) { node->m_thing = NULL; } diff --git a/doomclassic/doom/p_maputl.cpp b/doomclassic/doom/p_maputl.cpp index 96703f4e..f68e68f8 100644 --- a/doomclassic/doom/p_maputl.cpp +++ b/doomclassic/doom/p_maputl.cpp @@ -727,7 +727,7 @@ P_TraverseIntercepts dist = MAXINT; for (size_t i = 0 ; i < ::g->interind-1; i++) { - scan = ::g->intercepts[i]; + scan = ::g->intercepts[i].get(); if (scan->frac < dist) { dist = scan->frac; @@ -810,11 +810,11 @@ P_PathTraverse if (::g->intercepts.empty()) { #if _ITERATOR_DEBUG_LEVEL < 2 ::g->intercepts.reserve(MAXINTERCEPTS); - ::g->intercepts.emplace_back(new intercept_t()); + ::g->intercepts.emplace_back(std::make_unique()); #else ::g->intercepts.resize(MAXINTERCEPTS); for (int ii = 0; ii < MAXINTERCEPTS; ii++) { - ::g->intercepts[ii] = new intercept_t(); + ::g->intercepts[ii] = std::make_unique(); } #endif } @@ -932,13 +932,13 @@ void AddNewIntercept() { if (::g->intercepts.size() == ::g->intercepts.capacity()) { ::g->intercepts.reserve(::g->intercepts.size() + MAXINTERCEPTS); } - ::g->intercepts.emplace_back(new intercept_t()); + ::g->intercepts.emplace_back(std::make_unique()); #else if (::g->intercepts.size() == ::g->intercepts.capacity()) { ::g->intercepts.resize(::g->intercepts.size() + MAXINTERCEPTS); } for (int j = ::g->interind; j < ::g->intercepts.size(); j++) { - ::g->intercepts[j] = new intercept_t(); + ::g->intercepts[j] = std::make_unique(); } #endif } diff --git a/doomclassic/doom/p_spec.cpp b/doomclassic/doom/p_spec.cpp index 773292d3..00266da1 100644 --- a/doomclassic/doom/p_spec.cpp +++ b/doomclassic/doom/p_spec.cpp @@ -1709,11 +1709,11 @@ void P_UpdateSpecials (void) for (ai = 0; ai < ::g->numlinespecials; ai++) { // line = ::g->linespeciallist[i]; - switch(::g->linespeciallist[ai]->special) + switch(::g->linespeciallist[ai].special) { case 48: // EFFECT FIRSTCOL SCROLL + - ::g->sides[::g->linespeciallist[ai]->sidenum[0]].textureoffset += FRACUNIT; + ::g->sides[::g->linespeciallist[ai].sidenum[0]].textureoffset += FRACUNIT; break; } } @@ -1963,21 +1963,13 @@ void P_SpawnSpecials (void) case 48: // EFFECT FIRSTCOL SCROLL+ if (::g->numlinespecials >= ::g->linespeciallist.size()) { -#if _ITERATOR_DEBUG_LEVEL < 2 - //::g->linespeciallist.clear(); - if (::g->linespeciallist.size() == ::g->linespeciallist.capacity()) { - ::g->linespeciallist.reserve(::g->linespeciallist.size() + MAXLINEANIMS); - } - ::g->linespeciallist.emplace_back(&::g->lines[i]); -#else if (::g->linespeciallist.size() == ::g->linespeciallist.capacity()) { ::g->linespeciallist.resize(::g->linespeciallist.size() + MAXLINEANIMS); } - ::g->linespeciallist[::g->numlinespecials] = &::g->lines[i]; -#endif + ::g->linespeciallist[::g->numlinespecials] = ::g->lines[i]; } else { - ::g->linespeciallist[::g->numlinespecials] = &::g->lines[i]; + ::g->linespeciallist[::g->numlinespecials] = ::g->lines[i]; } ::g->numlinespecials++; break; @@ -2138,7 +2130,8 @@ void T_Scroll(scroll_t *s) ::g->sectors[sec->heightsec].floorheight > height ? ::g->sectors[sec->heightsec].floorheight : MININT; - for (msecnode_t* node : ::g->sector_list) { + for (int i = 0; i < ::g->sector_list.size(); i++) { + msecnode_t* node = ::g->sector_list[i].get(); if (node != NULL) { if (node->m_sector == sec) { if (!((thing = node->m_thing)->flags & MF_NOCLIP) && diff --git a/doomclassic/doom/r_bsp.cpp b/doomclassic/doom/r_bsp.cpp index 3f2cdfcc..b4a28ff5 100644 --- a/doomclassic/doom/r_bsp.cpp +++ b/doomclassic/doom/r_bsp.cpp @@ -67,11 +67,11 @@ void R_ClearDrawSegs (void) if (::g->drawsegs.empty()) { #if _ITERATOR_DEBUG_LEVEL < 2 ::g->drawsegs.reserve(MAXDRAWSEGS); - ::g->drawsegs.emplace_back(new drawseg_t()); + ::g->drawsegs.emplace_back(std::make_unique()); #else ::g->drawsegs.resize(MAXDRAWSEGS); for (int di = 0; di < MAXDRAWSEGS; di++) { - ::g->drawsegs[di] = new drawseg_t(); + ::g->drawsegs[di] = std::make_unique(); } #endif } diff --git a/doomclassic/doom/r_plane.cpp b/doomclassic/doom/r_plane.cpp index 009031f2..a55e284d 100644 --- a/doomclassic/doom/r_plane.cpp +++ b/doomclassic/doom/r_plane.cpp @@ -197,11 +197,11 @@ void R_ClearPlanes (void) if (::g->visplanes.empty()) { #if _ITERATOR_DEBUG_LEVEL < 2 ::g->visplanes.reserve(MAXVISPLANES); - ::g->visplanes.emplace_back(new visplane_t()); + ::g->visplanes.emplace_back(std::make_unique()); #else ::g->visplanes.resize(MAXVISPLANES); for (int vpi = 0; vpi < MAXVISPLANES; vpi++) { - ::g->visplanes[vpi] = new visplane_t(); + ::g->visplanes[vpi] = std::make_unique(); } #endif } @@ -235,13 +235,13 @@ visplane_t* R_FindPlane( fixed_t height, int picnum, int lightlevel,fixed_t xoff lightlevel = 0; } for (uint i = 0; i < ::g->planeind; i++) { - check = ::g->visplanes[i]; + check = ::g->visplanes[i].get(); if (height == check->height && picnum == check->picnum && lightlevel == check->lightlevel && xoffs == check->xoffs && check->yoffs) { break; } } - if (check != ::g->visplanes[::g->planeind-1]) + if (check != ::g->visplanes[::g->planeind-1].get()) return check; //if (::g->lastvisplane - ::g->visplanes == MAXVISPLANES) @@ -326,7 +326,7 @@ R_CheckPlane ::g->visplanes[::g->planeind-1]->height = pl->height; ::g->visplanes[::g->planeind - 1]->picnum = pl->picnum; ::g->visplanes[::g->planeind - 1]->lightlevel = pl->lightlevel; - pl = ::g->visplanes[::g->planeind - 1]; + pl = ::g->visplanes[::g->planeind - 1].get(); AddNewVisplane(); pl->minx = start; pl->maxx = stop; @@ -558,11 +558,11 @@ void AddNewVisplane() { if (::g->visplanes.size() == ::g->visplanes.capacity()) { ::g->visplanes.reserve(::g->visplanes.size() + MAXVISPLANES); } - ::g->visplanes.emplace_back(new visplane_t()); + ::g->visplanes.emplace_back(std::make_unique()); #else ::g->visplanes.resize(::g->visplanes.size() + MAXVISPLANES); for (int vpi = ::g->planeind; vpi < ::g->visplanes.size(); vpi++) { - ::g->visplanes[vpi] = new visplane_t(); + ::g->visplanes[vpi] = std::make_unique(); } #endif } diff --git a/doomclassic/doom/r_segs.cpp b/doomclassic/doom/r_segs.cpp index 0524d1e2..8e7f9df7 100644 --- a/doomclassic/doom/r_segs.cpp +++ b/doomclassic/doom/r_segs.cpp @@ -393,7 +393,7 @@ R_StoreWallRange sineval = finesine[distangle>>ANGLETOFINESHIFT]; ::g->rw_distance = FixedMul (hyp, sineval); - ::g->ds_p = ::g->drawsegs[::g->drawsegind - 1]; + ::g->ds_p = ::g->drawsegs[::g->drawsegind - 1].get(); ::g->ds_p->x1 = ::g->rw_x = start; ::g->ds_p->x2 = stop; ::g->ds_p->curline = ::g->curline; @@ -737,13 +737,13 @@ void AddDrawSeg() { if (::g->drawsegs.size() == ::g->drawsegs.capacity()) { ::g->drawsegs.reserve(::g->drawsegs.size() + MAXDRAWSEGS); } - ::g->drawsegs.emplace_back(new drawseg_t()); + ::g->drawsegs.emplace_back(std::make_unique()); #else if (::g->drawsegs.size() == ::g->drawsegs.capacity()) { ::g->drawsegs.resize(::g->drawsegs.size() + MAXDRAWSEGS); } for (int i = ::g->drawsegind; i < ::g->drawsegs.size(); i++) { - ::g->drawsegs[i] = new drawseg_t(); + ::g->drawsegs[i] = std::make_unique(); } #endif } diff --git a/doomclassic/doom/r_things.cpp b/doomclassic/doom/r_things.cpp index be833472..a5ce76f4 100644 --- a/doomclassic/doom/r_things.cpp +++ b/doomclassic/doom/r_things.cpp @@ -323,8 +323,8 @@ void R_ZeroVisSprite(int index) { ::g->vissprites[index]->gz = 0; ::g->vissprites[index]->gzt = 0; ::g->vissprites[index]->mobjflags = 0; - ::g->vissprites[index]->next = ::g->vissprites[index]; - ::g->vissprites[index]->prev = ::g->vissprites[index - 1]; + ::g->vissprites[index]->next = ::g->vissprites[index].get(); + ::g->vissprites[index]->prev = ::g->vissprites[index - 1].get(); ::g->vissprites[index]->patch = 0; ::g->vissprites[index]->scale = 0; ::g->vissprites[index]->startfrac = 0; @@ -346,11 +346,11 @@ void R_ClearSprites (void) if (::g->vissprites.empty()) { #if _ITERATOR_DEBUG_LEVEL < 2 ::g->vissprites.reserve(MAXVISSPRITES); - ::g->vissprites.emplace_back(new vissprite_t()); + ::g->vissprites.emplace_back(std::make_unique()); #else ::g->vissprites.resize(MAXVISSPRITES); for (int vi = 0; vi < MAXVISSPRITES; vi++) { - ::g->vissprites[vi] = new vissprite_t(); + ::g->vissprites[vi] = std::make_unique(); } #endif } @@ -377,13 +377,13 @@ vissprite_t* R_NewVisSprite (void) if (::g->vissprites.size() == ::g->vissprites.capacity()) { ::g->vissprites.reserve(::g->vissprites.size() + MAXVISSPRITES); } - ::g->vissprites.emplace_back(new vissprite_t()); + ::g->vissprites.emplace_back(std::make_unique()); #else if (::g->vissprites.size() == ::g->vissprites.capacity()) { ::g->vissprites.resize(::g->vissprites.size() + MAXVISSPRITES); } for (int vi = ::g->visspriteind; vi < ::g->vissprites.size(); vi++) { - ::g->vissprites[vi] = new vissprite_t(); + ::g->vissprites[vi] = std::make_unique(); } #endif } @@ -391,7 +391,7 @@ vissprite_t* R_NewVisSprite (void) R_ZeroVisSprite(::g->visspriteind); } - return ::g->vissprites[::g->visspriteind-1]; + return ::g->vissprites[::g->visspriteind-1].get(); } @@ -907,23 +907,23 @@ void R_SortVisSprites (void) { //GK:use the actual vector instead of a temp array if (i_ < ::g->visspriteind -1) { - ::g->vissprites[i_]->next= ::g->vissprites[i_ + 1]; + ::g->vissprites[i_]->next= ::g->vissprites[i_ + 1].get(); } else { - ::g->vissprites[i_]->next = ::g->vissprites[i_]; + ::g->vissprites[i_]->next = ::g->vissprites[i_].get(); } if (i_ > 0) { - ::g->vissprites[i_]->prev = ::g->vissprites[i_ - 1]; + ::g->vissprites[i_]->prev = ::g->vissprites[i_ - 1].get(); } else { - ::g->vissprites[i_]->prev = ::g->vissprites[i_]; + ::g->vissprites[i_]->prev = ::g->vissprites[i_].get(); } } ::g->vissprites[0]->prev = &unsorted; unsorted.next = &*::g->vissprites[0]; ::g->vissprites[::g->visspriteind-1]->next = &unsorted; - unsorted.prev = ::g->vissprites[::g->visspriteind-1]; + unsorted.prev = ::g->vissprites[::g->visspriteind-1].get(); // pull the ::g->vissprites out by scale //best = 0; // shut up the compiler warning @@ -973,7 +973,7 @@ void R_DrawSprite (vissprite_t* spr) // is the clip seg. for (int i = ::g->drawsegind - 2; i >= 0; i--) { - ds = ::g->drawsegs[i]; + ds = ::g->drawsegs[i].get(); // determine if the drawseg obscures the sprite if (ds->x1 > spr->x2 || ds->x2 < spr->x1 @@ -1091,7 +1091,7 @@ void R_DrawMasked (void) // render any remaining masked mid textures for (int i = ::g->drawsegind - 2; i >= 0; i--) { - ds = ::g->drawsegs[i]; + ds = ::g->drawsegs[i].get(); if (ds->maskedtexturecol) R_RenderMaskedSegRange(ds, ds->x1, ds->x2); } diff --git a/doomclassic/doom/r_things.h b/doomclassic/doom/r_things.h index 6a3e693b..eb6a5819 100644 --- a/doomclassic/doom/r_things.h +++ b/doomclassic/doom/r_things.h @@ -36,7 +36,7 @@ If you have questions concerning this license or the applicable additional terms //GK : Increase the number of things from 128 to 245760 (lets become NUTS) #define MAXVISSPRITES 128 -extern std::vector vissprites; +extern std::vector> vissprites; //extern vissprite_t* vissprite_p; extern vissprite_t vsprsortedhead; diff --git a/doomclassic/doom/vars.h b/doomclassic/doom/vars.h index 560817b3..87ee5683 100644 --- a/doomclassic/doom/vars.h +++ b/doomclassic/doom/vars.h @@ -530,7 +530,7 @@ int bombdamage; qboolean crushchange; qboolean nofit; // Temporary holder for thing_sectorlist threads -std::vector sector_list; // phares 3/16/98 +std::vector> sector_list; // phares 3/16/98 size_t headsecind; // p_map.vars end // // p_maputl.vars begin // @@ -540,7 +540,7 @@ fixed_t openrange; fixed_t lowfloor; //GK:From now on it uses indexed vectors (for now until and if I found something better) size_t interind; -std::vector intercepts; +std::vector> intercepts; //intercept_t* intercept_p; divline_t trace; qboolean earlyout; @@ -612,7 +612,7 @@ int levelFragCount; //GK:From now on it uses indexed vectors (for now until and if I found something better) size_t numlinespecials; long linespecind; -std::vector linespeciallist{}; +std::vector linespeciallist{}; animdef_t animdefs[23]; //GK: Make this global in order to be used and elsewhere // p_spec.vars end // // p_switch.vars begin // @@ -634,7 +634,7 @@ side_t* sidedef; line_t* linedef; sector_t* frontsector; sector_t* backsector; -std::vector drawsegs; +std::vector> drawsegs; size_t drawsegind; drawseg_t* ds_p; cliprange_t* newend; @@ -808,7 +808,7 @@ long numsprites; spriteframe_t sprtemp[29]; int maxframe; size_t visspriteind; -std::vector vissprites; +std::vector> vissprites; //vissprite_t* vissprite_p; int newvissprite; vissprite_t overflowsprite; @@ -995,7 +995,7 @@ int texnum; //GK: Store pointer of current texture in order to take it's height // r_data end // // r_plane begin // //GK:From now on it uses indexed vectors (for now until and if I found something better) -std::vector visplanes; +std::vector> visplanes; size_t planeind; //visplane_t* lastvisplane; visplane_t* floorplane; @@ -1134,8 +1134,7 @@ int lastMasocTick; int timeDelta; int lastTicTime; int skipTicInterpolationCheck; -int accumulatedTimeDelta; -int accumulatedTimeDelta2; +std::vector accumulatedTimeDeltas; //GK: Mouse Acceleration Fix int prevMouseTime;