More Progress

This commit is contained in:
2022-10-18 15:23:50 -07:00
parent 0ec2809d88
commit 6f10535962
45 changed files with 7994 additions and 0 deletions

View 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)

View 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>

View 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
)

View 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() {
}

View 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;
};
}