Character is rendering in-game

This commit is contained in:
2021-08-22 23:30:53 -07:00
parent fabb35b7cf
commit 87e7f599a6
20 changed files with 284 additions and 161 deletions

View File

@ -42,7 +42,7 @@
#include "game/poker/pokergame.h"
#include "game/poker/pokerdiscussion.h"
#include "game/poker/pokergameassets.h"
#include "game/poker/pokerrender.h"
#include "game/poker/pokerworld.h"
#include "game/poker/pokerui.h"
// Player Input
@ -63,6 +63,7 @@
#include "poker/turn.h"
#include "poker/winner.h"
// User Interface Objects
#include "ui/frame.h"
#include "ui/label.h"

View File

@ -8,7 +8,7 @@
#pragma once
#include "../../libs.h"
#include "pokergameassets.h"
#include "pokerrender.h"
#include "pokerworld.h"
#include "pokerui.h"
#include "../../poker/poker.h"
#include "../../vn/vnconversation.h"
@ -24,8 +24,8 @@ typedef struct {
/** Assets (Files) for the game. */
pokergameassets_t assets;
/** Rendering Engine for the game. */
pokerrender_t render;
/** Poker Game World. */
pokerworld_t world;
/** UI For the Game */
pokerui_t ui;

View File

@ -14,7 +14,9 @@ typedef struct {
font_t font;
shader_t shader;
language_t language;
texture_t testTexture;
texture_t testTexture;
texture_t roomTexture;
texture_t pennyTexture;
} pokergameassets_t;

View File

@ -11,4 +11,4 @@
typedef struct {
primitive_t skywall;
} pokerrender_t;
} pokerworld_t;

View File

@ -17,16 +17,23 @@
/** How many quads the VN Character has. Base, Eyes, Mouth and Eyebrows */
#define VN_CHARACTER_QUAD_COUNT 4
#define VN_CHARACTER_QUAD_BASE 0
#define VN_CHARACTER_QUAD_EYEBROWS 1
#define VN_CHARACTER_QUAD_EYES 2
#define VN_CHARACTER_QUAD_MOUTH 3
typedef struct {
float x, y, z;
float yaw, pitch, roll;
float scaleX, scaleY;
bool talking;
float blinkStart;
primitive_t primitive;
texture_t *texture;
int32_t baseWidth, baseHeight;
int32_t faceX, faceY;
int32_t faceWidth, faceHeight;
} vncharacter_t;

View File

@ -28,6 +28,8 @@ void skywallInit(primitive_t *primitive) {
r = p * MATH_PI * 2.0f;// Convert % to radians
}
r += mathDeg2Rad(90);
// Determine the X/Z for the given radian
x = SKYWALL_SIZE * (float)cos(r);
z = SKYWALL_SIZE * (float)sin(r);

View File

@ -12,6 +12,7 @@ void renderInit() {
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
// Setup the alpha blend function.
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

View File

@ -10,17 +10,29 @@
bool pokerGameInit(game_t *game) {
pokergame_t *pokerGame = &game->pokerGame;
// Load the Assets
// Load the Assets.
pokerGameAssetsInit(&pokerGame->assets);
// Initialize the Visual Novel Engine.
vnSceneInit(&pokerGame->scene,
&pokerGame->assets.font,
&pokerGame->assets.testTexture
);
// Initialize the world
pokerRenderInit(&pokerGame->render);
pokerWorldInit(pokerGame);
vnCharacterInit(pokerGame->scene.characters, &pokerGame->assets.pennyTexture,
1000, 1920,
367,256, 280,280
);
pokerGame->scene.characterCount = 1;
// Initialize the UI.
pokerUiInit(pokerGame);
// Prep the VN Conversation Engine.
vnSceneInit(&pokerGame->scene, &pokerGame->assets.font, &pokerGame->assets.testTexture);
// Add the first action, the game action, and then start the action queue.
pokerGameActionStartAdd(pokerGame);
queueNext(&pokerGame->scene.conversation.actionQueue);
@ -31,17 +43,17 @@ void pokerGameUpdate(game_t *game) {
pokergame_t *pokerGame;
pokerGame = &game->pokerGame;
// Update the scene
// Update the VN Engine.
vnSceneUpdate(&pokerGame->scene, &game->engine);
// Bind the shader.
shaderUse(&pokerGame->assets.shader);
// Render the visual novel scene
// Render the visual novel scene.
vnSceneRenderWorld(&pokerGame->scene,&game->engine,&pokerGame->assets.shader);
// Render the world
pokerRenderRender(&pokerGame->render, &game->engine, &pokerGame->assets);
pokerWorldRender(&pokerGame->world, &game->engine, &pokerGame->assets);
vnSceneRenderCharacters(&pokerGame->scene, &pokerGame->assets.shader);
// Render the UI
vnSceneRenderGui(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
@ -49,8 +61,18 @@ void pokerGameUpdate(game_t *game) {
}
void pokerGameDispose(game_t *game) {
pokerUiDispose(&game->pokerGame);
pokerRenderDispose(&game->pokerGame.render);
vnSceneDispose(&game->pokerGame.scene);
pokerGameAssetsDispose(&game->pokerGame.assets);
pokergame_t *pokerGame;
pokerGame = &game->pokerGame;
//Cleanup the UI
pokerUiDispose(pokerGame);
// Cleanup the world
pokerWorldDispose(pokerGame);
// Destroy the Visual Novel engine.
vnSceneDispose(&pokerGame->scene);
// Unload all assets
pokerGameAssetsDispose(&pokerGame->assets);
}

View File

@ -13,13 +13,9 @@
#include "../../vn/vnscene.h"
#include "actions/start.h"
#include "pokerui.h"
#include "pokerrender.h"
#include "pokerworld.h"
#include "actions/start.h"
#include "../../ui/frame.h"
#include "../../physics/aabb.h"
#include "../../input/input.h"
/**
* Initializes the game state for the poker game.
*

View File

@ -7,20 +7,35 @@
#include "pokergameassets.h"
bool pokerGameAssetsInit(pokergameassets_t *assets) {
// Load the game's shader
assetShaderLoad(&assets->shader,
"shaders/textured.vert", "shaders/textured.frag"
);
// Load the game's font
assetFontLoad(&assets->font, "fonts/opensans/OpenSans-Bold.ttf");
// Initialize the language buffer.
languageInit(&assets->language, "locale/language/en-US.csv");
// Load the world textures.
assetTextureLoad(&assets->testTexture, "test_texture.png");
assetTextureLoad(&assets->roomTexture, "textures/pub_skywall.png");
assetTextureLoad(&assets->roomTexture, "world/pub/pub_skywall.png");
// Load the character textures.
assetTextureLoad(&assets->pennyTexture, "characters/penny/sprites/sheet.png");
return true;
}
void pokerGameAssetsDispose(pokergameassets_t *assets) {
// Now we unload in what is essentially the reverse of the above.
textureDispose(&assets->roomTexture);
textureDispose(&assets->testTexture);
languageDispose(&assets->language);
shaderDispose(&assets->shader);
fontDispose(&assets->font);
shaderDispose(&assets->shader);
}

View File

@ -1,25 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "pokerrender.h"
void pokerRenderInit(pokerrender_t *render) {
skywallInit(&render->skywall);
}
void pokerRenderRender(
pokerrender_t *render, engine_t *engine, pokergameassets_t *assets
) {
// Render the wall
shaderUseTexture(&assets->shader, &assets->roomTexture);
shaderUsePosition(&assets->shader, 0, 0, 0, 0,engine->time.current/3,0);
primitiveDraw(&render->skywall, 0, -1);
}
void pokerRenderDispose(pokerrender_t *render) {
primitiveDispose(&render->skywall);
}

View File

@ -1,36 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../../display/shader.h"
#include "../../display/primitive.h"
#include "../../display/primitives/skywall.h"
#include "../../vn/vnscene.h"
/**
* Initialize the poker renderer.
*
* @param render Render to initialize.
*/
void pokerRenderInit(pokerrender_t *render);
/**
* Render the poker game.
* @param render Renderer to use.
* @param engine Engine for rendering.
* @param assets Poker game assets.
*/
void pokerRenderRender(
pokerrender_t *render, engine_t *engine, pokergameassets_t *assets
);
/**
* Cleanup the poker renderer.
* @param render Render to dispose.
*/
void pokerRenderDispose(pokerrender_t *render);

View File

@ -0,0 +1,26 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "pokerworld.h"
void pokerWorldInit(pokergame_t *game) {
// Initialize the skywal
skywallInit(&game->world.skywall);
}
void pokerWorldRender(
pokerworld_t *world, engine_t *engine, pokergameassets_t *assets
) {
// Render the wall
shaderUseTexture(&assets->shader, &assets->roomTexture);
shaderUsePosition(&assets->shader, 0, 0, 0, 0,0,0);
primitiveDraw(&world->skywall, 0, -1);
}
void pokerWorldDispose(pokergame_t *game) {
primitiveDispose(&game->world.skywall);
}

View File

@ -0,0 +1,37 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../../display/shader.h"
#include "../../display/primitive.h"
#include "../../display/primitives/skywall.h"
#include "../../vn/vnscene.h"
/**
* Initialize the poker renderer.
*
* @param game Game to initialize for.
*/
void pokerWorldInit(pokergame_t *game);
/**
* Render the poker world.
*
* @param world Poker Game World.
* @param engine Game engine.
* @param assets Assets to use.
*/
void pokerWorldRender(
pokerworld_t *world, engine_t *engine, pokergameassets_t *assets
);
/**
* Cleanup the poker world.
* @param game Game to clean up for.
*/
void pokerWorldDispose(pokergame_t *game);

View File

@ -8,6 +8,7 @@
#pragma once
#include <dawn/dawn.h>
#include "../../display/animation/queue.h"
#include "../dealer.h"
#include "../bet.h"
#include "../player.h"

View File

@ -34,7 +34,7 @@ void frameSetInnerSize(frame_t *frame, float width, float height) {
float bottomStart = FRAME_BORDER_SIZE + height;
float bottomEnd = bottomStart + FRAME_BORDER_SIZE;
float tw = 0.33333;
float tw = 1.0f / 3.0f;
float th = tw;
// Buffer the top left edge

View File

@ -7,14 +7,16 @@
#include "vncharacter.h"
void vnCharacterInit(
vncharacter_t *character, texture_t *texture,
int32_t baseWidth, int32_t baseHeight,
int32_t faceX, int32_t faceY,
int32_t faceWidth, int32_t faceHeight
) {
character->x = 0;
character->y = 0;
character->z = 0;
character->x = 0.5f;
character->y = -1.17f;
character->z = -0.35f;
character->yaw = 0;
character->pitch = 0;
@ -23,97 +25,115 @@ void vnCharacterInit(
character->scaleX = 1;
character->scaleY = 1;
character->talking = false;
character->texture = texture;
character->talking = true;
character->blinkStart = 0;
// Init the primitive.
character->texture = texture;
primitiveInit(&character->primitive,
QUAD_VERTICE_COUNT * VN_CHARACTER_QUAD_COUNT,
QUAD_INDICE_COUNT * VN_CHARACTER_QUAD_COUNT
);
character->baseWidth = baseWidth;
character->baseHeight = baseHeight;
character->faceX = faceX;
character->faceY = faceY;
character->faceWidth = faceWidth;
character->faceHeight = faceHeight;
// Buffer the base quad, this never changes (currently)
quadBuffer(&character->primitive, 0,
0,0,0,0,
((float)baseWidth / (float)baseHeight), baseHeight, 1, 1,
0, 0
_vnCharacterBuffer(character,
0, 0, baseWidth, baseHeight, 0, 0, 0
);
_vnCharacterFaceBuffer(character, 0, 0, VN_CHARACTER_QUAD_EYEBROWS);
_vnCharacterFaceBuffer(character, 0, 1, VN_CHARACTER_QUAD_EYES);
_vnCharacterFaceBuffer(character, 0, 2, VN_CHARACTER_QUAD_MOUTH);
}
// character->blinkStart = randFloatRange(0, VN_CHARACTER_BLINK_TIME_RANGE_MAX);
void _vnCharacterBuffer(vncharacter_t *character,
int32_t x, int32_t y, int32_t width, int32_t height, int32_t tx, int32_t ty,
int32_t i
) {
// Calc size for each pixel.
float ps = 1.0f / (float)character->baseHeight;// Prefer Height
float tpx = 1.0f / (float)character->texture->width;
float tpy = 1.0f / (float)character->texture->height;
// character->name = "";
// Center on the X axis
x -= (float)character->baseWidth / 2.0f;
// // Setup Textures
// character->textureEyes = textureEyes;
// character->textureBody = textureBody;
// character->textureMouth = textureMouth;
// character->textureFace = textureFace;
// Put on the feet
y -= character->baseHeight;
// // Tileset
// tilesetInit(&character->tilesetEyes, 1, 6,
// textureEyes->width, textureEyes->height,
// 0, 0, 0, 0
// );
// tilesetInit(&character->tilesetMouth, 1, 11,
// textureMouth->width, textureMouth->height,
// 0, 0, 0, 0
// );
quadBuffer(&character->primitive, 0.001f * (float)i,
(float)x * ps, 1 - (float)y * ps,
(float)tx * tpx, (float)ty * tpy,
(float)(x + width) * ps, 1 - (float)(y + height) * ps,
(float)(tx + width) * tpx, (float)(ty + height) * tpy,
i * QUAD_VERTICE_COUNT, i * QUAD_INDICE_COUNT
);
}
// vnCharacterSetEyes(character, 0);
// vnCharacterSetMouth(character, 9);
// div.x0 = 0, div.x1 = 1;
// div.y0 = 0, div.y1 = 1;
// _vnCharacterQuad(&character->primitiveBody, &div);
// _vnCharacterQuad(&character->primitiveFace, &div);
void _vnCharacterFaceBuffer(vncharacter_t *character,
int32_t col, int32_t row, int32_t i
) {
_vnCharacterBuffer(character,
character->faceX, character->faceY,
character->faceWidth, character->faceHeight,
character->baseWidth + (character->faceWidth * col),
character->faceHeight * row,
i
);
}
void vnCharacterUpdate(vncharacter_t *character, engine_t *engine) {
// float n;
float n;
// // Update the blinking frames
// n = (engine->time.current - character->blinkStart) * 1.5;
// if(n >= 1) {
// character->blinkStart = engine->time.current + randFloatRange(
// 1, VN_CHARACTER_BLINK_TIME_RANGE_MAX
// );
// } else if(n > 0) {
// n = easeInQuad(easeTimeToForwardAndBackward(n) * 2);
// vnCharacterSetEyes(character, n * character->tilesetEyes.count);
// }
// Update the blinking frames
n = (engine->time.current - character->blinkStart) * 3.0f;
if(n > 1.0f) {
character->blinkStart = engine->time.current + randFloatRange(
1, VN_CHARACTER_BLINK_TIME_RANGE_MAX
);
} else if(n > 0) {
n = easeInQuad(easeTimeToForwardAndBackward(n) * 4);
_vnCharacterFaceBuffer(character,
(int32_t)n, 1, VN_CHARACTER_QUAD_EYES
);
}
// // Updating the talking frames
// if(character->talking) {
// vnCharacterSetMouth(character,
// (int32_t)(engine->time.current*12) % character->tilesetMouth.count
// );
// } else {
// vnCharacterSetMouth(character, 9);
// }
// Updating the talking frames
if(character->talking) {
n = easeTimeToForwardAndBackward(fmod(engine->time.current * 1.6, 1)) * 6;
_vnCharacterFaceBuffer(character,
(int32_t)n, 2, VN_CHARACTER_QUAD_MOUTH
);
} else {
_vnCharacterFaceBuffer(character,
0, 2, VN_CHARACTER_QUAD_MOUTH
);
}
// // Update the scale frames
// float speed, amount;
// if(character->talking) {
// speed = 2.5;
// amount = 100;
// n = easeTimeToForwardAndBackward(fmod(engine->time.current, 1 / speed) * speed) * 2;
// n = easeInOutQuad(n) / amount - (1/(amount*2));
// character->scaleX = 1 + n;
// character->scaleY = 1 - n;
// } else {
// speed = 10;
// amount = 50;
// Update the scale frames for talking/breathing
float speed, amount;
if(character->talking) {
speed = 1.0f;
amount = 400.0f;
} else {
speed = 0.4f;
amount = 400.0f;
// n = easeTimeToForwardAndBackward(fmod(engine->time.current, speed) / speed)*2;
// n = easeInOutCubic(n) / amount - (1/(amount*2));
// character->scaleX = 1 + n;
// character->scaleY = 1 + n*2;
// }
}
n = easeTimeToForwardAndBackward(fmod(engine->time.current, 1 / speed) * speed) * 2.0f;
n = easeInOutQuad(n) / amount - (1/(amount*2));
character->scaleX = 1 + n;
character->scaleY = 1 - n;
}
void vnCharacterRender(vncharacter_t *character, shader_t *shader) {
@ -126,3 +146,7 @@ void vnCharacterRender(vncharacter_t *character, shader_t *shader) {
shaderUseTexture(shader, character->texture);
primitiveDraw(&character->primitive, 0, -1);
}
void vnCharacterDispose(vncharacter_t *character) {
primitiveDispose(&character->primitive);
}

View File

@ -13,10 +13,56 @@
#include "../display/shader.h"
#include "../display/primitives/quad.h"
/**
* Initialize a VN Character.
*
* @param character Character to initialize.
* @param texture The characters' texture.
* @param baseWidth The width of the base character within the texture.
* @param baseHeight The height of the base character within the texture.
* @param faceX The X position on the face that the faces are cropped.
* @param faceY The Y position on the face that the faces are cropped.
* @param faceWidth The width of the cropped face.
* @param faceHeight The height of the cropped face.
*/
void vnCharacterInit(
vncharacter_t *character, texture_t *texture,
int32_t baseWidth, int32_t baseHeight,
int32_t faceX, int32_t faceY,
int32_t faceWidth, int32_t faceHeight
);
/**
* Buffer part of a VN Character texture onto the primitive. All the below units
* are believed to be in pixels, the relatives will be recalculated on the fly.
*
* @param character Character to buffer to.
* @param x Local X position of the VN Character to buffer to.
* @param y Local Y positon of the VN character to buffer to.
* @param width Width of the subarea.
* @param height Height of the subarea.
* @param tx Texture X position.
* @param ty Texture Y position.
* @param i Quad index to buffer to.
*/
void _vnCharacterBuffer(vncharacter_t *character,
int32_t x, int32_t y, int32_t width, int32_t height, int32_t tx, int32_t ty,
int32_t i
);
/**
* Buffer the face of a VN Character to the primitive.
*
* @param character Character to buffer to.
* @param col Face Column.
* @param row Face Row.
* @param i Quad index to buffer to.
*/
void _vnCharacterFaceBuffer(vncharacter_t *character,
int32_t col, int32_t row, int32_t i
);
void vnCharacterUpdate(vncharacter_t *character, engine_t *engine);
void vnCharacterRender(vncharacter_t *character, shader_t *shader);
void vnCharacterDispose(vncharacter_t *character);

View File

@ -33,8 +33,6 @@ void vnSceneDispose(vnscene_t *scene) {
}
void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader) {
uint8_t i;
// Adjust 3D Space position
cameraLookAt(&scene->camera,
0.5, 0.5, 0.75,
@ -42,13 +40,17 @@ void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader) {
);
// Set Camera Perspective
cameraPerspective(&scene->camera, 45,
cameraPerspective(&scene->camera, 35,
engine->render.width/engine->render.height,
0.01f, 1000.0f
);
// Update Shader
shaderUseCamera(shader, &scene->camera);
}
void vnSceneRenderCharacters(vnscene_t *scene, shader_t *shader) {
uint8_t i;
// Render each character
for(i = 0; i < scene->characterCount; i++) {

View File

@ -21,4 +21,6 @@ void vnSceneDispose(vnscene_t *scene);
void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader);
void vnSceneRenderCharacters(vnscene_t *scene, shader_t *shader);
void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, shader_t *shader);