GroveEngine/CLAUDE.md
StillHammer 0540fbf526 fix: Resolve bgfx Frame 1 crash on Windows DLL + MinGW GCC 15 compatibility
- Add BGFX_CONFIG_MULTITHREADED=0 to fix TLS crash when bgfx runs from DLL
- Add -include stdint.h for MinGW GCC 15+ compatibility with bgfx third-party code
- Guard SDL2-dependent visual tests with if(SDL2_FOUND)
- Clean up debug logging in BgfxDevice::frame() and BgfxRendererModule::process()
- Re-enable all modules in test_full_stack_interactive.cpp
- Add grove::fs namespace for cross-platform filesystem operations
- Add InputModule C export for feedEvent across DLL boundary

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 11:03:06 +07:00

4.8 KiB

GroveEngine - Claude Code Context

Project Overview

GroveEngine is a C++17 hot-reload module system for game engines. It supports dynamic loading/unloading of modules (.so) with state preservation during hot-reload.

Documentation

For developers using GroveEngine:

  • DEVELOPER_GUIDE.md - Complete guide to building applications with GroveEngine (modules, IIO topics, examples)
  • USER_GUIDE.md - Core module system, hot-reload, IIO communication basics

Module-specific:

  • BgfxRenderer README - 2D rendering module (sprites, text, tilemap, particles)
  • InputModule README - Input handling (mouse, keyboard, gamepad)
  • UIModule - User interface system (buttons, panels, scrolling, tooltips)

Available Modules

Module Status Description Build Flag
BgfxRenderer Phase 7-8 Complete 2D rendering (sprites, text, tilemap, particles) -DGROVE_BUILD_BGFX_RENDERER=ON
UIModule Phase 7 Complete UI widgets (buttons, panels, scrolling, tooltips) -DGROVE_BUILD_UI_MODULE=ON
InputModule Production Ready Input handling (mouse, keyboard, SDL backend) -DGROVE_BUILD_INPUT_MODULE=ON

Integration: All modules communicate via IIO topics. See DEVELOPER_GUIDE.md for complete IIO topics reference.

Build & Test

# Build core only
cmake -B build && cmake --build build -j4

# Build with all modules
cmake -B build -DGROVE_BUILD_BGFX_RENDERER=ON -DGROVE_BUILD_UI_MODULE=ON -DGROVE_BUILD_INPUT_MODULE=ON
cmake --build build -j4

# Run all tests (23+ tests)
cd build && ctest --output-on-failure

# Build with ThreadSanitizer
cmake -DGROVE_ENABLE_TSAN=ON -B build-tsan
cmake --build build-tsan -j4

Architecture

Key Components

  • ModuleLoader: Handles dlopen/dlclose of .so modules with hot-reload support
  • SequentialModuleSystem: Single-threaded module execution for testing
  • IntraIOManager: Inter-module communication with pub/sub routing
  • TopicTree: O(k) topic matching with wildcard support

Thread Safety Patterns

See docs/coding_guidelines.md for detailed synchronization guidelines.

DO:

// Multiple mutexes - use scoped_lock (deadlock-free)
std::scoped_lock lock(mutex1, mutex2);

// Read-heavy data - use shared_mutex
std::shared_lock readLock(sharedMutex);   // concurrent reads
std::unique_lock writeLock(sharedMutex);  // exclusive write

DON'T:

// NEVER nest lock_guard - causes deadlock
std::lock_guard lock1(mutex1);
std::lock_guard lock2(mutex2);  // DEADLOCK RISK

ModuleLoader Usage

  • Each ModuleLoader instance manages ONE module lifecycle
  • Don't reuse loader for multiple independent modules (causes SEGFAULT)
  • reload() safely handles state extraction and library reload
  • load(path, name, isReload=true) for hot-reload with cache bypass

Known Issues

  • TankModule.h linter bug: A linter sometimes merges lines 35-36. If build fails with "logger not declared", check this file.

Test Categories

Test # Name Duration Description
1-10 scenario_* ~0.01s Basic scenarios
11 ProductionHotReload ~12s Full hot-reload cycle
12 ChaosMonkey ~41s Stress testing
13 StressTest ~180s Heavy load
15 MemoryLeakHunter ~135s 200 reload cycles
19 CrossSystemIntegration ~4s Multi-system test

Module Architecture Quick Reference

BgfxRenderer

  • RHI Layer: Abstracts bgfx calls (RHIDevice.h, BgfxDevice.cpp)
  • RenderGraph: Topological sort with Kahn's algorithm for pass ordering
  • CommandBuffer: Records commands, executed by device at frame end
  • IIO Topics: render:sprite, render:text, render:tilemap, render:particle, render:camera, render:clear, render:debug/*

UIModule

  • UIRenderer: Publishes render commands to BgfxRenderer via IIO (layer 1000+)
  • Widgets: UIButton, UIPanel, UILabel, UICheckbox, UISlider, UITextInput, UIProgressBar, UIImage, UIScrollPanel, UITooltip
  • IIO Topics: Consumes input:*, publishes ui:click, ui:action, ui:value_changed, etc.

InputModule

  • Backends: SDLBackend (mouse, keyboard, gamepad Phase 2)
  • Thread-safe: Event buffering with lock-free design
  • IIO Topics: input:mouse:*, input:keyboard:*, input:gamepad:*

Debugging Tools

# ThreadSanitizer (detects data races, deadlocks)
cmake -DGROVE_ENABLE_TSAN=ON -B build-tsan

# Helgrind (alternative deadlock detector)
cmake -DGROVE_ENABLE_HELGRIND=ON -B build
make helgrind