Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
World.h
Go to the documentation of this file.
1/**
2 * @file World.h
3 * @brief World and ECS Manager for Olympe Engine
4 * @author Nicolas Chereau
5 * @date 2025
6 * @version 2.0
7 *
8 * @details
9 * This file contains the World class which manages the Entity-Component-System
10 * architecture, level loading, and game state. The World is a singleton that
11 * coordinates all game entities, components, and systems.
12 *
13 * Key responsibilities:
14 * - Entity lifecycle management (create, destroy, query)
15 * - Component storage and retrieval
16 * - System execution coordination
17 * - Level loading from Tiled maps
18 * - Tile rendering and tileset management
19 *
20 * @note World purpose: Manage the overall game world, including object management,
21 * level handling, and ECS architecture.
22 */
23#pragma once
24
25#include "system/EventQueue.h"
26#include "system/system_utils.h"
27#include <vector>
28#include <memory>
29#include <unordered_map>
30#include <queue>
31#include <type_traits>
32
33#include "Level.h"
34#include "GameState.h"
35
36// Include ECS related headers
37#include "Ecs_Entity.h"
38#include "ECS_Components.h"
39#include "ECS_Systems.h"
40#include "ECS_Register.h" // Include the implementation of ComponentPool
41#include "PrefabScanner.h"
42#include "PrefabFactory.h"
43
44// JSON library for tile layer loading
45#include "third_party/nlohmann/json.hpp"
46#include "ParameterResolver.h"
47
48// Forward declarations for 3-Phase Level Loading
49//struct PrefabRegistry;
50namespace Olympe {
51 namespace Tiled {
52 struct LevelParseResult;
53 struct TiledMap;
54 }
55 namespace Editor {
56 struct LevelDefinition;
57 struct EntityInstance;
58 }
59}
60
61// ========================================================================
62// TILE LAYER SUPPORT
63// ========================================================================
64
65/**
66 * @struct TileChunk
67 * @brief Represents a chunk of tiles for rendering
68 *
69 * Tile chunks are used to batch tile rendering for performance.
70 * Each chunk contains a grid of tiles from a single layer.
71 */
73{
74 std::string layerName; ///< Name of the source layer
75 int x; ///< Chunk X position (in tiles)
76 int y; ///< Chunk Y position (in tiles)
77 int width; ///< Chunk width (in tiles)
78 int height; ///< Chunk height (in tiles)
79 int zOrder; ///< Render order (Z-coordinate)
80 std::vector<uint32_t> tileGIDs; ///< Tile Global IDs (with flip flags)
81
82 /** @brief Default constructor */
83 TileChunk() : x(0), y(0), width(0), height(0), zOrder(0) {}
84};
85
86/**
87 * @class TilesetManager
88 * @brief Manages tilesets loaded from Tiled maps
89 *
90 * Handles both image-based tilesets (single texture atlas) and
91 * collection tilesets (individual tile images).
92 *
93 * Provides tile lookup by Global ID (GID) and texture access.
94 */
96{
97public:
98 /**
99 * @struct TilesetInfo
100 * @brief Information about a loaded tileset
101 *
102 * Stores tileset properties including dimensions, offsets, and textures.
103 * Critical for proper tile rendering with correct positioning.
104 */
106 {
107 uint32_t firstgid; ///< First Global ID in this tileset
108 uint32_t lastgid; ///< Last Global ID (firstgid + tilecount - 1)
109 std::string name; ///< Tileset name
110 int tilewidth; ///< Width of each tile
111 int tileheight; ///< Height of each tile
112 int columns; ///< Number of columns in atlas
113 int imagewidth; ///< Total atlas width
114 int imageheight; ///< Total atlas height
115 int margin; ///< Margin around atlas
116 int spacing; ///< Spacing between tiles
117 bool isCollection; ///< True if collection tileset
118
119 // ====================================================================
120 // CRITICAL: Global tile offset for this tileset
121 // These values come from the .tsx/.tsj file's <tileoffset> element
122 // ALL tiles in this tileset inherit these offset values for rendering
123 // Examples from Olympe tilesets:
124 // - Trees.tsj: tileoffsetX = -100, tileoffsetY = 0
125 // - Tiles iso cube.tsx: tileoffsetX = 0, tileoffsetY = 26
126 // - tiles-iso-1.tsx: tileoffsetX = 0, tileoffsetY = 0 (default)
127 // ====================================================================
128 int tileoffsetX; ///< Global X offset for all tiles
129 int tileoffsetY; ///< Global Y offset for all tiles
130
131 // Image-based tileset
132 SDL_Texture* texture; ///< Atlas texture (image-based)
133
134 // Collection tileset (individual tiles)
135 std::map<uint32_t, SDL_Texture*> individualTiles; ///< Per-tile textures
136 std::map<uint32_t, SDL_Rect> individualSrcRects; ///< Per-tile source rects
137
138 /**
139 * @brief Default constructor with explicit initialization
140 */
145 };
146
147 /**
148 * @brief Clear all loaded tilesets
149 */
150 void Clear();
151
152 /**
153 * @brief Load tilesets from JSON data
154 * @param tilesetsJson JSON array of tileset definitions
155 */
157
158 /**
159 * @brief Get texture and source rect for a tile by GID
160 * @param gid Global tile ID
161 * @param outTexture Output texture pointer
162 * @param outSrcRect Output source rectangle
163 * @param outTileset Output tileset info pointer
164 * @return True if tile was found
165 */
166 bool GetTileTexture(uint32_t gid, SDL_Texture*& outTexture, SDL_Rect& outSrcRect, const TilesetInfo*& outTileset);
167
168 /**
169 * @brief Get all loaded tilesets
170 * @return Reference to tileset vector
171 */
172 const std::vector<TilesetInfo>& GetTilesets() const { return m_tilesets; }
173
174private:
175 std::vector<TilesetInfo> m_tilesets; ///< All loaded tilesets
176};
177
178/**
179 * @class World
180 * @brief Core ECS manager and world coordinator
181 *
182 * The World class is the central hub for the Entity-Component-System architecture.
183 * It manages all entities, components, systems, and level loading.
184 *
185 * Key features:
186 * - Entity creation and destruction
187 * - Component addition, removal, and queries
188 * - System registration and execution
189 * - Level loading from Tiled maps (.tmj/.tmx)
190 * - Tile rendering with multiple tilesets
191 * - Collision and navigation mesh management
192 *
193 * @note Singleton class - use World::Get() to access
194 *
195 * @example
196 * @code
197 * // Create entity
198 * EntityID player = World::Get().CreateEntity();
199 *
200 * // Add components
201 * Position_data pos;
202 * pos.position = Vector(100, 200, 0);
203 * World::Get().AddComponent<Position_data>(player, pos);
204 *
205 * // Query entities
206 * auto entities = World::Get().GetEntitiesWithComponents<Position_data, Sprite_data>();
207 * @endcode
208 */
209class World
210{
211public:
212 /** @brief Default constructor */
213 World();
214
215 /** @brief Destructor */
216 virtual ~World();
217
218 /**
219 * @brief Get singleton instance
220 * @return Reference to World singleton
221 */
223 {
224 static World instance;
225 return instance;
226 }
227
228 /**
229 * @brief Get singleton instance (short form)
230 * @return Reference to World singleton
231 */
232 static World& Get() { return GetInstance(); }
233
234 //---------------------------------------------------------------
235 // ECS Systems
237 void Add_ECS_System(std::unique_ptr<ECS_System> system);
238 void Process_ECS_Systems();
239 void Render_ECS_Systems();
241
242 // Get a specific system by type
243 template <typename T>
245 {
246 for (auto& system : m_systems)
247 {
248 T* castedSystem = dynamic_cast<T*>(system.get());
249 if (castedSystem)
250 return castedSystem;
251 }
252 return nullptr;
253 }
254
255 //---------------------------------------------------------------
256 // Main processing loop called each frame: events are processed first (async), then stages in order
257 void Process()
258 {
259 //0) Swap EventQueue buffers to make previous frame's events readable
260 // This is the single point per frame where write buffer becomes read buffer
262
263 // check global game state
265 bool paused = (state == GameState::GameState_Paused);
266
267 // ECS Processing Systems
269 }
270 //---------------------------------------------------------------------------------------------
271 void Render()
272 {
273 // ECS Rendering Systems
276 }
277 //---------------------------------------------------------------------------------------------
278 // Level management
279 void AddLevel(std::unique_ptr<Level> level)
280 {
281 if (level) m_levels.push_back(std::move(level));
282 }
283
284 const std::vector<std::unique_ptr<Level>>& GetLevels() const { return m_levels; }
285
286 // Tiled MapEditor integration
287 bool LoadLevelFromTiled(const std::string& tiledMapPath);
288 void UnloadCurrentLevel();
289
290 // NEW: Load and prepare all behavior tree dependencies for a level
292
293 // Generate collision and navigation maps from TMJ/TMX level data
296
297 // ========================================================================
298 // PHASE 2 & 3: Advanced Level Loading Structures
299 // ========================================================================
300
321
371
372 // -------------------------------------------------------------
373 // ECS Entity Management
375 void DestroyEntity(EntityID entity);
376 bool IsEntityValid(EntityID entity) const
377 {
378 return m_entitySignatures.find(entity) != m_entitySignatures.end();
379 }
380 /**
381 * @brief Get all active entity IDs
382 * @return Vector of all entity IDs in the world
383 */
384 const std::vector<EntityID>& GetAllEntities() const
385 {
386 return m_entities;
387 }
388 // -------------------------------------------------------------
389 // Component Management (Pool Facade)
390
391 // Add Component: takes type (T) and constructor arguments
392 template <typename T, typename... Args>
394 {
396
397 // 1. Instantiate the pool if it's the first time we add this type
398 if (m_componentPools.find(typeID) == m_componentPools.end())
399 {
400 m_componentPools[typeID] = std::make_unique<ComponentPool<T>>();
401 }
402
403 // 2. Get the pool and add the component
404 auto* pool = static_cast<ComponentPool<T>*>(m_componentPools[typeID].get());
405
406 // Creation and adding of the component using perfect forwarding
407 pool->AddComponent(entity, std::forward<Args>(args)...);
408
409 // 3. Update the Entity's Signature
410 m_entitySignatures[entity].set(typeID, true);
411
412 // 4. Notify Systems about the signature change
413 Notify_ECS_Systems(entity, m_entitySignatures[entity]);
414
415 // 5. Special handling: Register input entities with InputsManager
417
418 return pool->GetComponent(entity);
419 }
420
421 template <typename T>
423 {
425 if (m_componentPools.find(typeID) == m_componentPools.end()) return;
426
427 // 1. Remove from the pool
428 m_componentPools[typeID]->RemoveComponent(entity);
429
430 // 2. Update the Entity's Signature
431 m_entitySignatures[entity].set(typeID, false);
432
433 // 3. Notify Systems
434 Notify_ECS_Systems(entity, m_entitySignatures[entity]);
435 }
436
437 template <typename T>
439 {
441 if (m_componentPools.find(typeID) == m_componentPools.end())
442 {
443 throw std::runtime_error("Component pool not registered.");
444 }
445
446 auto* pool = static_cast<ComponentPool<T>*>(m_componentPools[typeID].get());
447 return pool->GetComponent(entity);
448 }
449
450 template <typename T>
451 bool HasComponent(EntityID entity) const
452 {
454
455 // Fast check using the signature
456 if (m_entitySignatures.count(entity) && m_entitySignatures.at(entity).test(typeID))
457 {
458 // Delegate the final check to the specific Pool
459 if (m_componentPools.count(typeID)) {
460 auto* pool = static_cast<ComponentPool<T>*>(m_componentPools.at(typeID).get());
461 return pool->HasComponent(entity);
462 }
463 }
464 return false;
465 }
466
467 // ========================================================================
468 // Layer Management API
469 // ========================================================================
470
471 /// Get the default render layer for an entity type
472 /// Automatically assigns appropriate layer based on entity classification
474 {
475 switch (type)
476 {
478 case EntityType::NPC:
480
482 return RenderLayer::Characters; // Same layer as players for proper overlap
483
484 case EntityType::Item:
487
491
494
497
500 return RenderLayer::Ground; // Invisible helpers at ground level
501
504 case EntityType::None:
505 default:
506 return RenderLayer::Ground;
507 }
508 }
509
510 /// Set entity render layer (updates position.z)
511 void SetEntityLayer(EntityID entity, RenderLayer layer);
512
513 /// Calculate layer index from zOrder value (for Tiled levels)
514 /// Maps zOrder ranges to layer indices for proper depth sorting
515 RenderLayer CalculateLayerFromZOrder(float zOrder) const;
516
517 /// Get entity render layer
518 RenderLayer GetEntityLayer(EntityID entity) const;
519
520 /// Get next available custom layer index (for dynamic layers)
522 {
523 return m_nextCustomLayerIndex++;
524 }
525
526 // ========================================================================
527 // Grid Management
528 // ========================================================================
529
530 /// Toggle grid visibility
532 {
533 for (const auto& kv : m_entitySignatures)
534 {
535 EntityID e = kv.first;
537 {
539 settings.enabled = !settings.enabled;
540
541 SYSTEM_LOG << "World::ToggleGrid: Grid "
542 << (settings.enabled ? "enabled" : "disabled") << "\n";
543 break;
544 }
545 }
546 }
547
548 /// Get current grid state
550 {
551 for (const auto& kv : m_entitySignatures)
552 {
553 EntityID e = kv.first;
555 {
557 return settings.enabled;
558 }
559 }
560 return false; // Default if no GridSettings entity exists
561 }
562
563 /// Toggle collision overlay visibility
565 {
566 for (const auto& kv : m_entitySignatures)
567 {
568 EntityID e = kv.first;
570 {
572 settings.showCollisionOverlay = !settings.showCollisionOverlay;
573
574 SYSTEM_LOG << "World::ToggleCollisionOverlay: Collision overlay "
575 << (settings.showCollisionOverlay ? "enabled" : "disabled") << "\n";
576 break;
577 }
578 }
579 }
580
581 /// Toggle navigation overlay visibility
583 {
584 for (const auto& kv : m_entitySignatures)
585 {
586 EntityID e = kv.first;
588 {
590 settings.showNavigationOverlay = !settings.showNavigationOverlay;
591
592 SYSTEM_LOG << "World::ToggleNavigationOverlay: Navigation overlay "
593 << (settings.showNavigationOverlay ? "enabled" : "disabled") << "\n";
594 break;
595 }
596 }
597 }
598
599 /// Get collision overlay state
601 {
602 for (const auto& kv : m_entitySignatures)
603 {
604 EntityID e = kv.first;
606 {
608 return settings.showCollisionOverlay;
609 }
610 }
611 return false; // Default if no GridSettings entity exists
612 }
613
614 /// Get navigation overlay state
616 {
617 for (const auto& kv : m_entitySignatures)
618 {
619 EntityID e = kv.first;
621 {
623 return settings.showNavigationOverlay;
624 }
625 }
626 return false; // Default if no GridSettings entity exists
627 }
628
629 /// Synchronize grid settings with loaded level
630 /// Extracts map orientation and tile dimensions from LevelDefinition
631 /// and updates GridSettings_data (projection mode, cellSize, hexRadius)
632 /// Supports: orthogonal, isometric, hexagonal orientations
634
635 // Public for inspection/debug
636 std::unordered_map<EntityID, ComponentSignature> m_entitySignatures;
637
638private:
639 // Mapping: TypeID -> Component Pool
640 std::unordered_map<ComponentTypeID, std::unique_ptr<IComponentPool>> m_componentPools;
641
642 // Entity ID management
644 std::queue<EntityID> m_freeEntityIDs;
645 std::vector<EntityID> m_entities;
646
647 // System management
648 std::vector<std::unique_ptr<ECS_System>> m_systems;
649
650 // Notifies systems when an Entity's signature changes
652
653 // Helper functions for SFINAE-based special component registration (C++14 compatible)
654 // Helper function for SFINAE-based special component registration
655 template <typename T>
656 void HandleSpecialComponentRegistration(EntityID entity, typename std::enable_if<std::is_same<T, PlayerBinding_data>::value>::type* = nullptr)
657 {
660 }
661
662 template <typename T>
663 void HandleSpecialComponentRegistration(EntityID entity, typename std::enable_if<!std::is_same<T, PlayerBinding_data>::value>::type* = nullptr)
664 {
665 // Do nothing for other types
666 }
667
668 // Blueprint Editor notification hooks
671
672 // ========================================================================
673 // PHASE 2 & 3: Helper Methods for 6-Phase Level Loading
674 // ========================================================================
675
676 // Phase 2: Validate level prefabs (after normalization)
678
679 // Phase 4: Visual structure instantiation passes
682 InstantiationResult& result);
683
686 InstantiationResult& result);
687
688 // Phase 6: Relationship linking
691 InstantiationResult& result);
692
693 /// Unified entity instantiation helper (used by all Phase 5 passes)
694 /// Types are already normalized, performs direct lookup and instantiation
696 const std::shared_ptr<Olympe::Editor::EntityInstance>& entityInstance,
698 InstantiationResult::PassStats& stats);
699
700 // ========================================================================
701 // Player Entity Registration (for level-loaded players)
702 // ========================================================================
703
704 /// Register a player entity that was loaded from a level file
705 /// Validates required components and delegates to VideoGame for full setup
706 void RegisterPlayerEntity(EntityID entity);
707
708 // ========================================================================
709 // Helper Methods for Entity Instantiation
710 // ========================================================================
711
712 /// Extract custom properties from JSON overrides into LevelInstanceParameters
714 const nlohmann::json& overrides,
717 const PrefabBlueprint* prefab = nullptr);
718
719 /// Create a red placeholder entity for missing prefabs
722 InstantiationResult::PassStats& stats);
723
724 /// Extract prefab name from prefab path (removes path and extension)
725 std::string ExtractPrefabName(const std::string& prefabPath);
726
727
728public:
729 // Get tile chunks (for rendering system)
730 const std::vector<TileChunk>& GetTileChunks() const { return m_tileChunks; }
731
732 // Get tileset manager (for rendering system)
734
735 // Get map configuration for rendering
736 const std::string& GetMapOrientation() const { return m_mapOrientation; }
737 int GetTileWidth() const { return m_tileWidth; }
738 int GetTileHeight() const { return m_tileHeight; }
739
740 // Get isometric origin offset (computed from map bounds)
741 // This offset is applied to tile rendering to align tiles and entities in the same world space
742 float GetIsometricOriginX() const;
743 float GetIsometricOriginY() const;
744
745 // Set map bounds (for isometric origin calculation)
746 void SetMapBounds(int minTileX, int minTileY, int maxTileX, int maxTileY, int chunkOriginX, int chunkOriginY);
747
748 // Get chunk origin (for orthogonal/hex/staggered entity offset)
749 int GetChunkOriginX() const { return m_chunkOriginX; }
750 int GetChunkOriginY() const { return m_chunkOriginY; }
751
752
753 // Tile layer loading helper methods (internal use only)
754 void LoadTileLayer(const nlohmann::json& layerJson, InstantiationResult& result);
755 void LoadTileChunk(const nlohmann::json& chunkJson, const std::string& layerName,
756 int zOrder, const std::string& encoding);
757 void LoadTileData(const nlohmann::json& dataJson, const std::string& layerName,
758 int width, int height, int zOrder, const std::string& encoding);
759
760private:
762 std::vector<TileChunk> m_tileChunks;
763 std::string m_mapOrientation; // "orthogonal" or "isometric"
766 std::vector<std::unique_ptr<Level>> m_levels;
767
768 // Map bounds (for isometric origin calculation)
769 int m_minTileX = 0;
770 int m_minTileY = 0;
771 int m_maxTileX = 0;
772 int m_maxTileY = 0;
773
774 // Chunk origin (for orthogonal/hex/staggered entity offset)
777
778 // Cached isometric origin (computed once, used many times during rendering)
779 mutable float m_cachedIsometricOriginX = 0.0f;
780 mutable float m_cachedIsometricOriginY = 0.0f;
781 mutable bool m_isometricOriginCached = false;
782
783 // Custom layer counter (starts after predefined layers)
785};
Core ECS component definitions.
RenderLayer
Render layer enumeration for Z-ordering.
std::bitset< MAX_COMPONENTS > ComponentSignature
Definition ECS_Entity.h:31
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::uint64_t EntityID
Definition ECS_Entity.h:21
std::uint64_t ComponentTypeID
Definition ECS_Entity.h:27
EntityType
Definition GameObject.h:22
GameState
Definition GameState.h:7
@ GameState_Paused
void RegisterInputEntityWithManager(EntityID e)
Definition World.cpp:49
void AddComponent(EntityID entity, Args &&... args)
bool HasComponent(EntityID entity) const
T & GetComponent(EntityID entity)
static EventQueue & Get()
Definition EventQueue.h:34
void BeginFrame()
Definition EventQueue.h:56
Factory class for creating entities from prefab blueprints.
Manages tilesets loaded from Tiled maps.
Definition World.h:96
const std::vector< TilesetInfo > & GetTilesets() const
Get all loaded tilesets.
Definition World.h:172
void Clear()
Clear all loaded tilesets.
Definition World.cpp:1780
std::vector< TilesetInfo > m_tilesets
All loaded tilesets.
Definition World.h:175
void LoadTilesets(const nlohmann::json &tilesetsJson)
Load tilesets from JSON data.
Definition World.cpp:1805
bool GetTileTexture(uint32_t gid, SDL_Texture *&outTexture, SDL_Rect &outSrcRect, const TilesetInfo *&outTileset)
Get texture and source rect for a tile by GID.
Definition World.cpp:2149
Core ECS manager and world coordinator.
Definition World.h:210
void NotifyBlueprintEditorEntityCreated(EntityID entity)
Definition World.cpp:347
int GetTileHeight() const
Definition World.h:738
std::queue< EntityID > m_freeEntityIDs
Definition World.h:644
void ToggleCollisionOverlay()
Toggle collision overlay visibility.
Definition World.h:564
bool m_isometricOriginCached
Definition World.h:781
bool InstantiatePass1_VisualLayers(const Olympe::Editor::LevelDefinition &levelDef, InstantiationResult &result)
Definition World.cpp:1485
const std::vector< EntityID > & GetAllEntities() const
Get all active entity IDs.
Definition World.h:384
bool IsNavigationOverlayVisible()
Get navigation overlay state.
Definition World.h:615
int m_chunkOriginY
Definition World.h:776
EntityID CreateMissingPrefabPlaceholder(const Olympe::Editor::EntityInstance &entityInstance, InstantiationResult::PassStats &stats)
Create a red placeholder entity for missing prefabs.
Definition World.cpp:2724
int GetChunkOriginX() const
Definition World.h:749
std::vector< std::unique_ptr< Level > > m_levels
Definition World.h:766
EntityID InstantiateEntity(const std::shared_ptr< Olympe::Editor::EntityInstance > &entityInstance, PrefabFactory &factory, InstantiationResult::PassStats &stats)
Unified entity instantiation helper (used by all Phase 5 passes) Types are already normalized,...
Definition World.cpp:1387
void Initialize_ECS_Systems()
Definition World.cpp:87
void UnloadCurrentLevel()
Definition World.cpp:1302
bool LoadLevelFromTiled(const std::string &tiledMapPath)
Definition World.cpp:1006
bool IsCollisionOverlayVisible()
Get collision overlay state.
Definition World.h:600
void NotifyBlueprintEditorEntityDestroyed(EntityID entity)
Definition World.cpp:355
int m_minTileX
Definition World.h:769
void Render_ECS_Systems()
Definition World.cpp:185
void LoadTileLayer(const nlohmann::json &layerJson, InstantiationResult &result)
Definition World.cpp:1632
std::string ExtractPrefabName(const std::string &prefabPath)
Extract prefab name from prefab path (removes path and extension)
Definition World.cpp:2760
int m_tileWidth
Definition World.h:764
const std::vector< TileChunk > & GetTileChunks() const
Definition World.h:730
EntityID m_nextEntityID
Definition World.h:643
void LoadTileData(const nlohmann::json &dataJson, const std::string &layerName, int width, int height, int zOrder, const std::string &encoding)
Definition World.cpp:1737
void Process()
Definition World.h:257
void HandleSpecialComponentRegistration(EntityID entity, typename std::enable_if<!std::is_same< T, PlayerBinding_data >::value >::type *=nullptr)
Definition World.h:663
static World & Get()
Get singleton instance (short form)
Definition World.h:232
int m_maxTileX
Definition World.h:771
T & AddComponent(EntityID entity, Args &&... args)
Definition World.h:393
int m_minTileY
Definition World.h:770
bool HasComponent(EntityID entity) const
Definition World.h:451
bool IsEntityValid(EntityID entity) const
Definition World.h:376
void Render()
Definition World.h:271
void SyncGridWithLevel(const Olympe::Editor::LevelDefinition &levelDef)
Synchronize grid settings with loaded level Extracts map orientation and tile dimensions from LevelDe...
Definition World.cpp:364
void LoadTileChunk(const nlohmann::json &chunkJson, const std::string &layerName, int zOrder, const std::string &encoding)
Definition World.cpp:1682
bool LoadLevelDependencies(const nlohmann::json &levelJson)
Definition World.cpp:926
const std::vector< std::unique_ptr< Level > > & GetLevels() const
Definition World.h:284
std::unordered_map< ComponentTypeID, std::unique_ptr< IComponentPool > > m_componentPools
Definition World.h:640
void ValidateLevelPrefabs(const Olympe::Editor::LevelDefinition &levelDef)
Definition World.cpp:1361
void SetMapBounds(int minTileX, int minTileY, int maxTileX, int maxTileY, int chunkOriginX, int chunkOriginY)
Definition World.cpp:2795
T * GetSystem()
Definition World.h:244
RenderLayer GetDefaultLayerForType(EntityType type) const
Get the default render layer for an entity type Automatically assigns appropriate layer based on enti...
Definition World.h:473
TilesetManager m_tilesetManager
Definition World.h:761
void Notify_ECS_Systems(EntityID entity, ComponentSignature signature)
Definition World.cpp:206
T & GetComponent(EntityID entity)
Definition World.h:438
std::unordered_map< EntityID, ComponentSignature > m_entitySignatures
Definition World.h:636
RenderLayer CalculateLayerFromZOrder(float zOrder) const
Calculate layer index from zOrder value (for Tiled levels) Maps zOrder ranges to layer indices for pr...
Definition World.cpp:309
RenderLayer GetEntityLayer(EntityID entity) const
Get entity render layer.
Definition World.cpp:334
virtual ~World()
Destructor.
Definition World.cpp:82
void RemoveComponent(EntityID entity)
Definition World.h:422
void GenerateCollisionAndNavigationMaps(const Olympe::Tiled::TiledMap &tiledMap, const Olympe::Editor::LevelDefinition &levelDef)
Definition World.cpp:476
int GetChunkOriginY() const
Definition World.h:750
bool InstantiatePass2_SpatialStructure(const Olympe::Editor::LevelDefinition &levelDef, InstantiationResult &result)
Definition World.cpp:2248
int m_maxTileY
Definition World.h:772
float m_cachedIsometricOriginX
Definition World.h:779
void ToggleNavigationOverlay()
Toggle navigation overlay visibility.
Definition World.h:582
void RegisterPlayerEntity(EntityID entity)
Register a player entity that was loaded from a level file Validates required components and delegate...
Definition World.cpp:2777
const std::string & GetMapOrientation() const
Definition World.h:736
float m_cachedIsometricOriginY
Definition World.h:780
float GetIsometricOriginX() const
Definition World.cpp:2812
float GetIsometricOriginY() const
Definition World.cpp:2835
int m_tileHeight
Definition World.h:765
void ToggleGrid()
Toggle grid visibility.
Definition World.h:531
std::vector< std::unique_ptr< ECS_System > > m_systems
Definition World.h:648
std::vector< EntityID > m_entities
Definition World.h:645
void Process_ECS_Systems()
Definition World.cpp:176
EntityID CreateEntity()
Definition World.cpp:225
void RenderDebug_ECS_Systems()
Definition World.cpp:196
std::vector< TileChunk > m_tileChunks
Definition World.h:762
bool IsGridEnabled()
Get current grid state.
Definition World.h:549
int m_chunkOriginX
Definition World.h:775
int GetTileWidth() const
Definition World.h:737
void HandleSpecialComponentRegistration(EntityID entity, typename std::enable_if< std::is_same< T, PlayerBinding_data >::value >::type *=nullptr)
Definition World.h:656
int m_nextCustomLayerIndex
Definition World.h:784
void Add_ECS_System(std::unique_ptr< ECS_System > system)
Definition World.cpp:170
bool InstantiatePass5_Relationships(const Olympe::Editor::LevelDefinition &levelDef, InstantiationResult &result)
Definition World.cpp:2270
TilesetManager & GetTilesetManager()
Definition World.h:733
std::string m_mapOrientation
Definition World.h:763
static World & GetInstance()
Get singleton instance.
Definition World.h:222
void SetEntityLayer(EntityID entity, RenderLayer layer)
Set entity render layer (updates position.z)
Definition World.cpp:292
void DestroyEntity(EntityID entity)
Definition World.cpp:255
World()
Default constructor.
Definition World.cpp:54
int GetNextCustomLayerIndex()
Get next available custom layer index (for dynamic layers)
Definition World.h:521
void AddLevel(std::unique_ptr< Level > level)
Definition World.h:279
void ExtractCustomProperties(const nlohmann::json &overrides, LevelInstanceParameters &instanceParams, const Olympe::Editor::EntityInstance *entityInstance=nullptr, const PrefabBlueprint *prefab=nullptr)
Extract custom properties from JSON overrides into LevelInstanceParameters.
Definition World.cpp:2469
GameState GetState()
Definition GameState.cpp:15
nlohmann::json json
Represents a chunk of tiles for rendering.
Definition World.h:73
int zOrder
Render order (Z-coordinate)
Definition World.h:79
int height
Chunk height (in tiles)
Definition World.h:78
int x
Chunk X position (in tiles)
Definition World.h:75
TileChunk()
Default constructor.
Definition World.h:83
int width
Chunk width (in tiles)
Definition World.h:77
int y
Chunk Y position (in tiles)
Definition World.h:76
std::string layerName
Name of the source layer.
Definition World.h:74
std::vector< uint32_t > tileGIDs
Tile Global IDs (with flip flags)
Definition World.h:80
Information about a loaded tileset.
Definition World.h:106
int columns
Number of columns in atlas.
Definition World.h:112
std::string name
Tileset name.
Definition World.h:109
int tileoffsetX
Global X offset for all tiles.
Definition World.h:128
SDL_Texture * texture
Atlas texture (image-based)
Definition World.h:132
int imagewidth
Total atlas width.
Definition World.h:113
uint32_t firstgid
First Global ID in this tileset.
Definition World.h:107
int tileoffsetY
Global Y offset for all tiles.
Definition World.h:129
int imageheight
Total atlas height.
Definition World.h:114
TilesetInfo()
Default constructor with explicit initialization.
Definition World.h:141
int spacing
Spacing between tiles.
Definition World.h:116
int margin
Margin around atlas.
Definition World.h:115
int tileheight
Height of each tile.
Definition World.h:111
bool isCollection
True if collection tileset.
Definition World.h:117
std::map< uint32_t, SDL_Texture * > individualTiles
Per-tile textures.
Definition World.h:135
int tilewidth
Width of each tile.
Definition World.h:110
uint32_t lastgid
Last Global ID (firstgid + tilecount - 1)
Definition World.h:108
std::map< uint32_t, SDL_Rect > individualSrcRects
Per-tile source rects.
Definition World.h:136
std::vector< std::string > failedObjects
Definition World.h:329
PassStats pass2_spatialStructure
Definition World.h:339
PassStats pass5_relationships
Definition World.h:342
bool IsComplete() const
Definition World.h:366
PassStats pass3_staticObjects
Definition World.h:340
std::map< std::string, EntityID > entityRegistry
Definition World.h:344
std::vector< EntityID > sectors
Definition World.h:346
int GetTotalCreated() const
Definition World.h:350
PassStats pass1_visualLayers
Definition World.h:338
PassStats pass4_dynamicObjects
Definition World.h:341
std::map< int, EntityID > objectIdToEntity
Definition World.h:345
int GetTotalFailed() const
Definition World.h:359
PrefabRegistry prefabRegistry
Definition World.h:312
DataManager::LevelPreloadResult preloadResult
Definition World.h:313
PreloadStats stats
Definition World.h:314
std::vector< std::string > errors
Definition World.h:316
std::vector< std::string > missingPrefabs
Definition World.h:315
#define SYSTEM_LOG