Changeset 95
- Timestamp:
- 07/03/13 00:21:08 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/gdk/conv_f1.cpp
r80 r95 1 1 // This file is a part of the Framsticks GDK library. 2 // Copyright (C) 2002-201 1Szymon Ulatowski. See LICENSE.txt for details.2 // Copyright (C) 2002-2013 Szymon Ulatowski. See LICENSE.txt for details. 3 3 // Refer to http://www.framsticks.com/ for further information. 4 4 … … 25 25 SList neuro_f1_to_f0; // neuro_f1_to_f0(f1_refno) = actual neuro pointer 26 26 Neuro *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) {} }; 27 SyntParam *neuro_cls_param; 28 29 struct Connection { int n1,n2; double w; 30 Connection(int _n1,int _n2, double _w):n1(_n1),n2(_n2),w(_w) {} }; 31 29 32 SListTempl<Connection> connections; 30 33 int usemapping; … … 39 42 void growConnection(const char* begin,const char* colon,const char* end,F1Props& props); 40 43 int countBranches(const char*g,SList &out); 41 void addClassParam(const SString& newparam);44 SyntParam* lastNeuroClassParam(); 42 45 void addClassParam(const char* name,double value); 46 void addClassParam(const char* name,const char* value); 43 47 44 48 const MultiRange* makeRange(const char*g) {return makeRange(g,g);} … … 226 230 } 227 231 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 } 232 SyntParam* Builder::lastNeuroClassParam() 233 { 234 if (!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 } 249 return neuro_cls_param; 250 } 251 235 252 void Builder::addClassParam(const char* name,double value) 236 253 { 237 SString t; 238 sprintf(t.directWrite(30),"%s=%g",name,value); 239 t.endWrite(); 240 addClassParam(t); 241 } 242 254 lastNeuroClassParam(); 255 if (neuro_cls_param) 256 neuro_cls_param->setDoubleById(name,value); 257 } 258 259 void Builder::addClassParam(const char* name,const char* value) 260 { 261 lastNeuroClassParam(); 262 if (neuro_cls_param) 263 neuro_cls_param->setById(name,ExtValue(value)); 264 } 243 265 244 266 int Builder::countBranches(const char*g,SList &out) … … 286 308 const char*neuroend=skipNeuro(t); 287 309 last_f1_neuro=model.addNewNeuro(); 310 neuro_cls_param=NULL; 288 311 last_f1_neuro->attachToPart(getLastPart()); 289 312 const MultiRange *mr=makeRange(t-1,neuroend+1); … … 354 377 else if (cls->getPreferredLocation()==1) 355 378 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 } 356 391 } 357 392 } … … 364 399 t++; 365 400 } 401 SAFEDELETE(neuro_cls_param); 366 402 return t; 367 403 } … … 419 455 if (usemapping) out->setMapping(*makeRange(begin,end-1)); 420 456 } 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))));457 else if (*begin=='!') addClassParam("fo",atof(colon+1)); 458 else if (*begin=='=') addClassParam("in",atof(colon+1)); 423 459 else 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 */428 460 else if (islower(begin[0])) 429 461 { 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.