Skip to content

Commit 267ab66

Browse files
committed
Cleanup documentation and remove redundant comments
1 parent 4826f32 commit 267ab66

File tree

5 files changed

+38
-152
lines changed

5 files changed

+38
-152
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ The worker import fix is necessary because `wasm-bindgen-rayon` generates worker
167167
evo/
168168
├── src/ # Rust source code
169169
│ ├── components.rs # ECS components
170-
│ ├── genes.rs # Genetic system
171-
│ ├── systems.rs # Simulation systems
170+
│ ├── genes/ # Genetic system module
171+
│ ├── systems/ # Simulation systems modules
172172
│ ├── spatial_grid.rs # Spatial optimization
173-
│ ├── stats.rs # Analytics and statistics
174-
│ ├── simulation.rs # Main simulation orchestration
175-
│ ├── config.rs # Configuration management
176-
│ ├── ui.rs # GPU-accelerated rendering (desktop)
173+
│ ├── stats/ # Analytics and statistics module
174+
│ ├── simulation/ # Main simulation orchestration module
175+
│ ├── config/ # Configuration management module
176+
│ ├── ui/ # GPU-accelerated rendering (desktop)
177177
│ ├── web/ # Web-specific modules
178178
│ └── main.rs # Application entry point
179179
├── web/ # Web application
@@ -320,11 +320,11 @@ cargo run -- --config my_config.json
320320
### Key Modules
321321

322322
- **`components.rs`**: ECS components
323-
- **`genes.rs`**: Genetic system with grouped traits
324-
- **`systems.rs`**: Simulation systems
323+
- **`genes/`**: Genetic system with grouped traits
324+
- **`systems/`**: Simulation systems
325325
- **`spatial_grid.rs`**: Spatial optimization
326-
- **`simulation.rs`**: Main simulation orchestration
327-
- **`ui.rs`**: GPU-accelerated rendering (desktop)
326+
- **`simulation/`**: Main simulation orchestration
327+
- **`ui/`**: GPU-accelerated rendering (desktop)
328328
- **`web/`**: Web-specific modules
329329

330330
### Testing

docs/DEPLOYMENT.md

Lines changed: 25 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,176 +1,69 @@
11
# Cloudflare Deployment Guide
22

3-
This guide explains how to deploy the Evolution Simulation to Cloudflare Workers.
3+
This guide explains how to deploy the Evolution Simulation to Cloudflare Pages.
44

55
## Prerequisites
66

77
1. **Cloudflare Account**: Sign up at [cloudflare.com](https://cloudflare.com)
8-
2. **Wrangler CLI**: Install the Cloudflare Workers CLI
9-
3. **Domain**: A domain name (optional, you can use the default workers.dev subdomain)
8+
2. **Wrangler CLI**: Install the Cloudflare Workers/Pages CLI
9+
3. **Rust Toolchain**: Nightly toolchain with WASM support (see README.md)
1010

11-
## Setup
11+
## Deployment Steps
1212

13-
### 1. Install Wrangler CLI
13+
### 1. Install Dependencies
1414

1515
```bash
16-
npm install -g wrangler
16+
npm install
1717
```
1818

1919
### 2. Login to Cloudflare
2020

2121
```bash
22-
wrangler login
22+
npx wrangler login
2323
```
2424

25-
### 3. Configure the Project
26-
27-
Edit `wrangler.toml` and update the following:
28-
29-
- `name`: Your preferred worker name
30-
- `route`: Your domain (if you have one)
31-
- `kv_namespaces`: Remove or configure if you need KV storage
32-
33-
### 4. Build the Project
25+
### 3. Build the Project
3426

3527
```bash
3628
npm run build:web
3729
```
3830

39-
This will:
40-
- Compile the Rust code to WebAssembly
41-
- Generate the necessary JavaScript bindings
42-
- Place the files in the `pkg/` directory
31+
This commands compiles the Rust code to WebAssembly and places the output in the `pkg/` directory.
4332

44-
## Deployment
45-
46-
### Quick Deploy
33+
### 4. Deploy to Cloudflare Pages
4734

4835
```bash
36+
# Deploy to production
4937
npm run deploy
50-
```
51-
52-
This will:
53-
1. Build the web assets
54-
2. Deploy to Cloudflare Workers
55-
3. Provide you with a URL
56-
57-
### Environment-Specific Deployments
58-
59-
For staging and production environments, you can modify the `wrangler.toml` file and use:
60-
61-
```bash
62-
# Deploy to staging
63-
wrangler deploy --env staging
6438

65-
# Deploy to production
66-
wrangler deploy --env production
39+
# Or manually:
40+
npx wrangler pages deploy web --project-name evo
6741
```
6842

69-
### Local Development
43+
This uploads the `web/` directory (which includes the index.html, CSS, JS, and the generated WASM in `web/pkg/`) to Cloudflare Pages.
44+
45+
## Local Development
7046

71-
Test the worker locally before deploying:
47+
Test the Pages build locally:
7248

7349
```bash
7450
npm run dev:worker
7551
```
7652

77-
This will start a local development server that mimics the Cloudflare Workers environment.
53+
This builds the project and starts a local Pages server (using `wrangler pages dev`).
7854

7955
## Configuration
8056

81-
### wrangler.toml
82-
83-
The main configuration file contains:
84-
85-
- **Worker settings**: Name, compatibility date, etc.
86-
- **Site configuration**: Points to the `./web` directory for static assets
87-
- **Build command**: Automatically runs `npm run build:web` before deployment
88-
- **Environment settings**: Separate configs for staging and production
89-
90-
### Environment Variables
91-
92-
You can add environment variables in `wrangler.toml`:
93-
94-
```toml
95-
[vars]
96-
API_KEY = "your-api-key"
97-
ENVIRONMENT = "production"
98-
```
99-
100-
### Custom Domains
101-
102-
The application is deployed with a custom domain at [https://evo.tre.systems/](https://evo.tre.systems/).
103-
104-
To use a custom domain:
57+
### COOP/COEP Headers regarding SharedArrayBuffer
10558

106-
1. Add your domain to Cloudflare
107-
2. Update the `route` in `wrangler.toml`
108-
3. Deploy with `wrangler deploy --env production`
59+
The simulation uses `SharedArrayBuffer` for parallel processing (via `rayon`). This requires specific security headers to be served:
10960

110-
## File Structure
61+
- `Cross-Origin-Opener-Policy: same-origin`
62+
- `Cross-Origin-Embedder-Policy: require-corp`
11163

112-
```
113-
├── worker.js # Cloudflare Worker code
114-
├── wrangler.toml # Worker configuration
115-
├── web/ # Static assets
116-
│ ├── index.html
117-
│ ├── css/
118-
│ ├── js/
119-
│ └── pkg/ # WASM files (generated)
120-
└── pkg/ # WASM package (generated)
121-
```
64+
These are configured in the `web/_headers` file, which Cloudflare Pages uses to apply headers.
12265

12366
## Troubleshooting
12467

125-
### Common Issues
126-
127-
1. **WASM not loading**: Ensure CORS headers are set correctly
128-
2. **Build failures**: Check that all dependencies are installed
129-
3. **Deployment errors**: Verify your Cloudflare account and permissions
130-
131-
### Debug Commands
132-
133-
```bash
134-
# Check worker logs
135-
wrangler tail
136-
137-
# Test locally
138-
wrangler dev
139-
140-
# Check build output
141-
ls -la pkg/
142-
```
143-
144-
## Performance
145-
146-
The worker is optimized for:
147-
148-
- **Fast loading**: WASM files are cached for 1 year
149-
- **CORS compliance**: Proper headers for cross-origin requests
150-
- **Static asset serving**: Efficient delivery of HTML, CSS, and JS
151-
152-
## Monitoring
153-
154-
Monitor your deployment:
155-
156-
1. **Cloudflare Dashboard**: View analytics and logs
157-
2. **Worker Logs**: Use `wrangler tail` for real-time logs
158-
3. **Performance**: Check the Cloudflare Analytics dashboard
159-
160-
## Security
161-
162-
The worker includes:
163-
164-
- **CORS headers**: Proper cross-origin resource sharing
165-
- **Security headers**: COEP and COOP for isolation
166-
- **Input validation**: Prevents directory traversal attacks
167-
168-
## Cost
169-
170-
Cloudflare Workers pricing:
171-
172-
- **Free tier**: 100,000 requests/day
173-
- **Paid tier**: $5/month for 10M requests
174-
- **Additional**: $0.50 per million requests
175-
176-
Most small to medium projects will fit within the free tier.
68+
### "SharedArrayBuffer is not defined"
69+
If you see this error in the browser console, it means the COOP/COEP headers are missing. Ensure `web/_headers` exists and is being deployed.

src/simulation/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ impl Simulation {
222222
let mut new_energy = energy.current;
223223
let mut eaten_entity = None;
224224

225-
// Apply movement
226225
self.apply_movement_to_entity(
227226
genes,
228227
&mut new_pos,
@@ -232,15 +231,13 @@ impl Simulation {
232231
&nearby_entities,
233232
);
234233

235-
// Handle boundaries
236234
self.movement_system.handle_boundaries(
237235
&mut new_pos,
238236
&mut new_velocity,
239237
self.world_size,
240238
&self.config,
241239
);
242240

243-
// Handle interactions
244241
self.apply_interactions_to_entity(
245242
&mut new_energy,
246243
&mut eaten_entity,
@@ -250,11 +247,9 @@ impl Simulation {
250247
&nearby_entities,
251248
);
252249

253-
// Apply energy changes
254250
self.energy_system
255251
.update_energy(&mut new_energy, size, genes, &self.config);
256252

257-
// Check reproduction and death
258253
let population_density = self.calculate_population_density();
259254
let should_reproduce =
260255
self.check_reproduction_for_entity(new_energy, energy.max, genes, population_density);
@@ -496,7 +491,6 @@ impl Simulation {
496491
.collect()
497492
}
498493

499-
/// Get a reference to the world for stats calculation
500494
pub fn world(&self) -> &World {
501495
&self.world
502496
}

src/ui/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod state;
22

33
use crate::config::SimulationConfig;
44
use crate::simulation::Simulation;
5-
use state::State; // Import logic from state.rs
5+
use state::State;
66

77
use std::sync::Arc;
88
use winit::{

src/ui/state.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use wgpu::util::DeviceExt;
77
struct Vertex {
88
position: [f32; 2],
99
color: [f32; 3],
10-
center: [f32; 2], // Center position of the ball
10+
center: [f32; 2],
1111
radius: f32,
1212
}
1313

@@ -95,7 +95,7 @@ impl State {
9595
offset: std::mem::size_of::<[f32; 2]>() as wgpu::BufferAddress
9696
+ std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
9797
shader_location: 2,
98-
format: wgpu::VertexFormat::Float32x2, // Changed to Float32x2 for center
98+
format: wgpu::VertexFormat::Float32x2,
9999
},
100100
wgpu::VertexAttribute {
101101
offset: std::mem::size_of::<[f32; 2]>() as wgpu::BufferAddress
@@ -211,7 +211,6 @@ impl State {
211211
// Create a quad for each entity (will be rendered as a glowing ball)
212212
let color = [r, g, b];
213213

214-
// Quad vertices (two triangles to form a square)
215214
// Triangle 1
216215
vertices.push(Vertex {
217216
position: [screen_x - quad_size, screen_y - quad_size],

0 commit comments

Comments
 (0)