Skip to content

Commit ac27caa

Browse files
committed
DaemonSourceGenerator: do not copy the embedded files in the map
1 parent f87d034 commit ac27caa

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
@@ -11,13 +11,16 @@ file(READ ${INPUT_FILE} contents HEX)
1111
# Translate the file content.
1212
if ("${FILE_FORMAT}" STREQUAL "TEXT")
1313
# Strip \r for consistency.
14-
string(REGEX REPLACE "(0d)?(..)" "0x\\2," contents "${contents}")
14+
string(REGEX REPLACE "(0d)?(..)" "0x\\2," contents "${contents}")
1515
elseif("${FILE_FORMAT}" STREQUAL "BINARY")
1616
string(REGEX REPLACE "(..)" "0x\\1," contents "${contents}")
1717
else()
1818
message(FATAL_ERROR "Unknown file format: ${FILE_FORMAT}")
1919
endif()
2020

21+
# Add null terminator.
22+
set(contents "${contents}0x00,")
23+
2124
# Split long lines.
2225
string(REGEX REPLACE
2326
"(0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,)" "\\1\n"
@@ -28,7 +31,7 @@ string(REGEX REPLACE
2831
string(REGEX REPLACE ",$" ",\n" contents "${contents}")
2932

3033
file(WRITE ${OUTPUT_FILE}
31-
"const unsigned char ${VARIABLE_NAME}[] =\n"
34+
"constexpr unsigned char ${VARIABLE_NAME}[] =\n"
3235
"{\n"
3336
"${contents}"
3437
"};\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)