rngine 0.11.6 → 0.12.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/module/GameMethods.js.map +1 -1
- package/lib/typescript/src/GameMethods.d.ts +2 -2
- package/lib/typescript/src/GameMethods.d.ts.map +1 -1
- package/lib/typescript/src/GameMethods.nitro.d.ts +5 -5
- package/lib/typescript/src/GameMethods.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +19 -8
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/nitrogen/generated/shared/c++/{Entity.hpp → EntityInitializer.hpp} +16 -12
- package/nitrogen/generated/shared/c++/EntityUpdate.hpp +6 -2
- package/nitrogen/generated/shared/c++/HybridGameMethodsSpec.hpp +13 -13
- package/nitrogen/generated/shared/c++/{Screen.hpp → ScreenInitializer.hpp} +11 -11
- package/nitrogen/generated/shared/c++/{World.hpp → WorldInitializer.hpp} +11 -11
- package/package.json +1 -1
- package/shared/GameLoop.cpp +19 -36
- package/shared/GameMethods.cpp +104 -19
- package/shared/GameMethods.hpp +9 -5
- package/shared/GameRenderer.cpp +20 -28
- package/shared/custom/Entity.hpp +307 -0
- package/shared/custom/Screen.hpp +217 -0
- package/shared/custom/World.hpp +98 -0
- package/shared/utils/AssetUtils.cpp +7 -10
- package/shared/utils/AssetUtils.hpp +2 -4
- package/shared/utils/CollisionUtils.cpp +2 -3
- package/src/GameMethods.nitro.ts +7 -7
- package/src/GameMethods.ts +2 -2
- package/src/types.ts +29 -8
|
@@ -1 +1 @@
|
|
|
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","result","key"],"sourceRoot":"../../src","sources":["GameMethods.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,wBAAqB;AAGjD,SAASC,KAAK,QAAQ,cAAc;;AAEpC;AACA,OAAO,MAAMC,SAAS,GAAGA,CAAC;EACxBC,KAAK;EACLC,MAAM;EACNC,QAAQ,GAAG,EAAE;EACbC,OAAO,GAAG,EAAE;EACZC,MAAM,GAAG;AACH,CAAC,KAAK;EACZP,WAAW,CAACQ,QAAQ,CAACL,KAAK,CAAC;EAC3BH,WAAW,CAACS,SAAS,CAACL,MAAM,CAAC;EAC7BJ,WAAW,CAACU,WAAW,CAACL,QAAQ,CAAC;EACjCL,WAAW,CAACW,UAAU,CAACL,OAAO,CAAC;EAC/B,IAAIC,MAAM,EAAE;IACVP,WAAW,CAACY,KAAK,CAAC,CAAC;EACrB,CAAC,MAAM;IACLZ,WAAW,CAACa,MAAM,CAAC,CAAC;EACtB;AACF,CAAC;;AAED;AACA,OAAO,MAAMD,KAAK,GAAGA,CAAA,KAAMZ,WAAW,CAACY,KAAK,CAAC,CAAC;;AAE9C;AACA,OAAO,MAAMC,MAAM,GAAGA,CAAA,KAAMb,WAAW,CAACa,MAAM,CAAC,CAAC;;AAEhD;AACA,OAAO,MAAMC,KAAK,GAAIT,
|
|
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","result","key"],"sourceRoot":"../../src","sources":["GameMethods.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,wBAAqB;AAGjD,SAASC,KAAK,QAAQ,cAAc;;AAEpC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C,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,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EntityInitializer, 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;
|
|
@@ -7,7 +7,7 @@ export declare const pause: () => void;
|
|
|
7
7
|
/** Resumes the game loop. */
|
|
8
8
|
export declare const resume: () => void;
|
|
9
9
|
/** Spawns one or more entities into the world. Skips duplicates by id. */
|
|
10
|
-
export declare const spawn: (entities:
|
|
10
|
+
export declare const spawn: (entities: EntityInitializer | EntityInitializer[]) => void;
|
|
11
11
|
/** Removes an entity or all entities matching the given id prefix from the world. Only the provided fields are changed. */
|
|
12
12
|
export declare const despawn: (id: string) => void;
|
|
13
13
|
/** Fires one update, applied to entities matching the given id prefix from the world. Only the provided fields are changed. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GameMethods.d.ts","sourceRoot":"","sources":["../../../src/GameMethods.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"GameMethods.d.ts","sourceRoot":"","sources":["../../../src/GameMethods.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAS,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAS,CAAC;AAGtC,4FAA4F;AAC5F,eAAO,MAAM,SAAS,GAAI,+CAMvB,MAAM,SAUR,CAAC;AAEF,uDAAuD;AACvD,eAAO,MAAM,KAAK,YAA4B,CAAC;AAE/C,6BAA6B;AAC7B,eAAO,MAAM,MAAM,YAA6B,CAAC;AAEjD,0EAA0E;AAC1E,eAAO,MAAM,KAAK,GAAI,UAAU,iBAAiB,GAAG,iBAAiB,EAAE,SAGtE,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,19 +1,19 @@
|
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EntityUpdate, System, ScreenUpdate, WorldInitializer, ScreenInitializer, EntityInitializer } from './types.js';
|
|
3
3
|
interface GameMethods extends HybridObject<{
|
|
4
4
|
ios: 'c++';
|
|
5
5
|
android: 'c++';
|
|
6
6
|
}> {
|
|
7
7
|
/** Configuration Methods */
|
|
8
|
-
setWorld(world:
|
|
9
|
-
setScreen(screen:
|
|
10
|
-
setEntities(entities:
|
|
8
|
+
setWorld(world: WorldInitializer): void;
|
|
9
|
+
setScreen(screen: ScreenInitializer): void;
|
|
10
|
+
setEntities(entities: EntityInitializer[]): void;
|
|
11
11
|
setSystems(systems: System[]): void;
|
|
12
12
|
/** Pause/Resume Methods */
|
|
13
13
|
pause(): void;
|
|
14
14
|
resume(): void;
|
|
15
15
|
/** Entity Update Methods */
|
|
16
|
-
spawn(entities:
|
|
16
|
+
spawn(entities: EntityInitializer[]): void;
|
|
17
17
|
despawn(id: string): void;
|
|
18
18
|
updateEntities(entityUpdates: EntityUpdate[]): void;
|
|
19
19
|
/** Screen Update Methods */
|
|
@@ -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,
|
|
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,YAAY,EACZ,MAAM,EACN,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,YAAS,CAAC;AAGjB,UAAU,WAAY,SAAQ,YAAY,CAAC;IACzC,GAAG,EAAE,KAAK,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;IACA,4BAA4B;IAC5B,QAAQ,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACxC,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC3C,WAAW,CAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;IACjD,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,iBAAiB,EAAE,GAAG,IAAI,CAAC;IAC3C,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"}
|
|
@@ -58,8 +58,10 @@ interface Kinematic {
|
|
|
58
58
|
ay?: number;
|
|
59
59
|
/** Mass in arbitrary units. */
|
|
60
60
|
mass?: number;
|
|
61
|
+
/** Coefficient of restitution (bounciness) from 0.0 to 1.0. Defaults to 0.0. */
|
|
62
|
+
restitution?: number;
|
|
61
63
|
}
|
|
62
|
-
export interface
|
|
64
|
+
export interface WorldInitializer {
|
|
63
65
|
/** Number of game logic updates per second. */
|
|
64
66
|
tickRate: number;
|
|
65
67
|
/** Horizontal gravitational acceleration in game units per second squared. */
|
|
@@ -67,18 +69,27 @@ export interface World {
|
|
|
67
69
|
/** Vertical gravitational acceleration in game units per second squared. */
|
|
68
70
|
gy?: number;
|
|
69
71
|
}
|
|
70
|
-
export
|
|
72
|
+
export type World = CustomType<Required<WorldInitializer>, 'margelo::nitro::rngine::World', {
|
|
73
|
+
include: 'World.hpp';
|
|
74
|
+
}>;
|
|
75
|
+
export interface ScreenInitializer extends Positioned, Rect, Renderable {
|
|
76
|
+
}
|
|
77
|
+
export type Screen = CustomType<Required<ScreenInitializer>, 'margelo::nitro::rngine::Screen', {
|
|
78
|
+
include: 'Screen.hpp';
|
|
79
|
+
}>;
|
|
80
|
+
export interface ScreenUpdate extends Partial<ScreenInitializer> {
|
|
71
81
|
}
|
|
72
|
-
export interface
|
|
82
|
+
export interface EntityInitializer extends Positioned, Shaped, Renderable, Kinematic {
|
|
73
83
|
/** Unique identifier. Use `_` as a separator for group queries e.g. `'enemy_1'`. */
|
|
74
84
|
id: string;
|
|
75
85
|
}
|
|
86
|
+
export type Entity = CustomType<Required<EntityInitializer>, 'margelo::nitro::rngine::Entity', {
|
|
87
|
+
include: 'Entity.hpp';
|
|
88
|
+
}>;
|
|
76
89
|
export interface EntityUpdate extends Partial<Positioned & Shaped & Renderable & Kinematic> {
|
|
77
90
|
/** Unique identifier or prefix of the entities to update. */
|
|
78
91
|
id: string;
|
|
79
92
|
}
|
|
80
|
-
export interface ScreenUpdate extends Partial<Screen> {
|
|
81
|
-
}
|
|
82
93
|
export type CollisionPair = CustomType<{
|
|
83
94
|
/** Entity id or prefix of the first entity to watch. */
|
|
84
95
|
a: string;
|
|
@@ -129,11 +140,11 @@ export type System = CustomType<{
|
|
|
129
140
|
}>;
|
|
130
141
|
export type Config = {
|
|
131
142
|
/** World settings: tick rate and gravity. */
|
|
132
|
-
world:
|
|
143
|
+
world: WorldInitializer;
|
|
133
144
|
/** Screen dimensions and background. */
|
|
134
|
-
screen:
|
|
145
|
+
screen: ScreenInitializer;
|
|
135
146
|
/** Entities to spawn when the game starts. */
|
|
136
|
-
entities?:
|
|
147
|
+
entities?: EntityInitializer[];
|
|
137
148
|
/** Systems that define game logic, each running every tick against its subscribed entities and collisions. */
|
|
138
149
|
systems?: System[];
|
|
139
150
|
/** Whether the game starts paused. Defaults to true. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/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E,CAAC;CAC1B,EACD,uCAAuC,EACvC;IAAE,OAAO,EAAE,mBAAmB,CAAA;CAAE,CACjC,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,UAAU,CAC7B;IACE,gEAAgE;IAChE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iEAAiE;IACjE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,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,aAAa,EAAE,aAAa,KAAK,IAAI,CAAC;CAChD,EACD,gCAAgC,EAChC;IAAE,OAAO,EAAE,YAAY,CAAA;CAAE,CAC1B,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,6CAA6C;IAC7C,KAAK,EAAE,gBAAgB,CAAC;IACxB,wCAAwC;IACxC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC/B,8GAA8G;IAC9G,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,wDAAwD;IACxD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// EntityInitializer.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © Marc Rousavy @ Margelo
|
|
@@ -48,9 +48,9 @@ namespace margelo::nitro::rngine { enum class Repeat; }
|
|
|
48
48
|
namespace margelo::nitro::rngine {
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* A struct which can be represented as a JavaScript object (
|
|
51
|
+
* A struct which can be represented as a JavaScript object (EntityInitializer).
|
|
52
52
|
*/
|
|
53
|
-
struct
|
|
53
|
+
struct EntityInitializer final {
|
|
54
54
|
public:
|
|
55
55
|
std::string id SWIFT_PRIVATE;
|
|
56
56
|
double px SWIFT_PRIVATE;
|
|
@@ -73,25 +73,26 @@ namespace margelo::nitro::rngine {
|
|
|
73
73
|
std::optional<double> ax SWIFT_PRIVATE;
|
|
74
74
|
std::optional<double> ay SWIFT_PRIVATE;
|
|
75
75
|
std::optional<double> mass SWIFT_PRIVATE;
|
|
76
|
+
std::optional<double> restitution SWIFT_PRIVATE;
|
|
76
77
|
|
|
77
78
|
public:
|
|
78
|
-
|
|
79
|
-
explicit
|
|
79
|
+
EntityInitializer() = default;
|
|
80
|
+
explicit EntityInitializer(std::string id, double px, double py, std::variant<Rect, Circle> shape, std::optional<double> angle, std::optional<bool> isSensor, std::optional<std::string> color, std::optional<double> asset, std::optional<bool> flipH, std::optional<bool> flipV, std::optional<ObjectFit> objectFit, std::optional<bool> clip, std::optional<Repeat> repeat, std::optional<double> progress, std::optional<double> speed, std::optional<bool> loop, std::optional<double> vx, std::optional<double> vy, std::optional<double> ax, std::optional<double> ay, std::optional<double> mass, std::optional<double> restitution): id(id), px(px), py(py), shape(shape), angle(angle), isSensor(isSensor), color(color), asset(asset), flipH(flipH), flipV(flipV), objectFit(objectFit), clip(clip), repeat(repeat), progress(progress), speed(speed), loop(loop), vx(vx), vy(vy), ax(ax), ay(ay), mass(mass), restitution(restitution) {}
|
|
80
81
|
|
|
81
82
|
public:
|
|
82
|
-
friend bool operator==(const
|
|
83
|
+
friend bool operator==(const EntityInitializer& lhs, const EntityInitializer& rhs) = default;
|
|
83
84
|
};
|
|
84
85
|
|
|
85
86
|
} // namespace margelo::nitro::rngine
|
|
86
87
|
|
|
87
88
|
namespace margelo::nitro {
|
|
88
89
|
|
|
89
|
-
// C++
|
|
90
|
+
// C++ EntityInitializer <> JS EntityInitializer (object)
|
|
90
91
|
template <>
|
|
91
|
-
struct JSIConverter<margelo::nitro::rngine::
|
|
92
|
-
static inline margelo::nitro::rngine::
|
|
92
|
+
struct JSIConverter<margelo::nitro::rngine::EntityInitializer> final {
|
|
93
|
+
static inline margelo::nitro::rngine::EntityInitializer fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
93
94
|
jsi::Object obj = arg.asObject(runtime);
|
|
94
|
-
return margelo::nitro::rngine::
|
|
95
|
+
return margelo::nitro::rngine::EntityInitializer(
|
|
95
96
|
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id"))),
|
|
96
97
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "px"))),
|
|
97
98
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "py"))),
|
|
@@ -112,10 +113,11 @@ namespace margelo::nitro {
|
|
|
112
113
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy"))),
|
|
113
114
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax"))),
|
|
114
115
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ay"))),
|
|
115
|
-
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mass")))
|
|
116
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mass"))),
|
|
117
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "restitution")))
|
|
116
118
|
);
|
|
117
119
|
}
|
|
118
|
-
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::
|
|
120
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::EntityInitializer& arg) {
|
|
119
121
|
jsi::Object obj(runtime);
|
|
120
122
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "id"), JSIConverter<std::string>::toJSI(runtime, arg.id));
|
|
121
123
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "px"), JSIConverter<double>::toJSI(runtime, arg.px));
|
|
@@ -138,6 +140,7 @@ namespace margelo::nitro {
|
|
|
138
140
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ax"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.ax));
|
|
139
141
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ay"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.ay));
|
|
140
142
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "mass"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.mass));
|
|
143
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "restitution"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.restitution));
|
|
141
144
|
return obj;
|
|
142
145
|
}
|
|
143
146
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -169,6 +172,7 @@ namespace margelo::nitro {
|
|
|
169
172
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax")))) return false;
|
|
170
173
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ay")))) return false;
|
|
171
174
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mass")))) return false;
|
|
175
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "restitution")))) return false;
|
|
172
176
|
return true;
|
|
173
177
|
}
|
|
174
178
|
};
|
|
@@ -73,10 +73,11 @@ namespace margelo::nitro::rngine {
|
|
|
73
73
|
std::optional<double> ax SWIFT_PRIVATE;
|
|
74
74
|
std::optional<double> ay SWIFT_PRIVATE;
|
|
75
75
|
std::optional<double> mass SWIFT_PRIVATE;
|
|
76
|
+
std::optional<double> restitution SWIFT_PRIVATE;
|
|
76
77
|
|
|
77
78
|
public:
|
|
78
79
|
EntityUpdate() = default;
|
|
79
|
-
explicit EntityUpdate(std::string id, std::optional<double> px, std::optional<double> py, std::optional<std::variant<Rect, Circle>> shape, std::optional<double> angle, std::optional<bool> isSensor, std::optional<std::string> color, std::optional<double> asset, std::optional<bool> flipH, std::optional<bool> flipV, std::optional<ObjectFit> objectFit, std::optional<bool> clip, std::optional<Repeat> repeat, std::optional<double> progress, std::optional<double> speed, std::optional<bool> loop, std::optional<double> vx, std::optional<double> vy, std::optional<double> ax, std::optional<double> ay, std::optional<double> mass): id(id), px(px), py(py), shape(shape), angle(angle), isSensor(isSensor), color(color), asset(asset), flipH(flipH), flipV(flipV), objectFit(objectFit), clip(clip), repeat(repeat), progress(progress), speed(speed), loop(loop), vx(vx), vy(vy), ax(ax), ay(ay), mass(mass) {}
|
|
80
|
+
explicit EntityUpdate(std::string id, std::optional<double> px, std::optional<double> py, std::optional<std::variant<Rect, Circle>> shape, std::optional<double> angle, std::optional<bool> isSensor, std::optional<std::string> color, std::optional<double> asset, std::optional<bool> flipH, std::optional<bool> flipV, std::optional<ObjectFit> objectFit, std::optional<bool> clip, std::optional<Repeat> repeat, std::optional<double> progress, std::optional<double> speed, std::optional<bool> loop, std::optional<double> vx, std::optional<double> vy, std::optional<double> ax, std::optional<double> ay, std::optional<double> mass, std::optional<double> restitution): id(id), px(px), py(py), shape(shape), angle(angle), isSensor(isSensor), color(color), asset(asset), flipH(flipH), flipV(flipV), objectFit(objectFit), clip(clip), repeat(repeat), progress(progress), speed(speed), loop(loop), vx(vx), vy(vy), ax(ax), ay(ay), mass(mass), restitution(restitution) {}
|
|
80
81
|
|
|
81
82
|
public:
|
|
82
83
|
friend bool operator==(const EntityUpdate& lhs, const EntityUpdate& rhs) = default;
|
|
@@ -112,7 +113,8 @@ namespace margelo::nitro {
|
|
|
112
113
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "vy"))),
|
|
113
114
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax"))),
|
|
114
115
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ay"))),
|
|
115
|
-
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mass")))
|
|
116
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mass"))),
|
|
117
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "restitution")))
|
|
116
118
|
);
|
|
117
119
|
}
|
|
118
120
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::EntityUpdate& arg) {
|
|
@@ -138,6 +140,7 @@ namespace margelo::nitro {
|
|
|
138
140
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ax"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.ax));
|
|
139
141
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "ay"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.ay));
|
|
140
142
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "mass"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.mass));
|
|
143
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "restitution"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.restitution));
|
|
141
144
|
return obj;
|
|
142
145
|
}
|
|
143
146
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -169,6 +172,7 @@ namespace margelo::nitro {
|
|
|
169
172
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ax")))) return false;
|
|
170
173
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ay")))) return false;
|
|
171
174
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mass")))) return false;
|
|
175
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "restitution")))) return false;
|
|
172
176
|
return true;
|
|
173
177
|
}
|
|
174
178
|
};
|
|
@@ -13,20 +13,20 @@
|
|
|
13
13
|
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
|
-
// Forward declaration of `
|
|
17
|
-
namespace margelo::nitro::rngine { struct
|
|
18
|
-
// Forward declaration of `
|
|
19
|
-
namespace margelo::nitro::rngine { struct
|
|
20
|
-
// Forward declaration of `
|
|
21
|
-
namespace margelo::nitro::rngine { struct
|
|
16
|
+
// Forward declaration of `WorldInitializer` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::rngine { struct WorldInitializer; }
|
|
18
|
+
// Forward declaration of `ScreenInitializer` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::rngine { struct ScreenInitializer; }
|
|
20
|
+
// Forward declaration of `EntityInitializer` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::rngine { struct EntityInitializer; }
|
|
22
22
|
// Forward declaration of `EntityUpdate` to properly resolve imports.
|
|
23
23
|
namespace margelo::nitro::rngine { struct EntityUpdate; }
|
|
24
24
|
// Forward declaration of `ScreenUpdate` to properly resolve imports.
|
|
25
25
|
namespace margelo::nitro::rngine { struct ScreenUpdate; }
|
|
26
26
|
|
|
27
|
-
#include "
|
|
28
|
-
#include "
|
|
29
|
-
#include "
|
|
27
|
+
#include "WorldInitializer.hpp"
|
|
28
|
+
#include "ScreenInitializer.hpp"
|
|
29
|
+
#include "EntityInitializer.hpp"
|
|
30
30
|
#include <vector>
|
|
31
31
|
#include "System.hpp"
|
|
32
32
|
#include <string>
|
|
@@ -65,13 +65,13 @@ namespace margelo::nitro::rngine {
|
|
|
65
65
|
|
|
66
66
|
public:
|
|
67
67
|
// Methods
|
|
68
|
-
virtual void setWorld(const
|
|
69
|
-
virtual void setScreen(const
|
|
70
|
-
virtual void setEntities(const std::vector<
|
|
68
|
+
virtual void setWorld(const WorldInitializer& world) = 0;
|
|
69
|
+
virtual void setScreen(const ScreenInitializer& screen) = 0;
|
|
70
|
+
virtual void setEntities(const std::vector<EntityInitializer>& entities) = 0;
|
|
71
71
|
virtual void setSystems(const std::vector<margelo::nitro::rngine::System>& systems) = 0;
|
|
72
72
|
virtual void pause() = 0;
|
|
73
73
|
virtual void resume() = 0;
|
|
74
|
-
virtual void spawn(const std::vector<
|
|
74
|
+
virtual void spawn(const std::vector<EntityInitializer>& entities) = 0;
|
|
75
75
|
virtual void despawn(const std::string& id) = 0;
|
|
76
76
|
virtual void updateEntities(const std::vector<EntityUpdate>& entityUpdates) = 0;
|
|
77
77
|
virtual void updateScreen(const ScreenUpdate& screenUpdate) = 0;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// ScreenInitializer.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © Marc Rousavy @ Margelo
|
|
@@ -41,9 +41,9 @@ namespace margelo::nitro::rngine { enum class Repeat; }
|
|
|
41
41
|
namespace margelo::nitro::rngine {
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* A struct which can be represented as a JavaScript object (
|
|
44
|
+
* A struct which can be represented as a JavaScript object (ScreenInitializer).
|
|
45
45
|
*/
|
|
46
|
-
struct
|
|
46
|
+
struct ScreenInitializer final {
|
|
47
47
|
public:
|
|
48
48
|
double px SWIFT_PRIVATE;
|
|
49
49
|
double py SWIFT_PRIVATE;
|
|
@@ -61,23 +61,23 @@ namespace margelo::nitro::rngine {
|
|
|
61
61
|
std::optional<bool> loop SWIFT_PRIVATE;
|
|
62
62
|
|
|
63
63
|
public:
|
|
64
|
-
|
|
65
|
-
explicit
|
|
64
|
+
ScreenInitializer() = default;
|
|
65
|
+
explicit ScreenInitializer(double px, double py, double width, double height, std::optional<std::string> color, std::optional<double> asset, std::optional<bool> flipH, std::optional<bool> flipV, std::optional<ObjectFit> objectFit, std::optional<bool> clip, std::optional<Repeat> repeat, std::optional<double> progress, std::optional<double> speed, std::optional<bool> loop): px(px), py(py), width(width), height(height), color(color), asset(asset), flipH(flipH), flipV(flipV), objectFit(objectFit), clip(clip), repeat(repeat), progress(progress), speed(speed), loop(loop) {}
|
|
66
66
|
|
|
67
67
|
public:
|
|
68
|
-
friend bool operator==(const
|
|
68
|
+
friend bool operator==(const ScreenInitializer& lhs, const ScreenInitializer& rhs) = default;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
} // namespace margelo::nitro::rngine
|
|
72
72
|
|
|
73
73
|
namespace margelo::nitro {
|
|
74
74
|
|
|
75
|
-
// C++
|
|
75
|
+
// C++ ScreenInitializer <> JS ScreenInitializer (object)
|
|
76
76
|
template <>
|
|
77
|
-
struct JSIConverter<margelo::nitro::rngine::
|
|
78
|
-
static inline margelo::nitro::rngine::
|
|
77
|
+
struct JSIConverter<margelo::nitro::rngine::ScreenInitializer> final {
|
|
78
|
+
static inline margelo::nitro::rngine::ScreenInitializer fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
79
79
|
jsi::Object obj = arg.asObject(runtime);
|
|
80
|
-
return margelo::nitro::rngine::
|
|
80
|
+
return margelo::nitro::rngine::ScreenInitializer(
|
|
81
81
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "px"))),
|
|
82
82
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "py"))),
|
|
83
83
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
|
|
@@ -94,7 +94,7 @@ namespace margelo::nitro {
|
|
|
94
94
|
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "loop")))
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
|
-
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::
|
|
97
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::ScreenInitializer& arg) {
|
|
98
98
|
jsi::Object obj(runtime);
|
|
99
99
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "px"), JSIConverter<double>::toJSI(runtime, arg.px));
|
|
100
100
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "py"), JSIConverter<double>::toJSI(runtime, arg.py));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// WorldInitializer.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © Marc Rousavy @ Margelo
|
|
@@ -35,38 +35,38 @@
|
|
|
35
35
|
namespace margelo::nitro::rngine {
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* A struct which can be represented as a JavaScript object (
|
|
38
|
+
* A struct which can be represented as a JavaScript object (WorldInitializer).
|
|
39
39
|
*/
|
|
40
|
-
struct
|
|
40
|
+
struct WorldInitializer final {
|
|
41
41
|
public:
|
|
42
42
|
double tickRate SWIFT_PRIVATE;
|
|
43
43
|
std::optional<double> gx SWIFT_PRIVATE;
|
|
44
44
|
std::optional<double> gy SWIFT_PRIVATE;
|
|
45
45
|
|
|
46
46
|
public:
|
|
47
|
-
|
|
48
|
-
explicit
|
|
47
|
+
WorldInitializer() = default;
|
|
48
|
+
explicit WorldInitializer(double tickRate, std::optional<double> gx, std::optional<double> gy): tickRate(tickRate), gx(gx), gy(gy) {}
|
|
49
49
|
|
|
50
50
|
public:
|
|
51
|
-
friend bool operator==(const
|
|
51
|
+
friend bool operator==(const WorldInitializer& lhs, const WorldInitializer& rhs) = default;
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
} // namespace margelo::nitro::rngine
|
|
55
55
|
|
|
56
56
|
namespace margelo::nitro {
|
|
57
57
|
|
|
58
|
-
// C++
|
|
58
|
+
// C++ WorldInitializer <> JS WorldInitializer (object)
|
|
59
59
|
template <>
|
|
60
|
-
struct JSIConverter<margelo::nitro::rngine::
|
|
61
|
-
static inline margelo::nitro::rngine::
|
|
60
|
+
struct JSIConverter<margelo::nitro::rngine::WorldInitializer> final {
|
|
61
|
+
static inline margelo::nitro::rngine::WorldInitializer fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
62
62
|
jsi::Object obj = arg.asObject(runtime);
|
|
63
|
-
return margelo::nitro::rngine::
|
|
63
|
+
return margelo::nitro::rngine::WorldInitializer(
|
|
64
64
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "tickRate"))),
|
|
65
65
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "gx"))),
|
|
66
66
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "gy")))
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
|
-
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::
|
|
69
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rngine::WorldInitializer& arg) {
|
|
70
70
|
jsi::Object obj(runtime);
|
|
71
71
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "tickRate"), JSIConverter<double>::toJSI(runtime, arg.tickRate));
|
|
72
72
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "gx"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.gx));
|
package/package.json
CHANGED
package/shared/GameLoop.cpp
CHANGED
|
@@ -189,9 +189,9 @@ void GameLoop::updateStats(double deltaTime) {
|
|
|
189
189
|
|
|
190
190
|
void GameLoop::updateScreen(double deltaTime) {
|
|
191
191
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
192
|
-
if (_screen.asset
|
|
192
|
+
if (_screen.asset != 0) {
|
|
193
193
|
AssetUtils::updateProgress(_screen.progress, _screen.speed, _screen.loop,
|
|
194
|
-
_screen.asset
|
|
194
|
+
_screen.asset, deltaTime);
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
|
@@ -201,33 +201,19 @@ void GameLoop::updateEntities(double deltaTime) {
|
|
|
201
201
|
|
|
202
202
|
for (auto &[id, entity] : _entities) {
|
|
203
203
|
|
|
204
|
-
if (entity.mass
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
if (_world.gy.has_value()) {
|
|
209
|
-
entity.vy = entity.vy.value_or(0.0) + _world.gy.value() * deltaTime;
|
|
210
|
-
}
|
|
204
|
+
if (entity.mass > 0.0) {
|
|
205
|
+
entity.vx = entity.vx + _world.gx * deltaTime;
|
|
206
|
+
entity.vy = entity.vy + _world.gy * deltaTime;
|
|
211
207
|
}
|
|
212
208
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
if (entity.ay.has_value()) {
|
|
217
|
-
entity.vy = entity.vy.value_or(0.0) + entity.ay.value() * deltaTime;
|
|
218
|
-
}
|
|
209
|
+
entity.vx = entity.vx + entity.ax * deltaTime;
|
|
210
|
+
entity.vy = entity.vy + entity.ay * deltaTime;
|
|
219
211
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
if (entity.vy.has_value()) {
|
|
224
|
-
entity.py += entity.vy.value() * deltaTime;
|
|
225
|
-
}
|
|
212
|
+
entity.px += entity.vx * deltaTime;
|
|
213
|
+
entity.py += entity.vy * deltaTime;
|
|
226
214
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
entity.asset.value(), deltaTime);
|
|
230
|
-
}
|
|
215
|
+
AssetUtils::updateProgress(entity.progress, entity.speed, entity.loop,
|
|
216
|
+
entity.asset, deltaTime);
|
|
231
217
|
}
|
|
232
218
|
}
|
|
233
219
|
|
|
@@ -266,15 +252,11 @@ void GameLoop::resolveCollisions() {
|
|
|
266
252
|
Entity &a = itA->second;
|
|
267
253
|
Entity &b = itB->second;
|
|
268
254
|
|
|
269
|
-
if (a.isSensor
|
|
255
|
+
if (a.isSensor || b.isSensor)
|
|
270
256
|
continue;
|
|
271
257
|
|
|
272
|
-
double inverseMassA =
|
|
273
|
-
|
|
274
|
-
: 0.0;
|
|
275
|
-
double inverseMassB = (b.mass.has_value() && b.mass.value() > 0.0)
|
|
276
|
-
? 1.0 / b.mass.value()
|
|
277
|
-
: 0.0;
|
|
258
|
+
double inverseMassA = a.mass > 0.0 ? 1.0 / a.mass : 0.0;
|
|
259
|
+
double inverseMassB = b.mass > 0.0 ? 1.0 / b.mass : 0.0;
|
|
278
260
|
double totalInverseMass = inverseMassA + inverseMassB;
|
|
279
261
|
if (totalInverseMass == 0.0)
|
|
280
262
|
continue;
|
|
@@ -286,16 +268,17 @@ void GameLoop::resolveCollisions() {
|
|
|
286
268
|
b.px += c.nx * correction * inverseMassB;
|
|
287
269
|
b.py += c.ny * correction * inverseMassB;
|
|
288
270
|
|
|
289
|
-
double avx = a.vx
|
|
290
|
-
double bvx = b.vx
|
|
271
|
+
double avx = a.vx, avy = a.vy;
|
|
272
|
+
double bvx = b.vx, bvy = b.vy;
|
|
291
273
|
double relativeVx = bvx - avx, relativeVy = bvy - avy;
|
|
292
274
|
double velocityAlongNormal = relativeVx * c.nx + relativeVy * c.ny;
|
|
293
275
|
if (velocityAlongNormal > 0)
|
|
294
276
|
continue;
|
|
295
277
|
|
|
296
|
-
double restitution =
|
|
278
|
+
double restitution = restitution = std::max(a.restitution, b.restitution);
|
|
279
|
+
|
|
297
280
|
double impulse =
|
|
298
|
-
-(1 + restitution) * velocityAlongNormal / totalInverseMass;
|
|
281
|
+
-(1.0 + restitution) * velocityAlongNormal / totalInverseMass;
|
|
299
282
|
|
|
300
283
|
a.vx = avx - impulse * c.nx * inverseMassA;
|
|
301
284
|
a.vy = avy - impulse * c.ny * inverseMassA;
|