2 #include "OSGBaseInitFunctions.h"
4 #include "OSGNodeCore.h"
8 static void dumpAspect(OSG::TestFC
*pFC
, OSG::UInt32 uiAspect
)
10 OSG::UInt32 uiCurrAspect
= OSG::Thread::getCurrentAspect();
12 OSG::Thread::setAspectTo(uiAspect
);
14 #ifdef OSG_MT_CPTR_ASPECT
15 OSG::TestFC
*pAFC
= OSG::convertToCurrentAspect(pFC
);
17 OSG::TestFC
*pAFC
= getCPtr(pFC
);
26 fprintf(stderr
, "No Aspect Ptr\n");
29 OSG::Thread::setAspectTo(uiCurrAspect
);
32 void applyToAspect(OSG::UInt32 uiAspect
, bool bClear
= true)
34 OSG::UInt32 uiCurrAspect
= OSG::Thread::getCurrentAspect();
36 OSG::Thread::setAspectTo(uiAspect
);
38 OSG::Thread::getCurrentChangeList()->applyNoClear();
42 OSG::Thread::getCurrentChangeList()->clear();
45 OSG::Thread::setAspectTo(uiCurrAspect
);
48 void applyToAspectAndClear(OSG::UInt32 uiAspect
)
50 OSG::UInt32 uiCurrAspect
= OSG::Thread::getCurrentAspect();
52 OSG::Thread::setAspectTo(uiAspect
);
54 OSG::Thread::getCurrentChangeList()->applyAndClear();
56 OSG::Thread::setAspectTo(uiCurrAspect
);
59 void testSharing(void)
61 fprintf(stderr
, "sharing\n");
62 fprintf(stderr
, "%" PRIUSize
"\n", sizeof(OSG::TestFC
));
64 OSG::TestFCUnrecPtr pTestFC
= OSG::TestFC::create();
66 fprintf(stderr
, "sharing | created\n");
68 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
70 fprintf(stderr
, "Aspect %d\n", i
);
72 dumpAspect(pTestFC
, i
);
75 OSG::Thread::getCurrentChangeList()->dump();
78 pTestFC
->editMFField1()->reserve (32);
79 pTestFC
->editMFField1()->push_back( 0);
80 pTestFC
->editMFField1()->push_back( 1);
81 pTestFC
->editMFField1()->push_back( 2);
82 pTestFC
->editMFField1()->push_back( 3);
85 OSG::Thread::getCurrentChangeList()->dump();
88 pTestFC
->editSFField2()->setValue(4);
91 OSG::Thread::getCurrentChangeList()->dump();
93 OSG::Thread::getCurrentChangeList()->commitChanges();
95 OSG::Thread::getCurrentChangeList()->dump();
97 fprintf(stderr
, "sharing | filled\n");
99 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
101 fprintf(stderr
, "Aspect %d\n", i
);
102 dumpAspect(pTestFC
, i
);
105 fprintf(stderr
, "sharing | apply\n");
107 applyToAspect(1, false);
110 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
112 fprintf(stderr
, "Aspect %d\n", i
);
114 dumpAspect(pTestFC
, i
);
117 pTestFC
->editMFField1()->clear();
118 pTestFC
->editMFField1()->push_back( 10);
119 pTestFC
->editMFField1()->push_back( 11);
120 pTestFC
->editMFField1()->push_back( 12);
121 pTestFC
->editMFField1()->push_back( 13);
123 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
125 fprintf(stderr
, "Aspect %d\n", i
);
127 dumpAspect(pTestFC
, i
);
130 applyToAspect(1, false);
133 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
135 fprintf(stderr
, "Aspect %d\n", i
);
137 dumpAspect(pTestFC
, i
);
143 void testSharing1(void)
145 fprintf(stderr
, "sharing\n");
146 fprintf(stderr
, "%" PRIUSize
"\n", sizeof(OSG::TestFC
));
148 OSG::TestFCUnrecPtr pTestFC
= OSG::TestFC::create();
150 fprintf(stderr
, "sharing | created\n");
152 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
154 fprintf(stderr
, "Aspect %d\n", i
);
156 dumpAspect(pTestFC
, i
);
159 OSG::Thread::getCurrentChangeList()->dump();
161 pTestFC
->editMFField1()->reserve (1024);
163 for(OSG::UInt32 i
= 0; i
< 1024; ++i
)
165 pTestFC
->editMFField1()->push_back(i
);
168 OSG::Thread::getCurrentChangeList()->dump();
170 OSG::Thread::getCurrentChangeList()->commitChanges();
172 OSG::Thread::getCurrentChangeList()->dump();
174 fprintf(stderr
, "sharing | filled\n");
176 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
178 fprintf(stderr
, "Aspect %d\n", i
);
179 dumpAspect(pTestFC
, i
);
182 fprintf(stderr
, "sharing | apply\n");
189 pTestFC
->editMFField1();
190 OSG::Thread::getCurrentChangeList()->commitChanges();
198 void testSharing2(void)
200 fprintf(stderr
, "sharing\n");
201 fprintf(stderr
, "%" PRIUSize
"\n", sizeof(OSG::TestFC
));
203 OSG::TestFCUnrecPtr pTestFC
= OSG::TestFC::create();
205 fprintf(stderr
, "sharing | created\n");
207 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
209 fprintf(stderr
, "Aspect %d\n", i
);
211 dumpAspect(pTestFC
, i
);
214 OSG::Thread::getCurrentChangeList()->dump();
216 pTestFC
->editMFField1()->reserve (1024);
218 for(OSG::UInt32 i
= 0; i
< 1024; ++i
)
220 pTestFC
->editMFField1()->push_back(i
);
223 OSG::Thread::getCurrentChangeList()->dump();
225 OSG::Thread::getCurrentChangeList()->commitChanges();
227 OSG::Thread::getCurrentChangeList()->dump();
229 fprintf(stderr
, "sharing | filled\n");
231 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
233 fprintf(stderr
, "Aspect %d\n", i
);
234 dumpAspect(pTestFC
, i
);
237 fprintf(stderr
, "sharing | apply\n");
251 OSG::SFNodePtr sfNode
;
252 OSG::MFNodePtr mfNode
;
254 OSG::NodePtr pNode
= OSG::Node::create();
256 sfNode
.setValue(pNode
);
257 mfNode
.push_back(pNode
);
260 fprintf(stderr, "%p %p %p | %d %d\n",
264 OSG::Node::VolumeFieldId,
265 OSG::Node::TravMaskFieldId);
268 OSG::NodePtr pNode1
= OSG::Node::create();
270 sfNode
.setValue(pNode1
);
272 mfNode
.replace(1, pNode1
);
274 const OSG::Field
*pF1
= pNode
->getSFVolume();
275 OSG::Field
*pF2
= pNode
->editSFVolume();
277 OSG::GetFieldHandlePtr pRF1
= pNode
->getField("volume");
278 OSG::EditFieldHandlePtr pRF2
= pNode
->editField("volume");
280 fprintf(stderr
, "#### Field %p %p | %p %p\n",
286 // fprintf(stderr, "%p %p %p\n", pNode1, sfNode.getValue(), mfNode[1]);
288 const OSG::SFNodePtr constSFNode
;
290 // fprintf(stderr, "%p %p\n", pNode1, constSFNode.getValue());
292 OSG::FieldContainerPtr pNodeClone
= deepClone(pNode
);
294 OSG::FieldContainerPtr pFC
=
295 OSG::FieldContainerFactory::the()->createContainer("Billboard");
297 fprintf(stderr
, "### FOO %p\n", getCPtr(pFC
));
303 void testRefCount(void)
306 OSG::NodePtr pNode
= OSG::Node::create();
308 OSG::NodePtr pNode1
= OSG::Node::create();
310 fprintf(stderr
, "1\n");
318 pNode
->addChild(pNode1
);
320 fprintf(stderr
, "2\n");
328 fprintf(stderr
, "3\n");
336 applyToAspect(1, false);
339 fprintf(stderr
, "4\n");
347 fprintf(stderr
, "5\n");
355 applyToAspect(1, false);
357 fprintf(stderr
, "6\n");
367 fprintf(stderr
, "7\n");
371 void testChangeList(void)
373 fprintf(stderr
, "testChangeList\n");
374 fprintf(stderr
, "%" PRIUSize
"\n", sizeof(OSG::TestFC
));
376 OSG::TestFCUnrecPtr pTestFC
= OSG::TestFC::create();
378 fprintf(stderr
, "sharing | created\n");
380 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
382 fprintf(stderr
, "Aspect %d\n", i
);
384 dumpAspect(pTestFC
, i
);
387 OSG::Thread::getCurrentChangeList()->dump();
389 fprintf(stderr
, "=================================================\n");
391 pTestFC
->editSFField2()->setValue(4);
393 fprintf(stderr
, "Changed\n");
394 OSG::Thread::getCurrentChangeList()->dump();
396 OSG::Thread::getCurrentChangeList()->commitChanges();
398 fprintf(stderr
, "Commited\n");
399 OSG::Thread::getCurrentChangeList()->dump();
401 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
403 fprintf(stderr
, "Aspect %d\n", i
);
405 dumpAspect(pTestFC
, i
);
408 fprintf(stderr
, "=================================================\n");
410 pTestFC
->editSFField2()->setValue(4);
412 fprintf(stderr
, "Changed\n");
413 OSG::Thread::getCurrentChangeList()->dump();
415 OSG::Thread::getCurrentChangeList()->commitChangesAndClear();
417 fprintf(stderr
, "CommitAndCleared\n");
418 OSG::Thread::getCurrentChangeList()->dump();
420 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
422 fprintf(stderr
, "Aspect %d\n", i
);
424 dumpAspect(pTestFC
, i
);
427 fprintf(stderr
, "=================================================\n");
429 pTestFC
->editSFField2()->setValue(4);
431 fprintf(stderr
, "Changed\n");
432 OSG::Thread::getCurrentChangeList()->dump();
434 // OSG::Thread::getCurrentChangeList()->commitChanges();
436 applyToAspectAndClear(1);
438 fprintf(stderr
, "Changed\n");
439 OSG::Thread::getCurrentChangeList()->dump();
441 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
443 fprintf(stderr
, "Aspect %d\n", i
);
445 dumpAspect(pTestFC
, i
);
448 fprintf(stderr
, "=================================================\n");
450 pTestFC
->editSFField2()->setValue(4);
452 fprintf(stderr
, "Changed\n");
453 OSG::Thread::getCurrentChangeList()->dump();
455 // OSG::Thread::getCurrentChangeList()->commitChanges();
457 applyToAspect(1, false);
459 fprintf(stderr
, "Changed\n");
460 OSG::Thread::getCurrentChangeList()->dump();
462 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
464 fprintf(stderr
, "Aspect %d\n", i
);
466 dumpAspect(pTestFC
, i
);
469 fprintf(stderr
, "=================================================\n");
471 pTestFC
->editSFField2()->setValue(4);
473 fprintf(stderr
, "Changed\n");
474 OSG::Thread::getCurrentChangeList()->dump();
476 // OSG::Thread::getCurrentChangeList()->commitChanges();
478 applyToAspect(1, true);
480 fprintf(stderr
, "Changed\n");
481 OSG::Thread::getCurrentChangeList()->dump();
483 for(OSG::UInt32 i
= 0; i
< OSG::ThreadManager::getNumAspects(); ++i
)
485 fprintf(stderr
, "Aspect %d\n", i
);
487 dumpAspect(pTestFC
, i
);
494 int main (int argc
, char **argv
)
497 OSG::ThreadManager::setNumAspects(3);
498 OSG::osgInit(argc
, argv
);
500 OSG::Thread::getCurrentChangeList()->dump ();
501 OSG::Thread::getCurrentChangeList()->clear();
503 OSG::Node ::getClassType().dump();
504 OSG::NodeCore::getClassType().dump();
513 fprintf(stderr
, "exit\n");