Browse Source

Created Entity class

Thomas Buck 10 years ago
parent
commit
6f15905676
14 changed files with 167 additions and 81 deletions
  1. 23
    18
      CMakeLists.txt
  2. 6
    0
      ChangeLog.md
  3. 6
    0
      TODO.md
  4. 56
    0
      include/Entity.h
  5. 0
    2
      include/Render.h
  6. 0
    4
      include/SkeletalModel.h
  7. 1
    0
      include/TombRaider.h
  8. 20
    18
      include/World.h
  9. 0
    3
      include/WorldData.h
  10. 1
    1
      src/CMakeLists.txt
  11. 37
    0
      src/Entity.cpp
  12. 15
    9
      src/Game.cpp
  13. 0
    20
      src/Render.cpp
  14. 2
    6
      src/SkeletalModel.cpp

+ 23
- 18
CMakeLists.txt View File

@@ -38,25 +38,30 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
38 38
     set (WARNINGS "${WARNINGS} -Wno-missing-prototypes -Wno-missing-variable-declarations")
39 39
     set (WARNINGS "${WARNINGS} -Wno-disabled-macro-expansion")
40 40
     set (WARNINGS "${WARNINGS} -Wno-shorten-64-to-32 -Wno-sign-conversion")
41
+    set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
42
+    set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0")
43
+    set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -O2 -fomit-frame-pointer")
44
+    set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -ffast-math -funroll-loops")
41 45
 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
42 46
     set (WARNINGS "${WARNINGS} -Wall -Wextra -Wpedantic")
47
+    set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
48
+    set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0")
49
+    set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -O2 -fomit-frame-pointer")
50
+    set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -ffast-math -funroll-loops")
43 51
 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
44 52
     # TODO Visual C++ compiler flags?
45 53
 endif()
46 54
 
47 55
 # Flags for all builds
48
-set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11 ${WARNINGS}")
56
+set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} ${WARNINGS}")
49 57
 
50 58
 # Flags for Debug build
51
-set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0")
52 59
 set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -DDEBUG")
53 60
 set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -DEXPERIMENTAL")
54 61
 # set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -DMULTITEXTURE")
55 62
 
56 63
 # Flags for Releasae builds
57
-set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
58
-set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -ffast-math -funroll-loops")
59
-set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -fomit-frame-pointer")
64
+set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -DNDEBUG")
60 65
 
61 66
 #################################################################
62 67
 
@@ -65,15 +70,16 @@ add_subdirectory (src)
65 70
 
66 71
 #################################################################
67 72
 
68
-# Target for running the setup
69
-add_custom_target (setup "${PROJECT_SOURCE_DIR}/cmake/setup.sh"
70
-    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
71
-)
73
+if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
72 74
 
73
-#################################################################
75
+    # Target for running the setup
76
+    add_custom_target (setup "${PROJECT_SOURCE_DIR}/cmake/setup.sh"
77
+        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
78
+    )
74 79
 
75
-# Target for running cppcheck
76
-if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
80
+    #################################################################
81
+
82
+    # Target for running cppcheck
77 83
     set (CHECK_STD "--std=c++11" "--std=posix")
78 84
     set (CHECK_FLAGS "--quiet" "--force")
79 85
     set (CHECK_NORMAL "--enable=information,warning,performance,portability")
@@ -88,12 +94,10 @@ if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
88 94
     add_custom_target (checkConfig echo "Checking cppcheck config..."
89 95
         COMMAND cppcheck ${CHECK_FLAGS} "-I${PROJECT_SOURCE_DIR}/include" ${CHECK_CONFIG} ${PROJECT_SOURCE_DIR}
90 96
     )
91
-endif (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
92 97
 
93
-#################################################################
98
+    #################################################################
94 99
 
95
-# Generate Doxygen Documentation
96
-if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
100
+    # Generate Doxygen Documentation
97 101
     find_package (Doxygen)
98 102
     if (DOXYGEN_FOUND)
99 103
         # Configure the Template Doxyfile for our specific project
@@ -122,8 +126,9 @@ if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
122 126
             COMMAND sed -i '' "s/CALL_GRAPH             = YES/CALL_GRAPH             = NO/g" Doxyfile
123 127
             COMMAND sed -i '' "s/CALLER_GRAPH           = YES/CALLER_GRAPH           = NO/g" Doxyfile
124 128
             SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
129
+
130
+        # Clean doc files
131
+        set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "doc")
125 132
     endif (DOXYGEN_FOUND)
126 133
 endif (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
127 134
 
128
-# Clean doc files
129
-set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "doc")

+ 6
- 0
ChangeLog.md View File

@@ -2,6 +2,12 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140515 ]
6
+    * Slight cmake script improvements
7
+    * Created Entity class that will also get animation state
8
+      from SkeletalModel
9
+    * Removed some unused old code parts
10
+
5 11
     [ 20140507 ]
6 12
     * Prepared for Windows support using Visual C++
7 13
       - Wrote utils/time implementation for Windows

+ 6
- 0
TODO.md View File

@@ -18,6 +18,12 @@ There are these DebugModel, DebugMap flags...?
18 18
 
19 19
 * 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
20 20
 
21
+## Cmake
22
+
23
+* Windows setup script needed, moving to AppData/Roaming
24
+* Support SSE with other compilers than Clang (src/CMakeLists.txt)
25
+* Visual C++ compiler flags? (CMakeLists.txt)
26
+
21 27
 ## Future Features
22 28
 
23 29
 * Use only assets from old TR games?

+ 56
- 0
include/Entity.h View File

@@ -0,0 +1,56 @@
1
+/*!
2
+ * \file include/Entity.h
3
+ * \brief World Entities
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _ENTITY_H_
9
+#define _ENTITY_H_
10
+
11
+#include "math/math.h"
12
+#include "TombRaider.h"
13
+
14
+class Entity {
15
+public:
16
+    typedef enum {
17
+        MoveTypeWalkNoSwim = -1,
18
+        MoveTypeWalk       = 0,
19
+        MoveTypeNoClipping = 1,
20
+        MoveTypeFly        = 2,
21
+        MoveTypeSwim       = 3
22
+    } MoveType;
23
+
24
+    Entity(TombRaider &tr);
25
+
26
+    // Animation State
27
+
28
+    unsigned int getAnimationFrame();
29
+    void setAnimationFrame(unsigned int index);
30
+
31
+    unsigned int getBoneFrame();
32
+    void setBoneFrame(unsigned int index);
33
+
34
+    unsigned int getIdleAnimation();
35
+    void setIdleAnimation(unsigned int index);
36
+
37
+private:
38
+    vec3_t pos;
39
+    vec3_t angles;
40
+    int room;
41
+
42
+    unsigned int skeletalModel;
43
+    MoveType moveType;
44
+
45
+    int state;
46
+    int objectId;
47
+
48
+    // Animation State
49
+
50
+    unsigned int boneFrame;
51
+    unsigned int animationFrame;
52
+    unsigned int idleAnimation;
53
+};
54
+
55
+#endif
56
+

+ 0
- 2
include/Render.h View File

@@ -121,8 +121,6 @@ public:
121 121
 
122 122
     void setSkyMesh(int index, bool rot);
123 123
 
124
-    void ViewModel(entity_t *ent, int index);
125
-
126 124
     void addSkeletalModel(SkeletalModel *mdl);
127 125
 
128 126
     unsigned int getFlags();

+ 0
- 4
include/SkeletalModel.h View File

@@ -79,11 +79,7 @@ public:
79 79
 
80 80
     void setIdleAnimation(int index);
81 81
 
82
-    unsigned int flags;
83 82
     skeletal_model_t *model; //!< World render model
84
-    float time;              //!< Interpolation use
85
-    float lastTime;
86
-    float rate;              //!< \fixme temp cache this here for old animation system use
87 83
 
88 84
 private:
89 85
     int mBoneFrame;      //!< Bone frame

+ 1
- 0
include/TombRaider.h View File

@@ -10,6 +10,7 @@
10 10
 #define _TOMBRAIDER_H_
11 11
 
12 12
 #include <cstdint>
13
+#include <cstdio>
13 14
 
14 15
 #ifdef WIN32
15 16
 typedef uint8_t u_int8_t;

+ 20
- 18
include/World.h View File

@@ -29,6 +29,23 @@ public:
29 29
     ~World();
30 30
 
31 31
     /*!
32
+     * \brief Clears all data in world
33
+     */
34
+    void destroy();
35
+
36
+    void addRoom(Room &room);
37
+
38
+    unsigned int sizeRoom();
39
+
40
+    Room &getRoom(unsigned int index);
41
+
42
+    void addSprite(SpriteSequence &sprite);
43
+
44
+    unsigned int sizeSprite();
45
+
46
+    SpriteSequence &getSprite(unsigned int index);
47
+
48
+    /*!
32 49
      * \brief Adds mesh to world
33 50
      * \param model mesh to add
34 51
      */
@@ -58,18 +75,6 @@ public:
58 75
     skeletal_model_t *getModel(int index);
59 76
     std::vector<entity_t *> *getEntities();
60 77
 
61
-    void addRoom(Room &room);
62
-
63
-    unsigned int sizeRoom();
64
-
65
-    Room &getRoom(unsigned int index);
66
-
67
-    void addSprite(SpriteSequence &sprite);
68
-
69
-    unsigned int sizeSprite();
70
-
71
-    SpriteSequence &getSprite(unsigned int index);
72
-
73 78
     /*!
74 79
      * \brief Find room a location is in.
75 80
      *
@@ -117,6 +122,7 @@ public:
117 122
      * \returns sector index of position in room
118 123
      */
119 124
     int getSector(int room, float x, float z);
125
+
120 126
     int getSector(int room, float x, float z, float *floor, float *ceiling);
121 127
 
122 128
     unsigned int getRoomInfo(int room);
@@ -138,12 +144,6 @@ public:
138 144
      */
139 145
     void getHeightAtPosition(int index, float x, float *y, float z);
140 146
 
141
-    /*!
142
-     * \brief Clears all data in world
143
-     * \todo in future will check if data is in use before clearing
144
-     */
145
-    void destroy();
146
-
147 147
 private:
148 148
 
149 149
     // Old World
@@ -155,6 +155,8 @@ private:
155 155
     std::vector<Room *> mRooms;
156 156
     std::vector<SpriteSequence *> mSprites;
157 157
 
158
+    //std::vector<Entity *> mEntities;
159
+    //std::vector<SkeletalModel *> mModels;
158 160
 };
159 161
 
160 162
 #endif

+ 0
- 3
include/WorldData.h View File

@@ -51,7 +51,6 @@ typedef struct {
51 51
 } model_mesh_t;
52 52
 
53 53
 typedef struct {
54
-    int id;                  //!< Unique identifier
55 54
     float pos[3];            //!< World position
56 55
     float angles[3];         //!< Euler angles (pitch, yaw, roll)
57 56
     int room;                //!< Current room entity is in
@@ -60,9 +59,7 @@ typedef struct {
60 59
     int state;               //!< State of the Player, AI, or object
61 60
     int objectId;            //!< What kind of entity?
62 61
 
63
-    int modelId;             //!< Animation model
64 62
     SkeletalModel *tmpHook;
65
-    bool animate;
66 63
 } entity_t;
67 64
 
68 65
 #endif

+ 1
- 1
src/CMakeLists.txt View File

@@ -42,6 +42,7 @@ endif (OPENAL_FOUND)
42 42
 set (SRCS ${SRCS} "Camera.cpp")
43 43
 set (SRCS ${SRCS} "Command.cpp")
44 44
 set (SRCS ${SRCS} "Console.cpp")
45
+set (SRCS ${SRCS} "Entity.cpp")
45 46
 set (SRCS ${SRCS} "Game.cpp")
46 47
 set (SRCS ${SRCS} "main.cpp")
47 48
 set (SRCS ${SRCS} "Menu.cpp")
@@ -141,7 +142,6 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
141 142
     if (NOT "${SSE_FOUND_MSG}" STREQUAL "")
142 143
         message (STATUS "Enabled${SSE_FOUND_MSG}...")
143 144
     endif (NOT "${SSE_FOUND_MSG}" STREQUAL "")
144
-# TODO support SSE with other compilers than Clang
145 145
 endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
146 146
 
147 147
 # Apply Flags

+ 37
- 0
src/Entity.cpp View File

@@ -0,0 +1,37 @@
1
+/*!
2
+ * \file src/Entity.cpp
3
+ * \brief World Entities
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "Entity.h"
9
+
10
+Entity::Entity(TombRaider &tr) {
11
+
12
+}
13
+
14
+unsigned int Entity::getAnimationFrame() {
15
+    return animationFrame;
16
+}
17
+
18
+void Entity::setAnimationFrame(unsigned int index) {
19
+    animationFrame = index;
20
+}
21
+
22
+unsigned int Entity::getBoneFrame() {
23
+    return boneFrame;
24
+}
25
+
26
+void Entity::setBoneFrame(unsigned int index) {
27
+    boneFrame = index;
28
+}
29
+
30
+unsigned int Entity::getIdleAnimation() {
31
+    return idleAnimation;
32
+}
33
+
34
+void Entity::setIdleAnimation(unsigned int index) {
35
+    idleAnimation = index;
36
+}
37
+

+ 15
- 9
src/Game.cpp View File

@@ -189,10 +189,8 @@ void Game::processSprites() {
189 189
 
190 190
 void Game::processRooms() {
191 191
     printf("Processing rooms: ");
192
-    for (int index = 0; index < mTombRaider.NumRooms(); index++) {
193
-        Room &room = *new Room(mTombRaider, index);
194
-        getWorld().addRoom(room);
195
-    }
192
+    for (int index = 0; index < mTombRaider.NumRooms(); index++)
193
+        getWorld().addRoom(*new Room(mTombRaider, index));
196 194
     printf("Done! Found %d rooms.\n", mTombRaider.NumRooms());
197 195
 }
198 196
 
@@ -358,6 +356,7 @@ void Game::processMoveables()
358 356
     }
359 357
 
360 358
     // Get models that aren't items
359
+    /*
361 360
     for (i = 0; i < mTombRaider.NumMoveables(); ++i)
362 361
     {
363 362
         switch ((int)moveable[i].object_id)
@@ -401,14 +400,24 @@ void Game::processMoveables()
401 400
                 }
402 401
         }
403 402
     }
403
+    */
404 404
 
405 405
     printf("Done! Found %d models.\n", mTombRaider.NumMoveables() + statCount);
406 406
 }
407 407
 
408
+// index moveable, i item, sometimes both moveable
408 409
 void Game::processMoveable(int index, int i, int *ent,
409 410
         std::vector<skeletal_model_t *> &cache2,
410 411
         std::vector<unsigned int> &cache, int object_id)
411 412
 {
413
+    // This creates both Entity and SkeletalModel
414
+    // Basic Idea:
415
+    // - Move animation state from SkeletalModel into Entity
416
+    // - Check if skeletal model is already stored
417
+    // - If so tell new Entity to reuse
418
+    // - Else store new skeletal model, tell new entity to use this one
419
+
420
+
412 421
     skeletal_model_t *r_model = NULL;
413 422
     skeletal_model_t *c_model = NULL;
414 423
     animation_frame_t *animation_frame = NULL;
@@ -446,13 +455,13 @@ void Game::processMoveable(int index, int i, int *ent,
446 455
     yaw *= 90;
447 456
 
448 457
     thing = new entity_t;
449
-    thing->id = (*ent)++;
458
+    //thing->id = (*ent)++;
450 459
     thing->pos[0] = item[i].x;
451 460
     thing->pos[1] = item[i].y;
452 461
     thing->pos[2] = item[i].z;
453 462
     thing->angles[1] = yaw;
454 463
     thing->objectId = moveable[index].object_id;
455
-    thing->animate = false;
464
+    //thing->animate = false;
456 465
 
457 466
     sModel = new SkeletalModel();
458 467
     getRender().addSkeletalModel(sModel);
@@ -490,13 +499,11 @@ void Game::processMoveable(int index, int i, int *ent,
490 499
         switch (mTombRaider.Engine())
491 500
         {
492 501
             case TR_VERSION_3:
493
-                mLara->modelId = i;
494 502
                 sModel->setAnimation(TR_ANIAMTION_RUN);
495 503
                 sModel->setIdleAnimation(TR_ANIAMTION_STAND);
496 504
                 r_model->tr4Overlay = false;
497 505
                 break;
498 506
             case TR_VERSION_4:
499
-                mLara->modelId = i;
500 507
                 sModel->setAnimation(TR_ANIAMTION_RUN);
501 508
                 sModel->setIdleAnimation(TR_ANIAMTION_STAND);
502 509
                 // Only TR4 lara has 2 layer bone tags/meshes per bone frame
@@ -506,7 +513,6 @@ void Game::processMoveable(int index, int i, int *ent,
506 513
             case TR_VERSION_2:
507 514
             case TR_VERSION_5:
508 515
             case TR_VERSION_UNKNOWN:
509
-                mLara->modelId = index;
510 516
                 sModel->setAnimation(TR_ANIAMTION_RUN);
511 517
                 sModel->setIdleAnimation(TR_ANIAMTION_STAND);
512 518
                 r_model->tr4Overlay = false;

+ 0
- 20
src/Render.cpp View File

@@ -1111,26 +1111,6 @@ void Render::setSkyMesh(int index, bool rot)
1111 1111
 }
1112 1112
 
1113 1113
 
1114
-void Render::ViewModel(entity_t *ent, int index)
1115
-{
1116
-    skeletal_model_t *model;
1117
-
1118
-
1119
-    if (!ent)
1120
-    {
1121
-        return;
1122
-    }
1123
-
1124
-    model = getWorld().getModel(index);
1125
-
1126
-    if (model)
1127
-    {
1128
-        ent->modelId = index;
1129
-        printf("Viewmodel skeletal model %i\n", model->id);
1130
-    }
1131
-}
1132
-
1133
-
1134 1114
 void Render::addSkeletalModel(SkeletalModel *mdl)
1135 1115
 {
1136 1116
     mModels.push_back(mdl);

+ 2
- 6
src/SkeletalModel.cpp View File

@@ -11,17 +11,14 @@
11 11
 
12 12
 SkeletalModel::SkeletalModel() {
13 13
     model = NULL;
14
-    flags = 0;
15 14
     mBoneFrame = 0;
16 15
     mAnimationFrame = 0;
17 16
     mIdleAnimation = 0;
18
-    time = 0.0f;
19
-    lastTime = 0.0f;
20
-    rate = 0.0f;
21 17
 }
22 18
 
23 19
 SkeletalModel::~SkeletalModel() {
24
-    //! \fixme Causes "freeing already freed pointer" exceptions or EXEC_BAD_ACCESS
20
+    // Model is really stored in World and deleted there
21
+    // Deleting it here causes EXEC_BAD_ACCESS...
25 22
     /* if (model) {
26 23
         for(std::vector<animation_frame_t>::size_type i = 0; i < model->animation.size(); i++) {
27 24
             animation_frame_t *af = model->animation[i];
@@ -76,7 +73,6 @@ void SkeletalModel::setAnimation(int index) {
76 73
     if (a) {
77 74
         mAnimationFrame = index;
78 75
         mBoneFrame = 0;
79
-        rate = a->rate;
80 76
     }
81 77
 }
82 78
 

Loading…
Cancel
Save