12
12
if len (sys .argv ) < 4 :
13
13
print (sys .argv [0 ] + " - Incorrect argument count" )
14
14
else :
15
-
16
15
#arguments
17
16
outputFilename = sys .argv [1 ]
18
17
cmakeSourceDir = sys .argv [2 ]
19
18
resourcesFile = sys .argv [3 ]
19
+ resourcesNamespace = sys .argv [4 ]
20
+ correspondingHeaderFile = sys .argv [5 ]
20
21
21
22
with open (resourcesFile , "r" ) as f :
22
23
resourcePaths = f .read ().rstrip ().split (',' )
23
24
24
25
#opening a file
25
26
outp = open (outputFilename ,"w+" )
26
27
27
- outp .write ("#include <stdlib.h>\n " )
28
- outp .write ("#include <cstdint>\n " )
29
- outp .write ("#include <string>\n " )
30
- outp .write ("#include <unordered_map>\n " )
31
- outp .write ("#include <utility>\n " )
32
- outp .write ("#include <nbl/core/string/StringLiteral.h>\n " )
33
- outp .write ("using namespace nbl;\n " )
34
- outp .write ("using namespace nbl::builtin;\n \n " )
35
- outp .write ("namespace nbl {\n " )
36
- outp .write ("\t namespace builtin {\n \n " )
28
+ outp .write ("#include \" " + correspondingHeaderFile + "\" \n " )
29
+ outp .write ("\t namespace " + resourcesNamespace + " {\n " )
37
30
38
31
# writing binary data of all files in a loop
39
32
for x in resourcePaths :
40
- outp .write ('\n \t \ t template<> const std::pair<const uint8_t*, size_t> get_resource<typename NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("%s")>()' % x )
41
- outp .write ('\n \t \t {' )
42
- outp .write ('\n \t \t \ t static const uint8_t data[] = {\n \t \t \t ' )
33
+ outp .write ('\n \t template<> const std::pair<const uint8_t*, size_t> get_resource<typename NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("%s")>()' % x )
34
+ outp .write ('\n \t {' )
35
+ outp .write ('\n \t \t static const uint8_t data[] = {\n \t \t \t ' )
43
36
try :
44
37
with open (cmakeSourceDir + '/' + x , "rb" ) as f :
45
38
index = 0
57
50
print ('Error: BuiltinResources - file with the following path not found: ' + x )
58
51
outp .write ('\n \n Error: BuiltinResources - file with the following path not found: %s' % x )
59
52
60
- outp .write ('\n \t \t \t };' )
61
- outp .write ('\n \t \t \ t return { data, sizeof(data) };' )
62
- outp .write ('\n \t \t }' )
63
- outp .write ('\n \t \ t template const std::pair<const uint8_t*, size_t> get_resource<typename NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("%s")>();\n \n \n ' % x )
53
+ outp .write ('\n \t \t };' )
54
+ outp .write ('\n \t \t return { data, sizeof(data) };' )
55
+ outp .write ('\n \t }' )
56
+ outp .write ('\n \t template const std::pair<const uint8_t*, size_t> get_resource<typename NBL_CORE_UNIQUE_STRING_LITERAL_TYPE("%s")>();\n \n \n ' % x )
64
57
65
58
66
- outp .write ("\t \ t std::pair<const uint8_t*, size_t> get_resource_runtime(const std::string& filename) {\n " )
67
- outp .write ("\t \t \ t static std::unordered_map<std::string, int> resourcesByFilename( {\n " )
59
+ outp .write ("\t std::pair<const uint8_t*, size_t> get_resource_runtime(const std::string& filename) {\n " )
60
+ outp .write ("\t \t static std::unordered_map<std::string, int> resourcesByFilename( {\n " )
68
61
counter = 1
69
62
for x in resourcePaths :
70
- outp .write ("\t \t \t \t {\" %s\" , %d},\n " % (x ,counter ))
63
+ outp .write ("\t \t \t {\" %s\" , %d},\n " % (x ,counter ))
71
64
counter += 1
72
- outp .write ("\t \t \t });\n \n " )
73
- outp .write ("\t \t \ t auto resource = resourcesByFilename.find(filename);\n " )
74
- outp .write ("\t \t \ t if(resource == resourcesByFilename.end()) return { nullptr,0ull };\n " )
75
- outp .write ("\t \t \ t switch (resource->second) \n \t \t \t {\n " )
65
+ outp .write ("\t \t });\n \n " )
66
+ outp .write ("\t \t auto resource = resourcesByFilename.find(filename);\n " )
67
+ outp .write ("\t \t if(resource == resourcesByFilename.end()) return { nullptr,0ull };\n " )
68
+ outp .write ("\t \t switch (resource->second) \n \t \t \t {\n " )
76
69
counter = 1
77
70
for x in resourcePaths :
78
- outp .write ("\t \t \t \ t case %d:\n \t \t \t \t \t return get_resource<typename NBL_CORE_UNIQUE_STRING_LITERAL_TYPE(\" %s\" )>();\n " % (counter ,x ))
71
+ outp .write ("\t \t \t case %d:\n \t \t \t \t \t return get_resource<typename NBL_CORE_UNIQUE_STRING_LITERAL_TYPE(\" %s\" )>();\n " % (counter ,x ))
79
72
counter += 1
80
73
81
- outp .write ("\t \t \t \t default:\n " )
82
- outp .write ("\t \t \t \t \t return { nullptr,0ull };\n " )
83
- outp .write ("\t \t \t }\n \t \t }" )
84
- outp .write ("\n \t }" )
74
+ outp .write ("\t \t \t default:\n " )
75
+ outp .write ("\t \t \t \t return { nullptr,0ull };\n " )
76
+ outp .write ("\t \t }\n \t }" )
85
77
outp .write ("\n }" )
86
78
outp .close ()
0 commit comments