From 7b742e913f0f04b70dc5294127584b6ff111b482 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 16 Mar 2015 16:58:50 +0100 Subject: [PATCH] Introduced chunk class. --- game/chunk.cc | 21 +++++++++++++++++++++ game/chunk.hh | 17 +++++++++++++++++ game/level.cc | 25 ++++++++++++------------- game/level.hh | 11 +++++++---- game/loader.cc | 3 ++- 5 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 game/chunk.cc create mode 100644 game/chunk.hh diff --git a/game/chunk.cc b/game/chunk.cc new file mode 100644 index 0000000..d7d381d --- /dev/null +++ b/game/chunk.cc @@ -0,0 +1,21 @@ +#include "chunk.hh" + +Chunk::Chunk() { +} + +Chunk::~Chunk() { + for(unsigned int i = 0; i* additionalMatrices) { + for(unsigned int i = 0; irender(shader, lightingPass, texturePass, viewProjcetionMatrix, additionalMatrices); + } +} + +void Chunk::addObject(Object* object) { + objects.push_back(object); +} diff --git a/game/chunk.hh b/game/chunk.hh new file mode 100644 index 0000000..bc9d603 --- /dev/null +++ b/game/chunk.hh @@ -0,0 +1,17 @@ +#pragma once + +#include "object.hh" +#include + +using namespace ACGL::OpenGL; + +class Chunk { + public: + Chunk(); + ~Chunk(); + void render(SharedShaderProgram shader, bool lightingPass, bool texturePass, + glm::mat4* viewProjcetionMatrix, std::vector* additionalMatrices=0); + void addObject(Object* object); + private: + std::vector objects; +}; diff --git a/game/level.cc b/game/level.cc index 69fab74..f1fe491 100644 --- a/game/level.cc +++ b/game/level.cc @@ -16,9 +16,6 @@ Level::~Level() { if (luaState!=nullptr) { lua_close(luaState); } - for(unsigned int i = 0; i* shadowVPs) { - for(unsigned int i = 0; irender(shader, lightingPass, true, viewProjectionMatrix, shadowVPs); + chunks.at(i).render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs); } else { - objects.at(i)->render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs); + chunks.at(i).render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs); } } if (lightingPass && waterPlane) { @@ -191,8 +188,8 @@ float Level::getSkydomeSize() { return this->skydomeSize; } -std::vector* Level::getObjects() { - return &objects; +std::vector* Level::getAllObjects() { + return &allObjects; } std::vector* Level::getPhysicsObjects() { @@ -229,7 +226,8 @@ void Level::setSkydomeObject(Skydome object){ } void Level::addObject(Object* object) { - objects.push_back(object); + allObjects.push_back(object); + chunks.at(0).addObject(object); } void Level::addPhysicsObject(Object* object) { @@ -267,10 +265,6 @@ Physics* Level::getPhysics() { return &physics; } -unsigned int Level::getObjectsVectorSize() { - return objects.size(); -} - unsigned int Level::getPhysicsObjectsVectorSize() { return physicsObjects.size(); } @@ -337,3 +331,8 @@ void Level::printPosition() { printf("Player position: %2.2f, %2.2f, %2.2f\n", cameraCenter->getPosition().x, cameraCenter->getPosition().y, cameraCenter->getPosition().z); } + +void Level::generateChunks(int chunkSize) { + chunks = std::vector(1); + chunks.at(0) = Chunk(); +} diff --git a/game/level.hh b/game/level.hh index 53a4db8..7c4b0ef 100644 --- a/game/level.hh +++ b/game/level.hh @@ -12,6 +12,7 @@ #include "trigger.hh" #include "skydome.hh" #include "keyboardState.hh" +#include "chunk.hh" extern "C" { #include "lua.h" @@ -43,7 +44,7 @@ class Level { float getSkydomeSize(); void setWaterPlane(Object* water); Skydome* getSkydome(); - std::vector* getObjects(); + std::vector* getAllObjects(); std::vector* getPhysicsObjects(); void moveObject(int objectIndex, float strength, float xPos, float yPos, float zPos); void setStrength(float strength); @@ -56,9 +57,8 @@ class Level { void setFogColourNight(glm::vec4 colour); void setDirectionalLight(Light light); void setSunDirection(float x, float y, float z); - Physics* getPhysics(); - unsigned int getObjectsVectorSize(); unsigned int getPhysicsObjectsVectorSize(); + Physics* getPhysics(); void setCameraCenter(Object* object); void addLight(Light light); void preloadLightPosition(float xPos, float yPos, float zPos); @@ -74,10 +74,13 @@ class Level { void activateEndgame(); void setTerrain(Terrain terrain); void printPosition(); + void generateChunks(int chunkSize); private: lua_State* luaState=nullptr; - std::vector objects; + std::vector crossChunkObjects; + std::vector allObjects; std::vector physicsObjects; + std::vector chunks; std::vector lights; std::vector triggers; Object* waterPlane; diff --git a/game/loader.cc b/game/loader.cc index 835a38b..e773082 100644 --- a/game/loader.cc +++ b/game/loader.cc @@ -82,6 +82,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa level->setTerrain(terrain); // Because object gets copied a lot load it when it has reached it's final destination level->getTerrain()->load(); + level->generateChunks(50.0f); Model terrainModel = Model(level->getTerrain()->getModel()); std::string terrainTexture = queryString(terrainElement, "texture"); float terrainAmbientFactor = queryFloat(terrainElement, "ambientFactor"); @@ -341,7 +342,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa //create an identifier for this object std::vector objectIdentifier = std::vector(5); - objectIdentifier[0] = level->getObjectsVectorSize()-1; + objectIdentifier[0] = level->getAllObjects()->size()-1; if (physicType.compare("None") == 0){ objectIdentifier[1] = 0; }else{