Changeset 1260


Ignore:
Timestamp:
06/22/23 04:00:45 (10 months ago)
Author:
Maciej Komosinski
Message:

Cosmetic

Location:
cpp/frams
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/Makefile-SDK-files

    r1242 r1260  
    4141NN_LAYOUT_OBJS=frams/canvas/nn_layout_model.o frams/canvas/nn_simple_layout.o frams/canvas/nn_smart_layout.o
    4242
    43 SDK_OBJS=frams/util/list.o frams/util/advlist.o frams/param/param.o frams/util/sstring.o frams/util/sstringutils.o frams/util/3d.o frams/vm/classes/3dobject.o frams/model/model.o frams/model/modelparts.o frams/neuro/neurolibrary.o frams/genetics/geno.o frams/genetics/genoconv.o frams/util/extvalue.o frams/vm/classes/collectionobj.o frams/util/hashtable.o common/log.o common/util-string.o common/util-file.o common/nonstd_stdio.o frams/util/callbacks.o frams/param/syntparam.o frams/util/multirange.o frams/util/multimap.o frams/param/paramtabobj.o common/loggers/loggers.o frams/param/paramobj.o frams/genetics/genooperators.o common/nonstd_math.o frams/util/validitychecks.o common/Convert.o frams/util/rndutil.o common/virtfile/stringfile.o common/virtfile/stdinoutfilesystem.o $(PRINTFLOAT_OBJS)
     43SDK_OBJS=frams/util/list.o frams/util/advlist.o frams/param/param.o frams/param/paramlist.o frams/util/sstring.o frams/util/sstringutils.o frams/util/3d.o frams/vm/classes/3dobject.o frams/model/model.o frams/model/modelparts.o frams/neuro/neurolibrary.o frams/genetics/geno.o frams/genetics/genoconv.o frams/util/extvalue.o frams/vm/classes/collectionobj.o frams/util/hashtable.o common/log.o common/util-string.o common/util-file.o common/nonstd_stdio.o frams/util/callbacks.o frams/param/syntparam.o frams/util/multirange.o frams/util/multimap.o frams/param/paramtabobj.o common/loggers/loggers.o frams/param/paramobj.o frams/genetics/genooperators.o common/nonstd_math.o frams/util/validitychecks.o common/Convert.o frams/util/rndutil.o common/virtfile/stringfile.o common/virtfile/stdinoutfilesystem.o $(PRINTFLOAT_OBJS)
    4444
    4545STDOUT_LOGGER_OBJS=common/virtfile/virtfile.o common/loggers/loggertostdout.o common/console.o
  • cpp/frams/_demos/geneprops_test.cpp

    r1242 r1260  
    8080        int maxcount = 4;
    8181
    82         enum Function { Legacy, RecreatedLegacy, New05, NewExponential };
    83         Function fun = Legacy;
     82        enum Function { Legacy, AllChange05, ExperimentalExponential };
     83        Function fun = AllChange05;
    8484
    8585        int argpos = 0;
     
    9191                        {
    9292                        case 'l': fun = Legacy; break;
    93                         case 'r': fun = RecreatedLegacy; break;
    94                         case 'n': fun = New05; break;
    95                         case 'e': fun = NewExponential; break;
     93                        case 'n': fun = AllChange05; break;
     94                        case 'e': fun = ExperimentalExponential; break;
    9695                        case 'h': printf("%s args: [modifier [max_count]] (one of " F14_MODIFIERS ")\n"
    9796                                "\t-l = legacy function\n"
    98                                 "\t-r = recreated legacy function\n"
    99                                 "\t-n = new, change=0.5, normalizeBiol4 disabled\n"
    100                                 "\t-e = new exponential function\n", argv[0]);
     97                                "\t-n = modern, change=0.5, normalizeBiol4 disabled\n"
     98                                "\t-e = experimental exponential function\n", argv[0]);
    10199                                return 0;
    102100                        default: fprintf(stderr, "%s: invalid option: %s\n", argv[0], arg); return 2;
     
    115113
    116114        GenePropsOps_Exponential exponential_ops;
    117         GenePropsOps_Old recreated_ops;
    118         GenePropsOps_New05 new05_ops;
     115        GenePropsOps_Legacy legacy_ops;
     116        GenePropsOps_AllChange05 allchange05_ops;
    119117        GenePropsOps *ops;
    120118
    121119        switch (fun)
    122120        {
    123         case RecreatedLegacy: ops = &recreated_ops; break;
    124         case NewExponential:  ops = &exponential_ops; break;
    125         case New05:  ops = &new05_ops; break;
     121        case Legacy: ops = &legacy_ops; break;
     122        case ExperimentalExponential:  ops = &exponential_ops; break;
     123        case AllChange05:  ops = &allchange05_ops; break;
    126124        default: ops = NULL;
    127125        }
     
    138136                                char m = ((1 << c) & i) ? modifier_u : modifier_l;
    139137                                tmp[c] = m;
    140                                 if (fun == Legacy)
    141                                         props.executeModifier_Legacy(m);
    142                                 else
    143                                         props.executeModifier(m, ops);
     138                                props.executeModifier(m, ops);
    144139                        }
    145140                        if (count > 0)
  • cpp/frams/genetics/geneprops.cpp

    r1248 r1260  
    5151}
    5252
    53 int GeneProps::executeModifier_Legacy(char modif)
    54 {
    55         switch (modif)
    56         {
    57 #ifdef v1f1COMPATIBLE
    58         case 'L': length += (3.0 - length) * 0.3;
    59                 length = std::min(length, Model::getMaxJoint().d.x); break;
    60 #else
    61         case 'L': length += (2.0 - length) * 0.3; //2.0 is currently Model::getMaxJoint().d.x so min() does not limit the range
    62                 length = std::min(length, Model::getMaxJoint().d.x); break;
    63 #endif
    64         case 'l': length += (0.33 - length) * 0.3;
    65                 length = std::max(length, Model::getMinJoint().d.x); break;
    66 
    67         case 'W': weight += (2.0 - weight) * 0.3; break;
    68         case 'w': weight += (0.5 - weight) * 0.3; break;
    69         case 'F': friction += (4 - friction) * 0.2; break;
    70         case 'f': friction -= friction * 0.2; break;
    71         case 'C': curvedness += (2.0 - curvedness) * 0.25; break;
    72         case 'c': curvedness += (-2.0 - curvedness) * 0.25; break;
    73         case 'Q': twist += (M_PI_2 - twist) * 0.3; break;
    74         case 'q': twist += (-M_PI_2 - twist) * 0.3; break;
    75         case 'E': energy += (10.0 - energy) * 0.1; break;
    76         case 'e': energy -= energy * 0.1;  break;
    77 
    78         case 'A': assimilation += (1 - assimilation) * 0.8; normalizeBiol4(); break;
    79         case 'a': assimilation -= assimilation * 0.4; normalizeBiol4(); break;
    80         case 'I': ingestion += (1 - ingestion) * 0.8; normalizeBiol4(); break;
    81         case 'i': ingestion -= ingestion * 0.4; normalizeBiol4(); break;
    82         case 'S': stamina += (1 - stamina) * 0.8; normalizeBiol4(); break;
    83         case 's': stamina -= stamina * 0.4; normalizeBiol4(); break;
    84         case 'M': muscle_power += (1 - muscle_power) * 0.8; normalizeBiol4(); break;
    85         case 'm': muscle_power -= muscle_power * 0.4; normalizeBiol4(); break;
    86 
    87         case 'D': cred += (1.0 - cred) * 0.25; break;
    88         case 'd': cred += (0.0 - cred) * 0.25; break;
    89         case 'G': cgreen += (1.0 - cgreen) * 0.25; break;
    90         case 'g': cgreen += (0.0 - cgreen) * 0.25; break;
    91         case 'B': cblue += (1.0 - cblue) * 0.25; break;
    92         case 'b': cblue += (0.0 - cblue) * 0.25; break;
    93 
    94         default: return -1;
    95         }
    96         return 0;
    97 }
    98 
    9953int GeneProps::executeModifier(char modif, GenePropsOps* ops)
    10054{
    10155        if (ops == NULL)
    102                 ops = getStandardOps();
     56                ops = getDefaultOps();
    10357
    10458#define APPLY(name) ops->name->apply(name, modif)
     
    152106
    153107        if (ops == NULL)
    154                 ops = getStandardOps();
     108                ops = getDefaultOps();
    155109        if (ops->use_normalizebiol4) normalizeBiol4();
    156110
     
    171125}
    172126
    173 double GenePropsOp_Old::increase(double value) const
     127double GenePropsOp_Legacy::increase(double value) const
    174128{
    175129        return value + (maxvalue - value) * change;
    176130}
    177131
    178 double GenePropsOp_Old::decrease(double value) const
     132double GenePropsOp_Legacy::decrease(double value) const
    179133{
    180134        return value + (minvalue - value) * revchange;
    181135}
    182136
    183 GenePropsOp_Old::GenePropsOp_Old(double minvalue, double maxvalue, double defvalue, double change, double revchange)
     137GenePropsOp_Legacy::GenePropsOp_Legacy(double minvalue, double maxvalue, double defvalue, double change, double revchange)
    184138{
    185139        this->minvalue = minvalue;
     
    246200}
    247201
    248 GenePropsOps_Old::GenePropsOps_Old()
     202GenePropsOps_Legacy::GenePropsOps_Legacy()
    249203{
    250204        use_normalizebiol4 = true;
    251205
    252         length = new GenePropsOp_Old(0.33, 2.0, GeneProps::standard_values.length, 0.3);
    253         weight = new GenePropsOp_Old(0.5, 2.0, GeneProps::standard_values.weight, 0.3);
    254         friction = new GenePropsOp_Old(0, 4.0, GeneProps::standard_values.friction, 0.2);
    255         curvedness = new GenePropsOp_Old(-2, 2, GeneProps::standard_values.curvedness, 0.25);
    256         twist = new GenePropsOp_Old(-M_PI_2, M_PI_2, GeneProps::standard_values.twist, 0.3);
    257         energy = new GenePropsOp_Old(0, 10, GeneProps::standard_values.energy, 0.1);
    258 
    259         assimilation = new GenePropsOp_Old(0, 1, GeneProps::standard_values.assimilation, 0.8, 0.4);
    260         ingestion = new GenePropsOp_Old(0, 1, GeneProps::standard_values.ingestion, 0.8, 0.4);
    261         stamina = new GenePropsOp_Old(0, 1, GeneProps::standard_values.stamina, 0.8, 0.4);
    262         muscle_power = new GenePropsOp_Old(0, 1, GeneProps::standard_values.muscle_power, 0.8, 0.4);
    263 
    264         cred = new GenePropsOp_Old(0, 1, GeneProps::standard_values.cred, 0.25);
    265         cgreen = new GenePropsOp_Old(0, 1, GeneProps::standard_values.cgreen, 0.25);
    266         cblue = new GenePropsOp_Old(0, 1, GeneProps::standard_values.cblue, 0.25);
    267 }
    268 
    269 GenePropsOps_New05::GenePropsOps_New05()
     206        length = new GenePropsOp_Legacy(0.33, 2.0, GeneProps::standard_values.length, 0.3);
     207        weight = new GenePropsOp_Legacy(0.5, 2.0, GeneProps::standard_values.weight, 0.3);
     208        friction = new GenePropsOp_Legacy(0, 4.0, GeneProps::standard_values.friction, 0.2);
     209        curvedness = new GenePropsOp_Legacy(-2, 2, GeneProps::standard_values.curvedness, 0.25);
     210        twist = new GenePropsOp_Legacy(-M_PI_2, M_PI_2, GeneProps::standard_values.twist, 0.3);
     211        energy = new GenePropsOp_Legacy(0, 10, GeneProps::standard_values.energy, 0.1);
     212
     213        assimilation = new GenePropsOp_Legacy(0, 1, GeneProps::standard_values.assimilation, 0.8, 0.4);
     214        ingestion = new GenePropsOp_Legacy(0, 1, GeneProps::standard_values.ingestion, 0.8, 0.4);
     215        stamina = new GenePropsOp_Legacy(0, 1, GeneProps::standard_values.stamina, 0.8, 0.4);
     216        muscle_power = new GenePropsOp_Legacy(0, 1, GeneProps::standard_values.muscle_power, 0.8, 0.4);
     217
     218        cred = new GenePropsOp_Legacy(0, 1, GeneProps::standard_values.cred, 0.25);
     219        cgreen = new GenePropsOp_Legacy(0, 1, GeneProps::standard_values.cgreen, 0.25);
     220        cblue = new GenePropsOp_Legacy(0, 1, GeneProps::standard_values.cblue, 0.25);
     221}
     222
     223GenePropsOps_AllChange05::GenePropsOps_AllChange05()
    270224{
    271225        use_normalizebiol4 = false;
     226
     227        constexpr float CHANGE = 0.5;
    272228        auto fields = { length,curvedness,weight,friction,muscle_power,assimilation,stamina,ingestion,twist,energy,cred,cgreen,cblue };
    273229        for (auto f : fields)
    274230        {
    275                 auto f_gpo = dynamic_cast<GenePropsOp_Old*>(f);
     231                auto f_gpo = dynamic_cast<GenePropsOp_Legacy*>(f);
    276232                if (f_gpo)
    277                         f_gpo->change = f_gpo->revchange = 0.5;
    278         }
     233                        f_gpo->change = f_gpo->revchange = CHANGE;
     234        }
     235
     236        delete curvedness;
     237        curvedness = new GenePropsOp_Legacy(-M_PI_2, M_PI_2, GeneProps::standard_values.curvedness, CHANGE);
    279238}
    280239
     
    298257}
    299258
    300 
    301 GenePropsOps* GeneProps::standard_ops = NULL;
    302 GenePropsOps* GeneProps::getStandardOps()
    303 {
    304         if (!standard_ops)
    305                 standard_ops = new GenePropsOps_New05();
    306         return standard_ops;
    307 }
     259GenePropsOps* GeneProps::getAllChange05Ops()
     260{
     261        static GenePropsOps_AllChange05 ops;
     262        return &ops;
     263}
     264
     265GenePropsOps* GeneProps::getLegacyOps()
     266{
     267        static GenePropsOps_Legacy ops;
     268        return &ops;
     269}
     270
     271static GenePropsOps* default_ops = NULL;
     272
     273GenePropsOps* GeneProps::getDefaultOps()
     274{
     275        if (!default_ops)
     276                default_ops = getAllChange05Ops();
     277        return default_ops;
     278}
     279
     280void GeneProps::setDefaultOps(GenePropsOps* ops)
     281{
     282        default_ops = ops;
     283}
  • cpp/frams/genetics/geneprops.h

    r1249 r1260  
    2828};
    2929
    30 class GenePropsOp_Old : public GenePropsOp
     30class GenePropsOp_Legacy : public GenePropsOp
    3131{
    3232        double minvalue, maxvalue, defvalue, change, revchange;
    3333public:
    34         GenePropsOp_Old(double minvalue, double maxvalue, double defvalue, double change, double revchange = -1);
     34        GenePropsOp_Legacy(double minvalue, double maxvalue, double defvalue, double change, double revchange = -1);
    3535        double increase(double value) const;
    3636        double decrease(double value) const;
    37         friend class GenePropsOps_New05;
     37        friend class GenePropsOps_AllChange05;
    3838};
    3939
    4040class GenePropsOp_NormalizedAndScaled : public GenePropsOp
    4141{
    42         GenePropsOp_Old normalized;
     42        GenePropsOp_Legacy normalized;
    4343public:
    4444        GenePropsOp_NormalizedAndScaled(double change) :normalized(-1, 1, 0, change) {}
     
    7979};
    8080
    81 class GenePropsOps_Old : public GenePropsOps
     81class GenePropsOps_Legacy : public GenePropsOps
    8282{
    8383public:
    84         GenePropsOps_Old();
     84        GenePropsOps_Legacy();
    8585};
    8686
    87 class GenePropsOps_New05 : public GenePropsOps_Old
     87/**
     88* Just as legacy (before 2023-06), but the influence of each modifier is uniform and simpler (no normalizeBiol4()).
     89* This is what is currently used in Framsticks.
     90*/
     91class GenePropsOps_AllChange05 : public GenePropsOps_Legacy
    8892{
    8993public:
    90         GenePropsOps_New05();
     94        GenePropsOps_AllChange05();
    9195};
    9296
     97/**
     98* Just an experiment with a different scaling of the influence of individual modifier characters to cover
     99* the entire range of parameter values. After investigations we decided that it does not
     100* provide any advantages over "AllChange05".
     101*/
    93102class GenePropsOps_Exponential : public GenePropsOps
    94103{
     
    132141
    133142        static GeneProps standard_values;
    134         static GenePropsOps* standard_ops;
    135         static GenePropsOps* getStandardOps();
     143       
     144        static GenePropsOps* getDefaultOps();
     145        static void setDefaultOps(GenePropsOps* ops);
    136146
     147        static GenePropsOps* getAllChange05Ops();
     148        static GenePropsOps* getLegacyOps();
     149       
    137150        /**
    138151         * Constructor initializing all properties with default values.
     
    154167         */
    155168        int executeModifier(char modif, GenePropsOps* ops = NULL);
    156         int executeModifier_Legacy(char modif);
    157169
    158170        /**
Note: See TracChangeset for help on using the changeset viewer.