source: cpp/frams/_demos/genotypeloader.cpp @ 635

Last change on this file since 635 was 635, checked in by Maciej Komosinski, 7 years ago

Introduced specialized info_* fields in (Mini)Genotype that match FEC fields

  • Property svn:eol-style set to native
File size: 3.5 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[635]2// Copyright (C) 1999-2016  Maciej Komosinski and Szymon Ulatowski.
[286]3// See LICENSE.txt for details.
[109]4
5#include "genotypeloader.h"
6
7#define FIELDSTRUCT MiniGenotype
[635]8ParamEntry minigenotype_paramtab[] =
9{
10        { "Genotype", 1, 29, "org", },
[473]11
[635]12        { "name", 0, 0, "Name", "s 0 40", FIELD(name), },
13        { "genotype", 0, 0, "Genotype", "s 1", FIELD(genotype), "Genes as a string of characters.", },
[473]14
[635]15        { "info_timestamp", 1, 0, "Creation time", "fd 0 -1 0", FIELD(info_timestamp), },
16        { "info_author", 1, 0, "Author name", "s 0 100", FIELD(info_author), },
17        { "info_author_ispublic", 1, 0, "Author name is public", "d 0 1 1", FIELD(info_author_ispublic), },
18        { "info_email", 1, 0, "Author email", "s 0 100", FIELD(info_email), },
19        { "info_email_ispublic", 1, 0, "Author email is public", "d 0 1 0", FIELD(info_email_ispublic), },
20        { "info", 1, 0, "Description", "s 1 1000", FIELD(info), "Short description of key features of this creature.", },
21        { "info_origin", 1, 0, "Origin", "d 0 4 0 ~Unspecified~Designed~Designed and evolved~Evolved under various conditions~Evolved using single, constant setup", FIELD(info_origin), "Declaration of how this genotype originated." },
22        { "info_how_created", 1, 0, "How created", "s 1 1000", FIELD(info_how_created), "Description of the process of designing and/or evolving this genotype." },
23        { "info_performance", 1, 0, "Performance notes", "s 1 1000", FIELD(info_performance), "Description of why this genotype is special/interesting and how it performs." },
[473]24
[635]25        { "energy0", 0, 0, "Starting energy", "f 0 -1 0", FIELD(energy0), },
26        { "numparts", 0, 0, "Body parts", "d", FIELD(numparts), },
27        { "numjoints", 0, 0, "Body joints", "d", FIELD(numjoints), },
28        { "numneurons", 0, 0, "Brain size", "d", FIELD(numneurons), },
29        { "numconnections", 0, 0, "Brain connections", "d", FIELD(numconnections), },
[473]30
[635]31        { "num", 0, 0, "Ordinal number", "d", FIELD(ordnumber), },
32        { "gnum", 0, 0, "Generation", "d", FIELD(generation), },
[473]33
[635]34        { "instances", 0, 0, "Instances", "d", FIELD(instances), "Copies of this genotype", },
[473]35
[635]36        { "lifespan", 0, 0, "Life span", "f", FIELD(lifespan), "Average life span", },
37        { "velocity", 0, 0, "Velocity", "f", FIELD(velocity), "Average velocity", },
38        { "distance", 0, 0, "Distance", "f", FIELD(distance), },
39        { "vertvel", 0, 0, "Vertical velocity", "f", FIELD(vertvel), },
40        { "vertpos", 0, 0, "Vertical position", "f", FIELD(vertpos), },
[473]41
[635]42        { "user1", 0, 0, "User field 1", "x", FIELD(user1), },
43        { "user2", 0, 0, "User field 2", "x", FIELD(user2), },
44        { "user3", 0, 0, "User field 3", "x", FIELD(user3), },
[473]45
[635]46        { "is_valid", 0, 0, "Validity", "d -1 1 -1", FIELD(is_valid),
47        "0 = invalid genotype\n"
48        "1 = valid genotype\n"
49        "-1 = validity is not known." },
[473]50
[635]51        { "uid", 0, 0, "#", "s", FIELD(uid), "Unique identifier" },
52
53        { 0, 0, 0, },
[109]54};
55#undef FIELDSTRUCT
56
[635]57MiniGenotypeLoader::MiniGenotypeLoader() :genotype_param(minigenotype_paramtab, &genotype_object) { init(); }
58MiniGenotypeLoader::MiniGenotypeLoader(VirtFILE *f) : MultiParamLoader(f), genotype_param(minigenotype_paramtab, &genotype_object) { init(); }
59MiniGenotypeLoader::MiniGenotypeLoader(const char* filename) : MultiParamLoader(filename), genotype_param(minigenotype_paramtab, &genotype_object) { init(); }
[109]60
61void MiniGenotypeLoader::init()
62{
[635]63        addObject(&genotype_param);
64        breakOn(MultiParamLoader::OnError + MultiParamLoader::AfterObject);
[109]65}
66
67MiniGenotype* MiniGenotypeLoader::loadNextGenotype()
68{
[635]69        genotype_object.clear();
70        if ((go() == AfterObject) && (getObject().matchesInterfaceName(&genotype_param)))
71                return &genotype_object;
72        else
73                return 0;
[109]74}
Note: See TracBrowser for help on using the repository browser.