rngine 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +150 -0
  3. package/Rngine.podspec +29 -0
  4. package/android/CMakeLists.txt +31 -0
  5. package/android/build.gradle +118 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/cpp/GameLoopJNI.cpp +31 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +11 -0
  9. package/android/src/main/java/com/margelo/nitro/rngine/GameEngine.kt +34 -0
  10. package/android/src/main/java/com/margelo/nitro/rngine/GameView.kt +63 -0
  11. package/android/src/main/java/com/margelo/nitro/rngine/Rect.kt +9 -0
  12. package/android/src/main/java/com/margelo/nitro/rngine/RectSerializer.kt +23 -0
  13. package/android/src/main/java/com/margelo/nitro/rngine/RnginePackage.kt +29 -0
  14. package/ios/Rngine.swift +28 -0
  15. package/lib/module/GameEngine.js +15 -0
  16. package/lib/module/GameEngine.js.map +1 -0
  17. package/lib/module/GameEngine.nitro.js +4 -0
  18. package/lib/module/GameEngine.nitro.js.map +1 -0
  19. package/lib/module/GameMethods.js +44 -0
  20. package/lib/module/GameMethods.js.map +1 -0
  21. package/lib/module/GameMethods.nitro.js +4 -0
  22. package/lib/module/GameMethods.nitro.js.map +1 -0
  23. package/lib/module/index.js +6 -0
  24. package/lib/module/index.js.map +1 -0
  25. package/lib/module/package.json +1 -0
  26. package/lib/module/types.js +2 -0
  27. package/lib/module/types.js.map +1 -0
  28. package/lib/typescript/package.json +1 -0
  29. package/lib/typescript/src/GameEngine.d.ts +13 -0
  30. package/lib/typescript/src/GameEngine.d.ts.map +1 -0
  31. package/lib/typescript/src/GameEngine.nitro.d.ts +7 -0
  32. package/lib/typescript/src/GameEngine.nitro.d.ts.map +1 -0
  33. package/lib/typescript/src/GameMethods.d.ts +16 -0
  34. package/lib/typescript/src/GameMethods.d.ts.map +1 -0
  35. package/lib/typescript/src/GameMethods.nitro.d.ts +18 -0
  36. package/lib/typescript/src/GameMethods.nitro.d.ts.map +1 -0
  37. package/lib/typescript/src/index.d.ts +4 -0
  38. package/lib/typescript/src/index.d.ts.map +1 -0
  39. package/lib/typescript/src/types.d.ts +48 -0
  40. package/lib/typescript/src/types.d.ts.map +1 -0
  41. package/nitro.json +33 -0
  42. package/nitrogen/generated/android/c++/JHybridGameEngineSpec.cpp +49 -0
  43. package/nitrogen/generated/android/c++/JHybridGameEngineSpec.hpp +63 -0
  44. package/nitrogen/generated/android/c++/views/JHybridGameEngineStateUpdater.cpp +53 -0
  45. package/nitrogen/generated/android/c++/views/JHybridGameEngineStateUpdater.hpp +49 -0
  46. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/HybridGameEngineSpec.kt +53 -0
  47. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/rngineOnLoad.kt +35 -0
  48. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/views/HybridGameEngineManager.kt +80 -0
  49. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/views/HybridGameEngineStateUpdater.kt +23 -0
  50. package/nitrogen/generated/android/rngine+autolinking.cmake +84 -0
  51. package/nitrogen/generated/android/rngine+autolinking.gradle +27 -0
  52. package/nitrogen/generated/android/rngineOnLoad.cpp +66 -0
  53. package/nitrogen/generated/android/rngineOnLoad.hpp +34 -0
  54. package/nitrogen/generated/ios/Rngine+autolinking.rb +62 -0
  55. package/nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.cpp +33 -0
  56. package/nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.hpp +40 -0
  57. package/nitrogen/generated/ios/Rngine-Swift-Cxx-Umbrella.hpp +41 -0
  58. package/nitrogen/generated/ios/RngineAutolinking.mm +43 -0
  59. package/nitrogen/generated/ios/RngineAutolinking.swift +26 -0
  60. package/nitrogen/generated/ios/c++/HybridGameEngineSpecSwift.cpp +11 -0
  61. package/nitrogen/generated/ios/c++/HybridGameEngineSpecSwift.hpp +75 -0
  62. package/nitrogen/generated/ios/c++/views/HybridGameEngineComponent.mm +118 -0
  63. package/nitrogen/generated/ios/swift/HybridGameEngineSpec.swift +55 -0
  64. package/nitrogen/generated/ios/swift/HybridGameEngineSpec_cxx.swift +147 -0
  65. package/nitrogen/generated/shared/c++/Entity.hpp +111 -0
  66. package/nitrogen/generated/shared/c++/HybridGameEngineSpec.cpp +21 -0
  67. package/nitrogen/generated/shared/c++/HybridGameEngineSpec.hpp +62 -0
  68. package/nitrogen/generated/shared/c++/HybridGameMethodsSpec.cpp +30 -0
  69. package/nitrogen/generated/shared/c++/HybridGameMethodsSpec.hpp +80 -0
  70. package/nitrogen/generated/shared/c++/System.hpp +91 -0
  71. package/nitrogen/generated/shared/c++/World.hpp +91 -0
  72. package/nitrogen/generated/shared/c++/views/HybridGameEngineComponent.cpp +72 -0
  73. package/nitrogen/generated/shared/c++/views/HybridGameEngineComponent.hpp +109 -0
  74. package/nitrogen/generated/shared/json/GameEngineConfig.json +9 -0
  75. package/package.json +180 -0
  76. package/src/GameEngine.nitro.ts +10 -0
  77. package/src/GameEngine.tsx +17 -0
  78. package/src/GameMethods.nitro.ts +18 -0
  79. package/src/GameMethods.ts +46 -0
  80. package/src/index.tsx +21 -0
  81. package/src/types.ts +50 -0
@@ -0,0 +1,84 @@
1
+ #
2
+ # rngine+autolinking.cmake
3
+ # This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ # https://github.com/mrousavy/nitro
5
+ # Copyright © Marc Rousavy @ Margelo
6
+ #
7
+
8
+ # This is a CMake file that adds all files generated by Nitrogen
9
+ # to the current CMake project.
10
+ #
11
+ # To use it, add this to your CMakeLists.txt:
12
+ # ```cmake
13
+ # include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/rngine+autolinking.cmake)
14
+ # ```
15
+
16
+ # Define a flag to check if we are building properly
17
+ add_definitions(-DBUILDING_RNGINE_WITH_GENERATED_CMAKE_PROJECT)
18
+
19
+ # Enable Raw Props parsing in react-native (for Nitro Views)
20
+ add_definitions(-DRN_SERIALIZABLE_STATE)
21
+
22
+ # Add all headers that were generated by Nitrogen
23
+ include_directories(
24
+ "../nitrogen/generated/shared/c++"
25
+ "../nitrogen/generated/android/c++"
26
+ "../nitrogen/generated/android/"
27
+ )
28
+
29
+ # Add all .cpp sources that were generated by Nitrogen
30
+ target_sources(
31
+ # CMake project name (Android C++ library name)
32
+ rngine PRIVATE
33
+ # Autolinking Setup
34
+ ../nitrogen/generated/android/rngineOnLoad.cpp
35
+ # Shared Nitrogen C++ sources
36
+ ../nitrogen/generated/shared/c++/HybridGameEngineSpec.cpp
37
+ ../nitrogen/generated/shared/c++/views/HybridGameEngineComponent.cpp
38
+ ../nitrogen/generated/shared/c++/HybridGameMethodsSpec.cpp
39
+ # Android-specific Nitrogen C++ sources
40
+ ../nitrogen/generated/android/c++/JHybridGameEngineSpec.cpp
41
+ ../nitrogen/generated/android/c++/views/JHybridGameEngineStateUpdater.cpp
42
+ )
43
+
44
+ # From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
45
+ # Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
46
+ target_compile_definitions(
47
+ rngine PRIVATE
48
+ -DFOLLY_NO_CONFIG=1
49
+ -DFOLLY_HAVE_CLOCK_GETTIME=1
50
+ -DFOLLY_USE_LIBCPP=1
51
+ -DFOLLY_CFG_NO_COROUTINES=1
52
+ -DFOLLY_MOBILE=1
53
+ -DFOLLY_HAVE_RECVMMSG=1
54
+ -DFOLLY_HAVE_PTHREAD=1
55
+ # Once we target android-23 above, we can comment
56
+ # the following line. NDK uses GNU style stderror_r() after API 23.
57
+ -DFOLLY_HAVE_XSI_STRERROR_R=1
58
+ )
59
+
60
+ # Add all libraries required by the generated specs
61
+ find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
62
+ find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
63
+ find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
64
+
65
+ # Link all libraries together
66
+ target_link_libraries(
67
+ rngine
68
+ fbjni::fbjni # <-- Facebook C++ JNI helpers
69
+ ReactAndroid::jsi # <-- RN: JSI
70
+ react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
71
+ )
72
+
73
+ # Link react-native (different prefab between RN 0.75 and RN 0.76)
74
+ if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
75
+ target_link_libraries(
76
+ rngine
77
+ ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
78
+ )
79
+ else()
80
+ target_link_libraries(
81
+ rngine
82
+ ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
83
+ )
84
+ endif()
@@ -0,0 +1,27 @@
1
+ ///
2
+ /// rngine+autolinking.gradle
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ /// This is a Gradle file that adds all files generated by Nitrogen
9
+ /// to the current Gradle project.
10
+ ///
11
+ /// To use it, add this to your build.gradle:
12
+ /// ```gradle
13
+ /// apply from: '../nitrogen/generated/android/rngine+autolinking.gradle'
14
+ /// ```
15
+
16
+ logger.warn("[NitroModules] 🔥 rngine is boosted by nitro!")
17
+
18
+ android {
19
+ sourceSets {
20
+ main {
21
+ java.srcDirs += [
22
+ // Nitrogen files
23
+ "${project.projectDir}/../nitrogen/generated/android/kotlin"
24
+ ]
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// rngineOnLoad.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #ifndef BUILDING_RNGINE_WITH_GENERATED_CMAKE_PROJECT
9
+ #error rngineOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
10
+ #endif
11
+
12
+ #include "rngineOnLoad.hpp"
13
+
14
+ #include <jni.h>
15
+ #include <fbjni/fbjni.h>
16
+ #include <NitroModules/HybridObjectRegistry.hpp>
17
+
18
+ #include "JHybridGameEngineSpec.hpp"
19
+ #include "views/JHybridGameEngineStateUpdater.hpp"
20
+ #include <NitroModules/DefaultConstructableObject.hpp>
21
+ #include "GameMethods.hpp"
22
+
23
+ namespace margelo::nitro::rngine {
24
+
25
+ int initialize(JavaVM* vm) {
26
+ return facebook::jni::initialize(vm, []() {
27
+ ::margelo::nitro::rngine::registerAllNatives();
28
+ });
29
+ }
30
+
31
+ struct JHybridGameEngineSpecImpl: public jni::JavaClass<JHybridGameEngineSpecImpl, JHybridGameEngineSpec::JavaPart> {
32
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/rngine/GameEngine;";
33
+ static std::shared_ptr<JHybridGameEngineSpec> create() {
34
+ static const auto constructorFn = javaClassStatic()->getConstructor<JHybridGameEngineSpecImpl::javaobject()>();
35
+ jni::local_ref<JHybridGameEngineSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
36
+ return javaPart->getJHybridGameEngineSpec();
37
+ }
38
+ };
39
+
40
+ void registerAllNatives() {
41
+ using namespace margelo::nitro;
42
+ using namespace margelo::nitro::rngine;
43
+
44
+ // Register native JNI methods
45
+ margelo::nitro::rngine::JHybridGameEngineSpec::CxxPart::registerNatives();
46
+ margelo::nitro::rngine::views::JHybridGameEngineStateUpdater::registerNatives();
47
+
48
+ // Register Nitro Hybrid Objects
49
+ HybridObjectRegistry::registerHybridObjectConstructor(
50
+ "GameEngine",
51
+ []() -> std::shared_ptr<HybridObject> {
52
+ return JHybridGameEngineSpecImpl::create();
53
+ }
54
+ );
55
+ HybridObjectRegistry::registerHybridObjectConstructor(
56
+ "GameMethods",
57
+ []() -> std::shared_ptr<HybridObject> {
58
+ static_assert(std::is_default_constructible_v<GameMethods>,
59
+ "The HybridObject \"GameMethods\" is not default-constructible! "
60
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
61
+ return std::make_shared<GameMethods>();
62
+ }
63
+ );
64
+ }
65
+
66
+ } // namespace margelo::nitro::rngine
@@ -0,0 +1,34 @@
1
+ ///
2
+ /// rngineOnLoad.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include <jni.h>
9
+ #include <functional>
10
+ #include <NitroModules/NitroDefines.hpp>
11
+
12
+ namespace margelo::nitro::rngine {
13
+
14
+ [[deprecated("Use registerNatives() instead.")]]
15
+ int initialize(JavaVM* vm);
16
+
17
+ /**
18
+ * Register the native (C++) part of rngine, and autolinks all Hybrid Objects.
19
+ * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
20
+ * inside a `facebook::jni::initialize(vm, ...)` call.
21
+ * Example:
22
+ * ```cpp (cpp-adapter.cpp)
23
+ * JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
24
+ * return facebook::jni::initialize(vm, []() {
25
+ * // register all rngine HybridObjects
26
+ * margelo::nitro::rngine::registerNatives();
27
+ * // any other custom registrations go here.
28
+ * });
29
+ * }
30
+ * ```
31
+ */
32
+ void registerAllNatives();
33
+
34
+ } // namespace margelo::nitro::rngine
@@ -0,0 +1,62 @@
1
+ #
2
+ # Rngine+autolinking.rb
3
+ # This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ # https://github.com/mrousavy/nitro
5
+ # Copyright © Marc Rousavy @ Margelo
6
+ #
7
+
8
+ # This is a Ruby script that adds all files generated by Nitrogen
9
+ # to the given podspec.
10
+ #
11
+ # To use it, add this to your .podspec:
12
+ # ```ruby
13
+ # Pod::Spec.new do |spec|
14
+ # # ...
15
+ #
16
+ # # Add all files generated by Nitrogen
17
+ # load 'nitrogen/generated/ios/Rngine+autolinking.rb'
18
+ # add_nitrogen_files(spec)
19
+ # end
20
+ # ```
21
+
22
+ def add_nitrogen_files(spec)
23
+ Pod::UI.puts "[NitroModules] 🔥 Rngine is boosted by nitro!"
24
+
25
+ spec.dependency "NitroModules"
26
+
27
+ current_source_files = Array(spec.attributes_hash['source_files'])
28
+ spec.source_files = current_source_files + [
29
+ # Generated cross-platform specs
30
+ "nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
31
+ # Generated bridges for the cross-platform specs
32
+ "nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
33
+ ]
34
+
35
+ current_public_header_files = Array(spec.attributes_hash['public_header_files'])
36
+ spec.public_header_files = current_public_header_files + [
37
+ # Generated specs
38
+ "nitrogen/generated/shared/**/*.{h,hpp}",
39
+ # Swift to C++ bridging helpers
40
+ "nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.hpp"
41
+ ]
42
+
43
+ current_private_header_files = Array(spec.attributes_hash['private_header_files'])
44
+ spec.private_header_files = current_private_header_files + [
45
+ # iOS specific specs
46
+ "nitrogen/generated/ios/c++/**/*.{h,hpp}",
47
+ # Views are framework-specific and should be private
48
+ "nitrogen/generated/shared/**/views/**/*"
49
+ ]
50
+
51
+ current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
52
+ spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
53
+ # Use C++ 20
54
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
55
+ # Enables C++ <-> Swift interop (by default it's only ObjC)
56
+ "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
57
+ # Enables stricter modular headers
58
+ "DEFINES_MODULE" => "YES",
59
+ # Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here)
60
+ "SWIFT_INSTALL_OBJC_HEADER" => "NO",
61
+ })
62
+ end
@@ -0,0 +1,33 @@
1
+ ///
2
+ /// Rngine-Swift-Cxx-Bridge.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "Rngine-Swift-Cxx-Bridge.hpp"
9
+
10
+ // Include C++ implementation defined types
11
+ #include "HybridGameEngineSpecSwift.hpp"
12
+ #include "Rngine-Swift-Cxx-Umbrella.hpp"
13
+ #include <NitroModules/NitroDefines.hpp>
14
+
15
+ namespace margelo::nitro::rngine::bridge::swift {
16
+
17
+ // pragma MARK: std::shared_ptr<HybridGameEngineSpec>
18
+ std::shared_ptr<HybridGameEngineSpec> create_std__shared_ptr_HybridGameEngineSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
19
+ Rngine::HybridGameEngineSpec_cxx swiftPart = Rngine::HybridGameEngineSpec_cxx::fromUnsafe(swiftUnsafePointer);
20
+ return std::make_shared<margelo::nitro::rngine::HybridGameEngineSpecSwift>(swiftPart);
21
+ }
22
+ void* NON_NULL get_std__shared_ptr_HybridGameEngineSpec_(std__shared_ptr_HybridGameEngineSpec_ cppType) {
23
+ std::shared_ptr<margelo::nitro::rngine::HybridGameEngineSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::rngine::HybridGameEngineSpecSwift>(cppType);
24
+ #ifdef NITRO_DEBUG
25
+ if (swiftWrapper == nullptr) [[unlikely]] {
26
+ throw std::runtime_error("Class \"HybridGameEngineSpec\" is not implemented in Swift!");
27
+ }
28
+ #endif
29
+ Rngine::HybridGameEngineSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
30
+ return swiftPart.toUnsafe();
31
+ }
32
+
33
+ } // namespace margelo::nitro::rngine::bridge::swift
@@ -0,0 +1,40 @@
1
+ ///
2
+ /// Rngine-Swift-Cxx-Bridge.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `HybridGameEngineSpec` to properly resolve imports.
12
+ namespace margelo::nitro::rngine { class HybridGameEngineSpec; }
13
+
14
+ // Forward declarations of Swift defined types
15
+ // Forward declaration of `HybridGameEngineSpec_cxx` to properly resolve imports.
16
+ namespace Rngine { class HybridGameEngineSpec_cxx; }
17
+
18
+ // Include C++ defined types
19
+ #include "HybridGameEngineSpec.hpp"
20
+ #include <memory>
21
+
22
+ /**
23
+ * Contains specialized versions of C++ templated types so they can be accessed from Swift,
24
+ * as well as helper functions to interact with those C++ types from Swift.
25
+ */
26
+ namespace margelo::nitro::rngine::bridge::swift {
27
+
28
+ // pragma MARK: std::shared_ptr<HybridGameEngineSpec>
29
+ /**
30
+ * Specialized version of `std::shared_ptr<HybridGameEngineSpec>`.
31
+ */
32
+ using std__shared_ptr_HybridGameEngineSpec_ = std::shared_ptr<HybridGameEngineSpec>;
33
+ std::shared_ptr<HybridGameEngineSpec> create_std__shared_ptr_HybridGameEngineSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
34
+ void* NON_NULL get_std__shared_ptr_HybridGameEngineSpec_(std__shared_ptr_HybridGameEngineSpec_ cppType);
35
+
36
+ // pragma MARK: std::weak_ptr<HybridGameEngineSpec>
37
+ using std__weak_ptr_HybridGameEngineSpec_ = std::weak_ptr<HybridGameEngineSpec>;
38
+ inline std__weak_ptr_HybridGameEngineSpec_ weakify_std__shared_ptr_HybridGameEngineSpec_(const std::shared_ptr<HybridGameEngineSpec>& strong) noexcept { return strong; }
39
+
40
+ } // namespace margelo::nitro::rngine::bridge::swift
@@ -0,0 +1,41 @@
1
+ ///
2
+ /// Rngine-Swift-Cxx-Umbrella.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `HybridGameEngineSpec` to properly resolve imports.
12
+ namespace margelo::nitro::rngine { class HybridGameEngineSpec; }
13
+
14
+ // Include C++ defined types
15
+ #include "HybridGameEngineSpec.hpp"
16
+ #include <memory>
17
+
18
+ // C++ helpers for Swift
19
+ #include "Rngine-Swift-Cxx-Bridge.hpp"
20
+
21
+ // Common C++ types used in Swift
22
+ #include <NitroModules/ArrayBufferHolder.hpp>
23
+ #include <NitroModules/AnyMapUtils.hpp>
24
+ #include <NitroModules/RuntimeError.hpp>
25
+ #include <NitroModules/DateToChronoDate.hpp>
26
+
27
+ // Forward declarations of Swift defined types
28
+ // Forward declaration of `HybridGameEngineSpec_cxx` to properly resolve imports.
29
+ namespace Rngine { class HybridGameEngineSpec_cxx; }
30
+
31
+ // Include Swift defined types
32
+ #if __has_include("Rngine-Swift.h")
33
+ // This header is generated by Xcode/Swift on every app build.
34
+ // If it cannot be found, make sure the Swift module's name (= podspec name) is actually "Rngine".
35
+ #include "Rngine-Swift.h"
36
+ // Same as above, but used when building with frameworks (`use_frameworks`)
37
+ #elif __has_include(<Rngine/Rngine-Swift.h>)
38
+ #include <Rngine/Rngine-Swift.h>
39
+ #else
40
+ #error Rngine's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "Rngine", and try building the app first.
41
+ #endif
@@ -0,0 +1,43 @@
1
+ ///
2
+ /// RngineAutolinking.mm
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <NitroModules/HybridObjectRegistry.hpp>
10
+ #import "Rngine-Swift-Cxx-Umbrella.hpp"
11
+ #import <type_traits>
12
+
13
+ #include "HybridGameEngineSpecSwift.hpp"
14
+ #include "GameMethods.hpp"
15
+
16
+ @interface RngineAutolinking : NSObject
17
+ @end
18
+
19
+ @implementation RngineAutolinking
20
+
21
+ + (void) load {
22
+ using namespace margelo::nitro;
23
+ using namespace margelo::nitro::rngine;
24
+
25
+ HybridObjectRegistry::registerHybridObjectConstructor(
26
+ "GameEngine",
27
+ []() -> std::shared_ptr<HybridObject> {
28
+ std::shared_ptr<HybridGameEngineSpec> hybridObject = Rngine::RngineAutolinking::createGameEngine();
29
+ return hybridObject;
30
+ }
31
+ );
32
+ HybridObjectRegistry::registerHybridObjectConstructor(
33
+ "GameMethods",
34
+ []() -> std::shared_ptr<HybridObject> {
35
+ static_assert(std::is_default_constructible_v<GameMethods>,
36
+ "The HybridObject \"GameMethods\" is not default-constructible! "
37
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
38
+ return std::make_shared<GameMethods>();
39
+ }
40
+ );
41
+ }
42
+
43
+ @end
@@ -0,0 +1,26 @@
1
+ ///
2
+ /// RngineAutolinking.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ // TODO: Use empty enums once Swift supports exporting them as namespaces
11
+ // See: https://github.com/swiftlang/swift/pull/83616
12
+ public final class RngineAutolinking {
13
+ public typealias bridge = margelo.nitro.rngine.bridge.swift
14
+
15
+ public static func createGameEngine() -> bridge.std__shared_ptr_HybridGameEngineSpec_ {
16
+ let hybridObject = GameEngine()
17
+ return { () -> bridge.std__shared_ptr_HybridGameEngineSpec_ in
18
+ let __cxxWrapped = hybridObject.getCxxWrapper()
19
+ return __cxxWrapped.getCxxPart()
20
+ }()
21
+ }
22
+
23
+ public static func isGameEngineRecyclable() -> Bool {
24
+ return GameEngine.self is any RecyclableView.Type
25
+ }
26
+ }
@@ -0,0 +1,11 @@
1
+ ///
2
+ /// HybridGameEngineSpecSwift.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridGameEngineSpecSwift.hpp"
9
+
10
+ namespace margelo::nitro::rngine {
11
+ } // namespace margelo::nitro::rngine
@@ -0,0 +1,75 @@
1
+ ///
2
+ /// HybridGameEngineSpecSwift.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include "HybridGameEngineSpec.hpp"
11
+
12
+ // Forward declaration of `HybridGameEngineSpec_cxx` to properly resolve imports.
13
+ namespace Rngine { class HybridGameEngineSpec_cxx; }
14
+
15
+
16
+
17
+
18
+
19
+ #include "Rngine-Swift-Cxx-Umbrella.hpp"
20
+
21
+ namespace margelo::nitro::rngine {
22
+
23
+ /**
24
+ * The C++ part of HybridGameEngineSpec_cxx.swift.
25
+ *
26
+ * HybridGameEngineSpecSwift (C++) accesses HybridGameEngineSpec_cxx (Swift), and might
27
+ * contain some additional bridging code for C++ <> Swift interop.
28
+ *
29
+ * Since this obviously introduces an overhead, I hope at some point in
30
+ * the future, HybridGameEngineSpec_cxx can directly inherit from the C++ class HybridGameEngineSpec
31
+ * to simplify the whole structure and memory management.
32
+ */
33
+ class HybridGameEngineSpecSwift: public virtual HybridGameEngineSpec {
34
+ public:
35
+ // Constructor from a Swift instance
36
+ explicit HybridGameEngineSpecSwift(const Rngine::HybridGameEngineSpec_cxx& swiftPart):
37
+ HybridObject(HybridGameEngineSpec::TAG),
38
+ _swiftPart(swiftPart) { }
39
+
40
+ public:
41
+ // Get the Swift part
42
+ inline Rngine::HybridGameEngineSpec_cxx& getSwiftPart() noexcept {
43
+ return _swiftPart;
44
+ }
45
+
46
+ public:
47
+ inline size_t getExternalMemorySize() noexcept override {
48
+ return _swiftPart.getMemorySize();
49
+ }
50
+ bool equals(const std::shared_ptr<HybridObject>& other) override {
51
+ if (auto otherCast = std::dynamic_pointer_cast<HybridGameEngineSpecSwift>(other)) {
52
+ return _swiftPart.equals(otherCast->_swiftPart);
53
+ }
54
+ return false;
55
+ }
56
+ void dispose() noexcept override {
57
+ _swiftPart.dispose();
58
+ }
59
+ std::string toString() override {
60
+ return _swiftPart.toString();
61
+ }
62
+
63
+ public:
64
+ // Properties
65
+
66
+
67
+ public:
68
+ // Methods
69
+
70
+
71
+ private:
72
+ Rngine::HybridGameEngineSpec_cxx _swiftPart;
73
+ };
74
+
75
+ } // namespace margelo::nitro::rngine
@@ -0,0 +1,118 @@
1
+ ///
2
+ /// HybridGameEngineComponent.mm
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #import "HybridGameEngineComponent.hpp"
9
+ #import <memory>
10
+ #import <react/renderer/componentregistry/ComponentDescriptorProvider.h>
11
+ #import <React/RCTViewComponentView.h>
12
+ #import <React/RCTComponentViewFactory.h>
13
+ #import <React/UIView+ComponentViewProtocol.h>
14
+ #import <NitroModules/NitroDefines.hpp>
15
+ #import <UIKit/UIKit.h>
16
+
17
+ #import "HybridGameEngineSpecSwift.hpp"
18
+ #import "Rngine-Swift-Cxx-Umbrella.hpp"
19
+
20
+ #if __has_include(<cxxreact/ReactNativeVersion.h>)
21
+ #include <cxxreact/ReactNativeVersion.h>
22
+ #if REACT_NATIVE_VERSION_MINOR >= 82
23
+ #define ENABLE_RCT_COMPONENT_VIEW_INVALIDATE
24
+ #endif
25
+ #endif
26
+
27
+ using namespace facebook;
28
+ using namespace margelo::nitro::rngine;
29
+ using namespace margelo::nitro::rngine::views;
30
+
31
+ /**
32
+ * Represents the React Native View holder for the Nitro "GameEngine" HybridView.
33
+ */
34
+ @interface HybridGameEngineComponent: RCTViewComponentView
35
+ + (BOOL)shouldBeRecycled;
36
+ @end
37
+
38
+ @implementation HybridGameEngineComponent {
39
+ std::shared_ptr<HybridGameEngineSpecSwift> _hybridView;
40
+ }
41
+
42
+ + (void) load {
43
+ [super load];
44
+ [RCTComponentViewFactory.currentComponentViewFactory registerComponentViewClass:[HybridGameEngineComponent class]];
45
+ }
46
+
47
+ + (react::ComponentDescriptorProvider) componentDescriptorProvider {
48
+ return react::concreteComponentDescriptorProvider<HybridGameEngineComponentDescriptor>();
49
+ }
50
+
51
+ - (instancetype) init {
52
+ if (self = [super init]) {
53
+ std::shared_ptr<HybridGameEngineSpec> hybridView = Rngine::RngineAutolinking::createGameEngine();
54
+ _hybridView = std::dynamic_pointer_cast<HybridGameEngineSpecSwift>(hybridView);
55
+ [self updateView];
56
+ }
57
+ return self;
58
+ }
59
+
60
+ - (void) updateView {
61
+ // 1. Get Swift part
62
+ Rngine::HybridGameEngineSpec_cxx& swiftPart = _hybridView->getSwiftPart();
63
+
64
+ // 2. Get UIView*
65
+ void* viewUnsafe = swiftPart.getView();
66
+ UIView* view = (__bridge_transfer UIView*) viewUnsafe;
67
+
68
+ // 3. Update RCTViewComponentView's [contentView]
69
+ [self setContentView:view];
70
+ }
71
+
72
+ - (void) updateProps:(const std::shared_ptr<const react::Props>&)props
73
+ oldProps:(const std::shared_ptr<const react::Props>&)oldProps {
74
+ // 1. Downcast props
75
+ const auto& newViewPropsConst = *std::static_pointer_cast<HybridGameEngineProps const>(props);
76
+ auto& newViewProps = const_cast<HybridGameEngineProps&>(newViewPropsConst);
77
+ Rngine::HybridGameEngineSpec_cxx& swiftPart = _hybridView->getSwiftPart();
78
+
79
+ // 2. Update each prop individually
80
+ swiftPart.beforeUpdate();
81
+
82
+
83
+
84
+ swiftPart.afterUpdate();
85
+
86
+ // 3. Update hybridRef if it changed
87
+ if (newViewProps.hybridRef.isDirty) {
88
+ // hybridRef changed - call it with new this
89
+ const auto& maybeFunc = newViewProps.hybridRef.value;
90
+ if (maybeFunc.has_value()) {
91
+ maybeFunc.value()(_hybridView);
92
+ }
93
+ newViewProps.hybridRef.isDirty = false;
94
+ }
95
+
96
+ // 4. Continue in base class
97
+ [super updateProps:props oldProps:oldProps];
98
+ }
99
+
100
+ + (BOOL)shouldBeRecycled {
101
+ return Rngine::RngineAutolinking::isGameEngineRecyclable();
102
+ }
103
+
104
+ - (void)prepareForRecycle {
105
+ [super prepareForRecycle];
106
+ Rngine::HybridGameEngineSpec_cxx& swiftPart = _hybridView->getSwiftPart();
107
+ swiftPart.maybePrepareForRecycle();
108
+ }
109
+
110
+ #ifdef ENABLE_RCT_COMPONENT_VIEW_INVALIDATE
111
+ - (void)invalidate {
112
+ Rngine::HybridGameEngineSpec_cxx& swiftPart = _hybridView->getSwiftPart();
113
+ swiftPart.onDropView();
114
+ [super invalidate];
115
+ }
116
+ #endif
117
+
118
+ @end