RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic  
View previous topic - View next topic  
Author Message
Gardon
Scholar


Joined: 05 Feb 2006
Posts: 157

PostPosted: Wed Mar 15, 2006 3:04 am    Post subject: GameSTate problem [quote]

Ok, so I got the menu and engine classes to work together.

Basically what I do is run a loop in main, which polls for input,

etc. and then has a switch statement for the current gamestate

The gamestate is initially set to MENU, since menu will be the first action
performed by the game, so the switch statement executes Menu's run function.

The run function returns a gamestate, which is set globally to the gamestate, so it can change to engine if necessary (like if the user clicks the new game button, the gamestate will change in menu, which agani will change in the main loop, causing GAMELOOP to execute next, in stead of MENU)


Ok!

The problem lies in going back to menu. I have the mouse
and keyboard input all set for getting into engine, but I
can't get the user back to menu once in engine.

I basically poll for the escape key in engine, and if that
key is pressed, the gamestate is returned through engine's
run function, changing the global gamestate to execute
MENU on the next loop.

But when I go back to menu it seems as if it's still
executing the engine's Draw function, because it keeps
flipping between the menu bitmap and the engine
screen (causing flicker)

But this is impossible because I only have 2 gamestates:
MENU and GAMELOOP, which change based on the
returned state from that case in the switch statement.

so when the escape key is registered in Engine->Run(),
at the end of the Run function it returns MENU as the
new gamestate, so the next loop through main will
execute MENU's run function.


If you guys want the project to look at, let me know.
I just don't see how this is possible.


Oh, and I know it's still calling engine's update method
because I've changed the screen and stuff, and it
still draws what I told it to in the function I'm no longer
calling.


What the hell?

Thanks,

Jason
Back to top  
cowgod
Wandering Minstrel


Joined: 22 Nov 2005
Posts: 114
Location: Pittsburgh, USA

PostPosted: Wed Mar 15, 2006 4:08 am    Post subject: [quote]

Are you using a double buffer? Make sure you're not switching buffers when you don't need to or drawing to the wrong buffer or something.

Is the engine drawing in a seperate thread from the main loop? If so, you need to terminate the seperate thread.

Are you using Java? If not, I can't really help you by looking at the code.

If you are, it may be that you have to turn off the repainting and paint the game actively.
Back to top  
Gardon
Scholar


Joined: 05 Feb 2006
Posts: 157

PostPosted: Thu Mar 16, 2006 12:14 am    Post subject: [quote]

Hmmmm... well, what I'm doing is passing the graphics object to the menu and and engine classes.

Graphics is initially initialized and sets up all the SDL_Video stuff to get the window up and everything.

I don't think it's the buffer because it seems as though it's running the engine->Run() code without me instructing to do so.


Anyway, if you could help me out with this that would rock. Here's the version.


To look at the thing, just check out:

main.cpp
graphics.h
menu.cpp/h
engine.cpp/h

and possibly

enums.h

thanks,

Jason
Back to top  
cowgod
Wandering Minstrel


Joined: 22 Nov 2005
Posts: 114
Location: Pittsburgh, USA

PostPosted: Thu Mar 16, 2006 5:01 am    Post subject: [quote]

I downloaded the file, but I don't have the right software to open it. (I guess I should get WinRar or something.)

I'm not sure whether I'd be able to solve your problem anyways, as I've been using Java instead of C++ for game programming for the past 5 or 6 years.

Could someone else take a look at his code?
Back to top  
cowgod
Wandering Minstrel


Joined: 22 Nov 2005
Posts: 114
Location: Pittsburgh, USA

PostPosted: Thu Mar 16, 2006 5:02 am    Post subject: [quote]

Also, you might want to post on a more programming-centric forum, such as http://www.garagegames.com.
Back to top  
Gardon
Scholar


Joined: 05 Feb 2006
Posts: 157

PostPosted: Thu Mar 16, 2006 11:14 pm    Post subject: [quote]

that's fine, thanks for the link

Jason
Back to top  
Post new topic Reply to topic Page 1 of 1 All times are GMT
 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum