GithubHelp home page GithubHelp logo

codegoose / emico Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 2.78 MB

A tool to assist quickly embedding thousands of files within an executable, accessible during runtime via a map.

Python 19.30% C++ 5.26% C 75.44%

emico's Introduction

emico

For when you have many many many large or small files that you'd rather neatly tuck away inside the binary.

Sample

#include <emico.h>
#include <iostream>

using std::cout;
using std::endl;

int main() {

	cout << "There are " << emico::assets.size() << " embedded assets." << endl;

	for (auto &asset : emico::assets) {
		
		cout << "\t" << asset.first << // Unique ID based on the original file path.
			" : " << asset.second.first << // The memory address of the file contents.
			" (" << asset.second.second << " bytes)" << endl; // Length in bytes of the content.
	}
}

Output

There are 2 embedded assets.
	metadata.things.txt : 0x74616420656d6f53 (39 bytes)
	textures.hye2o8un1rq11.png : 0xa1a0a0d474e5089 (5846127 bytes)

Procedure

Run python3 emico.py. The script will use the masterfully crafted incbin to embed the file contents into individual .cpp source files. It will also generate an appopriate CMakeLists.txt for you.

Here's what the assets directory looked like in the above sample output:

.
├── metadata
│   └── things.txt
└── textures
    └── hye2o8un1rq11.png

The root level must be always a folder but you can have as many files and folders underneath as your heart desires.

Check if an item exists

Since the map is constant, use .find() to get a specific item:

if (auto data = emico::assets.find("shaders.cartoon.glsl"); data != emico::assets.end()) {
	data -> ...
}

Specifics

Here's an example of what the generate emico.cpp will look like:

#include <emico.h>
extern const unsigned char *g_emico_metadata_things_txt_data;
extern const unsigned int g_emico_metadata_things_txt_size;
extern const unsigned char *g_emico_textures_hye2o8un1rq11_png_data;
extern const unsigned int g_emico_textures_hye2o8un1rq11_png_size;
const std::map<std::string, std::pair<const void *, unsigned int>> emico::assets {
	{ "metadata.things.txt", { g_emico_metadata_things_txt_data, g_emico_metadata_things_txt_size } },
	{ "textures.hye2o8un1rq11.png", { g_emico_textures_hye2o8un1rq11_png_data, g_emico_textures_hye2o8un1rq11_png_size } }
};

Those extern's are defined in the many many other source files that are generated to represent each file. Here's src/hye2o8un1rq11.png.cpp:

#define INCBIN_STYLE INCBIN_STYLE_SNAKE
#include <incbin.h>
INCBIN(_emico_textures_hye2o8un1rq11_png, "../assets/textures/hye2o8un1rq11.png");

Super simple and saves loads of time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.