From f8ac9a2662ea61b6c268d6e0fe8a4feed45234bd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 19:21:41 +0200 Subject: [PATCH] - moved DObject and core parts of the VM to 'common'. # Conflicts: # src/common/objects/dobject.h --- CMakeLists.txt | 17 +- src/CMakeLists.txt | 53 ++-- src/common/audio/sound/s_soundinternal.h | 13 +- src/{ => common/objects}/__autostart.cpp | 0 src/{ => common/objects}/autosegs.h | 0 src/{ => common/objects}/dobject.cpp | 0 src/{ => common/objects}/dobject.h | 4 +- src/{ => common/objects}/dobjgc.cpp | 5 - src/{ => common/objects}/dobjgc.h | 0 src/{ => common/objects}/dobjtype.cpp | 0 src/{ => common/objects}/dobjtype.h | 0 src/{ => common/objects}/zzautozend.cpp | 0 .../scripting/core}/scopebarrier.cpp | 0 .../scripting/core}/scopebarrier.h | 0 .../scripting/core}/symbols.cpp | 0 .../scripting/core}/symbols.h | 0 .../scripting/core}/types.cpp | 0 .../scripting/core}/types.h | 2 +- .../scripting/core}/vmdisasm.cpp | 1 + .../scripting/interface/stringformat.cpp | 278 ++++++++++++++++++ .../vm => common/scripting/jit}/jit.cpp | 1 + .../vm => common/scripting/jit}/jit.h | 0 .../vm => common/scripting/jit}/jit_call.cpp | 0 .../vm => common/scripting/jit}/jit_flow.cpp | 0 .../vm => common/scripting/jit}/jit_load.cpp | 0 .../vm => common/scripting/jit}/jit_math.cpp | 1 + .../vm => common/scripting/jit}/jit_move.cpp | 7 +- .../scripting/jit}/jit_runtime.cpp | 2 +- .../vm => common/scripting/jit}/jit_store.cpp | 0 .../vm => common/scripting/jit}/jitintern.h | 0 src/{ => common}/scripting/vm/vm.h | 4 +- src/{ => common}/scripting/vm/vmexec.cpp | 12 +- src/{ => common}/scripting/vm/vmexec.h | 4 +- src/{ => common}/scripting/vm/vmframe.cpp | 0 src/{ => common}/scripting/vm/vmintern.h | 0 src/{ => common}/scripting/vm/vmops.h | 0 src/common/utility/basics.h | 48 ++- src/d_main.cpp | 6 + src/doomtype.h | 41 --- src/menu/menu.cpp | 2 +- src/p_setup.cpp | 2 +- src/rendering/hwrenderer/scene/hw_clipper.cpp | 1 + src/rendering/hwrenderer/scene/hw_sprites.cpp | 1 + src/scripting/backend/vmbuilder.cpp | 2 +- src/scripting/dictionary.cpp | 2 +- src/scripting/thingdef_data.cpp | 230 --------------- src/serializer.cpp | 4 +- src/sound/s_doomsound.h | 9 - 48 files changed, 403 insertions(+), 349 deletions(-) rename src/{ => common/objects}/__autostart.cpp (100%) rename src/{ => common/objects}/autosegs.h (100%) rename src/{ => common/objects}/dobject.cpp (100%) rename src/{ => common/objects}/dobject.h (99%) rename src/{ => common/objects}/dobjgc.cpp (99%) rename src/{ => common/objects}/dobjgc.h (100%) rename src/{ => common/objects}/dobjtype.cpp (100%) rename src/{ => common/objects}/dobjtype.h (100%) rename src/{ => common/objects}/zzautozend.cpp (100%) rename src/{scripting/backend => common/scripting/core}/scopebarrier.cpp (100%) rename src/{scripting/backend => common/scripting/core}/scopebarrier.h (100%) rename src/{scripting => common/scripting/core}/symbols.cpp (100%) rename src/{scripting => common/scripting/core}/symbols.h (100%) rename src/{scripting => common/scripting/core}/types.cpp (100%) rename src/{scripting => common/scripting/core}/types.h (99%) rename src/{scripting/backend => common/scripting/core}/vmdisasm.cpp (99%) create mode 100644 src/common/scripting/interface/stringformat.cpp rename src/{scripting/vm => common/scripting/jit}/jit.cpp (99%) rename src/{scripting/vm => common/scripting/jit}/jit.h (100%) rename src/{scripting/vm => common/scripting/jit}/jit_call.cpp (100%) rename src/{scripting/vm => common/scripting/jit}/jit_flow.cpp (100%) rename src/{scripting/vm => common/scripting/jit}/jit_load.cpp (100%) rename src/{scripting/vm => common/scripting/jit}/jit_math.cpp (99%) rename src/{scripting/vm => common/scripting/jit}/jit_move.cpp (97%) rename src/{scripting/vm => common/scripting/jit}/jit_runtime.cpp (99%) rename src/{scripting/vm => common/scripting/jit}/jit_store.cpp (100%) rename src/{scripting/vm => common/scripting/jit}/jitintern.h (100%) rename src/{ => common}/scripting/vm/vm.h (99%) rename src/{ => common}/scripting/vm/vmexec.cpp (94%) rename src/{ => common}/scripting/vm/vmexec.h (99%) rename src/{ => common}/scripting/vm/vmframe.cpp (100%) rename src/{ => common}/scripting/vm/vmintern.h (100%) rename src/{ => common}/scripting/vm/vmops.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb7b65764..f1edbca84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,7 +194,6 @@ endif() # find_package( asmjit ) #endif() - if( MSVC ) # Eliminate unreferenced functions and data # Perform identical COMDAT folding @@ -213,20 +212,6 @@ if( MSVC ) #set( ALL_C_FLAGS "${ALL_C_FLAGS} /arch:SSE2") # This is already the default -# if( CMAKE_SIZEOF_VOID_P MATCHES "4") -# # SSE2 option (to allow x87 in 32 bit and disallow extended feature sets which have not yet been checked for precision) -# option (ZDOOM_USE_SSE2 "Use SSE2 instruction set") -# if (ZDOOM_USE_SSE2) -# set( ALL_C_FLAGS "${ALL_C_FLAGS} /arch:SSE2") -# else () -# if (MSVC_VERSION GREATER 1699) -# # On Visual C++ 2012 and later SSE2 is the default, so we need to switch it off explicitly -# set( ALL_C_FLAGS "${ALL_C_FLAGS} /arch:IA32") -# endif () -# endif () -# else() -# set( ALL_C_FLAGS "${ALL_C_FLAGS} /arch:SSE2") -# endif() # Avoid CRT DLL dependancies in release builds, optionally generate assembly output for checking crash locations. option( ZDOOM_GENERATE_ASM "Generate assembly output." OFF ) @@ -330,7 +315,7 @@ if( ZLIB_FOUND AND NOT FORCE_INTERNAL_ZLIB ) message( STATUS "Using system zlib, includes found at ${ZLIB_INCLUDE_DIR}" ) else() message( STATUS "Using internal zlib" ) - set( SKIP_INSTALL_ALL TRUE ) # Avoid installing zlib alongside zdoom + set( SKIP_INSTALL_ALL TRUE ) # Avoid installing zlib add_subdirectory( libraries/zlib ) set( ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libraries/zlib ) set( ZLIB_LIBRARIES z ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 928d0f1dc..77b539ae4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -612,19 +612,23 @@ file( GLOB HEADER_FILES common/utility/*.h common/engine/*.h common/fonts/*.h + common/objects/*.h common/filesystem/*.h common/textures/hires/hqnx/*.h common/textures/hires/hqnx_asm/*.h common/textures/hires/xbr/*.h common/thirdparty/*.h common/thirdparty/rapidjson/*.h - common/thirdparty/math./*h + common/thirdparty/math/*h + common/scripting/core/*h + common/scripting/vm/*h + common/scripting/jit/*h + common/scripting/interface/*.h utility/*.h scripting/*.h scripting/backend/*.h scripting/decorate/*.h scripting/zscript/*.h - scripting/vm/*.h sound/midisources/*.h rendering/*.h rendering/2d/*.h @@ -739,14 +743,14 @@ set( NOT_COMPILED_SOURCE_FILES ) set( VM_JIT_SOURCES - scripting/vm/jit.cpp - scripting/vm/jit_runtime.cpp - scripting/vm/jit_call.cpp - scripting/vm/jit_flow.cpp - scripting/vm/jit_load.cpp - scripting/vm/jit_math.cpp - scripting/vm/jit_move.cpp - scripting/vm/jit_store.cpp + common/scripting/jit/jit.cpp + common/scripting/jit/jit_runtime.cpp + common/scripting/jit/jit_call.cpp + common/scripting/jit/jit_flow.cpp + common/scripting/jit/jit_load.cpp + common/scripting/jit/jit_math.cpp + common/scripting/jit/jit_move.cpp + common/scripting/jit/jit_store.cpp ) # This is disabled for now because I cannot find a way to give the .pch file a different name. @@ -838,9 +842,6 @@ set (PCH_SOURCES d_net.cpp d_netinfo.cpp d_protocol.cpp - dobject.cpp - dobjgc.cpp - dobjtype.cpp doomstat.cpp g_cvars.cpp g_dumpinfo.cpp @@ -1037,25 +1038,19 @@ set (PCH_SOURCES r_data/models/models_ue1.cpp r_data/models/models_obj.cpp scripting/dictionary.cpp - scripting/symbols.cpp scripting/vmiterators.cpp scripting/vmthunks.cpp scripting/vmthunks_actors.cpp - scripting/types.cpp scripting/thingdef.cpp scripting/thingdef_data.cpp scripting/thingdef_properties.cpp scripting/backend/codegen.cpp - scripting/backend/scopebarrier.cpp scripting/backend/dynarrays.cpp scripting/backend/vmbuilder.cpp - scripting/backend/vmdisasm.cpp scripting/decorate/olddecorations.cpp scripting/decorate/thingdef_exp.cpp scripting/decorate/thingdef_parse.cpp scripting/decorate/thingdef_states.cpp - scripting/vm/vmexec.cpp - scripting/vm/vmframe.cpp scripting/zscript/ast.cpp scripting/zscript/zcc_compile.cpp scripting/zscript/zcc_parser.cpp @@ -1152,6 +1147,16 @@ set (PCH_SOURCES common/engine/i_interface.cpp common/engine/renderstyle.cpp common/engine/v_colortables.cpp + common/objects/dobject.cpp + common/objects/dobjgc.cpp + common/objects/dobjtype.cpp + common/scripting/core/symbols.cpp + common/scripting/core/types.cpp + common/scripting/core/scopebarrier.cpp + common/scripting/core/vmdisasm.cpp + common/scripting/vm/vmexec.cpp + common/scripting/vm/vmframe.cpp + common/scripting/interface/stringformat.cpp utility/m_random.cpp utility/nodebuilder/nodebuild.cpp @@ -1181,7 +1186,7 @@ endif() add_executable( zdoom WIN32 MACOSX_BUNDLE ${HEADER_FILES} ${NOT_COMPILED_SOURCE_FILES} - __autostart.cpp + common/objects/__autostart.cpp ${SYSTEM_SOURCES} ${FASTMATH_SOURCES} ${PCH_SOURCES} @@ -1207,7 +1212,7 @@ add_executable( zdoom WIN32 MACOSX_BUNDLE common/thirdparty/math/tan.c common/thirdparty/math/tanh.c common/thirdparty/math/fastsin.cpp - zzautozend.cpp + common/objects/zzautozend.cpp ) set_source_files_properties( ${FASTMATH_SOURCES} PROPERTIES COMPILE_FLAGS ${ZD_FASTMATH_FLAG} ) @@ -1241,6 +1246,10 @@ include_directories( . common/console common/engine common/fonts + common/objects + common/scripting/vm + common/scripting/jit + common/scripting/core g_statusbar console playsim @@ -1258,7 +1267,6 @@ include_directories( . utility utility/nodebuilder scripting - scripting/vm rendering rendering/vulkan/thirdparty ../libraries/gdtoa @@ -1427,7 +1435,6 @@ source_group("Platforms\\Win32 Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURC source_group("Scripting\\Decorate frontend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/decorate/.+") source_group("Scripting\\ZScript frontend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/zscript/.+" FILES ${CMAKE_CURRENT_BINARY_DIR}/zcc-parse.c ${CMAKE_CURRENT_BINARY_DIR}/zcc-parse.h) source_group("Scripting\\Compiler backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/backend/.+") -source_group("Scripting\\VM" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/vm/.+") source_group("Scripting" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/.+") source_group("Common" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/.+") source_group("Common\\Audio" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/audio/.+") diff --git a/src/common/audio/sound/s_soundinternal.h b/src/common/audio/sound/s_soundinternal.h index e77c9db82..5ecb6ee48 100644 --- a/src/common/audio/sound/s_soundinternal.h +++ b/src/common/audio/sound/s_soundinternal.h @@ -91,8 +91,8 @@ enum ROLLOFF_Custom // Lookup volume from SNDCURVE }; -int S_FindSound(const char *logicalname); -int S_FindSoundByResID(int snd_id); +inline int S_FindSoundByResID(int ndx); +inline int S_FindSound(const char* name); // An index into the S_sfx[] array. class FSoundID @@ -429,3 +429,12 @@ struct FReverbField }; +inline int S_FindSoundByResID(int ndx) +{ + return soundEngine->FindSoundByResID(ndx); +} + +inline int S_FindSound(const char* name) +{ + return soundEngine->FindSound(name); +} diff --git a/src/__autostart.cpp b/src/common/objects/__autostart.cpp similarity index 100% rename from src/__autostart.cpp rename to src/common/objects/__autostart.cpp diff --git a/src/autosegs.h b/src/common/objects/autosegs.h similarity index 100% rename from src/autosegs.h rename to src/common/objects/autosegs.h diff --git a/src/dobject.cpp b/src/common/objects/dobject.cpp similarity index 100% rename from src/dobject.cpp rename to src/common/objects/dobject.cpp diff --git a/src/dobject.h b/src/common/objects/dobject.h similarity index 99% rename from src/dobject.h rename to src/common/objects/dobject.h index c3e3ae288..d55a079e5 100644 --- a/src/dobject.h +++ b/src/common/objects/dobject.h @@ -36,9 +36,11 @@ #include #include -#include "doomtype.h" #include "m_alloc.h" #include "vectors.h" +#include "name.h" +#include "palentry.h" +#include "textureid.h" class PClass; class PType; diff --git a/src/dobjgc.cpp b/src/common/objects/dobjgc.cpp similarity index 99% rename from src/dobjgc.cpp rename to src/common/objects/dobjgc.cpp index bed2caa08..96128f2bd 100644 --- a/src/dobjgc.cpp +++ b/src/common/objects/dobjgc.cpp @@ -293,12 +293,7 @@ static void MarkRoot() if (playeringame[i]) players[i].PropagateMark(); } - // Mark sectors. - for (auto Level : AllLevels()) - { - Level->Mark(); - } // NextToThink must not be freed while thinkers are ticking. Mark(NextToThink); // Mark soft roots. diff --git a/src/dobjgc.h b/src/common/objects/dobjgc.h similarity index 100% rename from src/dobjgc.h rename to src/common/objects/dobjgc.h diff --git a/src/dobjtype.cpp b/src/common/objects/dobjtype.cpp similarity index 100% rename from src/dobjtype.cpp rename to src/common/objects/dobjtype.cpp diff --git a/src/dobjtype.h b/src/common/objects/dobjtype.h similarity index 100% rename from src/dobjtype.h rename to src/common/objects/dobjtype.h diff --git a/src/zzautozend.cpp b/src/common/objects/zzautozend.cpp similarity index 100% rename from src/zzautozend.cpp rename to src/common/objects/zzautozend.cpp diff --git a/src/scripting/backend/scopebarrier.cpp b/src/common/scripting/core/scopebarrier.cpp similarity index 100% rename from src/scripting/backend/scopebarrier.cpp rename to src/common/scripting/core/scopebarrier.cpp diff --git a/src/scripting/backend/scopebarrier.h b/src/common/scripting/core/scopebarrier.h similarity index 100% rename from src/scripting/backend/scopebarrier.h rename to src/common/scripting/core/scopebarrier.h diff --git a/src/scripting/symbols.cpp b/src/common/scripting/core/symbols.cpp similarity index 100% rename from src/scripting/symbols.cpp rename to src/common/scripting/core/symbols.cpp diff --git a/src/scripting/symbols.h b/src/common/scripting/core/symbols.h similarity index 100% rename from src/scripting/symbols.h rename to src/common/scripting/core/symbols.h diff --git a/src/scripting/types.cpp b/src/common/scripting/core/types.cpp similarity index 100% rename from src/scripting/types.cpp rename to src/common/scripting/core/types.cpp diff --git a/src/scripting/types.h b/src/common/scripting/core/types.h similarity index 99% rename from src/scripting/types.h rename to src/common/scripting/core/types.h index 7d2f2341c..3d0fcc42c 100644 --- a/src/scripting/types.h +++ b/src/common/scripting/core/types.h @@ -2,7 +2,7 @@ #include "dobject.h" #include "serializer.h" -#include "scripting/backend/scopebarrier.h" +#include "scopebarrier.h" // Variable/parameter/field flags ------------------------------------------- diff --git a/src/scripting/backend/vmdisasm.cpp b/src/common/scripting/core/vmdisasm.cpp similarity index 99% rename from src/scripting/backend/vmdisasm.cpp rename to src/common/scripting/core/vmdisasm.cpp index 0046bd727..b3dbece6e 100644 --- a/src/scripting/backend/vmdisasm.cpp +++ b/src/common/scripting/core/vmdisasm.cpp @@ -35,6 +35,7 @@ #include "c_console.h" #include "templates.h" #include "vmintern.h" +#include "printf.h" #define NOP MODE_AUNUSED | MODE_BUNUSED | MODE_CUNUSED diff --git a/src/common/scripting/interface/stringformat.cpp b/src/common/scripting/interface/stringformat.cpp new file mode 100644 index 000000000..589698ee2 --- /dev/null +++ b/src/common/scripting/interface/stringformat.cpp @@ -0,0 +1,278 @@ +/* +** thingdef_data.cpp +** +** DECORATE data tables +** +**--------------------------------------------------------------------------- +** Copyright 2002-2008 Christoph Oelckers +** Copyright 2004-2008 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. +** 4. When not used as part of ZDoom or a ZDoom derivative, this code will be +** covered by the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or (at +** your option) any later version. +** +** 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 "zstring.h" +#include "vm.h" +#include "gstrings.h" +#include "v_font.h" +#include "types.h" + + + +FString FStringFormat(VM_ARGS, int offset) +{ + PARAM_VA_POINTER(va_reginfo) // Get the hidden type information array + assert(va_reginfo[offset] == REGT_STRING); + + FString fmtstring = param[offset].s().GetChars(); + + param += offset; + numparam -= offset; + va_reginfo += offset; + + // note: we don't need a real printf format parser. + // enough to simply find the subtitution tokens and feed them to the real printf after checking types. + // https://en.wikipedia.org/wiki/Printf_format_string#Format_placeholder_specification + FString output; + bool in_fmt = false; + FString fmt_current; + int argnum = 1; + int argauto = 1; + // % = starts + // [0-9], -, +, \s, 0, #, . continue + // %, s, d, i, u, fF, eE, gG, xX, o, c, p, aA terminate + // various type flags are not supported. not like stuff like 'hh' modifier is to be used in the VM. + // the only combination that is parsed locally is %n$... + bool haveargnums = false; + for (size_t i = 0; i < fmtstring.Len(); i++) + { + char c = fmtstring[i]; + if (in_fmt) + { + if (c == '*' && (fmt_current.Len() == 1 || (fmt_current.Len() == 2 && fmt_current[1] == '0'))) + { + fmt_current += c; + } + else if ((c >= '0' && c <= '9') || + c == '-' || c == '+' || (c == ' ' && fmt_current.Back() != ' ') || c == '#' || c == '.') + { + fmt_current += c; + } + else if (c == '$') // %number$format + { + if (!haveargnums && argauto > 1) + ThrowAbortException(X_FORMAT_ERROR, "Cannot mix explicit and implicit arguments."); + FString argnumstr = fmt_current.Mid(1); + if (!argnumstr.IsInt()) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for argument number, got '%s'.", argnumstr.GetChars()); + auto argnum64 = argnumstr.ToLong(); + if (argnum64 < 1 || argnum64 >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format (tried to access argument %d, %d total).", argnum64, numparam); + fmt_current = "%"; + haveargnums = true; + argnum = int(argnum64); + } + else + { + fmt_current += c; + + switch (c) + { + // string + case 's': + { + if (argnum < 0 && haveargnums) + ThrowAbortException(X_FORMAT_ERROR, "Cannot mix explicit and implicit arguments."); + in_fmt = false; + // fail if something was found, but it's not a string + if (argnum >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); + if (va_reginfo[argnum] != REGT_STRING) ThrowAbortException(X_FORMAT_ERROR, "Expected a string for format %s.", fmt_current.GetChars()); + // append + output.AppendFormat(fmt_current.GetChars(), param[argnum].s().GetChars()); + if (!haveargnums) argnum = ++argauto; + else argnum = -1; + break; + } + + // pointer + case 'p': + { + if (argnum < 0 && haveargnums) + ThrowAbortException(X_FORMAT_ERROR, "Cannot mix explicit and implicit arguments."); + in_fmt = false; + // fail if something was found, but it's not a string + if (argnum >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); + if (va_reginfo[argnum] != REGT_POINTER) ThrowAbortException(X_FORMAT_ERROR, "Expected a pointer for format %s.", fmt_current.GetChars()); + // append + output.AppendFormat(fmt_current.GetChars(), param[argnum].a); + if (!haveargnums) argnum = ++argauto; + else argnum = -1; + break; + } + + // int formats (including char) + case 'd': + case 'i': + case 'u': + case 'x': + case 'X': + case 'o': + case 'c': + case 'B': + { + if (argnum < 0 && haveargnums) + ThrowAbortException(X_FORMAT_ERROR, "Cannot mix explicit and implicit arguments."); + in_fmt = false; + // append + if (fmt_current[1] == '*' || fmt_current[2] == '*') + { + // fail if something was found, but it's not an int + if (argnum+1 >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); + if (va_reginfo[argnum] != REGT_INT && + va_reginfo[argnum] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); + if (va_reginfo[argnum+1] != REGT_INT && + va_reginfo[argnum+1] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); + + output.AppendFormat(fmt_current.GetChars(), param[argnum].ToInt(va_reginfo[argnum]), param[argnum + 1].ToInt(va_reginfo[argnum + 1])); + argauto++; + } + else + { + // fail if something was found, but it's not an int + if (argnum >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); + if (va_reginfo[argnum] != REGT_INT && + va_reginfo[argnum] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); + output.AppendFormat(fmt_current.GetChars(), param[argnum].ToInt(va_reginfo[argnum])); + } + if (!haveargnums) argnum = ++argauto; + else argnum = -1; + break; + } + + // double formats + case 'f': + case 'F': + case 'e': + case 'E': + case 'g': + case 'G': + case 'a': + case 'A': + { + if (argnum < 0 && haveargnums) + ThrowAbortException(X_FORMAT_ERROR, "Cannot mix explicit and implicit arguments."); + in_fmt = false; + if (fmt_current[1] == '*' || fmt_current[2] == '*') + { + // fail if something was found, but it's not an int + if (argnum + 1 >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); + if (va_reginfo[argnum] != REGT_INT && + va_reginfo[argnum] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); + if (va_reginfo[argnum + 1] != REGT_INT && + va_reginfo[argnum + 1] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); + + output.AppendFormat(fmt_current.GetChars(), param[argnum].ToInt(va_reginfo[argnum]), param[argnum + 1].ToDouble(va_reginfo[argnum + 1])); + argauto++; + } + else + { + // fail if something was found, but it's not a float + if (argnum >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); + if (va_reginfo[argnum] != REGT_INT && + va_reginfo[argnum] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); + // append + output.AppendFormat(fmt_current.GetChars(), param[argnum].ToDouble(va_reginfo[argnum])); + } + if (!haveargnums) argnum = ++argauto; + else argnum = -1; + break; + } + + default: + // invalid character + output += fmt_current; + in_fmt = false; + break; + } + } + } + else + { + if (c == '%') + { + if (i + 1 < fmtstring.Len() && fmtstring[i + 1] == '%') + { + output += '%'; + i++; + } + else + { + in_fmt = true; + fmt_current = "%"; + } + } + else + { + output += c; + } + } + } + + return output; +} + +DEFINE_ACTION_FUNCTION(FStringStruct, Format) +{ + PARAM_PROLOGUE; + FString s = FStringFormat(VM_ARGS_NAMES); + ACTION_RETURN_STRING(s); +} + +DEFINE_ACTION_FUNCTION(FStringStruct, AppendFormat) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + // first parameter is the self pointer + FString s = FStringFormat(VM_ARGS_NAMES, 1); + (*self) += s; + return 0; +} + +DEFINE_ACTION_FUNCTION(FStringStruct, AppendCharacter) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_INT(c); + self->AppendCharacter(c); + return 0; +} + +DEFINE_ACTION_FUNCTION(FStringStruct, DeleteLastCharacter) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + self->DeleteLastCharacter(); + return 0; +} diff --git a/src/scripting/vm/jit.cpp b/src/common/scripting/jit/jit.cpp similarity index 99% rename from src/scripting/vm/jit.cpp rename to src/common/scripting/jit/jit.cpp index 1813d19ca..aa48585af 100644 --- a/src/scripting/vm/jit.cpp +++ b/src/common/scripting/jit/jit.cpp @@ -1,6 +1,7 @@ #include "jit.h" #include "jitintern.h" +#include "printf.h" extern PString *TypeString; extern PStruct *TypeVector2; diff --git a/src/scripting/vm/jit.h b/src/common/scripting/jit/jit.h similarity index 100% rename from src/scripting/vm/jit.h rename to src/common/scripting/jit/jit.h diff --git a/src/scripting/vm/jit_call.cpp b/src/common/scripting/jit/jit_call.cpp similarity index 100% rename from src/scripting/vm/jit_call.cpp rename to src/common/scripting/jit/jit_call.cpp diff --git a/src/scripting/vm/jit_flow.cpp b/src/common/scripting/jit/jit_flow.cpp similarity index 100% rename from src/scripting/vm/jit_flow.cpp rename to src/common/scripting/jit/jit_flow.cpp diff --git a/src/scripting/vm/jit_load.cpp b/src/common/scripting/jit/jit_load.cpp similarity index 100% rename from src/scripting/vm/jit_load.cpp rename to src/common/scripting/jit/jit_load.cpp diff --git a/src/scripting/vm/jit_math.cpp b/src/common/scripting/jit/jit_math.cpp similarity index 99% rename from src/scripting/vm/jit_math.cpp rename to src/common/scripting/jit/jit_math.cpp index 4210fa6ff..0b142563d 100644 --- a/src/scripting/vm/jit_math.cpp +++ b/src/common/scripting/jit/jit_math.cpp @@ -1,5 +1,6 @@ #include "jitintern.h" +#include "basics.h" ///////////////////////////////////////////////////////////////////////////// // String instructions. diff --git a/src/scripting/vm/jit_move.cpp b/src/common/scripting/jit/jit_move.cpp similarity index 97% rename from src/scripting/vm/jit_move.cpp rename to src/common/scripting/jit/jit_move.cpp index 767000c7d..584de35a1 100644 --- a/src/scripting/vm/jit_move.cpp +++ b/src/common/scripting/jit/jit_move.cpp @@ -1,8 +1,7 @@ #include "jitintern.h" #include "v_video.h" -#include "s_sound.h" -#include "r_state.h" +#include "s_soundinternal.h" #include "texturemanager.h" void JitCompiler::EmitMOVE() @@ -52,8 +51,8 @@ static void CastN2S(FString *a, int b) { FName name = FName(ENamedName(b)); *a = static int CastS2Co(FString *b) { return V_GetColor(nullptr, *b); } static void CastCo2S(FString *a, int b) { PalEntry c(b); a->Format("%02x %02x %02x", c.r, c.g, c.b); } static int CastS2So(FString *b) { return FSoundID(*b); } -static void CastSo2S(FString* a, int b) { *a = S_GetSoundName(b); } -static void CastSID2S(FString *a, unsigned int b) { *a = (b >= sprites.Size()) ? "TNT1" : sprites[b].name; } +static void CastSo2S(FString* a, int b) { *a = soundEngine->GetSoundName(b); } +static void CastSID2S(FString* a, unsigned int b) { VM_CastSpriteIDToString(a, b); } static void CastTID2S(FString *a, int b) { auto tex = TexMan.GetTexture(*(FTextureID*)&b); *a = (tex == nullptr) ? "(null)" : tex->GetName().GetChars(); } void JitCompiler::EmitCAST() diff --git a/src/scripting/vm/jit_runtime.cpp b/src/common/scripting/jit/jit_runtime.cpp similarity index 99% rename from src/scripting/vm/jit_runtime.cpp rename to src/common/scripting/jit/jit_runtime.cpp index 5e922be6f..b0a9dc488 100644 --- a/src/scripting/vm/jit_runtime.cpp +++ b/src/common/scripting/jit/jit_runtime.cpp @@ -56,7 +56,7 @@ static void *AllocJitMemory(size_t size) } else { - const size_t bytesToAllocate = MAX(size_t(1024 * 1024), size); + const size_t bytesToAllocate = std::max(size_t(1024 * 1024), size); size_t allocatedSize = 0; void *p = OSUtils::allocVirtualMemory(bytesToAllocate, &allocatedSize, OSUtils::kVMWritable | OSUtils::kVMExecutable); if (!p) diff --git a/src/scripting/vm/jit_store.cpp b/src/common/scripting/jit/jit_store.cpp similarity index 100% rename from src/scripting/vm/jit_store.cpp rename to src/common/scripting/jit/jit_store.cpp diff --git a/src/scripting/vm/jitintern.h b/src/common/scripting/jit/jitintern.h similarity index 100% rename from src/scripting/vm/jitintern.h rename to src/common/scripting/jit/jitintern.h diff --git a/src/scripting/vm/vm.h b/src/common/scripting/vm/vm.h similarity index 99% rename from src/scripting/vm/vm.h rename to src/common/scripting/vm/vm.h index a2f002f04..0eeec06b4 100644 --- a/src/scripting/vm/vm.h +++ b/src/common/scripting/vm/vm.h @@ -43,7 +43,7 @@ #include "engineerrors.h" #include "memarena.h" #include "name.h" -#include "scripting/backend/scopebarrier.h" +#include "scopebarrier.h" class DObject; union VMOP; @@ -56,6 +56,8 @@ extern FMemArena ClassDataAllocator; void JitRelease(); +extern void (*VM_CastSpriteIDToString)(FString* a, unsigned int b); + typedef unsigned char VM_UBYTE; typedef signed char VM_SBYTE; diff --git a/src/scripting/vm/vmexec.cpp b/src/common/scripting/vm/vmexec.cpp similarity index 94% rename from src/scripting/vm/vmexec.cpp rename to src/common/scripting/vm/vmexec.cpp index 2ac0d4e70..6921d3dac 100644 --- a/src/scripting/vm/vmexec.cpp +++ b/src/common/scripting/vm/vmexec.cpp @@ -32,17 +32,23 @@ */ #include -#include -#include -#include "r_state.h" +#include +#include "v_video.h" +#include "s_soundinternal.h" +#include "basics.h" +//#include "r_state.h" #include "stats.h" #include "vmintern.h" #include "types.h" +#include "basics.h" #include "texturemanager.h" extern cycle_t VMCycles[10]; extern int VMCalls[10]; +// THe sprite ID to string cast is game specific so let's do it with a callback to remove the dependency and allow easier reuse. +void (*VM_CastSpriteIDToString)(FString* a, unsigned int b) = [](FString* a, unsigned int b) { a->Format("%d", b); }; + // intentionally implemented in a different source file to prevent inlining. #if 0 void ThrowVMException(VMException *x); diff --git a/src/scripting/vm/vmexec.h b/src/common/scripting/vm/vmexec.h similarity index 99% rename from src/scripting/vm/vmexec.h rename to src/common/scripting/vm/vmexec.h index 26622b3e1..72e0d0199 100644 --- a/src/scripting/vm/vmexec.h +++ b/src/common/scripting/vm/vmexec.h @@ -1837,12 +1837,12 @@ static void DoCast(const VMRegisters ®, const VMFrame *f, int a, int b, int c case CAST_So2S: ASSERTS(a); ASSERTD(b); - reg.s[a] = S_GetSoundName(reg.d[b]); + reg.s[a] = soundEngine->GetSoundName(reg.d[b]); break; case CAST_SID2S: ASSERTS(a); ASSERTD(b); - reg.s[a] = unsigned(reg.d[b]) >= sprites.Size() ? "TNT1" : sprites[reg.d[b]].name; + VM_CastSpriteIDToString(®.s[a], reg.d[b]); break; case CAST_TID2S: diff --git a/src/scripting/vm/vmframe.cpp b/src/common/scripting/vm/vmframe.cpp similarity index 100% rename from src/scripting/vm/vmframe.cpp rename to src/common/scripting/vm/vmframe.cpp diff --git a/src/scripting/vm/vmintern.h b/src/common/scripting/vm/vmintern.h similarity index 100% rename from src/scripting/vm/vmintern.h rename to src/common/scripting/vm/vmintern.h diff --git a/src/scripting/vm/vmops.h b/src/common/scripting/vm/vmops.h similarity index 100% rename from src/scripting/vm/vmops.h rename to src/common/scripting/vm/vmops.h diff --git a/src/common/utility/basics.h b/src/common/utility/basics.h index d71554473..f5ecdd1a2 100644 --- a/src/common/utility/basics.h +++ b/src/common/utility/basics.h @@ -1,5 +1,4 @@ -#ifndef __BASICS_H -#define __BASICS_H +#pragma once #include #include @@ -56,11 +55,52 @@ typedef uint32_t angle_t; using INTBOOL = int; using BITFIELD = uint32_t; -#endif #if defined(_MSC_VER) #define NOVTABLE __declspec(novtable) #else #define NOVTABLE -#endif \ No newline at end of file +#endif + +// always use our own definition for consistency. +#ifdef M_PI +#undef M_PI +#endif + +const double M_PI = 3.14159265358979323846; // matches value in gcc v2 math.h + +inline float DEG2RAD(float deg) +{ + return deg * float(M_PI / 180.0); +} + +inline double DEG2RAD(double deg) +{ + return deg * (M_PI / 180.0); +} + +inline float RAD2DEG(float deg) +{ + return deg * float(180. / M_PI); +} + + +// Auto-registration sections for GCC. +// Apparently, you cannot do string concatenation inside section attributes. +#ifdef __MACH__ +#define SECTION_AREG "__DATA,areg" +#define SECTION_CREG "__DATA,creg" +#define SECTION_FREG "__DATA,freg" +#define SECTION_GREG "__DATA,greg" +#define SECTION_MREG "__DATA,mreg" +#define SECTION_YREG "__DATA,yreg" +#else +#define SECTION_AREG "areg" +#define SECTION_CREG "creg" +#define SECTION_FREG "freg" +#define SECTION_GREG "greg" +#define SECTION_MREG "mreg" +#define SECTION_YREG "yreg" +#endif + diff --git a/src/d_main.cpp b/src/d_main.cpp index 6641282f7..69301e295 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2743,6 +2743,10 @@ int PalCheck(int tex) return tex; } +static void Doom_CastSpriteIDToString(FString* a, unsigned int b) +{ + *a = (b >= sprites.Size()) ? "TNT1" : sprites[b].name; +} //========================================================================== // @@ -2760,6 +2764,8 @@ static int D_DoomMain_Internal (void) int argcount; FIWadManager *iwad_man; + VM_CastSpriteIDToString = Doom_CastSpriteIDToString; + // Set up the button list. Mlook and Klook need a bit of extra treatment. buttonMap.SetButtons(DoomButtons, countof(DoomButtons)); buttonMap.GetButton(Button_Mlook)->ReleaseHandler = Mlook_ReleaseHandler; diff --git a/src/doomtype.h b/src/doomtype.h index 1f40f0f2c..5b1819d08 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -52,45 +52,4 @@ enum class ELightMode : int8_t DoomSoftware = 16 }; -// always use our own definition for consistency. -#ifdef M_PI -#undef M_PI -#endif - -const double M_PI = 3.14159265358979323846; // matches value in gcc v2 math.h - -inline float DEG2RAD(float deg) -{ - return deg * float(M_PI / 180.0); -} - -inline double DEG2RAD(double deg) -{ - return deg * (M_PI / 180.0); -} - -inline float RAD2DEG(float deg) -{ - return deg * float(180. / M_PI); -} - - -// Auto-registration sections for GCC. -// Apparently, you cannot do string concatenation inside section attributes. -#ifdef __MACH__ -#define SECTION_AREG "__DATA,areg" -#define SECTION_CREG "__DATA,creg" -#define SECTION_FREG "__DATA,freg" -#define SECTION_GREG "__DATA,greg" -#define SECTION_MREG "__DATA,mreg" -#define SECTION_YREG "__DATA,yreg" -#else -#define SECTION_AREG "areg" -#define SECTION_CREG "creg" -#define SECTION_FREG "freg" -#define SECTION_GREG "greg" -#define SECTION_MREG "mreg" -#define SECTION_YREG "yreg" -#endif - #endif diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index a9edc516f..5f354d934 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -54,7 +54,7 @@ #include "v_video.h" #include "i_system.h" #include "c_buttons.h" -#include "scripting/types.h" +#include "types.h" #include "texturemanager.h" int DMenu::InMenu; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 97072b882..fbd93e75e 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -67,7 +67,7 @@ #include "p_destructible.h" #include "types.h" #include "i_time.h" -#include "scripting/vm/vm.h" +#include "vm.h" #include "a_specialspot.h" #include "maploader/maploader.h" #include "p_acs.h" diff --git a/src/rendering/hwrenderer/scene/hw_clipper.cpp b/src/rendering/hwrenderer/scene/hw_clipper.cpp index 85646f84c..fd69e267c 100644 --- a/src/rendering/hwrenderer/scene/hw_clipper.cpp +++ b/src/rendering/hwrenderer/scene/hw_clipper.cpp @@ -37,6 +37,7 @@ #include "hw_clipper.h" #include "g_levellocals.h" +#include "basics.h" unsigned Clipper::starttime; diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 889d1c4f8..6b1e9ae97 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -42,6 +42,7 @@ #include "r_data/models/models.h" #include "vectors.h" #include "texturemanager.h" +#include "basics.h" #include "hwrenderer/models/hw_models.h" #include "hwrenderer/scene/hw_drawstructs.h" diff --git a/src/scripting/backend/vmbuilder.cpp b/src/scripting/backend/vmbuilder.cpp index 393e3a53d..5e0b314f6 100644 --- a/src/scripting/backend/vmbuilder.cpp +++ b/src/scripting/backend/vmbuilder.cpp @@ -36,7 +36,7 @@ #include "codegen.h" #include "m_argv.h" #include "c_cvars.h" -#include "scripting/vm/jit.h" +#include "jit.h" EXTERN_CVAR(Bool, strictdecorate); diff --git a/src/scripting/dictionary.cpp b/src/scripting/dictionary.cpp index eb9f323f9..b8dacd2bc 100644 --- a/src/scripting/dictionary.cpp +++ b/src/scripting/dictionary.cpp @@ -1,6 +1,6 @@ #include "dictionary.h" -#include "scripting/vm/vm.h" +#include "vm.h" #include "serializer.h" #include diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 12c5cfe8f..3715eab16 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -949,233 +949,3 @@ DEFINE_ACTION_FUNCTION(DObject, BAM) ACTION_RETURN_INT(DAngle(ang).BAMs()); } -FString FStringFormat(VM_ARGS, int offset) -{ - PARAM_VA_POINTER(va_reginfo) // Get the hidden type information array - assert(va_reginfo[offset] == REGT_STRING); - - FString fmtstring = param[offset].s().GetChars(); - - param += offset; - numparam -= offset; - va_reginfo += offset; - - // note: we don't need a real printf format parser. - // enough to simply find the subtitution tokens and feed them to the real printf after checking types. - // https://en.wikipedia.org/wiki/Printf_format_string#Format_placeholder_specification - FString output; - bool in_fmt = false; - FString fmt_current; - int argnum = 1; - int argauto = 1; - // % = starts - // [0-9], -, +, \s, 0, #, . continue - // %, s, d, i, u, fF, eE, gG, xX, o, c, p, aA terminate - // various type flags are not supported. not like stuff like 'hh' modifier is to be used in the VM. - // the only combination that is parsed locally is %n$... - bool haveargnums = false; - for (size_t i = 0; i < fmtstring.Len(); i++) - { - char c = fmtstring[i]; - if (in_fmt) - { - if (c == '*' && (fmt_current.Len() == 1 || (fmt_current.Len() == 2 && fmt_current[1] == '0'))) - { - fmt_current += c; - } - else if ((c >= '0' && c <= '9') || - c == '-' || c == '+' || (c == ' ' && fmt_current.Back() != ' ') || c == '#' || c == '.') - { - fmt_current += c; - } - else if (c == '$') // %number$format - { - if (!haveargnums && argauto > 1) - ThrowAbortException(X_FORMAT_ERROR, "Cannot mix explicit and implicit arguments."); - FString argnumstr = fmt_current.Mid(1); - if (!argnumstr.IsInt()) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for argument number, got '%s'.", argnumstr.GetChars()); - auto argnum64 = argnumstr.ToLong(); - if (argnum64 < 1 || argnum64 >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format (tried to access argument %d, %d total).", argnum64, numparam); - fmt_current = "%"; - haveargnums = true; - argnum = int(argnum64); - } - else - { - fmt_current += c; - - switch (c) - { - // string - case 's': - { - if (argnum < 0 && haveargnums) - ThrowAbortException(X_FORMAT_ERROR, "Cannot mix explicit and implicit arguments."); - in_fmt = false; - // fail if something was found, but it's not a string - if (argnum >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); - if (va_reginfo[argnum] != REGT_STRING) ThrowAbortException(X_FORMAT_ERROR, "Expected a string for format %s.", fmt_current.GetChars()); - // append - output.AppendFormat(fmt_current.GetChars(), param[argnum].s().GetChars()); - if (!haveargnums) argnum = ++argauto; - else argnum = -1; - break; - } - - // pointer - case 'p': - { - if (argnum < 0 && haveargnums) - ThrowAbortException(X_FORMAT_ERROR, "Cannot mix explicit and implicit arguments."); - in_fmt = false; - // fail if something was found, but it's not a string - if (argnum >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); - if (va_reginfo[argnum] != REGT_POINTER) ThrowAbortException(X_FORMAT_ERROR, "Expected a pointer for format %s.", fmt_current.GetChars()); - // append - output.AppendFormat(fmt_current.GetChars(), param[argnum].a); - if (!haveargnums) argnum = ++argauto; - else argnum = -1; - break; - } - - // int formats (including char) - case 'd': - case 'i': - case 'u': - case 'x': - case 'X': - case 'o': - case 'c': - case 'B': - { - if (argnum < 0 && haveargnums) - ThrowAbortException(X_FORMAT_ERROR, "Cannot mix explicit and implicit arguments."); - in_fmt = false; - // append - if (fmt_current[1] == '*' || fmt_current[2] == '*') - { - // fail if something was found, but it's not an int - if (argnum+1 >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); - if (va_reginfo[argnum] != REGT_INT && - va_reginfo[argnum] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); - if (va_reginfo[argnum+1] != REGT_INT && - va_reginfo[argnum+1] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); - - output.AppendFormat(fmt_current.GetChars(), param[argnum].ToInt(va_reginfo[argnum]), param[argnum + 1].ToInt(va_reginfo[argnum + 1])); - argauto++; - } - else - { - // fail if something was found, but it's not an int - if (argnum >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); - if (va_reginfo[argnum] != REGT_INT && - va_reginfo[argnum] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); - output.AppendFormat(fmt_current.GetChars(), param[argnum].ToInt(va_reginfo[argnum])); - } - if (!haveargnums) argnum = ++argauto; - else argnum = -1; - break; - } - - // double formats - case 'f': - case 'F': - case 'e': - case 'E': - case 'g': - case 'G': - case 'a': - case 'A': - { - if (argnum < 0 && haveargnums) - ThrowAbortException(X_FORMAT_ERROR, "Cannot mix explicit and implicit arguments."); - in_fmt = false; - if (fmt_current[1] == '*' || fmt_current[2] == '*') - { - // fail if something was found, but it's not an int - if (argnum + 1 >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); - if (va_reginfo[argnum] != REGT_INT && - va_reginfo[argnum] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); - if (va_reginfo[argnum + 1] != REGT_INT && - va_reginfo[argnum + 1] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); - - output.AppendFormat(fmt_current.GetChars(), param[argnum].ToInt(va_reginfo[argnum]), param[argnum + 1].ToDouble(va_reginfo[argnum + 1])); - argauto++; - } - else - { - // fail if something was found, but it's not a float - if (argnum >= numparam) ThrowAbortException(X_FORMAT_ERROR, "Not enough arguments for format."); - if (va_reginfo[argnum] != REGT_INT && - va_reginfo[argnum] != REGT_FLOAT) ThrowAbortException(X_FORMAT_ERROR, "Expected a numeric value for format %s.", fmt_current.GetChars()); - // append - output.AppendFormat(fmt_current.GetChars(), param[argnum].ToDouble(va_reginfo[argnum])); - } - if (!haveargnums) argnum = ++argauto; - else argnum = -1; - break; - } - - default: - // invalid character - output += fmt_current; - in_fmt = false; - break; - } - } - } - else - { - if (c == '%') - { - if (i + 1 < fmtstring.Len() && fmtstring[i + 1] == '%') - { - output += '%'; - i++; - } - else - { - in_fmt = true; - fmt_current = "%"; - } - } - else - { - output += c; - } - } - } - - return output; -} - -DEFINE_ACTION_FUNCTION(FStringStruct, Format) -{ - PARAM_PROLOGUE; - FString s = FStringFormat(VM_ARGS_NAMES); - ACTION_RETURN_STRING(s); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, AppendFormat) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - // first parameter is the self pointer - FString s = FStringFormat(VM_ARGS_NAMES, 1); - (*self) += s; - return 0; -} - -DEFINE_ACTION_FUNCTION(FStringStruct, AppendCharacter) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_INT(c); - self->AppendCharacter(c); - return 0; -} - -DEFINE_ACTION_FUNCTION(FStringStruct, DeleteLastCharacter) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - self->DeleteLastCharacter(); - return 0; -} diff --git a/src/serializer.cpp b/src/serializer.cpp index bca340231..79d12ec37 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -1673,7 +1673,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundI if (!arc.w->inObject() || def == nullptr || sid != *def) { arc.WriteKey(key); - const char *sn = S_GetSoundName(sid); + const char *sn = soundEngine->GetSoundName(sid); if (sn != nullptr) arc.w->String(sn); else arc.w->Null(); } @@ -2088,7 +2088,7 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, char *&pstr // // This is a bit of a cheat because it never actually writes out the pointer. // The rules for levels are that they must be self-contained. -// No level and no pbject that is part of a level may reference a different one. +// No level and no object that is part of a level may reference a different one. // // When writing, this merely checks if the rules are obeyed and if not errors out. // When reading, it assumes that the object was properly written and restores diff --git a/src/sound/s_doomsound.h b/src/sound/s_doomsound.h index 2ea833dc0..0953af4b0 100644 --- a/src/sound/s_doomsound.h +++ b/src/sound/s_doomsound.h @@ -79,12 +79,3 @@ inline const char* S_GetSoundName(FSoundID id) return soundEngine->GetSoundName(id); } -inline int S_FindSound(const char* logicalname) -{ - return soundEngine->FindSound(logicalname); -} - -inline int S_FindSoundByResID(int rid) -{ - return soundEngine->FindSoundByResID(rid); -}