• 15
• 15
• 11
• 9
• 10

# Creating a Data Block Loader or something?

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

## Recommended Posts

Hello.

I would like to load all my game data from a vector list so I can load one block(List Item)at a time
and report back to the render function on its progress or even a block at a time( a numer of items).
But I have came across the issue where say for my menu classes there all derived from a base menu class

like this

{
do stuff
};

then I allocate them like so

basemenu[0] = new MainMenu();//this is the part I can't pass in

How Would I create a base class to contain the different classes that need allocation

I was going down this here path when I got to the part to create a block to add to the loadstream class

{
public:

//data each menu item need to load
Camera *cam;
basemenu *menu;//this is where I need to new each class type

//someobj that takes the new data loaded
ObjDataOwner *owner;//where the new data it to go
//other suff

At the moment I allocate the menu pointers,  when I add the item to the vector for later process.

I don't want to have a base class for each menu type.
I'm not to sure on template classes I have used them in the past., but not for allocation of different types

##### Share on other sites

You can use templated classes to load different types - in fact its how I load different types of components in to one component vector.. just make whatever your container class is (in my case Entity) templated so that it can call new TemplateType() on whatever subclass type you are trying to add to the vector..

ie my templated Entity class adds components like this

	template<class CompType>
CompType * createComponent(NSbool pOverwrite=true)
{
CompType * comp = new CompType(this);
comp->init();
mComponents[CompType::getType()] = pComp;
return comp;
}


where mComponents is a vector of component pointers (I removed some error checking stuff to make it more readable)... I personally use a known index system so that certain components are always at certain positions in the vector - but that is irrelevant for you - you could just add the new component with a push back

Also - when you get you menus.. if you have a templated container class to get them from - you can get them without having to typecast each time... just define a getMenu function and do the typecast within the function returning the templated type.. something like this..

template<class MenuType>
{
return (MenuType*)mMenus.findMenu(pMenuName); // do the typecast here - you might want to use a different type of cast but even this should work
return NULL; // if no menu was found return NULL
}


Hope that helps

Edited by EarthBanana