Have the submodules working correctly.

This commit is contained in:
2021-09-30 21:38:01 -07:00
parent 7ce46d3e44
commit 88a75e2ddd
15 changed files with 6950 additions and 48 deletions

View File

@ -3,4 +3,4 @@
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
add_subdirectory(glfw)
add_subdirectory(glfwclient)

View File

@ -5,6 +5,10 @@
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} src glfw glad_gl_core_33)
target_link_libraries(${PROJECT_NAME}
game
glfw
glad
)

View File

@ -3,12 +3,17 @@
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "glwfwplatform.h"
#include "glfwclient.h"
game_t *GAME_STATE;
GLFWwindow *window = NULL;
static game_t *GAME_STATE;
static GLFWwindow *window = NULL;
int32_t main() {
double time, newTime;
game_t *game;
input_t *input;
float fDelta;
// Attempt to init GLFW
if(!glfwInit()) return 1;
@ -23,23 +28,23 @@ int32_t main() {
glfwTerminate();
return 1;
}
// Load GLAD
glfwMakeContextCurrent(window);
glfwSwapInterval(0);
gladLoadGL((GLADloadfunc)glfwGetProcAddress);
// gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
// Setup window listeners
glfwSetWindowSizeCallback(window, &glfwOnResize);
glfwSetKeyCallback(window, &glfwOnKey);
glfwSetErrorCallback(&glfwOnError);
glfwSetCursorPosCallback(window, &glfwOnCursor);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
// Prepare the game
game_t *game = malloc(sizeof(game_t));
game = malloc(sizeof(game_t));
GAME_STATE = game;
input_t *input = &game->engine.input;
input = &game->engine.input;
printf("Game is %zu bytes.\n", sizeof(game_t));
@ -47,7 +52,7 @@ int32_t main() {
renderSetResolution(&game->engine.render,
WINDOW_WIDTH_DEFAULT, WINDOW_HEIGHT_DEFAULT
);
// Init the game
if(gameInit(game)) {
// Bind initial keys
@ -69,18 +74,15 @@ int32_t main() {
inputBind(input, INPUT_MOUSE_Y, GLFW_PLATFORM_INPUT_MOUSE_Y);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
// Update the window title.
glfwSetWindowTitle(window, game->engine.name);
double time = 0;
time = 0;
// Main Render Loop
while(!glfwWindowShouldClose(window)) {
glfwPollEvents();
// Determine the delta.
double newTime = glfwGetTime();
float fDelta = (float)(newTime - time);
newTime = glfwGetTime();
fDelta = (float)(newTime - time);
time = newTime;
// Tick the engine.
@ -89,9 +91,11 @@ int32_t main() {
sleep(0);//Fixes some weird high CPU bug, not actually necessary.
}
// Game has finished running, cleanup.
gameDispose(game);
}
free(game);
// Terminate the GLFW context.
@ -110,9 +114,9 @@ void glfwOnKey(GLFWwindow *window,
) {
input_t *input = &GAME_STATE->engine.input;
if(action == GLFW_PRESS) {
input->buffer[glfwGetInputSourceForKey(key)] = 1;
inputStateSet(input, glfwGetInputSourceForKey(key), 1.0f);
} else if(action == GLFW_RELEASE) {
input->buffer[glfwGetInputSourceForKey(key)] = 0;
inputStateSet(input, glfwGetInputSourceForKey(key), 0.0f);
}
}
@ -122,11 +126,10 @@ void glfwOnError(int error, const char* description) {
void glfwOnCursor(GLFWwindow *window, double x, double y) {
input_t *input = &GAME_STATE->engine.input;
input->buffer[GLFW_PLATFORM_INPUT_MOUSE_X] = (float)x;
input->buffer[GLFW_PLATFORM_INPUT_MOUSE_Y] = (float)y;
inputStateSet(input, GLFW_PLATFORM_INPUT_MOUSE_X, (float)x);
inputStateSet(input, GLFW_PLATFORM_INPUT_MOUSE_Y, (float)y);
}
inputsource_t glfwGetInputSourceForKey(int32_t key) {
return (inputsource_t)((
key <= GLFW_KEY_GRAVE_ACCENT ? key - GLFW_KEY_SPACE :

View File

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT
#pragma once
#include <glad/gl.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <libs.h>
#include <display/render.h>