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.
- package/LICENSE +20 -0
- package/README.md +150 -0
- package/Rngine.podspec +29 -0
- package/android/CMakeLists.txt +31 -0
- package/android/build.gradle +118 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/GameLoopJNI.cpp +31 -0
- package/android/src/main/cpp/cpp-adapter.cpp +11 -0
- package/android/src/main/java/com/margelo/nitro/rngine/GameEngine.kt +34 -0
- package/android/src/main/java/com/margelo/nitro/rngine/GameView.kt +63 -0
- package/android/src/main/java/com/margelo/nitro/rngine/Rect.kt +9 -0
- package/android/src/main/java/com/margelo/nitro/rngine/RectSerializer.kt +23 -0
- package/android/src/main/java/com/margelo/nitro/rngine/RnginePackage.kt +29 -0
- package/ios/Rngine.swift +28 -0
- package/lib/module/GameEngine.js +15 -0
- package/lib/module/GameEngine.js.map +1 -0
- package/lib/module/GameEngine.nitro.js +4 -0
- package/lib/module/GameEngine.nitro.js.map +1 -0
- package/lib/module/GameMethods.js +44 -0
- package/lib/module/GameMethods.js.map +1 -0
- package/lib/module/GameMethods.nitro.js +4 -0
- package/lib/module/GameMethods.nitro.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/GameEngine.d.ts +13 -0
- package/lib/typescript/src/GameEngine.d.ts.map +1 -0
- package/lib/typescript/src/GameEngine.nitro.d.ts +7 -0
- package/lib/typescript/src/GameEngine.nitro.d.ts.map +1 -0
- package/lib/typescript/src/GameMethods.d.ts +16 -0
- package/lib/typescript/src/GameMethods.d.ts.map +1 -0
- package/lib/typescript/src/GameMethods.nitro.d.ts +18 -0
- package/lib/typescript/src/GameMethods.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +48 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/nitro.json +33 -0
- package/nitrogen/generated/android/c++/JHybridGameEngineSpec.cpp +49 -0
- package/nitrogen/generated/android/c++/JHybridGameEngineSpec.hpp +63 -0
- package/nitrogen/generated/android/c++/views/JHybridGameEngineStateUpdater.cpp +53 -0
- package/nitrogen/generated/android/c++/views/JHybridGameEngineStateUpdater.hpp +49 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/HybridGameEngineSpec.kt +53 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/rngineOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/views/HybridGameEngineManager.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/views/HybridGameEngineStateUpdater.kt +23 -0
- package/nitrogen/generated/android/rngine+autolinking.cmake +84 -0
- package/nitrogen/generated/android/rngine+autolinking.gradle +27 -0
- package/nitrogen/generated/android/rngineOnLoad.cpp +66 -0
- package/nitrogen/generated/android/rngineOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/Rngine+autolinking.rb +62 -0
- package/nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.cpp +33 -0
- package/nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.hpp +40 -0
- package/nitrogen/generated/ios/Rngine-Swift-Cxx-Umbrella.hpp +41 -0
- package/nitrogen/generated/ios/RngineAutolinking.mm +43 -0
- package/nitrogen/generated/ios/RngineAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridGameEngineSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridGameEngineSpecSwift.hpp +75 -0
- package/nitrogen/generated/ios/c++/views/HybridGameEngineComponent.mm +118 -0
- package/nitrogen/generated/ios/swift/HybridGameEngineSpec.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridGameEngineSpec_cxx.swift +147 -0
- package/nitrogen/generated/shared/c++/Entity.hpp +111 -0
- package/nitrogen/generated/shared/c++/HybridGameEngineSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridGameEngineSpec.hpp +62 -0
- package/nitrogen/generated/shared/c++/HybridGameMethodsSpec.cpp +30 -0
- package/nitrogen/generated/shared/c++/HybridGameMethodsSpec.hpp +80 -0
- package/nitrogen/generated/shared/c++/System.hpp +91 -0
- package/nitrogen/generated/shared/c++/World.hpp +91 -0
- package/nitrogen/generated/shared/c++/views/HybridGameEngineComponent.cpp +72 -0
- package/nitrogen/generated/shared/c++/views/HybridGameEngineComponent.hpp +109 -0
- package/nitrogen/generated/shared/json/GameEngineConfig.json +9 -0
- package/package.json +180 -0
- package/src/GameEngine.nitro.ts +10 -0
- package/src/GameEngine.tsx +17 -0
- package/src/GameMethods.nitro.ts +18 -0
- package/src/GameMethods.ts +46 -0
- package/src/index.tsx +21 -0
- package/src/types.ts +50 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridGameEngineSpec.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
|
+
/// See ``HybridGameEngineSpec``
|
|
11
|
+
public protocol HybridGameEngineSpec_protocol: HybridObject, HybridView {
|
|
12
|
+
// Properties
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
// Methods
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public extension HybridGameEngineSpec_protocol {
|
|
20
|
+
/// Default implementation of ``HybridObject.toString``
|
|
21
|
+
func toString() -> String {
|
|
22
|
+
return "[HybridObject GameEngine]"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/// See ``HybridGameEngineSpec``
|
|
27
|
+
open class HybridGameEngineSpec_base {
|
|
28
|
+
private weak var cxxWrapper: HybridGameEngineSpec_cxx? = nil
|
|
29
|
+
public init() { }
|
|
30
|
+
public func getCxxWrapper() -> HybridGameEngineSpec_cxx {
|
|
31
|
+
#if DEBUG
|
|
32
|
+
guard self is any HybridGameEngineSpec else {
|
|
33
|
+
fatalError("`self` is not a `HybridGameEngineSpec`! Did you accidentally inherit from `HybridGameEngineSpec_base` instead of `HybridGameEngineSpec`?")
|
|
34
|
+
}
|
|
35
|
+
#endif
|
|
36
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
37
|
+
return cxxWrapper
|
|
38
|
+
} else {
|
|
39
|
+
let cxxWrapper = HybridGameEngineSpec_cxx(self as! any HybridGameEngineSpec)
|
|
40
|
+
self.cxxWrapper = cxxWrapper
|
|
41
|
+
return cxxWrapper
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A Swift base-protocol representing the GameEngine HybridObject.
|
|
48
|
+
* Implement this protocol to create Swift-based instances of GameEngine.
|
|
49
|
+
* ```swift
|
|
50
|
+
* class HybridGameEngine : HybridGameEngineSpec {
|
|
51
|
+
* // ...
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
public typealias HybridGameEngineSpec = HybridGameEngineSpec_protocol & HybridGameEngineSpec_base
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridGameEngineSpec_cxx.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
|
+
/**
|
|
11
|
+
* A class implementation that bridges HybridGameEngineSpec over to C++.
|
|
12
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
13
|
+
*
|
|
14
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
15
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
16
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
17
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
18
|
+
*/
|
|
19
|
+
open class HybridGameEngineSpec_cxx {
|
|
20
|
+
/**
|
|
21
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::rngine::bridge::swift`)
|
|
22
|
+
* from `Rngine-Swift-Cxx-Bridge.hpp`.
|
|
23
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
24
|
+
*/
|
|
25
|
+
public typealias bridge = margelo.nitro.rngine.bridge.swift
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Holds an instance of the `HybridGameEngineSpec` Swift protocol.
|
|
29
|
+
*/
|
|
30
|
+
private var __implementation: any HybridGameEngineSpec
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
34
|
+
*/
|
|
35
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridGameEngineSpec_
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create a new `HybridGameEngineSpec_cxx` that wraps the given `HybridGameEngineSpec`.
|
|
39
|
+
* All properties and methods bridge to C++ types.
|
|
40
|
+
*/
|
|
41
|
+
public init(_ implementation: any HybridGameEngineSpec) {
|
|
42
|
+
self.__implementation = implementation
|
|
43
|
+
self.__cxxPart = .init()
|
|
44
|
+
/* no base class */
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the actual `HybridGameEngineSpec` instance this class wraps.
|
|
49
|
+
*/
|
|
50
|
+
@inline(__always)
|
|
51
|
+
public func getHybridGameEngineSpec() -> any HybridGameEngineSpec {
|
|
52
|
+
return __implementation
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
57
|
+
* This acquires one additional strong reference on the object!
|
|
58
|
+
*/
|
|
59
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
60
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Casts an unsafe pointer to a `HybridGameEngineSpec_cxx`.
|
|
65
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridGameEngineSpec_cxx>`.
|
|
66
|
+
* This removes one strong reference from the object!
|
|
67
|
+
*/
|
|
68
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridGameEngineSpec_cxx {
|
|
69
|
+
return Unmanaged<HybridGameEngineSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
74
|
+
* The C++ part is a `std::shared_ptr<HybridGameEngineSpec>`.
|
|
75
|
+
*/
|
|
76
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridGameEngineSpec_ {
|
|
77
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
78
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
79
|
+
return cachedCxxPart
|
|
80
|
+
} else {
|
|
81
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridGameEngineSpec_(self.toUnsafe())
|
|
82
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridGameEngineSpec_(newCxxPart)
|
|
83
|
+
return newCxxPart
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
91
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
92
|
+
*/
|
|
93
|
+
@inline(__always)
|
|
94
|
+
public var memorySize: Int {
|
|
95
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Compares this object with the given [other] object for reference equality.
|
|
100
|
+
*/
|
|
101
|
+
@inline(__always)
|
|
102
|
+
public func equals(other: HybridGameEngineSpec_cxx) -> Bool {
|
|
103
|
+
return self.__implementation === other.__implementation
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Call dispose() on the Swift class.
|
|
108
|
+
* This _may_ be called manually from JS.
|
|
109
|
+
*/
|
|
110
|
+
@inline(__always)
|
|
111
|
+
public func dispose() {
|
|
112
|
+
self.__implementation.dispose()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Call toString() on the Swift class.
|
|
117
|
+
*/
|
|
118
|
+
@inline(__always)
|
|
119
|
+
public func toString() -> String {
|
|
120
|
+
return self.__implementation.toString()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Properties
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
// Methods
|
|
127
|
+
public final func getView() -> UnsafeMutableRawPointer {
|
|
128
|
+
return Unmanaged.passRetained(__implementation.view).toOpaque()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public final func beforeUpdate() {
|
|
132
|
+
__implementation.beforeUpdate()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public final func afterUpdate() {
|
|
136
|
+
__implementation.afterUpdate()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public final func maybePrepareForRecycle() {
|
|
140
|
+
guard let recyclable = __implementation as? any RecyclableView else { return }
|
|
141
|
+
recyclable.prepareForRecycle()
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public final func onDropView() {
|
|
145
|
+
__implementation.onDropView()
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Entity.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
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#include <string>
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::rngine {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (Entity).
|
|
39
|
+
*/
|
|
40
|
+
struct Entity final {
|
|
41
|
+
public:
|
|
42
|
+
std::string id SWIFT_PRIVATE;
|
|
43
|
+
double px SWIFT_PRIVATE;
|
|
44
|
+
double py SWIFT_PRIVATE;
|
|
45
|
+
double width SWIFT_PRIVATE;
|
|
46
|
+
double height SWIFT_PRIVATE;
|
|
47
|
+
std::string color SWIFT_PRIVATE;
|
|
48
|
+
double vx SWIFT_PRIVATE;
|
|
49
|
+
double vy SWIFT_PRIVATE;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
Entity() = default;
|
|
53
|
+
explicit Entity(std::string id, double px, double py, double width, double height, std::string color, double vx, double vy): id(id), px(px), py(py), width(width), height(height), color(color), vx(vx), vy(vy) {}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
friend bool operator==(const Entity& lhs, const Entity& rhs) = default;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} // namespace margelo::nitro::rngine
|
|
60
|
+
|
|
61
|
+
namespace margelo::nitro {
|
|
62
|
+
|
|
63
|
+
// C++ Entity <> JS Entity (object)
|
|
64
|
+
template <>
|
|
65
|
+
struct JSIConverter<margelo::nitro::rngine::Entity> final {
|
|
66
|
+
static inline margelo::nitro::rngine::Entity fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
67
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
68
|
+
return margelo::nitro::rngine::Entity(
|
|
69
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id"))),
|
|
70
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "px"))),
|
|
71
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "py"))),
|
|
72
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
|
|
73
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height"))),
|
|
74
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color"))),
|
|
75
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx"))),
|
|
76
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::Entity& arg) {
|
|
80
|
+
jsi::Object obj(runtime);
|
|
81
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "id"), JSIConverter<std::string>::toJSI(runtime, arg.id));
|
|
82
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "px"), JSIConverter<double>::toJSI(runtime, arg.px));
|
|
83
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "py"), JSIConverter<double>::toJSI(runtime, arg.py));
|
|
84
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "width"), JSIConverter<double>::toJSI(runtime, arg.width));
|
|
85
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<double>::toJSI(runtime, arg.height));
|
|
86
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "color"), JSIConverter<std::string>::toJSI(runtime, arg.color));
|
|
87
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "vx"), JSIConverter<double>::toJSI(runtime, arg.vx));
|
|
88
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "vy"), JSIConverter<double>::toJSI(runtime, arg.vy));
|
|
89
|
+
return obj;
|
|
90
|
+
}
|
|
91
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
92
|
+
if (!value.isObject()) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
jsi::Object obj = value.getObject(runtime);
|
|
96
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id")))) return false;
|
|
100
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "px")))) return false;
|
|
101
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "py")))) return false;
|
|
102
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width")))) return false;
|
|
103
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
|
|
104
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "color")))) return false;
|
|
105
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx")))) return false;
|
|
106
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))) return false;
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridGameEngineSpec.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 "HybridGameEngineSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::rngine {
|
|
11
|
+
|
|
12
|
+
void HybridGameEngineSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
} // namespace margelo::nitro::rngine
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridGameEngineSpec.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
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
namespace margelo::nitro::rngine {
|
|
21
|
+
|
|
22
|
+
using namespace margelo::nitro;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An abstract base class for `GameEngine`
|
|
26
|
+
* Inherit this class to create instances of `HybridGameEngineSpec` in C++.
|
|
27
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
28
|
+
* @example
|
|
29
|
+
* ```cpp
|
|
30
|
+
* class HybridGameEngine: public HybridGameEngineSpec {
|
|
31
|
+
* public:
|
|
32
|
+
* HybridGameEngine(...): HybridObject(TAG) { ... }
|
|
33
|
+
* // ...
|
|
34
|
+
* };
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
class HybridGameEngineSpec: public virtual HybridObject {
|
|
38
|
+
public:
|
|
39
|
+
// Constructor
|
|
40
|
+
explicit HybridGameEngineSpec(): HybridObject(TAG) { }
|
|
41
|
+
|
|
42
|
+
// Destructor
|
|
43
|
+
~HybridGameEngineSpec() override = default;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
// Properties
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
// Methods
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
protected:
|
|
54
|
+
// Hybrid Setup
|
|
55
|
+
void loadHybridMethods() override;
|
|
56
|
+
|
|
57
|
+
protected:
|
|
58
|
+
// Tag for logging
|
|
59
|
+
static constexpr auto TAG = "GameEngine";
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
} // namespace margelo::nitro::rngine
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridGameMethodsSpec.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 "HybridGameMethodsSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::rngine {
|
|
11
|
+
|
|
12
|
+
void HybridGameMethodsSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("setTickRate", &HybridGameMethodsSpec::setTickRate);
|
|
18
|
+
prototype.registerHybridMethod("setWorld", &HybridGameMethodsSpec::setWorld);
|
|
19
|
+
prototype.registerHybridMethod("setEntities", &HybridGameMethodsSpec::setEntities);
|
|
20
|
+
prototype.registerHybridMethod("setSystems", &HybridGameMethodsSpec::setSystems);
|
|
21
|
+
prototype.registerHybridMethod("pause", &HybridGameMethodsSpec::pause);
|
|
22
|
+
prototype.registerHybridMethod("resume", &HybridGameMethodsSpec::resume);
|
|
23
|
+
prototype.registerHybridMethod("spawn", &HybridGameMethodsSpec::spawn);
|
|
24
|
+
prototype.registerHybridMethod("despawn", &HybridGameMethodsSpec::despawn);
|
|
25
|
+
prototype.registerHybridMethod("setP", &HybridGameMethodsSpec::setP);
|
|
26
|
+
prototype.registerHybridMethod("setV", &HybridGameMethodsSpec::setV);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
} // namespace margelo::nitro::rngine
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridGameMethodsSpec.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
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `World` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::rngine { struct World; }
|
|
18
|
+
// Forward declaration of `Entity` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::rngine { struct Entity; }
|
|
20
|
+
// Forward declaration of `System` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::rngine { struct System; }
|
|
22
|
+
|
|
23
|
+
#include "World.hpp"
|
|
24
|
+
#include "Entity.hpp"
|
|
25
|
+
#include <vector>
|
|
26
|
+
#include "System.hpp"
|
|
27
|
+
#include <string>
|
|
28
|
+
|
|
29
|
+
namespace margelo::nitro::rngine {
|
|
30
|
+
|
|
31
|
+
using namespace margelo::nitro;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* An abstract base class for `GameMethods`
|
|
35
|
+
* Inherit this class to create instances of `HybridGameMethodsSpec` in C++.
|
|
36
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
37
|
+
* @example
|
|
38
|
+
* ```cpp
|
|
39
|
+
* class HybridGameMethods: public HybridGameMethodsSpec {
|
|
40
|
+
* public:
|
|
41
|
+
* HybridGameMethods(...): HybridObject(TAG) { ... }
|
|
42
|
+
* // ...
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
class HybridGameMethodsSpec: public virtual HybridObject {
|
|
47
|
+
public:
|
|
48
|
+
// Constructor
|
|
49
|
+
explicit HybridGameMethodsSpec(): HybridObject(TAG) { }
|
|
50
|
+
|
|
51
|
+
// Destructor
|
|
52
|
+
~HybridGameMethodsSpec() override = default;
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
// Properties
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
// Methods
|
|
60
|
+
virtual void setTickRate(double tickRate) = 0;
|
|
61
|
+
virtual void setWorld(const World& world) = 0;
|
|
62
|
+
virtual void setEntities(const std::vector<Entity>& entities) = 0;
|
|
63
|
+
virtual void setSystems(const std::vector<System>& systems) = 0;
|
|
64
|
+
virtual void pause() = 0;
|
|
65
|
+
virtual void resume() = 0;
|
|
66
|
+
virtual void spawn(const std::vector<Entity>& entities) = 0;
|
|
67
|
+
virtual void despawn(const std::string& id) = 0;
|
|
68
|
+
virtual void setP(const std::string& id, double px, double py) = 0;
|
|
69
|
+
virtual void setV(const std::string& id, double vx, double vy) = 0;
|
|
70
|
+
|
|
71
|
+
protected:
|
|
72
|
+
// Hybrid Setup
|
|
73
|
+
void loadHybridMethods() override;
|
|
74
|
+
|
|
75
|
+
protected:
|
|
76
|
+
// Tag for logging
|
|
77
|
+
static constexpr auto TAG = "GameMethods";
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace margelo::nitro::rngine
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// System.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
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
// Forward declaration of `Entity` to properly resolve imports.
|
|
32
|
+
namespace margelo::nitro::rngine { struct Entity; }
|
|
33
|
+
|
|
34
|
+
#include <string>
|
|
35
|
+
#include <vector>
|
|
36
|
+
#include "Entity.hpp"
|
|
37
|
+
#include <functional>
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro::rngine {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A struct which can be represented as a JavaScript object (System).
|
|
43
|
+
*/
|
|
44
|
+
struct System final {
|
|
45
|
+
public:
|
|
46
|
+
std::vector<std::string> ids SWIFT_PRIVATE;
|
|
47
|
+
std::function<void(const std::vector<Entity>& /* entities */)> onTick SWIFT_PRIVATE;
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
System() = default;
|
|
51
|
+
explicit System(std::vector<std::string> ids, std::function<void(const std::vector<Entity>& /* entities */)> onTick): ids(ids), onTick(onTick) {}
|
|
52
|
+
|
|
53
|
+
public:
|
|
54
|
+
// System is not equatable because these properties are not equatable: onTick
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
} // namespace margelo::nitro::rngine
|
|
58
|
+
|
|
59
|
+
namespace margelo::nitro {
|
|
60
|
+
|
|
61
|
+
// C++ System <> JS System (object)
|
|
62
|
+
template <>
|
|
63
|
+
struct JSIConverter<margelo::nitro::rngine::System> final {
|
|
64
|
+
static inline margelo::nitro::rngine::System fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
65
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
66
|
+
return margelo::nitro::rngine::System(
|
|
67
|
+
JSIConverter<std::vector<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ids"))),
|
|
68
|
+
JSIConverter<std::function<void(const std::vector<margelo::nitro::rngine::Entity>&)>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onTick")))
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::System& arg) {
|
|
72
|
+
jsi::Object obj(runtime);
|
|
73
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ids"), JSIConverter<std::vector<std::string>>::toJSI(runtime, arg.ids));
|
|
74
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "onTick"), JSIConverter<std::function<void(const std::vector<margelo::nitro::rngine::Entity>&)>>::toJSI(runtime, arg.onTick));
|
|
75
|
+
return obj;
|
|
76
|
+
}
|
|
77
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
78
|
+
if (!value.isObject()) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
jsi::Object obj = value.getObject(runtime);
|
|
82
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
if (!JSIConverter<std::vector<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ids")))) return false;
|
|
86
|
+
if (!JSIConverter<std::function<void(const std::vector<margelo::nitro::rngine::Entity>&)>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onTick")))) return false;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
} // namespace margelo::nitro
|