|
|
|
|
|
by a1369209993
2853 days ago
|
|
Another option is to build a set of diffs (Unit::MoveTo,Score::Add,...) based on the existing (immutabled viewed) state, then apply them mutably (possibly checking for conflicts on moveto et al): diff = differential(state)
state.update(diff) # or state = update(state,diff)
# or state += ∂_∂t(state) if you're feeling overly mathy
|
|
I've been tempted lately to model application state as the integral over time of all events (deltas) that have occurred. For example, imagine a simple game state:
If initial game state = and you have some events (deltas): You could "sum" them up (integrate over time) and get a game state of x = 5, v = 0 where t >= 5.I've found this approach kinda sucks when you add things like collision detection. Your application would have to emit velocity deltas when objects would collide. If you've got a point that bounces around in a box with perfectly elastic collisions, then over time you'd have an infinite number of these collision/velocity delta events. But as you receive new events, all your precomputed collision events are for nothing (if your player logs out). So the traditional update loop simulate each tick as it occurs seems to work best.
Is there a more general way of thinking about this integration? Maybe with respect to another variable? Perhaps it would address this problem I'm having where I feel forced to quantize my game state onto ticks.