This commit is contained in:
2024-01-14 11:56:47 -05:00
parent 402874e23e
commit e4d36da95f
14 changed files with 64 additions and 44 deletions

View File

@@ -1,11 +1,11 @@
#pragma once
#include <cstdint>
#include <cstring>
#include <iostream>
#include <fstream>
#include <GL/gl.h>
#include <rewindow/types/window.h>
#include <engine/world.h>
enum class GAMESTATE: uint8_t {
NORMAL = 0, //Gameplay.
IN_MAIN_MENU = 1,
@@ -21,6 +21,7 @@ public:
//uint16_t minimumTickDelta = 15625;
//float tickDelta = NULL;
bool fullscreen;
World* world;
bool debug = true;
uint64_t tickCount = 0;
uint64_t frameCount = 0;

13
include/engine/world.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
#include <types/entityList.h>
class World {
private:
EntityList eList;
public:
EntityList* entityList();
std::string name;
[[nodiscard]] static int getEntityCount();
[[nodiscard]] static int getMobyCount();
};

View File

@@ -2,7 +2,6 @@
#include <types/moby.h>
#include <types/player.h>
#include <engine/engine.h>
#include <types/entityList.h>
#include <GL/glu.h>
#include <J3ML/Geometry.h>

View File

@@ -1,20 +1,9 @@
#pragma once
#include <vector>
#include "entity.h"
#include <types/entity.h>
//the primary entity list.
inline std::vector<Entity*> entityList;
inline bool storeEntity(Entity* e) {
// TODO: Check if entity is already in list
if (std::ranges::find(entityList, e) != entityList.end())
{ return false; }
entityList.push_back(e);
return true;
}
inline Entity* getFirstByName(const std::string& name);
inline Entity* getByUUID(uint64_t uuid);
class EntityList {
public:
std::vector<Entity*> list;
bool storeEntity(Entity* entity);
};

View File

@@ -3,10 +3,9 @@
#include <iostream>
#include <cmath>
#include <types/collision/collision.h>
#include "moby.h"
#include "entityList.h"
#include "../engine/engine.h"
#include "vertex.h"
#include <types/moby.h>
#include <engine/engine.h>
#include <types/vertex.h>
class Player : public Moby {
public:
bool alive;
@@ -62,7 +61,7 @@ public:
// Shit like this is just my
inline Player* getPlayer() {
for (auto& e : entityList)
for (auto& e : engine->world->entityList()->list)
if (auto* p = dynamic_cast<Player*>(e) )
return p;
std::cerr << "Attempt to get Player pointer while not in scene." << std::endl;

View File

@@ -1,5 +0,0 @@
#pragma once
namespace World {
}

View File

@@ -1,9 +1,7 @@
#include <engine/engine.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <sstream>
#include <thread>
void Engine::quit() {
window->destroyWindow();
@@ -19,6 +17,7 @@ float Engine::getGLVersion()
void Engine::initGL()
{
world = new(World);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -0.5f, 0.5f);

View File

@@ -1,10 +1,7 @@
#include <engine/occlusion.h>
#include <engine/engine.h>
#include <types/entity.h>
#include <types/entityList.h>
#include <J3ML/Geometry.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include "J3ML/LinearAlgebra/Vector3.h"
bool Occlusion::frustumCull(Camera* camera, Entity* entity) {
Geometry::Frustum frustum = camera->getFrustum();

View File

@@ -13,23 +13,23 @@ void Render::pre_render() {
engine->initGL();
engine->loadConfig();
auto *camera = new Camera();
storeEntity(camera);
engine->world->entityList()->storeEntity(camera);
getCamera()->position = {0.0f, -2.0f, -5.0f};
getCamera()->angle.y = 0.0f;
getCamera()->sMove.load("assets/scriptedMove/default.smov");
auto *skybox = new Skybox();
skybox->draw = true;
storeEntity(skybox);
engine->world->entityList()->storeEntity(skybox);
auto *player = new Player();
player->angle = {0, 0, 0};
player->draw = true;
storeEntity(player);
engine->world->entityList()->storeEntity(player);
}
//std::cout << engine->frameCount << std::endl;
engine->window->pollEvents();
engine->frameCount++;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (auto& e : entityList)
for (auto& e : engine->world->entityList()->list)
e->pre_render();
}
@@ -37,14 +37,14 @@ void Render::render() {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//TODO: *Always* render the camera first.
for (auto& e : entityList) {
for (auto& e : engine->world->entityList()->list) {
if (e->draw)
e->render();
}
}
void Render::post_render() {
for (auto& e : entityList)
for (auto& e : engine->world->entityList()->list)
e->post_render();
//Reset all the transformations for the next frame.

20
src/engine/world.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include <engine/engine.h>
#include <engine/world.h>
#include <types/moby.h>
EntityList* World::entityList() {
return &eList;
}
int World::getEntityCount() {
return engine->world->eList.list.size();
}
int World::getMobyCount() {
int count;
for (auto& e : engine->world->entityList()->list)
if (auto* c = dynamic_cast<Moby*>(e))
count++;
return count;
}

View File

@@ -113,7 +113,7 @@ Geometry::Frustum Camera::getFrustum() {
//TODO: Make it such that we don't have to do this.
Camera* getCamera() {
for (auto& e : entityList)
for (auto& e : engine->world->entityList()->list)
if (auto* c = dynamic_cast<Camera*>(e))
return c;
std::cerr << "Attempt to get Camera pointer while not in scene." << std::endl;

9
src/types/entityList.cpp Normal file
View File

@@ -0,0 +1,9 @@
#include <types/entityList.h>
bool EntityList::storeEntity(Entity *entity) {
if (std::ranges::find(list, entity) != list.end()) {
return false;
}
list.push_back(entity);
return true;
}

View File

@@ -1,6 +1,6 @@
#include <types/skybox.h>
#include <types/entityList.h>
#include <engine/engine.h>
void Skybox::pre_render() {
//PLACEHOLDER.
if (engine->frameCount == 1) {
@@ -17,7 +17,7 @@ void Skybox::render() {
}
Skybox* getSkybox() {
for (auto& e : entityList)
for (auto& e : engine->world->entityList()->list)
if (auto* s = dynamic_cast<Skybox*>(e))
return s;
std::cerr << "Attempt to get Skybox pointer while not in scene." << std::endl;

View File

@@ -1 +0,0 @@
#include <types/world.h>