From 7cefa4f9699fbc5c88a2f74597d62b79d2714c67 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Thu, 10 Mar 2022 15:58:05 -0800 Subject: [PATCH] Add initial version of asset inclusion in binary --- build/.gitignore | 5 ++++- build/README.md | 11 ++++++++--- build/build.sh | 3 +++ build/packer.py | 19 +++++++++++++++++++ build/run.sh | 2 ++ include/.gitignore | 1 + src/Main.cpp | 19 ++++++++++--------- 7 files changed, 47 insertions(+), 13 deletions(-) create mode 100755 build/build.sh create mode 100644 build/packer.py create mode 100755 build/run.sh create mode 100644 include/.gitignore diff --git a/build/.gitignore b/build/.gitignore index 02c52c7..207712c 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -1,3 +1,6 @@ * !README.md -!.gitignore \ No newline at end of file +!.gitignore +!packer.py +!build.sh +!run.sh \ No newline at end of file diff --git a/build/README.md b/build/README.md index 30e865b..4c8d5e5 100644 --- a/build/README.md +++ b/build/README.md @@ -2,14 +2,19 @@ This build setup is only working/tested for GNU/Linux systems. In order to have the required development dependencies, install them using your system's package manager. This is `libsfml-dev` on Debian-based systems and `sfml` on Arch-based systems (untested). They package must be at version 2.5. -First, `cd` into this folder, then run Cmake to generate the Makefile. If you ever update `CMakeLists.txt`, run this command again. +To compile: ```SH -cmake .. +./build.sh ``` To compile and run: ```SH -cmake --build . && ./elnutris +./run.sh +``` + +To run: +``` +./elnutris ``` diff --git a/build/build.sh b/build/build.sh new file mode 100755 index 0000000..07fed81 --- /dev/null +++ b/build/build.sh @@ -0,0 +1,3 @@ +python3 packer.py +cmake .. +cmake --build . \ No newline at end of file diff --git a/build/packer.py b/build/packer.py new file mode 100644 index 0000000..5f59e20 --- /dev/null +++ b/build/packer.py @@ -0,0 +1,19 @@ +import os + +RES_DIR = "../res/" +RES_FILE = "../include/res.hpp" + +resources = os.fsencode(RES_DIR) +res = "" + +for resource in os.listdir(resources): + encoded = f"const unsigned char {os.path.splitext(resource)[0].decode().upper()}[] = {'{'} " + file = open(RES_DIR + resource.decode(), "rb") # read binary + for byte in file.read(): + encoded += f"0x{byte.to_bytes(1, byteorder='little').hex()}, " + encoded = encoded[:-2] + " };" + res += encoded + "\n" + +res_file = open(RES_FILE, "w") +res_file.write(res) +res_file.close() \ No newline at end of file diff --git a/build/run.sh b/build/run.sh new file mode 100755 index 0000000..7bfb8de --- /dev/null +++ b/build/run.sh @@ -0,0 +1,2 @@ +./build.sh +./elnutris \ No newline at end of file diff --git a/include/.gitignore b/include/.gitignore new file mode 100644 index 0000000..caec75c --- /dev/null +++ b/include/.gitignore @@ -0,0 +1 @@ +res.hpp \ No newline at end of file diff --git a/src/Main.cpp b/src/Main.cpp index f85a9e0..52f2b58 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #define TILE_SIZE 20 @@ -289,17 +290,17 @@ int main() TileType* grid[GRID_HEIGHT][GRID_WIDTH] = { nullptr }; sf::Texture texture; - texture.loadFromFile("../res/texture.png"); + texture.loadFromMemory(&TEXTURE, sizeof(TEXTURE)); sf::Sprite sprite; sprite.setTexture(texture); sf::Texture background_texture; - background_texture.loadFromFile("../res/background.png"); + background_texture.loadFromMemory(&BACKGROUND, sizeof(BACKGROUND)); sf::Sprite background; background.setTexture(background_texture); sf::Texture numeral_texture; - numeral_texture.loadFromFile("../res/numerals.png"); + numeral_texture.loadFromMemory(&NUMERALS, sizeof(NUMERALS)); NumberRenderer number_renderer(numeral_texture, sf::IntRect(134, 0, 10, 16), { sf::IntRect(0, 0, 14, 16), sf::IntRect(14, 0, 8, 16), @@ -350,42 +351,42 @@ int main() // https://sfxr.me/#57uBnWWZeyDTsBRrJsAp2Vwd76cMVrdeRQ7DirNQW5XekKxcrCUNx47Zggh7Uqw4R5FdeUpyk362uhjWmpNHmqxE7JBp3EkxDxfJ1VjzMRpuSHieW6B5iyVFM sf::SoundBuffer rotate_buffer; - rotate_buffer.loadFromFile("../res/rotate.wav"); + rotate_buffer.loadFromMemory(&ROTATE, sizeof(ROTATE)); sf::Sound rotate_sound; rotate_sound.setBuffer(rotate_buffer); // https://sfxr.me/#57uBnWTMa2LUtaPa3P8xWZekiRxNwCPFWpRoPDVXDJM9KHkiGJcs6J62FRcjMY5oVNdT73MtmUf5rXCPvSZWL7AZuTRWWjKbPKTpZjT85AcZ6htUqTswkjksZ sf::SoundBuffer snap_buffer; - snap_buffer.loadFromFile("../res/snap.wav"); + snap_buffer.loadFromMemory(&SNAP, sizeof(SNAP)); sf::Sound snap_sound; snap_sound.setBuffer(snap_buffer); // https://sfxr.me/#57uBnWbareN7MJJsWGD8eFCrqjikS9f8JXg8jvmKzMdVtqmRsb81eToSUpnkqgFhvxD2QoAjpw4SmGZHZjbhEiPQKetRSHCHXYFZzD7Q6RVVS9CRSeRAb6bZp sf::SoundBuffer game_over_buffer; - game_over_buffer.loadFromFile("../res/game_over.wav"); + game_over_buffer.loadFromMemory(&GAME_OVER, sizeof(GAME_OVER)); sf::Sound game_over_sound; game_over_sound.setBuffer(game_over_buffer); // https://sfxr.me/#7BMHBGMfGk8EHV8czJkUucUm8EMAnMNxiqYyTfKkMpHFJu44GEdD7xP6E8NM3K7RKRExTpagPBAiWf7BLtC52CEWJVGHh8hwDLygoEG86tcPth2UtmfdrXLoh sf::SoundBuffer row_clear_buffer; - row_clear_buffer.loadFromFile("../res/row_clear.wav"); + row_clear_buffer.loadFromMemory(&ROW_CLEAR, sizeof(ROW_CLEAR)); sf::Sound row_clear_sound; row_clear_sound.setBuffer(row_clear_buffer); // https://sfxr.me/#57uBnWg8448kTPqWAxeDvZ5CP5JWbrfJGWuRcTjva5uX3vvBnEAZ6SfiH9oLKMXgsusuJwGWx6KPfvLfHtqnhLxr476ptGv4jPbfNhQaFMYeMHFdHk9SotQ4X sf::SoundBuffer level_up_buffer; - level_up_buffer.loadFromFile("../res/level_up.wav"); + level_up_buffer.loadFromMemory(&LEVEL_UP, sizeof(LEVEL_UP)); sf::Sound level_up_sound; level_up_sound.setBuffer(level_up_buffer); // https://sfxr.me/#34T6PkzvrkfdahGDBAh1uYGXTwZ8rG54kxfHpgdVCPxqG7yyK5UuqgiK9Z8Q5177itxbkSNfLSHm4zTkemT4iyxJpW89VJx82feaq8qxZeA5AJR2nWZZR59hq sf::SoundBuffer new_highscore_buffer; - new_highscore_buffer.loadFromFile("../res/new_highscore.wav"); + new_highscore_buffer.loadFromMemory(&NEW_HIGHSCORE, sizeof(NEW_HIGHSCORE)); sf::Sound new_highscore_sound; new_highscore_sound.setBuffer(new_highscore_buffer);