From 548aa059039edf054dfbe211a005b08db88dc92b Mon Sep 17 00:00:00 2001 From: Michael Zhao <44533763+Pistonight@users.noreply.github.com> Date: Sun, 21 Jun 2026 18:14:34 -0700 Subject: [PATCH] update to c++23 --- CMakeLists.txt | 4 +- src/Lawn/Board.cpp | 1 - src/Lawn/System/Music.h | 8 +- src/Sexy.TodLib/Definition.cpp | 365 ++++++++++-------- src/Sexy.TodLib/Definition.h | 50 +-- .../OriginalCompiledDefinition.cpp | 57 ++- src/Sexy.TodLib/OriginalCompiledDefinition.h | 53 ++- src/Sexy.TodLib/TodList.h | 7 +- src/SexyAppFramework/BassMusicInterface.cpp | 8 +- src/SexyAppFramework/BassMusicInterface.h | 8 +- src/SexyAppFramework/HTTPTransfer.cpp | 7 +- src/SexyAppFramework/SEHCatcher.cpp | 78 ++-- src/SexyAppFramework/SexyAppBase.cpp | 242 ++++++------ 13 files changed, 476 insertions(+), 412 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cb2e3e6..77af024b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,8 @@ if(MSVC AND GITHUB_ACTIONS) add_link_options(/SAFESEH:NO) endif() -set(CMAKE_C_STANDARD 17) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_STANDARD 23) +set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) diff --git a/src/Lawn/Board.cpp b/src/Lawn/Board.cpp index 548c96dc..2982a18c 100644 --- a/src/Lawn/Board.cpp +++ b/src/Lawn/Board.cpp @@ -42,7 +42,6 @@ #include "../Sexy.TodLib/EffectSystem.h" #include "../Sexy.TodLib/TodStringFile.h" #include "../SexyAppFramework/ImageFont.h" -#include #include "../SexyAppFramework/SoundManager.h" #include "../SexyAppFramework/ButtonWidget.h" #include "../SexyAppFramework/WidgetManager.h" diff --git a/src/Lawn/System/Music.h b/src/Lawn/System/Music.h index ccd23b46..f4ac17fa 100644 --- a/src/Lawn/System/Music.h +++ b/src/Lawn/System/Music.h @@ -2,6 +2,13 @@ #define __MUSIC_H__ #include + +// Include windows ourselves to prevent bass.h from including windows and leak macros +// IWYU pragma: begin_exports <- this suppresses clangd warning +#include "../../SexyAppFramework/Platform.h" +// IWYU pragma: end_exports +// this comment exists to prevent formatter from reordering this include + #include class LawnApp; @@ -103,7 +110,6 @@ class Music void MusicInit(); void MusicDispose() { - ; } void MusicUpdate(); void StopAllMusic(); diff --git a/src/Sexy.TodLib/Definition.cpp b/src/Sexy.TodLib/Definition.cpp index 5ff3f8bb..a030eb3f 100644 --- a/src/Sexy.TodLib/Definition.cpp +++ b/src/Sexy.TodLib/Definition.cpp @@ -9,136 +9,167 @@ #include #include "OriginalCompiledDefinition.h" -DefSymbol gTrailFlagDefSymbols[] = {{0, "Loops"}, {-1, nullptr}}; +DefSymbol gTrailFlagDefSymbols[] = { + { 0, "Loops" }, + { -1, nullptr } +}; DefField gTrailDefFields[] = { - {"Image", offsetof(TrailDefinition, mImage), DefFieldType::DT_IMAGE, nullptr}, - {"MaxPoints", offsetof(TrailDefinition, mMaxPoints), DefFieldType::DT_INT, nullptr}, - {"MinPointDistance", offsetof(TrailDefinition, mMinPointDistance), DefFieldType::DT_FLOAT, nullptr}, - {"TrailFlags", offsetof(TrailDefinition, mTrailFlags), DefFieldType::DT_FLAGS, gTrailFlagDefSymbols}, - {"WidthOverLength", offsetof(TrailDefinition, mWidthOverLength), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"WidthOverTime", offsetof(TrailDefinition, mWidthOverTime), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"AlphaOverLength", offsetof(TrailDefinition, mAlphaOverLength), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"AlphaOverTime", offsetof(TrailDefinition, mAlphaOverTime), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"TrailDuration", offsetof(TrailDefinition, mTrailDuration), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"", 0x0, DefFieldType::DT_INVALID, nullptr}}; -DefMap gTrailDefMap = {gTrailDefFields, sizeof(TrailDefinition), TrailDefinitionConstructor}; - -DefSymbol gParticleFlagSymbols[] = {{0, "RandomLaunchSpin"}, - {1, "AlignLaunchSpin"}, - {2, "AlignToPixel"}, - {4, "ParticleLoops"}, - {3, "SystemLoops"}, - {5, "ParticlesDontFollow"}, - {6, "RandomStartTime"}, - {7, "DieIfOverloaded"}, - {8, "Additive"}, - {9, "FullScreen"}, - {10, "SoftwareOnly"}, - {11, "HardwareOnly"}, - {-1, nullptr}}; + { "Image", offsetof(TrailDefinition, mImage), DefFieldType::DT_IMAGE, nullptr }, + { "MaxPoints", offsetof(TrailDefinition, mMaxPoints), DefFieldType::DT_INT, nullptr }, + { "MinPointDistance", offsetof(TrailDefinition, mMinPointDistance), DefFieldType::DT_FLOAT, nullptr }, + { "TrailFlags", offsetof(TrailDefinition, mTrailFlags), DefFieldType::DT_FLAGS, gTrailFlagDefSymbols }, + { "WidthOverLength", offsetof(TrailDefinition, mWidthOverLength), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "WidthOverTime", offsetof(TrailDefinition, mWidthOverTime), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "AlphaOverLength", offsetof(TrailDefinition, mAlphaOverLength), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "AlphaOverTime", offsetof(TrailDefinition, mAlphaOverTime), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "TrailDuration", offsetof(TrailDefinition, mTrailDuration), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "", 0x0, DefFieldType::DT_INVALID, nullptr } +}; +DefMap gTrailDefMap = { gTrailDefFields, sizeof(TrailDefinition), TrailDefinitionConstructor }; + +DefSymbol gParticleFlagSymbols[] = { + { 0, "RandomLaunchSpin" }, + { 1, "AlignLaunchSpin" }, + { 2, "AlignToPixel" }, + { 4, "ParticleLoops" }, + { 3, "SystemLoops" }, + { 5, "ParticlesDontFollow" }, + { 6, "RandomStartTime" }, + { 7, "DieIfOverloaded" }, + { 8, "Additive" }, + { 9, "FullScreen" }, + { 10, "SoftwareOnly" }, + { 11, "HardwareOnly" }, + { -1, nullptr } +}; DefSymbol gEmitterTypeSymbols[] = { - {0, "Circle"}, {1, "Box"}, {2, "BoxPath"}, {3, "CirclePath"}, {4, "CircleEvenSpacing"}, {-1, nullptr}}; + { 0, "Circle" }, + { 1, "Box" }, + { 2, "BoxPath" }, + { 3, "CirclePath" }, + { 4, "CircleEvenSpacing" }, + { -1, nullptr } +}; DefSymbol gParticleTypeSymbols[] = { - {1, "Friction"}, {2, "Acceleration"}, {3, "Attractor"}, {4, "MaxVelocity"}, - {5, "Velocity"}, {6, "Position"}, {7, "SystemPosition"}, {8, "GroundConstraint"}, - {9, "Shake"}, {10, "Circle"}, {11, "Away"}, {-1, nullptr}}; + { 1, "Friction" }, + { 2, "Acceleration" }, + { 3, "Attractor" }, + { 4, "MaxVelocity" }, + { 5, "Velocity" }, + { 6, "Position" }, + { 7, "SystemPosition" }, + { 8, "GroundConstraint" }, + { 9, "Shake" }, + { 10, "Circle" }, + { 11, "Away" }, + { -1, nullptr } +}; DefField gParticleFieldDefFields[] = { - {"FieldType", offsetof(ParticleField, mFieldType), DefFieldType::DT_ENUM, gParticleTypeSymbols}, - {"x", offsetof(ParticleField, mX), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"y", offsetof(ParticleField, mY), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"", 0x0, DefFieldType::DT_INVALID, nullptr}, + { "FieldType", offsetof(ParticleField, mFieldType), DefFieldType::DT_ENUM, gParticleTypeSymbols }, + { "x", offsetof(ParticleField, mX), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "y", offsetof(ParticleField, mY), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "", 0x0, DefFieldType::DT_INVALID, nullptr }, }; -DefMap gParticleFieldDefMap = {gParticleFieldDefFields, sizeof(ParticleField), ParticleFieldConstructor}; +DefMap gParticleFieldDefMap = { gParticleFieldDefFields, sizeof(ParticleField), ParticleFieldConstructor }; DefField gEmitterDefFields[] = { - {"Image", offsetof(TodEmitterDefinition, mImage), DefFieldType::DT_IMAGE, nullptr}, - {"ImageRow", offsetof(TodEmitterDefinition, mImageRow), DefFieldType::DT_INT, nullptr}, - {"ImageCol", offsetof(TodEmitterDefinition, mImageCol), DefFieldType::DT_INT, nullptr}, - {"ImageFrames", offsetof(TodEmitterDefinition, mImageFrames), DefFieldType::DT_INT, nullptr}, - {"Animated", offsetof(TodEmitterDefinition, mAnimated), DefFieldType::DT_INT, nullptr}, - {"ParticleFlags", offsetof(TodEmitterDefinition, mParticleFlags), DefFieldType::DT_FLAGS, gParticleFlagSymbols}, - {"EmitterType", offsetof(TodEmitterDefinition, mEmitterType), DefFieldType::DT_ENUM, gEmitterTypeSymbols}, - {"Name", offsetof(TodEmitterDefinition, mName), DefFieldType::DT_STRING, nullptr}, - {"SystemDuration", offsetof(TodEmitterDefinition, mSystemDuration), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"OnDuration", offsetof(TodEmitterDefinition, mOnDuration), DefFieldType::DT_STRING, nullptr}, - {"CrossFadeDuration", offsetof(TodEmitterDefinition, mCrossFadeDuration), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"SpawnRate", offsetof(TodEmitterDefinition, mSpawnRate), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"SpawnMinActive", offsetof(TodEmitterDefinition, mSpawnMinActive), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"SpawnMaxActive", offsetof(TodEmitterDefinition, mSpawnMaxActive), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"SpawnMaxLaunched", offsetof(TodEmitterDefinition, mSpawnMaxLaunched), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"EmitterRadius", offsetof(TodEmitterDefinition, mEmitterRadius), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"EmitterOffsetX", offsetof(TodEmitterDefinition, mEmitterOffsetX), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"EmitterOffsetY", offsetof(TodEmitterDefinition, mEmitterOffsetY), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"EmitterBoxX", offsetof(TodEmitterDefinition, mEmitterBoxX), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"EmitterBoxY", offsetof(TodEmitterDefinition, mEmitterBoxY), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"EmitterPath", offsetof(TodEmitterDefinition, mEmitterPath), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"EmitterSkewX", offsetof(TodEmitterDefinition, mEmitterSkewX), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"EmitterSkewY", offsetof(TodEmitterDefinition, mEmitterSkewY), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ParticleDuration", offsetof(TodEmitterDefinition, mParticleDuration), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"SystemRed", offsetof(TodEmitterDefinition, mSystemRed), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"SystemGreen", offsetof(TodEmitterDefinition, mSystemGreen), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"SystemBlue", offsetof(TodEmitterDefinition, mSystemBlue), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"SystemAlpha", offsetof(TodEmitterDefinition, mSystemAlpha), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"SystemBrightness", offsetof(TodEmitterDefinition, mSystemBrightness), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"LaunchSpeed", offsetof(TodEmitterDefinition, mLaunchSpeed), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"LaunchAngle", offsetof(TodEmitterDefinition, mLaunchAngle), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"Field", offsetof(TodEmitterDefinition, mParticleFields), DefFieldType::DT_ARRAY, &gParticleFieldDefMap}, - {"SystemField", offsetof(TodEmitterDefinition, mSystemFields), DefFieldType::DT_ARRAY, &gParticleFieldDefMap}, - {"ParticleRed", offsetof(TodEmitterDefinition, mParticleRed), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ParticleGreen", offsetof(TodEmitterDefinition, mParticleGreen), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ParticleBlue", offsetof(TodEmitterDefinition, mParticleBlue), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ParticleAlpha", offsetof(TodEmitterDefinition, mParticleAlpha), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ParticleBrightness", offsetof(TodEmitterDefinition, mParticleBrightness), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ParticleSpinAngle", offsetof(TodEmitterDefinition, mParticleSpinAngle), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ParticleSpinSpeed", offsetof(TodEmitterDefinition, mParticleSpinSpeed), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ParticleScale", offsetof(TodEmitterDefinition, mParticleScale), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ParticleStretch", offsetof(TodEmitterDefinition, mParticleStretch), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"CollisionReflect", offsetof(TodEmitterDefinition, mCollisionReflect), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"CollisionSpin", offsetof(TodEmitterDefinition, mCollisionSpin), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ClipTop", offsetof(TodEmitterDefinition, mClipTop), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ClipBottom", offsetof(TodEmitterDefinition, mClipBottom), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ClipLeft", offsetof(TodEmitterDefinition, mClipLeft), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"ClipRight", offsetof(TodEmitterDefinition, mClipRight), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"AnimationRate", offsetof(TodEmitterDefinition, mAnimationRate), DefFieldType::DT_TRACK_FLOAT, nullptr}, - {"", 0x0, DefFieldType::DT_INVALID, nullptr}, + { "Image", offsetof(TodEmitterDefinition, mImage), DefFieldType::DT_IMAGE, nullptr }, + { "ImageRow", offsetof(TodEmitterDefinition, mImageRow), DefFieldType::DT_INT, nullptr }, + { "ImageCol", offsetof(TodEmitterDefinition, mImageCol), DefFieldType::DT_INT, nullptr }, + { "ImageFrames", offsetof(TodEmitterDefinition, mImageFrames), DefFieldType::DT_INT, nullptr }, + { "Animated", offsetof(TodEmitterDefinition, mAnimated), DefFieldType::DT_INT, nullptr }, + { "ParticleFlags", offsetof(TodEmitterDefinition, mParticleFlags), DefFieldType::DT_FLAGS, gParticleFlagSymbols }, + { "EmitterType", offsetof(TodEmitterDefinition, mEmitterType), DefFieldType::DT_ENUM, gEmitterTypeSymbols }, + { "Name", offsetof(TodEmitterDefinition, mName), DefFieldType::DT_STRING, nullptr }, + { "SystemDuration", offsetof(TodEmitterDefinition, mSystemDuration), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "OnDuration", offsetof(TodEmitterDefinition, mOnDuration), DefFieldType::DT_STRING, nullptr }, + { "CrossFadeDuration", offsetof(TodEmitterDefinition, mCrossFadeDuration), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "SpawnRate", offsetof(TodEmitterDefinition, mSpawnRate), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "SpawnMinActive", offsetof(TodEmitterDefinition, mSpawnMinActive), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "SpawnMaxActive", offsetof(TodEmitterDefinition, mSpawnMaxActive), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "SpawnMaxLaunched", offsetof(TodEmitterDefinition, mSpawnMaxLaunched), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "EmitterRadius", offsetof(TodEmitterDefinition, mEmitterRadius), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "EmitterOffsetX", offsetof(TodEmitterDefinition, mEmitterOffsetX), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "EmitterOffsetY", offsetof(TodEmitterDefinition, mEmitterOffsetY), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "EmitterBoxX", offsetof(TodEmitterDefinition, mEmitterBoxX), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "EmitterBoxY", offsetof(TodEmitterDefinition, mEmitterBoxY), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "EmitterPath", offsetof(TodEmitterDefinition, mEmitterPath), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "EmitterSkewX", offsetof(TodEmitterDefinition, mEmitterSkewX), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "EmitterSkewY", offsetof(TodEmitterDefinition, mEmitterSkewY), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ParticleDuration", offsetof(TodEmitterDefinition, mParticleDuration), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "SystemRed", offsetof(TodEmitterDefinition, mSystemRed), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "SystemGreen", offsetof(TodEmitterDefinition, mSystemGreen), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "SystemBlue", offsetof(TodEmitterDefinition, mSystemBlue), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "SystemAlpha", offsetof(TodEmitterDefinition, mSystemAlpha), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "SystemBrightness", offsetof(TodEmitterDefinition, mSystemBrightness), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "LaunchSpeed", offsetof(TodEmitterDefinition, mLaunchSpeed), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "LaunchAngle", offsetof(TodEmitterDefinition, mLaunchAngle), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "Field", offsetof(TodEmitterDefinition, mParticleFields), DefFieldType::DT_ARRAY, &gParticleFieldDefMap }, + { "SystemField", offsetof(TodEmitterDefinition, mSystemFields), DefFieldType::DT_ARRAY, &gParticleFieldDefMap }, + { "ParticleRed", offsetof(TodEmitterDefinition, mParticleRed), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ParticleGreen", offsetof(TodEmitterDefinition, mParticleGreen), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ParticleBlue", offsetof(TodEmitterDefinition, mParticleBlue), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ParticleAlpha", offsetof(TodEmitterDefinition, mParticleAlpha), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ParticleBrightness", offsetof(TodEmitterDefinition, mParticleBrightness), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ParticleSpinAngle", offsetof(TodEmitterDefinition, mParticleSpinAngle), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ParticleSpinSpeed", offsetof(TodEmitterDefinition, mParticleSpinSpeed), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ParticleScale", offsetof(TodEmitterDefinition, mParticleScale), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ParticleStretch", offsetof(TodEmitterDefinition, mParticleStretch), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "CollisionReflect", offsetof(TodEmitterDefinition, mCollisionReflect), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "CollisionSpin", offsetof(TodEmitterDefinition, mCollisionSpin), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ClipTop", offsetof(TodEmitterDefinition, mClipTop), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ClipBottom", offsetof(TodEmitterDefinition, mClipBottom), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ClipLeft", offsetof(TodEmitterDefinition, mClipLeft), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "ClipRight", offsetof(TodEmitterDefinition, mClipRight), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "AnimationRate", offsetof(TodEmitterDefinition, mAnimationRate), DefFieldType::DT_TRACK_FLOAT, nullptr }, + { "", 0x0, DefFieldType::DT_INVALID, nullptr }, }; -DefMap gEmitterDefMap = {gEmitterDefFields, sizeof(TodEmitterDefinition), TodEmitterDefinitionConstructor}; +DefMap gEmitterDefMap = { gEmitterDefFields, sizeof(TodEmitterDefinition), TodEmitterDefinitionConstructor }; -DefField gParticleDefFields[] = {{"Emitter", 0x0, DefFieldType::DT_ARRAY, &gEmitterDefMap}, - {"", 0x0, DefFieldType::DT_INVALID, nullptr}}; -DefMap gParticleDefMap = {gParticleDefFields, sizeof(TodParticleDefinition), TodParticleDefinitionConstructor}; +DefField gParticleDefFields[] = { + { "Emitter", 0x0, DefFieldType::DT_ARRAY, &gEmitterDefMap }, + { "", 0x0, DefFieldType::DT_INVALID, nullptr } +}; +DefMap gParticleDefMap = { gParticleDefFields, sizeof(TodParticleDefinition), TodParticleDefinitionConstructor }; DefField gReanimatorTransformDefFields[] = { - {"x", offsetof(ReanimatorTransform, mTransX), DefFieldType::DT_FLOAT, nullptr}, - {"y", offsetof(ReanimatorTransform, mTransY), DefFieldType::DT_FLOAT, nullptr}, - {"kx", offsetof(ReanimatorTransform, mSkewX), DefFieldType::DT_FLOAT, nullptr}, - {"ky", offsetof(ReanimatorTransform, mSkewY), DefFieldType::DT_FLOAT, nullptr}, - {"sx", offsetof(ReanimatorTransform, mScaleX), DefFieldType::DT_FLOAT, nullptr}, - {"sy", offsetof(ReanimatorTransform, mScaleY), DefFieldType::DT_FLOAT, nullptr}, - {"f", offsetof(ReanimatorTransform, mFrame), DefFieldType::DT_FLOAT, nullptr}, - {"a", offsetof(ReanimatorTransform, mAlpha), DefFieldType::DT_FLOAT, nullptr}, - {"i", offsetof(ReanimatorTransform, mImage), DefFieldType::DT_IMAGE, nullptr}, - {"font", offsetof(ReanimatorTransform, mFont), DefFieldType::DT_FONT, nullptr}, - {"text", offsetof(ReanimatorTransform, mText), DefFieldType::DT_STRING, nullptr}, - {"", 0x0, DefFieldType::DT_INVALID, nullptr}}; -DefMap gReanimatorTransformDefMap = {gReanimatorTransformDefFields, sizeof(ReanimatorTransform), - ReanimatorTransformConstructor}; + { "x", offsetof(ReanimatorTransform, mTransX), DefFieldType::DT_FLOAT, nullptr }, + { "y", offsetof(ReanimatorTransform, mTransY), DefFieldType::DT_FLOAT, nullptr }, + { "kx", offsetof(ReanimatorTransform, mSkewX), DefFieldType::DT_FLOAT, nullptr }, + { "ky", offsetof(ReanimatorTransform, mSkewY), DefFieldType::DT_FLOAT, nullptr }, + { "sx", offsetof(ReanimatorTransform, mScaleX), DefFieldType::DT_FLOAT, nullptr }, + { "sy", offsetof(ReanimatorTransform, mScaleY), DefFieldType::DT_FLOAT, nullptr }, + { "f", offsetof(ReanimatorTransform, mFrame), DefFieldType::DT_FLOAT, nullptr }, + { "a", offsetof(ReanimatorTransform, mAlpha), DefFieldType::DT_FLOAT, nullptr }, + { "i", offsetof(ReanimatorTransform, mImage), DefFieldType::DT_IMAGE, nullptr }, + { "font", offsetof(ReanimatorTransform, mFont), DefFieldType::DT_FONT, nullptr }, + { "text", offsetof(ReanimatorTransform, mText), DefFieldType::DT_STRING, nullptr }, + { "", 0x0, DefFieldType::DT_INVALID, nullptr } +}; +DefMap gReanimatorTransformDefMap = { gReanimatorTransformDefFields, sizeof(ReanimatorTransform), + ReanimatorTransformConstructor }; DefField gReanimatorTrackDefFields[] = { - {"name", offsetof(ReanimatorTrack, mName), DefFieldType::DT_STRING, nullptr}, - {"t", offsetof(ReanimatorTrack, mTransforms), DefFieldType::DT_ARRAY, &gReanimatorTransformDefMap}, - {"", 0x0, DefFieldType::DT_INVALID, nullptr}}; -DefMap gReanimatorTrackDefMap = {gReanimatorTrackDefFields, sizeof(ReanimatorTrack), ReanimatorTrackConstructor}; + { "name", offsetof(ReanimatorTrack, mName), DefFieldType::DT_STRING, nullptr }, + { "t", offsetof(ReanimatorTrack, mTransforms), DefFieldType::DT_ARRAY, &gReanimatorTransformDefMap }, + { "", 0x0, DefFieldType::DT_INVALID, nullptr } +}; +DefMap gReanimatorTrackDefMap = { gReanimatorTrackDefFields, sizeof(ReanimatorTrack), ReanimatorTrackConstructor }; DefField gReanimatorDefFields[] = { - {"track", offsetof(ReanimatorDefinition, mTracks), DefFieldType::DT_ARRAY, &gReanimatorTrackDefMap}, - {"fps", offsetof(ReanimatorDefinition, mFPS), DefFieldType::DT_FLOAT, nullptr}, - {"", 0x0, DefFieldType::DT_INVALID, nullptr}}; -DefMap gReanimatorDefMap = {gReanimatorDefFields, sizeof(ReanimatorDefinition), ReanimatorDefinitionConstructor}; + { "track", offsetof(ReanimatorDefinition, mTracks), DefFieldType::DT_ARRAY, &gReanimatorTrackDefMap }, + { "fps", offsetof(ReanimatorDefinition, mFPS), DefFieldType::DT_FLOAT, nullptr }, + { "", 0x0, DefFieldType::DT_INVALID, nullptr } +}; +DefMap gReanimatorDefMap = { gReanimatorDefFields, sizeof(ReanimatorDefinition), ReanimatorDefinitionConstructor }; static DefLoadResPath gDefLoadResPaths[4] = { - {"IMAGE_", ""}, {"IMAGE_", "particles/"}, {"IMAGE_REANIM_", "reanim/"}, {"IMAGE_REANIM_", "images/"}}; + { "IMAGE_", "" }, + { "IMAGE_", "particles/" }, + { "IMAGE_REANIM_", "reanim/" }, + { "IMAGE_REANIM_", "images/" } +}; void *ParticleFieldConstructor(void *thePointer) { @@ -358,7 +389,7 @@ bool DefReadFromCacheFlag(void *&theReadPtr, uint32_t *theFlag) return true; } -bool DefReadFromCacheString(void *&theReadPtr, char **theString) +bool DefReadFromCacheString(void *&theReadPtr, const char **theString) { uint32_t aLen; SMemR(theReadPtr, &aLen, sizeof(uint32_t)); @@ -430,7 +461,7 @@ bool DefMapReadFromCache(void *&theReadPtr, DefMap *theDefMap, void *theDefiniti aSucceed = DefReadFromCacheFlag(theReadPtr, (uint32_t *)aDest); break; case DefFieldType::DT_STRING: - aSucceed = DefReadFromCacheString(theReadPtr, (char **)aDest); + aSucceed = DefReadFromCacheString(theReadPtr, (const char **)aDest); break; case DefFieldType::DT_VECTOR2: aSucceed = DefReadFromCacheVector2(theReadPtr, (SexyVector2 *)aDest); @@ -500,7 +531,7 @@ uint32_t DefinitionCalcHash(DefMap *theDefMap) } void *DefinitionUncompressCompiledBuffer(const CompiledDefinitionHeader *aHeader, void *theCompressedBuffer, - size_t theCompressedBufferSize, const SexyString &theCompiledFilePath) + size_t theCompressedBufferSize, const SexyString &theCompiledFilePath) { auto sz = theCompressedBufferSize; @@ -551,7 +582,7 @@ bool DefinitionReadCompiledFile(const SexyString &theCompiledFilePath, DefMap *t void *aDataPtr = (void *)aCompiledFile.GetCompressedData(); void *anUncompressedData = - DefinitionUncompressCompiledBuffer(aHeader, aDataPtr, aCompressedSize, theCompiledFilePath); + DefinitionUncompressCompiledBuffer(aHeader, aDataPtr, aCompressedSize, theCompiledFilePath); if (anUncompressedData == nullptr) { @@ -570,7 +601,7 @@ bool DefinitionReadCompiledFile(const SexyString &theCompiledFilePath, DefMap *t if (aResult) //If it's an x86 machine, and we find original definitions, load them, then convert to the format we use currently { TodTraceAndLog("[TodLib] - Converting a Legacy Compiled Definition: \"%s\" to the New Format\n", - theCompiledFilePath.c_str()); + theCompiledFilePath.c_str()); DefinitionWriteCompiledFile(theCompiledFilePath, theDefMap, theDefinition); } return aResult; @@ -592,9 +623,9 @@ bool IsFileInPakFile(const SexyString &theFilePath) { PFILE *pFile = p_fopen(theFilePath.c_str(), "rb"); bool aIsInPak = - pFile && - !pFile - ->mFP; // The file found and opened by mPakRecordMap.find has a null pointer mFP (because it was not opened from an actual file). + pFile && + !pFile + ->mFP; // The file found and opened by mPakRecordMap.find has a null pointer mFP (because it was not opened from an actual file). if (pFile) { p_fclose(pFile); @@ -618,10 +649,14 @@ void DefinitionFillWithDefaults(DefMap *theDefMap, void *theDefinition) { memset(theDefinition, NULL, theDefMap->mDefSize); // Initialize theDefinition to 0. for (DefField *aField = theDefMap->mMapFields; *aField->mFieldName != '\0'; - aField++) // Iterate through each member variable of theDefinition + aField++) + { if (aField->mFieldType == DefFieldType::DT_STRING) - *(char **)((uintptr_t)theDefinition + aField->mFieldOffset) = - ""; // Assign all char* member variables to pointers to empty character arrays. + { + *(const char **)((uintptr_t)theDefinition + aField->mFieldOffset) = + ""; + } + } } void DefinitionXmlError(XMLParser *theXmlParser, const char *theFormat, ...) @@ -634,7 +669,7 @@ void DefinitionXmlError(XMLParser *theXmlParser, const char *theFormat, ...) int aLine = theXmlParser->GetCurrentLineNum(); std::string aFileName = theXmlParser->GetFileName(); TodTraceAndLog("[TodLib] - %s(%d): XML Definition Error: %s\n", aFileName.c_str(), aLine, - aFormattedMessage.c_str()); + aFormattedMessage.c_str()); } bool DefinitionReadXMLString(XMLParser *theXmlParser, SexyString &theValue) @@ -648,9 +683,9 @@ bool DefinitionReadXMLString(XMLParser *theXmlParser, SexyString &theValue) if (aXMLElement.mType == XMLElement::TYPE_END) // Processing ends when the end tag is read. return true; else if ( - aXMLElement.mType != - XMLElement:: - TYPE_ELEMENT) // Apart from the closing tag, under normal circumstances, the content read here should be the defined main text. + aXMLElement.mType != + XMLElement:: + TYPE_ELEMENT) // Apart from the closing tag, under normal circumstances, the content read here should be the defined main text. { DefinitionXmlError(theXmlParser, "unknown element type"); return false; @@ -761,7 +796,7 @@ bool DefinitionReadArrayField(XMLParser *theXmlParser, DefinitionArrayDef *theAr { // When theArray already contains elements, and the number of elements is a power of 2. if (theArray->mArrayCount >= 1 && - (theArray->mArrayCount == 1 || (theArray->mArrayCount & (theArray->mArrayCount - 1)) == 0)) + (theArray->mArrayCount == 1 || (theArray->mArrayCount & (theArray->mArrayCount - 1)) == 0)) { void *anNewData = DefinitionAlloc(2 * theArray->mArrayCount * aDefMap->mDefSize); @@ -773,7 +808,7 @@ bool DefinitionReadArrayField(XMLParser *theXmlParser, DefinitionArrayDef *theAr } if (DefinitionLoadMap(theXmlParser, aDefMap, - (unsigned char *)theArray->mArrayData + aDefMap->mDefSize * (theArray->mArrayCount - 1))) + (unsigned char *)theArray->mArrayData + aDefMap->mDefSize * (theArray->mArrayCount - 1))) return true; DefinitionXmlError(theXmlParser, "failed to read sub def"); @@ -781,18 +816,18 @@ bool DefinitionReadArrayField(XMLParser *theXmlParser, DefinitionArrayDef *theAr } DefSymbol gDefTrackEaseSymbols[] = { - {TodCurves::CURVE_EASE_IN_OUT_WEAK, "EaseInOutWeak"}, - {TodCurves::CURVE_FAST_IN_OUT_WEAK, "FastInOutWeak"}, - {TodCurves::CURVE_EASE_IN_OUT, "EaseInOut"}, - {TodCurves::CURVE_FAST_IN_OUT, "FastInOut"}, - {TodCurves::CURVE_EASE_IN, "EaseIn"}, - {TodCurves::CURVE_EASE_OUT, "EaseOut"}, - {TodCurves::CURVE_EASE_SIN_WAVE, "EaseSinWave"}, - {TodCurves::CURVE_BOUNCE_FAST_MIDDLE, "BounceFastMiddle"}, - {TodCurves::CURVE_BOUNCE_SLOW_MIDDLE, "BounceSlowMiddle"}, - {TodCurves::CURVE_BOUNCE, "Bounce"}, - {TodCurves::CURVE_SIN_WAVE, "SinWave"}, - {TodCurves::CURVE_LINEAR, "Linear"}, + { TodCurves::CURVE_EASE_IN_OUT_WEAK, "EaseInOutWeak" }, + { TodCurves::CURVE_FAST_IN_OUT_WEAK, "FastInOutWeak" }, + { TodCurves::CURVE_EASE_IN_OUT, "EaseInOut" }, + { TodCurves::CURVE_FAST_IN_OUT, "FastInOut" }, + { TodCurves::CURVE_EASE_IN, "EaseIn" }, + { TodCurves::CURVE_EASE_OUT, "EaseOut" }, + { TodCurves::CURVE_EASE_SIN_WAVE, "EaseSinWave" }, + { TodCurves::CURVE_BOUNCE_FAST_MIDDLE, "BounceFastMiddle" }, + { TodCurves::CURVE_BOUNCE_SLOW_MIDDLE, "BounceSlowMiddle" }, + { TodCurves::CURVE_BOUNCE, "Bounce" }, + { TodCurves::CURVE_SIN_WAVE, "SinWave" }, + { TodCurves::CURVE_LINEAR, "Linear" }, }; // Read FloatTrackField from Definition XML @@ -844,7 +879,7 @@ bool DefinitionReadFloatTrackField(XMLParser *theXmlParser, FloatParameterTrack { size_t aStrLen = strlen(gDefTrackEaseSymbols[i].mSymbolName); if (strncmp(gDefTrackEaseSymbols[i].mSymbolName, aStringChars + anIdx, aStrLen) == - 0) // could be the distribution? + 0) // could be the distribution? { aTrackNode.mDistribution = (TodCurves)gDefTrackEaseSymbols[i].mSymbolValue; anIdx += aStrLen + 1; // Accounts for space (' '), expressions never end with a curve @@ -977,7 +1012,7 @@ bool DefinitionReadFloatTrackField(XMLParser *theXmlParser, FloatParameterTrack } bool DefinitionReadFlagField(XMLParser *theXmlParser, const SexyString &theElementName, uintptr_t *theResultValue, - DefSymbol *theSymbolMap) + DefSymbol *theSymbolMap) { int aValue; if (!DefSymbolValueFromString(theSymbolMap, theElementName.c_str(), &aValue)) @@ -1016,7 +1051,7 @@ bool DefinitionReadImageField(XMLParser *theXmlParser, Image **theImage) return true; std::string aMessgae = - StrFormat("Failed to find image '%s' in %s", aStringValue.c_str(), theXmlParser->GetFileName().c_str()); + StrFormat("Failed to find image '%s' in %s", aStringValue.c_str(), theXmlParser->GetFileName().c_str()); TodErrorMessageBox(aMessgae.c_str(), "Missing image"); return false; } @@ -1031,7 +1066,7 @@ bool DefinitionReadFontField(XMLParser *theXmlParser, Font **theFont) return true; std::string aMessgae = - StrFormat("Failed to find font '%s' in %s", aStringValue.c_str(), theXmlParser->GetFileName().c_str()); + StrFormat("Failed to find font '%s' in %s", aStringValue.c_str(), theXmlParser->GetFileName().c_str()); TodErrorMessageBox(aMessgae.c_str(), "Missing font"); return false; } @@ -1054,8 +1089,8 @@ bool DefinitionReadField(XMLParser *theXmlParser, DefMap *theDefMap, void *theDe return true; } if (aXMLElement.mType != - XMLElement:: - TYPE_START) // Normally, the start tag should be read here, while other content is read in subsequent corresponding functions. + XMLElement:: + TYPE_START) // Normally, the start tag should be read here, while other content is read in subsequent corresponding functions. { DefinitionXmlError(theXmlParser, "Missing element start"); return false; @@ -1065,12 +1100,12 @@ bool DefinitionReadField(XMLParser *theXmlParser, DefMap *theDefMap, void *theDe { void *pVar = (void *)((uintptr_t)theDefinition + aField->mFieldOffset); if (aField->mFieldType == DefFieldType::DT_FLAGS && - DefinitionReadFlagField(theXmlParser, aXMLElement.mValue, (uintptr_t *)pVar, - (DefSymbol *)aField->mExtraData)) + DefinitionReadFlagField(theXmlParser, aXMLElement.mValue, (uintptr_t *)pVar, + (DefSymbol *)aField->mExtraData)) return true; if (stricmp(aXMLElement.mValue.c_str(), aField->mFieldName) == - 0) // Determine if aXMLElement is defined as the member variable. + 0) // Determine if aXMLElement is defined as the member variable. { bool aSuccess = false; switch (aField->mFieldType) @@ -1114,7 +1149,7 @@ bool DefinitionReadField(XMLParser *theXmlParser, DefMap *theDefMap, void *theDe } } DefinitionXmlError(theXmlParser, "Ignoring unknown element '%s'", - aXMLElement.mValue.c_str()); // When no member variables are defined in aXMLElement + aXMLElement.mValue.c_str()); // When no member variables are defined in aXMLElement return false; } @@ -1280,7 +1315,7 @@ bool DefinitionWriteCompiledFile(const SexyString &theCompiledFilePath, DefMap * uLongf aCompressedSize = compressBound(aCompiler.mBuffer.size()); void *aCompressedData = DefinitionAlloc(aCompressedSize); int res = compress((Bytef *)aCompressedData, &aCompressedSize, (Bytef *)aCompiler.mBuffer.data(), - aHeader.mUncompressedSize); + aHeader.mUncompressedSize); if (res != Z_OK) { @@ -1299,7 +1334,7 @@ bool DefinitionWriteCompiledFile(const SexyString &theCompiledFilePath, DefMap * } bool DefinitionCompileFile(const SexyString theXMLFilePath, const SexyString &theCompiledFilePath, DefMap *theDefMap, - void *theDefinition) + void *theDefinition) { XMLParser aXMLParser; if (!aXMLParser.OpenFile(theXMLFilePath)) @@ -1334,8 +1369,8 @@ bool DefinitionCompileAndLoad(const SexyString &theXMLFilePath, DefMap *theDefMa PerfTimer aTimer; aTimer.Start(); bool aResult = - DefinitionCompileFile(theXMLFilePath, "fresh_" + aCompiledFilePath, theDefMap, - theDefinition); //write to fresh_compiled to not overwrite on game re-compile by accident + DefinitionCompileFile(theXMLFilePath, "fresh_" + aCompiledFilePath, theDefMap, + theDefinition); //write to fresh_compiled to not overwrite on game re-compile by accident TodTraceAndLog("[TodLib] - compile %d ms:'%s'", (int)aTimer.GetDuration(), aCompiledFilePath.c_str()); TodHesitationTrace("compiled %s", aCompiledFilePath.c_str()); if (aResult) @@ -1352,7 +1387,7 @@ float FloatTrackEvaluate(FloatParameterTrack &theTrack, float theTimeValue, floa if (theTimeValue < theTrack.mNodes[0].mTime) // If the current time is less than the start time of the first node return TodCurveEvaluate(theInterp, theTrack.mNodes[0].mLowValue, theTrack.mNodes[0].mHighValue, - theTrack.mNodes[0].mDistribution); + theTrack.mNodes[0].mDistribution); for (int i = 1; i < theTrack.mCountNodes; i++) { @@ -1363,24 +1398,24 @@ float FloatTrackEvaluate(FloatParameterTrack &theTrack, float theTimeValue, floa // Calculate the progress from the current node to the next node at the current time. float aTimeFraction = (theTimeValue - aNodeCur->mTime) / (aNodeNxt->mTime - aNodeCur->mTime); float aLeftValue = - TodCurveEvaluate(theInterp, aNodeCur->mLowValue, aNodeCur->mHighValue, aNodeCur->mDistribution); + TodCurveEvaluate(theInterp, aNodeCur->mLowValue, aNodeCur->mHighValue, aNodeCur->mDistribution); float aRightValue = - TodCurveEvaluate(theInterp, aNodeNxt->mLowValue, aNodeNxt->mHighValue, aNodeNxt->mDistribution); + TodCurveEvaluate(theInterp, aNodeNxt->mLowValue, aNodeNxt->mHighValue, aNodeNxt->mDistribution); return TodCurveEvaluate(aTimeFraction, aLeftValue, aRightValue, aNodeCur->mCurveType); } } FloatParameterTrackNode *aLastNode = - &theTrack - .mNodes[theTrack.mCountNodes - 1]; // If the current time is greater than the start time of the last node + &theTrack + .mNodes[theTrack.mCountNodes - 1]; // If the current time is greater than the start time of the last node return TodCurveEvaluate(theInterp, aLastNode->mLowValue, aLastNode->mHighValue, aLastNode->mDistribution); } void FloatTrackSetDefault(FloatParameterTrack &theTrack, float theValue) { if (theTrack.mNodes == nullptr && - theValue != - 0.0f) // Ensure that this parameter has no nodes (has not been assigned a value) and that the given default value is not 0. + theValue != + 0.0f) // Ensure that this parameter has no nodes (has not been assigned a value) and that the given default value is not 0. { theTrack.mCountNodes = 1; // The default parameter track has exactly one node. FloatParameterTrackNode *aNode = (FloatParameterTrackNode *)DefinitionAlloc(sizeof(FloatParameterTrackNode)); @@ -1402,7 +1437,7 @@ bool FloatTrackIsConstantZero(FloatParameterTrack &theTrack) { // When a track has no nodes, or has only one node whose maximum and minimum values ​​are both 0, the values ​​on that track are considered to be always zero. return theTrack.mCountNodes == 0 || - (theTrack.mCountNodes == 1 && theTrack.mNodes[0].mLowValue == 0.0f && theTrack.mNodes[0].mHighValue == 0.0f); + (theTrack.mCountNodes == 1 && theTrack.mNodes[0].mLowValue == 0.0f && theTrack.mNodes[0].mHighValue == 0.0f); } float FloatTrackEvaluateFromLastTime(FloatParameterTrack &theTrack, float theTimeValue, float theInterp) @@ -1414,8 +1449,8 @@ void DefinitionFreeArrayField(DefinitionArrayDef *theArray, DefMap *theDefMap) { for (int i = 0; i < theArray->mArrayCount; i++) DefinitionFreeMap(theDefMap, - (void *)((uintptr_t)theArray->mArrayData + - theDefMap->mDefSize * i)); // The last parameter represents pData[i]. + (void *)((uintptr_t)theArray->mArrayData + + theDefMap->mDefSize * i)); // The last parameter represents pData[i]. DefinitionFree(theArray->mArrayData); } diff --git a/src/Sexy.TodLib/Definition.h b/src/Sexy.TodLib/Definition.h index cc224560..39ec2134 100644 --- a/src/Sexy.TodLib/Definition.h +++ b/src/Sexy.TodLib/Definition.h @@ -40,7 +40,7 @@ enum class DefFieldType : int class DefSymbol { public: - int mSymbolValue; // The value of the flag bit or the numerical value corresponding to the enumeration item; if it is -1, it means that the item does not exist. + int mSymbolValue; // The value of the flag bit or the numerical value corresponding to the enumeration item; if it is -1, it means that the item does not exist. const char *mSymbolName; // The flag or the name of the enumeration item, when a null pointer indicates that the item does not exist, is used as a marker to indicate the end of the read. }; extern DefSymbol gParticleFlagSymbols[]; @@ -55,15 +55,15 @@ extern DefSymbol gParticleTypeSymbols[]; class DefField { public: - const char *mFieldName; // The name of _MemVar. Pointing to an empty character array indicates that this variable does not exist, and is therefore used as a marker to indicate the end of reading. - int mFieldOffset; // Offset within the class (understand in conjunction with assembly language) + const char *mFieldName; // The name of _MemVar. Pointing to an empty character array indicates that this variable does not exist, and is therefore used as a marker to indicate the end of reading. + int mFieldOffset; // Offset within the class (understand in conjunction with assembly language) DefFieldType mFieldType; // *_MemVar The data storage type varies, and the reading method also differs for different types of data. - void *mExtraData; // Additional data. Used for deep copying pointer variables contained in *_MemVar. - // If _MemVar is a pointer variable pointing to other defined data, then mExtraData is a pointer to the definition structure diagram of the class defined by _MemVar; - // If _MemVar is data of a flag or enumeration type, then mExtraData is a pointer to an array of DefSymbol arrays for each of its flag data; otherwise, mExtraData is a null pointer. - // Although by using the definition structure diagram of a _DefClass class, it is possible to read all the data of the _DefClass through relevant functions (i.e., perform a shallow copy). - // However, the data pointed to by some pointer variables in _DefClass still needs to be recursively read (i.e., deep copied) based on the definition structure diagram of the corresponding type. - // In other words, by using a nested definition structure diagram, the pointers of various types of variables that originally had hierarchical relationships are "expanded" until there are no pointers in the current variable's data that can be "expanded", at which point the recursive reading ends. + void *mExtraData; // Additional data. Used for deep copying pointer variables contained in *_MemVar. + // If _MemVar is a pointer variable pointing to other defined data, then mExtraData is a pointer to the definition structure diagram of the class defined by _MemVar; + // If _MemVar is data of a flag or enumeration type, then mExtraData is a pointer to an array of DefSymbol arrays for each of its flag data; otherwise, mExtraData is a null pointer. + // Although by using the definition structure diagram of a _DefClass class, it is possible to read all the data of the _DefClass through relevant functions (i.e., perform a shallow copy). + // However, the data pointed to by some pointer variables in _DefClass still needs to be recursively read (i.e., deep copied) based on the definition structure diagram of the corresponding type. + // In other words, by using a nested definition structure diagram, the pointers of various types of variables that originally had hierarchical relationships are "expanded" until there are no pointers in the current variable's data that can be "expanded", at which point the recursive reading ends. }; // ==================================================================================================== @@ -75,8 +75,8 @@ class DefMap { public: DefField - *mMapFields; // An array of structure fields, recording the structure of each member variable in the _DefClass class within _DefClass (each record represents one structure). - int mDefSize; // The memory size occupied by a _DefClass instance, which is also the length of the initial read, is typically sizeof(_DefClass). + *mMapFields; // An array of structure fields, recording the structure of each member variable in the _DefClass class within _DefClass (each record represents one structure). + int mDefSize; // The memory size occupied by a _DefClass instance, which is also the length of the initial read, is typically sizeof(_DefClass). void *(*mConstructorFunc)(void *); // A pointer to the constructor of an instance of type _DefClass. }; @@ -118,9 +118,9 @@ class DefinitionArrayDef public: void *mArrayData; // An array consisting of instances of a specific defined data type, such as the "track" definition in an animation definition. int mArrayCount; // The size of the array, such as the number of "tracks" in an animation definition or the number of "emitters" in a particle system definition. - // Define a combination of "array (pointer) + quantity" in the data class, which will be treated as a DefinitionArrayDef structure by DefField when read. - // For example, *mEmitterDefs and mEmitterDefCount under TodParticleDefinition, and *mParticleFields and mParticleFieldCount under TodEmitterDefinition. - // During reading, data items in mArrayCount are always correctly read on the first read (because they are integers), and therefore will also serve as a verification reference during the subsequent repair process of mArrayData. + // Define a combination of "array (pointer) + quantity" in the data class, which will be treated as a DefinitionArrayDef structure by DefField when read. + // For example, *mEmitterDefs and mEmitterDefCount under TodParticleDefinition, and *mParticleFields and mParticleFieldCount under TodEmitterDefinition. + // During reading, data items in mArrayCount are always correctly read on the first read (because they are integers), and therefore will also serve as a verification reference during the subsequent repair process of mArrayData. }; // ==================================================================================================== @@ -131,7 +131,7 @@ class DefinitionArrayDef class DefLoadResPath { public: - const char *mPrefix; // Image prefixes, such as "IMAGE_" + const char *mPrefix; // Image prefixes, such as "IMAGE_" const char *mDirectory; // The folder containing the textures corresponding to the prefix, such as "images\". }; @@ -151,30 +151,30 @@ bool DefinitionReadVector2Field(XMLParser *theXmlParser, SexyVector2 *theValue); bool DefinitionReadArrayField(XMLParser *theXmlParser, DefinitionArrayDef *theArray, DefField *theField); bool DefinitionReadFloatTrackField(XMLParser *theXmlParser, FloatParameterTrack *theTrack); bool DefinitionReadFlagField(XMLParser *theXmlParser, - const SexyString &theElementName, - uintptr_t *theResultValue, - DefSymbol *theSymbolMap); + const SexyString &theElementName, + uintptr_t *theResultValue, + DefSymbol *theSymbolMap); bool DefinitionReadImageField(XMLParser *theXmlParser, Image **theImage); bool DefinitionReadFontField(XMLParser *theXmlParser, Font **theFont); bool DefinitionReadField(XMLParser *theXmlParser, DefMap *theDefMap, void *theDefinition, bool *theDone); bool DefinitionWriteCompiledFile(const SexyString &theCompiledFilePath, DefMap *theDefMap, void *theDefinition); bool DefinitionCompileFile(const SexyString theXMLFilePath, - const SexyString &theCompiledFilePath, - DefMap *theDefMap, - void *theDefinition); + const SexyString &theCompiledFilePath, + DefMap *theDefMap, + void *theDefinition); void *DefinitionAlloc(int theSize); void DefinitionFree(void *&theMemory); void *DefinitionUncompressCompiledBuffer(const CompiledDefinitionHeader *aHeader, - void *theCompressedBuffer, - size_t theCompressedBufferSize, - const SexyString &theCompiledFilePath); + void *theCompressedBuffer, + size_t theCompressedBufferSize, + const SexyString &theCompiledFilePath); uint32_t /*__cdecl*/ DefinitionCalcHashSymbolMap(int aSchemaHash, DefSymbol *theSymbolMap); uint32_t /*__cdecl*/ DefinitionCalcHashDefMap(int aSchemaHash, DefMap *theDefMap, TodList &theProgressMaps); uint32_t /*__cdecl*/ DefinitionCalcHash(DefMap *theDefMap); bool DefReadFromCacheInt(void *&theReadPtr, int *theInt); bool DefReadFromCacheFloat(void *&theReadPtr, float *theFloat); bool DefReadFromCacheFlag(void *&theReadPtr, uint32_t *theFlag); -bool DefReadFromCacheString(void *&theReadPtr, char **theString); +bool DefReadFromCacheString(void *&theReadPtr, const char **theString); bool DefReadFromCacheVector2(void *&theReadPtr, SexyVector2 *theVector); bool DefReadFromCacheArray(void *&theReadPtr, DefinitionArrayDef *theArray, DefMap *theDefMap); bool DefReadFromCacheImage(void *&theReadPtr, Image **theImage); diff --git a/src/Sexy.TodLib/OriginalCompiledDefinition.cpp b/src/Sexy.TodLib/OriginalCompiledDefinition.cpp index eb00f4c0..f181365a 100644 --- a/src/Sexy.TodLib/OriginalCompiledDefinition.cpp +++ b/src/Sexy.TodLib/OriginalCompiledDefinition.cpp @@ -6,12 +6,11 @@ #include "../SexyAppFramework/PerfTimer.h" #include - bool LegacyDefinition::DefReadFromCacheArray(void *&theReadPtr, DefinitionArrayDef *theArray, DefMap *theDefMap) { int aDefSize; SMemR(theReadPtr, &aDefSize, sizeof(int)); // First read an integer representing the size of the definition struct class described by theDefMap - if (aDefSize != theDefMap->mDefSize) // Compare it with the size declared by the currently given definition struct map to check whether they match + if (aDefSize != theDefMap->mDefSize) // Compare it with the size declared by the currently given definition struct map to check whether they match { TodTrace("[TodLib] - cache has old def: array size"); return false; @@ -25,7 +24,7 @@ bool LegacyDefinition::DefReadFromCacheArray(void *&theReadPtr, DefinitionArrayD SMemR(theReadPtr, pData, aArraySize); // Still a rough read of all the data, then fix the pointers according to theDefMap's struct field array for (int i = 0; i < theArray->mArrayCount; i++) if (!LegacyDefinition::DefMapReadFromCache( - theReadPtr, theDefMap, (void *)((int)pData + theDefMap->mDefSize * i))) // The last argument represents pData[i] + theReadPtr, theDefMap, (void *)((int)pData + theDefMap->mDefSize * i))) // The last argument represents pData[i] return false; return true; } @@ -44,7 +43,7 @@ bool LegacyDefinition::DefReadFromCacheFloatTrack(void *&theReadPtr, FloatParame return true; } -bool LegacyDefinition::DefReadFromCacheString(void *&theReadPtr, char **theString) +bool LegacyDefinition::DefReadFromCacheString(void *&theReadPtr, const char **theString) { int aLen; SMemR(theReadPtr, &aLen, sizeof(int)); @@ -64,9 +63,9 @@ bool LegacyDefinition::DefReadFromCacheString(void *&theReadPtr, char **theStrin bool LegacyDefinition::DefReadFromCacheImage(void *&theReadPtr, Image **theImage) { int aLen; - SMemR(theReadPtr, &aLen, sizeof(int)); // Read the length of the image label character array + SMemR(theReadPtr, &aLen, sizeof(int)); // Read the length of the image label character array char *aImageName = (char *)_alloca(aLen + 1); // Allocate memory space for the image label character array on the stack - SMemR(theReadPtr, aImageName, aLen); // Read the image label character array + SMemR(theReadPtr, aImageName, aLen); // Read the image label character array aImageName[aLen] = '\0'; *theImage = nullptr; @@ -76,9 +75,9 @@ bool LegacyDefinition::DefReadFromCacheImage(void *&theReadPtr, Image **theImage bool LegacyDefinition::DefReadFromCacheFont(void *&theReadPtr, Font **theFont) { int aLen; - SMemR(theReadPtr, &aLen, sizeof(int)); // Read the length of the font label character array + SMemR(theReadPtr, &aLen, sizeof(int)); // Read the length of the font label character array char *aFontName = (char *)_alloca(aLen + 1); // Allocate memory space for the font label character array on the stack - SMemR(theReadPtr, aFontName, aLen); // Read the font label character array + SMemR(theReadPtr, aFontName, aLen); // Read the font label character array aFontName[aLen] = '\0'; *theFont = nullptr; @@ -95,7 +94,7 @@ bool LegacyDefinition::DefMapReadFromCache(void *&theReadPtr, DefMap *theDefMap, switch (aField->mFieldType) { case DefFieldType::DT_STRING: - aSucceed = LegacyDefinition::DefReadFromCacheString(theReadPtr, (char **)aDest); + aSucceed = LegacyDefinition::DefReadFromCacheString(theReadPtr, (const char **)aDest); break; case DefFieldType::DT_ARRAY: aSucceed = LegacyDefinition::DefReadFromCacheArray(theReadPtr, (DefinitionArrayDef *)aDest, (DefMap *)aField->mExtraData); @@ -129,8 +128,8 @@ uint32_t LegacyDefinition::DefinitionCalcHashSymbolMap(int aSchemaHash, DefSymbo } uint32_t LegacyDefinition::DefinitionCalcHashDefMap(int aSchemaHash, - DefMap *theDefMap, - TodList &theProgressMaps) + DefMap *theDefMap, + TodList &theProgressMaps) { for (TodListNode *aNode = theProgressMaps.mHead; aNode != nullptr; aNode = aNode->mNext) if (aNode->mValue == theDefMap) @@ -160,7 +159,7 @@ uint32_t LegacyDefinition::DefinitionCalcHash(DefMap *theDefMap) { TodList aProgressMaps; uint32_t aResult = - LegacyDefinition::DefinitionCalcHashDefMap(crc32(0L, (Bytef *)Z_NULL, NULL) + 1, theDefMap, aProgressMaps); + LegacyDefinition::DefinitionCalcHashDefMap(crc32(0L, (Bytef *)Z_NULL, NULL) + 1, theDefMap, aProgressMaps); return aResult; } @@ -171,14 +170,14 @@ bool LegacyDefinition::DefinitionReadCompiledFile(const SexyString &theCompiledF PFILE *pFile = p_fopen(theCompiledFilePath.c_str(), "rb"); if (pFile) { - p_fseek(pFile, 0, 2); // Move the pointer to the read location to the end of the file + p_fseek(pFile, 0, 2); // Move the pointer to the read location to the end of the file size_t aCompressedSize = p_ftell(pFile); // The offset obtained at this time is the size of the entire file - p_fseek(pFile, 0, 0); // Then move the pointer to the read position back to the beginning of the file + p_fseek(pFile, 0, 0); // Then move the pointer to the read position back to the beginning of the file void *aCompressedBuffer = DefinitionAlloc(aCompressedSize); // Read the file, and determine whether the actual read size is the complete file size, if it is not equal, it is determined that the read failed bool aReadCompressedFailed = - p_fread(aCompressedBuffer, sizeof(char), aCompressedSize, pFile) != aCompressedSize; - p_fclose(pFile); // Close the resource file stream and free up the memory occupied by pFile + p_fread(aCompressedBuffer, sizeof(char), aCompressedSize, pFile) != aCompressedSize; + p_fclose(pFile); // Close the resource file stream and free up the memory occupied by pFile if (aReadCompressedFailed) // Determine whether the reading is successful { TodTrace("[TodLib] - Failed to read compiled file: %s\n", theCompiledFilePath.c_str()); @@ -188,16 +187,16 @@ bool LegacyDefinition::DefinitionReadCompiledFile(const SexyString &theCompiledF { size_t aUncompressedSize; void *aUncompressedBuffer = LegacyDefinition::DefinitionUncompressCompiledBuffer( - aCompressedBuffer, aCompressedSize, aUncompressedSize, theCompiledFilePath); + aCompressedBuffer, aCompressedSize, aUncompressedSize, theCompiledFilePath); DefinitionFree(aCompressedBuffer); if (aUncompressedBuffer) { uint32_t aDefHash = LegacyDefinition::DefinitionCalcHash( - theDefMap); // Calculate the CRC check value, which will be used to detect the integrity of the data + theDefMap); // Calculate the CRC check value, which will be used to detect the integrity of the data if (aUncompressedSize < - theDefMap->mDefSize + - sizeof( - uint32_t)) // Detect whether the length of the decompressed data is sufficient for the length of "define data + a check value to record data" + theDefMap->mDefSize + + sizeof( + uint32_t)) // Detect whether the length of the decompressed data is sufficient for the length of "define data + a check value to record data" TodTrace("[TodLib] - Compiled file size too small: %s\n", theCompiledFilePath.c_str()); else { @@ -206,7 +205,7 @@ bool LegacyDefinition::DefinitionReadCompiledFile(const SexyString &theCompiledF uint32_t aCashHash; SMemR(aBufferPtr, &aCashHash, sizeof(uint32_t)); //Read the CRC check value of the record if (aCashHash != - aDefHash) // Determine whether the check value is consistent, if it is inconsistent, the data is wrong + aDefHash) // Determine whether the check value is consistent, if it is inconsistent, the data is wrong TodTrace("[TodLib] - Compiled file schema wrong: %s\n", theCompiledFilePath.c_str()); else { @@ -232,9 +231,9 @@ bool LegacyDefinition::DefinitionReadCompiledFile(const SexyString &theCompiledF } void *LegacyDefinition::DefinitionUncompressCompiledBuffer(void *theCompressedBuffer, - size_t theCompressedBufferSize, - size_t &theUncompressedSize, - const SexyString &theCompiledFilePath) + size_t theCompressedBufferSize, + size_t &theUncompressedSize, + const SexyString &theCompiledFilePath) { auto sz = theCompressedBufferSize; // theCompressedBuffer The first two four-byte bytes contain special data, and this check verifies whether its length is sufficient for 8 bytes (i.e., 2 four-byte bytes). @@ -253,11 +252,11 @@ void *LegacyDefinition::DefinitionUncompressCompiledBuffer(void *theCompressedBu Bytef *aUncompressedBuffer = (Bytef *)DefinitionAlloc(aHeader->mUncompressedSize); theCompressedBufferSize = aHeader->mUncompressedSize; //my addition Bytef *aSrc = (Bytef *)theCompressedBuffer + - sizeof(LegacyDefinition::CompressedDefinitionHeader); // The actual data to decompress starts at the 3rd four-byte word + sizeof(LegacyDefinition::CompressedDefinitionHeader); // The actual data to decompress starts at the 3rd four-byte word int aResult = uncompress(aUncompressedBuffer, - (uLongf *)&theCompressedBufferSize, - aSrc, - sz - sizeof(LegacyDefinition::CompressedDefinitionHeader)); + (uLongf *)&theCompressedBufferSize, + aSrc, + sz - sizeof(LegacyDefinition::CompressedDefinitionHeader)); TOD_ASSERT(aResult == Z_OK); TOD_ASSERT(theCompressedBufferSize == aHeader->mUncompressedSize); theUncompressedSize = aHeader->mUncompressedSize; diff --git a/src/Sexy.TodLib/OriginalCompiledDefinition.h b/src/Sexy.TodLib/OriginalCompiledDefinition.h index 268c9696..3c82aa6c 100644 --- a/src/Sexy.TodLib/OriginalCompiledDefinition.h +++ b/src/Sexy.TodLib/OriginalCompiledDefinition.h @@ -17,30 +17,29 @@ class FloatParameterTrack; namespace LegacyDefinition { - // ==================================================================================================== - // Compress definition data header - // ---------------------------------------------------------------------------------------------------- - // Add a compression definition header before the compressed data to record the verification cache value and the original data length, which is used to check data integrity during decompression. - // ==================================================================================================== - class CompressedDefinitionHeader - { - public: - unsigned int mCookie; // Cache values ​​used for compression verification - unsigned long mUncompressedSize; // Length of uncompressed data - }; - - bool DefinitionReadCompiledFile(const SexyString &theCompiledFilePath, DefMap *theDefMap, void *theDefinition); - void *DefinitionUncompressCompiledBuffer(void *theCompressedBuffer, size_t theCompressedBufferSize, size_t &theUncompressedSize, const SexyString &theCompiledFilePath); - uint32_t DefinitionCalcHashSymbolMap(int aSchemaHash, DefSymbol *theSymbolMap); - uint32_t DefinitionCalcHashDefMap(int aSchemaHash, DefMap *theDefMap, TodList &theProgressMaps); - uint32_t DefinitionCalcHash(DefMap *theDefMap); - bool DefReadFromCacheString(void *&theReadPtr, char **theString); - bool DefReadFromCacheArray(void *&theReadPtr, DefinitionArrayDef *theArray, DefMap *theDefMap); - bool DefReadFromCacheImage(void *&theReadPtr, Image **theImage); - bool DefReadFromCacheFont(void *&theReadPtr, Font **theFont); - bool DefReadFromCacheFloatTrack(void *&theReadPtr, FloatParameterTrack *theTrack); - bool DefMapReadFromCache(void *&theReadPtr, DefMap *theDefMap, void *theDefinition); -} - - -#endif \ No newline at end of file +// ==================================================================================================== +// Compress definition data header +// ---------------------------------------------------------------------------------------------------- +// Add a compression definition header before the compressed data to record the verification cache value and the original data length, which is used to check data integrity during decompression. +// ==================================================================================================== +class CompressedDefinitionHeader +{ + public: + unsigned int mCookie; // Cache values ​​used for compression verification + unsigned long mUncompressedSize; // Length of uncompressed data +}; + +bool DefinitionReadCompiledFile(const SexyString &theCompiledFilePath, DefMap *theDefMap, void *theDefinition); +void *DefinitionUncompressCompiledBuffer(void *theCompressedBuffer, size_t theCompressedBufferSize, size_t &theUncompressedSize, const SexyString &theCompiledFilePath); +uint32_t DefinitionCalcHashSymbolMap(int aSchemaHash, DefSymbol *theSymbolMap); +uint32_t DefinitionCalcHashDefMap(int aSchemaHash, DefMap *theDefMap, TodList &theProgressMaps); +uint32_t DefinitionCalcHash(DefMap *theDefMap); +bool DefReadFromCacheString(void *&theReadPtr, const char **theString); +bool DefReadFromCacheArray(void *&theReadPtr, DefinitionArrayDef *theArray, DefMap *theDefMap); +bool DefReadFromCacheImage(void *&theReadPtr, Image **theImage); +bool DefReadFromCacheFont(void *&theReadPtr, Font **theFont); +bool DefReadFromCacheFloatTrack(void *&theReadPtr, FloatParameterTrack *theTrack); +bool DefMapReadFromCache(void *&theReadPtr, DefMap *theDefMap, void *theDefinition); +} // namespace LegacyDefinition + +#endif diff --git a/src/Sexy.TodLib/TodList.h b/src/Sexy.TodLib/TodList.h index 5886f01c..494db4d2 100644 --- a/src/Sexy.TodLib/TodList.h +++ b/src/Sexy.TodLib/TodList.h @@ -4,6 +4,7 @@ #define MAX_GLOBAL_ALLOCATORS 128 #include "TodDebug.h" +#include "TodCommon.h" struct TodAllocator { @@ -26,7 +27,8 @@ struct TodAllocator extern int gNumGlobalAllocators; extern TodAllocator gGlobalAllocators[MAX_GLOBAL_ALLOCATORS]; -template class TodListNode +template +class TodListNode { public: T mValue; @@ -34,7 +36,8 @@ template class TodListNode TodListNode *mPrev; }; -template class TodList +template +class TodList { public: TodListNode *mHead; diff --git a/src/SexyAppFramework/BassMusicInterface.cpp b/src/SexyAppFramework/BassMusicInterface.cpp index fa3d96c0..e4c1cdf0 100644 --- a/src/SexyAppFramework/BassMusicInterface.cpp +++ b/src/SexyAppFramework/BassMusicInterface.cpp @@ -1,5 +1,4 @@ #include "BassMusicInterface.h" -#include #include "../PakLib/PakInterface.h" #include "Common.h" @@ -18,13 +17,13 @@ BassMusicInfo::BassMusicInfo() BassMusicInterface::BassMusicInterface(Window *theWindow) { BOOL success; - #ifdef _WIN32 +#ifdef _WIN32 SDL_PropertiesID props = SDL_GetWindowProperties(theWindow->mInternalWindow); HWND aHWND = theWindow->GetHWND(); success = BASS_Init(1, 44100, 0, aHWND, NULL); - #else +#else success = BASS_Init(1, 44100, 0, NULL, NULL); - #endif +#endif BASS_SetConfig(BASS_CONFIG_BUFFER, 2000); BASS_SetConfig(BASS_CONFIG_FLOATDSP, TRUE); @@ -71,7 +70,6 @@ bool BassMusicInterface::LoadMusic(int theSongId, const std::string &theFileName delete[] aData; } - if (aHMusic == NULL && aStream == NULL) return false; diff --git a/src/SexyAppFramework/BassMusicInterface.h b/src/SexyAppFramework/BassMusicInterface.h index 9254a20c..d1eb8679 100644 --- a/src/SexyAppFramework/BassMusicInterface.h +++ b/src/SexyAppFramework/BassMusicInterface.h @@ -1,6 +1,12 @@ #ifndef __BASSMUSICINTERFACE_H__ #define __BASSMUSICINTERFACE_H__ +// Include windows ourselves to prevent bass.h from including windows and leak macros +// IWYU pragma: begin_exports <- this suppresses clangd warning +#include "Platform.h" +// IWYU pragma: end_exports +// this comment exists to prevent formatter from reordering this include + #include "MusicInterface.h" #include "Window.h" #include @@ -40,7 +46,7 @@ class BassMusicInterface : public MusicInterface int mMusicLoadFlags; public: - BassMusicInterface(Window* theWindow); + BassMusicInterface(Window *theWindow); virtual ~BassMusicInterface(); virtual bool LoadMusic(int theSongId, const std::string &theFileName); diff --git a/src/SexyAppFramework/HTTPTransfer.cpp b/src/SexyAppFramework/HTTPTransfer.cpp index 70c32791..6af3d699 100644 --- a/src/SexyAppFramework/HTTPTransfer.cpp +++ b/src/SexyAppFramework/HTTPTransfer.cpp @@ -1,8 +1,13 @@ +// Include windows ourselves to prevent curl.h from including windows and leak macros +// IWYU pragma: begin_exports <- this suppresses clangd warning +#include "Platform.h" +// IWYU pragma: end_exports +// this comment exists to prevent formatter from reordering this include + #include "HTTPTransfer.h" #include "SexyAppBase.h" #include - using namespace Sexy; static int gCurTransferId = 1; diff --git a/src/SexyAppFramework/SEHCatcher.cpp b/src/SexyAppFramework/SEHCatcher.cpp index eb14fbf1..4099289c 100644 --- a/src/SexyAppFramework/SEHCatcher.cpp +++ b/src/SexyAppFramework/SEHCatcher.cpp @@ -16,7 +16,7 @@ #if SEXY_USE_IMGUI #include #include //use SDL3 Renderer for the handler. -#include //use SDL3 Renderer for the handler. +#include //use SDL3 Renderer for the handler. #endif #include @@ -40,7 +40,7 @@ bool SEHCatcher::mAllowSubmit = true; std::string SEHCatcher::mCrashMessage = "An unexpected error has occured!"; std::string SEHCatcher::mSubmitHost; std::string SEHCatcher::mSubmitMessage = - "Please help out by providing as much information as you can about this crash."; + "Please help out by providing as much information as you can about this crash."; std::string SEHCatcher::mSubmitErrorMessage = "Failed to redirect to issue page."; static bool gUseDefaultFonts = true; @@ -49,37 +49,39 @@ static bool gUseDefaultFonts = true; struct { DWORD dwExceptionCode; - char *szMessage; -} gMsgTable[] = {{STATUS_SEGMENT_NOTIFICATION, "Segment Notification"}, - {STATUS_BREAKPOINT, "Breakpoint"}, - {STATUS_SINGLE_STEP, "Single step"}, - {STATUS_WAIT_0, "Wait 0"}, - {STATUS_ABANDONED_WAIT_0, "Abandoned Wait 0"}, - {STATUS_USER_APC, "User APC"}, - {STATUS_TIMEOUT, "Timeout"}, - {STATUS_PENDING, "Pending"}, - {STATUS_GUARD_PAGE_VIOLATION, "Guard Page Violation"}, - {STATUS_DATATYPE_MISALIGNMENT, "Data Type Misalignment"}, - {STATUS_ACCESS_VIOLATION, "Access Violation"}, - {STATUS_IN_PAGE_ERROR, "In Page Error"}, - {STATUS_NO_MEMORY, "No Memory"}, - {STATUS_ILLEGAL_INSTRUCTION, "Illegal Instruction"}, - {STATUS_NONCONTINUABLE_EXCEPTION, "Noncontinuable Exception"}, - {STATUS_INVALID_DISPOSITION, "Invalid Disposition"}, - {STATUS_ARRAY_BOUNDS_EXCEEDED, "Array Bounds Exceeded"}, - {STATUS_FLOAT_DENORMAL_OPERAND, "Float Denormal Operand"}, - {STATUS_FLOAT_DIVIDE_BY_ZERO, "Divide by Zero"}, - {STATUS_FLOAT_INEXACT_RESULT, "Float Inexact Result"}, - {STATUS_FLOAT_INVALID_OPERATION, "Float Invalid Operation"}, - {STATUS_FLOAT_OVERFLOW, "Float Overflow"}, - {STATUS_FLOAT_STACK_CHECK, "Float Stack Check"}, - {STATUS_FLOAT_UNDERFLOW, "Float Underflow"}, - {STATUS_INTEGER_DIVIDE_BY_ZERO, "Integer Divide by Zero"}, - {STATUS_INTEGER_OVERFLOW, "Integer Overflow"}, - {STATUS_PRIVILEGED_INSTRUCTION, "Privileged Instruction"}, - {STATUS_STACK_OVERFLOW, "Stack Overflow"}, - {STATUS_CONTROL_C_EXIT, "Ctrl+C Exit"}, - {0xFFFFFFFF, ""}}; + const char *szMessage; +} gMsgTable[] = { + { STATUS_SEGMENT_NOTIFICATION, "Segment Notification" }, + { STATUS_BREAKPOINT, "Breakpoint" }, + { STATUS_SINGLE_STEP, "Single step" }, + { STATUS_WAIT_0, "Wait 0" }, + { STATUS_ABANDONED_WAIT_0, "Abandoned Wait 0" }, + { STATUS_USER_APC, "User APC" }, + { STATUS_TIMEOUT, "Timeout" }, + { STATUS_PENDING, "Pending" }, + { STATUS_GUARD_PAGE_VIOLATION, "Guard Page Violation" }, + { STATUS_DATATYPE_MISALIGNMENT, "Data Type Misalignment" }, + { STATUS_ACCESS_VIOLATION, "Access Violation" }, + { STATUS_IN_PAGE_ERROR, "In Page Error" }, + { STATUS_NO_MEMORY, "No Memory" }, + { STATUS_ILLEGAL_INSTRUCTION, "Illegal Instruction" }, + { STATUS_NONCONTINUABLE_EXCEPTION, "Noncontinuable Exception" }, + { STATUS_INVALID_DISPOSITION, "Invalid Disposition" }, + { STATUS_ARRAY_BOUNDS_EXCEEDED, "Array Bounds Exceeded" }, + { STATUS_FLOAT_DENORMAL_OPERAND, "Float Denormal Operand" }, + { STATUS_FLOAT_DIVIDE_BY_ZERO, "Divide by Zero" }, + { STATUS_FLOAT_INEXACT_RESULT, "Float Inexact Result" }, + { STATUS_FLOAT_INVALID_OPERATION, "Float Invalid Operation" }, + { STATUS_FLOAT_OVERFLOW, "Float Overflow" }, + { STATUS_FLOAT_STACK_CHECK, "Float Stack Check" }, + { STATUS_FLOAT_UNDERFLOW, "Float Underflow" }, + { STATUS_INTEGER_DIVIDE_BY_ZERO, "Integer Divide by Zero" }, + { STATUS_INTEGER_OVERFLOW, "Integer Overflow" }, + { STATUS_PRIVILEGED_INSTRUCTION, "Privileged Instruction" }, + { STATUS_STACK_OVERFLOW, "Stack Overflow" }, + { STATUS_CONTROL_C_EXIT, "Ctrl+C Exit" }, + { 0xFFFFFFFF, "" } +}; #endif @@ -164,7 +166,7 @@ void SEHCatcher::DoHandleDebugEvent(LPEXCEPTION_POINTERS lpEP) /////////////////////////// // first name the exception - char *szName = nullptr; + const char *szName = nullptr; for (int i = 0; gMsgTable[i].dwExceptionCode != 0xFFFFFFFF; i++) { if (gMsgTable[i].dwExceptionCode == lpEP->ExceptionRecord->ExceptionCode) @@ -315,8 +317,8 @@ void SEHCatcher::ShowErrorDialog(const std::string &theErrorTitle, const std::st ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::Begin("An unexpected error has occurred!", nullptr, - ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | - ImGuiWindowFlags_NoSavedSettings); + ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoSavedSettings); ImGui::TextWrapped("%s", mCrashMessage.c_str()); ImGui::Spacing(); @@ -397,12 +399,12 @@ std::string SEHCatcher::GetSysInfo() aDebugDump += "9x "; char aVersionStr[20]; - sprintf(aVersionStr, "%d.%d", aVersionInfo.dwMajorVersion, aVersionInfo.dwMinorVersion); + sprintf(aVersionStr, "%lu.%lu", aVersionInfo.dwMajorVersion, aVersionInfo.dwMinorVersion); aDebugDump += aVersionStr; aDebugDump += " "; aDebugDump += aVersionInfo.szCSDVersion; aDebugDump += " "; - sprintf(aVersionStr, "%d", aVersionInfo.dwBuildNumber); + sprintf(aVersionStr, "%lu", aVersionInfo.dwBuildNumber); aDebugDump += "Build "; aDebugDump += aVersionStr; aDebugDump += "\n"; diff --git a/src/SexyAppFramework/SexyAppBase.cpp b/src/SexyAppFramework/SexyAppBase.cpp index ec48c652..c98db364 100644 --- a/src/SexyAppFramework/SexyAppBase.cpp +++ b/src/SexyAppFramework/SexyAppBase.cpp @@ -1,3 +1,9 @@ +// Include windows ourselves to prevent bass.h and curl.h from including windows and leak macros +// IWYU pragma: begin_exports <- this suppresses clangd warning +#include "Platform.h" +// IWYU pragma: end_exports +// this comment exists to prevent formatter from reordering this include + //#define SEXY_TRACING_ENABLED //#define SEXY_PERF_ENABLED //#define SEXY_MEMTRACE @@ -106,7 +112,8 @@ unsigned char gFingerCursorData[] = { 0xfc, 0x00, 0x00, 0xdf, 0xfc, 0x00, 0x00, 0x5f, 0xfc, 0x00, 0x00, 0x7f, 0xfc, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x3f, 0xf8, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; //HotSpot: 15 10 //Size: 32 32 @@ -124,7 +131,8 @@ unsigned char gDraggingCursorData[] = { 0xfe, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x3f, 0xfe, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; static GPUImage *gFPSImage = NULL; static SysFont *gDebugFont = nullptr; @@ -296,7 +304,7 @@ SexyAppBase::SexyAppBase() SetString("UP_TO_DATE_BODY", "There are no updates available for this product at this time."); SetString("NEW_VERSION_TITLE", "New Version"); SetString("NEW_VERSION_BODY", - "There is an update available for this product. Would you like to visit the web site to download it?"); + "There is an update available for this product. Would you like to visit the web site to download it?"); mDemoPrefix = "sexyapp"; mDemoFileName = mDemoPrefix + ".dmo"; @@ -353,18 +361,20 @@ SexyAppBase::~SexyAppBase() { showedMsgBox = true; - SDL_MessageBoxButtonData buttons[] = {{SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Yes"}, - {SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 1, "No"}}; + SDL_MessageBoxButtonData buttons[] = { + { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Yes" }, + { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 1, "No" } + }; SDL_MessageBoxData msgBoxData; msgBoxData.flags = SDL_MESSAGEBOX_WARNING; msgBoxData.title = GetString("HARDWARE_ACCEL_SWITCHED_ON", - "Hardware Acceleration was switched on during this session.\nIf this " - "resulted in slower performance,it should be switched off.\nWould " - "you like to keep Hardware Acceleration switched on?") - .c_str(); + "Hardware Acceleration was switched on during this session.\nIf this " + "resulted in slower performance,it should be switched off.\nWould " + "you like to keep Hardware Acceleration switched on?") + .c_str(); std::string aMessage = - (mCompanyName + " " + - GetString("HARDWARE_ACCEL_CONFIRMATION", "Hardware Acceleration Confirmation")); + (mCompanyName + " " + + GetString("HARDWARE_ACCEL_CONFIRMATION", "Hardware Acceleration Confirmation")); msgBoxData.message = aMessage.c_str(); msgBoxData.buttons = buttons; msgBoxData.numbuttons = 2; @@ -387,18 +397,20 @@ SexyAppBase::~SexyAppBase() if (!showedMsgBox && Renderer::gRenderingPreDrawError && !IsScreenSaver()) { - SDL_MessageBoxButtonData buttons[] = {{SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Yes"}, - {SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 1, "No"}}; + SDL_MessageBoxButtonData buttons[] = { + { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Yes" }, + { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 1, "No" } + }; SDL_MessageBoxData msgBoxData; msgBoxData.flags = SDL_MESSAGEBOX_WARNING; std::string anAntiDangle1 = - GetString("HARDWARE_ACCEL_NOT_WORKING", - "Hardware Acceleration may not have been working correctly during this session.\n" - "If you noticed graphics problems, you may want to turn off Hardware Acceleration.\n" - "Would you like to keep Hardware Acceleration switched on?"); + GetString("HARDWARE_ACCEL_NOT_WORKING", + "Hardware Acceleration may not have been working correctly during this session.\n" + "If you noticed graphics problems, you may want to turn off Hardware Acceleration.\n" + "Would you like to keep Hardware Acceleration switched on?"); msgBoxData.title = anAntiDangle1.c_str(); std::string anAntiDangle2 = - mCompanyName + " " + GetString("HARDWARE_ACCEL_CONFIRMATION", "Hardware Acceleration Confirmation"); + mCompanyName + " " + GetString("HARDWARE_ACCEL_CONFIRMATION", "Hardware Acceleration Confirmation"); msgBoxData.message = anAntiDangle2.c_str(); msgBoxData.buttons = buttons; @@ -681,7 +693,7 @@ void SexyAppBase::WriteDemoBuffer() Buffer aMarkerBuffer; aMarkerBuffer.WriteLong(mDemoMarkerList.size()); for (DemoMarkerList::iterator aMarkerItr = mDemoMarkerList.begin(); aMarkerItr != mDemoMarkerList.end(); - ++aMarkerItr) + ++aMarkerItr) { aMarkerBuffer.WriteString(aMarkerItr->first); aMarkerBuffer.WriteLong(aMarkerItr->second); @@ -912,15 +924,15 @@ void SexyAppBase::DemoAssertIntEqual(int theInt) } Dialog *SexyAppBase::NewDialog(int theDialogId, bool isModal, const SexyString &theDialogHeader, - const SexyString &theDialogLines, const SexyString &theDialogFooter, int theButtonMode) + const SexyString &theDialogLines, const SexyString &theDialogFooter, int theButtonMode) { Dialog *aDialog = - new Dialog(NULL, NULL, theDialogId, isModal, theDialogHeader, theDialogLines, theDialogFooter, theButtonMode); + new Dialog(NULL, NULL, theDialogId, isModal, theDialogHeader, theDialogLines, theDialogFooter, theButtonMode); return aDialog; } Dialog *SexyAppBase::DoDialog(int theDialogId, bool isModal, const SexyString &theDialogHeader, - const SexyString &theDialogLines, const SexyString &theDialogFooter, int theButtonMode) + const SexyString &theDialogLines, const SexyString &theDialogFooter, int theButtonMode) { KillDialog(theDialogId); @@ -1094,7 +1106,7 @@ std::string SexyAppBase::GetProductVersionDLL(const std::string &thePath) // Dynamically Load Version.dll typedef DWORD(APIENTRY * GetFileVersionInfoSizeFunc)(LPSTR lptstrFilename, LPDWORD lpdwHandle); typedef BOOL(APIENTRY * GetFileVersionInfoFunc)(LPSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData); - typedef BOOL(APIENTRY * VerQueryValueFunc)(const LPVOID pBlock, LPSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen); + typedef BOOL(APIENTRY * VerQueryValueFunc)(const LPVOID pBlock, LPCSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen); static GetFileVersionInfoSizeFunc aGetFileVersionInfoSizeFunc = NULL; static GetFileVersionInfoFunc aGetFileVersionInfoFunc = NULL; @@ -1103,7 +1115,7 @@ std::string SexyAppBase::GetProductVersionDLL(const std::string &thePath) if (aGetFileVersionInfoSizeFunc == NULL) { aGetFileVersionInfoSizeFunc = - (GetFileVersionInfoSizeFunc)GetProcAddress(gVersionDLL, "GetFileVersionInfoSizeA"); + (GetFileVersionInfoSizeFunc)GetProcAddress(gVersionDLL, "GetFileVersionInfoSizeA"); aGetFileVersionInfoFunc = (GetFileVersionInfoFunc)GetProcAddress(gVersionDLL, "GetFileVersionInfoA"); aVerQueryValueFunc = (VerQueryValueFunc)GetProcAddress(gVersionDLL, "VerQueryValueA"); } @@ -1122,12 +1134,12 @@ std::string SexyAppBase::GetProductVersionDLL(const std::string &thePath) aProductVersion = aBuffer; } else if (aVerQueryValueFunc(aVersionBuffer, "\\StringFileInfo\\040904E4\\ProductVersion", (void **)&aBuffer, - &aSize)) + &aSize)) { aProductVersion = aBuffer; - } - delete aVersionBuffer; + delete aVersionBuffer; + } } return aProductVersion; @@ -1207,7 +1219,7 @@ void SexyAppBase::DumpProgramInfo() tm *aTM = localtime(&aTime); aDumpStream << "
" << asctime(aTM) << "
" - << std::endl; + << std::endl; int anImgNum = 0; @@ -1263,7 +1275,7 @@ void SexyAppBase::DumpProgramInfo() aTextureMemory += ((TextureData *)aMemoryImage->mGPUData)->mTexMemSize; aMemorySize = aBitsMemory + aSurfaceMemory + aPalletizedMemory + aNativeAlphaMemory + aRLAlphaMemory + - aRLAdditiveMemory + aTextureMemory; + aRLAdditiveMemory + aTextureMemory; aTotalMemory += aMemorySize; aSortedImageMap.insert(SortedImageMap::value_type(aMemorySize, aMemoryImage)); @@ -1297,7 +1309,7 @@ void SexyAppBase::DumpProgramInfo() aDumpStream << "" << std::endl; aDumpStream << "" << std::endl; + << " HEIGHT=" << aThumbHeight << ">" << std::endl; int aNumPixels = aMemoryImage->mWidth * aMemoryImage->mHeight; @@ -1363,50 +1375,50 @@ void SexyAppBase::DumpProgramInfo() char aStr[256]; sprintf(aStr, "%d x %d
%s bytes", aMemoryImage->mWidth, aMemoryImage->mHeight, - CommaSeperate(aMemorySize).c_str()); + CommaSeperate(aMemorySize).c_str()); aDumpStream << "" << aStr << "" << std::endl; aDumpStream << "" - << SexyStringToString(((aBitsMemory != 0) ? "mBits
" + CommaSeperate(aBitsMemory) : " ")) - << "" << std::endl; + << SexyStringToString(((aBitsMemory != 0) ? "mBits
" + CommaSeperate(aBitsMemory) : " ")) + << "" << std::endl; aDumpStream << "" - << SexyStringToString( - ((aPalletizedMemory != 0) ? "Palletized
" + CommaSeperate(aPalletizedMemory) : " ")) - << "" << std::endl; + << SexyStringToString( + ((aPalletizedMemory != 0) ? "Palletized
" + CommaSeperate(aPalletizedMemory) : " ")) + << "" << std::endl; aDumpStream << "" - << SexyStringToString( - ((aSurfaceMemory != 0) ? "DDSurface
" + CommaSeperate(aSurfaceMemory) : " ")) - << "" << std::endl; + << SexyStringToString( + ((aSurfaceMemory != 0) ? "DDSurface
" + CommaSeperate(aSurfaceMemory) : " ")) + << "" << std::endl; aDumpStream << "" - << SexyStringToString(((aMemoryImage->mGPUData != NULL) - ? "Texture
" + StringToSexyString(aTextureFormatName) + "
" + - CommaSeperate(aTextureMemory) - : " ")) - << "" << std::endl; + << SexyStringToString(((aMemoryImage->mGPUData != NULL) + ? "Texture
" + StringToSexyString(aTextureFormatName) + "
" + + CommaSeperate(aTextureMemory) + : " ")) + << "" << std::endl; aDumpStream << "" << SexyStringToString(((aMemoryImage->mIsVolatile) ? "Volatile" : " ")) << "" - << std::endl; + << std::endl; aDumpStream << "" << SexyStringToString(((aMemoryImage->mForcedMode) ? "Forced" : " ")) << "" - << std::endl; + << std::endl; aDumpStream << "" << SexyStringToString(((aMemoryImage->mHasAlpha) ? "HasAlpha" : " ")) << "" - << std::endl; + << std::endl; aDumpStream << "" << SexyStringToString(((aMemoryImage->mHasTrans) ? "HasTrans" : " ")) << "" - << std::endl; + << std::endl; aDumpStream << "" - << SexyStringToString(((aNativeAlphaMemory != 0) - ? "NativeAlpha
" + CommaSeperate(aNativeAlphaMemory) - : " ")) - << "" << std::endl; + << SexyStringToString(((aNativeAlphaMemory != 0) + ? "NativeAlpha
" + CommaSeperate(aNativeAlphaMemory) + : " ")) + << "" << std::endl; aDumpStream << "" - << SexyStringToString( - ((aRLAlphaMemory != 0) ? "RLAlpha
" + CommaSeperate(aRLAlphaMemory) : " ")) - << "" << std::endl; + << SexyStringToString( + ((aRLAlphaMemory != 0) ? "RLAlpha
" + CommaSeperate(aRLAlphaMemory) : " ")) + << "" << std::endl; aDumpStream << "" - << SexyStringToString( - ((aRLAdditiveMemory != 0) ? "RLAdditive
" + CommaSeperate(aRLAdditiveMemory) : " ")) - << "" << std::endl; + << SexyStringToString( + ((aRLAdditiveMemory != 0) ? "RLAdditive
" + CommaSeperate(aRLAdditiveMemory) : " ")) + << "" << std::endl; aDumpStream << "" << (aMemoryImage->mFilePath.empty() ? " " : aMemoryImage->mFilePath) << "" - << std::endl; + << std::endl; aDumpStream << "" << std::endl; @@ -1428,7 +1440,7 @@ void SexyAppBase::DumpProgramInfo() } ImageLib::WriteImage((GetAppDataFolder() + std::string("_dump\\") + aThumbName).c_str(), &anImageLibImage, - ".jpeg"); + ".jpeg"); // Write high resolution image @@ -1476,7 +1488,7 @@ double SexyAppBase::GetLoadingThreadProgress() } bool SexyAppBase::RegistryWrite(const std::string &theValueName, JSONRegistryType theType, const uint8_t *theValue, - uint32_t theLength) + uint32_t theLength) { if (mPlayingDemoBuffer) { @@ -1665,13 +1677,13 @@ bool SexyAppBase::RegistryGetSubKeys(const std::string &theKeyName, StringVector } bool SexyAppBase::RegistryRead(const std::string &theValueName, JSONRegistryType *theType, uint8_t *theValue, - uint32_t *theLength) + uint32_t *theLength) { return RegistryReadKey(theValueName, theType, theValue, theLength, 0); } bool SexyAppBase::RegistryReadKey(const std::string &theValueName, JSONRegistryType *theType, uint8_t *theValue, - uint32_t *theLength, int theKey) + uint32_t *theLength, int theKey) { std::filesystem::path configPath = GetAppDataFolder() + "/registry.json"; if (!std::filesystem::exists(configPath) || !theType || !theValue || !theLength) @@ -2087,10 +2099,10 @@ std::string SexyAppBase::GetGameSEHInfo() // c++20: replace with std::format std::ostringstream aInfoStream; aInfoStream << "Product: " << mProdName << "\r\n" - << "Version: " << mProductVersion << "\r\n" - << "Time Loaded" << aTimeStr << "\r\n" - << "Fullscreen: " << (mIsWindowed ? "No" : "Yes") << "\r\n" - << "Primary ThreadId:" << mPrimaryThreadId << "\r\n"; + << "Version: " << mProductVersion << "\r\n" + << "Time Loaded" << aTimeStr << "\r\n" + << "Fullscreen: " << (mIsWindowed ? "No" : "Yes") << "\r\n" + << "Primary ThreadId:" << mPrimaryThreadId << "\r\n"; return aInfoStream.str(); } @@ -2590,7 +2602,7 @@ bool SexyAppBase::DrawDirtyStuff() if (mPlayingDemoBuffer) g.DrawImage(gDemoTimeLeftImage, mWidth - gDemoTimeLeftImage->GetWidth() - 10, - mHeight - gFPSImage->GetHeight() - gDemoTimeLeftImage->GetHeight() - 15); + mHeight - gFPSImage->GetHeight() - gDemoTimeLeftImage->GetHeight() - 15); } uint32_t aPreScreenBltTime = timeGetTime(); @@ -2717,13 +2729,13 @@ int SexyAppBase::MsgBox(const std::string &theText, const std::string &theTitle, aConvertedFlags |= SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT; if (theFlags & SexyMessageBoxFlags::MESSAGEBOX_BTN_OK) - aButtonVec.push_back({SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Ok"}); + aButtonVec.push_back({ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Ok" }); if (theFlags & SexyMessageBoxFlags::MESSAGEBOX_BTN_CANCEL) - aButtonVec.push_back({SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0, "Cancel"}); + aButtonVec.push_back({ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0, "Cancel" }); if (theFlags & SexyMessageBoxFlags::MESSAGEBOX_BTN_YES) - aButtonVec.push_back({SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Yes"}); + aButtonVec.push_back({ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Yes" }); if (theFlags & SexyMessageBoxFlags::MESSAGEBOX_BTN_NO) - aButtonVec.push_back({SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0, "No"}); + aButtonVec.push_back({ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0, "No" }); SDL_MessageBoxData msgBoxData; msgBoxData.window = nullptr; @@ -2755,7 +2767,7 @@ void SexyAppBase::Popup(const std::string &theString) BeginPopup(); if (!mShutdown) SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, GetString("FATAL_ERROR", "FATAL ERROR").c_str(), - theString.c_str(), aInternalWindow); + theString.c_str(), aInternalWindow); EndPopup(); } @@ -2790,7 +2802,7 @@ static intptr_t CALLBACK MarkerListDialogProc(HWND hwnd, UINT msg, WPARAM wParam GetClientRect(hwnd, &aRect); MoveWindow(aListBox, 10, 10, aRect.right - aRect.left - 20, aRect.bottom - aRect.top - 20, FALSE); for (SexyAppBase::DemoMarkerList::iterator anItr = gSexyAppBase->mDemoMarkerList.begin(); - anItr != gSexyAppBase->mDemoMarkerList.end(); ++anItr) + anItr != gSexyAppBase->mDemoMarkerList.end(); ++anItr) { if (anItr->second <= gSexyAppBase->mUpdateCount) continue; @@ -3388,7 +3400,7 @@ void SexyAppBase::ShowMemoryUsage() aDesc = "Unsupported"; aStr += - StrFormat("Current Rendering Backend: %s\n", gRenderBackends.find(mRenderer->mCurrentBackend)->second.c_str()); + StrFormat("Current Rendering Backend: %s\n", gRenderBackends.find(mRenderer->mCurrentBackend)->second.c_str()); aStr += StrFormat("3D-Mode is %s (3D is %s on this system)\n\n", Is3DAccelerated() ? "On" : "Off", aDesc); aStr += StrFormat("Num Images: %d\n", (int)mMemoryImageSet.size()); @@ -3404,16 +3416,16 @@ void SexyAppBase::ShowMemoryUsage() FormatUsage aUsage = aFormatMap[PixelFormat_A8R8G8B8]; aStr += StrFormat("A8R8G8B8: %d - %s KB\n", aUsage.first, - SexyStringToString(CommaSeperate(aUsage.second / 1024)).c_str()); + SexyStringToString(CommaSeperate(aUsage.second / 1024)).c_str()); aUsage = aFormatMap[PixelFormat_A4R4G4B4]; aStr += StrFormat("A4R4G4B4: %d - %s KB\n", aUsage.first, - SexyStringToString(CommaSeperate(aUsage.second / 1024)).c_str()); + SexyStringToString(CommaSeperate(aUsage.second / 1024)).c_str()); aUsage = aFormatMap[PixelFormat_R5G6B5]; aStr += StrFormat("R5G6B5: %d - %s KB\n", aUsage.first, - SexyStringToString(CommaSeperate(aUsage.second / 1024)).c_str()); + SexyStringToString(CommaSeperate(aUsage.second / 1024)).c_str()); aUsage = aFormatMap[PixelFormat_Palette8]; aStr += StrFormat("Palette8: %d - %s KB\n", aUsage.first, - SexyStringToString(CommaSeperate(aUsage.second / 1024)).c_str()); + SexyStringToString(CommaSeperate(aUsage.second / 1024)).c_str()); MsgBox(aStr, "Video Stats", MESSAGEBOX_BTN_OK); mLastTime = timeGetTime(); @@ -3535,8 +3547,8 @@ bool SexyAppBase::ProcessDeferredMessages(bool singleMessage) #if SEXY_USE_IMGUI #if SEXY_USE_SDL3_RENDERER if (mRenderer->mCurrentBackend == RenderingBackend::BACKEND_SDL3 && - (anEvent.type == SDL_EVENT_MOUSE_BUTTON_DOWN || anEvent.type == SDL_EVENT_MOUSE_BUTTON_UP || - anEvent.type == SDL_EVENT_MOUSE_MOTION)) + (anEvent.type == SDL_EVENT_MOUSE_BUTTON_DOWN || anEvent.type == SDL_EVENT_MOUSE_BUTTON_UP || + anEvent.type == SDL_EVENT_MOUSE_MOTION)) { SDL_Event aConvertedEvent = SDL_Event(anEvent); int x = aConvertedEvent.motion.x; @@ -3724,7 +3736,7 @@ bool SexyAppBase::ProcessDeferredMessages(bool singleMessage) // as relative==true for mouse warp injections), revert to mouse mode. // SDL3 sets event.motion.which == SDL_TOUCH_MOUSEID for touch/synthetic events. if (anEvent.motion.which != SDL_TOUCH_MOUSEID && - (std::abs(anEvent.motion.xrel) > 2 || std::abs(anEvent.motion.yrel) > 2)) + (std::abs(anEvent.motion.xrel) > 2 || std::abs(anEvent.motion.yrel) > 2)) { mUsingGamepad = false; EnforceCursor(); @@ -3737,9 +3749,9 @@ bool SexyAppBase::ProcessDeferredMessages(bool singleMessage) #endif if (!(x >= mRenderer->mPresentationRect.mX && - x < mRenderer->mPresentationRect.mX + mRenderer->mPresentationRect.mWidth && - y >= mRenderer->mPresentationRect.mY && - y < mRenderer->mPresentationRect.mY + mRenderer->mPresentationRect.mHeight && x > 0 && y > 0)) + x < mRenderer->mPresentationRect.mX + mRenderer->mPresentationRect.mWidth && + y >= mRenderer->mPresentationRect.mY && + y < mRenderer->mPresentationRect.mY + mRenderer->mPresentationRect.mHeight && x > 0 && y > 0)) { break; } @@ -3786,9 +3798,9 @@ bool SexyAppBase::ProcessDeferredMessages(bool singleMessage) int x = anEvent.button.x; int y = anEvent.button.y; if (!(x >= mRenderer->mPresentationRect.mX && - x < mRenderer->mPresentationRect.mX + mRenderer->mPresentationRect.mWidth && - y >= mRenderer->mPresentationRect.mY && - y < mRenderer->mPresentationRect.mY + mRenderer->mPresentationRect.mHeight && x > 0 && y > 0)) + x < mRenderer->mPresentationRect.mX + mRenderer->mPresentationRect.mWidth && + y >= mRenderer->mPresentationRect.mY && + y < mRenderer->mPresentationRect.mY + mRenderer->mPresentationRect.mHeight && x > 0 && y > 0)) { break; } @@ -4125,7 +4137,7 @@ void SexyAppBase::MakeWindow() #if SEXY_USE_OPENGL anError += - StrFormat("OpenGL: %s\n", OpenGLRenderer::TestOpenGL(mWindow->mInternalWindow) ? "OK" : "FAILED"); + StrFormat("OpenGL: %s\n", OpenGLRenderer::TestOpenGL(mWindow->mInternalWindow) ? "OK" : "FAILED"); #endif #if SEXY_USE_SDL3_RENDERER @@ -4192,7 +4204,7 @@ void SexyAppBase::DeleteNativeImageData() void SexyAppBase::DeleteExtraImageData() { - auto aLock = std::scoped_lock(mRenderer->mCritSect); + auto aLock = std::scoped_lock(mRenderer->mCritSect); MemoryImageSet::iterator anItr = mMemoryImageSet.begin(); while (anItr != mMemoryImageSet.end()) { @@ -4380,7 +4392,7 @@ void SexyAppBase::EnforceCursor() else { if (mCursorNum >= NUM_CURSORS || (mCursorImages[mCursorNum] == nullptr) || - ((!mPlayingDemoBuffer) && (!mCustomCursorsEnabled))) + ((!mPlayingDemoBuffer) && (!mCustomCursorsEnabled))) { SDL_SetCursor(mSystemCursors[aNativeCursor]); SDL_ShowCursor(); @@ -4390,9 +4402,9 @@ void SexyAppBase::EnforceCursor() if (!mCachedCursors[mCursorNum]) { SDL_Surface *aSurface = - SDL_CreateSurfaceFrom(mCursorImages[mCursorNum]->mWidth, mCursorImages[mCursorNum]->mHeight, - SDL_PIXELFORMAT_ARGB8888, ((GPUImage *)mCursorImages[mCursorNum])->GetBits(), - mCursorImages[mCursorNum]->mWidth * sizeof(uint32_t)); + SDL_CreateSurfaceFrom(mCursorImages[mCursorNum]->mWidth, mCursorImages[mCursorNum]->mHeight, + SDL_PIXELFORMAT_ARGB8888, ((GPUImage *)mCursorImages[mCursorNum])->GetBits(), + mCursorImages[mCursorNum]->mWidth * sizeof(uint32_t)); SDL_Cursor *aCursor = SDL_CreateColorCursor(aSurface, 0, 0); mCachedCursors[mCursorNum] = aCursor; @@ -4963,7 +4975,7 @@ bool SexyAppBase::LoadProperties(const std::string &theFileName, bool required, else { Popup(GetString("UNABLE_OPEN_PROPERTIES", "Unable to open properties file ") + - StringToSexyString(theFileName)); + StringToSexyString(theFileName)); return false; } } @@ -4972,7 +4984,7 @@ bool SexyAppBase::LoadProperties(const std::string &theFileName, bool required, if (!CheckSignature(aBuffer, theFileName)) { Popup(GetString("PROPERTIES_SIG_FAILED", "Signature check failed on ") + - StringToSexyString(theFileName + "'")); + StringToSexyString(theFileName + "'")); return false; } } @@ -5288,7 +5300,7 @@ void SexyAppBase::HandleCmdLineParam(const std::string &theParamName, const std: else { Popup(GetString("INVALID_COMMANDLINE_PARAM", "Invalid command line parameter: ") + - StringToSexyString(theParamName)); + StringToSexyString(theParamName)); DoExit(0); } } @@ -5543,7 +5555,7 @@ Sexy::GPUImage *SexyAppBase::GetImage(const std::string &theFileName, bool commi } Sexy::GPUImage *SexyAppBase::CreateCrossfadeImage(Sexy::Image *theImage1, const Rect &theRect1, Sexy::Image *theImage2, - const Rect &theRect2, double theFadeFactor) + const Rect &theRect2, double theFadeFactor) { MemoryImage *aMemoryImage1 = dynamic_cast(theImage1); MemoryImage *aMemoryImage2 = dynamic_cast(theImage2); @@ -5552,14 +5564,14 @@ Sexy::GPUImage *SexyAppBase::CreateCrossfadeImage(Sexy::Image *theImage1, const return NULL; if ((theRect1.mX < 0) || (theRect1.mY < 0) || (theRect1.mX + theRect1.mWidth > theImage1->GetWidth()) || - (theRect1.mY + theRect1.mHeight > theImage1->GetHeight())) + (theRect1.mY + theRect1.mHeight > theImage1->GetHeight())) { DBG_ASSERTE("Crossfade Rect1 out of bounds"); return NULL; } if ((theRect2.mX < 0) || (theRect2.mY < 0) || (theRect2.mX + theRect2.mWidth > theImage2->GetWidth()) || - (theRect2.mY + theRect2.mHeight > theImage2->GetHeight())) + (theRect2.mY + theRect2.mHeight > theImage2->GetHeight())) { DBG_ASSERTE("Crossfade Rect2 out of bounds"); return NULL; @@ -5595,9 +5607,9 @@ Sexy::GPUImage *SexyAppBase::CreateCrossfadeImage(Sexy::Image *theImage1, const //p2 = 0xFFFFFFFF; *d++ = ((((p1 & 0x000000FF) * aOMM + (p2 & 0x000000FF) * aMult) >> 8) & 0x000000FF) | - ((((p1 & 0x0000FF00) * aOMM + (p2 & 0x0000FF00) * aMult) >> 8) & 0x0000FF00) | - ((((p1 & 0x00FF0000) * aOMM + (p2 & 0x00FF0000) * aMult) >> 8) & 0x00FF0000) | - ((((p1 >> 24) * aOMM + (p2 >> 24) * aMult) << 16) & 0xFF000000); + ((((p1 & 0x0000FF00) * aOMM + (p2 & 0x0000FF00) * aMult) >> 8) & 0x0000FF00) | + ((((p1 & 0x00FF0000) * aOMM + (p2 & 0x00FF0000) * aMult) >> 8) & 0x00FF0000) | + ((((p1 >> 24) * aOMM + (p2 >> 24) * aMult) << 16) & 0xFF000000); } } @@ -5634,9 +5646,9 @@ void SexyAppBase::ColorizeImage(Image *theImage, const Color &theColor) uint32_t aColor = aBits[i]; aBits[i] = ((((aColor & 0xFF000000) >> 8) * theColor.mAlpha) & 0xFF000000) | - ((((aColor & 0x00FF0000) * theColor.mRed) >> 8) & 0x00FF0000) | - ((((aColor & 0x0000FF00) * theColor.mGreen) >> 8) & 0x0000FF00) | - ((((aColor & 0x000000FF) * theColor.mBlue) >> 8) & 0x000000FF); + ((((aColor & 0x00FF0000) * theColor.mRed) >> 8) & 0x00FF0000) | + ((((aColor & 0x0000FF00) * theColor.mGreen) >> 8) & 0x0000FF00) | + ((((aColor & 0x000000FF) * theColor.mBlue) >> 8) & 0x000000FF); } } else @@ -5704,9 +5716,9 @@ GPUImage *SexyAppBase::CreateColorizedImage(Image *theImage, const Color &theCol uint32_t aColor = aSrcBits[i]; aDestBits[i] = ((((aColor & 0xFF000000) >> 8) * theColor.mAlpha) & 0xFF000000) | - ((((aColor & 0x00FF0000) * theColor.mRed) >> 8) & 0x00FF0000) | - ((((aColor & 0x0000FF00) * theColor.mGreen) >> 8) & 0x0000FF00) | - ((((aColor & 0x000000FF) * theColor.mBlue) >> 8) & 0x000000FF); + ((((aColor & 0x00FF0000) * theColor.mRed) >> 8) & 0x00FF0000) | + ((((aColor & 0x0000FF00) * theColor.mGreen) >> 8) & 0x0000FF00) | + ((((aColor & 0x000000FF) * theColor.mBlue) >> 8) & 0x000000FF); } } else @@ -6008,7 +6020,7 @@ void SexyAppBase::RGBToHSL(const uint32_t *theSource, uint32_t *theDest, int the { uint32_t src = theSource[i]; theDest[i] = - (src & 0xFF000000) | (RGBToHSL(((src >> 16) & 0xFF), (src >> 8) & 0xFF, (src & 0xFF)) & 0x00FFFFFF); + (src & 0xFF000000) | (RGBToHSL(((src >> 16) & 0xFF), (src >> 8) & 0xFF, (src & 0xFF)) & 0x00FFFFFF); } } @@ -6119,13 +6131,13 @@ void SexyAppBase::SetMasterVolume(double theMasterVolume) void SexyAppBase::AddMemoryImage(MemoryImage *theMemoryImage) { - auto aLock = std::scoped_lock(mRenderer->mCritSect); + auto aLock = std::scoped_lock(mRenderer->mCritSect); mMemoryImageSet.insert(theMemoryImage); } void SexyAppBase::RemoveMemoryImage(MemoryImage *theMemoryImage) { - auto aLock = std::scoped_lock(mRenderer->mCritSect); + auto aLock = std::scoped_lock(mRenderer->mCritSect); MemoryImageSet::iterator anItr = mMemoryImageSet.find(theMemoryImage); if (anItr != mMemoryImageSet.end()) mMemoryImageSet.erase(anItr); @@ -6209,9 +6221,9 @@ SharedImageRef SexyAppBase::GetSharedImage(const std::string &theFileName, const SharedImageRef aSharedImageRef; { - auto aLock = std::scoped_lock(mRenderer->mCritSect); + auto aLock = std::scoped_lock(mRenderer->mCritSect); aResultPair = mSharedImageMap.insert( - SharedImageMap::value_type(SharedImageMap::key_type(anUpperFileName, anUpperVariant), SharedImage())); + SharedImageMap::value_type(SharedImageMap::key_type(anUpperFileName, anUpperVariant), SharedImage())); aSharedImageRef = &aResultPair.first->second; } @@ -6232,7 +6244,7 @@ SharedImageRef SexyAppBase::GetSharedImage(const std::string &theFileName, const void SexyAppBase::CleanSharedImages() { - auto aLock = std::scoped_lock(mRenderer->mCritSect); + auto aLock = std::scoped_lock(mRenderer->mCritSect); if (mCleanupSharedImages) {