Overview
Minecraft Community Edition uses a fixed timestep game loop running at 20 ticks per second (TPS) for logic and targeting 60 frames per second (FPS) for rendering. The loop is split between the main thread handling rendering and input, with optional threading for level updates.Main Game Loop
The primary game loop is implemented inMinecraft::run_middle() in Minecraft.cpp:1252.
Loop Structure
Minecraft.cpp:1252
Timer System
The game uses aTimer class initialized with SharedConstants::TICKS_PER_SECOND (20 TPS).
SharedConstants::TICKS_PER_SECOND = 20- Fixed tick rateMS_PER_TICK = 50- Milliseconds per tick (1000ms / 20 ticks)
Minecraft.cpp:127
Tick Processing
The server processes game logic in fixed 50ms intervals:MinecraftServer.cpp:1116
Tick Components
- Connection Ticking - Process network packets
- Level Ticking - Update world state, entities, tile entities
- Player Ticking - Process player actions and movement
- Weather Updates - Rain and thunder state changes
- Time Updates - Day/night cycle progression
Update/Render Separation
The architecture separates simulation from rendering:Update Thread
- Runs at 20 TPS fixed timestep
- Processes game logic deterministically
- Handles entity updates, physics, AI
- Independent of frame rate
Render Thread
- Targets 60 FPS
- Interpolates between tick states for smooth visuals
- Uses
timer->afor interpolation alpha - Can run faster or slower than update rate
Minecraft.cpp:764
Level Tick Thread
Optionally, level ticking can be offloaded to a separate thread:Minecraft.cpp:230-234
Benefits
- Offloads expensive world updates from main thread
- Runs at 20 Hz instead of 60 Hz
- Reduces frame drops during heavy world processing
- Uses CPU core 3 for parallel execution
Platform-Specific Threading (C4JThread)
The game uses a custom threading systemC4JThread that wraps platform-specific thread APIs:
Thread Creation
Thread Types
Event Queue Thread:- Level tick offloading
- Post-processing during world generation
- Background chunk operations
Minecraft.cpp:230
Pause System
The game supports pausing simulation while keeping rendering active:MinecraftServer.cpp:1104-1154
Frame Timing
The game tracks frame and tick durations for debugging:Minecraft.cpp:90-92
Performance Monitoring
- Frame times stored in ring buffer
- Displayed in debug overlay (F3)
- Shows tick duration graph
- Helps identify performance bottlenecks
Memory Management per Frame
Each frame resets temporary object pools:- Reduces memory allocations
- Improves cache coherency
- Prevents memory fragmentation
- Faster than individual allocations
Minecraft.cpp:1276-1277
Split-Screen Multiplayer
The game loop processes up to 4 local players:Player Context Switching
Minecraft.cpp:861-876
Related Systems
- World Management - Level updates within the game loop
- Entity System - Entity ticking and updates
- Multiplayer - Network packet processing
Key Takeaways
- Fixed Timestep: Game logic always runs at 20 TPS for determinism
- Render Interpolation: Smooth 60 FPS visuals via alpha blending
- Thread Safety: Critical sections protect shared data structures
- Split-Screen: Each player processes sequentially with context switching
- Pause Support: Can pause simulation while maintaining connections