From 6055f136d8a5afa952255ff30b29d44927cfdca3 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 3 Mar 2017 16:30:04 +0100 Subject: [PATCH 1/7] Make sure SwapInterval is only ever called while the default frame buffer is bound to avoid problems with some drivers --- src/gl/system/gl_framebuffer.cpp | 23 ++++++++++++++++++++++- src/gl/system/gl_framebuffer.h | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 1a4582d80..864d796a8 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -83,7 +83,7 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, int width, int height, int { // SetVSync needs to be at the very top to workaround a bug in Nvidia's OpenGL driver. // If wglSwapIntervalEXT is called after glBindFramebuffer in a frame the setting is not changed! - SetVSync(vid_vsync); + Super::SetVSync(vid_vsync); // Make sure all global variables tracking OpenGL context state are reset.. FHardwareTexture::InitGlobalState(); @@ -230,6 +230,27 @@ void OpenGLFrameBuffer::Swap() mDebug->Update(); } +//========================================================================== +// +// Enable/disable vertical sync +// +//========================================================================== + +void OpenGLFrameBuffer::SetVSync(bool vsync) +{ + // Switch to the default frame buffer because some drivers associate the vsync state with the bound FB object. + GLint oldDrawFramebufferBinding = 0, oldReadFramebufferBinding = 0; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDrawFramebufferBinding); + glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldReadFramebufferBinding); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + + Super::SetVSync(vsync); + + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDrawFramebufferBinding); + glBindFramebuffer(GL_READ_FRAMEBUFFER, oldReadFramebufferBinding); +} + //=========================================================================== // // DoSetGamma diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index 0eb289ffe..d6306fcdf 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -83,6 +83,8 @@ public: bool Is8BitMode() { return false; } bool IsHWGammaActive() const { return HWGammaActive; } + void SetVSync(bool vsync); + private: PalEntry Flash; From 7736e4274064fb358565d8e4658d0e3afc159f58 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 3 Mar 2017 18:53:11 +0100 Subject: [PATCH 2/7] - fixed: The respawn event handler was not called for a regular in-game respawn, only for a cheat resurrection. --- src/p_mobj.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 1e2559ec5..d7de2a18c 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -5563,6 +5563,7 @@ APlayerPawn *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags) for (int ii=0; ii < BODYQUESIZE; ++ii) if (bodyque[ii] == p->mo) bodyque[ii] = oldactor; + E_PlayerRespawned(int(p - players)); FBehavior::StaticStartTypedScripts (SCRIPT_Respawn, p->mo, true); } } From 217bcb847d2a703ecf5fd302127feeac73b3fa3c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 3 Mar 2017 19:19:19 +0100 Subject: [PATCH 3/7] - fixed: When the savegame code errors out, some cleanup is required in G_DoSaveGame. --- src/dobjtype.cpp | 3 +-- src/g_game.cpp | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index a2a5a6883..98a893391 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -1398,8 +1398,7 @@ void PPointer::WriteValue(FSerializer &ar, const char *key,const void *addr) con } else { - assert(0 && "Pointer points to a type we don't handle"); - I_Error("Attempt to save pointer to unhandled type"); + I_Error("Attempt to save pointer to unhandled type %s", PointedType->DescriptiveName()); } } diff --git a/src/g_game.cpp b/src/g_game.cpp index b39ee52a8..4391a0571 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -2270,7 +2270,29 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio I_FreezeTime(true); insave = true; - G_SnapshotLevel (); + try + { + G_SnapshotLevel(); + } + catch(CRecoverableError &err) + { + // delete the snapshot. Since the save failed it is broken. + insave = false; + level.info->Snapshot.Clean(); + Printf(PRINT_HIGH, "Save failed\n"); + Printf(PRINT_HIGH, "%s\n", err.GetMessage()); + // The time freeze must be reset if the save fails. + if (cl_waitforsave) + I_FreezeTime(false); + return; + } + catch (...) + { + insave = false; + if (cl_waitforsave) + I_FreezeTime(false); + throw; + } BufferWriter savepic; FSerializer savegameinfo; // this is for displayable info about the savegame From f563a296c2315b463387a864ed3902e5f720d33d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 3 Mar 2017 19:23:27 +0100 Subject: [PATCH 4/7] - added an ACS ScriptCall function. So far only superficially tested. --- src/p_acs.cpp | 164 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 140 insertions(+), 24 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 4e1b7a026..027b614ea 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -180,7 +180,7 @@ inline int PitchToACS(DAngle ang) struct CallReturn { - CallReturn(int pc, ScriptFunction *func, FBehavior *module, SDWORD *locals, ACSLocalArrays *arrays, bool discard, unsigned int runaway) + CallReturn(int pc, ScriptFunction *func, FBehavior *module, int32_t *locals, ACSLocalArrays *arrays, bool discard, unsigned int runaway) : ReturnFunction(func), ReturnModule(module), ReturnLocals(locals), @@ -192,7 +192,7 @@ struct CallReturn ScriptFunction *ReturnFunction; FBehavior *ReturnModule; - SDWORD *ReturnLocals; + int32_t *ReturnLocals; ACSLocalArrays *ReturnArrays; int ReturnAddress; int bDiscardResult; @@ -206,7 +206,7 @@ static DLevelScript *P_GetScriptGoing (AActor *who, line_t *where, int num, cons struct FBehavior::ArrayInfo { DWORD ArraySize; - SDWORD *Elements; + int32_t *Elements; }; TArray FBehavior::StaticModules; @@ -243,11 +243,11 @@ inline int uallong(const int &foo) //============================================================================ // ACS variables with world scope -SDWORD ACS_WorldVars[NUM_WORLDVARS]; +int32_t ACS_WorldVars[NUM_WORLDVARS]; FWorldGlobalArray ACS_WorldArrays[NUM_WORLDVARS]; // ACS variables with global scope -SDWORD ACS_GlobalVars[NUM_GLOBALVARS]; +int32_t ACS_GlobalVars[NUM_GLOBALVARS]; FWorldGlobalArray ACS_GlobalArrays[NUM_GLOBALVARS]; //---------------------------------------------------------------------------- @@ -261,7 +261,7 @@ FWorldGlobalArray ACS_GlobalArrays[NUM_GLOBALVARS]; struct FACSStack { - SDWORD buffer[STACK_SIZE]; + int32_t buffer[STACK_SIZE]; int sp; FACSStack *next; FACSStack *prev; @@ -979,7 +979,7 @@ void P_ClearACSVars(bool alsoglobal) // //============================================================================ -static void WriteVars (FSerializer &file, SDWORD *vars, size_t count, const char *key) +static void WriteVars (FSerializer &file, int32_t *vars, size_t count, const char *key) { size_t i, j; @@ -1007,7 +1007,7 @@ static void WriteVars (FSerializer &file, SDWORD *vars, size_t count, const char // //============================================================================ -static void ReadVars (FSerializer &arc, SDWORD *vars, size_t count, const char *key) +static void ReadVars (FSerializer &arc, int32_t *vars, size_t count, const char *key) { memset(&vars[0], 0, count * 4); arc.Array(key, vars, (int)count); @@ -1684,10 +1684,10 @@ void FBehavior::SerializeVars (FSerializer &arc) } } -void FBehavior::SerializeVarSet (FSerializer &arc, SDWORD *vars, int max) +void FBehavior::SerializeVarSet (FSerializer &arc, int32_t *vars, int max) { - SDWORD count; - SDWORD first, last; + int32_t count; + int32_t first, last; if (arc.BeginObject(nullptr)) { @@ -1997,7 +1997,7 @@ bool FBehavior::Init(int lumpnum, FileReader * fr, int len) { MapVarStore[LittleLong(chunk[2+i*2])] = i; ArrayStore[i].ArraySize = LittleLong(chunk[3+i*2]); - ArrayStore[i].Elements = new SDWORD[ArrayStore[i].ArraySize]; + ArrayStore[i].Elements = new int32_t[ArrayStore[i].ArraySize]; memset(ArrayStore[i].Elements, 0, ArrayStore[i].ArraySize*sizeof(DWORD)); } } @@ -2013,7 +2013,7 @@ bool FBehavior::Init(int lumpnum, FileReader * fr, int len) // optimizer. Might be some undefined behavior in this code, // but I don't know what it is. unsigned int initsize = MIN (ArrayStore[arraynum].ArraySize, (LittleLong(chunk[1])-4)/4); - SDWORD *elems = ArrayStore[arraynum].Elements; + int32_t *elems = ArrayStore[arraynum].Elements; for (unsigned int j = 0; j < initsize; ++j) { elems[j] = LittleLong(chunk[3+j]); @@ -2062,7 +2062,7 @@ bool FBehavior::Init(int lumpnum, FileReader * fr, int len) int arraynum = MapVarStore[LittleLong(chunk[i+2])]; if ((unsigned)arraynum < (unsigned)NumArrays) { - SDWORD *elems = ArrayStore[arraynum].Elements; + int32_t *elems = ArrayStore[arraynum].Elements; for (int j = ArrayStore[arraynum].ArraySize; j > 0; --j, ++elems) { // *elems |= LibraryID; @@ -2088,7 +2088,7 @@ bool FBehavior::Init(int lumpnum, FileReader * fr, int len) chunkData += 4; if ((unsigned)arraynum < (unsigned)NumArrays) { - SDWORD *elems = ArrayStore[arraynum].Elements; + int32_t *elems = ArrayStore[arraynum].Elements; // Ending zeros may be left out. for (int j = MIN(LittleLong(chunk[1])-5, ArrayStore[arraynum].ArraySize); j > 0; --j, ++elems, ++chunkData) { @@ -4371,6 +4371,7 @@ enum EACSFunctions ACSF_Floor, ACSF_Round, ACSF_Ceil, + ACSF_ScriptCall, // OpenGL stuff @@ -4753,9 +4754,121 @@ static int SwapActorTeleFog(AActor *activator, int tid) return count; } +static int ScriptCall(unsigned argc, int32_t *args) +{ + int retval = 0; + if (argc >= 2) + { + auto clsname = FBehavior::StaticLookupString(args[0]); + auto funcname = FBehavior::StaticLookupString(args[1]); + auto cls = PClass::FindClass(clsname); + if (!cls) + { + I_Error("ACS call to unknown class in script function %s.%s", cls, funcname); + } + auto funcsym = dyn_cast(cls->Symbols.FindSymbol(funcname, true)); + if (funcsym == nullptr) + { + I_Error("ACS call to unknown script function %s.%s", cls, funcname); + } + auto func = funcsym->Variants[0].Implementation; + if (func->ImplicitArgs > 0) + { + I_Error("ACS call to non-static script function %s.%s", cls, funcname); + } + TArray params; + for (unsigned i = 2; i < argc; i++) + { + if (func->Proto->ArgumentTypes.Size() < i - 1) + { + I_Error("Too many parameters in call to %s.%s", cls, funcname); + } + auto argtype = func->Proto->ArgumentTypes[i - 2]; + // The only types allowed are int, bool, double, Name, Sound, Color and String + if (argtype == TypeSInt32 || argtype == TypeColor) + { + params.Push(args[i]); + } + else if (argtype == TypeBool) + { + params.Push(!!args[i]); + } + else if (argtype == TypeFloat64) + { + params.Push(ACSToDouble(args[i])); + } + else if (argtype == TypeName) + { + params.Push(FName(FBehavior::StaticLookupString(args[i])).GetIndex()); + } + else if (argtype == TypeString) + { + params.Push(FBehavior::StaticLookupString(args[i])); + } + else if (argtype == TypeSound) + { + params.Push(int(FSoundID(FBehavior::StaticLookupString(args[i])))); + } + else + { + I_Error("Invalid type %s in call to %s.%s", argtype->DescriptiveName(), cls, funcname); + } + } + if (func->Proto->ArgumentTypes.Size() > params.Size()) + { + // Check if we got enough parameters. That means we either cover the full argument list of the function or the next argument is optional. + if (!(funcsym->Variants[0].ArgFlags[params.Size()] & VARF_Optional)) + { + I_Error("Insufficient parameters in call to %s.%s", cls, funcname); + } + } + // The return value can be the same types as the parameter types, plus void + if (func->Proto->ReturnTypes.Size() == 0) + { + GlobalVMStack.Call(func, ¶ms[0], params.Size(), nullptr, 0); + } + else + { + auto rettype = func->Proto->ReturnTypes[0]; + if (rettype == TypeSInt32 || rettype == TypeBool || rettype == TypeColor || rettype == TypeName || rettype == TypeSound) + { + VMReturn ret(&retval); + GlobalVMStack.Call(func, ¶ms[0], params.Size(), &ret, 1); + if (rettype == TypeName) + { + retval = GlobalACSStrings.AddString(FName(ENamedName(retval))); + } + else if (rettype == TypeSound) + { + retval = GlobalACSStrings.AddString(FSoundID(retval)); + } + } + else if (rettype == TypeFloat64) + { + double d; + VMReturn ret(&d); + GlobalVMStack.Call(func, ¶ms[0], params.Size(), &ret, 1); + retval = DoubleToACS(d); + } + else if (rettype == TypeString) + { + FString d; + VMReturn ret(&d); + GlobalVMStack.Call(func, ¶ms[0], params.Size(), &ret, 1); + retval = GlobalACSStrings.AddString(d); + } + else + { + // All other return values can not be handled so ignore them. + GlobalVMStack.Call(func, ¶ms[0], params.Size(), nullptr, 0); + } + } + } + return retval; +} -int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args) +int DLevelScript::CallFunction(int argCount, int funcIndex, int32_t *args) { AActor *actor; switch(funcIndex) @@ -6103,6 +6216,9 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound) case ACSF_Round: return (args[0] + 32768) & ~0xffff; + case ACSF_ScriptCall: + return ScriptCall(argCount, args); + default: break; } @@ -6192,7 +6308,7 @@ static void SetMarineSprite(AActor *marine, PClassActor *source) int DLevelScript::RunScript () { DACSThinker *controller = DACSThinker::ActiveThinker; - SDWORD *locals = &Localvars[0]; + int32_t *locals = &Localvars[0]; ACSLocalArrays noarrays; ACSLocalArrays *localarrays = &noarrays; ScriptFunction *activeFunction = NULL; @@ -6266,7 +6382,7 @@ int DLevelScript::RunScript () } FACSStack stackobj; - SDWORD *Stack = stackobj.buffer; + int32_t *Stack = stackobj.buffer; int &sp = stackobj.sp; int *pc = this->pc; @@ -6560,7 +6676,7 @@ int DLevelScript::RunScript () int i; ScriptFunction *func; FBehavior *module; - SDWORD *mylocals; + int32_t *mylocals; if(pcd == PCD_CALLSTACK) { @@ -6615,7 +6731,7 @@ int DLevelScript::RunScript () int value; union { - SDWORD *retsp; + int32_t *retsp; CallReturn *ret; }; @@ -7770,7 +7886,7 @@ scriptwait: while (min <= max) { int mid = (min + max) / 2; - SDWORD caseval = LittleLong(pc[mid*2]); + int32_t caseval = LittleLong(pc[mid*2]); if (caseval == STACK(1)) { pc = activeBehavior->Ofs2PC (LittleLong(pc[mid*2+1])); @@ -9185,7 +9301,7 @@ scriptwait: const char *str = FBehavior::StaticLookupString(STACK(1)); if (str != NULL) { - STACK(1) = SDWORD(strlen(str)); + STACK(1) = int32_t(strlen(str)); break; } @@ -9355,7 +9471,7 @@ scriptwait: switch (STACK(1)) { case PLAYERINFO_TEAM: STACK(2) = userinfo->GetTeam(); break; - case PLAYERINFO_AIMDIST: STACK(2) = (SDWORD)(userinfo->GetAimDist() * (0x40000000/90.)); break; // Yes, this has been returning a BAM since its creation. + case PLAYERINFO_AIMDIST: STACK(2) = (int32_t)(userinfo->GetAimDist() * (0x40000000/90.)); break; // Yes, this has been returning a BAM since its creation. case PLAYERINFO_COLOR: STACK(2) = userinfo->GetColor(); break; case PLAYERINFO_GENDER: STACK(2) = userinfo->GetGender(); break; case PLAYERINFO_NEVERSWITCH: STACK(2) = userinfo->GetNeverSwitch(); break; @@ -9762,7 +9878,7 @@ DLevelScript::DLevelScript (AActor *who, line_t *where, int num, const ScriptPtr script = num; assert(code->VarCount >= code->ArgCount); Localvars.Resize(code->VarCount); - memset(&Localvars[0], 0, code->VarCount * sizeof(SDWORD)); + memset(&Localvars[0], 0, code->VarCount * sizeof(int32_t)); for (int i = 0; i < MIN(argcount, code->ArgCount); ++i) { Localvars[i] = args[i]; From c630b070113f04ca7bc6a5dd8339a630b79faf09 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 3 Mar 2017 19:35:08 +0100 Subject: [PATCH 5/7] - replaced SDWORD with int32_t globally. This type wasn't used in the software rendering code so it could be removed already. The other homegrown types will have to be dealt with later. --- src/actor.h | 10 +++---- src/basictypes.h | 3 +- src/c_console.cpp | 2 +- src/doomdata.h | 4 +-- src/fragglescript/t_func.cpp | 2 +- src/fragglescript/t_script.h | 2 +- src/gl/system/gl_wipe.cpp | 12 ++++---- src/oplsynth/dosbox/opl.cpp | 2 +- src/oplsynth/nukedopl3.h | 2 +- src/p_acs.h | 14 +++++----- src/p_buildmap.cpp | 16 +++++------ src/p_conversation.cpp | 34 +++++++++++------------ src/p_glnodes.cpp | 14 +++++----- src/p_switch.cpp | 2 +- src/po_man.cpp | 2 +- src/resourcefiles/file_zip.cpp | 2 +- src/s_advsound.cpp | 2 +- src/s_sndseq.cpp | 6 ++-- src/s_sndseq.h | 6 ++-- src/s_sound.cpp | 4 +-- src/scripting/decorate/olddecorations.cpp | 2 +- src/textures/backdroptexture.cpp | 14 +++++----- src/textures/ddstexture.cpp | 4 +-- src/timidity/instrum_dls.cpp | 10 +++---- src/timidity/instrum_sf2.cpp | 10 +++---- src/timidity/mix.cpp | 12 ++++---- src/timidity/timidity.h | 4 +-- 27 files changed, 98 insertions(+), 99 deletions(-) diff --git a/src/actor.h b/src/actor.h index 9fc1d10f1..e435a1fb7 100644 --- a/src/actor.h +++ b/src/actor.h @@ -1037,7 +1037,7 @@ public: double StealthAlpha; // Minmum alpha for MF_STEALTH. int WoundHealth; // Health needed to enter wound state - SDWORD tics; // state tic counter + int32_t tics; // state tic counter FState *state; //VMFunction *Damage; // For missiles and monster railgun int DamageVal; @@ -1062,10 +1062,10 @@ public: // also the originator for missiles TObjPtr lastenemy; // Last known enemy -- killough 2/15/98 TObjPtr LastHeard; // [RH] Last actor this one heard - SDWORD reactiontime; // if non 0, don't attack yet; used by + int32_t reactiontime; // if non 0, don't attack yet; used by // player to freeze a bit after teleporting - SDWORD threshold; // if > 0, the target will be chased - SDWORD DefThreshold; // [MC] Default threshold which the actor will reset its threshold to after switching targets + int32_t threshold; // if > 0, the target will be chased + int32_t DefThreshold; // [MC] Default threshold which the actor will reset its threshold to after switching targets // no matter what (even if shot) player_t *player; // only valid if type of APlayerPawn TObjPtr LastLookActor; // Actor last looked for (if TIDtoHate != 0) @@ -1159,7 +1159,7 @@ public: double MaxDropOffHeight; double MaxStepHeight; - SDWORD Mass; + int32_t Mass; SWORD PainChance; int PainThreshold; FNameNoInit DamageType; diff --git a/src/basictypes.h b/src/basictypes.h index ff2cd972e..acb499c0d 100644 --- a/src/basictypes.h +++ b/src/basictypes.h @@ -7,7 +7,6 @@ typedef int8_t SBYTE; typedef uint8_t BYTE; typedef int16_t SWORD; typedef uint16_t WORD; -typedef int32_t SDWORD; typedef uint32_t uint32; typedef int64_t SQWORD; typedef uint64_t QWORD; @@ -63,7 +62,7 @@ union QWORD_UNION #define FRACBITS 16 #define FRACUNIT (1<DrawChar (ConFont, CR_ORANGE, (int)i, tickerY, 0x13, TAG_DONE); else diff --git a/src/doomdata.h b/src/doomdata.h index 39f0d184a..0c1fb4a97 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -262,8 +262,8 @@ struct mapseg_t struct mapseg4_t { - SDWORD v1; - SDWORD v2; + int32_t v1; + int32_t v2; SWORD angle; WORD linedef; SWORD side; diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 68d940704..1a979824f 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -479,7 +479,7 @@ DFsSection *FParser::looping_section() int n; // check thru all the hashchains - SDWORD rover_index = Script->MakeIndex(Rover); + int32_t rover_index = Script->MakeIndex(Rover); for(n=0; n, InitIntToZero> FWorldGlobalArray; +typedef TMap, InitIntToZero> FWorldGlobalArray; // ACS variables with world scope -extern SDWORD ACS_WorldVars[NUM_WORLDVARS]; +extern int32_t ACS_WorldVars[NUM_WORLDVARS]; extern FWorldGlobalArray ACS_WorldArrays[NUM_WORLDVARS]; // ACS variables with global scope -extern SDWORD ACS_GlobalVars[NUM_GLOBALVARS]; +extern int32_t ACS_GlobalVars[NUM_GLOBALVARS]; extern FWorldGlobalArray ACS_GlobalArrays[NUM_GLOBALVARS]; #define LIBRARYID_MASK 0xFFF00000 @@ -323,7 +323,7 @@ public: ACSProfileInfo *GetFunctionProfileData(ScriptFunction *func) { return GetFunctionProfileData((int)(func - (ScriptFunction *)Functions)); } const char *LookupString (DWORD index) const; - SDWORD *MapVars[NUM_MAPVARS]; + int32_t *MapVars[NUM_MAPVARS]; static FBehavior *StaticLoadModule (int lumpnum, FileReader * fr=NULL, int len=0); static void StaticLoadDefaultModules (); @@ -359,7 +359,7 @@ private: ArrayInfo **Arrays; int NumTotalArrays; DWORD StringTable; - SDWORD MapVarStore[NUM_MAPVARS]; + int32_t MapVarStore[NUM_MAPVARS]; TArray Imports; DWORD LibraryID; char ModuleName[9]; @@ -375,7 +375,7 @@ private: int FindStringInChunk (DWORD *chunk, const char *varname) const; void SerializeVars (FSerializer &arc); - void SerializeVarSet (FSerializer &arc, SDWORD *vars, int max); + void SerializeVarSet (FSerializer &arc, int32_t *vars, int max); void MarkMapVarStrings() const; void LockMapVarStrings() const; @@ -919,7 +919,7 @@ protected: int DoSpawnSpot (int type, int spot, int tid, int angle, bool forced); int DoSpawnSpotFacing (int type, int spot, int tid, bool forced); int DoClassifyActor (int tid); - int CallFunction(int argCount, int funcIndex, SDWORD *args); + int CallFunction(int argCount, int funcIndex, int32_t *args); void DoFadeTo (int r, int g, int b, int a, int time); void DoFadeRange (int r1, int g1, int b1, int a1, diff --git a/src/p_buildmap.cpp b/src/p_buildmap.cpp index 3d1e77d6d..1be648bc2 100644 --- a/src/p_buildmap.cpp +++ b/src/p_buildmap.cpp @@ -46,7 +46,7 @@ struct sectortype { SWORD wallptr, wallnum; - SDWORD ceilingZ, floorZ; + int32_t ceilingZ, floorZ; SWORD ceilingstat, floorstat; SWORD ceilingpicnum, ceilingheinum; SBYTE ceilingshade; @@ -74,7 +74,7 @@ struct sectortype //32 bytes struct walltype { - SDWORD x, y; + int32_t x, y; SWORD point2, nextwall, nextsector, cstat; SWORD picnum, overpicnum; SBYTE shade; @@ -100,7 +100,7 @@ struct walltype //44 bytes struct spritetype { - SDWORD x, y, z; + int32_t x, y, z; SWORD cstat, picnum; SBYTE shade; BYTE pal, clipdist, filler; @@ -146,8 +146,8 @@ static bool P_LoadBloodMap (BYTE *data, size_t len, FMapThing **sprites, int *nu static void LoadSectors (sectortype *bsectors, int count); static void LoadWalls (walltype *walls, int numwalls, sectortype *bsectors); static int LoadSprites (spritetype *sprites, Xsprite *xsprites, int numsprites, sectortype *bsectors, FMapThing *mapthings); -static vertex_t *FindVertex (SDWORD x, SDWORD y); -static void CreateStartSpot (SDWORD *pos, FMapThing *start); +static vertex_t *FindVertex (int32_t x, int32_t y); +static void CreateStartSpot (int32_t *pos, FMapThing *start); static void CalcPlane (SlopeWork &slope, secplane_t &plane); static void Decrypt (void *to, const void *from, int len, int key); @@ -232,7 +232,7 @@ bool P_LoadBuildMap (BYTE *data, size_t len, FMapThing **sprites, int *numspr) numsprites = *(WORD *)(data + 24 + numsec*sizeof(sectortype) + numwalls*sizeof(walltype)); *sprites = new FMapThing[numsprites + 1]; - CreateStartSpot ((SDWORD *)(data + 4), *sprites); + CreateStartSpot ((int32_t *)(data + 4), *sprites); *numspr = 1 + LoadSprites ((spritetype *)(data + 26 + numsec*sizeof(sectortype) + numwalls*sizeof(walltype)), NULL, numsprites, (sectortype *)(data + 22), *sprites + 1); @@ -755,7 +755,7 @@ static int LoadSprites (spritetype *sprites, Xsprite *xsprites, int numsprites, // //========================================================================== -vertex_t *FindVertex (SDWORD xx, SDWORD yy) +vertex_t *FindVertex (int32_t xx, int32_t yy) { int i; @@ -780,7 +780,7 @@ vertex_t *FindVertex (SDWORD xx, SDWORD yy) // //========================================================================== -static void CreateStartSpot (SDWORD *pos, FMapThing *start) +static void CreateStartSpot (int32_t *pos, FMapThing *start) { short angle = LittleShort(*(WORD *)(&pos[3])); FMapThing mt = { 0, }; diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index f43313682..0ac80171c 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -66,22 +66,22 @@ // The conversations as they exist inside a SCRIPTxx lump. struct Response { - SDWORD GiveType; - SDWORD Item[3]; - SDWORD Count[3]; + int32_t GiveType; + int32_t Item[3]; + int32_t Count[3]; char Reply[32]; char Yes[80]; - SDWORD Link; - DWORD Log; + int32_t Link; + uint32_t Log; char No[80]; }; struct Speech { - DWORD SpeakerType; - SDWORD DropType; - SDWORD ItemCheck[3]; - SDWORD Link; + uint32_t SpeakerType; + int32_t DropType; + int32_t ItemCheck[3]; + int32_t Link; char Name[16]; char Sound[8]; char Backdrop[8]; @@ -92,9 +92,9 @@ struct Speech // The Teaser version of the game uses an older version of the structure struct TeaserSpeech { - DWORD SpeakerType; - SDWORD DropType; - DWORD VoiceNumber; + uint32_t SpeakerType; + int32_t DropType; + uint32_t VoiceNumber; char Name[16]; char Dialogue[320]; Response Responses[5]; @@ -116,8 +116,8 @@ static int ConversationPauseTic; static int StaticLastReply; static bool LoadScriptFile(int lumpnum, FileReader *lump, int numnodes, bool include, int type); -static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, DWORD &prevSpeakerType); -static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, DWORD &prevSpeakerType); +static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpeakerType); +static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpeakerType); static void ParseReplies (FStrifeDialogueReply **replyptr, Response *responses); static bool DrawConversationMenu (); static void PickConversationReply (int replyindex); @@ -243,7 +243,7 @@ bool LoadScriptFile (const char *name, bool include, int type) static bool LoadScriptFile(int lumpnum, FileReader *lump, int numnodes, bool include, int type) { int i; - DWORD prevSpeakerType; + uint32_t prevSpeakerType; FStrifeDialogueNode *node; char buffer[4]; @@ -317,7 +317,7 @@ static bool LoadScriptFile(int lumpnum, FileReader *lump, int numnodes, bool inc // //============================================================================ -static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, DWORD &prevSpeakerType) +static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, uint32_t &prevSpeakerType) { FStrifeDialogueNode *node; Speech speech; @@ -393,7 +393,7 @@ static FStrifeDialogueNode *ReadRetailNode (FileReader *lump, DWORD &prevSpeaker // //============================================================================ -static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, DWORD &prevSpeakerType) +static FStrifeDialogueNode *ReadTeaserNode (FileReader *lump, uint32_t &prevSpeakerType) { FStrifeDialogueNode *node; TeaserSpeech speech; diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 43ed096e0..d30cb812e 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -82,13 +82,13 @@ static void CreateCachedNodes(MapData *map); // fixed 32 bit gl_vert format v2.0+ (glBsp 1.91) struct mapglvertex_t { - SDWORD x,y; + int32_t x,y; }; struct gl3_mapsubsector_t { - SDWORD numsegs; - SDWORD firstseg; // Index of first one; segs are stored sequentially. + int32_t numsegs; + int32_t firstseg; // Index of first one; segs are stored sequentially. }; struct glseg_t @@ -102,11 +102,11 @@ struct glseg_t struct glseg3_t { - SDWORD v1; - SDWORD v2; + int32_t v1; + int32_t v2; WORD linedef; WORD side; - SDWORD partner; + int32_t partner; }; struct gl5_mapnode_t @@ -621,7 +621,7 @@ static bool LoadNodes (FileReader * lump) no->dy = LittleShort(mn->dy)<children[j]); + int32_t child = LittleLong(mn->children[j]); if (child & GL5_NF_SUBSECTOR) { child &= ~GL5_NF_SUBSECTOR; diff --git a/src/p_switch.cpp b/src/p_switch.cpp index ae7cf2143..3e956f691 100644 --- a/src/p_switch.cpp +++ b/src/p_switch.cpp @@ -69,7 +69,7 @@ public: bool bFlippable; bool bReturning; FSwitchDef *m_SwitchDef; - SDWORD m_Frame; + int32_t m_Frame; DWORD m_Timer; DVector2 m_Pos; diff --git a/src/po_man.cpp b/src/po_man.cpp index c2c8f5a7d..ebe39ccca 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -147,7 +147,7 @@ polyspawns_t *polyspawns; // [RH] Let P_SpawnMapThings() find our thingies for u // PRIVATE DATA DEFINITIONS ------------------------------------------------ -static TArray KnownPolySides; +static TArray KnownPolySides; static FPolyNode *FreePolyNodes; // CODE -------------------------------------------------------------------- diff --git a/src/resourcefiles/file_zip.cpp b/src/resourcefiles/file_zip.cpp index 7b83084ab..a48a17ca2 100644 --- a/src/resourcefiles/file_zip.cpp +++ b/src/resourcefiles/file_zip.cpp @@ -151,7 +151,7 @@ static DWORD Zip_FindCentralDir(FileReader * fin) if (fin->Seek(uReadPos, SEEK_SET) != 0) break; - if (fin->Read(buf, (SDWORD)uReadSize) != (SDWORD)uReadSize) break; + if (fin->Read(buf, (int32_t)uReadSize) != (int32_t)uReadSize) break; for (i = (int)uReadSize - 3; (i--) > 0;) { diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index 952a40d09..687a27a43 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -167,7 +167,7 @@ struct FBloodSFX int Pitch; // pitch change int PitchRange; // range of random pitch DWORD Format; // format of audio 1=11025 5=22050 - SDWORD LoopStart; // loop position (-1 means no looping) + int32_t LoopStart; // loop position (-1 means no looping) char RawName[9]; // name of RAW resource }; diff --git a/src/s_sndseq.cpp b/src/s_sndseq.cpp index 6506f303b..af3f3617b 100644 --- a/src/s_sndseq.cpp +++ b/src/s_sndseq.cpp @@ -34,8 +34,8 @@ // MACROS ------------------------------------------------------------------ #define GetCommand(a) ((a) & 255) -#define GetData(a) (SDWORD(a) >> 8 ) -#define GetFloatData(a) float((SDWORD(a) >> 8 )/65536.f) +#define GetData(a) (int32_t(a) >> 8 ) +#define GetFloatData(a) float((int32_t(a) >> 8 )/65536.f) #define MakeCommand(a,b) ((a) | ((b) << 8)) #define HexenPlatSeq(a) (a) #define HexenDoorSeq(a) ((a) | 0x40) @@ -1390,7 +1390,7 @@ void SN_StopAllSequences (void) // //========================================================================== -ptrdiff_t SN_GetSequenceOffset (int sequence, SDWORD *sequencePtr) +ptrdiff_t SN_GetSequenceOffset (int sequence, int32_t *sequencePtr) { return sequencePtr - Sequences[sequence]->Script; } diff --git a/src/s_sndseq.h b/src/s_sndseq.h index a35fab026..e77df2271 100644 --- a/src/s_sndseq.h +++ b/src/s_sndseq.h @@ -44,7 +44,7 @@ protected: DSeqNode (); DSeqNode (int sequence, int modenum); - SDWORD *m_SequencePtr; + int32_t *m_SequencePtr; int m_Sequence; FSoundID m_CurrentSoundID; @@ -74,7 +74,7 @@ struct FSoundSequence FName SeqName; FName Slot; FSoundID StopSound; - SDWORD Script[1]; // + more until end of sequence script + int32_t Script[1]; // + more until end of sequence script }; void S_ParseSndSeq (int levellump); @@ -93,7 +93,7 @@ void SN_StopSequence (FPolyObj *poly); bool SN_AreModesSame(int sequence, seqtype_t type, int mode1, int mode2); bool SN_AreModesSame(FName name, int mode1, int mode2); void SN_UpdateActiveSequences (void); -ptrdiff_t SN_GetSequenceOffset (int sequence, SDWORD *sequencePtr); +ptrdiff_t SN_GetSequenceOffset (int sequence, int32_t *sequencePtr); void SN_DoStop (void *); void SN_ChangeNodeData (int nodeNum, int seqOffset, int delayTics, float volume, int currentSoundID); diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 840559127..89fc13365 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -1400,7 +1400,7 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx) FWadLump wlump = Wads.OpenLumpNum(sfx->lumpnum); BYTE *sfxdata = new BYTE[size]; wlump.Read(sfxdata, size); - SDWORD dmxlen = LittleLong(((SDWORD *)sfxdata)[1]); + int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]); std::pair snd; // If the sound is voc, use the custom loader. @@ -1460,7 +1460,7 @@ static void S_LoadSound3D(sfxinfo_t *sfx) FWadLump wlump = Wads.OpenLumpNum(sfx->lumpnum); BYTE *sfxdata = new BYTE[size]; wlump.Read(sfxdata, size); - SDWORD dmxlen = LittleLong(((SDWORD *)sfxdata)[1]); + int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]); std::pair snd; // If the sound is voc, use the custom loader. diff --git a/src/scripting/decorate/olddecorations.cpp b/src/scripting/decorate/olddecorations.cpp index 7370ddb54..e656445fc 100644 --- a/src/scripting/decorate/olddecorations.cpp +++ b/src/scripting/decorate/olddecorations.cpp @@ -483,7 +483,7 @@ static void ParseInsideDecoration (Baggage &bag, AActor *defaults, else if (sc.Compare ("Mass")) { sc.MustGetFloat (); - defaults->Mass = SDWORD(sc.Float); + defaults->Mass = int32_t(sc.Float); } else if (sc.Compare ("Translation1")) { diff --git a/src/textures/backdroptexture.cpp b/src/textures/backdroptexture.cpp index b4b2793dc..0f18fe6d6 100644 --- a/src/textures/backdroptexture.cpp +++ b/src/textures/backdroptexture.cpp @@ -289,7 +289,7 @@ void FBackdropTexture::Render() DWORD a1, a2, a3, a4; - SDWORD c1, c2, c3, c4; + int32_t c1, c2, c3, c4; DWORD tx, ty, tc, ts; DWORD ux, uy, uc, us; DWORD ltx, lty, lux, luy; @@ -302,10 +302,10 @@ void FBackdropTexture::Render() double z1 = (cos(TORAD(z2ang)) / 4 + 0.5) * (0x8000000); double z2 = (cos(TORAD(z1ang)) / 4 + 0.75) * (0x8000000); - tc = SDWORD(cos(TORAD(t1ang)) * z1); - ts = SDWORD(sin(TORAD(t1ang)) * z1); - uc = SDWORD(cos(TORAD(t2ang)) * z2); - us = SDWORD(sin(TORAD(t2ang)) * z2); + tc = int32_t(cos(TORAD(t1ang)) * z1); + ts = int32_t(sin(TORAD(t1ang)) * z1); + uc = int32_t(cos(TORAD(t2ang)) * z2); + us = int32_t(sin(TORAD(t2ang)) * z2); ltx = -width / 2 * tc; lty = -width / 2 * ts; @@ -316,8 +316,8 @@ void FBackdropTexture::Render() { a1 = time1; a2 = time2; - c3 = SDWORD(cos(TORAD(a3)) * 65536.0); - c4 = SDWORD(cos(TORAD(a4)) * 65536.0); + c3 = int32_t(cos(TORAD(a3)) * 65536.0); + c4 = int32_t(cos(TORAD(a4)) * 65536.0); tx = ltx - (y - height / 2)*ts; ty = lty + (y - height / 2)*tc; ux = lux - (y - height / 2)*us; diff --git a/src/textures/ddstexture.cpp b/src/textures/ddstexture.cpp index a2c69b38b..c55cf11bb 100644 --- a/src/textures/ddstexture.cpp +++ b/src/textures/ddstexture.cpp @@ -126,7 +126,7 @@ struct DDSURFACEDESC2 DWORD Width; union { - SDWORD Pitch; + int32_t Pitch; DWORD LinearSize; }; DWORD Depth; @@ -172,7 +172,7 @@ protected: BYTE RShiftL, GShiftL, BShiftL, AShiftL; BYTE RShiftR, GShiftR, BShiftR, AShiftR; - SDWORD Pitch; + int32_t Pitch; DWORD LinearSize; static void CalcBitShift (DWORD mask, BYTE *lshift, BYTE *rshift); diff --git a/src/timidity/instrum_dls.cpp b/src/timidity/instrum_dls.cpp index fefac19e0..c882cd84e 100644 --- a/src/timidity/instrum_dls.cpp +++ b/src/timidity/instrum_dls.cpp @@ -253,7 +253,7 @@ http://www.midi.org/about-midi/dls/dlsspec.shtml #define FAR typedef SWORD SHORT; typedef WORD USHORT; -typedef SDWORD LONG; +typedef int32_t LONG; typedef DWORD ULONG; #define mmioFOURCC MAKE_ID #define DEFINE_GUID(A, B, C, E, F, G, H, I, J, K, L, M) @@ -1075,15 +1075,15 @@ static double to_normalized_percent(int decipercent) } /* convert from 8bit value to fractional offset (15.15) */ -static SDWORD to_offset(int offset) +static int32_t to_offset(int offset) { - return (SDWORD)offset << (7+15); + return (int32_t)offset << (7+15); } /* calculate ramp rate in fractional unit; * diff = 8bit, time = msec */ -static SDWORD calc_rate(Renderer *song, int diff, int sample_rate, double msec) +static int32_t calc_rate(Renderer *song, int diff, int sample_rate, double msec) { double rate; @@ -1093,7 +1093,7 @@ static SDWORD calc_rate(Renderer *song, int diff, int sample_rate, double msec) diff = 255; diff <<= (7+15); rate = ((double)diff / song->rate) * song->control_ratio * 1000.0 / msec; - return (SDWORD)rate; + return (int32_t)rate; } static int load_connection(ULONG cConnections, CONNECTION *artList, USHORT destination) diff --git a/src/timidity/instrum_sf2.cpp b/src/timidity/instrum_sf2.cpp index cae7ae57f..2e9d7d0c0 100644 --- a/src/timidity/instrum_sf2.cpp +++ b/src/timidity/instrum_sf2.cpp @@ -199,12 +199,12 @@ static double timecent_to_sec(SWORD timecent) return pow(2.0, timecent / 1200.0); } -static SDWORD to_offset(int offset) +static int32_t to_offset(int offset) { - return (SDWORD)offset << (7+15); + return (int32_t)offset << (7+15); } -static SDWORD calc_rate(Renderer *song, int diff, double sec) +static int32_t calc_rate(Renderer *song, int diff, double sec) { double rate; @@ -214,7 +214,7 @@ static SDWORD calc_rate(Renderer *song, int diff, double sec) diff = 255; diff <<= (7+15); rate = ((double)diff / song->rate) * song->control_ratio / sec; - return (SDWORD)rate; + return (int32_t)rate; } @@ -1524,7 +1524,7 @@ void SFFile::LoadSample(SFSample *sample) { BYTE samp; *fp >> samp; - sample->InMemoryData[i] = ((((SDWORD(sample->InMemoryData[i] * 32768) << 8) | samp) << 8) >> 8) / 8388608.f; + sample->InMemoryData[i] = ((((int32_t(sample->InMemoryData[i] * 32768) << 8) | samp) << 8) >> 8) / 8388608.f; } } // Final 0 byte is for interpolation. diff --git a/src/timidity/mix.cpp b/src/timidity/mix.cpp index cd1ede89d..037226c2c 100644 --- a/src/timidity/mix.cpp +++ b/src/timidity/mix.cpp @@ -426,7 +426,7 @@ static int update_signal(Voice *v) return 0; } -static void mix_mystery_signal(SDWORD control_ratio, const sample_t *sp, float *lp, Voice *v, int count) +static void mix_mystery_signal(int32_t control_ratio, const sample_t *sp, float *lp, Voice *v, int count) { final_volume_t left = v->left_mix, @@ -477,7 +477,7 @@ static void mix_mystery_signal(SDWORD control_ratio, const sample_t *sp, float * } } -static void mix_single_signal(SDWORD control_ratio, const sample_t *sp, float *lp, Voice *v, float *ampat, int count) +static void mix_single_signal(int32_t control_ratio, const sample_t *sp, float *lp, Voice *v, float *ampat, int count) { final_volume_t amp; int cc; @@ -518,17 +518,17 @@ static void mix_single_signal(SDWORD control_ratio, const sample_t *sp, float *l } } -static void mix_single_left_signal(SDWORD control_ratio, const sample_t *sp, float *lp, Voice *v, int count) +static void mix_single_left_signal(int32_t control_ratio, const sample_t *sp, float *lp, Voice *v, int count) { mix_single_signal(control_ratio, sp, lp, v, &v->left_mix, count); } -static void mix_single_right_signal(SDWORD control_ratio, const sample_t *sp, float *lp, Voice *v, int count) +static void mix_single_right_signal(int32_t control_ratio, const sample_t *sp, float *lp, Voice *v, int count) { mix_single_signal(control_ratio, sp, lp + 1, v, &v->right_mix, count); } -static void mix_mono_signal(SDWORD control_ratio, const sample_t *sp, float *lp, Voice *v, int count) +static void mix_mono_signal(int32_t control_ratio, const sample_t *sp, float *lp, Voice *v, int count) { final_volume_t left = v->left_mix; @@ -568,7 +568,7 @@ static void mix_mono_signal(SDWORD control_ratio, const sample_t *sp, float *lp, } } -static void mix_mystery(SDWORD control_ratio, const sample_t *sp, float *lp, Voice *v, int count) +static void mix_mystery(int32_t control_ratio, const sample_t *sp, float *lp, Voice *v, int count) { final_volume_t left = v->left_mix, diff --git a/src/timidity/timidity.h b/src/timidity/timidity.h index 2ca64a59a..b3a1e2c80 100644 --- a/src/timidity/timidity.h +++ b/src/timidity/timidity.h @@ -211,7 +211,7 @@ enum struct Sample { - SDWORD + int32_t loop_start, loop_end, data_length, sample_rate; float @@ -233,7 +233,7 @@ struct Sample } sf2; } envelope; sample_t *data; - SDWORD + int32_t tremolo_sweep_increment, tremolo_phase_increment, vibrato_sweep_increment, vibrato_control_ratio; BYTE From fd20e1d78ff1d6d048cc903535fe82270c972020 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 3 Mar 2017 20:11:13 +0100 Subject: [PATCH 6/7] - allow hooking custom serializers into PPointer so that serializable types can be handled without having to create new type classes which would be a bit unwieldy thanks to how the type system works. --- src/dobjtype.cpp | 8 ++++ src/dobjtype.h | 13 ++++++ src/scripting/thingdef_data.cpp | 80 +++++++++++++++++++++++++++++++-- 3 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 98a893391..1a582d366 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -1396,6 +1396,10 @@ void PPointer::WriteValue(FSerializer &ar, const char *key,const void *addr) con ar(key, *(DObject **)addr); } } + else if (writer != nullptr) + { + writer(ar, key, addr); + } else { I_Error("Attempt to save pointer to unhandled type %s", PointedType->DescriptiveName()); @@ -1425,6 +1429,10 @@ bool PPointer::ReadValue(FSerializer &ar, const char *key, void *addr) const } return res; } + else if (reader != nullptr) + { + return reader(ar, key, addr); + } return false; } diff --git a/src/dobjtype.h b/src/dobjtype.h index f589b4e48..1a30b42ed 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -362,13 +362,26 @@ public: class PPointer : public PBasicType { DECLARE_CLASS(PPointer, PBasicType); + public: + typedef void(*WriteHandler)(FSerializer &ar, const char *key, const void *addr); + typedef bool(*ReadHandler)(FSerializer &ar, const char *key, void *addr); + PPointer(); PPointer(PType *pointsat, bool isconst = false); PType *PointedType; bool IsConst; + WriteHandler writer = nullptr; + ReadHandler reader = nullptr; + + void InstallHandlers(WriteHandler w, ReadHandler r) + { + writer = w; + reader = r; + } + virtual bool IsMatch(intptr_t id1, intptr_t id2) const; virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const; void SetPointer(void *base, unsigned offset, TArray *special = NULL) const override; diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 4b65e6413..c50b7f65b 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -59,6 +59,7 @@ #include "menu/menu.h" #include "teaminfo.h" #include "r_data/sprites.h" +#include "serializer.h" static TArray properties; static TArray AFTable; @@ -741,7 +742,7 @@ static int fieldcmp(const void * a, const void * b) void InitThingdef() { // Create all global variables here because this cannot be done on the script side and really isn't worth adding support for. - // Also create all special fields here that cannot be declared by script syntax. + // Also create all special fields here that cannot be declared by script syntax plus the pointer serializers. Doing all these with class overrides would be a bit messy. auto secplanestruct = NewNativeStruct("Secplane", nullptr); secplanestruct->Size = sizeof(secplane_t); @@ -750,18 +751,62 @@ void InitThingdef() auto sectorstruct = NewNativeStruct("Sector", nullptr); sectorstruct->Size = sizeof(sector_t); sectorstruct->Align = alignof(sector_t); + NewPointer(sectorstruct, false)->InstallHandlers( + [](FSerializer &ar, const char *key, const void *addr) + { + ar(key, *(sector_t **)addr); + }, + [](FSerializer &ar, const char *key, void *addr) + { + Serialize(ar, key, *(sector_t **)addr, nullptr); + return true; + } + ); auto linestruct = NewNativeStruct("Line", nullptr); linestruct->Size = sizeof(line_t); linestruct->Align = alignof(line_t); + NewPointer(linestruct, false)->InstallHandlers( + [](FSerializer &ar, const char *key, const void *addr) + { + ar(key, *(line_t **)addr); + }, + [](FSerializer &ar, const char *key, void *addr) + { + Serialize(ar, key, *(line_t **)addr, nullptr); + return true; + } + ); auto sidestruct = NewNativeStruct("Side", nullptr); sidestruct->Size = sizeof(side_t); sidestruct->Align = alignof(side_t); + NewPointer(sidestruct, false)->InstallHandlers( + [](FSerializer &ar, const char *key, const void *addr) + { + ar(key, *(side_t **)addr); + }, + [](FSerializer &ar, const char *key, void *addr) + { + Serialize(ar, key, *(side_t **)addr, nullptr); + return true; + } + ); auto vertstruct = NewNativeStruct("Vertex", nullptr); vertstruct->Size = sizeof(vertex_t); vertstruct->Align = alignof(vertex_t); + NewPointer(vertstruct, false)->InstallHandlers( + [](FSerializer &ar, const char *key, const void *addr) + { + ar(key, *(vertex_t **)addr); + }, + [](FSerializer &ar, const char *key, void *addr) + { + Serialize(ar, key, *(vertex_t **)addr, nullptr); + return true; + } + ); auto sectorportalstruct = NewNativeStruct("SectorPortal", nullptr); sectorportalstruct->Size = sizeof(FSectorPortal); @@ -779,6 +824,36 @@ void InitThingdef() teamstruct->Size = sizeof(FTeam); teamstruct->Align = alignof(FTeam); + PStruct *pstruct = NewNativeStruct("PlayerInfo", nullptr); + pstruct->Size = sizeof(player_t); + pstruct->Align = alignof(player_t); + NewPointer(pstruct, false)->InstallHandlers( + [](FSerializer &ar, const char *key, const void *addr) + { + ar(key, *(player_t **)addr); + }, + [](FSerializer &ar, const char *key, void *addr) + { + Serialize(ar, key, *(player_t **)addr, nullptr); + return true; + } + ); + + auto fontstruct = NewNativeStruct("FFont", nullptr); + fontstruct->Size = sizeof(FFont); + fontstruct->Align = alignof(FFont); + NewPointer(fontstruct, false)->InstallHandlers( + [](FSerializer &ar, const char *key, const void *addr) + { + ar(key, *(FFont **)addr); + }, + [](FSerializer &ar, const char *key, void *addr) + { + Serialize(ar, key, *(FFont **)addr, nullptr); + return true; + } + ); + // set up the lines array in the sector struct. This is a bit messy because the type system is not prepared to handle a pointer to an array of pointers to a native struct even remotely well... // As a result, the size has to be set to something large and arbritrary because it can change between maps. This will need some serious improvement when things get cleaned up. sectorstruct->AddNativeField("lines", NewPointer(NewResizableArray(NewPointer(linestruct, false)), false), myoffsetof(sector_t, Lines), VARF_Native); @@ -843,9 +918,6 @@ void InitThingdef() Namespaces.GlobalNamespace->Symbols.AddSymbol(gi); // set up a variable for the global players array. - PStruct *pstruct = NewNativeStruct("PlayerInfo", nullptr); - pstruct->Size = sizeof(player_t); - pstruct->Align = alignof(player_t); PArray *parray = NewArray(pstruct, MAXPLAYERS); PField *fieldptr = new PField("players", parray, VARF_Native | VARF_Static, (intptr_t)&players); Namespaces.GlobalNamespace->Symbols.AddSymbol(fieldptr); From 4b63092c7a20a42e361a90b57f66d5643c8998e6 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Fri, 3 Mar 2017 12:48:56 -0500 Subject: [PATCH 7/7] - disable size checking in windowed mode for vid_setmode, allowing it to set arbitrary sizes. --- src/v_video.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/v_video.cpp b/src/v_video.cpp index aca00cfb3..d993204a2 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -72,6 +72,7 @@ FRenderer *Renderer; IMPLEMENT_CLASS(DCanvas, true, false) IMPLEMENT_CLASS(DFrameBuffer, true, false) +EXTERN_CVAR (Bool, fullscreen) #if defined(_DEBUG) && defined(_M_IX86) && !defined(__MINGW32__) #define DBGBREAK { __asm int 3 } @@ -1489,6 +1490,9 @@ CCMD (vid_setmode) goodmode = true; } + if (!fullscreen) + goodmode = true; + if (goodmode) { // The actual change of resolution will take place