More Progress
This commit is contained in:
19
src/dawn/CMakeLists.txt
Normal file
19
src/dawn/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Libraries
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
glm
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(scene)
|
43
src/dawn/dawnlibs.hpp
Normal file
43
src/dawn/dawnlibs.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
|
||||
|
||||
// Static Libs
|
||||
extern "C" {
|
||||
// Standard Libs
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef bool bool_t;
|
||||
typedef float float_t;
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
// #include <iterator>
|
||||
// #include <algorithm>
|
||||
// #include <string>
|
||||
// #include <sstream>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
23
src/dawn/display/RenderManager.hpp
Normal file
23
src/dawn/display/RenderManager.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class DawnGame;
|
||||
|
||||
class RenderManager {
|
||||
public:
|
||||
std::weak_ptr<DawnGame> game;
|
||||
|
||||
RenderManager(std::weak_ptr<DawnGame>);
|
||||
|
||||
void init();
|
||||
void update();
|
||||
|
||||
~RenderManager();
|
||||
};
|
||||
}
|
35
src/dawn/game/DawnGame.hpp
Normal file
35
src/dawn/game/DawnGame.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
// 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"
|
||||
|
||||
#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> scene;
|
||||
std::weak_ptr<DawnHost> host;
|
||||
|
||||
public:
|
||||
RenderManager renderManager;
|
||||
|
||||
DawnGame(std::weak_ptr<DawnHost> host);
|
||||
|
||||
int32_t init();
|
||||
int32_t update(float_t delta);
|
||||
|
||||
~DawnGame();
|
||||
};
|
||||
}
|
89
src/dawn/host/DawnHost.hpp
Normal file
89
src/dawn/host/DawnHost.hpp
Normal file
@ -0,0 +1,89 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
/** Implies the host initialized successfully */
|
||||
#define DAWN_HOST_INIT_RESULT_SUCCESS 0
|
||||
|
||||
/** Implies that the update was successful, and the loop should continue */
|
||||
#define DAWN_HOST_UPDATE_RESULT_SUCCESS 0
|
||||
/** Implies that the update was successful, but the loop should not continue */
|
||||
#define DAWN_HOST_UPDATE_RESULT_EXIT 1
|
||||
|
||||
/** Implies that the host started successfully */
|
||||
#define DAWN_HOST_START_RESULT_SUCCESS 0
|
||||
/** Implies that the host started successfully, and then finished everything */
|
||||
#define DAWN_HOST_START_RESULT_EXIT_SUCCESS 1
|
||||
|
||||
namespace Dawn {
|
||||
/**
|
||||
* DawnHostData is a custom forwarder that allows any host to define what it
|
||||
* will need access to, data-wise. For example, GLFW+GLAD uses this to hold
|
||||
* the window handle during the hosts' session, so that it can destroy it
|
||||
* safely when the host is unloaded.
|
||||
*/
|
||||
class DawnHostData;
|
||||
|
||||
class DawnHost {
|
||||
public:
|
||||
std::unique_ptr<DawnHostData> data;
|
||||
|
||||
/**
|
||||
* Construct a new DawnHost. Hosts are set by the various dawn platform
|
||||
* libraries to be handled in different ways depending on the exact
|
||||
* system. For example, Windows can support both GLFW+GLAD or SDL and may
|
||||
* opt to invoke a DawnHost for either of these scenarios.
|
||||
*/
|
||||
DawnHost();
|
||||
|
||||
/**
|
||||
* Request to initialize the host. Hosts can initialize themselves pretty
|
||||
* much however they want, but they must return a status code, in cases
|
||||
* where some hosts may not be responsible for their own invokation.
|
||||
*
|
||||
* @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(std::weak_ptr<DawnGame> game);
|
||||
|
||||
/**
|
||||
* Request to start the main loop. This method may not exist and may not
|
||||
* need to exist depending on the host. For that reason this is marked as
|
||||
* virtual and is up to the main caller to know how this start method
|
||||
* needs to be called. Start should request update() to be invoked if it
|
||||
* does begin the main thread.
|
||||
*
|
||||
* @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(std::weak_ptr<DawnGame> game);
|
||||
|
||||
/**
|
||||
* Requests the host to perform a main-thread update.
|
||||
*
|
||||
* @param game Game instance that this host is running for.
|
||||
* @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(std::weak_ptr<DawnGame> game, float_t delta);
|
||||
|
||||
/**
|
||||
* Request the host to be unloaded. This is a bit different from dispose
|
||||
* as we are likely to unload the host just after the game is unloaded,
|
||||
* but before the parent program has requested memory freeing.
|
||||
*
|
||||
* @param game Game instance that this host is running for.
|
||||
*/
|
||||
void unload(std::weak_ptr<DawnGame> game);
|
||||
|
||||
/**
|
||||
* Destroy (and unload) all of the DawnHost data from memory.
|
||||
*/
|
||||
~DawnHost();
|
||||
};
|
||||
}
|
15
src/dawn/scene/CMakeLists.txt
Normal file
15
src/dawn/scene/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
# 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
|
||||
Scene.cpp
|
||||
SceneItem.cpp
|
||||
SceneItemComponent.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(components)
|
44
src/dawn/scene/Scene.cpp
Normal file
44
src/dawn/scene/Scene.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Scene.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Scene::Scene(std::weak_ptr<DawnGame> game) {
|
||||
this->game = game;
|
||||
this->nextId = 0;
|
||||
}
|
||||
|
||||
void Scene::update() {
|
||||
// Finsh adding scene items that were trying to add from the last frame.
|
||||
auto it = this->itemsNotInitialized.begin();
|
||||
while(it != this->itemsNotInitialized.end()) {
|
||||
this->items[it->first] = it->second;
|
||||
it++;
|
||||
it->second->init();
|
||||
}
|
||||
this->itemsNotInitialized.clear();
|
||||
|
||||
// TODO: Cleanup old scene items
|
||||
|
||||
// TODO: Tick scene items(?)
|
||||
}
|
||||
|
||||
std::shared_ptr<SceneItem> Scene::createSceneItem() {
|
||||
sceneitemid_t id = this->nextId++;
|
||||
auto item = std::make_shared<SceneItem>(weak_from_this(), id);
|
||||
this->itemsNotInitialized[id] = item;
|
||||
return item;
|
||||
}
|
||||
|
||||
void Scene::removeSceneItem(SceneItem *item) {
|
||||
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
|
||||
}
|
33
src/dawn/scene/Scene.hpp
Normal file
33
src/dawn/scene/Scene.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "SceneItem.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class DawnGame;
|
||||
|
||||
class Scene :
|
||||
public std::enable_shared_from_this<Scene>
|
||||
{
|
||||
private:
|
||||
sceneitemid_t nextId;
|
||||
std::map<sceneitemid_t,std::shared_ptr<SceneItem>> items;
|
||||
std::map<sceneitemid_t,std::shared_ptr<SceneItem>> itemsNotInitialized;
|
||||
|
||||
public:
|
||||
std::weak_ptr<DawnGame> game;
|
||||
|
||||
Scene(std::weak_ptr<DawnGame> game);
|
||||
|
||||
void update();
|
||||
|
||||
std::shared_ptr<SceneItem> createSceneItem();
|
||||
|
||||
void removeSceneItem(SceneItem *item);
|
||||
|
||||
~Scene();
|
||||
};
|
||||
}
|
22
src/dawn/scene/SceneItem.cpp
Normal file
22
src/dawn/scene/SceneItem.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SceneItem.hpp"
|
||||
#include "Scene.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
SceneItem::SceneItem(std::weak_ptr<Scene>, sceneitemid_t id) {
|
||||
this->scene = scene;
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
void SceneItem::init() {
|
||||
|
||||
}
|
||||
|
||||
SceneItem::~SceneItem() {
|
||||
|
||||
}
|
47
src/dawn/scene/SceneItem.hpp
Normal file
47
src/dawn/scene/SceneItem.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "SceneItemComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
typedef int32_t sceneitemid_t;
|
||||
|
||||
class Scene;
|
||||
|
||||
class SceneItem {
|
||||
private:
|
||||
std::vector<std::shared_ptr<SceneItemComponent>> components;
|
||||
|
||||
public:
|
||||
std::weak_ptr<Scene> scene;
|
||||
sceneitemid_t id;
|
||||
|
||||
SceneItem(std::weak_ptr<Scene> scene, sceneitemid_t id);
|
||||
|
||||
void init();
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<T> addComponent() {
|
||||
auto component = std::make_unique<T>(this);
|
||||
this->components.push_back(component);
|
||||
return component;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::shared_ptr<T> getComponent() {
|
||||
auto it = this->components.begin();
|
||||
while(it != this->components.end()) {
|
||||
std::shared_ptr<T> castedAs = dynamic_cast<std::shared_ptr<T>>(*it);
|
||||
if(castedAs != nullptr) return castedAs;
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
~SceneItem();
|
||||
};
|
||||
}
|
17
src/dawn/scene/SceneItemComponent.cpp
Normal file
17
src/dawn/scene/SceneItemComponent.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SceneItemComponent.hpp"
|
||||
#include "SceneItem.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
SceneItemComponent::SceneItemComponent(std::weak_ptr<SceneItem> item) {
|
||||
this->item = item;
|
||||
}
|
||||
|
||||
SceneItemComponent::~SceneItemComponent() {
|
||||
|
||||
}
|
22
src/dawn/scene/SceneItemComponent.hpp
Normal file
22
src/dawn/scene/SceneItemComponent.hpp
Normal 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 "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SceneItem;
|
||||
|
||||
class SceneItemComponent {
|
||||
public:
|
||||
std::weak_ptr<SceneItem> item;
|
||||
|
||||
SceneItemComponent(std::weak_ptr<SceneItem> item);
|
||||
|
||||
virtual void start() = 0;
|
||||
|
||||
virtual ~SceneItemComponent();
|
||||
};
|
||||
}
|
10
src/dawn/scene/components/CMakeLists.txt
Normal file
10
src/dawn/scene/components/CMakeLists.txt
Normal 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
|
||||
DummyComponent.cpp
|
||||
)
|
12
src/dawn/scene/components/DummyComponent.cpp
Normal file
12
src/dawn/scene/components/DummyComponent.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "DummyComponent.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void DummyComponent::start() {
|
||||
std::cout << "Dummy Component Start" << std::endl;
|
||||
}
|
18
src/dawn/scene/components/DummyComponent.hpp
Normal file
18
src/dawn/scene/components/DummyComponent.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class DummyComponent : public SceneItemComponent {
|
||||
public:
|
||||
DummyComponent(std::weak_ptr<SceneItem> item) : SceneItemComponent(item) {
|
||||
std::cout << "Dummy Component Initialized" << std::endl;
|
||||
};
|
||||
|
||||
void start() override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user