Entity system at last
This commit is contained in:
13
src/game.cpp
13
src/game.cpp
@@ -83,15 +83,14 @@ void Game::Setup(int w, int h) {
|
||||
*m_logger << LOGGER_ENDL;
|
||||
IsDisplayOpen = true;
|
||||
|
||||
m_player = std::make_shared<Entity>(0, 70, 0);
|
||||
|
||||
m_player->EntityCamera = std::make_shared<Camera>(w, h);
|
||||
std::shared_ptr<Camera> playercamera = std::make_shared<Camera>(w, h);
|
||||
m_player = std::make_shared<Player>(glm::vec3(0), glm::vec3(0), playercamera);
|
||||
|
||||
std::shared_ptr<CBlockDictionary> BlockDictionary = CBlockDictionary::GetInstance();
|
||||
|
||||
BlockDictionary->Build();
|
||||
|
||||
m_world = std::make_unique<World>();
|
||||
m_world = std::make_shared<World>();
|
||||
|
||||
Texture texture;
|
||||
m_world->SetTextureMap(texture.LoadTextures(BlockDictionary->Textures));
|
||||
@@ -132,7 +131,7 @@ void Game::Input(SDL_Event* e) {
|
||||
|
||||
if (e->window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
|
||||
m_player->EntityCamera->UpdateProjection(e->window.data1, e->window.data2);
|
||||
m_player->CameraUpdateProjection(e->window.data1, e->window.data2);
|
||||
glViewport(0, 0, e->window.data1, e->window.data2);
|
||||
|
||||
}
|
||||
@@ -152,11 +151,11 @@ void Game::Input(SDL_Event* e) {
|
||||
|
||||
}
|
||||
|
||||
if (IsMouseActive) m_player->EntityCamera->HandleMouse(*e);
|
||||
if (IsMouseActive) m_player->HandleMouseSDL(*e);
|
||||
|
||||
}
|
||||
|
||||
m_player->EntityCamera->MoveCamera(state);
|
||||
m_player->MoveSDL(state);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ class Logger;
|
||||
|
||||
class Renderer;
|
||||
class Camera;
|
||||
class Entity;
|
||||
|
||||
class Player;
|
||||
class World;
|
||||
|
||||
class Game {
|
||||
@@ -44,11 +45,10 @@ private:
|
||||
|
||||
std::shared_ptr<Logger> m_logger;
|
||||
|
||||
|
||||
std::shared_ptr<Renderer> m_renderer;
|
||||
std::shared_ptr<World> m_world;
|
||||
|
||||
std::shared_ptr<Entity> m_player;
|
||||
std::shared_ptr<Player> m_player;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,11 @@ public:
|
||||
glm::vec3 Max;
|
||||
};
|
||||
|
||||
class Collider : public ColliderBox {
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
// TODO: Trees
|
||||
class EntityCollider {
|
||||
public:
|
||||
|
||||
@@ -13,6 +13,8 @@ Camera::Camera() {
|
||||
|
||||
viewMatrix = {};
|
||||
|
||||
UpdateView();
|
||||
|
||||
}
|
||||
|
||||
Camera::Camera(int w, int h) {
|
||||
@@ -28,6 +30,8 @@ Camera::Camera(int w, int h) {
|
||||
|
||||
viewMatrix = {};
|
||||
|
||||
UpdateView();
|
||||
|
||||
}
|
||||
|
||||
void Camera::UpdateView() {
|
||||
@@ -161,6 +165,8 @@ void Camera::UpdatePosition(glm::vec3 position) {
|
||||
|
||||
Position = position;
|
||||
|
||||
UpdateView();
|
||||
|
||||
}
|
||||
|
||||
void Camera::UpdateEulerLookDirection(float roll, float pitch, float yaw) {
|
||||
@@ -170,6 +176,8 @@ void Camera::UpdateEulerLookDirection(float roll, float pitch, float yaw) {
|
||||
LookDirection.y = sin(Yaw) * cos(Pitch);
|
||||
LookDirection.z = sin(Pitch);
|
||||
|
||||
UpdateView();
|
||||
|
||||
}
|
||||
|
||||
void Camera::UpdateLookDirection(glm::vec3 lookDirection) {
|
||||
@@ -178,4 +186,6 @@ void Camera::UpdateLookDirection(glm::vec3 lookDirection) {
|
||||
Pitch = asin(-lookDirection.y);
|
||||
Yaw = atan2(lookDirection.x, lookDirection.z);
|
||||
|
||||
UpdateView();
|
||||
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ public:
|
||||
|
||||
void UpdateProjection(int width, int height);
|
||||
|
||||
void HandleMouse(SDL_Event e);
|
||||
// Keyboard
|
||||
void MoveCamera(Uint8* state);
|
||||
// Mouse
|
||||
void HandleMouse(SDL_Event e);
|
||||
void MouseMoved(glm::vec2 mouseDelta);
|
||||
|
||||
float MouseSensitivity = 0.1f;
|
||||
|
||||
@@ -13,38 +13,47 @@ Entity::Entity(glm::vec3 postion, glm::vec3 direction, std::shared_ptr<Camera> c
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
Player::Player(glm::vec3 position, glm::vec3 direction) {
|
||||
Player::Player(glm::vec3 position, glm::vec3 direction, std::shared_ptr<Camera> camera)
|
||||
: Entity(position, direction, camera) {
|
||||
|
||||
Position = { 0, 64, 0 };
|
||||
EntityCamera->Position = { Position.x, Position.y + EyePosition, Position.z };
|
||||
EntityCamera->UpdateView();
|
||||
|
||||
}
|
||||
|
||||
void Player::Move(Uint8* state) {
|
||||
|
||||
void Player::MoveSDL(Uint8* state) {
|
||||
|
||||
EntityCamera->MoveCamera(state);
|
||||
Position = EntityCamera->Position;
|
||||
Position.y -= EyePosition;
|
||||
|
||||
}
|
||||
|
||||
void Player::HandleMouseSDL(SDL_Event e) {
|
||||
|
||||
}
|
||||
|
||||
void UpdatePosition(glm::vec3 position);
|
||||
void UpdateDirection(glm::vec3 direction);
|
||||
|
||||
void CameaUpdateProjection(int xres, int yres);
|
||||
=======
|
||||
Player::Player(glm::vec3 position, glm::vec3 direction, std::shared_ptr<Camera> camera)
|
||||
: Entity(position, direction, camera) {
|
||||
|
||||
camera->Position =
|
||||
EntityCamera->HandleMouse(e);
|
||||
Direction = EntityCamera->LookDirection;
|
||||
|
||||
}
|
||||
|
||||
Player(glm::vec3 position, glm::vec3 direction = {0.0f, 0.0f, 0.0f});
|
||||
void Player::UpdatePosition(glm::vec3 position) {
|
||||
|
||||
void Move(Uint8* state);
|
||||
void HandleMouse(SDL_Event e);
|
||||
Position = position;
|
||||
EntityCamera->UpdatePosition({ Position.x, Position.y + EyePosition, Position.z });
|
||||
|
||||
void UpdatePosition(glm::vec3 position);
|
||||
void UpdateDirection(glm::vec3 direction);
|
||||
}
|
||||
|
||||
void CameaUpdateProjection(int xres, int yres);
|
||||
>>>>>>> 0b6a3b520cd2e51e4d8cf7716ec4ddcf51297e2e
|
||||
|
||||
void Player::UpdateDirection(glm::vec3 direction) {
|
||||
|
||||
Direction = direction;
|
||||
EntityCamera->UpdateLookDirection(direction);
|
||||
|
||||
}
|
||||
|
||||
void Player::CameraUpdateProjection(int xres, int yres) {
|
||||
|
||||
EntityCamera->UpdateProjection(xres, yres);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
class Camera;
|
||||
|
||||
class Collider;
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
|
||||
@@ -15,7 +17,6 @@ public:
|
||||
glm::vec3 Position;
|
||||
// Look direction of the camera
|
||||
glm::vec3 Direction;
|
||||
|
||||
// Velocity in direction
|
||||
// of movement
|
||||
glm::vec3 Velocity;
|
||||
@@ -24,25 +25,26 @@ public:
|
||||
std::shared_ptr<Camera> EntityCamera;
|
||||
|
||||
// Collider
|
||||
|
||||
// std::unique_ptr<Collider> EntityCollider;
|
||||
|
||||
// Mesh (or reference to)
|
||||
|
||||
};
|
||||
|
||||
|
||||
class Player : public Entity {
|
||||
public:
|
||||
|
||||
Player(glm::vec3 position, glm::vec3 direction, std::shared_ptr<Camera> camera);
|
||||
|
||||
void Move(Uint8* state);
|
||||
float EyePosition = 1.7f;
|
||||
|
||||
void MoveSDL(Uint8* state);
|
||||
void HandleMouseSDL(SDL_Event e);
|
||||
|
||||
void UpdatePosition(glm::vec3 position);
|
||||
void UpdateDirection(glm::vec3 direction);
|
||||
|
||||
void CameaUpdateProjection(int xres, int yres);
|
||||
void CameraUpdateProjection(int xres, int yres);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user