diff --git a/assets/characters/penny/design/dealer.psd b/assets/characters/penny/design/dealer.psd index 45b353c7..12b4c63b 100644 Binary files a/assets/characters/penny/design/dealer.psd and b/assets/characters/penny/design/dealer.psd differ diff --git a/assets/world/pub/pub_skywal_upscaledl.png b/assets/world/pub/pub_skywal_upscaledl.png new file mode 100644 index 00000000..2a943c46 Binary files /dev/null and b/assets/world/pub/pub_skywal_upscaledl.png differ diff --git a/assets/world/pub/pub_skywall.png b/assets/world/pub/pub_skywall.png index 025a2e69..b76172d9 100644 Binary files a/assets/world/pub/pub_skywall.png and b/assets/world/pub/pub_skywall.png differ diff --git a/assets/world/pub/pub_skywall_original.png b/assets/world/pub/pub_skywall_original.png new file mode 100644 index 00000000..82cf817a Binary files /dev/null and b/assets/world/pub/pub_skywall_original.png differ diff --git a/include/dawn/display/animation/easing.h b/include/dawn/display/animation/easing.h index fb5e0808..05c32769 100644 --- a/include/dawn/display/animation/easing.h +++ b/include/dawn/display/animation/easing.h @@ -15,15 +15,6 @@ */ #define easeTimeToEase(start, current, duration) ((current-start)/duration) -/** - * Animation tool for converting 0-1 space into a 0-0.5 back to zero space. This - * is intended to make a "Forward then backwards" effect for animation. This - * method will not scale t. - * @param t Time in space to back and fourth on between 0 and 1. - * @returns Forward and backwards time. 0 to 0.5 are as such, 0.5 to 1 are from - * 0.5 to 0. - */ -#define easeTimeToForwardAndBackward(t) (t < 0.5 ? t : 1 - t) // Easing Functions, most were sourced from https://gist.github.com/gre/1650294 #define easeLinear(t) t diff --git a/include/dawn/util/math.h b/include/dawn/util/math.h index e4d3b431..1b7593ba 100644 --- a/include/dawn/util/math.h +++ b/include/dawn/util/math.h @@ -11,9 +11,18 @@ * Returns the modulous a result for b. Consdiders negative numbers correctly. * @param a Number to modulo against. (a % b) * @param b Number to modulo with. (a % b) + * @returns The modulo result. */ #define mathMod(a,b) (a%b+b)%b +/** + * Returns the modulous a result for b. Works for floating point numbers. + * @param a Number to modulo against. (a % b) + * @param b Number to modulo with. (a % b) + * @returns The modulo result. + */ +#define mathModFloat(a, b) (float)fmod(a, b) + /** * Returns the maximum of two numbers. * @param a Number A. diff --git a/include/dawn/vn/vncharacter.h b/include/dawn/vn/vncharacter.h index 4ed94481..bc59fe57 100644 --- a/include/dawn/vn/vncharacter.h +++ b/include/dawn/vn/vncharacter.h @@ -17,11 +17,97 @@ /** How many quads the VN Character has. Base, Eyes, Mouth and Eyebrows */ #define VN_CHARACTER_QUAD_COUNT 4 +/** The Quads */ #define VN_CHARACTER_QUAD_BASE 0 #define VN_CHARACTER_QUAD_EYEBROWS 1 #define VN_CHARACTER_QUAD_EYES 2 #define VN_CHARACTER_QUAD_MOUTH 3 +/** How many frames does each mouth set have */ +#define VN_CHARACTER_TALKING_FRAME_COUNT 3 + +#define VN_CHARACTER_EMOTION_BORED 0x00 +#define VN_CHARACTER_EMOTION_BORED_SMILING 0x01 +#define VN_CHARACTER_EMOTION_BORED_DISAGREE 0x02 +#define VN_CHARACTER_EMOTION_BORED_AGREE 0x03 +#define VN_CHARACTER_EMOTION_SHORT 0x04 +#define VN_CHARACTER_EMOTION_SMUG_SLIGHT 0x05 +#define VN_CHARACTER_EMOTION_BORED_ANNOYED 0x06 +#define VN_CHARACTER_EMOTION_BORED_PROUD 0x07 +#define VN_CHARACTER_EMOTION_BORED_THINKING 0x08 +#define VN_CHARACTER_EMOTION_HAPPY_THINKING 0x09 +#define VN_CHARACTER_EMOTION_SERIOUS_THINKING 0x0A +#define VN_CHARACTER_EMOTION_SMUG_THINKING_SLIGHT 0x0B +#define VN_CHARACTER_EMOTION_XXXX_THINKING 0x0C// "concerned thinking" +#define VN_CHARACTER_EMOTION_HAPPY_FAKE_THINKING 0x0D +#define VN_CHARACTER_EMOTION_XXXX_THINKING2 0x0E// "serious concerned thinking" +#define VN_CHARACTER_EMOTION_XXXX_THINKING3 0x0F // "Happy pleased thinking" +#define VN_CHARACTER_EMOTION_BORED_LISTENING 0x10 +#define VN_CHARACTER_EMOTION_HUMBLED 0x11 +#define VN_CHARACTER_EMOTION_CONCERNED_1 0x12 +#define VN_CHARACTER_EMOTION_PROUD 0x13 +#define VN_CHARACTER_EMOTION_DEADPAN 0x14 +#define VN_CHARACTER_EMOTION_SMIRK 0x15 +#define VN_CHARACTER_EMOTION_CONCERNED_2 0x16 +#define VN_CHARACTER_EMOTION_TEASING 0x17 +#define VN_CHARACTER_EMOTION_XXXX_THINKING4 0x18// "concerned thinking lightly" +#define VN_CHARACTER_EMOTION_XXXX_THINKING5 0x19// "daydreaming" +#define VN_CHARACTER_EMOTION_XXXX_THINKING6 0x1A// "concerned thinking heavy" +#define VN_CHARACTER_EMOTION_XXXX_THINKING7 0x1B// "pleasant daydreaming" +#define VN_CHARACTER_EMOTION_XXXX_THINKING8 0x1C// not really sure +#define VN_CHARACTER_EMOTION_ANIME_MOM 0x1D +#define VN_CHARACTER_EMOTION_XXXX_THINKING9 0x1E// not really sure +#define VN_CHARACTER_EMOTION_ANIME_MOM_SMUG 0x1F +#define VN_CHARACTER_EMOTION_CURIOUS 0x20 +#define VN_CHARACTER_EMOTION_HAPPY 0x21 +#define VN_CHARACTER_EMOTION_CONCERNED_WORRIED 0x22 +#define VN_CHARACTER_EMOTION_HAPPY_PROUD_SLIGHT 0x23 +#define VN_CHARACTER_EMOTION_NOT_BELIEVING 0x24//"Mhm, suuure" +#define VN_CHARACTER_EMOTION_HAPPY_TIRED 0x25 +#define VN_CHARACTER_EMOTION_CONCERNED_SLIGHT 0x26 +#define VN_CHARACTER_EMOTION_HAPPY_PROUD 0x27 +#define VN_CHARACTER_EMOTION_XXXX_THINKING10 0x28// sort of tsundere +#define VN_CHARACTER_EMOTION_XXXX_THINKING11 0x29// "thinking of something nice" +#define VN_CHARACTER_EMOTION_XXXX_THINKING12 0x2A// big sister vibes +#define VN_CHARACTER_EMOTION_XXXX_THINKING13 0x2B// "vibin" +#define VN_CHARACTER_EMOTION_XXXX_THINKING14 0x2C// not really sure +#define VN_CHARACTER_EMOTION_XXXX_THINKING15 0x2D// not really sure +#define VN_CHARACTER_EMOTION_XXXX_THINKING16 0x2E// not really sure +#define VN_CHARACTER_EMOTION_XXXX_THINKING17 0x2F// not really sure +#define VN_CHARACTER_EMOTION_CONCERNED 0x30 +#define VN_CHARACTER_EMOTION_RELIEVED 0x31 +#define VN_CHARACTER_EMOTION_CONCERNED_VERY 0x32 +#define VN_CHARACTER_EMOTION_RELIEVED_SMUG 0x33//"slightly smug" +#define VN_CHARACTER_EMOTION_CONCERNED_3 0x34// "slightly worried" +#define VN_CHARACTER_EMOTION_CONCERNED_4 0x35// "slightly smug" +#define VN_CHARACTER_DISAPPOINTED 0x36// "slightly worried" +#define VN_CHARACTER_EMOTION_CONCERNED_5 0x37// "slightly smugger" +#define VN_CHARACTER_EMOTION_CONCERNED_THINKING 0x38 +#define VN_CHARACTER_EMOTION_SMUG_1 0x39 +#define VN_CHARACTER_EMOTION_CONCERNED_THINKING_DEEP 0x3A +#define VN_CHARACTER_EMOTION_SMUG_2 0x3B +#define VN_CHARACTER_EMOTION_XXXX_THINKING18 0x3C// not really sure +#define VN_CHARACTER_EMOTION_XXXX_THINKING19 0x3D// not really sure +#define VN_CHARACTER_EMOTION_XXXX_THINKING20 0x3E// not really sure +#define VN_CHARACTER_EMOTION_XXXX_THINKING21 0x3F// not really sure +#define VN_CHARACTER_EMOTION_SERIOUS 0x40 +#define VN_CHARACTER_EMOTION_READY 0x41 +#define VN_CHARACTER_EMOTION_SERIOUS_ANGRY 0x42 +#define VN_CHARACTER_EMOTION_SMUG 0x43 +#define VN_CHARACTER_EMOTION_ANGRY 0x44 +#define VN_CHARACTER_EMOTION_ANGRY_PROUD 0x45 +#define VN_CHARACTER_EMOTION_ANGRY_VERY 0x46 +#define VN_CHARACTER_EMOTION_SMUG_VERY 0x47 +#define VN_CHARACTER_EMOTION_SERIOUS_THINKING_VERY 0x48 +#define VN_CHARACTER_EMOTION_SMUG_THINKING 0x49 +#define VN_CHARACTER_EMOTION_ANGRY_THINKING 0x4A +#define VN_CHARACTER_EMOTION_SMUG_THINKING_VERY 0x4B +#define VN_CHARACTER_EMOTION_XXXX_THINKING22 0x4C// not really sure +#define VN_CHARACTER_EMOTION_HAPPY_FAKE_THINKING_ANGRY 0x4D +#define VN_CHARACTER_EMOTION_XXXX_THINKING23 0x4E// not really sure +#define VN_CHARACTER_EMOTION_BOASTFUL 0x4F + + typedef struct { float x, y, z; float yaw, pitch, roll; @@ -30,6 +116,8 @@ typedef struct { bool talking; float blinkStart; + uint8_t emotion; + primitive_t primitive; texture_t *texture; diff --git a/src/display/animation/animation.c b/src/display/animation/animation.c new file mode 100644 index 00000000..72e5f586 --- /dev/null +++ b/src/display/animation/animation.c @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "animation.h" + +float animForwardAndBackward(float t) { + return (t < 0.5 ? t : 1 - t); +} + +float animForwardAndBackwardScaled(float t) { + return animForwardAndBackward(t) * 2.0f; +} + +float animTimeScaleFromFrameTime(int32_t frames, float time) { + return 1.0f / (float)frames / time; +} diff --git a/src/display/animation/animation.h b/src/display/animation/animation.h new file mode 100644 index 00000000..7ddcda4b --- /dev/null +++ b/src/display/animation/animation.h @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include + +/** + * Animation tool for converting 0-1 space into a 0-0.5 back to zero space. This + * is intended to make a "Forward then backwards" effect for animation. This + * method will not scale t. + * @param t Time in space to back and fourth on between 0 and 1. + * @returns Forward and backwards time. 0 to 0.5 are as such, 0.5 to 1 are from + * 0.5 to 0. + */ +float animForwardAndBackward(float t); + +/** + * Animation tool for converting 0-1 space into a 0-1-0 space. Scaled version of + * animForwardAndBackward(). + * @param t Time in space to back and fourth on between 0 and 1. + * @returns Forward and backwards time. + */ +float animForwardAndBackwardScaled(float t); + +/** + * Returns the time scale (speed to multiply time range by) for a given frame + * time and frame count. E.g. 3 frames at 0.5 time each would have a time scale + * of 1.5. + * + * @param frames Frames to get the scale of. + * @param time Time to get the scale of. + * @return The time scale. + */ +float animTimeScaleFromFrameTime(int32_t frames, float time); \ No newline at end of file diff --git a/src/display/primitives/skywall.c b/src/display/primitives/skywall.c index b7332248..40c8d024 100644 --- a/src/display/primitives/skywall.c +++ b/src/display/primitives/skywall.c @@ -13,7 +13,7 @@ void skywallInit(primitive_t *primitive) { vertice_t vertices[SKYWALL_VERTICE_COUNT]; indice_t indices[SKYWALL_INDICE_COUNT]; int32_t n, i, j; - float x, z, p, r; + float x, y, z, p, r; // For each slice. We iterate slices+1 to do the wrapping mentioned below. for(i = 0; i < SKYWALL_SLICE_COUNT+1; i++) { @@ -33,12 +33,13 @@ void skywallInit(primitive_t *primitive) { // Determine the X/Z for the given radian x = SKYWALL_SIZE * (float)cos(r); z = SKYWALL_SIZE * (float)sin(r); + y = SKYWALL_SIZE * 1.333f; // Get the start index for the ertices n = i * SKYWALL_VERTICES_PER_SLICE; - vertices[n].x = x, vertices[n].y = -SKYWALL_SIZE, vertices[n].z = z; + vertices[n].x = x, vertices[n].y = -y, vertices[n].z = z; vertices[n].u = p, vertices[n].v = 1; - vertices[n+1].x = x, vertices[n+1].y = SKYWALL_SIZE, vertices[n+1].z = z; + vertices[n+1].x = x, vertices[n+1].y = y, vertices[n+1].z = z; vertices[n+1].u = p, vertices[n+1].v = 0; if(i == SKYWALL_SLICE_COUNT) continue; diff --git a/src/display/primitives/skywall.h b/src/display/primitives/skywall.h index cf536f45..a3fae043 100644 --- a/src/display/primitives/skywall.h +++ b/src/display/primitives/skywall.h @@ -23,6 +23,6 @@ #define SKYWALL_INDICE_COUNT SKYWALL_INDICES_PER_SLICE*SKYWALL_SLICE_COUNT /** How big the skywall cylinder is */ -#define SKYWALL_SIZE 100 +#define SKYWALL_SIZE 10 void skywallInit(primitive_t *primitive); \ No newline at end of file diff --git a/src/game/poker/pokergame.c b/src/game/poker/pokergame.c index 38f9d2c9..8f05ea9b 100644 --- a/src/game/poker/pokergame.c +++ b/src/game/poker/pokergame.c @@ -26,7 +26,16 @@ bool pokerGameInit(game_t *game) { 1000, 1920, 367,256, 280,280 ); - pokerGame->scene.characterCount = 1; + + vnCharacterInit(pokerGame->scene.characters + 1, &pokerGame->assets.pennyTexture, + 1000, 1920, + 367,256, 280,280 + ); + (pokerGame->scene.characters + 0)->x -= 0.3f; + (pokerGame->scene.characters + 1)->x += 0.3f; + (pokerGame->scene.characters + 1)->talking = true; + + pokerGame->scene.characterCount = 2; // Initialize the UI. diff --git a/src/vn/vncharacter.c b/src/vn/vncharacter.c index 58c3f70e..9fa7cc38 100644 --- a/src/vn/vncharacter.c +++ b/src/vn/vncharacter.c @@ -14,9 +14,9 @@ void vnCharacterInit( int32_t faceX, int32_t faceY, int32_t faceWidth, int32_t faceHeight ) { - character->x = 0.5f; - character->y = -1.17f; - character->z = -0.35f; + character->x = 0; + character->y = -2.2f; + character->z = -0.3f; character->yaw = 0; character->pitch = 0; @@ -26,16 +26,9 @@ void vnCharacterInit( character->scaleY = 1; character->texture = texture; - character->talking = true; + character->talking = false; character->blinkStart = 0; - // Init the primitive. - 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; @@ -43,13 +36,21 @@ void vnCharacterInit( character->faceWidth = faceWidth; character->faceHeight = faceHeight; + character->emotion = VN_CHARACTER_EMOTION_HAPPY; + + // Init the primitive. + primitiveInit(&character->primitive, + QUAD_VERTICE_COUNT * VN_CHARACTER_QUAD_COUNT, + QUAD_INDICE_COUNT * VN_CHARACTER_QUAD_COUNT + ); + // Buffer the base quad, this never changes (currently) _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); + _vnCharacterFaceBuffer(character, 0, VN_CHARACTER_QUAD_EYEBROWS); + _vnCharacterFaceBuffer(character, 0, VN_CHARACTER_QUAD_EYES); + _vnCharacterFaceBuffer(character, 0, VN_CHARACTER_QUAD_MOUTH); } void _vnCharacterBuffer(vncharacter_t *character, @@ -77,63 +78,78 @@ void _vnCharacterBuffer(vncharacter_t *character, } void _vnCharacterFaceBuffer(vncharacter_t *character, - int32_t col, int32_t row, int32_t i + int32_t col, int32_t i ) { _vnCharacterBuffer(character, character->faceX, character->faceY, character->faceWidth, character->faceHeight, character->baseWidth + (character->faceWidth * col), - character->faceHeight * row, + character->faceHeight * (i -1), i ); } void vnCharacterUpdate(vncharacter_t *character, engine_t *engine) { - float n; + uint8_t eyes, mouth, eyebrows; + float t; - // 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 - ); - } + // Setup frames based on the emotion. + mouth = character->emotion % 0x04; + eyes = (character->emotion/0x04) % 0x04; + eyebrows = ((character->emotion/0x04)/0x04) % 0x05; - // Updating the talking frames + _vnCharacterFaceBuffer(character, eyebrows, VN_CHARACTER_QUAD_EYEBROWS); + _vnCharacterFaceBuffer(character, eyes, VN_CHARACTER_QUAD_EYES); + + mouth *= VN_CHARACTER_TALKING_FRAME_COUNT; 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 - ); + t = animForwardAndBackwardScaled(mathModFloat( + engine->time.current * animTimeScaleFromFrameTime(3, 0.2f), 1.0f + )); + mouth += (uint8_t)(t * VN_CHARACTER_TALKING_FRAME_COUNT); } + _vnCharacterFaceBuffer(character, mouth, VN_CHARACTER_QUAD_MOUTH); - // Update the scale frames for talking/breathing + + + + + // float n; + // // 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 + // ); + // } + // if(character->talking) { + // n = easeTimeToForwardAndBackward( + // mathModFloat(engine->time.current * 1.6, 1) + // ) * 6.0f; + // _vnCharacterFaceBuffer(character, + // (int32_t)n, 2, VN_CHARACTER_QUAD_MOUTH + // ); + // } else { + // _vnCharacterFaceBuffer(character, + // 0, 2, VN_CHARACTER_QUAD_MOUTH + // ); + // } + + // Update the scale frames for breathing / talk 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; + speed = 0.2f; + amount = 300.0f; + t = animForwardAndBackwardScaled( + mathModFloat(engine->time.current, 1 / speed) * speed + ); + t = easeInOutQuad(t) / amount - (1/(amount*2)); + character->scaleX = 1 + t; + character->scaleY = 1 - t; } void vnCharacterRender(vncharacter_t *character, shader_t *shader) { diff --git a/src/vn/vncharacter.h b/src/vn/vncharacter.h index 65e8ea97..e1de59cf 100644 --- a/src/vn/vncharacter.h +++ b/src/vn/vncharacter.h @@ -12,6 +12,7 @@ #include "../display/primitive.h" #include "../display/shader.h" #include "../display/primitives/quad.h" +#include "../display/animation/animation.h" /** * Initialize a VN Character. @@ -55,12 +56,9 @@ void _vnCharacterBuffer(vncharacter_t *character, * * @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 _vnCharacterFaceBuffer(vncharacter_t *character, int32_t col, int32_t i); void vnCharacterUpdate(vncharacter_t *character, engine_t *engine); void vnCharacterRender(vncharacter_t *character, shader_t *shader); diff --git a/src/vn/vnscene.c b/src/vn/vnscene.c index e9f10258..62eb1535 100644 --- a/src/vn/vnscene.c +++ b/src/vn/vnscene.c @@ -35,8 +35,8 @@ void vnSceneDispose(vnscene_t *scene) { void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader) { // Adjust 3D Space position cameraLookAt(&scene->camera, - 0.5, 0.5, 0.75, - 0.5, 0.5, -0.5 + 0.5, -0.5f, 0.5f, + 0.5, -0.5f, -0.5 ); // Set Camera Perspective