Part one - removed references and smart pointers

This commit is contained in:
2022-11-11 19:08:46 -08:00
parent e892224900
commit e6d475d170
76 changed files with 3899 additions and 3707 deletions

View File

@ -17,6 +17,7 @@ target_include_directories(${DAWN_TARGET_NAME}
) )
# Subdirs # Subdirs
add_subdirectory(assert)
add_subdirectory(asset) add_subdirectory(asset)
add_subdirectory(display) add_subdirectory(display)
add_subdirectory(input) add_subdirectory(input)

View File

@ -3,7 +3,7 @@
# This software is released under the MIT License. # This software is released under the MIT License.
# https://opensource.org/licenses/MIT # https://opensource.org/licenses/MIT
target_sources(${PROJECT_NAME} target_sources(${DAWN_TARGET_NAME}
PRIVATE PRIVATE
assert.cpp assert.cpp
) )

View File

@ -27,15 +27,11 @@
} }
void assertNotNull(const void *pointer) { void assertNotNull(const void *pointer) {
assertTrue(pointer != NULL); assertTrue(pointer != nullptr && pointer != NULL);
}
void assertNotNullptr(const void *ptr) {
assertTRue(ptr != nullptr);
} }
void assertNull(const void *pointer) { void assertNull(const void *pointer) {
assertTrue(pointer == NULL); assertTrue(pointer == NULL || pointer == nullptr);
} }
void assertDeprecated() { void assertDeprecated() {

View File

@ -13,11 +13,6 @@
#if ASSERTS_ENABLED == 0 #if ASSERTS_ENABLED == 0
static inline void assertTrue(bool_t x) {} static inline void assertTrue(bool_t x) {}
static inline void assertFalse(bool_t x) {}
static inline void assertUnreachable() {}
static inline void assertNotNull(const void *pointer) {}
static inline void assertNull(const void *pointer) {}
static inline void assertDeprecated() {}
#elif ASSERTS_ENABLED == 1 #elif ASSERTS_ENABLED == 1
@ -45,13 +40,6 @@ static inline void assertDeprecated() {}
*/ */
void assertNotNull(const void *pointer); void assertNotNull(const void *pointer);
/**
* Asserts a given pointer to not be a C++ nullptr.
*
* @param ptr Pointer to assert not nullptr.
*/
void assertNotNullptr(const void *ptr);
/** /**
* Asserts a given pointer to be a nullptr. * Asserts a given pointer to be a nullptr.
* @param pointer Pointer to assert is nullptr. * @param pointer Pointer to assert is nullptr.
@ -66,9 +54,5 @@ static inline void assertDeprecated() {}
#else #else
#define assertTrue assert #define assertTrue assert
#define assertFalse(x) assertTrue(x == 0)
#define assertNotNull(x) assert(x != NULL)
#define assertUnreachable() assert(false)
#define assertDeprecated assertUnreachable
#endif #endif

View File

@ -7,9 +7,11 @@
using namespace Dawn; using namespace Dawn;
Asset::Asset(AssetManager &assetManager, std::string name) : Asset::Asset(AssetManager *assetManager, std::string name) {
assetManager(assetManager) assertTrue(name.size() > 0);
{ assertNotNull(assetManager);
this->assetManager = assetManager;
this->name = name; this->name = name;
} }

View File

@ -5,13 +5,14 @@
#pragma once #pragma once
#include "dawnlibs.hpp" #include "dawnlibs.hpp"
#include "assert/assert.hpp"
namespace Dawn { namespace Dawn {
class AssetManager; class AssetManager;
class Asset { class Asset {
public: public:
AssetManager &assetManager; AssetManager *assetManager;
std::string name; std::string name;
uint8_t state = 0x00; uint8_t state = 0x00;
bool loaded = false; bool loaded = false;
@ -22,7 +23,7 @@ namespace Dawn {
* @param assetManager Asset manager that this asset belongs to. * @param assetManager Asset manager that this asset belongs to.
* @param name Name of the asset. * @param name Name of the asset.
*/ */
Asset(AssetManager &assetManager, std::string name); Asset(AssetManager *assetManager, std::string name);
/** /**
* Virtual function that will be called by the asset manager on a * Virtual function that will be called by the asset manager on a

View File

@ -8,47 +8,59 @@
using namespace Dawn; using namespace Dawn;
AssetLoader::AssetLoader(std::string fileName) { AssetLoader::AssetLoader(std::string fileName) {
assertTrue(fileName.size() > 0);
this->fileName = fileName; this->fileName = fileName;
this->handle = nullptr; this->handle = nullptr;
} }
void AssetLoader::open() { void AssetLoader::open() {
assertNull(this->handle);
std::string pathFull = DAWN_ASSET_BUILD_PREFIX + this->fileName; std::string pathFull = DAWN_ASSET_BUILD_PREFIX + this->fileName;
this->handle = fopen(pathFull.c_str(), "rb"); this->handle = fopen(pathFull.c_str(), "rb");
if(this->handle == NULL || this->handle == nullptr) { assertNotNull(this->handle);
throw "Failed to open file handle for " + this->fileName;
}
} }
int32_t AssetLoader::close() { int32_t AssetLoader::close() {
assertNotNull(this->handle);
int32_t ret = fclose(this->handle); int32_t ret = fclose(this->handle);
this->handle = nullptr; this->handle = nullptr;
return ret; return ret;
} }
size_t AssetLoader::read(uint8_t *buffer, size_t size) { size_t AssetLoader::read(uint8_t *buffer, size_t size) {
assertNotNull(buffer);
assertTrue(size > 0);
assertNotNull(this->handle);
return fread(buffer, 1, size, this->handle); return fread(buffer, 1, size, this->handle);
} }
int32_t AssetLoader::end() { int32_t AssetLoader::end() {
assertNotNull(this->handle);
return fseek(this->handle, 0, SEEK_END); return fseek(this->handle, 0, SEEK_END);
} }
size_t AssetLoader::skip(size_t n) { size_t AssetLoader::skip(size_t n) {
assertTrue(n > 0);
assertNotNull(this->handle);
return fseek(this->handle, n, SEEK_CUR); return fseek(this->handle, n, SEEK_CUR);
} }
int32_t AssetLoader::rewind() { int32_t AssetLoader::rewind() {
assertNotNull(this->handle);
return fseek(this->handle, 0, SEEK_SET); return fseek(this->handle, 0, SEEK_SET);
} }
size_t AssetLoader::getPosition() { size_t AssetLoader::getPosition() {
assertNotNull(this->handle);
return ftell(this->handle); return ftell(this->handle);
} }
size_t AssetLoader::loadRaw(uint8_t **buffer) { size_t AssetLoader::loadRaw(uint8_t **buffer) {
size_t length, read; size_t length, read;
assertNotNull(buffer);
// Open a buffer. // Open a buffer.
this->open(); this->open();

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include "dawnlibs.hpp" #include "dawnlibs.hpp"
#include "assert/assert.hpp"
#include "util/memory.hpp" #include "util/memory.hpp"
namespace Dawn { namespace Dawn {
@ -93,6 +94,9 @@ namespace Dawn {
int32_t i; int32_t i;
bool result; bool result;
assertNotNull(instance);
assertNotNull(callback);
// Open the buffer. // Open the buffer.
this->open(); this->open();

View File

@ -29,9 +29,24 @@ void AssetManager::update() {
if(asset->loaded) { if(asset->loaded) {
it = this->assetsNotLoaded.erase(it); it = this->assetsNotLoaded.erase(it);
this->assets[asset->name] = asset;
continue; continue;
} }
++it; ++it;
} }
} }
AssetManager::~AssetManager() {
auto it = this->assets.begin();
while(it != this->assets.end()) {
delete it->second;
++it;
}
auto it2 = this->assetsNotLoaded.begin();
while(it2 != this->assetsNotLoaded.end()) {
delete it2->second;
++it2;
}
}

View File

@ -4,14 +4,14 @@
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "asset/Asset.hpp" #include "Asset.hpp"
namespace Dawn { namespace Dawn {
class AssetManager { class AssetManager {
private: private:
/** List of pointers to assets, mapped by their asset key. */ /** List of pointers to assets, mapped by their asset key. */
std::map<std::string, std::shared_ptr<Asset>> assets; std::map<std::string, Asset*> assets;
std::map<std::string, std::shared_ptr<Asset>> assetsNotLoaded; std::map<std::string, Asset*> assetsNotLoaded;
public: public:
void init(); void init();
@ -24,15 +24,19 @@ namespace Dawn {
* @return The asset element to be loaded. * @return The asset element to be loaded.
*/ */
template<class T> template<class T>
std::shared_ptr<T> load(std::string name) { T * load(std::string name) {
assertTrue(name.size() > 0);
auto existing = this->assets.find(name); auto existing = this->assets.find(name);
if(existing != this->assets.end()) { if(existing != this->assets.end()) {
return std::dynamic_pointer_cast<T>(existing->second); return (T*)existing->second;
} }
auto asset = std::make_shared<T>(*this, name); auto asset = new T(this, name);
this->assets[name] = asset; this->assets[name] = asset;
this->assetsNotLoaded[name] = asset; this->assetsNotLoaded[name] = asset;
return asset; return asset;
} }
~AssetManager();
}; };
} }

View File

@ -7,11 +7,11 @@
using namespace Dawn; using namespace Dawn;
TextureAsset::TextureAsset(AssetManager &assetManager, std::string name) : TextureAsset::TextureAsset(AssetManager *assetManager, std::string name) :
Asset(assetManager, name), Asset(assetManager, name),
loader(name + ".texture") loader(name + ".texture"),
texture()
{ {
this->texture = std::make_shared<Texture>();
} }
void TextureAsset::updateSync() { void TextureAsset::updateSync() {
@ -20,8 +20,8 @@ void TextureAsset::updateSync() {
) return; ) return;
this->state = 0x04; this->state = 0x04;
this->texture->setSize(this->width, this->height); this->texture.setSize(this->width, this->height);
this->texture->buffer(this->colors); this->texture.buffer(this->colors);
this->state = 0x05; this->state = 0x05;
this->loaded = true; this->loaded = true;
} }
@ -41,12 +41,12 @@ void TextureAsset::updateAsync() {
integer[j] = '\0'; integer[j] = '\0';
if(this->width == -1) { if(this->width == -1) {
this->width = atoi(integer); this->width = atoi(integer);
if(this->width <= 0) throw "Invalid width"; assertTrue(this->width > 0);
j = 0; j = 0;
continue; continue;
} else { } else {
this->height = atoi(integer); this->height = atoi(integer);
if(this->height <= 0) throw "Invalid height"; assertTrue(this->height > 0);
break; break;
} }
} }

View File

@ -17,13 +17,24 @@ namespace Dawn {
struct Color *colors; struct Color *colors;
public: public:
std::shared_ptr<Texture> texture; Texture texture;
TextureAsset(AssetManager &assetManager, std::string name); /**
* Constructs a texture asset loader. You should instead use the parent
* asset managers' abstracted load method
*
* @param assetManager Asset manager this asset belongs to.
* @param name File name asset to load, omitting the extension.
*/
TextureAsset(AssetManager *assetManager, std::string name);
void updateSync() override; void updateSync() override;
void updateAsync() override; void updateAsync() override;
/**
* Dispose / Cleanup the texture asset. Will also dispose the underlying
* texture itself.
*/
~TextureAsset(); ~TextureAsset();
}; };
} }

View File

@ -7,7 +7,7 @@
using namespace Dawn; using namespace Dawn;
TrueTypeAsset::TrueTypeAsset(AssetManager &assMan, std::string name) : TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) :
Asset(assMan, name), Asset(assMan, name),
loader(name + ".truetype") loader(name + ".truetype")
{ {
@ -23,6 +23,10 @@ void TrueTypeAsset::updateSync() {
this->font.characterData, this->font.characterData,
sizeof(truetypechar_t) * TRUETYPE_NUM_CHARS sizeof(truetypechar_t) * TRUETYPE_NUM_CHARS
); );
memoryFree(this->buffer);
this->buffer = nullptr;
this->state = 0x05; this->state = 0x05;
this->loaded = true; this->loaded = true;
} }
@ -48,14 +52,17 @@ void TrueTypeAsset::updateAsync() {
intBuffer[j] = '\0'; intBuffer[j] = '\0';
if(width == -1) { if(width == -1) {
this->width = atoi(intBuffer); this->width = atoi(intBuffer);
assertTrue(this->width > 0);
j = 0; j = 0;
continue; continue;
} else if(height == -1) { } else if(height == -1) {
this->height = atoi(intBuffer); this->height = atoi(intBuffer);
assertTrue(this->height > 0);
j = 0; j = 0;
continue; continue;
} else { } else {
fontSize = atoi(intBuffer); fontSize = atoi(intBuffer);
assertTrue(fontSize > 0);
break; break;
} }
} }
@ -72,5 +79,8 @@ void TrueTypeAsset::updateAsync() {
} }
TrueTypeAsset::~TrueTypeAsset() { TrueTypeAsset::~TrueTypeAsset() {
if(this->buffer != nullptr) {
memoryFree(this->buffer);
this->buffer = nullptr;
}
} }

View File

@ -20,11 +20,21 @@ namespace Dawn {
public: public:
TrueTypeFont font; TrueTypeFont font;
TrueTypeAsset(AssetManager &assMan, std::string name); /**
* Constructs a new True Type Asset. As with all other assets you should
* instead use the AssetManaager.load method.
*
* @param assMan Asset manager that this asset belongs to.
* @param name Filename of this asset.
*/
TrueTypeAsset(AssetManager *assMan, std::string name);
void updateSync() override; void updateSync() override;
void updateAsync() override; void updateAsync() override;
/**
* Disposes / Cleans up the truetype asset.
*/
~TrueTypeAsset(); ~TrueTypeAsset();
}; };
} }

View File

@ -6,12 +6,13 @@
#include "RenderPipeline.hpp" #include "RenderPipeline.hpp"
#include "game/DawnGame.hpp" #include "game/DawnGame.hpp"
#include "display/mesh/QuadMesh.hpp" #include "display/mesh/QuadMesh.hpp"
#include "scene/SceneItem.hpp"
using namespace Dawn; using namespace Dawn;
RenderPipeline::RenderPipeline(RenderManager &renderManager) : RenderPipeline::RenderPipeline(RenderManager *renderManager) {
renderManager(renderManager) assertNotNull(renderManager);
{ this->renderManager = renderManager;
} }
void RenderPipeline::init() { void RenderPipeline::init() {
@ -19,24 +20,24 @@ void RenderPipeline::init() {
} }
void RenderPipeline::render() { void RenderPipeline::render() {
this->renderScene(*this->renderManager.game.scene); this->renderScene(this->renderManager->game->scene);
} }
void RenderPipeline::renderScene(Scene &scene) { void RenderPipeline::renderScene(Scene *scene) {
RenderTarget &backBuffer = this->renderManager.getBackBuffer(); auto backBuffer = this->renderManager->getBackBuffer();
auto cameras = scene.findComponents<Camera>(); auto cameras = scene->findComponents<Camera>();
std::shared_ptr<Camera> backBufferCamera = nullptr; Camera *backBufferCamera = nullptr;
// First, render all non-backbuffer cameras. // First, render all non-backbuffer cameras.
auto it = cameras.begin(); auto it = cameras.begin();
while(it != cameras.end()) { while(it != cameras.end()) {
RenderTarget &cameraTarget = (*it)->getRenderTarget(); RenderTarget *cameraTarget = (*it)->getRenderTarget();
// Leave the backbuffer camera(s) to last, so we skip them. // Leave the backbuffer camera(s) to last, so we skip them.
if(&cameraTarget == &backBuffer) { if(cameraTarget == backBuffer) {
backBufferCamera = *it; backBufferCamera = *it;
} else { } else {
this->renderSceneCamera(scene, **it); this->renderSceneCamera(scene, *it);
} }
++it; ++it;
@ -44,34 +45,34 @@ void RenderPipeline::renderScene(Scene &scene) {
// Now render the backbuffer camera. // Now render the backbuffer camera.
if(backBufferCamera == nullptr) return; if(backBufferCamera == nullptr) return;
this->renderSceneCamera(scene, *backBufferCamera); this->renderSceneCamera(scene, backBufferCamera);
// Now we try and render UI components // Now we try and render UI components
auto uiCanvasList = scene.findComponents<UICanvas>(); auto uiCanvasList = scene->findComponents<UICanvas>();
auto itCanvas = uiCanvasList.begin(); auto itCanvas = uiCanvasList.begin();
while(itCanvas != uiCanvasList.end()) { while(itCanvas != uiCanvasList.end()) {
this->renderUI(scene, *backBufferCamera, **itCanvas); this->renderUI(scene, backBufferCamera, *itCanvas);
++itCanvas; ++itCanvas;
} }
} }
void RenderPipeline::renderSceneCamera(Scene &scene, Camera &camera) { void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
RenderTarget &renderTarget = camera.getRenderTarget(); RenderTarget *renderTarget = camera->getRenderTarget();
renderTarget.bind(); renderTarget->bind();
renderTarget.clear( renderTarget->clear(
RENDER_TARGET_CLEAR_FLAG_DEPTH | RENDER_TARGET_CLEAR_FLAG_DEPTH |
RENDER_TARGET_CLEAR_FLAG_COLOR RENDER_TARGET_CLEAR_FLAG_COLOR
); );
this->renderManager.setRenderFlags( this->renderManager->setRenderFlags(
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST | RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST |
RENDER_MANAGER_RENDER_FLAG_BLEND RENDER_MANAGER_RENDER_FLAG_BLEND
); );
auto meshes = scene.findComponents<MeshRenderer>(); auto meshes = scene->findComponents<MeshRenderer>();
auto it = meshes.begin(); auto it = meshes.begin();
while(it != meshes.end()) { while(it != meshes.end()) {
auto mesh = *it; auto mesh = *it;
auto material = mesh->item.getComponent<Material>(); auto material = mesh->item->getComponent<Material>();
// TODO: fallback material? // TODO: fallback material?
if(material == nullptr) { if(material == nullptr) {
@ -81,8 +82,8 @@ void RenderPipeline::renderSceneCamera(Scene &scene, Camera &camera) {
auto shader = material->getShader(); auto shader = material->getShader();
shader->bind(); shader->bind();
shader->setGlobalParameters(camera.projection, camera.transform.getWorldTransform()); shader->setGlobalParameters(camera->projection, camera->transform->getWorldTransform());
shader->setMeshParameters(mesh->item.transform.getWorldTransform()); shader->setMeshParameters(mesh->item->transform.getWorldTransform());
material->setShaderParameters(); material->setShaderParameters();
mesh->mesh->draw(MESH_DRAW_MODE_TRIANGLES, 0, -1); mesh->mesh->draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
@ -91,20 +92,20 @@ void RenderPipeline::renderSceneCamera(Scene &scene, Camera &camera) {
} }
void RenderPipeline::renderUI( void RenderPipeline::renderUI(
Scene &scene, Scene *scene,
Camera &camera, Camera *camera,
UICanvas &canvas UICanvas *canvas
) { ) {
// Get the // Get the
RenderTarget *renderTarget; RenderTarget *renderTarget;
glm::mat4 transform; glm::mat4 transform;
glm::mat4 projection; glm::mat4 projection;
switch(canvas.drawType) { switch(canvas->drawType) {
case UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE: case UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE:
transform = glm::mat4(1.0f); transform = glm::mat4(1.0f);
projection = glm::ortho(0.0f, canvas.getWidth(), canvas.getHeight(), 0.0f); projection = glm::ortho(0.0f, canvas->getWidth(), canvas->getHeight(), 0.0f);
renderTarget = &camera.getRenderTarget(); renderTarget = camera->getRenderTarget();
break; break;
default: default:
throw "UI Draw modes are not yet supported."; throw "UI Draw modes are not yet supported.";
@ -116,21 +117,21 @@ void RenderPipeline::renderUI(
RENDER_TARGET_CLEAR_FLAG_DEPTH | RENDER_TARGET_CLEAR_FLAG_DEPTH |
RENDER_TARGET_CLEAR_FLAG_COLOR RENDER_TARGET_CLEAR_FLAG_COLOR
); );
this->renderManager.setRenderFlags( this->renderManager->setRenderFlags(
RENDER_MANAGER_RENDER_FLAG_BLEND | RENDER_MANAGER_RENDER_FLAG_BLEND |
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST
); );
// Prepare the UI Shader // Prepare the UI Shader
auto shader = this->renderManager.getUIShader(); auto shader = this->renderManager->getUIShader();
shader->bind(); shader->bind();
shader->setUICamera(transform, projection); shader->setUICamera(transform, projection);
// Render the children // Render the children
glm::mat4 rootMatrix = canvas.transform.getWorldTransform(); glm::mat4 rootMatrix = canvas->transform->getWorldTransform();
auto it = canvas.children.begin(); auto it = canvas->children.begin();
while(it != canvas.children.end()) { while(it != canvas->children.end()) {
(*it)->draw(*shader, rootMatrix); (*it)->draw(shader, rootMatrix);
++it; ++it;
} }
} }

View File

@ -14,7 +14,7 @@
namespace Dawn { namespace Dawn {
class RenderPipeline { class RenderPipeline {
public: public:
RenderManager &renderManager; RenderManager *renderManager;
/** /**
* Constructs a new RenderPipeline. Render Pipelines are my attempt to * Constructs a new RenderPipeline. Render Pipelines are my attempt to
@ -23,7 +23,7 @@ namespace Dawn {
* *
* @param renderManager Parent render manager this pipeline belongs to. * @param renderManager Parent render manager this pipeline belongs to.
*/ */
RenderPipeline(RenderManager &renderManager); RenderPipeline(RenderManager *renderManager);
/** /**
* Initialize the render pipeline. * Initialize the render pipeline.
@ -41,7 +41,7 @@ namespace Dawn {
* *
* @param scene Scene to render. * @param scene Scene to render.
*/ */
virtual void renderScene(Scene &scene); virtual void renderScene(Scene *scene);
/** /**
* Render a specific camera on a specific scene. * Render a specific camera on a specific scene.
@ -49,7 +49,7 @@ namespace Dawn {
* @param scene Scene to render. * @param scene Scene to render.
* @param camera Camera within the scene to render. * @param camera Camera within the scene to render.
*/ */
virtual void renderSceneCamera(Scene &scene, Camera &camera); virtual void renderSceneCamera(Scene *scene, Camera *camera);
/** /**
* Renders a UI Canvas to the back buffer. * Renders a UI Canvas to the back buffer.
@ -59,9 +59,9 @@ namespace Dawn {
* @param canvas Canvas to render. * @param canvas Canvas to render.
*/ */
virtual void renderUI( virtual void renderUI(
Scene &scene, Scene *scene,
Camera &camera, Camera *camera,
UICanvas &canvas UICanvas *canvas
); );
/** /**

View File

@ -14,7 +14,7 @@
namespace Dawn { namespace Dawn {
class RenderTarget { class RenderTarget {
public: public:
Event<RenderTarget &, float_t, float_t> eventRenderTargetResized; Event<RenderTarget*, float_t, float_t> eventRenderTargetResized;
/** /**
* Return the width of the render target. * Return the width of the render target.

View File

@ -8,11 +8,12 @@
using namespace Dawn; using namespace Dawn;
Transform::Transform(SceneItem &item) : Transform::Transform(SceneItem *item) :
item(item),
transformLocal(1.0f), transformLocal(1.0f),
transformWorld(1.0f) transformWorld(1.0f)
{ {
assertNotNull(item);
this->item = item;
this->updateLocalValuesFromLocalTransform(); this->updateLocalValuesFromLocalTransform();
} }
@ -122,7 +123,7 @@ void Transform::setWorldTransform(glm::mat4 transform) {
void Transform::setParent(Transform *parent) { void Transform::setParent(Transform *parent) {
if(parent == this) throw "Cannot self reference"; assertTrue(parent != this);
auto currentParent = this->getParent(); auto currentParent = this->getParent();
if(currentParent == parent) return; if(currentParent == parent) return;

View File

@ -5,12 +5,13 @@
#pragma once #pragma once
#include "dawnlibs.hpp" #include "dawnlibs.hpp"
#include "assert/assert.hpp"
#include "util/flag.hpp" #include "util/flag.hpp"
namespace Dawn { namespace Dawn {
class SceneItem; class SceneItem;
class Transform : public std::enable_shared_from_this<Transform> { class Transform {
private: private:
// Local (real) values // Local (real) values
glm::vec3 localPosition; glm::vec3 localPosition;
@ -37,7 +38,7 @@ namespace Dawn {
void updateChildrenTransforms(); void updateChildrenTransforms();
public: public:
SceneItem &item; SceneItem *item;
/** /**
* Constructs a new transform instance. Currently I have bound transforms * Constructs a new transform instance. Currently I have bound transforms
@ -48,7 +49,7 @@ namespace Dawn {
* *
* @param item Item that this transform belongs to. * @param item Item that this transform belongs to.
*/ */
Transform(SceneItem &item); Transform(SceneItem *item);
/** /**
* Orients this transform to look at a given point in world space. * Orients this transform to look at a given point in world space.

View File

@ -23,15 +23,18 @@ namespace Dawn {
renderflag_t renderFlags = 0; renderflag_t renderFlags = 0;
public: public:
DawnGame &game; DawnGame *game;
std::shared_ptr<RenderPipeline> renderPipeline; RenderPipeline *renderPipeline;
/** /**
* Default constructor for a render manager instance. * Default constructor for a render manager instance.
* *
* @param game Game that this render manager belongs to. * @param game Game that this render manager belongs to.
*/ */
IRenderManager(DawnGame &game) : game(game) {} IRenderManager(DawnGame *game) {
assertNotNull(game);
this->game = game;
}
/** /**
* Returns the primary render target (the backbuffer) that draws directly * Returns the primary render target (the backbuffer) that draws directly
@ -39,7 +42,7 @@ namespace Dawn {
* *
* @return Shared pointer to the backbuffer render target. * @return Shared pointer to the backbuffer render target.
*/ */
virtual RenderTarget & getBackBuffer() = 0; virtual RenderTarget * getBackBuffer() = 0;
/** /**
* Returns the current render pipeline intended to be used for rendering * Returns the current render pipeline intended to be used for rendering
@ -47,7 +50,7 @@ namespace Dawn {
* *
* @return Reference to the currently active main scene render pipeline. * @return Reference to the currently active main scene render pipeline.
*/ */
virtual RenderPipeline & getRenderPipeline() = 0; virtual RenderPipeline * getRenderPipeline() = 0;
/** /**
* Returns the default shader, the default shader will be applied to the * Returns the default shader, the default shader will be applied to the
@ -55,14 +58,14 @@ namespace Dawn {
* *
* @return Reference to the default shader. * @return Reference to the default shader.
*/ */
virtual std::shared_ptr<Shader> getDefaultShader() = 0; virtual Shader * getDefaultShader() = 0;
/** /**
* Returns the UI Shader used by the game's UI engine. * Returns the UI Shader used by the game's UI engine.
* *
* @return Pointer to the UI Shader. * @return Pointer to the UI Shader.
*/ */
virtual std::shared_ptr<UIShader> getUIShader() = 0; virtual UIShader * getUIShader() = 0;
/** /**
* Sets the render flags for the render manager to use. * Sets the render flags for the render manager to use.

View File

@ -9,11 +9,50 @@
namespace Dawn { namespace Dawn {
class ITexture { class ITexture {
public: public:
/**
* Returns the width of the texture.
*
* @return Width of the texture.
*/
virtual int32_t getWidth() = 0; virtual int32_t getWidth() = 0;
/**
* Returns the height of the texture.
*
* @return Height of the texture.
*/
virtual int32_t getHeight() = 0; virtual int32_t getHeight() = 0;
/**
* Initializes a texture.
*
* @param width Width of the texture (in pixels).
* @param height Height of the texture (in pixels).
*/
virtual void setSize(int32_t width, int32_t height) = 0; virtual void setSize(int32_t width, int32_t height) = 0;
/**
* Fill a texture with a single color. This is stupidly costly.
*
* @param color Color to fill.
*/
virtual void fill(struct Color) = 0; virtual void fill(struct Color) = 0;
/**
* Returns true only when the texture has been loaded, sized and put on
* the gpu for rendering.
*
* @return True if ready, otherwise false.
*/
virtual bool_t isReady() = 0; virtual bool_t isReady() = 0;
/**
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
* avoid doing this too often.
*
* @param pixels Array of pixels you're trying to buffer.
* @return The amount of bytes buffered to the texture.
*/
virtual void buffer(struct Color pixels[]) = 0; virtual void buffer(struct Color pixels[]) = 0;
}; };
} }

View File

@ -18,17 +18,55 @@
namespace Dawn { namespace Dawn {
class Font { class Font {
public: public:
/**
* Buffer the characters of a string onto a primitive and get the result of the
* buffer back as a resulting generic measurement information structure. Note
* that measure is REQUIRED, and must be DISPOSED after it has been calculated.
*
* @param text String to buffer.
* @param fontSize Font size to use for the buffer operation.
* @param maxWidth Maximum width (in pixels) to use to textwrap. -1 for no wrap.
* @param mesh Mesh to buffer the string on to.
* @param info Pointer to where you want to store resulting measurements.
*/
virtual void buffer( virtual void buffer(
std::string text, std::string text,
float_t fontSize, float_t fontSize,
float_t maxWidth, float_t maxWidth,
Mesh &mesh, Mesh *mesh,
struct FontMeasure *info struct FontMeasure *info
) = 0; ) = 0;
virtual Texture & getTexture() = 0; /**
virtual void draw(Mesh &mesh, int32_t startCharacter, int32_t length) = 0; * Returns the texture that is used for a given font.
*
* @return Pointer to the texture used by this font.
*/
virtual Texture * getTexture() = 0;
/**
* Draw a previously buffered font primitive.
*
* @param mesh Mesh to draw.
* @param start Start character to draw.
* @param length Count of characters to draw, set to -1 to draw all.
*/
virtual void draw(Mesh *mesh, int32_t startCharacter, int32_t length) = 0;
/**
* Returns the line height of a given font and font size combination.
*
* @param fontSize Font size to get the line height for.
* @return The line height of this font at this font size.
*/
virtual float_t getLineHeight(float_t fontSize) = 0; virtual float_t getLineHeight(float_t fontSize) = 0;
/**
* Retreive the default font size of a given font. Useful if you want to use
* the original font's font size for pixel-perfect rendering.
*
* @return The font size fo that font item.
*/
virtual float_t getDefaultFontSize() = 0; virtual float_t getDefaultFontSize() = 0;
}; };
} }

View File

@ -20,6 +20,7 @@ int32_t FontMeasure::getQuadCount() {
} }
float_t FontMeasure::getHeightOfLineCount(int32_t lineCount) { float_t FontMeasure::getHeightOfLineCount(int32_t lineCount) {
assertTrue(lineCount > 0);
return this->lineHeight * lineCount; return this->lineHeight * lineCount;
} }
@ -28,14 +29,20 @@ size_t FontMeasure::getLineCount() {
} }
int32_t FontMeasure::getQuadsOnLine(int32_t line) { int32_t FontMeasure::getQuadsOnLine(int32_t line) {
assertTrue(line >= 0);
assertTrue(line < this->lines.size());
return this->lines[line].length; return this->lines[line].length;
} }
int32_t FontMeasure::getQuadIndexOnLine(int32_t line) { int32_t FontMeasure::getQuadIndexOnLine(int32_t line) {
assertTrue(line >= 0);
assertTrue(line < this->lines.size());
return this->lines[line].start; return this->lines[line].start;
} }
void FontMeasure::addLine(int32_t start, int32_t len) { void FontMeasure::addLine(int32_t start, int32_t len) {
assertTrue(start >= 0);
assertTrue(len >= 0);
struct FontLineMeasure info; struct FontLineMeasure info;
info.start = start; info.start = start;
info.length = len; info.length = len;

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include "dawnlibs.hpp" #include "dawnlibs.hpp"
#include "assert/assert.hpp"
namespace Dawn { namespace Dawn {
struct FontLineMeasure { struct FontLineMeasure {

View File

@ -13,6 +13,12 @@
using namespace Dawn; using namespace Dawn;
void TrueTypeFont::bakeQuad(truetypequad_t *quad,float_t *x,float_t *y,char c){ void TrueTypeFont::bakeQuad(truetypequad_t *quad,float_t *x,float_t *y,char c){
assertNotNull(quad);
assertNotNull(x);
assertNotNull(y);
assertTrue(c >= TRUETYPE_FIRST_CHAR);
assertTrue(c < (TRUETYPE_FIRST_CHAR+TRUETYPE_NUM_CHARS));
stbtt_GetBakedQuad( stbtt_GetBakedQuad(
this->characterData, this->characterData,
this->texture.getWidth(), this->texture.getHeight(), this->texture.getWidth(), this->texture.getHeight(),
@ -40,11 +46,15 @@ void TrueTypeFont::buffer(
std::string text, std::string text,
float_t fontSize, float_t fontSize,
float_t maxWidth, float_t maxWidth,
Mesh &mesh, Mesh *mesh,
struct FontMeasure *info struct FontMeasure *info
) { ) {
auto stringLength = text.length(); assertNotNull(mesh);
assertNotNull(info);
assertTrue(fontSize > 0);
assertTrue(maxWidth == -1 || maxWidth > 0);
auto stringLength = text.length();
if(stringLength == 0) { if(stringLength == 0) {
info->length = 0; info->length = 0;
info->realLength = 0; info->realLength = 0;
@ -53,15 +63,18 @@ void TrueTypeFont::buffer(
info->width = 0; info->width = 0;
info->height = 0.0f; info->height = 0.0f;
info->lineHeight = 0.0f; info->lineHeight = 0.0f;
mesh.createBuffers(0, 0); mesh->createBuffers(0, 0);
return; return;
} }
auto quads = new truetypequad_t[stringLength]; auto quads = new truetypequad_t[stringLength];
assertNotNull(quads);
// Get the font scale // Get the font scale
auto scale = this->getScale(fontSize); auto scale = this->getScale(fontSize);
assertTrue(scale > 0);
// Adjust the max width to match the scale, and allow "no max width". // Adjust the max width to match the scale, and allow "no max width".
maxWidth = maxWidth == -1 ? 9999999 : maxWidth * (1 / scale); maxWidth = maxWidth == -1 ? 9999999 : maxWidth * (1 / scale);
@ -143,7 +156,7 @@ void TrueTypeFont::buffer(
} }
// Initialize primitive // Initialize primitive
mesh.createBuffers( mesh->createBuffers(
QUAD_VERTICE_COUNT * info->realLength, QUAD_VERTICE_COUNT * info->realLength,
QUAD_INDICE_COUNT * info->realLength QUAD_INDICE_COUNT * info->realLength
); );
@ -163,7 +176,7 @@ void TrueTypeFont::buffer(
info->height = mathMax<float_t>(info->height, quad->y1); info->height = mathMax<float_t>(info->height, quad->y1);
// Buffer the quad. // Buffer the quad.
QuadMesh::bufferQuadMesh(&mesh, QuadMesh::bufferQuadMesh(mesh,
glm::vec2(quad->x0, quad->y0), glm::vec2(quad->s0, quad->t0), glm::vec2(quad->x0, quad->y0), glm::vec2(quad->s0, quad->t0),
glm::vec2(quad->x1, quad->y1), glm::vec2(quad->s1, quad->t1), glm::vec2(quad->x1, quad->y1), glm::vec2(quad->s1, quad->t1),
j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
@ -173,12 +186,14 @@ void TrueTypeFont::buffer(
delete quads; delete quads;
} }
Texture & TrueTypeFont::getTexture() { Texture * TrueTypeFont::getTexture() {
return this->texture; return &this->texture;
} }
void TrueTypeFont::draw(Mesh &mesh, int32_t startchar, int32_t length) { void TrueTypeFont::draw(Mesh *mesh, int32_t startchar, int32_t length) {
mesh.draw( assertNotNull(mesh);
mesh->draw(
MESH_DRAW_MODE_TRIANGLES, MESH_DRAW_MODE_TRIANGLES,
startchar * QUAD_INDICE_COUNT, startchar * QUAD_INDICE_COUNT,
length == -1 ? length : length * QUAD_INDICE_COUNT length == -1 ? length : length * QUAD_INDICE_COUNT
@ -186,10 +201,10 @@ void TrueTypeFont::draw(Mesh &mesh, int32_t startchar, int32_t length) {
} }
float_t TrueTypeFont::getLineHeight(float_t fontSize) { float_t TrueTypeFont::getLineHeight(float_t fontSize) {
assertTrue(fontSize > 0);
return 13.0f; return 13.0f;
} }
float_t TrueTypeFont::getDefaultFontSize() { float_t TrueTypeFont::getDefaultFontSize() {
return (float_t)this->fontSize; return (float_t)this->fontSize;
} }

View File

@ -71,12 +71,11 @@ namespace Dawn {
std::string text, std::string text,
float_t fontSize, float_t fontSize,
float_t maxWidth, float_t maxWidth,
Mesh &mesh, Mesh *mesh,
struct FontMeasure *info struct FontMeasure *info
) override; ) override;
Texture * getTexture() override;
Texture & getTexture() override; void draw(Mesh *mesh, int32_t startCharacter, int32_t length) override;
void draw(Mesh &mesh, int32_t startCharacter, int32_t length) override;
float_t getLineHeight(float_t fontSize) override; float_t getLineHeight(float_t fontSize) override;
float_t getDefaultFontSize() override; float_t getDefaultFontSize() override;
}; };

View File

@ -8,11 +8,13 @@
using namespace Dawn; using namespace Dawn;
void CubeMesh::buffer( void CubeMesh::buffer(
Mesh &mesh, Mesh *mesh,
glm::vec3 pos, glm::vec3 size, glm::vec3 pos, glm::vec3 size,
int32_t verticeStart, int32_t indiceStart int32_t verticeStart, int32_t indiceStart
) { ) {
mesh.bufferPositions(verticeStart, std::array<glm::vec3, CUBE_VERTICE_COUNT>{{ assertNotNull(mesh);
mesh->bufferPositions(verticeStart, std::array<glm::vec3, CUBE_VERTICE_COUNT>{{
pos, pos,
glm::vec3(pos.x+size.x, pos.y, pos.z), glm::vec3(pos.x+size.x, pos.y, pos.z),
glm::vec3(pos.x, pos.y+size.y, pos.z), glm::vec3(pos.x, pos.y+size.y, pos.z),
@ -24,7 +26,7 @@ void CubeMesh::buffer(
pos + size pos + size
}}); }});
mesh.bufferCoordinates(verticeStart,std::array<glm::vec2,CUBE_VERTICE_COUNT>{{ mesh->bufferCoordinates(verticeStart,std::array<glm::vec2,CUBE_VERTICE_COUNT>{{
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(1, 0), glm::vec2(1, 0),
glm::vec2(0, 1), glm::vec2(0, 1),
@ -36,7 +38,7 @@ void CubeMesh::buffer(
glm::vec2(1, 1) glm::vec2(1, 1)
}}); }});
mesh.bufferIndices(indiceStart, std::array<meshindice_t, CUBE_INDICE_COUNT>{{ mesh->bufferIndices(indiceStart, std::array<meshindice_t, CUBE_INDICE_COUNT>{{
// Back // Back
verticeStart, verticeStart + 1, verticeStart + 3, verticeStart, verticeStart + 1, verticeStart + 3,
verticeStart, verticeStart + 2, verticeStart + 3, verticeStart, verticeStart + 2, verticeStart + 3,

View File

@ -13,7 +13,7 @@ namespace Dawn {
class CubeMesh { class CubeMesh {
public: public:
static void buffer( static void buffer(
Mesh &mesh, Mesh *mesh,
glm::vec3 pos, glm::vec3 size, glm::vec3 pos, glm::vec3 size,
int32_t verticeStart, int32_t indiceStart int32_t verticeStart, int32_t indiceStart
); );

View File

@ -13,6 +13,8 @@ void QuadMesh::bufferQuadMeshWithZ(
glm::vec2 xy1, glm::vec2 uv1, glm::vec2 xy1, glm::vec2 uv1,
float_t z, int32_t verticeStart, int32_t indiceStart float_t z, int32_t verticeStart, int32_t indiceStart
) { ) {
assertNotNull(mesh);
mesh->bufferPositions( mesh->bufferPositions(
verticeStart, std::array<glm::vec3, QUAD_VERTICE_COUNT>{{ verticeStart, std::array<glm::vec3, QUAD_VERTICE_COUNT>{{
glm::vec3(xy0, z), glm::vec3(xy0, z),

View File

@ -7,19 +7,21 @@
using namespace Dawn; using namespace Dawn;
void TriangleMesh::createTriangleMesh(Mesh &mesh) { void TriangleMesh::createTriangleMesh(Mesh *mesh) {
mesh.createBuffers(3, 3); assertNotNull(mesh);
mesh.bufferPositions(0, std::array<glm::vec3, 3>{{
mesh->createBuffers(3, 3);
mesh->bufferPositions(0, std::array<glm::vec3, 3>{{
glm::vec3(-0.5f, -0.5f, 0), glm::vec3(-0.5f, -0.5f, 0),
glm::vec3(0.5f, -0.5f, 0), glm::vec3(0.5f, -0.5f, 0),
glm::vec3(0, 0.5f, 0) glm::vec3(0, 0.5f, 0)
}}); }});
mesh.bufferCoordinates(0, std::array<glm::vec2, 3>{{ mesh->bufferCoordinates(0, std::array<glm::vec2, 3>{{
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(0, 1), glm::vec2(0, 1),
glm::vec2(1, 0) glm::vec2(1, 0)
}}); }});
mesh.bufferIndices(0, std::array<meshindice_t,3>{{ mesh->bufferIndices(0, std::array<meshindice_t,3>{{
0, 1, 2 0, 1, 2
}}); }});
} }

View File

@ -14,6 +14,6 @@ namespace Dawn {
* *
* @param mesh Mesh to initialize as a triangle. * @param mesh Mesh to initialize as a triangle.
*/ */
static void createTriangleMesh(Mesh &mesh); static void createTriangleMesh(Mesh *mesh);
}; };
} }

View File

@ -33,7 +33,7 @@ namespace Dawn {
* *
* @param material Material to set the default parameters on to. * @param material Material to set the default parameters on to.
*/ */
virtual void setDefaultParameters(Material &material) = 0; virtual void setDefaultParameters(Material *material) = 0;
/** /**
* Requested by the render pipeline (typically) to set global level (once * Requested by the render pipeline (typically) to set global level (once

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include "dawnlibs.hpp" #include "dawnlibs.hpp"
#include "assert/assert.hpp"
namespace Dawn { namespace Dawn {
@ -29,10 +30,9 @@ namespace Dawn {
* @param instance Instance that the callback belongs to. * @param instance Instance that the callback belongs to.
* @param callback Callback method that invokes back. * @param callback Callback method that invokes back.
*/ */
EventListener(T *instance, void (T::*callback)(A... args)) : EventListener(T *instance, void (T::*callback)(A... args)) {
instance(instance), this->instance = instance;
callback(callback) this->callback = callback;
{
} }
void invoke(A... args) { void invoke(A... args) {

View File

@ -21,7 +21,7 @@ namespace Dawn {
class IDawnGame { class IDawnGame {
public: public:
std::shared_ptr<Scene> scene; Scene *scene;
/** /**
* Initialize the game. This is performed by the host at a time that is * Initialize the game. This is performed by the host at a time that is

View File

@ -29,11 +29,9 @@ namespace Dawn {
*/ */
class DawnHostData; class DawnHostData;
class DawnHost : class DawnHost {
public std::enable_shared_from_this<DawnHost>
{
public: public:
std::unique_ptr<DawnHostData> data; DawnHostData *data;
DawnGame *game; DawnGame *game;
/** /**
@ -52,7 +50,7 @@ namespace Dawn {
* @param game Game instance that this host is running for. * @param game Game instance that this host is running for.
* @return A status code, where DAWN_HOST_INIT_RESULT_SUCCESS is success. * @return A status code, where DAWN_HOST_INIT_RESULT_SUCCESS is success.
*/ */
int32_t init(DawnGame &game); int32_t init(DawnGame *game);
/** /**
* Request to start the main loop. This method may not exist and may not * Request to start the main loop. This method may not exist and may not
@ -64,7 +62,7 @@ namespace Dawn {
* @param game Game instance that this host is running for. * @param game Game instance that this host is running for.
* @return A status code, refer to DAWN_HOST_START_RESULT_{} definitions. * @return A status code, refer to DAWN_HOST_START_RESULT_{} definitions.
*/ */
virtual int32_t start(DawnGame &game); virtual int32_t start(DawnGame *game);
/** /**
* Requests the host to perform a main-thread update. * Requests the host to perform a main-thread update.
@ -73,7 +71,7 @@ namespace Dawn {
* @param delta How much time has passed (in seconds) since the last tick. * @param delta How much time has passed (in seconds) since the last tick.
* @return A status code, refer to DAWN_HOST_UPDATE_RESULT_{} definitions. * @return A status code, refer to DAWN_HOST_UPDATE_RESULT_{} definitions.
*/ */
int32_t update(DawnGame &game, float_t delta); int32_t update(DawnGame *game, float_t delta);
/** /**
* Request the host to be unloaded. This is a bit different from dispose * Request the host to be unloaded. This is a bit different from dispose
@ -82,7 +80,7 @@ namespace Dawn {
* *
* @param game Game instance that this host is running for. * @param game Game instance that this host is running for.
*/ */
void unload(DawnGame &game); void unload(DawnGame *game);
/** /**
* Destroy (and unload) all of the DawnHost data from memory. * Destroy (and unload) all of the DawnHost data from memory.

View File

@ -29,9 +29,11 @@ namespace Dawn {
virtual float_t getInputValue(T axis) = 0; virtual float_t getInputValue(T axis) = 0;
public: public:
DawnGame &game; DawnGame *game;
IInputManager(DawnGame &game) : game(game) {} IInputManager(DawnGame *game) {
this->game = game;
}
/** /**
* Binds an axis to a bind. * Binds an axis to a bind.

View File

@ -8,7 +8,8 @@
using namespace Dawn; using namespace Dawn;
Scene::Scene(DawnGame &game) : game(game) { Scene::Scene(DawnGame *game) {
this->game = game;
this->nextId = 0; this->nextId = 0;
} }
@ -26,15 +27,16 @@ void Scene::update() {
// TODO: Tick scene items(?) // TODO: Tick scene items(?)
this->eventSceneUpdate.invoke(); this->eventSceneUpdate.invoke();
if(!this->game.timeManager.isPaused) this->eventSceneUnpausedUpdate.invoke(); if(!this->game->timeManager.isPaused) this->eventSceneUnpausedUpdate.invoke();
} }
std::shared_ptr<SceneItem> Scene::createSceneItem() { SceneItem * Scene::createSceneItem() {
sceneitemid_t id = this->nextId++; sceneitemid_t id = this->nextId++;
auto item = std::make_shared<SceneItem>(*this, id); auto item = new SceneItem(this, id);
this->itemsNotInitialized[id] = item; this->itemsNotInitialized[id] = item;
return item; return item;
} }
Scene::~Scene() { Scene::~Scene() {
} }

View File

@ -13,11 +13,11 @@ namespace Dawn {
class Scene { class Scene {
private: private:
sceneitemid_t nextId; sceneitemid_t nextId;
std::map<sceneitemid_t, std::shared_ptr<SceneItem>> items; std::map<sceneitemid_t, SceneItem*> items;
std::map<sceneitemid_t, std::shared_ptr<SceneItem>> itemsNotInitialized; std::map<sceneitemid_t, SceneItem*> itemsNotInitialized;
public: public:
DawnGame &game; DawnGame *game;
Event<> eventSceneUpdate; Event<> eventSceneUpdate;
Event<> eventSceneUnpausedUpdate; Event<> eventSceneUnpausedUpdate;
@ -26,7 +26,7 @@ namespace Dawn {
* *
* @param game Reference to the game that this scene belongs to. * @param game Reference to the game that this scene belongs to.
*/ */
Scene(DawnGame &game); Scene(DawnGame *game);
/** /**
* Perform a one frame synchronous tick on the current scene. This may * Perform a one frame synchronous tick on the current scene. This may
@ -39,7 +39,7 @@ namespace Dawn {
* *
* @return A shared pointer to the created SceneItem. * @return A shared pointer to the created SceneItem.
*/ */
std::shared_ptr<SceneItem> createSceneItem(); SceneItem * createSceneItem();
/** /**
* Finds an existing component on the scene (Root Level Only) that has a * Finds an existing component on the scene (Root Level Only) that has a
@ -50,7 +50,7 @@ namespace Dawn {
* @return Pointer to the found component (and by extension the item). * @return Pointer to the found component (and by extension the item).
*/ */
template<class T> template<class T>
std::shared_ptr<T> findComponent() { T * findComponent() {
auto it = this->items.begin(); auto it = this->items.begin();
while(it != this->items.end()) { while(it != this->items.end()) {
auto component = it->second->getComponent<T>(); auto component = it->second->getComponent<T>();
@ -68,8 +68,8 @@ namespace Dawn {
* @return List of matching compnoents. * @return List of matching compnoents.
*/ */
template<class T> template<class T>
std::vector<std::shared_ptr<T>> findComponents() { std::vector<T*> findComponents() {
std::vector<std::shared_ptr<T>> components; std::vector<T*> components;
auto it = this->items.begin(); auto it = this->items.begin();
while(it != this->items.end()) { while(it != this->items.end()) {
auto component = it->second->getComponent<T>(); auto component = it->second->getComponent<T>();

View File

@ -8,11 +8,9 @@
using namespace Dawn; using namespace Dawn;
SceneItem::SceneItem(Scene &scene, sceneitemid_t id) : SceneItem::SceneItem(Scene *scene, sceneitemid_t id) : transform(this) {
scene(scene), this->id = id;
id(id), this->scene = scene;
transform(*this)
{
} }
void SceneItem::init() { void SceneItem::init() {

View File

@ -15,10 +15,10 @@ namespace Dawn {
class SceneItem { class SceneItem {
private: private:
std::vector<std::shared_ptr<SceneItemComponent>> components; std::vector<SceneItemComponent*> components;
public: public:
Scene &scene; Scene *scene;
sceneitemid_t id; sceneitemid_t id;
Transform transform; Transform transform;
@ -29,7 +29,7 @@ namespace Dawn {
* @param scene Weak pointer to the Scene that this SceneItem belongs to. * @param scene Weak pointer to the Scene that this SceneItem belongs to.
* @param id Scene Item ID that the Scene assigned this SceneItem. * @param id Scene Item ID that the Scene assigned this SceneItem.
*/ */
SceneItem(Scene &scene, sceneitemid_t id); SceneItem(Scene *scene, sceneitemid_t id);
/** /**
* Called by the Scene the frame after we were constructed so we can begin * Called by the Scene the frame after we were constructed so we can begin
@ -48,8 +48,8 @@ namespace Dawn {
* @return A shared pointer to the newly added component. * @return A shared pointer to the newly added component.
*/ */
template<class T> template<class T>
std::shared_ptr<T> addComponent() { T * addComponent() {
auto component = std::make_shared<T>(*this); auto component = new T(this);
this->components.push_back(component); this->components.push_back(component);
return component; return component;
} }
@ -63,10 +63,10 @@ namespace Dawn {
* @return A shared pointer to the component, or nullptr if not found. * @return A shared pointer to the component, or nullptr if not found.
*/ */
template<class T> template<class T>
std::shared_ptr<T> getComponent() { T * getComponent() {
auto it = this->components.begin(); auto it = this->components.begin();
while(it != this->components.end()) { while(it != this->components.end()) {
auto castedAs = std::dynamic_pointer_cast<T>(*it); T *castedAs = dynamic_cast<T*>(*it);
if(castedAs != nullptr) return castedAs; if(castedAs != nullptr) return castedAs;
++it; ++it;
} }
@ -80,10 +80,10 @@ namespace Dawn {
* @return Pointer to the child, or nullptr if not found. * @return Pointer to the child, or nullptr if not found.
*/ */
template<class T> template<class T>
std::shared_ptr<T> findChild() { T * findChild() {
auto it = this->transform.children.begin(); auto it = this->transform.children.begin();
while(it != this->transform.children.end()) { while(it != this->transform.children.end()) {
auto child = (*it)->item.getComponent<T>(); auto child = (*it)->item->getComponent<T>();
if(child != nullptr) return child; if(child != nullptr) return child;
++it; ++it;
} }
@ -98,11 +98,11 @@ namespace Dawn {
* @return Array of pointers to matching children. * @return Array of pointers to matching children.
*/ */
template<class T> template<class T>
std::vector<std::shared_ptr<T>> findChildren() { std::vector<T*> findChildren() {
auto it = this->transform.children.begin(); auto it = this->transform.children.begin();
std::vector<std::shared_ptr<T>> children; std::vector<T*> children;
while(it != this->transform.children.end()) { while(it != this->transform.children.end()) {
auto child = (*it)->item.getComponent<T>(); auto child = (*it)->item->getComponent<T>();
if(child != nullptr) children.push_back(child); if(child != nullptr) children.push_back(child);
++it; ++it;
} }

View File

@ -10,10 +10,9 @@
using namespace Dawn; using namespace Dawn;
SceneItemComponent::SceneItemComponent(SceneItem &item) : SceneItemComponent::SceneItemComponent(SceneItem *item) {
item(item), this->item = item;
transform(item.transform) this->transform = &item->transform;
{
} }
void SceneItemComponent::init() { void SceneItemComponent::init() {
@ -25,12 +24,12 @@ std::vector<SceneItemComponent*> SceneItemComponent::getDependencies() {
return std::vector<SceneItemComponent*>(); return std::vector<SceneItemComponent*>();
} }
Scene & SceneItemComponent::getScene() { Scene * SceneItemComponent::getScene() {
return this->item.scene; return this->item->scene;
} }
DawnGame & SceneItemComponent::getGame() { DawnGame * SceneItemComponent::getGame() {
return this->item.scene.game; return this->item->scene->game;
} }
void SceneItemComponent::onStart() { void SceneItemComponent::onStart() {

View File

@ -14,8 +14,8 @@ namespace Dawn {
class SceneItemComponent { class SceneItemComponent {
public: public:
SceneItem &item; SceneItem *item;
Transform &transform; Transform *transform;
bool_t hasInitialized = false; bool_t hasInitialized = false;
/** /**
@ -25,7 +25,7 @@ namespace Dawn {
* *
* @param item Scene Item thsi component belongs to. * @param item Scene Item thsi component belongs to.
*/ */
SceneItemComponent(SceneItem &item); SceneItemComponent(SceneItem *item);
/** /**
* Requested on the first frame that the parent scene item has become * Requested on the first frame that the parent scene item has become
@ -45,13 +45,13 @@ namespace Dawn {
* Shorthand to return the scene that this component's item belongs to. * Shorthand to return the scene that this component's item belongs to.
* @return The current scene. * @return The current scene.
*/ */
Scene & getScene(); Scene * getScene();
/** /**
* Shorthand to return the game that this scene belongs to. * Shorthand to return the game that this scene belongs to.
* @return The current game. * @return The current game.
*/ */
DawnGame & getGame(); DawnGame * getGame();
/** /**
* Same as init, but intended for your subclass to override. * Same as init, but intended for your subclass to override.

View File

@ -9,10 +9,10 @@
using namespace Dawn; using namespace Dawn;
Camera::Camera(SceneItem &item) : Camera::Camera(SceneItem *item) :
SceneItemComponent(item) SceneItemComponent(item)
{ {
this->getRenderTarget().eventRenderTargetResized.addListener( this->getRenderTarget()->eventRenderTargetResized.addListener(
this, &Camera::onRenderTargetResize this, &Camera::onRenderTargetResize
); );
} }
@ -41,40 +41,40 @@ void Camera::updateProjection() {
} }
} }
RenderTarget & Camera::getRenderTarget() { RenderTarget * Camera::getRenderTarget() {
if(this->target == nullptr) { if(this->target == nullptr) {
return this->getGame().renderManager.getBackBuffer(); return this->getGame()->renderManager.getBackBuffer();
} }
return *this->target; return this->target;
} }
void Camera::setRenderTarget(std::shared_ptr<RenderTarget> renderTarget) { void Camera::setRenderTarget(RenderTarget *renderTarget) {
if(renderTarget == this->target) return; if(renderTarget == this->target) return;
this->getRenderTarget().eventRenderTargetResized.removeListener( this->getRenderTarget()->eventRenderTargetResized.removeListener(
this, &Camera::onRenderTargetResize this, &Camera::onRenderTargetResize
); );
this->target = renderTarget; this->target = renderTarget;
this->getRenderTarget().eventRenderTargetResized.addListener( this->getRenderTarget()->eventRenderTargetResized.addListener(
this, &Camera::onRenderTargetResize this, &Camera::onRenderTargetResize
); );
this->updateProjection(); this->updateProjection();
} }
float_t Camera::getAspect() { float_t Camera::getAspect() {
RenderTarget &target = this->getRenderTarget(); RenderTarget *target = this->getRenderTarget();
return target.getWidth() / target.getHeight(); return target->getWidth() / target->getHeight();
} }
void Camera::onStart() { void Camera::onStart() {
this->updateProjection(); this->updateProjection();
} }
void Camera::onRenderTargetResize(RenderTarget &target, float_t w, float_t h) { void Camera::onRenderTargetResize(RenderTarget *target, float_t w, float_t h) {
this->updateProjection(); this->updateProjection();
} }
Camera::~Camera() { Camera::~Camera() {
this->getRenderTarget().eventRenderTargetResized.removeListener( this->getRenderTarget()->eventRenderTargetResized.removeListener(
this, &Camera::onRenderTargetResize this, &Camera::onRenderTargetResize
); );
} }

View File

@ -15,9 +15,9 @@ namespace Dawn {
class Camera : public SceneItemComponent { class Camera : public SceneItemComponent {
protected: protected:
std::shared_ptr<RenderTarget> target = nullptr; RenderTarget *target = nullptr;
void onRenderTargetResize(RenderTarget &target, float_t w, float_t h); void onRenderTargetResize(RenderTarget *target, float_t w, float_t h);
public: public:
glm::mat4 projection; glm::mat4 projection;
@ -41,7 +41,7 @@ namespace Dawn {
* *
* @param item SceneItem that this component belongs to. * @param item SceneItem that this component belongs to.
*/ */
Camera(SceneItem &item); Camera(SceneItem *item);
/** /**
* Updates the projection matrix. * Updates the projection matrix.
@ -54,14 +54,14 @@ namespace Dawn {
* *
* @return The target render target framebuffer. * @return The target render target framebuffer.
*/ */
RenderTarget & getRenderTarget(); RenderTarget * getRenderTarget();
/** /**
* Updates the render target for the camera to use. * Updates the render target for the camera to use.
* *
* @param renderTarget Render target for this camera to draw to. * @param renderTarget Render target for this camera to draw to.
*/ */
void setRenderTarget(std::shared_ptr<RenderTarget> renderTarget); void setRenderTarget(RenderTarget *renderTarget);
/** /**
* Returs the aspect ratio of the camera. * Returs the aspect ratio of the camera.

View File

@ -9,10 +9,8 @@
using namespace Dawn; using namespace Dawn;
Material::Material(SceneItem &item) : Material::Material(SceneItem *item) : SceneItemComponent(item) {
SceneItemComponent(item), this->shader = item->scene->game->renderManager.getDefaultShader();
shader(item.scene.game.renderManager.getDefaultShader())
{
this->updateShaderParameters(); this->updateShaderParameters();
} }
@ -21,7 +19,7 @@ void Material::updateShaderParameters() {
this->boolValues.clear(); this->boolValues.clear();
this->parameters = this->shader->getParameters(); this->parameters = this->shader->getParameters();
this->shader->setDefaultParameters(*this); this->shader->setDefaultParameters(this);
// We do need to validate these params at some point to make sure that the // We do need to validate these params at some point to make sure that the
// shader has actually bound them. // shader has actually bound them.
@ -62,11 +60,11 @@ void Material::setShaderParameters() {
} }
} }
std::shared_ptr<Shader> Material::getShader() { Shader * Material::getShader() {
return this->shader; return this->shader;
} }
void Material::setShader(std::shared_ptr<Shader> shader) { void Material::setShader(Shader * shader) {
this->shader = shader; this->shader = shader;
this->updateShaderParameters(); this->updateShaderParameters();
} }

View File

@ -12,7 +12,7 @@ namespace Dawn {
class Material : public SceneItemComponent { class Material : public SceneItemComponent {
private: private:
std::shared_ptr<Shader> shader; Shader *shader;
/** /**
* Internal method that will be invoked to go through and update all of * Internal method that will be invoked to go through and update all of
@ -34,14 +34,14 @@ namespace Dawn {
* *
* @param item Scene Item this component belongs to. * @param item Scene Item this component belongs to.
*/ */
Material(SceneItem &item); Material(SceneItem *item);
/** /**
* Return the shader this material is currently using. * Return the shader this material is currently using.
* *
* @return Shader pointer to the currently bound shader. * @return Shader pointer to the currently bound shader.
*/ */
std::shared_ptr<Shader> getShader(); Shader * getShader();
/** /**
* Sets the shader for the material to use. This will also clear and * Sets the shader for the material to use. This will also clear and
@ -49,7 +49,7 @@ namespace Dawn {
* *
* @param shader Shader to set. * @param shader Shader to set.
*/ */
void setShader(std::shared_ptr<Shader> shader); void setShader(Shader * shader);
/** /**
* Protected method that can be called, likely by the render pipeline, to * Protected method that can be called, likely by the render pipeline, to

View File

@ -7,8 +7,5 @@
using namespace Dawn; using namespace Dawn;
MeshRenderer::MeshRenderer(SceneItem &item) : MeshRenderer::MeshRenderer(SceneItem *item) : SceneItemComponent(item) {
SceneItemComponent(item)
{
} }

View File

@ -10,13 +10,13 @@
namespace Dawn { namespace Dawn {
class MeshRenderer : public SceneItemComponent { class MeshRenderer : public SceneItemComponent {
public: public:
std::shared_ptr<Mesh> mesh = nullptr; Mesh * mesh = nullptr;
/** /**
* Constructs a MeshRenderer scene item component. * Constructs a MeshRenderer scene item component.
* *
* @param item Scene Item this mesh renderer belongs to. * @param item Scene Item this mesh renderer belongs to.
*/ */
MeshRenderer(SceneItem &item); MeshRenderer(SceneItem *item);
}; };
} }

View File

@ -10,31 +10,30 @@
using namespace Dawn; using namespace Dawn;
std::shared_ptr<UICanvas> UICanvas::createCanvas(std::shared_ptr<Scene> scene) { UICanvas * UICanvas::createCanvas(Scene *scene) {
auto item = scene->createSceneItem(); auto item = scene->createSceneItem();
return item->addComponent<UICanvas>(); return item->addComponent<UICanvas>();
} }
UICanvas::UICanvas(SceneItem &item) : SceneItemComponent(item) { UICanvas::UICanvas(SceneItem *item) : SceneItemComponent(item) {
} }
float_t UICanvas::getWidth() { float_t UICanvas::getWidth() {
return this->getGame().renderManager.getBackBuffer().getWidth(); return this->getGame()->renderManager.getBackBuffer()->getWidth();
} }
float_t UICanvas::getHeight() { float_t UICanvas::getHeight() {
return this->getGame().renderManager.getBackBuffer().getHeight(); return this->getGame()->renderManager.getBackBuffer()->getHeight();
} }
void UICanvas::onStart() { void UICanvas::onStart() {
std::cout << "Canvas event" << std::endl; this->getGame()->renderManager.getBackBuffer()->eventRenderTargetResized
this->getGame().renderManager.getBackBuffer() .addListener(this, &UICanvas::onBackBufferResize)
.eventRenderTargetResized.addListener(this, &UICanvas::onBackBufferResize)
; ;
} }
void UICanvas::onBackBufferResize( void UICanvas::onBackBufferResize(
RenderTarget &target, RenderTarget *target,
float_t width, float_t width,
float_t height float_t height
) { ) {
@ -46,7 +45,7 @@ void UICanvas::onBackBufferResize(
} }
UICanvas::~UICanvas() { UICanvas::~UICanvas() {
this->getGame().renderManager.getBackBuffer() this->getGame()->renderManager.getBackBuffer()->eventRenderTargetResized
.eventRenderTargetResized.removeListener(this, &UICanvas::onBackBufferResize) .removeListener(this, &UICanvas::onBackBufferResize)
; ;
} }

View File

@ -19,30 +19,58 @@ namespace Dawn {
class UICanvas : public SceneItemComponent { class UICanvas : public SceneItemComponent {
protected: protected:
void onBackBufferResize( void onBackBufferResize(
RenderTarget &target, RenderTarget *target,
float_t width, float_t width,
float_t height float_t height
); );
public: public:
static std::shared_ptr<UICanvas> createCanvas( /**
std::shared_ptr<Scene> scene * Creates a UI Canvas Scene Item Element, and attaches it to the provided
); * scene.
*
* @param scene Scene to create the UI Canvas for.
* @return Created UI Canvas.
*/
static UICanvas * createCanvas(Scene *scene);
// //
std::vector<std::shared_ptr<UIComponent>> children; std::vector<UIComponent*> children;
UIDrawType drawType = UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE; UIDrawType drawType = UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE;
UICanvas(SceneItem &item); /**
* Constructs the UI Canvas Scene Item Component.
*
* @param item Item that this canvas item belongs to.
*/
UICanvas(SceneItem *item);
/**
* Construct and append a UI item to this UI Canvas.
*
* @tparam Type of the UI Item.
* @return Pointer to the created UI Item.
*/
template<class T> template<class T>
std::shared_ptr<T> addElement() { T * addElement() {
auto item = std::make_shared<T>(*this); auto item = new T(this);
this->children.push_back(item); this->children.push_back(item);
return item; return item;
} }
/**
* Returns the width of the root UI Canvas size. In future I may allow
* this to be dynamic, right now it uses the render canvas however.
*
* @return Width of the UI Canvas.
*/
float_t getWidth(); float_t getWidth();
/**
* Returns the height of this UI Canvas element.
*
* @return Height of the UI Canvas.
*/
float_t getHeight(); float_t getHeight();
void onStart() override; void onStart() override;

View File

@ -7,7 +7,7 @@
using namespace Dawn; using namespace Dawn;
UIBorder::UIBorder(UICanvas &canvas) : UIComponent(canvas) { UIBorder::UIBorder(UICanvas *canvas) : UIComponent(canvas) {
this->mesh.createBuffers(QUAD_VERTICE_COUNT * 9, QUAD_INDICE_COUNT * 9); this->mesh.createBuffers(QUAD_VERTICE_COUNT * 9, QUAD_INDICE_COUNT * 9);
this->texture = new Texture(); this->texture = new Texture();
@ -111,12 +111,12 @@ void UIBorder::updatePositions() {
); );
} }
void UIBorder::drawSelf(UIShader &shader, glm::mat4 transform) { void UIBorder::drawSelf(UIShader *shader, glm::mat4 transform) {
if(this->texture == nullptr) return; if(this->texture == nullptr) return;
shader.setUIColor(COLOR_WHITE); shader->setUIColor(COLOR_WHITE);
shader.setUIModel(transform); shader->setUIModel(transform);
shader.setUITexture(this->texture); shader->setUITexture(this->texture);
this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1); this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
} }

View File

@ -17,12 +17,12 @@ namespace Dawn {
glm::vec2 uv1 = glm::vec2(1.0f, 1.0f); glm::vec2 uv1 = glm::vec2(1.0f, 1.0f);
void updatePositions() override; void updatePositions() override;
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override; void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
public: public:
Texture *texture; Texture *texture;
UIBorder(UICanvas &canvas); UIBorder(UICanvas *canvas);
/** /**
* Changes the dimensions of the border. * Changes the dimensions of the border.

View File

@ -7,16 +7,15 @@
using namespace Dawn; using namespace Dawn;
UIComponent::UIComponent(UICanvas &canvas) : UIComponent::UIComponent(UICanvas *canvas) {
canvas(canvas) this->canvas = canvas;
{
} }
void UIComponent::updatePositions() { void UIComponent::updatePositions() {
// X Alignment // X Alignment
if(this->alignX == UI_COMPONENT_ALIGN_STRETCH) { if(this->alignX == UI_COMPONENT_ALIGN_STRETCH) {
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->width = this->canvas.getWidth(); this->width = this->canvas->getWidth();
} else { } else {
this->width = this->parent->getWidth(); this->width = this->parent->getWidth();
} }
@ -28,7 +27,7 @@ void UIComponent::updatePositions() {
} else if(this->alignX == UI_COMPONENT_ALIGN_END) { } else if(this->alignX == UI_COMPONENT_ALIGN_END) {
this->width = this->alignment[0]; this->width = this->alignment[0];
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->relativeX = this->canvas.getWidth(); this->relativeX = this->canvas->getWidth();
} else { } else {
this->relativeX = this->parent->getWidth(); this->relativeX = this->parent->getWidth();
} }
@ -37,7 +36,7 @@ void UIComponent::updatePositions() {
} else if(this->alignX == UI_COMPONENT_ALIGN_MIDDLE) { } else if(this->alignX == UI_COMPONENT_ALIGN_MIDDLE) {
this->width = this->alignment[2]; this->width = this->alignment[2];
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->relativeX = this->canvas.getWidth(); this->relativeX = this->canvas->getWidth();
} else { } else {
this->relativeX = this->parent->getWidth(); this->relativeX = this->parent->getWidth();
} }
@ -47,7 +46,7 @@ void UIComponent::updatePositions() {
// Y Alignment // Y Alignment
if(this->alignY == UI_COMPONENT_ALIGN_STRETCH) { if(this->alignY == UI_COMPONENT_ALIGN_STRETCH) {
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->height = this->canvas.getHeight(); this->height = this->canvas->getHeight();
} else { } else {
this->height = this->parent->getHeight(); this->height = this->parent->getHeight();
} }
@ -59,7 +58,7 @@ void UIComponent::updatePositions() {
} else if(this->alignY == UI_COMPONENT_ALIGN_END) { } else if(this->alignY == UI_COMPONENT_ALIGN_END) {
this->height = this->alignment[1]; this->height = this->alignment[1];
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->relativeY = this->canvas.getHeight(); this->relativeY = this->canvas->getHeight();
} else { } else {
this->relativeY = this->parent->getHeight(); this->relativeY = this->parent->getHeight();
} }
@ -68,7 +67,7 @@ void UIComponent::updatePositions() {
} else if(this->alignY == UI_COMPONENT_ALIGN_MIDDLE) { } else if(this->alignY == UI_COMPONENT_ALIGN_MIDDLE) {
this->height = this->alignment[3]; this->height = this->alignment[3];
if(this->parent == nullptr) { if(this->parent == nullptr) {
this->relativeY = this->canvas.getHeight(); this->relativeY = this->canvas->getHeight();
} else { } else {
this->relativeY = this->parent->getHeight(); this->relativeY = this->parent->getHeight();
} }
@ -117,7 +116,7 @@ void UIComponent::setTransform(
this->updatePositions(); this->updatePositions();
} }
void UIComponent::draw(UIShader &uiShader, glm::mat4 parentTransform) { void UIComponent::draw(UIShader *uiShader, glm::mat4 parentTransform) {
// Calculate self transform matrix // Calculate self transform matrix
glm::mat4 selfTransform = parentTransform * glm::translate( glm::mat4 selfTransform = parentTransform * glm::translate(
glm::mat4(1.0f), glm::vec3(this->relativeX, this->relativeY, this->z) glm::mat4(1.0f), glm::vec3(this->relativeX, this->relativeY, this->z)

View File

@ -56,12 +56,12 @@ namespace Dawn {
* @param uiShader UI Shader for the child to use. * @param uiShader UI Shader for the child to use.
* @param selfTransform Self alignment transform. * @param selfTransform Self alignment transform.
*/ */
virtual void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) = 0; virtual void drawSelf(UIShader *uiShader, glm::mat4 selfTransform) = 0;
public: public:
UICanvas &canvas; UICanvas *canvas;
UIComponent(UICanvas &canvas); UIComponent(UICanvas *canvas);
/** /**
* Returns the calculated width, based on the internal alignment values. * Returns the calculated width, based on the internal alignment values.
@ -106,7 +106,7 @@ namespace Dawn {
float_t z float_t z
); );
void draw(UIShader &uiShader, glm::mat4 parentTransform); void draw(UIShader *uiShader, glm::mat4 parentTransform);
/** /**
* Adds a child to this UI Component. * Adds a child to this UI Component.

View File

@ -7,7 +7,7 @@
using namespace Dawn; using namespace Dawn;
UILabel::UILabel(UICanvas &canvas) : UIComponent(canvas) { UILabel::UILabel(UICanvas *canvas) : UIComponent(canvas) {
} }
@ -21,11 +21,14 @@ void UILabel::updateMesh() {
if(this->font == nullptr) return; if(this->font == nullptr) return;
if(this->text.size() == 0) return; if(this->text.size() == 0) return;
float_t width = this->getWidth();
if(width == 0) width = -1;
this->font->buffer( this->font->buffer(
this->text, this->text,
this->fontSize, this->fontSize,
this->getWidth(), width,
this->mesh, &this->mesh,
&this->measure &this->measure
); );
@ -51,15 +54,15 @@ void UILabel::setFontSize(float_t fontSize) {
this->needsRebuffering = true; this->needsRebuffering = true;
} }
void UILabel::drawSelf(UIShader &shader, glm::mat4 selfTransform) { void UILabel::drawSelf(UIShader *shader, glm::mat4 selfTransform) {
if(this->font == nullptr || this->text.size() == 0) return; if(this->font == nullptr || this->text.size() == 0) return;
this->updateMesh(); this->updateMesh();
shader.setUIColor(this->textColor); shader->setUIColor(this->textColor);
shader.setUIModel(selfTransform); shader->setUIModel(selfTransform);
shader.setUITexture(&this->font->getTexture()); shader->setUITexture(this->font->getTexture());
this->font->draw(this->mesh, this->startQuad, this->quadCount); this->font->draw(&this->mesh, this->startQuad, this->quadCount);
} }
void UILabel::setTransform( void UILabel::setTransform(

View File

@ -27,8 +27,8 @@ namespace Dawn {
/** The colour of this label */ /** The colour of this label */
struct Color textColor = COLOR_MAGENTA; struct Color textColor = COLOR_MAGENTA;
UILabel(UICanvas &canvas); UILabel(UICanvas *canvas);
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override; void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
void setTransform( void setTransform(
UIComponentAlign xAlign, UIComponentAlign xAlign,
UIComponentAlign yAlign, UIComponentAlign yAlign,

View File

@ -7,7 +7,7 @@
using namespace Dawn; using namespace Dawn;
UISprite::UISprite(UICanvas &canvas) : UIComponent(canvas) { UISprite::UISprite(UICanvas *canvas) : UIComponent(canvas) {
this->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT); this->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
} }
@ -22,12 +22,12 @@ void UISprite::updatePositions() {
); );
} }
void UISprite::drawSelf(UIShader &uiShader, glm::mat4 selfTransform) { void UISprite::drawSelf(UIShader *uiShader, glm::mat4 selfTransform) {
uiShader.setUITexture(nullptr); uiShader->setUITexture(nullptr);
uiShader.setUIModel(selfTransform); uiShader->setUIModel(selfTransform);
uiShader.setUIModel(glm::mat4(1.0f)); uiShader->setUIModel(glm::mat4(1.0f));
uiShader.setUIColor(COLOR_WHITE); uiShader->setUIColor(COLOR_WHITE);
uiShader.setUITexture(this->texture); uiShader->setUITexture(this->texture);
this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1); this->mesh.draw(MESH_DRAW_MODE_TRIANGLES, 0, -1);
} }

View File

@ -12,7 +12,7 @@ namespace Dawn {
class UISprite : public UIComponent { class UISprite : public UIComponent {
protected: protected:
void updatePositions() override; void updatePositions() override;
void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) override; void drawSelf(UIShader *uiShader, glm::mat4 selfTransform) override;
public: public:
Mesh mesh; Mesh mesh;
@ -23,6 +23,6 @@ namespace Dawn {
* *
* @param canvas Canvas that this sprite belongs to. * @param canvas Canvas that this sprite belongs to.
*/ */
UISprite(UICanvas &canvas); UISprite(UICanvas *canvas);
}; };
} }

View File

@ -8,7 +8,7 @@
using namespace Dawn; using namespace Dawn;
VisualNovelTextbox::VisualNovelTextbox(UICanvas &canvas) : VisualNovelTextbox::VisualNovelTextbox(UICanvas *canvas) :
UIComponent(canvas), UIComponent(canvas),
border(canvas), border(canvas),
label(canvas) label(canvas)
@ -21,7 +21,7 @@ VisualNovelTextbox::VisualNovelTextbox(UICanvas &canvas) :
this->label.startQuad = 0; this->label.startQuad = 0;
this->label.quadCount = 0; this->label.quadCount = 0;
this->canvas.getScene().eventSceneUnpausedUpdate.addListener( this->canvas->getScene()->eventSceneUnpausedUpdate.addListener(
this, &VisualNovelTextbox::textboxOnSceneUpdate this, &VisualNovelTextbox::textboxOnSceneUpdate
); );
} }
@ -53,15 +53,15 @@ void VisualNovelTextbox::updatePositions() {
} }
void VisualNovelTextbox::textboxOnSceneUpdate() { void VisualNovelTextbox::textboxOnSceneUpdate() {
DawnGame &game = this->canvas.getGame(); DawnGame *game = this->canvas->getGame();
if(this->hasRevealedAllCurrentCharacters()) { if(this->hasRevealedAllCurrentCharacters()) {
if(this->hasRevealedAllCharacters()) { if(this->hasRevealedAllCharacters()) {
if(game.inputManager.isPressed(INPUT_BIND_ACCEPT)) { if(game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
this->eventClose.invoke(); this->eventClose.invoke();
} }
} else { } else {
if(game.inputManager.isPressed(INPUT_BIND_ACCEPT)) { if(game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
this->lineCurrent += this->getCountOfVisibleLines(); this->lineCurrent += this->getCountOfVisibleLines();
this->label.startQuad = 0; this->label.startQuad = 0;
for(int32_t i = 0; i < this->lineCurrent; i++) { for(int32_t i = 0; i < this->lineCurrent; i++) {
@ -90,10 +90,10 @@ void VisualNovelTextbox::textboxOnSceneUpdate() {
} }
auto lastTimeCharacter = (int32_t)mathFloorFloat(this->timeCharacter); auto lastTimeCharacter = (int32_t)mathFloorFloat(this->timeCharacter);
if(game.inputManager.isDown(INPUT_BIND_ACCEPT)) { if(game->inputManager.isDown(INPUT_BIND_ACCEPT)) {
this->timeCharacter += game.timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED_FASTER; this->timeCharacter += game->timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED_FASTER;
} else { } else {
this->timeCharacter += game.timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED; this->timeCharacter += game->timeManager.delta * VISUAL_NOVEL_TEXTBOX_SPEED;
} }
auto newTimeCharacter = (int32_t)mathFloorFloat(this->timeCharacter); auto newTimeCharacter = (int32_t)mathFloorFloat(this->timeCharacter);
if(newTimeCharacter == lastTimeCharacter) return; if(newTimeCharacter == lastTimeCharacter) return;
@ -114,7 +114,7 @@ int32_t VisualNovelTextbox::getCountOfVisibleLines() {
return this->label.measure.getLineCount(); return this->label.measure.getLineCount();
} }
void VisualNovelTextbox::drawSelf(UIShader &shader, glm::mat4 self) {} void VisualNovelTextbox::drawSelf(UIShader *shader, glm::mat4 self) {}
void VisualNovelTextbox::setBorder(Texture *texture, glm::vec2 dimensions) { void VisualNovelTextbox::setBorder(Texture *texture, glm::vec2 dimensions) {
this->border.texture = texture; this->border.texture = texture;
@ -156,7 +156,7 @@ bool_t VisualNovelTextbox::hasRevealedAllCharacters() {
} }
VisualNovelTextbox::~VisualNovelTextbox() { VisualNovelTextbox::~VisualNovelTextbox() {
this->canvas.getScene().eventSceneUnpausedUpdate.removeListener( this->canvas->getScene()->eventSceneUnpausedUpdate.removeListener(
this, &VisualNovelTextbox::textboxOnSceneUpdate this, &VisualNovelTextbox::textboxOnSceneUpdate
); );
} }

View File

@ -22,7 +22,7 @@ namespace Dawn {
float_t timeCharacter = 0.0f; float_t timeCharacter = 0.0f;
void updatePositions() override; void updatePositions() override;
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override; void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
/** /**
* Listens for scene updates. * Listens for scene updates.
@ -44,17 +44,12 @@ namespace Dawn {
Event<> eventAllCharactersRevealed; Event<> eventAllCharactersRevealed;
Event<> eventClose; Event<> eventClose;
VisualNovelTextbox(UICanvas &canvas); VisualNovelTextbox(UICanvas *canvas);
void setFont(Font *font); void setFont(Font *font);
void setBorder(Texture *texture, glm::vec2 dimensions); void setBorder(Texture *texture, glm::vec2 dimensions);
void setText(std::string text, float_t fontSize); void setText(std::string text, float_t fontSize);
bool_t hasRevealedAllCurrentCharacters(); bool_t hasRevealedAllCurrentCharacters();
bool_t hasRevealedAllCharacters(); bool_t hasRevealedAllCharacters();
~VisualNovelTextbox(); ~VisualNovelTextbox();
}; };
} }

View File

@ -17,13 +17,13 @@ DawnHost *DAWN_HOST = nullptr;
// Host // Host
DawnHost::DawnHost() { DawnHost::DawnHost() {
this->data = std::make_unique<DawnHostData>(); this->data = new DawnHostData();
this->data->window = nullptr; this->data->window = nullptr;
} }
int32_t DawnHost::init(DawnGame &game) { int32_t DawnHost::init(DawnGame *game) {
// Update values // Update values
this->game = &game; this->game = game;
DAWN_HOST = this; DAWN_HOST = this;
// Init GLFW // Init GLFW
@ -51,18 +51,18 @@ int32_t DawnHost::init(DawnGame &game) {
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
// Override the defaults // Override the defaults
game.renderManager.backBuffer.setSize( game->renderManager.backBuffer.setSize(
DAWN_GLFW_WINDOW_WIDTH_DEFAULT, DAWN_GLFW_WINDOW_WIDTH_DEFAULT,
DAWN_GLFW_WINDOW_HEIGHT_DEFAULT DAWN_GLFW_WINDOW_HEIGHT_DEFAULT
); );
// Default keybinds // Default keybinds
game.inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_ENTER); game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_ENTER);
game.inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_E); game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_E);
game.inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_SPACE); game->inputManager.bind(INPUT_BIND_ACCEPT, GLFW_KEY_SPACE);
// Initialize the game // Initialize the game
auto result = game.init(); auto result = game->init();
if(result != DAWN_GAME_INIT_RESULT_SUCCESS) return result; if(result != DAWN_GAME_INIT_RESULT_SUCCESS) return result;
// Set up event listeners // Set up event listeners
@ -72,7 +72,7 @@ int32_t DawnHost::init(DawnGame &game) {
return DAWN_HOST_INIT_RESULT_SUCCESS; return DAWN_HOST_INIT_RESULT_SUCCESS;
} }
int32_t DawnHost::start(DawnGame &game) { int32_t DawnHost::start(DawnGame *game) {
double_t time, newTime; double_t time, newTime;
float_t fDelta; float_t fDelta;
int32_t updateResult; int32_t updateResult;
@ -105,8 +105,8 @@ int32_t DawnHost::start(DawnGame &game) {
return DAWN_HOST_START_RESULT_EXIT_SUCCESS; return DAWN_HOST_START_RESULT_EXIT_SUCCESS;
} }
int32_t DawnHost::update(DawnGame &game, float_t delta) { int32_t DawnHost::update(DawnGame *game, float_t delta) {
auto ret = game.update(delta); auto ret = game->update(delta);
switch(ret) { switch(ret) {
case DAWN_GAME_UPDATE_RESULT_SUCCESS: case DAWN_GAME_UPDATE_RESULT_SUCCESS:
return DAWN_HOST_UPDATE_RESULT_SUCCESS; return DAWN_HOST_UPDATE_RESULT_SUCCESS;
@ -119,7 +119,7 @@ int32_t DawnHost::update(DawnGame &game, float_t delta) {
} }
} }
void DawnHost::unload(DawnGame &game) { void DawnHost::unload(DawnGame *game) {
glfwDestroyWindow(this->data->window); glfwDestroyWindow(this->data->window);
this->data->window = nullptr; this->data->window = nullptr;
glfwTerminate(); glfwTerminate();

View File

@ -8,7 +8,7 @@
using namespace Dawn; using namespace Dawn;
InputManager::InputManager(DawnGame &game) : IInputManager<int32_t>(game) { InputManager::InputManager(DawnGame *game) : IInputManager<int32_t>(game) {
} }

View File

@ -14,6 +14,6 @@ namespace Dawn {
public: public:
std::map<int32_t, float_t> rawInputValues; std::map<int32_t, float_t> rawInputValues;
InputManager(DawnGame &game); InputManager(DawnGame *game);
}; };
} }

View File

@ -11,11 +11,11 @@ int32_t main(int32_t argc, char **args) {
int32_t result; int32_t result;
// Create the host // Create the host
auto host = std::make_shared<DawnHost>(); auto host = new DawnHost();
auto game = std::make_shared<DawnGame>(*host); auto game = new DawnGame(host);
// Initialize the host and error check // Initialize the host and error check
result = host->init(*game); result = host->init(game);
switch(result) { switch(result) {
case DAWN_HOST_INIT_RESULT_SUCCESS: case DAWN_HOST_INIT_RESULT_SUCCESS:
break; break;
@ -24,7 +24,7 @@ int32_t main(int32_t argc, char **args) {
} }
// Request the main loop to start running. // Request the main loop to start running.
result = host->start(*game); result = host->start(game);
switch(result) { switch(result) {
case DAWN_HOST_START_RESULT_SUCCESS: case DAWN_HOST_START_RESULT_SUCCESS:
break; break;
@ -35,7 +35,10 @@ int32_t main(int32_t argc, char **args) {
} }
// Main loop finished without errors, cleanup // Main loop finished without errors, cleanup
host->unload(*game); host->unload(game);
delete game;
delete host;
// Success // Success
return 0; return 0;

View File

@ -25,7 +25,7 @@ void BackBufferRenderTarget::setSize(float_t width, float_t height) {
this->width = width; this->width = width;
this->height = height; this->height = height;
this->eventRenderTargetResized.invoke(*this, width, height); this->eventRenderTargetResized.invoke(this, width, height);
} }
void BackBufferRenderTarget::setClearColor(struct Color color) { void BackBufferRenderTarget::setClearColor(struct Color color) {

View File

@ -10,13 +10,13 @@
using namespace Dawn; using namespace Dawn;
RenderManager::RenderManager(DawnGame &game) : RenderManager::RenderManager(DawnGame *game) :
IRenderManager(game), IRenderManager(game),
backBuffer(*this) backBuffer(*this)
{ {
this->standardRenderPipeline=std::make_shared<StandardRenderPipeline>(*this); this->standardRenderPipeline = new StandardRenderPipeline(this);
this->simpleShader = std::make_shared<SimpleTexturedShader>(); this->simpleShader = new SimpleTexturedShader();
this->uiShader = std::make_shared<UIShader>(); this->uiShader = new UIShader();
} }
void RenderManager::init() { void RenderManager::init() {
@ -24,7 +24,6 @@ void RenderManager::init() {
this->simpleShader->compile(); this->simpleShader->compile();
this->uiShader->compile(); this->uiShader->compile();
// Prepare the initial values // Prepare the initial values
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -32,19 +31,19 @@ void RenderManager::init() {
glDepthFunc(GL_LESS); glDepthFunc(GL_LESS);
} }
RenderTarget & RenderManager::getBackBuffer() { RenderTarget * RenderManager::getBackBuffer() {
return this->backBuffer; return &this->backBuffer;
} }
RenderPipeline & RenderManager::getRenderPipeline() { RenderPipeline * RenderManager::getRenderPipeline() {
return *this->standardRenderPipeline; return this->standardRenderPipeline;
} }
std::shared_ptr<Shader> RenderManager::getDefaultShader() { Shader * RenderManager::getDefaultShader() {
return this->simpleShader; return this->simpleShader;
} }
std::shared_ptr<UIShader> RenderManager::getUIShader() { UIShader * RenderManager::getUIShader() {
return this->uiShader; return this->uiShader;
} }
@ -65,9 +64,11 @@ void RenderManager::setRenderFlags(renderflag_t flags) {
} }
void RenderManager::update() { void RenderManager::update() {
this->getRenderPipeline().render(); this->getRenderPipeline()->render();
} }
RenderManager::~RenderManager() { RenderManager::~RenderManager() {
delete this->standardRenderPipeline;
delete this->simpleShader;
delete this->uiShader;
} }

View File

@ -13,22 +13,22 @@ namespace Dawn {
class RenderManager : public IRenderManager { class RenderManager : public IRenderManager {
private: private:
std::shared_ptr<StandardRenderPipeline> standardRenderPipeline; StandardRenderPipeline *standardRenderPipeline;
public: public:
BackBufferRenderTarget backBuffer; BackBufferRenderTarget backBuffer;
std::shared_ptr<SimpleTexturedShader> simpleShader; SimpleTexturedShader *simpleShader;
std::shared_ptr<UIShader> uiShader; UIShader *uiShader;
/** /**
* Construct a new RenderManager for a game instance. * Construct a new RenderManager for a game instance.
*/ */
RenderManager(DawnGame &game); RenderManager(DawnGame *game);
RenderTarget & getBackBuffer() override; RenderTarget * getBackBuffer() override;
RenderPipeline & getRenderPipeline() override; RenderPipeline * getRenderPipeline() override;
std::shared_ptr<Shader> getDefaultShader() override; Shader * getDefaultShader() override;
std::shared_ptr<UIShader> getUIShader() override; UIShader * getUIShader() override;
void setRenderFlags(renderflag_t renderFlags) override; void setRenderFlags(renderflag_t renderFlags) override;
void init() override; void init() override;
void update() override; void update() override;

View File

@ -8,7 +8,7 @@
using namespace Dawn; using namespace Dawn;
StandardRenderPipeline::StandardRenderPipeline(RenderManager &renderManager) : StandardRenderPipeline::StandardRenderPipeline(RenderManager *renderManager) :
RenderPipeline(renderManager) RenderPipeline(renderManager)
{ {
} }

View File

@ -10,6 +10,6 @@
namespace Dawn { namespace Dawn {
class StandardRenderPipeline : public RenderPipeline { class StandardRenderPipeline : public RenderPipeline {
public: public:
StandardRenderPipeline(RenderManager &renderManager); StandardRenderPipeline(RenderManager *renderManager);
}; };
} }

View File

@ -18,8 +18,6 @@ namespace Dawn {
GLuint id = -1; GLuint id = -1;
public: public:
void bind(textureslot_t slot);
int32_t getWidth() override; int32_t getWidth() override;
int32_t getHeight() override; int32_t getHeight() override;
void setSize(int32_t width, int32_t height) override; void setSize(int32_t width, int32_t height) override;
@ -27,6 +25,13 @@ namespace Dawn {
bool_t isReady() override; bool_t isReady() override;
void buffer(struct Color pixels[]) override; void buffer(struct Color pixels[]) override;
/**
* Binds the texture to the given slot (for use by the shaders).
*
* @param slot Slot to bind to.
*/
void bind(textureslot_t slot);
~Texture(); ~Texture();
}; };
} }

View File

@ -6,6 +6,7 @@
#pragma once #pragma once
#include "display/mesh/_Mesh.hpp" #include "display/mesh/_Mesh.hpp"
#include "dawnopengl.hpp" #include "dawnopengl.hpp"
#include "assert/assert.hpp"
/** Indice that references a specific vertice */ /** Indice that references a specific vertice */
typedef int32_t meshindice_t; typedef int32_t meshindice_t;

View File

@ -28,8 +28,8 @@ namespace Dawn {
return ps; return ps;
} }
void setDefaultParameters(Material &material) override { void setDefaultParameters(Material *material) override {
material.colorValues[this->paramColor] = COLOR_WHITE; material->colorValues[this->paramColor] = COLOR_WHITE;
} }
void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override { void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override {

View File

@ -28,8 +28,8 @@ namespace Dawn {
return ps; return ps;
} }
void setDefaultParameters(Material &material) override { void setDefaultParameters(Material *material) override {
material.colorValues[this->paramColor] = COLOR_WHITE; material->colorValues[this->paramColor] = COLOR_WHITE;
} }
void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override { void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override {

View File

@ -10,13 +10,13 @@
using namespace Dawn; using namespace Dawn;
std::shared_ptr<TrueTypeAsset> assetFont; TrueTypeAsset *assetFont;
std::shared_ptr<TextureAsset> assetTexture; TextureAsset *assetTexture;
DawnGame::DawnGame(DawnHost &host) : DawnGame::DawnGame(DawnHost *host) :
host(host), host(host),
renderManager(*this), renderManager(this),
inputManager(*this) inputManager(this)
{ {
} }
@ -24,11 +24,11 @@ int32_t DawnGame::init() {
this->assetManager.init(); this->assetManager.init();
this->renderManager.init(); this->renderManager.init();
this->scene = std::make_shared<Scene>(*this); this->scene = new Scene(this);
auto cameraObject = this->scene->createSceneItem(); auto cameraObject = this->scene->createSceneItem();
auto camera = cameraObject->addComponent<Camera>(); auto camera = cameraObject->addComponent<Camera>();
camera->transform.lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0)); camera->transform->lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0));
auto canvas = UICanvas::createCanvas(this->scene); auto canvas = UICanvas::createCanvas(this->scene);
@ -39,7 +39,7 @@ int32_t DawnGame::init() {
} }
auto textbox = canvas->addElement<VisualNovelTextbox>(); auto textbox = canvas->addElement<VisualNovelTextbox>();
textbox->setBorder(assetTexture->texture.get(), glm::vec2(16, 16)); textbox->setBorder(&assetTexture->texture, glm::vec2(16, 16));
textbox->setFont(&assetFont->font); textbox->setFont(&assetFont->font);
textbox->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus leo odio, egestas nec imperdiet ac, placerat eget quam. Nam tellus justo, aliquam sed porta quis, ullamcorper in libero. Proin auctor eget elit nec rutrum. Vestibulum tincidunt sem vel nisi sagittis, sed imperdiet eros aliquet. Fusce a ultrices augue, at auctor lacus. Sed lobortis, ante vitae vehicula egestas, lorem turpis cursus dui, sit amet egestas mauris ligula non ipsum. Pellentesque scelerisque posuere lorem sit amet tempor. Praesent ac hendrerit mi. Nulla mollis diam vitae vestibulum aliquam. Nullam metus justo, viverra sed risus eu, tincidunt sodales lacus. Quisque efficitur accumsan posuere. Aliquam posuere volutpat diam quis lacinia. Nullam blandit nulla vestibulum mi placerat varius. Proin egestas lacus nec pellentesque iaculis. Vestibulum ex metus, congue in eleifend et, scelerisque a nulla. Pellentesque cursus lectus sed arcu efficitur tincidunt. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla a felis non velit fermentum ullamcorper.", 40); textbox->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus leo odio, egestas nec imperdiet ac, placerat eget quam. Nam tellus justo, aliquam sed porta quis, ullamcorper in libero. Proin auctor eget elit nec rutrum. Vestibulum tincidunt sem vel nisi sagittis, sed imperdiet eros aliquet. Fusce a ultrices augue, at auctor lacus. Sed lobortis, ante vitae vehicula egestas, lorem turpis cursus dui, sit amet egestas mauris ligula non ipsum. Pellentesque scelerisque posuere lorem sit amet tempor. Praesent ac hendrerit mi. Nulla mollis diam vitae vestibulum aliquam. Nullam metus justo, viverra sed risus eu, tincidunt sodales lacus. Quisque efficitur accumsan posuere. Aliquam posuere volutpat diam quis lacinia. Nullam blandit nulla vestibulum mi placerat varius. Proin egestas lacus nec pellentesque iaculis. Vestibulum ex metus, congue in eleifend et, scelerisque a nulla. Pellentesque cursus lectus sed arcu efficitur tincidunt. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla a felis non velit fermentum ullamcorper.", 40);
textbox->setTransform( textbox->setTransform(

View File

@ -10,13 +10,13 @@
namespace Dawn { namespace Dawn {
class DawnGame : public IDawnGame { class DawnGame : public IDawnGame {
public: public:
DawnHost &host; DawnHost *host;
RenderManager renderManager; RenderManager renderManager;
AssetManager assetManager; AssetManager assetManager;
InputManager inputManager; InputManager inputManager;
TimeManager timeManager; TimeManager timeManager;
DawnGame(DawnHost &host); DawnGame(DawnHost *host);
int32_t init() override; int32_t init() override;
int32_t update(float_t delta) override; int32_t update(float_t delta) override;
}; };

View File

@ -11,11 +11,11 @@ int32_t main(int32_t argc, char **args) {
int32_t result; int32_t result;
// Create the host // Create the host
auto host = std::make_shared<DawnHost>(); auto host = new DawnHost();
auto game = std::make_shared<DawnGame>(*host); auto game = new DawnGame(host);
// Initialize the host and error check // Initialize the host and error check
result = host->init(*game); result = host->init(game);
switch(result) { switch(result) {
case DAWN_HOST_INIT_RESULT_SUCCESS: case DAWN_HOST_INIT_RESULT_SUCCESS:
break; break;
@ -24,7 +24,7 @@ int32_t main(int32_t argc, char **args) {
} }
// Request the main loop to start running. // Request the main loop to start running.
result = host->start(*game); result = host->start(game);
switch(result) { switch(result) {
case DAWN_HOST_START_RESULT_SUCCESS: case DAWN_HOST_START_RESULT_SUCCESS:
break; break;
@ -35,7 +35,10 @@ int32_t main(int32_t argc, char **args) {
} }
// Main loop finished without errors, cleanup // Main loop finished without errors, cleanup
host->unload(*game); host->unload(game);
delete game;
delete host;
// Success // Success
return 0; return 0;