Domanda

Cosa odi di più del loop del gioco moderno?Il ciclo del gioco può essere migliorato o c'è solo un'alternativa migliore, come un'architettura guidata dagli eventi?

È stato utile?

Soluzione

It seems like this really ought to be a CW...

I'm taking a grad-level game engine programming course right now and they're sticking with the game loop approach. Granted, that doesn't mean it's the only/best solution but it's certainly logical. Using a loop allows you to ensure that all game systems get their turn to run without requesting their own timed interrupts or something else. Control can be centralized: in my current project, I have a GameManager class that, each frame, loops through the Update(float deltaTime) function for every registered object in turn. I don't have to debug an event system or set up timed signals, I just use a loop to call a series of functions. No muss, no fuss.

To answer your question of what do I hate most, the loop approach does logically lend itself to liberal use of inheritance and polymorphism which can bloat the size/complexity of your objects. If you're not careful, this can be a mild-to-horrible pitfall. If you are careful, it may not be a problem at all.

Altri suggerimenti

No matter there is any event in the game or not, game is supposed to draw itself and update it at a fixed rate, so I don't think dropping the game loop is possible. Still I would be wondered if anyone can think of any other alternative of game loop.

Usually the event driven architectures work best for games (only do something if the user wants something done). BUT, you'll still always need to have a thread constantly redrawing the world.

To be fully event based you could spawn an extra thread that does nothing but put a CPUTick event into your event queue every x milliseconds.

In JavaScript this is usually the more natural route, because you can so easily create an extra 'thread' that sends you the events with setInterval().

Or, if you already have a loop in the framework containing your game - like JS has in the browser, or python has with twisted - you can tell that looper to call you back at fixed intervals. e.g.:

function gameLoop() {
   // update, draw...
}
window.setInterval(gameLoop, 1000/fps);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top