This is very outdated and doesn't reflect the state of the project well. I'll write about current architecture some day! (Posted on 21-02-17)Some programming stuff.I use C++11 with SFML and Lua for scripting. The most important aspect of the engine is entity/component/system model. Here's my implementation of it.
Entities are different objects in the game: characters, houses, items, etc.
Each entity has unique id (which is used to identify them) and a number of components.
So, characters have:
GraphicsComponent,
MovementComponent,
CollisionComponent,
HealthComponent, etc.
Static objects don't need all of that so they only have
GraphicsComponent and
CollisionComponent.
So, entities are made from "blocks". Those blocks can have unique behaviour by scripting. But I'll talk more about that later.
Basically, it looks like this in code:
class Entity {
public:
... // some stuff
private:
int uid;
std::vector<std::unique_ptr<Component>> components;
... // some other stuff
};
Component is simply a collection of data. For example,
GraphicsComponent holds sprite and other stuff related to graphics,
MovementComponent has velocity, etc.-etc.
Systems operate on components. Basically most of the game logics is there.
For example,
MovementSystem iterates over
MovementComponent's of active objects and adds to a current position for each entity. Most systems operate on one type of component and it doesn't matter to them what entity any component belongs to. This makes adding new types of entities easy as I don't have to change logics very often.
Entity definitions are stored in Lua scripts. Here's an example of a chest entity:
http://pastebin.com/P3mAD8NNAs you can see, every component parameter is here but I can also define functions in Lua script. This let's me specify object behaviour so it's not hard coded in C++! This is very useful as I don't have to recompile the game very often.
Lots of Lua function have bindings to functions in C++, so I can use this function in a script:
setAnimation(someEntity, "animationName")
which will call this function in C++
void setAnimation(ind entityId, const std::string& animationName) {
auto e = engine_system.em->getEntity(entityId);
... // code to set animation
}
Notice, that I don't pass around pointers or entity references but instead pass ints which is faster.
Getting entity from id is also fast, as each entitiy is stoped in a hash map and can be quickly accessed by unique id.
Once the entity templated is loaded in C++, every entity of this "class" is created with the template which is a lot faster than reading properties from scripts over and over.
There's some basic support for "inheritance" so if some entities have lots in common, they can use other entities properties, overwrite some properties and add new components.
Here's an example of that a chest that uses different sprite:
http://pastebin.com/6pQKJz5PAs you can see, there's no need to copy-paste everything, I can just change some of the parameters, the rest will be copied from base entity.
Chest vs super_chest. The only thing different is the graphics and size. (You can read more about inheritance and scripting
here)
My game also has in-game level editor.
Bigger gif:
http://i.imgur.com/8HtWIYU.webmIt has lots of features: tile map editing, multiple object selection and moving, object creation, undo, etc.
And that's basically it. If you have some questions, feel free to ask!
(I'll write about messaging between systems, events and decoupling soon!)