Common Systems Documentation
This section covers systems and components shared between the R-Type client and server.
📚 Documentation Index
Configuration & Data
- Level Configuration
- JSON-based level definitions
- Wave and enemy spawning system
- Design patterns and examples
- Performance considerations
Resource Management
- Asset Management
- Embedded resource system
- TextureManager (sprites/images)
- SoundManager (audio/music)
- Build integration and optimization
Gameplay Systems
- Replay System
- Recording during gameplay
- Binary file format (.rtr)
- Playback with full controls
- Performance and best practices
🎯 Quick Links
For Game Designers
- Creating Levels: Level Configuration Guide
- Adding Assets: Asset Management
- Testing Replays: Replay System Usage
For Developers
- Level Parsing: WaveLoader Implementation
- Asset Loading: TextureManager & SoundManager
- Replay Recording: ReplayRecorder API
For System Architects
- Data Formats: JSON Schema & .rtr Format
- Memory Usage: Performance Analysis
- File I/O: Recording Flow
🏗️ System Architecture
┌─────────────────────────────────────────────────────┐
│ Common Layer │
├─────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌────────────┐ │
│ │ Level │ │ Asset │ │ Replay │ │
│ │ Config │ │ Manager │ │ System │ │
│ │ (JSON) │ │ (Embedded) │ │ (.rtr) │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬─────┘ │
│ │ │ │ │
├─────────┼────────────────┼────────────────┼───────┤
│ │ │ │ │
│ ┌──────▼──────┐ ┌──────▼──────┐ ┌──────▼─────┐ │
│ │ Server │ │ Client │ │ Client │ │
│ │ (Waves/AI) │ │ (Graphics) │ │ (Viewer) │ │
│ └─────────────┘ └─────────────┘ └────────────┘ │
└─────────────────────────────────────────────────────┘
📋 Feature Matrix
| Feature | Client | Server | Common |
|---|---|---|---|
| Level Definition (JSON) | ❌ | ✅ | ✅ |
| Wave Management | ❌ | ✅ | ✅ |
| Texture Loading | ✅ | ❌ | ✅ |
| Sound Manager | ✅ | ❌ | ✅ |
| Replay Recording | ✅ | ❌ | ✅ |
| Replay Playback | ✅ | ❌ | ✅ |
| Asset Embedding | ✅ | ❌ | ✅ |
🔧 Development Workflow
Adding a New Level
- Create JSON file:
levels/level_XX.json - Define waves and enemies: Follow schema
- Validate syntax:
cat level_XX.json | jq empty - Test in-game: Restart server, play through level
- Iterate balance: Adjust spawn timing, enemy counts
Adding New Assets
- Place files: Put in
assets/sprites/orassets/sound/ - Rebuild: CMake will embed assets automatically
- Load at runtime: Use TextureManager/SoundManager
- Test rendering: Verify assets load correctly
- Optimize: Compress images, trim audio
Recording & Analyzing Replays
- Play game: Recording starts automatically
- Check file: Look in
replays/directory - Load replay: Use Replay Browser in main menu
- Analyze gameplay: Watch for bugs, balance issues
- Share replays: Send
.rtrfiles for bug reports
🎓 Learning Path
Beginner
- Start with level editing: Modify
level_01.json - Test changes: Restart server, play modified level
- Add simple enemies: Use BASIC type with SEQUENTIAL pattern
- Watch replays: Record and watch your test games
Intermediate
- Create custom levels: Design full level with multiple waves
- Add new sprites: Learn asset embedding workflow
- Understand replay format: Read
.rtrfiles with hex editor - Optimize performance: Profile asset loading times
Advanced
- Extend level system: Add new enemy types, patterns
- Implement hot-reload: Reload levels without restart
- Compress replays: Add compression to reduce file size
- Create level editor: GUI tool for level creation
🐛 Troubleshooting
Level Issues
| Problem | Solution |
|---|---|
| Level not loading | Check filename format: level_XX.json |
| Enemies not spawning | Validate JSON, check spawn coordinates |
| Wave never completes | Set waitForAllDestroyed correctly |
Asset Issues
| Problem | Solution |
|---|---|
| Texture not loading | Verify file in assets/, rebuild project |
| Sound not playing | Check audio format (WAV/OGG), volume > 0 |
| Large executable | Compress assets, use texture atlases |
Replay Issues
| Problem | Solution |
|---|---|
| Replay corrupted | Check recording completed before exit |
| Playback desync | Ensure client version matches |
| Seek is slow | Implement keyframe system |
📚 Additional Resources
External Documentation
- JSON Specification: json.org
- SFML Asset Loading: sfml-dev.org/tutorials
- Binary File Formats: Binary data in C++
Related Docs
🤝 Contributing
Found issues or want to improve these systems?
- Test thoroughly: Verify changes don't break existing levels/assets
- Update docs: Keep documentation in sync with code
- Validate formats: Ensure backward compatibility
- Profile performance: Measure impact of changes
- Submit PR: Include tests and documentation updates
Happy developing! 🚀