diff --git a/game/graphics.hh b/game/graphics.hh index 0560e27..ec1c815 100644 --- a/game/graphics.hh +++ b/game/graphics.hh @@ -53,7 +53,7 @@ class Graphics { std::string loadingScreenContinuePath; SharedTexture2D loadingScreen; SharedTexture2D loadingContinueScreen; - std::vector* closestLights; + std::vector>* closestLights; std::vector closestFlames; SharedShaderProgram loadingShader; SharedShaderProgram lightingShader; diff --git a/game/level.cc b/game/level.cc index fbf8e7a..4407e94 100644 --- a/game/level.cc +++ b/game/level.cc @@ -18,9 +18,6 @@ Level::~Level() { lua_close(luaState); } delete(waterPlane); - for(unsigned int i = 0; i* Level::getLights() { +std::vector>* Level::getLights() { return &lights; } @@ -353,7 +350,7 @@ void Level::setCameraCenter(Object* object) { } void Level::addLight(Light light) { - Light *add_light = new Light(light); + shared_ptr add_light = shared_ptr(new Light(light)); this->lights.push_back(add_light); } @@ -363,7 +360,7 @@ void Level::preloadLightPosition(float xPos, float yPos, float zPos){ void Level::addLightByParameters(float redColour, float greenColour, float blueColour, float intensity, float flameYOffset, float flameHeight, float flameWidth){ glm::vec3 colour = glm::vec3(redColour, greenColour, blueColour); - this->lights.push_back(new Light(nextLightPosition, colour, intensity, flameYOffset, flameHeight, flameWidth)); + this->addLight(Light(nextLightPosition, colour, intensity, flameYOffset, flameHeight, flameWidth)); } void Level::deleteFourLights(){ @@ -446,7 +443,7 @@ Object* Level::getWaterPlane() { return waterPlane; } -bool Level::compareLightDistances(Light* a, Light* b) { +bool Level::compareLightDistances(shared_ptr a, shared_ptr b) { if (glm::distance(cameraCenter->getPosition(), a->getPosition()) < glm::distance(cameraCenter->getPosition(), b->getPosition())) { return true; @@ -456,13 +453,13 @@ bool Level::compareLightDistances(Light* a, Light* b) { } } -std::vector* Level::getClosestLights() { - closestLights = std::vector(lights); +std::vector>* Level::getClosestLights() { + closestLights = std::vector>(lights); std::sort(closestLights.begin(), closestLights.end(), - [this](Light* a, Light* b) {return compareLightDistances(a, b); }); + [this](shared_ptr a, shared_ptr b) {return compareLightDistances(a, b); }); if (lights.size() > 15) { - closestLights = std::vector(&closestLights[0], + closestLights = std::vector>(&closestLights[0], &closestLights[15]); } return &closestLights; diff --git a/game/level.hh b/game/level.hh index 7dea9fd..9ce9997 100644 --- a/game/level.hh +++ b/game/level.hh @@ -37,7 +37,7 @@ class Level { std::vector* shadowVPs=0); glm::vec3 getAmbientLight(); Light* getDirectionalLight(); - std::vector* getLights(); + std::vector>* getLights(); Object* getCameraCenter(); Camera* getCamera(); glm::vec3 getCameraPosition(); @@ -84,7 +84,7 @@ class Level { void addToSpecificChunk(Object* object, int xPosition, int zPosition); void enqueueObjects(Graphics* graphics); void sortObjects(int textureCount); - std::vector* getClosestLights(); + std::vector>* getClosestLights(); private: std::vector getSurroundingChunks(int chunkRenderDistance); lua_State* luaState=nullptr; @@ -93,8 +93,8 @@ class Level { std::vector allObjects; std::vector physicsObjects; std::vector> chunks; - std::vector lights; - std::vector closestLights; + std::vector> lights; + std::vector> closestLights; std::vector triggers; Object* waterPlane=nullptr; glm::vec3 ambientLight; @@ -114,7 +114,7 @@ class Level { glm::vec3 nextLightPosition; int chunkSize; float farPlane; - bool compareLightDistances(Light* a, Light* b); + bool compareLightDistances(shared_ptr a, shared_ptr b); }; #endif