Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 tom_mai78101   Members   -  Reputation: 568

Like
0Likes
Like

Posted 01 July 2012 - 04:54 AM

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.

Sponsor:

#2 DemonRad   Members   -  Reputation: 290

Like
0Likes
Like

Posted 01 July 2012 - 08:15 AM

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!


#3 tom_mai78101   Members   -  Reputation: 568

Like
0Likes
Like

Posted 01 July 2012 - 05:45 PM

How do you stop updating a game loop that has the speed of 30 ticks per frame, 60 frames per second?

#4 ApochPiQ   Moderators   -  Reputation: 14671

Like
0Likes
Like

Posted 01 July 2012 - 06:08 PM

while (game_running)

{

    if (dialog_mode)

        update_dialog();

    else

        update_game(); // or "tick" as you call it

}


#5 tom_mai78101   Members   -  Reputation: 568

Like
0Likes
Like

Posted 02 July 2012 - 08:01 AM

I think I got the gist of it. Here's what I've come up, derived from ApochPiQ:
  • Instead of using if...else... to split the game loop into two sections, I can increase the number of sections using a switch statement.
  • A player do not have more than 1 focus on a screen that spans across two or more sections.
  • 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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS