Skip to main content
added 17 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124

Flight Simulator, Wolfenstein, and classic Pong are purely real-time simulations. There is no turn-based element here. They are typically as fine-grained as you can get, often using every one of 60 frames of 16.6ms period each in a second, to perform new logic. Of course, this doesn't mean they always do; they can also wait to do certain tasks only periodically, such as AI updates.

Flight Simulator, Wolfenstein, and classic Pong are purely real-time simulations. There is no turn-based element here.

Flight Simulator, Wolfenstein, and classic Pong are purely real-time simulations. There is no turn-based element here. They are typically as fine-grained as you can get, often using every one of 60 frames of 16.6ms period each in a second, to perform new logic. Of course, this doesn't mean they always do; they can also wait to do certain tasks only periodically, such as AI updates.

added 17 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124

Angband, Nethack are a good example of a very simple turn-based game. These require no loop whatsoever in your code. User input comes from the keyboard which is handled by the OS, so you just let the OS notify your application and when a keyboard event occurs, and your functions otherwise know nothing about timing loops, and need not do so.

Battle Chess is a turn based game with real time animation, movement etc. Clearly, a loop is once again the basis for responding to user interaction. In this case it is also used for animation, gradual moves between tiles, special effects, etc. (possibly even for sound). But the difference here is that while such a game is fundamentally loop-based, it is preventing you from supplying user input for those periods when a move has just been made and your knight is fighting the enemy bishop: it just controls when & how you are allowed to supply input. Otherwise, it operates much like Pong, CoD etc.

Loop-based / real-time systems are required for any reactive/interactive system. Event-based systems, while often appearing very different to real-time systems, are actuallyoften fundamentally associate with, if not driven by loops, and indeed often co-exist alongside themloops in various different forms.

Angband, Nethack are a good example of a very simple turn-based game. These require no loop whatsoever. User input comes from the keyboard which is handled by the OS, so you just let the OS notify your application and when a keyboard event occurs, and your functions otherwise know nothing about timing loops, and need not do so.

Battle Chess is a turn based game with real time animation, movement etc. Clearly, a loop is once again the basis for responding to user interaction. In this case it is also used for animation, gradual moves between tiles, special effects, etc. (possibly even for sound). But the difference here is that while such a game is fundamentally loop-based, it is preventing you from supplying user input for those periods when a move has just been made and your knight is fighting the enemy bishop: it just controls when & how you are allowed to supply input. Otherwise, it operates much like Pong etc.

Loop-based / real-time systems are required for any reactive/interactive system. Event-based systems, while often appearing very different to real-time systems, are actually fundamentally driven by loops, and indeed often co-exist alongside them in various different forms.

Angband, Nethack are a good example of a very simple turn-based game. These require no loop whatsoever in your code. User input comes from the keyboard which is handled by the OS, so you just let the OS notify your application and when a keyboard event occurs, and your functions otherwise know nothing about timing loops, and need not do so.

Battle Chess is a turn based game with real time animation, movement etc. Clearly, a loop is once again the basis for responding to user interaction. In this case it is also used for animation, gradual moves between tiles, special effects, etc. (possibly even for sound). But the difference here is that while such a game is fundamentally loop-based, it is preventing you from supplying user input for those periods when a move has just been made and your knight is fighting the enemy bishop: it just controls when & how you are allowed to supply input. Otherwise, it operates much like Pong, CoD etc.

Loop-based / real-time systems are required for any reactive/interactive system. Event-based systems, while often appearing very different to real-time systems, are often fundamentally associate with, if not driven by loops, and co-exist alongside loops in various different forms.

added 1101 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124

Your Game

For a Dwarf Fortress style game, I'd start with the following timing mechanism, see Fix your Timestep. Some here may be your code, some like the loop or vsync event mechanism may be 3rd party:

bool isRunning = true;
//assume milliseconds for all time* variables
int timeAccumulated = 0;
int timeStep = 1000; //period = 1000ms : frequency = 1fps
while (isRunning) //cpu
{
    tick();
}
//...or don't use such a loop, and instead call tick() on vsync event.

void tick()
{
    timeDelta = SomeMethod(); //may be yours, system's, or library's
    timeAccumulated += timeDelta; //see "Fix your Timestep"
    
    if (timeAccumulated <= timeStep)
    {
        timeAccumulated -= timeStep; 
    
        turn(); //call all your custom turn logic here
    }
    //inputs must have immediate effect, so are not called in turn()...
    isRunning = CheckKeyPressed("ESCAPE"); //for example
}

...So the outer block (while) controls actions which must have an immediate response, like queuing up input for use in the next turn, handling loads etc. OTOH the inner block (if) only allows this loop iteration to make game logic happen once a second has passed since the last turn was enacted.

Your Game

For a Dwarf Fortress style game, I'd start with the following timing mechanism, see Fix your Timestep. Some here may be your code, some like the loop or vsync event mechanism may be 3rd party:

bool isRunning = true;
//assume milliseconds for all time* variables
int timeAccumulated = 0;
int timeStep = 1000; //period = 1000ms : frequency = 1fps
while (isRunning) //cpu
{
    tick();
}
//...or don't use such a loop, and instead call tick() on vsync event.

void tick()
{
    timeDelta = SomeMethod(); //may be yours, system's, or library's
    timeAccumulated += timeDelta; //see "Fix your Timestep"
    
    if (timeAccumulated <= timeStep)
    {
        timeAccumulated -= timeStep; 
    
        turn(); //call all your custom turn logic here
    }
    //inputs must have immediate effect, so are not called in turn()...
    isRunning = CheckKeyPressed("ESCAPE"); //for example
}

...So the outer block (while) controls actions which must have an immediate response, like queuing up input for use in the next turn, handling loads etc. OTOH the inner block (if) only allows this loop iteration to make game logic happen once a second has passed since the last turn was enacted.

deleted 12 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124
Loading
deleted 12 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124
Loading
deleted 12 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124
Loading
added 277 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124
Loading
added 2 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124
Loading
added 95 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124
Loading
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124
Loading