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
add_subdirectory(assert)
add_subdirectory(asset)
add_subdirectory(display)
add_subdirectory(input)

View File

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

View File

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

View File

@ -13,11 +13,6 @@
#if ASSERTS_ENABLED == 0
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
@ -45,13 +40,6 @@ static inline void assertDeprecated() {}
*/
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.
* @param pointer Pointer to assert is nullptr.
@ -66,9 +54,5 @@ static inline void assertDeprecated() {}
#else
#define assertTrue assert
#define assertFalse(x) assertTrue(x == 0)
#define assertNotNull(x) assert(x != NULL)
#define assertUnreachable() assert(false)
#define assertDeprecated assertUnreachable
#endif

View File

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

View File

@ -5,13 +5,14 @@
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
namespace Dawn {
class AssetManager;
class Asset {
public:
AssetManager &assetManager;
AssetManager *assetManager;
std::string name;
uint8_t state = 0x00;
bool loaded = false;
@ -22,7 +23,7 @@ namespace Dawn {
* @param assetManager Asset manager that this asset belongs to.
* @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

View File

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

View File

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

View File

@ -29,9 +29,24 @@ void AssetManager::update() {
if(asset->loaded) {
it = this->assetsNotLoaded.erase(it);
this->assets[asset->name] = asset;
continue;
}
++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
#pragma once
#include "asset/Asset.hpp"
#include "Asset.hpp"
namespace Dawn {
class AssetManager {
private:
/** List of pointers to assets, mapped by their asset key. */
std::map<std::string, std::shared_ptr<Asset>> assets;
std::map<std::string, std::shared_ptr<Asset>> assetsNotLoaded;
std::map<std::string, Asset*> assets;
std::map<std::string, Asset*> assetsNotLoaded;
public:
void init();
@ -24,15 +24,19 @@ namespace Dawn {
* @return The asset element to be loaded.
*/
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);
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->assetsNotLoaded[name] = asset;
return asset;
}
~AssetManager();
};
}

View File

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

View File

@ -17,13 +17,24 @@ namespace Dawn {
struct Color *colors;
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 updateAsync() override;
/**
* Dispose / Cleanup the texture asset. Will also dispose the underlying
* texture itself.
*/
~TextureAsset();
};
}

View File

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

View File

@ -20,11 +20,21 @@ namespace Dawn {
public:
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 updateAsync() override;
/**
* Disposes / Cleans up the truetype asset.
*/
~TrueTypeAsset();
};
}

View File

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

View File

@ -14,7 +14,7 @@
namespace Dawn {
class RenderPipeline {
public:
RenderManager &renderManager;
RenderManager *renderManager;
/**
* 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.
*/
RenderPipeline(RenderManager &renderManager);
RenderPipeline(RenderManager *renderManager);
/**
* Initialize the render pipeline.
@ -41,7 +41,7 @@ namespace Dawn {
*
* @param scene Scene to render.
*/
virtual void renderScene(Scene &scene);
virtual void renderScene(Scene *scene);
/**
* Render a specific camera on a specific scene.
@ -49,7 +49,7 @@ namespace Dawn {
* @param scene 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.
@ -59,9 +59,9 @@ namespace Dawn {
* @param canvas Canvas to render.
*/
virtual void renderUI(
Scene &scene,
Camera &camera,
UICanvas &canvas
Scene *scene,
Camera *camera,
UICanvas *canvas
);
/**

View File

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

View File

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

View File

@ -5,12 +5,13 @@
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
#include "util/flag.hpp"
namespace Dawn {
class SceneItem;
class Transform : public std::enable_shared_from_this<Transform> {
class Transform {
private:
// Local (real) values
glm::vec3 localPosition;
@ -37,7 +38,7 @@ namespace Dawn {
void updateChildrenTransforms();
public:
SceneItem &item;
SceneItem *item;
/**
* Constructs a new transform instance. Currently I have bound transforms
@ -48,7 +49,7 @@ namespace Dawn {
*
* @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.

View File

@ -23,15 +23,18 @@ namespace Dawn {
renderflag_t renderFlags = 0;
public:
DawnGame &game;
std::shared_ptr<RenderPipeline> renderPipeline;
DawnGame *game;
RenderPipeline *renderPipeline;
/**
* Default constructor for a render manager instance.
*
* @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
@ -39,7 +42,7 @@ namespace Dawn {
*
* @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
@ -47,7 +50,7 @@ namespace Dawn {
*
* @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
@ -55,14 +58,14 @@ namespace Dawn {
*
* @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.
*
* @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.

View File

@ -9,11 +9,50 @@
namespace Dawn {
class ITexture {
public:
/**
* Returns the width of the texture.
*
* @return Width of the texture.
*/
virtual int32_t getWidth() = 0;
/**
* Returns the height of the texture.
*
* @return Height of the texture.
*/
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;
/**
* Fill a texture with a single color. This is stupidly costly.
*
* @param color Color to fill.
*/
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;
/**
* 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;
};
}

View File

@ -18,17 +18,55 @@
namespace Dawn {
class Font {
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(
std::string text,
float_t fontSize,
float_t maxWidth,
Mesh &mesh,
Mesh *mesh,
struct FontMeasure *info
) = 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;
/**
* 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;
};
}

View File

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

View File

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

View File

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

View File

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

View File

@ -8,11 +8,13 @@
using namespace Dawn;
void CubeMesh::buffer(
Mesh &mesh,
Mesh *mesh,
glm::vec3 pos, glm::vec3 size,
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,
glm::vec3(pos.x+size.x, pos.y, pos.z),
glm::vec3(pos.x, pos.y+size.y, pos.z),
@ -24,7 +26,7 @@ void CubeMesh::buffer(
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(1, 0),
glm::vec2(0, 1),
@ -36,7 +38,7 @@ void CubeMesh::buffer(
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
verticeStart, verticeStart + 1, verticeStart + 3,
verticeStart, verticeStart + 2, verticeStart + 3,

View File

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

View File

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

View File

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

View File

@ -14,6 +14,6 @@ namespace Dawn {
*
* @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.
*/
virtual void setDefaultParameters(Material &material) = 0;
virtual void setDefaultParameters(Material *material) = 0;
/**
* Requested by the render pipeline (typically) to set global level (once

View File

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

View File

@ -21,7 +21,7 @@ namespace Dawn {
class IDawnGame {
public:
std::shared_ptr<Scene> scene;
Scene *scene;
/**
* 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 DawnHost :
public std::enable_shared_from_this<DawnHost>
{
class DawnHost {
public:
std::unique_ptr<DawnHostData> data;
DawnHostData *data;
DawnGame *game;
/**
@ -52,7 +50,7 @@ namespace Dawn {
* @param game Game instance that this host is running for.
* @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
@ -64,7 +62,7 @@ namespace Dawn {
* @param game Game instance that this host is running for.
* @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.
@ -73,7 +71,7 @@ namespace Dawn {
* @param delta How much time has passed (in seconds) since the last tick.
* @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
@ -82,7 +80,7 @@ namespace Dawn {
*
* @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.

View File

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

View File

@ -8,7 +8,8 @@
using namespace Dawn;
Scene::Scene(DawnGame &game) : game(game) {
Scene::Scene(DawnGame *game) {
this->game = game;
this->nextId = 0;
}
@ -26,15 +27,16 @@ void Scene::update() {
// TODO: Tick scene items(?)
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++;
auto item = std::make_shared<SceneItem>(*this, id);
auto item = new SceneItem(this, id);
this->itemsNotInitialized[id] = item;
return item;
}
Scene::~Scene() {
}

View File

@ -13,11 +13,11 @@ namespace Dawn {
class Scene {
private:
sceneitemid_t nextId;
std::map<sceneitemid_t, std::shared_ptr<SceneItem>> items;
std::map<sceneitemid_t, std::shared_ptr<SceneItem>> itemsNotInitialized;
std::map<sceneitemid_t, SceneItem*> items;
std::map<sceneitemid_t, SceneItem*> itemsNotInitialized;
public:
DawnGame &game;
DawnGame *game;
Event<> eventSceneUpdate;
Event<> eventSceneUnpausedUpdate;
@ -26,7 +26,7 @@ namespace Dawn {
*
* @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
@ -39,7 +39,7 @@ namespace Dawn {
*
* @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
@ -50,7 +50,7 @@ namespace Dawn {
* @return Pointer to the found component (and by extension the item).
*/
template<class T>
std::shared_ptr<T> findComponent() {
T * findComponent() {
auto it = this->items.begin();
while(it != this->items.end()) {
auto component = it->second->getComponent<T>();
@ -68,8 +68,8 @@ namespace Dawn {
* @return List of matching compnoents.
*/
template<class T>
std::vector<std::shared_ptr<T>> findComponents() {
std::vector<std::shared_ptr<T>> components;
std::vector<T*> findComponents() {
std::vector<T*> components;
auto it = this->items.begin();
while(it != this->items.end()) {
auto component = it->second->getComponent<T>();

View File

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

View File

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

View File

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

View File

@ -14,8 +14,8 @@ namespace Dawn {
class SceneItemComponent {
public:
SceneItem &item;
Transform &transform;
SceneItem *item;
Transform *transform;
bool_t hasInitialized = false;
/**
@ -25,7 +25,7 @@ namespace Dawn {
*
* @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
@ -45,13 +45,13 @@ namespace Dawn {
* Shorthand to return the scene that this component's item belongs to.
* @return The current scene.
*/
Scene & getScene();
Scene * getScene();
/**
* Shorthand to return the game that this scene belongs to.
* @return The current game.
*/
DawnGame & getGame();
DawnGame * getGame();
/**
* Same as init, but intended for your subclass to override.

View File

@ -9,10 +9,10 @@
using namespace Dawn;
Camera::Camera(SceneItem &item) :
Camera::Camera(SceneItem *item) :
SceneItemComponent(item)
{
this->getRenderTarget().eventRenderTargetResized.addListener(
this->getRenderTarget()->eventRenderTargetResized.addListener(
this, &Camera::onRenderTargetResize
);
}
@ -41,40 +41,40 @@ void Camera::updateProjection() {
}
}
RenderTarget & Camera::getRenderTarget() {
RenderTarget * Camera::getRenderTarget() {
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;
this->getRenderTarget().eventRenderTargetResized.removeListener(
this->getRenderTarget()->eventRenderTargetResized.removeListener(
this, &Camera::onRenderTargetResize
);
this->target = renderTarget;
this->getRenderTarget().eventRenderTargetResized.addListener(
this->getRenderTarget()->eventRenderTargetResized.addListener(
this, &Camera::onRenderTargetResize
);
this->updateProjection();
}
float_t Camera::getAspect() {
RenderTarget &target = this->getRenderTarget();
return target.getWidth() / target.getHeight();
RenderTarget *target = this->getRenderTarget();
return target->getWidth() / target->getHeight();
}
void Camera::onStart() {
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();
}
Camera::~Camera() {
this->getRenderTarget().eventRenderTargetResized.removeListener(
this->getRenderTarget()->eventRenderTargetResized.removeListener(
this, &Camera::onRenderTargetResize
);
}

View File

@ -15,9 +15,9 @@ namespace Dawn {
class Camera : public SceneItemComponent {
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:
glm::mat4 projection;
@ -41,7 +41,7 @@ namespace Dawn {
*
* @param item SceneItem that this component belongs to.
*/
Camera(SceneItem &item);
Camera(SceneItem *item);
/**
* Updates the projection matrix.
@ -54,14 +54,14 @@ namespace Dawn {
*
* @return The target render target framebuffer.
*/
RenderTarget & getRenderTarget();
RenderTarget * getRenderTarget();
/**
* Updates the render target for the camera to use.
*
* @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.

View File

@ -9,10 +9,8 @@
using namespace Dawn;
Material::Material(SceneItem &item) :
SceneItemComponent(item),
shader(item.scene.game.renderManager.getDefaultShader())
{
Material::Material(SceneItem *item) : SceneItemComponent(item) {
this->shader = item->scene->game->renderManager.getDefaultShader();
this->updateShaderParameters();
}
@ -21,7 +19,7 @@ void Material::updateShaderParameters() {
this->boolValues.clear();
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
// shader has actually bound them.
@ -62,11 +60,11 @@ void Material::setShaderParameters() {
}
}
std::shared_ptr<Shader> Material::getShader() {
Shader * Material::getShader() {
return this->shader;
}
void Material::setShader(std::shared_ptr<Shader> shader) {
void Material::setShader(Shader * shader) {
this->shader = shader;
this->updateShaderParameters();
}

View File

@ -12,7 +12,7 @@ namespace Dawn {
class Material : public SceneItemComponent {
private:
std::shared_ptr<Shader> shader;
Shader *shader;
/**
* 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.
*/
Material(SceneItem &item);
Material(SceneItem *item);
/**
* Return the shader this material is currently using.
*
* @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
@ -49,7 +49,7 @@ namespace Dawn {
*
* @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

View File

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

View File

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

View File

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

View File

@ -19,30 +19,58 @@ namespace Dawn {
class UICanvas : public SceneItemComponent {
protected:
void onBackBufferResize(
RenderTarget &target,
RenderTarget *target,
float_t width,
float_t height
);
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;
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>
std::shared_ptr<T> addElement() {
auto item = std::make_shared<T>(*this);
T * addElement() {
auto item = new T(this);
this->children.push_back(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();
/**
* Returns the height of this UI Canvas element.
*
* @return Height of the UI Canvas.
*/
float_t getHeight();
void onStart() override;

View File

@ -7,7 +7,7 @@
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->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;
shader.setUIColor(COLOR_WHITE);
shader.setUIModel(transform);
shader.setUITexture(this->texture);
shader->setUIColor(COLOR_WHITE);
shader->setUIModel(transform);
shader->setUITexture(this->texture);
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);
void updatePositions() override;
void drawSelf(UIShader &shader, glm::mat4 selfTransform) override;
void drawSelf(UIShader *shader, glm::mat4 selfTransform) override;
public:
Texture *texture;
UIBorder(UICanvas &canvas);
UIBorder(UICanvas *canvas);
/**
* Changes the dimensions of the border.

View File

@ -7,16 +7,15 @@
using namespace Dawn;
UIComponent::UIComponent(UICanvas &canvas) :
canvas(canvas)
{
UIComponent::UIComponent(UICanvas *canvas) {
this->canvas = canvas;
}
void UIComponent::updatePositions() {
// X Alignment
if(this->alignX == UI_COMPONENT_ALIGN_STRETCH) {
if(this->parent == nullptr) {
this->width = this->canvas.getWidth();
this->width = this->canvas->getWidth();
} else {
this->width = this->parent->getWidth();
}
@ -28,7 +27,7 @@ void UIComponent::updatePositions() {
} else if(this->alignX == UI_COMPONENT_ALIGN_END) {
this->width = this->alignment[0];
if(this->parent == nullptr) {
this->relativeX = this->canvas.getWidth();
this->relativeX = this->canvas->getWidth();
} else {
this->relativeX = this->parent->getWidth();
}
@ -37,7 +36,7 @@ void UIComponent::updatePositions() {
} else if(this->alignX == UI_COMPONENT_ALIGN_MIDDLE) {
this->width = this->alignment[2];
if(this->parent == nullptr) {
this->relativeX = this->canvas.getWidth();
this->relativeX = this->canvas->getWidth();
} else {
this->relativeX = this->parent->getWidth();
}
@ -47,7 +46,7 @@ void UIComponent::updatePositions() {
// Y Alignment
if(this->alignY == UI_COMPONENT_ALIGN_STRETCH) {
if(this->parent == nullptr) {
this->height = this->canvas.getHeight();
this->height = this->canvas->getHeight();
} else {
this->height = this->parent->getHeight();
}
@ -59,7 +58,7 @@ void UIComponent::updatePositions() {
} else if(this->alignY == UI_COMPONENT_ALIGN_END) {
this->height = this->alignment[1];
if(this->parent == nullptr) {
this->relativeY = this->canvas.getHeight();
this->relativeY = this->canvas->getHeight();
} else {
this->relativeY = this->parent->getHeight();
}
@ -68,7 +67,7 @@ void UIComponent::updatePositions() {
} else if(this->alignY == UI_COMPONENT_ALIGN_MIDDLE) {
this->height = this->alignment[3];
if(this->parent == nullptr) {
this->relativeY = this->canvas.getHeight();
this->relativeY = this->canvas->getHeight();
} else {
this->relativeY = this->parent->getHeight();
}
@ -117,7 +116,7 @@ void UIComponent::setTransform(
this->updatePositions();
}
void UIComponent::draw(UIShader &uiShader, glm::mat4 parentTransform) {
void UIComponent::draw(UIShader *uiShader, glm::mat4 parentTransform) {
// Calculate self transform matrix
glm::mat4 selfTransform = parentTransform * glm::translate(
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 selfTransform Self alignment transform.
*/
virtual void drawSelf(UIShader &uiShader, glm::mat4 selfTransform) = 0;
virtual void drawSelf(UIShader *uiShader, glm::mat4 selfTransform) = 0;
public:
UICanvas &canvas;
UICanvas *canvas;
UIComponent(UICanvas &canvas);
UIComponent(UICanvas *canvas);
/**
* Returns the calculated width, based on the internal alignment values.
@ -106,7 +106,7 @@ namespace Dawn {
float_t z
);
void draw(UIShader &uiShader, glm::mat4 parentTransform);
void draw(UIShader *uiShader, glm::mat4 parentTransform);
/**
* Adds a child to this UI Component.

View File

@ -7,7 +7,7 @@
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->text.size() == 0) return;
float_t width = this->getWidth();
if(width == 0) width = -1;
this->font->buffer(
this->text,
this->fontSize,
this->getWidth(),
this->mesh,
width,
&this->mesh,
&this->measure
);
@ -51,15 +54,15 @@ void UILabel::setFontSize(float_t fontSize) {
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;
this->updateMesh();
shader.setUIColor(this->textColor);
shader.setUIModel(selfTransform);
shader.setUITexture(&this->font->getTexture());
shader->setUIColor(this->textColor);
shader->setUIModel(selfTransform);
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(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,8 +18,6 @@ namespace Dawn {
GLuint id = -1;
public:
void bind(textureslot_t slot);
int32_t getWidth() override;
int32_t getHeight() override;
void setSize(int32_t width, int32_t height) override;
@ -27,6 +25,13 @@ namespace Dawn {
bool_t isReady() 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();
};
}

View File

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

View File

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

View File

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

View File

@ -10,13 +10,13 @@
using namespace Dawn;
std::shared_ptr<TrueTypeAsset> assetFont;
std::shared_ptr<TextureAsset> assetTexture;
TrueTypeAsset *assetFont;
TextureAsset *assetTexture;
DawnGame::DawnGame(DawnHost &host) :
DawnGame::DawnGame(DawnHost *host) :
host(host),
renderManager(*this),
inputManager(*this)
renderManager(this),
inputManager(this)
{
}
@ -24,11 +24,11 @@ int32_t DawnGame::init() {
this->assetManager.init();
this->renderManager.init();
this->scene = std::make_shared<Scene>(*this);
this->scene = new Scene(this);
auto cameraObject = this->scene->createSceneItem();
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);
@ -39,7 +39,7 @@ int32_t DawnGame::init() {
}
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->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(

View File

@ -10,13 +10,13 @@
namespace Dawn {
class DawnGame : public IDawnGame {
public:
DawnHost &host;
DawnHost *host;
RenderManager renderManager;
AssetManager assetManager;
InputManager inputManager;
TimeManager timeManager;
DawnGame(DawnHost &host);
DawnGame(DawnHost *host);
int32_t init() 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;
// Create the host
auto host = std::make_shared<DawnHost>();
auto game = std::make_shared<DawnGame>(*host);
auto host = new DawnHost();
auto game = new DawnGame(host);
// Initialize the host and error check
result = host->init(*game);
result = host->init(game);
switch(result) {
case DAWN_HOST_INIT_RESULT_SUCCESS:
break;
@ -24,7 +24,7 @@ int32_t main(int32_t argc, char **args) {
}
// Request the main loop to start running.
result = host->start(*game);
result = host->start(game);
switch(result) {
case DAWN_HOST_START_RESULT_SUCCESS:
break;
@ -35,7 +35,10 @@ int32_t main(int32_t argc, char **args) {
}
// Main loop finished without errors, cleanup
host->unload(*game);
host->unload(game);
delete game;
delete host;
// Success
return 0;