Ignore:
Timestamp:
05/06/25 22:56:57 (3 days ago)
Author:
Maciej Komosinski
Message:

Introduced GeneProps::get_standard_values(): a getter function to ensure controlled initialization of the static "standard_values" object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/geneprops.cpp

    r1260 r1335  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2025  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    66#include <algorithm>
    77
    8 GeneProps GeneProps::standard_values;
     8
     9const GeneProps& GeneProps::get_standard_values() //this getter function ensures controlled initialization of the static standard_values object
     10{
     11        static GeneProps standard_values;
     12        return standard_values;
     13}
    914
    1015GeneProps::GeneProps()
     
    9499void GeneProps::propagateAlong(bool use_f1_muscle_reset_range, GenePropsOps* ops)
    95100{
     101        const GeneProps& standard_values = get_standard_values();
    96102        length = 0.5 * length + 0.5 * standard_values.length;
    97103        weight += (standard_values.weight - weight) * 0.5;
     
    202208GenePropsOps_Legacy::GenePropsOps_Legacy()
    203209{
     210        const GeneProps& standard_values = GeneProps::get_standard_values();
     211
    204212        use_normalizebiol4 = true;
    205213
    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);
     214        length = new GenePropsOp_Legacy(0.33, 2.0, standard_values.length, 0.3);
     215        weight = new GenePropsOp_Legacy(0.5, 2.0, standard_values.weight, 0.3);
     216        friction = new GenePropsOp_Legacy(0, 4.0, standard_values.friction, 0.2);
     217        curvedness = new GenePropsOp_Legacy(-2, 2, standard_values.curvedness, 0.25);
     218        twist = new GenePropsOp_Legacy(-M_PI_2, M_PI_2, standard_values.twist, 0.3);
     219        energy = new GenePropsOp_Legacy(0, 10, standard_values.energy, 0.1);
     220
     221        assimilation = new GenePropsOp_Legacy(0, 1, standard_values.assimilation, 0.8, 0.4);
     222        ingestion = new GenePropsOp_Legacy(0, 1, standard_values.ingestion, 0.8, 0.4);
     223        stamina = new GenePropsOp_Legacy(0, 1, standard_values.stamina, 0.8, 0.4);
     224        muscle_power = new GenePropsOp_Legacy(0, 1, standard_values.muscle_power, 0.8, 0.4);
     225
     226        cred = new GenePropsOp_Legacy(0, 1, standard_values.cred, 0.25);
     227        cgreen = new GenePropsOp_Legacy(0, 1, standard_values.cgreen, 0.25);
     228        cblue = new GenePropsOp_Legacy(0, 1, standard_values.cblue, 0.25);
    221229}
    222230
    223231GenePropsOps_AllChange05::GenePropsOps_AllChange05()
    224232{
     233        const GeneProps& standard_values = GeneProps::get_standard_values();
     234
    225235        use_normalizebiol4 = false;
    226236
     
    235245
    236246        delete curvedness;
    237         curvedness = new GenePropsOp_Legacy(-M_PI_2, M_PI_2, GeneProps::standard_values.curvedness, CHANGE);
     247        curvedness = new GenePropsOp_Legacy(-M_PI_2, M_PI_2, standard_values.curvedness, CHANGE);
    238248}
    239249
    240250GenePropsOps_Exponential::GenePropsOps_Exponential()
    241251{
    242         length = new GenePropsOp_Exponential(0.33, 2.0, GeneProps::standard_values.length);
    243         weight = new GenePropsOp_Exponential(0.5, 2.0, GeneProps::standard_values.weight);
    244         friction = new GenePropsOp_Exponential(0, 4.0, GeneProps::standard_values.friction);
    245         curvedness = new GenePropsOp_Exponential(-2, 2, GeneProps::standard_values.curvedness);
    246         twist = new GenePropsOp_Exponential(-M_PI_2, M_PI_2, GeneProps::standard_values.twist);
    247         energy = new GenePropsOp_Exponential(0, 10, GeneProps::standard_values.energy);
    248 
    249         assimilation = new GenePropsOp_Exponential(0, 1, GeneProps::standard_values.assimilation);
    250         ingestion = new GenePropsOp_Exponential(0, 1, GeneProps::standard_values.ingestion);
    251         stamina = new GenePropsOp_Exponential(0, 1, GeneProps::standard_values.stamina);
    252         muscle_power = new GenePropsOp_Exponential(0, 1, GeneProps::standard_values.muscle_power);
    253 
    254         cred = new GenePropsOp_Exponential(0, 1, GeneProps::standard_values.cred);
    255         cgreen = new GenePropsOp_Exponential(0, 1, GeneProps::standard_values.cgreen);
    256         cblue = new GenePropsOp_Exponential(0, 1, GeneProps::standard_values.cblue);
     252        const GeneProps& standard_values = GeneProps::get_standard_values();
     253        length = new GenePropsOp_Exponential(0.33, 2.0, standard_values.length);
     254        weight = new GenePropsOp_Exponential(0.5, 2.0, standard_values.weight);
     255        friction = new GenePropsOp_Exponential(0, 4.0, standard_values.friction);
     256        curvedness = new GenePropsOp_Exponential(-2, 2, standard_values.curvedness);
     257        twist = new GenePropsOp_Exponential(-M_PI_2, M_PI_2, standard_values.twist);
     258        energy = new GenePropsOp_Exponential(0, 10, standard_values.energy);
     259
     260        assimilation = new GenePropsOp_Exponential(0, 1, standard_values.assimilation);
     261        ingestion = new GenePropsOp_Exponential(0, 1, standard_values.ingestion);
     262        stamina = new GenePropsOp_Exponential(0, 1, standard_values.stamina);
     263        muscle_power = new GenePropsOp_Exponential(0, 1, standard_values.muscle_power);
     264
     265        cred = new GenePropsOp_Exponential(0, 1, standard_values.cred);
     266        cgreen = new GenePropsOp_Exponential(0, 1, standard_values.cgreen);
     267        cblue = new GenePropsOp_Exponential(0, 1, standard_values.cblue);
    257268}
    258269
Note: See TracChangeset for help on using the changeset viewer.