Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
/home/runner/work/Olympe-Engine/Olympe-Engine/Source/World.h
// Create entity
// Add components
pos.position = Vector(100, 200, 0);
// Query entities
auto entities = World::Get().GetEntitiesWithComponents<Position_data, Sprite_data>();
std::uint64_t EntityID
Definition ECS_Entity.h:21
static World & Get()
Get singleton instance (short form)
Definition World.h:232
T & AddComponent(EntityID entity, Args &&... args)
Definition World.h:393
EntityID CreateEntity()
Definition World.cpp:225
Position component for spatial location.
Vector position
2D/3D position vector
/**
* @file World.h
* @brief World and ECS Manager for Olympe Engine
* @author Nicolas Chereau
* @date 2025
* @version 2.0
*
* @details
* This file contains the World class which manages the Entity-Component-System
* architecture, level loading, and game state. The World is a singleton that
* coordinates all game entities, components, and systems.
*
* Key responsibilities:
* - Entity lifecycle management (create, destroy, query)
* - Component storage and retrieval
* - System execution coordination
* - Level loading from Tiled maps
* - Tile rendering and tileset management
*
* @note World purpose: Manage the overall game world, including object management,
* level handling, and ECS architecture.
*/
#pragma once
#include <vector>
#include <memory>
#include <unordered_map>
#include <queue>
#include <type_traits>
#include "Level.h"
#include "GameState.h"
// Include ECS related headers
#include "Ecs_Entity.h"
#include "ECS_Components.h"
#include "ECS_Systems.h"
#include "ECS_Register.h" // Include the implementation of ComponentPool
#include "PrefabScanner.h"
#include "PrefabFactory.h"
// JSON library for tile layer loading
#include "third_party/nlohmann/json.hpp"
// Forward declarations for 3-Phase Level Loading
//struct PrefabRegistry;
namespace Olympe {
namespace Tiled {
struct LevelParseResult;
struct TiledMap;
}
namespace Editor {
struct LevelDefinition;
struct EntityInstance;
}
}
// ========================================================================
// TILE LAYER SUPPORT
// ========================================================================
/**
* @struct TileChunk
* @brief Represents a chunk of tiles for rendering
*
* Tile chunks are used to batch tile rendering for performance.
* Each chunk contains a grid of tiles from a single layer.
*/
struct TileChunk
{
std::string layerName; ///< Name of the source layer
int x; ///< Chunk X position (in tiles)
int y; ///< Chunk Y position (in tiles)
int width; ///< Chunk width (in tiles)
int height; ///< Chunk height (in tiles)
int zOrder; ///< Render order (Z-coordinate)
std::vector<uint32_t> tileGIDs; ///< Tile Global IDs (with flip flags)
/** @brief Default constructor */
TileChunk() : x(0), y(0), width(0), height(0), zOrder(0) {}
};
/**
* @class TilesetManager
* @brief Manages tilesets loaded from Tiled maps
*
* Handles both image-based tilesets (single texture atlas) and
* collection tilesets (individual tile images).
*
* Provides tile lookup by Global ID (GID) and texture access.
*/
{
public:
/**
* @struct TilesetInfo
* @brief Information about a loaded tileset
*
* Stores tileset properties including dimensions, offsets, and textures.
* Critical for proper tile rendering with correct positioning.
*/
struct TilesetInfo
{
uint32_t firstgid; ///< First Global ID in this tileset
uint32_t lastgid; ///< Last Global ID (firstgid + tilecount - 1)
std::string name; ///< Tileset name
int tilewidth; ///< Width of each tile
int tileheight; ///< Height of each tile
int columns; ///< Number of columns in atlas
int imagewidth; ///< Total atlas width
int imageheight; ///< Total atlas height
int margin; ///< Margin around atlas
int spacing; ///< Spacing between tiles
bool isCollection; ///< True if collection tileset
// ====================================================================
// CRITICAL: Global tile offset for this tileset
// These values come from the .tsx/.tsj file's <tileoffset> element
// ALL tiles in this tileset inherit these offset values for rendering
// Examples from Olympe tilesets:
// - Trees.tsj: tileoffsetX = -100, tileoffsetY = 0
// - Tiles iso cube.tsx: tileoffsetX = 0, tileoffsetY = 26
// - tiles-iso-1.tsx: tileoffsetX = 0, tileoffsetY = 0 (default)
// ====================================================================
int tileoffsetX; ///< Global X offset for all tiles
int tileoffsetY; ///< Global Y offset for all tiles
// Image-based tileset
SDL_Texture* texture; ///< Atlas texture (image-based)
// Collection tileset (individual tiles)
std::map<uint32_t, SDL_Texture*> individualTiles; ///< Per-tile textures
std::map<uint32_t, SDL_Rect> individualSrcRects; ///< Per-tile source rects
/**
* @brief Default constructor with explicit initialization
*/
isCollection(false), tileoffsetX(0), tileoffsetY(0), texture(nullptr) {
}
};
/**
* @brief Clear all loaded tilesets
*/
void Clear();
/**
* @brief Load tilesets from JSON data
* @param tilesetsJson JSON array of tileset definitions
*/
void LoadTilesets(const nlohmann::json& tilesetsJson);
/**
* @brief Get texture and source rect for a tile by GID
* @param gid Global tile ID
* @param outTexture Output texture pointer
* @param outSrcRect Output source rectangle
* @param outTileset Output tileset info pointer
* @return True if tile was found
*/
bool GetTileTexture(uint32_t gid, SDL_Texture*& outTexture, SDL_Rect& outSrcRect, const TilesetInfo*& outTileset);
/**
* @brief Get all loaded tilesets
* @return Reference to tileset vector
*/
const std::vector<TilesetInfo>& GetTilesets() const { return m_tilesets; }
private:
std::vector<TilesetInfo> m_tilesets; ///< All loaded tilesets
};
/**
* @class World
* @brief Core ECS manager and world coordinator
*
* The World class is the central hub for the Entity-Component-System architecture.
* It manages all entities, components, systems, and level loading.
*
* Key features:
* - Entity creation and destruction
* - Component addition, removal, and queries
* - System registration and execution
* - Level loading from Tiled maps (.tmj/.tmx)
* - Tile rendering with multiple tilesets
* - Collision and navigation mesh management
*
* @note Singleton class - use World::Get() to access
*
* @example
* @code
* // Create entity
* EntityID player = World::Get().CreateEntity();
*
* // Add components
* Position_data pos;
* pos.position = Vector(100, 200, 0);
* World::Get().AddComponent<Position_data>(player, pos);
*
* // Query entities
* auto entities = World::Get().GetEntitiesWithComponents<Position_data, Sprite_data>();
* @endcode
*/
class World
{
public:
/** @brief Default constructor */
World();
/** @brief Destructor */
virtual ~World();
/**
* @brief Get singleton instance
* @return Reference to World singleton
*/
static World& GetInstance()
{
static World instance;
return instance;
}
/**
* @brief Get singleton instance (short form)
* @return Reference to World singleton
*/
static World& Get() { return GetInstance(); }
//---------------------------------------------------------------
// ECS Systems
void Add_ECS_System(std::unique_ptr<ECS_System> system);
// Get a specific system by type
template <typename T>
T* GetSystem()
{
for (auto& system : m_systems)
{
T* castedSystem = dynamic_cast<T*>(system.get());
if (castedSystem)
return castedSystem;
}
return nullptr;
}
//---------------------------------------------------------------
// Main processing loop called each frame: events are processed first (async), then stages in order
void Process()
{
//0) Swap EventQueue buffers to make previous frame's events readable
// This is the single point per frame where write buffer becomes read buffer
// check global game state
bool paused = (state == GameState::GameState_Paused);
// ECS Processing Systems
}
//---------------------------------------------------------------------------------------------
void Render()
{
// ECS Rendering Systems
}
//---------------------------------------------------------------------------------------------
// Level management
void AddLevel(std::unique_ptr<Level> level)
{
if (level) m_levels.push_back(std::move(level));
}
const std::vector<std::unique_ptr<Level>>& GetLevels() const { return m_levels; }
// Tiled MapEditor integration
bool LoadLevelFromTiled(const std::string& tiledMapPath);
// NEW: Load and prepare all behavior tree dependencies for a level
bool LoadLevelDependencies(const nlohmann::json& levelJson);
// Generate collision and navigation maps from TMJ/TMX level data
// ========================================================================
// PHASE 2 & 3: Advanced Level Loading Structures
// ========================================================================
struct Phase2Result
{
struct PreloadStats
{
};
PreloadStats stats;
std::vector<std::string> missingPrefabs;
std::vector<std::string> errors;
bool success;
Phase2Result() : success(false) {}
};
struct InstantiationResult
{
struct PassStats
{
int failed;
std::vector<std::string> failedObjects;
bool IsSuccess() const { return failed == 0; }
};
bool success;
PassStats pass1_visualLayers;
std::map<std::string, EntityID> entityRegistry; // name -> entity ID
std::map<int, EntityID> objectIdToEntity; // Tiled object ID -> entity ID
std::vector<EntityID> sectors;
int GetTotalCreated() const
{
}
int GetTotalFailed() const
{
}
bool IsComplete() const
{
return success && GetTotalFailed() == 0;
}
};
// -------------------------------------------------------------
// ECS Entity Management
void DestroyEntity(EntityID entity);
bool IsEntityValid(EntityID entity) const
{
return m_entitySignatures.find(entity) != m_entitySignatures.end();
}
/**
* @brief Get all active entity IDs
* @return Vector of all entity IDs in the world
*/
const std::vector<EntityID>& GetAllEntities() const
{
return m_entities;
}
// -------------------------------------------------------------
// Component Management (Pool Facade)
// Add Component: takes type (T) and constructor arguments
template <typename T, typename... Args>
T& AddComponent(EntityID entity, Args&&... args)
{
// 1. Instantiate the pool if it's the first time we add this type
{
m_componentPools[typeID] = std::make_unique<ComponentPool<T>>();
}
// 2. Get the pool and add the component
auto* pool = static_cast<ComponentPool<T>*>(m_componentPools[typeID].get());
// Creation and adding of the component using perfect forwarding
pool->AddComponent(entity, std::forward<Args>(args)...);
// 3. Update the Entity's Signature
m_entitySignatures[entity].set(typeID, true);
// 4. Notify Systems about the signature change
// 5. Special handling: Register input entities with InputsManager
return pool->GetComponent(entity);
}
template <typename T>
{
if (m_componentPools.find(typeID) == m_componentPools.end()) return;
// 1. Remove from the pool
m_componentPools[typeID]->RemoveComponent(entity);
// 2. Update the Entity's Signature
m_entitySignatures[entity].set(typeID, false);
// 3. Notify Systems
}
template <typename T>
{
{
throw std::runtime_error("Component pool not registered.");
}
auto* pool = static_cast<ComponentPool<T>*>(m_componentPools[typeID].get());
return pool->GetComponent(entity);
}
template <typename T>
bool HasComponent(EntityID entity) const
{
// Fast check using the signature
if (m_entitySignatures.count(entity) && m_entitySignatures.at(entity).test(typeID))
{
// Delegate the final check to the specific Pool
if (m_componentPools.count(typeID)) {
auto* pool = static_cast<ComponentPool<T>*>(m_componentPools.at(typeID).get());
return pool->HasComponent(entity);
}
}
return false;
}
// ========================================================================
// Layer Management API
// ========================================================================
/// Get the default render layer for an entity type
/// Automatically assigns appropriate layer based on entity classification
{
switch (type)
{
return RenderLayer::Characters; // Same layer as players for proper overlap
return RenderLayer::Ground; // Invisible helpers at ground level
default:
}
}
/// Set entity render layer (updates position.z)
void SetEntityLayer(EntityID entity, RenderLayer layer);
/// Calculate layer index from zOrder value (for Tiled levels)
/// Maps zOrder ranges to layer indices for proper depth sorting
/// Get entity render layer
/// Get next available custom layer index (for dynamic layers)
{
}
// ========================================================================
// Grid Management
// ========================================================================
/// Toggle grid visibility
void ToggleGrid()
{
for (const auto& kv : m_entitySignatures)
{
EntityID e = kv.first;
{
settings.enabled = !settings.enabled;
SYSTEM_LOG << "World::ToggleGrid: Grid "
<< (settings.enabled ? "enabled" : "disabled") << "\n";
break;
}
}
}
/// Get current grid state
{
for (const auto& kv : m_entitySignatures)
{
EntityID e = kv.first;
{
return settings.enabled;
}
}
return false; // Default if no GridSettings entity exists
}
/// Toggle collision overlay visibility
{
for (const auto& kv : m_entitySignatures)
{
EntityID e = kv.first;
{
settings.showCollisionOverlay = !settings.showCollisionOverlay;
SYSTEM_LOG << "World::ToggleCollisionOverlay: Collision overlay "
<< (settings.showCollisionOverlay ? "enabled" : "disabled") << "\n";
break;
}
}
}
/// Toggle navigation overlay visibility
{
for (const auto& kv : m_entitySignatures)
{
EntityID e = kv.first;
{
settings.showNavigationOverlay = !settings.showNavigationOverlay;
SYSTEM_LOG << "World::ToggleNavigationOverlay: Navigation overlay "
<< (settings.showNavigationOverlay ? "enabled" : "disabled") << "\n";
break;
}
}
}
/// Get collision overlay state
{
for (const auto& kv : m_entitySignatures)
{
EntityID e = kv.first;
{
return settings.showCollisionOverlay;
}
}
return false; // Default if no GridSettings entity exists
}
/// Get navigation overlay state
{
for (const auto& kv : m_entitySignatures)
{
EntityID e = kv.first;
{
return settings.showNavigationOverlay;
}
}
return false; // Default if no GridSettings entity exists
}
/// Synchronize grid settings with loaded level
/// Extracts map orientation and tile dimensions from LevelDefinition
/// and updates GridSettings_data (projection mode, cellSize, hexRadius)
/// Supports: orthogonal, isometric, hexagonal orientations
// Public for inspection/debug
std::unordered_map<EntityID, ComponentSignature> m_entitySignatures;
private:
// Mapping: TypeID -> Component Pool
std::unordered_map<ComponentTypeID, std::unique_ptr<IComponentPool>> m_componentPools;
// Entity ID management
std::queue<EntityID> m_freeEntityIDs;
std::vector<EntityID> m_entities;
// System management
std::vector<std::unique_ptr<ECS_System>> m_systems;
// Notifies systems when an Entity's signature changes
// Helper functions for SFINAE-based special component registration (C++14 compatible)
// Helper function for SFINAE-based special component registration
template <typename T>
void HandleSpecialComponentRegistration(EntityID entity, typename std::enable_if<std::is_same<T, PlayerBinding_data>::value>::type* = nullptr)
{
}
template <typename T>
void HandleSpecialComponentRegistration(EntityID entity, typename std::enable_if<!std::is_same<T, PlayerBinding_data>::value>::type* = nullptr)
{
// Do nothing for other types
}
// Blueprint Editor notification hooks
// ========================================================================
// PHASE 2 & 3: Helper Methods for 6-Phase Level Loading
// ========================================================================
// Phase 2: Validate level prefabs (after normalization)
// Phase 4: Visual structure instantiation passes
InstantiationResult& result);
InstantiationResult& result);
// Phase 6: Relationship linking
InstantiationResult& result);
/// Unified entity instantiation helper (used by all Phase 5 passes)
/// Types are already normalized, performs direct lookup and instantiation
const std::shared_ptr<Olympe::Editor::EntityInstance>& entityInstance,
InstantiationResult::PassStats& stats);
// ========================================================================
// Player Entity Registration (for level-loaded players)
// ========================================================================
/// Register a player entity that was loaded from a level file
/// Validates required components and delegates to VideoGame for full setup
// ========================================================================
// Helper Methods for Entity Instantiation
// ========================================================================
/// Extract custom properties from JSON overrides into LevelInstanceParameters
const nlohmann::json& overrides,
const PrefabBlueprint* prefab = nullptr);
/// Create a red placeholder entity for missing prefabs
InstantiationResult::PassStats& stats);
/// Extract prefab name from prefab path (removes path and extension)
std::string ExtractPrefabName(const std::string& prefabPath);
public:
// Get tile chunks (for rendering system)
const std::vector<TileChunk>& GetTileChunks() const { return m_tileChunks; }
// Get tileset manager (for rendering system)
// Get map configuration for rendering
const std::string& GetMapOrientation() const { return m_mapOrientation; }
int GetTileWidth() const { return m_tileWidth; }
int GetTileHeight() const { return m_tileHeight; }
// Get isometric origin offset (computed from map bounds)
// This offset is applied to tile rendering to align tiles and entities in the same world space
float GetIsometricOriginX() const;
float GetIsometricOriginY() const;
// Set map bounds (for isometric origin calculation)
void SetMapBounds(int minTileX, int minTileY, int maxTileX, int maxTileY, int chunkOriginX, int chunkOriginY);
// Get chunk origin (for orthogonal/hex/staggered entity offset)
int GetChunkOriginX() const { return m_chunkOriginX; }
int GetChunkOriginY() const { return m_chunkOriginY; }
// Tile layer loading helper methods (internal use only)
void LoadTileLayer(const nlohmann::json& layerJson, InstantiationResult& result);
void LoadTileChunk(const nlohmann::json& chunkJson, const std::string& layerName,
int zOrder, const std::string& encoding);
void LoadTileData(const nlohmann::json& dataJson, const std::string& layerName,
int width, int height, int zOrder, const std::string& encoding);
private:
std::vector<TileChunk> m_tileChunks;
std::string m_mapOrientation; // "orthogonal" or "isometric"
std::vector<std::unique_ptr<Level>> m_levels;
// Map bounds (for isometric origin calculation)
int m_minTileX = 0;
int m_minTileY = 0;
int m_maxTileX = 0;
int m_maxTileY = 0;
// Chunk origin (for orthogonal/hex/staggered entity offset)
int m_chunkOriginX = 0;
int m_chunkOriginY = 0;
// Cached isometric origin (computed once, used many times during rendering)
mutable float m_cachedIsometricOriginX = 0.0f;
mutable float m_cachedIsometricOriginY = 0.0f;
mutable bool m_isometricOriginCached = false;
// Custom layer counter (starts after predefined layers)
};
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 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
int m_maxTileX
Definition World.h:771
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
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
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