basic display

This commit is contained in:
Ben Kyd
2020-02-11 14:27:10 +00:00
parent 7e0629e785
commit 8c9048ef2a
3 changed files with 129 additions and 1 deletions

78
src/display.cpp Normal file
View File

@@ -0,0 +1,78 @@
#include "display.hpp"
#include <memory>
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;
}

51
src/display.hpp Normal file
View File

@@ -0,0 +1,51 @@
#pragma once
#include <olcPixelGameEngine.hpp>
#include <string>
#include <mutex>
#include <glm/vec3.hpp>
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;
};
}

View File

@@ -1,5 +1,4 @@
#define OLC_PGE_APPLICATION
#include <olcPixelGameEngine.hpp>
class Application : public olc::PixelGameEngine
{