Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Creating a Data Block Loader or something?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 ankhd   Members   -  Reputation: 1523

Like
0Likes
Like

Posted 13 May 2014 - 11:58 PM

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

 

 



Sponsor:

#2 EarthBanana   Members   -  Reputation: 1090

Like
1Likes
Like

Posted 14 May 2014 - 10:14 AM

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, 14 May 2014 - 10:16 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS