Basic Scene creation

This commit is contained in:
2022-07-09 22:21:56 +02:00
parent f8b390923e
commit 6a2e8d3b2f
13 changed files with 80 additions and 108 deletions

View File

@ -15,19 +15,20 @@
void ProcessVertices(aiMesh* mesh, std::vector<BarinkEngine::Vertex>& out_vertices);
void ProcessIndices(aiMesh* mesh, std::vector<unsigned int>& out_indices);
namespace BarinkEngine {
class ModelImporter {
class ModelImporter {
public:
public:
SceneObject* Import(const std::string path);
private:
static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
static std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
SceneObject* Import(const std::string path);
};
private:
static BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene);
static std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene);
};
}

View File

@ -3,13 +3,13 @@
#include <imgui.h>
struct EngineStatistics {
uint32_t lastSampleTime;
long long lastSampleTime;
float frameTime;
uint32_t verts;
uint32_t DC;
uint64_t frames;
uint64_t FPS;
long long frames;
long long FPS;
};
extern EngineStatistics* ES;
@ -18,15 +18,15 @@ inline void PerfomanceSamplerInit(){
ES->frames = 0;
ES->lastSampleTime = 0;
ES->lastSampleTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
}
inline void SamplePerformance(void) {
ES->frames++;
ES->DC = 0;
ES->verts = 0;
unsigned int now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
unsigned int MilliSecondsPast = now - ES->lastSampleTime;
unsigned long long now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
unsigned long long MilliSecondsPast = now - ES->lastSampleTime;
if (MilliSecondsPast >= 1000) {
ES->frameTime = (float)1000 / ES->frames;

View File

@ -13,7 +13,7 @@ public:
Node& GetSceneNode(std::string);
Node& GetRoot();
Scene(std::string SceneName = "Default Scene");
Scene(const std::string& sceneName = "Default Scene");
~Scene();
private:

View File

@ -5,8 +5,8 @@
class Node {
public:
Node(std::string& name);
std::string& name;
Node(const std::string& name);
const std::string& name;
Node* parent;
std::vector<Node*> children;
@ -18,7 +18,7 @@ class Node {
class Group : public Node {
public:
Group(std::string& name);
Group(const std::string& name);
Transform& transform;
};

View File

@ -2,7 +2,7 @@
#include <string>
#include <map>
#include "Scene.h"
static class SceneManager {
class SceneManager {
public:
static Scene* CreateScene(const std::string& name );
@ -12,7 +12,6 @@ public:
private:
static Scene* CurrentScene;
static std::map<std::string, Scene*> Scenes;
static std::map<std::string, Scene*> Scenes;
};

View File

@ -3,20 +3,20 @@
#include "Graphics/Renderable.h"
#include "Scene/Node.h"
class SceneCamera : public Group
{
public:
Camera& camera;
SceneCamera();
};
namespace BarinkEngine {
class SceneCamera : public Group
{
public:
Camera& camera;
SceneCamera();
};
class SceneObject : public Group
{
public:
Renderable& renderable;
SceneObject();
};
class SceneObject : public Group
{
public:
SceneObject(std::string name, Renderable* visual);
~SceneObject();
Renderable* renderable;
};
}

View File

@ -1,13 +1,12 @@
#include "Scene.h"
#include "Scene.h"
#include "Scene/Node.h"
void DeleteSubGraph(Node* tree);
Scene::Scene(std::string sceneName)
Scene::Scene(const std::string& sceneName)
{
// Create a root node
root = new Group(sceneName);
root->name = sceneName;
}
Scene::~Scene()
@ -18,7 +17,7 @@ Scene::~Scene()
}
Node* SearchInChildren(Node* root, std::string name ) {
Node* SearchInChildren(Node* root, const std::string name ) {
if (root->name == name)
return root;

View File

@ -1,7 +1,7 @@
#include "Scene/Node.h"
Node::Node(std::string& name)
Node::Node(const std::string& name)
: name(name), parent(nullptr), children(std::vector<Node*>()) {}
Group::Group(std::string& name )
Group::Group(const std::string& name )
: Node(name), transform(Transform()) {}

View File

@ -2,17 +2,21 @@
Scene* SceneManager::CreateScene(const std::string& name)
{
/*
Scenes = std::map<std::string, Scene*>();
SceneManager::Scenes[name] = new Scene(name);
*/
return &SceneManager::GetScene(name);
return new Scene(name);
}
Scene& SceneManager::GetScene(const std::string& name)
{
return *SceneManager::Scenes[name];
return Scene();
//return *SceneManager::Scenes[name];
}
void SceneManager::LoadScene( Scene& scene)
{
CurrentScene = &scene;
//SceneManager::CurrentScene = &scene;
}

View File

@ -0,0 +1,12 @@
#include "Scene/SceneNodeTypes.h"
BarinkEngine::SceneCamera::SceneCamera()
: Group(std::string("Camera")), camera(Camera(glm::vec3(0.0f), glm::vec3(0.0f), 0))
{}
BarinkEngine::SceneObject::SceneObject(std::string name, Renderable* visual)
: Group(name), renderable(visual)
{}
BarinkEngine::SceneObject::~SceneObject()
{}

View File

@ -1,10 +1,10 @@
#include "AssetManager/ModelImporter.h"
SceneObject* ModelImporter::Import(const std::string path)
BarinkEngine::SceneObject* BarinkEngine::ModelImporter::Import(const std::string path)
{
SceneObject* root = new SceneObject();
SceneObject* root = new SceneObject(std::string(path), nullptr);
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
@ -17,7 +17,7 @@ SceneObject* ModelImporter::Import(const std::string path)
}
std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const aiScene* scene)
std::vector<BarinkEngine::Mesh> BarinkEngine::ModelImporter::processNode(aiNode* node, const aiScene* scene)
{
std::vector<BarinkEngine::Mesh> meshes;
@ -38,7 +38,7 @@ std::vector<BarinkEngine::Mesh> ModelImporter::processNode(aiNode* node, const a
return meshes;
}
BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
BarinkEngine::Mesh BarinkEngine::ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene) {
std::vector<unsigned int> indices;
std::vector<BarinkEngine::Vertex> vertices;

View File

@ -14,7 +14,7 @@ void BarinkEngine::Renderer::Render()
{
for (auto model : models) {
model->Draw();
//model->Draw();
}
}