[286] | 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. |
---|
[109] | 4 | |
---|
| 5 | #ifndef _GENOTYPELOADER_H_ |
---|
| 6 | #define _GENOTYPELOADER_H_ |
---|
| 7 | |
---|
| 8 | #include <frams/util/sstring.h> |
---|
| 9 | #include <frams/param/multiparamload.h> |
---|
| 10 | |
---|
[473] | 11 | /** Defines the association between "org:" object (found in genotype files) |
---|
| 12 | and the MiniGenotype fields. MiniGenotypeLoader uses this definition |
---|
| 13 | but you can also use it to make MultiParamLoader load genotype |
---|
| 14 | */ |
---|
| 15 | extern ParamEntry minigenotype_paramtab[]; |
---|
| 16 | |
---|
[109] | 17 | /** Helper class, mostly useful with MultiParamLoader |
---|
| 18 | or its specialized version: MiniGenotypeLoader. |
---|
[473] | 19 | MiniGenotype stores the subset of Genotype fields (the ones normally saved in .gen files) |
---|
[109] | 20 | */ |
---|
| 21 | class MiniGenotype |
---|
| 22 | { |
---|
| 23 | public: |
---|
[473] | 24 | SString name,genotype,info,uid; |
---|
| 25 | double energy0,lifespan,velocity,distance,vertvel,vertpos; |
---|
| 26 | paInt numparts,numjoints,numneurons,numconnections,ordnumber,generation,instances,is_valid; |
---|
| 27 | ExtValue user1,user2,user3; |
---|
| 28 | void clear() {Param p(minigenotype_paramtab,this); p.setDefault();} |
---|
[109] | 29 | }; |
---|
| 30 | |
---|
| 31 | /** In most simple cases this is the class you would use to load a series of genotypes from |
---|
| 32 | the Framsticks genotype file. |
---|
| 33 | |
---|
| 34 | Usage pattern: (see loadertest.cpp for the working code) |
---|
| 35 | |
---|
| 36 | 1.Initialize |
---|
| 37 | |
---|
| 38 | 2.while(genotype=loadNextGenotype()) doSomethingWith(genotype); |
---|
| 39 | |
---|
| 40 | 3.Done! |
---|
| 41 | |
---|
| 42 | MiniGenotypeLoader is simply the MultiParamLoader configured to load one kind of data: "org:" objects. |
---|
| 43 | The instance of this class can also be reconfigured to recognize more objects by using MultiParamLoader |
---|
| 44 | methods, or you can use it as a guide for creating your own specialized class. |
---|
| 45 | */ |
---|
| 46 | class MiniGenotypeLoader: public MultiParamLoader |
---|
| 47 | { |
---|
| 48 | MiniGenotype genotype_object; |
---|
| 49 | Param genotype_param; |
---|
| 50 | bool initialized; |
---|
| 51 | void init(); |
---|
| 52 | public: |
---|
| 53 | MiniGenotypeLoader(); |
---|
| 54 | MiniGenotypeLoader(VirtFILE *f); |
---|
| 55 | MiniGenotypeLoader(const char* filename); |
---|
| 56 | |
---|
| 57 | /** @returns genotype object if one was loaded or NULL otherwise. |
---|
| 58 | |
---|
| 59 | Returned MiniGenotype pointer always references the the same object (MiniGenotypeLoader::genotype_object) |
---|
| 60 | which means you may need to copy the data from it before calling loadNextGenotype() again. |
---|
| 61 | In the default configuration (simple MiniGenotypeLoader) NULL is always final and should be used |
---|
| 62 | to finish processing. |
---|
| 63 | |
---|
| 64 | If the loader is configured to load other objects or stop on other conditions, NULL will also mean |
---|
| 65 | every condition other than "GenotypeLoaded". In such cases you need MultiParamLoader::getStatus(), |
---|
| 66 | MultiParamLoader::finished() and other methods to determine the real cause of NULL. |
---|
| 67 | */ |
---|
| 68 | MiniGenotype* loadNextGenotype(); |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | #endif |
---|