Base refactor
This commit is contained in:
@ -1,10 +1,9 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
DawnGame.cpp
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Game.cpp
|
||||
)
|
@ -1,54 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
DawnGame::DawnGame(const std::weak_ptr<DawnHost> host) :
|
||||
host(host),
|
||||
inputManager(),
|
||||
saveManager(this)
|
||||
{
|
||||
renderManager = std::make_shared<RenderManager>();
|
||||
}
|
||||
|
||||
int32_t DawnGame::init() {
|
||||
this->assetManager.init();
|
||||
this->renderManager->init(weak_from_this());
|
||||
this->scene = dawnGameGetInitialScene(weak_from_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();
|
||||
|
||||
if(this->sceneToCutTo != nullptr) {
|
||||
this->scene = nullptr;
|
||||
this->scene = this->sceneToCutTo;
|
||||
this->sceneToCutTo = nullptr;
|
||||
}
|
||||
|
||||
if(this->closeRequested) {
|
||||
return DAWN_GAME_UPDATE_RESULT_EXIT;
|
||||
}
|
||||
|
||||
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void DawnGame::sceneCutover(std::shared_ptr<Scene> scene) {
|
||||
if(scene == nullptr) scene = this->scene;
|
||||
this->sceneToCutTo = scene;
|
||||
}
|
||||
|
||||
void DawnGame::close() {
|
||||
this->closeRequested = true;
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "display/RenderManager.hpp"
|
||||
#include "asset/AssetManager.hpp"
|
||||
#include "input/InputManager.hpp"
|
||||
#include "time/TimeManager.hpp"
|
||||
#include "input/InputBinds.hpp"
|
||||
#include "save/SaveManager.hpp"
|
||||
|
||||
#define DAWN_GAME_INIT_RESULT_SUCCESS 0
|
||||
#define DAWN_GAME_UPDATE_RESULT_SUCCESS 0
|
||||
#define DAWN_GAME_UPDATE_RESULT_EXIT 1
|
||||
|
||||
namespace Dawn {
|
||||
class DawnHost;
|
||||
|
||||
class DawnGame : public std::enable_shared_from_this<DawnGame> {
|
||||
private:
|
||||
std::shared_ptr<Scene> sceneToCutTo;
|
||||
bool_t closeRequested = false;
|
||||
|
||||
public:
|
||||
const std::weak_ptr<DawnHost> host;
|
||||
std::shared_ptr<Scene> scene;
|
||||
AssetManager assetManager;
|
||||
TimeManager timeManager;
|
||||
std::shared_ptr<RenderManager> renderManager;
|
||||
InputManager inputManager;
|
||||
SaveManager saveManager;
|
||||
|
||||
/**
|
||||
* Construct a new game instance.
|
||||
*
|
||||
* @param host Host that executed this game instantiation.
|
||||
*/
|
||||
DawnGame(const std::weak_ptr<DawnHost> host);
|
||||
|
||||
/**
|
||||
* Initialize the game. This is performed by the host at a time that is
|
||||
* deemed to have the host ready for the game's initialization. This will
|
||||
* return an initialize result, where DAWN_GAME_INIT_RESULT_SUCCESS is
|
||||
* the only "successful" result, anything else is deemed a failure state.
|
||||
*
|
||||
* @param host Pointer to the host that is running this game.
|
||||
* @return The game initialize result.
|
||||
*/
|
||||
int32_t init();
|
||||
|
||||
/**
|
||||
* Performs a game update operation. This operation should occur exactly
|
||||
* once per frame, synchronously on the main thread. Updates can only
|
||||
* have two valid exit results, either DAWN_GAME_UPDATE_RESULT_SUCCESS for
|
||||
* a successful update, and request that we continue to update, or
|
||||
* DAWN_GAME_UPDATE_RESULT_EXIT for a successful update but to request
|
||||
* that no more update operations occur. Any other result is considered a
|
||||
* failure state.
|
||||
*
|
||||
* @param delta Time delta to tick the game by.
|
||||
* @return The game update result.
|
||||
*/
|
||||
int32_t update(float_t delta);
|
||||
|
||||
/**
|
||||
* Changes to a new scene, will dispose the currently active scene as part
|
||||
* of that process. This assumes the other scene has already been loaded
|
||||
* and staged.
|
||||
*
|
||||
* @param scene Scene to cut over to.
|
||||
*/
|
||||
void sceneCutover(std::shared_ptr<Scene> scene);
|
||||
|
||||
/**
|
||||
* Gracefully requests that the game should be closed as soon as possible.
|
||||
*/
|
||||
void close();
|
||||
};
|
||||
|
||||
/**
|
||||
* Unimplemented by default, required by the game as the basic entry point
|
||||
* for which scene should be used by default.
|
||||
*
|
||||
* @param game Game that is requesting this scene.
|
||||
* @return Pointer to a scene that you wish to have as the default scene.
|
||||
*/
|
||||
std::shared_ptr<Scene> dawnGameGetInitialScene(std::weak_ptr<DawnGame> game);
|
||||
}
|
31
src/dawn/game/Game.cpp
Normal file
31
src/dawn/game/Game.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Game.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Game::Game() {
|
||||
|
||||
}
|
||||
|
||||
void Game::init() {
|
||||
renderHost.init();
|
||||
inputManager.init(shared_from_this());
|
||||
}
|
||||
|
||||
void Game::update() {
|
||||
renderHost.update();
|
||||
}
|
||||
|
||||
bool_t Game::isCloseRequested() {
|
||||
return (
|
||||
renderHost.isCloseRequested()
|
||||
);
|
||||
}
|
||||
|
||||
Game::~Game() {
|
||||
|
||||
}
|
46
src/dawn/game/Game.hpp
Normal file
46
src/dawn/game/Game.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "display/RenderHost.hpp"
|
||||
#include "input/InputManager.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class Game : public std::enable_shared_from_this<Game> {
|
||||
public:
|
||||
RenderHost renderHost;
|
||||
InputManager inputManager;
|
||||
|
||||
/**
|
||||
* Constructs the game instance, does not initialize anything.
|
||||
*/
|
||||
Game();
|
||||
|
||||
/**
|
||||
* Initialize the game and all of its components.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Performs a single update tick on the game engine, and in turn all of
|
||||
* the game's sub systems.
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Returns whether the game has been requested to gracefully close at the
|
||||
* next available opportunity.
|
||||
*
|
||||
* @return True if the game should close.
|
||||
*/
|
||||
bool_t isCloseRequested();
|
||||
|
||||
/**
|
||||
* Deconstructs the game instance, does not deinitialize anything.
|
||||
*/
|
||||
virtual ~Game();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user