BROKE BUILD: entity system lol time to dieee
This commit is contained in:
17
src/game.cpp
17
src/game.cpp
@@ -12,6 +12,7 @@
|
||||
#include "renderer/camera.hpp"
|
||||
|
||||
#include "world/chunk/chunk.hpp"
|
||||
#include "world/entity.hpp"
|
||||
#include "world/world.hpp"
|
||||
#include "world/block.hpp"
|
||||
|
||||
@@ -82,10 +83,9 @@ void Game::Setup(int w, int h) {
|
||||
*m_logger << LOGGER_ENDL;
|
||||
IsDisplayOpen = true;
|
||||
|
||||
m_cameras["Default"] = std::make_shared<Camera>(w, h);
|
||||
m_activeCamera = m_cameras["Default"];
|
||||
m_activeCamera->Position = { 0, 70, 0 };
|
||||
m_activeCamera->UpdateView();
|
||||
m_player = std::make_shared<Entity>(0, 70, 0);
|
||||
|
||||
m_player->EntityCamera = std::make_shared<Camera>(w, h);
|
||||
|
||||
std::shared_ptr<CBlockDictionary> BlockDictionary = CBlockDictionary::GetInstance();
|
||||
|
||||
@@ -132,7 +132,7 @@ void Game::Input(SDL_Event* e) {
|
||||
|
||||
if (e->window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
|
||||
m_activeCamera->UpdateProjection(e->window.data1, e->window.data2);
|
||||
m_player->EntityCamera->UpdateProjection(e->window.data1, e->window.data2);
|
||||
glViewport(0, 0, e->window.data1, e->window.data2);
|
||||
|
||||
}
|
||||
@@ -152,11 +152,11 @@ void Game::Input(SDL_Event* e) {
|
||||
|
||||
}
|
||||
|
||||
if (IsMouseActive) m_activeCamera->HandleMouse(*e);
|
||||
if (IsMouseActive) m_player->EntityCamera->HandleMouse(*e);
|
||||
|
||||
}
|
||||
|
||||
m_activeCamera->MoveCamera(state);
|
||||
m_player->EntityCamera->MoveCamera(state);
|
||||
|
||||
}
|
||||
|
||||
@@ -175,7 +175,8 @@ void Game::Run() {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClearBufferfv(GL_COLOR, 0, clear);
|
||||
|
||||
m_renderer->Render(m_world , m_activeCamera);
|
||||
m_world->Update(m_player);
|
||||
m_renderer->Render(m_world, m_player);
|
||||
|
||||
SDL_GL_SwapWindow(m_window);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class Logger;
|
||||
|
||||
class Renderer;
|
||||
class Camera;
|
||||
class Entity;
|
||||
class World;
|
||||
|
||||
class Game {
|
||||
@@ -47,9 +48,8 @@ private:
|
||||
std::shared_ptr<Renderer> m_renderer;
|
||||
std::shared_ptr<World> m_world;
|
||||
|
||||
std::map<std::string, std::shared_ptr<Camera>> m_cameras;
|
||||
std::shared_ptr<Camera> m_activeCamera;
|
||||
|
||||
std::shared_ptr<Entity> m_player;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
#include "camera.hpp"
|
||||
|
||||
Camera::Camera() {
|
||||
|
||||
projMatrix = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 1000.0f);
|
||||
|
||||
roll = 0.0f;
|
||||
pitch = 0.0f;
|
||||
yaw = 0.0f;
|
||||
|
||||
Position = {};
|
||||
LookDirection = {};
|
||||
|
||||
viewMatrix = {};
|
||||
|
||||
}
|
||||
|
||||
Camera::Camera(int w, int h) {
|
||||
|
||||
projMatrix = glm::perspective(glm::radians(45.0f), (float)w / float(h), 0.1f, 1000.0f);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
Camera();
|
||||
Camera(int w, int h);
|
||||
|
||||
void UpdateView();
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "frustrum.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class FrustrumPlane {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ Renderer::Renderer() {
|
||||
}
|
||||
|
||||
// Perform the render passes
|
||||
void Renderer::Render(std::shared_ptr<World> world, std::shared_ptr<Camera> camera) {
|
||||
void Renderer::Render(std::shared_ptr<World> world, std::shared_ptr<Entity> entity) {
|
||||
|
||||
world->Render(camera);
|
||||
world->Render(entity);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
class Camera;
|
||||
class Entity;
|
||||
class World;
|
||||
|
||||
// Does GL render passes then returns to the game loop
|
||||
@@ -11,7 +11,7 @@ class Renderer {
|
||||
public:
|
||||
Renderer();
|
||||
|
||||
void Render(std::shared_ptr<World> world, std::shared_ptr<Camera> camera);
|
||||
void Render(std::shared_ptr<World> world, std::shared_ptr<Entity> entity);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
#include "entity.hpp"
|
||||
|
||||
#include "../renderer/camera.hpp"
|
||||
|
||||
Entity::Entity(glm::vec3 postion, glm::vec3 direction, std::shared_ptr<Camera> camera)
|
||||
: Position(Position)
|
||||
, Direction(direction)
|
||||
, EntityCamera(camera)
|
||||
{
|
||||
|
||||
if (EntityCamera) {
|
||||
EntityCamera->UpdateView();
|
||||
}
|
||||
}
|
||||
|
||||
Player::Player {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,27 +3,49 @@
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
class Camera;
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
|
||||
Entity();
|
||||
Entity(glm::vec3 position, glm::vec3 direction = { 0.0f, 0.0f, 0.0f }, std::shared_ptr<Camera> camera = std::make_shared<Camera>());
|
||||
|
||||
// World position
|
||||
bool Player = false;
|
||||
|
||||
// World position, 1.7 units below the
|
||||
// camera position.
|
||||
glm::vec3 Position;
|
||||
// Look direction
|
||||
// Look direction of the camera
|
||||
glm::vec3 Direction;
|
||||
|
||||
// Velocity in direction
|
||||
// of movement
|
||||
glm::vec3 Velocity;
|
||||
|
||||
// Can be null
|
||||
std::shared_ptr<Camera> EntityCamera;
|
||||
|
||||
// Collider
|
||||
|
||||
|
||||
// Mesh (or reference to)
|
||||
|
||||
};
|
||||
|
||||
|
||||
class Player : public Entity {
|
||||
public:
|
||||
|
||||
Player(glm::vec3 position, glm::vec3 direction = {0.0f, 0.0f, 0.0f});
|
||||
|
||||
void Move(Uint8* state);
|
||||
void HandleMouse(SDL_Event e);
|
||||
|
||||
void UpdatePosition(glm::vec3 position);
|
||||
void UpdateDirection(glm::vec3 direction);
|
||||
|
||||
void CameaUpdateProjection(int xres, int yres);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
|
||||
#include "../renderer/shader.hpp"
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "../util/fastnoise.hpp"
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "entity.hpp"
|
||||
|
||||
World::World() {
|
||||
|
||||
}
|
||||
@@ -87,7 +89,11 @@ std::vector<std::shared_ptr<Chunk>> World::GetRenderableChunks() {
|
||||
|
||||
}
|
||||
|
||||
void World::Render(std::shared_ptr<Camera> camera) {
|
||||
void World::Update(std::shared_ptr<Entity> player) {
|
||||
|
||||
}
|
||||
|
||||
void World::Render(std::shared_ptr<Entity> player) {
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, m_textureMapID);
|
||||
|
||||
@@ -96,7 +102,7 @@ void World::Render(std::shared_ptr<Camera> camera) {
|
||||
|
||||
for (int i = 0; i < chunks.size(); i++) {
|
||||
|
||||
chunks[i]->Render(camera, m_shaders["Basic"]);
|
||||
chunks[i]->Render(player->EntityCamera, m_shaders["Basic"]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
class FastNoise;
|
||||
|
||||
class Shader;
|
||||
class Entity;
|
||||
|
||||
class World {
|
||||
public:
|
||||
@@ -33,8 +34,8 @@ public:
|
||||
|
||||
std::vector<std::shared_ptr<Chunk>> GetRenderableChunks();
|
||||
|
||||
|
||||
void Render(std::shared_ptr<Camera> camera);
|
||||
void Update(std::shared_ptr<Entity> player);
|
||||
void Render(std::shared_ptr<Entity> player);
|
||||
|
||||
~World();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user