Bläddra i källkod

Fixed SkeletalModel animation creation

Thomas Buck 10 år sedan
förälder
incheckning
e59892542e
4 ändrade filer med 20 tillägg och 18 borttagningar
  1. 3
    0
      ChangeLog.md
  2. 2
    8
      TODO.md
  3. 1
    1
      include/SkeletalModel.h
  4. 14
    9
      src/SkeletalModel.cpp

+ 3
- 0
ChangeLog.md Visa fil

@@ -2,6 +2,9 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140617 ]
6
+    * Finally fixed SkeletalModel bug introduced a month ago
7
+
5 8
     [ 20140615 ]
6 9
     * Added FontManager, selecting Font library to use depending on
7 10
       the file extension of the font file specified in the config.

+ 2
- 8
TODO.md Visa fil

@@ -2,23 +2,17 @@
2 2
 
3 3
 ## General
4 4
 
5
-There are these DebugModel, DebugMap flags...?
6
-
7 5
 * Endian dependence ugly, shouldn't dereference to different types?
8 6
     * TombRaider.h/cpp structs aren't aligned... unportable to some big endian & other archs?!
9 7
 * Use more asserts
10 8
 * Don't use C-Style code, try to replace with C++ lib
11
-    * Use shared_ptr, should make memory handling/segfaults much less of a problem
12
-        * Don't even new ... the data structures but use std::make_shared or allocate_shared?
13
-        * Pass object references to all other objects that need it, completely remove gOpenRaider
14 9
     * Use std::strings
15
-    * Rewrite Console and use operator << to write to the console
10
+    * Rewrite Console and use operator << to write to the console?
16 11
 * SDL_TTF 2.0.12+ can do line breaks, use it: http://stackoverflow.com/questions/17847818/how-to-do-line-breaks-and-line-wrapping-with-sdl-ttf/18418688#18418688
17 12
 
18 13
 ## Changes
19 14
 
20 15
 * Using std::vector with [] is not bound checked. Segfaults were caused because the upper bound of the argument was never checked and garbage was returned... Do consistent checks, or use .at() as it throws an exception
21
-* The wrong SkeletalModels are used by entities, except for Lara...?
22 16
 
23 17
 ## Cmake
24 18
 
@@ -28,7 +22,7 @@ There are these DebugModel, DebugMap flags...?
28 22
 
29 23
 ## Future Features
30 24
 
31
-* Use only assets from old TR games, not even depending on a font file?
32 25
 * Cut TGA image reader, currently only used for menu background?!
26
+    * Abstract image reading/writing, like Font Engine selection
33 27
 * When cutscene rendering is working, use TR4/5 style menu?
34 28
 

+ 1
- 1
include/SkeletalModel.h Visa fil

@@ -47,7 +47,7 @@ private:
47 47
 
48 48
 class AnimationFrame {
49 49
 public:
50
-    AnimationFrame(TombRaider &tr, unsigned int index, int a);
50
+    AnimationFrame(TombRaider &tr, unsigned int index, int a, unsigned int *frame_offset, int frame_step);
51 51
     ~AnimationFrame();
52 52
 
53 53
     unsigned int size();

+ 14
- 9
src/SkeletalModel.cpp Visa fil

@@ -102,16 +102,14 @@ void BoneFrame::getPosition(vec3_t p) {
102 102
     p[2] = pos[2];
103 103
 }
104 104
 
105
-AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, int a) {
105
+AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, int a, unsigned int *frame_offset, int frame_step) {
106 106
     tr2_moveable_t *moveable = tr.Moveable();
107 107
     tr2_animation_t *animation = tr.Animation();
108 108
 
109
-    unsigned int frame_offset = animation[a].frame_offset / 2;
110
-    int frame_step = animation[a].frame_size;
111 109
     unsigned int frame_count = (animation[a].frame_end - animation[a].frame_start) + 1;
112 110
     rate = animation[a].frame_rate;
113 111
 
114
-    for (unsigned int f = 0; f < frame_count; f++, frame_offset += frame_step) {
112
+    for (unsigned int f = 0; f < frame_count; f++, *frame_offset += frame_step) {
115 113
         // HACK: Lara's ObjectID is 315, but her meshes start at 0, so make a
116 114
         // quick substitution (so she doesn't appear as a bunch of thighs)
117 115
         if ((index == 0) && (tr.Engine() == TR_VERSION_3)) {
@@ -138,13 +136,13 @@ AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, int a) {
138 136
             }
139 137
         }
140 138
 
141
-        if (frame_offset > tr.NumFrames()) {
139
+        if (*frame_offset > tr.NumFrames()) {
142 140
             getConsole().print("WARNING: Bad animation frame %i > %i (%u.%d)",
143
-                    frame_offset, tr.NumFrames(), index, a);
141
+                    *frame_offset, tr.NumFrames(), index, a);
144 142
             return;
145 143
         }
146 144
 
147
-        frame.push_back(new BoneFrame(tr, index, frame_offset));
145
+        frame.push_back(new BoneFrame(tr, index, *frame_offset));
148 146
     }
149 147
 }
150 148
 
@@ -234,20 +232,27 @@ SkeletalModel::SkeletalModel(TombRaider &tr, unsigned int index, int objectId) {
234 232
     unsigned int frame_offset = anim[a].frame_offset / 2;
235 233
     int frame_step = anim[a].frame_size;
236 234
 
235
+    int frame_cycle = 0;
236
+
237 237
     if (a >= (int)tr.NumAnimations())
238 238
         a = tr.NumFrames() - frame_offset; //! \fixme Couldn't a be already used out of range?!
239 239
     else
240
-        a = (anim[a].frame_offset / 2) - frame_offset;
240
+        a = (anim[a].frame_offset / 2) - frame_offset; //! \fixme Same as a = 0; ??
241 241
 
242 242
     if (frame_step != 0) // prevent divide-by-zero errors
243 243
         a /= frame_step;
244 244
 
245
+    if (a != 0)
246
+        frame_offset += frame_step * (frame_cycle % a);
247
+
245 248
     if (a < 0) {
246 249
         getConsole().print("Invalid animation data for model %d. Skip!", index);
247 250
         return;
248 251
     } else {
249 252
         for (; a < tr.getNumAnimsForMoveable(index); a++) {
250
-            animation.push_back(new AnimationFrame(tr, index, a));
253
+            animation.push_back(new AnimationFrame(tr, index, a, &frame_offset, frame_step));
254
+            frame_offset = anim[a].frame_offset / 2;
255
+            frame_step = anim[a].frame_size;
251 256
         }
252 257
     }
253 258
 }

Laddar…
Avbryt
Spara