Skip to content
Dandielo edited this page May 6, 2022 · 3 revisions

Overview

A World in IceShard is a concept like a scene but without any assumptions about what data or logic it contains. It allows for easy separation of various systems like Audio, UI, Game Loop, Rendering, etc...

Worlds are created using a WorldTemplate object which currently defines the name, traits and entity_storage of a World.

You can have multiple worlds created at the same time and activate/deactivate them separately.

However, if you introduce dependencies between traits of different worlds. You are responsible for properly managing activation.

World Traits

Each world object is a container for world traits. Traits are small, system-like objects that match the world's lifetime. Each trait is allowed to allocate and process any data available from the current and previous engine frame, and access entity data via ecs queries.

Box2D trait example

The PhysicsBox2D trait queries the entity storage for entities with specific components (Position2D, PhysicsObject) and creates Box2D objects out of their definitions if they don't exist yet.

It will keep every frame both representations (ecs and box2d) up to date.

Adding this trait will automatically enable physics for all matching entities.

Multi-World logic

The engine is from the start using a multi-world setup. This is because the graphics and game loop are separated into two threads and only communicate with each other via frame messages / shards.

If you deactivated the main game world, the graphics rendering would still go on. Just the view would be frozen because no new data would be sent to the graphics world.

Because of this separation, it's easy to implement any kind of pause or game logic state changes. The idea would be to have a main game world which tracks the games' state and only controls which worlds are active and which ones are not.

You can implement cutscenes, blocking UI, menus, multi-layered game states, network, and whatever comes to mind.

API Reference

TODO