Update to newer Godot and switch to using floats instead of doubles.
This commit is contained in:
parent
65ef70f583
commit
f0d60c6882
20 changed files with 51 additions and 54 deletions
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Godot.NET.Sdk/4.0.2">
|
<Project Sdk="Godot.NET.Sdk/4.2.2">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
|
|
|
@ -5,16 +5,16 @@ public static class Constants
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// a constant representing 1 Meter in pixels.
|
/// a constant representing 1 Meter in pixels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const double Meter = 10;
|
public const float Meter = 10;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the pixel size of either the vertical or the horizontal size of the walls.
|
/// the pixel size of either the vertical or the horizontal size of the walls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const long WallSize = 30;
|
public const int WallSize = 30;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the extents (half of the size) of the pixel size of either the width for the vertical walls,
|
/// the extents (half of the size) of the pixel size of either the width for the vertical walls,
|
||||||
/// or the height for the horizontal walls.
|
/// or the height for the horizontal walls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const long WallSizeExtents = WallSize / 2;
|
public const int WallSizeExtents = WallSize / 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
namespace Pong.Scripts.Data;
|
|
||||||
|
|
||||||
public static class DoubleExtensions
|
|
||||||
{
|
|
||||||
public static double ByMeter(this double num)
|
|
||||||
{
|
|
||||||
return num * Constants.Meter;
|
|
||||||
}
|
|
||||||
}
|
|
9
Scripts/Data/FloatExtensions.cs
Normal file
9
Scripts/Data/FloatExtensions.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
namespace Pong.Scripts.Data;
|
||||||
|
|
||||||
|
public static class FloatExtensions
|
||||||
|
{
|
||||||
|
public static float ByMeter(this float num)
|
||||||
|
{
|
||||||
|
return num * Constants.Meter;
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,8 +23,8 @@ public record GameArea
|
||||||
/// <param name="globalPosition">a Vector2 containing a global position inside the game area.</param>
|
/// <param name="globalPosition">a Vector2 containing a global position inside the game area.</param>
|
||||||
public Vector2 NormalizePosition(Vector2 globalPosition)
|
public Vector2 NormalizePosition(Vector2 globalPosition)
|
||||||
{
|
{
|
||||||
var normalizedX = Mathf.InverseLerp(-X.ByWallSizeExtents, X.ByWallSizeExtents, globalPosition.X);
|
float normalizedX = (float)Mathf.InverseLerp(-X.ByWallSizeExtents, X.ByWallSizeExtents, globalPosition.X);
|
||||||
var normalizedY = Mathf.InverseLerp(-Y.ByWallSizeExtents, Y.ByWallSizeExtents, globalPosition.Y);
|
float normalizedY = (float)Mathf.InverseLerp(-Y.ByWallSizeExtents, Y.ByWallSizeExtents, globalPosition.Y);
|
||||||
return new Vector2(normalizedX, normalizedY);
|
return new Vector2(normalizedX, normalizedY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ public record GameArea
|
||||||
/// <param name="normalizedPosition">a Vector2 containing a normalized position.</param>
|
/// <param name="normalizedPosition">a Vector2 containing a normalized position.</param>
|
||||||
public Vector2 GlobalizePosition(Vector2 normalizedPosition)
|
public Vector2 GlobalizePosition(Vector2 normalizedPosition)
|
||||||
{
|
{
|
||||||
var globalizedX = Mathf.Lerp(-X.ByWallSizeExtents, X.ByWallSizeExtents, normalizedPosition.X);
|
float globalizedX = (float)Mathf.Lerp(-X.ByWallSizeExtents, X.ByWallSizeExtents, normalizedPosition.X);
|
||||||
var globalizedY = Mathf.Lerp(-Y.ByWallSizeExtents, Y.ByWallSizeExtents, normalizedPosition.Y);
|
float globalizedY = (float)Mathf.Lerp(-Y.ByWallSizeExtents, Y.ByWallSizeExtents, normalizedPosition.Y);
|
||||||
return new Vector2(globalizedX, globalizedY);
|
return new Vector2(globalizedX, globalizedY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,22 +4,22 @@ namespace Pong.Scripts.Data;
|
||||||
/// simple wrapper structure to a double that makes it easy to get commonly used calculations of the number.
|
/// simple wrapper structure to a double that makes it easy to get commonly used calculations of the number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Coordinate">the coordinate you want to wrap.</param>
|
/// <param name="Coordinate">the coordinate you want to wrap.</param>
|
||||||
public readonly record struct GameCoordinate(double Coordinate)
|
public readonly record struct GameCoordinate(float Coordinate)
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the original coordinate. you don't really need to use this as the struct has an implicit operator, but
|
/// the original coordinate. you don't really need to use this as the struct has an implicit operator, but
|
||||||
/// its here if you need it.
|
/// its here if you need it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly double Coordinate = Coordinate;
|
public readonly float Coordinate = Coordinate;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// get the coordinate but calculated by the extents of the wall size.
|
/// get the coordinate but calculated by the extents of the wall size.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double ByWallSizeExtents => Coordinate - Constants.WallSizeExtents;
|
public float ByWallSizeExtents => Coordinate - Constants.WallSizeExtents;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// get the coordinate but calculated by the wall size.
|
/// get the coordinate but calculated by the wall size.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double ByWallSize => Coordinate - Constants.WallSize;
|
public float ByWallSize => Coordinate - Constants.WallSize;
|
||||||
|
|
||||||
public static implicit operator double(GameCoordinate coord) => coord.Coordinate;
|
public static implicit operator float(GameCoordinate coord) => coord.Coordinate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,16 +8,16 @@ public struct Settings
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the scale of the game. this can be from 1.0 to 2.0
|
/// the scale of the game. this can be from 1.0 to 2.0
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double Scale;
|
public float Scale;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// options for VSync. 0 is Disabled, 1 is Enabled, 2 is Adaptive, 3 is Mailbox. These match the <see cref="DisplayServer.VSyncMode"/> enum on
|
/// options for VSync. 0 is Disabled, 1 is Enabled, 2 is Adaptive, 3 is Mailbox. These match the <see cref="DisplayServer.VSyncMode"/> enum on
|
||||||
/// the <see cref="DisplayServer"/>.
|
/// the <see cref="DisplayServer"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long VSync;
|
public int VSync;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the default values of settings.
|
/// the default values of settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Settings Default => new() { Scale = 1.0, VSync = (long)DisplayServer.VSyncMode.Enabled };
|
public static Settings Default => new() { Scale = 1.0f, VSync = (int)DisplayServer.VSyncMode.Enabled };
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ namespace Pong.Scripts.Managers;
|
||||||
|
|
||||||
public partial class BasePaddle: RigidBody2D
|
public partial class BasePaddle: RigidBody2D
|
||||||
{
|
{
|
||||||
[Export] protected double MoveSpeed;
|
[Export] protected float MoveSpeed;
|
||||||
|
|
||||||
internal ScalingManager ScalingManager;
|
internal ScalingManager ScalingManager;
|
||||||
protected Vector2? NewPosition;
|
protected Vector2? NewPosition;
|
||||||
|
|
|
@ -65,8 +65,8 @@ public partial class ScalingManager : Node
|
||||||
_enemy.Running = false;
|
_enemy.Running = false;
|
||||||
|
|
||||||
var normalizedPaddlePosition =
|
var normalizedPaddlePosition =
|
||||||
GameArea?.NormalizePosition(_paddle.Position) ?? new Vector2(0, 0.5);
|
GameArea?.NormalizePosition(_paddle.Position) ?? new Vector2(0, 0.5f);
|
||||||
var normalizedEnemyPosition = GameArea?.NormalizePosition(_enemy.Position) ?? new Vector2(1, 0.5);
|
var normalizedEnemyPosition = GameArea?.NormalizePosition(_enemy.Position) ?? new Vector2(1, 0.5f);
|
||||||
var normalizedBallPosition = GameArea?.NormalizePosition(_ball.Position) ?? new Vector2(0, 0);
|
var normalizedBallPosition = GameArea?.NormalizePosition(_ball.Position) ?? new Vector2(0, 0);
|
||||||
|
|
||||||
_gameResolution = DisplayServer.WindowGetSize();
|
_gameResolution = DisplayServer.WindowGetSize();
|
||||||
|
|
|
@ -16,7 +16,7 @@ public partial class Settings : BaseMenu
|
||||||
GetNodes();
|
GetNodes();
|
||||||
|
|
||||||
_scale.Value = _settings.SettingsData.Scale;
|
_scale.Value = _settings.SettingsData.Scale;
|
||||||
_vSync.Selected = (int)_settings.SettingsData.VSync;
|
_vSync.Selected = _settings.SettingsData.VSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBackButtonPressed()
|
private void OnBackButtonPressed()
|
||||||
|
@ -72,7 +72,7 @@ public partial class Settings : BaseMenu
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async void OnSaveButtonPressed()
|
private async void OnSaveButtonPressed()
|
||||||
{
|
{
|
||||||
if (!await _settings.SaveSettings(_settings.SettingsData with { Scale = _scale.Value, VSync = _vSync.Selected})) return;
|
if (!await _settings.SaveSettings(_settings.SettingsData with { Scale = (float)_scale.Value, VSync = _vSync.Selected})) return;
|
||||||
_saveButton.Disabled = true;
|
_saveButton.Disabled = true;
|
||||||
_scaleModified = false;
|
_scaleModified = false;
|
||||||
_vSyncModified = false;
|
_vSyncModified = false;
|
||||||
|
|
|
@ -2,13 +2,13 @@ namespace Pong.Scripts.Objects;
|
||||||
|
|
||||||
public partial class Ball : CharacterBody2D
|
public partial class Ball : CharacterBody2D
|
||||||
{
|
{
|
||||||
[Export] private double _ballSpeed;
|
[Export] private float _ballSpeed;
|
||||||
[Export] private double _maxRandomAngle;
|
[Export] private float _maxRandomAngle;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// this property multiples the ballSpeed by the <see cref="Constants.Meter">Meter</see> constant.
|
/// this property multiples the ballSpeed by the <see cref="Constants.Meter">Meter</see> constant.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private double BallSpeed => _ballSpeed * Constants.Meter;
|
private float BallSpeed => _ballSpeed * Constants.Meter;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// flick the ball in a direction.
|
/// flick the ball in a direction.
|
||||||
|
@ -26,14 +26,14 @@ public partial class Ball : CharacterBody2D
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
CollisionCheck(delta);
|
CollisionCheck((float)delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// this method moves the ball and bounces if it collides with something.
|
/// this method moves the ball and bounces if it collides with something.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="delta">delta time from the <see cref="_PhysicsProcess">_PhysicsProcess</see> method.</param>
|
/// <param name="delta">delta time from the <see cref="_PhysicsProcess">_PhysicsProcess</see> method.</param>
|
||||||
private void CollisionCheck(double delta)
|
private void CollisionCheck(float delta)
|
||||||
{
|
{
|
||||||
var collision = MoveAndCollide(Velocity * delta);
|
var collision = MoveAndCollide(Velocity * delta);
|
||||||
if (collision == null) return;
|
if (collision == null) return;
|
||||||
|
|
|
@ -65,7 +65,7 @@ public partial class Enemy : BasePaddle
|
||||||
NewPosition = null;
|
NewPosition = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scan(GetPhysicsProcessDeltaTime(), state);
|
Scan((float)GetPhysicsProcessDeltaTime(), state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Draw()
|
public override void _Draw()
|
||||||
|
@ -74,7 +74,7 @@ public partial class Enemy : BasePaddle
|
||||||
DrawRect(_scanArea, Colors.Aqua);
|
DrawRect(_scanArea, Colors.Aqua);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Scan(double delta, PhysicsDirectBodyState2D state)
|
private void Scan(float delta, PhysicsDirectBodyState2D state)
|
||||||
{
|
{
|
||||||
var result = _spaceState.IntersectShape(_query);
|
var result = _spaceState.IntersectShape(_query);
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public partial class Enemy : BasePaddle
|
||||||
/// <param name="result">a dictionary of objects that collided with the cast. this method only works if
|
/// <param name="result">a dictionary of objects that collided with the cast. this method only works if
|
||||||
/// theres an object that has the Ball class.</param>
|
/// theres an object that has the Ball class.</param>
|
||||||
/// <param name="state"></param>
|
/// <param name="state"></param>
|
||||||
private void TrackBall(double delta, IReadOnlyList<Dictionary> result, PhysicsDirectBodyState2D state)
|
private void TrackBall(float delta, IReadOnlyList<Dictionary> result, PhysicsDirectBodyState2D state)
|
||||||
{
|
{
|
||||||
// checks if the collider is a ball, if not, return.
|
// checks if the collider is a ball, if not, return.
|
||||||
if (result[0][_collider].As<Ball>() is not { } ball) return;
|
if (result[0][_collider].As<Ball>() is not { } ball) return;
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace Pong.Scripts.Objects;
|
||||||
|
|
||||||
public partial class Paddle : BasePaddle
|
public partial class Paddle : BasePaddle
|
||||||
{
|
{
|
||||||
private double _verticalInput;
|
private float _verticalInput;
|
||||||
private readonly StringName _paddleUp = "paddle_up";
|
private readonly StringName _paddleUp = "paddle_up";
|
||||||
private readonly StringName _paddleDown = "paddle_down";
|
private readonly StringName _paddleDown = "paddle_down";
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public partial class Paddle : BasePaddle
|
||||||
/// a method that returns a number that represents input on the vertical axis.
|
/// a method that returns a number that represents input on the vertical axis.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>1 for up, -1 for down, 0 for nothing.</returns>
|
/// <returns>1 for up, -1 for down, 0 for nothing.</returns>
|
||||||
private double GetVerticalInput()
|
private float GetVerticalInput()
|
||||||
{
|
{
|
||||||
if (Input.IsActionPressed(_paddleUp))
|
if (Input.IsActionPressed(_paddleUp))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
[configuration]
|
[configuration]
|
||||||
|
|
||||||
entry_symbol = "git_plugin_init"
|
entry_symbol = "git_plugin_init"
|
||||||
|
compatibility_minimum = "4.1.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
|
|
||||||
macos.editor = "macos/libgit_plugin.macos.editor.universal.dylib"
|
macos.editor = "macos/libgit_plugin.macos.editor.universal.dylib"
|
||||||
windows.editor.x86_64 = "win64/libgit_plugin.windows.editor.x86_64.dll"
|
windows.editor.x86_64 = "win64/libgit_plugin.windows.editor.x86_64.dll"
|
||||||
linux.editor.double.x86_64 = "linux/libgit_plugin.linux.editor.double.x86_64.so"
|
linux.editor.x86_64 = "linux/libgit_plugin.linux.editor.x86_64.so"
|
||||||
linux.editor.double.arm64 = "linux/libgit_plugin.linux.editor.double.arm64.so"
|
linux.editor.arm64 = "linux/libgit_plugin.linux.editor.arm64.so"
|
||||||
linux.editor.rv64 = ""
|
linux.editor.rv64 = ""
|
||||||
|
|
3
addons/godot-git-plugin/linux/.gitattributes
vendored
3
addons/godot-git-plugin/linux/.gitattributes
vendored
|
@ -1,2 +1 @@
|
||||||
libgit_plugin.linux.editor.double.arm64.so filter=lfs diff=lfs merge=lfs -text
|
*.so filter=lfs diff=lfs merge=lfs -text
|
||||||
libgit_plugin.linux.editor.double.x86_64.so filter=lfs diff=lfs merge=lfs -text
|
|
||||||
|
|
BIN
addons/godot-git-plugin/linux/libgit_plugin.linux.editor.double.arm64.so
(Stored with Git LFS)
BIN
addons/godot-git-plugin/linux/libgit_plugin.linux.editor.double.arm64.so
(Stored with Git LFS)
Binary file not shown.
BIN
addons/godot-git-plugin/linux/libgit_plugin.linux.editor.double.x86_64.so
(Stored with Git LFS)
BIN
addons/godot-git-plugin/linux/libgit_plugin.linux.editor.double.x86_64.so
(Stored with Git LFS)
Binary file not shown.
BIN
addons/godot-git-plugin/linux/libgit_plugin.linux.editor.x86_64.so
(Stored with Git LFS)
Executable file
BIN
addons/godot-git-plugin/linux/libgit_plugin.linux.editor.x86_64.so
(Stored with Git LFS)
Executable file
Binary file not shown.
|
@ -3,5 +3,5 @@
|
||||||
name="Godot Git Plugin"
|
name="Godot Git Plugin"
|
||||||
description="This plugin lets you interact with Git without leaving the Godot editor. More information can be found at https://github.com/godotengine/godot-git-plugin/wiki"
|
description="This plugin lets you interact with Git without leaving the Godot editor. More information can be found at https://github.com/godotengine/godot-git-plugin/wiki"
|
||||||
author="twaritwaikar"
|
author="twaritwaikar"
|
||||||
version="v3.0.0-beta1"
|
version="3.1.1"
|
||||||
script="godot-git-plugin.gd"
|
script="godot-git-plugin.gd"
|
||||||
|
|
|
@ -12,7 +12,7 @@ config_version=5
|
||||||
|
|
||||||
config/name="Pong"
|
config/name="Pong"
|
||||||
run/main_scene="res://Scenes/UI/Menus/MainMenu.tscn"
|
run/main_scene="res://Scenes/UI/Menus/MainMenu.tscn"
|
||||||
config/features=PackedStringArray("4.0", "C#", "Double Precision", "Mobile")
|
config/features=PackedStringArray("4.2", "C#", "Mobile")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
[autoload]
|
[autoload]
|
||||||
|
@ -35,7 +35,7 @@ version_control/autoload_on_startup=true
|
||||||
|
|
||||||
[editor_plugins]
|
[editor_plugins]
|
||||||
|
|
||||||
enabled=PackedStringArray("res://addons/CustomTypes/plugin.cfg")
|
enabled=PackedStringArray()
|
||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
|
@ -63,4 +63,4 @@ scene_reload={
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
renderer/rendering_method="gl_compatibility"
|
renderer/rendering_method="mobile"
|
||||||
|
|
Loading…
Reference in a new issue