|
@@ -17,7 +17,6 @@
|
17
|
17
|
|
18
|
18
|
World::World()
|
19
|
19
|
{
|
20
|
|
- mClearLock = false;
|
21
|
20
|
mFlags = 0;
|
22
|
21
|
}
|
23
|
22
|
|
|
@@ -320,17 +319,159 @@ void World::clearFlag(WorldFlag flag)
|
320
|
319
|
|
321
|
320
|
void World::destroy()
|
322
|
321
|
{
|
323
|
|
- // Add some locking to check use state first
|
324
|
|
- if (!mClearLock)
|
325
|
|
- {
|
326
|
|
- clear();
|
|
322
|
+ room_mesh_t *room;
|
|
323
|
+ model_mesh_t *mesh;
|
|
324
|
+ sprite_seq_t *sprite;
|
|
325
|
+ skeletal_model_t *model;
|
|
326
|
+ bone_frame_t *boneframe;
|
|
327
|
+ bone_tag_t *tag;
|
|
328
|
+ animation_frame_t *animation;
|
|
329
|
+ std::list<skeletal_model_t *> cache;
|
|
330
|
+
|
|
331
|
+ for (std::vector<int>::size_type i = 0; i != mEntities.size(); i++)
|
|
332
|
+ delete mEntities[i];
|
|
333
|
+ mEntities.clear();
|
|
334
|
+
|
|
335
|
+ for (std::vector<int>::size_type i = 0; i != mRooms.size(); i++) {
|
|
336
|
+ room = mRooms[i];
|
|
337
|
+
|
|
338
|
+ if (room) {
|
|
339
|
+ //! \fixme Causes "freeing already freed pointer" exceptions or EXEC_BAD_ACCESS
|
|
340
|
+
|
|
341
|
+ //for (std::vector<int>::size_type j = 0; j != room->portals.size(); j++)
|
|
342
|
+ // delete room->portals[i];
|
|
343
|
+ room->portals.clear();
|
|
344
|
+
|
|
345
|
+ //for (std::vector<int>::size_type j = 0; j != room->models.size(); j++)
|
|
346
|
+ // delete room->models[i];
|
|
347
|
+ room->models.clear();
|
|
348
|
+
|
|
349
|
+ //for (std::vector<int>::size_type j = 0; j != room->sprites.size(); j++)
|
|
350
|
+ // delete room->sprites[i];
|
|
351
|
+ room->sprites.clear();
|
|
352
|
+
|
|
353
|
+ //for (std::vector<int>::size_type j = 0; j != room->sectors.size(); j++)
|
|
354
|
+ // delete room->sectors[i];
|
|
355
|
+ room->sectors.clear();
|
|
356
|
+
|
|
357
|
+ //for (std::vector<int>::size_type j = 0; j != room->boxes.size(); j++)
|
|
358
|
+ // delete room->boxes[i];
|
|
359
|
+ room->boxes.clear();
|
|
360
|
+
|
|
361
|
+ delete room;
|
|
362
|
+ }
|
327
|
363
|
}
|
|
364
|
+
|
|
365
|
+ for (std::vector<int>::size_type i = 0; i != mMeshes.size(); i++) {
|
|
366
|
+ mesh = mMeshes[i];
|
|
367
|
+
|
|
368
|
+ if (!mesh)
|
|
369
|
+ continue;
|
|
370
|
+
|
|
371
|
+ for (std::vector<int>::size_type j = 0; j != mesh->texturedTriangles.size(); j++) {
|
|
372
|
+ if (mesh->texturedTriangles[j])
|
|
373
|
+ delete mesh->texturedTriangles[j];
|
|
374
|
+ }
|
|
375
|
+
|
|
376
|
+ for (std::vector<int>::size_type j = 0; j != mesh->coloredTriangles.size(); j++) {
|
|
377
|
+ if (mesh->coloredTriangles[j])
|
|
378
|
+ delete mesh->coloredTriangles[j];
|
|
379
|
+ }
|
|
380
|
+
|
|
381
|
+ for (std::vector<int>::size_type j = 0; j != mesh->texturedRectangles.size(); j++) {
|
|
382
|
+ if (mesh->texturedRectangles[j])
|
|
383
|
+ delete mesh->texturedRectangles[j];
|
|
384
|
+ }
|
|
385
|
+
|
|
386
|
+ for (std::vector<int>::size_type j = 0; j != mesh->coloredRectangles.size(); j++) {
|
|
387
|
+ if (mesh->coloredRectangles[j])
|
|
388
|
+ delete mesh->coloredRectangles[j];
|
|
389
|
+ }
|
|
390
|
+
|
|
391
|
+ if (mesh->vertices)
|
|
392
|
+ delete [] mesh->vertices;
|
|
393
|
+
|
|
394
|
+ if (mesh->colors)
|
|
395
|
+ delete [] mesh->colors;
|
|
396
|
+
|
|
397
|
+ if (mesh->normals)
|
|
398
|
+ delete [] mesh->normals;
|
|
399
|
+
|
|
400
|
+ delete mesh;
|
|
401
|
+ }
|
|
402
|
+
|
|
403
|
+ mMeshes.clear();
|
|
404
|
+
|
|
405
|
+ for (std::vector<int>::size_type i = 0; i != mSprites.size(); i++) {
|
|
406
|
+ sprite = mSprites[i];
|
|
407
|
+
|
|
408
|
+ if (!sprite)
|
|
409
|
+ continue;
|
|
410
|
+
|
|
411
|
+ if (sprite->sprite)
|
|
412
|
+ delete [] sprite->sprite;
|
|
413
|
+
|
|
414
|
+ delete sprite;
|
|
415
|
+ }
|
|
416
|
+
|
|
417
|
+ mSprites.clear();
|
|
418
|
+
|
|
419
|
+ for (std::vector<int>::size_type i = 0; i != mModels.size(); i++) {
|
|
420
|
+ model = mModels[i];
|
|
421
|
+
|
|
422
|
+ if (!model)
|
|
423
|
+ continue;
|
|
424
|
+
|
|
425
|
+ // No smart pointers, so skip if deleted once =)
|
|
426
|
+ bool found = false;
|
|
427
|
+ for (std::list<skeletal_model_t *>::const_iterator iterator = cache.begin(), end = cache.end(); iterator != end; ++iterator) {
|
|
428
|
+ if (model == *iterator) {
|
|
429
|
+ found = true;
|
|
430
|
+ break;
|
|
431
|
+ }
|
|
432
|
+ }
|
|
433
|
+
|
|
434
|
+ if (!found)
|
|
435
|
+ cache.push_back(model);
|
|
436
|
+ else
|
|
437
|
+ continue;
|
|
438
|
+
|
|
439
|
+ for (std::vector<int>::size_type j = 0; j != model->animation.size(); j++) {
|
|
440
|
+ animation = model->animation[j];
|
|
441
|
+
|
|
442
|
+ if (!animation)
|
|
443
|
+ continue;
|
|
444
|
+
|
|
445
|
+ for (std::vector<int>::size_type k = 0; k != animation->frame.size(); k++) {
|
|
446
|
+ boneframe = animation->frame[k];
|
|
447
|
+
|
|
448
|
+ if (!boneframe)
|
|
449
|
+ continue;
|
|
450
|
+
|
|
451
|
+ for (std::vector<int>::size_type l = 0; l != boneframe->tag.size(); l++) {
|
|
452
|
+ tag = boneframe->tag[l];
|
|
453
|
+
|
|
454
|
+ if (!tag)
|
|
455
|
+ continue;
|
|
456
|
+
|
|
457
|
+ delete tag;
|
|
458
|
+ }
|
|
459
|
+
|
|
460
|
+ delete boneframe;
|
|
461
|
+ }
|
|
462
|
+
|
|
463
|
+ delete animation;
|
|
464
|
+ }
|
|
465
|
+
|
|
466
|
+ delete model;
|
|
467
|
+ }
|
|
468
|
+
|
|
469
|
+ mModels.clear();
|
328
|
470
|
}
|
329
|
471
|
|
330
|
472
|
|
331
|
473
|
void World::addRoom(room_mesh_t *room)
|
332
|
474
|
{
|
333
|
|
- mClearLock = false;
|
334
|
475
|
mRooms.push_back(room);
|
335
|
476
|
}
|
336
|
477
|
|
|
@@ -338,10 +479,7 @@ void World::addRoom(room_mesh_t *room)
|
338
|
479
|
void World::addMesh(model_mesh_t *mesh)
|
339
|
480
|
{
|
340
|
481
|
if (mesh)
|
341
|
|
- {
|
342
|
|
- mClearLock = false;
|
343
|
482
|
mMeshes.push_back(mesh);
|
344
|
|
- }
|
345
|
483
|
}
|
346
|
484
|
|
347
|
485
|
|
|
@@ -349,7 +487,6 @@ void World::addEntity(entity_t *e)
|
349
|
487
|
{
|
350
|
488
|
if (e)
|
351
|
489
|
{
|
352
|
|
- mClearLock = false;
|
353
|
490
|
e->master = 0x0;
|
354
|
491
|
e->moveType = worldMoveType_walk; // Walk
|
355
|
492
|
e->room = getRoomByLocation(e->pos[0], e->pos[1], e->pos[2]);
|
|
@@ -362,7 +499,6 @@ int World::addModel(skeletal_model_t *model)
|
362
|
499
|
{
|
363
|
500
|
if (model)
|
364
|
501
|
{
|
365
|
|
- mClearLock = false;
|
366
|
502
|
mModels.push_back(model);
|
367
|
503
|
return mModels.size() - 1;
|
368
|
504
|
}
|
|
@@ -374,10 +510,7 @@ int World::addModel(skeletal_model_t *model)
|
374
|
510
|
void World::addSprite(sprite_seq_t *sprite)
|
375
|
511
|
{
|
376
|
512
|
if (sprite)
|
377
|
|
- {
|
378
|
|
- mClearLock = false;
|
379
|
513
|
mSprites.push_back(sprite);
|
380
|
|
- }
|
381
|
514
|
}
|
382
|
515
|
|
383
|
516
|
|
|
@@ -599,156 +732,4 @@ void World::moveEntity(entity_t *e, char movement)
|
599
|
732
|
// Private Mutators
|
600
|
733
|
////////////////////////////////////////////////////////////
|
601
|
734
|
|
602
|
|
-void World::clear() {
|
603
|
|
- room_mesh_t *room;
|
604
|
|
- model_mesh_t *mesh;
|
605
|
|
- sprite_seq_t *sprite;
|
606
|
|
- skeletal_model_t *model;
|
607
|
|
- bone_frame_t *boneframe;
|
608
|
|
- bone_tag_t *tag;
|
609
|
|
- animation_frame_t *animation;
|
610
|
|
- std::list<skeletal_model_t *> cache;
|
611
|
|
-
|
612
|
|
- mClearLock = true;
|
613
|
|
-
|
614
|
|
- for (std::vector<int>::size_type i = 0; i != mEntities.size(); i++)
|
615
|
|
- delete mEntities[i];
|
616
|
|
- mEntities.clear();
|
617
|
|
-
|
618
|
|
- for (std::vector<int>::size_type i = 0; i != mRooms.size(); i++) {
|
619
|
|
- room = mRooms[i];
|
620
|
|
-
|
621
|
|
- if (room) {
|
622
|
|
- //! \fixme Causes "freeing already freed pointer" exceptions or EXEC_BAD_ACCESS
|
623
|
|
-
|
624
|
|
- //for (std::vector<int>::size_type j = 0; j != room->portals.size(); j++)
|
625
|
|
- // delete room->portals[i];
|
626
|
|
- room->portals.clear();
|
627
|
|
-
|
628
|
|
- //for (std::vector<int>::size_type j = 0; j != room->models.size(); j++)
|
629
|
|
- // delete room->models[i];
|
630
|
|
- room->models.clear();
|
631
|
|
-
|
632
|
|
- //for (std::vector<int>::size_type j = 0; j != room->sprites.size(); j++)
|
633
|
|
- // delete room->sprites[i];
|
634
|
|
- room->sprites.clear();
|
635
|
|
-
|
636
|
|
- //for (std::vector<int>::size_type j = 0; j != room->sectors.size(); j++)
|
637
|
|
- // delete room->sectors[i];
|
638
|
|
- room->sectors.clear();
|
639
|
|
-
|
640
|
|
- //for (std::vector<int>::size_type j = 0; j != room->boxes.size(); j++)
|
641
|
|
- // delete room->boxes[i];
|
642
|
|
- room->boxes.clear();
|
643
|
|
-
|
644
|
|
- delete room;
|
645
|
|
- }
|
646
|
|
- }
|
647
|
|
-
|
648
|
|
- for (std::vector<int>::size_type i = 0; i != mMeshes.size(); i++) {
|
649
|
|
- mesh = mMeshes[i];
|
650
|
|
-
|
651
|
|
- if (!mesh)
|
652
|
|
- continue;
|
653
|
|
-
|
654
|
|
- for (std::vector<int>::size_type j = 0; j != mesh->texturedTriangles.size(); j++) {
|
655
|
|
- if (mesh->texturedTriangles[j])
|
656
|
|
- delete mesh->texturedTriangles[j];
|
657
|
|
- }
|
658
|
|
-
|
659
|
|
- for (std::vector<int>::size_type j = 0; j != mesh->coloredTriangles.size(); j++) {
|
660
|
|
- if (mesh->coloredTriangles[j])
|
661
|
|
- delete mesh->coloredTriangles[j];
|
662
|
|
- }
|
663
|
|
-
|
664
|
|
- for (std::vector<int>::size_type j = 0; j != mesh->texturedRectangles.size(); j++) {
|
665
|
|
- if (mesh->texturedRectangles[j])
|
666
|
|
- delete mesh->texturedRectangles[j];
|
667
|
|
- }
|
668
|
|
-
|
669
|
|
- for (std::vector<int>::size_type j = 0; j != mesh->coloredRectangles.size(); j++) {
|
670
|
|
- if (mesh->coloredRectangles[j])
|
671
|
|
- delete mesh->coloredRectangles[j];
|
672
|
|
- }
|
673
|
|
-
|
674
|
|
- if (mesh->vertices)
|
675
|
|
- delete [] mesh->vertices;
|
676
|
|
-
|
677
|
|
- if (mesh->colors)
|
678
|
|
- delete [] mesh->colors;
|
679
|
|
-
|
680
|
|
- if (mesh->normals)
|
681
|
|
- delete [] mesh->normals;
|
682
|
|
-
|
683
|
|
- delete mesh;
|
684
|
|
- }
|
685
|
|
-
|
686
|
|
- mMeshes.clear();
|
687
|
|
-
|
688
|
|
- for (std::vector<int>::size_type i = 0; i != mSprites.size(); i++) {
|
689
|
|
- sprite = mSprites[i];
|
690
|
|
-
|
691
|
|
- if (!sprite)
|
692
|
|
- continue;
|
693
|
|
-
|
694
|
|
- if (sprite->sprite)
|
695
|
|
- delete [] sprite->sprite;
|
696
|
|
-
|
697
|
|
- delete sprite;
|
698
|
|
- }
|
699
|
|
-
|
700
|
|
- mSprites.clear();
|
701
|
|
-
|
702
|
|
- for (std::vector<int>::size_type i = 0; i != mModels.size(); i++) {
|
703
|
|
- model = mModels[i];
|
704
|
|
-
|
705
|
|
- if (!model)
|
706
|
|
- continue;
|
707
|
|
-
|
708
|
|
- // No smart pointers, so skip if deleted once =)
|
709
|
|
- bool found = false;
|
710
|
|
- for (std::list<skeletal_model_t *>::const_iterator iterator = cache.begin(), end = cache.end(); iterator != end; ++iterator) {
|
711
|
|
- if (model == *iterator) {
|
712
|
|
- found = true;
|
713
|
|
- break;
|
714
|
|
- }
|
715
|
|
- }
|
716
|
|
-
|
717
|
|
- if (!found)
|
718
|
|
- cache.push_back(model);
|
719
|
|
- else
|
720
|
|
- continue;
|
721
|
|
-
|
722
|
|
- for (std::vector<int>::size_type j = 0; j != model->animation.size(); j++) {
|
723
|
|
- animation = model->animation[j];
|
724
|
|
-
|
725
|
|
- if (!animation)
|
726
|
|
- continue;
|
727
|
|
-
|
728
|
|
- for (std::vector<int>::size_type k = 0; k != animation->frame.size(); k++) {
|
729
|
|
- boneframe = animation->frame[k];
|
730
|
|
-
|
731
|
|
- if (!boneframe)
|
732
|
|
- continue;
|
733
|
|
-
|
734
|
|
- for (std::vector<int>::size_type l = 0; l != boneframe->tag.size(); l++) {
|
735
|
|
- tag = boneframe->tag[l];
|
736
|
|
-
|
737
|
|
- if (!tag)
|
738
|
|
- continue;
|
739
|
|
-
|
740
|
|
- delete tag;
|
741
|
|
- }
|
742
|
|
-
|
743
|
|
- delete boneframe;
|
744
|
|
- }
|
745
|
|
-
|
746
|
|
- delete animation;
|
747
|
|
- }
|
748
|
|
-
|
749
|
|
- delete model;
|
750
|
|
- }
|
751
|
|
-
|
752
|
|
- mModels.clear();
|
753
|
|
-}
|
754
|
735
|
|