Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Creating a Data Block Loader or something?

4: Adsense

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   


Posted 13 May 2014 - 11:58 PM


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

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



#2 EarthBanana   GDNet+   


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);
                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.