There are two classes in my game that are really useful, but slowly becoming a pain. Message and Property (property is essentially a component).
They both derive from a base class and contain a static id so that systems can only pay attention to the ones they want to. It's working out very well... except...
I'm constantly making new message types and property types as I extend my game. Each time I need to write 2 files (hpp and cpp) and a ton of boilerplate to get essentially an classID and one or two standard data types or a pointer.
It's starting to make playing around and testing out new ideas a real chore. I wish when I want to create a new message or property type, I want to be able to just type something like
ShootableProperty: int gunType, float shotspeed;
ItemCollectedMessage: int itemType;
instead of creating a header and cpp file, writing a constructor, including the parent class, etc etc.
It's around 20 - 40 lines (including include guards, and everything) just to do what logically is 1 or 2 lines in my mind.
Is there some programming pattern to get around this?
What about with scripting (which I know nothing of)... is there a way to define a bunch of classes that are almost the same?
Here is exactly what one class looks like:
// Velocity.h
#ifndef VELOCITY_H_
#define VELOCITY_H_
#include "Properties.h"
#include <SFML/System/Vector2.hpp>
namespace LaB
{
namespace P
{
class Velocity: public LaB::Property
{
public:
static const PropertyID id;
Velocity(float vx = 0.0, float vy = 0.0)
: velocity(vx,vy) {}
Velocity(sf::Vector2f v) : velocity(v) {};
sf::Vector2f velocity;
};
} /* namespace P */
} /* namespace LaB */
#endif /* LaB::P_VELOCITY_H_ */
// Velocity.cpp
#include "Properties/Velocity.h"
namespace LaB
{
namespace P
{
const PropertyID Velocity::id = Property::registerID();
} /* namespace P */
} /* namespace LaB */
All of that just for a 2D Vector and an ID saying to expect a 2D vector. (Granted, some properties have more complicated elements, but it's the same idea)