From a4857acd2672e980f1c30f18f18a687cf931bfe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20G=C3=A1lffy?= Date: Sat, 2 Dec 2023 13:25:04 +0100 Subject: [PATCH] refactor: Make Interpolators a static class --- addons/netfox.extras/plugin.cfg | 2 +- addons/netfox.noray/plugin.cfg | 2 +- addons/netfox/interpolators.gd | 17 +++++++++-------- addons/netfox/netfox.gd | 4 ---- addons/netfox/plugin.cfg | 2 +- project.godot | 5 ++--- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/addons/netfox.extras/plugin.cfg b/addons/netfox.extras/plugin.cfg index d8e6e320..654a033c 100644 --- a/addons/netfox.extras/plugin.cfg +++ b/addons/netfox.extras/plugin.cfg @@ -3,5 +3,5 @@ name="netfox.extras" description="Game-specific utilities for Netfox" author="Tamas Galffy" -version="1.0.1" +version="1.0.2" script="netfox-extras.gd" diff --git a/addons/netfox.noray/plugin.cfg b/addons/netfox.noray/plugin.cfg index 72691e16..2962b697 100644 --- a/addons/netfox.noray/plugin.cfg +++ b/addons/netfox.noray/plugin.cfg @@ -3,5 +3,5 @@ name="netfox.noray" description="Bulletproof your connectivity with noray integration for netfox" author="Tamas Galffy" -version="1.0.1" +version="1.0.2" script="netfox-noray.gd" diff --git a/addons/netfox/interpolators.gd b/addons/netfox/interpolators.gd index a0a46f35..07063f7d 100644 --- a/addons/netfox/interpolators.gd +++ b/addons/netfox/interpolators.gd @@ -1,4 +1,5 @@ -extends Node +extends Object +class_name Interpolators class Interpolator: var is_applicable: Callable @@ -10,26 +11,26 @@ class Interpolator: result.apply = apply return result -var DEFAULT_INTERPOLATOR = Interpolator.make( +static var DEFAULT_INTERPOLATOR = Interpolator.make( func (v): return true, func (a, b, f): return a if f < 0.5 else b ) -var interpolators: Array[Interpolator] -var default_apply: Callable = func(a, b, f): a if f < 0.5 else b +static var interpolators: Array[Interpolator] +static var default_apply: Callable = func(a, b, f): a if f < 0.5 else b ## Register an interpolator. ## ## New interpolators are pushed to the front of the list, making them have ## precedence over existing ones. This can be useful in case you want to override ## the built-in interpolators. -func register(is_applicable: Callable, apply: Callable): +static func register(is_applicable: Callable, apply: Callable): interpolators.push_front(Interpolator.make(is_applicable, apply)) ## Find the appropriate interpolator for the given value. ## ## If none was found, the default interpolator is returned. -func find_for(value) -> Callable: +static func find_for(value) -> Callable: for interpolator in interpolators: if interpolator.is_applicable.call(value): return interpolator.apply @@ -41,10 +42,10 @@ func find_for(value) -> Callable: ## Note, that it is usually faster to just cache the Callable returned by find_for ## and call that, instead of calling interpolate repeatedly. The latter will have ## to lookup the appropriate interpolator on every call. -func interpolate(a, b, f: float): +static func interpolate(a, b, f: float): return find_for(a).call(a, b, f) -func _init(): +static func _static_init(): # Register built-in interpolators # Float register( diff --git a/addons/netfox/netfox.gd b/addons/netfox/netfox.gd index 68a82397..4706517c 100644 --- a/addons/netfox/netfox.gd +++ b/addons/netfox/netfox.gd @@ -88,10 +88,6 @@ const AUTOLOADS = [ { "name": "NetworkEvents", "path": ROOT + "/network-events.gd" - }, - { - "name": "Interpolators", - "path": ROOT + "/interpolators.gd" } ] diff --git a/addons/netfox/plugin.cfg b/addons/netfox/plugin.cfg index 93d46894..2892fb14 100644 --- a/addons/netfox/plugin.cfg +++ b/addons/netfox/plugin.cfg @@ -3,5 +3,5 @@ name="netfox" description="A higher-level networking addon with rollback support" author="Tamas Galffy" -version="1.0.1" +version="1.0.2" script="netfox.gd" diff --git a/project.godot b/project.godot index 69fc4dfe..70b8f4dd 100644 --- a/project.godot +++ b/project.godot @@ -20,14 +20,13 @@ config/icon="res://icon.png" [autoload] Async="*res://examples/shared/scripts/async.gd" -Noray="*res://addons/netfox.noray/noray.gd" -PacketHandshake="*res://addons/netfox.noray/packet-handshake.gd" GameEvents="*res://examples/forest-brawl/scripts/game-events.gd" NetworkTime="*res://addons/netfox/network-time.gd" NetworkTimeSynchronizer="*res://addons/netfox/network-time-synchronizer.gd" NetworkRollback="*res://addons/netfox/rollback/network-rollback.gd" NetworkEvents="*res://addons/netfox/network-events.gd" -Interpolators="*res://addons/netfox/interpolators.gd" +Noray="*res://addons/netfox.noray/noray.gd" +PacketHandshake="*res://addons/netfox.noray/packet-handshake.gd" [display]