Started work on prefabs.

This commit is contained in:
2022-12-19 22:41:16 -08:00
parent 53ebbf0699
commit d619e33763
24 changed files with 403 additions and 15 deletions

View File

@ -3,9 +3,6 @@
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# DEBUG
set(DAWN_BUILDING dawnpokergame)
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)

View File

@ -6,9 +6,9 @@
# Check for build target, or default
if(NOT DEFINED DAWN_BUILD_TARGET)
if(WIN32)
set(DAWN_BUILD_TARGET "target-pokergame-win32-glfw")
set(DAWN_BUILD_TARGET "target-barrygame-win32-glfw")
elseif(UNIX AND NOT APPLE)
set(DAWN_BUILD_TARGET "target-pokergame-linux64-glfw")
set(DAWN_BUILD_TARGET "target-barrygame-linux64-glfw")
endif()
endif()

View File

@ -0,0 +1,8 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(DAWN_BUILDING dawnbarrygame CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_WIN32 true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})

View File

@ -3,5 +3,6 @@
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(DAWN_BUILDING dawnpokergame CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_LINUX64 true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})

View File

@ -3,5 +3,6 @@
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(DAWN_BUILDING dawnpokergame CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_WIN32 true CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(DAWN_TARGET_GLFW true CACHE INTERNAL ${DAWN_CACHE_TARGET})

View File

@ -21,7 +21,9 @@ void RenderPipeline::init() {
}
void RenderPipeline::render() {
this->renderScene(this->renderManager->game->scene);
if(this->renderManager->game->scene != nullptr) {
this->renderScene(this->renderManager->game->scene);
}
}
void RenderPipeline::renderScene(Scene *scene) {

View File

@ -23,7 +23,7 @@ namespace Dawn {
class IDawnGame {
public:
Scene *scene;
Scene *scene = nullptr;
/**
* Initialize the game. This is performed by the host at a time that is

60
src/dawn/scene/Prefab.hpp Normal file
View File

@ -0,0 +1,60 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "SceneItem.hpp"
#include "SceneItemComponent.hpp"
#include "scene/components/Components.hpp"
#include "util/array.hpp"
namespace Dawn {
class Prefab {
public:
/**
* Returns a list of assets that this prefab requires to be loaded for the
* instanciation to work.
*
* @param man Asset Manager to retreive the assets from.
* @return List of required assets, includes sibling/child assets.
*/
static virtual std::vector<Asset*> getAssets(AssetManager *man) = 0;
/**
* Create a scene item from this prefab.
*
* @param scene Scene to add the item to.
* @return The created scene item for this prefab.
*/
static virtual SceneItem * create(Scene *scene) = 0;
};
template<class T>
class UIPrefab : public Prefab {
public:
/** @deprecated */
static SceneItem * create(Scene *scene) override {
assertUnreachable();
}
/**
* Applies a UI Prefab styling to an existing UI Element.
*
* @param existing Existing item to apply styling to.
*/
static virtual void uiApply(T *existing) = 0;
/**
* Creates a UI Item from this prefab.
*
* @param canvas Canvas to create this item on to.
* @return Pointer to the created UI Item.
*/
static virtual T * uiCreate(UICanvas *canvas) {
auto item = canvas->addElement<T>();
uiApply(item);
return item;
}
}
}

View File

@ -29,7 +29,7 @@ void SimpleVNScene::stage() {
// UI
this->canvas = UICanvas::createCanvas(this);
this->textbox = PokerGameTextbox::create(canvas);
this->textbox = Prefab::create<VisualNovelTextboxPrefab>(this)->getComponent<VisualNovelTextbox>();
this->background = SimpleVisualNovelBackground::create(this);
// VN Manager

View File

@ -8,7 +8,7 @@
#include "game/DawnGame.hpp"
#include "util/array.hpp"
#include "scene/components/Components.hpp"
#include "ui/PokerGameTextbox.hpp"
#include "prefabs/VisualNovelTextboxPrefab.hpp"
#include "visualnovel/VisualNovelManager.hpp"
#include "visualnovel/events/VisualNovelTextboxEvent.hpp"
#include "visualnovel/events/VisualNovelPauseEvent.hpp"

View File

@ -0,0 +1,37 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Set up the executable
set(DAWN_TARGET_NAME "BarryGame" CACHE INTERNAL ${DAWN_CACHE_TARGET})
# Build Project
add_executable(${DAWN_TARGET_NAME})
# Includes
target_include_directories(${DAWN_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
# Subdirs
add_subdirectory(game)
add_subdirectory(save)
# Assets
tool_language(language_en games/barrygame/locale/en.csv)
tool_texture(texture_test texture_test.png)
tool_truetype(truetype_ark
ark-pixel.ttf
truetype_ark
96
96
10
)
add_dependencies(${DAWN_TARGET_NAME}
language_en
texture_test
truetype_ark
)

View File

@ -0,0 +1,10 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
DawnGame.cpp
)

View File

@ -0,0 +1,43 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "DawnGame.hpp"
#include "scenes/TestScene.hpp"
using namespace Dawn;
TrueTypeAsset *assetFont;
TextureAsset *assetTexture;
DawnGame::DawnGame(DawnHost *host) :
host(host),
renderManager(this),
inputManager(this),
localeManager(this),
saveManager(this)
{
}
int32_t DawnGame::init() {
this->assetManager.init();
this->localeManager.init();
this->renderManager.init();
this->scene = new TestScene(this);
return DAWN_GAME_INIT_RESULT_SUCCESS;
}
int32_t DawnGame::update(float_t delta) {
this->assetManager.update();
this->inputManager.update();
this->timeManager.update(delta);
if(this->scene != nullptr) this->scene->update();
this->renderManager.update();
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
}

View File

@ -0,0 +1,26 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "game/_DawnGame.hpp"
#include "scene/components/Components.hpp"
#include "save/BarrySaveManager.hpp"
namespace Dawn {
class DawnGame : public IDawnGame {
public:
DawnHost *host;
RenderManager renderManager;
AssetManager assetManager;
InputManager inputManager;
TimeManager timeManager;
LocaleManager localeManager;
BarrySaveManager saveManager;
DawnGame(DawnHost *host);
int32_t init() override;
int32_t update(float_t delta) override;
};
}

View File

@ -0,0 +1,9 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "input/InputManager.hpp"
#define INPUT_BIND_ACCEPT ((inputbind_t)1)

View File

@ -0,0 +1,38 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/Prefab.hpp"
#include "ui/UIBorder.hpp"
#include "asset/assets/TextureAsset.hpp"
#include "game/DawnGame.hpp"
#define UI_BORDER_TEXTURE_ASSET "texture_test"
namespace Dawn {
class UIBorderPrefab : public UIPrefab<UIBorder> {
protected:
static std::vector<Asset*> getAssets(AssetManager *man) override {
return std::vector<Asset*>{
man->get<TextureAsset>(UI_BORDER_TEXTURE_ASSET)
};
}
static SceneItem * uiCreate(UICanvas *canvas) override {
auto border = canvas->addElement<UIBorder>();
UIPrefab::uiApply(border);
return border;
}
public:
void uiApply(UIBorder *border) {
border->texture = &border
->getGame()
->assetManager.get<TextureAsset>(UI_BORDER_TEXTURE_ASSET)->texture
;
border->setBorderSize(glm::vec2(16, 16));
}
}
}

View File

@ -0,0 +1,36 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "prefabs/UIBorderPrefab.hpp"
#include "visualnovel/ui/VisualNovelTextbox.hpp"
namespace Dawn {
class VisualNovelTextboxPrefab : public UIPrefab<VisualNovelTextbox> {
public:
static std::vector<Asset*> getAssets(AssetManager *man) {
std::vector<Asset*> assets{
man->get<TrueTypeAsset>("truetype_ark")
};
vectorAppend(&assets, &UIBorderPrefab::getAssets(man));
return assets;
}
static void uiApply(VisualNovelTextbox *textbox) override {
assertNotNull(textbox);
auto assetFont = textbox->getGame()->assetManager.get<TrueTypeAsset>("truetype_ark");
UIBorderPrefab::uiApply(&textbox->border);
textbox->setFont(&assetFont->font);
textbox->setFontSize(40);
textbox->setLabelPadding(glm::vec2(10, 8));
textbox->setTransform(
UI_COMPONENT_ALIGN_STRETCH, UI_COMPONENT_ALIGN_END,
glm::vec4(0, 238, 0, 0),
0.0f
);
}
}
}

View File

@ -0,0 +1,28 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "BarrySaveManager.hpp"
using namespace Dawn;
BarrySaveManager::BarrySaveManager(DawnGame *game) : SaveManager(game) {
}
bool_t BarrySaveManager::validateSave(struct SaveFile raw) {
if(!raw.has(POKER_SAVE_KEY_EXAMPLE)) return true;
this->currentSave.copy(raw, POKER_SAVE_KEY_EXAMPLE);
return false;
}
void BarrySaveManager::setExample(int32_t val) {
savedata_t value;
value.i32 = val;
this->currentSave.set(POKER_SAVE_KEY_EXAMPLE, value);
}
int32_t BarrySaveManager::getExample() {
return this->currentSave.get(POKER_SAVE_KEY_EXAMPLE).i32;
}

View File

@ -0,0 +1,22 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "save/SaveManager.hpp"
#define POKER_SAVE_KEY_EXAMPLE "poker.example"
namespace Dawn {
class BarrySaveManager : public SaveManager {
protected:
virtual bool_t validateSave(struct SaveFile raw) override;
public:
BarrySaveManager(DawnGame *game);
void setExample(int32_t value);
int32_t getExample();
};
}

View File

@ -0,0 +1,10 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
BarrySaveManager.cpp
)

View File

@ -0,0 +1,32 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "visualnovel/scene/SimpleVNScene.hpp"
namespace Dawn {
class TestScene : public SimpleVNScene {
protected:
void vnStage() override {
SimpleVNScene::vnStage();
}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, &SimpleVNScene::getRequiredAssets());
return assets;
}
IVisualNovelEvent * getVNEvent() override {
return nullptr;
// auto start = new VisualNovelTextboxEvent(vnManager,nullptr,"scene.1.1");
// return start;
}
public:
TestScene(DawnGame *game) : SimpleVNScene(game) {}
}
}

View File

@ -4,13 +4,10 @@
// https://opensource.org/licenses/MIT
#include "DawnGame.hpp"
#include "scenes/TestScene.hpp"
#include "scenes/Scene_1_1.hpp"
using namespace Dawn;
TrueTypeAsset *assetFont;
TextureAsset *assetTexture;
DawnGame::DawnGame(DawnHost *host) :
host(host),
renderManager(this),
@ -25,7 +22,7 @@ int32_t DawnGame::init() {
this->localeManager.init();
this->renderManager.init();
this->scene = new TestScene(this);
this->scene = new Scene_1_1(this);
return DAWN_GAME_INIT_RESULT_SUCCESS;
}

View File

@ -0,0 +1,31 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "SimpleVNScene.hpp"
namespace Dawn {
class Scene_1_1 : public SimpleVNScene {
protected:
void vnStage() override {
SimpleVNScene::vnStage();
}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, &SimpleVNScene::getRequiredAssets());
return assets;
}
IVisualNovelEvent * getVNEvent() override {
auto start = new VisualNovelTextboxEvent(vnManager,nullptr,"scene.1.1");
return start;
}
public:
Scene_1_1(DawnGame *game) : SimpleVNScene(game) {}
};
}

View File

@ -41,7 +41,7 @@ namespace Dawn {
);
start
->then(new VisualNovelTextboxEvent(vnManager, penny->getComponent<VisualNovelCharacter>(), "undefined"))
->then(new VisualNovelTextboxEvent(vnManager, penny->getComponent<VisualNovelCharacter>(), "scene.1.1"))
// ->then(new PokerNewGameEvent(vnManager))
->then(new VisualNovelTextboxEvent(vnManager, penny->getComponent<VisualNovelCharacter>(), "undefined"))
// ->then(new PokerInitialEvent(vnManager))