Introduced chunk class.

This commit is contained in:
Faerbit 2015-03-16 16:58:50 +01:00
parent 73f7ec6a70
commit 7b742e913f
5 changed files with 59 additions and 18 deletions

21
game/chunk.cc Normal file
View File

@ -0,0 +1,21 @@
#include "chunk.hh"
Chunk::Chunk() {
}
Chunk::~Chunk() {
for(unsigned int i = 0; i<objects.size(); i++) {
delete objects.at(i);
}
}
void Chunk::render(SharedShaderProgram shader, bool lightingPass, bool texturePass,
glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices) {
for(unsigned int i = 0; i<objects.size(); i++) {
objects.at(i)->render(shader, lightingPass, texturePass, viewProjcetionMatrix, additionalMatrices);
}
}
void Chunk::addObject(Object* object) {
objects.push_back(object);
}

17
game/chunk.hh Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include "object.hh"
#include <ACGL/OpenGL/Objects.hh>
using namespace ACGL::OpenGL;
class Chunk {
public:
Chunk();
~Chunk();
void render(SharedShaderProgram shader, bool lightingPass, bool texturePass,
glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices=0);
void addObject(Object* object);
private:
std::vector<Object*> objects;
};

View File

@ -16,9 +16,6 @@ Level::~Level() {
if (luaState!=nullptr) {
lua_close(luaState);
}
for(unsigned int i = 0; i<objects.size(); i++) {
delete(objects.at(i));
}
delete(waterPlane);
}
@ -55,12 +52,12 @@ void Level::load() {
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) {
for(unsigned int i = 0; i<objects.size(); i++) {
for(unsigned int i = 0; i<chunks.size(); i++) {
if (lightingPass) {
objects.at(i)->render(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<Object*>* Level::getObjects() {
return &objects;
std::vector<Object*>* Level::getAllObjects() {
return &allObjects;
}
std::vector<Object*>* 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<Chunk>(1);
chunks.at(0) = Chunk();
}

View File

@ -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<Object*>* getObjects();
std::vector<Object*>* getAllObjects();
std::vector<Object*>* 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<Object*> objects;
std::vector<Object*> crossChunkObjects;
std::vector<Object*> allObjects;
std::vector<Object*> physicsObjects;
std::vector<Chunk> chunks;
std::vector<Light> lights;
std::vector<Trigger> triggers;
Object* waterPlane;

View File

@ -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<int> objectIdentifier = std::vector<int>(5);
objectIdentifier[0] = level->getObjectsVectorSize()-1;
objectIdentifier[0] = level->getAllObjects()->size()-1;
if (physicType.compare("None") == 0){
objectIdentifier[1] = 0;
}else{