mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[ion] Linux: improve incbin.py script
This commit is contained in:
committed by
EmilieNumworks
parent
5da82d8423
commit
560c4b3821
@@ -28,20 +28,14 @@ endif
|
||||
LDFLAGS += -ljpeg
|
||||
|
||||
$(eval $(call rule_for, \
|
||||
LINUX_ASSETS, \
|
||||
ion/src/simulator/linux/assets.s, \
|
||||
INCBIN, \
|
||||
ion/src/simulator/linux/assets.s ion/src/simulator/linux/images.h, \
|
||||
$(ion_simulator_assets_paths), \
|
||||
$$(PYTHON) ion/src/simulator/linux/assets.py --files $(ion_simulator_assets) --implementation $$@, \
|
||||
$$(PYTHON) ion/src/simulator/linux/incbin.py $(ion_simulator_assets) -o $$@, \
|
||||
global \
|
||||
))
|
||||
|
||||
$(call object_for,ion/src/simulator/linux/images.cpp): $(BUILD_DIR)/ion/src/simulator/linux/images.h
|
||||
|
||||
# The header is refered to as <ion/src/simulator/linux/images.h> so make sure it's findable this way
|
||||
SFLAGS += -I$(BUILD_DIR)
|
||||
|
||||
$(eval $(call rule_for, \
|
||||
LINUX_ASSETS, \
|
||||
ion/src/simulator/linux/images.h, \
|
||||
$(ion_simulator_assets_paths), \
|
||||
$$(PYTHON) ion/src/simulator/linux/assets.py --files $(ion_simulator_assets) --header $$@, \
|
||||
global \
|
||||
))
|
||||
|
||||
@@ -105,15 +105,15 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
|
||||
|
||||
// Find the asset corresponding to identifier
|
||||
for (size_t i = 0; i < sizeof(resources_addresses)/sizeof(resources_addresses[0]); i++) {
|
||||
if (strcmp(identifier, resources_addresses[i].identifier) == 0) {
|
||||
if (strcmp(identifier, resources_addresses[i].identifier()) == 0) {
|
||||
if (strcmp(jpgExtension, identifier + strlen(identifier) - strlen(jpgExtension)) == 0) {
|
||||
format = AssetFormat::JPG;
|
||||
} else {
|
||||
assert(strcmp(pngExtension, identifier + strlen(identifier) - strlen(pngExtension)) == 0);
|
||||
format = AssetFormat::PNG;
|
||||
}
|
||||
assetStart = resources_addresses[i].start;
|
||||
assertSize = resources_addresses[i].end - resources_addresses[i].start;
|
||||
assetStart = resources_addresses[i].start();
|
||||
assertSize = resources_addresses[i].end() - resources_addresses[i].start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,8 @@ import io
|
||||
import os
|
||||
|
||||
parser = argparse.ArgumentParser(description="Process some asset files.")
|
||||
parser.add_argument('--files', nargs='+', help='a list of file names')
|
||||
parser.add_argument('--implementation', help='the .s file to generate')
|
||||
parser.add_argument('--header', help='the .h file to generate')
|
||||
parser.add_argument('assets', metavar='asset', type=str, nargs='+', help='The list of assets to include')
|
||||
parser.add_argument('-o', help='The file to generate')
|
||||
args = parser.parse_args()
|
||||
|
||||
def print_asset(f, asset):
|
||||
@@ -26,7 +25,6 @@ def print_assembly(files, path):
|
||||
f = open(path, "w")
|
||||
for asset in files:
|
||||
print_asset(f, asset)
|
||||
identifier += 1
|
||||
f.close()
|
||||
|
||||
def print_declaration(f, asset):
|
||||
@@ -35,18 +33,30 @@ def print_declaration(f, asset):
|
||||
f.write("extern unsigned char _ion_simulator_" + asset_basename + "_end;\n")
|
||||
|
||||
def print_mapping(f, asset):
|
||||
f.write('"' + asset + '", &_ion_simulator_' + asset_basename +'_start, &_ion_simulator_' + asset_basename '_end},\n')
|
||||
asset_basename = os.path.splitext(asset)[0]
|
||||
f.write('ResourceMap("' + asset + '", &_ion_simulator_' + asset_basename +'_start, &_ion_simulator_' + asset_basename + '_end),\n')
|
||||
|
||||
def print_header(files, path):
|
||||
f = open(path, "w")
|
||||
f.write("#ifndef ION_SIMULATOR_LINUX_IMAGES_H\n")
|
||||
f.write("#define ION_SIMULATOR_LINUX_IMAGES_H\n\n")
|
||||
f.write("// This file is auto-generated by assets.py\n\n")
|
||||
f.write("// This file is auto-generated by incbin.py\n\n")
|
||||
|
||||
for asset in files:
|
||||
print_declaration(f, asset)
|
||||
|
||||
f.write("\nstatic struct { const char * identifier; unsigned char * start; unsigned char * end; } resources_addresses[] = {\n")
|
||||
f.write("\nclass ResourceMap {\n")
|
||||
f.write("public:\n")
|
||||
f.write(" constexpr ResourceMap(const char * identifier, unsigned char * start, unsigned char * end) : m_identifier(identifier), m_start(start), m_end(end) {}\n")
|
||||
f.write(" const char * identifier() const { return m_identifier; }\n")
|
||||
f.write(" unsigned char * start() const { return m_start; }\n")
|
||||
f.write(" unsigned char * end() const { return m_end; }\n")
|
||||
f.write("private:\n")
|
||||
f.write(" const char * m_identifier;\n")
|
||||
f.write(" unsigned char * m_start;\n")
|
||||
f.write(" unsigned char * m_end;\n")
|
||||
f.write("};\n\n")
|
||||
f.write("static constexpr ResourceMap resources_addresses[] = {\n")
|
||||
for asset in files:
|
||||
print_mapping(f, asset)
|
||||
|
||||
@@ -54,7 +64,7 @@ def print_header(files, path):
|
||||
f.write("#endif\n")
|
||||
f.close()
|
||||
|
||||
if (args.implementation):
|
||||
print_assembly(args.files, args.implementation)
|
||||
if (args.header):
|
||||
print_header(args.files, args.implementation)
|
||||
if (args.o.endswith(".s")):
|
||||
print_assembly(args.assets, args.o)
|
||||
if (args.o.endswith(".h")):
|
||||
print_header(args.assets, args.o)
|
||||
Reference in New Issue
Block a user