renderer: Draw sprite centered on world pos

This commit is contained in:
doyle 2023-09-16 12:46:28 +10:00
parent 3ea0ae2e64
commit b82dfcb0e3
3 changed files with 34 additions and 16 deletions

View File

@ -47,11 +47,12 @@ void TELY_DLL_Init(void *user_data)
// NOTE: TELY Game ============================================================================= // NOTE: TELY Game =============================================================================
TELY_Assets *assets = &platform->assets; TELY_Assets *assets = &platform->assets;
TELY_Game *game = Dqn_Arena_New(&platform->arena, TELY_Game, Dqn_ZeroMem_Yes); Feely_Pona *pona = Dqn_Arena_New(&platform->arena, Feely_Pona, Dqn_ZeroMem_Yes);
TELY_Game *game = &pona->game;
game->chunk_pool.arena = &platform->arena; game->chunk_pool.arena = &platform->arena;
platform->user_data = game; platform->user_data = game;
{ {
TELY_AssetSpriteSheet *sheet = &game->hero_sprite_sheet; TELY_AssetSpriteSheet *sheet = &pona->hero_sprite_sheet;
Dqn_ThreadScratch scratch = Dqn_Thread_GetScratch(nullptr); Dqn_ThreadScratch scratch = Dqn_Thread_GetScratch(nullptr);
Dqn_String8 sheet_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/adventurer-v1.5-sheet.png", DQN_STRING_FMT(assets->textures_dir)); Dqn_String8 sheet_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/adventurer-v1.5-sheet.png", DQN_STRING_FMT(assets->textures_dir));
sheet->tex_handle = platform->func_load_texture(assets, DQN_STRING8("Hero"), sheet_path); sheet->tex_handle = platform->func_load_texture(assets, DQN_STRING8("Hero"), sheet_path);
@ -82,8 +83,8 @@ void TELY_DLL_Init(void *user_data)
{DQN_STRING8("Leap slice C"), /*index*/ 103, /*count*/ 6}, {DQN_STRING8("Leap slice C"), /*index*/ 103, /*count*/ 6},
}; };
game->hero_sprite_anims = Dqn_Slice_Alloc<TELY_AssetSpriteAnimation>(&platform->arena, DQN_ARRAY_UCOUNT(hero_anims), Dqn_ZeroMem_No); pona->hero_sprite_anims = Dqn_Slice_Alloc<TELY_AssetSpriteAnimation>(&platform->arena, DQN_ARRAY_UCOUNT(hero_anims), Dqn_ZeroMem_No);
DQN_MEMCPY(game->hero_sprite_anims.data, &hero_anims, sizeof(hero_anims[0]) * DQN_ARRAY_UCOUNT(hero_anims)); DQN_MEMCPY(pona->hero_sprite_anims.data, &hero_anims, sizeof(hero_anims[0]) * DQN_ARRAY_UCOUNT(hero_anims));
} }
game->entities = Dqn_VArray_Init<TELY_GameEntity>(&platform->arena, 1024 * 8); game->entities = Dqn_VArray_Init<TELY_GameEntity>(&platform->arena, 1024 * 8);
@ -169,9 +170,9 @@ void TELY_DLL_Init(void *user_data)
TELY_GameEntity *first_entity = TELY_Game_MakeEntityPointerF(game, "Hero"); TELY_GameEntity *first_entity = TELY_Game_MakeEntityPointerF(game, "Hero");
first_entity->local_pos = Dqn_V2_InitNx2(100.f, 100.f); first_entity->local_pos = Dqn_V2_InitNx2(100.f, 100.f);
first_entity->size_scale = Dqn_V2_InitNx1(4); first_entity->size_scale = Dqn_V2_InitNx1(4);
first_entity->sprite_sheet = &game->hero_sprite_sheet; first_entity->sprite_sheet = &pona->hero_sprite_sheet;
first_entity->sprite_anims = game->hero_sprite_anims; first_entity->sprite_anims = pona->hero_sprite_anims;
first_entity->local_hit_box_size = Dqn_V2_InitV2I(game->hero_sprite_sheet.sprite_size); first_entity->local_hit_box_size = Dqn_V2_InitV2I(pona->hero_sprite_sheet.sprite_size);
first_entity->flags |= TELY_EntityFlag_Clickable; first_entity->flags |= TELY_EntityFlag_Clickable;
first_entity->flags |= TELY_EntityFlag_MoveByKeyboard; first_entity->flags |= TELY_EntityFlag_MoveByKeyboard;
first_entity->flags |= TELY_EntityFlag_MoveByMouse; first_entity->flags |= TELY_EntityFlag_MoveByMouse;
@ -179,10 +180,10 @@ void TELY_DLL_Init(void *user_data)
uint16_t font_size = 18; uint16_t font_size = 18;
game->camera.scale = Dqn_V2_InitNx1(1); game->camera.scale = Dqn_V2_InitNx1(1);
game->inter_regular_font = platform->func_load_font(assets, DQN_STRING8("Inter (Regular)"), DQN_STRING8("Data/Inter-Regular.otf"), font_size); pona->inter_regular_font = platform->func_load_font(assets, DQN_STRING8("Inter (Regular)"), DQN_STRING8("Data/Inter-Regular.otf"), font_size);
game->inter_italic_font = platform->func_load_font(assets, DQN_STRING8("Inter (Italic)"), DQN_STRING8("Data/Inter-Italic.otf"), font_size); pona->inter_italic_font = platform->func_load_font(assets, DQN_STRING8("Inter (Italic)"), DQN_STRING8("Data/Inter-Italic.otf"), font_size);
game->jetbrains_mono_font = platform->func_load_font(assets, DQN_STRING8("JetBrains Mono NL (Regular)"), DQN_STRING8("Data/JetBrainsMonoNL-Regular.ttf"), font_size); pona->jetbrains_mono_font = platform->func_load_font(assets, DQN_STRING8("JetBrains Mono NL (Regular)"), DQN_STRING8("Data/JetBrainsMonoNL-Regular.ttf"), font_size);
game->test_audio = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa")); pona->test_audio = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa"));
// NOTE: TELY audio ============================================================================ // NOTE: TELY audio ============================================================================
@ -202,14 +203,15 @@ void TELY_DLL_FrameUpdate(void *user_data)
TELY_PlatformInput *input = &platform->input; TELY_PlatformInput *input = &platform->input;
TELY_Assets *assets = &platform->assets; TELY_Assets *assets = &platform->assets;
TELY_Renderer *renderer = &platform->renderer; TELY_Renderer *renderer = &platform->renderer;
TELY_Game *game = DQN_CAST(TELY_Game *) platform->user_data; Feely_Pona *pona = DQN_CAST(Feely_Pona *) platform->user_data;
TELY_Game *game = &pona->game;
TELY_UI *ui = &game->ui; TELY_UI *ui = &game->ui;
TELY_UI_FrameSetup(ui, assets, &platform->frame_arena); TELY_UI_FrameSetup(ui, assets, &platform->frame_arena);
TELY_UI_PushFont(ui, game->jetbrains_mono_font); TELY_UI_PushFont(ui, pona->jetbrains_mono_font);
TELY_Render_ClearColourV3(renderer, TELY_COLOUR_BLACK_MIDNIGHT_V4.rgb); TELY_Render_ClearColourV3(renderer, TELY_COLOUR_BLACK_MIDNIGHT_V4.rgb);
TELY_Render_PushFont(renderer, game->jetbrains_mono_font); TELY_Render_PushFont(renderer, pona->jetbrains_mono_font);
{ {
Dqn_ThreadScratch scratch = Dqn_Thread_GetScratch(nullptr); Dqn_ThreadScratch scratch = Dqn_Thread_GetScratch(nullptr);
Dqn_String8Builder builder = {}; Dqn_String8Builder builder = {};
@ -269,7 +271,7 @@ void TELY_DLL_FrameUpdate(void *user_data)
TELY_Audio *audio = &platform->audio; TELY_Audio *audio = &platform->audio;
if (audio->playback_size == 0) { if (audio->playback_size == 0) {
TELY_Audio_Play(audio, game->test_audio, 1.f /*volume*/); TELY_Audio_Play(audio, pona->test_audio, 1.f /*volume*/);
} }
// ============================================================================================= // =============================================================================================
@ -401,8 +403,8 @@ void TELY_DLL_FrameUpdate(void *user_data)
src_rect.size.h = DQN_CAST(Dqn_f32)sprite_sheet->sprite_size.h; src_rect.size.h = DQN_CAST(Dqn_f32)sprite_sheet->sprite_size.h;
Dqn_Rect dest_rect = {}; Dqn_Rect dest_rect = {};
dest_rect.pos = world_pos;
dest_rect.size = src_rect.size * entity->size_scale; dest_rect.size = src_rect.size * entity->size_scale;
dest_rect.pos = world_pos - (dest_rect.size * .5f);
if (entity->facing_left) if (entity->facing_left)
dest_rect.size.w *= -1.f; // NOTE: Flip the texture horizontally dest_rect.size.w *= -1.f; // NOTE: Flip the texture horizontally

15
feely_pona.h Normal file
View File

@ -0,0 +1,15 @@
#if defined(__clang__)
#pragma once
#include "feely_pona_unity.h"
#endif
struct Feely_Pona
{
TELY_Game game;
TELY_AssetFontHandle inter_regular_font;
TELY_AssetFontHandle inter_italic_font;
TELY_AssetFontHandle jetbrains_mono_font;
Dqn_Slice<TELY_AssetSpriteAnimation> hero_sprite_anims;
TELY_AssetSpriteSheet hero_sprite_sheet;
TELY_AssetAudioHandle test_audio;
};

View File

@ -51,6 +51,7 @@ DQN_MSVC_WARNING_DISABLE(4505) // warning C4505: unreferenced function with inte
#include "tely_ui.h" #include "tely_ui.h"
#include "tely_rfui.h" #include "tely_rfui.h"
#include "tely_game.h" #include "tely_game.h"
#include "feely_pona.h"
#include "tely_tools.cpp" #include "tely_tools.cpp"
#include "tely_game.cpp" #include "tely_game.cpp"