Skip to content

Commit 19685ae

Browse files
engine architecture
1 parent 644c9a1 commit 19685ae

File tree

1 file changed

+197
-127
lines changed

1 file changed

+197
-127
lines changed

readme.md

Lines changed: 197 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -12,138 +12,208 @@ The battle for Earth had begun, and the fate of humanity rested in the hands of
1212
## Overview
1313
XENOWAR is a modern HTML5 Canvas-based space shooter game engine built with vanilla JavaScript, featuring a component-based architecture, particle systems, formation patterns, and dynamic audio management.
1414

15-
## Architecture
16-
17-
### Core Systems
18-
- **Game Loop**: Implements a request animation frame-based game loop with delta time
19-
- **Virtual Resolution**: Uses a 1080x1080 virtual resolution with dynamic scaling
20-
- **State Management**: Screen-based state system (Startup, Intro, Game)
21-
- **Event System**: DOM-based event handling for input
22-
- **Asset Management**: Dynamic loading of images and audio
23-
24-
### Key Components
25-
26-
#### Rendering System
27-
- Canvas-based rendering with hardware acceleration
28-
- Multiple render layers (Background, Entities, Particles, HUD)
29-
- Screen space transformation and scaling
30-
- Offscreen canvas for performance optimization
31-
- Particle pre-rendering
32-
33-
#### Audio System
34-
- Dynamic audio loading and playback
15+
# XENOWAR Engine Documentation
16+
17+
## Build Pipeline and Development Flow
18+
19+
```mermaid
20+
graph TD
21+
A[Source Code] --> B[Vite Dev Server]
22+
B --> C[Hot Module Replacement]
23+
A --> D[Build Process]
24+
D --> E[JavaScript Minification]
25+
D --> F[Asset Optimization]
26+
D --> G[Shader Compilation]
27+
E & F & G --> H[Production Bundle]
28+
H --> I[GitHub Pages Deploy]
29+
```
30+
31+
## Development Setup
32+
33+
### Prerequisites
34+
```bash
35+
# Required software
36+
- Node.js 18+
37+
- npm 9+
38+
- Modern web browser with WebGL2 support
39+
40+
# Installation
41+
npm install # Install dependencies
42+
npm run dev # Start development server
43+
npm run build # Create production build
44+
```
45+
46+
## Core Systems Architecture
47+
48+
### Rendering Pipeline
49+
```mermaid
50+
graph LR
51+
A[Game State] --> B[Entity Renderer]
52+
B --> C[Particle System]
53+
C --> D[Post-Processing]
54+
D --> E[CRT Shader]
55+
E --> F[Screen Output]
56+
```
57+
58+
### CRT Shader System
59+
```javascript
60+
// Configurable shader parameters
61+
{
62+
"scanline": {
63+
"intensity": 0.28, // Scanline strength
64+
"count": 1024.0, // Number of scanlines
65+
"rollingSpeed": 10.3 // Rolling speed
66+
},
67+
"screenEffects": {
68+
"vignetteStrength": 0.22,
69+
"brightness": 1.1,
70+
"curvature": 0.1
71+
}
72+
}
73+
```
74+
75+
## Asset Pipeline
76+
77+
### Image Processing
78+
- Automatic sprite optimization
79+
- Background texture processing
80+
- Dimension verification
81+
- Palette optimization
82+
- Compression profiles
83+
84+
### Audio System
3585
- Web Audio API integration
36-
- Spatial audio with panning
37-
- Music playlist management with shuffling
38-
- Sound effects with pitch variation
39-
40-
#### Particle Systems
41-
- Pooled particle management
42-
- Multiple particle types (Engine, Laser, Explosion)
43-
- Hardware-accelerated rendering
44-
- Performance-optimized with pre-rendering
86+
- Spatial audio support
87+
- Dynamic music system
88+
- Sound effect manager
89+
- Audio pooling
90+
91+
## Performance Optimizations
92+
93+
### Memory Management
94+
- Object pooling for particles
95+
- Texture atlasing
96+
- Asset preloading
97+
- Garbage collection optimization
98+
- Memory monitoring
99+
100+
### Rendering Optimizations
101+
- WebGL2 acceleration
102+
- Batch rendering
103+
- Shader-based effects
104+
- Double-buffered rendering
45105
- Screen-space culling
46106

47-
#### Formation System
48-
- Dynamic pattern-based formations
49-
- Spline-based movement paths
50-
- Bezier curve interpolation
51-
- Pattern switching with smooth transitions
52-
- Difficulty-based scaling
107+
## Technical Architecture
108+
109+
### Core Components
110+
```mermaid
111+
graph TD
112+
A[Game Core] --> B[Renderer]
113+
A --> C[Audio System]
114+
A --> D[Input Manager]
115+
B --> E[Particle Engine]
116+
B --> F[Post-Processing]
117+
C --> G[Music Player]
118+
C --> H[SFX Manager]
119+
```
53120

54-
### Technical Features
121+
### Component Communication
122+
- Event-based messaging
123+
- Component lifecycle management
124+
- State synchronization
125+
- Update hierarchy
126+
- Resource sharing
55127

56-
#### Performance Optimizations
57-
- Object pooling for particles
58-
- Pre-rendered particle effects
59-
- Offscreen canvas usage
60-
- Efficient collision detection
61-
- Memory management for disposable objects
62-
63-
#### Visual Effects
64-
- Dynamic lighting and glow effects
65-
- Screen-space composition
66-
- Particle trails and explosions
67-
- Background parallax scrolling
68-
- Screen shake and flash effects
69-
70-
#### Audio Features
71-
- Dynamic music system
72-
- Positional audio effects
73-
- Volume fading and transitions
74-
- Multiple audio channels
75-
- Pitch shifting for variety
76-
77-
#### Input Handling
78-
- Keyboard input management
79-
- Event debouncing
80-
- Screen-specific input handlers
81-
- Input state tracking
82-
83-
### File Structure
128+
## Debug Features
129+
130+
### Performance Monitoring
131+
```javascript
132+
// Enable debug mode
133+
engine.debug.enableProfiling();
134+
engine.debug.showStats();
135+
```
136+
137+
### Debug Commands
138+
- `debug.showColliders()` - Show collision bounds
139+
- `debug.showFPS()` - Display FPS counter
140+
- `debug.profile()` - Start performance profiling
141+
- `debug.showPoolStats()` - Display object pool stats
142+
143+
## Asset Requirements
144+
145+
### Sprites
146+
- Format: PNG with transparency
147+
- Dimensions: Power of 2 recommended
148+
- Maximum size: 2048x2048
149+
- Color depth: 32-bit RGBA
150+
151+
### Audio
152+
- Format: MP3/M4A
153+
- Sample rate: 44.1kHz
154+
- Bit depth: 16-bit
155+
- Channels: Stereo
156+
157+
## Build Configuration
158+
159+
### Development Build
160+
```bash
161+
npm run dev
162+
# Starts development server with:
163+
# - Hot module replacement
164+
# - Source maps
165+
# - Debug tools
166+
# - Uncompressed assets
84167
```
85-
/shooter
86-
├── index.html # Main entry point
87-
├── js/
88-
│ ├── game.js # Core game engine
89-
│ ├── player.js # Player entity
90-
│ ├── alien.js # Enemy entities
91-
│ ├── patterns/ # Formation patterns
92-
│ ├── screens/ # Game screens
93-
│ ├── effects/ # Visual effects
94-
│ ├── audio/ # Audio management
95-
│ └── math/ # Math utilities
96-
├── audio/ # Audio assets
97-
├── sprites/ # Image assets
98-
└── backgrounds/ # Background images
168+
169+
### Production Build
170+
```bash
171+
npm run build
172+
# Creates optimized build with:
173+
# - Minified JavaScript
174+
# - Compressed assets
175+
# - Dead code elimination
176+
# - Bundled modules
177+
```
178+
179+
## Performance Guidelines
180+
181+
### Best Practices
182+
1. Use object pooling for frequent allocations
183+
2. Batch WebGL draw calls
184+
3. Minimize garbage collection
185+
4. Pre-render static elements
186+
5. Implement efficient collision detection
187+
188+
### Memory Management
189+
- Monitor heap usage
190+
- Implement dispose patterns
191+
- Cache frequently used objects
192+
- Clear unused resources
193+
- Manage texture memory
194+
195+
## Contributing Guidelines
196+
197+
### Code Style
198+
```javascript
199+
// Use ES6+ features for modern JavaScript
200+
class Component {
201+
constructor() {
202+
this.pool = new Pool();
203+
}
204+
205+
update(deltaTime) {
206+
// Use object pooling
207+
this.pool.forEach(entity => {
208+
// Entity updates
209+
});
210+
}
211+
}
99212
```
100213

101-
### Core Classes
102-
103-
#### Game Class
104-
- Main game loop management
105-
- State management
106-
- Resource management
107-
- Input handling
108-
- Screen management
109-
110-
#### ParticleEngine
111-
- Particle pool management
112-
- Particle updating
113-
- Efficient rendering
114-
- Performance optimization
115-
116-
#### Formation System
117-
- Pattern-based movement
118-
- Enemy formation management
119-
- Difficulty scaling
120-
- Collision detection
121-
122-
#### AudioManager
123-
- Music playlist management
124-
- Sound effect handling
125-
- Spatial audio
126-
- Volume control
127-
128-
### Building and Running
129-
130-
1. Clone the repository
131-
2. Serve with any HTTP server (e.g., `python -m http.server`)
132-
3. Open in a modern browser
133-
134-
### Performance Considerations
135-
- Uses requestAnimationFrame for smooth animation
136-
- Implements object pooling for particles
137-
- Pre-renders common visual effects
138-
- Optimizes canvas state changes
139-
- Implements efficient collision detection
140-
141-
### Future Improvements
142-
- WebGL rendering pipeline
143-
- Additional formation patterns
144-
- Enhanced particle effects
145-
- More audio features
146-
- Mobile support
147-
148-
## License
149-
MIT License
214+
### Pull Request Process
215+
1. Fork repository
216+
2. Create feature branch
217+
3. Follow code style guide
218+
4. Update documentation
219+
5. Submit pull request

0 commit comments

Comments
 (0)