diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index d7e77606d..040a7c92b 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -986,6 +986,7 @@ set (PCH_SOURCES core/maphack.cpp core/mapinfo.cpp core/maploader.cpp + core/postprocessor.cpp core/searchpaths.cpp core/screenjob.cpp core/initfs.cpp diff --git a/source/core/postprocessor.cpp b/source/core/postprocessor.cpp new file mode 100644 index 000000000..7a48052e7 --- /dev/null +++ b/source/core/postprocessor.cpp @@ -0,0 +1,103 @@ +/* +** postprocessor.cpp +** Level postprocessing +** +**--------------------------------------------------------------------------- +** Copyright 2009 Randy Heit +** Copyright 2009-2018 Christoph Oelckers +** Copyright 2019 Alexey Lysiuk +** 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. +**--------------------------------------------------------------------------- +** +*/ +#include "dobject.h" +#include "vm.h" +#include "printf.h" +#include "types.h" + +//========================================================================== +// +// PostProcessLevel +// +//========================================================================== + +class DLevelPostProcessor : public DObject +{ + DECLARE_ABSTRACT_CLASS(DLevelPostProcessor, DObject) +public: +}; + +IMPLEMENT_CLASS(DLevelPostProcessor, true, false); + +void PostProcessLevel(FName checksum, const FString& mapname) +{ + auto lc = Create(); + + for(auto cls : PClass::AllClasses) + { + if (cls->IsDescendantOf(RUNTIME_CLASS(DLevelPostProcessor))) + { + PFunction *const func = dyn_cast(cls->FindSymbol("Apply", false)); + if (func == nullptr) + { + Printf("Missing 'Apply' method in class '%s', level compatibility object ignored\n", cls->TypeName.GetChars()); + continue; + } + + auto argTypes = func->Variants[0].Proto->ArgumentTypes; + if (argTypes.Size() != 3 || argTypes[1] != TypeName || argTypes[2] != TypeString) + { + Printf("Wrong signature of 'Apply' method in class '%s', level compatibility object ignored\n", cls->TypeName.GetChars()); + continue; + } + + VMValue param[] = { lc, checksum.GetIndex(), &mapname }; + VMCall(func->Variants[0].Implementation, param, 3, nullptr, 0); + } + } +} + +DEFINE_ACTION_FUNCTION(DLevelPostProcessor, SetSpriteLotag) +{ + PARAM_SELF_PROLOGUE(DLevelPostProcessor); + PARAM_INT(sprite); + PARAM_INT(lotag); + + // todo + return 0; +} + +DEFINE_ACTION_FUNCTION(DLevelPostProcessor, ChangeSpriteFlags) +{ + PARAM_SELF_PROLOGUE(DLevelPostProcessor); + PARAM_INT(sprite); + PARAM_INT(clearmask); + PARAM_INT(setflag); + + // todo + return 0; +} + diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index 9350ba327..29c05f07a 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -35,6 +35,8 @@ version "4.9" #include "zscript/usermapmenu.zs" #include "zscript/maptypes.zs" #include "zscript/coreactor.zs" +#include "zscript/level_postprocessor.zs" +#include "zscript/level_compatibility.zs" #include "zscript/alt_hud.zs" #include "zscript/games/duke/dukeactor.zs" #include "zscript/games/blood/bloodactor.zs" diff --git a/wadsrc/static/zscript/level_compatibility.zs b/wadsrc/static/zscript/level_compatibility.zs new file mode 100644 index 000000000..52192b199 --- /dev/null +++ b/wadsrc/static/zscript/level_compatibility.zs @@ -0,0 +1,12 @@ + +class LevelCompatibility : LevelPostProcessor +{ + protected void Apply(Name checksum, String mapname) + { + switch (checksum) + { + case 'none': + return; + } + } +} diff --git a/wadsrc/static/zscript/level_postprocessor.zs b/wadsrc/static/zscript/level_postprocessor.zs new file mode 100644 index 000000000..9af905a9d --- /dev/null +++ b/wadsrc/static/zscript/level_postprocessor.zs @@ -0,0 +1,10 @@ + +class LevelPostProcessor native play +{ + protected void Apply(Name checksum, String mapname) + { + } + + protected native void SetSpriteLotag(int sprite, int tag); + protected native void ChangeSpriteFlags(int sprite, int set, int clear); +}