mocha-engine / mocha

Mocha: A work-in-progress 3D game engine
GNU Lesser General Public License v3.0
53 stars 7 forks source link

Console System Improvements #46

Closed MuffinTastic closed 1 year ago

MuffinTastic commented 1 year ago

Changes:

Usage Examples Native CVar with a callback ```cpp static FloatCVar cvartest_float( "cvartest.float", 0.0f, CVarFlags::None, "Yeah", []( float oldValue, float newValue ) { spdlog::trace( "cvartest.float changed! old {}, new {}", oldValue, newValue ); } ); ``` Native CCmd ```cpp static CCmd cvartest_command( "cvartest.command", CVarFlags::None, "A test command", []( std::vector arguments ) { spdlog::trace( "cvartest.command has been invoked! Hooray" ); for ( int i = 0; i < arguments.size(); i++ ) { spdlog::trace( "\t{} - '{}'", i, arguments.at( i ) ); } } ); ``` Several managed ConCmds ```cs [ConCmd.Test( "cvartest.managed.anything", "This is a description" )] public static void One( List arguments ) { Log.Info( "This is a command, woohoo" ); foreach ( var arg in arguments ) { Log.Info( $" - {arg}" ); } } [ConCmd.Cheat( "cvartest.managed.string" )] public static void String( string hello ) { Log.Info( hello + " [modified]"); } [ConCmd.Test( "cvartest.managed.float" )] public static void Float( float hello ) { Log.Info( hello + 20.0f ); } [ConCmd.Test( "cvartest.managed.double" )] public static void Double( double hello ) { Log.Info( hello + 34.0 ); } [ConCmd.Test( "cvartest.managed.int" )] public static void Int( int hello ) { Log.Info( hello - 123 ); } [ConCmd.Test( "cvartest.managed.uint" )] public static void UInt( uint hello ) { Log.Info( hello + 456 ); } [ConCmd.Test( "cvartest.managed.long" )] public static void Long( long hello ) { Log.Info( hello - 1234 ); } [ConCmd.Test( "cvartest.managed.ulong" )] public static void ULong( ulong hello ) { Log.Info( hello - 5678 ); } [ConCmd.Test( "cvartest.managed.bool" )] public static void Bool( bool hello ) { Log.Info( hello ); } [ConCmd.Test( "cvartest.managed.two" )] public static void Two( int one, float two ) { Log.Info( $"{one}, {two}" ); } [ConCmd.Test( "cvartest.managed.twodefault" )] public static void TwoDefault( int one, float two = 10.0f ) { Log.Info( $"{one}, {two}" ); } [ConCmd.Test( "cvartest.managed.threedefault" )] public static void ThreeDefault( int one, bool two, float three = 10.0f ) { Log.Info( $"{one}, {two}, {three}" ); } [ConCmd.Test( "cvartest.managed.threedefault2" )] public static void ThreeDefault2( int one, bool two = true, float three = 10.0f ) { Log.Info( $"{one}, {two}, {three}" ); } ``` ![image](https://user-images.githubusercontent.com/10884425/215709974-5c676cfa-94f9-49ed-b3e1-86c2ca17d908.png)

Notes:

xezno commented 1 year ago

LGTM, thanks a ton for this! Should make both engine & game development much easier, and I do feel your concerns about string operations in c++ - I think they suck too - but I think your solution works fine. Awesome work!