From a7f966376db73d67a40dbc7493787c5b3bde2ae2 Mon Sep 17 00:00:00 2001 From: Persephone Date: Sat, 22 Feb 2025 18:50:09 -0700 Subject: [PATCH] stuff --- NetClassic/InputHandler.cs | 12 ++++++++++++ NetClassic/Logger.cs | 8 ++++---- NetClassic/Player.cs | 0 NetClassic/Program.cs | 40 ++++++++++++++++++++++++++++---------- 4 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 NetClassic/InputHandler.cs create mode 100644 NetClassic/Player.cs diff --git a/NetClassic/InputHandler.cs b/NetClassic/InputHandler.cs new file mode 100644 index 0000000..080d82b --- /dev/null +++ b/NetClassic/InputHandler.cs @@ -0,0 +1,12 @@ +using System; + +namespace NetClassic +{ + public class InputHandler + { + public static void HandleKeyboardInputs(object e) + { + + } + } +} diff --git a/NetClassic/Logger.cs b/NetClassic/Logger.cs index 33bcc4c..022666e 100644 --- a/NetClassic/Logger.cs +++ b/NetClassic/Logger.cs @@ -9,7 +9,7 @@ namespace NetClassic { LoggerName = loggerName; } - public void logInfo(string logData) + public void LogInfo(string logData) { ConsoleColor old = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Gray; @@ -17,7 +17,7 @@ namespace NetClassic Console.ForegroundColor = old; } - public void logWarning(string logData) + public void LogWarning(string logData) { ConsoleColor old = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; @@ -25,7 +25,7 @@ namespace NetClassic Console.ForegroundColor = old; } - public void logError(string logData) + public void LogError(string logData) { ConsoleColor old = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; @@ -33,7 +33,7 @@ namespace NetClassic Console.ForegroundColor = old; } - public void logFatal(string logData) + public void LogFatal(string logData) { ConsoleColor old = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkRed; diff --git a/NetClassic/Player.cs b/NetClassic/Player.cs new file mode 100644 index 0000000..e69de29 diff --git a/NetClassic/Program.cs b/NetClassic/Program.cs index c1567e6..3dd0e35 100644 --- a/NetClassic/Program.cs +++ b/NetClassic/Program.cs @@ -1,4 +1,4 @@ -using SDL2; +using static SDL2.SDL; using System; using System.Timers; @@ -8,24 +8,44 @@ namespace NetClassic { static bool gameRunning = true; static Logger logger = new Logger("NetClassic.Program"); + static long frameTime = 0; + static void Main(string[] args) { - logger.logInfo("Initializing SDL Video and Events..."); - SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_EVENTS); - logger.logInfo("Creating Window..."); - IntPtr window = SDL.SDL_CreateWindow("NetClassic", SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, 1024, 768, SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL); - logger.logInfo("Creating Renderer..."); - IntPtr renderer = SDL.SDL_CreateRenderer(window, -1, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED); + logger.LogInfo($"NetClassic vPreDev on {Environment.OSVersion.VersionString}"); + logger.LogInfo("Initializing SDL Video and Events..."); + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); + logger.LogInfo("Creating Window..."); + IntPtr window = SDL_CreateWindow("NetClassic", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 854, 480, SDL_WindowFlags.SDL_WINDOW_OPENGL); + logger.LogInfo("Creating Renderer..."); + IntPtr renderer = SDL_CreateRenderer(window, -1, SDL_RendererFlags.SDL_RENDERER_ACCELERATED); while(gameRunning) { - SDL.SDL_Event e; - if (SDL.SDL_WaitEvent(out e) != 0) + // log last frame Timers + if (frameTime != 0) { - if (e.type == SDL.SDL_EventType.SDL_QUIT) + logger.LogInfo($"Last frame took {DateTimeOffset.Now.ToUnixTimeMilliseconds() - frameTime}ms"); + } + frameTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + + // handle input + SDL_Event e; + if (SDL_WaitEvent(out e) != 0) + { + if (e.type == SDL_EventType.SDL_QUIT) { gameRunning = false; } + else if (e.type == SDL_EventType.SDL_KEYDOWN) + { + InputHandler.HandleKeyboardInputs(e); + } } + + // draw + SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255); + SDL_RenderClear(renderer); + SDL_RenderPresent(renderer); } } }