rngine 0.7.0 → 0.7.1
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/lib/typescript/src/nativeTypes.d.ts +6 -2
- package/lib/typescript/src/nativeTypes.d.ts.map +1 -1
- package/nitrogen/generated/shared/c++/Entity.hpp +10 -2
- package/nitrogen/generated/shared/c++/EntityUpdate.hpp +10 -2
- package/package.json +1 -1
- package/shared/GameLoop.cpp +13 -6
- package/shared/GameMethods.cpp +6 -0
- package/src/nativeTypes.ts +6 -2
|
@@ -27,10 +27,14 @@ interface Renderable {
|
|
|
27
27
|
progress?: number;
|
|
28
28
|
}
|
|
29
29
|
interface Kinematic {
|
|
30
|
-
/**
|
|
30
|
+
/** Horizontal velocity in game units per second. */
|
|
31
31
|
vx?: number;
|
|
32
|
-
/**
|
|
32
|
+
/** Vertical velocity in game units per second. */
|
|
33
33
|
vy?: number;
|
|
34
|
+
/** Horizontal acceleration in game units per second squared. */
|
|
35
|
+
ax?: number;
|
|
36
|
+
/** Vertical acceleration in game units per second squared. */
|
|
37
|
+
ay?: number;
|
|
34
38
|
}
|
|
35
39
|
export interface Screen extends Rect, Renderable {
|
|
36
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeTypes.d.ts","sourceRoot":"","sources":["../../../src/nativeTypes.ts"],"names":[],"mappings":"AAAA,UAAU,UAAU;IAClB,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,UAAU,IAAI;IACZ,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,MAAM;IACd,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,MAAM;IACd,2BAA2B;IAC3B,KAAK,EAAE,IAAI,GAAG,MAAM,CAAC;CACtB;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Z;AAED,MAAM,WAAW,YAAa,SAAQ,OAAO,CAC3C,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,CAC7C;IACC,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,aAAa;IAC5B,wDAAwD;IACxD,CAAC,EAAE,MAAM,CAAC;IACV,yDAAyD;IACzD,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,SAAS;IACxB,wDAAwD;IACxD,CAAC,EAAE,MAAM,CAAC;IACV,yDAAyD;IACzD,CAAC,EAAE,MAAM,CAAC;IACV,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,MAAM;IACrB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,+CAA+C;IAC/C,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAC7B,mEAAmE;IACnE,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,MAAM,CAAC;CACjE"}
|
|
@@ -55,10 +55,12 @@ namespace margelo::nitro::rngine {
|
|
|
55
55
|
std::optional<double> progress SWIFT_PRIVATE;
|
|
56
56
|
std::optional<double> vx SWIFT_PRIVATE;
|
|
57
57
|
std::optional<double> vy SWIFT_PRIVATE;
|
|
58
|
+
std::optional<double> ax SWIFT_PRIVATE;
|
|
59
|
+
std::optional<double> ay SWIFT_PRIVATE;
|
|
58
60
|
|
|
59
61
|
public:
|
|
60
62
|
Entity() = default;
|
|
61
|
-
explicit Entity(std::string id, double px, double py, std::variant<Rect, Circle> shape, std::optional<std::string> color, std::optional<double> asset, std::optional<double> progress, std::optional<double> vx, std::optional<double> vy): id(id), px(px), py(py), shape(shape), color(color), asset(asset), progress(progress), vx(vx), vy(vy) {}
|
|
63
|
+
explicit Entity(std::string id, double px, double py, std::variant<Rect, Circle> shape, std::optional<std::string> color, std::optional<double> asset, std::optional<double> progress, std::optional<double> vx, std::optional<double> vy, std::optional<double> ax, std::optional<double> ay): id(id), px(px), py(py), shape(shape), color(color), asset(asset), progress(progress), vx(vx), vy(vy), ax(ax), ay(ay) {}
|
|
62
64
|
|
|
63
65
|
public:
|
|
64
66
|
friend bool operator==(const Entity& lhs, const Entity& rhs) = default;
|
|
@@ -82,7 +84,9 @@ namespace margelo::nitro {
|
|
|
82
84
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset"))),
|
|
83
85
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress"))),
|
|
84
86
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx"))),
|
|
85
|
-
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))
|
|
87
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy"))),
|
|
88
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax"))),
|
|
89
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ay")))
|
|
86
90
|
);
|
|
87
91
|
}
|
|
88
92
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::Entity& arg) {
|
|
@@ -96,6 +100,8 @@ namespace margelo::nitro {
|
|
|
96
100
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "progress"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.progress));
|
|
97
101
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "vx"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vx));
|
|
98
102
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "vy"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vy));
|
|
103
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ax"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.ax));
|
|
104
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ay"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.ay));
|
|
99
105
|
return obj;
|
|
100
106
|
}
|
|
101
107
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -115,6 +121,8 @@ namespace margelo::nitro {
|
|
|
115
121
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress")))) return false;
|
|
116
122
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx")))) return false;
|
|
117
123
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))) return false;
|
|
124
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax")))) return false;
|
|
125
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ay")))) return false;
|
|
118
126
|
return true;
|
|
119
127
|
}
|
|
120
128
|
};
|
|
@@ -55,10 +55,12 @@ namespace margelo::nitro::rngine {
|
|
|
55
55
|
std::optional<double> progress SWIFT_PRIVATE;
|
|
56
56
|
std::optional<double> vx SWIFT_PRIVATE;
|
|
57
57
|
std::optional<double> vy SWIFT_PRIVATE;
|
|
58
|
+
std::optional<double> ax SWIFT_PRIVATE;
|
|
59
|
+
std::optional<double> ay SWIFT_PRIVATE;
|
|
58
60
|
|
|
59
61
|
public:
|
|
60
62
|
EntityUpdate() = default;
|
|
61
|
-
explicit EntityUpdate(std::string id, std::optional<double> px, std::optional<double> py, std::optional<std::variant<Rect, Circle>> shape, std::optional<std::string> color, std::optional<double> asset, std::optional<double> progress, std::optional<double> vx, std::optional<double> vy): id(id), px(px), py(py), shape(shape), color(color), asset(asset), progress(progress), vx(vx), vy(vy) {}
|
|
63
|
+
explicit EntityUpdate(std::string id, std::optional<double> px, std::optional<double> py, std::optional<std::variant<Rect, Circle>> shape, std::optional<std::string> color, std::optional<double> asset, std::optional<double> progress, std::optional<double> vx, std::optional<double> vy, std::optional<double> ax, std::optional<double> ay): id(id), px(px), py(py), shape(shape), color(color), asset(asset), progress(progress), vx(vx), vy(vy), ax(ax), ay(ay) {}
|
|
62
64
|
|
|
63
65
|
public:
|
|
64
66
|
friend bool operator==(const EntityUpdate& lhs, const EntityUpdate& rhs) = default;
|
|
@@ -82,7 +84,9 @@ namespace margelo::nitro {
|
|
|
82
84
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "asset"))),
|
|
83
85
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress"))),
|
|
84
86
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx"))),
|
|
85
|
-
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))
|
|
87
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy"))),
|
|
88
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax"))),
|
|
89
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ay")))
|
|
86
90
|
);
|
|
87
91
|
}
|
|
88
92
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::EntityUpdate& arg) {
|
|
@@ -96,6 +100,8 @@ namespace margelo::nitro {
|
|
|
96
100
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "progress"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.progress));
|
|
97
101
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "vx"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vx));
|
|
98
102
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "vy"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.vy));
|
|
103
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ax"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.ax));
|
|
104
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ay"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.ay));
|
|
99
105
|
return obj;
|
|
100
106
|
}
|
|
101
107
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -115,6 +121,8 @@ namespace margelo::nitro {
|
|
|
115
121
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "progress")))) return false;
|
|
116
122
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vx")))) return false;
|
|
117
123
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy")))) return false;
|
|
124
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax")))) return false;
|
|
125
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ay")))) return false;
|
|
118
126
|
return true;
|
|
119
127
|
}
|
|
120
128
|
};
|
package/package.json
CHANGED
package/shared/GameLoop.cpp
CHANGED
|
@@ -192,16 +192,23 @@ void GameLoop::updateEntities(double deltaTime) {
|
|
|
192
192
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
193
193
|
|
|
194
194
|
for (auto &[id, entity] : _entities) {
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
|
|
196
|
+
if (entity.ax.has_value()) {
|
|
197
|
+
entity.vx = entity.vx.value_or(0.0) + entity.ax.value() * deltaTime;
|
|
198
|
+
}
|
|
199
|
+
if (entity.ay.has_value()) {
|
|
200
|
+
entity.vy = entity.vy.value_or(0.0) + entity.ay.value() * deltaTime;
|
|
197
201
|
}
|
|
198
202
|
|
|
199
|
-
if (entity.
|
|
200
|
-
entity.
|
|
203
|
+
if (entity.vx.has_value()) {
|
|
204
|
+
entity.px += entity.vx.value() * deltaTime;
|
|
205
|
+
}
|
|
206
|
+
if (entity.vy.has_value()) {
|
|
207
|
+
entity.py += entity.vy.value() * deltaTime;
|
|
201
208
|
}
|
|
202
209
|
|
|
203
|
-
if (entity.asset && entity.asset < 0) {
|
|
204
|
-
auto it = _lottieDurations.find(
|
|
210
|
+
if (entity.asset.has_value() && entity.asset.value() < 0) {
|
|
211
|
+
auto it = _lottieDurations.find(entity.asset.value());
|
|
205
212
|
if (it != _lottieDurations.end() && it->second > 0.0) {
|
|
206
213
|
entity.progress =
|
|
207
214
|
fmod(entity.progress.value_or(0.0) + deltaTime / it->second, 1.0);
|
package/shared/GameMethods.cpp
CHANGED
|
@@ -145,6 +145,12 @@ void GameMethods::update(const std::vector<EntityUpdate> &updates) {
|
|
|
145
145
|
if (update.vy.has_value()) {
|
|
146
146
|
entity->vy = update.vy.value();
|
|
147
147
|
}
|
|
148
|
+
if (update.ax.has_value()) {
|
|
149
|
+
entity->ax = update.ax.value();
|
|
150
|
+
}
|
|
151
|
+
if (update.ay.has_value()) {
|
|
152
|
+
entity->ay = update.ay.value();
|
|
153
|
+
}
|
|
148
154
|
}
|
|
149
155
|
|
|
150
156
|
__android_log_print(ANDROID_LOG_INFO, "GameMethods",
|
package/src/nativeTypes.ts
CHANGED
|
@@ -32,10 +32,14 @@ interface Renderable {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
interface Kinematic {
|
|
35
|
-
/**
|
|
35
|
+
/** Horizontal velocity in game units per second. */
|
|
36
36
|
vx?: number;
|
|
37
|
-
/**
|
|
37
|
+
/** Vertical velocity in game units per second. */
|
|
38
38
|
vy?: number;
|
|
39
|
+
/** Horizontal acceleration in game units per second squared. */
|
|
40
|
+
ax?: number;
|
|
41
|
+
/** Vertical acceleration in game units per second squared. */
|
|
42
|
+
ay?: number;
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
export interface Screen extends Rect, Renderable {}
|