I really love this talk by Mary Rose Cook — she illustrates step-by-step how to code a game loop from scratch in 30 minutes. https://youtu.be/hbKN-9o5_Z0
How do I design a game from scratch? A primer on core loops
11–20 of 45 posts
Re: How do I design a game from scratch? A primer on core loops
#12Gamedev here. Slight correction: what they're describing is the smallest viable loop, not necessarily the core loop. The core loop is the smallest engagement loop in the game, where the player goes through it inside a single session, and reaches some kind of a stopping point, but also wants to come back and go through it all over again (right away, or next time). It can be the smallest loop, maybe, sometimes, but usu…
I guess in some games there are many loops within loops within loops. E.g. in "slay the spire", a game i am very fond of, the smallest loop could be "you draw a hand of cards from your deck and decide which card to play on what target" - usually taking a few seconds to decide or perhaps a few minutes if you are in a very tricky situation where you might win or lose unless you make a carefully considered move. The nex…
The best games have a layering of loops of different frequencies, which complement each other. That's what gives games that "one more turn" feeling, if at every turn you're confronted with multiple decision points with different result horizons. So at every point in time, some decisions ripen and are ready to collect, while others require attention but will have payoffs at very different times in the future.
Edit: for roguelites like STS I would count a single run as the core loop. Especially in the presence of metagame, the benefits gathered during any single run add up, and make the player that much more interested in coming back and giving it another try.
Re: How do I design a game from scratch? A primer on core loops
#13Gamedev here. Slight correction: what they're describing is the smallest viable loop, not necessarily the core loop. The core loop is the smallest engagement loop in the game, where the player goes through it inside a single session, and reaches some kind of a stopping point, but also wants to come back and go through it all over again (right away, or next time). It can be the smallest loop, maybe, sometimes, but usu…
Thanks for explaining this so concisely
Re: How do I design a game from scratch? A primer on core loops
#14Re: How do I design a game from scratch? A primer on core loops
#15Some assumptions that may be terribly wrong:
- The user input loop (keyboard, mouse) is still the main loop somewhere at the very bottom. Or is it different in RPGs?
- Spawn threads each with their own inner loop, for each complex agent. Not necessarily an OS thread, but something that has its main loop and a stack.
- Objects that don't have a "brain" don't need a thread, e.g. the ball in the tennis game. All such objects are managed from a single thread.
- There's a rendering loop, possibly with its own complex multithreaded architecture.
I don't know, did I come close to what's actually happening in complex RPG games?
Re: How do I design a game from scratch? A primer on core loops
#16I've never designed games beyond tetris, could someone explain in a few words, what the architecture of a RPG looks like? Some assumptions that may be terribly wrong: - The user input loop (keyboard, mouse) is still the main loop somewhere at the very bottom. Or is it different in RPGs? - Spawn threads each with their own inner loop, for each complex agent. Not necessarily an OS thread, but something that has its mai…
delta_t = time between last frame and now
fetch input status
for each entity: entity.think(delta_t) (for example, if a monster is in the state of moving towards me, it will move speed*delta_t units)
Render()
Never saw loops with real threads, that looks like asking for trouble.
If it was a multiplayer game then the think part was on the server and the client would just ready entity state from the network, sent input to server, and render().
Re: How do I design a game from scratch? A primer on core loops
#17I've never designed games beyond tetris, could someone explain in a few words, what the architecture of a RPG looks like? Some assumptions that may be terribly wrong: - The user input loop (keyboard, mouse) is still the main loop somewhere at the very bottom. Or is it different in RPGs? - Spawn threads each with their own inner loop, for each complex agent. Not necessarily an OS thread, but something that has its mai…
I did some big game dev for some years 10 years ago. The loop was (there was only 1 loop): delta_t = time between last frame and now fetch input status for each entity: entity.think(delta_t) (for example, if a monster is in the state of moving towards me, it will move speed*delta_t units) Render() Never saw loops with real threads, that looks like asking for trouble. If it was a multiplayer game then the think part w…
entities.forEach { $0.think(delta_t) }
is essentially cooperative multitasking, whose efficiency is questionable in general and especially on multicore hardware - but I don't know about games. Let alone programming think(delta_t) adds complexity and introduces more states within each entity, compared to real threads with their own stacks.Re: How do I design a game from scratch? A primer on core loops
#18Earlier quoted context omitted.
I did some big game dev for some years 10 years ago. The loop was (there was only 1 loop): delta_t = time between last frame and now fetch input status for each entity: entity.think(delta_t) (for example, if a monster is in the state of moving towards me, it will move speed*delta_t units) Render() Never saw loops with real threads, that looks like asking for trouble. If it was a multiplayer game then the think part w…
Interesting. Something suggests a loop that does entities.forEach { $0.think(delta_t) } is essentially cooperative multitasking, whose efficiency is questionable in general and especially on multicore hardware - but I don't know about games. Let alone programming think(delta_t) adds complexity and introduces more states within each entity, compared to real threads with their own stacks.
Re: How do I design a game from scratch? A primer on core loops
#19Earlier quoted context omitted.
Interesting. Something suggests a loop that does entities.forEach { $0.think(delta_t) } is essentially cooperative multitasking, whose efficiency is questionable in general and especially on multicore hardware - but I don't know about games. Let alone programming think(delta_t) adds complexity and introduces more states within each entity, compared to real threads with their own stacks.
Also you can check games like quake, doom etc which have opened their source, they are all done like that.