From 75cd00a3404679076be9b732ccbf01f88b89681e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 14 Jun 2020 17:22:56 +0200 Subject: [PATCH] - fixed some issues with setup parts for ZScript in the wrong place. This never showed on GZDoom as an error but on Raze which has no actor classes it caused incompletely set up class descriptors. --- src/common/audio/sound/s_reverbedit.cpp | 3 +- src/common/objects/dobjtype.cpp | 28 +++++ src/common/objects/dobjtype.h | 1 + src/common/scripting/frontend/zcc_compile.cpp | 13 ++ src/common/scripting/frontend/zcc_compile.h | 1 + src/common/scripting/interface/vmnatives.cpp | 23 ++++ src/common/scripting/vm/vmexec.h | 4 + src/d_gui.h | 115 ------------------ src/g_game.cpp | 1 - src/gamedata/info.cpp | 26 +--- src/scripting/vmthunks.cpp | 22 ---- src/scripting/zscript/zcc_compile_doom.cpp | 2 +- src/scripting/zscript/zcc_compile_doom.h | 2 +- 13 files changed, 74 insertions(+), 167 deletions(-) delete mode 100644 src/d_gui.h diff --git a/src/common/audio/sound/s_reverbedit.cpp b/src/common/audio/sound/s_reverbedit.cpp index 54e0a3431..25993a400 100644 --- a/src/common/audio/sound/s_reverbedit.cpp +++ b/src/common/audio/sound/s_reverbedit.cpp @@ -39,9 +39,8 @@ #include "templates.h" #include "filesystem.h" #include "i_system.h" -#include "m_misc.h" #include "printf.h" - +#include "i_specialpaths.h" #include "c_cvars.h" #include "c_dispatch.h" #include "vm.h" diff --git a/src/common/objects/dobjtype.cpp b/src/common/objects/dobjtype.cpp index 83653c20e..cf6d32d04 100644 --- a/src/common/objects/dobjtype.cpp +++ b/src/common/objects/dobjtype.cpp @@ -922,3 +922,31 @@ unsigned GetVirtualIndex(PClass *cls, const char *funcname) return VIndex; } + +void PClass::InitializeDefaults() +{ + if (VMType != nullptr) // purely internal classes have no symbol table + { + if (bRuntimeClass) + { + // Copy parent values from the parent defaults. + assert(ParentClass != nullptr); + if (Defaults != nullptr) ParentClass->InitializeSpecials(Defaults, ParentClass->Defaults, &PClass::SpecialInits); + for (const PField* field : Fields) + { + if (!(field->Flags & VARF_Native) && !(field->Flags & VARF_Meta)) + { + field->Type->SetDefaultValue(Defaults, unsigned(field->Offset), &SpecialInits); + } + } + } + if (Meta != nullptr) ParentClass->InitializeSpecials(Meta, ParentClass->Meta, &PClass::MetaInits); + for (const PField* field : Fields) + { + if (!(field->Flags & VARF_Native) && (field->Flags & VARF_Meta)) + { + field->Type->SetDefaultValue(Meta, unsigned(field->Offset), &MetaInits); + } + } + } +} \ No newline at end of file diff --git a/src/common/objects/dobjtype.h b/src/common/objects/dobjtype.h index 16adbf72f..07a48454e 100644 --- a/src/common/objects/dobjtype.h +++ b/src/common/objects/dobjtype.h @@ -46,6 +46,7 @@ public: int FindVirtualIndex(FName name, PFunction::Variant *variant, PFunction *parentfunc); PSymbol *FindSymbol(FName symname, bool searchparents) const; PField *AddField(FName name, PType *type, uint32_t flags); + void InitializeDefaults(); static void StaticInit(); static void StaticShutdown(); diff --git a/src/common/scripting/frontend/zcc_compile.cpp b/src/common/scripting/frontend/zcc_compile.cpp index 59870ee9b..5c73fc1cc 100644 --- a/src/common/scripting/frontend/zcc_compile.cpp +++ b/src/common/scripting/frontend/zcc_compile.cpp @@ -650,6 +650,7 @@ int ZCCCompiler::Compile() CreateStructTypes(); CompileAllConstants(); CompileAllFields(); + InitDefaults(); InitFunctions(); return FScriptPosition::ErrorCounter; } @@ -1942,6 +1943,18 @@ void ZCCCompiler::SetImplicitArgs(TArray* args, TArray* argfla } +void ZCCCompiler::InitDefaults() +{ + for (auto c : Classes) + { + if (c->ClassType()->ParentClass) + { + auto ti = c->ClassType(); + ti->InitializeDefaults(); + } + } +} + //========================================================================== // // diff --git a/src/common/scripting/frontend/zcc_compile.h b/src/common/scripting/frontend/zcc_compile.h index 5c90f77dd..ca19d8aff 100644 --- a/src/common/scripting/frontend/zcc_compile.h +++ b/src/common/scripting/frontend/zcc_compile.h @@ -139,6 +139,7 @@ protected: void CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool forclass); void InitFunctions(); + virtual void InitDefaults(); TArray Constants; TArray Structs; diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp index 03348124a..b62e22993 100644 --- a/src/common/scripting/interface/vmnatives.cpp +++ b/src/common/scripting/interface/vmnatives.cpp @@ -46,6 +46,7 @@ #include "vm.h" #include "gstrings.h" #include "printf.h" +#include "s_music.h" //========================================================================== @@ -75,6 +76,20 @@ DEFINE_ACTION_FUNCTION(_TexMan, GetName) ACTION_RETURN_STRING(retval); } +static int CheckForTexture(const FString& name, int type, int flags) +{ + return TexMan.CheckForTexture(name, static_cast(type), flags).GetIndex(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, CheckForTexture, CheckForTexture) +{ + PARAM_PROLOGUE; + PARAM_STRING(name); + PARAM_INT(type); + PARAM_INT(flags); + ACTION_RETURN_INT(CheckForTexture(name, type, flags)); +} + //========================================================================== // // @@ -618,3 +633,11 @@ DEFINE_ACTION_FUNCTION(_Console, Printf) Printf("%s\n", s.GetChars()); return 0; } + +DEFINE_GLOBAL_NAMED(mus_playing, musplaying); +DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, name); +DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, baseorder); +DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, loop); + +DEFINE_GLOBAL_NAMED(PClass::AllClasses, AllClasses) +DEFINE_GLOBAL(Bindings) diff --git a/src/common/scripting/vm/vmexec.h b/src/common/scripting/vm/vmexec.h index d88945a44..154cac29e 100644 --- a/src/common/scripting/vm/vmexec.h +++ b/src/common/scripting/vm/vmexec.h @@ -360,6 +360,10 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret) OP(SS): ASSERTA(a); ASSERTS(B); ASSERTKD(C); GETADDR(PA,KC,X_WRITE_NIL); +#ifdef _DEBUG + // Should never happen, if it does it indicates a compiler side problem. + if (((FString*)ptr)->GetChars() == nullptr) ThrowAbortException(X_OTHER, "Uninitialized string"); +#endif *(FString *)ptr = reg.s[B]; NEXTOP; OP(SS_R): diff --git a/src/d_gui.h b/src/d_gui.h deleted file mode 100644 index 774f928ac..000000000 --- a/src/d_gui.h +++ /dev/null @@ -1,115 +0,0 @@ -/* -** d_gui.h -** -**--------------------------------------------------------------------------- -** Copyright 1998-2006 Randy Heit -** 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. -**--------------------------------------------------------------------------- -** -** So when do I get a real UT-like windowing system? -*/ - -#ifndef __D_GUI_H__ -#define __D_GUI_H__ - -// For a GUIEvent, x and y specify absolute location of mouse pointer -enum EGUIEvent -{ - EV_GUI_None, - EV_GUI_KeyDown, // data1: unshifted ASCII, data2: shifted ASCII, data3: modifiers - EV_GUI_KeyRepeat, // same - EV_GUI_KeyUp, // same - EV_GUI_Char, // data1: translated character (for user text input), data2: alt down? - EV_GUI_FirstMouseEvent, - EV_GUI_MouseMove, - EV_GUI_LButtonDown, - EV_GUI_LButtonUp, - EV_GUI_LButtonDblClick, - EV_GUI_MButtonDown, - EV_GUI_MButtonUp, - EV_GUI_MButtonDblClick, - EV_GUI_RButtonDown, - EV_GUI_RButtonUp, - EV_GUI_RButtonDblClick, - EV_GUI_WheelUp, // data3: shift/ctrl/alt - EV_GUI_WheelDown, // " - EV_GUI_WheelRight, // " - EV_GUI_WheelLeft, // " - EV_GUI_BackButtonDown, - EV_GUI_BackButtonUp, - EV_GUI_FwdButtonDown, - EV_GUI_FwdButtonUp, - EV_GUI_LastMouseEvent, -}; - -enum GUIKeyModifiers -{ - GKM_SHIFT = 1, - GKM_CTRL = 2, - GKM_ALT = 4, - GKM_META = 8, - GKM_LBUTTON = 16 -}; - -// Special codes for some GUI keys, including a few real ASCII codes. -enum ESpecialGUIKeys -{ - GK_PGDN = 1, - GK_PGUP = 2, - GK_HOME = 3, - GK_END = 4, - GK_LEFT = 5, - GK_RIGHT = 6, - GK_ALERT = 7, // ASCII bell - GK_BACKSPACE= 8, // ASCII - GK_TAB = 9, // ASCII - GK_LINEFEED = 10, // ASCII - GK_DOWN = 10, - GK_VTAB = 11, // ASCII - GK_UP = 11, - GK_FORMFEED = 12, // ASCII - GK_RETURN = 13, // ASCII - GK_F1 = 14, - GK_F2 = 15, - GK_F3 = 16, - GK_F4 = 17, - GK_F5 = 18, - GK_F6 = 19, - GK_F7 = 20, - GK_F8 = 21, - GK_F9 = 22, - GK_F10 = 23, - GK_F11 = 24, - GK_F12 = 25, - GK_DEL = 26, - GK_ESCAPE = 27, // ASCII - GK_FREE1 = 28, - GK_FREE2 = 29, - GK_BACK = 30, // browser back key - GK_CESCAPE = 31 // color escape -}; - -#endif //__D_GUI_H__ diff --git a/src/g_game.cpp b/src/g_game.cpp index 7568ec7f8..41f1f5e8b 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -3086,7 +3086,6 @@ DEFINE_GLOBAL(playeringame) DEFINE_GLOBAL(PlayerClasses) DEFINE_GLOBAL_NAMED(Skins, PlayerSkins) DEFINE_GLOBAL(consoleplayer) -DEFINE_GLOBAL_NAMED(PClass::AllClasses, AllClasses) DEFINE_GLOBAL_NAMED(PClassActor::AllActorClasses, AllActorClasses) DEFINE_GLOBAL_NAMED(primaryLevel, Level) DEFINE_GLOBAL(validcount) diff --git a/src/gamedata/info.cpp b/src/gamedata/info.cpp index 0530b7de3..364f34c07 100644 --- a/src/gamedata/info.cpp +++ b/src/gamedata/info.cpp @@ -510,31 +510,7 @@ void PClassActor::InitializeDefaults() else memset(Meta, 0, MetaSize); } } - - if (VMType != nullptr) // purely internal classes have no symbol table - { - if (bRuntimeClass) - { - // Copy parent values from the parent defaults. - assert(ParentClass != nullptr); - if (Defaults != nullptr) ParentClass->InitializeSpecials(Defaults, ParentClass->Defaults, &PClass::SpecialInits); - for (const PField* field : Fields) - { - if (!(field->Flags & VARF_Native) && !(field->Flags & VARF_Meta)) - { - field->Type->SetDefaultValue(Defaults, unsigned(field->Offset), &SpecialInits); - } - } - } - if (Meta != nullptr) ParentClass->InitializeSpecials(Meta, ParentClass->Meta, &PClass::MetaInits); - for (const PField* field : Fields) - { - if (!(field->Flags & VARF_Native) && (field->Flags & VARF_Meta)) - { - field->Type->SetDefaultValue(Meta, unsigned(field->Offset), &MetaInits); - } - } - } + PClass::InitializeDefaults(); } //========================================================================== diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 6b8343f0a..782a7e24f 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -1607,22 +1607,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, ReplaceTextures, ReplaceTextures) return 0; } -static int CheckForTexture(const FString& name, int type, int flags) -{ - return TexMan.CheckForTexture(name, static_cast(type), flags).GetIndex(); -} - -DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, CheckForTexture, CheckForTexture) -{ - PARAM_PROLOGUE; - PARAM_STRING(name); - PARAM_INT(type); - PARAM_INT(flags); - ACTION_RETURN_INT(CheckForTexture(name, type, flags)); -} - - - //===================================================================================== // // secplane_t exports @@ -2920,12 +2904,6 @@ DEFINE_FIELD(DHUDFont, mFont); DEFINE_GLOBAL(StatusBar); -DEFINE_GLOBAL(Bindings) DEFINE_GLOBAL(AutomapBindings) -DEFINE_GLOBAL_NAMED(mus_playing, musplaying); -DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, name); -DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, baseorder); -DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, loop); - DEFINE_GLOBAL(generic_ui) diff --git a/src/scripting/zscript/zcc_compile_doom.cpp b/src/scripting/zscript/zcc_compile_doom.cpp index 350253c04..8353d11f9 100644 --- a/src/scripting/zscript/zcc_compile_doom.cpp +++ b/src/scripting/zscript/zcc_compile_doom.cpp @@ -648,7 +648,7 @@ void ZCCDoomCompiler::InitDefaults() if (c->Defaults.Size()) Error(c->cls, "%s: Non-actor classes may not have defaults", c->ClassType()->TypeName.GetChars()); if (c->ClassType()->ParentClass) { - auto ti = static_cast(c->ClassType()); + auto ti = c->ClassType(); ti->InitializeDefaults(); } } diff --git a/src/scripting/zscript/zcc_compile_doom.h b/src/scripting/zscript/zcc_compile_doom.h index 24f1350c9..36d7a4680 100644 --- a/src/scripting/zscript/zcc_compile_doom.h +++ b/src/scripting/zscript/zcc_compile_doom.h @@ -24,7 +24,7 @@ private: void DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt *property, AActor *defaults, Baggage &bag); void ProcessDefaultProperty(PClassActor *cls, ZCC_PropertyStmt *prop, Baggage &bag); void ProcessDefaultFlag(PClassActor *cls, ZCC_FlagStmt *flg); - void InitDefaults(); + void InitDefaults() override final; FxExpression *SetupActionFunction(PClass *cls, ZCC_TreeNode *af, int StateFlags); void CompileStates(); int CheckActionKeyword(ZCC_FuncDeclarator *f, uint32_t &varflags, int useflags, ZCC_StructWork *c);