Skip to content
This repository was archived by the owner on Nov 14, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Gamebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
namespace gamebase
{
Gamebase::Gamebase(std::unique_ptr<TimerBase> timerImplementation)
: timer(std::move(timerImplementation)), _shouldQuit(false)
: timer(std::move(timerImplementation)),
graphicsDevice(nullptr), _shouldQuit(false)
{

}
Expand All @@ -22,13 +23,22 @@ namespace gamebase
// Initialization failed
return;
}

if(this->graphicsDevice == nullptr)
{
// Graphics device is not set
// TODO: Throw an exception here
return;
}

this->Load();
while(!shouldQuit())
{
timer->Start();
this->Update();
this->graphicsDevice->Clear();
this->Draw();
this->graphicsDevice->Clear();
timer->Stop();

// Wait until the time for the given frame is elapsed
Expand Down
6 changes: 6 additions & 0 deletions Gamebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

// Include utilities
#include "utils/TimerBase.h"
#include "utils/IGraphicsDevice.h"

#include <memory>

Expand All @@ -45,6 +46,7 @@ namespace gamebase {
protected:
std::unique_ptr<TimerBase> timer;
bool shouldQuit();
std::unique_ptr<IGraphicsDevice> graphicsDevice;

public:
Gamebase(std::unique_ptr<TimerBase> timerImplementation);
Expand All @@ -56,5 +58,9 @@ namespace gamebase {
void Run(unsigned int fps);

virtual void Quit();
void registerGraphicsDevice(std::unique_ptr<IGraphicsDevice> graphicsDevice)
{
this->graphicsDevice = std::move(graphicsDevice);
}
};
}
11 changes: 11 additions & 0 deletions utils/IGraphicsDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace gamebase
{
class IGraphicsDevice
{
public:
virtual void Clear() = 0;
virtual void Draw() = 0;
};
}