Started work on prefabs.
This commit is contained in:
@ -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) {
|
||||
|
@ -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
60
src/dawn/scene/Prefab.hpp
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
51
src/dawn/visualnovel/scene/SimpleVNScene.cpp
Normal file
51
src/dawn/visualnovel/scene/SimpleVNScene.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SimpleVNScene.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
SimpleVNScene::SimpleVNScene(DawnGame *game) : Scene(game) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::vector<Asset*> SimpleVNScene::getRequiredAssets() {
|
||||
auto assMan = &this->game->assetManager;
|
||||
return PokerGameTextbox::getAssets(assMan);
|
||||
}
|
||||
|
||||
void SimpleVNScene::stage() {
|
||||
// Camera
|
||||
this->camera = Camera::create(this);
|
||||
this->camera->transform->lookAtPixelPerfect(
|
||||
glm::vec3(0, 0, 0),
|
||||
glm::vec3(0, 0, 0),
|
||||
1.0f,
|
||||
camera->fov
|
||||
);
|
||||
|
||||
// UI
|
||||
this->canvas = UICanvas::createCanvas(this);
|
||||
this->textbox = Prefab::create<VisualNovelTextboxPrefab>(this)->getComponent<VisualNovelTextbox>();
|
||||
this->background = SimpleVisualNovelBackground::create(this);
|
||||
|
||||
// VN Manager
|
||||
auto vnManagerItem = this->createSceneItem();
|
||||
this->vnManager = vnManagerItem->addComponent<VisualNovelManager>();
|
||||
|
||||
// Stage VN Items
|
||||
this->vnStage();
|
||||
|
||||
// Fader (Drawn over the top of everything else)
|
||||
this->vnFader = VisualNovelFader::create(canvas);
|
||||
|
||||
// Begin VN.
|
||||
this->vnManager->setEvent(this->getVNEvent());
|
||||
}
|
||||
|
||||
void SimpleVNScene::vnStage() {
|
||||
|
||||
}
|
43
src/dawn/visualnovel/scene/SimpleVNScene.hpp
Normal file
43
src/dawn/visualnovel/scene/SimpleVNScene.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/Scene.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "util/array.hpp"
|
||||
#include "scene/components/Components.hpp"
|
||||
#include "prefabs/VisualNovelTextboxPrefab.hpp"
|
||||
#include "visualnovel/VisualNovelManager.hpp"
|
||||
#include "visualnovel/events/VisualNovelTextboxEvent.hpp"
|
||||
#include "visualnovel/events/VisualNovelPauseEvent.hpp"
|
||||
#include "visualnovel/events/VisualNovelFadeEvent.hpp"
|
||||
#include "visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SimpleVNScene : public Scene {
|
||||
protected:
|
||||
Camera *camera = nullptr;
|
||||
UICanvas *canvas = nullptr;
|
||||
VisualNovelTextbox *textbox = nullptr;
|
||||
SimpleVisualNovelBackground *background = nullptr;
|
||||
VisualNovelFader *vnFader = nullptr;
|
||||
VisualNovelManager *vnManager = nullptr;
|
||||
|
||||
virtual void vnStage();
|
||||
virtual IVisualNovelEvent * getVNEvent() = 0;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a new Simple VN Scene. Custom class that implements the most
|
||||
* common VN Things.
|
||||
*
|
||||
* @param game
|
||||
*/
|
||||
SimpleVNScene(DawnGame *game);
|
||||
|
||||
std::vector<Asset*> getRequiredAssets() override;
|
||||
void stage() override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user