Fixed an include paradox

This commit is contained in:
2023-11-19 13:32:14 -05:00
parent c85adb2a55
commit 5d02e8abe0
6 changed files with 37 additions and 37 deletions

View File

@@ -44,7 +44,7 @@ void pre_render() {
engine->initGL();
auto camera = new(Camera);
entityList.storeEntity(camera);
entityList.getCamera()->position.set(0.0f,0.0f,5.0f);
getCamera()->position.set(0.0f,0.0f,5.0f);
auto skybox = new(Skybox);
entityList.storeEntity(skybox);
}
@@ -52,16 +52,14 @@ void pre_render() {
process_sdl_events();
engine->frameCount++;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
entityList.getSkybox()->position.x = entityList.getCamera()->position.x;
entityList.getSkybox()->position.z = entityList.getCamera()->position.z;
entityList.getSkybox()->position.y = entityList.getCamera()->position.y;
}
void render() {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
entityList.getCamera()->render();
entityList.getSkybox()->render();
//*Always* render the camera first.
getCamera()->render();
getSkybox()->render();
glPushMatrix();
glBegin(GL_QUADS);
glColor3f(1,0.5,1);

View File

@@ -3,6 +3,7 @@
#include <thread>
#include "engine.h"
#include "../types/entityList.h"
#include "../types/camera.h"
[[noreturn]] void gameTick() {
while (true) {
@@ -27,7 +28,7 @@
if (engine->tickCount % 64 == 0)
engine->debugInfo();
if(engine->frameCount > 0)
entityList.getCamera()->update();
getCamera()->update();
auto stop = std::chrono::high_resolution_clock::now();
//limit to 64 ticks per second.
if ((int) engine->tickDelta < engine->minimumTickDelta)

View File

@@ -1,6 +1,7 @@
#pragma once
#include "moby.h"
#include "../engine/engine.h"
#include "entityList.h"
enum class CAMERAMODE: uint8_t {
FREECAM = 0,
@@ -38,7 +39,7 @@ public:
//My axis are flipped????
this->position.z += speed * forwardDirection.x;
this->position.x += speed * forwardDirection.z;
this->position.y += speed * forwardDirection.y;
this->position.y += speed * -forwardDirection.y;
}
void move(float x, float y, float z) {
@@ -107,4 +108,10 @@ public:
std::cout << "X: " << position.x << " Y: " << position.y << " Z: " << position.z << std::endl;
std::cout << "Pitch: " << angles.x << " Yaw: " << angles.y << " Roll: " << angles.z << std::endl;
}
};
};
inline Camera* getCamera() {
for (auto& e : entityList.list)
if (auto* c = dynamic_cast<Camera*>(e))
return dynamic_cast<Camera *>(e);
}

View File

@@ -1,36 +1,16 @@
#pragma once
#include <vector>
#include "entity.h"
#include "player.h"
#include "camera.h"
#include "skybox.h"
class entitylist {
class EntityList {
public:
std::vector<Entity*> list;
inline Player* getPlayer() {
for (auto& e : this->list)
if (auto* p = dynamic_cast<Player*>(e) )
return dynamic_cast<Player *>(e);
}
inline Camera* getCamera() {
for (auto& e : this->list)
if (auto* p = dynamic_cast<Camera*>(e) )
return dynamic_cast<Camera *>(e);
}
inline Skybox* getSkybox() {
for (auto& e : this->list)
if (auto* p = dynamic_cast<Skybox*>(e) )
return dynamic_cast<Skybox *>(e);
}
inline void storeEntity(Entity* e) {
this->list.push_back(e);
}
};
//the primary entity list.
entitylist entityList;
EntityList entityList;

View File

@@ -1,6 +1,6 @@
#pragma once
#include "moby.h"
#include "entityList.h"
class Player : public Moby {
public:
bool alive;
@@ -18,4 +18,10 @@ public:
void render() {
}
};
};
inline Player* getPlayer() {
for (auto& e : entityList.list)
if (auto* p = dynamic_cast<Player*>(e) )
return dynamic_cast<Player *>(e);
}

View File

@@ -1,9 +1,10 @@
#pragma once
#include <SDL2/SDL_opengl.h>
#include "moby.h"
#include "geometry.h"
#include "entityList.h"
#include "moby.h"
#include "camera.h"
class Skybox : public Moby {
public:
const Geometry geometry = {
@@ -46,7 +47,8 @@ public:
//TODO: Teleport the sphere such that the center of the sphere is the cameras position every frame.
glPushMatrix();
glColor3f(1,0,0);
glTranslatef(position.x,position.y+10,position.z);
this->position.set(getCamera()->position);
glTranslatef(position.x,position.y+2,position.z);
glBegin(GL_QUADS);
glColor3f(1,0,0);
// Front face
@@ -88,4 +90,10 @@ public:
glPopMatrix();
}
};
};
inline Skybox* getSkybox() {
for (auto& e : entityList.list)
if (auto* s = dynamic_cast<Skybox*>(e) )
return dynamic_cast<Skybox *>(e);
}