Browse Source

Fixed more cppcheck warnings

Thomas Buck 10 years ago
parent
commit
497f6a692b
16 changed files with 142 additions and 96 deletions
  1. 17
    4
      Makefile
  2. 4
    4
      include/List.h
  3. 1
    1
      include/Map.h
  4. 1
    1
      include/Quaternion.h
  5. 7
    4
      include/Tree.h
  6. 3
    0
      include/Vector.h
  7. 4
    4
      include/Vector3d.h
  8. 2
    1
      src/Emitter.cpp
  9. 1
    2
      src/MatMath.cpp
  10. 56
    19
      src/Network.cpp
  11. 8
    8
      src/OpenRaider.cpp
  12. 2
    3
      src/Quaternion.cpp
  13. 21
    18
      src/Render.cpp
  14. 3
    19
      src/TombRaider.cpp
  15. 8
    4
      src/Vector3d.cpp
  16. 4
    4
      test/TombRaider.cpp

+ 17
- 4
Makefile View File

205
 
205
 
206
 #################################################################
206
 #################################################################
207
 
207
 
208
+CHECK_INC=-Iinclude
209
+#CHECK_INC+=$(GL_DEFS) $(AUDIO_DEFS)
210
+#ifeq ($(UNAME),Darwin)
211
+#SDK_ROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
212
+#CHECK_INC+=-I$(SDK_ROOT)/usr/include
213
+#CHECK_INC+=-I$(SDK_ROOT)/usr/include/malloc
214
+#CHECK_INC+=-I$(SDK_ROOT)/usr/include/machine
215
+#CHECK_INC+=-I$(SDK_ROOT)/usr/include/c++/4.2.1
216
+#CHECK_INC+=-I$(SDK_ROOT)/usr/include/c++/4.2.1/tr1
217
+#CHECK_INC+=-I$(SDK_ROOT)/usr/include/c++/4.2.1/backward
218
+#endif
219
+
208
 check:
220
 check:
209
-	cppcheck -Iinclude $(GL_DEFS) $(AUDIO_DEFS) --enable=information .
221
+	cppcheck --quiet $(CHECK_INC) --force \
222
+		--enable=information,warning,performance,portability .
210
 
223
 
211
-fullCheck:
212
-	cppcheck -Iinclude $(GL_DEFS) $(AUDIO_DEFS) --enable=all --inconclusive --std=posix .
224
+checkFull:
225
+	cppcheck --quiet $(CHECK_INC) --enable=all --std=posix --force .
213
 
226
 
214
 #################################################################
227
 #################################################################
215
 
228
 
216
 clean: clean-small clean-dep clean-doc
229
 clean: clean-small clean-dep clean-doc
217
 
230
 
218
-clean-small: clean-build clean-test clean-obj 
231
+clean-small: clean-build clean-test clean-obj
219
 	@-rm -rf bin/OpenRaider.app
232
 	@-rm -rf bin/OpenRaider.app
220
 	@-rm -rf bin/OpenRaider.dmg
233
 	@-rm -rf bin/OpenRaider.dmg
221
 	@-rm -rf bin/OpenRaider.zip
234
 	@-rm -rf bin/OpenRaider.zip

+ 4
- 4
include/List.h View File

95
      * \brief Print this ListNode
95
      * \brief Print this ListNode
96
      */
96
      */
97
     void Print() {
97
     void Print() {
98
-        printf("(%i, %p)",  _id, _data);
98
+        printf("(%u, %p)",  _id, _data);
99
     }
99
     }
100
 
100
 
101
 private:
101
 private:
216
             return SearchId(i);
216
             return SearchId(i);
217
         } else {
217
         } else {
218
 #ifdef DEBUG_INDEX_EMPTY_LIST
218
 #ifdef DEBUG_INDEX_EMPTY_LIST
219
-            printf("List[%i] = NULL\n", i);
219
+            printf("List[%u] = NULL\n", i);
220
 #endif
220
 #endif
221
         }
221
         }
222
         return 0;
222
         return 0;
296
      */
296
      */
297
     void Print(void (*print_func)(T)) {
297
     void Print(void (*print_func)(T)) {
298
         ListNode<T> *current = _head;
298
         ListNode<T> *current = _head;
299
-        printf(" [%i] {\n", _num_items);
299
+        printf(" [%u] {\n", _num_items);
300
         while (current) {
300
         while (current) {
301
             printf("#%i, ", current->Id());
301
             printf("#%i, ", current->Id());
302
             if (print_func)
302
             if (print_func)
312
      */
312
      */
313
     void Print() {
313
     void Print() {
314
         ListNode<T> *current = _head;
314
         ListNode<T> *current = _head;
315
-        printf("List %i {\n", _num_items);
315
+        printf("List %u {\n", _num_items);
316
         while (current) {
316
         while (current) {
317
             //current->Print();
317
             //current->Print();
318
             printf("%i", current->Id());
318
             printf("%i", current->Id());

+ 1
- 1
include/Map.h View File

466
             return;
466
             return;
467
         }
467
         }
468
 
468
 
469
-        printf(" [%i] {\n", _num_items);
469
+        printf(" [%u] {\n", _num_items);
470
 
470
 
471
         while (current) {
471
         while (current) {
472
             printf("(");
472
             printf("(");

+ 1
- 1
include/Quaternion.h View File

97
      * Mongoose - Created
97
      * Mongoose - Created
98
      ------------------------------------------------------*/
98
      ------------------------------------------------------*/
99
 
99
 
100
-    Quaternion operator =(const Quaternion &q);
100
+    Quaternion &operator =(const Quaternion &q);
101
     /*------------------------------------------------------
101
     /*------------------------------------------------------
102
      * Pre  :
102
      * Pre  :
103
      * Post : Asigns Q to this quaternion
103
      * Post : Asigns Q to this quaternion

+ 7
- 4
include/Tree.h View File

456
      * \sa Tree::Remove()
456
      * \sa Tree::Remove()
457
      */
457
      */
458
     bool RemoveByData(Data data) {
458
     bool RemoveByData(Data data) {
459
-        bool error;
459
+        bool error = true;
460
         if (_root)
460
         if (_root)
461
             Remove(_root->SearchByData(data, &error));
461
             Remove(_root->SearchByData(data, &error));
462
         return error;
462
         return error;
470
      * \sa Tree::Remove()
470
      * \sa Tree::Remove()
471
      */
471
      */
472
     bool RemoveByKey(Key key) {
472
     bool RemoveByKey(Key key) {
473
-        bool error;
473
+        bool error = true;
474
         if (_root) {
474
         if (_root) {
475
 #ifdef OBSOLETE
475
 #ifdef OBSOLETE
476
             // Mongoose 2002.02.18, To remove duplicates
476
             // Mongoose 2002.02.18, To remove duplicates
477
-            erorr = false;
477
+            error = false;
478
             while (!error) {
478
             while (!error) {
479
 #endif
479
 #endif
480
                 Remove(_root->SearchByKey(key, &error));
480
                 Remove(_root->SearchByKey(key, &error));
623
      * \sa TreeNode::PrintInorderSpecial()
623
      * \sa TreeNode::PrintInorderSpecial()
624
      */
624
      */
625
     void PrintSpecial(void (*print_func_k)(Key), void (*print_func_d)(Data)) {
625
     void PrintSpecial(void (*print_func_k)(Key), void (*print_func_d)(Data)) {
626
-        printf("Tree: %i elements {\n", _num_elements);
626
+        printf("Tree: %u elements {\n", _num_elements);
627
         if (_root && print_func_k && print_func_d) {
627
         if (_root && print_func_k && print_func_d) {
628
             printf("Root: ");
628
             printf("Root: ");
629
             _root->PrintNodeSpecial(print_func_k, print_func_d);
629
             _root->PrintNodeSpecial(print_func_k, print_func_d);
954
             prev = GetSuccessor(tree);
954
             prev = GetSuccessor(tree);
955
         }
955
         }
956
 
956
 
957
+        if (!prev)
958
+            return; // Probably a good idea, as there's a check if(prev) later
959
+
957
         if (prev->GetLeft())
960
         if (prev->GetLeft())
958
         {
961
         {
959
             cur = prev->GetLeft();
962
             cur = prev->GetLeft();

+ 3
- 0
include/Vector.h View File

44
         mReserve = 0;
44
         mReserve = 0;
45
         mStart = 0;
45
         mStart = 0;
46
         mEnd = 0;
46
         mEnd = 0;
47
+        mIndex = 0;
47
         copy(vector);
48
         copy(vector);
48
     }
49
     }
49
 
50
 
201
         }
202
         }
202
         mStart = vector.begin();
203
         mStart = vector.begin();
203
         mEnd = vector.end();
204
         mEnd = vector.end();
205
+        mError = vector.Error();
206
+        mIndex = vector.getCurrentIndex();
204
         for (i = vector.begin(); i < vector.end(); ++i) {
207
         for (i = vector.begin(); i < vector.end(); ++i) {
205
             mData[i] = vector[i];
208
             mData[i] = vector[i];
206
         }
209
         }

+ 4
- 4
include/Vector3d.h View File

235
      * Mongoose - Created
235
      * Mongoose - Created
236
      ------------------------------------------------------*/
236
      ------------------------------------------------------*/
237
 
237
 
238
-    void operator =(const Vector3d &v);
238
+    Vector3d &operator =(const Vector3d &v);
239
     /*------------------------------------------------------
239
     /*------------------------------------------------------
240
      * Pre  :
240
      * Pre  :
241
      * Post : this = v, values are assigned   =)
241
      * Post : this = v, values are assigned   =)
246
      * Mongoose - Created
246
      * Mongoose - Created
247
      ------------------------------------------------------*/
247
      ------------------------------------------------------*/
248
 
248
 
249
-    void operator +=(const Vector3d &v);
249
+    Vector3d &operator +=(const Vector3d &v);
250
     /*------------------------------------------------------
250
     /*------------------------------------------------------
251
      * Pre  :
251
      * Pre  :
252
      * Post : this += v, values are sumed, assigned   =)
252
      * Post : this += v, values are sumed, assigned   =)
257
      * Mongoose - Created
257
      * Mongoose - Created
258
      ------------------------------------------------------*/
258
      ------------------------------------------------------*/
259
 
259
 
260
-    void operator -=(const Vector3d &v);
260
+    Vector3d &operator -=(const Vector3d &v);
261
     /*------------------------------------------------------
261
     /*------------------------------------------------------
262
      * Pre  :
262
      * Pre  :
263
      * Post : this -= v, values are diffed, assigned   =)
263
      * Post : this -= v, values are diffed, assigned   =)
268
      * Mongoose - Created
268
      * Mongoose - Created
269
      ------------------------------------------------------*/
269
      ------------------------------------------------------*/
270
 
270
 
271
-    void operator *=(vec_t s);
271
+    Vector3d &operator *=(vec_t s);
272
     /*------------------------------------------------------
272
     /*------------------------------------------------------
273
      * Pre  :
273
      * Pre  :
274
      * Post : this *= s, values are scaled, assigned   =)
274
      * Post : this *= s, values are scaled, assigned   =)

+ 2
- 1
src/Emitter.cpp View File

25
 vec_t Emitter::mFrustum[6][4];
25
 vec_t Emitter::mFrustum[6][4];
26
 
26
 
27
 int Emitter::compareParticleDist(const void *voidA, const void *voidB) {
27
 int Emitter::compareParticleDist(const void *voidA, const void *voidB) {
28
-    Particle *a = (Particle *)voidA, *b = (Particle *)voidB;
28
+    Particle *a = const_cast<Particle *>(static_cast<const Particle *>(voidA));
29
+    Particle *b = const_cast<Particle *>(static_cast<const Particle *>(voidB));
29
     float x, y, z, distA, distB;
30
     float x, y, z, distA, distB;
30
 
31
 
31
     if (!a || !b)
32
     if (!a || !b)

+ 1
- 2
src/MatMath.cpp View File

111
     //  vec3_t normal, a, b;
111
     //  vec3_t normal, a, b;
112
     Vector3d a, b, normal, pA, pB;
112
     Vector3d a, b, normal, pA, pB;
113
     vec_t d, denominator, mu;
113
     vec_t d, denominator, mu;
114
-    double theta;
115
 
114
 
116
 
115
 
117
     pA = Vector3d(p1);
116
     pA = Vector3d(p1);
184
 #else // assume convex polygons here for sure
183
 #else // assume convex polygons here for sure
185
     //mtkVectorSubtract(intersect, polygon[0], a);
184
     //mtkVectorSubtract(intersect, polygon[0], a);
186
     //theta = mtkVectorDotProduct(a, normal);
185
     //theta = mtkVectorDotProduct(a, normal);
187
-    theta = Vector3d::dot(b - Vector3d(polygon[0]), normal); // b = intersect
186
+    double theta = Vector3d::dot(b - Vector3d(polygon[0]), normal); // b = intersect
188
 
187
 
189
     if (theta >= 90.0) // Yeah I know
188
     if (theta >= 90.0) // Yeah I know
190
         return 0;
189
         return 0;

+ 56
- 19
src/Network.cpp View File

166
 
166
 
167
 void Network::setBindHost(char *s)
167
 void Network::setBindHost(char *s)
168
 {
168
 {
169
-    if (!s && !s[0])
169
+    if (!s || !s[0])
170
         return;
170
         return;
171
 
171
 
172
     strncpy(mBindHost, s, BIND_HOST_STR_SZ);
172
     strncpy(mBindHost, s, BIND_HOST_STR_SZ);
175
 
175
 
176
 void Network::setRemoteHost(char *s)
176
 void Network::setRemoteHost(char *s)
177
 {
177
 {
178
-    if (!s && !s[0])
178
+    if (!s || !s[0])
179
         return;
179
         return;
180
 
180
 
181
     strncpy(mRemoteHost, s, REMOTE_HOST_STR_SZ);
181
     strncpy(mRemoteHost, s, REMOTE_HOST_STR_SZ);
295
     memset(&s_in, 0, sizeof(s_in));
295
     memset(&s_in, 0, sizeof(s_in));
296
     s_in.sin_family = AF_INET;
296
     s_in.sin_family = AF_INET;
297
 #ifdef LOCAL_BCAST
297
 #ifdef LOCAL_BCAST
298
-    struct hostent *hostptr;
299
-
300
-    if ((hostptr = gethostbyname(hostid)) == NULL)
301
-    {
302
-        fprintf(stderr, "Server: recv_udp, Invalid host name '%s'\n", hostid);
298
+    // Replace deprecated gethostbyname() with getaddrinfo()
299
+    //struct hostent *hostptr;
300
+    //if ((hostptr = gethostbyname(hostid)) == NULL)
301
+    //{
302
+    //    fprintf(stderr, "Server: recv_udp, Invalid host name '%s'\n", hostid);
303
+    //    return -1;
304
+    //}
305
+    //memcpy((void *)(&s_in.sin_addr), hostptr->h_addr, hostptr->h_length);
306
+    struct addrinfo *result, *res;
307
+    bool found = false;
308
+    int error = getaddrinfo(hostid, NULL, NULL, &result);
309
+    if (error != 0) {
310
+        fprintf(stderr, "Server: %s\n", gai_strerror(error));
311
+        return -1;
312
+    }
313
+    for (res = result; res != NULL; res = res->ai_next) {
314
+        if (res->ss_family == AF_INET) {
315
+            found = true;
316
+            memcpy((void *)&s_in, res->ai_addr, res->ai_addrlen);
317
+            break; // Found something suitable
318
+        }
319
+    }
320
+    freeaddrinfo(result);
321
+    if (!found) {
322
+        fprintf(stderr, "Server: Can't bind to %s\n", hostid);
303
         return -1;
323
         return -1;
304
     }
324
     }
305
-
306
-    memcpy((void *)(&s_in.sin_addr), hostptr->h_addr, hostptr->h_length);
307
 #else
325
 #else
308
     s_in.sin_addr.s_addr = htonl(INADDR_ANY);
326
     s_in.sin_addr.s_addr = htonl(INADDR_ANY);
309
 #endif
327
 #endif
348
         if (mDebug)
366
         if (mDebug)
349
         {
367
         {
350
             printf("=====================================================\n");
368
             printf("=====================================================\n");
351
-            printf("Packet %i\n", packetsRecieved);
369
+            printf("Packet %u\n", packetsRecieved);
352
             printf("Server: Recieved packet from %u\n",
370
             printf("Server: Recieved packet from %u\n",
353
                     f.uid);
371
                     f.uid);
354
         }
372
         }
374
                     gClients[i].frameExpected = 0;
392
                     gClients[i].frameExpected = 0;
375
                     ++gNumClients;
393
                     ++gNumClients;
376
 
394
 
377
-                    printf("Server: %u made connection, as client %i\n",
395
+                    printf("Server: %u made connection, as client %u\n",
378
                             gClients[i].uid, i);
396
                             gClients[i].uid, i);
379
                     break;
397
                     break;
380
                 }
398
                 }
491
     unsigned int fsize, last_frame_sent = 0;
509
     unsigned int fsize, last_frame_sent = 0;
492
     int socket_fd, cc, done;
510
     int socket_fd, cc, done;
493
     struct sockaddr_in dest;
511
     struct sockaddr_in dest;
494
-    struct hostent *hostptr;
512
+    struct addrinfo *addr;
495
     network_frame_t f;
513
     network_frame_t f;
496
     struct timeval timeout;
514
     struct timeval timeout;
497
-    fd_set  readfds;
515
+    fd_set readfds;
498
     unsigned int packetsSent = 0;
516
     unsigned int packetsSent = 0;
499
     unsigned int seq = 0;
517
     unsigned int seq = 0;
500
     char timedOut = 1;
518
     char timedOut = 1;
515
         exit(0);
533
         exit(0);
516
     }
534
     }
517
 
535
 
518
-    if ((hostptr = gethostbyname(mRemoteHost)) == NULL)
519
-    {
520
-        fprintf(stderr, "Client: send_udp: invalid host name, %s\n",
521
-                mRemoteHost);
536
+    //if ((hostptr = gethostbyname(mRemoteHost)) == NULL)
537
+    //{
538
+    //    fprintf(stderr, "Client: send_udp: invalid host name, %s\n",
539
+    //            mRemoteHost);
540
+    //    exit(0);
541
+    //}
542
+
543
+    int error = getaddrinfo(mRemoteHost, NULL, NULL, &addr);
544
+    if (error != 0) {
545
+        fprintf(stderr, "Client: %s\n", gai_strerror(error));
522
         exit(0);
546
         exit(0);
523
     }
547
     }
524
 
548
 
528
     int port = getPort();
552
     int port = getPort();
529
     dest.sin_port = htons(port);
553
     dest.sin_port = htons(port);
530
 #ifdef LOCAL_BCAST
554
 #ifdef LOCAL_BCAST
531
-    memcpy(hostptr->h_addr, (char *) &dest.sin_addr, hostptr->h_length);
555
+    //memcpy(hostptr->h_addr, (char *) &dest.sin_addr, hostptr->h_length);
556
+    bool found = false;
557
+    for (struct addrinfo *res = addr; res != NULL; res = res->ai_next) {
558
+        if (res->ss_family == AF_INET) {
559
+            found = true;
560
+            memcpy((void *)&dest.sin_addr, res->ai_addr.sin_addr, sizeof(res->ai_addr.sin_addr));
561
+            break; // Found something suitable
562
+        }
563
+    }
564
+    freeaddrinfo(addr);
565
+    if (!found) {
566
+        fprintf(stderr, "Client: Can't connect to %s\n", hostid);
567
+        return;
568
+    }
532
 #else
569
 #else
533
     if (inet_pton(AF_INET, mRemoteHost, &dest.sin_addr) < 0)
570
     if (inet_pton(AF_INET, mRemoteHost, &dest.sin_addr) < 0)
534
     {
571
     {
549
         if (mDebug)
586
         if (mDebug)
550
         {
587
         {
551
             printf("=====================================================\n");
588
             printf("=====================================================\n");
552
-            printf("Packet %i\n", packetsSent);
589
+            printf("Packet %u\n", packetsSent);
553
         }
590
         }
554
 
591
 
555
         // 1. Get packet to send over wire
592
         // 1. Get packet to send over wire

+ 8
- 8
src/OpenRaider.cpp View File

191
 {
191
 {
192
     if (LARA)
192
     if (LARA)
193
     {
193
     {
194
-        SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
194
+        SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
195
 
195
 
196
         if (mdl)
196
         if (mdl)
197
         {
197
         {
252
         p->pitch = LARA->angles[1];
252
         p->pitch = LARA->angles[1];
253
         p->view_model = LARA->modelId;
253
         p->view_model = LARA->modelId;
254
 
254
 
255
-        SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
255
+        SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
256
 
256
 
257
         if (mdl)
257
         if (mdl)
258
         {
258
         {
329
         gPiggyBack.data.pitch = LARA->angles[2];
329
         gPiggyBack.data.pitch = LARA->angles[2];
330
         gPiggyBack.data.view_model = LARA->modelId;
330
         gPiggyBack.data.view_model = LARA->modelId;
331
 
331
 
332
-        SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
332
+        SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
333
 
333
 
334
         if (mdl)
334
         if (mdl)
335
         {
335
         {
769
         case '[':
769
         case '[':
770
             if (LARA)
770
             if (LARA)
771
             {
771
             {
772
-                SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
772
+                SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
773
 
773
 
774
                 if (mdl)
774
                 if (mdl)
775
                 {
775
                 {
782
         case ']':
782
         case ']':
783
             if (LARA)
783
             if (LARA)
784
             {
784
             {
785
-                SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
785
+                SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
786
 
786
 
787
                 if (mdl)
787
                 if (mdl)
788
                 {
788
                 {
1199
         default:
1199
         default:
1200
             if (LARA)
1200
             if (LARA)
1201
             {
1201
             {
1202
-                mdl = (SkeletalModel *)LARA->tmpHook;
1202
+                mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
1203
 
1203
 
1204
                 if (mdl)
1204
                 if (mdl)
1205
                 {
1205
                 {
3099
     {
3099
     {
3100
         if (LARA)
3100
         if (LARA)
3101
         {
3101
         {
3102
-            SkeletalModel *smdl = (SkeletalModel *)LARA->tmpHook;
3102
+            SkeletalModel *smdl = static_cast<SkeletalModel *>(LARA->tmpHook);
3103
             skeletal_model_t *mdl = gWorld.getModel(atoi(cmd));
3103
             skeletal_model_t *mdl = gWorld.getModel(atoi(cmd));
3104
 
3104
 
3105
             if (smdl)
3105
             if (smdl)
3182
     {
3182
     {
3183
         if (atoi(cmd))
3183
         if (atoi(cmd))
3184
         {
3184
         {
3185
-            m_render.clearFlags(Render::fUsePortals);
3185
+            m_render.setFlags(Render::fUsePortals);
3186
         }
3186
         }
3187
         else
3187
         else
3188
         {
3188
         {

+ 2
- 3
src/Quaternion.cpp View File

88
 }
88
 }
89
 
89
 
90
 
90
 
91
-Quaternion Quaternion::operator =(const Quaternion &q)
91
+Quaternion &Quaternion::operator =(const Quaternion &q)
92
 {
92
 {
93
     mW  = q.mW;
93
     mW  = q.mW;
94
     mX = q.mX;
94
     mX = q.mX;
95
     mY = q.mY;
95
     mY = q.mY;
96
     mZ = q.mZ;
96
     mZ = q.mZ;
97
-
98
-    return (*this);
97
+    return *this;
99
 }
98
 }
100
 
99
 
101
 
100
 

+ 21
- 18
src/Render.cpp View File

112
 
112
 
113
 int compareRoomDist(const void *voidA, const void *voidB)
113
 int compareRoomDist(const void *voidA, const void *voidB)
114
 {
114
 {
115
-    RenderRoom *a = (RenderRoom *)voidA, *b = (RenderRoom *)voidB;
115
+    const RenderRoom *a = static_cast<const RenderRoom *>(voidA);
116
+    const RenderRoom *b = static_cast<const RenderRoom *>(voidB);
116
 
117
 
117
 
118
 
118
     if (!a || !b || !a->room || !b->room)
119
     if (!a || !b || !a->room || !b->room)
329
         unsigned int snowTex1, unsigned int snowTex2)
330
         unsigned int snowTex1, unsigned int snowTex2)
330
 {
331
 {
331
 #ifdef USING_EMITTER
332
 #ifdef USING_EMITTER
333
+    if (mEmitter)
334
+        delete mEmitter; // Public, so avoid possible leak
335
+
332
     // Mongoose 2002.01.01, Screwing around with particle emitter test
336
     // Mongoose 2002.01.01, Screwing around with particle emitter test
333
     //   note this is backwards b/c load screen is rendered upsidedown
337
     //   note this is backwards b/c load screen is rendered upsidedown
334
     //mEmitter = new Emitter(/*name*/"snow", size);
338
     //mEmitter = new Emitter(/*name*/"snow", size);
929
             // Mongoose 2002.12.24, Some entities have no animation  =p
933
             // Mongoose 2002.12.24, Some entities have no animation  =p
930
             if (e->tmpHook)
934
             if (e->tmpHook)
931
             {
935
             {
932
-                SkeletalModel *mdl = (SkeletalModel *)e->tmpHook;
936
+                SkeletalModel *mdl = static_cast<SkeletalModel *>(e->tmpHook);
933
 
937
 
934
                 if (mdl->model->animation.empty())
938
                 if (mdl->model->animation.empty())
935
                     continue;
939
                     continue;
964
             glPushMatrix();
968
             glPushMatrix();
965
             glTranslatef(e->pos[0], e->pos[1], e->pos[2]);
969
             glTranslatef(e->pos[0], e->pos[1], e->pos[2]);
966
             glRotatef(e->angles[1], 0, 1, 0);
970
             glRotatef(e->angles[1], 0, 1, 0);
967
-            drawModel((SkeletalModel *)e->tmpHook);
971
+            drawModel(static_cast<SkeletalModel *>(e->tmpHook));
968
             glPopMatrix();
972
             glPopMatrix();
969
         }
973
         }
970
     }
974
     }
1307
     // Draw lara or other player model ( move to entity rendering method )
1311
     // Draw lara or other player model ( move to entity rendering method )
1308
     if (mFlags & Render::fViewModel && LARA && LARA->tmpHook)
1312
     if (mFlags & Render::fViewModel && LARA && LARA->tmpHook)
1309
     {
1313
     {
1310
-        SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
1314
+        SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
1311
         int frame = mdl->getAnimation();
1315
         int frame = mdl->getAnimation();
1312
 
1316
 
1313
-
1314
-        // Mongoose 2002.03.22, Test 'idle' aniamtions
1315
-        if (!LARA->moving)
1317
+        if (mdl)
1316
         {
1318
         {
1317
-            frame = mdl->getIdleAnimation();
1318
 
1319
 
1319
-            // Mongoose 2002.08.15, Stop flickering of idle lara here
1320
-            if (frame == 11)
1320
+            // Mongoose 2002.03.22, Test 'idle' aniamtions
1321
+            if (!LARA->moving)
1321
             {
1322
             {
1322
-                mdl->setFrame(0);
1323
+                frame = mdl->getIdleAnimation();
1324
+
1325
+                // Mongoose 2002.08.15, Stop flickering of idle lara here
1326
+                if (frame == 11)
1327
+                {
1328
+                    mdl->setFrame(0);
1329
+                }
1323
             }
1330
             }
1324
-        }
1325
 
1331
 
1326
-        if (mdl)
1327
-        {
1328
             animation_frame_t *animation = mdl->model->animation[frame];
1332
             animation_frame_t *animation = mdl->model->animation[frame];
1329
 
1333
 
1330
             if (animation && mdl->getFrame() > (int)animation->frame.size()-1)
1334
             if (animation && mdl->getFrame() > (int)animation->frame.size()-1)
1345
         glRotated(mCamera->getYaw(), 0, 1, 0);
1349
         glRotated(mCamera->getYaw(), 0, 1, 0);
1346
 #endif
1350
 #endif
1347
 
1351
 
1348
-        drawModel((SkeletalModel *)LARA->tmpHook);
1352
+        drawModel(static_cast<SkeletalModel *>(LARA->tmpHook));
1349
         glPopMatrix();
1353
         glPopMatrix();
1350
     }
1354
     }
1351
 
1355
 
1382
     bone_frame_t *boneframe2 = 0x0;
1386
     bone_frame_t *boneframe2 = 0x0;
1383
     bone_tag_t *tag;
1387
     bone_tag_t *tag;
1384
     bone_tag_t *tag2;
1388
     bone_tag_t *tag2;
1385
-    unsigned int i;
1386
     int bframe, aframe;
1389
     int bframe, aframe;
1387
     skeletal_model_t *mdl;
1390
     skeletal_model_t *mdl;
1388
 
1391
 
1501
 #ifdef EXPERIMENTAL_NON_ITEM_RENDER
1504
 #ifdef EXPERIMENTAL_NON_ITEM_RENDER
1502
                 drawModel(mModels[mdl->ponytail], 0, 0);
1505
                 drawModel(mModels[mdl->ponytail], 0, 0);
1503
 #else
1506
 #else
1504
-                for (i = 0; i < mdl->ponytailNumMeshes; ++i)
1507
+                for (unsigned int i = 0; i < mdl->ponytailNumMeshes; ++i)
1505
                 {
1508
                 {
1506
                     glPushMatrix();
1509
                     glPushMatrix();
1507
 
1510
 
1535
                     }
1538
                     }
1536
                 }
1539
                 }
1537
 
1540
 
1538
-                for (i = 0; i < mdl->ponytailNumMeshes; ++i)
1541
+                for (unsigned int i = 0; i < mdl->ponytailNumMeshes; ++i)
1539
                 {
1542
                 {
1540
                     glPopMatrix();
1543
                     glPopMatrix();
1541
                 }
1544
                 }

+ 3
- 19
src/TombRaider.cpp View File

1500
         _sound_sources =
1500
         _sound_sources =
1501
             (tr2_sound_source_t*) new unsigned char[_num_sound_sources*40];
1501
             (tr2_sound_source_t*) new unsigned char[_num_sound_sources*40];
1502
 
1502
 
1503
-        if (mEngineVersion == TR_VERSION_4)
1504
-        {
1505
-            // Mongoose 2002.04.04, was 40 sized reads before extra_camera
1506
-            Fread(_sound_sources, sizeof(tr2_sound_source_t),
1507
-                    _num_sound_sources, f);
1508
-        }
1509
-        else
1510
-        {
1511
-            Fread(_sound_sources, sizeof(tr2_sound_source_t),
1512
-                    _num_sound_sources, f);
1513
-        }
1503
+        Fread(_sound_sources, sizeof(tr2_sound_source_t),
1504
+                _num_sound_sources, f);
1514
         //! \fixme endian
1505
         //! \fixme endian
1515
     }
1506
     }
1516
 
1507
 
1823
     }
1814
     }
1824
     else
1815
     else
1825
     {
1816
     {
1826
-        if (mEngineVersion == TR_VERSION_4)
1827
-        {
1828
-            Fread(mSoundMap, sizeof(short), 370, f);
1829
-        }
1830
-        else
1831
-        {
1832
-            Fread(mSoundMap, sizeof(short), 370, f);
1833
-        }
1817
+        Fread(mSoundMap, sizeof(short), 370, f);
1834
     }
1818
     }
1835
     //! \fixme endian
1819
     //! \fixme endian
1836
 
1820
 

+ 8
- 4
src/Vector3d.cpp View File

171
 }
171
 }
172
 
172
 
173
 
173
 
174
-void Vector3d::operator =(const Vector3d &v)
174
+Vector3d &Vector3d::operator =(const Vector3d &v)
175
 {
175
 {
176
     mVec[0] = v.mVec[0];
176
     mVec[0] = v.mVec[0];
177
     mVec[1] = v.mVec[1];
177
     mVec[1] = v.mVec[1];
178
     mVec[2] = v.mVec[2];
178
     mVec[2] = v.mVec[2];
179
+    return *this;
179
 }
180
 }
180
 
181
 
181
 
182
 
182
-void Vector3d::operator +=(const Vector3d &v)
183
+Vector3d &Vector3d::operator +=(const Vector3d &v)
183
 {
184
 {
184
     mVec[0] += v.mVec[0];
185
     mVec[0] += v.mVec[0];
185
     mVec[1] += v.mVec[1];
186
     mVec[1] += v.mVec[1];
186
     mVec[2] += v.mVec[2];
187
     mVec[2] += v.mVec[2];
188
+    return *this;
187
 }
189
 }
188
 
190
 
189
 
191
 
190
-void Vector3d::operator -=(const Vector3d &v)
192
+Vector3d &Vector3d::operator -=(const Vector3d &v)
191
 {
193
 {
192
     mVec[0] -= v.mVec[0];
194
     mVec[0] -= v.mVec[0];
193
     mVec[1] -= v.mVec[1];
195
     mVec[1] -= v.mVec[1];
194
     mVec[2] -= v.mVec[2];
196
     mVec[2] -= v.mVec[2];
197
+    return *this;
195
 }
198
 }
196
 
199
 
197
 
200
 
198
-void Vector3d::operator *=(vec_t s)
201
+Vector3d &Vector3d::operator *=(vec_t s)
199
 {
202
 {
200
     mVec[0] *= s;
203
     mVec[0] *= s;
201
     mVec[1] *= s;
204
     mVec[1] *= s;
202
     mVec[2] *= s;
205
     mVec[2] *= s;
206
+    return *this;
203
 }
207
 }
204
 
208
 
205
 
209
 

+ 4
- 4
test/TombRaider.cpp View File

466
             j = moveable[i].starting_mesh;
466
             j = moveable[i].starting_mesh;
467
             n = moveable[i].num_meshes + j;
467
             n = moveable[i].num_meshes + j;
468
 
468
 
469
-            fprintf(f, "Lara (%i)\n", i);
469
+            fprintf(f, "Lara (%u)\n", i);
470
         }
470
         }
471
         else if (moveable[i].object_id == 30)
471
         else if (moveable[i].object_id == 30)
472
         {
472
         {
481
             {
481
             {
482
                 case 8: // Joints, ( interconnecting skin/ploys )
482
                 case 8: // Joints, ( interconnecting skin/ploys )
483
                 case 9:
483
                 case 9:
484
-                    fprintf(f, "TR4 lara joints (%i)\n", i);
484
+                    fprintf(f, "TR4 lara joints (%u)\n", i);
485
                     j = moveable[i].starting_mesh;
485
                     j = moveable[i].starting_mesh;
486
                     n = moveable[i].num_meshes + j;
486
                     n = moveable[i].num_meshes + j;
487
             }
487
             }
489
 
489
 
490
         for (k = j; j < n; ++j)
490
         for (k = j; j < n; ++j)
491
         {
491
         {
492
-            fprintf(f, "\tMesh[%i] = %i\n", (j - k), j);
492
+            fprintf(f, "\tMesh[%i] = %u\n", (j - k), j);
493
         }
493
         }
494
     }
494
     }
495
 
495
 
525
 
525
 
526
     if (total)
526
     if (total)
527
     {
527
     {
528
-        printf("Dumped %ibytes (%.2f MB) of audio samples\n",
528
+        printf("Dumped %ubytes (%.2f MB) of audio samples\n",
529
                 total, (float)total/1024000.0);
529
                 total, (float)total/1024000.0);
530
     }
530
     }
531
 }
531
 }

Loading…
Cancel
Save