- Backend update from GZDoom.

This commit is contained in:
Christoph Oelckers 2023-05-27 10:10:42 +02:00
parent 5dfb0c902a
commit f3ea1e312a
11 changed files with 309 additions and 17 deletions

View file

@ -965,6 +965,7 @@ set (PCH_SOURCES
core/maploader.cpp
core/postprocessor.cpp
core/searchpaths.cpp
core/serializer_raze.cpp
core/screenjob.cpp
core/initfs.cpp
core/statistics.cpp

View file

@ -220,6 +220,7 @@ std2:
'bright' { RET(StateOptions ? TK_Bright : TK_Identifier); }
'fast' { RET(StateOptions ? TK_Fast : TK_Identifier); }
'slow' { RET(StateOptions ? TK_Slow : TK_Identifier); }
'ticadjust' { RET(StateOptions ? TK_NoDelay : TK_Identifier); }
'nodelay' { RET(StateOptions ? TK_NoDelay : TK_Identifier); }
'canraise' { RET(StateOptions ? TK_CanRaise : TK_Identifier); }
'offset' { RET(StateOptions ? TK_Offset : TK_Identifier); }

View file

@ -308,13 +308,6 @@ inline FSerializer& Serialize(FSerializer& arc, const char* key, BitArray& value
}
template<> FSerializer& Serialize(FSerializer& arc, const char* key, PClass*& clst, PClass** def);
template<> inline FSerializer& Serialize(FSerializer& arc, const char* key, PClassActor*& clst, PClassActor** def)
{
PClass* c = (PClass*)clst;
Serialize(arc, key, c, (PClass**)def);
clst = (PClassActor*)c;
return arc;
}
template<> FSerializer& Serialize(FSerializer& arc, const char* key, FFont*& font, FFont** def);
template<> FSerializer &Serialize(FSerializer &arc, const char *key, Dictionary *&dict, Dictionary **def);

View file

@ -312,7 +312,7 @@ void UpdateGenericUI(bool cvar)
}
// Turkish i crap. What a mess, just to save two code points... :(
switchstr = GStrings["REQUIRED_CHARACTERS"];
special_i = switchstr && strstr(switchstr, "\xc4\xb0") != nullptr; // capital dotted i (I).
special_i = switchstr && strstr(switchstr, "\xc4\xb0") != nullptr; // capital dotted i (İ).
if (special_i)
{
upperforlower['i'] = 0x130;

View file

@ -635,11 +635,15 @@ void I_StartFrame ()
void I_GetAxes(float axes[NUM_JOYAXIS])
{
memset(axes, 0, sizeof(float) * NUM_JOYAXIS);
int i;
for (i = 0; i < NUM_JOYAXIS; ++i)
{
axes[i] = 0;
}
if (use_joystick)
{
for (unsigned i = 0; i < NUM_JOYDEVICES; ++i)
for (i = 0; i < NUM_JOYDEVICES; ++i)
{
if (JoyDevices[i] != NULL)
{

View file

@ -189,6 +189,8 @@ CUSTOM_CVAR (Int, in_mouse, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL)
//
//==========================================================================
static bool mouse_shown = true;
static void SetCursorState(bool visible)
{
CursorState = visible || !m_hidepointer;
@ -196,13 +198,19 @@ static void SetCursorState(bool visible)
{
if (CursorState)
{
ShowCursor(1);
SetCursor((HCURSOR)(intptr_t)GetClassLongPtr(mainwindow.GetHandle(), GCLP_HCURSOR));
if(!mouse_shown)
{
ShowCursor(true);
mouse_shown = true;
}
}
else
{
ShowCursor(0);
SetCursor(NULL);
if(mouse_shown)
{
ShowCursor(false);
mouse_shown = false;
}
}
}
}

View file

@ -2568,7 +2568,15 @@ ExpEmit FxAssign::Emit(VMFunctionBuilder *build)
}
pointer.Free(build);
return result;
if(intconst)
{ //fix int constant return for assignment
return Right->Emit(build);
}
else
{
return result;
}
}
//==========================================================================

View file

@ -140,7 +140,7 @@ bool ReadSavegame(const char* name)
}
void* data = info->Lock();
FSerializer arc;
FRazeSerializer arc;
if (!arc.OpenReader((const char*)data, info->LumpSize))
{
info->Unlock();
@ -173,7 +173,7 @@ bool WriteSavegame(const char* filename, const char *name)
{
BufferWriter savepic;
FSerializer savegameinfo; // this is for displayable info about the savegame.
FSerializer savegamesession; // saved game session settings.
FRazeSerializer savegamesession; // saved game session settings.
char buf[100];
mysnprintf(buf, countof(buf), GAMENAME " %s", GetVersionString());

View file

@ -4,6 +4,7 @@
#include "build.h"
#include "gamefuncs.h"
#include "coreactor.h"
#include "serializer_raze.h"
// Savegame utilities
class FileReader;

View file

@ -0,0 +1,254 @@
/*
** serializer.cpp
** Savegame wrapper around RapidJSON
**
**---------------------------------------------------------------------------
** Copyright 2016 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
// The #defines here *MUST* match serializer.cpp, or we will get countless strange errors.
#define RAPIDJSON_48BITPOINTER_OPTIMIZATION 0 // disable this insanity which is bound to make the code break over time.
#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
#define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
#define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseFullPrecisionFlag
#include <zlib.h>
#include "rapidjson/rapidjson.h"
#include "rapidjson/writer.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/document.h"
#include "serializer_raze.h"
#include "states.h"
#include "actorinfo.h"
#include "printf.h"
#include "utf8.h"
#include "serializer_internal.h"
//==========================================================================
//
//
//
//==========================================================================
FSerializer &FRazeSerializer::Sprite(const char *key, int32_t &spritenum, int32_t *def)
{
#if 0
if (isWriting())
{
if (w->inObject() && def != nullptr && *def == spritenum) return *this;
WriteKey(key);
w->String(sprites[spritenum].name);
}
else
{
auto val = r->FindKey(key);
if (val != nullptr)
{
if (val->IsString())
{
FName name = val->GetString();
for (auto hint = NumStdSprites; hint-- != 0; )
{
if (sprites[hint].dwName == name)
{
spritenum = hint;
break;
}
}
}
}
}
#endif
return *this;
}
//==========================================================================
//
//
//
//==========================================================================
FSerializer& FRazeSerializer::StatePointer(const char* key, void* ptraddr, bool *res)
{
if (isWriting())
{
if (res) *res = true;
(*this)(key, *(FState**)ptraddr);
}
else
{
::Serialize(*this, key, *(FState**)ptraddr, nullptr, res);
}
return *this;
}
//==========================================================================
//
//
//
//==========================================================================
template<> FSerializer &Serialize(FSerializer &arc, const char *key, PClassActor *&clst, PClassActor **def)
{
if (arc.isWriting())
{
if (!arc.w->inObject() || def == nullptr || clst != *def)
{
arc.WriteKey(key);
if (clst == nullptr)
{
arc.w->Null();
}
else
{
arc.w->String(clst->TypeName.GetChars());
}
}
}
else
{
auto val = arc.r->FindKey(key);
if (val != nullptr)
{
assert(val->IsString() || val->IsNull());
if (val->IsString())
{
clst = PClass::FindActor(UnicodeToString(val->GetString()));
}
else if (val->IsNull())
{
clst = nullptr;
}
else
{
Printf(TEXTCOLOR_RED "string type expected for '%s'\n", key);
clst = nullptr;
arc.mErrors++;
}
}
}
return arc;
}
//==========================================================================
//
//
//
//==========================================================================
FSerializer &Serialize(FSerializer &arc, const char *key, FState *&state, FState **def, bool *retcode)
{
#if 0
if (retcode) *retcode = false;
if (arc.isWriting())
{
if (!arc.w->inObject() || def == nullptr || state != *def)
{
if (retcode) *retcode = true;
arc.WriteKey(key);
if (state == nullptr)
{
arc.w->Null();
}
else
{
PClassActor *info = FState::StaticFindStateOwner(state);
if (info != NULL)
{
arc.w->StartArray();
arc.w->String(info->TypeName.GetChars());
arc.w->Uint((uint32_t)(state - info->GetStates()));
arc.w->EndArray();
}
else
{
arc.w->Null();
}
}
}
}
else
{
auto val = arc.r->FindKey(key);
if (val != nullptr)
{
if (val->IsNull())
{
if (retcode) *retcode = true;
state = nullptr;
}
else if (val->IsArray())
{
if (retcode) *retcode = true;
const rapidjson::Value &cls = (*val)[0];
const rapidjson::Value &ndx = (*val)[1];
state = nullptr;
assert(cls.IsString() && ndx.IsUint());
if (cls.IsString() && ndx.IsUint())
{
PClassActor *clas = PClass::FindActor(UnicodeToString(cls.GetString()));
if (clas && ndx.GetUint() < (unsigned)clas->GetStateCount())
{
state = clas->GetStates() + ndx.GetUint();
}
else
{
// this can actually happen by changing the DECORATE so treat it as a warning, not an error.
state = nullptr;
Printf(TEXTCOLOR_ORANGE "Invalid state '%s+%d' for '%s'\n", cls.GetString(), ndx.GetInt(), key);
}
}
else
{
assert(false && "not a state");
Printf(TEXTCOLOR_RED "data does not represent a state for '%s'\n", key);
arc.mErrors++;
}
}
else if (!retcode)
{
assert(false && "not an array");
Printf(TEXTCOLOR_RED "array type expected for '%s'\n", key);
arc.mErrors++;
}
}
}
#endif
return arc;
}

View file

@ -0,0 +1,22 @@
#pragma once
#include "serializer.h"
class PClassActor;
struct FState;
class FRazeSerializer : public FSerializer
{
public:
FSerializer &Sprite(const char *key, int32_t &spritenum, int32_t *def) override;
FSerializer& StatePointer(const char* key, void* ptraddr, bool *res) override;
};
template<> FSerializer &Serialize(FSerializer &arc, const char *key, PClassActor *&clst, PClassActor **def);
FSerializer &Serialize(FSerializer &arc, const char *key, FState *&state, FState **def, bool *retcode);
template<> inline FSerializer &Serialize(FSerializer &arc, const char *key, FState *&state, FState **def)
{
return Serialize(arc, key, state, def, nullptr);
}