More Progress
This commit is contained in:
28
src/CMakeLists.txt
Normal file
28
src/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Change what we are building
|
||||
add_subdirectory(dawnpokergame)
|
||||
|
||||
# Check the game project includes the target name
|
||||
if(NOT DEFINED DAWN_TARGET_NAME)
|
||||
message(FATAL_ERROR "You need to define a DAWN_TARGET_NAME")
|
||||
endif()
|
||||
|
||||
# Add in base library
|
||||
add_subdirectory(dawn)
|
||||
|
||||
# Compile entry targets
|
||||
if(DAWN_TARGET_WIN32)
|
||||
add_subdirectory(dawnwin32)
|
||||
else()
|
||||
message(FATAL_ERROR "You need to define an entry target")
|
||||
endif()
|
||||
|
||||
# Compile support targets
|
||||
if(DAWN_TARGET_GLFW)
|
||||
add_subdirectory(dawnglfw)
|
||||
add_subdirectory(dawnopengl)
|
||||
endif()
|
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;
|
||||
};
|
||||
}
|
20
src/dawnglfw/CMakeLists.txt
Normal file
20
src/dawnglfw/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Libs
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
glfw
|
||||
glad
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(host)
|
7
src/dawnglfw/dawnopengl.hpp
Normal file
7
src/dawnglfw/dawnopengl.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
10
src/dawnglfw/host/CMakeLists.txt
Normal file
10
src/dawnglfw/host/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
|
||||
DawnGLFWHost.cpp
|
||||
)
|
104
src/dawnglfw/host/DawnGLFWHost.cpp
Normal file
104
src/dawnglfw/host/DawnGLFWHost.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "DawnGLFWHost.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
// Host
|
||||
DawnHost::DawnHost() {
|
||||
this->data = std::make_unique<DawnHostData>();
|
||||
this->data->window = nullptr;
|
||||
}
|
||||
|
||||
int32_t DawnHost::init(std::weak_ptr<DawnGame> game) {
|
||||
// Init GLFW
|
||||
if(!glfwInit()) return DAWN_GLFW_INIT_RESULT_INIT_FAILED;
|
||||
|
||||
// Create Window
|
||||
this->data->window = glfwCreateWindow(
|
||||
DAWN_GLFW_WINDOW_WIDTH_DEFAULT,
|
||||
DAWN_GLFW_WINDOW_HEIGHT_DEFAULT,
|
||||
"Dawn", NULL, NULL
|
||||
);
|
||||
if(this->data->window == nullptr) {
|
||||
glfwTerminate();
|
||||
return DAWN_GLFW_INIT_RESULT_WINDOW_CREATE_FAILED;
|
||||
}
|
||||
|
||||
// Load GLAD
|
||||
glfwMakeContextCurrent(this->data->window);
|
||||
// glfwSwapInterval(0); // "Vsync" disabled if uncommented
|
||||
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||
|
||||
return DAWN_HOST_INIT_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DawnHost::start(std::weak_ptr<DawnGame> game) {
|
||||
double_t time, newTime;
|
||||
float_t fDelta;
|
||||
int32_t updateResult;
|
||||
|
||||
// Main Render Loop
|
||||
time = 0.0f;
|
||||
while(true) {
|
||||
// Determine the delta.
|
||||
newTime = glfwGetTime();
|
||||
fDelta = (float_t)(newTime - time);
|
||||
time = newTime;
|
||||
|
||||
// Perform update
|
||||
updateResult = this->update(game, fDelta);
|
||||
|
||||
// Did the update complete successfully?
|
||||
if(updateResult == DAWN_HOST_UPDATE_RESULT_EXIT) {
|
||||
break;
|
||||
} else if(updateResult != DAWN_HOST_UPDATE_RESULT_SUCCESS) {
|
||||
return DAWN_GLFW_START_RESULT_UPDATE_FAILED;
|
||||
}
|
||||
|
||||
// Tick the engine.
|
||||
glfwSwapBuffers(this->data->window);
|
||||
|
||||
// Update events
|
||||
glfwPollEvents();
|
||||
|
||||
// Was the window requested to close?
|
||||
if(glfwWindowShouldClose(this->data->window)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return DAWN_HOST_START_RESULT_EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DawnHost::update(std::weak_ptr<DawnGame> game, float_t delta) {
|
||||
if(auto g = game.lock()) {
|
||||
auto ret = g->update(delta);
|
||||
switch(ret) {
|
||||
case DAWN_GAME_UPDATE_RESULT_SUCCESS:
|
||||
return DAWN_HOST_UPDATE_RESULT_SUCCESS;
|
||||
|
||||
case DAWN_GAME_UPDATE_RESULT_EXIT:
|
||||
return DAWN_HOST_UPDATE_RESULT_EXIT;
|
||||
|
||||
default:
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DawnHost::unload(std::weak_ptr<DawnGame> game) {
|
||||
glfwDestroyWindow(this->data->window);
|
||||
this->data->window = nullptr;
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
DawnHost::~DawnHost() {
|
||||
|
||||
}
|
25
src/dawnglfw/host/DawnGLFWHost.hpp
Normal file
25
src/dawnglfw/host/DawnGLFWHost.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "host/DawnHost.hpp"
|
||||
|
||||
#define DAWN_GLFW_WINDOW_WIDTH_DEFAULT 1280
|
||||
#define DAWN_GLFW_WINDOW_HEIGHT_DEFAULT 720
|
||||
|
||||
#define DAWN_GLFW_INIT_RESULT_INIT_FAILED -1
|
||||
#define DAWN_GLFW_INIT_RESULT_WINDOW_CREATE_FAILED -2
|
||||
|
||||
#define DAWN_GLFW_START_RESULT_UPDATE_FAILED -1
|
||||
|
||||
namespace Dawn {
|
||||
class DawnHostData {
|
||||
public:
|
||||
GLFWwindow *window;
|
||||
};
|
||||
}
|
26
src/dawnopengl/CMakeLists.txt
Normal file
26
src/dawnopengl/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Libraries
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${OPENGL_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${OPENGL_LIBRARIES}
|
||||
)
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(display)
|
10
src/dawnopengl/display/CMakeLists.txt
Normal file
10
src/dawnopengl/display/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
|
||||
RenderManager.cpp
|
||||
)
|
34
src/dawnopengl/display/RenderManager.cpp
Normal file
34
src/dawnopengl/display/RenderManager.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "dawnopengl.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "display/RenderManager.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
RenderManager::RenderManager(std::weak_ptr<DawnGame> game) {
|
||||
this->game = game;
|
||||
}
|
||||
|
||||
void RenderManager::init() {
|
||||
glClearColor(
|
||||
0.39215686274f,
|
||||
0.58431372549f,
|
||||
0.9294117647f,
|
||||
1.0f
|
||||
);
|
||||
|
||||
glViewport(0, 0, 500, 500);
|
||||
}
|
||||
|
||||
void RenderManager::update() {
|
||||
printf("Rendering\n");
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
RenderManager::~RenderManager() {
|
||||
|
||||
}
|
13
src/dawnpokergame/CMakeLists.txt
Normal file
13
src/dawnpokergame/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
# 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 "PokerGame" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
|
||||
# Build Project
|
||||
add_executable(${DAWN_TARGET_NAME})
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(game)
|
10
src/dawnpokergame/game/CMakeLists.txt
Normal file
10
src/dawnpokergame/game/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
|
||||
DawnPokerGame.cpp
|
||||
)
|
32
src/dawnpokergame/game/DawnPokerGame.cpp
Normal file
32
src/dawnpokergame/game/DawnPokerGame.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "DawnPokerGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
DawnGame::DawnGame(std::weak_ptr<DawnHost> host) :
|
||||
renderManager(weak_from_this())
|
||||
{
|
||||
this->host = host;
|
||||
}
|
||||
|
||||
int32_t DawnGame::init() {
|
||||
this->renderManager.init();
|
||||
|
||||
this->scene = std::make_unique<Scene>(weak_from_this());
|
||||
|
||||
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DawnGame::update(float_t delta) {
|
||||
this->renderManager.update();
|
||||
|
||||
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
DawnGame::~DawnGame() {
|
||||
|
||||
}
|
7
src/dawnpokergame/game/DawnPokerGame.hpp
Normal file
7
src/dawnpokergame/game/DawnPokerGame.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "game/DawnGame.hpp"
|
13
src/dawnwin32/CMakeLists.txt
Normal file
13
src/dawnwin32/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(host)
|
10
src/dawnwin32/host/CMakeLists.txt
Normal file
10
src/dawnwin32/host/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
|
||||
DawnHostWin32.cpp
|
||||
)
|
42
src/dawnwin32/host/DawnHostWin32.cpp
Normal file
42
src/dawnwin32/host/DawnHostWin32.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "DawnHostWin32.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
int32_t main(int32_t argc, char **args) {
|
||||
int32_t result;
|
||||
|
||||
// Create the host
|
||||
auto host = std::make_shared<DawnHost>();
|
||||
auto game = std::make_shared<DawnGame>(host);
|
||||
|
||||
// Initialize the host and error check
|
||||
result = host->init(std::weak_ptr<DawnGame>(game));
|
||||
switch(result) {
|
||||
case DAWN_HOST_INIT_RESULT_SUCCESS:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
|
||||
// Request the main loop to start running.
|
||||
result = host->start(std::weak_ptr<DawnGame>(game));
|
||||
switch(result) {
|
||||
case DAWN_HOST_START_RESULT_SUCCESS:
|
||||
break;
|
||||
case DAWN_HOST_START_RESULT_EXIT_SUCCESS:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
|
||||
// Main loop finished without errors, cleanup
|
||||
host->unload(std::weak_ptr<DawnGame>(game));
|
||||
|
||||
// Success
|
||||
return 0;
|
||||
}
|
18
src/dawnwin32/host/DawnHostWin32.hpp
Normal file
18
src/dawnwin32/host/DawnHostWin32.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 "dawnlibs.hpp"
|
||||
#include "host/DawnHost.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
/**
|
||||
* Main entry function received by parent Win32 Operating System.
|
||||
*
|
||||
* @param argc Count of arguments passed to the program.
|
||||
* @param args Array of strings provided to the program.
|
||||
* @return 0 for success, else for any issue/error.
|
||||
*/
|
||||
int32_t main(int32_t argc, char **args);
|
Reference in New Issue
Block a user