Made multiple managers for individual pieces

Added UIManager that renders the UI inside the window
This commit is contained in:
2022-05-28 18:49:08 +02:00
parent dae8830e2b
commit 76c051e407
18 changed files with 358 additions and 197 deletions

View File

@ -1,31 +1,64 @@
#include "BarinkEngine.h"
#include <imgui.h>
extern void Start(int argc, char* argv[]);
extern void UpdateApplication();
extern void Update();
extern void Stop();
using namespace BarinkEngine;
void DrawMyGUI();
bool ShouldQuit = false;
BarinkWindow* MainWindow;
int main(int argc, char* argv[]) {
// Start Engine
Engine::Startup();
// Startup services
MainWindow = new BarinkWindow(800, 600);
Renderer renderer = Renderer();
InputManager InputSystem = InputManager();
InputSystem.attach(MainWindow);
GUIManager GUISystem = GUIManager(MainWindow);
// First call to setup game
Start(argc, argv);
while (!ShouldQuit) {
//InputManager::PollEvents();
// Runtime loop
while (!MainWindow->WindowShouldClose()) {
InputSystem.PollEvents();
Update();
UpdateApplication();
renderer.Render();
DrawMyGUI();
GUISystem.Render();
MainWindow->SwapBuffers();
}
// Shutdown game
Stop();
// Kill Engine
Engine::Shutdown();
// Shutdown Services
delete MainWindow;
return 0;
}
@ -33,5 +66,41 @@ int main(int argc, char* argv[]) {
void WARN(std::string message) {
spdlog::warn(message);
}
void DrawMyGUI() {
ImGui::NewFrame();
ImGui::Begin("Transform");
ImGui::Text("Cube");
/*
ImGui::InputFloat3("Position:", (float*)nullptr);
ImGui::InputFloat3("Rotation:", (float*)nullptr);
ImGui::InputFloat3("Scale:", (float*)nullptr);
*/
ImGui::End();
ImGui::Begin("Camera");
//ImGui::SliderFloat("Zoom:", &NULL, 10, 190);
ImGui::End();
ImGui::Begin("Scripting!!");
//ImGui::InputTextMultiline("Lua Script", nullptr, 255);
//runCode = ImGui::Button("Run");
ImGui::End();
ImGui::ShowDemoWindow();
}

View File

@ -1,10 +0,0 @@
#include "include/BarinkEngine.h"
namespace BarinkEngine {
void Engine::Startup() {
std::cout << "Starting Engine! vroom vroom!" << std::endl;
}
void Engine::Shutdown() {
std::cout << "ShutDown Engine!" << std::endl;
}
};

View File

@ -3,23 +3,18 @@
#include <string>
#include <filesystem>
#include "Engine.h"
#include "glm/glm.hpp"
#include "graphics/Shader.h"
#include "graphics/Window.h"
#include "graphics/Camera.h"
#include "graphics/Renderable.h"
#include "spdlog/spdlog.h"
#include "MemoryManager.h"
#include "Input/InputManager.h"
#include "Graphics/Renderer.h"
#include "Graphics/GUI/GUIManager.h"
void WARN(std::string message);
extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
}
void WARN(std::string message);

View File

@ -1,10 +0,0 @@
#pragma once
namespace BarinkEngine {
class Engine {
public:
static void Startup();
static void Shutdown();
};
};

View File

@ -0,0 +1,15 @@
#pragma once
#include "Graphics/Window.h"
class GUIManager {
public:
GUIManager(BarinkWindow* window);
~GUIManager();
void Render();
private:
BarinkWindow* currentwindow;
};

View File

@ -13,10 +13,6 @@
*/
class Renderable {
private:
std::vector<BarinkEngine::Mesh> meshes;
Renderable();
public:
Buffer vertexBuffer;
Buffer elementBuffer;
@ -27,4 +23,7 @@ public:
static Renderable Load();
void Draw();
private:
std::vector<BarinkEngine::Mesh> meshes;
Renderable();
};

View File

@ -0,0 +1,21 @@
#pragma once
#include "Graphics/Renderable.h"
#include <vector>
namespace BarinkEngine {
class Renderer {
public:
Renderer();
~Renderer();
void Render();
void Submit(Renderable* model);
private:
std::vector<Renderable*> models;
};
}

View File

@ -0,0 +1,18 @@
#pragma once
#include <vector>
#include "Graphics/Window.h"
namespace BarinkEngine {
class InputManager {
public:
InputManager();
void PollEvents();
void attach(BarinkWindow* window);
private:
std::vector<BarinkWindow*> windows;
};
}

View File

@ -1,17 +0,0 @@
#pragma once
#include <iostream>
#include <stdlib.h>
static int HeapAllocations = 0;
static int HeapDeallocations = 0;
inline void* operator new(std::size_t sz) {
HeapAllocations++;
return std::malloc(sz);
}
inline void operator delete(void* ptr) noexcept {
HeapDeallocations++;
std::free(ptr);
}

View File

@ -0,0 +1,28 @@
#pragma once
#include <string>
extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
}
#include "LuaScriptingManager.h"
/*
class LuaScript {
public:
LuaScript(const std::string&);
void execute(lua_State& l);
private:
std::string filePath;
};
*/

View File

@ -0,0 +1,28 @@
#pragma once
#include <vector>
extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
}
#include "LuaScript.h"
/*
class LuaScriptingManager
{
public:
std::vector<LuaScript*> scripts;
LuaScriptingManager();
void ExecuteLuaString(const std::string&);
private:
lua_State* L;
lua_State& getState();
};*/

View File

@ -0,0 +1,19 @@
#include "Input/InputManager.h"
void BarinkEngine::InputManager::PollEvents()
{
for (std::vector<BarinkWindow*>::iterator it = windows.begin(); it != windows.end(); ++it) {
(*it)->Poll();
}
}
void BarinkEngine::InputManager::attach(BarinkWindow* window)
{
windows.push_back(window);
}
BarinkEngine::InputManager::InputManager()
{
windows = std::vector<BarinkWindow*>();
}

View File

@ -0,0 +1,11 @@
#include "Scripting/LuaScript.h"
/*
LuaScript::LuaScript(const std::string& path)
: filePath(path) {
}
void LuaScript::execute(lua_State& l)
{
luaL_dofile(&l, filePath.c_str());
}
*/

View File

@ -0,0 +1,18 @@
#include "Scripting/LuaScriptingManager.h"
/*
LuaScriptingManager::LuaScriptingManager()
{
L = luaL_newstate();
luaL_openlibs(L);
}
void LuaScriptingManager::ExecuteLuaString(const std::string& code) {
luaL_dostring(L, code.c_str());
}
lua_State& LuaScriptingManager::getState()
{
return (*L);
}
*/

View File

@ -0,0 +1,38 @@
#include "Graphics/GUI/GUIManager.h"
#include "imgui.h"
#include "backends/imgui_impl_opengl3.h"
#include <backends/imgui_impl_glfw.cpp>
GUIManager::GUIManager(BarinkWindow* window)
: currentwindow(window)
{
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
(void)io;
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(currentwindow->windowptr(), true);
ImGui_ImplOpenGL3_Init("#version 440");
ImGui_ImplGlfw_NewFrame();
ImGui_ImplOpenGL3_NewFrame();
}
GUIManager::~GUIManager()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
void GUIManager::Render()
{
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}

View File

@ -0,0 +1,24 @@
#include "Graphics/Renderer.h"
BarinkEngine::Renderer::Renderer()
{
models = std::vector<Renderable*>();
}
BarinkEngine::Renderer::~Renderer()
{
// CleanUp!
}
void BarinkEngine::Renderer::Render()
{
for (auto model : models) {
model->Draw();
}
}
void BarinkEngine::Renderer::Submit(Renderable* model)
{
models.push_back(model);
}

View File

@ -1,12 +1,14 @@
#include "Graphics/Window.h"
#include <stdlib.h>
#include <stdio.h>
#include <GLFW/glfw3.h>
#include <spdlog/spdlog.h>
bool BarinkWindow::InitGLFW(){
if(!glfwInit())
{
// spdlog::error("Failed to initialise GLFW!");
spdlog::error("Failed to initialise GLFW!");
return false;
}
@ -23,7 +25,7 @@ Width(width), Height(height), FullScreen(false){
if( !window)
{
// spdlog::error("GLFW failed to create window!");
spdlog::error("GLFW failed to create window!");
glfwTerminate();
return;
}
@ -43,8 +45,6 @@ Width(width), Height(height), FullScreen(false){
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
}
@ -63,8 +63,7 @@ bool BarinkWindow::WindowShouldClose(){
}
void BarinkWindow::Poll()
{
{
glfwPollEvents();
}