Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Game States

Author
Message
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 22nd Apr 2010 02:38
I was looking at the tutorial for dark invaders that comes with Dark GDK and he does the states through a switch case. I was trying to do that with my project just for some testing but ran into some problems. Here is the basics of what I am doing with my cases:



So this is where my problem is in Gamesetup() it looks like this:




So I'm setting up the world (which is just a box2d thing to set the physics world) and running all of my setup. Pretty self explanatory. Now when I want to run my GamePlay() function which looks like this:



In Gameplay() I make calls to things like mouse and keyboard but since they are in the setup function they don't know about each other. How can I initialize something in one function and then use it in other functions?

Also is this even the right way to do game states. If not any other suggestions because this is really just a test for my game to make sure I can switch from a start screen to the actual game.
Bran flakes91093
15
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 22nd Apr 2010 03:03
You could declare them at the global scope so every function can use them.

"A computer once beat me at chess, but it was no match for me at kick boxing."
Emo Philips
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 02:34
Hey thanks for the response that worked kind of. My boxes aren't updating at all now but I'm sure I will figure it out. Thanks.
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 04:08
So I was doing some testing and took the GamePlay() Function and just put that in the while loop. Here is what it looks like:



here is the function:



So for some reason my boxes will draw but they wont update. Anyone know why?
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 05:06
Ok, I have a bit of time this evening, I can look at what you got, but I need to see *all* of the code that pertains to this issue...

The only thing I do know is that your gamePlay() function does not offer any means to escape (ie: change state) and since it's called (according to your original switch-block above) when game-state is set to "egamePlay", all I see is an infinite loop... How do you exit egamePlay state?

Let me see what you have and I can try and help...

JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 05:25
Here is my main.


There are a few things that I tested and figured out but I am still having trouble with the update.

So first off these lines of code are what was giving me problems before:



Basically I have to call b2World after I set the upper and lower bound of the physics world problem is I am using world in my GamePlay() function so I cant globally declare b2World because it has to be after


Now in the main that I provided I am jut trying to get the function to work before I use the case switches so thats why some of that code isn't being used.

So I'm a little confused as to why it works when I take it out of the function and just put it in the while loop. Isn't putting that function doing the same thing as just putting it in the while loop?

I will be checking this often since you are going to take some time out of your night. If you need anything else let me know.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 05:51
That's not true, what you have is:

1) Global scope b2World, and;
2) Local scoped b2World (local to LoopGDK function).

So, in LoopGDK(), your call to world.step() is calling the local instance (not the global instance). Not sure if this is the *source* of your problem, but it can't help it none and from your description, it would appear to be so...

My suggestion, just from first looks, is to declare the global scope as b2World *world = NULL; and remove the local LoopGDK scoped variable...

then after your calls to worldAABB.lower/upper bound you can create the pointer such as:

world = new b2World(worldAABB, gravity, doSleep);

This, of course, changes your world from an instance to a pointer of an instance, so everywhere you pass an &world parameter, change it to *world to dereference it and then pass that reference instead...

See how that works for you...

I'll be checking back soon, so let me know. BTW: This still does not address the fact that playGame() has no means of escape, keep that in mind as you move forward...

JTK

Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 05:51
So I might have narrowed it down but it stills goes back to my original question.

How can I declare this code:




in void DarkGDK ( void ) and then call world in my function GamePlay()?

When I do that it gives me errors because it doesn't know what world is.

Any suggestions on that?
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 05:53
Yup that's what I was thinking and you just answered my question I will try this with my code and see what happens. Also As of right now I don't really have a game that's why I am not exiting the state as of right now. But I will post back If i get it to work
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 06:05 Edited at: 23rd Apr 2010 06:13
Just getting some errors with my rigid body classes. Do I actually have to go in and change what I am referencing for example my GameObject class takes a pointer to b2World like this:



Because of how we changed b2World do I need to change all my classes to?

If so how exactly do I do that?

Still new to pointers =)

EDIT:
So Got the errors to go away but now it breaks when I try to create a rigid box. Guessing it still has to do with my pointer and what not.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 06:09
No. My mistake, if the parameter calls for a b2World*, just pass world as is, w/o the & or the * (it's alread a pointer)... My bad...



JTK
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 06:11
NOTE: That includes the code I just gave you...

JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 06:13
Tried that and it breaks on me coukld that be because of the pointer or maybe something else?
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 06:17
Doubt it, but I know nothing about your rigidbox classes...

In the code I gave back, search and replace:

Search: "(*world)"
Replace: "world"

Note, exclude quotes (")... You don't want & or * prefixing world...

If that doesnt' fix it, then I need to see the rididbox classes too...


NOTE TO ALL: And thus the importance of including source with your inquiries... (forgive me poof, I just had to do it... )

JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 06:24 Edited at: 23rd Apr 2010 06:31
Yeah I replaced it all and it works but I get that break so do you just want my rigidbox class or should I just give you my all my source files?

I will give you the GameObject class which is what it derives from and the rigid box class for now:


GameObject.h




GameObject.cpp



RigidBox.h




RigidBox.cpp


RigidBox derives from box which derives fro game object but box and rigidbox are almost the exact same thing just two lines of code difference so gameobject is probably going to help more

Also this is where the break takes me if it helps. It is a file from box2d.

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 06:30
What's the error it gives you? With what I'm seeing, there shouldn't be a problem...

JTK



OOOOOOoooooohhhhhh.....

I'll bet you're getting an Undeclared value (or something to that effect) aren't you?
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 06:32 Edited at: 23rd Apr 2010 06:35
Expression cannot be evaluated is what I see in the watcher window.

Sorry this is the message that pops up when it breaks to

Unhandled exception at 0x004e1e5c in Getting Started.exe: 0xC0000005: Access violation reading location 0x000191d4
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 06:34
Ok... Hold on, didn't see the part with the link-list the first pass...

Give me a few, although it'd prob be better to send me the entire code: jumpster at gdnmail.net if you would...

Regards,
JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 06:41
Going to attempt to attach it here. Tell me if it worked
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 06:42
At first glance, this would appear to be the culprit:

b2Body* b = new (mem) b2Body(def, this);

Try removing the (mem) since that's trying to typecast to an actual variable name (mem is declared just above it); for that matter, try removing the mem-declaration above it - from the looks, it's trying to call it's own allocation routine - which for debugging purposes, we'll try to circumvent...

What's that do?

JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 06:49 Edited at: 23rd Apr 2010 06:52
Well that is a box2d function. I didn't make it I am just using it as the physics for my game so I don't think I should change anything from box2d

Oh btw my project is to big because box2d is like 42mb and I haven't tried going through there files yet and deleting what I don't need. Just figured I would do that when the game is closer to being distributed. So would it help if I gave you all the files I'm currently using in my project or do you need to be able to compile them
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 06:51
Fine. I agree with that, but I don't see the attachment above, so I can't really tell what's going on...

Can you at least step through the code and tell me exactly which line it is breaking on?

JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 06:55 Edited at: 23rd Apr 2010 07:03
Its breaking on the creation of the object here:



EDIT:
Be back soon leaving from school to go home.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 07:40
Yes, I would need to compile them, is it an entire project? If so, feel free to delete the following files:

Anything in the DEBUG or RELEASE sub directories,
Any VC++ Intellisense files (HUGE) - I can recreate here,

Actually, for that matter, I only need the SOU file(s), project files (if more than one) but most importantly, I need the .H and .C/.CPP files (presumably .CPP) - I just need the source files (not neccessarily the ability to compile).

JTK
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Apr 2010 07:58
Sorry, but it's nearly 1am here, I have to get to bed now.

Either email me the source (address above) or post it here, with out it, I can't do much more as I have to be able to follow the flow...

I'll check both in the morning, until then, sorry I wasn't much help.

Good-night!

JTK
marlou
15
Years of Service
User Offline
Joined: 17th Jan 2009
Location:
Posted: 23rd Apr 2010 10:32
Maybe it's this one. XD

The RigidBox pointed to by Temp gets deleted after the while loop since its declared in a local scope.
Try declaring the pointers RigidBox* Temp and Box* Temp global.
Or use smart pointers and not naked pointers..
Tell me if it works XD

When a person has nothing but a dream, can he dare to dream.
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 23rd Apr 2010 13:26
Hey JTK sorry I wasn't able to respond. I am going to try an figure it out for tomorrow. The point you got me to makes since so I will try and mess with my code and figure it out for myself, If I get really stumped I will respond back to this post. But thanks for where you have got me I guess the only thing I have left to ask is that the right way we should be doing it?

I mean is there any other way for me to be able to call "world" in my GamePlay() function? If not then I will keep messing with my code until I get it to work. Also, if anything I will actually go through my files and make it so it isn't so big so I can give them to you.

Marlou:
I'm still a little new to programming so when you say smart pointers to naked pointers I don't really know the difference but honestly please inform me because I am always down to learn new concepts.

Again thanks for the help guys.

Login to post a reply

Server time is: 2024-07-07 01:36:10
Your offset time is: 2024-07-07 01:36:10