LCOV - code coverage report
Current view: top level - src - GameLevel.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 95.8 % 24 23
Test Date: 2026-04-03 02:26:39 Functions: 93.8 % 16 15

            Line data    Source code
       1              : /**
       2              :  * @file GameLevel.h
       3              :  * @brief Representation of a game level or scene.
       4              :  *
       5              :  * A game level manages and displays a collection of game objects.
       6              :  */
       7              : #ifndef _GAME_LEVEL_H_
       8              : #define _GAME_LEVEL_H_
       9              : 
      10              : #include "ObjectList.h"
      11              : #include "Object.h"
      12              : #include "ModelGameObject.h"
      13              : #include "Terrain.h"
      14              : #include "Camera.h"
      15              : #include "QuadTree.h"
      16              : #include "Music.h"
      17              : 
      18              : extern "C" {
      19              :   #include "luajit-2.1/lua.h"
      20              :   #include "luajit-2.1/lualib.h"
      21              :   #include "luajit-2.1/lauxlib.h"
      22              : }
      23              : 
      24              : #define MAX_LEVEL_OBJECTS 1024
      25              : 
      26              : #define TYPE_GAME_OBJECT 1
      27              : #define TYPE_GAME_TEXT   2
      28              : #define TYPE_GAME_SPRITE 3
      29              : 
      30              : class GameLevel {
      31              :   public:
      32              :     GameLevel(const unsigned int& lists);
      33              :     ~GameLevel();
      34              : 
      35              :     void updateLevel();
      36              :     void animateLevel();
      37              :     void prepareLevel();
      38              :     void drawLevel();
      39              : 
      40              :     bool loadLevel(const char* file);
      41              :     bool loadLevelFromBuffer(const char* buffer);
      42              :     void loadScript(const std::string& script);
      43              : 
      44              :     Object* findEnemyOfType(const int& typeId);
      45              :     float findDistance(Object* a, Object* b);
      46              : 
      47              :     void drawSky();
      48              :     bool checkComplete();
      49              :     void unloadLevel();
      50              :     void removeObjects();
      51              : 
      52              :     void postDraw();
      53              : 
      54              :     void updateTerrain(int &x, int &z, float &height, int &type, float &red, float &green, float &blue);
      55              :     void updateColor(int &x, int &z, float &red, float &green, float &blue);
      56              : 
      57              :     void getTerrainInfo(int &x, int &z, float &height, int &type, float &red, float &green, float &blue);
      58              :     void saveTerrain(const char*);
      59              :     void toggleGrid();
      60              :     void toggleBoundingBoxes();
      61              :     void toggleControlTriangles();
      62              : 
      63              :     void drawObjects();
      64              :     void drawObjectOutlines();
      65              :     void drawShadows(Vector*);
      66              : 
      67              :     void updateObjects(Vector*);
      68              :     void prepareObjects();
      69              :     void animateObjects(const float& elapsed);
      70              : 
      71              :     Object* addObject(const std::string& script, lua_State* L, const unsigned int& typeId);
      72              : 
      73            1 :     ObjectList* getObjects()         { return &objects_; }
      74            3 :     Terrain* getTerrain()            { return((Terrain*)terrain_); }
      75            3 :     Camera* getCamera()              { return((Camera*)camera_); }
      76            4 :     ModelGameObject* getPlayer()     { return((ModelGameObject*)player_); }
      77            0 :     Music* getMusic()                { return &music_; }
      78           11 :     void setCamera(Camera* camera)   {
      79           11 :       camera_           = camera;
      80           11 :       idToObjectMap_[0] = (Object*)camera_;
      81           11 :       camera_->setGameLevelId(0);
      82           11 :     }
      83              : 
      84            1 :     void setId(const int &id) { id_ = id; }
      85            2 :     int getId()               { return id_; }
      86              : 
      87            2 :     float getElapsedTime()                        { return elapsedTime_; }
      88            1 :     void setElapsedTime(const float &elapsedTime) { elapsedTime_ = elapsedTime; }
      89              : 
      90            1 :     void setComplete(const bool &isComplete)        { isComplete_ = isComplete; }
      91            2 :     std::string getMusicPath()                      { return musicPath_; }
      92            1 :     void setMusicPath(const std::string &musicPath) { musicPath_ = musicPath; }
      93            1 :     Vector* getLightDirection()                     { return &lightDirection_; }
      94              : 
      95              :     void setSkyBox(float[][3], const int&, const int&);
      96            1 :     void setLightDirection(const float &x, const float &y, const float &z) {
      97            1 :       lightDirection_.setVector(x, y, z);
      98            1 :       lightDirection_.normalize();
      99            1 :     }
     100              : 
     101            7 :     Object* getObjectFromId(const int &id) {
     102            7 :       return (id >= 0 && id < MAX_LEVEL_OBJECTS ? idToObjectMap_[id] : NULL);
     103              :     }
     104              : 
     105              :   private:
     106              :     unsigned int lists_;      // display lists used for rendering
     107              : 
     108              :     Vector lightDirection_;
     109              : 
     110              :     ModelGameObject* player_; // player object
     111              :     Object* camera_;          // camera
     112              :     Terrain *terrain_;        // Terrain for this level (if one is loaded)
     113              : 
     114              :     Music music_;
     115              : 
     116              :     ObjectList objects_;
     117              :     std::map <std::string, ObjectList> freeObjects_;
     118              :     Object* idToObjectMap_[MAX_LEVEL_OBJECTS];
     119              :     unsigned int numObjects_;
     120              : 
     121              :     // colors for sky box
     122              :     float bgcolor_[3][3];
     123              : 
     124              :     bool isComplete_;
     125              : 
     126              :     float elapsedTime_;
     127              : 
     128              :     QuadTree quadTree_;
     129              :     DisplayList displayList_;
     130              : 
     131              :     bool grid_;
     132              :     bool bboxes_;
     133              :     bool controlTriangles_;
     134              : 
     135              :     std::string musicPath_;
     136              : 
     137              :     int id_;
     138              : 
     139              :     lua_State* luaState_;
     140              : 
     141              :     bool prepLevelLoad(const char* luaCode);
     142              :     bool finishLevelLoad();
     143              : };
     144              : 
     145              : #endif
        

Generated by: LCOV version 2.4-0