diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dc8034a43..94f7c9ab3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1220,7 +1220,6 @@ set (PCH_SOURCES thingdef/thingdef_properties.cpp thingdef/thingdef_states.cpp xlat/parse_xlat.cpp - fragglescript/t_fspic.cpp fragglescript/t_func.cpp fragglescript/t_load.cpp fragglescript/t_oper.cpp diff --git a/src/fragglescript/t_fspic.cpp b/src/fragglescript/t_fspic.cpp deleted file mode 100644 index 0e7c80346..000000000 --- a/src/fragglescript/t_fspic.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* -** t_fspic.cpp -** Fragglescript HUD pics (incomplete and untested!) -** -**--------------------------------------------------------------------------- -** Copyright 2005 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. -**--------------------------------------------------------------------------- -** -*/ - -#include "t_script.h" -#include "doomtype.h" -#include "p_local.h" -#include "farchive.h" -#include "sbar.h" -#include "v_video.h" - - - -struct FHudPic -{ - FTextureID texturenum; - int xpos; - int ypos; - bool draw; - - void Serialize(FArchive & arc) - { - arc << xpos << ypos << draw << texturenum; - } - -}; - -//====================================================================== -// -//====================================================================== -class DHUDPicManager : public DHUDMessage -{ - // This is no real hudmessage but this way I don't need any external code to handle this - // because the hudmessage and thinker code handles everything automatically - DECLARE_CLASS(DHUDPicManager, DHUDMessage) - float basetrans; - -public: - - TArray piclist; - - DHUDPicManager(); - ~DHUDPicManager() {} - void Serialize(FArchive & ar); - virtual void DoDraw (int linenum, int x, int y, int hudheight, float translucent); - void DoDraw (int, int, int, bool, int) { assert(false); } -} ; - -IMPLEMENT_CLASS(DHUDPicManager) - -//====================================================================== -// -//====================================================================== -DHUDPicManager::DHUDPicManager() -{ - HUDWidth=HUDHeight=0; - basetrans=0.8f; - //SetID(0xffffffff); - NumLines=1; - HoldTics=0; // stay forever! - //logtoconsole=false; -} - - -//====================================================================== -// -//====================================================================== -void DHUDPicManager::Serialize(FArchive & ar) -{ - Super::Serialize(ar); - - short count=piclist.Size(); - ar << count << basetrans; - if (ar.IsLoading()) piclist.Resize(count); - for(int i=0;iDrawTexture(tex, piclist[i].xpos, piclist[i].ypos, DTA_320x200, true, - DTA_AlphaF, translucent*basetrans, TAG_DONE); - } -} - - -//====================================================================== -// -//====================================================================== -static TArray & GetPicList() -{ - //TThinkerIterator it; - DHUDPicManager * pm=NULL;//it.Next(); - - if (!pm) pm=new DHUDPicManager; - return pm->piclist; -} - -//====================================================================== -// -// External interface -// -//====================================================================== - -//====================================================================== -// -//====================================================================== -int HU_GetFSPic(FTextureID texturenum, int xpos, int ypos) -{ - TArray &piclist=GetPicList(); - unsigned int i; - - for(i=0;i &piclist=GetPicList(); - - if(handle >= piclist.Size()) return -1; - piclist[handle].texturenum.SetInvalid(); - return 0; -} - - -//====================================================================== -// -//====================================================================== -int HU_ModifyFSPic(unsigned handle, FTextureID texturenum, int xpos, int ypos) -{ - TArray &piclist=GetPicList(); - - if(handle >= piclist.Size()) return -1; - if(!piclist[handle].texturenum.isValid()) return -1; - - piclist[handle].texturenum = texturenum; - piclist[handle].xpos = xpos; - piclist[handle].ypos = ypos; - return 0; -} - -//====================================================================== -// -//====================================================================== -int HU_FSDisplay(unsigned handle, bool newval) -{ - TArray &piclist=GetPicList(); - - if(handle >= piclist.Size()) return -1; - if(!piclist[handle].texturenum.isValid()) return -1; - - piclist[handle].draw = newval; - return 0; -} - diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index deb4907a3..6c7196f62 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -3647,58 +3647,24 @@ void FParser::SF_Pow() //========================================================================== -int HU_GetFSPic(FTextureID lumpnum, int xpos, int ypos); -int HU_DeleteFSPic(unsigned int handle); -int HU_ModifyFSPic(unsigned int handle, FTextureID lumpnum, int xpos, int ypos); -int HU_FSDisplay(unsigned int handle, bool newval); - void FParser::SF_NewHUPic() { - if (CheckArgs(3)) - { - t_return.type = svt_int; - t_return.value.i = HU_GetFSPic( - TexMan.GetTexture(stringvalue(t_argv[0]), FTexture::TEX_MiscPatch, FTextureManager::TEXMAN_TryAny), - intvalue(t_argv[1]), intvalue(t_argv[2])); - } + // disabled because it was never used and never tested } void FParser::SF_DeleteHUPic() { - if (CheckArgs(1)) - { - if (HU_DeleteFSPic(intvalue(t_argv[0])) == -1) - script_error("deletehupic: Invalid sfpic handle: %i\n", intvalue(t_argv[0])); - } + // disabled because it was never used and never tested } void FParser::SF_ModifyHUPic() { - if (t_argc != 4) - { - script_error("modifyhupic: invalid number of arguments\n"); - return; - } - - if (HU_ModifyFSPic(intvalue(t_argv[0]), - TexMan.GetTexture(stringvalue(t_argv[0]), FTexture::TEX_MiscPatch, FTextureManager::TEXMAN_TryAny), - intvalue(t_argv[2]), intvalue(t_argv[3])) == -1) - { - script_error("modifyhypic: invalid sfpic handle %i\n", intvalue(t_argv[0])); - } - return; + // disabled because it was never used and never tested } void FParser::SF_SetHUPicDisplay() { - if (t_argc != 2) - { - script_error("sethupicdisplay: invalud number of arguments\n"); - return; - } - - if (HU_FSDisplay(intvalue(t_argv[0]), intvalue(t_argv[1]) > 0 ? 1 : 0) == -1) - script_error("sethupicdisplay: invalid pic handle %i\n", intvalue(t_argv[0])); + // disabled because it was never used and never tested } diff --git a/src/serializer.h b/src/serializer.h new file mode 100644 index 000000000..f56f9c87a --- /dev/null +++ b/src/serializer.h @@ -0,0 +1,209 @@ +#ifndef __SERIALIZER_H +#define __SERIALIZER_H + +#include +#include "tarray.h" +#include "r_defs.h" + +struct FWriter; +struct FReader; + +extern TArray loadsectors; +extern TArray loadlines; +extern TArray loadsides; +extern char nulspace[]; + + + +class FSerializer +{ + +public: + FWriter *w = nullptr; + FReader *r = nullptr; + + int ArraySize(); + +public: + + bool OpenWriter(); + bool OpenReader(const char *buffer, size_t length); + void Close(); + void WriteKey(const char *key); + bool BeginObject(const char *name); + void EndObject(); + bool BeginArray(const char *name); + void EndArray(); + void WriteObjects(); + const char *GetOutput(unsigned *len = nullptr); + FSerializer &Args(const char *key, int *args, int *defargs, int special); + FSerializer &Terrain(const char *key, int &terrain, int *def = nullptr); + FSerializer &Sprite(const char *key, uint16_t &spritenum, uint16_t *def); + FSerializer &StringPtr(const char *key, const char *&charptr); // This only retrieves the address but creates no permanent copy of the string. + bool isReading() const + { + return r != nullptr; + } + + bool isWriting() const + { + return w != nullptr; + } + + bool canSkip() const; + + template + FSerializer &operator()(const char *key, T &obj) + { + return Serialize(*this, key, obj, (T*)nullptr); + } + + template + FSerializer &operator()(const char *key, T &obj, T &def) + { + return Serialize(*this, key, obj, &def); + } + + template + FSerializer &Array(const char *key, T *obj, int count, bool fullcompare = false) + { + if (fullcompare && isWriting() && !memcmp(obj, nulspace, count * sizeof(T))) + { + return *this; + } + + if (BeginArray(key)) + { + for (int i = 0; i < count; i++) + { + Serialize(*this, nullptr, obj[i], (T*)nullptr); + } + EndArray(); + } + return *this; + } + + template + FSerializer &Array(const char *key, T *obj, T *def, int count, bool fullcompare = false) + { + if (fullcompare && isWriting() && def != nullptr && !memcmp(obj, def, count * sizeof(T))) + { + return *this; + } + if (BeginArray(key)) + { + for (int i = 0; i < count; i++) + { + Serialize(*this, nullptr, obj[i], def ? &def[i] : nullptr); + } + EndArray(); + } + return *this; + } +}; + +FSerializer &Serialize(FSerializer &arc, const char *key, bool &value, bool *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, int64_t &value, int64_t *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, uint64_t &value, uint64_t *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, int32_t &value, int32_t *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, uint32_t &value, uint32_t *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, int8_t &value, int8_t *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, uint8_t &value, uint8_t *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, int16_t &value, int16_t *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, uint16_t &value, uint16_t *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, double &value, double *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, float &value, float *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, side_t *&value, side_t **defval); +FSerializer &Serialize(FSerializer &arc, const char *key, sector_t *&value, sector_t **defval); +FSerializer &Serialize(FSerializer &arc, const char *key, player_t *&value, player_t **defval); +FSerializer &Serialize(FSerializer &arc, const char *key, line_t *&value, line_t **defval); +FSerializer &Serialize(FSerializer &arc, const char *key, FTextureID &value, FTextureID *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, DObject *&value, DObject ** /*defval*/); +FSerializer &Serialize(FSerializer &arc, const char *key, FName &value, FName *defval); +FSerializer &Serialize(FSerializer &arc, const char *key, FDynamicColormap *&cm, FDynamicColormap **def); +FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundID *def); +FSerializer &Serialize(FSerializer &arc, const char *key, PClassActor *&clst, PClassActor **def); +FSerializer &Serialize(FSerializer &arc, const char *key, FState *&state, FState **def); +FSerializer &Serialize(FSerializer &arc, const char *key, FStrifeDialogueNode *&node, FStrifeDialogueNode **def); +FSerializer &Serialize(FSerializer &arc, const char *key, FString *&pstr, FString **def); + + +template +FSerializer &Serialize(FSerializer &arc, const char *key, T *&value, T **) +{ + DObject *v = static_cast(value); + Serialize(arc, key, v, nullptr); + value = static_cast(v); + return arc; +} + +template +FSerializer &Serialize(FSerializer &arc, const char *key, TObjPtr &value, TObjPtr *) +{ + Serialize(arc, key, value.o, nullptr); + return arc; +} + +template +FSerializer &Serialize(FSerializer &arc, const char *key, TArray &value, TArray *) +{ + if (arc.isWriting()) + { + if (value.Size() == 0) return arc; // do not save empty arrays + } + bool res = arc.BeginArray(key); + if (arc.isReading()) + { + if (!res) + { + value.Clear(); + return arc; + } + value.Resize(arc.ArraySize()); + } + for (unsigned i = 0; i < value.Size(); i++) + { + Serialize(arc, nullptr, value[i], (T*)nullptr); + } + arc.EndArray(); + return arc; +} + +inline FSerializer &Serialize(FSerializer &arc, const char *key, DVector3 &p, DVector3 *def) +{ + return arc.Array(key, &p[0], def? &(*def)[0] : nullptr, 3, true); +} + +inline FSerializer &Serialize(FSerializer &arc, const char *key, DRotator &p, DRotator *def) +{ + return arc.Array(key, &p[0], def? &(*def)[0] : nullptr, 3, true); +} + +inline FSerializer &Serialize(FSerializer &arc, const char *key, DVector2 &p, DVector2 *def) +{ + return arc.Array(key, &p[0], def? &(*def)[0] : nullptr, 2, true); +} + +inline FSerializer &Serialize(FSerializer &arc, const char *key, DAngle &p, DAngle *def) +{ + return Serialize(arc, key, p.Degrees, def? &def->Degrees : nullptr); +} + +inline FSerializer &Serialize(FSerializer &arc, const char *key, PalEntry &pe, PalEntry *def) +{ + return Serialize(arc, key, pe.d, def? &def->d : nullptr); +} + +inline FSerializer &Serialize(FSerializer &arc, const char *key, FRenderStyle &style, FRenderStyle *def) +{ + return Serialize(arc, key, style.AsDWORD, def ? &def->AsDWORD : nullptr); +} + +template +FSerializer &Serialize(FSerializer &arc, const char *key, TFlags &flags, TFlags *def) +{ + return Serialize(arc, key, flags.Value, def? &def->Value : nullptr); +} + + +#endif \ No newline at end of file