This repository has been archived by the owner on Mar 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Templating
pointcache edited this page Sep 11, 2016
·
11 revisions
Idea: Have a mechanism allowing to read text files in game directory and load data from them as entities on demand.
Benefits:
- database of entity templates, with definition inheritance
- runtime read/write/update/delta changes etc
- allows for dynamic replacement of an entity/component with updated one
- human readable format, with emphasis on editability outside of editor, modding
Proposal:
-
first step would be to have a "database" like system, that scans some root directory for all files of template format, builds a database from them.
-
the database itself must be configurable outside of editor through xml file.
-
Database reads files, creates registry
-
Registry is hierarchically sorted in order of inheritance (objects without parents first, and so on)
-
Database reads files and creates templates from them
- templates remember the files they are and line
-
when database is filled, it will provide ready entities on demand
Template construction:
- receive databaseID request
Entity GetEntity(string databaseID)
- find corresponding template
- if it has parent first construct parent
- we have 2 options here, 1- default would be slow reflection based component initialization from template string based value-pairs, with optional fast code generated initializers, in the end the method doesnt matter because all that is needed is a ready entity, how we achieve that may vary and i would encourage multiple ways.
- Template database allows to refresh template - read file on runtime and update cached template, find entities that are created from it and update them (or something like that)
#pipeline
- have a directory filled with ".db" files
- each db file can have any amount of entities, so split is purely organizational/logical
- content looks like this
//Only value types are allowed, simple string/int/floats
chicken "Chicken" // database id, actual Name
[Position] // component without any specific data, will be added by constructor
[Creature] // component with data, will be stored into database template, if no data is specified default values will be used
max_hp = 90000
attack_dmg = 1
attack = meelee
range = 1
speed = 1
run_speed = 3
[Behavior]
ai = animal/chicken
[ColorComponent]
color = #ffffff
[Resources]
prefabID = animals/chicken //strings used without quotes
iconID = animals/chicken
chicken_brown "Brown Chicken" chicken //ID, Name and PARENT ID
[ColorComponent]
color = #ffffff //custom deserializer picks up aliases and converts them
[Resources]
prefabID = animals/chicken
iconID = animals/chicken_brown
feather "Feather"
[Position]
[Item]
mass = 0.01
- its parsed into a template object
public class EntityTemplate
{
public string databaseID;
public string parentID;
public string Name;
public Dictionary<string, Dictionary<string, string>> components
= new Dictionary<string, Dictionary<string, string>>();
}
- template is used by entity factory, or to apply changes t existing entity