More Progress
This commit is contained in:
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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user