In testing
Composable speed modifiers
Replacing last-writer-wins movement speed with stackable, named modifiers, and moving a live codebase onto it without breaking anything.
- Role
- Design and implementation
- Stack
- Lua (GLua)
- Context
- Shared player systems on Diverge Networks
- Status
- In testing
The problem
Every system on the server set player speed directly. Carrying a lot of cash, being drunk and being tased all overwrote each other, and nothing restored the right value afterwards. The last system to write won.
The design
- Each system sets and clears its own named modifier. Setting the same name again replaces it instead of stacking.
- The final speed is recomputed from a base value and every active modifier: multipliers multiply together, flat adjustments add, and the result never drops below zero.
- Because order doesn’t matter, removing one effect never disturbs another.
- The whole API is generated in one loop for all eight movement speeds the engine has, from walking to ladder climbing.
Code excerpt coming soon
The generated modifier API, the recompute step, and the legacy setter that makes gradual migration possible.
assets/excerpts/speed-modifiers.lua
Migrating without breaking anything
A codebase this size can’t switch over in one go. The engine’s old speed setters still work, but now set the base value and log a warning naming the call site. Plugins I haven’t converted yet keep behaving correctly, and the warnings show me exactly what’s left to migrate.
Video (optional) coming soon
A player slowed by carrying cash and by being drunk at the same time, then recovering from one without losing the other.
assets/projects/speed-modifiers/speed-stacking.mp4 (about 15 seconds)