Jump to content
  • Advertisement
Sign in to follow this  
ankhd

Creating a Data Block Loader or something?

This topic is 1496 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

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

class basemenu;//do stuff

class MainMenu :public basemenu
{
do stuff
};

then I allocate them like so

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

basemenu[1] = new AboutMenu();

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

class basestreamloaderdata;

class StreamLoaderMenuItem : public basestreamloaderdata
{
public:

StreamLoaderMenuItem (void){}
virtual ~StreamLoaderMenuItem (void){}

//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

};//end StreamLoaderMenuItem

 

this class StreamLoaderMenuItem, is 1 menu that can be loaded later.
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 this post


Link to post
Share on other sites
Advertisement

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>	
MenuType * getMenu(std::string & pMenuName)
{
	if (hasMenu<MenuType>(pMenuName)) // check to make sure it has the menu
		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

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!