screen doesn't redraw when cpu in control!

BlitzMax Forums/BlitzMax Programming/screen doesn't redraw when cpu in control!

kaiserpc(Posted 2008) [#1]
Hi,

I'm writing a turn based strategy game for the Retro Remakes comp - deadline midnight gmt tonight!!

Anyway occasionally when the cpu is moving the enemy units, the screen isn't getting re-drawn - a hourglass appears and the screen remains static.

The game is still working because you can hear the movement sound effects, when it finally goes back to the player's move - the screen draw start working again!

This is in windowed mode by the way - haven't tested if it does the same full screen.

It only happens very occasionally but all my testers think the game has crashed and they ctrl-alt-del out

Any ideas? has anyone seen this before?


Brucey(Posted 2008) [#2]
You might want to split your "action" code over several cycles, rather than trying to do it all in the same frame.
Not difficult to do. I used the same method for some path-finding AI, when I had *many* bots trying to recalculate paths over a large, changing map. The closest ones (to the terrain change) would be processed first, while those further away would be processed several cycles later - therefore spreading the load out and stopping stutter/hangs.


kaiserpc(Posted 2008) [#3]
thx Brucey.

I'm afraid I'm a bit of a newbie (this is my 1st Blitzmax game) so not sure what you mean (my enemy moves one unit at a time - going through a tlist, so I don't have loads of units moving at the same time) or if this is the same scenario as I'm trying to explain.

to try and explain again the moves are happening (it's not a fps problem and there's no stuttering) because I can hear them, and the units are being moved - but the whole screen is frozen at the point it stop working and then a hour glass appear at this point and stays on the screen until the player takes control again


plash(Posted 2008) [#4]
Try a small delay (Delay(10)) in your mainloop.
It's common for games to *get stuck* because it does more logic than rendering (or- doing logic so much as to mess with windows).


Brucey(Posted 2008) [#5]
Doesn't the Flip cause the screen display to be updated, regardless what else is going on?
(Assuming we are talking about a graphics context, rather than say a GUI Canvas)


kaiserpc(Posted 2008) [#6]
no, thats just it the "flip" is there but it's just not redrawing in windowed mode - very bizarre. Also, it you click on the screen while the cpu is moving one of their units - it always freezes.

The window says "Blitzmax Application not responding" at the top and the hour glass appears.


MGE(Posted 2008) [#7]
"hourglass" ? ? ? I've never heard of this at all. Are you using MaxGui or a 3rd party gui? Or anything on standard that could be affecting the rendering pipeline?


kaiserpc(Posted 2008) [#8]
just using the standard build - no addons

the cursor changes to a hourglass until it's the player's turn - then everything is fine again


plash(Posted 2008) [#9]
@MGE: He is talking about the windows 'loading' cursor (which usually comes up when the application with focus is using alot of CPU power).

Also, it you click on the screen while the cpu is moving one of their units - it always freezes.
I've seen that alot with other applications/games when my CPU is being used heavily.

How long does it usually take for the calculations before it is the players turn?


MGE(Posted 2008) [#10]
ahh... ok..thanks Plash. Even with Plash's suggestion to put a Delay(10) in there it still happens?

As as last resort, post your code or an exe here so we can test it on our machines.


kaiserpc(Posted 2008) [#11]
To be honest, I'm not sure where this extra delay would go. Just before the flip?

Anyway, here is a link to the game (just download, and unzip everything to a new folder)

http://kaiserpc.co.uk/games/SorcererLord.zip (13mb)

I've uploaded the source to the same location:
http://kaiserpc.co.uk/games/SLGame.bmx
http://kaiserpc.co.uk/games/SLClasses.bmx

The "bug" happens intermittently so you might not see it to begin with


kaiserpc(Posted 2008) [#12]
Should have said the "flip" is in the "drawEverything" function, and the main game loop function is called "mainGameLoop"


plash(Posted 2008) [#13]
Eh.. after hardship with the menu/gui system (mouse clicks take a while to get noticed, and it crashed once), I finally got it to start a game.

I think it's because your doing alot of stuff in between rendering a single frame, really hard to say for sure.
You definitely have a major issue with event/key handling though.


kaiserpc(Posted 2008) [#14]
yep, I know about the lag in the menu - will be fixed in the next version (never had it crash before though - where did it crash, and what were you doing?)

- As for my real issue with the app not responding when the enemy is moving, I don't think I'm doing a lot different to when the player moves - there is probably more things for the cpu to check when the player moves. So I don't understand why it only happens when the cpu is moving - plus it only happens intermittently - very confused :-(