Reshuffled

This commit is contained in:
2021-04-19 21:30:34 +10:00
parent cc94f7c775
commit ff8b84b542
45 changed files with 218 additions and 140 deletions

63
src/game/game.c Normal file
View File

@ -0,0 +1,63 @@
/**
* Copyright (c) 2021 Dominic Msters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "game.h"
game_t * gameInit(platform_t *platform) {
// Create the game
game_t *game = malloc(sizeof(game_t));
if(game == NULL) return NULL;
// Load the game engine
game->engine = engineInit(platform, GAME_NAME, GAME_INPUT_COUNT);
if(game->engine == NULL) {
free(game);
return NULL;
}
// Load the Shader
game->shader = assetShaderLoad("shaders/test.vert", "shaders/test.frag");
// Prepare the camera.
game->camera = cameraCreate();
uint32_t d = 10;
cameraLookAt(game->camera, d, d, d, 0, 0, 0);
cameraPerspective(game->camera, 45.0f, 1920.0f/1080.0f, 0.5f, 500.0f);
// Load the world
game->world = worldLoad("testworld/");
// Pass to the main game to handle
return game;
}
uint32_t gameUpdate(game_t *game) {
uint32_t result;
// Update the engine.
result = engineUpdate(game->engine);
if(result != 0) return result;
// Prepare for rendering
shaderUse(game->shader);
shaderUseCamera(game->shader, game->camera);
worldRender(game->world, game->shader, game->camera);
return 0;
}
void gameDispose(game_t *game) {
worldDispose(game->world);
shaderDipose(game->shader);
cameraDispose(game->camera);
engineDispose(game->engine);
free(game);
}
engine_t * gameGetEngine(game_t *game) {
return game->engine;
}

59
src/game/game.h Normal file
View File

@ -0,0 +1,59 @@
/**
* Copyright (c) 2021 Dominic Msters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <stdbool.h>
#include "../engine.h"
#include "../platform.h"
#include "../display/camera.h"
#include "../display/shader.h"
#include "../world/world.h"
/////////////////////////////////// CONSTANTS //////////////////////////////////
/** Name of the Game */
#define GAME_NAME "Dawn Game"
/** Inputs */
#define GAME_INPUT_UP (inputbind_t)0x01
#define GAME_INPUT_DOWN (inputbind_t)0x02
#define GAME_INPUT_LEFT (inputbind_t)0x03
#define GAME_INPUT_RIGHT (inputbind_t)0x04
#define GAME_INPUT_COUNT 5
/////////////////////////////// TYPE DEFINITIONS ///////////////////////////////
/** Information about the current game context. */
typedef struct {
/** The engine context for the game */
engine_t *engine;
/** Rendering items */
camera_t *camera;
shader_t *shader;
world_t *world;
} game_t;
/**
* Initialize the game context.
*
* @return The game instance context.
*/
game_t * gameInit(platform_t *platform);
/**
* Start the main game loop.
*
* @param game The game to start the loop for.
* @return Refer to engineUpdate. 0 for loop continue, 1 for safe exit.
*/
uint32_t gameUpdate(game_t *game);
/**
* Cleanup a previously constructed.
* @param game The game to cleanup.
*/
void gameDispose(game_t *game);