Skip to content

Commit c9e7f9c

Browse files
committed
DaemonSourceGenerator: do not copy the embedded files in the map
1 parent 95e1b3e commit c9e7f9c

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

cmake/DaemonSourceGenerator.cmake

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,20 @@ macro(daemon_embed_files basename slug format targetname)
110110
)
111111

112112
string(APPEND embed_map_text
113-
"\t{ \"${filename}\", "
114-
"std::string(reinterpret_cast<const char *>( ${filename_symbol} ), "
115-
"sizeof( ${filename_symbol} )) },\n"
113+
"\t{ \"${filename}\", { ${filename_symbol}, sizeof( ${filename_symbol}) - 1 } },\n"
116114
)
117115
endforeach()
118116

119117
string(APPEND embed_CPP_text
120118
"\n"
121-
"const std::unordered_map<std::string, std::string> FileMap\n{\n"
119+
"const embeddedFileMap_t FileMap\n{\n"
122120
"${embed_map_text}"
123121
"};\n"
124122
"}"
125123
)
126124

127125
string(APPEND embed_H_text
128-
"extern const std::unordered_map<std::string, std::string> FileMap;\n"
126+
"extern const embeddedFileMap_t FileMap;\n"
129127
"};\n"
130128
)
131129

cmake/EmbedText.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ file(READ ${INPUT_FILE} contents HEX)
1010

1111
if ("${FILE_FORMAT}" STREQUAL "TEXT")
1212
# Strip \r for consistency.
13-
string(REGEX REPLACE "(0d)?(..)" "0x\\2," contents "${contents}")
13+
string(REGEX REPLACE "(0d)?(..)" "0x\\2," contents "${contents}")
1414
elseif("${FILE_FORMAT}" STREQUAL "BINARY")
1515
string(REGEX REPLACE "(..)" "0x\\1," contents "${contents}")
1616
else()
1717
message(FATAL_ERROR "Unknown file format: ${FILE_FORMAT}")
1818
endif()
1919

20+
# Add null terminator.
21+
string(REGEX REPLACE ",$" ",0x00," contents "${contents}")
22+
2023
# Split long lines.
2124
string(REGEX REPLACE
2225
"(0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,)" "\\1\n"
@@ -26,7 +29,7 @@ string(REGEX REPLACE
2629
string(REGEX REPLACE ",$" ",\n" contents "${contents}")
2730

2831
file(WRITE ${OUTPUT_FILE}
29-
"const unsigned char ${VARIABLE_NAME}[] =\n"
32+
"constexpr unsigned char ${VARIABLE_NAME}[] =\n"
3033
"{\n"
3134
"${contents}"
3235
"};\n"

src/common/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4848
#include "Color.h"
4949
#include "Serialize.h"
5050
#include "DisjointSets.h"
51+
#include "EmbeddedFile.h"
5152

5253
using Math::Vec2;
5354
using Math::Vec3;

src/common/EmbeddedFile.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct embeddedFileMapEntry_t
2+
{
3+
const unsigned char* data;
4+
size_t size;
5+
};
6+
7+
using embeddedFileMap_t = std::unordered_map<std::string, const embeddedFileMapEntry_t>;

src/engine/renderer/gl_shader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace // Implementation details
9494
{
9595
auto it = EngineShaders::FileMap.find(filename);
9696
if (it != EngineShaders::FileMap.end())
97-
return it->second.c_str();
97+
return (const char*) it->second.data;
9898
return nullptr;
9999
}
100100

0 commit comments

Comments
 (0)