more window init stuff
parent
adc06fb4fc
commit
55cd87ab28
34
src/Game.cs
34
src/Game.cs
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using SDL2;
|
||||||
using SDL2;
|
|
||||||
using Campari;
|
using Campari;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
@ -11,10 +10,10 @@ namespace MoonWorks
|
||||||
private double timestep;
|
private double timestep;
|
||||||
ulong currentTime = SDL.SDL_GetPerformanceCounter();
|
ulong currentTime = SDL.SDL_GetPerformanceCounter();
|
||||||
double accumulator = 0;
|
double accumulator = 0;
|
||||||
|
bool debugMode;
|
||||||
|
|
||||||
public IntPtr WindowHandle { get; }
|
public Window Window { get; }
|
||||||
public GraphicsDevice GraphicsDevice { get; }
|
public GraphicsDevice GraphicsDevice { get; }
|
||||||
|
|
||||||
public Input Input { get; }
|
public Input Input { get; }
|
||||||
|
|
||||||
private Dictionary<PresentMode, RefreshCS.Refresh.PresentMode> moonWorksToRefreshPresentMode = new Dictionary<PresentMode, RefreshCS.Refresh.PresentMode>
|
private Dictionary<PresentMode, RefreshCS.Refresh.PresentMode> moonWorksToRefreshPresentMode = new Dictionary<PresentMode, RefreshCS.Refresh.PresentMode>
|
||||||
|
@ -25,8 +24,12 @@ namespace MoonWorks
|
||||||
{ PresentMode.FIFORelaxed, RefreshCS.Refresh.PresentMode.FIFORelaxed }
|
{ PresentMode.FIFORelaxed, RefreshCS.Refresh.PresentMode.FIFORelaxed }
|
||||||
};
|
};
|
||||||
|
|
||||||
public Game(uint windowWidth, uint windowHeight, PresentMode presentMode, int targetTimestep = 60, bool debugMode = false)
|
public Game(
|
||||||
{
|
WindowCreateInfo windowCreateInfo,
|
||||||
|
PresentMode presentMode,
|
||||||
|
int targetTimestep = 60,
|
||||||
|
bool debugMode = false
|
||||||
|
) {
|
||||||
timestep = 1.0 / targetTimestep;
|
timestep = 1.0 / targetTimestep;
|
||||||
|
|
||||||
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_TIMER | SDL.SDL_INIT_GAMECONTROLLER) < 0)
|
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_TIMER | SDL.SDL_INIT_GAMECONTROLLER) < 0)
|
||||||
|
@ -35,18 +38,17 @@ namespace MoonWorks
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowHandle = SDL.SDL_CreateWindow(
|
Input = new Input();
|
||||||
"CampariTest",
|
|
||||||
SDL.SDL_WINDOWPOS_UNDEFINED,
|
Window = new Window(windowCreateInfo);
|
||||||
SDL.SDL_WINDOWPOS_UNDEFINED,
|
|
||||||
(int)windowWidth,
|
GraphicsDevice = new GraphicsDevice(
|
||||||
(int)windowHeight,
|
Window.Handle,
|
||||||
SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN
|
moonWorksToRefreshPresentMode[presentMode],
|
||||||
|
debugMode
|
||||||
);
|
);
|
||||||
|
|
||||||
GraphicsDevice = new GraphicsDevice(WindowHandle, moonWorksToRefreshPresentMode[presentMode], debugMode);
|
this.debugMode = debugMode;
|
||||||
|
|
||||||
Input = new Input();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run()
|
public void Run()
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace MoonWorks
|
||||||
|
{
|
||||||
|
public enum ScreenMode
|
||||||
|
{
|
||||||
|
Fullscreen,
|
||||||
|
BorderlessWindow,
|
||||||
|
Windowed
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
using System;
|
||||||
|
using SDL2;
|
||||||
|
|
||||||
|
namespace MoonWorks
|
||||||
|
{
|
||||||
|
public class Window
|
||||||
|
{
|
||||||
|
public IntPtr Handle { get; }
|
||||||
|
public ScreenMode ScreenMode { get; }
|
||||||
|
|
||||||
|
public Window(WindowCreateInfo windowCreateInfo)
|
||||||
|
{
|
||||||
|
var windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN;
|
||||||
|
|
||||||
|
if (windowCreateInfo.ScreenMode == ScreenMode.Fullscreen)
|
||||||
|
{
|
||||||
|
windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
|
||||||
|
}
|
||||||
|
else if (windowCreateInfo.ScreenMode == ScreenMode.BorderlessWindow)
|
||||||
|
{
|
||||||
|
windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScreenMode = windowCreateInfo.ScreenMode;
|
||||||
|
|
||||||
|
Handle = SDL.SDL_CreateWindow(
|
||||||
|
"CampariTest",
|
||||||
|
SDL.SDL_WINDOWPOS_UNDEFINED,
|
||||||
|
SDL.SDL_WINDOWPOS_UNDEFINED,
|
||||||
|
(int)windowCreateInfo.WindowWidth,
|
||||||
|
(int)windowCreateInfo.WindowHeight,
|
||||||
|
windowFlags
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeScreenMode(ScreenMode screenMode)
|
||||||
|
{
|
||||||
|
SDL.SDL_WindowFlags windowFlag = 0;
|
||||||
|
|
||||||
|
if (screenMode == ScreenMode.Fullscreen)
|
||||||
|
{
|
||||||
|
windowFlag = SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
|
||||||
|
}
|
||||||
|
else if (screenMode == ScreenMode.BorderlessWindow)
|
||||||
|
{
|
||||||
|
windowFlag = SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL.SDL_SetWindowFullscreen(Handle, (uint) windowFlag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace MoonWorks
|
||||||
|
{
|
||||||
|
public struct WindowCreateInfo
|
||||||
|
{
|
||||||
|
public uint WindowWidth;
|
||||||
|
public uint WindowHeight;
|
||||||
|
public ScreenMode ScreenMode;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue