Dawn/src/engine/engine.c
2021-04-16 06:51:00 +10:00

82 lines
1.7 KiB
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "engine.h"
camera_t *camera;
shader_t *shader;
world_t *world;
texture_t *texture;
spritebatch_t *batch;
tileset_t *tileset;
primitive_t *primitive;
engine_t * engineInit(platform_t *platform, char *name, uint32_t inputCount) {
// Create the engine instance.
engine_t *engine = malloc(sizeof(engine_t));
if(engine == NULL) return NULL;
engine->name = name;
engine->platform = platform;
// Setup the renderer.
engine->render = renderInit(name);
if(engine->render == NULL) {
free(engine);
return NULL;
}
// Setup the input manager.
engine->input = inputInit(inputCount, platform->inputSourceCount);
if(engine->input == NULL) {
free(engine->render);
free(engine);
return NULL;
}
shader = assetShaderLoad("shaders/test.vert", "shaders/test.frag");
camera = cameraCreate();
cameraLookAt(camera,
20, 20, 20,
0, 0, 0
);
cameraLookAt(camera,
6, 6, 8,
0, 0, 0
);
cameraPerspective(camera, 45.0f, 1920.0f/1080.0f, 0.5f, 100.0f);
shaderUseCamera(shader, camera);
world = worldCreate();
texture = assetTextureLoad("tileset.png");
tileset = tilesetCreate(
texture->width/16, texture->height/16,
texture->width, texture->height,
0, 0,
0, 0
);
return engine;
}
uint32_t engineUpdate(engine_t *engine) {
shaderUse(shader);
renderFrame(engine->render);
worldRender(world, shader);
inputUpdate(engine->input);
return 0;
}
bool engineDispose(engine_t *engine) {
if(!renderDispose(engine->render)) return false;
free(engine);
return true;
}