rngine 0.11.2 → 0.11.4

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 (33) hide show
  1. package/android/CMakeLists.txt +2 -0
  2. package/lib/module/GameMethods.js +1 -14
  3. package/lib/module/GameMethods.js.map +1 -1
  4. package/lib/module/index.js.map +1 -1
  5. package/lib/typescript/src/GameMethods.d.ts +1 -1
  6. package/lib/typescript/src/GameMethods.d.ts.map +1 -1
  7. package/lib/typescript/src/GameMethods.nitro.d.ts +1 -1
  8. package/lib/typescript/src/GameMethods.nitro.d.ts.map +1 -1
  9. package/lib/typescript/src/index.d.ts +0 -1
  10. package/lib/typescript/src/index.d.ts.map +1 -1
  11. package/lib/typescript/src/types.d.ts +126 -3
  12. package/lib/typescript/src/types.d.ts.map +1 -1
  13. package/nitrogen/generated/shared/c++/HybridGameMethodsSpec.hpp +1 -3
  14. package/package.json +1 -1
  15. package/shared/GameLoop.cpp +14 -17
  16. package/shared/custom/Collision.hpp +136 -0
  17. package/shared/custom/CollisionPair.hpp +100 -0
  18. package/shared/custom/System.hpp +166 -0
  19. package/shared/custom/SystemContext.hpp +139 -0
  20. package/shared/utils/AssetUtils.cpp +77 -62
  21. package/src/GameMethods.nitro.ts +1 -1
  22. package/src/GameMethods.ts +2 -17
  23. package/src/index.tsx +0 -9
  24. package/src/types.ts +152 -12
  25. package/lib/module/nativeTypes.js +0 -2
  26. package/lib/module/nativeTypes.js.map +0 -1
  27. package/lib/typescript/src/nativeTypes.d.ts +0 -114
  28. package/lib/typescript/src/nativeTypes.d.ts.map +0 -1
  29. package/nitrogen/generated/shared/c++/Collision.hpp +0 -99
  30. package/nitrogen/generated/shared/c++/CollisionPair.hpp +0 -87
  31. package/nitrogen/generated/shared/c++/System.hpp +0 -100
  32. package/nitrogen/generated/shared/c++/SystemContext.hpp +0 -99
  33. package/src/nativeTypes.ts +0 -128
@@ -5,6 +5,7 @@ set(PACKAGE_NAME rngine)
5
5
  set(CMAKE_VERBOSE_MAKEFILE ON)
6
6
  set(CMAKE_CXX_STANDARD 20)
7
7
  set(UTILS_ROOT ${CMAKE_SOURCE_DIR}/../shared/utils)
8
+ set(CUSTOM_ROOT ${CMAKE_SOURCE_DIR}/../shared/custom)
8
9
  set(SKIA_ROOT ${CMAKE_SOURCE_DIR}/../shared/skia)
9
10
  set(SKIA_LIBS_ROOT ${CMAKE_SOURCE_DIR}/../node_modules/react-native-skia-android/libs/${ANDROID_ABI})
10
11
 
@@ -54,6 +55,7 @@ include_directories(
54
55
  "src/main/cpp"
55
56
  "../shared"
56
57
  "${UTILS_ROOT}"
58
+ "${CUSTOM_ROOT}"
57
59
  "${SKIA_ROOT}"
58
60
  )
59
61
 
@@ -11,23 +11,10 @@ export const configure = ({
11
11
  systems = [],
12
12
  paused = true
13
13
  }) => {
14
- let nativeSystems = [];
15
- for (const system of systems) {
16
- nativeSystems.push({
17
- entities: system.entities,
18
- collisions: system.collisions,
19
- onTick: systemContext => {
20
- const start = Date.now();
21
- system.onTick(systemContext);
22
- const finish = Date.now();
23
- return finish - start;
24
- }
25
- });
26
- }
27
14
  gameMethods.setWorld(world);
28
15
  gameMethods.setScreen(screen);
29
16
  gameMethods.setEntities(entities);
30
- gameMethods.setSystems(nativeSystems);
17
+ gameMethods.setSystems(systems);
31
18
  if (paused) {
32
19
  gameMethods.pause();
33
20
  } else {
@@ -1 +1 @@
1
- {"version":3,"names":["gameMethods","Image","configure","world","screen","entities","systems","paused","nativeSystems","system","push","collisions","onTick","systemContext","start","Date","now","finish","setWorld","setScreen","setEntities","setSystems","pause","resume","spawn","entityArray","Array","isArray","despawn","id","updateEntity","entityUpdate","updateEntities","entityUpdates","updateScreen","screenUpdate","assetCache","WeakMap","nextId","loadAsset","asset","Error","has","get","assetId","set","isLottieLoaded","loadLottie","JSON","stringify","isAssetLoaded","assetUri","resolveAssetSource","uri","isLoaded","loadImage","loadAssets","assets","keys","Object","result","key"],"sourceRoot":"../../src","sources":["GameMethods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C,yCAAyC,CAAC;MAC5D;MACA,OAAOG,OAAO;IAEhB,KAAK,QAAQ;MACX,IAAI5C,WAAW,CAACkD,aAAa,CAACV,KAAK,CAAC,EAAE;QACpC,OAAOA,KAAK;MACd;MACA,MAAMW,QAAQ,GAAGlD,KAAK,CAACmD,kBAAkB,CAACZ,KAAK,CAAC,EAAEa,GAAG;MACrD,IAAI,CAACF,QAAQ,EAAE;QACb,MAAM,IAAIV,KAAK,CAAC,+CAA+CD,KAAK,EAAE,CAAC;MACzE;MACA,MAAMc,QAAQ,GAAG,MAAMtD,WAAW,CAACuD,SAAS,CAACf,KAAK,EAAEW,QAAQ,CAAC;MAC7D,IAAI,CAACG,QAAQ,EAAE;QACb,MAAM,IAAIb,KAAK,CAAC,wCAAwC,CAAC;MAC3D;MACA,OAAOD,KAAK;EAChB;EAEA,MAAM,IAAIC,KAAK,CAAC,uCAAuC,OAAOD,KAAK,GAAG,CAAC;AACzE,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMgB,UAAU,GAAG,MACxBC,MAAS,IAC+B;EACxC,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACD,MAAM,CAAgB;EAC/C,MAAMG,MAAM,GAAG,CAAC,CAA+B;EAE/C,KAAK,MAAMC,GAAG,IAAIH,IAAI,EAAE;IACtBE,MAAM,CAACC,GAAG,CAAC,GAAG,MAAMtB,SAAS,CAACkB,MAAM,CAACI,GAAG,CAAC,CAAC;EAC5C;EAEA,OAAOD,MAAM;AACf,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["gameMethods","Image","configure","world","screen","entities","systems","paused","setWorld","setScreen","setEntities","setSystems","pause","resume","spawn","entityArray","Array","isArray","despawn","id","updateEntity","entityUpdate","updateEntities","entityUpdates","updateScreen","screenUpdate","assetCache","WeakMap","nextId","loadAsset","asset","Error","has","get","assetId","set","isLottieLoaded","loadLottie","JSON","stringify","isAssetLoaded","assetUri","resolveAssetSource","uri","isLoaded","loadImage","loadAssets","assets","keys","Object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G,QAAQ,EAAE;QACb,MAAM,IAAIb,KAAK,CAAC,wCAAwC,CAAC;MAC3D;MACA,OAAOD,KAAK;EAChB;EAEA,MAAM,IAAIC,KAAK,CAAC,uCAAuC,OAAOD,KAAK,GAAG,CAAC;AACzE,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMgB,UAAU,GAAG,MACxBC,MAAS,IAC+B;EACxC,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACD,MAAM,CAAgB;EAC/C,MAAMG,MAAM,GAAG,CAAC,CAA+B;EAE/C,KAAK,MAAMC,GAAG,IAAIH,IAAI,EAAE;IACtBE,MAAM,CAACC,GAAG,CAAC,GAAG,MAAMtB,SAAS,CAACkB,MAAM,CAACI,GAAG,CAAC,CAAC;EAC5C;EAEA,OAAOD,MAAM;AACf,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["GameEngine"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,UAAU,MAAM,iBAAc;AAErC,cAAc,kBAAe;AAC7B,cAAc,YAAS;AAUvB,SAASA,UAAU","ignoreList":[]}
1
+ {"version":3,"names":["GameEngine"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,UAAU,MAAM,iBAAc;AAErC,cAAc,kBAAe;AAC7B,cAAc,YAAS;AACvB,SAASA,UAAU","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { Entity, EntityUpdate, ScreenUpdate } from './nativeTypes.js';
1
+ import type { Entity, EntityUpdate, ScreenUpdate } from './types.js';
2
2
  import type { Config } from './types.js';
3
3
  /** Sets up the game engine with the given configuration. Call this before anything else. */
4
4
  export declare const configure: ({ world, screen, entities, systems, paused, }: Config) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"GameMethods.d.ts","sourceRoot":"","sources":["../../../src/GameMethods.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAU,MAA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,eAAO,MAAM,KAAK,GAAI,UAAU,MAAM,GAAG,MAAM,EAAE,SAGhD,CAAC;AAEF,2HAA2H;AAC3H,eAAO,MAAM,OAAO,GAAI,IAAI,MAAM,SAA4B,CAAC;AAE/D,+HAA+H;AAC/H,eAAO,MAAM,YAAY,GAAI,cAAc,YAAY,SAEtD,CAAC;AAEF,oGAAoG;AACpG,eAAO,MAAM,cAAc,GAAI,eAAe,YAAY,EAAE,SAE3D,CAAC;AAEF,gEAAgE;AAChE,eAAO,MAAM,YAAY,GAAI,cAAc,YAAY,SAEtD,CAAC;AA2CF;;yEAEyE;AACzE,eAAO,MAAM,UAAU,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,QAAQ,CAAC,KACR,OAAO,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,GAAE,CASpC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { HybridObject } from 'react-native-nitro-modules';
2
- import type { Entity, EntityUpdate, System, Screen, World, ScreenUpdate } from './nativeTypes.js';
2
+ import type { Entity, EntityUpdate, System, Screen, World, ScreenUpdate } from './types.js';
3
3
  interface GameMethods extends HybridObject<{
4
4
  ios: 'c++';
5
5
  android: 'c++';
@@ -1 +1 @@
1
- {"version":3,"file":"GameMethods.nitro.d.ts","sourceRoot":"","sources":["../../../src/GameMethods.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,MAAM,EACN,MAAM,EACN,KAAK,EACL,YAAY,EACb,MAAM,kBAAe,CAAC;AAGvB,UAAU,WAAY,SAAQ,YAAY,CAAC;IACzC,GAAG,EAAE,KAAK,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;IACA,4BAA4B;IAC5B,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,SAAS,C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AI,CAAC;IAC7B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACtC,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAEpC,2BAA2B;IAC3B,KAAK,IAAI,IAAI,CAAC;IACd,MAAM,IAAI,IAAI,CAAC;IAEf,4BAA4B;IAC5B,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,cAAc,CAAC,aAAa,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAEpD,4BAA4B;IAC5B,YAAY,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAE/C,oBAAoB;IACpB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1D,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3D;AAED,eAAO,MAAM,WAAW,aACqC,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import GameEngine from './GameEngine.js';
2
2
  export * from './GameMethods.js';
3
3
  export * from './types.js';
4
- export type { World, Screen, Entity, CollisionPair, Collision, EntityUpdate, SystemContext, } from './nativeTypes.js';
5
4
  export { GameEngine };
6
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAc,CAAC;AAEtC,cAAc,kBAAe,CAAC;AAC9B,cAAc,YAAS,CAAC;AACxB,YAAY,EACV,KAAK,EACL,MAAM,EACN,MAAM,EACN,aAAa,EACb,SAAS,EACT,YAAY,EACZ,aAAa,GACd,MAAM,kBAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAc,CAAC;AAEtC,cAAc,kBAAe,CAAC;AAC9B,cAAc,YAAS,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -1,8 +1,130 @@
1
- import type { System as NativeSystem, Screen, Entity, World, SystemContext } from './nativeTypes.js';
2
- export type System = Omit<NativeSystem, 'onTick'> & {
1
+ import type { CustomType } from 'react-native-nitro-modules';
2
+ interface Positioned {
3
+ /** X position in game units. */
4
+ px: number;
5
+ /** Y position in game units. */
6
+ py: number;
7
+ }
8
+ interface Rect {
9
+ /** Width in game units. */
10
+ width: number;
11
+ /** Height in game units. */
12
+ height: number;
13
+ }
14
+ interface Circle {
15
+ /** Radius in game units. */
16
+ radius: number;
17
+ }
18
+ interface Shaped {
19
+ /** Shape of the entity. */
20
+ shape: Rect | Circle;
21
+ /** Indicates whether the entity is a sensor. Sensors trigger collision events but don't react physically. */
22
+ isSensor?: boolean;
23
+ }
24
+ export type ObjectFit = 'fill' | 'contain' | 'cover' | 'none';
25
+ export type Repeat = 'no-repeat' | 'repeat' | 'repeat-x' | 'repeat-y';
26
+ interface Renderable {
27
+ /** Fill color as a hex string e.g. `'#00ff00'`. */
28
+ color?: string;
29
+ /** Asset to render, use `require` with the file path to get the id. */
30
+ asset?: number;
31
+ /** Whether to flip the rendered asset horizontally. */
32
+ flipH?: boolean;
33
+ /** Whether to flip the rendered asset vertically. */
34
+ flipV?: boolean;
35
+ /** How the asset should be scaled to fit its target dimensions. Defaults to `'fill'`. */
36
+ objectFit?: ObjectFit;
37
+ /** Explicitly clips content that overflows the target dimensions. Defaults to `false`. */
38
+ clip?: boolean;
39
+ /** Repeating/tiling mode for the asset across target bounds. Defaults to `'no-repeat'`. */
40
+ repeat?: Repeat;
41
+ /** Animation progress between 0 and 1, automatically advanced each tick for Lottie assets. */
42
+ progress?: number;
43
+ /** Playback speed multiplier for Lottie assets (1 = normal speed). */
44
+ speed?: number;
45
+ /** Whether the Lottie animation should restart automatically upon completion. */
46
+ loop?: boolean;
47
+ }
48
+ interface Kinematic {
49
+ /** Horizontal velocity in game units per second. */
50
+ vx?: number;
51
+ /** Vertical velocity in game units per second. */
52
+ vy?: number;
53
+ /** Horizontal acceleration in game units per second squared. */
54
+ ax?: number;
55
+ /** Vertical acceleration in game units per second squared. */
56
+ ay?: number;
57
+ /** Mass in arbitrary units. */
58
+ mass?: number;
59
+ }
60
+ export interface World {
61
+ /** Number of game logic updates per second. */
62
+ tickRate: number;
63
+ /** Horizontal gravitational acceleration in game units per second squared. */
64
+ gx?: number;
65
+ /** Vertical gravitational acceleration in game units per second squared. */
66
+ gy?: number;
67
+ }
68
+ export interface Screen extends Positioned, Rect, Renderable {
69
+ }
70
+ export interface Entity extends Positioned, Shaped, Renderable, Kinematic {
71
+ /** Unique identifier. Use `_` as a separator for group queries e.g. `'enemy_1'`. */
72
+ id: string;
73
+ }
74
+ export interface EntityUpdate extends Partial<Positioned & Shaped & Renderable & Kinematic> {
75
+ /** Unique identifier or prefix of the entities to update. */
76
+ id: string;
77
+ }
78
+ export interface ScreenUpdate extends Partial<Screen> {
79
+ }
80
+ export type CollisionPair = CustomType<{
81
+ /** Entity id or prefix of the first entity to watch. */
82
+ a: string;
83
+ /** Entity id or prefix of the second entity to watch. */
84
+ b: string;
85
+ }, 'margelo::nitro::rngine::CollisionPair', {
86
+ include: 'CollisionPair.hpp';
87
+ }>;
88
+ export type Collision = CustomType<{
89
+ /** Id of the first entity involved in the collision. */
90
+ a: string;
91
+ /** Id of the second entity involved in the collision. */
92
+ b: string;
93
+ /** Penetration depth of the collision. */
94
+ depth: number;
95
+ /** X component of a normalised vector that represents the direction between the bodies providing the minimum separating distance. */
96
+ nx: number;
97
+ /** Y component of a normalised vector that represents the direction between the bodies providing the minimum separating distance. */
98
+ ny: number;
99
+ }, 'margelo::nitro::rngine::Collision', {
100
+ include: 'Collision.hpp';
101
+ }>;
102
+ export type SystemContext = CustomType<{
103
+ /** Current game world state. */
104
+ world?: World;
105
+ /** Current game screen state. */
106
+ screen?: Screen;
107
+ /** Entities resolved from the system's entity subscriptions. */
108
+ entities?: Entity[];
109
+ /** Collisions matching the system's collision subscriptions. */
110
+ collisions?: Collision[];
111
+ }, 'margelo::nitro::rngine::SystemContext', {
112
+ include: 'SystemContext.hpp';
113
+ }>;
114
+ export type System = CustomType<{
115
+ /** Whether to include the world state in the system context. */
116
+ world?: boolean;
117
+ /** Whether to include the screen state in the system context. */
118
+ screen?: boolean;
119
+ /** Entity ids or prefixes this system subscribes to. */
120
+ entities?: string[];
121
+ /** Collision pairs to watch for every tick. */
122
+ collisions?: CollisionPair[];
3
123
  /** Called every tick with the resolved entities and collisions. */
4
124
  onTick: (systemContext: SystemContext) => void;
5
- };
125
+ }, 'margelo::nitro::rngine::System', {
126
+ include: 'System.hpp';
127
+ }>;
6
128
  export type Config = {
7
129
  /** World settings: tick rate and gravity. */
8
130
  world: World;
@@ -15,4 +137,5 @@ export type Config = {
15
137
  /** Whether the game starts paused. Defaults to true. */
16
138
  paused?: boolean;
17
139
  };
140
+ export {};
18
141
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,IAAI,YAAY,EACtB,MAAM,EACN,MAAM,EACN,KAAK,EACL,aAAa,EACd,MAAM,kBAAe,CAAC;AAEvB,MAAM,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG;IAClD,mEAAmE;IACnE,MAAM,EAAE,CAAC,aAAa,EAAE,aAAa,KAAK,IAAI,CAAC;CAChD,CAAC;AA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nB,6CAA6C;IAC7C,KAAK,EAAE,KAAK,CAAC;IACb,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,8GAA8G;IAC9G,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,wDAAwD;IACxD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC"}
@@ -19,8 +19,6 @@ namespace margelo::nitro::rngine { struct World; }
19
19
  namespace margelo::nitro::rngine { struct Screen; }
20
20
  // Forward declaration of `Entity` to properly resolve imports.
21
21
  namespace margelo::nitro::rngine { struct Entity; }
22
- // Forward declaration of `System` to properly resolve imports.
23
- namespace margelo::nitro::rngine { struct System; }
24
22
  // Forward declaration of `EntityUpdate` to properly resolve imports.
25
23
  namespace margelo::nitro::rngine { struct EntityUpdate; }
26
24
  // Forward declaration of `ScreenUpdate` to properly resolve imports.
@@ -70,7 +68,7 @@ namespace margelo::nitro::rngine {
70
68
  virtual void setWorld(const World& world) = 0;
71
69
  virtual void setScreen(const Screen& screen) = 0;
72
70
  virtual void setEntities(const std::vector<Entity>& entities) = 0;
73
- virtual void setSystems(const std::vector<System>& systems) = 0;
71
+ virtual void setSystems(const std::vector<margelo::nitro::rngine::System>& systems) = 0;
74
72
  virtual void pause() = 0;
75
73
  virtual void resume() = 0;
76
74
  virtual void spawn(const std::vector<Entity>& entities) = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rngine",
3
- "version": "0.11.2",
3
+ "version": "0.11.4",
4
4
  "description": "React Native 2D game engine powered by Nitro Modules",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -111,22 +111,30 @@ void GameLoop::runSystems() {
111
111
  auto &system = _systems[systemIndex];
112
112
  SystemContext systemContext;
113
113
 
114
- systemContext.screen = _screen;
114
+ if (system.world.value_or(false)) {
115
+ systemContext.world = _world;
116
+ }
117
+
118
+ if (system.screen.value_or(false)) {
119
+ systemContext.screen = _screen;
120
+ }
115
121
 
116
122
  if (system.entities.has_value()) {
123
+ systemContext.entities.emplace();
117
124
  for (const auto &id : system.entities.value()) {
118
125
  auto resolvedEntitiesInternal = resolveEntitiesInternal(id);
119
126
  for (auto *entity : resolvedEntitiesInternal)
120
- systemContext.entities.push_back(*entity);
127
+ systemContext.entities->push_back(*entity);
121
128
  }
122
129
  }
123
130
 
124
131
  if (system.collisions.has_value()) {
132
+ systemContext.collisions.emplace();
125
133
  for (const auto &pair : system.collisions.value()) {
126
134
  for (const auto &c : _collisions) {
127
135
 
128
136
  if (entityIdMatches(c.a, pair.a) && entityIdMatches(c.b, pair.b)) {
129
- systemContext.collisions.push_back(c);
137
+ systemContext.collisions.value().push_back(c);
130
138
  } else if (entityIdMatches(c.a, pair.b) &&
131
139
  entityIdMatches(c.b, pair.a)) {
132
140
  auto swappedCollision = c;
@@ -137,25 +145,14 @@ void GameLoop::runSystems() {
137
145
  swappedCollision.nx = -c.nx;
138
146
  swappedCollision.ny = -c.ny;
139
147
 
140
- systemContext.collisions.push_back(swappedCollision);
148
+ systemContext.collisions->push_back(swappedCollision);
141
149
  }
142
150
  }
143
151
  }
144
152
  }
145
153
 
146
- __android_log_print(
147
- ANDROID_LOG_DEBUG, "GameLoop",
148
- "System Index: %zu, Entities: %zu, Collisions: %zu, Calling onTick",
149
- systemIndex, systemContext.entities.size(),
150
- systemContext.collisions.size());
151
-
152
- std::shared_ptr<Promise<double>> promise = system.onTick(systemContext);
153
- std::future<double> future = promise->await();
154
- double duration = future.get();
155
-
156
- __android_log_print(ANDROID_LOG_DEBUG, "GameLoop",
157
- "System Index: %zu, onTick Complete, Duration: %.2fms",
158
- systemIndex, duration);
154
+ std::shared_ptr<Promise<void>> promise = system.onTick(systemContext);
155
+ promise->await().get();
159
156
  }
160
157
  }
161
158
 
@@ -0,0 +1,136 @@
1
+ #pragma once
2
+
3
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
4
+ #include <NitroModules/JSIConverter.hpp>
5
+ #else
6
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
7
+ #endif
8
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
9
+ #include <NitroModules/NitroDefines.hpp>
10
+ #else
11
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
12
+ #endif
13
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
14
+ #include <NitroModules/JSIHelpers.hpp>
15
+ #else
16
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
17
+ #endif
18
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
19
+ #include <NitroModules/PropNameIDCache.hpp>
20
+ #else
21
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
22
+ #endif
23
+
24
+ #include <string>
25
+
26
+ namespace margelo::nitro::rngine {
27
+
28
+ struct Collision final {
29
+ public:
30
+ std::string a SWIFT_PRIVATE;
31
+ std::string b SWIFT_PRIVATE;
32
+ double depth SWIFT_PRIVATE;
33
+ double nx SWIFT_PRIVATE;
34
+ double ny SWIFT_PRIVATE;
35
+
36
+ public:
37
+ Collision() = default;
38
+ explicit Collision(std::string a, std::string b, double depth, double nx,
39
+ double ny)
40
+ : a(a), b(b), depth(depth), nx(nx), ny(ny) {}
41
+
42
+ public:
43
+ friend bool operator==(const Collision &lhs, const Collision &rhs) = default;
44
+ };
45
+
46
+ } // namespace margelo::nitro::rngine
47
+
48
+ namespace margelo::nitro {
49
+
50
+ template <> struct JSIConverter<rngine::Collision> final {
51
+
52
+ static inline rngine::Collision fromJSI(jsi::Runtime &runtime,
53
+ const jsi::Value &arg) {
54
+ jsi::Object obj = arg.asObject(runtime);
55
+
56
+ return rngine::Collision(
57
+ JSIConverter<std::string>::fromJSI(
58
+ runtime,
59
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "a"))),
60
+ JSIConverter<std::string>::fromJSI(
61
+ runtime,
62
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "b"))),
63
+ JSIConverter<double>::fromJSI(
64
+ runtime,
65
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "depth"))),
66
+ JSIConverter<double>::fromJSI(
67
+ runtime,
68
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "nx"))),
69
+ JSIConverter<double>::fromJSI(
70
+ runtime,
71
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "ny"))));
72
+ }
73
+
74
+ static inline jsi::Value toJSI(jsi::Runtime &runtime,
75
+ const rngine::Collision &arg) {
76
+ jsi::Object obj(runtime);
77
+
78
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "a"),
79
+ JSIConverter<std::string>::toJSI(runtime, arg.a));
80
+
81
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "b"),
82
+ JSIConverter<std::string>::toJSI(runtime, arg.b));
83
+
84
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "depth"),
85
+ JSIConverter<double>::toJSI(runtime, arg.depth));
86
+
87
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "nx"),
88
+ JSIConverter<double>::toJSI(runtime, arg.nx));
89
+
90
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "ny"),
91
+ JSIConverter<double>::toJSI(runtime, arg.ny));
92
+
93
+ return obj;
94
+ }
95
+
96
+ static inline bool canConvert(jsi::Runtime &runtime,
97
+ const jsi::Value &value) {
98
+ if (!value.isObject()) {
99
+ return false;
100
+ }
101
+
102
+ jsi::Object obj = value.getObject(runtime);
103
+
104
+ if (!nitro::isPlainObject(runtime, obj)) {
105
+ return false;
106
+ }
107
+
108
+ if (!JSIConverter<std::string>::canConvert(
109
+ runtime,
110
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "a"))))
111
+ return false;
112
+
113
+ if (!JSIConverter<std::string>::canConvert(
114
+ runtime,
115
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "b"))))
116
+ return false;
117
+
118
+ if (!JSIConverter<double>::canConvert(
119
+ runtime,
120
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "depth"))))
121
+ return false;
122
+
123
+ if (!JSIConverter<double>::canConvert(
124
+ runtime,
125
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "nx"))))
126
+ return false;
127
+
128
+ if (!JSIConverter<double>::canConvert(
129
+ runtime,
130
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "ny"))))
131
+ return false;
132
+
133
+ return true;
134
+ }
135
+ };
136
+ } // namespace margelo::nitro
@@ -0,0 +1,100 @@
1
+ #pragma once
2
+
3
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
4
+ #include <NitroModules/JSIConverter.hpp>
5
+ #else
6
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
7
+ #endif
8
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
9
+ #include <NitroModules/NitroDefines.hpp>
10
+ #else
11
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
12
+ #endif
13
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
14
+ #include <NitroModules/JSIHelpers.hpp>
15
+ #else
16
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
17
+ #endif
18
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
19
+ #include <NitroModules/PropNameIDCache.hpp>
20
+ #else
21
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
22
+ #endif
23
+
24
+ #include <string>
25
+
26
+ namespace margelo::nitro::rngine {
27
+
28
+ struct CollisionPair final {
29
+ public:
30
+ std::string a SWIFT_PRIVATE;
31
+ std::string b SWIFT_PRIVATE;
32
+
33
+ public:
34
+ CollisionPair() = default;
35
+ explicit CollisionPair(std::string a, std::string b) : a(a), b(b) {}
36
+
37
+ public:
38
+ friend bool operator==(const CollisionPair &lhs,
39
+ const CollisionPair &rhs) = default;
40
+ };
41
+
42
+ } // namespace margelo::nitro::rngine
43
+
44
+ namespace margelo::nitro {
45
+
46
+ template <> struct JSIConverter<rngine::CollisionPair> final {
47
+
48
+ static inline rngine::CollisionPair fromJSI(jsi::Runtime &runtime,
49
+ const jsi::Value &arg) {
50
+ jsi::Object obj = arg.asObject(runtime);
51
+
52
+ return rngine::CollisionPair(
53
+ JSIConverter<std::string>::fromJSI(
54
+ runtime,
55
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "a"))),
56
+ JSIConverter<std::string>::fromJSI(
57
+ runtime,
58
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "b"))));
59
+ }
60
+
61
+ static inline jsi::Value toJSI(jsi::Runtime &runtime,
62
+ const rngine::CollisionPair &arg) {
63
+ jsi::Object obj(runtime);
64
+
65
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "a"),
66
+ JSIConverter<std::string>::toJSI(runtime, arg.a));
67
+
68
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "b"),
69
+ JSIConverter<std::string>::toJSI(runtime, arg.b));
70
+
71
+ return obj;
72
+ }
73
+
74
+ static inline bool canConvert(jsi::Runtime &runtime,
75
+ const jsi::Value &value) {
76
+ if (!value.isObject()) {
77
+ return false;
78
+ }
79
+
80
+ jsi::Object obj = value.getObject(runtime);
81
+
82
+ if (!nitro::isPlainObject(runtime, obj)) {
83
+ return false;
84
+ }
85
+
86
+ if (!JSIConverter<std::string>::canConvert(
87
+ runtime,
88
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "a"))))
89
+ return false;
90
+
91
+ if (!JSIConverter<std::string>::canConvert(
92
+ runtime,
93
+ obj.getProperty(runtime, PropNameIDCache::get(runtime, "b"))))
94
+ return false;
95
+
96
+ return true;
97
+ }
98
+ };
99
+
100
+ } // namespace margelo::nitro