• 9
• 13
• 18
• 19
• 27

global variables & vectors

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

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 on other sites
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 on other sites
Quote:
 Original post by ToohrVykThe 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.

I think i understand now , but thats just theory!

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 on other sites
std::vector<SDL_Surface*> surfaces;surfaces.push_back(SDL_GetScreen());

Share on other sites
Quote:
 Original post by ToohrVykstd::vector 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:

thanks for the great help so far ! .

~delete me
..double 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 on other sites
Quote:
 Original post by ToohrVykWell, 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!