1 | // This file is a part of Framsticks GDK library. |
---|
2 | // Copyright (C) 2002-2006 Szymon Ulatowski. See LICENSE.txt for details. |
---|
3 | // Refer to http://www.frams.alife.pl/ for further information. |
---|
4 | |
---|
5 | #include <stdlib.h> |
---|
6 | #include <math.h> |
---|
7 | #include <stdio.h> |
---|
8 | #include <string.h> |
---|
9 | #include <ctype.h> |
---|
10 | #include <time.h> |
---|
11 | #include <errno.h> |
---|
12 | |
---|
13 | /////////////////////////////// MODELPARTS.CPP /////////////// |
---|
14 | |
---|
15 | #include "modelparts.h" |
---|
16 | #include "model.h" |
---|
17 | |
---|
18 | #include "nonstd.h" |
---|
19 | #include "param.h" |
---|
20 | #include "neurolibrary.h" |
---|
21 | #include "multirange.h" |
---|
22 | #include "extvalue.h" |
---|
23 | |
---|
24 | template<> |
---|
25 | char ModelUserTags::reg[5]={0}; |
---|
26 | |
---|
27 | ///////////////////////// |
---|
28 | |
---|
29 | PartBase::~PartBase() |
---|
30 | {if (mapped) delete mapped;} |
---|
31 | |
---|
32 | void PartBase::notifyMappingChange() |
---|
33 | { |
---|
34 | if (owner) owner->partmappingchanged=1; |
---|
35 | } |
---|
36 | |
---|
37 | void PartBase::setMapping(const IRange &r) |
---|
38 | { |
---|
39 | if (mapped) (*mapped)=r; |
---|
40 | else mapped=new MultiRange(r); |
---|
41 | notifyMappingChange(); |
---|
42 | } |
---|
43 | |
---|
44 | void PartBase::clearMapping() |
---|
45 | { |
---|
46 | if (mapped) {delete mapped; mapped=0;} |
---|
47 | } |
---|
48 | |
---|
49 | void PartBase::addMapping(const IRange &r) |
---|
50 | { |
---|
51 | if (mapped) mapped->add(r); |
---|
52 | else mapped=new MultiRange(r); |
---|
53 | notifyMappingChange(); |
---|
54 | } |
---|
55 | |
---|
56 | void PartBase::setMapping(const MultiRange &mr) |
---|
57 | { |
---|
58 | if (mapped) (*mapped)=mr; |
---|
59 | else mapped=new MultiRange(mr); |
---|
60 | notifyMappingChange(); |
---|
61 | } |
---|
62 | |
---|
63 | void PartBase::addMapping(const MultiRange &mr) |
---|
64 | { |
---|
65 | if (mapped) mapped->add(mr); |
---|
66 | else mapped=new MultiRange(mr); |
---|
67 | notifyMappingChange(); |
---|
68 | } |
---|
69 | |
---|
70 | void PartBase::setInfo(const SString& name,const SString& value) |
---|
71 | { |
---|
72 | strSetField(info,name,value); |
---|
73 | } |
---|
74 | |
---|
75 | void PartBase::setInfo(const SString& name,int value) |
---|
76 | { |
---|
77 | setInfo(name,SString::valueOf(value)); |
---|
78 | } |
---|
79 | |
---|
80 | void PartBase::setInfo(const SString& name,double value) |
---|
81 | { |
---|
82 | setInfo(name,SString::valueOf(value)); |
---|
83 | } |
---|
84 | |
---|
85 | SString PartBase::getInfo(const SString& name) |
---|
86 | { |
---|
87 | return strGetField(info,name); |
---|
88 | } |
---|
89 | |
---|
90 | ///////////////////////// |
---|
91 | |
---|
92 | NeuroClass::NeuroClass(ParamEntry *_props,SString _description, |
---|
93 | int _prefinputs,int _prefoutput,int _preflocation, |
---|
94 | int *_vectordata,bool own_vd,int vhints) |
---|
95 | :longname(_props->id), |
---|
96 | name(_props->name), |
---|
97 | description(_description), |
---|
98 | props(_props), |
---|
99 | prefinputs(_prefinputs), |
---|
100 | prefoutput(_prefoutput), |
---|
101 | preflocation(_preflocation), |
---|
102 | vectordata(_vectordata),ownedvectordata(own_vd), |
---|
103 | visualhints(vhints),impl(0),active(1),genactive(0) |
---|
104 | {} |
---|
105 | |
---|
106 | NeuroClass::~NeuroClass() |
---|
107 | { |
---|
108 | setSymbolGlyph(0,0); |
---|
109 | } |
---|
110 | |
---|
111 | NeuroClass::NeuroClass() |
---|
112 | :name("Invalid"),props(empty_paramtab), |
---|
113 | prefinputs(0), prefoutput(0), |
---|
114 | preflocation(0), vectordata(0), ownedvectordata(0), |
---|
115 | impl(0), active(1), genactive(0) |
---|
116 | {} |
---|
117 | |
---|
118 | SString NeuroClass::getSummary() |
---|
119 | { |
---|
120 | SString t; |
---|
121 | t=getDescription(); |
---|
122 | if (t.len()) t+="\n\n"; |
---|
123 | t+="Characteristics:\n"; |
---|
124 | if(getPreferredInputs()) |
---|
125 | { |
---|
126 | if (getPreferredInputs()<0) t+=" supports any number of inputs\n"; |
---|
127 | else if (getPreferredInputs()==1) t+=" uses single input\n"; |
---|
128 | else {sprintf(t.directAppend(30)," uses %d inputs\n",getPreferredInputs()); t.endAppend();} |
---|
129 | } |
---|
130 | else t+=" does not use inputs\n"; |
---|
131 | if(getPreferredOutput()) |
---|
132 | t+=" provides output value\n"; |
---|
133 | else |
---|
134 | t+=" does not provide output value\n"; |
---|
135 | switch(getPreferredLocation()) |
---|
136 | { |
---|
137 | case 0: t+=" does not require location in body\n"; break; |
---|
138 | case 1: t+=" should be located on a Part\n"; break; |
---|
139 | case 2: t+=" should be located on a Joint\n"; break; |
---|
140 | } |
---|
141 | Param p=getProperties(); |
---|
142 | if (p.getPropCount()) |
---|
143 | { |
---|
144 | if (t.len()) t+="\n\n"; |
---|
145 | t+="Properties:\n"; |
---|
146 | const char *h; |
---|
147 | int i; |
---|
148 | for(i=0;i<p.getPropCount();i++) |
---|
149 | { |
---|
150 | if (i) t+="\n"; |
---|
151 | t+=" "; t+=p.name(i); t+=" ("; t+=p.id(i); t+=")"; |
---|
152 | switch(*p.type(i)) |
---|
153 | { |
---|
154 | case 'd': t+=" integer"; |
---|
155 | {long a,b,c; if (p.getMinMax(i,a,b,c)>=2) {sprintf(t.directAppend(30)," %d..%d",a,b); t.endAppend();}} |
---|
156 | break; |
---|
157 | case 'f': t+=" float"; |
---|
158 | {double a,b,c; if (p.getMinMax(i,a,b,c)>=2) {sprintf(t.directAppend(30)," %g..%g",a,b); t.endAppend();}} |
---|
159 | break; |
---|
160 | case 's': t+=" string"; break; |
---|
161 | case 'x': t+=" anything"; break; |
---|
162 | } |
---|
163 | if (h=p.help(i)) if (*h) {t+=" - "; t+=h;} |
---|
164 | } |
---|
165 | } |
---|
166 | return t; |
---|
167 | } |
---|
168 | |
---|
169 | ///////////////////////// |
---|
170 | |
---|
171 | ///////////////////////////////////// |
---|
172 | |
---|
173 | Neuro::Neuro(double _state,double _inertia,double _force,double _sigmo) |
---|
174 | :state(_state),PartBase(getDefaultStyle()) |
---|
175 | #ifdef MODEL_V1_COMPATIBLE |
---|
176 | ,inertia(_inertia),force(_force),sigmo(_sigmo) |
---|
177 | #endif |
---|
178 | { |
---|
179 | #ifdef MODEL_V1_COMPATIBLE |
---|
180 | olditems=0; |
---|
181 | #endif |
---|
182 | flags=0; |
---|
183 | myclass=0; |
---|
184 | knownclass=1; |
---|
185 | } |
---|
186 | |
---|
187 | Neuro::Neuro(void):PartBase(getDefaultStyle()) |
---|
188 | { |
---|
189 | #include "defassign-f0_neuro.h" |
---|
190 | state=0.0; |
---|
191 | myclass=0; |
---|
192 | knownclass=1; |
---|
193 | refno=0; |
---|
194 | pos=Pt3D_0; rot=Pt3D_0; |
---|
195 | parent=0; part=0; joint=0; |
---|
196 | parentcount=0; |
---|
197 | #ifdef MODEL_V1_COMPATIBLE |
---|
198 | olditems=0; |
---|
199 | #endif |
---|
200 | flags=0; |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | Neuro::~Neuro() |
---|
205 | { |
---|
206 | #ifdef MODEL_V1_COMPATIBLE |
---|
207 | if (olditems) delete olditems; |
---|
208 | #endif |
---|
209 | int i; |
---|
210 | for(i=0;i<inputs.size();i++) |
---|
211 | { |
---|
212 | NInput &ni=inputs(i); |
---|
213 | if (ni.info) delete ni.info; |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | SString** Neuro::inputInfo(int i) |
---|
218 | { |
---|
219 | if (i>=getInputCount()) return 0; |
---|
220 | return &inputs(i).info; |
---|
221 | } |
---|
222 | |
---|
223 | void Neuro::setInputInfo(int i,const SString& name,const SString &value) |
---|
224 | { |
---|
225 | SString **s=inputInfo(i); |
---|
226 | if (!s) return; |
---|
227 | if (!*s) *s=new SString(); |
---|
228 | strSetField(**s,name,value); |
---|
229 | } |
---|
230 | |
---|
231 | void Neuro::setInputInfo(int i,const SString& name,int value) |
---|
232 | { |
---|
233 | setInputInfo(i,name,SString::valueOf(value)); |
---|
234 | } |
---|
235 | |
---|
236 | void Neuro::setInputInfo(int i,const SString& name,double value) |
---|
237 | { |
---|
238 | setInputInfo(i,name,SString::valueOf(value)); |
---|
239 | } |
---|
240 | |
---|
241 | SString Neuro::getInputInfo(int i) |
---|
242 | { |
---|
243 | SString **s=inputInfo(i); |
---|
244 | if (!s) return SString(); |
---|
245 | if (!*s) return SString(); |
---|
246 | return **s; |
---|
247 | } |
---|
248 | |
---|
249 | SString Neuro::getInputInfo(int i,const SString& name) |
---|
250 | { |
---|
251 | SString **s=inputInfo(i); |
---|
252 | if (!s) return SString(); |
---|
253 | if (!*s) return SString(); |
---|
254 | return strGetField(**s,name); |
---|
255 | } |
---|
256 | |
---|
257 | void Neuro::operator=(const Neuro& src) |
---|
258 | { |
---|
259 | refno=src.refno; |
---|
260 | #ifdef MODEL_V1_COMPATIBLE |
---|
261 | neuro_refno=-1; |
---|
262 | conn_refno=-1; |
---|
263 | force=src.force; |
---|
264 | sigmo=src.sigmo; |
---|
265 | inertia=src.inertia; |
---|
266 | weight=src.weight; |
---|
267 | olditems=0; |
---|
268 | #endif |
---|
269 | state=src.state; |
---|
270 | part_refno=-1; |
---|
271 | joint_refno=-1; |
---|
272 | pos=src.pos; rot=src.rot; |
---|
273 | parent=0; part=0; joint=0; |
---|
274 | parentcount=0; |
---|
275 | flags=0; |
---|
276 | myclass=src.myclass; |
---|
277 | knownclass=src.knownclass; |
---|
278 | myclassname=src.myclassname; |
---|
279 | myclassparams=src.myclassparams; |
---|
280 | } |
---|
281 | |
---|
282 | void Neuro::attachToPart(int i) |
---|
283 | {attachToPart((i>=0)?owner->getPart(i):0);} |
---|
284 | |
---|
285 | void Neuro::attachToJoint(int i) |
---|
286 | {attachToJoint((i>=0)?owner->getJoint(i):0);} |
---|
287 | |
---|
288 | int Neuro::getClassCount() |
---|
289 | {return NeuroLibrary::staticlibrary.getClassCount();} |
---|
290 | |
---|
291 | NeuroClass* Neuro::getClass(int classindex) |
---|
292 | {return NeuroLibrary::staticlibrary.getClass(classindex);} |
---|
293 | |
---|
294 | NeuroClass* Neuro::getClass(const SString& classname) |
---|
295 | {return NeuroLibrary::staticlibrary.findClass(classname);} |
---|
296 | |
---|
297 | int Neuro::getClassIndex(const NeuroClass*nc) |
---|
298 | {return NeuroLibrary::staticlibrary.classes.find((void*)nc);} |
---|
299 | |
---|
300 | NeuroClass* Neuro::getClass() |
---|
301 | { |
---|
302 | checkClass(); |
---|
303 | return myclass; |
---|
304 | } |
---|
305 | |
---|
306 | void Neuro::setClass(NeuroClass* cl) |
---|
307 | { |
---|
308 | myclass=cl; |
---|
309 | myclassname=cl->getName(); |
---|
310 | knownclass=1; |
---|
311 | } |
---|
312 | |
---|
313 | SString Neuro::getClassName(int classindex) |
---|
314 | { |
---|
315 | NeuroClass *cl=NeuroLibrary::staticlibrary.getClass(classindex); |
---|
316 | return cl? cl->getName() : SString(); |
---|
317 | } |
---|
318 | |
---|
319 | void Neuro::setDetails(const SString& details) |
---|
320 | { |
---|
321 | int colon=details.indexOf(':'); |
---|
322 | if (colon>=0) {myclassname=details.substr(0,colon); myclassparams=details.substr(colon+1);} |
---|
323 | else {myclassname=details; myclassparams=0;} |
---|
324 | knownclass=0; |
---|
325 | } |
---|
326 | |
---|
327 | SString Neuro::getDetails() |
---|
328 | { |
---|
329 | SString ret=getClassName(); |
---|
330 | if (myclassparams.len()) {if (!ret.len()) ret="N"; ret+=":"; ret+=myclassparams;} |
---|
331 | return ret; |
---|
332 | } |
---|
333 | |
---|
334 | void Neuro::checkClass() |
---|
335 | { |
---|
336 | if (knownclass) return; |
---|
337 | myclass=getClass(myclassname); |
---|
338 | knownclass=1; |
---|
339 | } |
---|
340 | |
---|
341 | SyntParam Neuro::classProperties() |
---|
342 | { |
---|
343 | NeuroClass *cl=getClass(); |
---|
344 | ParamEntry *pe = cl ? cl->getParamTab() : emptyParamTab; |
---|
345 | return SyntParam(pe,&myclassparams); |
---|
346 | } |
---|
347 | |
---|
348 | SString Neuro::getClassName() |
---|
349 | { |
---|
350 | return myclassname; |
---|
351 | } |
---|
352 | |
---|
353 | void Neuro::setClassName(const SString& clazz) |
---|
354 | { |
---|
355 | myclassname=clazz; |
---|
356 | knownclass=0; |
---|
357 | } |
---|
358 | |
---|
359 | int Neuro::addInput(Neuro* child,float weight,const SString *info) |
---|
360 | { |
---|
361 | inputs+=NInput(child,weight,(info&&(info->len()))?new SString(*info):0); |
---|
362 | child->parentcount++; |
---|
363 | if (child->parentcount==1) {child->parent=this;} |
---|
364 | return inputs.size()-1; |
---|
365 | } |
---|
366 | |
---|
367 | int Neuro::findInput(Neuro* child) const |
---|
368 | { |
---|
369 | for(int i=0;i<inputs.size();i++) |
---|
370 | if (inputs(i).n==child) return i; |
---|
371 | return -1; |
---|
372 | } |
---|
373 | |
---|
374 | Neuro* Neuro::getInput(int i,float &weight) const |
---|
375 | { |
---|
376 | if (i>=getInputCount()) return 0; |
---|
377 | NInput &inp=inputs(i); |
---|
378 | weight=inp.weight; |
---|
379 | return inp.n; |
---|
380 | } |
---|
381 | |
---|
382 | float Neuro::getInputWeight(int i) const |
---|
383 | { |
---|
384 | return inputs(i).weight; |
---|
385 | } |
---|
386 | |
---|
387 | void Neuro::setInputWeight(int i,float w) |
---|
388 | { |
---|
389 | inputs(i).weight=w; |
---|
390 | } |
---|
391 | |
---|
392 | void Neuro::setInput(int i,Neuro* n) |
---|
393 | { |
---|
394 | NInput &inp=inputs(i); |
---|
395 | inp.n=n; |
---|
396 | } |
---|
397 | |
---|
398 | void Neuro::setInput(int i,Neuro* n,float w) |
---|
399 | { |
---|
400 | NInput &inp=inputs(i); |
---|
401 | inp.n=n; |
---|
402 | inp.weight=w; |
---|
403 | } |
---|
404 | |
---|
405 | void Neuro::removeInput(int refno) |
---|
406 | { |
---|
407 | Neuro *child=getInput(refno); |
---|
408 | child->parentcount--; |
---|
409 | if (child->parent==this) child->parent=0; |
---|
410 | SString *s=inputs(refno).info; |
---|
411 | if (s) delete s; |
---|
412 | inputs.remove(refno); |
---|
413 | } |
---|
414 | |
---|
415 | int Neuro::removeInput(Neuro* child) |
---|
416 | { |
---|
417 | int i=findInput(child); |
---|
418 | if (i>=0) removeInput(i); |
---|
419 | return i; |
---|
420 | } |
---|
421 | |
---|
422 | int Neuro::getOutputsCount() const |
---|
423 | { |
---|
424 | int c=0; |
---|
425 | for(int i=0;i<owner->getNeuroCount();i++) |
---|
426 | for(int j=0;j<owner->getNeuro(i)->getInputCount();j++) c+=owner->getNeuro(i)->getInput(j)==this; |
---|
427 | return c; |
---|
428 | } |
---|
429 | |
---|
430 | int Neuro::isOldEffector() |
---|
431 | { |
---|
432 | static SString bend("|"),rot("@"); |
---|
433 | return ((getClassName()==bend)||(getClassName()==rot)); |
---|
434 | } |
---|
435 | |
---|
436 | int Neuro::isOldReceptor() |
---|
437 | { |
---|
438 | static SString g("G"),t("T"),s("S"); |
---|
439 | return ((getClassName()==g)||(getClassName()==t)||(getClassName()==s)); |
---|
440 | } |
---|
441 | |
---|
442 | int Neuro::isOldNeuron() |
---|
443 | { |
---|
444 | static SString n("N"); |
---|
445 | return (getClassName()==n); |
---|
446 | } |
---|
447 | |
---|
448 | int Neuro::isNNConnection() |
---|
449 | { |
---|
450 | static SString conn("-"); |
---|
451 | return (getClassName()==conn); |
---|
452 | } |
---|
453 | |
---|
454 | int Neuro::findInputs(SList& result,const char* classname,const Part* part,const Joint* joint) const |
---|
455 | { |
---|
456 | Neuro *nu; |
---|
457 | SString cn(classname); |
---|
458 | int n0=result.size(); |
---|
459 | for(int i=0;nu=getInput(i);i++) |
---|
460 | { |
---|
461 | if (part) |
---|
462 | if (nu->part != part) continue; |
---|
463 | if (joint) |
---|
464 | if (nu->joint != joint) continue; |
---|
465 | if (classname) |
---|
466 | if (nu->getClassName() != cn) continue; |
---|
467 | result+=(void*)nu; |
---|
468 | } |
---|
469 | return result.size()-n0; |
---|
470 | } |
---|
471 | |
---|
472 | int Neuro::findOutputs(SList& result,const char* classname,const Part* part,const Joint* joint) const |
---|
473 | { // not very efficient... |
---|
474 | Neuro *nu,*inp; |
---|
475 | SString cn(classname); |
---|
476 | SList found; |
---|
477 | int n0=result.size(); |
---|
478 | for(int i=0;nu=getModel().getNeuro(i);i++) |
---|
479 | { |
---|
480 | if (part) |
---|
481 | if (nu->part != part) continue; |
---|
482 | if (joint) |
---|
483 | if (nu->joint != joint) continue; |
---|
484 | if (classname) |
---|
485 | if (inp->getClassName() != cn) continue; |
---|
486 | for (int j=0;inp=nu->getInput(j);j++) |
---|
487 | if (inp==this) |
---|
488 | { |
---|
489 | result+=(void*)nu; |
---|
490 | break; |
---|
491 | } |
---|
492 | } |
---|
493 | return result.size()-n0; |
---|
494 | } |
---|
495 | |
---|
496 | void Neuro::get_inputCount(PARAMGETARGS) |
---|
497 | {ret->setInt(inputs.size());} |
---|
498 | |
---|
499 | void Neuro::p_getInputNeuroDef(ExtValue *args,ExtValue *ret) |
---|
500 | { |
---|
501 | int i=args->getInt(); |
---|
502 | if ((i<0)||(i>=inputs.size())) |
---|
503 | ret->setEmpty(); |
---|
504 | else |
---|
505 | ret->setObject(ExtObject(&st_neuroparam,inputs(i).n)); |
---|
506 | } |
---|
507 | |
---|
508 | void Neuro::p_getInputWeight(ExtValue *args,ExtValue *ret) |
---|
509 | { |
---|
510 | int i=args->getInt(); |
---|
511 | if ((i<0)||(i>=inputs.size())) |
---|
512 | ret->setEmpty(); |
---|
513 | else |
---|
514 | ret->setDouble(inputs(i).weight); |
---|
515 | } |
---|
516 | |
---|
517 | void Neuro::p_getInputNeuroIndex(ExtValue *args,ExtValue *ret) |
---|
518 | { |
---|
519 | int i=args->getInt(); |
---|
520 | if ((i<0)||(i>=inputs.size())) |
---|
521 | ret->setInt(-1); |
---|
522 | else |
---|
523 | ret->setInt(inputs(i).n->refno); |
---|
524 | } |
---|
525 | |
---|
526 | /////// old items |
---|
527 | #ifdef MODEL_V1_COMPATIBLE |
---|
528 | void OldItems::buildlist() |
---|
529 | { // guaranteed to work only for old NN layouts |
---|
530 | // (neurons,neuro connections, old receptors and effectors) |
---|
531 | if (listok) return; |
---|
532 | // inputs can contain both neuroitem connections (details="") and direct neuron references (details="N") |
---|
533 | // in OldItems we create neuroitems freom direct references |
---|
534 | for(int i=0;i<neuro.getInputCount();i++) |
---|
535 | { |
---|
536 | float w; |
---|
537 | Neuro *n=neuro.getInput(i,w); |
---|
538 | if (n->isOldNeuron()) |
---|
539 | { |
---|
540 | Neuro *ni=new Neuro(); |
---|
541 | ni->setClassName("-"); |
---|
542 | ni->weight=w; |
---|
543 | ni->neuro_refno=neuro.refno; |
---|
544 | ni->conn_refno=n->refno; |
---|
545 | items+=ni; |
---|
546 | syntitems+=ni; |
---|
547 | } |
---|
548 | else |
---|
549 | { |
---|
550 | items+=n; |
---|
551 | n->weight=w; |
---|
552 | } |
---|
553 | } |
---|
554 | SList outputs; |
---|
555 | neuro.findOutputs(outputs); |
---|
556 | FOREACH(Neuro*,n,outputs) |
---|
557 | { |
---|
558 | if (n->isNNConnection() || n->isOldNeuron()) |
---|
559 | outputs-=n; |
---|
560 | } |
---|
561 | items+=outputs; |
---|
562 | listok=1; |
---|
563 | } |
---|
564 | |
---|
565 | void OldItems::freelist() |
---|
566 | { |
---|
567 | FOREACH(Neuro*,n,syntitems) |
---|
568 | delete n; |
---|
569 | syntitems.clear(); |
---|
570 | items.clear(); |
---|
571 | listok=0; |
---|
572 | } |
---|
573 | |
---|
574 | int OldItems::getItemCount() |
---|
575 | { |
---|
576 | buildlist(); |
---|
577 | return items.size(); |
---|
578 | } |
---|
579 | |
---|
580 | NeuroItem *OldItems::getNeuroItem(int i) |
---|
581 | { |
---|
582 | buildlist(); |
---|
583 | return (NeuroItem*)items(i); |
---|
584 | } |
---|
585 | |
---|
586 | NeuroItem *OldItems::addNewNeuroItem() |
---|
587 | { |
---|
588 | Neuro *nu=neuro.getModel().addNewNeuro(); |
---|
589 | nu->setClassName("-"); |
---|
590 | if (listok) items+=nu; |
---|
591 | neuro.addInput(nu); |
---|
592 | return (NeuroItem*)nu; |
---|
593 | } |
---|
594 | |
---|
595 | int OldItems::findNeuroItem(NeuroItem *ni) |
---|
596 | { |
---|
597 | buildlist(); |
---|
598 | return items.find((void*)ni); |
---|
599 | } |
---|
600 | #endif |
---|
601 | |
---|
602 | /////////////////////////////////////// |
---|
603 | |
---|
604 | const SString& Part::getDefaultStyle() |
---|
605 | {static SString s("part"); return s;} |
---|
606 | const SString& Joint::getDefaultStyle() |
---|
607 | {static SString s("joint"); return s;} |
---|
608 | /* |
---|
609 | const SString& Neuro::getDefaultStyle() |
---|
610 | {static SString s("neuro"); return s;} |
---|
611 | const SString& NeuroItem::getDefaultStyle() |
---|
612 | {static SString s("neuroitem"); return s;} |
---|
613 | */ |
---|
614 | const SString& Neuro::getDefaultStyle() |
---|
615 | {static SString s("neuro"); return s;} |
---|
616 | |
---|
617 | Part::Part():PartBase(getDefaultStyle()) |
---|
618 | { |
---|
619 | o=Orient_1; |
---|
620 | p=Pt3D_0; |
---|
621 | rot=Pt3D_0; |
---|
622 | flags=0; |
---|
623 | #include "defassign-f0_part.h" |
---|
624 | } |
---|
625 | |
---|
626 | void Part::operator=(const Part& src) |
---|
627 | { |
---|
628 | p=src.p; o=src.o; |
---|
629 | flags=src.flags; |
---|
630 | mass=src.mass; density=src.density; |
---|
631 | friction=src.friction; |
---|
632 | ingest=src.ingest; |
---|
633 | assim=src.assim; |
---|
634 | size=src.size; |
---|
635 | rot=src.rot; |
---|
636 | refno=src.refno; |
---|
637 | } |
---|
638 | |
---|
639 | /////////////////////////// |
---|
640 | |
---|
641 | Joint::Joint():PartBase(getDefaultStyle()) |
---|
642 | { |
---|
643 | rot=Pt3D_0; |
---|
644 | #include "defassign-f0_joint.h" |
---|
645 | d.x=JOINT_DELTA_MARKER; |
---|
646 | part1=0; part2=0; |
---|
647 | flags=0; |
---|
648 | usedelta=0; |
---|
649 | } |
---|
650 | |
---|
651 | void Joint::operator=(const Joint& src) |
---|
652 | { |
---|
653 | rot=src.rot; |
---|
654 | d=src.d; |
---|
655 | stamina=src.stamina; |
---|
656 | stif=src.stif; rotstif=src.rotstif; |
---|
657 | part1=0; part2=0; |
---|
658 | flags=src.flags; |
---|
659 | usedelta=src.usedelta; |
---|
660 | refno=src.refno; |
---|
661 | } |
---|
662 | |
---|
663 | void Joint::attachToParts(Part* p1,Part* p2) |
---|
664 | { |
---|
665 | part1=p1; |
---|
666 | part2=p2; |
---|
667 | if (p1 && p2) |
---|
668 | { |
---|
669 | o=rot; |
---|
670 | if (usedelta) |
---|
671 | { |
---|
672 | p1->o.transform(p2->o,o); |
---|
673 | // p2->o.x=p1->o/o.x; p2->o.y=p1->o/o.y; p2->o.z=p1->o/o.z; |
---|
674 | p2->p=p2->o.transform(d)+p1->p; |
---|
675 | } |
---|
676 | } |
---|
677 | } |
---|
678 | |
---|
679 | void Joint::attachToParts(int p1,int p2) |
---|
680 | { |
---|
681 | attachToParts((p1>=0)?owner->getPart(p1):0,(p2>=0)?owner->getPart(p2):0); |
---|
682 | } |
---|
683 | |
---|
684 | void Joint::resetDelta() |
---|
685 | { |
---|
686 | d=Pt3D(JOINT_DELTA_MARKER,0,0); |
---|
687 | } |
---|
688 | |
---|
689 | void Joint::useDelta(int false_or_true) |
---|
690 | { |
---|
691 | usedelta=false_or_true; |
---|
692 | } |
---|
693 | |
---|
694 | int Joint::isDelta() |
---|
695 | { |
---|
696 | return usedelta; |
---|
697 | } |
---|
698 | |
---|
699 | ///////////////////////////////////////////////////////////////// |
---|
700 | ///////////////////////////////////////////////////////////////// |
---|
701 | |
---|
702 | #include "f0classes.h" |
---|
703 | |
---|
704 | #ifdef MODEL_V1_COMPATIBLE |
---|
705 | |
---|
706 | #define FIELDSTRUCT Neuro |
---|
707 | ParamEntry f0_old_neuro_tab[]= |
---|
708 | { |
---|
709 | {"Connections",2,6,"n",}, |
---|
710 | {"Other properties",}, |
---|
711 | {"p",0,0,"part ref#","d",FIELD(part_refno),}, |
---|
712 | {"j",0,0,"joint ref#","d",FIELD(joint_refno),}, |
---|
713 | {"s",1,0,"state","f",FIELD(state),}, |
---|
714 | {"in",1,0,"Inertia","f",FIELD(inertia),}, |
---|
715 | {"fo",1,0,"Force","f",FIELD(force),}, |
---|
716 | {"si",1,0,"Sigmoid","f",FIELD(sigmo),}, |
---|
717 | {0,0,0,}, |
---|
718 | }; |
---|
719 | #undef FIELDSTRUCT |
---|
720 | |
---|
721 | #define FIELDSTRUCT NeuroItem |
---|
722 | ParamEntry f0_neuroitem_paramtab[]= |
---|
723 | { |
---|
724 | {"Connections",3,12,"ni",}, |
---|
725 | {"Geometry",}, |
---|
726 | {"Other",}, |
---|
727 | {"n",0,0,"neuron ref#","d",FIELD(neuro_refno),}, |
---|
728 | {"c",2,0,"connection ref#","d",FIELD(conn_refno),}, |
---|
729 | {"w",2,0,"connection weight","f",FIELD(weight),}, |
---|
730 | {"p",0,0,"part ref#","d",FIELD(part_refno),}, |
---|
731 | {"j",0,0,"joint ref#","d",FIELD(joint_refno),}, |
---|
732 | {"px",1,0,"position.x","f",FIELD(pos.x),}, |
---|
733 | {"py",1,0,"position.y","f",FIELD(pos.y),}, |
---|
734 | {"pz",1,0,"position.z","f",FIELD(pos.z),}, |
---|
735 | {"rx",1,0,"rotation.x","f",FIELD(rot.x),}, |
---|
736 | {"ry",1,0,"rotation.y","f",FIELD(rot.y),}, |
---|
737 | {"rz",1,0,"rotation.z","f",FIELD(rot.z),}, |
---|
738 | {"d",2,0,"item details","s",GETSET(details),}, |
---|
739 | {0,0,0,}, |
---|
740 | }; |
---|
741 | #undef FIELDSTRUCT |
---|
742 | #endif |
---|
743 | |
---|
744 | //////////////////////////////////////// |
---|
745 | |
---|
746 | ParamEntry Neuro::emptyParamTab[]= |
---|
747 | { |
---|
748 | {"Undefined Neuro",1,0,"?",}, |
---|
749 | {0,0,0,}, |
---|
750 | }; |
---|
751 | |
---|
752 | static Param staticparam; |
---|
753 | |
---|
754 | ParamInterface &Part::extraProperties() |
---|
755 | { |
---|
756 | staticparam.setParamTab(f0_part_xtra_paramtab); |
---|
757 | staticparam.select(this); |
---|
758 | return staticparam; |
---|
759 | } |
---|
760 | |
---|
761 | ParamInterface &Joint::extraProperties() |
---|
762 | { |
---|
763 | staticparam.setParamTab(f0_joint_xtra_paramtab); |
---|
764 | staticparam.select(this); |
---|
765 | return staticparam; |
---|
766 | } |
---|
767 | |
---|
768 | ParamInterface &Neuro::extraProperties() |
---|
769 | { |
---|
770 | staticparam.setParamTab(f0_neuro_xtra_paramtab); |
---|
771 | staticparam.select(this); |
---|
772 | return staticparam; |
---|
773 | } |
---|
774 | |
---|
775 | ParamInterface &Part::properties() |
---|
776 | { |
---|
777 | staticparam.setParamTab(f0_part_paramtab); |
---|
778 | staticparam.select(this); |
---|
779 | return staticparam; |
---|
780 | } |
---|
781 | |
---|
782 | ParamInterface &Joint::properties() |
---|
783 | { |
---|
784 | staticparam.setParamTab(usedelta?f0_joint_paramtab:f0_nodeltajoint_paramtab); |
---|
785 | staticparam.select(this); |
---|
786 | return staticparam; |
---|
787 | } |
---|
788 | |
---|
789 | ParamInterface &Neuro::properties() |
---|
790 | { |
---|
791 | staticparam.setParamTab(f0_neuro_paramtab); |
---|
792 | staticparam.select(this); |
---|
793 | return staticparam; |
---|
794 | } |
---|
795 | |
---|
796 | class NeuroExtParamTab: public ParamTab |
---|
797 | { |
---|
798 | public: |
---|
799 | NeuroExtParamTab():ParamTab(f0_neuro_paramtab) |
---|
800 | { |
---|
801 | #define FIELDSTRUCT NeuroExt |
---|
802 | ParamEntry entry={"class",2,0,"neuro class","s",GETSET(neuroclass)}; |
---|
803 | #undef FIELDSTRUCT |
---|
804 | add(&entry); |
---|
805 | |
---|
806 | #define FIELDSTRUCT Neuro |
---|
807 | ParamEntry entry2={"state",2,0,"state","f",FIELD(state)}; |
---|
808 | #undef FIELDSTRUCT |
---|
809 | add(&entry2); |
---|
810 | } |
---|
811 | }; |
---|
812 | |
---|
813 | //////////////////////// |
---|
814 | |
---|
815 | NeuroConn::NeuroConn() |
---|
816 | { |
---|
817 | #include "defassign-f0_neuroconn.h" |
---|
818 | } |
---|
819 | |
---|
820 | ////////////////////////////////////// |
---|
821 | |
---|
822 | ParamEntry *NeuroExt::getParamTab() |
---|
823 | { |
---|
824 | static NeuroExtParamTab tab; |
---|
825 | return tab.getParamTab(); |
---|
826 | } |
---|
827 | |
---|
828 | void NeuroExt::get_neuroclass(PARAMGETARGS) |
---|
829 | {ret->setString(getClassName());} |
---|
830 | |
---|
831 | int NeuroExt::set_neuroclass(PARAMSETARGS) |
---|
832 | {setClassName(arg->getString());return PSET_CHANGED;} |
---|
833 | |
---|
834 | Param st_neuroparam(f0_neuro_paramtab,0,"NeuroDef"); |
---|
835 | Param st_jointparam(f0_joint_paramtab,0,"Joint"); |
---|
836 | Param st_partparam(f0_part_paramtab,0,"Part"); |
---|
837 | |
---|
838 | |
---|