diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 52af19b7b..d2723f810 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -773,6 +773,7 @@ set (PCH_SOURCES core/movie/playmve.cpp core/automap.cpp + core/binaryangle.cpp core/cheats.cpp core/cheathandler.cpp core/mathutil.cpp diff --git a/source/core/binaryangle.cpp b/source/core/binaryangle.cpp new file mode 100644 index 000000000..e50abcbec --- /dev/null +++ b/source/core/binaryangle.cpp @@ -0,0 +1,64 @@ +/* +** binaryangle.cpp +** +** type safe representations of high precision angle and horizon values. +** Angle uses natural 32 bit overflow to clamp to one rotation. +** +**--------------------------------------------------------------------------- +** Copyright 2020 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 "binaryangle.h" + +FSerializer &Serialize(FSerializer &arc, const char *key, binangle &obj, binangle *defval) +{ + if (arc.BeginObject(key)) + { + arc("value", obj.value).EndObject(); + } + return arc; +} + +FSerializer &Serialize(FSerializer &arc, const char *key, lookangle &obj, lookangle *defval) +{ + if (arc.BeginObject(key)) + { + arc("value", obj.value).EndObject(); + } + return arc; +} + +FSerializer &Serialize(FSerializer &arc, const char *key, fixedhoriz &obj, fixedhoriz *defval) +{ + if (arc.BeginObject(key)) + { + arc("value", obj.value).EndObject(); + } + return arc; +} diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index 811c5acd1..f7ed7c566 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -39,8 +39,11 @@ #include #include "m_fixed.h" #include "xs_Float.h" // needed for reliably overflowing float->int conversions. +#include "serializer.h" #include "build.h" +class FSerializer; + enum { BAMUNIT = 1 << 21 @@ -57,6 +60,8 @@ class binangle friend constexpr binangle buildang(uint32_t v); friend binangle radang(double v); friend binangle degang(double v); + + friend FSerializer &Serialize(FSerializer &arc, const char *key, binangle &obj, binangle *defval); public: binangle() = default; @@ -119,6 +124,8 @@ class lookangle friend constexpr lookangle buildlook(int32_t v); friend lookangle radlook(double v); friend lookangle deglook(double v); + + friend FSerializer &Serialize(FSerializer &arc, const char *key, lookangle &obj, lookangle *defval); public: lookangle() = default; @@ -201,6 +208,8 @@ class fixedhoriz friend constexpr fixedhoriz buildhoriz(int v); friend fixedhoriz pitchhoriz(double v); friend fixedhoriz bamhoriz(int32_t v); + + friend FSerializer &Serialize(FSerializer &arc, const char *key, fixedhoriz &obj, fixedhoriz *defval); public: fixedhoriz() = default; diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 1d11c04f6..998fb26a5 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -113,12 +113,12 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, arc("posx", w.posx) ("posy", w.posy) ("posz", w.posz) - //("q16ang", w.angle.ang.asq16()) - //("q16horiz", w.horizon.horiz.asq16()) - //("q16horizoff", w.horizon.horizoff.asq16()) - //("q16rotscrnang", w.angle.rotscrnang.asbuild()) - //("q16look_ang", w.angle.look_ang.asq16()) - //("one_eighty_count", w.angle.spin.asq16()) + ("ang", w.angle.ang) + ("look_ang", w.angle.look_ang) + ("rotscrnang", w.angle.rotscrnang) + ("horiz", w.horizon.horiz) + ("horizoff", w.horizon.horizoff) + ("spin", w.angle.spin) ("gotweapon", w.gotweapon) ("palette", w.palette) ("pals", w.pals) @@ -284,10 +284,11 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, .EndObject(); w.invdisptime = 0; - //w.angle.oang = w.angle.ang; - //w.horizon.ohoriz = w.horizon.horiz; - //w.horizon.ohorizoff = w.horizon.horizoff; - //w.oq16rotscrnang = w.angle.rotscrnang; + w.angle.oang = w.angle.ang; + w.angle.olook_ang = w.angle.look_ang; + w.angle.orotscrnang = w.angle.rotscrnang; + w.horizon.ohoriz = w.horizon.horiz; + w.horizon.ohorizoff = w.horizon.horizoff; w.oposx = w.posx; w.oposy = w.posy; w.oposz = w.posz;