- backend update from Raze.

This commit is contained in:
Christoph Oelckers 2021-08-31 07:59:37 +02:00
parent fe1514ce04
commit b5294e9e90
6 changed files with 54 additions and 34 deletions

View file

@ -1051,8 +1051,8 @@ FSerializer &Serialize(FSerializer &arc, const char *key, double &value, double
auto val = arc.r->FindKey(key); auto val = arc.r->FindKey(key);
if (val != nullptr) if (val != nullptr)
{ {
assert(val->IsDouble()); assert(val->IsNumber());
if (val->IsDouble()) if (val->IsNumber())
{ {
value = val->GetDouble(); value = val->GetDouble();
} }

View file

@ -912,6 +912,12 @@ LumpShortName& FileSystem::GetShortName(int i)
return FileInfo[i].shortName; return FileInfo[i].shortName;
} }
FString& FileSystem::GetLongName(int i)
{
if ((unsigned)i >= NumEntries) I_Error("GetLongName: Invalid index");
return FileInfo[i].longName;
}
void FileSystem::RenameFile(int num, const char* newfn) void FileSystem::RenameFile(int num, const char* newfn)
{ {
if ((unsigned)num >= NumEntries) I_Error("RenameFile: Invalid index"); if ((unsigned)num >= NumEntries) I_Error("RenameFile: Invalid index");

View file

@ -117,6 +117,7 @@ public:
} }
LumpShortName& GetShortName(int i); // may only be called before the hash chains are set up. LumpShortName& GetShortName(int i); // may only be called before the hash chains are set up.
FString& GetLongName(int i); // may only be called before the hash chains are set up.
void RenameFile(int num, const char* fn); void RenameFile(int num, const char* fn);
bool CreatePathlessCopy(const char* name, int id, int flags); bool CreatePathlessCopy(const char* name, int id, int flags);

View file

@ -67,22 +67,14 @@ static uint64_t NSToMS(uint64_t ns)
return static_cast<uint64_t>(ns / 1'000'000); return static_cast<uint64_t>(ns / 1'000'000);
} }
static int NSToTic(uint64_t ns) static int NSToTic(uint64_t ns, double const ticrate)
{ {
return static_cast<int>(ns * GameTicRate / 1'000'000'000); return static_cast<int>(ns * ticrate / 1'000'000'000);
} }
static int NSToBuildTic(uint64_t ns) static uint64_t TicToNS(double tic, double const ticrate)
{ {
return static_cast<int>(ns * 120 / 1'000'000'000); return static_cast<uint64_t>(tic * 1'000'000'000 / ticrate);
}
static uint64_t TicToNS(int tic)
{
return static_cast<uint64_t>(tic) * 1'000'000'000 / GameTicRate;
}
static uint64_t BuildTicToNS(int tic)
{
return static_cast<uint64_t>(tic) * 1'000'000'000 / 120;
} }
void I_SetFrameTime() void I_SetFrameTime()
@ -111,18 +103,18 @@ void I_WaitVBL(int count)
I_SetFrameTime(); I_SetFrameTime();
} }
int I_WaitForTic(int prevtic) int I_WaitForTic(int prevtic, double const ticrate)
{ {
// Waits until the current tic is greater than prevtic. Time must not be frozen. // Waits until the current tic is greater than prevtic. Time must not be frozen.
int time; int time;
while ((time = I_GetTime()) <= prevtic) while ((time = I_GetTime(ticrate)) <= prevtic)
{ {
// Windows-specific note: // Windows-specific note:
// The minimum amount of time a thread can sleep is controlled by timeBeginPeriod. // The minimum amount of time a thread can sleep is controlled by timeBeginPeriod.
// We set this to 1 ms in DoMain. // We set this to 1 ms in DoMain.
const uint64_t next = FirstFrameStartTime + TicToNS(prevtic + 1); const uint64_t next = FirstFrameStartTime + TicToNS(prevtic + 1, ticrate);
const uint64_t now = I_nsTime(); const uint64_t now = I_nsTime();
if (next > now) if (next > now)
@ -166,21 +158,16 @@ uint64_t I_GetTimeNS()
return CurrentFrameStartTime - FirstFrameStartTime; return CurrentFrameStartTime - FirstFrameStartTime;
} }
int I_GetTime() int I_GetTime(double const ticrate)
{ {
return NSToTic(CurrentFrameStartTime - FirstFrameStartTime); return NSToTic(CurrentFrameStartTime - FirstFrameStartTime, ticrate);
} }
int I_GetBuildTime() double I_GetTimeFrac(double const ticrate)
{ {
return NSToBuildTic(CurrentFrameStartTime - FirstFrameStartTime); int currentTic = NSToTic(CurrentFrameStartTime - FirstFrameStartTime, ticrate);
} uint64_t ticStartTime = FirstFrameStartTime + TicToNS(currentTic, ticrate);
uint64_t ticNextTime = FirstFrameStartTime + TicToNS(currentTic + 1, ticrate);
double I_GetTimeFrac()
{
int currentTic = NSToTic(CurrentFrameStartTime - FirstFrameStartTime);
uint64_t ticStartTime = FirstFrameStartTime + TicToNS(currentTic);
uint64_t ticNextTime = FirstFrameStartTime + TicToNS(currentTic + 1);
return (CurrentFrameStartTime - ticStartTime) / (double)(ticNextTime - ticStartTime); return (CurrentFrameStartTime - ticStartTime) / (double)(ticNextTime - ticStartTime);
} }

View file

@ -9,17 +9,14 @@ extern double TimeScale;
void I_SetFrameTime(); void I_SetFrameTime();
// Called by D_DoomLoop, returns current time in tics. // Called by D_DoomLoop, returns current time in tics.
int I_GetTime(); int I_GetTime(double const ticrate = GameTicRate);
// same, but using nanoseconds // same, but using nanoseconds
uint64_t I_GetTimeNS(); uint64_t I_GetTimeNS();
// Called by Build games in lieu of totalclock, returns current time in tics at ticrate of 120. double I_GetTimeFrac(double const ticrate = GameTicRate);
int I_GetBuildTime();
double I_GetTimeFrac();
// like I_GetTime, except it waits for a new tic before returning // like I_GetTime, except it waits for a new tic before returning
int I_WaitForTic(int); int I_WaitForTic(int prevtic, double const ticrate = GameTicRate);
// Freezes tic counting temporarily. While frozen, calls to I_GetTime() // Freezes tic counting temporarily. While frozen, calls to I_GetTime()
// will always return the same value. // will always return the same value.

View file

@ -292,6 +292,17 @@ public:
return i; return i;
} }
bool Contains(const T& item) const
{
unsigned int i;
for(i = 0;i < Count;++i)
{
if(Array[i] == item)
return true;
}
return false;
}
template<class Func> template<class Func>
unsigned int FindEx(Func compare) const unsigned int FindEx(Func compare) const
{ {
@ -826,6 +837,18 @@ public:
CopyNodes(o.Nodes, o.Size); CopyNodes(o.Nodes, o.Size);
} }
TMap(TMap &&o)
{
Nodes = o.Nodes;
LastFree = o.LastFree; /* any free position is before this position */
Size = o.Size; /* must be a power of 2 */
NumUsed = o.NumUsed;
o.Size = 0;
o.NumUsed = 0;
o.SetNodeVector(1);
}
TMap &operator= (const TMap &o) TMap &operator= (const TMap &o)
{ {
NumUsed = 0; NumUsed = 0;
@ -835,6 +858,12 @@ public:
return *this; return *this;
} }
TMap &operator= (TMap &&o)
{
TransferFrom(o);
return *this;
}
//======================================================================= //=======================================================================
// //
// TransferFrom // TransferFrom