Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore the Asset Packs to ship all game assets in a more compact way #31

Open
iWas-Coder opened this issue May 21, 2024 · 0 comments
Open
Assignees
Labels
✨ feature New feature or request 🏆 good first issue Good for newcomers

Comments

@iWas-Coder
Copy link
Member

iWas-Coder commented May 21, 2024

https://www.youtube.com/watch?v=_k4TaZmSteY

Spec

https://github.com/sparky-game/skap-spec

This can be used for the release version of the game. So, every time that we interact with an asset, we need to do different things whether we are in debug mode or not:

  • Debug :: load assets from original files (.e.g. assets/icon.png, assets/models/7mm.glb, etc.).
  • Release :: load assets from Asset Pack (i.e. assets.skap), so they are pre-loaded in the way that the game uses them, no need to load them again (i.e. no need to call LoadModel("..."), just read the bytes from the Asset Pack and store them as a Model struct).

Header

[4 bytes] Signature -> "SKAP" (char signature[4])
[1 byte] Format version -> 1 (u8 fmt_ver)
[8 bytes] Build version -> 202405201829 (u64 build_ver)

static u64 concat_num(u64 x, u64 y) {
  u64 n = 10;
  while (y >= n) n *= 10;
  return n * x + y;
}
static u64 compute_build_ver(void) {
  time_t t = time(0);
  struct tm *t_spec = localtime(&t);
  u64 t_spec_arr[] = {
    t_spec->tm_mon + 1,
    t_spec->tm_mday,
    t_spec->tm_hour,
    t_spec->tm_min
  };
  u64 build_ver = t_spec->tm_year + 1900;
  for (size_t i = 0; i < 4; ++i) {
    if (t_spec_arr[i] < 10) build_ver *= 10;
    build_ver = concat_num(build_ver, t_spec_arr[i]);
  }
  return build_ver;
}
u64 build_ver = compute_build_ver();
printf("build_ver => %lld\n", build_ver);

Image

Index

Types of assets:

  • Images (LoadImage(...))
  • Textures (LoadTexture(...))
  • Sounds (LoadSound(...))
  • Music (LoadMusic(...))
  • Models (LoadModel(...))
  • Shaders (???)

Important

The LoadTexture(...) function cannot be utilised, since it uploads the data directly to the GPU. We need to use for all image files the LoadImage(...) function instead.

Blob

The rest of binary data contained in a *.skap file appart from the Header and the Index.

Components

skap tool (serialization)

Asset Pack bundler tool, it ends up creating the assets.skap file.

sk_assetpack module (deserialization)

Asset Pack loader code, it loads the Header and the Index right away, then it retrieves data from the binary blob when requested.

@iWas-Coder iWas-Coder self-assigned this May 21, 2024
@iWas-Coder iWas-Coder added ✨ feature New feature or request 🏆 good first issue Good for newcomers labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature New feature or request 🏆 good first issue Good for newcomers
Projects
Status: wip
Development

No branches or pull requests

1 participant