Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

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:

  1. 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.

  2. the database itself must be configurable outside of editor through xml file.

  3. Database reads files, creates registry

  4. Registry is hierarchically sorted in order of inheritance (objects without parents first, and so on)

  5. Database reads files and creates templates from them

    • templates remember the files they are and line
  6. when database is filled, it will provide ready entities on demand

Template construction:

  1. receive databaseID request
Entity GetEntity(string databaseID)
  1. find corresponding template
  2. if it has parent first construct parent
  3. 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

  1. have a directory filled with ".db" files
  2. each db file can have any amount of entities, so split is purely organizational/logical
  3. 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
  1. 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>>();        

    }
  1. template is used by entity factory, or to apply changes t existing entity
Clone this wiki locally