e4dcf1d852
This method is used to generate headers for embedding files into the binary (think about the new `#embed` feature in C23 and C++26). While the stringification step itself was plenty fast, it then proceeded to wrap everything using the `textwrap` module. `textwrap` is *very* slow, as it's apparently optimized for human text. This patch reimplements the wrapping logic using a simple regex, resulting in a tremendous speed improvement (~6x), and switches to `map` for the stringification itself (thanks Rémi!) It also removes a (practically) unused argument, `initial_indent`. The generated files are pretty much the same, with a tiny difference in line length (for some reason the old logic overshot the requested line length)
80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
#!/usr/bin/env python
|
|
from misc.utility.scons_hints import *
|
|
|
|
import methods
|
|
|
|
Import("env")
|
|
|
|
env_effects = env.Clone()
|
|
|
|
# metal-cpp headers for Metal FX
|
|
if env["metal"]:
|
|
env_effects.Prepend(CPPPATH=["#thirdparty/metal-cpp"])
|
|
|
|
# Thirdparty source files
|
|
|
|
thirdparty_obj = []
|
|
|
|
thirdparty_dir = "#thirdparty/amd-fsr2/"
|
|
thirdparty_sources = ["ffx_assert.cpp", "ffx_fsr2.cpp"]
|
|
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
|
|
|
|
env_effects.Prepend(CPPPATH=[thirdparty_dir])
|
|
|
|
|
|
def areatex_builder(target, source, env):
|
|
buffer = methods.get_buffer(str(source[0]))
|
|
|
|
with methods.generated_wrapper(str(target[0])) as file:
|
|
file.write(f"""\
|
|
#define AREATEX_WIDTH 160
|
|
#define AREATEX_HEIGHT 560
|
|
#define AREATEX_PITCH (AREATEX_WIDTH * 2)
|
|
#define AREATEX_SIZE (AREATEX_HEIGHT * AREATEX_PITCH)
|
|
|
|
inline constexpr const unsigned char area_tex_png[] = {{
|
|
{methods.format_buffer(buffer, 1)}
|
|
}};
|
|
""")
|
|
|
|
|
|
env.CommandNoCache("smaa_area_tex.gen.h", "#thirdparty/smaa/AreaTex.png", env.Run(areatex_builder))
|
|
|
|
|
|
def searchtex_builder(target, source, env):
|
|
buffer = methods.get_buffer(str(source[0]))
|
|
|
|
with methods.generated_wrapper(str(target[0])) as file:
|
|
file.write(f"""\
|
|
#define SEARCHTEX_WIDTH 64
|
|
#define SEARCHTEX_HEIGHT 16
|
|
#define SEARCHTEX_PITCH SEARCHTEX_WIDTH
|
|
#define SEARCHTEX_SIZE (SEARCHTEX_HEIGHT * SEARCHTEX_PITCH)
|
|
|
|
inline constexpr const unsigned char search_tex_png[] = {{
|
|
{methods.format_buffer(buffer, 1)}
|
|
}};
|
|
""")
|
|
|
|
|
|
env.CommandNoCache("smaa_search_tex.gen.h", "#thirdparty/smaa/SearchTex.png", env.Run(searchtex_builder))
|
|
|
|
# This flag doesn't actually control anything GCC specific in FSR2. It determines
|
|
# if symbols should be exported, which is not required for Godot.
|
|
env_effects.Append(CPPDEFINES=["FFX_GCC"])
|
|
|
|
env_thirdparty = env_effects.Clone()
|
|
env_thirdparty.disable_warnings()
|
|
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
|
|
env.servers_sources += thirdparty_obj
|
|
|
|
# Godot source files
|
|
|
|
module_obj = []
|
|
|
|
env_effects.add_source_files(module_obj, "*.cpp")
|
|
env.servers_sources += module_obj
|
|
|
|
# Needed to force rebuilding the module files when the thirdparty library is updated.
|
|
env.Depends(module_obj, thirdparty_obj)
|