How do you split your game logic into two groups: background rendering, and game dialogs?

Started by
3 comments, last by tom_mai78101 11 years, 9 months ago
I have a game loop, with two functions, Render() and Tick(). Tick() is a conditional function with many other objects interacting within this, and runs nearly 30 times before Render(), which draw frames onto the screen, is run 1 time. That's a close 1:30 ratio for those two functions, respectively.

I wanted to create a dialog that asks for user name input inside Tick(). My hypothesis is that while the game screen is running Render() for background rendering, I can also run Tick() and check both for user input and object interaction. And once the user finishes input and executing a specific command, I can dismiss the dialog, continue object interactions, and continue rendering normally.

However, my conclusion is that my hypothesis is flawed, but I have no clue to how to fix this. I have tried a few implementations on my Android phone, and get a variety of different results. For example, sometimes the dialog shows up, but the rendering is out of sync. Sometimes, the dialog failed to appear, but the rendering is working nicely. There was one extremity that causes both Eclipse IDE and my Android phone to freeze, and that was when I was trying to implement a synchronized wait-notify method, and resulted in hundreds of thousands of threads running in parallel.

In short, implementation is currently bugged with my hypothesis. I would like for some help in figuring out how I should split my game logic, so that I can get user input, check for object conditions, and render frames onto the screen, without being so flawed?

Thanks in advance.

If TL;DR, I'm in a month-long developer's hell, and I have been unable to successfully implement my plans. Please help me.
Advertisement
All rendered stuff should be updated every frame.

When you want to stop game logic because of dialog just stop updating game logic and update only dialog logic.

Peace and love, now I understand really what it means! Guardian Angels exist! Thanks!

How do you stop updating a game loop that has the speed of 30 ticks per frame, 60 frames per second?
while (game_running)
{
if (dialog_mode)
update_dialog();
else
update_game(); // or "tick" as you call it
}

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

I think I got the gist of it. Here's what I've come up, derived from ApochPiQ:

  1. Instead of using if...else... to split the game loop into two sections, I can increase the number of sections using a switch statement.
  2. A player do not have more than 1 focus on a screen that spans across two or more sections.
  3. One thread for game loop is enough to do rendering, game logic, dialog, user input, etc. Basically, everything can be done with 1 thread.

Guess I'll have to re-write my game. Caught a flu, so it won't be easy.

This topic is closed to new replies.

Advertisement