Skip to content

Commit

Permalink
Updated Fjord to use modern C# naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
dinkelspiel committed Aug 2, 2023
1 parent 4a65b62 commit d3f8898
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 171 deletions.
2 changes: 1 addition & 1 deletion Libraries/SDL2-CS
8 changes: 4 additions & 4 deletions src/Debug/ConsoleScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class ConsoleScene : Scene

public ConsoleScene(int width, int height, string id) : base(width, height, id)
{
SetClearColor(UiStyles.Background);
SetUpdateOnlyIfActive(true);
ClearColor = UiStyles.Background;
UpdateOnlyIfActive = true;
}

public override void Update()
Expand Down Expand Up @@ -133,7 +133,7 @@ void HandleCurrentWord()

logsLength = Debug.Logs.Count;

FUI.OverrideMousePosition(Mouse.Position);
FUI.OverMousePosition = Mouse.Position;

float height = 0;
if(consoleInput != "" && Debug.commands.Keys.ToList().Where((command) => command == consoleInput).ToList().Count != 1 )
Expand Down Expand Up @@ -177,6 +177,6 @@ void HandleCurrentWord()
scrollYOffset = scrollY - Mouse.Position.Y;
});
}
FUI.ResetMousePosition();
FUI.OverMousePosition = null;
}
}
2 changes: 1 addition & 1 deletion src/Debug/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static void Initialize()
if(args.Length > 0) {
if(args[0].GetType() == typeof(float)) {
Debug.Log(args[0].GetType());
Game.SetMaxFPS((double)((float)args[0]));
Game.FPSMax = (double)((float)args[0]);
} else {
Debug.Log(LogLevel.Warning, $"Argument must be number");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/InspectorScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class InspectorScene : Scene

public InspectorScene(int width, int height, string id) : base(width, height, id)
{
SetClearColor(UiStyles.Background);
ClearColor = UiStyles.Background;
// SetUpdateOnlyIfActive(true);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Debug/OldInspectorScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class OldInspectorScene : Scene

public OldInspectorScene(int width, int height, string id) : base(width, height, id)
{
SetClearColor(UiStyles.Background);
SetUpdateOnlyIfActive(true);
ClearColor = UiStyles.Background;
UpdateOnlyIfActive = true;
}

public override void Update()
Expand Down
8 changes: 4 additions & 4 deletions src/Debug/PerformanceScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public PerformanceScene(int width, int height, string id) : base(width, height,

public override void Awake()
{
SetClearColor(UiStyles.Background);
ClearColor = UiStyles.Background;
}

public override void Update()
Expand All @@ -41,9 +41,9 @@ public override void Update()
{
setFps = SDL_GetTicks64();

InputFPS = Game.inputFPS;
UpdateFPS = Game.updateFPS;
ProgramFPS = Game.programFPS;
InputFPS = Game.InputFPS;
UpdateFPS = Game.UpdateFPS;
ProgramFPS = Game.ProgramFPS;

recentInputFPS.Add(InputFPS);
recentProgramFPS.Add(ProgramFPS);
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public float DeltaTime
{
get
{
return (float)Game.GetDeltaTime();
return (float)Game.DeltaTime;
}
private set
{
Expand Down
44 changes: 17 additions & 27 deletions src/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ public static class Game

internal static bool Running = true;

private static ulong timeNow = 0;
private static ulong timeLast = 0;
private static double deltaTime = 0.0;
private static ulong _timeNow = 0;
private static ulong _timeLast = 0;
public static double DeltaTime { internal set; get; } = 0.0;

internal static float inputFPS = 0;
internal static float updateFPS = 0;
internal static float programFPS = 0;
internal static float InputFPS = 0;
internal static float UpdateFPS = 0;
internal static float ProgramFPS = 0;

private static double FPSCapLast = 0;
private static double FPSMax = 144;
private static double _fpsCapLast = 0;
public static double FPSMax = 144;

public static void Initialize(string title, int width, int height)
{
Expand Down Expand Up @@ -98,15 +98,15 @@ public static void Run()
while (Running)
{
var FPSCapNow = SDL_GetTicks64();
var FPSCapDelta = FPSCapNow - FPSCapLast;
var FPSCapDelta = FPSCapNow - _fpsCapLast;

if(FPSCapDelta > 1000/FPSMax)
{
timeNow = SDL_GetPerformanceCounter();
deltaTime = ((timeNow - timeLast)*1000 / (double)SDL_GetPerformanceFrequency()) * 0.001;
timeLast = timeNow;
_timeNow = SDL_GetPerformanceCounter();
DeltaTime = ((_timeNow - _timeLast)*1000 / (double)SDL_GetPerformanceFrequency()) * 0.001;
_timeLast = _timeNow;

FPSCapLast = FPSCapNow;
_fpsCapLast = FPSCapNow;

ulong programStart = SDL_GetPerformanceCounter();

Expand All @@ -123,13 +123,13 @@ public static void Run()


var elapsed = (inputEnd - inputStart) / (float)SDL_GetPerformanceFrequency();
inputFPS = 1f / elapsed;
InputFPS = 1f / elapsed;

elapsed = (updateEnd - updateStart) / (float)SDL_GetPerformanceFrequency();
updateFPS = 1f / elapsed;
UpdateFPS = 1f / elapsed;

elapsed = (programEnd - programStart) / (float)SDL_GetPerformanceFrequency();
programFPS = 1f / elapsed;
ProgramFPS = 1f / elapsed;

for (var i = 0; i < GlobalKeyboard.downKeys.Length; i++)
{
Expand All @@ -155,24 +155,14 @@ public static void Run()
}
}

public static float GetDeltaTime()
{
return (float)deltaTime;
}

public static void SetMaxFPS(double FPS)
{
FPSMax = FPS;
}

public static void Update()
{
SDL_GetWindowSize(SDLWindow, out Window.Width, out Window.Height);

SDL_SetRenderDrawColor(SDLRenderer, 0, 0, 0, 255);
SDL_RenderClear(SDLRenderer);

foreach (string id in SceneHandler.GetLoadedScenes())
foreach (string id in SceneHandler.LoadedScenes)
{
try {
SceneHandler.Scenes[id].UpdateCall();
Expand Down
7 changes: 1 addition & 6 deletions src/Graphics/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ public static class Font
internal static Dictionary<string, IntPtr> Fonts = new ();
internal static Dictionary<string, IntPtr> FontCache = new();

internal static string DefaultFont = "segoeui.ttf";

public static string GetDefaultFont()
{
return DefaultFont;
}
public static string DefaultFont { internal set; get; } = "segoeui.ttf";

public static void Initialize()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Graphics/Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ internal static void LineDirect(Line line)
// drawInsClone.color *= (drawIns.hoverAnimation.colorDriver(drawIns.hoverAnimation.progress) + 1);
if(sceneId == null ? Helpers.PointDistance(GlobalMouse.Position, drawInsClone.position) < drawInsClone.radius : Helpers.PointDistance(SceneHandler.Scenes[sceneId].Mouse.Position, drawInsClone.position) < drawInsClone.radius) {
if(drawIns.hoverAnimation.progress < 1)
drawIns.hoverAnimation.progress += drawIns.hoverAnimation.speed * (float)Game.GetDeltaTime();
drawIns.hoverAnimation.progress += drawIns.hoverAnimation.speed * (float)Game.DeltaTime;
} else if(drawIns.hoverAnimation.progress > 0) {
drawIns.hoverAnimation.progress -= drawIns.hoverAnimation.speed * (float)Game.GetDeltaTime();
drawIns.hoverAnimation.progress -= drawIns.hoverAnimation.speed * (float)Game.DeltaTime;
if(drawIns.hoverAnimation.progress < 0)
drawIns.hoverAnimation.progress = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Scenes/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void Update(Vector2 WindowSize)
((float)(random.NextDouble() - 0.5) * CameraShakeIntensity) * (CameraShakeLife / CameraShakeLifeMax)
)
);
CameraShakeLife -= 100 * Game.GetDeltaTime();
CameraShakeLife -= 100 * (float)Game.DeltaTime;
} else
{
Offset = CoreOffset;
Expand Down
87 changes: 26 additions & 61 deletions src/Scenes/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ namespace Fjord.Scenes;

public abstract class Scene : ICloneable
{
private string SceneID;
public string SceneID { get => SceneID; set => throw new Exception("Can't set SceneID"); }

public bool AllowWindowResize = false;
public bool AlwaysRebuildTexture = false;
public bool AlwaysAtBack = false;
public bool AlwaysAtFront = false;
public bool AllowWindowResize { get; set; } = false;
public bool AlwaysRebuildTexture { get; set; } = false;
public bool AlwaysAtBack { get; set; } = false;
public bool AlwaysAtFront { get; set; } = false;

public bool Paused = false;

internal bool showCursor = true;
internal bool captureMouseInput = true;
internal bool ShowCursor = true;
internal bool CaptureMouseInput = true;

internal bool updateOnlyIfActive = false;
internal bool hasRendered = false;
internal bool UpdateOnlyIfActive = false;
internal bool HasRendered = false;

public SceneKeyboard Keyboard;
public SceneMouse Mouse;
Expand All @@ -31,7 +31,7 @@ public float DeltaTime
{
get
{
return (float)Game.GetDeltaTime();
return (float)Game.DeltaTime;
}
private set
{
Expand Down Expand Up @@ -61,65 +61,30 @@ private set
internal SDL_Rect LocalWindowSize = new();
internal Vector2 OriginalWindowSize = new();
internal IntPtr RenderTarget;
internal SDL_Color ClearColor = new()

private SDL_Color _clearColor = new()
{
r = 0,
g = 0,
b = 0,
a = 0
};

public void SetClearColor(SDL_Color cc)
{
ClearColor = cc;
}

public void SetClearColor(Vector4 cc)
{
ClearColor = new()
public Vector4 ClearColor {
get => new(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a);
set => _clearColor = new()
{
r = (byte)cc.X,
g = (byte)cc.Y,
b = (byte)cc.Z,
a = (byte)cc.W
r = (byte)value.X,
g = (byte)value.Y,
b = (byte)value.Z,
a = (byte)value.W
};
}

public void SetClearColor(int r, int g, int b, int a)
{
ClearColor = new()
{
r = (byte)r,
g = (byte)g,
b = (byte)b,
a = (byte)a
};
}

public SDL_Color GetClearColor()
{
return ClearColor;
}

public string GetSceneID()
{
return SceneID;
}

public void SetShowCursor(bool showCursor)
{
this.showCursor = showCursor;
}

public void SetCaptureMouse(bool capture)
{
this.captureMouseInput = capture;
}

public void SetUpdateOnlyIfActive(bool active)
{
this.updateOnlyIfActive = active;
}

public void ApplyOriginalAspectRatio()
{
Expand Down Expand Up @@ -227,7 +192,7 @@ internal void UpdateCall()

if(MouseInsideScene)
{
SDL_ShowCursor(showCursor ? SDL_ENABLE : SDL_DISABLE);
SDL_ShowCursor(ShowCursor ? SDL_ENABLE : SDL_DISABLE);
}

LocalWindowSize = new()
Expand All @@ -242,7 +207,7 @@ internal void UpdateCall()
WindowSize = new(OriginalWindowSize.X, OriginalWindowSize.Y);
}

if (AlwaysRebuildTexture && (MouseInsideScene || !updateOnlyIfActive))
if (AlwaysRebuildTexture && (MouseInsideScene || !UpdateOnlyIfActive))
{
WindowSize = new() {
X = LocalWindowSize.w,
Expand All @@ -260,7 +225,7 @@ internal void UpdateCall()
Mouse.LocalPosition.X = (GlobalMouse.Position.X - LocalWindowSize.x) + Camera.Offset.X;
Mouse.LocalPosition.Y = (GlobalMouse.Position.Y - LocalWindowSize.y) + Camera.Offset.Y;

hasRendered = false;
HasRendered = false;
} else
{
float wRatio = (float)WindowSize.X / (float)LocalWindowSize.w;
Expand All @@ -287,7 +252,7 @@ internal void UpdateCall()
{
if(Helpers.PointInside(GlobalMouse.Position, SceneHandler.Scenes[scene].LocalWindowSize))
{
if(SceneHandler.Scenes[scene].captureMouseInput)
if(SceneHandler.Scenes[scene].CaptureMouseInput)
{
eligble.Add(scene);
}
Expand Down Expand Up @@ -327,10 +292,10 @@ internal void UpdateCall()
if(!Paused)
Camera.Update(WindowSize);

if((!updateOnlyIfActive || !hasRendered) && !Paused)
if((!UpdateOnlyIfActive || !HasRendered) && !Paused)
{
SDL_SetRenderTarget(Game.SDLRenderer, RenderTarget);
SDL_SetRenderDrawColor(Game.SDLRenderer, ClearColor.r, ClearColor.g, ClearColor.b, ClearColor.a);
SDL_SetRenderDrawColor(Game.SDLRenderer, (byte)ClearColor.X, (byte)ClearColor.Y, (byte)ClearColor.Y, (byte)ClearColor.Z);
SDL_RenderClear(Game.SDLRenderer);

Draw.CurrentSceneID = SceneID;
Expand All @@ -348,7 +313,7 @@ internal void UpdateCall()

drawBuffer = new();

hasRendered = true;
HasRendered = true;
}

SDL_SetRenderTarget(Game.SDLRenderer, IntPtr.Zero);
Expand Down
Loading

0 comments on commit d3f8898

Please sign in to comment.