rngine 0.4.2 → 0.6.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/README.md +1 -1
- package/android/kls_database.db +0 -0
- package/android/src/main/cpp/GameLoopJNI.cpp +84 -27
- package/android/src/main/java/com/margelo/nitro/rngine/GameAssets.kt +34 -20
- package/android/src/main/java/com/margelo/nitro/rngine/GameView.kt +80 -48
- package/android/src/main/java/com/margelo/nitro/rngine/Rect.kt +2 -2
- package/android/src/main/java/com/margelo/nitro/rngine/Screen.kt +9 -0
- package/android/src/main/java/com/margelo/nitro/rngine/Snapshot.kt +3 -0
- package/android/src/main/java/com/margelo/nitro/rngine/SnapshotSerializer.kt +33 -0
- package/lib/module/GameAssets.js +41 -0
- package/lib/module/GameAssets.js.map +1 -0
- package/lib/module/GameEngine.js +1 -1
- package/lib/module/GameEngine.js.map +1 -1
- package/lib/module/GameMethods.js +43 -0
- package/lib/module/GameMethods.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/GameAssets.d.ts +2 -0
- package/lib/typescript/src/GameAssets.d.ts.map +1 -0
- package/lib/typescript/src/GameAssets.nitro.d.ts +2 -2
- package/lib/typescript/src/GameAssets.nitro.d.ts.map +1 -1
- package/lib/typescript/src/GameMethods.d.ts +8 -0
- package/lib/typescript/src/GameMethods.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/nativeTypes.d.ts +25 -44
- package/lib/typescript/src/nativeTypes.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +2 -15
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridGameAssetsSpec.cpp +31 -6
- package/nitrogen/generated/android/c++/JHybridGameAssetsSpec.hpp +2 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngine/HybridGameAssetsSpec.kt +3 -2
- package/nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.cpp +16 -0
- package/nitrogen/generated/ios/Rngine-Swift-Cxx-Bridge.hpp +65 -6
- package/nitrogen/generated/ios/Rngine-Swift-Cxx-Umbrella.hpp +1 -0
- package/nitrogen/generated/ios/c++/HybridGameAssetsSpecSwift.hpp +7 -2
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridGameAssetsSpec.swift +2 -2
- package/nitrogen/generated/ios/swift/HybridGameAssetsSpec_cxx.swift +24 -8
- package/nitrogen/generated/shared/c++/HybridGameAssetsSpec.hpp +3 -2
- package/package.json +1 -1
- package/shared/GameLoop.cpp +11 -38
- package/shared/GameLoop.hpp +0 -2
- package/shared/GameMethods.cpp +2 -0
- package/src/GameAssets.nitro.ts +2 -2
- package/src/GameAssets.ts +47 -0
- package/src/GameEngine.tsx +1 -1
- package/src/GameMethods.ts +48 -0
- package/src/index.tsx +8 -1
- package/src/nativeTypes.ts +31 -46
- package/src/types.ts +3 -19
- package/android/src/main/java/com/margelo/nitro/rngine/RectSerializer.kt +0 -25
- package/lib/module/Shared.js +0 -85
- package/lib/module/Shared.js.map +0 -1
- package/lib/typescript/src/Shared.d.ts +0 -8
- package/lib/typescript/src/Shared.d.ts.map +0 -1
- package/shared/Rect.hpp +0 -16
- package/src/Shared.ts +0 -99
- /package/{shared → android/src/main/cpp}/ColorUtils.hpp +0 -0
package/shared/GameLoop.hpp
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
#include "Entity.hpp"
|
|
4
4
|
#include "GameStats.hpp"
|
|
5
|
-
#include "Rect.hpp"
|
|
6
5
|
#include "Screen.hpp"
|
|
7
6
|
#include "System.hpp"
|
|
8
7
|
#include <atomic>
|
|
@@ -34,7 +33,6 @@ public:
|
|
|
34
33
|
|
|
35
34
|
std::vector<Entity *> resolveEntitiesInternal(const std::string &prefix);
|
|
36
35
|
void registerLottieDuration(double, double);
|
|
37
|
-
std::vector<Rect> getRectsSnapshot();
|
|
38
36
|
|
|
39
37
|
void setTickRate(double tickRate) { _tickRate.store(tickRate); };
|
|
40
38
|
|
package/shared/GameMethods.cpp
CHANGED
|
@@ -29,6 +29,8 @@ void GameMethods::setEntities(const std::vector<Entity> &entities) {
|
|
|
29
29
|
std::lock_guard<std::mutex> snapshotLock(instance.getSnapshotMutexInternal());
|
|
30
30
|
auto &entitiesInternal = instance.getEntitiesInternal();
|
|
31
31
|
auto &entitiesSnapshotInternal = instance.getEntitiesSnapshotInternal();
|
|
32
|
+
entitiesInternal.clear();
|
|
33
|
+
entitiesSnapshotInternal.clear();
|
|
32
34
|
for (auto &entity : entities) {
|
|
33
35
|
entitiesInternal[entity.id] = entity;
|
|
34
36
|
entitiesSnapshotInternal[entity.id] = entity;
|
package/src/GameAssets.nitro.ts
CHANGED
|
@@ -6,8 +6,8 @@ interface GameAssets extends HybridObject<{
|
|
|
6
6
|
android: 'kotlin';
|
|
7
7
|
}> {
|
|
8
8
|
isAssetRegistered(id: number): boolean;
|
|
9
|
-
registerSvg(id: number, uri: string): void
|
|
10
|
-
registerLottie(id: number, json: string): void
|
|
9
|
+
registerSvg(id: number, uri: string): Promise<void>;
|
|
10
|
+
registerLottie(id: number, json: string): Promise<void>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export const gameAssets =
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Image } from 'react-native';
|
|
2
|
+
import { gameAssets } from './GameAssets.nitro';
|
|
3
|
+
|
|
4
|
+
const assetCache = new WeakMap<object, number>();
|
|
5
|
+
let nextId = -1;
|
|
6
|
+
|
|
7
|
+
const loadAsset = async (asset: unknown) => {
|
|
8
|
+
switch (typeof asset) {
|
|
9
|
+
case 'object':
|
|
10
|
+
if (asset === null) {
|
|
11
|
+
throw new Error('loadAssets: asset cannot be null');
|
|
12
|
+
}
|
|
13
|
+
if (assetCache.has(asset)) {
|
|
14
|
+
return assetCache.get(asset)!;
|
|
15
|
+
}
|
|
16
|
+
const assetId = nextId--;
|
|
17
|
+
assetCache.set(asset, assetId);
|
|
18
|
+
await gameAssets.registerLottie(assetId, JSON.stringify(asset));
|
|
19
|
+
return assetId;
|
|
20
|
+
|
|
21
|
+
case 'number':
|
|
22
|
+
if (gameAssets.isAssetRegistered(asset)) {
|
|
23
|
+
return asset;
|
|
24
|
+
}
|
|
25
|
+
const assetUri = Image.resolveAssetSource(asset)?.uri;
|
|
26
|
+
if (!assetUri) {
|
|
27
|
+
throw new Error(`loadAssets: could not resolve asset URI for ${asset}`);
|
|
28
|
+
}
|
|
29
|
+
await gameAssets.registerSvg(asset, assetUri);
|
|
30
|
+
return asset;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
throw new Error(`loadAssets: unsupported asset type "${typeof asset}"`);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const loadAssets = async <T extends Record<string, unknown>>(
|
|
37
|
+
assets: T
|
|
38
|
+
): Promise<{ [K in keyof T]: number }> => {
|
|
39
|
+
const keys = Object.keys(assets) as (keyof T)[];
|
|
40
|
+
const result = {} as { [K in keyof T]: number };
|
|
41
|
+
|
|
42
|
+
for (const key of keys) {
|
|
43
|
+
result[key] = await loadAsset(assets[key]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
};
|
package/src/GameEngine.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getHostComponent } from 'react-native-nitro-modules';
|
|
2
|
-
|
|
2
|
+
import GameEngineConfig from '../nitrogen/generated/shared/json/GameEngineConfig.json';
|
|
3
3
|
import type { GameEngineMethods, GameEngineProps } from './GameEngine.nitro';
|
|
4
4
|
|
|
5
5
|
/**
|
package/src/GameMethods.ts
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
import { gameMethods } from './GameMethods.nitro';
|
|
2
|
+
import type { Entity, EntityUpdate, System } from './nativeTypes';
|
|
3
|
+
import type { Config } from './types';
|
|
4
|
+
|
|
5
|
+
/** Sets up the game engine with the given configuration. Call this before anything else. */
|
|
6
|
+
export const configure = ({
|
|
7
|
+
tickRate,
|
|
8
|
+
screen,
|
|
9
|
+
entities = [],
|
|
10
|
+
systems = [],
|
|
11
|
+
paused = true,
|
|
12
|
+
}: Config) => {
|
|
13
|
+
let nativeSystems: System[] = [];
|
|
14
|
+
|
|
15
|
+
for (const system of systems) {
|
|
16
|
+
nativeSystems.push({
|
|
17
|
+
entities: system.entities,
|
|
18
|
+
collisions: system.collisions,
|
|
19
|
+
onTick: (e, c) => {
|
|
20
|
+
const start = Date.now();
|
|
21
|
+
system.onTick(e, c);
|
|
22
|
+
const finish = Date.now();
|
|
23
|
+
return finish - start;
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
gameMethods.setTickRate(tickRate);
|
|
29
|
+
gameMethods.setScreen(screen);
|
|
30
|
+
gameMethods.setEntities(entities);
|
|
31
|
+
gameMethods.setSystems(nativeSystems);
|
|
32
|
+
if (paused) {
|
|
33
|
+
gameMethods.pause();
|
|
34
|
+
} else {
|
|
35
|
+
gameMethods.resume();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
|
|
3
39
|
/** Pauses the game loop. Systems will stop running. */
|
|
4
40
|
export const pause = () => gameMethods.pause();
|
|
@@ -6,5 +42,17 @@ export const pause = () => gameMethods.pause();
|
|
|
6
42
|
/** Resumes the game loop. */
|
|
7
43
|
export const resume = () => gameMethods.resume();
|
|
8
44
|
|
|
45
|
+
/** Spawns one or more entities into the world. Skips duplicates by id. */
|
|
46
|
+
export const spawn = (entities: Entity | Entity[]) => {
|
|
47
|
+
const entityArray = Array.isArray(entities) ? entities : [entities];
|
|
48
|
+
gameMethods.spawn(entityArray);
|
|
49
|
+
};
|
|
50
|
+
|
|
9
51
|
/** Removes an entity or all entities matching the given id prefix from the world. */
|
|
10
52
|
export const despawn = (id: string) => gameMethods.despawn(id);
|
|
53
|
+
|
|
54
|
+
/** Updates one or more entities. Only the provided fields are changed. */
|
|
55
|
+
export const update = (updates: EntityUpdate | EntityUpdate[]) => {
|
|
56
|
+
const entityUpdateArray = Array.isArray(updates) ? updates : [updates];
|
|
57
|
+
gameMethods.update(entityUpdateArray);
|
|
58
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import GameEngine from './GameEngine';
|
|
2
2
|
|
|
3
3
|
export * from './GameMethods';
|
|
4
|
-
export * from './
|
|
4
|
+
export * from './GameAssets';
|
|
5
5
|
export * from './types';
|
|
6
|
+
export type {
|
|
7
|
+
Screen,
|
|
8
|
+
Entity,
|
|
9
|
+
CollisionPair,
|
|
10
|
+
Collision,
|
|
11
|
+
EntityUpdate,
|
|
12
|
+
} from './nativeTypes';
|
|
6
13
|
export { GameEngine };
|
package/src/nativeTypes.ts
CHANGED
|
@@ -1,83 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
/** Width of the screen in game units. */
|
|
3
|
-
width: number;
|
|
4
|
-
/** Height of the screen in game units. */
|
|
5
|
-
height: number;
|
|
6
|
-
/** Background color of the screen as a hex string e.g. `'#1a1a1a'`. */
|
|
7
|
-
color?: string;
|
|
8
|
-
/** Asset to render, use `require` with the file path to get the id. */
|
|
9
|
-
asset?: number;
|
|
10
|
-
/** Animation progress between 0 and 1, automatically advanced each tick for Lottie assets. */
|
|
11
|
-
progress?: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type Entity = {
|
|
15
|
-
/** Unique identifier. Use `_` as a separator for group queries e.g. `'enemy_1'`. */
|
|
16
|
-
id: string;
|
|
1
|
+
interface Positioned {
|
|
17
2
|
/** X position in game units. */
|
|
18
3
|
px: number;
|
|
19
4
|
/** Y position in game units. */
|
|
20
5
|
py: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface Shaped {
|
|
21
9
|
/** Width in game units. */
|
|
22
10
|
width: number;
|
|
23
11
|
/** Height in game units. */
|
|
24
12
|
height: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface Renderable {
|
|
25
16
|
/** Fill color as a hex string e.g. `'#00ff00'`. */
|
|
26
17
|
color?: string;
|
|
27
18
|
/** Asset to render, use `require` with the file path to get the id. */
|
|
28
19
|
asset?: number;
|
|
29
20
|
/** Animation progress between 0 and 1, automatically advanced each tick for Lottie assets. */
|
|
30
21
|
progress?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Kinematic {
|
|
31
25
|
/** Velocity on the X axis in game units per second. */
|
|
32
26
|
vx?: number;
|
|
33
27
|
/** Velocity on the Y axis in game units per second. */
|
|
34
28
|
vy?: number;
|
|
35
|
-
}
|
|
29
|
+
}
|
|
36
30
|
|
|
37
|
-
export
|
|
31
|
+
export interface Screen extends Shaped, Renderable {}
|
|
32
|
+
|
|
33
|
+
export interface Entity extends Positioned, Shaped, Renderable, Kinematic {
|
|
34
|
+
/** Unique identifier. Use `_` as a separator for group queries e.g. `'enemy_1'`. */
|
|
35
|
+
id: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface EntityUpdate extends Partial<
|
|
39
|
+
Positioned & Shaped & Renderable & Kinematic
|
|
40
|
+
> {
|
|
41
|
+
/** Unique identifier or prefix of the entities to update. */
|
|
42
|
+
id: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface CollisionPair {
|
|
38
46
|
/** Entity id or prefix of the first entity to watch. */
|
|
39
47
|
a: string;
|
|
40
48
|
/** Entity id or prefix of the second entity to watch. */
|
|
41
49
|
b: string;
|
|
42
|
-
}
|
|
50
|
+
}
|
|
43
51
|
|
|
44
|
-
export
|
|
52
|
+
export interface Collision {
|
|
45
53
|
/** Id of the first entity involved in the collision. */
|
|
46
54
|
a: string;
|
|
47
55
|
/** Id of the second entity involved in the collision. */
|
|
48
56
|
b: string;
|
|
49
57
|
/** Penetration depth of the collision. */
|
|
50
58
|
depth: number;
|
|
51
|
-
}
|
|
59
|
+
}
|
|
52
60
|
|
|
53
|
-
export
|
|
61
|
+
export interface System {
|
|
54
62
|
/** Entity ids or prefixes this system subscribes to. */
|
|
55
63
|
entities?: string[];
|
|
56
64
|
/** Collision pairs to watch for every tick. */
|
|
57
65
|
collisions?: CollisionPair[];
|
|
58
66
|
/** Called every tick with the resolved entities and collisions. */
|
|
59
67
|
onTick: (entities: Entity[], collisions: Collision[]) => number;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type EntityUpdate = {
|
|
63
|
-
/** Unique identifier or prefix of the entities to update. */
|
|
64
|
-
id: string;
|
|
65
|
-
/** X position in game units. */
|
|
66
|
-
px?: number;
|
|
67
|
-
/** Y position in game units. */
|
|
68
|
-
py?: number;
|
|
69
|
-
/** Width in game units. */
|
|
70
|
-
width?: number;
|
|
71
|
-
/** Height in game units. */
|
|
72
|
-
height?: number;
|
|
73
|
-
/** Fill color as a hex string e.g. `'#00ff00'`. */
|
|
74
|
-
color?: string;
|
|
75
|
-
/** Asset to render, use `require` with the file path to get the id. */
|
|
76
|
-
asset?: number;
|
|
77
|
-
/** Animation progress between 0 and 1, automatically advanced each tick for Lottie assets. */
|
|
78
|
-
progress?: number;
|
|
79
|
-
/** Velocity on the X axis in game units per second. */
|
|
80
|
-
vx?: number;
|
|
81
|
-
/** Velocity on the Y axis in game units per second. */
|
|
82
|
-
vy?: number;
|
|
83
|
-
};
|
|
68
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,29 +1,13 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
Screen as NativeScreen,
|
|
3
|
-
Entity as NativeEntity,
|
|
4
|
-
EntityUpdate as NativeEntityUpdate,
|
|
5
2
|
System as NativeSystem,
|
|
6
3
|
Collision,
|
|
4
|
+
Screen,
|
|
5
|
+
Entity,
|
|
7
6
|
} from './nativeTypes';
|
|
8
7
|
|
|
9
|
-
export type Asset = number | object;
|
|
10
|
-
|
|
11
|
-
export type Screen = Omit<NativeScreen, 'asset'> & {
|
|
12
|
-
/** Asset to render, use `require` with the file path to get the id. */
|
|
13
|
-
asset?: Asset;
|
|
14
|
-
};
|
|
15
|
-
export type Entity = Omit<NativeEntity, 'asset'> & {
|
|
16
|
-
/** Asset to render, use `require` with the file path to get the id. */
|
|
17
|
-
asset?: Asset;
|
|
18
|
-
};
|
|
19
|
-
export type EntityUpdate = Omit<NativeEntityUpdate, 'asset'> & {
|
|
20
|
-
/** Asset to render, use `require` with the file path to get the id. */
|
|
21
|
-
asset?: Asset;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
8
|
export type System = Omit<NativeSystem, 'onTick'> & {
|
|
25
9
|
/** Called every tick with the resolved entities and collisions. */
|
|
26
|
-
onTick: (entities:
|
|
10
|
+
onTick: (entities: Entity[], collisions: Collision[]) => void;
|
|
27
11
|
};
|
|
28
12
|
|
|
29
13
|
export type Config = {
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
package com.margelo.nitro.rngine
|
|
2
|
-
|
|
3
|
-
import java.nio.ByteBuffer
|
|
4
|
-
import java.nio.ByteOrder
|
|
5
|
-
|
|
6
|
-
object RectSerializer {
|
|
7
|
-
private const val RECT_SIZE = 4 * 5 + 4 * 2
|
|
8
|
-
fun decode(buffer: ByteBuffer): ArrayList<Rect> {
|
|
9
|
-
buffer.order(ByteOrder.nativeOrder())
|
|
10
|
-
val rects = ArrayList<Rect>()
|
|
11
|
-
|
|
12
|
-
while (buffer.remaining() >= RECT_SIZE) {
|
|
13
|
-
val left = buffer.float
|
|
14
|
-
val right = buffer.float
|
|
15
|
-
val top = buffer.float
|
|
16
|
-
val bottom = buffer.float
|
|
17
|
-
val progress = buffer.float
|
|
18
|
-
val color = buffer.int
|
|
19
|
-
val asset = buffer.int
|
|
20
|
-
|
|
21
|
-
rects.add(Rect(left, right, top, bottom, progress, color, asset))
|
|
22
|
-
}
|
|
23
|
-
return rects
|
|
24
|
-
}
|
|
25
|
-
}
|
package/lib/module/Shared.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { Image } from 'react-native';
|
|
4
|
-
import { gameAssets } from "./GameAssets.nitro.js";
|
|
5
|
-
import { gameMethods } from "./GameMethods.nitro.js";
|
|
6
|
-
const assetCache = new WeakMap();
|
|
7
|
-
let nextId = -1;
|
|
8
|
-
const registerAssetIfNotExist = asset => {
|
|
9
|
-
switch (typeof asset) {
|
|
10
|
-
case 'object':
|
|
11
|
-
if (assetCache.has(asset)) {
|
|
12
|
-
return assetCache.get(asset);
|
|
13
|
-
}
|
|
14
|
-
const assetId = nextId--;
|
|
15
|
-
assetCache.set(asset, assetId);
|
|
16
|
-
gameAssets.registerLottie(assetId, JSON.stringify(asset));
|
|
17
|
-
return assetId;
|
|
18
|
-
case 'number':
|
|
19
|
-
if (gameAssets.isAssetRegistered(asset)) {
|
|
20
|
-
return asset;
|
|
21
|
-
}
|
|
22
|
-
const assetUri = Image.resolveAssetSource(asset)?.uri;
|
|
23
|
-
if (!assetUri) {
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
gameAssets.registerSvg(asset, assetUri);
|
|
27
|
-
return asset;
|
|
28
|
-
}
|
|
29
|
-
return;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/** Sets up the game engine with the given configuration. Call this before anything else. */
|
|
33
|
-
export const configure = ({
|
|
34
|
-
tickRate,
|
|
35
|
-
screen,
|
|
36
|
-
entities = [],
|
|
37
|
-
systems = [],
|
|
38
|
-
paused = true
|
|
39
|
-
}) => {
|
|
40
|
-
screen.asset = registerAssetIfNotExist(screen.asset);
|
|
41
|
-
for (const entity of entities) {
|
|
42
|
-
entity.asset = registerAssetIfNotExist(entity.asset);
|
|
43
|
-
}
|
|
44
|
-
let nativeSystems = [];
|
|
45
|
-
for (const system of systems) {
|
|
46
|
-
nativeSystems.push({
|
|
47
|
-
entities: system.entities,
|
|
48
|
-
collisions: system.collisions,
|
|
49
|
-
onTick: (e, c) => {
|
|
50
|
-
const start = Date.now();
|
|
51
|
-
system.onTick(e, c);
|
|
52
|
-
const finish = Date.now();
|
|
53
|
-
return finish - start;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
gameMethods.setTickRate(tickRate);
|
|
58
|
-
gameMethods.setScreen(screen);
|
|
59
|
-
gameMethods.setEntities(entities);
|
|
60
|
-
gameMethods.setSystems(nativeSystems);
|
|
61
|
-
if (paused) {
|
|
62
|
-
gameMethods.pause();
|
|
63
|
-
} else {
|
|
64
|
-
gameMethods.resume();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/** Spawns one or more entities into the world. Skips duplicates by id. */
|
|
69
|
-
export const spawn = entities => {
|
|
70
|
-
const entityArray = Array.isArray(entities) ? entities : [entities];
|
|
71
|
-
for (const entity of entityArray) {
|
|
72
|
-
entity.asset = registerAssetIfNotExist(entity.asset);
|
|
73
|
-
}
|
|
74
|
-
gameMethods.spawn(entityArray);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/** Updates one or more entities. Only the provided fields are changed. */
|
|
78
|
-
export const update = updates => {
|
|
79
|
-
const entityUpdateArray = Array.isArray(updates) ? updates : [updates];
|
|
80
|
-
for (const entityUpdate of entityUpdateArray) {
|
|
81
|
-
entityUpdate.asset = registerAssetIfNotExist(entityUpdate.asset);
|
|
82
|
-
}
|
|
83
|
-
gameMethods.update(entityUpdateArray);
|
|
84
|
-
};
|
|
85
|
-
//# sourceMappingURL=Shared.js.map
|
package/lib/module/Shared.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Image","gameAssets","gameMethods","assetCache","WeakMap","nextId","registerAssetIfNotExist","asset","has","get","assetId","set","registerLottie","JSON","stringify","isAssetRegistered","assetUri","resolveAssetSource","uri","registerSvg","configure","tickRate","screen","entities","systems","paused","entity","nativeSystems","system","push","collisions","onTick","e","c","start","Date","now","finish","setTickRate","setScreen","setEntities","setSystems","pause","resume","spawn","entityArray","Array","isArray","update","updates","entityUpdateArray","entityUpdate"],"sourceRoot":"../../src","sources":["Shared.ts"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Config, Entity, EntityUpdate } from './types';
|
|
2
|
-
/** Sets up the game engine with the given configuration. Call this before anything else. */
|
|
3
|
-
export declare const configure: ({ tickRate, screen, entities, systems, paused, }: Config) => void;
|
|
4
|
-
/** Spawns one or more entities into the world. Skips duplicates by id. */
|
|
5
|
-
export declare const spawn: (entities: Entity | Entity[]) => void;
|
|
6
|
-
/** Updates one or more entities. Only the provided fields are changed. */
|
|
7
|
-
export declare const update: (updates: EntityUpdate | EntityUpdate[]) => void;
|
|
8
|
-
//# sourceMappingURL=Shared.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Shared.d.ts","sourceRoot":"","sources":["../../../src/Shared.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAS,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA8BnE,4FAA4F;AAC5F,eAAO,MAAM,SAAS,GAAI,kDAMvB,MAAM,SA8BR,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,KAAK,GAAI,UAAU,MAAM,GAAG,MAAM,EAAE,SAQhD,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,MAAM,GAAI,SAAS,YAAY,GAAG,YAAY,EAAE,SAQ5D,CAAC"}
|
package/shared/Rect.hpp
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
namespace margelo::nitro::rngine {
|
|
4
|
-
static constexpr int RECT_SIZE =
|
|
5
|
-
sizeof(float) * 5 + sizeof(uint32_t) + sizeof(int32_t);
|
|
6
|
-
|
|
7
|
-
struct Rect {
|
|
8
|
-
float left;
|
|
9
|
-
float right;
|
|
10
|
-
float top;
|
|
11
|
-
float bottom;
|
|
12
|
-
float progress;
|
|
13
|
-
uint32_t color;
|
|
14
|
-
int32_t asset;
|
|
15
|
-
};
|
|
16
|
-
} // namespace margelo::nitro::rngine
|
package/src/Shared.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Image } from 'react-native';
|
|
2
|
-
import { gameAssets } from './GameAssets.nitro';
|
|
3
|
-
import { gameMethods } from './GameMethods.nitro';
|
|
4
|
-
import type {
|
|
5
|
-
Screen as NativeScreen,
|
|
6
|
-
Entity as NativeEntity,
|
|
7
|
-
EntityUpdate as NativeEntityUpdate,
|
|
8
|
-
System as NativeSystem,
|
|
9
|
-
} from './nativeTypes';
|
|
10
|
-
import type { Asset, Config, Entity, EntityUpdate } from './types';
|
|
11
|
-
|
|
12
|
-
const assetCache = new WeakMap<object, number>();
|
|
13
|
-
let nextId = -1;
|
|
14
|
-
|
|
15
|
-
const registerAssetIfNotExist = (asset?: Asset) => {
|
|
16
|
-
switch (typeof asset) {
|
|
17
|
-
case 'object':
|
|
18
|
-
if (assetCache.has(asset)) {
|
|
19
|
-
return assetCache.get(asset);
|
|
20
|
-
}
|
|
21
|
-
const assetId = nextId--;
|
|
22
|
-
assetCache.set(asset, assetId);
|
|
23
|
-
gameAssets.registerLottie(assetId, JSON.stringify(asset));
|
|
24
|
-
return assetId;
|
|
25
|
-
|
|
26
|
-
case 'number':
|
|
27
|
-
if (gameAssets.isAssetRegistered(asset)) {
|
|
28
|
-
return asset;
|
|
29
|
-
}
|
|
30
|
-
const assetUri = Image.resolveAssetSource(asset)?.uri;
|
|
31
|
-
if (!assetUri) {
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
gameAssets.registerSvg(asset, assetUri);
|
|
35
|
-
return asset;
|
|
36
|
-
}
|
|
37
|
-
return;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/** Sets up the game engine with the given configuration. Call this before anything else. */
|
|
41
|
-
export const configure = ({
|
|
42
|
-
tickRate,
|
|
43
|
-
screen,
|
|
44
|
-
entities = [],
|
|
45
|
-
systems = [],
|
|
46
|
-
paused = true,
|
|
47
|
-
}: Config) => {
|
|
48
|
-
screen.asset = registerAssetIfNotExist(screen.asset);
|
|
49
|
-
for (const entity of entities) {
|
|
50
|
-
entity.asset = registerAssetIfNotExist(entity.asset);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let nativeSystems: NativeSystem[] = [];
|
|
54
|
-
|
|
55
|
-
for (const system of systems) {
|
|
56
|
-
nativeSystems.push({
|
|
57
|
-
entities: system.entities,
|
|
58
|
-
collisions: system.collisions,
|
|
59
|
-
onTick: (e, c) => {
|
|
60
|
-
const start = Date.now();
|
|
61
|
-
system.onTick(e, c);
|
|
62
|
-
const finish = Date.now();
|
|
63
|
-
return finish - start;
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
gameMethods.setTickRate(tickRate);
|
|
69
|
-
gameMethods.setScreen(screen as NativeScreen);
|
|
70
|
-
gameMethods.setEntities(entities as NativeEntity[]);
|
|
71
|
-
gameMethods.setSystems(nativeSystems);
|
|
72
|
-
if (paused) {
|
|
73
|
-
gameMethods.pause();
|
|
74
|
-
} else {
|
|
75
|
-
gameMethods.resume();
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/** Spawns one or more entities into the world. Skips duplicates by id. */
|
|
80
|
-
export const spawn = (entities: Entity | Entity[]) => {
|
|
81
|
-
const entityArray = Array.isArray(entities) ? entities : [entities];
|
|
82
|
-
|
|
83
|
-
for (const entity of entityArray) {
|
|
84
|
-
entity.asset = registerAssetIfNotExist(entity.asset);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
gameMethods.spawn(entityArray as NativeEntity[]);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/** Updates one or more entities. Only the provided fields are changed. */
|
|
91
|
-
export const update = (updates: EntityUpdate | EntityUpdate[]) => {
|
|
92
|
-
const entityUpdateArray = Array.isArray(updates) ? updates : [updates];
|
|
93
|
-
|
|
94
|
-
for (const entityUpdate of entityUpdateArray) {
|
|
95
|
-
entityUpdate.asset = registerAssetIfNotExist(entityUpdate.asset);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
gameMethods.update(entityUpdateArray as NativeEntityUpdate[]);
|
|
99
|
-
};
|
|
File without changes
|