Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdx-3.x #32

Merged
merged 10 commits into from
Nov 23, 2024
4 changes: 1 addition & 3 deletions .github/workflows/javascript_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ env:
GODOT_BASE_BRANCH: 3.x
SCONSFLAGS: verbose=yes warnings=all werror=yes debug_symbols=no
EM_VERSION: 3.1.39
EM_CACHE_FOLDER: "emsdk-cache"

concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-javascript
Expand All @@ -26,8 +25,7 @@ jobs:
uses: mymindstorm/setup-emsdk@v14
with:
version: ${{env.EM_VERSION}}
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
cache-key: emsdk-${{ matrix.cache-name }}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}
no-cache: true

- name: Verify Emscripten setup
run: |
Expand Down
3 changes: 2 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,13 @@ elif selected_platform != "":

# The following only makes sense when the 'env' is defined, and assumes it is.
if "env" in locals():
# FIXME: This method mixes both cosmetic progress stuff and cache handling...
methods.show_progress(env)
# TODO: replace this with `env.Dump(format="json")`
# once we start requiring SCons 4.0 as min version.
methods.dump(env)

methods.clean_cache(env)


def print_elapsed_time():
elapsed_time_sec = round(time.time() - time_at_start, 3)
Expand Down
1 change: 1 addition & 0 deletions doc/classes/Timer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<member name="autostart" type="bool" setter="set_autostart" getter="has_autostart" default="false">
If [code]true[/code], the timer will automatically start when entering the scene tree.
[b]Note:[/b] This property is automatically set to [code]false[/code] after the timer enters the scene tree and starts.
[b]Note:[/b] This property does nothing when the timer is running in the editor.
</member>
<member name="one_shot" type="bool" setter="set_one_shot" getter="is_one_shot" default="false">
If [code]true[/code], the timer will stop when reaching 0. If [code]false[/code], it will restart.
Expand Down
5 changes: 4 additions & 1 deletion drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2799,7 +2799,10 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform
const float fade_start = li->light_ptr->param[VS::LIGHT_PARAM_SHADOW_FADE_START];
// Using 1.0 would break `smoothstep()` in the shader.
ubo_data.fade_from = -ubo_data.shadow_split_offsets[shadow_count - 1] * MIN(fade_start, 0.999);
ubo_data.fade_to = -ubo_data.shadow_split_offsets[shadow_count - 1];

// To prevent the need for a fade to, store the fade to in the final split offset.
// It will either be the same as before, or the maximum split offset.
ubo_data.shadow_split_offsets[3] = ubo_data.shadow_split_offsets[shadow_count - 1];
}

glBindBuffer(GL_UNIFORM_BUFFER, state.directional_ubo);
Expand Down
3 changes: 1 addition & 2 deletions drivers/gles3/rasterizer_scene_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,7 @@ class RasterizerSceneGLES3 : public RasterizerScene {
float shadow_split_offsets[4];

float fade_from;
float fade_to;
float pad[2];
float pad[3];
};

struct LightInstance : public RID_Data {
Expand Down
8 changes: 3 additions & 5 deletions drivers/gles3/shaders/scene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ layout(std140) uniform DirectionalLightData { //ubo:3
mediump vec4 shadow_split_offsets;

mediump float fade_from;
mediump float fade_to;
mediump vec2 pad;
mediump vec3 pad;
};

#endif //ubershader-skip
Expand Down Expand Up @@ -848,8 +847,7 @@ layout(std140) uniform DirectionalLightData {
mediump vec4 shadow_split_offsets;

mediump float fade_from;
mediump float fade_to;
mediump vec2 pad;
mediump vec3 pad;
};

uniform highp sampler2DShadow directional_shadow; // texunit:-5
Expand Down Expand Up @@ -2292,7 +2290,7 @@ FRAGMENT_SHADER_CODE
shadow = min(shadow, contact_shadow);
}
#endif //ubershader-runtime
float pssm_fade = smoothstep(fade_from, fade_to, vertex.z);
float pssm_fade = smoothstep(fade_from, -shadow_split_offsets.w, vertex.z);
light_attenuation = mix(mix(shadow_color_contact.rgb, vec3(1.0), shadow), vec3(1.0), pssm_fade);
}

Expand Down
99 changes: 62 additions & 37 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,21 +1126,19 @@ def show_progress(env):
"fname": str(env.Dir("#")) + "/.scons_node_count",
}

import time, math
import math

class cache_progress:
# The default is 1 GB cache and 12 hours half life
def __init__(self, path=None, limit=1073741824, half_life=43200):
# The default is 1 GB cache
def __init__(self, path=None, limit=pow(1024, 3)):
self.path = path
self.limit = limit
self.exponent_scale = math.log(2) / half_life
if env["verbose"] and path != None:
screen.write(
"Current cache limit is {} (used: {})\n".format(
self.convert_size(limit), self.convert_size(self.get_size(path))
)
)
self.delete(self.file_list())

def __call__(self, node, *args, **kw):
if show_progress:
Expand All @@ -1158,12 +1156,65 @@ def __call__(self, node, *args, **kw):
screen.write("\r[Initial build] ")
screen.flush()

def convert_size(self, size_bytes):
if size_bytes == 0:
return "0 bytes"
size_name = ("bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
i = int(math.floor(math.log(size_bytes, 1024)))
p = math.pow(1024, i)
s = round(size_bytes / p, 2)
return "%s %s" % (int(s) if i == 0 else s, size_name[i])

def get_size(self, start_path="."):
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size

def progress_finish(target, source, env):
try:
with open(node_count_data["fname"], "w") as f:
f.write("%d\n" % node_count_data["count"])
except Exception:
pass

try:
with open(node_count_data["fname"]) as f:
node_count_data["max"] = int(f.readline())
except Exception:
pass

cache_directory = os.environ.get("SCONS_CACHE")
# Simple cache pruning, attached to SCons' progress callback. Trim the
# cache directory to a size not larger than cache_limit.
cache_limit = float(os.getenv("SCONS_CACHE_LIMIT", 1024)) * 1024 * 1024
progressor = cache_progress(cache_directory, cache_limit)
Progress(progressor, interval=node_count_data["interval"])

progress_finish_command = Command("progress_finish", [], progress_finish)
AlwaysBuild(progress_finish_command)


def clean_cache(env):
import atexit
import time

class cache_clean:
def __init__(self, path=None, limit=pow(1024, 3)):
self.path = path
self.limit = limit

def clean(self):
self.delete(self.file_list())

def delete(self, files):
if len(files) == 0:
return
if env["verbose"]:
# Utter something
screen.write("\rPurging %d %s from cache...\n" % (len(files), len(files) > 1 and "files" or "file"))
print("Purging %d %s from cache..." % (len(files), "files" if len(files) > 1 else "file"))
[os.remove(f) for f in files]

def file_list(self):
Expand Down Expand Up @@ -1197,46 +1248,20 @@ def file_list(self):
else:
return [x[0] for x in file_stat[mark:]]

def convert_size(self, size_bytes):
if size_bytes == 0:
return "0 bytes"
size_name = ("bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
i = int(math.floor(math.log(size_bytes, 1024)))
p = math.pow(1024, i)
s = round(size_bytes / p, 2)
return "%s %s" % (int(s) if i == 0 else s, size_name[i])

def get_size(self, start_path="."):
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size

def progress_finish(target, source, env):
def cache_finally():
nonlocal cleaner
try:
with open(node_count_data["fname"], "w") as f:
f.write("%d\n" % node_count_data["count"])
progressor.delete(progressor.file_list())
cleaner.clean()
except Exception:
pass

try:
with open(node_count_data["fname"]) as f:
node_count_data["max"] = int(f.readline())
except Exception:
pass

cache_directory = os.environ.get("SCONS_CACHE")
# Simple cache pruning, attached to SCons' progress callback. Trim the
# cache directory to a size not larger than cache_limit.
cache_limit = float(os.getenv("SCONS_CACHE_LIMIT", 1024)) * 1024 * 1024
progressor = cache_progress(cache_directory, cache_limit)
Progress(progressor, interval=node_count_data["interval"])
cleaner = cache_clean(cache_directory, cache_limit)

progress_finish_command = Command("progress_finish", [], progress_finish)
AlwaysBuild(progress_finish_command)
atexit.register(cache_finally)


def dump(env):
Expand Down
Loading