Merge remote-tracking branch 'gzdoom/master' into merge-gzdoom

This commit is contained in:
Magnus Norddahl 2023-10-19 21:05:17 +02:00
commit e75e5a387b
600 changed files with 40006 additions and 59374 deletions

View file

@ -224,7 +224,7 @@ static void FormatTime(const FString& timeForm, int timeVal, FString* result)
if (timeinfo != nullptr)
{
char timeString[1024];
if (strftime(timeString, sizeof(timeString), timeForm, timeinfo))
if (strftime(timeString, sizeof(timeString), timeForm.GetChars(), timeinfo))
*result = timeString;
}
}

View file

@ -0,0 +1,6 @@
#pragma once
#include "fs_files.h"
using FileSys::FileReader;
using FileSys::FileWriter;
using FileSys::BufferWriter;

View file

@ -0,0 +1,7 @@
#pragma once
#include "fs_filesystem.h"
using FileSys::FileSystem;
using FileSys::FResourceFile;
inline FileSys::FileSystem fileSystem;

View file

@ -419,12 +419,12 @@ void BuildAddress (sockaddr_in *address, const char *name)
if (!isnamed)
{
address->sin_addr.s_addr = inet_addr (target);
address->sin_addr.s_addr = inet_addr (target.GetChars());
Printf ("Node number %d, address %s\n", doomcom.numnodes, target.GetChars());
}
else
{
hostentry = gethostbyname (target);
hostentry = gethostbyname (target.GetChars());
if (!hostentry)
I_FatalError ("gethostbyname: couldn't find %s\n%s", target.GetChars(), neterror());
address->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0];

View file

@ -98,7 +98,7 @@ static bool M_SetJoystickConfigSection(IJoystickConfig *joy, bool create, FConfi
FString id = "Joy:";
id += joy->GetIdentifier();
if (!GameConfig) return false;
return GameConfig->SetSection(id, create);
return GameConfig->SetSection(id.GetChars(), create);
}
//==========================================================================

View file

@ -120,6 +120,7 @@ xx(Vector)
xx(Map)
xx(MapIterator)
xx(Array)
xx(Function)
xx(Include)
xx(Sound)
xx(State)
@ -139,6 +140,7 @@ xx(Max)
xx(Min_Normal)
xx(Min_Denormal)
xx(Epsilon)
xx(Equal_Epsilon)
xx(NaN)
xx(Infinity)
xx(Dig)
@ -189,6 +191,7 @@ xx(SetNull)
xx(Key)
xx(Index)
xx(Find)
xx(Call)
// color channels
xx(a)
@ -268,6 +271,7 @@ xx(BuiltinRandom2)
xx(BuiltinFRandom)
xx(BuiltinNameToClass)
xx(BuiltinClassCast)
xx(BuiltinFunctionPtrCast)
xx(ScreenJobRunner)
xx(Action)

View file

@ -3,8 +3,7 @@
#include <stdint.h>
#include "memarena.h"
#include "palentry.h"
class FileReader;
#include "files.h"
enum
{

View file

@ -136,7 +136,7 @@ void FScanner::Open (const char *name)
//
// FScanner :: OpenFile
//
// Loads a script from a file. Uses new/delete for memory allocation.
// Loads a script from a file.
//
//==========================================================================
@ -148,9 +148,9 @@ bool FScanner::OpenFile (const char *name)
if (!fr.OpenFile(name)) return false;
auto filesize = fr.GetLength();
auto filebuff = fr.Read();
if (filebuff.Size() == 0 && filesize > 0) return false;
if (filebuff.size() == 0 && filesize > 0) return false;
ScriptBuffer = FString((const char *)filebuff.Data(), filesize);
ScriptBuffer = FString((const char *)filebuff.data(), filesize);
ScriptName = name; // This is used for error messages so the full file name is preferable
LumpNum = -1;
PrepareScript ();
@ -200,10 +200,13 @@ void FScanner :: OpenLumpNum (int lump)
{
Close ();
{
FileData mem = fileSystem.ReadFile(lump);
ScriptBuffer = mem.GetString();
auto mem = fileSystem.OpenFileReader(lump);
auto buff = ScriptBuffer.LockNewBuffer(mem.GetLength());
mem.Read(buff, mem.GetLength());
buff[mem.GetLength()] = 0;
ScriptBuffer.UnlockBuffer();
}
ScriptName = fileSystem.GetFileFullPath(lump);
ScriptName = fileSystem.GetFileFullPath(lump).c_str();
LumpNum = lump;
PrepareScript ();
}

View file

@ -1,6 +1,7 @@
#ifndef __SC_MAN_H__
#define __SC_MAN_H__
#include <vector>
#include "zstring.h"
#include "tarray.h"
#include "name.h"
@ -74,6 +75,10 @@ public:
{
OpenMem(name, (const char*)buffer.Data(), buffer.Size());
}
void OpenMem(const char* name, const std::vector<uint8_t>& buffer)
{
OpenMem(name, (const char*)buffer.data(), (int)buffer.size());
}
void OpenString(const char *name, FString buffer);
void OpenLumpNum(int lump);
void Close();

View file

@ -169,6 +169,7 @@ std2:
'map' { RET(TK_Map); }
'mapiterator' { RET(TK_MapIterator); }
'array' { RET(TK_Array); }
'function' { RET(ParseVersion >= MakeVersion(4, 12, 0)? TK_FunctionType : TK_Identifier); }
'in' { RET(TK_In); }
'sizeof' { RET(TK_SizeOf); }
'alignof' { RET(TK_AlignOf); }
@ -204,6 +205,7 @@ std2:
'stop' { RET(TK_Stop); }
'null' { RET(TK_Null); }
'nullptr' { RET(ParseVersion >= MakeVersion(4, 9, 0)? TK_Null : TK_Identifier); }
'sealed' { RET(ParseVersion >= MakeVersion(4, 12, 0)? TK_Sealed : TK_Identifier); }
'is' { RET(ParseVersion >= MakeVersion(1, 0, 0)? TK_Is : TK_Identifier); }
'replaces' { RET(ParseVersion >= MakeVersion(1, 0, 0)? TK_Replaces : TK_Identifier); }

View file

@ -122,6 +122,7 @@ xx(TK_Null, "'null'")
xx(TK_Global, "'global'")
xx(TK_Stop, "'stop'")
xx(TK_Include, "'include'")
xx(TK_Sealed, "'sealed'")
xx(TK_Is, "'is'")
xx(TK_Replaces, "'replaces'")
@ -130,6 +131,7 @@ xx(TK_Vector3, "'vector3'")
xx(TK_Map, "'map'")
xx(TK_MapIterator, "'mapiterator'")
xx(TK_Array, "'array'")
xx(TK_FunctionType, "'function'")
xx(TK_In, "'in'")
xx(TK_SizeOf, "'sizeof'")
xx(TK_AlignOf, "'alignof'")

View file

@ -37,7 +37,7 @@
#define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
#define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseFullPrecisionFlag
#include <zlib.h>
#include <miniz.h>
#include "rapidjson/rapidjson.h"
#include "rapidjson/writer.h"
#include "rapidjson/prettywriter.h"
@ -57,6 +57,8 @@
#include "base64.h"
#include "vm.h"
using namespace FileSys;
extern DObject *WP_NOCHANGE;
bool save_full = false; // for testing. Should be removed afterward.
@ -696,7 +698,6 @@ void FSerializer::ReadObjects(bool hubtravel)
}
EndArray();
assert(!founderrors);
if (founderrors)
{
Printf(TEXTCOLOR_RED "Failed to restore all objects in savegame\n");
@ -749,6 +750,7 @@ FCompressedBuffer FSerializer::GetCompressedOutput()
FCompressedBuffer buff;
WriteObjects();
EndObject();
buff.filename = nullptr;
buff.mSize = (unsigned)w->mOutString.GetSize();
buff.mZipFlags = 0;
buff.mCRC32 = crc32(0, (const Bytef*)w->mOutString.GetString(), buff.mSize);
@ -1137,13 +1139,13 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FTextureID &value, FTe
const char *name;
auto lump = pic->GetSourceLump();
if (fileSystem.GetLinkedTexture(lump) == pic)
if (TexMan.GetLinkedTexture(lump) == pic)
{
name = fileSystem.GetFileFullName(lump);
}
else
{
name = pic->GetName();
name = pic->GetName().GetChars();
}
arc.WriteKey(key);
arc.w->StartArray();
@ -1505,8 +1507,8 @@ FString DictionaryToString(const Dictionary &dict)
while (i.NextPair(pair))
{
writer.Key(pair->Key);
writer.String(pair->Value);
writer.Key(pair->Key.GetChars());
writer.String(pair->Value.GetChars());
}
writer.EndObject();
@ -1654,6 +1656,84 @@ FSerializer &Serialize(FSerializer &arc, const char *key, NumericValue &value, N
return arc;
}
//==========================================================================
//
// PFunctionPointer
//
//==========================================================================
void SerializeFunctionPointer(FSerializer &arc, const char *key, FunctionPointerValue *&p)
{
if (arc.isWriting())
{
if(p)
{
arc.BeginObject(key);
arc("Class",p->ClassName);
arc("Function",p->FunctionName);
arc.EndObject();
}
else
{
arc.WriteKey(key);
arc.w->Null();
}
}
else
{
assert(p);
auto v = arc.r->FindKey(key);
if(!v || v->IsNull())
{
p = nullptr;
}
else if(v->IsObject())
{
arc.r->mObjects.Push(FJSONObject(v)); // BeginObject
const char * cstr;
arc.StringPtr("Class", cstr);
if(!cstr)
{
arc.StringPtr("Function", cstr);
if(!cstr)
{
Printf(TEXTCOLOR_RED "Function Pointer missing Class and Function Fields in Object\n");
}
else
{
Printf(TEXTCOLOR_RED "Function Pointer missing Class Field in Object\n");
}
arc.mErrors++;
arc.EndObject();
p = nullptr;
return;
}
p->ClassName = FString(cstr);
arc.StringPtr("Function", cstr);
if(!cstr)
{
Printf(TEXTCOLOR_RED "Function Pointer missing Function Field in Object\n");
arc.mErrors++;
arc.EndObject();
p = nullptr;
return;
}
p->FunctionName = FString(cstr);
arc.EndObject();
}
else
{
Printf(TEXTCOLOR_RED "Function Pointer is not an Object\n");
arc.mErrors++;
p = nullptr;
}
}
}
#include "renderstyle.h"
FSerializer& Serialize(FSerializer& arc, const char* key, FRenderStyle& style, FRenderStyle* def)
{

View file

@ -4,7 +4,6 @@
#include <stdint.h>
#include <type_traits>
#include "tarray.h"
#include "file_zip.h"
#include "tflags.h"
#include "vectors.h"
#include "palentry.h"
@ -55,6 +54,12 @@ struct NumericValue
}
};
struct FunctionPointerValue
{
FString ClassName;
FString FunctionName;
};
class FSerializer
{
@ -80,7 +85,7 @@ public:
void SetUniqueSoundNames() { soundNamesAreUnique = true; }
bool OpenWriter(bool pretty = true);
bool OpenReader(const char *buffer, size_t length);
bool OpenReader(FCompressedBuffer *input);
bool OpenReader(FileSys::FCompressedBuffer *input);
void Close();
void ReadObjects(bool hubtravel);
bool BeginObject(const char *name);
@ -91,7 +96,7 @@ public:
unsigned GetSize(const char *group);
const char *GetKey();
const char *GetOutput(unsigned *len = nullptr);
FCompressedBuffer GetCompressedOutput();
FileSys::FCompressedBuffer GetCompressedOutput();
// The sprite serializer is a special case because it is needed by the VM to handle its 'spriteid' type.
virtual FSerializer &Sprite(const char *key, int32_t &spritenum, int32_t *def);
// This is only needed by the type system.
@ -236,6 +241,8 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FString &sid, FString
FSerializer &Serialize(FSerializer &arc, const char *key, NumericValue &sid, NumericValue *def);
FSerializer &Serialize(FSerializer &arc, const char *key, struct ModelOverride &sid, struct ModelOverride *def);
void SerializeFunctionPointer(FSerializer &arc, const char *key, FunctionPointerValue *&p);
template <typename T/*, typename = std::enable_if_t<std::is_base_of_v<DObject, T>>*/>
FSerializer &Serialize(FSerializer &arc, const char *key, T *&value, T **)
{

View file

@ -116,7 +116,7 @@ void FStat::PrintStat (F2DDrawer *drawer)
// Count number of linefeeds but ignore terminating ones.
if (stattext[i] == '\n') y -= fontheight;
}
DrawText(drawer, NewConsoleFont, CR_GREEN, 5 / textScale, y, stattext,
DrawText(drawer, NewConsoleFont, CR_GREEN, 5 / textScale, y, stattext.GetChars(),
DTA_VirtualWidth, twod->GetWidth() / textScale,
DTA_VirtualHeight, twod->GetHeight() / textScale,
DTA_KeepRatio, true, TAG_DONE);

View file

@ -51,6 +51,7 @@ void FStringTable::LoadStrings (const char *language)
{
int lastlump, lump;
allStrings.Clear();
lastlump = 0;
while ((lump = fileSystem.FindLump("LMACROS", &lastlump)) != -1)
{
@ -60,10 +61,10 @@ void FStringTable::LoadStrings (const char *language)
lastlump = 0;
while ((lump = fileSystem.FindLump ("LANGUAGE", &lastlump)) != -1)
{
auto lumpdata = fileSystem.GetFileData(lump);
auto lumpdata = fileSystem.ReadFile(lump);
if (!ParseLanguageCSV(lump, lumpdata))
LoadLanguage (lump, lumpdata);
if (!ParseLanguageCSV(lump, lumpdata.GetString(), lumpdata.GetSize()))
LoadLanguage (lump, lumpdata.GetString(), lumpdata.GetSize());
}
UpdateLanguage(language);
allMacros.Clear();
@ -77,9 +78,9 @@ void FStringTable::LoadStrings (const char *language)
//==========================================================================
TArray<TArray<FString>> FStringTable::parseCSV(const TArray<uint8_t> &buffer)
TArray<TArray<FString>> FStringTable::parseCSV(const char* buffer, size_t size)
{
const size_t bufLength = buffer.Size();
const size_t bufLength = size;
TArray<TArray<FString>> data;
TArray<FString> row;
TArray<char> cell;
@ -158,16 +159,13 @@ TArray<TArray<FString>> FStringTable::parseCSV(const TArray<uint8_t> &buffer)
bool FStringTable::readMacros(int lumpnum)
{
auto lumpdata = fileSystem.GetFileData(lumpnum);
auto data = parseCSV(lumpdata);
auto lumpdata = fileSystem.ReadFile(lumpnum);
auto data = parseCSV(lumpdata.GetString(), lumpdata.GetSize());
for (unsigned i = 1; i < data.Size(); i++)
{
auto macroname = data[i][0];
auto language = data[i][1];
if (macroname.IsEmpty() || language.IsEmpty()) continue;
FStringf combined_name("%s/%s", language.GetChars(), macroname.GetChars());
FName name = combined_name.GetChars();
FName name = macroname.GetChars();
StringMacro macro;
@ -186,11 +184,11 @@ bool FStringTable::readMacros(int lumpnum)
//
//==========================================================================
bool FStringTable::ParseLanguageCSV(int lumpnum, const TArray<uint8_t> &buffer)
bool FStringTable::ParseLanguageCSV(int lumpnum, const char* buffer, size_t size)
{
if (buffer.Size() < 11) return false;
if (strnicmp((const char*)buffer.Data(), "default,", 8) && strnicmp((const char*)buffer.Data(), "identifier,", 11 )) return false;
auto data = parseCSV(buffer);
if (size < 11) return false;
if (strnicmp(buffer, "default,", 8) && strnicmp(buffer, "identifier,", 11 )) return false;
auto data = parseCSV(buffer, size);
int labelcol = -1;
int filtercol = -1;
@ -243,7 +241,7 @@ bool FStringTable::ParseLanguageCSV(int lumpnum, const TArray<uint8_t> &buffer)
auto filter = filterstr.Split(" ", FString::TOK_SKIPEMPTY);
for (auto& entry : filter)
{
if (sysCallbacks.CheckGame(entry))
if (sysCallbacks.CheckGame(entry.GetChars()))
{
ok = true;
break;
@ -282,14 +280,14 @@ bool FStringTable::ParseLanguageCSV(int lumpnum, const TArray<uint8_t> &buffer)
//
//==========================================================================
void FStringTable::LoadLanguage (int lumpnum, const TArray<uint8_t> &buffer)
void FStringTable::LoadLanguage (int lumpnum, const char* buffer, size_t size)
{
bool errordone = false;
TArray<uint32_t> activeMaps;
FScanner sc;
bool hasDefaultEntry = false;
sc.OpenMem("LANGUAGE", buffer);
sc.OpenMem("LANGUAGE", buffer, (int)size);
sc.SetCMode (true);
while (sc.GetString ())
{
@ -445,9 +443,8 @@ void FStringTable::InsertString(int lumpnum, int langid, FName label, const FStr
break;
}
FString macroname(te.strings[0].GetChars() + index + 2, endindex - index - 2);
FStringf lookupstr("%s/%s", strlangid, macroname.GetChars());
FStringf replacee("@[%s]", macroname.GetChars());
FName lookupname(lookupstr.GetChars(), true);
FName lookupname(macroname.GetChars(), true);
auto replace = allMacros.CheckKey(lookupname);
for (int i = 0; i < 4; i++)
{
@ -642,7 +639,7 @@ bool FStringTable::MatchDefaultString(const char *name, const char *content) con
// Check a secondary key, in case the text comparison cannot be done due to needed orthographic fixes (see Harmony's exit text)
FStringf checkkey("%s_CHECK", name);
auto cc = GetLanguageString(checkkey, FStringTable::default_table);
auto cc = GetLanguageString(checkkey.GetChars(), FStringTable::default_table);
if (cc) c = cc;
return (c && !strnicmp(c, content, strcspn(content, "\n\r\t")));

View file

@ -44,6 +44,7 @@
#include <stdlib.h>
#include <vector>
#include "basics.h"
#include "zstring.h"
#include "tarray.h"
@ -86,7 +87,7 @@ public:
void LoadStrings(const char *language);
void UpdateLanguage(const char* language);
StringMap GetDefaultStrings() { return allStrings[default_table]; } // Dehacked needs these for comparison
void SetOverrideStrings(StringMap && map)
void SetOverrideStrings(StringMap & map)
{
allStrings.Insert(override_table, map);
UpdateLanguage(nullptr);
@ -96,6 +97,7 @@ public:
bool MatchDefaultString(const char *name, const char *content) const;
const char *GetString(const char *name, uint32_t *langtable, int gender = -1) const;
const char *operator() (const char *name) const; // Never returns NULL
const char* operator() (const FString& name) const { return operator()(name.GetChars()); }
const char *operator[] (const char *name) const
{
return GetString(name, nullptr);
@ -111,11 +113,10 @@ private:
LangMap allStrings;
TArray<std::pair<uint32_t, StringMap*>> currentLanguageSet;
void LoadLanguage (int lumpnum, const TArray<uint8_t> &buffer);
TArray<TArray<FString>> parseCSV(const TArray<uint8_t> &buffer);
bool ParseLanguageCSV(int lumpnum, const TArray<uint8_t> &buffer);
void LoadLanguage (int lumpnum, const char* buffer, size_t size);
TArray<TArray<FString>> parseCSV(const char* buffer, size_t size);
bool ParseLanguageCSV(int lumpnum, const char* buffer, size_t size);
bool LoadLanguageFromSpreadsheet(int lumpnum, const TArray<uint8_t> &buffer);
bool readMacros(int lumpnum);
void DeleteString(int langid, FName label);
void DeleteForLabel(int lumpnum, FName label);