From 092443b37f47b8e9ac2ddea6cb4f4f70c6b2d916 Mon Sep 17 00:00:00 2001 From: jan610 Date: Sat, 18 May 2024 16:56:01 +0200 Subject: [PATCH 1/2] Added some Core commands Added Min,Max,Clamp,Wrap,Map,CurveValue,CurveAngle,WrapAngle --- AGK/AgkIde/AGKCommands.h | 3 +- AGK/AgkIde/media/main.agc.tags | 11 ++ AGK/CommandParserNew/Final/CommandList.dat | Bin 145441 -> 146116 bytes AGK/CompilerNew/CommandList.h | 17 +- .../Language Server Protocol/AGKCommands.h | 11 ++ AGK/apps/interpreter/AGKCommandEnums.h | 13 +- AGK/apps/interpreter/AGKCommandSwitch.h | 84 +++++++++ AGK/apps/interpreter/AGKCommandSwitch2D.h | 84 +++++++++ AGK/apps/interpreter/AGKPluginCommandList.h | 13 +- AGK/common/Source/Wrapper.cpp | 170 +++++++++++++++++- AGK/common/include/Wrapper.h | 11 ++ AGK/plugins/Source/AGKLibraryCommands.cpp | 22 +++ AGK/plugins/Source/AGKLibraryCommands.h | 22 +++ .../Builds/Studio/AGKStudioWindows/readme.txt | 1 - 14 files changed, 453 insertions(+), 9 deletions(-) delete mode 100644 AGK_Build/Builds/Studio/AGKStudioWindows/readme.txt diff --git a/AGK/AgkIde/AGKCommands.h b/AGK/AgkIde/AGKCommands.h index bfe66995..1e2365f5 100644 --- a/AGK/AgkIde/AGKCommands.h +++ b/AGK/AgkIde/AGKCommands.h @@ -236,5 +236,6 @@ static const char* const agk_identifiers[] = { "externalcommand", "externalcommandint", "externalcommandfloat", "externalcommandstring", "getappreceipt", "inapppurchaseactivatewithplan", "getinapppurchasesubnumplans", "getinapppurchasesubplannumperiods", "getinapppurchasesubplanprice", "getinapppurchasesubplanduration", "getinapppurchasesubplandurationunit", "getinapppurchasesubplanpaymenttype", "getinapppurchasesubplantags", "getinapppurchasesubplantoken", "getdisplaynumcutouts", "getdisplaycutouttop", "getdisplaycutoutbottom", "getdisplaycutoutleft", "getdisplaycutoutright", "getscreenboundssafetop", -"getscreenboundssafebottom", "getscreenboundssafeleft", "getscreenboundssaferight", "ispinappavailable", "pinapp", "isdarktheme", "getinapppurchaseisrenewing", +"getscreenboundssafebottom", "getscreenboundssafeleft", "getscreenboundssaferight", "ispinappavailable", "pinapp", "isdarktheme", "getinapppurchaseisrenewing", "lerp", "inverselerp", "map", "clamp", +"min", "max", "wrap", "sign", "wrapangle", "curvevalue", "curveangle", }; \ No newline at end of file diff --git a/AGK/AgkIde/media/main.agc.tags b/AGK/AgkIde/media/main.agc.tags index a4b5d289..3c5ea8eb 100644 --- a/AGK/AgkIde/media/main.agc.tags +++ b/AGK/AgkIde/media/main.agc.tags @@ -2119,3 +2119,14 @@ IsPinAppAvailable|Integer|()| PinApp||(Integer enable)| IsDarkTheme|Integer|()| GetInAppPurchaseIsRenewing|Integer|(Integer iID)| +Lerp|Float|(Float a, Float b, Float c)| +InverseLerp|Float|(Float a, Float b, Float c)| +Map|Float|(Float a, Float b, Float c, Float d, Float e)| +Clamp|Float|(Float a, Float b, Float c)| +Min|Float|(Float a, Float b)| +Max|Float|(Float a, Float b)| +Wrap|Float|(Float a, Float b, Float c)| +Sign|Integer|(Float a)| +WrapAngle|Float|(Float a)| +CurveValue|Float|(Float a, Float b, Float c)| +CurveAngle|Float|(Float a, Float b, Float c)| diff --git a/AGK/CommandParserNew/Final/CommandList.dat b/AGK/CommandParserNew/Final/CommandList.dat index 6226705da513142e425ebbdeb44e3e4f5746dbbd..74395ee0ca671e79782e29df5b621d369641f744 100644 GIT binary patch delta 410 zcmZ4Zf#b+m4#tE=##Tngt&B_x7Q!qH3=BT0MFmW(Kt@_leqssp^w^_}a#~D`K!Ieq zC<8Z;>zP-UT2!2hO}!GjdS;+{-$W#HS;6Kyp{WCNQ{dKsxv6k21Bm6ElbDNS4#a)p zXy!10?aR!Yu6UGDkJ&e|0>sb)doR2Q*%=V+66o4N;Sijeo;Q8M5k^T~P9P7Y%`q=M oCw2P8!;I3BTp*W}7L}!jCFYc-q6e2Ix_NNrU?b3#3!p0p0G~EnKmY&$ delta 18 ZcmX@|m1E%t4#v<%##Tngt&B_x763+^1 c) return c; + return a; +} + + +//****f* Core/Maths/Min +// FUNCTION +// Returns the minimum of two values. +// INPUTS +// a -- The first value. +// b -- The second value. +// SOURCE +float agk::Min(float a, float b) +//**** +{ + return fmin(a, b); +} + +//****f* Core/Maths/Max +// FUNCTION +// Returns the maximum of two values. +// INPUTS +// a -- The first value. +// b -- The second value. +// SOURCE +float agk::Max(float a, float b) +//**** +{ + return fmax(a, b); +} + +//****f* Core/Maths/Wrap +// FUNCTION +// Wraps a value within a specified range [min, max). +// INPUTS +// a -- The value to be wrapped. +// b -- The minimum value of the range. +// c -- The maximum value of the range (exclusive). +// SOURCE +float agk::Wrap(float a, float b, float c) +//**** +{ + if (b == c) return b; // If the range is zero, return the minimum value. + float range = c - b; + return b + fmod(fmod(a - b, range) + range, range); +} + +//****f* Core/Maths/WrapAngle +// FUNCTION +// Wraps an angle value within the range of 0 to 360 degrees. +// INPUTS +// a -- The angle value to be wrapped. +// SOURCE +float agk::WrapAngle(float a) +//**** +{ + float remainder = fmod(a, 360.0f); + if (remainder < 0.0f) remainder += 360.0f; + return remainder; +} + +//****f* Core/Maths/Sign +// FUNCTION +// Returns the sign of the value. +// INPUTS +// a -- The value whose sign is to be determined. +// SOURCE +int agk::Sign(float a) +//**** +{ + if (a > 0) return 1; + if (a < 0) return -1; + return 0; +} + +//****f* Core/Maths/CurveValue +// FUNCTION +// Moves a current value towards a destination value at a specified speed. +// INPUTS +// a -- The current value. +// b -- The destination value. +// c -- The speed of movement. +// SOURCE +float agk::CurveValue(float a, float b, float c) +//**** +{ + if (c < 1.0f) c = 1.0f; + return a + (b - a) / c; +} + +//****f* Core/Maths/CurveAngle +// FUNCTION +// Moves a current angle towards a destination angle at a specified angular speed. +// INPUTS +// a -- The current angle. +// b -- The destination angle. +// c -- The angular speed. +// SOURCE +float agk::CurveAngle(float a, float b, float c) +//**** +{ + float diff = agk::WrapAngle(b - a); + float speed = fabs(c); + float direction = agk::Sign(diff); + float angleToMove = agk::Min(speed, fabs(diff)) * direction; + return agk::WrapAngle(a + angleToMove); +} + + //****f* Core/Maths/Log // FUNCTION // Returns the natural logarithm of the given value. // INPUTS // a -- The input value // SOURCE -float agk::Log( float a ) +float agk::Log(float a) //**** { - return log( a ); + return log(a); } //****f* Core/Misc/SetSortTextures diff --git a/AGK/common/include/Wrapper.h b/AGK/common/include/Wrapper.h index 3c1649fd..a30e2e86 100644 --- a/AGK/common/include/Wrapper.h +++ b/AGK/common/include/Wrapper.h @@ -981,6 +981,17 @@ namespace AGK static int Mod( int a, int b ); static float FMod( float a, float b ); static float Pow( float a, float b ); + static float Lerp(float a, float b, float c); + static float InverseLerp(float a, float b, float c); + static float Map(float a, float b, float c, float d, float e); + static float Clamp(float a, float b, float c); + static float Min(float a, float b); + static float Max(float a, float b); + static float Wrap(float a, float b, float c); + static float WrapAngle(float a); + static int Sign(float a); + static float CurveValue(float a, float b, float c); + static float CurveAngle(float a, float b, float c); static float Log( float a ); // control functions diff --git a/AGK/plugins/Source/AGKLibraryCommands.cpp b/AGK/plugins/Source/AGKLibraryCommands.cpp index 41751718..7e16f0ea 100644 --- a/AGK/plugins/Source/AGKLibraryCommands.cpp +++ b/AGK/plugins/Source/AGKLibraryCommands.cpp @@ -2133,6 +2133,17 @@ int(*AGKCommand2129)( ) = 0; void(*AGKCommand2130)( int ) = 0; int(*AGKCommand2131)( ) = 0; int(*AGKCommand2132)( int ) = 0; +float(*AGKCommand2133)( float, float, float ) = 0; +float(*AGKCommand2134)( float, float, float ) = 0; +float(*AGKCommand2135)( float, float, float, float, float ) = 0; +float(*AGKCommand2136)( float, float, float ) = 0; +float(*AGKCommand2137)( float, float ) = 0; +float(*AGKCommand2138)( float, float ) = 0; +float(*AGKCommand2139)( float, float, float ) = 0; +int(*AGKCommand2140)( float ) = 0; +float(*AGKCommand2141)( float ) = 0; +float(*AGKCommand2142)( float, float, float ) = 0; +float(*AGKCommand2143)( float, float, float ) = 0; typedef void(*AGKVoidFunc)(void); AGKVoidFunc(*GetAGKFunction)( const char* ) = 0; @@ -4274,4 +4285,15 @@ extern "C" DLL_EXPORT void ReceiveAGKPtr( AGKVoidFunc ptr ) AGKCommand2130 = (void(*)(int)) GetAGKFunction( "PINAPP_0_L" ); AGKCommand2131 = (int(*)()) GetAGKFunction( "ISDARKTHEME_L_0" ); AGKCommand2132 = (int(*)(int)) GetAGKFunction( "GETINAPPPURCHASEISRENEWING_L_L" ); + AGKCommand2133 = (float(*)(float,float,float)) GetAGKFunction( "LERP_F_F_F_F" ); + AGKCommand2134 = (float(*)(float,float,float)) GetAGKFunction( "INVERSELERP_F_F_F_F" ); + AGKCommand2135 = (float(*)(float,float,float,float,float)) GetAGKFunction( "MAP_F_F_F_F_F_F" ); + AGKCommand2136 = (float(*)(float,float,float)) GetAGKFunction( "CLAMP_F_F_F_F" ); + AGKCommand2137 = (float(*)(float,float)) GetAGKFunction( "MIN_F_F_F" ); + AGKCommand2138 = (float(*)(float,float)) GetAGKFunction( "MAX_F_F_F" ); + AGKCommand2139 = (float(*)(float,float,float)) GetAGKFunction( "WRAP_F_F_F_F" ); + AGKCommand2140 = (int(*)(float)) GetAGKFunction( "SIGN_L_F" ); + AGKCommand2141 = (float(*)(float)) GetAGKFunction( "WRAPANGLE_F_F" ); + AGKCommand2142 = (float(*)(float,float,float)) GetAGKFunction( "CURVEVALUE_F_F_F_F" ); + AGKCommand2143 = (float(*)(float,float,float)) GetAGKFunction( "CURVEANGLE_F_F_F_F" ); } diff --git a/AGK/plugins/Source/AGKLibraryCommands.h b/AGK/plugins/Source/AGKLibraryCommands.h index f4719638..4280ad61 100644 --- a/AGK/plugins/Source/AGKLibraryCommands.h +++ b/AGK/plugins/Source/AGKLibraryCommands.h @@ -2144,6 +2144,17 @@ extern int(*AGKCommand2129)( ); extern void(*AGKCommand2130)( int ); extern int(*AGKCommand2131)( ); extern int(*AGKCommand2132)( int ); +extern float(*AGKCommand2133)( float, float, float ); +extern float(*AGKCommand2134)( float, float, float ); +extern float(*AGKCommand2135)( float, float, float, float, float ); +extern float(*AGKCommand2136)( float, float, float ); +extern float(*AGKCommand2137)( float, float ); +extern float(*AGKCommand2138)( float, float ); +extern float(*AGKCommand2139)( float, float, float ); +extern int(*AGKCommand2140)( float ); +extern float(*AGKCommand2141)( float ); +extern float(*AGKCommand2142)( float, float, float ); +extern float(*AGKCommand2143)( float, float, float ); class agk { @@ -4281,6 +4292,17 @@ class agk static inline void PinApp( int enable ) { AGKCommand2130( enable ); } static inline int IsDarkTheme( ) { return AGKCommand2131( ); } static inline int GetInAppPurchaseIsRenewing( int iID ) { return AGKCommand2132( iID ); } + static inline float Lerp( float a, float b, float c ) { return AGKCommand2133( a, b, c ); } + static inline float InverseLerp( float a, float b, float c ) { return AGKCommand2134( a, b, c ); } + static inline float Map( float a, float b, float c, float d, float e ) { return AGKCommand2135( a, b, c, d, e ); } + static inline float Clamp( float a, float b, float c ) { return AGKCommand2136( a, b, c ); } + static inline float Min( float a, float b ) { return AGKCommand2137( a, b ); } + static inline float Max( float a, float b ) { return AGKCommand2138( a, b ); } + static inline float Wrap( float a, float b, float c ) { return AGKCommand2139( a, b, c ); } + static inline int Sign( float a ) { return AGKCommand2140( a ); } + static inline float WrapAngle( float a ) { return AGKCommand2141( a ); } + static inline float CurveValue( float a, float b, float c ) { return AGKCommand2142( a, b, c ); } + static inline float CurveAngle( float a, float b, float c ) { return AGKCommand2143( a, b, c ); } }; #endif diff --git a/AGK_Build/Builds/Studio/AGKStudioWindows/readme.txt b/AGK_Build/Builds/Studio/AGKStudioWindows/readme.txt deleted file mode 100644 index f42713b5..00000000 --- a/AGK_Build/Builds/Studio/AGKStudioWindows/readme.txt +++ /dev/null @@ -1 +0,0 @@ -Empty Folder Until Filled \ No newline at end of file From 6feb77518913cccc6c193bb1694c04a4c67c16ab Mon Sep 17 00:00:00 2001 From: jan610 Date: Sun, 19 May 2024 16:36:08 +0200 Subject: [PATCH 2/2] Fixed CurveAngle --- AGK/common/Source/Wrapper.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/AGK/common/Source/Wrapper.cpp b/AGK/common/Source/Wrapper.cpp index b09035d3..3ab4dbd4 100644 --- a/AGK/common/Source/Wrapper.cpp +++ b/AGK/common/Source/Wrapper.cpp @@ -6033,34 +6033,36 @@ int agk::Sign(float a) // INPUTS // a -- The current value. // b -- The destination value. -// c -- The speed of movement. +// c -- The speed of movement (number of iterations to reach destination). // SOURCE float agk::CurveValue(float a, float b, float c) //**** { if (c < 1.0f) c = 1.0f; - return a + (b - a) / c; + return a + ((b - a) / c); } //****f* Core/Maths/CurveAngle // FUNCTION // Moves a current angle towards a destination angle at a specified angular speed. // INPUTS -// a -- The current angle. -// b -- The destination angle. -// c -- The angular speed. +// a -- The current angle (in degrees). +// b -- The destination angle (in degrees). +// c -- The angular speed (number of iterations to reach destination). // SOURCE float agk::CurveAngle(float a, float b, float c) //**** { - float diff = agk::WrapAngle(b - a); - float speed = fabs(c); - float direction = agk::Sign(diff); - float angleToMove = agk::Min(speed, fabs(diff)) * direction; - return agk::WrapAngle(a + angleToMove); + if (c < 1.0f) c = 1.0f; + float delta = agk::WrapAngle(b - a); + if (delta > 180.0f) { + delta -= 360.0f; + } + float angleToMove = delta / c; + a += angleToMove; + return agk::WrapAngle(a); } - //****f* Core/Maths/Log // FUNCTION // Returns the natural logarithm of the given value.