@inglorious/engine 13.0.1 → 13.0.3

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 (2) hide show
  1. package/README.md +157 -37
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -1,71 +1,191 @@
1
1
  # Inglorious Engine
2
2
 
3
- [![NPM version](https://img.shields.io/npm/v/@inglorious/engine.svg)](https://www.npmjs.com/package/@inglorious/engine)
4
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
4
 
6
- The core orchestrator for the [Inglorious Engine](https://github.com/IngloriousCoderz/inglorious-engine). This package provides a complete game loop, state management, and rendering pipeline in a single, cohesive unit. It is designed to be highly configurable and extensible, allowing you to build games with a functional, data-oriented approach.
5
+ A JavaScript game engine written with global state, immutability, and pure functions in mind. Have fun(ctional programming) with it!
7
6
 
8
- ---
7
+ ## Quick Start
9
8
 
10
- ## Core Concepts
9
+ The fastest way to start a new Inglorious Engine project is by using the official scaffolding tool.
11
10
 
12
- The `@inglorious/engine` package acts as the central hub that brings together all the engine's components. Its main responsibilities are:
11
+ Run the following command in your terminal and follow the prompts to create a new game from a variety of templates (including plain JavaScript, TypeScript, and IngloriousScript):
13
12
 
14
- 1. **Orchestrating the Game Loop**: The `Engine` class manages the game loop, which is responsible for continuously updating the state and rendering the game. The loop can be configured to use different timing mechanisms, such as `animationFrame` or a fixed `fps`.
13
+ ```bash
14
+ # with npm
15
+ npm create @inglorious/game@latest
15
16
 
16
- 2. **State Management**: It leverages the `@inglorious/store` package to manage the game's state. It provides methods to start, stop, and update the state manager, processing a queue of events on each frame.
17
+ # with pnpm
18
+ pnpm create @inglorious/game
19
+ ```
17
20
 
18
- 3. **Integrating the Renderer**: The engine is headless by design, but it can be configured with a renderer to display the game. The engine takes a renderer object in its configuration and integrates its systems and logic into the main game loop.
21
+ This will set up a complete project with a development server ready to go.
19
22
 
20
- 4. **Dev Tools Integration**: The engine automatically connects to a browser's dev tools for debugging and time-travel capabilities if `devMode` is enabled in the game's state.
23
+ ## Features
21
24
 
22
- ---
25
+ - **Functional & Data-Oriented**: Uses a single, immutable state object as the source of truth, inspired by functional programming principles.
26
+ - **Composable by Design**: Build complex behaviors by composing pure functions and decorators, offering a powerful alternative to inheritance.
27
+ - **Renderer Agnostic**: The engine is headless. You can use any rendering technology you like, from Canvas2D and HTML to React components.
28
+ - **Zero Build Step Option**: Write plain JavaScript and run it directly in the browser. No complex build configurations required.
23
29
 
24
- ## Installation
30
+ ## Documentation
25
31
 
26
- ```bash
27
- npm install @inglorious/engine
32
+ The best way to get started is with the official documentation, which includes a **[Quick Start Guide](https://inglorious-engine.vercel.app/?path=/docs/quick-start--docs)**.
33
+
34
+ Full documentation is available at: **[https://inglorious-engine.vercel.app/](https://inglorious-engine.vercel.app/)**
35
+
36
+ ## Why Functional Programming?
37
+
38
+ What makes this engine different from all the others is that, instead of Object Oriented Programming (OOP), which seems the most obvious choice for a game engine, this one is based on Functional Programming (FP).
39
+
40
+ FP has many advantages:
41
+
42
+ 1. **Single Source of Truth**: Your entire game state is a single, plain JavaScript object. This gives you complete control over your game's world at any moment, rather than having state scattered across countless objects. This is the core idea behind the Data-Driven Programming (DDP) paradigm that many modern engines are now adopting, and with this engine, you get that benefit naturally.
43
+
44
+ 2. **Efficient Immutability**: A common misconception is that creating a new state on every change is slow. This engine uses structural sharing (via Mutative), meaning only the parts of the state that actually change are copied. The rest of the state tree is shared by reference, making updates extremely fast. This provides a huge benefit:
45
+ - **Optimized Rendering**: Detecting changes becomes trivial and fast. A simple reference check (`prevState === nextState`) is all that's needed to determine if data has changed, enabling highly performant UIs (especially with libraries like React). This is much faster than the deep, recursive comparisons required in mutable systems.
46
+
47
+ 3. **Pure Functions**: Game logic is built with pure functions — functions that return a value based only on their inputs, with no side effects. This makes your game logic predictable, easy to test in isolation, and highly reusable, freeing you from the complexity of class methods with hidden side effects.
48
+
49
+ 4. **Composition over Inheritance**: Instead of complex class hierarchies, you build entities by composing functions. Think of it as a pipeline of operations applied to your data. This is a more flexible and powerful alternative to inheritance. You can mix and match behaviors (e.g., `canBeControlledByPlayer`, `canBeHurt`, `canShoot`) on the fly, avoiding the rigidity and common problems of deep inheritance chains.
50
+
51
+ 5. **Dynamic by Nature**: JavaScript objects are dynamic. You can add or remove properties from an entity at any time without being constrained by a rigid class definition. This is perfect for game development, where an entity's state can change unpredictably (e.g., gaining a temporary power-up). This flexibility allows for more emergent game mechanics.
52
+
53
+ 6. **Unparalleled Debugging and Tooling**: Because the entire game state is a single, serializable object, you can unlock powerful development patterns that are difficult to achieve in traditional OOP engines.
54
+ - **Time-Travel Debugging**: Save the state at any frame. You can step backward and forward through state changes to find exactly when a bug was introduced.
55
+ - **Hot-Reloading**: Modify your game's logic and instantly see the results without restarting. The engine can reload the code and re-apply it to the current state, dramatically speeding up iteration.
56
+ - **Simplified Persistence**: Saving and loading a game is as simple as serializing and deserializing a single JSON object.
57
+ - **Simplified Networking**: For multiplayer games, you don't need to synchronize complex objects. You just send small, serializable `event` objects over the network. Each client processes the same event with the same pure event handler, guaranteeing their game states stay in sync.
58
+
59
+ 7. **Leverage the Full JavaScript Ecosystem**: As a pure JavaScript engine, you have immediate access to the world's largest software repository: npm. Need advanced physics, complex AI, or a specific UI library? Integrate it with a simple `npm install`. You aren't limited to the built-in features or proprietary plugin ecosystem of a monolithic engine like Godot or Unity.
60
+
61
+ ## Architecture: State Management
62
+
63
+ The engine's state management is inspired by Redux, but it's specifically tailored for the demands of game development. If you're familiar with Redux, you'll recognize the core pattern: the UI (or game view) is a projection of the state, and the only way to change the state is to dispatch an action.
64
+
65
+ However, there are several key differences that make it unique:
66
+
67
+ 1. **Events, not Actions**: In Redux, you "dispatch actions." Here, we "notify of events." This is a deliberate semantic choice. An event handler is a function that reacts to a specific occurrence in the game world (e.g., `playerMove`, `enemyDestroy`). The naming convention is similar to standard JavaScript event handlers like `onClick`, where the handler name describes the event it's listening for.
68
+
69
+ 2. **Asynchronous Event Queue**: Unlike Redux's synchronous dispatch, events are not processed immediately. They are added to a central event queue. The engine's main loop processes this queue once per frame. This approach has several advantages:
70
+ - It decouples game logic from state updates.
71
+ - It ensures state changes happen at a predictable point in the game loop, preventing race conditions or cascading updates within a single frame.
72
+ - It allows for event batching and provides a solid foundation for networking and time-travel debugging.
73
+
74
+ 3. **Core Engine Events & Naming Convention**: The engine has a few built-in, **single-word** events that drive its core functionality. To avoid conflicts, you should use **multi-word `camelCase`** names for your own custom game events (`playerJump`, `itemCollect`). This convention is similar to how custom HTML elements require a hyphen to distinguish them from standard elements. Key engine events include:
75
+ - `update`: Fired on every frame, typically carrying the `deltaTime` since the last frame. This is where you'll put most of your continuous game logic (like movement).
76
+ - `add`: Used to add a new entity to the game state.
77
+ - `remove`: Used to remove an entity from the game state.
78
+ - `morph`: Used to dynamically change the behaviors associated with an entity's type.
79
+
80
+ 4. **Ergonomic Immutability with Mutative**: The state is immutable, but to make this easy to work with, we use Mutative. Inside your event handlers, you can write code that looks like it's mutating the state directly. Mutative handles the magic behind the scenes, producing a new, updated state with structural sharing, giving you the performance benefits of immutability with the developer experience of mutable code.
81
+
82
+ 5. **Composable Handlers via Function Piping**: Instead of large, monolithic "reducers," you build event handlers by composing smaller, pure functions. The engine encourages a pipeline pattern where an event and the current state are passed through a series of decorators or transformations. This makes your logic highly modular, reusable, and easy to test in isolation.
83
+
84
+ 6. **Handlers Can Issue New Events (Controlled Side-Effects)**: In a strict Redux pattern, reducers must be pure. We relax this rule for a pragmatic reason: event handlers in this engine **can notify of new events**. This allows you to create powerful, reactive chains of logic. For example, an `enemy:take_damage` handler might check the enemy's health and, if it drops to zero, notify of a new `enemy:destroyed` event.
85
+ - **How it works**: Any event notified from within a handler is simply added to the end of the main event queue. It will be processed in a subsequent pass of the game loop, not immediately. This prevents synchronous, cascading updates within a single frame and makes the flow of logic easier to trace.
86
+
87
+ - **A Word of Caution**: This power comes with responsibility. It is possible to create infinite loops (e.g., event A's handler notifies of event B, and event B's handler notifies of event A). Developers should be mindful of this when designing their event chains.
88
+
89
+ ## Frequently Unsolicited Complaints (FUCs)
90
+
91
+ A few... recurring themes have popped up in discussions about the engine. Let's address them head-on.
92
+
93
+ **"You just hate OOP."**
94
+
95
+ Not at all! OOP is a powerful paradigm, and parts of this engine use it — the `Engine` itself is a class, for example. My main reservation is with deep **inheritance** hierarchies, which can become rigid and fragile. This engine's architecture strongly favors **composition over inheritance** by design, which I believe is a more flexible way to build complex and dynamic behaviors in games.
96
+
97
+ **"This was made by a vibecoder who doesn't get cache optimization."**
98
+
99
+ This engine is the product of countless hours of coding, smartly paired with AI assistance. If you're not leveraging AI in your workflow today, you're the one missing out.
100
+
101
+ Now, let's talk performance. The critique often has two parts: garbage collection (GC) pressure from immutability, and cache performance compared to modern engines.
102
+
103
+ 1. **Garbage Collection**: The concern is that creating new objects on every state change will flood the GC. This is mitigated by **structural sharing** (via Mutative). We don't deep-clone the state; only the changed data paths create new objects. For the most extreme cases (e.g., a bullet hell), the engine provides a dedicated **entity pooling system** as a pragmatic escape hatch, eliminating GC pressure in performance hotspots.
104
+
105
+ 2. **Cache Performance & ECS**: The other critique is that modern engines like Unity or Godot use an Entity-Component-System (ECS) architecture to avoid deep object graphs (`player.inventory.getItem()`) and achieve better cache performance. **This is absolutely correct!** Those engines solve this problem very well.
106
+
107
+ This engine achieves a similar architectural goal — separating data from behavior — but through a functional paradigm that is native to JavaScript. Instead of fighting with OOP class hierarchies, you get a data-centric, ECS-like pattern by default. Centralizing state in a single object leverages the JS engine's highly optimized property access, which, while not the same as a C++ SoA layout, is a massive improvement over the pointer-chasing that plagues naive OOP designs.
108
+
109
+ **"JavaScript isn't a 'real' functional language."**
110
+
111
+ You're right, it's not Haskell. JavaScript is a multi-paradigm language, and that's one of its strengths! This engine leverages its first-class functions, closures, and native support for data structures (objects and arrays) to enable a functional _style_. We get many of the benefits—pure functions, immutability (with help), and composition—without needing to be dogmatic about it.
112
+
113
+ **"Data-Driven Programming is not the same as Data-Oriented Design."**
114
+
115
+ This is a frequent point of confusion, so let's clarify. The engine uses [Data-Driven _Programming_](https://en.wikipedia.org/wiki/Data-driven_programming), but it's important to distinguish it from [Data-Oriented _Design_](https://en.wikipedia.org/wiki/Data-oriented_design).
116
+
117
+ - **Data-Driven Programming (DDP)**: This is the architectural paradigm the engine is built on. It's about separating the data (your entities) from the logic that operates on it (your systems and event handlers). Your entire game state lives in one place, and your logic is a collection of pure functions that transform that data.
118
+
119
+ - **Data-Oriented Design (DOD)**: This is a lower-level implementation strategy focused on CPU cache performance, common in ECS architectures. It involves organizing data in contiguous memory blocks (e.g., an array of all positions, an array of all velocities) to minimize cache misses during iteration.
120
+
121
+ This engine does **not** implement a strict DOD memory layout. However, by centralizing all entities into a single, flat object, we get a pragmatic, "almost-DOD" benefit. We leverage the JavaScript engine's highly optimized internal object layout, which is significantly more cache-friendly than chasing pointers through a deeply nested OOP graph.
122
+
123
+ **"Functional programming is just painful to read and write."**
124
+
125
+ This is a common fear, especially for developers coming from a pure OOP background. The goal here isn't to force you to write Lisp in JavaScript. Instead, the API is intentionally designed to feel familiar and ergonomic:
126
+
127
+ - **`types` are your "classes"**: They act as blueprints for your game objects.
128
+ - **`entities` are your "instances"**: They are the concrete things in your game, created from a `type`.
129
+ - **Composition feels like inheritance**: You can "extend" a type (which is just an array of behaviors) by adding behaviors to it, like `[baseType, someBehavior]`, and you "extend" a behavior by creating a function that composes new event handlers onto a base type, like `(type) => ({ eventName(...args) { type.eventName?.(...args) } })`. You get the code reuse you expect, but with the power and flexibility of composition.
130
+ - **Immutable updates feel mutable**: Thanks to Mutative, you don't have to write complex functional updates. Inside your event handlers, you can write simple, direct code like `entity.health -= 10`, and the engine handles creating the new immutable state for you.
131
+
132
+ The engine provides the benefits of FP (predictability, testability) without the steep learning curve. You get to think in terms of familiar concepts while the engine handles the functional magic for you.
133
+
134
+ **"But I like my operators!"**
135
+
136
+ We do too! That's why the engine includes **IngloriousScript**, an optional Babel plugin that overloads standard JavaScript operators for intuitive vector math.
137
+
138
+ ```javascript
139
+ // Without IngloriousScript
140
+ const newPosition = mod(add(position, scale(velocity, dt)), worldSize)
141
+
142
+ // With IngloriousScript
143
+ const newPosition = (position + velocity * dt) % worldSize
28
144
  ```
29
145
 
30
- ---
146
+ It supports vector-vector, vector-scalar, and scalar-vector operations for `+`, `-`, `*`, `/`, `%`, and `**`, making your game logic clean, readable, and expressive.
31
147
 
32
- ## API
148
+ **"A good OOP developer just uses composition anyway. You don't need a new engine for that."**
33
149
 
34
- ### `new Engine(...gameConfigs)`
150
+ True, disciplined developers favor composition in any paradigm. The difference is that in many traditional OOP engines, inheritance is often presented as the default, easy path. This engine is designed so that **composition is the path of least resistance**. The architecture doesn't just allow for composition; it's built on it. You don't need discipline to avoid inheritance pitfalls when the framework naturally guides you to a better pattern.
35
151
 
36
- Creates a new `Engine` instance, given one or more configuration objects.
152
+ **"This is fine for toy projects, but immutability will never scale."**
37
153
 
38
- **Parameters:**
154
+ This critique usually misunderstands how modern immutability works. The engine uses structural sharing (via Mutative), which means we're not deep-copying the entire game state on every change. It's incredibly efficient.
39
155
 
40
- - `gameConfig` (object): The game-specific configuration. It is an object with the following properties:
41
- - `loop` (object, optional): Configuration for the game loop.
42
- - `type` (string, optional): The type of loop to use (`animationFrame` or `fixed`). Defaults to `animationFrame`.
43
- - `fps` (number, optional): The target frames per second. Only used with the `fixed` loop type. Defaults to `60`.
44
- - `types` (object, optional): A map of entity types.
45
- - `entities` (object, optional): A map of initial entities.
46
- - `systems` (array, optional): An array of system objects, which define behaviors for the whole state.
156
+ That said, we're pragmatic. For performance-critical scenarios like a bullet hell with thousands of short-lived objects, we provide an **entity pooling** system as an escape hatch. But for 99% of game logic, we believe the massive benefits of a predictable, testable, and debuggable state (hello, time-travel debugging!) are a worthwhile trade-off for a negligible performance cost.
47
157
 
48
- **Returns:**
158
+ **"My favorite OOP engine can do all this too!"**
49
159
 
50
- - A new `Engine` instance.
160
+ You're right. Modern engines like Unity (with DOTS) and Godot offer powerful, composition-based, ECS-like architectures out of the box. They are fantastic tools that have evolved to embrace these patterns.
51
161
 
52
- ### `await engine.init()`
162
+ To provide these features, however, they had to implement them within the constraints of a fundamentally object-oriented foundation. This sometimes results in systems that feel like they are working around the core OOP paradigm — almost to the point where it doesn't feel like OOP anymore.
53
163
 
54
- An asynchronous function that initializes the resources required for the game to load.
164
+ The difference with this engine is that it was designed with functional and data-oriented principles from the very beginning. Composition, event-driven architecture, and data-centric patterns aren't features layered on top; they are the fundamental, native way of building things. The entire engine speaks one language, making these good practices the most natural and intuitive way to build your game.
55
165
 
56
- ### `engine.start()`
166
+ **"You'll never compete with Unity/Godot/Unreal."**
57
167
 
58
- Starts the game loop, triggering the first `update` and `render` calls.
168
+ You're absolutely right. And we're not trying to.
59
169
 
60
- ### `engine.stop()`
170
+ This engine isn't for developers who want a massive, all-in-one, GUI-driven editor. It's for JavaScript developers who want to build games with the tools and ecosystem they already know and love. It's for those who are curious about applying functional programming principles to game development and who value architectural flexibility over a monolithic, proprietary feature set. It's a different tool for a different kind of developer.
61
171
 
62
- Halts the game loop and cleans up any resources. This method also processes a final `stop` event to ensure a clean shutdown.
172
+ **"Why not just use an existing engine?"**
63
173
 
64
- ---
174
+ Because building things is fun! This project is as much an exploration of software architecture as it is a tool for making games. It's for developers who are curious about functional programming and want to see how its principles can be applied to game development in a JavaScript environment.
175
+
176
+ ## Dependencies
177
+
178
+ The core engine relies on a few key, lightweight packages:
179
+
180
+ - [mutative](https://www.npmjs.com/package/mutative): For enabling ergonomic immutable updates with structural sharing.
181
+ - [@inglorious/utils](https://www.npmjs.com/package/@inglorious/utils): A collection of small, pure utility functions for things like vector math and data manipulation.
182
+ - [@inglorious/store](https://www.npmjs.com/package/@inglorious/store): The environment-agnostic core state management library.
183
+
184
+ ## Quick Start Example
65
185
 
66
- ## Basic Usage
186
+ ## Usage without a Build Step
67
187
 
68
- Here is a complete example showing how to set up and run a game using the engine.
188
+ If you prefer to avoid a build step, you can run the engine directly in the browser. The example below demonstrates how to set up a minimal game using ES modules, an `importmap`, and the 2D canvas renderer.
69
189
 
70
190
  ```html
71
191
  <!DOCTYPE html>
@@ -112,4 +232,4 @@ You're free to use, modify, and distribute this software. See [LICENSE](./LICENS
112
232
 
113
233
  ## Contributing
114
234
 
115
- We welcome contributions from the community\! Whether you're fixing a bug, adding a feature, or improving the documentation, your help is appreciated. Please read our [Contributing Guidelines](https://github.com/IngloriousCoderz/inglorious-engine/blob/main/CONTRIBUTING.md) for details on how to get started.
235
+ We welcome contributions from the community! Whether you're fixing a bug, adding a feature, or improving the documentation, your help is appreciated. Please read our [Contributing Guidelines](./CONTRIBUTING.md) for details on how to get started.
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@inglorious/engine",
3
- "version": "13.0.1",
3
+ "version": "13.0.3",
4
4
  "description": "A JavaScript game engine written with global state, immutability, and pure functions in mind. Have fun(ctional programming) with it!",
5
5
  "author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/IngloriousCoderz/inglorious-engine.git",
9
+ "url": "git+https://github.com/IngloriousCoderz/inglorious-forge.git",
10
10
  "directory": "packages/engine"
11
11
  },
12
12
  "homepage": "https://inglorious-engine.vercel.app/",
13
13
  "bugs": {
14
- "url": "https://github.com/IngloriousCoderz/inglorious-engine/issues"
14
+ "url": "https://github.com/IngloriousCoderz/inglorious-forge/issues"
15
15
  },
16
16
  "keywords": [
17
17
  "data-oriented",
@@ -31,18 +31,18 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@inglorious/utils": "3.7.0",
35
- "@inglorious/store": "7.1.1"
34
+ "@inglorious/store": "7.1.3",
35
+ "@inglorious/utils": "3.7.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@inglorious/store": "7.1.1",
38
+ "@inglorious/store": "7.1.3",
39
39
  "@inglorious/utils": "3.7.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "prettier": "^3.5.3",
43
43
  "vite": "^7.1.3",
44
44
  "vitest": "^1.6.0",
45
- "@inglorious/eslint-config": "1.1.0"
45
+ "@inglorious/eslint-config": "1.1.1"
46
46
  },
47
47
  "engines": {
48
48
  "node": ">= 22"