-
Notifications
You must be signed in to change notification settings - Fork 69
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
Rework asset embedding #197
Conversation
Create the directory for the output. Also, replace any ".."s in the filename to avoid putting files outside the current build dir.
Just calls blit_asset in a loop currently
Currently just a data pointer/length
Just inlines all the data in the cpp
Handles sprites for now
Fixes Clang errors
They need a different base dir
It's currently a bit inconsistent with subdirs. |
You're a magician! Tested in VSCode using CMake tools both via WSL/MinGW and regular Windows/MSVC. Builds and runs flawlessly in each case- granted I had some Python dependencies to install (I neglect my native Windows in favour of WSL) but that was as simple as using the terminal in VSCode to In both cases the diff --git a/CMakeLists.txt b/CMakeLists.txt
index ee99663..345dd99 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,5 +2,6 @@ cmake_minimum_required(VERSION 3.1)
project (rocks-and-diamonds)
include (../32blit-beta/32blit.cmake)
blit_executable (rocks-and-diamonds rocks-and-diamonds.cpp)
-blit_asset (rocks-and-diamonds level)
-blit_asset (rocks-and-diamonds sprites)
\ No newline at end of file
+blit_assets (rocks-and-diamonds
+ RAW level
+ SPRITE_PACKED sprites.png)
\ No newline at end of file
diff --git a/rocks-and-diamonds.cpp b/rocks-and-diamonds.cpp
index d40fb07..83dd35e 100644
--- a/rocks-and-diamonds.cpp
+++ b/rocks-and-diamonds.cpp
@@ -37,11 +37,11 @@ void init() {
set_screen_mode(ScreenMode::lores);
// Load the spritesheet from the linked binary blob
- screen.sprites = SpriteSheet::load((const uint8_t *)_binary_sprites_start);
+ screen.sprites = SpriteSheet::load((const uint8_t *)asset_sprites_png.data);
// Load the level data from the linked binary blob
// Note: This will be const! Should probably copy the level data to a local array first
- level = new TileMap((uint8_t *)_binary_level_start, nullptr, Size(level_width, level_height), screen.sprites);
+ level = new TileMap((uint8_t *)asset_level.data, nullptr, Size(level_width, level_height), screen.sprites);
}
void render(uint32_t time_ms) {
diff --git a/rocks-and-diamonds.hpp b/rocks-and-diamonds.hpp
index a4bf598..25a7040 100644
--- a/rocks-and-diamonds.hpp
+++ b/rocks-and-diamonds.hpp
@@ -3,12 +3,10 @@
#include <stdint.h>
#include "32blit.hpp"
+#include "assets.hpp"
void init();
void update(uint32_t time);
void render(uint32_t time);
-extern const char _binary_level_start[];
-extern const char _binary_sprites_start[];
-
void update_camera();
\ No newline at end of file I feel keeping |
Hmm the linker approach should be more efficient that just stuffing the data in an array, it's just a question of if it's worth the extra code. (Also, didn't want to delete ALL your code 😄 ) Added a little fix so that the asset pointers are const. |
Small thing I forgot to mention: |
This is most awesome, thank you! |
This main changes here are:
The new syntax for assets is:
This generates an
assets.hpp
file that can be included to access all of the assets, it looks a bit like this:Each asset has a
data
andlength
.