Sign in to follow this  

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

Recommended Posts

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.

[b]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.[/b]

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this