From 8c9048ef2aab14b0f5784d75a9fa14f0026d23f8 Mon Sep 17 00:00:00 2001 From: Ben Kyd Date: Tue, 11 Feb 2020 14:27:10 +0000 Subject: [PATCH] basic display --- src/display.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ src/display.hpp | 51 ++++++++++++++++++++++++++++++++ src/main.cpp | 1 - 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/display.cpp create mode 100644 src/display.hpp diff --git a/src/display.cpp b/src/display.cpp new file mode 100644 index 0000000..7ef7e76 --- /dev/null +++ b/src/display.cpp @@ -0,0 +1,78 @@ +#include "display.hpp" + +#include + +Aeon::DisplayBuff::DisplayBuff( int wit, int hei ) + : data(nullptr) + , w( wit ), h( hei ) +{ + data = (glm::vec3*)malloc( sizeof(glm::vec3) * (w * h) ); +} + +void Aeon::DisplayBuff::Set( int x, int y, glm::vec3 v ) +{ + data[y * w + x] = v; +} + +glm::vec3 Aeon::DisplayBuff::At( int x, int y ) +{ + return data[y * w + x]; +} + +Aeon::DisplayBuff::~DisplayBuff() +{ + free( data ); +} + + +Aeon::Display::Display() +{ + +} + +void Aeon::Display::Init( int x, int y ) +{ + this->Construct( x, y, 1, 1 ); + mW = x; mH = y; +} + +void Aeon::Display::Init( int x, int y, std::string title ) +{ + sAppName = title; + this->Construct( x, y, 1, 1 ); + mW = x; mH = y; +} + +void Aeon::Display::SetTitle( std::string title ) +{ + sAppName = title; +} + +void Aeon::Display::NewFrame( DisplayBuff* buf ) +{ + if ( buf->w != mW || buf->h != mH ) + return; + mNextFrame = buf; + mNewFrame = true; +} + +bool Aeon::Display::OnUserCreate() +{ + return true; +} + +bool Aeon::Display::OnUserUpdate( float fElapsedTime ) +{ + // Check if theres a more recent framebuffer + // then apply it + + if ( mNewFrame ) + { + + + mNextFrame = nullptr; + mNewFrame = false; + } + + return true; +} diff --git a/src/display.hpp b/src/display.hpp new file mode 100644 index 0000000..5f80f66 --- /dev/null +++ b/src/display.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include + +#include +#include + +#include + +namespace Aeon +{ + +struct DisplayBuff +{ + DisplayBuff( int w, int h ); + glm::vec3* data; + int w, h; + void Set( int x, int y, glm::vec3 v ); + glm::vec3 At( int x, int y ); + ~DisplayBuff(); +}; + +// Can be replaced with literally anything +// for the time being NEEDS to run on main thread +class Display : public olc::PixelGameEngine +{ + + Display(); + void Init( int x, int y ); + void Init( int x, int y, std::string title ); + + void SetTitle( std::string title ); + + void NewFrame( DisplayBuff* buf ); + +private: + // Cleared every swap + std::mutex mFrameMutex; + DisplayBuff* mNextFrame = nullptr; + bool mNewFrame = false; + + + int mW, mH; + +protected: + bool OnUserCreate() override; + bool OnUserUpdate( float fElapsedTime ) override; + +}; + +} diff --git a/src/main.cpp b/src/main.cpp index b5686c9..c2decdf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,4 @@ #define OLC_PGE_APPLICATION -#include class Application : public olc::PixelGameEngine {