diff --git a/CMakeLists.txt b/CMakeLists.txt index af4c4e6b..9bd00ee2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ set(SETTING_GAME_POKER 1) set(SETTING_GAME_DAWN 2) set(SETTING_GAME_SANDBOX 3) -set(SETTING_GAME SETTING_GAME_SANDBOX) +set(SETTING_GAME SETTING_GAME_POKER) set(SETTING_GAME_NAME "DawnGame") ################################## Targets ##################################### diff --git a/include/dawn/dawn.h b/include/dawn/dawn.h index ae2cafa2..fe0e8073 100644 --- a/include/dawn/dawn.h +++ b/include/dawn/dawn.h @@ -48,6 +48,8 @@ #include "game/poker/pokergameassets.h" #include "game/poker/pokerworld.h" +#include "game/sandbox/sandboxscene.h" + // Player Input #include "input/input.h" diff --git a/include/dawn/display/renderlist.h b/include/dawn/display/renderlist.h index 8988fc7f..59c23dd0 100644 --- a/include/dawn/display/renderlist.h +++ b/include/dawn/display/renderlist.h @@ -8,24 +8,28 @@ #pragma once #include "../libs.h" #include "../util/dynarray.h" -#include "../game/game.h" +#include "../engine/engine.h" #include "framebuffer.h" #include "shader.h" +#include "primitive.h" -typedef struct _renderpass_t renderpass_t; -typedef struct _renderlist_t renderlist_t; - -typedef void renderitem_t( - renderlist_t *list, renderpass_t *pass, game_t *game, int32_t i -); - -typedef struct _renderpass_t { - framebuffer_t framebuffer; +typedef struct { + framebuffer_t frame; shader_t *shader; } renderpass_t; -typedef struct _renderlist_t { - int32_t width; - int32_t height; +typedef struct { + framebuffer_t frame; + primitive_t quad; + dynarray_t passes; -} renderlist_t; \ No newline at end of file + void *user; +} renderlist_t; + +typedef void renderitemcallback_t( + renderlist_t *list, renderpass_t *pass, engine_t *engine, int32_t i +); + +typedef struct { + renderitemcallback_t *onRender; +} renderitem_t; \ No newline at end of file diff --git a/include/dawn/game/poker/ui/pokerplayerui.h b/include/dawn/game/poker/ui/pokerplayerui.h index 840e4eda..e68c90ac 100644 --- a/include/dawn/game/poker/ui/pokerplayerui.h +++ b/include/dawn/game/poker/ui/pokerplayerui.h @@ -12,6 +12,14 @@ #include "../../../display/framebuffer.h" #include "../../../display/camera.h" +#define POKER_PLAYER_UI_IMAGE_SIZE 64 +#define POKER_PLAYER_UI_IMAGE_RESOLUTION POKER_PLAYER_UI_IMAGE_SIZE * 2 +#define POKER_PLAYER_UI_IMAGE_DIST 0.8f +#define POKER_PLAYER_UI_IMAGE_Y 0.1f +#define POKER_PLAYER_UI_PADDING 8 + typedef struct { label_t label; + framebuffer_t frame; + primitive_t quad; } pokerplayerui_t; \ No newline at end of file diff --git a/include/dawn/game/sandbox/sandboxscene.h b/include/dawn/game/sandbox/sandboxscene.h index 391d8184..e4f80ac1 100644 --- a/include/dawn/game/sandbox/sandboxscene.h +++ b/include/dawn/game/sandbox/sandboxscene.h @@ -11,7 +11,14 @@ #include "../../display/shader.h" #include "../../display/font.h" #include "../../display/primitive.h" +#include "../../display/renderlist.h" typedef struct { camera_t camera; + renderlist_t list; + + shader_t shader; + texture_t texture; + + primitive_t cube; } sandboxscene_t; \ No newline at end of file diff --git a/platform/glfw/glwfwplatform.c b/platform/glfw/glwfwplatform.c index 62484514..69eee88f 100644 --- a/platform/glfw/glwfwplatform.c +++ b/platform/glfw/glwfwplatform.c @@ -127,10 +127,9 @@ void glfwOnCursor(GLFWwindow *window, double x, double y) { inputsource_t glfwGetInputSourceForKey(int32_t key) { - // return (inputsource_t)(( - // key <= GLFW_KEY_GRAVE_ACCENT ? key - GLFW_KEY_SPACE : - // key <= GLFW_KEY_MENU ? key - GLFW_KEY_ESCAPE + GLFW_KEY_GRAVE_ACCENT : - // key - // ) % INPUT_SOURCE_COUNT); - return 0; + return (inputsource_t)(( + key <= GLFW_KEY_GRAVE_ACCENT ? key - GLFW_KEY_SPACE : + key <= GLFW_KEY_MENU ? key - GLFW_KEY_ESCAPE + GLFW_KEY_GRAVE_ACCENT : + key + ) % INPUT_SOURCE_COUNT); } \ No newline at end of file diff --git a/src/display/render.c b/src/display/render.c index 0ab8f936..0293a0cb 100644 --- a/src/display/render.c +++ b/src/display/render.c @@ -19,7 +19,7 @@ void renderInit() { glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); - glClearColor(0,0,0, 1.0); + glClearColor(0,0,0, 0.0); } void renderFrameStart(render_t *render) { diff --git a/src/display/renderlist.c b/src/display/renderlist.c index 8d542fa3..a07b2478 100644 --- a/src/display/renderlist.c +++ b/src/display/renderlist.c @@ -8,36 +8,76 @@ #include "renderlist.h" void renderListInit(renderlist_t *list, int32_t passes, int32_t width, int32_t height) { - int32_t i; - renderpass_t *pass; - - list->width = width; - list->height = height; - + frameBufferInit(&list->frame, width, height); + quadInit(&list->quad, 0, 0,0,0,0, 1,1,1,1); dynArrayInit(&list->passes, sizeof(renderpass_t), passes); - - for(i = 0; i < passes; i++) { - pass = (renderpass_t *)dynArrayGet(&list->passes, i); - frameBufferInit(&pass->framebuffer, width, height); - } } -void renderListRenderPass(renderlist_t *list, game_t *game, int32_t pass, dynarray_t *items, int32_t itemCount) { +renderpass_t * renderListGetPass(renderlist_t *list, int32_t pass) { + return (renderpass_t *)dynArrayGet(&list->passes, pass); +} + +int32_t renderPassAdd(renderlist_t *list) { + int32_t i = dynArrayAdd(&list->passes); + renderpass_t *pass = renderListGetPass(list, i); + + frameBufferInit(&pass->frame, + list->frame.texture.width, list->frame.texture.height + ); + + return i; +} + +void renderListRenderPass( + renderlist_t *list, engine_t *engine, + camera_t *camera, int32_t pass, dynarray_t *items +) { int32_t i; renderpass_t *renderPass; renderitem_t *item; - renderPass = (renderpass_t *)dynArrayGet(&list->passes, pass); + renderPass = renderListGetPass(list, pass); // Bind the shader. - frameBufferUse(&renderPass->framebuffer, true); + frameBufferUse(&renderPass->frame, true); shaderUse(renderPass->shader); // "Uniforms" + shaderUseCamera(renderPass->shader, camera); // Render list - for(i = 0; i < itemCount; i++) { + for(i = 0; i < items->length; i++) { item = (renderitem_t *)dynArrayGet(items, i); - item(list, renderPass, game, i); + item->onRender(list, renderPass, engine, i); } + + frameBufferUnbind(&engine->render, false); +} + +void renderListRender(renderlist_t *list, engine_t *engine, shader_t *shader) { + camera_t camera; + int32_t i; + renderpass_t *pass; + + // Setup the camera + cameraLookAt(&camera, 0,0,1, 0,0,0); + cameraOrtho(&camera, 0,1, 0,1, 0.5f, 1.5f); + + // Bind the framebuffer + frameBufferUse(&list->frame, false); + + // Set the shader + shaderUse(shader); + shaderUsePosition(shader, 0,0,0, 0,0,0); + shaderUseCamera(shader, &camera); + + // Render each pass. + for(i = 0; i < list->passes.length; i++) { + pass = renderListGetPass(list, i); + shaderUseTexture(shader, &pass->frame.texture); + primitiveDraw(&list->quad, 0, -1); + } + + // Unbind the framebuffer. + frameBufferUnbind(&engine->render, false); } \ No newline at end of file diff --git a/src/display/renderlist.h b/src/display/renderlist.h index b8855b61..82d6213a 100644 --- a/src/display/renderlist.h +++ b/src/display/renderlist.h @@ -7,10 +7,20 @@ #pragma once #include +#include "../game/game.h" #include "framebuffer.h" #include "primitive.h" #include "shader.h" +#include "camera.h" #include "primitives/quad.h" #include "../util/dynarray.h" -void renderListInit(renderlist_t *renderList, int32_t passes); \ No newline at end of file +void renderListInit(renderlist_t *list, int32_t passes, int32_t width, int32_t height); +renderpass_t * renderListGetPass(renderlist_t *list, int32_t pass); +int32_t renderPassAdd(renderlist_t *list); +void renderListRenderPass( + renderlist_t *list, engine_t *engine, + camera_t *camera, int32_t pass, dynarray_t *items +); + +void renderListRender(renderlist_t *list, engine_t *engine, shader_t *shader); \ No newline at end of file diff --git a/src/engine/engine.c b/src/engine/engine.c index 98bc4f08..864fda25 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -20,7 +20,10 @@ void engineUpdateStart(engine_t *engine, game_t *game, float delta) { } bool engineUpdateEnd(engine_t *engine, game_t *game) { - if(inputIsPressed(&engine->input, INPUT_NULL)) return false; + if(inputIsPressed(&engine->input, INPUT_NULL)) { + printf("Game exit requested\n"); + return false; + } return true; } diff --git a/src/game/game.c b/src/game/game.c index 246e58a5..fc85ddce 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -41,7 +41,7 @@ bool gameUpdate(game_t *game, float platformDelta) { void gameDispose(game_t *game) { // Cleanup the game #if SETTING_GAME == SETTING_GAME_POKER - pokerGameDispose(game); + pokerGameDispose(&game->pokerGame); #elif SETTING_GAME == SETTING_GAME_DAWN dawnGameDispose(game); #elif SETTING_GAME == SETTING_GAME_SANDBOX diff --git a/src/game/poker/pokergame.c b/src/game/poker/pokergame.c index ab52f1ef..c32c992a 100644 --- a/src/game/poker/pokergame.c +++ b/src/game/poker/pokergame.c @@ -31,10 +31,13 @@ bool pokerGameInit(pokergame_t *game) { } void pokerGameUpdate(pokergame_t *game, engine_t *engine) { - // Update the VN Engine. vnSceneUpdate(&game->scene, engine); + // Update the UI + pokerUiUpdate(game, engine); + + // Bind the shader. shaderUse(&game->assets.shader); diff --git a/src/game/poker/pokerworld.c b/src/game/poker/pokerworld.c index 07027481..5da65666 100644 --- a/src/game/poker/pokerworld.c +++ b/src/game/poker/pokerworld.c @@ -32,12 +32,7 @@ void pokerWorldInit(pokergame_t *game) { void pokerWorldLookAtPlayer(vnscene_t *scene, uint8_t playerIndex) { uint8_t seat; - seat = ( - playerIndex == POKER_DEALER_INDEX ? - POKER_GAME_SEAT_DEALER : - POKER_GAME_SEAT_FOR_PLAYER(playerIndex) - ); - + seat = pokerGameSeatFromIndex(playerIndex); scene->cameraLookX = POKER_WORLD_SEAT_POSITION_X(seat); scene->cameraLookZ = POKER_WORLD_SEAT_POSITION_Z(seat); } diff --git a/src/game/poker/ui/pokerplayerui.c b/src/game/poker/ui/pokerplayerui.c index 9801029d..974b97ea 100644 --- a/src/game/poker/ui/pokerplayerui.c +++ b/src/game/poker/ui/pokerplayerui.c @@ -9,6 +9,55 @@ void pokerPlayerUiInit(pokerplayerui_t *ui) { labelInit(&ui->label); + + frameBufferInit(&ui->frame, + POKER_PLAYER_UI_IMAGE_RESOLUTION, POKER_PLAYER_UI_IMAGE_RESOLUTION + ); + + quadInit(&ui->quad, 0, + 0, 0, 0, 1, + POKER_PLAYER_UI_IMAGE_SIZE, POKER_PLAYER_UI_IMAGE_SIZE, 1, 0 + ); +} + +void pokerPlayerUiUpdate( + pokerplayerui_t *ui, pokergame_t *game, shader_t *shader, int32_t playerIndex, + engine_t *engine +) { + + camera_t camera; + uint8_t seat; + float x, y, z; + + // Bind the frame buffer + frameBufferUse(&ui->frame, true); + + // Set up the camera perspective + cameraPerspective(&camera, 45, + (float)POKER_PLAYER_UI_IMAGE_SIZE / (float)POKER_PLAYER_UI_IMAGE_SIZE, + 0.03f, 10.0f + ); + + // Locate the XYZ position of the camera to look at the player + seat = pokerGameSeatFromIndex(playerIndex); + x = POKER_WORLD_SEAT_POSITION_X(seat); + y = POKER_PLAYER_UI_IMAGE_Y; + z = POKER_WORLD_SEAT_POSITION_Z(seat); + + // Actually look at the player, we need to get close. + cameraLookAt(&camera, + x * POKER_PLAYER_UI_IMAGE_DIST, y, z * POKER_PLAYER_UI_IMAGE_DIST, + x, y, z + ); + + // Render the VN character + shaderUse(shader); + shaderUseCamera(shader, &camera); + shaderUsePosition(shader, 0,0,0, 0,0,0); + vnCharacterRender(game->scene.characters + playerIndex, shader); + + // Unbind the frame buffer. + frameBufferUnbind(&engine->render, false); } void pokerPlayerUiRender( @@ -22,13 +71,20 @@ void pokerPlayerUiRender( scale = fontGetScale(FONT_SIZE_DEFAULT); player = game->poker.players + playerIndex; + // Render Face + shaderUseTexture(shader, &ui->frame.texture); + shaderUsePosition(shader, x - POKER_PLAYER_UI_IMAGE_SIZE,y,0, 0,0,0); + primitiveDraw(&ui->quad, 0, -1); + + // Move everything left a bit. + x -= POKER_PLAYER_UI_IMAGE_SIZE + POKER_PLAYER_UI_PADDING; + y += (POKER_PLAYER_UI_IMAGE_SIZE - (FONT_LINE_HEIGHT * scale * 2)) / 2.0f; + // Render chips sprintf(buffer, "$%i", player->chips); labelSetText(&ui->label, font, buffer); labelRender(&ui->label, shader, x - ui->label.info.width, y); - // Render Face - // Render state if(player->state & POKER_PLAYER_STATE_OUT) { sprintf(buffer, "Out"); @@ -48,5 +104,7 @@ void pokerPlayerUiRender( } void pokerPlayerUiDispose(pokerplayerui_t *ui) { + primitiveDispose(&ui->quad); + frameBufferDispose(&ui->frame); labelDispose(&ui->label); } \ No newline at end of file diff --git a/src/game/poker/ui/pokerplayerui.h b/src/game/poker/ui/pokerplayerui.h index 020f0255..bc91d4b7 100644 --- a/src/game/poker/ui/pokerplayerui.h +++ b/src/game/poker/ui/pokerplayerui.h @@ -10,11 +10,19 @@ #include "../../../ui/label.h" #include "../../../ui/image.h" #include "../../../display/framebuffer.h" +#include "../../../display/primitive.h" +#include "../../../display/primitives/quad.h" +#include "../../../display/primitives/cube.h" #include "../../../display/camera.h" - +#include "../../../vn/vncharacter.h" void pokerPlayerUiInit(pokerplayerui_t *ui); +void pokerPlayerUiUpdate( + pokerplayerui_t *ui, pokergame_t *game, shader_t *shader, int32_t playerIndex, + engine_t *engine +); + void pokerPlayerUiRender( pokerplayerui_t *ui, pokergame_t *game, shader_t *shader, font_t *font, int32_t playerIndex, float x, float y diff --git a/src/game/poker/ui/pokerui.c b/src/game/poker/ui/pokerui.c index 72ea5ce6..2435e1a6 100644 --- a/src/game/poker/ui/pokerui.c +++ b/src/game/poker/ui/pokerui.c @@ -15,6 +15,17 @@ void pokerUiInit(pokergame_t *pokerGame) { } } +void pokerUiUpdate(pokergame_t *pokerGame, engine_t *engine) { + uint8_t i; + pokerplayerui_t *ui; + + for(i = 0; i < POKER_PLAYER_COUNT; i++) { + ui = pokerGame->ui.player + i; + + pokerPlayerUiUpdate(ui, pokerGame, &pokerGame->assets.shader, i, engine); + } +} + void pokerUiRender(pokergame_t *pokerGame, engine_t *engine) { uint8_t i; pokerplayerui_t *ui; diff --git a/src/game/poker/ui/pokerui.h b/src/game/poker/ui/pokerui.h index 7ce53040..b54cbad9 100644 --- a/src/game/poker/ui/pokerui.h +++ b/src/game/poker/ui/pokerui.h @@ -17,6 +17,14 @@ */ void pokerUiInit(pokergame_t *pokerGame); +/** + * Update the Poker Game UI. + * + * @param pokerGame Game to update. + * @param engine Engine to use for updating. + */ +void pokerUiUpdate(pokergame_t *pokerGame, engine_t *engine); + /** * Render the Poker Game UI. * diff --git a/src/game/sandbox/sandboxscene.c b/src/game/sandbox/sandboxscene.c index 2afa9274..fe7a5071 100644 --- a/src/game/sandbox/sandboxscene.c +++ b/src/game/sandbox/sandboxscene.c @@ -7,13 +7,50 @@ #include "sandboxscene.h" +void renderTest(renderlist_t *list, renderpass_t *pass, engine_t *engine, int32_t i) { + sandboxscene_t *scene; + scene = (sandboxscene_t *)list->user; + + shaderUsePosition(pass->shader, 0, 0, 0, engine->time.current, engine->time.current, 0); + shaderUseTexture(pass->shader, &scene->texture); + primitiveDraw(&scene->cube, 0, -1); +} + bool sandboxSceneInit(sandboxscene_t *game) { - printf("Sandbox init\n"); + int32_t passIndex; + renderpass_t *pass; + + // Load assets + assetTextureLoad(&game->texture, "test_texture.png"); + assetShaderLoad(&game->shader, "shaders/textured.vert", "shaders/textured.frag"); + cubeInit(&game->cube, 1.0f, 1.0f, 1.0f); + + // Initialize list + renderListInit(&game->list, 1, 400, 400); + game->list.user = game; + + // Set up the pass + passIndex = renderPassAdd(&game->list); + pass = renderListGetPass(&game->list, passIndex); + pass->shader = &game->shader; + return true; } void sandboxSceneUpdate(sandboxscene_t *game, engine_t *engine) { + dynarray_t items; + renderitem_t *item; + dynArrayInit(&items, sizeof(renderitem_t), 1); + item = (renderitem_t *)dynArrayGet(&items, dynArrayAdd(&items)); + item->onRender= &renderTest; + + cameraLookAt(&game->camera, 3,3,3, 0,0,0); + cameraPerspective(&game->camera, 75, 16.0f/9.0f, 0.3f, 100.0f); + renderListRenderPass(&game->list, engine, &game->camera, 0, &items); + renderListRender(&game->list, engine, &game->shader); + + dynArrayDispose(&items); } void sandboxSceneDispose(sandboxscene_t *game) { diff --git a/src/game/sandbox/sandboxscene.h b/src/game/sandbox/sandboxscene.h index 066a27c8..29c3dde5 100644 --- a/src/game/sandbox/sandboxscene.h +++ b/src/game/sandbox/sandboxscene.h @@ -12,6 +12,9 @@ #include "../../display/font.h" #include "../../display/primitive.h" #include "../../display/primitives/quad.h" +#include "../../display/primitives/cube.h" +#include "../../display/renderlist.h" +#include "../../file/asset.h" /** * Initialize the sandbox scene test game. diff --git a/src/util/dynarray.c b/src/util/dynarray.c index 4f265c24..075888f5 100644 --- a/src/util/dynarray.c +++ b/src/util/dynarray.c @@ -29,6 +29,12 @@ int32_t dynArrayPush(dynarray_t *array, void *data) { return i; } +int32_t dynArrayAdd(dynarray_t *array) { + int32_t i = array->length; + array->length++; + return i; +} + void dynArrayPop(dynarray_t *array) { array->length -= 1; } diff --git a/src/util/dynarray.h b/src/util/dynarray.h index c633a041..755c908a 100644 --- a/src/util/dynarray.h +++ b/src/util/dynarray.h @@ -48,6 +48,14 @@ void dynArraySet(dynarray_t *array, int32_t i, void *data); */ int32_t dynArrayPush(dynarray_t *array, void *data); +/** + * Create a new element in the array for you to use. + * + * @param array Array to add to. + * @return The index that the item was added to. + */ +int32_t dynArrayAdd(dynarray_t *array); + /** * "Pops" (Removes) the last element from the array. * diff --git a/src/vn/vncharacter.c b/src/vn/vncharacter.c index f579f9af..9ae309c5 100644 --- a/src/vn/vncharacter.c +++ b/src/vn/vncharacter.c @@ -151,7 +151,6 @@ void vnCharacterRender(vncharacter_t *character, shader_t *shader) { character->pitch, character->yaw, character->roll, character->scaleX, character->scaleY, 1 ); - shaderUseTexture(shader, character->texture); primitiveDraw(&character->primitive, 0, -1); }