Simplified DawnGAme a lot

This commit is contained in:
2023-03-15 15:50:29 -07:00
parent 09cb20271b
commit e13158e6c3
35 changed files with 800 additions and 707 deletions

13
assets/example-prefab.xml Normal file
View File

@ -0,0 +1,13 @@
<prefab>
<asset type="bitmapfont" name="font_bitmap" texture="bmfont.png" rows="16" columns="16" />
<component ref="canvas" type="UICanvas" />
<children>
<item>
<component ref="label" type="scene/components/ui/UILabel::UILabel" text="Hello World" font="font_bitmap" />
</item>
<!-- So here you can either do <item> which is recursive, or a prefab if you desire. -->
</children>
</prefab>

5
assets/example-scene.xml Normal file
View File

@ -0,0 +1,5 @@
<scene>
<item>
<component ref="camera" type="Camera" />
</item>
</scene>

View File

@ -6,14 +6,12 @@
# Check for build target, or default. This is pretty much not guaranteed.
if(NOT DEFINED DAWN_BUILD_TARGET)
if(WIN32)
set(DAWN_BUILD_TARGET "target-helloworld-win32-glfw")
set(DAWN_BUILD_TARGET "target-rose-win32-glfw")
elseif(UNIX AND NOT APPLE)
set(DAWN_BUILD_TARGET "target-helloworld-linux64-glfw")
set(DAWN_BUILD_TARGET "target-rose-linux64-glfw")
endif()
endif()
# set(DAWN_BUILD_TARGET "target-helloworld-vita")
# Now validate we have a build target for real
if(NOT DEFINED DAWN_BUILD_TARGET)
message(FATAL_ERROR "You need to define a DAWN_BUILD_TARGET")

View File

@ -0,0 +1,9 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
set(DAWN_BUILDING dawnrose 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})
set(DAWN_TARGET_NAME "Rose" CACHE INTERNAL ${DAWN_CACHE_TARGET})

View File

@ -26,6 +26,7 @@ target_sources(${DAWN_TARGET_NAME}
# Subdirs
add_subdirectory(asset)
add_subdirectory(display)
add_subdirectory(game)
add_subdirectory(games)
add_subdirectory(input)
add_subdirectory(locale)

View File

@ -0,0 +1,10 @@
# 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
)

View File

@ -4,7 +4,6 @@
// https://opensource.org/licenses/MIT
#include "DawnGame.hpp"
#include "scenes/HelloWorldScene.hpp"
using namespace Dawn;
@ -20,7 +19,7 @@ int32_t DawnGame::init() {
this->assetManager.init();
this->renderManager.init();
this->scene = new HelloWorldScene(this);
this->scene = dawnGameGetInitialScene(this);
return DAWN_GAME_INIT_RESULT_SUCCESS;
}

View File

@ -22,12 +22,25 @@
namespace Dawn {
class DawnHost;
class IDawnGame {
protected:
// SceneItemComponentList componentList;
class DawnGame {
private:
Scene *sceneToCutTo = nullptr;
public:
DawnHost *host;
Scene *scene = nullptr;
AssetManager assetManager;
TimeManager timeManager;
RenderManager renderManager;
InputManager inputManager;
SaveManager saveManager;
/**
* Construct a new game instance.
*
* @param host Host that executed this game instantiation.
*/
DawnGame(DawnHost *host);
/**
* Initialize the game. This is performed by the host at a time that is
@ -38,7 +51,7 @@ namespace Dawn {
* @param host Pointer to the host that is running this game.
* @return The game initialize result.
*/
virtual int32_t init() = 0;
int32_t init();
/**
* Performs a game update operation. This operation should occur exactly
@ -52,7 +65,7 @@ namespace Dawn {
* @param delta Time delta to tick the game by.
* @return The game update result.
*/
virtual int32_t update(float_t delta) = 0;
int32_t update(float_t delta);
/**
* Changes to a new scene, will dispose the currently active scene as part
@ -61,13 +74,15 @@ namespace Dawn {
*
* @param scene Scene to cut over to.
*/
virtual void sceneCutover(Scene *scene) = 0;
void sceneCutover(Scene *scene);
};
/**
* Cleanup the memory of the DawnGame instance.
* 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.
*/
virtual ~IDawnGame() {
}
};
Scene * dawnGameGetInitialScene(DawnGame *game);
}

View File

@ -190,7 +190,7 @@ enum SaveLoadResult SaveManager::loadFile() {
}
// Now pass off to the loader
if(this->validateSave(temporaryFile) != false) {
if(saveValidateFile(temporaryFile) != false) {
return SAVE_LOAD_RESULT_ERROR;
}

View File

@ -28,11 +28,6 @@ namespace Dawn {
SAVE_LOAD_RESULT_ERROR
};
class SaveManager {
protected:
int16_t currentSaveSlot = -1;
struct SaveFile currentSave;
/**
* Reads a save file and then validates all of the values. If a value is
* not validated then it will NOT be retained.
@ -40,7 +35,12 @@ namespace Dawn {
* @param file Save file to read from.
* @return Whether or not the save file is corrupt, false for not corrupt.
*/
virtual bool_t validateSave(struct SaveFile raw) = 0;
bool_t saveValidateFile(struct SaveFile raw);
class SaveManager {
protected:
int16_t currentSaveSlot = -1;
struct SaveFile currentSave;
public:
DawnGame *game;

View File

@ -9,7 +9,6 @@ target_sources(${DAWN_TARGET_NAME}
Scene.cpp
SceneItem.cpp
SceneItemComponent.cpp
SceneItemComponentList.cpp
)
# Subdirs

View File

@ -1,38 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct SceneItemComponentRegister {
uint8_t i;
};
class SceneItemComponentList {
private:
std::vector<struct SceneItemComponentRegister> components;
protected:
/**
* Request the list to append a scene item component of type T
* to the registry.
*
* @tparam T Parameter type of the SceneItemComponent
*/
template<class T>
void append() {
struct SceneItemComponentRegister r;
this->components.push_back(r);
}
public:
/**
* Initialies the scene item component list. This constructor is generated
* at build time from the scene item component registry tool.
*/
SceneItemComponentList();
};
}

View File

@ -15,6 +15,3 @@ target_include_directories(${DAWN_TARGET_NAME}
# Subdirs
add_subdirectory(game)
add_subdirectory(save)
# Assets
tool_bitmapfont(testbitmap bmfont.png 16 16)

View File

@ -6,5 +6,5 @@
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
DawnGame.cpp
HelloGame.cpp
)

View File

@ -1,28 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "game/_DawnGame.hpp"
#include "save/DawnGameSaveManager.hpp"
namespace Dawn {
class DawnGame : public IDawnGame {
private:
Scene *sceneToCutTo = nullptr;
public:
DawnHost *host;
RenderManager renderManager;
AssetManager assetManager;
InputManager inputManager;
TimeManager timeManager;
DawnGameSaveManager saveManager;
DawnGame(DawnHost *host);
int32_t init() override;
int32_t update(float_t delta) override;
void sceneCutover(Scene *scene) override;
};
}

View File

@ -0,0 +1,13 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "game/DawnGame.hpp"
#include "scenes/HelloWorldScene.hpp"
using namespace Dawn;
Scene * Dawn::dawnGameGetInitialScene(DawnGame *game) {
return new HelloWorldScene(game);
}

View File

@ -6,5 +6,5 @@
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
DawnGameSaveManager.cpp
HelloSave.cpp
)

View File

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

View File

@ -1,22 +0,0 @@
// Copyright (c) 2023 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 DawnGameSaveManager : public SaveManager {
protected:
virtual bool_t validateSave(struct SaveFile raw) override;
public:
DawnGameSaveManager(DawnGame *game);
void setExample(int32_t value);
int32_t getExample();
};
}

View File

@ -3,6 +3,10 @@
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SceneItemComponentList.hpp"
#include "save/SaveManager.hpp"
using namespace Dawn;
bool_t Dawn::saveValidateFile(struct SaveFile raw) {
return false;
}

View File

@ -0,0 +1,17 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# 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)

View File

@ -0,0 +1,10 @@
# 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
RoseGame.cpp
)

View File

@ -0,0 +1,13 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "game/DawnGame.hpp"
#include "scenes/HelloWorldScene.hpp"
using namespace Dawn;
Scene * Dawn::dawnGameGetInitialScene(DawnGame *game) {
return new HelloWorldScene(game);
}

View File

@ -0,0 +1,19 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "input/InputManager.hpp"
#define INPUT_BIND(n) ((inputbind_t)n)
#define INPUT_BIND_ACCEPT INPUT_BIND(1)
#define INPUT_BIND_NEGATIVE_X INPUT_BIND(2)
#define INPUT_BIND_POSITIVE_X INPUT_BIND(3)
#define INPUT_BIND_NEGATIVE_Y INPUT_BIND(4)
#define INPUT_BIND_POSITIVE_Y INPUT_BIND(5)
#define INPUT_BIND_MOUSE_X INPUT_BIND(6)
#define INPUT_BIND_MOUSE_Y INPUT_BIND(7)
#define INPUT_BIND_MOUSE_CLICK INPUT_BIND(8)
#define INPUT_BIND_CANCEL INPUT_BIND(9)

View File

@ -0,0 +1,10 @@
# 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
RoseSave.cpp
)

View File

@ -0,0 +1,12 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "save/SaveManager.hpp"
using namespace Dawn;
bool_t Dawn::saveValidateFile(struct SaveFile raw) {
return false;
}

View File

@ -0,0 +1,65 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/Scene.hpp"
#include "prefabs/SimpleSpinningCubePrefab.hpp"
#include "scene/components/ui/UILabel.hpp"
#include "scene/components/ui/UIImage.hpp"
#include "display/font/BitmapFont.hpp"
namespace Dawn {
class HelloWorldScene : public Scene {
protected:
Camera *camera;
SimpleSpinningCubePrefab *cube;
UICanvas *canvas;
UILabel *label;
UIImage *image;
BitmapFont font;
void stage() override {
camera = Camera::create(this);
camera->transform->lookAt(glm::vec3(0, 0, 8), glm::vec3(0, 0, 0));
cube = SimpleSpinningCubePrefab::create(this);
canvas = UICanvas::create(this);
auto imageItem = this->createSceneItem();
image = imageItem->addComponent<UIImage>();
image->color = COLOR_BLACK;
imageItem->transform.setParent(canvas->transform);
auto labelItem = this->createSceneItem();
label = labelItem->addComponent<UILabel>();
labelItem->transform.setParent(canvas->transform);
auto assMan = &this->game->assetManager;
auto texture = assMan->get<TextureAsset>("testbitmap_texture");
auto tileset = assMan->get<TilesetAsset>("testbitmap_tileset");
this->font.texture = &texture->texture;
this->font.tileset = &tileset->tileset;
label->text = "Hello World, how are you today? I hope you are doing well. I really like the fact I can ramble in my text for once.";
label->font = &font;
label->maxWidth = 220;
image->alignment = glm::vec4(0, 0, label->getContentWidth(), label->getContentHeight());
}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
assets.push_back(assMan->get<TextureAsset>("testbitmap_texture"));
assets.push_back(assMan->get<TilesetAsset>("testbitmap_tileset"));
return assets;
}
public:
HelloWorldScene(DawnGame *game) : Scene(game) {}
};
}