|
@@ -381,13 +381,10 @@ void Game::processMoveables()
|
381
|
381
|
|
382
|
382
|
// index moveable, i item, sometimes both moveable
|
383
|
383
|
// object_id of item or moveable
|
384
|
|
-void Game::processMoveable(int index, int i, int object_id)
|
385
|
|
-{
|
386
|
|
- //std::vector<skeletal_model_t *> &cache2
|
387
|
|
- //std::vector<unsigned int> &cache
|
388
|
|
-
|
|
384
|
+void Game::processMoveable(int index, int i, int object_id) {
|
389
|
385
|
bool cached = false;
|
390
|
|
- for (unsigned int mod = 0; mod < getWorld().sizeSkeletalModel(); mod++) {
|
|
386
|
+ unsigned int mod = 0;
|
|
387
|
+ for (; mod < getWorld().sizeSkeletalModel(); mod++) {
|
391
|
388
|
if (getWorld().getSkeletalModel(mod).getId() == moveable[index].object_id) {
|
392
|
389
|
cached = true;
|
393
|
390
|
break;
|
|
@@ -395,310 +392,14 @@ void Game::processMoveable(int index, int i, int object_id)
|
395
|
392
|
}
|
396
|
393
|
|
397
|
394
|
if (!cached) {
|
398
|
|
- getWorld().addSkeletalModel(*new SkeletalModel(mTombRaider, index));
|
399
|
|
- }
|
400
|
|
-
|
401
|
|
- getWorld().addEntity(*new Entity(mTombRaider, /* ... */ mod));
|
402
|
|
-
|
403
|
|
-
|
404
|
|
-
|
405
|
|
- // This creates both Entity and SkeletalModel
|
406
|
|
- // Basic Idea:
|
407
|
|
- // - Move animation state from SkeletalModel into Entity
|
408
|
|
- // - Check if skeletal model is already stored
|
409
|
|
- // - If so tell new Entity to reuse
|
410
|
|
- // - Else store new skeletal model, tell new entity to use this one
|
411
|
|
-
|
412
|
|
-
|
413
|
|
-
|
414
|
|
-
|
415
|
|
- int j, k, a, frame_step;
|
416
|
|
- unsigned int l, frame_offset, frame_count, f;
|
417
|
|
-
|
418
|
|
- unsigned short *frame = mTombRaider.Frame();
|
419
|
|
- tr2_moveable_t *moveable = mTombRaider.Moveable();
|
420
|
|
- tr2_meshtree_t *meshtree = mTombRaider.MeshTree();
|
421
|
|
- tr2_mesh_t *mesh = mTombRaider.Mesh();
|
422
|
|
- tr2_item_t *item = mTombRaider.Item();
|
423
|
|
- tr2_animation_t *animation = mTombRaider.Animation();
|
424
|
|
-
|
425
|
|
- float yaw = ((item[i].angle >> 14) & 0x03);
|
426
|
|
- yaw *= 90;
|
427
|
|
-
|
428
|
|
- entity_t *thing = new entity_t;
|
429
|
|
- thing->pos[0] = item[i].x;
|
430
|
|
- thing->pos[1] = item[i].y;
|
431
|
|
- thing->pos[2] = item[i].z;
|
432
|
|
- thing->angles[1] = yaw;
|
433
|
|
- thing->objectId = moveable[index].object_id;
|
434
|
|
-
|
435
|
|
- SkeletalModel *sModel = new SkeletalModel();
|
436
|
|
- getRender().addSkeletalModel(sModel);
|
437
|
|
- thing->tmpHook = sModel; // temp hack to keep a running version during refactoring
|
438
|
|
-
|
439
|
|
- if (mTombRaider.Engine() == TR_VERSION_1)
|
440
|
|
- {
|
441
|
|
- switch (thing->objectId)
|
442
|
|
- {
|
443
|
|
- case TombRaider1::Wolf:
|
444
|
|
- thing->state = TombRaider1::WolfState_Lying;
|
445
|
|
- sModel->setAnimation(3);
|
446
|
|
- sModel->setFrame(0);
|
447
|
|
- break;
|
448
|
|
- }
|
449
|
|
- }
|
450
|
|
-
|
451
|
|
- skeletal_model_t *r_model = new skeletal_model_t;
|
452
|
|
- r_model->id = moveable[index].object_id;
|
453
|
|
-
|
454
|
|
- // Gather more info if this is lara
|
455
|
|
- if (moveable[index].object_id == 0)
|
456
|
|
- {
|
457
|
|
- mLara = thing; // Mongoose 2002.03.22, Cheap hack for now
|
458
|
|
-
|
459
|
|
- sModel->setAnimation(TR_ANIAMTION_RUN);
|
460
|
|
- sModel->setIdleAnimation(TR_ANIAMTION_STAND);
|
461
|
|
-
|
462
|
|
- // Only TR4 lara has 2 layer bone tags/meshes per bone frame
|
463
|
|
- r_model->tr4Overlay = (mTombRaider.Engine() == TR_VERSION_4);
|
464
|
|
- r_model->ponytailId = 0;
|
465
|
|
- }
|
466
|
|
- else
|
467
|
|
- {
|
468
|
|
- r_model->ponytailId = -1;
|
469
|
|
- }
|
470
|
|
-
|
471
|
|
- // Animation
|
472
|
|
- a = moveable[index].animation;
|
473
|
|
-
|
474
|
|
- frame_offset = animation[a].frame_offset / 2;
|
475
|
|
- frame_step = animation[a].frame_size;
|
476
|
|
-
|
477
|
|
- if (a >= (int)mTombRaider.NumAnimations())
|
478
|
|
- {
|
479
|
|
- a = mTombRaider.NumFrames() - frame_offset;
|
480
|
|
- }
|
481
|
|
- else
|
482
|
|
- {
|
483
|
|
- a = (animation[a].frame_offset / 2) - frame_offset;
|
484
|
|
- }
|
485
|
|
-
|
486
|
|
- if (frame_step != 0) // prevent divide-by-zero errors
|
487
|
|
- a /= frame_step;
|
488
|
|
-
|
489
|
|
- if (a < 0)
|
490
|
|
- {
|
491
|
|
- //continue;
|
492
|
|
- getConsole().print("Invalid animation data for model %d", index);
|
493
|
|
- delete r_model;
|
494
|
|
- return; // leaking thing here!
|
495
|
|
- }
|
496
|
|
-
|
497
|
|
- //! \fixme Might be better UID for each model, but this seems to work well
|
498
|
|
- j = object_id;
|
499
|
|
-
|
500
|
|
- // We only want one copy of the skeletal model in memory
|
501
|
|
- unsigned int foundIndex;
|
502
|
|
- bool found = false;
|
503
|
|
- for (foundIndex = 0; foundIndex < cache.size(); foundIndex++) {
|
504
|
|
- if ((int)cache[foundIndex] == j) {
|
505
|
|
- found = true;
|
506
|
|
- break;
|
507
|
|
- }
|
|
395
|
+ getWorld().addSkeletalModel(*new SkeletalModel(mTombRaider, index, i));
|
508
|
396
|
}
|
509
|
|
- if (!found)
|
510
|
|
- {
|
511
|
|
- sModel->model = r_model;
|
512
|
|
- getWorld().addEntity(thing);
|
513
|
|
-
|
514
|
|
- k = getWorld().addModel(r_model);
|
515
|
|
-
|
516
|
|
- cache.push_back(j);
|
517
|
|
- cache2.push_back(r_model);
|
518
|
|
-
|
519
|
|
- switch (mTombRaider.Engine())
|
520
|
|
- {
|
521
|
|
- case TR_VERSION_4:
|
522
|
|
- if (mLara && moveable[index].object_id == 30)
|
523
|
|
- {
|
524
|
|
- r_model->ponytailId = k;
|
525
|
|
- r_model->ponytailMeshId = moveable[index].starting_mesh;
|
526
|
|
- r_model->ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
|
527
|
|
- moveable[index].num_meshes : 0);
|
528
|
|
- r_model->ponytailAngle = -90.0f;
|
529
|
|
- r_model->ponytail[0] = -3;
|
530
|
|
- r_model->ponytail[1] = -22;
|
531
|
|
- r_model->ponytail[2] = -20;
|
532
|
|
- r_model->ponyOff = 40;
|
533
|
|
- r_model->ponyOff2 = 32;
|
534
|
|
- r_model->pigtails = false;
|
535
|
|
-
|
536
|
|
- // Try to guess pigtails by looking for certian num verts in head
|
537
|
|
- if (mesh[moveable[0].starting_mesh].num_vertices > 80)
|
538
|
|
- {
|
539
|
|
- r_model->pigtails = true;
|
540
|
|
- r_model->ponyOff -= 20;
|
541
|
|
- r_model->ponytail[1] -= 32;
|
542
|
|
- }
|
543
|
|
-
|
544
|
|
- getRender().setFlags(Render::fRenderPonytail);
|
545
|
|
- getConsole().print("Found known ponytail");
|
546
|
|
- }
|
547
|
|
- break; // ?
|
548
|
|
- case TR_VERSION_1:
|
549
|
|
- case TR_VERSION_2:
|
550
|
|
- case TR_VERSION_3:
|
551
|
|
- case TR_VERSION_5:
|
552
|
|
- case TR_VERSION_UNKNOWN:
|
553
|
|
- if (mLara && moveable[index].object_id == 2)
|
554
|
|
- {
|
555
|
|
- r_model->ponytailId = k;
|
556
|
|
- r_model->ponytailMeshId = moveable[index].starting_mesh;
|
557
|
|
- r_model->ponytailNumMeshes = ((moveable[index].num_meshes > 0) ?
|
558
|
|
- moveable[index].num_meshes : 0);
|
559
|
|
- r_model->ponytailAngle = -90.0f;
|
560
|
|
- r_model->ponytail[0] = 0;
|
561
|
|
- r_model->ponytail[1] = -20;
|
562
|
|
- r_model->ponytail[2] = -20;
|
563
|
|
- r_model->ponyOff = 40;
|
564
|
|
- r_model->ponyOff2 = 0;
|
565
|
|
-
|
566
|
|
- getRender().setFlags(Render::fRenderPonytail);
|
567
|
|
- getConsole().print("Found ponytail?");
|
568
|
|
- }
|
569
|
|
- break;
|
570
|
|
- }
|
571
|
|
- }
|
572
|
|
- else
|
573
|
|
- {
|
574
|
|
- // Already cached
|
575
|
|
- delete r_model;
|
576
|
|
- r_model = cache2[foundIndex];
|
577
|
|
- sModel->model = r_model;
|
578
|
|
- getWorld().addEntity(thing);
|
579
|
|
- getWorld().addModel(r_model);
|
580
|
|
- printf("c");
|
581
|
|
- return;
|
582
|
|
- }
|
583
|
|
-
|
584
|
|
- //a = moveable[index].animation;
|
585
|
|
- //frame_offset = animation[a].frame_offset / 2;
|
586
|
|
- //frame_step = animation[a].frame_size;
|
587
|
|
-
|
588
|
|
- for (; a < mTombRaider.getNumAnimsForMoveable(index); a++) {
|
589
|
|
- frame_offset = animation[a].frame_offset / 2;
|
590
|
|
- frame_step = animation[a].frame_size;
|
591
|
|
-
|
592
|
|
- animation_frame_t *animation_frame = new animation_frame_t;
|
593
|
|
- r_model->animation.push_back(animation_frame);
|
594
|
397
|
|
595
|
|
- frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
|
596
|
|
- animation_frame->rate = animation[a].frame_rate;
|
|
398
|
+ getWorld().addEntity(*new Entity(mTombRaider, index, i, mod));
|
597
|
399
|
|
598
|
|
- // Get all the frames for aniamtion
|
599
|
|
- for (f = 0; f < frame_count; ++f, frame_offset += frame_step)
|
600
|
|
- {
|
601
|
|
- // HACK: Lara's ObjectID is 315, but her meshes start at 0, so make a
|
602
|
|
- // quick substitution (so she doesn't appear as a bunch of thighs)
|
603
|
|
- if (index == 0 && mTombRaider.Engine() == TR_VERSION_3)
|
604
|
|
- {
|
605
|
|
- for (j = 0; j < (int)mTombRaider.NumMoveables() && !index; ++j)
|
606
|
|
- {
|
607
|
|
- if (moveable[j].object_id == 315)
|
608
|
|
- index = j;
|
609
|
|
- }
|
610
|
|
- }
|
611
|
|
-
|
612
|
|
- // Fix Lara in TR4
|
613
|
|
- if (index == 0 && mTombRaider.Engine() == TR_VERSION_4)
|
614
|
|
- {
|
615
|
|
- for (j = 0; j < (int)mTombRaider.NumMoveables() && !index; ++j)
|
616
|
|
- {
|
617
|
|
- // Body is ItemID 8, joints are ItemID 9
|
618
|
|
- // (TR4 demo: body is ItemID 10, joints are ItemID 11)
|
619
|
|
- if (moveable[j].object_id == 8)
|
620
|
|
- index = j;
|
621
|
|
- }
|
622
|
|
- }
|
623
|
|
- else if (moveable[index].object_id == 8 &&
|
624
|
|
- mTombRaider.Engine() == TR_VERSION_4)
|
625
|
|
- {
|
626
|
|
- // KLUDGE to do "skinning"
|
627
|
|
- index = 0;
|
628
|
|
-
|
629
|
|
- for (j = 0; j < (int)mTombRaider.NumMoveables() && !index; ++j)
|
630
|
|
- {
|
631
|
|
- // Body is ItemID 8, joints are ItemID 9
|
632
|
|
- // (TR4 demo: body is ItemID 10, joints are ItemID 11)
|
633
|
|
- if (moveable[j].object_id == 9)
|
634
|
|
- index = j;
|
635
|
|
- }
|
636
|
|
- }
|
637
|
|
-
|
638
|
|
- // Mongoose 2002.08.15, Was
|
639
|
|
- // if (frame_offset + 8 > _tombraider.NumFrames())
|
640
|
|
- if (frame_offset > mTombRaider.NumFrames())
|
641
|
|
- {
|
642
|
|
- getConsole().print("WARNING: Bad animation frame %i > %i",
|
643
|
|
- frame_offset, mTombRaider.NumFrames());
|
644
|
|
- return; //continue;
|
645
|
|
- }
|
646
|
|
-
|
647
|
|
- // Generate bone frames and tags per frame ////////////
|
648
|
|
- bone_frame_t *bone = new bone_frame_t;
|
649
|
|
- animation_frame->frame.push_back(bone);
|
650
|
|
-
|
651
|
|
- // Init translate for bone frame
|
652
|
|
- bone->pos[0] = (short)frame[frame_offset + 6];
|
653
|
|
- bone->pos[1] = (short)frame[frame_offset + 7];
|
654
|
|
- bone->pos[2] = (short)frame[frame_offset + 8];
|
655
|
|
- bone->yaw = yaw;
|
656
|
|
-
|
657
|
|
- //printf("%f %f %f\n", bone->pos[0], bone->pos[1], bone->pos[2]);
|
658
|
|
-
|
659
|
|
- l = 9; // First angle offset in this Frame
|
660
|
|
-
|
661
|
|
- // Run through the tag and calculate the rotation and offset
|
662
|
|
- for (j = 0; j < (int)moveable[index].num_meshes; ++j)
|
663
|
|
- {
|
664
|
|
- bone_tag_t *tag = new bone_tag_t;
|
665
|
|
- bone->tag.push_back(tag);
|
666
|
|
- tag->off[0] = 0.0;
|
667
|
|
- tag->off[1] = 0.0;
|
668
|
|
- tag->off[2] = 0.0;
|
669
|
|
- tag->flag = 0x00;
|
670
|
|
- tag->rot[0] = 0.0;
|
671
|
|
- tag->rot[1] = 0.0;
|
672
|
|
- tag->rot[2] = 0.0;
|
673
|
|
- tag->mesh = moveable[index].starting_mesh + j;
|
674
|
|
-
|
675
|
|
- // Setup offsets to produce skeletion
|
676
|
|
- if (j == 0)
|
677
|
|
- {
|
678
|
|
- // Always push tag[0], this isn't really used either
|
679
|
|
- tag->flag = 0x02;
|
680
|
|
- }
|
681
|
|
- else // Nonprimary tag - position relative to first tag
|
682
|
|
- {
|
683
|
|
- int *tree;
|
684
|
|
- // Hack: moveable[index].mesh_tree is a byte offset
|
685
|
|
- // into mesh_tree[], so we have to convert to index
|
686
|
|
- tree = (int *)(void *)meshtree;
|
687
|
|
- tr2_meshtree_t *mesh_tree = (tr2_meshtree_t *)&tree[moveable[index].mesh_tree
|
688
|
|
- + ((j - 1) * 4)];
|
689
|
|
-
|
690
|
|
- tag->off[0] = mesh_tree->x;
|
691
|
|
- tag->off[1] = mesh_tree->y;
|
692
|
|
- tag->off[2] = mesh_tree->z;
|
693
|
|
- tag->flag = (char)mesh_tree->flags;
|
694
|
|
- }
|
695
|
|
-
|
696
|
|
- // Setup tag rotations
|
697
|
|
- mTombRaider.computeRotationAngles(&frame, &frame_offset, &l,
|
698
|
|
- tag->rot, tag->rot+1, tag->rot+2);
|
699
|
|
- }
|
700
|
|
- }
|
701
|
|
- }
|
|
400
|
+ // Store reference to Lara
|
|
401
|
+ if (getWorld().getEntity(getWorld().sizeEntity() - 1).getObjectId() == 0)
|
|
402
|
+ mLara = getWorld().sizeEntity() - 1;
|
702
|
403
|
|
703
|
404
|
if (i == mTombRaider.getSkyModelId())
|
704
|
405
|
getRender().setSkyMesh(i, //moveable[i].starting_mesh,
|