-
Notifications
You must be signed in to change notification settings - Fork 2
DataTable System
Data-driven table system for loading, querying, and hot-reloading structured game data from CSV and JSON files.
Source: SparkEngine/Source/Engine/DataTable/DataTableSystem.h
The DataTable system provides a lightweight, schema-flexible way to define game data (items, enemies, levels, balance parameters) in external CSV or JSON files. Tables are loaded at runtime, columns are auto-typed, and rows are queryable by ID or arbitrary column filters.
All values are stored internally as strings and converted on access via typed getters (GetInt, GetFloat, GetBool, GetString). Column types (String, Int, Float, Bool, Vector3) are auto-detected by scanning data values during load. The CSV parser is RFC 4180 compliant, handling quoted fields and embedded commas.
The DataTableRegistry singleton manages named tables, supports loading from disk with auto-detection of CSV vs JSON by file extension, and provides hot-reload via ReloadTable() which re-reads from the original source path.
DataTableRegistry (singleton)
+-- "weapons" --> DataTable (columns + rows + index)
+-- "enemies" --> DataTable
+-- "levels" --> DataTable
...
DataTable
+-- vector<DataColumn> (name, type, default)
+-- vector<DataRow> (string -> string maps)
+-- unordered_map index (ID column -> row index)
| Class | Description |
|---|---|
DataRow |
A single row of values with typed accessors (GetInt, GetFloat, etc.) |
DataTable |
A collection of rows and columns with CSV/JSON load/save and querying |
DataTableRegistry |
Singleton manager for named tables with file loading and hot-reload |
DataColumn |
Column definition with name, type, and default value |
id,name,damage,firerate,automatic
pistol,Pistol,25,2.5,false
rifle,Assault Rifle,30,10.0,true
shotgun,Shotgun,80,1.2,false
sniper,Sniper Rifle,100,0.8,false[
{ "id": "zombie", "name": "Zombie", "health": 100, "speed": 2.5, "aggressive": true },
{ "id": "skeleton", "name": "Skeleton", "health": 60, "speed": 4.0, "aggressive": true }
]auto& registry = Spark::Data::DataTableRegistry::GetInstance();
registry.Initialize();
// Load from file (auto-detects CSV vs JSON)
registry.LoadTableFromFile("weapons", "data/weapons.csv");
// Query by ID
auto* table = registry.GetTable("weapons");
auto* row = table->GetRow("rifle");
int damage = row->GetInt("damage"); // 30
float rate = row->GetFloat("firerate"); // 10.0f
bool isAuto = row->GetBool("automatic"); // true
// Find all rows matching a value
auto shotguns = table->FindRows("automatic", "false");
// Hot-reload after editing the file
registry.ReloadTable("weapons");
// Validate schema
auto errors = table->Validate();| Method | Description |
|---|---|
LoadFromCSV(string) |
Parse CSV content with auto-typed columns |
LoadFromJSON(string) |
Parse JSON array of objects |
SaveToCSV() / SaveToJSON() |
Export table to string |
AddRow(DataRow) |
Add a row (fills defaults, indexes by ID) |
RemoveRow(string) |
Remove a row by its ID value |
GetRow(string) |
Look up a row by ID column value |
FindRows(col, value) |
Find all rows where a column matches a value |
Validate() |
Check rows against column type schema |
| Method | Description |
|---|---|
Initialize() / Shutdown() |
Lifecycle management |
LoadTableFromFile(name, path) |
Load from disk (CSV/JSON auto-detected) |
RegisterTable(name, table) |
Register a pre-built table |
GetTable(name) |
Retrieve a table by name |
ReloadTable(name) |
Hot-reload from original source file |
GetTableNames() |
List all registered table names |
| Method | Description |
|---|---|
GetString(col) |
Get string value |
GetInt(col) |
Get int value (0 if absent) |
GetFloat(col) |
Get float value (0.0f if absent) |
GetBool(col) |
Get bool ("true"/"1" = true) |
SetValue(col, val) |
Set a column value |
| Option | Description |
|---|---|
| ID column | First column by default, or set via DataTable("columnName") constructor |
| Column types | Auto-detected: Bool, Int, Float, String
|
| Hot-reload | Call ReloadTable() -- re-reads from GetSourcePath()
|
- Loot and Crafting System -- Uses data tables for item definitions
- Localization System -- String tables for translated text
Published from ad9c3c1953cc. Edit the canonical source in wiki/.
- Documentation
- Docs route
- Wiki index
- Guides
- Tutorials
- Samples
- Examples
- API Reference
- API route
- Reference
- Build Guide
- Dependencies
- FAQ
- Changelog
- Roadmap
- Contributing
- Code of Conduct
- Home
- FAQ
- Getting Started
- Quick-Start Tutorial
- Making Your First Game
- Making Your First Multiplayer Game
- Artist Workflow Guide
- Editor Walkthrough
- Migration Guide
- How SparkEngine Works
- Architecture Overview
- Engine Architecture Flowchart
- Creating a Game Module
- Game Modules (catalog)
- Entity Component System
- Rendering and Graphics
- Physics
- Cloth Simulation
- Audio
- Input System
- Camera System
- Scripting with AngelScript
- Visual Scripting
- AI and Navigation
- Animation
- 2D Systems
- Networking
- Dedicated Server
- Multiplayer Quick Start
- Area Server Architecture
- Scene Management
- Large World Support
- Collaborative Editing
- Coroutine System
- Event System
- Event Response System
- Job System
- UI System
- UI Layout Extensions
- Localization
- Dialogue System
- Destruction System
- Replay System
- Achievement System
- Loading System
- Mod System
- Content Delivery
- Tween System
- Memory Integrity
- Gameplay Systems
- Terrain and Procedural Generation
- Save System
- Persistence System
- Day Night Cycle and Weather
- Cinematic Sequencer
- Runtime Prefabs
- SparkEditor
- Editor Tutorials
- SparkConsole
- SparkDaemon
- Shader Pipeline
- Asset Pipeline
- Asset Validation
- Asset Migration
- Game Packaging
- Online Services
- DataTable System
- Loot and Crafting System
- CSG System
- Font System
- Timer Manager
- Movie Render Pipeline
- HLOD and World Partition
- Remote Debug System
- Selection Manager
- Asset Dependency Graph
- Editor Automation
- File Watcher
- Project Templates
- System Requirements
- VR Support
- Mobile Platform
- Accessibility
- Platform Input
- Cross-Compilation: Wine Testing
- RHI Abstraction Layer
- D3D11 Backend
- D3D12 Backend
- Vulkan Backend
- OpenGL Backend
- Metal Backend
- DXR Raytracing
- Hybrid Ray Tracing
- Upscaling (DLSS/FSR)
- Render Graph
- Shader Graph
- GPU Particles
- GPU-Driven Rendering
- Volumetric Fog
- Volumetric Clouds
- Global Illumination
- Virtual Texturing
- Water Rendering
- Clustered Lighting
- Material System
- Post-Processing
- Shadow System
- Particle System
- Decal System
- Sky and Atmosphere
- Foliage System
- Mesh Shaders
- Neural Rendering
- Configuration Reference
- Performance Tips
- Benchmark Framework
- Threading Model
- Memory Safety
- Memory Management Patterns
- Build System and CMake Modules
- Profiler and Debugging
- Performance Profiling Guide
- Telemetry System
- Golden Image Testing
- Utilities
- Testing
- Codebase Statistics
- Codebase Health
- Error Handling Patterns
- Hot Reload Overview
- Troubleshooting
- Contributing
- Workflow Patterns
- Build Optimizations
- CI Reproducible Builds
- GitHub API and PR Checks
- Git Rebase Conflicts
- Clang-Format
- Code Quality Violations
- AI Bloat Pattern
- MinGW + Wine Cross-Compilation
- Live Editor Testing
- Engine & Renderer Landscape
- DuetOS Portability Catalog
- Five-Engine Analysis
- Eleven-Engine Analysis
- ThorVG / Unity Graphics Analysis
- Advanced Techniques Catalog
- Third-Party Library Evaluation
- Engine Viability Evaluation
- Engine Feature Recommendations
- Project Recommendations
- Mac Compatibility Analysis
- Codebase Observations
- Codebase Bloat Audit
- Test Suite Audit
- Documentation Coverage Audit
- ThirdParty Dependencies Audit
- Load Test Baseline
- Gameplay Systems Status
- SparkGame Module Status
- Stub and Abandoned Features
- Memory Integrity System
- Memory Safety Evaluation
- Hardware Acceleration Systems
- Jolt Physics Integration
- GPU/CPU Separation Plan
- Daemon Services Architecture
- Reflection & Polymorphism Refactoring Plan
- SparkBuild In-Tree
- Wine No-JobSystem Breakthrough
- Wine Role and Fallback Tiers