Last week I worked on creating a website to showcase a little bit of what Zero Gear is all in one place. You can view it here, at http:myZeroGear.com
Zero Gear website up!
Posted by David Marsh at 2:53 PM 9 comments
Templatize your factories
In Object Oriented Programming we create systems that manage objects. However, it is always a good idea to separate the implementation of the objects from the systems. This way, we can add or change objects and the system doesn't need to change.
This post is related to object Factories. A factory is responsible for creating objects. Here is a very simple example of an object factory:
IObject * ObjectFactory::CreateObject(const string & objectType)
{
if (objectType == "Model")
return new Model();
else if (objectType == "Sound")
return new Sound();
else if (objectType == "Light")
return new Light();
return NULL;
}
Each of these 3 objects derive from the IObject interface. Based on the type of the object ("Model", "Sound", or "Light") we create that object (new Model(), etc).
This is great. But we can improve...
What if we want to get a list of object types that the factory is able to create? This was my question and here is the way I solved the problem.
First we create an interface for our object factory. This would allow us to create multiple object factories for different parts of an application (one for the map editor, one for the driving level, etc) or for different applications all together.
class IObjectFactory
{
public:
IObject *(*Creator)(void);
virtual ~IObjectFactory() = 0 { }
/**
* Returns a list of objects that this factory can create
**/
list<string> GetCreationTypes(void);
/**
* Create an object of the type passed in
**/
IObject * CreateObject(const string & objectType);
protected:
void RegisterCreator(const std::string & objectType, IObjectFactory::Creator creator);
void UnregisterCreator(const std::string & objectType);
private:
IObjectFactory::Creator * GetCreator(const std::string & objectType);
map<string, IObjectFactory::Creator> objectCreators;
};
The concept is that we can Register a Creator into the IObjectFactory and then the factory will handle everything for us. We can create an object or get a list of object types that the factory can create at runtime without any additional modifications from us. The implementation for this interface is trivial...
This line is important:
typedef IObject *(*Creator)(void);
This defines a function pointer to a "Creator" function. This is a function that will create a specific object for us.
Here is a templated "Creator" for you to use:
template <typename T>
IObject * ObjectCreateFunction(void)
{
return new T();
}
Then simply inherit from IObjectFactory in your concrete object factory and define a constructor similar to this:
ConcreateObjectFactory::ConcreateObjectFactory()
{
RegisterCreator("Model", &ObjectCreateFunction<Model>);
RegisterCreator("Sound", &ObjectCreateFunction<Sound>);
RegisterCreator("Light", &ObjectCreateFunction<Light>);
}
P.S. I know that the IObjectFactory isn't a purely an interface but I am still going to call it an interface. Deal with it.
Posted by Brian Cronin at 3:12 PM 11 comments
Labels: code
more pretty pictures for you to eat
first up, we have 3 screenshots I put together, click to enlarge.
I also assembled 3 wallpapers (people always want wallpapers) in a veritable cornucopia of different resolutions.
standard ratio: 1024x768,1280x960,1600x1200
widescreen ratio: 1280x800,1440x900,1680x1050,1920x1200,2560x1600
standard ratio: 1024x768,1280x960,1600x1200
widescreen ratio: 1280x800,1440x900,1680x1050,1920x1200,2560x1600
standard ratio: 1024x768,1280x960,1600x1200
widescreen ratio: 1280x800,1440x900,1680x1050,1920x1200,2560x1600
Posted by David Marsh at 12:32 PM 2 comments
Labels: media
multi-player mayhem
Brian has been working a ton of hours getting the networking portion of our game far along enough to have our first Zero Gear play test, which we hosted at a LAN party this weekend. It seemed to be a great success and everyone seemed to have a great time driving around their characters even if we didn't have any real race rules in place yet. I was able to grab a lot of footage and I pieced together a little video, click the image below:
Here are a few action photos of the Zero Gear party in progress, thanks to everyone who came and played!
Posted by David Marsh at 6:56 PM 20 comments
New character poster, Robo Viking!
Here is another poster I whipped up after finishing the robot character. This little guy will pillage his way into your heart <3
Posted by David Marsh at 10:54 AM 5 comments
Labels: media
new character, now with 100% more robot
here is a quick look at a new character I just finished up
Here are a few more peeks at him with some different color schemes, of course you will be able to choose whatever combination you would like!
Posted by David Marsh at 2:38 PM 9 comments