Update to newer Godot and switch to using floats instead of doubles.

This commit is contained in:
Fries 2024-05-04 13:20:03 -07:00
parent 65ef70f583
commit f0d60c6882
20 changed files with 51 additions and 54 deletions

View File

@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.0.2">
<Project Sdk="Godot.NET.Sdk/4.2.2">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>

View File

@ -5,16 +5,16 @@ public static class Constants
/// <summary>
/// a constant representing 1 Meter in pixels.
/// </summary>
public const double Meter = 10;
public const float Meter = 10;
/// <summary>
/// the pixel size of either the vertical or the horizontal size of the walls.
/// </summary>
public const long WallSize = 30;
public const int WallSize = 30;
/// <summary>
/// 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.
/// </summary>
public const long WallSizeExtents = WallSize / 2;
public const int WallSizeExtents = WallSize / 2;
}

View File

@ -1,9 +0,0 @@
namespace Pong.Scripts.Data;
public static class DoubleExtensions
{
public static double ByMeter(this double num)
{
return num * Constants.Meter;
}
}

View File

@ -0,0 +1,9 @@
namespace Pong.Scripts.Data;
public static class FloatExtensions
{
public static float ByMeter(this float num)
{
return num * Constants.Meter;
}
}

View File

@ -23,8 +23,8 @@ public record GameArea
/// <param name="globalPosition">a Vector2 containing a global position inside the game area.</param>
public Vector2 NormalizePosition(Vector2 globalPosition)
{
var normalizedX = Mathf.InverseLerp(-X.ByWallSizeExtents, X.ByWallSizeExtents, globalPosition.X);
var normalizedY = Mathf.InverseLerp(-Y.ByWallSizeExtents, Y.ByWallSizeExtents, globalPosition.Y);
float normalizedX = (float)Mathf.InverseLerp(-X.ByWallSizeExtents, X.ByWallSizeExtents, globalPosition.X);
float normalizedY = (float)Mathf.InverseLerp(-Y.ByWallSizeExtents, Y.ByWallSizeExtents, globalPosition.Y);
return new Vector2(normalizedX, normalizedY);
}
@ -34,8 +34,8 @@ public record GameArea
/// <param name="normalizedPosition">a Vector2 containing a normalized position.</param>
public Vector2 GlobalizePosition(Vector2 normalizedPosition)
{
var globalizedX = Mathf.Lerp(-X.ByWallSizeExtents, X.ByWallSizeExtents, normalizedPosition.X);
var globalizedY = Mathf.Lerp(-Y.ByWallSizeExtents, Y.ByWallSizeExtents, normalizedPosition.Y);
float globalizedX = (float)Mathf.Lerp(-X.ByWallSizeExtents, X.ByWallSizeExtents, normalizedPosition.X);
float globalizedY = (float)Mathf.Lerp(-Y.ByWallSizeExtents, Y.ByWallSizeExtents, normalizedPosition.Y);
return new Vector2(globalizedX, globalizedY);
}

View File

@ -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.
/// </summary>
/// <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>
/// 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.
/// </summary>
public readonly double Coordinate = Coordinate;
public readonly float Coordinate = Coordinate;
/// <summary>
/// get the coordinate but calculated by the extents of the wall size.
/// </summary>
public double ByWallSizeExtents => Coordinate - Constants.WallSizeExtents;
public float ByWallSizeExtents => Coordinate - Constants.WallSizeExtents;
/// <summary>
/// get the coordinate but calculated by the wall size.
/// </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;
}

View File

@ -8,16 +8,16 @@ public struct Settings
/// <summary>
/// the scale of the game. this can be from 1.0 to 2.0
/// </summary>
public double Scale;
public float Scale;
/// <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
/// the <see cref="DisplayServer"/>.
/// </summary>
public long VSync;
public int VSync;
/// <summary>
/// the default values of settings.
/// </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 };
}

View File

@ -2,7 +2,7 @@ namespace Pong.Scripts.Managers;
public partial class BasePaddle: RigidBody2D
{
[Export] protected double MoveSpeed;
[Export] protected float MoveSpeed;
internal ScalingManager ScalingManager;
protected Vector2? NewPosition;

View File

@ -65,8 +65,8 @@ public partial class ScalingManager : Node
_enemy.Running = false;
var normalizedPaddlePosition =
GameArea?.NormalizePosition(_paddle.Position) ?? new Vector2(0, 0.5);
var normalizedEnemyPosition = GameArea?.NormalizePosition(_enemy.Position) ?? new Vector2(1, 0.5);
GameArea?.NormalizePosition(_paddle.Position) ?? new Vector2(0, 0.5f);
var normalizedEnemyPosition = GameArea?.NormalizePosition(_enemy.Position) ?? new Vector2(1, 0.5f);
var normalizedBallPosition = GameArea?.NormalizePosition(_ball.Position) ?? new Vector2(0, 0);
_gameResolution = DisplayServer.WindowGetSize();

View File

@ -16,7 +16,7 @@ public partial class Settings : BaseMenu
GetNodes();
_scale.Value = _settings.SettingsData.Scale;
_vSync.Selected = (int)_settings.SettingsData.VSync;
_vSync.Selected = _settings.SettingsData.VSync;
}
private void OnBackButtonPressed()
@ -72,7 +72,7 @@ public partial class Settings : BaseMenu
/// </summary>
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;
_scaleModified = false;
_vSyncModified = false;

View File

@ -2,13 +2,13 @@ namespace Pong.Scripts.Objects;
public partial class Ball : CharacterBody2D
{
[Export] private double _ballSpeed;
[Export] private double _maxRandomAngle;
[Export] private float _ballSpeed;
[Export] private float _maxRandomAngle;
/// <summary>
/// this property multiples the ballSpeed by the <see cref="Constants.Meter">Meter</see> constant.
/// </summary>
private double BallSpeed => _ballSpeed * Constants.Meter;
private float BallSpeed => _ballSpeed * Constants.Meter;
/// <summary>
/// flick the ball in a direction.
@ -26,14 +26,14 @@ public partial class Ball : CharacterBody2D
public override void _PhysicsProcess(double delta)
{
CollisionCheck(delta);
CollisionCheck((float)delta);
}
/// <summary>
/// this method moves the ball and bounces if it collides with something.
/// </summary>
/// <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);
if (collision == null) return;

View File

@ -65,7 +65,7 @@ public partial class Enemy : BasePaddle
NewPosition = null;
}
Scan(GetPhysicsProcessDeltaTime(), state);
Scan((float)GetPhysicsProcessDeltaTime(), state);
}
public override void _Draw()
@ -74,7 +74,7 @@ public partial class Enemy : BasePaddle
DrawRect(_scanArea, Colors.Aqua);
}
private void Scan(double delta, PhysicsDirectBodyState2D state)
private void Scan(float delta, PhysicsDirectBodyState2D state)
{
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
/// theres an object that has the Ball class.</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.
if (result[0][_collider].As<Ball>() is not { } ball) return;

View File

@ -5,7 +5,7 @@ namespace Pong.Scripts.Objects;
public partial class Paddle : BasePaddle
{
private double _verticalInput;
private float _verticalInput;
private readonly StringName _paddleUp = "paddle_up";
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.
/// </summary>
/// <returns>1 for up, -1 for down, 0 for nothing.</returns>
private double GetVerticalInput()
private float GetVerticalInput()
{
if (Input.IsActionPressed(_paddleUp))
{

View File

@ -1,11 +1,12 @@
[configuration]
entry_symbol = "git_plugin_init"
compatibility_minimum = "4.1.0"
[libraries]
macos.editor = "macos/libgit_plugin.macos.editor.universal.dylib"
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.double.arm64 = "linux/libgit_plugin.linux.editor.double.arm64.so"
linux.editor.x86_64 = "linux/libgit_plugin.linux.editor.x86_64.so"
linux.editor.arm64 = "linux/libgit_plugin.linux.editor.arm64.so"
linux.editor.rv64 = ""

View File

@ -1,2 +1 @@
libgit_plugin.linux.editor.double.arm64.so filter=lfs diff=lfs merge=lfs -text
libgit_plugin.linux.editor.double.x86_64.so filter=lfs diff=lfs merge=lfs -text
*.so filter=lfs diff=lfs merge=lfs -text

BIN
addons/godot-git-plugin/linux/libgit_plugin.linux.editor.x86_64.so (Stored with Git LFS) Executable file

Binary file not shown.

View File

@ -3,5 +3,5 @@
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"
author="twaritwaikar"
version="v3.0.0-beta1"
version="3.1.1"
script="godot-git-plugin.gd"

View File

@ -12,7 +12,7 @@ config_version=5
config/name="Pong"
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"
[autoload]
@ -35,7 +35,7 @@ version_control/autoload_on_startup=true
[editor_plugins]
enabled=PackedStringArray("res://addons/CustomTypes/plugin.cfg")
enabled=PackedStringArray()
[input]
@ -63,4 +63,4 @@ scene_reload={
[rendering]
renderer/rendering_method="gl_compatibility"
renderer/rendering_method="mobile"