Skip to content

Commit

Permalink
Merge branch 'master' into actor-sight-blocker
Browse files Browse the repository at this point in the history
  • Loading branch information
inkoalawetrust authored Mar 18, 2024
2 parents 2f5e36e + 458d81c commit 0dab8d4
Show file tree
Hide file tree
Showing 36 changed files with 255 additions and 684 deletions.
15 changes: 15 additions & 0 deletions src/common/engine/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,21 @@ bool FSerializer::BeginObject(const char *name)
//
//==========================================================================

bool FSerializer::HasKey(const char* name)
{
if (isReading())
{
return r->FindKey(name) != nullptr;
}
return false;
}

//==========================================================================
//
//
//
//==========================================================================

bool FSerializer::HasObject(const char* name)
{
if (isReading())
Expand Down
12 changes: 12 additions & 0 deletions src/common/engine/serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class FSerializer
void ReadObjects(bool hubtravel);
bool BeginObject(const char *name);
void EndObject();
bool HasKey(const char* name);
bool HasObject(const char* name);
bool BeginArray(const char *name);
void EndArray();
Expand Down Expand Up @@ -245,6 +246,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundI
FSerializer &Serialize(FSerializer &arc, const char *key, FString &sid, FString *def);
FSerializer &Serialize(FSerializer &arc, const char *key, NumericValue &sid, NumericValue *def);
FSerializer &Serialize(FSerializer &arc, const char *key, struct ModelOverride &mo, struct ModelOverride *def);
FSerializer &Serialize(FSerializer &arc, const char *key, struct AnimModelOverride &mo, struct AnimModelOverride *def);
FSerializer &Serialize(FSerializer &arc, const char *key, struct AnimOverride &ao, struct AnimOverride *def);
FSerializer& Serialize(FSerializer& arc, const char* key, FTranslationID& value, FTranslationID* defval);

Expand All @@ -259,6 +261,16 @@ FSerializer &Serialize(FSerializer &arc, const char *key, T *&value, T **)
return arc;
}

template<class A, class B>
FSerializer &Serialize(FSerializer &arc, const char *key, std::pair<A, B> &value, std::pair<A, B> *def)
{
arc.BeginObject(key);
Serialize(arc, "first", value.first, def ? &def->first : nullptr);
Serialize(arc, "second", value.second, def ? &def->second : nullptr);
arc.EndObject();
return arc;
}

template<class T, class TT>
FSerializer &Serialize(FSerializer &arc, const char *key, TArray<T, TT> &value, TArray<T, TT> *def)
{
Expand Down
5 changes: 2 additions & 3 deletions src/common/models/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
#include "texturemanager.h"
#include "modelrenderer.h"


TArray<FString> savedModelFiles;
TDeletingArray<FModel*> Models;
TArray<FSpriteModelFrame> SpriteModelFrames;
TMap<void*, FSpriteModelFrame> BaseSpriteModelFrames;
Expand Down Expand Up @@ -160,7 +158,7 @@ unsigned FindModel(const char * path, const char * modelfile, bool silent)

for(unsigned i = 0; i< Models.Size(); i++)
{
if (!Models[i]->mFileName.CompareNoCase(fullname)) return i;
if (Models[i]->mFileName.CompareNoCase(fullname) == 0) return i;
}

auto len = fileSystem.FileLength(lump);
Expand Down Expand Up @@ -236,6 +234,7 @@ unsigned FindModel(const char * path, const char * modelfile, bool silent)
}
// The vertex buffer cannot be initialized here because this gets called before OpenGL is initialized
model->mFileName = fullname;
model->mFilePath = {path, modelfile};
return Models.Push(model);
}

5 changes: 4 additions & 1 deletion src/common/models/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct FSpriteModelFrame;

FTextureID LoadSkin(const char* path, const char* fn);
void FlushModels();
extern TArray<FString> savedModelFiles;

extern TDeletingArray<FModel*> Models;
extern TArray<FSpriteModelFrame> SpriteModelFrames;
extern TMap<void*, FSpriteModelFrame> BaseSpriteModelFrames;
Expand Down Expand Up @@ -76,6 +76,7 @@ enum EFrameError
class FModel
{
public:

FModel();
virtual ~FModel();

Expand All @@ -100,7 +101,9 @@ class FModel
void DestroyVertexBuffer();

bool hasSurfaces = false;

FString mFileName;
std::pair<FString, FString> mFilePath;

FSpriteModelFrame *baseFrame;
private:
Expand Down
4 changes: 3 additions & 1 deletion src/common/objects/dobjtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ PClass *PClass::FindClassTentative(FName name)
//
//==========================================================================

bool ShouldAllowGameSpecificVirtual(FName name, unsigned index, PType* arg, PType* varg);

int PClass::FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction *parentfunc, bool exactReturnType, bool ignorePointerReadOnly)
{
auto proto = variant->Proto;
Expand Down Expand Up @@ -700,7 +702,7 @@ int PClass::FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction
break;
}
}
else
else if(!ShouldAllowGameSpecificVirtual(name, a, proto->ArgumentTypes[a], vproto->ArgumentTypes[a]))
{
fail = true;
break;
Expand Down
6 changes: 4 additions & 2 deletions src/common/platform/posix/cocoa/i_system.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/

#include "i_common.h"
#include "c_cvars.h"

#include <fnmatch.h>
#include <sys/sysctl.h>
Expand All @@ -40,7 +41,7 @@
#include "st_console.h"
#include "v_text.h"


EXTERN_CVAR(Bool, longsavemessages)
double PerfToSec, PerfToMillisec;

void CalculateCPUSpeed()
Expand Down Expand Up @@ -188,7 +189,8 @@ void I_OpenShellFolder(const char* folder)
NSString *currentpath = [filemgr currentDirectoryPath];

[filemgr changeCurrentDirectoryPath:[NSString stringWithUTF8String:folder]];
Printf("Opening folder: %s\n", folder);
if (longsavemessages)
Printf("Opening folder: %s\n", folder);
std::system("open .");
[filemgr changeCurrentDirectoryPath:currentpath];
}
Expand Down
9 changes: 7 additions & 2 deletions src/common/platform/posix/sdl/i_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int I_PickIWad_Cocoa (WadStuff *wads, int numwads, bool showwin, int defaultiwad
double PerfToSec, PerfToMillisec;
CVAR(Bool, con_printansi, true, CVAR_GLOBALCONFIG|CVAR_ARCHIVE);
CVAR(Bool, con_4bitansi, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE);
EXTERN_CVAR(Bool, longsavemessages)

extern FStartupScreen *StartWindow;

Expand Down Expand Up @@ -372,13 +373,17 @@ void I_OpenShellFolder(const char* infolder)

if (!chdir(infolder))
{
Printf("Opening folder: %s\n", infolder);
if (longsavemessages)
Printf("Opening folder: %s\n", infolder);
std::system("xdg-open .");
chdir(curdir);
}
else
{
Printf("Unable to open directory '%s\n", infolder);
if (longsavemessages)
Printf("Unable to open directory '%s\n", infolder);
else
Printf("Unable to open requested directory\n");
}
free(curdir);
}
Expand Down
9 changes: 7 additions & 2 deletions src/common/platform/win32/i_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static HCURSOR CreateBitmapCursor(int xhot, int yhot, HBITMAP and_mask, HBITMAP
EXTERN_CVAR (Bool, queryiwad);
// Used on welcome/IWAD screen.
EXTERN_CVAR (Int, vid_preferbackend)
EXTERN_CVAR(Bool, longsavemessages)

extern HANDLE StdOut;
extern bool FancyStdOut;
Expand Down Expand Up @@ -824,13 +825,17 @@ void I_OpenShellFolder(const char* infolder)
}
else if (SetCurrentDirectoryW(WideString(infolder).c_str()))
{
Printf("Opening folder: %s\n", infolder);
if (longsavemessages)
Printf("Opening folder: %s\n", infolder);
ShellExecuteW(NULL, L"open", L"explorer.exe", L".", NULL, SW_SHOWNORMAL);
SetCurrentDirectoryW(curdir.Data());
}
else
{
Printf("Unable to open directory '%s\n", infolder);
if (longsavemessages)
Printf("Unable to open directory '%s\n", infolder);
else
Printf("Unable to open requested directory\n");
}
}

41 changes: 27 additions & 14 deletions src/common/utility/tarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <utility>
#include <iterator>
#include <algorithm>
#include <functional>

#if !defined(_WIN32)
#include <inttypes.h> // for intptr_t
Expand Down Expand Up @@ -366,11 +367,11 @@ class TArray
}

template<typename Func>
bool IsSorted(Func lt)
bool IsSorted(Func &&lt)
{
for(unsigned i = 1; i < Count; i++)
{
if(lt(Array[i], Array[i-1])) return false;
if(std::invoke(lt, Array[i], Array[i-1])) return false;
}
return true;
}
Expand Down Expand Up @@ -418,7 +419,7 @@ class TArray
//
// exact = false returns the closest match, to be used for, ex., insertions, exact = true returns Size() when no match, like Find does
template<typename Func>
unsigned int SortedFind(const T& item, Func lt, bool exact = true) const
unsigned int SortedFind(const T& item, Func &&lt, bool exact = true) const
{
if(Count == 0) return 0;
if(Count == 1) return lt(item, Array[0]) ? 0 : 1;
Expand All @@ -430,11 +431,11 @@ class TArray
{
int mid = lo + ((hi - lo) / 2);

if(lt(Array[mid], item))
if(std::invoke(lt, Array[mid], item))
{
lo = mid + 1;
}
else if(lt(item, Array[mid]))
else if(std::invoke(lt, item, Array[mid]))
{
if(mid == 0) break; // prevent negative overflow due to unsigned numbers
hi = mid - 1;
Expand All @@ -450,7 +451,7 @@ class TArray
}
else
{
return (lo == Count || lt(item, Array[lo])) ? lo : lo + 1;
return (lo == Count || std::invoke(lt, item, Array[lo])) ? lo : lo + 1;
}
}

Expand All @@ -466,12 +467,24 @@ class TArray
}

template<class Func>
unsigned int FindEx(Func compare) const
bool Contains(const T& item, Func &&compare) const
{
unsigned int i;
for(i = 0;i < Count;++i)
{
if(std::invoke(compare, Array[i], item))
return true;
}
return false;
}

template<class Func>
unsigned int FindEx(Func &&compare) const
{
unsigned int i;
for (i = 0; i < Count; ++i)
{
if (compare(Array[i]))
if (std::invoke(compare, Array[i]))
break;
}
return i;
Expand Down Expand Up @@ -569,9 +582,9 @@ class TArray
}

template<typename Func>
unsigned SortedAddUnique(const T& obj, Func lt)
unsigned SortedAddUnique(const T& obj, Func &&lt)
{
auto f = SortedFind(obj, lt, true);
auto f = SortedFind(obj, std::forward<Func>(lt), true);
if (f == Size()) Push(obj);
return f;
}
Expand All @@ -591,9 +604,9 @@ class TArray
}

template<typename Func>
bool SortedDelete(const T& obj, Func lt)
bool SortedDelete(const T& obj, Func &&lt)
{
auto f = SortedFind(obj, lt, true);
auto f = SortedFind(obj, std::forward<Func>(lt), true);
if (f == Size())
{
Delete(f);
Expand Down Expand Up @@ -691,9 +704,9 @@ class TArray
}

template<typename Func>
void SortedInsert (const T &item, Func lt)
void SortedInsert (const T &item, Func &&lt)
{
Insert (SortedFind (item, lt, false), item);
Insert (SortedFind (item, std::forward<Func>(lt), false), item);
}

void ShrinkToFit ()
Expand Down
8 changes: 0 additions & 8 deletions src/g_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,14 +2148,6 @@ void G_DoLoadGame ()

BackupSaveName = savename;

//Push any added models from A_ChangeModel
for (auto& smf : savedModelFiles)
{
FString modelFilePath = smf.Left(smf.LastIndexOf("/")+1);
FString modelFileName = smf.Right(smf.Len() - smf.Left(smf.LastIndexOf("/") + 1).Len());
FindModel(modelFilePath.GetChars(), modelFileName.GetChars());
}

// At this point, the GC threshold is likely a lot higher than the
// amount of memory in use, so bring it down now by starting a
// collection.
Expand Down
Loading

0 comments on commit 0dab8d4

Please sign in to comment.