diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23a98a85..1526fbc3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,6 +38,7 @@ add_subdirectory(adera) add_subdirectory(osp) add_subdirectory(planet-a) add_subdirectory(ospjolt) +add_subdirectory(testapp) if(OSP_BUILD_GDEXTENSION) @@ -45,7 +46,7 @@ add_subdirectory(gdextension) else() -add_subdirectory(testapp) +add_subdirectory(testapp_magnum) add_subdirectory(osp_drawing_gl) add_subdirectory(adera_drawing_gl) diff --git a/src/gdextension/Example.cpp b/src/gdextension/Example.cpp deleted file mode 100644 index 2cf4586b..00000000 --- a/src/gdextension/Example.cpp +++ /dev/null @@ -1,848 +0,0 @@ -// Copied from godot-cpp/test/src and modified. - -#include "godot_cpp/classes/global_constants.hpp" -#include "godot_cpp/classes/label.hpp" -#include "godot_cpp/core/class_db.hpp" -#include "godot_cpp/variant/utility_functions.hpp" -#include "ospjolt/joltinteg.h" - -#include "Example.h" - -// Used to mark unused parameters to indicate intent and suppress warnings. -#define UNUSED( expr ) (void)( expr ) - -namespace -{ - constexpr int MAGIC_NUMBER = 42; - - class MyCallableCustom : public godot::CallableCustom - { - public: - virtual uint32_t hash() const - { - return 27; - } - - virtual godot::String get_as_text() const - { - return ""; - } - - static bool compare_equal_func( const CallableCustom *inA, const CallableCustom *inB ) - { - return inA == inB; - } - - virtual CompareEqualFunc get_compare_equal_func() const - { - return &MyCallableCustom::compare_equal_func; - } - - static bool compare_less_func( const CallableCustom *inA, const CallableCustom *inB ) - { - return reinterpret_cast( inA ) < reinterpret_cast( inB ); - } - - virtual CompareLessFunc get_compare_less_func() const - { - return &MyCallableCustom::compare_less_func; - } - - bool is_valid() const - { - return true; - } - - virtual godot::ObjectID get_object() const - { - return godot::ObjectID(); - } - - virtual void call( const godot::Variant **inArguments, int inArgcount, - godot::Variant &outReturnValue, - GDExtensionCallError &outCallError ) const - { - UNUSED( inArguments ); - UNUSED( inArgcount ); - - outReturnValue = "Hi"; - outCallError.error = GDEXTENSION_CALL_OK; - } - }; -} - -//// ExampleRef - -int ExampleRef::sInstanceCount = 0; -int ExampleRef::sLastID = 0; - -ExampleRef::ExampleRef() -{ - mID = ++sLastID; - sInstanceCount++; - - godot::UtilityFunctions::print( - "ExampleRef ", godot::itos( mID ), - " created, current instance count: ", godot::itos( sInstanceCount ) ); -} - -ExampleRef::~ExampleRef() -{ - sInstanceCount--; - godot::UtilityFunctions::print( - "ExampleRef ", godot::itos( mID ), - " destroyed, current instance count: ", godot::itos( sInstanceCount ) ); -} - -void ExampleRef::setId( int inID ) -{ - mID = inID; -} - -int ExampleRef::getID() const -{ - return mID; -} - -void ExampleRef::_bind_methods() -{ - godot::ClassDB::bind_method( godot::D_METHOD( "set_id", "id" ), &ExampleRef::setId ); - godot::ClassDB::bind_method( godot::D_METHOD( "get_id" ), &ExampleRef::getID ); - - godot::ClassDB::bind_method( godot::D_METHOD( "was_post_initialized" ), - &ExampleRef::wasPostInitialized ); -} - -void ExampleRef::_notification( int inWhat ) -{ - if ( inWhat == NOTIFICATION_POSTINITIALIZE ) - { - mPostInitialized = true; - } -} - -//// ExampleMin - -void ExampleMin::_bind_methods() -{ -} - -//// Example - -Example::Example() -{ - godot::UtilityFunctions::print( "Constructor." ); - ospjolt::ACtxJoltWorld::initJoltGlobal(); - auto world = ospjolt::ACtxJoltWorld(); -} - -Example::~Example() -{ - godot::UtilityFunctions::print( "Destructor." ); -} - -// Methods. -void Example::simpleFunc() -{ - godot::UtilityFunctions::print( " Simple func called." ); -} - -void Example::simpleConstFunc() const -{ - godot::UtilityFunctions::print( " Simple const func called." ); -} - -godot::String Example::returnSomething( const godot::String &inBase ) -{ - godot::UtilityFunctions::print( " Return something called." ); - - return inBase; -} - -godot::Viewport *Example::returnSomethingConst() const -{ - godot::UtilityFunctions::print( " Return something const called." ); - - if ( is_inside_tree() ) - { - godot::Viewport *result = get_viewport(); - - return result; - } - - return nullptr; -} - -godot::Ref Example::returnEmptyRef() const -{ - godot::Ref ref; - return ref; -} - -ExampleRef *Example::returnExtendedRef() const -{ - // You can instance and return a refcounted object like this, but keep in mind that refcounting - // starts with the returned object and it will be destroyed when all references are destroyed. - // If you store this pointer you run the risk of having a pointer to a destroyed object. - return memnew( ExampleRef() ); -} - -godot::Ref Example::extendedRefChecks( godot::Ref inRef ) const -{ - // This is the preferred way of instancing and returning a refcounted object: - godot::Ref ref; - ref.instantiate(); - - godot::UtilityFunctions::print( - " Example ref checks called with value: ", inRef->get_instance_id(), - ", returning value: ", ref->get_instance_id() ); - - return ref; -} - -godot::Variant Example::varargsFunc( const godot::Variant **inArgs, GDExtensionInt inArgCount, - GDExtensionCallError &outError ) -{ - UNUSED( inArgs ); - UNUSED( outError ); - - godot::UtilityFunctions::print( " Varargs (Variant return) called with ", - godot::String::num_int64( inArgCount ), " arguments" ); - - return inArgCount; -} - -int Example::varargsFuncNonVoidReturn( const godot::Variant **inArgs, GDExtensionInt inArgCount, - GDExtensionCallError &outError ) -{ - UNUSED( inArgs ); - UNUSED( outError ); - - godot::UtilityFunctions::print( " Varargs (int return) called with ", - godot::String::num_int64( inArgCount ), " arguments" ); - - return MAGIC_NUMBER; -} - -void Example::varargsFuncVoidReturn( const godot::Variant **inArgs, GDExtensionInt inArgCount, - GDExtensionCallError &outError ) -{ - UNUSED( inArgs ); - UNUSED( outError ); - - godot::UtilityFunctions::print( " Varargs (no return) called with ", - godot::String::num_int64( inArgCount ), " arguments" ); -} - -void Example::emitCustomSignal( const godot::String &inName, int inValue ) -{ - emit_signal( "custom_signal", inName, inValue ); -} - -int Example::defArgs( int inA, int inB ) const -{ - return inA + inB; -} - -godot::Array Example::testArray() const -{ - godot::Array arr; - - arr.resize( 2 ); - arr[0] = godot::Variant( 1 ); - arr[1] = godot::Variant( 2 ); - - return arr; -} - -void Example::testTypedArrayArg( const godot::TypedArray &inArray ) -{ - for ( int i = 0; i < inArray.size(); ++i ) - { - godot::UtilityFunctions::print( inArray[i] ); - } -} - -godot::TypedArray Example::testTypedArray() const -{ - godot::TypedArray arr; - - arr.resize( 2 ); - arr[0] = godot::Vector2( 1, 2 ); - arr[1] = godot::Vector2( 2, 3 ); - - return arr; -} - -godot::Dictionary Example::testDictionary() const -{ - godot::Dictionary dict; - - dict["hello"] = "world"; - dict["foo"] = "bar"; - - return dict; -} - -Example *Example::testNodeArgument( Example *inNode ) const -{ - // This should use godot::String::num_uint64(), but it is currently broken: - // https://github.com/godotengine/godot-cpp/issues/1014 - godot::UtilityFunctions::print( - " Test node argument called with ", - ( inNode != nullptr ) - ? godot::String::num_int64( static_cast( inNode->get_instance_id() ) ) - : "null" ); - return inNode; -} - -godot::String Example::testStringOps() const -{ - godot::String s = godot::String( "A" ); - s += "B"; - s += "C"; - s += char32_t( 0x010E ); - s = s + "E"; - - return s; -} - -godot::String Example::testStrUtility() const -{ - return godot::UtilityFunctions::str( "Hello, ", "World", "! The answer is ", 42 ); -} - -bool Example::testStringIsFortyTwo( const godot::String &inString ) const -{ - return strcmp( inString.utf8().ptr(), "forty two" ) == 0; -} - -godot::String Example::testStringResize( godot::String ioString ) const -{ - int64_t orig_len = ioString.length(); - - // This cast is to fix an issue with the API. - // See: https://github.com/godotengine/godot-cpp/issues/1338 - ioString.resize( static_cast( orig_len ) + 3 ); - - char32_t *data = ioString.ptrw(); - data[orig_len + 0] = '!'; - data[orig_len + 1] = '?'; - data[orig_len + 2] = '\0'; - - return ioString; -} - -int Example::testVectorOps() const -{ - godot::PackedInt32Array arr; - arr.push_back( 10 ); - arr.push_back( 20 ); - arr.push_back( 30 ); - arr.push_back( 45 ); - - int ret = 0; - for ( const int32_t &E : arr ) - { - ret += E; - } - - return ret; -} - -bool Example::testObjectCastToNode( godot::Object *inObject ) const -{ - return godot::Object::cast_to( inObject ) != nullptr; -} - -bool Example::testObjectCastToControl( godot::Object *inObject ) const -{ - return godot::Object::cast_to( inObject ) != nullptr; -} - -bool Example::testObjectCastToExample( godot::Object *inObject ) const -{ - return godot::Object::cast_to( inObject ) != nullptr; -} - -godot::Vector2i Example::testVariantVector2iConversion( const godot::Variant &inVariant ) const -{ - return inVariant; -} - -int Example::testVariantIntConversion( const godot::Variant &inVariant ) const -{ - return inVariant; -} - -float Example::testVariantFloatConversion( const godot::Variant &inVariant ) const -{ - return inVariant; -} - -godot::Variant Example::testVariantCall( godot::Variant inVariant ) -{ - return inVariant.call( "test", "hello" ); -} - -godot::Variant Example::testVariantIterator( const godot::Variant &inVariant ) -{ - godot::Array output; - godot::Variant iter; - - bool is_init_valid = true; - - if ( !inVariant.iter_init( iter, is_init_valid ) ) - { - if ( !is_init_valid ) - { - return "iter_init: not valid"; - } - - return output; - } - - bool is_iter_next_valid = true; - bool is_iter_get_valid = true; - - do - { - if ( !is_iter_next_valid ) - { - return "iter_next: not valid"; - } - - godot::Variant value = inVariant.iter_get( iter, is_iter_get_valid ); - - if ( !is_iter_get_valid ) - { - return "iter_get: not valid"; - } - - output.push_back( ( static_cast( value ) ) + 5 ); - - } while ( inVariant.iter_next( iter, is_iter_next_valid ) ); - - if ( !is_iter_next_valid ) - { - return "iter_next: not valid"; - } - - return output; -} - -void Example::testAddChild( godot::Node *inNode ) -{ - add_child( inNode ); -} - -void Example::testSetTileset( godot::TileMap *inTilemap, - const godot::Ref &inTileset ) const -{ - inTilemap->set_tileset( inTileset ); -} - -godot::Callable Example::testCallableMP() -{ - return callable_mp( this, &Example::unboundMethod1 ); -} - -godot::Callable Example::testCallableMPRet() -{ - return callable_mp( this, &Example::unboundMethod2 ); -} - -godot::Callable Example::testCallableMPRetC() const -{ - return callable_mp( this, &Example::unboundMethod3 ); -} - -godot::Callable Example::testCallableMPStatic() const -{ - return callable_mp_static( &Example::unboundStaticMethod1 ); -} - -godot::Callable Example::testCallableMPStaticRet() const -{ - return callable_mp_static( &Example::unboundStaticMethod2 ); -} - -godot::Callable Example::testCustomCallable() const -{ - return godot::Callable( memnew( MyCallableCustom ) ); -} - -void Example::callableBind() -{ - godot::Callable c = godot::Callable( this, "emit_custom_signal" ).bind( "bound", 11 ); - c.call(); -} - -void Example::unboundMethod1( godot::Object *inObject, godot::String inString, int inInt ) -{ - godot::String test = "unbound_method1: "; - test += inObject->get_class(); - test += " - " + inString; - emitCustomSignal( test, inInt ); -} - -godot::String Example::unboundMethod2( godot::Object *inObject, godot::String inString, int inInt ) -{ - godot::String test = "unbound_method2: "; - test += inObject->get_class(); - test += " - " + inString; - test += " - " + godot::itos( inInt ); - return test; -} - -godot::String Example::unboundMethod3( godot::Object *inObject, godot::String inString, - int inInt ) const -{ - godot::String test = "unbound_method3: "; - test += inObject->get_class(); - test += " - " + inString; - test += " - " + godot::itos( inInt ); - return test; -} - -void Example::unboundStaticMethod1( Example *inObject, godot::String inString, int inInt ) -{ - godot::String test = "unbound_static_method1: "; - test += inObject->get_class(); - test += " - " + inString; - inObject->emitCustomSignal( test, inInt ); -} - -godot::String Example::unboundStaticMethod2( godot::Object *inObject, godot::String inString, - int inInt ) -{ - godot::String test = "unbound_static_method2: "; - test += inObject->get_class(); - test += " - " + inString; - test += " - " + godot::itos( inInt ); - return test; -} - -godot::BitField Example::testBitfield( godot::BitField inFlags ) -{ - godot::UtilityFunctions::print( " Got BitField: ", godot::String::num_int64( inFlags ) ); - return inFlags; -} - -// RPC -void Example::testRPC( int inValue ) -{ - mLastRPCArg = inValue; -} - -void Example::testSendRPC( int inValue ) -{ - rpc( "test_rpc", inValue ); -} - -int Example::returnLastRPCArg() -{ - return mLastRPCArg; -} - -// Properties -void Example::setCustomPosition( const godot::Vector2 &inPos ) -{ - mCustomPosition = inPos; -} - -godot::Vector2 Example::getCustomPosition() const -{ - return mCustomPosition; -} - -godot::Vector4 Example::getV4() const -{ - return { 1.2f, 3.4f, 5.6f, 7.8f }; -} - -bool Example::testPostInitialize() const -{ - godot::Ref new_example_ref; - - new_example_ref.instantiate(); - - return new_example_ref->wasPostInitialized(); -} - -// Static methods -int Example::testStatic( int inA, int inB ) -{ - return inA + inB; -} - -void Example::testStatic2() -{ - godot::UtilityFunctions::print( " void static" ); -} - -// Virtual function override. -bool Example::_has_point( const godot::Vector2 &inPoint ) const -{ - auto *label = godot::Control::get_node( "Label" ); - - label->set_text( "Got point: " + godot::Variant( inPoint ).stringify() ); - - return false; -} - -void Example::_bind_methods() -{ - // Methods. - godot::ClassDB::bind_method( godot::D_METHOD( "simple_func" ), &Example::simpleFunc ); - godot::ClassDB::bind_method( godot::D_METHOD( "simple_const_func" ), - &Example::simpleConstFunc ); - godot::ClassDB::bind_method( godot::D_METHOD( "return_something" ), &Example::returnSomething ); - godot::ClassDB::bind_method( godot::D_METHOD( "return_something_const" ), - &Example::returnSomethingConst ); - godot::ClassDB::bind_method( godot::D_METHOD( "return_empty_ref" ), &Example::returnEmptyRef ); - godot::ClassDB::bind_method( godot::D_METHOD( "return_extended_ref" ), - &Example::returnExtendedRef ); - godot::ClassDB::bind_method( godot::D_METHOD( "extended_ref_checks", "ref" ), - &Example::extendedRefChecks ); - - godot::ClassDB::bind_method( godot::D_METHOD( "test_array" ), &Example::testArray ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_tarray_arg", "array" ), - &Example::testTypedArrayArg ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_tarray" ), &Example::testTypedArray ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_dictionary" ), &Example::testDictionary ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_node_argument" ), - &Example::testNodeArgument ); - - godot::ClassDB::bind_method( godot::D_METHOD( "test_string_ops" ), &Example::testStringOps ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_str_utility" ), &Example::testStrUtility ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_string_is_forty_two" ), - &Example::testStringIsFortyTwo ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_string_resize" ), - &Example::testStringResize ); - - godot::ClassDB::bind_method( godot::D_METHOD( "test_vector_ops" ), &Example::testVectorOps ); - - godot::ClassDB::bind_method( godot::D_METHOD( "test_object_cast_to_node", "object" ), - &Example::testObjectCastToNode ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_object_cast_to_control", "object" ), - &Example::testObjectCastToControl ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_object_cast_to_example", "object" ), - &Example::testObjectCastToExample ); - - godot::ClassDB::bind_method( godot::D_METHOD( "test_variant_vector2i_conversion", "variant" ), - &Example::testVariantVector2iConversion ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_variant_int_conversion", "variant" ), - &Example::testVariantIntConversion ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_variant_float_conversion", "variant" ), - &Example::testVariantFloatConversion ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_variant_call", "variant" ), - &Example::testVariantCall ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_variant_iterator", "input" ), - &Example::testVariantIterator ); - - godot::ClassDB::bind_method( godot::D_METHOD( "test_add_child", "node" ), - &Example::testAddChild ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_set_tileset", "tilemap", "tileset" ), - &Example::testSetTileset ); - - godot::ClassDB::bind_method( godot::D_METHOD( "test_callable_mp" ), &Example::testCallableMP ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_callable_mp_ret" ), - &Example::testCallableMPRet ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_callable_mp_retc" ), - &Example::testCallableMPRetC ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_callable_mp_static" ), - &Example::testCallableMPStatic ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_callable_mp_static_ret" ), - &Example::testCallableMPStaticRet ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_custom_callable" ), - &Example::testCustomCallable ); - - godot::ClassDB::bind_method( godot::D_METHOD( "test_bitfield", "flags" ), - &Example::testBitfield ); - - godot::ClassDB::bind_method( godot::D_METHOD( "test_rpc", "value" ), &Example::testRPC ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_send_rpc", "value" ), - &Example::testSendRPC ); - godot::ClassDB::bind_method( godot::D_METHOD( "return_last_rpc_arg" ), - &Example::returnLastRPCArg ); - - godot::ClassDB::bind_method( godot::D_METHOD( "def_args", "a", "b" ), &Example::defArgs, - DEFVAL( 100 ), DEFVAL( 200 ) ); - godot::ClassDB::bind_method( godot::D_METHOD( "callable_bind" ), &Example::callableBind ); - godot::ClassDB::bind_method( godot::D_METHOD( "test_post_initialize" ), - &Example::testPostInitialize ); - - godot::ClassDB::bind_static_method( "Example", godot::D_METHOD( "test_static", "a", "b" ), - &Example::testStatic ); - godot::ClassDB::bind_static_method( "Example", godot::D_METHOD( "test_static2" ), - &Example::testStatic2 ); - - { - godot::MethodInfo mi; - mi.arguments.emplace_back( godot::Variant::STRING, "some_argument" ); - mi.name = "varargs_func"; - - godot::ClassDB::bind_vararg_method( godot::METHOD_FLAGS_DEFAULT, "varargs_func", - &Example::varargsFunc, mi ); - } - - { - godot::MethodInfo mi; - mi.arguments.emplace_back( godot::Variant::STRING, "some_argument" ); - mi.name = "varargs_func_nv"; - - godot::ClassDB::bind_vararg_method( godot::METHOD_FLAGS_DEFAULT, "varargs_func_nv", - &Example::varargsFuncNonVoidReturn, mi ); - } - - { - godot::MethodInfo mi; - mi.arguments.emplace_back( godot::Variant::STRING, "some_argument" ); - mi.name = "varargs_func_void"; - - godot::ClassDB::bind_vararg_method( godot::METHOD_FLAGS_DEFAULT, "varargs_func_void", - &Example::varargsFuncVoidReturn, mi ); - } - - // Properties. - ADD_GROUP( "Test group", "group_" ); - ADD_SUBGROUP( "Test subgroup", "group_subgroup_" ); - - godot::ClassDB::bind_method( godot::D_METHOD( "get_custom_position" ), - &Example::getCustomPosition ); - godot::ClassDB::bind_method( godot::D_METHOD( "get_v4" ), &Example::getV4 ); - godot::ClassDB::bind_method( godot::D_METHOD( "set_custom_position", "position" ), - &Example::setCustomPosition ); - ADD_PROPERTY( godot::PropertyInfo( godot::Variant::VECTOR2, "group_subgroup_custom_position" ), - "set_custom_position", "get_custom_position" ); - - // Signals. - ADD_SIGNAL( godot::MethodInfo( "custom_signal", - godot::PropertyInfo( godot::Variant::STRING, "name" ), - godot::PropertyInfo( godot::Variant::INT, "value" ) ) ); - godot::ClassDB::bind_method( godot::D_METHOD( "emit_custom_signal", "name", "value" ), - &Example::emitCustomSignal ); - - // Constants. - BIND_ENUM_CONSTANT( FIRST ) - BIND_ENUM_CONSTANT( ANSWER_TO_EVERYTHING ) - - BIND_BITFIELD_FLAG( FLAG_ONE ); - BIND_BITFIELD_FLAG( FLAG_TWO ); - - BIND_CONSTANT( CONSTANT_WITHOUT_ENUM ); - BIND_ENUM_CONSTANT( OUTSIDE_OF_CLASS ); -} - -void Example::_notification( int inWhat ) -{ - godot::UtilityFunctions::print( "Notification: ", godot::String::num( inWhat ) ); -} - -bool Example::_set( const godot::StringName &inName, const godot::Variant &inValue ) -{ - godot::String name = inName; - - if ( name.begins_with( "dproperty" ) ) - { - int64_t index = name.get_slicec( '_', 1 ).to_int(); - mDProp[index] = inValue; - - return true; - } - - if ( name == "property_from_list" ) - { - mPropertyFromList = inValue; - - return true; - } - - return false; -} - -bool Example::_get( const godot::StringName &inName, godot::Variant &outReturn ) const -{ - godot::String name = inName; - - if ( name.begins_with( "dproperty" ) ) - { - int64_t index = name.get_slicec( '_', 1 ).to_int(); - outReturn = mDProp[index]; - - return true; - } - - if ( name == "property_from_list" ) - { - outReturn = mPropertyFromList; - - return true; - } - - return false; -} - -void Example::_get_property_list( godot::List *outList ) const -{ - outList->push_back( godot::PropertyInfo( godot::Variant::VECTOR3, "property_from_list" ) ); - - for ( int i = 0; i < 3; ++i ) - { - outList->push_back( - godot::PropertyInfo( godot::Variant::VECTOR2, "dproperty_" + godot::itos( i ) ) ); - } -} - -bool Example::_property_can_revert( const godot::StringName &inName ) const -{ - if ( inName == godot::StringName( "property_from_list" ) && - mPropertyFromList != godot::Vector3( MAGIC_NUMBER, MAGIC_NUMBER, MAGIC_NUMBER ) ) - { - return true; - } - - return false; -}; - -bool Example::_property_get_revert( const godot::StringName &inName, - godot::Variant &outProperty ) const -{ - if ( inName == godot::StringName( "property_from_list" ) ) - { - outProperty = godot::Vector3( MAGIC_NUMBER, MAGIC_NUMBER, MAGIC_NUMBER ); - - return true; - } - - return false; -}; - -void Example::_validate_property( godot::PropertyInfo &inProperty ) const -{ - godot::String name = inProperty.name; - - // Test hiding the "mouse_filter" property from the editor. - if ( name == "mouse_filter" ) - { - inProperty.usage = godot::PROPERTY_USAGE_NO_EDITOR; - } -} - -godot::String Example::_to_string() const -{ - return "[ GDExtension::Example <--> Instance ID:" + godot::uitos( get_instance_id() ) + " ]"; -} - -//// ExampleVirtual - -void ExampleVirtual::_bind_methods() -{ -} - -//// ExampleAbstract - -void ExampleAbstract::_bind_methods() -{ -} diff --git a/src/gdextension/Example.h b/src/gdextension/Example.h deleted file mode 100644 index dc876a8c..00000000 --- a/src/gdextension/Example.h +++ /dev/null @@ -1,200 +0,0 @@ -#pragma once -// Copied from godot-cpp/test/src and modified. - -#include "godot_cpp/classes/control.hpp" -#include "godot_cpp/classes/global_constants.hpp" -#include "godot_cpp/classes/tile_map.hpp" -#include "godot_cpp/classes/tile_set.hpp" -#include "godot_cpp/classes/viewport.hpp" -#include "godot_cpp/core/binder_common.hpp" -#include "godot_cpp/variant/variant.hpp" - -class ExampleRef : public godot::RefCounted -{ - GDCLASS( ExampleRef, RefCounted ) - -public: - ExampleRef(); - ~ExampleRef() override; - - void setId( int inID ); - int getID() const; - - bool wasPostInitialized() const - { - return mPostInitialized; - } - -protected: - static void _bind_methods(); - - void _notification( int inWhat ); - -private: - static int sInstanceCount; - static int sLastID; - - int mID; - bool mPostInitialized = false; -}; - -class ExampleMin : public godot::Control -{ - GDCLASS( ExampleMin, Control ) - -protected: - static void _bind_methods(); -}; - -class Example : public godot::Control -{ - GDCLASS( Example, godot::Control ) - -public: - // Constants. - enum Constants - { - FIRST, - ANSWER_TO_EVERYTHING = 42, - }; - - enum - { - CONSTANT_WITHOUT_ENUM = 314, - }; - - enum Flags - { - FLAG_ONE = 1, - FLAG_TWO = 2, - }; - - Example(); - ~Example() override; - - // Functions. - void simpleFunc(); - void simpleConstFunc() const; - godot::String returnSomething( const godot::String &inBase ); - godot::Viewport *returnSomethingConst() const; - godot::Ref returnEmptyRef() const; - ExampleRef *returnExtendedRef() const; - godot::Ref extendedRefChecks( godot::Ref inRef ) const; - godot::Variant varargsFunc( const godot::Variant **inArgs, GDExtensionInt inArgCount, - GDExtensionCallError &outError ); - int varargsFuncNonVoidReturn( const godot::Variant **inArgs, GDExtensionInt inArgCount, - GDExtensionCallError &outError ); - void varargsFuncVoidReturn( const godot::Variant **inArgs, GDExtensionInt inArgCount, - GDExtensionCallError &outError ); - - void emitCustomSignal( const godot::String &inName, int inValue ); - int defArgs( int inA = 100, int inB = 200 ) const; - - godot::Array testArray() const; - void testTypedArrayArg( const godot::TypedArray &inArray ); - godot::TypedArray testTypedArray() const; - godot::Dictionary testDictionary() const; - Example *testNodeArgument( Example *inNode ) const; - godot::String testStringOps() const; - godot::String testStrUtility() const; - bool testStringIsFortyTwo( const godot::String &inString ) const; - godot::String testStringResize( godot::String ioString ) const; - int testVectorOps() const; - - bool testObjectCastToNode( godot::Object *inObject ) const; - bool testObjectCastToControl( godot::Object *inObject ) const; - bool testObjectCastToExample( godot::Object *inObject ) const; - - godot::Vector2i testVariantVector2iConversion( const godot::Variant &inVariant ) const; - int testVariantIntConversion( const godot::Variant &inVariant ) const; - float testVariantFloatConversion( const godot::Variant &inVariant ) const; - godot::Variant testVariantCall( godot::Variant inVariant ); - godot::Variant testVariantIterator( const godot::Variant &inVariant ); - - void testAddChild( godot::Node *inNode ); - void testSetTileset( godot::TileMap *inTilemap, - const godot::Ref &inTileset ) const; - - godot::Callable testCallableMP(); - godot::Callable testCallableMPRet(); - godot::Callable testCallableMPRetC() const; - godot::Callable testCallableMPStatic() const; - godot::Callable testCallableMPStaticRet() const; - godot::Callable testCustomCallable() const; - - void callableBind(); - - void unboundMethod1( godot::Object *inObject, godot::String inString, int inInt ); - godot::String unboundMethod2( godot::Object *inObject, godot::String inString, int inInt ); - godot::String unboundMethod3( godot::Object *inObject, godot::String inString, - int inInt ) const; - static void unboundStaticMethod1( Example *inObject, godot::String inString, int inInt ); - static godot::String unboundStaticMethod2( godot::Object *inObject, godot::String inString, - int inInt ); - - godot::BitField testBitfield( godot::BitField inFlags ); - - // RPC - void testRPC( int inValue ); - void testSendRPC( int inValue ); - int returnLastRPCArg(); - - // Property - void setCustomPosition( const godot::Vector2 &inPos ); - godot::Vector2 getCustomPosition() const; - godot::Vector4 getV4() const; - - bool testPostInitialize() const; - - // Static method. - static int testStatic( int inA, int inB ); - static void testStatic2(); - - // Virtual function override (no need to bind manually). - virtual bool _has_point( const godot::Vector2 &inPoint ) const override; - -protected: - static void _bind_methods(); - - void _notification( int inWhat ); - bool _set( const godot::StringName &inName, const godot::Variant &inValue ); - bool _get( const godot::StringName &inName, godot::Variant &outReturn ) const; - void _get_property_list( godot::List *outList ) const; - bool _property_can_revert( const godot::StringName &inName ) const; - bool _property_get_revert( const godot::StringName &inName, godot::Variant &outProperty ) const; - void _validate_property( godot::PropertyInfo &inProperty ) const; - - godot::String _to_string() const; - -private: - godot::Vector2 mCustomPosition; - godot::Vector3 mPropertyFromList; - godot::Vector2 mDProp[3]; - - int mLastRPCArg = 0; -}; - -VARIANT_ENUM_CAST( Example::Constants ); -VARIANT_BITFIELD_CAST( Example::Flags ); - -enum EnumWithoutClass -{ - OUTSIDE_OF_CLASS = 512 -}; -VARIANT_ENUM_CAST( EnumWithoutClass ); - -class ExampleVirtual : public godot::Object -{ - GDCLASS( ExampleVirtual, godot::Object ) - -protected: - static void _bind_methods(); -}; - -class ExampleAbstract : public godot::Object -{ - GDCLASS( ExampleAbstract, godot::Object ) - -protected: - static void _bind_methods(); -}; diff --git a/src/gdextension/GDExtensionTemplate.cpp b/src/gdextension/GDExtensionTemplate.cpp deleted file mode 100644 index dd2f373c..00000000 --- a/src/gdextension/GDExtensionTemplate.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-License-Identifier: Unlicense - -#include "godot_cpp/core/class_db.hpp" -#include "godot_cpp/core/version.hpp" - -#include "GDExtensionTemplate.h" - -/// @file -/// GDExtensionTemplate example implementation. - -/*! -@brief Get the version string for this extension. - -@details -The version string is generated by cmake using src/Version.h.in. - -It uses the form " -<# commits since last tag>-". -If there are no commits since the last tag, only the tag is shown. - -@return The version string (e.g. "Foo v1.2.3-gdedbd01"). -*/ -godot::String GDExtensionTemplate::version() -{ - return "osp-gdextension v0.0.1"; -} - -/*! -@brief Get the godot-cpp version string for this extension. - -@details -The version string is generated using godot-cpp's core/version.hpp. - -@return The version string (e.g. "godot-cpp v4.2.0-stable"). -*/ -godot::String GDExtensionTemplate::godotCPPVersion() -{ - return "godot-cpp v" + godot::uitos( GODOT_VERSION_MAJOR ) + "." + - godot::uitos( GODOT_VERSION_MINOR ) + "." + godot::uitos( GODOT_VERSION_PATCH ) + "-" + - GODOT_VERSION_STATUS; -} - -/// Bind our methods so GDScript can access them. -void GDExtensionTemplate::_bind_methods() -{ - godot::ClassDB::bind_static_method( "GDExtensionTemplate", godot::D_METHOD( "version" ), - &GDExtensionTemplate::version ); - godot::ClassDB::bind_static_method( "GDExtensionTemplate", - godot::D_METHOD( "godot_cpp_version" ), - &GDExtensionTemplate::godotCPPVersion ); -} diff --git a/src/gdextension/GDExtensionTemplate.h b/src/gdextension/GDExtensionTemplate.h deleted file mode 100644 index 5eb40d01..00000000 --- a/src/gdextension/GDExtensionTemplate.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -// SPDX-License-Identifier: Unlicense - -#include "godot_cpp/classes/object.hpp" - -namespace godot -{ - class ClassDB; -}; - -class GDExtensionTemplate : public godot::Object -{ - GDCLASS( GDExtensionTemplate, godot::Object ) - -public: - static godot::String version(); - static godot::String godotCPPVersion(); - -private: - static void _bind_methods(); -}; diff --git a/src/gdextension/RegisterExtension.cpp b/src/gdextension/RegisterExtension.cpp deleted file mode 100644 index 699c4ee2..00000000 --- a/src/gdextension/RegisterExtension.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copied from godot-cpp/test/src and modified. - -#include "gdextension_interface.h" - -#include "godot_cpp/core/class_db.hpp" -#include "godot_cpp/core/defs.hpp" -#include "godot_cpp/godot.hpp" - -#include "Example.h" -#include "GDExtensionTemplate.h" - -/// @file -/// Register our classes with Godot. - -namespace -{ - /// @brief Called by Godot to let us register our classes with Godot. - /// - /// @param p_level the level being initialized by Godot - /// - /// @see GDExtensionInit - void initializeExtension( godot::ModuleInitializationLevel p_level ) - { - if ( p_level != godot::MODULE_INITIALIZATION_LEVEL_SCENE ) - { - return; - } - - godot::ClassDB::register_class(); - godot::ClassDB::register_class(); - godot::ClassDB::register_class(); - godot::ClassDB::register_class( true ); - godot::ClassDB::register_abstract_class(); - - godot::ClassDB::register_class(); - } - - /// @brief Called by Godot to let us do any cleanup. - /// - /// @see GDExtensionInit - void uninitializeExtension( godot::ModuleInitializationLevel p_level ) - { - if ( p_level != godot::MODULE_INITIALIZATION_LEVEL_SCENE ) - { - return; - } - } -} - -extern "C" -{ - /// @brief This is the entry point for the shared library. - /// - /// @note The name of this function must match the "entry_symbol" in - /// templates/template.*.gdextension.in - /// - /// @param p_get_proc_address the interface (need more info) - /// @param p_library the library (need more info) - /// @param r_initialization the intialization (need more info) - /// - /// @returns GDExtensionBool - GDExtensionBool GDE_EXPORT GDExtensionInit( - GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, - GDExtensionInitialization *r_initialization ) - { - { - godot::GDExtensionBinding::InitObject init_obj( p_get_proc_address, p_library, - r_initialization ); - - init_obj.register_initializer( initializeExtension ); - init_obj.register_terminator( uninitializeExtension ); - init_obj.set_minimum_library_initialization_level( - godot::MODULE_INITIALIZATION_LEVEL_SCENE ); - - return init_obj.init(); - } - } -} diff --git a/src/gdextension/flying_scene.cpp b/src/gdextension/flying_scene.cpp new file mode 100644 index 00000000..ea5ac773 --- /dev/null +++ b/src/gdextension/flying_scene.cpp @@ -0,0 +1,81 @@ +#include "flying_scene.h" +#include "ospjolt/joltinteg.h" +#include "ospjolt/joltinteg_fn.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace godot; + +void FlyingScene::_bind_methods() +{ +} + +FlyingScene::FlyingScene() +{ + // Initialize any variables here. + time_passed = 0.0; +} + +FlyingScene::~FlyingScene() +{ + delete joltWorld; +} + +void FlyingScene::_enter_tree() +{ + RenderingServer* renderingServer = RenderingServer::get_singleton(); + scenario = get_world_3d()->get_scenario(); + viewport = get_viewport()->get_viewport_rid(); + mainCamera = renderingServer->camera_create(); + renderingServer->viewport_attach_camera(viewport, mainCamera); + + Transform3D cform = Transform3D(Basis(), Vector3(0, 0, 4)); + renderingServer->camera_set_transform(mainCamera, cform); + renderingServer->viewport_set_scenario(viewport, scenario); + + lightInstance = renderingServer->instance_create(); + renderingServer->instance_set_scenario(lightInstance, scenario); + + RID light = renderingServer->directional_light_create(); + renderingServer->instance_set_base(lightInstance, light); + + Transform3D lform = Transform3D(Basis().rotated(Vector3(1, 1, 0), -1.3), Vector3(0., 0., 0.)); + renderingServer->instance_set_transform(lightInstance, lform); + + godot::UtilityFunctions::print("Created viewport, camera, scenario, and light"); + + //init physics + ospjolt::ACtxJoltWorld::initJoltGlobal(); + joltWorld = new ospjolt::ACtxJoltWorld(); + + godot::UtilityFunctions::print("Init physics"); + +} + +void FlyingScene::_ready() +{ + RenderingServer* renderingServer = RenderingServer::get_singleton(); + RID instance = renderingServer->instance_create(); + renderingServer->instance_set_scenario(instance, scenario); + + RID mesh = renderingServer->make_sphere_mesh(10, 10, 1); + renderingServer->instance_set_base(instance, mesh); + + Transform3D xform = Transform3D(Basis(), Vector3(0.5, 0, 0)); + renderingServer->instance_set_transform(instance, xform); + +} + +void FlyingScene::_physics_process(double delta) +{ + // ospjolt::SysJolt::update_world() update the world +} + diff --git a/src/gdextension/flying_scene.h b/src/gdextension/flying_scene.h new file mode 100644 index 00000000..ff37e33a --- /dev/null +++ b/src/gdextension/flying_scene.h @@ -0,0 +1,32 @@ +#pragma once + +#include "ospjolt/joltinteg.h" +#include + +namespace godot { + +class FlyingScene : public Node3D { + GDCLASS(FlyingScene, Node3D) + +private: + double time_passed; + RID scenario; + RID viewport; + RID mainCamera; + RID lightInstance; + ospjolt::ACtxJoltWorld* joltWorld; + +protected: + static void _bind_methods(); + +public: + FlyingScene(); + ~FlyingScene(); + + //void _process(double delta) override; + void _enter_tree() override; + void _ready() override; + void _physics_process(double delta) override; +}; + +} \ No newline at end of file diff --git a/src/gdextension/register_types.cpp b/src/gdextension/register_types.cpp new file mode 100644 index 00000000..d661b033 --- /dev/null +++ b/src/gdextension/register_types.cpp @@ -0,0 +1,36 @@ +#include "register_types.h" + +#include "flying_scene.h" + +#include +#include +#include + +using namespace godot; + +void godot::initialize_example_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } + + ClassDB::register_class(); +} + +void godot::uninitialize_example_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } +} + +extern "C" { +// Initialization. +GDExtensionBool GDE_EXPORT example_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) { + godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization); + + init_obj.register_initializer(initialize_example_module); + init_obj.register_terminator(uninitialize_example_module); + init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE); + + return init_obj.init(); +} +} \ No newline at end of file diff --git a/src/gdextension/register_types.h b/src/gdextension/register_types.h new file mode 100644 index 00000000..a3bc5591 --- /dev/null +++ b/src/gdextension/register_types.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace godot { + +void initialize_example_module(ModuleInitializationLevel p_level); +void uninitialize_example_module(ModuleInitializationLevel p_level); + +} \ No newline at end of file diff --git a/src/gdextension/templates/osp.gdextension b/src/gdextension/templates/osp.gdextension index 7111f874..876303c6 100644 --- a/src/gdextension/templates/osp.gdextension +++ b/src/gdextension/templates/osp.gdextension @@ -1,5 +1,5 @@ [configuration] -entry_symbol = "GDExtensionInit" +entry_symbol = "example_library_init" compatibility_minimum = 4.1 [icons] diff --git a/src/testapp/CMakeLists.txt b/src/testapp/CMakeLists.txt index 41de853c..f23ef47c 100644 --- a/src/testapp/CMakeLists.txt +++ b/src/testapp/CMakeLists.txt @@ -24,85 +24,36 @@ ## find_package(Magnum REQUIRED - GL - Shaders - MeshTools - Primitives Trade - Sdl2Application - AnyImageImporter ) -find_package(MagnumPlugins REQUIRED - TinyGltfImporter - StbImageImporter) - -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) -if(NOT Threads_FOUND) - message(FATAL_ERROR "Can't find a thread library to use!") -endif() - - -add_library(osp-magnum-deps INTERFACE) -add_custom_target(compile-osp-magnum-deps) - # TODO: This list shouldn't be required, but there appears to be a bug in cmake where # the add_custom_target() command, pointing to an INTERFACE dependency, doesn't # result in the dependencies of the interface building. # See: https://gitlab.kitware.com/cmake/cmake/-/issues/23569 -SET(OSP_MAGNUM_DEPS_LIBS +SET(OSP_DEPS_LIBS Threads::Threads EnTT::EnTT Corrade::Main - Magnum::Application - Magnum::GL Magnum::Magnum - Magnum::MeshTools - Magnum::Primitives - Magnum::Shaders Magnum::Trade - Magnum::AnyImageImporter - MagnumPlugins::TinyGltfImporter - MagnumPlugins::StbImageImporter toml11 spdlog longeron OpenSpaceProgram Adera - AderaGL - OspGL OspJolt PlanetA) -target_link_libraries(osp-magnum-deps INTERFACE ${OSP_MAGNUM_DEPS_LIBS}) -add_dependencies(compile-osp-magnum-deps ${OSP_MAGNUM_DEPS_LIBS}) -add_executable(osp-magnum) +add_library(OspTestApp STATIC) +target_link_libraries(OspTestApp PRIVATE ${OSP_DEPS_LIBS}) -target_compile_features(osp-magnum PUBLIC cxx_std_20) - -target_include_directories(osp-magnum PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - -# Link it to the interface library that describes the dependencies -target_link_libraries(osp-magnum PRIVATE osp-magnum-deps) +target_compile_features(OspTestApp PUBLIC cxx_std_20) # Gather paths to OSP headers and sources file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) -target_sources(osp-magnum PRIVATE "${CPP_FILES}" "${H_FILES}") +target_sources(OspTestApp PRIVATE "${CPP_FILES}" "${H_FILES}") # Enforce conformance mode for osp-magnum -target_compile_options(osp-magnum PRIVATE $<$:/permissive->) - -set_target_properties(osp-magnum PROPERTIES - EXPORT_COMPILE_COMMANDS TRUE - INSTALL_RPATH "$ORIGIN/lib" - C_EXTENSIONS OFF - C_STANDARD_REQUIRED ON - CXX_EXTENSIONS OFF - CXX_STANDARD_REQUIRED ON -) - -add_custom_target(run-osp-magnum - COMMAND $ - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/$) +target_compile_options(OspTestApp PRIVATE $<$:/permissive->) diff --git a/src/testapp/identifiers.h b/src/testapp/identifiers.h index 154c7fd7..0e25d04c 100644 --- a/src/testapp/identifiers.h +++ b/src/testapp/identifiers.h @@ -25,6 +25,13 @@ #pragma once #include +#include +#include +#include +#include +#include + +#include #include @@ -474,4 +481,14 @@ struct PlVehicleCtrl PipelineDef selectedVehicle {"selectedVehicle"}; }; +namespace scenes { + using enum EStgOptn; + using enum EStgCont; + using enum EStgIntr; + using enum EStgRevd; + using enum EStgEvnt; + using enum EStgFBO; + using enum EStgLink; +} + } // namespace testapp diff --git a/src/testapp/scenarios.h b/src/testapp/scenarios.h index 8beed14a..6cf27313 100644 --- a/src/testapp/scenarios.h +++ b/src/testapp/scenarios.h @@ -25,14 +25,11 @@ #pragma once #include "identifiers.h" -#include "testapp.h" // IWYU pragma: begin_exports #include // IWYU pragma: end_exports -#include - namespace testapp { @@ -55,14 +52,4 @@ struct MainLoopControl bool doRender; }; -struct ScenarioOption -{ - std::string_view m_description; - SceneSetupFunc_t m_setup; -}; - -using ScenarioMap_t = std::unordered_map; - -ScenarioMap_t const& scenarios(); - } // namespace testapp diff --git a/src/testapp/sessions/common.cpp b/src/testapp/sessions/common.cpp index cf752c7e..a7cd1021 100644 --- a/src/testapp/sessions/common.cpp +++ b/src/testapp/sessions/common.cpp @@ -23,6 +23,7 @@ * SOFTWARE. */ #include "common.h" +#include "../identifiers.h" #include "../scenarios.h" #include diff --git a/src/testapp/sessions/common.h b/src/testapp/sessions/common.h index c67f95b6..986b4fba 100644 --- a/src/testapp/sessions/common.h +++ b/src/testapp/sessions/common.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include diff --git a/src/testapp/sessions/jolt.cpp b/src/testapp/sessions/jolt.cpp index ccf886cb..dcb6962a 100644 --- a/src/testapp/sessions/jolt.cpp +++ b/src/testapp/sessions/jolt.cpp @@ -24,6 +24,7 @@ */ #include "jolt.h" #include "shapes.h" +#include "../identifiers.h" #include #include diff --git a/src/testapp/sessions/jolt.h b/src/testapp/sessions/jolt.h index 6acc2383..521ae6a4 100644 --- a/src/testapp/sessions/jolt.h +++ b/src/testapp/sessions/jolt.h @@ -24,12 +24,17 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include -#include -#include #include #include diff --git a/src/testapp/sessions/misc.cpp b/src/testapp/sessions/misc.cpp index 09967d1a..9cf7e474 100644 --- a/src/testapp/sessions/misc.cpp +++ b/src/testapp/sessions/misc.cpp @@ -23,7 +23,7 @@ * SOFTWARE. */ #include "misc.h" -#include "physics.h" +#include "../identifiers.h" #include #include diff --git a/src/testapp/sessions/misc.h b/src/testapp/sessions/misc.h index 012b9b2a..d7d68e04 100644 --- a/src/testapp/sessions/misc.h +++ b/src/testapp/sessions/misc.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include diff --git a/src/testapp/sessions/physics.cpp b/src/testapp/sessions/physics.cpp index 0bebbd1e..67fda25a 100644 --- a/src/testapp/sessions/physics.cpp +++ b/src/testapp/sessions/physics.cpp @@ -23,7 +23,7 @@ * SOFTWARE. */ #include "physics.h" -#include "common.h" +#include "../identifiers.h" #include #include diff --git a/src/testapp/sessions/physics.h b/src/testapp/sessions/physics.h index f8a72854..9aa8ceb5 100644 --- a/src/testapp/sessions/physics.h +++ b/src/testapp/sessions/physics.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include @@ -32,8 +39,6 @@ #include -#include - namespace testapp::scenes { diff --git a/src/testapp/sessions/shapes.cpp b/src/testapp/sessions/shapes.cpp index 1c63f583..cd971699 100644 --- a/src/testapp/sessions/shapes.cpp +++ b/src/testapp/sessions/shapes.cpp @@ -24,6 +24,7 @@ */ #include "shapes.h" #include "common.h" +#include "../identifiers.h" #include diff --git a/src/testapp/sessions/shapes.h b/src/testapp/sessions/shapes.h index c763d872..b9c57cce 100644 --- a/src/testapp/sessions/shapes.h +++ b/src/testapp/sessions/shapes.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include diff --git a/src/testapp/sessions/terrain.cpp b/src/testapp/sessions/terrain.cpp index eea97774..4f6ced0f 100644 --- a/src/testapp/sessions/terrain.cpp +++ b/src/testapp/sessions/terrain.cpp @@ -24,6 +24,8 @@ */ #include "terrain.h" #include "common.h" +#include "../identifiers.h" + #include #include diff --git a/src/testapp/sessions/terrain.h b/src/testapp/sessions/terrain.h index 13a61fde..eb18cb05 100644 --- a/src/testapp/sessions/terrain.h +++ b/src/testapp/sessions/terrain.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include "planet-a/chunk_utils.h" #include diff --git a/src/testapp/sessions/universe.cpp b/src/testapp/sessions/universe.cpp index 2537defd..7578ce1f 100644 --- a/src/testapp/sessions/universe.cpp +++ b/src/testapp/sessions/universe.cpp @@ -34,6 +34,8 @@ #include #include +#include "../identifiers.h" + #include using namespace adera; diff --git a/src/testapp/sessions/universe.h b/src/testapp/sessions/universe.h index 94039d16..2eebd69b 100644 --- a/src/testapp/sessions/universe.h +++ b/src/testapp/sessions/universe.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include diff --git a/src/testapp/sessions/vehicles.cpp b/src/testapp/sessions/vehicles.cpp index 6321ccb3..309bb459 100644 --- a/src/testapp/sessions/vehicles.cpp +++ b/src/testapp/sessions/vehicles.cpp @@ -35,6 +35,8 @@ #include #include +#include "../identifiers.h" + using namespace adera; using namespace osp::active; diff --git a/src/testapp/sessions/vehicles.h b/src/testapp/sessions/vehicles.h index 89caa031..7cc58c00 100644 --- a/src/testapp/sessions/vehicles.h +++ b/src/testapp/sessions/vehicles.h @@ -24,11 +24,20 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include + namespace testapp::scenes { + /** * @brief Support for Parts, Machines, and Links */ diff --git a/src/testapp/sessions/vehicles_machines.cpp b/src/testapp/sessions/vehicles_machines.cpp index c79660e2..92f93846 100644 --- a/src/testapp/sessions/vehicles_machines.cpp +++ b/src/testapp/sessions/vehicles_machines.cpp @@ -35,6 +35,7 @@ #include #include #include +#include "../identifiers.h" using namespace adera; @@ -223,24 +224,26 @@ Session setup_thrust_indicators( ActiveEnt const partEnt = rScnParts.partToActive[part]; for (MachinePair const pair : rScnParts.partToMachines[part]) - if (pair.type == gc_mtMagicRocket) { - DrawEnt const drawEnt = rThrustIndicator.rktToDrawEnt[pair.local]; - MachAnyId const anyId = rockets.localToAny[pair.local]; - - auto const& portSpan = floats.machToNode[anyId]; - NodeId const throttleIn = connected_node(portSpan, ports_magicrocket::gc_throttleIn.port); - NodeId const multiplierIn = connected_node(portSpan, ports_magicrocket::gc_multiplierIn.port); - - float const throttle = std::clamp(rSigValFloat[throttleIn], 0.0f, 1.0f); - float const multiplier = rSigValFloat[multiplierIn]; - float const thrustMag = throttle * multiplier; - - rCtxScnRdr.m_drawTransform[drawEnt] - = drawTf - * Matrix4::scaling({1.0f, 1.0f, thrustMag * rThrustIndicator.indicatorScale}) - * Matrix4::translation({0.0f, 0.0f, -1.0f}) - * Matrix4::scaling({0.2f, 0.2f, 1.0f}); + if (pair.type == gc_mtMagicRocket) + { + DrawEnt const drawEnt = rThrustIndicator.rktToDrawEnt[pair.local]; + MachAnyId const anyId = rockets.localToAny[pair.local]; + + auto const& portSpan = floats.machToNode[anyId]; + NodeId const throttleIn = connected_node(portSpan, ports_magicrocket::gc_throttleIn.port); + NodeId const multiplierIn = connected_node(portSpan, ports_magicrocket::gc_multiplierIn.port); + + float const throttle = std::clamp(rSigValFloat[throttleIn], 0.0f, 1.0f); + float const multiplier = rSigValFloat[multiplierIn]; + float const thrustMag = throttle * multiplier; + + rCtxScnRdr.m_drawTransform[drawEnt] + = drawTf + * Matrix4::scaling({1.0f, 1.0f, thrustMag * rThrustIndicator.indicatorScale}) + * Matrix4::translation({0.0f, 0.0f, -1.0f}) + * Matrix4::scaling({0.2f, 0.2f, 1.0f}); + } } }; diff --git a/src/testapp/sessions/vehicles_machines.h b/src/testapp/sessions/vehicles_machines.h index 95139245..39062656 100644 --- a/src/testapp/sessions/vehicles_machines.h +++ b/src/testapp/sessions/vehicles_machines.h @@ -24,7 +24,14 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include diff --git a/src/testapp/sessions/vehicles_prebuilt.cpp b/src/testapp/sessions/vehicles_prebuilt.cpp index 08f1d0f5..7878d95d 100644 --- a/src/testapp/sessions/vehicles_prebuilt.cpp +++ b/src/testapp/sessions/vehicles_prebuilt.cpp @@ -28,6 +28,8 @@ #include +#include "../identifiers.h" + using namespace adera; using namespace osp::link; diff --git a/src/testapp/sessions/vehicles_prebuilt.h b/src/testapp/sessions/vehicles_prebuilt.h index 4f2dabea..df15198b 100644 --- a/src/testapp/sessions/vehicles_prebuilt.h +++ b/src/testapp/sessions/vehicles_prebuilt.h @@ -24,12 +24,18 @@ */ #pragma once -#include "../scenarios.h" +#include +#include +#include +#include +#include +#include + +#include #include #include -#include #include #include diff --git a/src/testapp_magnum/CMakeLists.txt b/src/testapp_magnum/CMakeLists.txt new file mode 100644 index 00000000..38d638e4 --- /dev/null +++ b/src/testapp_magnum/CMakeLists.txt @@ -0,0 +1,109 @@ +## +# Open Space Program +# Copyright © 2019-2024 Open Space Program Project +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## + +find_package(Magnum REQUIRED + GL + Shaders + MeshTools + Primitives + Trade + Sdl2Application + AnyImageImporter + ) + +find_package(MagnumPlugins REQUIRED + TinyGltfImporter + StbImageImporter) + +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads) +if(NOT Threads_FOUND) + message(FATAL_ERROR "Can't find a thread library to use!") +endif() + + +add_library(osp-magnum-deps INTERFACE) +add_custom_target(compile-osp-magnum-deps) + +# TODO: This list shouldn't be required, but there appears to be a bug in cmake where +# the add_custom_target() command, pointing to an INTERFACE dependency, doesn't +# result in the dependencies of the interface building. +# See: https://gitlab.kitware.com/cmake/cmake/-/issues/23569 +SET(OSP_MAGNUM_DEPS_LIBS + Threads::Threads + EnTT::EnTT + Corrade::Main + Magnum::Application + Magnum::GL + Magnum::Magnum + Magnum::MeshTools + Magnum::Primitives + Magnum::Shaders + Magnum::Trade + Magnum::AnyImageImporter + MagnumPlugins::TinyGltfImporter + MagnumPlugins::StbImageImporter + toml11 + spdlog + longeron + OpenSpaceProgram + Adera + AderaGL + OspGL + OspJolt + PlanetA + OspTestApp) +target_link_libraries(osp-magnum-deps INTERFACE ${OSP_MAGNUM_DEPS_LIBS}) +add_dependencies(compile-osp-magnum-deps ${OSP_MAGNUM_DEPS_LIBS}) + +add_executable(osp-magnum) + +target_compile_features(osp-magnum PUBLIC cxx_std_20) + +target_include_directories(osp-magnum PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +# Link it to the interface library that describes the dependencies +target_link_libraries(osp-magnum PRIVATE osp-magnum-deps) + +# Gather paths to OSP headers and sources +file(GLOB_RECURSE CPP_FILES CONFIGURE_DEPENDS *.cpp) +file(GLOB_RECURSE H_FILES CONFIGURE_DEPENDS *.h) +target_sources(osp-magnum PRIVATE "${CPP_FILES}" "${H_FILES}") + +# Enforce conformance mode for osp-magnum +target_compile_options(osp-magnum PRIVATE $<$:/permissive->) + +set_target_properties(osp-magnum PROPERTIES + EXPORT_COMPILE_COMMANDS TRUE + INSTALL_RPATH "$ORIGIN/lib" + C_EXTENSIONS OFF + C_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON +) + +add_custom_target(run-osp-magnum + COMMAND $ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/$) diff --git a/src/testapp/MagnumApplication.cpp b/src/testapp_magnum/MagnumApplication.cpp similarity index 100% rename from src/testapp/MagnumApplication.cpp rename to src/testapp_magnum/MagnumApplication.cpp diff --git a/src/testapp/MagnumApplication.h b/src/testapp_magnum/MagnumApplication.h similarity index 100% rename from src/testapp/MagnumApplication.h rename to src/testapp_magnum/MagnumApplication.h diff --git a/src/testapp/README.md b/src/testapp_magnum/README.md similarity index 100% rename from src/testapp/README.md rename to src/testapp_magnum/README.md diff --git a/src/testapp/enginetest.cpp b/src/testapp_magnum/enginetest.cpp similarity index 100% rename from src/testapp/enginetest.cpp rename to src/testapp_magnum/enginetest.cpp diff --git a/src/testapp/enginetest.h b/src/testapp_magnum/enginetest.h similarity index 100% rename from src/testapp/enginetest.h rename to src/testapp_magnum/enginetest.h diff --git a/src/testapp/main.cpp b/src/testapp_magnum/main.cpp similarity index 99% rename from src/testapp/main.cpp rename to src/testapp_magnum/main.cpp index fd01a140..d806e142 100644 --- a/src/testapp/main.cpp +++ b/src/testapp_magnum/main.cpp @@ -26,8 +26,8 @@ #include "MagnumApplication.h" #include "testapp.h" #include "scenarios.h" -#include "identifiers.h" -#include "sessions/common.h" +#include +#include #include "sessions/magnum.h" #include diff --git a/src/testapp/scenarios.cpp b/src/testapp_magnum/scenarios.cpp similarity index 98% rename from src/testapp/scenarios.cpp rename to src/testapp_magnum/scenarios.cpp index a0eeecd3..31abf344 100644 --- a/src/testapp/scenarios.cpp +++ b/src/testapp_magnum/scenarios.cpp @@ -25,19 +25,19 @@ #include "scenarios.h" #include "enginetest.h" -#include "identifiers.h" +#include -#include "sessions/common.h" +#include #include "sessions/magnum.h" -#include "sessions/misc.h" -#include "sessions/jolt.h" -#include "sessions/physics.h" -#include "sessions/shapes.h" -#include "sessions/terrain.h" -#include "sessions/universe.h" -#include "sessions/vehicles.h" -#include "sessions/vehicles_machines.h" -#include "sessions/vehicles_prebuilt.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "MagnumApplication.h" diff --git a/src/testapp_magnum/scenarios.h b/src/testapp_magnum/scenarios.h new file mode 100644 index 00000000..73b0bb50 --- /dev/null +++ b/src/testapp_magnum/scenarios.h @@ -0,0 +1,51 @@ +/** + * Open Space Program + * Copyright © 2019-2021 Open Space Program Project + * + * MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#pragma once + +#include +#include +#include "testapp.h" + +// IWYU pragma: begin_exports +#include +// IWYU pragma: end_exports + +#include +#include + +namespace testapp +{ + +struct ScenarioOption +{ + std::string_view m_description; + SceneSetupFunc_t m_setup; +}; + +using ScenarioMap_t = std::unordered_map; + +ScenarioMap_t const& scenarios(); + +} // namespace testapp diff --git a/src/testapp/sessions/magnum.cpp b/src/testapp_magnum/sessions/magnum.cpp similarity index 99% rename from src/testapp/sessions/magnum.cpp rename to src/testapp_magnum/sessions/magnum.cpp index 2e07164f..9253cafd 100644 --- a/src/testapp/sessions/magnum.cpp +++ b/src/testapp_magnum/sessions/magnum.cpp @@ -23,7 +23,7 @@ * SOFTWARE. */ #include "magnum.h" -#include "common.h" +#include #include "../MagnumApplication.h" diff --git a/src/testapp/sessions/magnum.h b/src/testapp_magnum/sessions/magnum.h similarity index 100% rename from src/testapp/sessions/magnum.h rename to src/testapp_magnum/sessions/magnum.h diff --git a/src/testapp/testapp.cpp b/src/testapp_magnum/testapp.cpp similarity index 99% rename from src/testapp/testapp.cpp rename to src/testapp_magnum/testapp.cpp index 81a086f8..c2c815c9 100644 --- a/src/testapp/testapp.cpp +++ b/src/testapp_magnum/testapp.cpp @@ -23,7 +23,7 @@ * SOFTWARE. */ #include "testapp.h" -#include "identifiers.h" +#include #include #include diff --git a/src/testapp/testapp.h b/src/testapp_magnum/testapp.h similarity index 100% rename from src/testapp/testapp.h rename to src/testapp_magnum/testapp.h