Jump to content
  • Advertisement
Sign in to follow this  
3Dgonewild

global variables & vectors

This topic is 4035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi from a bad programmer ... In my games im using global variables...for almost everything. I know it sucks , but I HAVE NO IDEA what else to try. Also , im using ARRAYS -ready to EXPLODE- for images/textures ETC. IM ASKING for your help! What else can i try ? i need to improve my skills , please HELP! Also , can you tell me how to use vectors? Thanks..

Share this post


Link to post
Share on other sites
Advertisement
The fundamental thing you have to do is forget about "the". There is no such thing as "the renderer", "the world", "the resource manager". Think in terms of "one of the many": "one of the many renderers", "one of the many worlds", "one of the many resource managers". Just like you would think "one of the many enemy characters", for instance.

If an entity needs to interact with another entity (entities being functions, objects, or anything else), simply pass one entity to the other by reference.

For instance, if your player needs to draw something, then you will have to give it "one of the many resource managers", from which it will extract the correct model, and the "one of the many renderers", into which it will insert the model to be rendered.

The fact that, in the end, your game will use only one renderer is only a coincidence that you should not rely on when writing the rest of your code: always assume that you have many different objects of the same type lying around at any given time, so that every object needs its users to specify which precise renderer/world/manager it needs to use.

As for vectors, I suggest that you go read an online tutorial (there are many around) and come back with more precise questions.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
The fundamental thing you have to do is forget about "the". There is no such thing as "the renderer", "the world", "the resource manager". Think in terms of "one of the many": "one of the many renderers", "one of the many worlds", "one of the many resource managers". Just like you would think "one of the many enemy characters", for instance.

If an entity needs to interact with another entity (entities being functions, objects, or anything else), simply pass one entity to the other by reference.

For instance, if your player needs to draw something, then you will have to give it "one of the many resource managers", from which it will extract the correct model, and the "one of the many renderers", into which it will insert the model to be rendered.

The fact that, in the end, your game will use only one renderer is only a coincidence that you should not rely on when writing the rest of your code: always assume that you have many different objects of the same type lying around at any given time, so that every object needs its users to specify which precise renderer/world/manager it needs to use.

As for vectors, I suggest that you go read an online tutorial (there are many around) and come back with more precise questions.

Thanks for the reply...

I think i understand now , but thats just theory!
Are there any tutorials about this?


Share this post


Link to post
Share on other sites
Ok , i think i found the right way(classes).

Now i have another problem..with vector..

How can i create a vector surface array?

Something like this:


vector <SDL_SURFACE> test;

and then somehow i want to be able to add more surfaces...

any help?

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
std::vector<SDL_Surface*> surfaces;
surfaces.push_back(SDL_GetScreen());



thanks!
Is there any problem if replace "sdl_getscreen" with a counter(integer)?
also , how can i force the selected item to load an image?

example:

surfaces.selectedITEM(0).LOADIMAGE="b.png";


thanks for the great help so far ! .

Share this post


Link to post
Share on other sites
Well, there is obviously a problem, since an integer counter is not a surface. The vector contains surfaces, not integers!

You can do whatever you wish with the contents of the vector—they're images, after all.

However, loading functions usually return a new surface, so you would push that surface into the vector.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Well, there is obviously a problem, since an integer counter is not a surface. The vector contains surfaces, not integers!

You can do whatever you wish with the contents of the vector—they're images, after all.

However, loading functions usually return a new surface, so you would push that surface into the vector.


Sorry , im confused . ..

So , when you call "push_back" , you're actually adding a new slot in the surface array? or im wrong?
What i dont understand , is "SDL_GetScreen()" function.
I cant find any information for this function!

thanks for your time.

Share this post


Link to post
Share on other sites
It doesn't add a new slot: it adds a new element.

I don't think the SDL_GetScreen even exists. But if it did, it would return the screen surface.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!