Biome class deleted.
This commit is contained in:
parent
e2c258afbd
commit
3f77b81c52
@ -1,7 +1,6 @@
|
||||
KubKraft=/home/quentin/Bureau/KubKraft CD=. filter=".gitignore *.c *.h *.diff *.vim AUTHORS ChangeLog COPYING Makefile Notes TODO *.textile *.cpp" {
|
||||
Makefile
|
||||
include=include {
|
||||
biome.h
|
||||
chunk.h
|
||||
config.h
|
||||
cube.h
|
||||
@ -12,7 +11,6 @@ KubKraft=/home/quentin/Bureau/KubKraft CD=. filter=".gitignore *.c *.h *.diff *.
|
||||
types.h
|
||||
}
|
||||
source=source {
|
||||
biome.cpp
|
||||
chunk.cpp
|
||||
cube.cpp
|
||||
init.cpp
|
||||
|
@ -1,52 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------
|
||||
|
||||
KubKraft
|
||||
Copyright (C) 2012 Quent42340 <quent42340@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---------------------------------------------------------------------------------*/
|
||||
#ifndef BIOME_H
|
||||
#define BIOME_H
|
||||
|
||||
class Biome {
|
||||
public:
|
||||
Biome(int x, int y, int z, Textures textures);
|
||||
~Biome();
|
||||
|
||||
void draw();
|
||||
void updateChunks();
|
||||
|
||||
int x() const { return m_x; }
|
||||
int y() const { return m_y; }
|
||||
int z() const { return m_z; }
|
||||
|
||||
void deleteCube(Cube *cube) { currentChunk->deleteCube(cube); }
|
||||
void addCube(Cube *selectedCube) { currentChunk->addCube(selectedCube); }
|
||||
|
||||
Chunk *findNearestChunk(float x, float y, float z);
|
||||
|
||||
static Chunk *currentChunk;
|
||||
|
||||
private:
|
||||
int m_x;
|
||||
int m_y;
|
||||
int m_z;
|
||||
|
||||
Textures m_textures;
|
||||
|
||||
std::vector<Chunk*> m_chunks;
|
||||
};
|
||||
|
||||
#endif // BIOME_H
|
@ -39,20 +39,20 @@ class Scene {
|
||||
void display();
|
||||
|
||||
void loadTextures();
|
||||
void drawBiomes();
|
||||
void drawChunks();
|
||||
void drawField();
|
||||
|
||||
void lockMouse();
|
||||
void unlockMouse();
|
||||
|
||||
Biome *findNearestBiome(float x, float y, float z);
|
||||
Chunk *findNearestChunk(float x, float y, float z);
|
||||
|
||||
static bool intersectionLinePlane(vect3D normal, vect3D planePoint, vect3D lineOrigPoint, vect3D directionVector, float *distance);
|
||||
static bool intersectionLineCube(int cubeX, int cubeY, int cubeZ, vect3D lineOrigPoint, vect3D directionVector, float *distance, s8 *face);
|
||||
static void testCubes(std::vector<Cube*> cubes);
|
||||
|
||||
static Player *player;
|
||||
static Biome *biome;
|
||||
static Chunk *currentChunk;
|
||||
static Cube *selectedCube;
|
||||
|
||||
private:
|
||||
@ -60,7 +60,7 @@ class Scene {
|
||||
|
||||
Textures m_textures;
|
||||
|
||||
std::vector<Biome*> m_biomes;
|
||||
std::vector<Chunk*> m_chunks;
|
||||
};
|
||||
|
||||
#endif // SCENE_H
|
||||
|
@ -1,93 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------
|
||||
|
||||
KubKraft
|
||||
Copyright (C) 2012 Quent42340 <quent42340@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
---------------------------------------------------------------------------------*/
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cmath>
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "types.h"
|
||||
#include "player.h"
|
||||
#include "map.h"
|
||||
#include "cube.h"
|
||||
#include "chunk.h"
|
||||
#include "biome.h"
|
||||
#include "scene.h"
|
||||
|
||||
Chunk *Biome::currentChunk = NULL;
|
||||
|
||||
Biome::Biome(int x, int y, int z, Textures textures) {
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
m_z = z;
|
||||
|
||||
m_textures = textures;
|
||||
|
||||
m_chunks.push_back(new Chunk(m_x, m_y, m_z, m_textures));
|
||||
m_chunks.push_back(new Chunk(m_x + 16, m_y, m_z, m_textures));
|
||||
m_chunks.push_back(new Chunk(m_x, m_y + 16, m_z, m_textures));
|
||||
m_chunks.push_back(new Chunk(m_x + 16, m_y + 16, m_z, m_textures));
|
||||
|
||||
currentChunk = findNearestChunk(Scene::player->x(), Scene::player->y(), Scene::player->z());
|
||||
}
|
||||
|
||||
Biome::~Biome() {
|
||||
m_chunks.clear();
|
||||
|
||||
delete currentChunk;
|
||||
}
|
||||
|
||||
void Biome::draw() {
|
||||
for(std::vector<Chunk*>::iterator it = m_chunks.begin() ; it != m_chunks.end() ; it++) {
|
||||
(*it)->draw();
|
||||
}
|
||||
}
|
||||
|
||||
void Biome::updateChunks() {
|
||||
currentChunk = findNearestChunk(Scene::player->x(), Scene::player->y(), Scene::player->z());
|
||||
}
|
||||
|
||||
Chunk *Biome::findNearestChunk(float x, float y, float z) {
|
||||
float distance = FAR;
|
||||
Chunk *chunk = NULL;
|
||||
|
||||
for(std::vector<Chunk*>::iterator it = m_chunks.begin() ; it != m_chunks.end() ; it++) {
|
||||
vect3D center;
|
||||
|
||||
// 8 here is 16, so chunk size, divided by 2
|
||||
center.x = (*it)->x() + 8;
|
||||
center.y = (*it)->y() + 8;
|
||||
center.z = (*it)->z() + 8;
|
||||
|
||||
float d = sqrt(pow(center.x - x, 2) + pow(center.y - y, 2) + pow(center.z - z, 2));
|
||||
|
||||
if(d < distance) {
|
||||
distance = d;
|
||||
chunk = (*it);
|
||||
}
|
||||
}
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "map.h"
|
||||
#include "cube.h"
|
||||
#include "chunk.h"
|
||||
#include "biome.h"
|
||||
#include "scene.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include "cube.h"
|
||||
#include "chunk.h"
|
||||
#include "player.h"
|
||||
#include "biome.h"
|
||||
#include "scene.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "map.h"
|
||||
#include "cube.h"
|
||||
#include "chunk.h"
|
||||
#include "biome.h"
|
||||
#include "scene.h"
|
||||
|
||||
using namespace std;
|
||||
@ -212,7 +211,7 @@ void Scene::testCubes(std::vector<Cube*> cubes) {
|
||||
float d = -1;
|
||||
s8 f = -1;
|
||||
|
||||
bool result = intersectionLineCube((*it)->x() + biome->x(), (*it)->y() + biome->y(), (*it)->z() + biome->z(), linePoint, directionVector, &d, &f);
|
||||
bool result = intersectionLineCube((*it)->x() + currentChunk->x(), (*it)->y() + currentChunk->y(), (*it)->z() + currentChunk->z(), linePoint, directionVector, &d, &f);
|
||||
|
||||
if(result && (d < distance) && (d < 5)) {
|
||||
distance = d;
|
||||
@ -231,7 +230,7 @@ void Scene::testCubes(std::vector<Cube*> cubes) {
|
||||
}
|
||||
|
||||
Player *Scene::player;
|
||||
Biome *Scene::biome;
|
||||
Chunk *Scene::currentChunk;
|
||||
Cube *Scene::selectedCube;
|
||||
|
||||
Scene::Scene() {
|
||||
@ -240,9 +239,12 @@ Scene::Scene() {
|
||||
|
||||
loadTextures();
|
||||
|
||||
m_biomes.push_back(new Biome(0, 0, 0, m_textures));
|
||||
m_chunks.push_back(new Chunk(0, 0, 0, m_textures));
|
||||
m_chunks.push_back(new Chunk(16, 0, 0, m_textures));
|
||||
m_chunks.push_back(new Chunk(0, 16, 0, m_textures));
|
||||
m_chunks.push_back(new Chunk(16, 16, 0, m_textures));
|
||||
|
||||
biome = findNearestBiome(player->x(), player->y(), player->z());
|
||||
currentChunk = findNearestChunk(player->x(), player->y(), player->z());
|
||||
|
||||
selectedCube = new Cube(-1, -1, -1, m_textures["dirt"], NULL);
|
||||
}
|
||||
@ -254,7 +256,7 @@ Scene::~Scene() {
|
||||
element->second = 0;
|
||||
}
|
||||
|
||||
delete biome;
|
||||
delete currentChunk;
|
||||
delete player;
|
||||
delete selectedCube;
|
||||
}
|
||||
@ -312,12 +314,12 @@ void Scene::manageEvents() {
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if(event.button.button == SDL_BUTTON_LEFT) {
|
||||
// To fix for multiples biomes
|
||||
biome->deleteCube(selectedCube);
|
||||
// To fix for multiples currentChunks
|
||||
currentChunk->deleteCube(selectedCube);
|
||||
selectedCube = new Cube(-1, -1, -1, 0, NULL);
|
||||
}
|
||||
if(event.button.button == SDL_BUTTON_RIGHT) {
|
||||
biome->addCube(selectedCube);
|
||||
currentChunk->addCube(selectedCube);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -408,17 +410,18 @@ void Scene::loadTextures() {
|
||||
m_textures["bedrock"] = loadTexture("textures/bedrock.bmp");
|
||||
}
|
||||
|
||||
void Scene::drawBiomes() {
|
||||
biome = findNearestBiome(player->x(), player->y(), player->z());
|
||||
biome->draw();
|
||||
cout << "Previous chunk: (" << Biome::currentChunk->x() << ";" << Biome::currentChunk->y() << ";" << Biome::currentChunk->z() << ")";
|
||||
biome->updateChunks();
|
||||
testCubes(Biome::currentChunk->cubes());
|
||||
cout << "| New chunk: (" << Biome::currentChunk->x() << ";" << Biome::currentChunk->y() << ";" << Biome::currentChunk->z() << ")" << endl;
|
||||
void Scene::drawChunks() {
|
||||
currentChunk = findNearestChunk(player->x(), player->y(), player->z());
|
||||
|
||||
for(vector<Chunk*>::iterator it = m_chunks.begin() ; it != m_chunks.end() ; it++) {
|
||||
(*it)->draw();
|
||||
}
|
||||
|
||||
testCubes(currentChunk->cubes());
|
||||
}
|
||||
|
||||
void Scene::drawField() {
|
||||
drawBiomes();
|
||||
drawChunks();
|
||||
|
||||
// Turn on textures
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
@ -467,11 +470,11 @@ void Scene::unlockMouse() {
|
||||
SDL_ShowCursor(true);
|
||||
}
|
||||
|
||||
Biome *Scene::findNearestBiome(float x, float y, float z) {
|
||||
Chunk *Scene::findNearestChunk(float x, float y, float z) {
|
||||
float distance = FAR;
|
||||
Biome *biome = NULL;
|
||||
Chunk *chunk = NULL;
|
||||
|
||||
for(vector<Biome*>::iterator it = m_biomes.begin() ; it != m_biomes.end() ; it++) {
|
||||
for(vector<Chunk*>::iterator it = m_chunks.begin() ; it != m_chunks.end() ; it++) {
|
||||
vect3D center;
|
||||
|
||||
center.x = (*it)->x() + 8;
|
||||
@ -482,10 +485,10 @@ Biome *Scene::findNearestBiome(float x, float y, float z) {
|
||||
|
||||
if(d < distance) {
|
||||
distance = d;
|
||||
biome = (*it);
|
||||
chunk = (*it);
|
||||
}
|
||||
}
|
||||
|
||||
return biome;
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user