Declarative game engines that avoid object-oriented programming (OOP) are relatively rare, as many game engines are built around OOP principles to manage complexity, modularity, and state. However, there are some declarative, functional, or data-driven approaches to game development that either minimize or entirely avoid OOP. These approaches often emphasize immutability, pure functions, and data-oriented design. Below is an exploration of declarative game engines and frameworks that align with non-OOP paradigms, along with some notable examples and concepts.
1. Understanding Declarative and Non-OOP Game Development
- Declarative Programming: In a declarative approach, you describe what the game should do, rather than how to do it. This contrasts with imperative programming, where you explicitly define the steps to achieve a result.
- Non-OOP Paradigms: Non-OOP game engines often use functional programming, data-oriented design, or entity-component-system (ECS) architectures. These paradigms focus on data transformation, immutability, and separation of concerns, avoiding traditional class hierarchies and inheritance.
2. Entity-Component-System (ECS) as a Non-OOP Alternative
Many modern game engines use ECS, which is inherently data-driven and declarative in nature. ECS avoids traditional OOP by separating data (components) from behavior (systems), making it a good fit for non-OOP game development.
- How ECS Works:
- Entities: Simple IDs or containers that represent game objects.
- Components: Pure data structures that describe properties (e.g., position, velocity, sprite).
- Systems: Functions or procedures that operate on entities with specific components, defining behavior.
- Why ECS is Non-OOP: Instead of using classes and inheritance, ECS uses composition and data transformation, aligning with functional or data-oriented paradigms.
Examples of ECS-Based Engines:
- Bevy (Rust):
- Bevy is a modern, open-source game engine written in Rust that uses ECS as its core architecture.
- It avoids OOP by using Rust's struct-based components and systems, emphasizing immutability and functional programming principles.
- Bevy's declarative nature comes from its query system and the way you define game logic as systems that operate on data.
- Website: bevyengine.org
- Flecs (C/C++):
- Flecs is a lightweight ECS library that can be used to build games or simulations.
- It avoids OOP by treating components as plain data and systems as functions, with no reliance on class hierarchies.
- Website: flecs.dev
- EnTT (C++):
- EnTT is another ECS library for C++ that avoids OOP principles, focusing on data-oriented design.
- It is highly performant and declarative, allowing you to define game logic as systems that operate on entities and components.
- Website: github.com/skypjack/entt
3. Functional Programming-Based Game Engines
Functional programming (FP) is inherently declarative, as it emphasizes pure functions, immutability, and data transformation. Some game engines or frameworks are built around FP principles, avoiding OOP entirely.
Examples:
- Elm Architecture for Games:
- Elm is a functional programming language for building web applications, but its architecture (Model-Update-View) has been adapted for game development.
- Frameworks like A-Frame (for WebVR) or custom Elm-based game frameworks use a declarative, functional approach to define game state and behavior.
- Elm avoids OOP by using immutable data structures and pure functions to handle game logic.
- Website: elm-lang.org
- Haskell-Based Game Development:
- Haskell, a purely functional programming language, has libraries like Gloss and SDL2 for game development.
- These libraries encourage a declarative style, where game state is managed as immutable data, and behavior is defined as pure functions.
- Example: Gloss allows you to define games by specifying a state transformation function and a rendering function, avoiding OOP entirely.
- Website: hackage.haskell.org/package/gloss
- PureScript:
- PureScript is another functional language for web development, and libraries like purescript-canvas or purescript-halogen can be used to build declarative, non-OOP games in the browser.
- Website: purescript.org
4. Data-Oriented Design (DOD) Engines
Data-oriented design focuses on optimizing data layout and transformation, often avoiding OOP's reliance on objects and inheritance. DOD is common in high-performance game engines and aligns well with declarative principles.
Examples:
- Unity's DOTS (Data-Oriented Technology Stack):
- Unity, traditionally an OOP-based engine, has introduced DOTS, which uses ECS and data-oriented design to achieve high performance.
- While Unity itself is OOP-based, DOTS avoids traditional OOP by using pure data components and systems, making it more declarative and functional in nature.
- Website: unity.com/dots
- Custom DOD Frameworks:
- Many developers build custom game engines using DOD principles, often in languages like C, C++, or Rust. These engines avoid OOP by treating game state as raw data and behavior as functions that transform that data.
5. Declarative Game Frameworks for Specific Domains
Some frameworks are designed for specific types of games (e.g., visual novels, interactive fiction) and use declarative, non-OOP approaches.
Examples:
- Twine:
- Twine is a tool for creating interactive, text-based games (e.g., choose-your-own-adventure stories).
- It uses a declarative approach, where you define nodes and transitions in a visual editor or markup language, avoiding OOP entirely.
- Website: twinery.org
- Ren'Py:
- Ren'Py is a visual novel engine that uses a declarative scripting language (based on Python) to define game flow, dialogue, and visuals.
- While Python is OOP-capable, Ren'Py's scripting layer is primarily declarative, focusing on defining scenes, characters, and transitions without requiring OOP.
- Website: renpy.org
- Inform 7:
- Inform 7 is a declarative language for creating interactive fiction.
- It uses natural language-like syntax to define game rules, objects, and behavior, avoiding traditional programming paradigms like OOP.
- Website: inform7.com
6. Custom Declarative Game Engines
If none of the existing engines meet your needs, you can build a custom declarative game engine using non-OOP principles. Here are some approaches:
- Use a Functional Language: Languages like Haskell, OCaml, or F# are well-suited for building declarative, non-OOP game engines.
- Use a Data-Oriented Language: Languages like Rust or C++ can be used to build ECS-based engines that avoid OOP.
- Use a Declarative Framework: Frameworks like React (for web-based games) or Flutter can be adapted for game development, using declarative, functional principles.
7. Challenges of Non-OOP Declarative Game Engines
While declarative, non-OOP game engines offer benefits like simplicity, performance, and maintainability, they also come with challenges:
- Learning Curve: Functional programming and ECS can be unfamiliar to developers accustomed to OOP.
- Tooling: Non-OOP engines often have less mature tooling compared to mainstream OOP engines like Unity or Unreal.
- Community Support: Declarative, non-OOP engines may have smaller communities, making it harder to find tutorials or plugins.
8. Recommendations
If you're looking for a declarative, non-OOP game engine, consider the following based on your needs:
- For General-Purpose Games: Bevy (Rust) is an excellent choice for its modern ECS architecture and functional design.
- For Web-Based Games: Elm or PureScript frameworks offer declarative, functional game development in the browser.
- For High-Performance Games: Flecs or EnTT (C/C++) provide lightweight, non-OOP ECS solutions.
- For Text-Based or Narrative Games: Twine or Inform 7 offer declarative, non-OOP tools for interactive fiction.
Conclusion
Declarative game engines that avoid OOP are often built around ECS, functional programming, or data-oriented design. While they may not be as mainstream as OOP-based engines, they offer unique advantages in terms of performance, scalability, and maintainability. Bevy, Flecs, and functional programming frameworks like Gloss or Elm are great starting points for exploring this paradigm. If you're interested in a specific type of game or language, let me know, and I can provide more tailored recommendations!