Extract some configuration into EngineConfig
parent
0db190f453
commit
7712735f0e
|
@ -21,7 +21,7 @@ static void onGlfwError(int error, const char* description);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void init() {
|
void init(EngineConfig config) {
|
||||||
if (window) {
|
if (window) {
|
||||||
logError("init called more than once");
|
logError("init called more than once");
|
||||||
return;
|
return;
|
||||||
|
@ -41,7 +41,12 @@ void init() {
|
||||||
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||||
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
||||||
|
|
||||||
window = glfwCreateWindow(1280, 720, "shadowclad", NULL, NULL);
|
window = glfwCreateWindow(config.windowWidth,
|
||||||
|
config.windowHeight,
|
||||||
|
config.windowTitle.cstr,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
if (!window) {
|
if (!window) {
|
||||||
logError("Window or context creation failed");
|
logError("Window or context creation failed");
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -60,8 +65,8 @@ void init() {
|
||||||
exit(EXIT_LIB_FAIL);
|
exit(EXIT_LIB_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
logInfo("Setting swap interval to 1");
|
logInfo("Setting swap interval to %d", config.swapInterval);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(config.swapInterval);
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
glfwGetFramebufferSize(window, &width, &height);
|
glfwGetFramebufferSize(window, &width, &height);
|
||||||
|
@ -99,6 +104,13 @@ void terminate() {
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EngineConfig defaultConfig() {
|
||||||
|
return (EngineConfig) { .windowWidth = 800,
|
||||||
|
.windowHeight = 600,
|
||||||
|
.windowTitle = newString(NULL),
|
||||||
|
.swapInterval = 1 };
|
||||||
|
}
|
||||||
|
|
||||||
static void onGlfwError(int error, const char* description) {
|
static void onGlfwError(int error, const char* description) {
|
||||||
logError("GLFW error: %s", description);
|
logError("GLFW error: %s", description);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,21 @@
|
||||||
#ifndef ENGINE_ENGINE_H_
|
#ifndef ENGINE_ENGINE_H_
|
||||||
#define ENGINE_ENGINE_H_
|
#define ENGINE_ENGINE_H_
|
||||||
|
|
||||||
void init();
|
#include "string.h"
|
||||||
|
|
||||||
|
typedef struct EngineConfig EngineConfig;
|
||||||
|
|
||||||
|
struct EngineConfig {
|
||||||
|
int windowWidth;
|
||||||
|
int windowHeight;
|
||||||
|
String windowTitle;
|
||||||
|
int swapInterval;
|
||||||
|
};
|
||||||
|
|
||||||
|
void init(EngineConfig);
|
||||||
void run(void (*updateFn) (float));
|
void run(void (*updateFn) (float));
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
|
EngineConfig defaultConfig();
|
||||||
|
|
||||||
#endif // ENGINE_ENGINE_H_
|
#endif // ENGINE_ENGINE_H_
|
||||||
|
|
|
@ -2,6 +2,22 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
String newString(const char* s) {
|
||||||
|
size_t len = 0u;
|
||||||
|
char* cstr;
|
||||||
|
if (s) {
|
||||||
|
len = strlen(s);
|
||||||
|
cstr = memcpy(malloc((len + 1) * sizeof(char)),
|
||||||
|
s,
|
||||||
|
len * sizeof(char));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cstr = malloc(1 * sizeof(char));
|
||||||
|
}
|
||||||
|
cstr[len] = '\0';
|
||||||
|
return (String) { .length = len, .cstr = cstr };
|
||||||
|
}
|
||||||
|
|
||||||
String stringFromAiString(const struct aiString aistr) {
|
String stringFromAiString(const struct aiString aistr) {
|
||||||
char* cstr = memcpy(malloc((aistr.length + 1) * sizeof(char)),
|
char* cstr = memcpy(malloc((aistr.length + 1) * sizeof(char)),
|
||||||
aistr.data,
|
aistr.data,
|
||||||
|
|
|
@ -10,6 +10,7 @@ struct String {
|
||||||
char* cstr;
|
char* cstr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
String newString(const char* s);
|
||||||
String stringFromAiString(const struct aiString aistr);
|
String stringFromAiString(const struct aiString aistr);
|
||||||
void dropString(String str);
|
void dropString(String str);
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,13 @@
|
||||||
#include "game/game.h"
|
#include "game/game.h"
|
||||||
|
|
||||||
int main(/*int argc, char** argv*/) {
|
int main(/*int argc, char** argv*/) {
|
||||||
|
EngineConfig cfg = { .windowWidth = 1280,
|
||||||
|
.windowHeight = 720,
|
||||||
|
.windowTitle = newString("shadowclad"),
|
||||||
|
.swapInterval = 1 };
|
||||||
|
|
||||||
// Engine startup
|
// Engine startup
|
||||||
init();
|
init(cfg);
|
||||||
|
|
||||||
initGame();
|
initGame();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue