Changeset 95


Ignore:
Timestamp:
07/03/13 00:21:08 (11 years ago)
Author:
sz
Message:

muscles encoded in a "new" way in f1 genotypes now behave as in "old" f1 (default values of their "power" and "range" properties depend on f1 modifiers)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/gdk/conv_f1.cpp

    r80 r95  
    11// This file is a part of the Framsticks GDK library.
    2 // Copyright (C) 2002-2011  Szymon Ulatowski.  See LICENSE.txt for details.
     2// Copyright (C) 2002-2013  Szymon Ulatowski.  See LICENSE.txt for details.
    33// Refer to http://www.framsticks.com/ for further information.
    44
     
    2525SList neuro_f1_to_f0; // neuro_f1_to_f0(f1_refno) = actual neuro pointer
    2626Neuro *last_f1_neuro;
    27         struct Connection { int n1,n2; double w;
    28                 Connection(int _n1,int _n2, double _w):n1(_n1),n2(_n2),w(_w) {} };
     27SyntParam *neuro_cls_param;
     28
     29struct Connection { int n1,n2; double w;
     30Connection(int _n1,int _n2, double _w):n1(_n1),n2(_n2),w(_w) {} };
     31
    2932SListTempl<Connection> connections;
    3033int usemapping;
     
    3942void growConnection(const char* begin,const char* colon,const char* end,F1Props& props);
    4043int countBranches(const char*g,SList &out);
    41 void addClassParam(const SString& newparam);
     44SyntParam* lastNeuroClassParam();
    4245void addClassParam(const char* name,double value);
     46void addClassParam(const char* name,const char* value);
    4347
    4448const MultiRange* makeRange(const char*g) {return makeRange(g,g);}
     
    226230}
    227231
    228 void Builder::addClassParam(const SString& newparam)
    229 {
    230 SString allparams=last_f1_neuro->getClassParams();
    231 if (allparams.len()) allparams+=',';
    232 allparams+=newparam;
    233 last_f1_neuro->setClassParams(allparams);
    234 }
     232SyntParam* Builder::lastNeuroClassParam()
     233{
     234if (!neuro_cls_param)
     235        {
     236        NeuroClass *cls=last_f1_neuro->getClass();
     237        if (cls)
     238                {
     239                neuro_cls_param=new SyntParam(last_f1_neuro->classProperties());
     240// this is equivalent to:
     241//              SyntParam tmp=last_f1_neuro->classProperties();
     242//              neuro_cls_param=new SyntParam(tmp);
     243// interestingly, some compilers eliminate the call to new SyntParam,
     244// realizing that a copy constructor is redundant when the original object is
     245// temporary. there are no side effect of such optimization, as long as the
     246// copy-constructed object is exact equivalent of the original.
     247                }
     248        }
     249return neuro_cls_param;
     250}
     251
    235252void Builder::addClassParam(const char* name,double value)
    236253{
    237 SString t;
    238 sprintf(t.directWrite(30),"%s=%g",name,value);
    239 t.endWrite();
    240 addClassParam(t);
    241 }
    242 
     254lastNeuroClassParam();
     255if (neuro_cls_param)
     256        neuro_cls_param->setDoubleById(name,value);
     257}
     258
     259void Builder::addClassParam(const char* name,const char* value)
     260{
     261lastNeuroClassParam();
     262if (neuro_cls_param)
     263        neuro_cls_param->setById(name,ExtValue(value));
     264}
    243265
    244266int Builder::countBranches(const char*g,SList &out)
     
    286308const char*neuroend=skipNeuro(t);
    287309last_f1_neuro=model.addNewNeuro();
     310neuro_cls_param=NULL;
    288311last_f1_neuro->attachToPart(getLastPart());
    289312const MultiRange *mr=makeRange(t-1,neuroend+1);
     
    354377                                        else if (cls->getPreferredLocation()==1)
    355378                                                last_f1_neuro->attachToPart(getLastPart());
     379
     380                                        lastNeuroClassParam();
     381                                        //special handling: muscle properties (can be overwritten by subsequent property assignments)
     382                                        if (!strcmp(cls->getName(),"|"))
     383                                                {
     384                                                neuro_cls_param->setDoubleById("p",lastjoint_muscle_power);
     385                                                neuro_cls_param->setDoubleById("r",props.bendrange);
     386                                                }
     387                                        else if (!strcmp(cls->getName(),"@"))
     388                                                {
     389                                                neuro_cls_param->setDoubleById("p",lastjoint_muscle_power);
     390                                                }
    356391                                        }
    357392                                }
     
    364399        t++;
    365400        }
     401SAFEDELETE(neuro_cls_param);
    366402return t;
    367403}
     
    419455        if (usemapping) out->setMapping(*makeRange(begin,end-1));
    420456        }
    421 else if (*begin=='!') addClassParam("fo",max(0.0,min(1.0,atof(colon+1))));
    422 else if (*begin=='=') addClassParam("in",max(0.0,min(1.0,atof(colon+1))));
     457else if (*begin=='!') addClassParam("fo",atof(colon+1));
     458else if (*begin=='=') addClassParam("in",atof(colon+1));
    423459else if (*begin=='/') addClassParam("si",atof(colon+1));
    424 /*else if (*begin=='!') last_f1_neuro->force=max(0.0,min(1.0,atof(colon+1)));
    425 else if (*begin=='=') last_f1_neuro->inertia=max(0.0,min(1.0,atof(colon+1)));
    426 else if (*begin=='/') last_f1_neuro->sigmo=atof(colon+1);
    427 */
    428460else if (islower(begin[0]))
    429461        {
    430         SString newparam(begin,end-begin);
    431         trim(newparam);
    432         newparam.directWrite()[colon-begin]='='; // ':' -> '='
    433         addClassParam(newparam);
    434         }
    435 }
     462        SString name(begin,colon-begin);
     463        SString value(colon+1,end-(colon+1));
     464        addClassParam(name,value);
     465        }
     466}
Note: See TracChangeset for help on using the changeset viewer.