Browse Source

Update asset management

Make distinctions between internal and external (downloaded from
third-party servers).
feature/data-structs
TheoryOfNekomata 2 years ago
parent
commit
033471bf25
22 changed files with 35 additions and 7 deletions
  1. +6
    -1
      CMakeLists.txt
  2. +0
    -0
      assets/internal/default/weapon-hitman/1-unload-var0.mp3
  3. +0
    -0
      assets/internal/default/weapon-hitman/1-unload-var1.mp3
  4. +0
    -0
      assets/internal/default/weapon-hitman/1-unload-var2.mp3
  5. +0
    -0
      assets/internal/default/weapon-hitman/sprite.svg
  6. +0
    -0
      assets/internal/default/weapon-impressor/sprite.svg
  7. +0
    -0
      assets/internal/default/weapon-militant/sprite.svg
  8. +0
    -0
      assets/internal/default/weapon-operator/sprite.svg
  9. +0
    -0
      assets/internal/default/weapon-ordinator/sprite.svg
  10. +0
    -0
      assets/internal/default/weapon-paragon/1-unload-var (1).mp3
  11. +0
    -0
      assets/internal/default/weapon-paragon/1-unload-var (2).mp3
  12. +0
    -0
      assets/internal/default/weapon-paragon/1-unload-var (3).mp3
  13. +0
    -0
      assets/internal/default/weapon-paragon/sprite.svg
  14. +0
    -0
      assets/internal/default/weapon-servant/sprite.svg
  15. +0
    -0
      assets/internal/default/weapon-specialist/sprite.svg
  16. +0
    -0
      assets/internal/default/weapon-tactician/sprite.svg
  17. +1
    -1
      src/packages/asset-inv/main.c
  18. +4
    -1
      src/packages/game/IZ_app.c
  19. +2
    -1
      src/packages/game/IZ_app.h
  20. +3
    -3
      src/packages/game/IZ_app_video.c
  21. +11
    -0
      src/packages/game/data/IZ_asset.c
  22. +8
    -0
      src/packages/game/data/IZ_asset.h

+ 6
- 1
CMakeLists.txt View File

@@ -95,7 +95,7 @@ add_executable(
src/packages/game/util/IZ_midi.h
src/packages/net/core/IZ_websocket.h
src/packages/net/core/IZ_websocket.c
src/packages/net/IZ_net_client.c src/packages/net/IZ_net_client.h src/packages/game/IZ_app_net.c src/packages/game/IZ_app_net.h src/packages/game/IZ_app_video.c src/packages/game/IZ_app_video.h src/packages/game/IZ_subsystem.h src/packages/game/IZ_app_input.c src/packages/game/IZ_app_input.h src/packages/game/IZ_app_config.c src/packages/game/IZ_app_config.h)
src/packages/net/IZ_net_client.c src/packages/net/IZ_net_client.h src/packages/game/IZ_app_net.c src/packages/game/IZ_app_net.h src/packages/game/IZ_app_video.c src/packages/game/IZ_app_video.h src/packages/game/IZ_subsystem.h src/packages/game/IZ_app_input.c src/packages/game/IZ_app_input.h src/packages/game/IZ_app_config.c src/packages/game/IZ_app_config.h src/packages/game/data/IZ_asset.c src/packages/game/data/IZ_asset.h)

target_link_libraries(
game
@@ -299,3 +299,8 @@ add_custom_command(TARGET game POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory # which executes "cmake - E copy_if_different..."
"${PROJECT_SOURCE_DIR}/assets" # <--this is in-file
$<TARGET_FILE_DIR:game>/assets) # <--this is out-file path

add_custom_command(TARGET asset-inv POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory # which executes "cmake - E copy_if_different..."
"${PROJECT_SOURCE_DIR}/assets" # <--this is in-file
$<TARGET_FILE_DIR:game>/assets) # <--this is out-file path

assets/default/weapon-hitman/1-unload-var0.mp3 → assets/internal/default/weapon-hitman/1-unload-var0.mp3 View File


assets/default/weapon-hitman/1-unload-var1.mp3 → assets/internal/default/weapon-hitman/1-unload-var1.mp3 View File


assets/default/weapon-hitman/1-unload-var2.mp3 → assets/internal/default/weapon-hitman/1-unload-var2.mp3 View File


assets/default/weapon-hitman/sprite.svg → assets/internal/default/weapon-hitman/sprite.svg View File


assets/default/weapon-impressor/sprite.svg → assets/internal/default/weapon-impressor/sprite.svg View File


assets/default/weapon-militant/sprite.svg → assets/internal/default/weapon-militant/sprite.svg View File


assets/default/weapon-operator/sprite.svg → assets/internal/default/weapon-operator/sprite.svg View File


assets/default/weapon-ordinator/sprite.svg → assets/internal/default/weapon-ordinator/sprite.svg View File


assets/default/weapon-paragon/1-unload-var (1).mp3 → assets/internal/default/weapon-paragon/1-unload-var (1).mp3 View File


assets/default/weapon-paragon/1-unload-var (2).mp3 → assets/internal/default/weapon-paragon/1-unload-var (2).mp3 View File


assets/default/weapon-paragon/1-unload-var (3).mp3 → assets/internal/default/weapon-paragon/1-unload-var (3).mp3 View File


assets/default/weapon-paragon/sprite.svg → assets/internal/default/weapon-paragon/sprite.svg View File


assets/default/weapon-servant/sprite.svg → assets/internal/default/weapon-servant/sprite.svg View File


assets/default/weapon-specialist/sprite.svg → assets/internal/default/weapon-specialist/sprite.svg View File


assets/default/weapon-tactician/sprite.svg → assets/internal/default/weapon-tactician/sprite.svg View File


+ 1
- 1
src/packages/asset-inv/main.c View File

@@ -122,5 +122,5 @@ i32 IZ_ReadAllAssetPacks(const char* current_dir, const char* ini_filename) {
}

i32 main(void) {
return IZ_ReadAllAssetPacks("assets", "assets.ini");
return IZ_ReadAllAssetPacks("assets\\internal", "assets.ini");
}

+ 4
- 1
src/packages/game/IZ_app.c View File

@@ -118,12 +118,15 @@ IZ_AppResult IZ_AppRun(struct IZ_App* app, u8 argc, const char* argv[]) {
return IZ_APP_RESULT_INITIALIZATION_ERROR;
}

char asset_dir[255];
IZ_AssetResolveDir("weapon-operator", asset_dir);
u16 sprite_slot_index = IZ_VideoGetNextFreeSpriteSlot(&app->video_state);
IZ_VideoLoadSprite(&app->video_state, (IZ_VideoLoadSpriteParams) {
.dir = "assets/default/weapon-servant",
.dir = asset_dir,
.filename = "sprite.svg",
.priority = IZ_VIDEO_SPRITE_PRIORITY_MEDIUM,
}, &app->video_state.active_sprites[sprite_slot_index]);
app->video_state.active_sprites[sprite_slot_index].sprite.scale_factor = 0.25f;

while (true) {
app->ticks = SDL_GetTicks64();


+ 2
- 1
src/packages/game/IZ_app.h View File

@@ -3,8 +3,9 @@

#include <SDL.h>
#include <libwebsockets.h>
#include "IZ_app_config.h"
#include "data/IZ_asset.h"
#include "memory/IZ_pool.h"
#include "IZ_app_config.h"
#include "IZ_app_input.h"
#include "IZ_app_net.h"
#include "IZ_app_video.h"


+ 3
- 3
src/packages/game/IZ_app_video.c View File

@@ -123,14 +123,14 @@ void IZ_VideoUpdate(IZ_VideoState* video_state) {
f32 draw_width = loaded_sprite->original_width * loaded_sprite->scale_factor;
f32 draw_height = loaded_sprite->original_height * loaded_sprite->scale_factor;
SDL_RenderCopyExF(video_state->renderer, loaded_sprite->texture, NULL, &(SDL_FRect) {
.x = 160,
.y = 120,
.x = 100,
.y = 100,
.w = draw_width,
.h = draw_height,
}, loaded_sprite->rotate_degrees++, &(SDL_FPoint) {
.x = draw_width / 2,
.y = draw_height / 2,
}, SDL_FLIP_HORIZONTAL);
}, SDL_FLIP_NONE);

// our goal is to render the svg files and apply custom transforms to some SVG groups if ever.
// TODO perhaps we can parse the SVG for easier transforms?


+ 11
- 0
src/packages/game/data/IZ_asset.c View File

@@ -0,0 +1,11 @@
#include "IZ_asset.h"

void IZ_AssetResolveDir(const char* asset_name, char* out) {
// TODO:
// 1. Check all folders under assets/
// 2. Check if the asset name exists under assets/internal/<pack>
// 3. Return the directory when directory exists for assets/internal/<pack>/<asset_name>
// 4. Return the directory when directory exists for assets/external/<pack>/<asset_name>
// 5. Else return assets/internal/default/<asset_name>
sprintf(out, "%s/%s", "assets/internal/default", asset_name);
}

+ 8
- 0
src/packages/game/data/IZ_asset.h View File

@@ -0,0 +1,8 @@
#ifndef IZ_ASSET_H
#define IZ_ASSET_H

#include <stdio.h>

void IZ_AssetResolveDir(const char*, char*);

#endif

Loading…
Cancel
Save