Skip to content

Commit 554fae1

Browse files
committed
DaemonSourceGenerator: do not copy the embedded files in the map
1 parent 86e0ce2 commit 554fae1

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
===========================================================================
3+
Daemon BSD Source Code
4+
Copyright (c) 2025, Daemon Developers
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the Daemon developers nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
===========================================================================
29+
*/
30+
31+
#ifndef COMMON_EMBEDDEDFILE_H_
32+
#define COMMON_EMBEDDEDFILE_H_
33+
struct embeddedFileMapEntry_t
34+
{
35+
const unsigned char* data;
36+
size_t size;
37+
};
38+
39+
using embeddedFileMap_t = std::unordered_map<std::string, const embeddedFileMapEntry_t>;
40+
#endif // COMMON_EMBEDDEDFILE_H_

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)