• Advertisement
Sign in to follow this  
  • entries
    61
  • comments
    131
  • views
    32149

Progress.

Sign in to follow this  

190 views

Phew, I've done "alot" of programming lately. The first thing I did(which I did over a week ago) was to add HTML support for my logging system(including bold and colored text [grin]). The next thing I did, which I started on thursday was to make a 2D sidescroller....

Yeah, it failed, but I accomplished things I've never accomplished before. Things like textureswaps, moving bullets, gamestates etc. But therein lies the problem. I have never done such a thing before so I kinda suck at designing it(yes, I have started to write down my thoughts now). So I froze it the day before yesterday.

What now?

Well, since I managed to do textureswaps, gamestates and (partly) bullets, I thought I'd do it the proper way(Meaning acctualy deleting my allocated memory [grin]). So yesterday I started out with an ambitious idea to write my own allocation functions. It crashed... But today is a fresh day, and I would like some help on how to do things. So here's some questions:

How do you delete/store your resources?
Do you store them in one big std::vector or do you store them in separate ones?
Do you keep rendervectors?
I mean, f.ex in the menu state do you make a std::vector and in the gamestate do you make another one?
Do you even use std::vectors?
I read HopeDaggers journal and he said he used std::lists, I don't have any experience with std::lists.

Do you make a STATE class or do you just use a global string called gState?

How do you generate your textures(OpenGL)?
I managed to do this, but I'm not sure it's the best way. Right now when I create an object I push_back it to a static std::vector called Renderer::textures and store the position, then I call a method in Renderer which is called GenerateTextures which traverse through the Renderer::textures and calls glGenerateTextures(1, Renderer::textures). finnaly I retrieve my GLuint from the Renderer::textures list and load in images using SDL.

Thanks for any input!
Sign in to follow this  


4 Comments


Recommended Comments

Usually, I'll set up a system that allocates objects, gives them a unique ID number, and then holds them in a std::map. You can get the original object (or, better, a reference to it) quite easily, and the ID insulates you from the risks of having a lot of pointers floating around, while still being lightweight and nice and abstract.

Share this comment


Link to comment
Thank you, now one last question:

If I have a std::vector or map that stores pointers(CObject* f.ex), will I delete the object if I do:


delete(CMemoryManager::AllocVec[i]);


Thanks for answering my question, I'll go look up on std::map now.

Share this comment


Link to comment
I'm pretty sure that'll work.

Also, for iterated-deletion, use something like this:

for(std::vector<TYPE>::iterator ListItor = Vector.begin(); ListItor != Vector.end(); ++ListItor)
{
TYPE* pValue = (*ListItor);
delete pValue;
}



I'm not sure if it's required, but I always get errors when trying to call delete (*ListItor).

Anyway, std::map FTW!

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement