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

Last change on this file since 473 was 473, checked in by sz, 9 years ago
  • MiniGenotype? extended to handle all Genotype fields contained in .gen files
  • loader_test now displays any MiniGenotype? field instead of the raw genotype when given the field name
  • MiniGenotypeLoader? and stdiofile.o included in SDK_LIB_OBJS
  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#include "genotypeloader.h"
6
7#define FIELDSTRUCT MiniGenotype
8ParamEntry minigenotype_paramtab[]=
9 {
10 {"Genotype",1,21,"org",},
11
12 {"name",0,0,"Name","s 0 40",FIELD(name),},
13 {"genotype",0,0,"Genotype","s 1",FIELD(genotype),},
14 {"info",0,0,"Info","s 1",FIELD(info),},
15
16 {"energy0",0,0,"Starting energy","f 0 -1 0",FIELD(energy0),},
17 {"numparts",0,0,"Body parts","d",FIELD(numparts),},
18 {"numjoints",0,0,"Body joints","d",FIELD(numjoints),},
19 {"numneurons",0,0,"Brain size","d",FIELD(numneurons),},
20 {"numconnections",0,0,"Brain connections","d",FIELD(numconnections),},
21
22 {"num",0,0,"Ordinal number","d",FIELD(ordnumber),},
23 {"gnum",0,0,"Generation","d",FIELD(generation),},
24
25 {"instances",0,0,"Instances","d",FIELD(instances),"Copies of this genotype",},
26
27 {"lifespan",0,0,"Life span","f",FIELD(lifespan),"Average life span",},
28 {"velocity",0,0,"Velocity","f",FIELD(velocity),"Average velocity",},
29 {"distance",0,0,"Distance","f",FIELD(distance),},
30 {"vertvel",0,0,"Vertical velocity","f",FIELD(vertvel),},
31 {"vertpos",0,0,"Vertical position","f",FIELD(vertpos),},
32
33 {"user1",0,0,"User field 1","x",FIELD(user1),},
34 {"user2",0,0,"User field 2","x",FIELD(user2),},
35 {"user3",0,0,"User field 3","x",FIELD(user3),},
36
37 {"is_valid",0,0,"Validity","d -1 1 -1",FIELD(is_valid),
38 "0 = invalid genotype\n"
39 "1 = valid genotype\n"
40  "-1 = validity is not known."},
41
42 {"uid",0,0,"#","s",FIELD(uid),"Unique identifier"},
43
44 {0,0,0,},
45};
46#undef FIELDSTRUCT
47
48MiniGenotypeLoader::MiniGenotypeLoader():genotype_param(minigenotype_paramtab,&genotype_object) {init();}
49MiniGenotypeLoader::MiniGenotypeLoader(VirtFILE *f):MultiParamLoader(f),genotype_param(minigenotype_paramtab,&genotype_object) {init();}
50MiniGenotypeLoader::MiniGenotypeLoader(const char* filename):MultiParamLoader(filename),genotype_param(minigenotype_paramtab,&genotype_object) {init();}
51
52void MiniGenotypeLoader::init()
53{
54addObject(&genotype_param);
55breakOn(MultiParamLoader::OnError + MultiParamLoader::AfterObject);
56}
57
58MiniGenotype* MiniGenotypeLoader::loadNextGenotype()
59{
60genotype_object.clear();
61if ((go()==AfterObject)&&(getObject().matchesInterfaceName(&genotype_param)))
62        return &genotype_object;
63else
64        return 0;
65}
Note: See TracBrowser for help on using the repository browser.