Added TASable

This commit is contained in:
alex-kumpula 2023-11-11 14:47:07 -07:00
parent 9f7780f176
commit 1ce9c11a02
10 changed files with 125 additions and 27 deletions

View File

@ -4,27 +4,27 @@ using System;
public partial class TAS_System : Node
{
private double _frameLength = 0.1;
private bool _isCountingFrames = false;
private Timer _frameTimer;
private bool _isIncrementingFrames = false;
private double _timeSinceLastFrame;
private int _currentFrame = 0;
private int _lastAdvancedFrame = 0;
public double FrameLength
{
get { return this._frameLength; }
private set { this._frameLength = value; }
set { this._frameLength = value; }
}
public bool IsCountingFrames
public bool IsIncrementingFrames
{
get { return this._isCountingFrames; }
private set { this._isCountingFrames = value; }
get { return this._isIncrementingFrames; }
private set { this._isIncrementingFrames = value; }
}
private Timer FrameTimer
private double TimeSinceLastFrame
{
get { return this._frameTimer; }
set { this._frameTimer = value; }
get { return this._timeSinceLastFrame; }
set { this._timeSinceLastFrame = value; }
}
public int CurrentFrame
@ -46,25 +46,28 @@ public partial class TAS_System : Node
private set { this._lastAdvancedFrame = value; }
}
/// <summary>
/// Signal is emitted whenever the current frame is incremented.
/// </summary>
/// <param name="newFrame"></param>
[Signal]
public delegate void FrameIncrementedEventHandler(int newFrame);
[Signal]
public delegate void FrameAdvancedEventHandler(int currentFrame);
public delegate void FramesAdvancedEventHandler(int startFrame, int endFrame);
[Signal]
public delegate void FramesAdvancedEventHandler(int numFrames);
[Signal]
public delegate void FramesRegressedEventHandler(int numFrames);
public delegate void FramesRegressedEventHandler(int startFrame, int endFrame);
public void StartCountingFrames()
public void StartIncrementingFrames()
{
this.IsIncrementingFrames = true;
}
public void StopCountingFrames()
public void StopIncrementingFrames()
{
this.IsIncrementingFrames = false;
}
public void ResetFrameCount()
@ -78,7 +81,8 @@ public partial class TAS_System : Node
{
int newFrame = Math.Min(this.CurrentFrame + numFrames, this.LastAdvancedFrame);
int framesAdvanced = newFrame - this.CurrentFrame;
EmitSignal(SignalName.FramesAdvanced, framesAdvanced);
EmitSignal(SignalName.FramesAdvanced, this.CurrentFrame, newFrame);
this.CurrentFrame = newFrame;
return framesAdvanced;
}
@ -87,7 +91,8 @@ public partial class TAS_System : Node
{
int newFrame = Math.Max(this.CurrentFrame - numFrames, 0);
int framesRegressed = newFrame - this.CurrentFrame;
EmitSignal(SignalName.FramesRegressed, framesRegressed);
EmitSignal(SignalName.FramesRegressed, this.CurrentFrame, newFrame);
this.CurrentFrame = newFrame;
return framesRegressed;
}
@ -99,7 +104,21 @@ public partial class TAS_System : Node
this.LastAdvancedFrame = this.CurrentFrame;
}
public override void _PhysicsProcess(double delta)
{
if (this.IsIncrementingFrames)
{
this.TimeSinceLastFrame += delta;
if (this.TimeSinceLastFrame >= this.FrameLength)
{
this.CurrentFrame++;
EmitSignal(SignalName.FrameIncremented, this.CurrentFrame);
this.TimeSinceLastFrame = 0 + (this.TimeSinceLastFrame - this.FrameLength);
}
}
// GD.Print(CurrentFrame);
}
// public void Test()
// {

View File

@ -2,5 +2,5 @@
[ext_resource type="Script" path="res://TAS_system/TAS_System.cs" id="1_4s6ry"]
[node name="System" type="Node"]
[node name="TAS_System" type="Node"]
script = ExtResource("1_4s6ry")

View File

@ -0,0 +1,33 @@
using Godot;
using System;
using System.Globalization;
public partial class TASable : Node
{
Node3D _parent;
public override void _Ready()
{
this._parent = this.GetParent<Node3D>();
TAS_System TAS = GetNode<TAS_System>("/root/TAS_System");
TAS.FrameIncremented += this.OnFrameIncremented;
TAS.FramesAdvanced += this.OnFramesAdvanced;
TAS.FramesRegressed += this.OnFramesRegressed;
}
public virtual void OnFrameIncremented(int newFrame)
{
GD.Print($"Frame advanced to {newFrame}, called from node {_parent.Name}");
}
public virtual void OnFramesAdvanced(int startFrame, int endFrame)
{
GD.Print($"Frames advanced from {startFrame} to {endFrame}, called from node {_parent.Name}");
}
public virtual void OnFramesRegressed(int startFrame, int endFrame)
{
GD.Print($"Frames regressed from {startFrame} to {endFrame}, called from node {_parent.Name}");
}
}

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://bjhii55pagkb5"]
[ext_resource type="Script" path="res://TAS_system/TASable.cs" id="1_uqel0"]
[node name="is_TASable" type="Node"]
script = ExtResource("1_uqel0")

View File

@ -12,7 +12,7 @@ func make_target():
func unmake_target():
walk_meshes_post_order(self.get_parent(), unchange_all_materials)
func walk_meshes_post_order(parent: Node3D, f: Callable):
func walk_meshes_post_order(parent: Node, f: Callable):
for child in parent.get_children():
walk_meshes_post_order(child, f)
if parent is MeshInstance3D:

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=2 format=3 uid="uid://w6cldokq87k0"]
[gd_scene load_steps=2 format=3 uid="uid://cbp8c4kpmr0hk"]
[ext_resource type="Script" path="res://control_scheme/is_targetable.gd" id="1_108lw"]

View File

@ -18,7 +18,7 @@ config/icon="res://icon.svg"
[autoload]
ControllerEventBus="*res://controller_event_bus.gd"
TAS="*res://TAS_system/TAS_System.tscn"
TAS_System="*res://TAS_system/TAS_System.tscn"
[dotnet]

View File

@ -10,9 +10,13 @@ public partial class TAS_test_001 : Node
// Initialization here.
GD.Print("Hello from C# to Godot :)");
TAS_System TAS = GetNode<TAS_System>("/root/TAS");
TAS_System TAS = GetNode<TAS_System>("/root/TAS_System");
// TAS.TestSignal += (x) => GD.Print(x);
TAS.FrameLength = 1.5;
TAS.StartIncrementingFrames();
// TAS.FrameIncremented += (x) => GD.Print(x);
// TAS.Test();
}

View File

@ -0,0 +1,36 @@
[gd_scene load_steps=7 format=3 uid="uid://by3rnp88l4plx"]
[ext_resource type="PackedScene" uid="uid://bua7f25rpewkp" path="res://small_room.glb" id="1_bo0jp"]
[ext_resource type="PackedScene" uid="uid://cbp8c4kpmr0hk" path="res://control_scheme/is_targetable.tscn" id="2_d7v5s"]
[ext_resource type="PackedScene" uid="uid://drmb4sitb74fx" path="res://control_scheme/controller.tscn" id="3_0hshv"]
[ext_resource type="PackedScene" uid="uid://bjhii55pagkb5" path="res://TAS_system/is_TASable.tscn" id="3_srlbt"]
[ext_resource type="Script" path="res://tests/TAS_system/TAS_test_001.cs" id="5_0ber1"]
[sub_resource type="Environment" id="Environment_f0m14"]
ambient_light_source = 2
ambient_light_color = Color(1, 1, 1, 1)
ambient_light_energy = 0.5
[node name="small_room" instance=ExtResource("1_bo0jp")]
[node name="is_TASable" parent="table" index="0" instance=ExtResource("3_srlbt")]
[node name="is_targetable" parent="grape" index="0" node_paths=PackedStringArray("attached_to") instance=ExtResource("2_d7v5s")]
attached_to = NodePath("..")
[node name="is_TASable" parent="grape" index="1" instance=ExtResource("3_srlbt")]
[node name="WorldEnvironment" type="WorldEnvironment" parent="." index="3"]
environment = SubResource("Environment_f0m14")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="WorldEnvironment" index="0"]
transform = Transform3D(1, 0, 0, 0, 0.933762, 0.357895, 0, -0.357895, 0.933762, 0, 1.43864, 1.81738)
[node name="controller" parent="." index="4" node_paths=PackedStringArray("camera", "initial_target") instance=ExtResource("3_0hshv")]
camera = NodePath("Camera3D")
initial_target = NodePath("../grape")
[node name="Camera3D" type="Camera3D" parent="controller" index="1"]
[node name="TAS_test_001" type="Node" parent="." index="6"]
script = ExtResource("5_0ber1")

View File

@ -2,7 +2,7 @@
[ext_resource type="PackedScene" uid="uid://bua7f25rpewkp" path="res://small_room.glb" id="1_2ticn"]
[ext_resource type="PackedScene" uid="uid://drmb4sitb74fx" path="res://control_scheme/controller.tscn" id="2_dcvuq"]
[ext_resource type="PackedScene" uid="uid://w6cldokq87k0" path="res://control_scheme/is_targetable.tscn" id="2_y2131"]
[ext_resource type="PackedScene" uid="uid://cbp8c4kpmr0hk" path="res://control_scheme/is_targetable.tscn" id="2_y2131"]
[sub_resource type="Environment" id="Environment_f0m14"]
ambient_light_source = 2