Expand description
§jugar-web
WASM browser integration for the Jugar game engine.
This crate provides the web platform layer that bridges Jugar to browsers. All game logic runs in Rust/WASM with ABSOLUTE ZERO JavaScript computation.
§Architecture
┌─────────────────────────────────────────────────────────────┐
│ Browser (JavaScript) │
│ - Event listeners (keyboard, mouse, touch) │
│ - requestAnimationFrame loop │
│ - Canvas2D rendering (drawing only) │
└─────────────────────────┬────────────────────────────────────┘
│ JSON Events ↓ ↑ JSON Commands
┌─────────────────────────┴────────────────────────────────────┐
│ WebPlatform (Rust/WASM) │
│ - Input translation (browser events → InputState) │
│ - Game logic (Pong, etc.) │
│ - Render command generation (Canvas2DCommand) │
│ - Time management (DOMHighResTimeStamp → seconds) │
└──────────────────────────────────────────────────────────────┘§Usage
// JavaScript (minimal event forwarding + Canvas2D execution)
import init, { WebPlatform } from './jugar_web.js';
const platform = new WebPlatform('{"width":800,"height":600}');
const events = [];
document.addEventListener('keydown', (e) => {
events.push({ event_type: 'KeyDown', timestamp: e.timeStamp, data: { key: e.code } });
});
function frame(timestamp) {
const commands = JSON.parse(platform.frame(timestamp, JSON.stringify(events)));
events.length = 0;
// Execute Canvas2D commands
for (const cmd of commands) {
switch (cmd.type) {
case 'Clear': ctx.fillStyle = rgba(cmd.color); ctx.fillRect(0, 0, w, h); break;
case 'FillRect': ctx.fillStyle = rgba(cmd.color); ctx.fillRect(cmd.x, cmd.y, cmd.width, cmd.height); break;
// ...
}
}
requestAnimationFrame(frame);
}Re-exports§
pub use ai::DeterminismConfig;pub use ai::DifficultyProfile;pub use ai::FlowChannel;pub use ai::FlowTheoryConfig;pub use ai::ModelMetadata;pub use ai::PlayerMetrics;pub use ai::PongAI;pub use ai::PongAIModel;pub use audio::AudioEvent;pub use audio::ProceduralAudio;pub use compute::detect_compute_capability;pub use compute::ComputeBenchmarkResult;pub use compute::ComputeCapability;pub use compute::ComputeDemo;pub use compute::ComputeDemoState;pub use compute::ComputeTier;pub use compute::GpuShaderInfo;pub use compute::ShaderType;pub use compute::PARTICLE_PHYSICS_WGSL;pub use demo::Attribution;pub use demo::DemoState;pub use demo::GameMode;pub use demo::PerformanceStats;pub use demo::SpeedMultiplier;pub use input::process_input_events;pub use input::translate_gamepad_axis;pub use input::translate_key;pub use input::BrowserEventData;pub use input::BrowserInputEvent;pub use input::InputTranslationError;pub use loadtest::AnomalyResult;pub use loadtest::ChaosConfig;pub use loadtest::ChaosResults;pub use loadtest::ChaosScenario;pub use loadtest::DriftDetector;pub use loadtest::DriftReport;pub use loadtest::FrameTimeReport;pub use loadtest::FrameTimeStats;pub use loadtest::LoadTestConfig;pub use loadtest::LoadTestResult;pub use loadtest::LoadTestSummary;pub use platform::DebugInfo;pub use platform::FrameOutput;pub use platform::GameState;pub use platform::PongGame;pub use platform::WebConfig;pub use platform::WebGame;pub use platform::WebPlatform;pub use platform::WebPlatformError;pub use render::convert_render_command;pub use render::convert_render_queue;pub use render::Canvas2DCommand;pub use render::Color;pub use render::RenderFrame;pub use render::TextAlign;pub use render::TextBaseline;pub use simd::batch_distance_squared;pub use simd::batch_particle_update;pub use simd::batch_update_positions;pub use simd::check_paddle_collisions;pub use simd::detect_compute_backend;pub use simd::trueno_backend_to_compute_backend;pub use simd::ComputeBackend;pub use simd::SimdBenchmark;pub use simd::SimdVec2;pub use simulation::check_invariants;pub use simulation::FailureReplay;pub use simulation::FuzzGenerator;pub use simulation::GameStateSnapshot;pub use simulation::InvariantViolation;pub use simulation::MonteCarloConfig;pub use simulation::TestResult;pub use simulation::TestTier;pub use simulation::TimestampedInput;pub use time::calculate_delta_time;pub use time::clamp_delta_time;pub use time::dom_timestamp_to_seconds;pub use time::seconds_to_dom_timestamp;pub use time::FrameTimer;pub use time::DEFAULT_MAX_DELTA_TIME;pub use time::TARGET_DT_120FPS;pub use time::TARGET_DT_30FPS;pub use time::TARGET_DT_60FPS;pub use trace::AdaptiveSnapshotter;pub use trace::BufferPolicy;pub use trace::Fixed32;pub use trace::FrameRecord;pub use trace::GameTracer;pub use trace::InputEvent;pub use trace::InputEventType;pub use trace::QueryResult;pub use trace::SnapshotDecision;pub use trace::TraceBuffer;pub use trace::TraceError;pub use trace::TraceQuery;pub use trace::TraceStats;pub use trace::TracerConfig;
Modules§
- ai
- AI opponent module for Pong game.
- audio
- Procedural audio for Pong game.
- compute
- WebGPU compute shader demonstration for physics calculations.
- demo
- Demo mode and game mode management.
- input
- Browser input event translation
- juice
- Game juice and visual feedback effects.
- loadtest
- Load Testing and Performance Validation
- platform
- Web platform integration for the Jugar game engine.
- render
- Canvas2D render commands for browser execution.
- simd
- SIMD-accelerated operations using trueno.
- simulation
- Game Simulation Testing Framework
- time
- Time utilities for browser integration.
- trace
- Game Event Tracing and Deterministic Replay
Macros§
- deterministic
- Poka-Yoke macro to enforce Fixed32 in deterministic game logic (Bessey 2010).