From 17f3466451b380cbe350d8fb2892c39c7fa4fc22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 28 Jun 2015 18:54:54 +0200 Subject: [PATCH] untie the engine from SDL2 and MiniTK --- Makefile | 42 +++++++++--------- OpenRA.Game/Game.cs | 16 +------ OpenRA.Game/Graphics/IGraphicsDevice.cs | 7 +-- OpenRA.Game/OpenRA.Game.csproj | 10 +---- OpenRA.Game/{Graphics => }/Renderer.cs | 11 ++--- OpenRA.Game/Settings.cs | 4 +- OpenRA.Game/Sound/Sound.cs | 43 ++++++++----------- OpenRA.Game/Sound/SoundDevice.cs | 7 ++- OpenRA.Platforms.Default/DefaultPlatform.cs | 32 ++++++++++++++ .../ErrorHandler.cs | 14 +++--- .../FrameBuffer.cs | 2 +- .../MultiTapDetection.cs | 2 +- .../OpenAlSoundEngine.cs | 18 ++++++-- .../OpenRA.Platforms.Default.csproj | 12 ++++-- .../Sdl2GraphicsDevice.cs | 29 +++++-------- .../Sdl2Input.cs | 2 +- .../Shader.cs | 2 +- .../Texture.cs | 2 +- .../VertexBuffer.cs | 2 +- .../NullGraphicsDevice.cs | 13 +----- OpenRA.Platforms.Null/NullPlatform.cs | 31 +++++++++++++ .../NullSound.cs | 7 ++- .../OpenRA.Platforms.Null.csproj | 12 ++++-- OpenRA.sln | 4 +- make.ps1 | 8 ++-- packaging/package-all.sh | 2 +- packaging/windows/OpenRA.nsi | 8 ++-- 27 files changed, 196 insertions(+), 146 deletions(-) rename OpenRA.Game/{Graphics => }/Renderer.cs (95%) create mode 100644 OpenRA.Platforms.Default/DefaultPlatform.cs rename {OpenRA.Renderer.Sdl2 => OpenRA.Platforms.Default}/ErrorHandler.cs (86%) rename {OpenRA.Renderer.Sdl2 => OpenRA.Platforms.Default}/FrameBuffer.cs (99%) rename {OpenRA.Renderer.Sdl2 => OpenRA.Platforms.Default}/MultiTapDetection.cs (98%) rename OpenRA.Game/Sound/OpenAlSound.cs => OpenRA.Platforms.Default/OpenAlSoundEngine.cs (95%) rename OpenRA.Renderer.Sdl2/OpenRA.Renderer.Sdl2.csproj => OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj (87%) rename {OpenRA.Renderer.Sdl2 => OpenRA.Platforms.Default}/Sdl2GraphicsDevice.cs (94%) rename {OpenRA.Renderer.Sdl2 => OpenRA.Platforms.Default}/Sdl2Input.cs (99%) rename {OpenRA.Renderer.Sdl2 => OpenRA.Platforms.Default}/Shader.cs (99%) rename {OpenRA.Renderer.Sdl2 => OpenRA.Platforms.Default}/Texture.cs (99%) rename {OpenRA.Renderer.Sdl2 => OpenRA.Platforms.Default}/VertexBuffer.cs (98%) rename {OpenRA.Renderer.Null => OpenRA.Platforms.Null}/NullGraphicsDevice.cs (91%) create mode 100644 OpenRA.Platforms.Null/NullPlatform.cs rename {OpenRA.Game/Sound => OpenRA.Platforms.Null}/NullSound.cs (89%) rename OpenRA.Renderer.Null/OpenRA.Renderer.Null.csproj => OpenRA.Platforms.Null/OpenRA.Platforms.Null.csproj (91%) diff --git a/Makefile b/Makefile index 2cb90d01a4..5781604907 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ INSTALL_PROGRAM = $(INSTALL) -m755 INSTALL_DATA = $(INSTALL) -m644 # program targets -CORE = rsdl2 rnull game utility +CORE = pdefault pnull game utility TOOLS = gamemonitor VERSION = $(shell git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || echo git-`git rev-parse --short HEAD`) @@ -100,25 +100,25 @@ endif game_SRCS := $(shell find OpenRA.Game/ -iname '*.cs') game_TARGET = OpenRA.Game.exe game_KIND = winexe -game_LIBS = $(COMMON_LIBS) $(game_DEPS) thirdparty/download/SDL2-CS.dll thirdparty/download/SharpFont.dll +game_LIBS = $(COMMON_LIBS) $(game_DEPS) thirdparty/download/SharpFont.dll game_FLAGS = -win32icon:OpenRA.Game/OpenRA.ico PROGRAMS += game game: $(game_TARGET) -# Renderer dlls -rsdl2_SRCS := $(shell find OpenRA.Renderer.Sdl2/ -iname '*.cs') -rsdl2_TARGET = OpenRA.Renderer.Sdl2.dll -rsdl2_KIND = library -rsdl2_DEPS = $(game_TARGET) -rsdl2_LIBS = $(COMMON_LIBS) thirdparty/download/SDL2-CS.dll $(rsdl2_DEPS) +# Platform dlls +pdefault_SRCS := $(shell find OpenRA.Platforms.Default/ -iname '*.cs') +pdefault_TARGET = OpenRA.Platforms.Default.dll +pdefault_KIND = library +pdefault_DEPS = $(game_TARGET) +pdefault_LIBS = $(COMMON_LIBS) thirdparty/download/SDL2-CS.dll $(pdefault_DEPS) -rnull_SRCS := $(shell find OpenRA.Renderer.Null/ -iname '*.cs') -rnull_TARGET = OpenRA.Renderer.Null.dll -rnull_KIND = library -rnull_DEPS = $(game_TARGET) -rnull_LIBS = $(COMMON_LIBS) $(rnull_DEPS) -PROGRAMS += rsdl2 rnull -renderers: $(rsdl2_TARGET) $(rnull_TARGET) +pnull_SRCS := $(shell find OpenRA.Platforms.Null/ -iname '*.cs') +pnull_TARGET = OpenRA.Platforms.Null.dll +pnull_KIND = library +pnull_DEPS = $(game_TARGET) +pnull_LIBS = $(COMMON_LIBS) $(pnull_DEPS) +PROGRAMS += pdefault pnull +platforms: $(pdefault_TARGET) $(pnull_TARGET) # Mods Common mod_common_SRCS := $(shell find OpenRA.Mods.Common/ -iname '*.cs') @@ -181,8 +181,11 @@ check: utility mods @echo "Checking for code style violations in OpenRA.Game..." @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Game @echo - @echo "Checking for code style violations in OpenRA.Renderer.Null..." - @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Renderer.Null + @echo "Checking for code style violations in OpenRA.Platforms.Default..." + @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Platforms.Default + @echo + @echo "Checking for code style violations in OpenRA.Platforms.Null..." + @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Platforms.Null @echo @echo "Checking for code style violations in OpenRA.GameMonitor..." @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.GameMonitor @@ -202,9 +205,6 @@ check: utility mods @echo "Checking for code style violations in OpenRA.Mods.TS..." @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Mods.TS @echo - @echo "Checking for code style violations in OpenRA.Renderer.Sdl2..." - @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Renderer.Sdl2 - @echo @echo "Checking for code style violations in OpenRA.Utility..." @mono --debug OpenRA.Utility.exe ra --check-code-style OpenRA.Utility @echo @@ -275,7 +275,7 @@ $(foreach prog,$(PROGRAMS),$(eval $(call BUILD_ASSEMBLY,$(prog)))) # default: core -core: game renderers mods utility +core: game platforms mods utility tools: gamemonitor diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 9088610862..a6a909b1c1 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -215,7 +215,7 @@ namespace OpenRA GeoIP.Initialize(); GlobalFileSystem.Mount(Platform.GameDir); // Needed to access shaders - var renderers = new[] { Settings.Graphics.Renderer, "Sdl2", null }; + var renderers = new[] { Settings.Graphics.Renderer, "Default", null }; foreach (var r in renderers) { if (r == null) @@ -234,18 +234,6 @@ namespace OpenRA } } - try - { - Sound.Create(Settings.Sound.Engine); - } - catch (Exception e) - { - Log.Write("sound", "{0}", e); - Console.WriteLine("Creating the sound engine failed. Fallback in place. Check sound.log for details."); - Settings.Sound.Engine = "Null"; - Sound.Create(Settings.Sound.Engine); - } - Console.WriteLine("Available mods:"); foreach (var mod in ModMetadata.AllMods) Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); @@ -287,7 +275,7 @@ namespace OpenRA Settings.Game.Mod = mod; Sound.StopVideo(); - Sound.Initialize(); + Sound.Initialize(Settings.Sound, Settings.Server); ModData = new ModData(mod, !Settings.Server.Dedicated); ModData.InitializeLoaders(); diff --git a/OpenRA.Game/Graphics/IGraphicsDevice.cs b/OpenRA.Game/Graphics/IGraphicsDevice.cs index 38bd38eb03..deb7ee4b48 100644 --- a/OpenRA.Game/Graphics/IGraphicsDevice.cs +++ b/OpenRA.Game/Graphics/IGraphicsDevice.cs @@ -15,11 +15,11 @@ using OpenRA.Graphics; namespace OpenRA { [AttributeUsage(AttributeTargets.Assembly)] - public sealed class RendererAttribute : Attribute + public sealed class PlatformAttribute : Attribute { public readonly Type Type; - public RendererAttribute(Type graphicsDeviceType) + public PlatformAttribute(Type graphicsDeviceType) { if (!typeof(IDeviceFactory).IsAssignableFrom(graphicsDeviceType)) throw new InvalidOperationException("Incorrect type in RendererAttribute"); @@ -29,7 +29,8 @@ namespace OpenRA public interface IDeviceFactory { - IGraphicsDevice Create(Size size, WindowMode windowMode); + IGraphicsDevice CreateGraphics(Size size, WindowMode windowMode); + ISoundEngine CreateSound(); } public interface IHardwareCursor : IDisposable { } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index b31585cea1..ad5a320dcc 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -84,10 +84,6 @@ ..\thirdparty\download\MaxMind.Db.dll False - - ..\thirdparty\download\SDL2-CS.dll - False - @@ -120,7 +116,6 @@ - @@ -228,8 +223,6 @@ - - @@ -249,6 +242,8 @@ + + @@ -298,7 +293,6 @@ - diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Renderer.cs similarity index 95% rename from OpenRA.Game/Graphics/Renderer.cs rename to OpenRA.Game/Renderer.cs index a67f409c52..2669b2db52 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Renderer.cs @@ -13,9 +13,10 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Reflection; +using OpenRA.Graphics; using OpenRA.Support; -namespace OpenRA.Graphics +namespace OpenRA { public sealed class Renderer : IDisposable { @@ -49,7 +50,7 @@ namespace OpenRA.Graphics var resolution = GetResolution(graphicSettings); var rendererName = serverSettings.Dedicated ? "Null" : graphicSettings.Renderer; - var rendererPath = Platform.ResolvePath(".", "OpenRA.Renderer." + rendererName + ".dll"); + var rendererPath = Platform.ResolvePath(".", "OpenRA.Platforms." + rendererName + ".dll"); Device = CreateDevice(Assembly.LoadFile(rendererPath), resolution.Width, resolution.Height, graphicSettings.Mode); @@ -79,12 +80,12 @@ namespace OpenRA.Graphics return new Size(size.X, size.Y); } - static IGraphicsDevice CreateDevice(Assembly rendererDll, int width, int height, WindowMode window) + static IGraphicsDevice CreateDevice(Assembly platformDll, int width, int height, WindowMode window) { - foreach (RendererAttribute r in rendererDll.GetCustomAttributes(typeof(RendererAttribute), false)) + foreach (PlatformAttribute r in platformDll.GetCustomAttributes(typeof(PlatformAttribute), false)) { var factory = (IDeviceFactory)r.Type.GetConstructor(Type.EmptyTypes).Invoke(null); - return factory.Create(new Size(width, height), window); + return factory.CreateGraphics(new Size(width, height), window); } throw new InvalidOperationException("Renderer DLL is missing RendererAttribute to tell us what type to use!"); diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 89c4cc5994..1a0542c396 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -111,7 +111,7 @@ namespace OpenRA public class GraphicSettings { - public string Renderer = "Sdl2"; + public string Renderer = "Default"; public WindowMode Mode = WindowMode.PseudoFullscreen; public int2 FullscreenSize = new int2(0, 0); public int2 WindowedSize = new int2(1024, 768); @@ -139,7 +139,7 @@ namespace OpenRA public bool Shuffle = false; public bool Repeat = false; - public string Engine = "AL"; + public string Engine = "Default"; public string Device = null; public bool CashTicks = true; diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index 2dfa54b18b..36892ba311 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -11,13 +11,12 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using OpenRA.FileFormats; using OpenRA.FileSystem; using OpenRA.GameRules; using OpenRA.Primitives; using OpenRA.Traits; -using OpenTK; -using OpenTK.Audio.OpenAL; namespace OpenRA { @@ -30,6 +29,17 @@ namespace OpenRA static ISound video; static MusicInfo currentMusic; + static ISoundEngine CreateDevice(Assembly platformDll) + { + foreach (PlatformAttribute r in platformDll.GetCustomAttributes(typeof(PlatformAttribute), false)) + { + var factory = (IDeviceFactory)r.Type.GetConstructor(Type.EmptyTypes).Invoke(null); + return factory.CreateSound(); + } + + throw new InvalidOperationException("Platform DLL is missing PlatformAttribute to tell us what type to use!"); + } + static ISoundSource LoadSound(string filename) { if (!GlobalFileSystem.Exists(filename)) @@ -56,26 +66,12 @@ namespace OpenRA return soundEngine.AddSoundSourceFromMemory(rawData, channels, sampleBits, sampleRate); } - static ISoundEngine CreateEngine(string engine) + public static void Initialize(SoundSettings soundSettings, ServerSettings serverSettings) { - engine = Game.Settings.Server.Dedicated ? "Null" : engine; - switch (engine) - { - case "AL": return new OpenAlSoundEngine(); - case "Null": return new NullSoundEngine(); + var engineName = serverSettings.Dedicated ? "Null" : soundSettings.Engine; + var enginePath = Platform.ResolvePath(".", "OpenRA.Platforms." + engineName + ".dll"); + soundEngine = CreateDevice(Assembly.LoadFile(enginePath)); - default: - throw new InvalidOperationException("Unsupported sound engine: {0}".F(engine)); - } - } - - public static void Create(string engine) - { - soundEngine = CreateEngine(engine); - } - - public static void Initialize() - { sounds = new Cache(LoadSound); music = null; currentMusic = null; @@ -86,14 +82,11 @@ namespace OpenRA { var defaultDevices = new[] { - new SoundDevice("AL", null, "Default Output"), + new SoundDevice("Default", null, "Default Output"), new SoundDevice("Null", null, "Output Disabled") }; - var devices = OpenAlSoundEngine.AvailableDevices() - .Select(d => new SoundDevice("AL", d, d)); - - return defaultDevices.Concat(devices).ToArray(); + return defaultDevices.Concat(soundEngine.AvailableDevices()).ToArray(); } public static void SetListenerPosition(WPos position) diff --git a/OpenRA.Game/Sound/SoundDevice.cs b/OpenRA.Game/Sound/SoundDevice.cs index 78eced3b75..23bbf3dcdb 100644 --- a/OpenRA.Game/Sound/SoundDevice.cs +++ b/OpenRA.Game/Sound/SoundDevice.cs @@ -8,10 +8,13 @@ */ #endregion +using System; + namespace OpenRA { - interface ISoundEngine + public interface ISoundEngine { + SoundDevice[] AvailableDevices(); ISoundSource AddSoundSourceFromMemory(byte[] data, int channels, int sampleBits, int sampleRate); ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume); float Volume { get; set; } @@ -41,7 +44,7 @@ namespace OpenRA } } - interface ISoundSource { } + public interface ISoundSource { } public interface ISound { diff --git a/OpenRA.Platforms.Default/DefaultPlatform.cs b/OpenRA.Platforms.Default/DefaultPlatform.cs new file mode 100644 index 0000000000..2471de12e8 --- /dev/null +++ b/OpenRA.Platforms.Default/DefaultPlatform.cs @@ -0,0 +1,32 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Drawing; +using System.Reflection; +using OpenRA; + +[assembly: Platform(typeof(OpenRA.Platforms.Default.DeviceFactory))] + +namespace OpenRA.Platforms.Default +{ + public class DeviceFactory : IDeviceFactory + { + public IGraphicsDevice CreateGraphics(Size size, WindowMode windowMode) + { + return new Sdl2GraphicsDevice(size, windowMode); + } + + public ISoundEngine CreateSound() + { + return new OpenAlSoundEngine(); + } + } +} diff --git a/OpenRA.Renderer.Sdl2/ErrorHandler.cs b/OpenRA.Platforms.Default/ErrorHandler.cs similarity index 86% rename from OpenRA.Renderer.Sdl2/ErrorHandler.cs rename to OpenRA.Platforms.Default/ErrorHandler.cs index bc1a093c6d..97e6389ef3 100644 --- a/OpenRA.Renderer.Sdl2/ErrorHandler.cs +++ b/OpenRA.Platforms.Default/ErrorHandler.cs @@ -1,18 +1,18 @@ #region Copyright & License Information /* -* Copyright 2007-2015 The OpenRA Developers (see AUTHORS) -* This file is part of OpenRA, which is free software. It is made -* available to you under the terms of the GNU General Public License -* as published by the Free Software Foundation. For more information, -* see COPYING. -*/ + * Copyright 2007-2015 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ #endregion using System; using System.Diagnostics; using OpenTK.Graphics.OpenGL; -namespace OpenRA.Renderer.Sdl2 +namespace OpenRA.Platforms.Default { public static class ErrorHandler { diff --git a/OpenRA.Renderer.Sdl2/FrameBuffer.cs b/OpenRA.Platforms.Default/FrameBuffer.cs similarity index 99% rename from OpenRA.Renderer.Sdl2/FrameBuffer.cs rename to OpenRA.Platforms.Default/FrameBuffer.cs index 6b0a182c8a..d73625899d 100644 --- a/OpenRA.Renderer.Sdl2/FrameBuffer.cs +++ b/OpenRA.Platforms.Default/FrameBuffer.cs @@ -14,7 +14,7 @@ using System.Drawing; using System.IO; using OpenTK.Graphics.OpenGL; -namespace OpenRA.Renderer.Sdl2 +namespace OpenRA.Platforms.Default { public sealed class FrameBuffer : IFrameBuffer { diff --git a/OpenRA.Renderer.Sdl2/MultiTapDetection.cs b/OpenRA.Platforms.Default/MultiTapDetection.cs similarity index 98% rename from OpenRA.Renderer.Sdl2/MultiTapDetection.cs rename to OpenRA.Platforms.Default/MultiTapDetection.cs index 4948bcb75b..6ff6f9f918 100644 --- a/OpenRA.Renderer.Sdl2/MultiTapDetection.cs +++ b/OpenRA.Platforms.Default/MultiTapDetection.cs @@ -11,7 +11,7 @@ using System; using OpenRA.Primitives; -namespace OpenRA.Renderer.Sdl2 +namespace OpenRA.Platforms.Default { public static class MultiTapDetection { diff --git a/OpenRA.Game/Sound/OpenAlSound.cs b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs similarity index 95% rename from OpenRA.Game/Sound/OpenAlSound.cs rename to OpenRA.Platforms.Default/OpenAlSoundEngine.cs index 6d57ae102c..fc8fed488d 100644 --- a/OpenRA.Game/Sound/OpenAlSound.cs +++ b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs @@ -19,10 +19,22 @@ using OpenRA.Traits; using OpenTK; using OpenTK.Audio.OpenAL; -namespace OpenRA +namespace OpenRA.Platforms.Default { class OpenAlSoundEngine : ISoundEngine { + public SoundDevice[] AvailableDevices() + { + var defaultDevices = new[] + { + new SoundDevice("Default", null, "Default Output"), + new SoundDevice("Null", null, "Output Disabled") + }; + + var physicalDevices = PhysicalDevices().Select(d => new SoundDevice("Default", d, d)); + return defaultDevices.Concat(physicalDevices).ToArray(); + } + class PoolSlot { public bool IsActive; @@ -55,7 +67,7 @@ namespace OpenRA return devices; } - public static string[] AvailableDevices() + static string[] PhysicalDevices() { // Returns all devices under Windows Vista and newer if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATE_ALL_EXT")) @@ -148,7 +160,7 @@ namespace OpenRA return null; } - var currFrame = Game.OrderManager.LocalFrameNumber; + var currFrame = Game.LocalTick; var atten = 1f; // Check if max # of instances-per-location reached: diff --git a/OpenRA.Renderer.Sdl2/OpenRA.Renderer.Sdl2.csproj b/OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj similarity index 87% rename from OpenRA.Renderer.Sdl2/OpenRA.Renderer.Sdl2.csproj rename to OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj index bf9f44a3b1..eb3f1b58d7 100644 --- a/OpenRA.Renderer.Sdl2/OpenRA.Renderer.Sdl2.csproj +++ b/OpenRA.Platforms.Default/OpenRA.Platforms.Default.csproj @@ -7,8 +7,8 @@ 2.0 {33D03738-C154-4028-8EA8-63A3C488A651} Library - OpenRA.Renderer.Sdl2 - OpenRA.Renderer.Sdl2 + OpenRA.Platforms.Default + OpenRA.Platforms.Default true @@ -34,20 +34,24 @@ + + ..\thirdparty\download\Eluant.dll + ..\thirdparty\download\SDL2-CS.dll - False - + + + diff --git a/OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs b/OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs similarity index 94% rename from OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs rename to OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs index 1fa8cfd985..77888e44fb 100644 --- a/OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs +++ b/OpenRA.Platforms.Default/Sdl2GraphicsDevice.cs @@ -1,11 +1,11 @@ #region Copyright & License Information /* -* Copyright 2007-2015 The OpenRA Developers (see AUTHORS) -* This file is part of OpenRA, which is free software. It is made -* available to you under the terms of the GNU General Public License -* as published by the Free Software Foundation. For more information, -* see COPYING. -*/ + * Copyright 2007-2015 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ #endregion using System; @@ -14,22 +14,12 @@ using System.IO; using System.Runtime.InteropServices; using OpenRA; using OpenRA.Graphics; +using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; using SDL2; -[assembly: Renderer(typeof(OpenRA.Renderer.Sdl2.DeviceFactory))] - -namespace OpenRA.Renderer.Sdl2 +namespace OpenRA.Platforms.Default { - public class DeviceFactory : IDeviceFactory - { - public IGraphicsDevice Create(Size size, WindowMode windowMode) - { - Console.WriteLine("Using SDL 2 with OpenGL renderer"); - return new Sdl2GraphicsDevice(size, windowMode); - } - } - public sealed class Sdl2GraphicsDevice : IGraphicsDevice { Size size; @@ -41,6 +31,8 @@ namespace OpenRA.Renderer.Sdl2 public Sdl2GraphicsDevice(Size windowSize, WindowMode windowMode) { + Console.WriteLine("Using SDL 2 with OpenGL renderer"); + size = windowSize; SDL.SDL_Init(SDL.SDL_INIT_NOPARACHUTE | SDL.SDL_INIT_VIDEO); @@ -84,6 +76,7 @@ namespace OpenRA.Renderer.Sdl2 context = SDL.SDL_GL_CreateContext(window); SDL.SDL_GL_MakeCurrent(window, context); + GL.LoadAll(); ErrorHandler.CheckGlVersion(); ErrorHandler.CheckGlError(); diff --git a/OpenRA.Renderer.Sdl2/Sdl2Input.cs b/OpenRA.Platforms.Default/Sdl2Input.cs similarity index 99% rename from OpenRA.Renderer.Sdl2/Sdl2Input.cs rename to OpenRA.Platforms.Default/Sdl2Input.cs index 757b310b63..44ccd0c7ac 100644 --- a/OpenRA.Renderer.Sdl2/Sdl2Input.cs +++ b/OpenRA.Platforms.Default/Sdl2Input.cs @@ -13,7 +13,7 @@ using System.Runtime.InteropServices; using System.Text; using SDL2; -namespace OpenRA.Renderer.Sdl2 +namespace OpenRA.Platforms.Default { public class Sdl2Input { diff --git a/OpenRA.Renderer.Sdl2/Shader.cs b/OpenRA.Platforms.Default/Shader.cs similarity index 99% rename from OpenRA.Renderer.Sdl2/Shader.cs rename to OpenRA.Platforms.Default/Shader.cs index 4c4edc9152..6e24a9692d 100644 --- a/OpenRA.Renderer.Sdl2/Shader.cs +++ b/OpenRA.Platforms.Default/Shader.cs @@ -15,7 +15,7 @@ using System.Text; using OpenRA.FileSystem; using OpenTK.Graphics.OpenGL; -namespace OpenRA.Renderer.Sdl2 +namespace OpenRA.Platforms.Default { public class Shader : IShader { diff --git a/OpenRA.Renderer.Sdl2/Texture.cs b/OpenRA.Platforms.Default/Texture.cs similarity index 99% rename from OpenRA.Renderer.Sdl2/Texture.cs rename to OpenRA.Platforms.Default/Texture.cs index 4f774bba2a..62946b0d96 100644 --- a/OpenRA.Renderer.Sdl2/Texture.cs +++ b/OpenRA.Platforms.Default/Texture.cs @@ -14,7 +14,7 @@ using System.Drawing.Imaging; using System.IO; using OpenTK.Graphics.OpenGL; -namespace OpenRA.Renderer.Sdl2 +namespace OpenRA.Platforms.Default { public sealed class Texture : ITexture { diff --git a/OpenRA.Renderer.Sdl2/VertexBuffer.cs b/OpenRA.Platforms.Default/VertexBuffer.cs similarity index 98% rename from OpenRA.Renderer.Sdl2/VertexBuffer.cs rename to OpenRA.Platforms.Default/VertexBuffer.cs index c4445504fd..8a7783aa94 100644 --- a/OpenRA.Renderer.Sdl2/VertexBuffer.cs +++ b/OpenRA.Platforms.Default/VertexBuffer.cs @@ -12,7 +12,7 @@ using System; using System.Runtime.InteropServices; using OpenTK.Graphics.OpenGL; -namespace OpenRA.Renderer.Sdl2 +namespace OpenRA.Platforms.Default { public sealed class VertexBuffer : IVertexBuffer where T : struct diff --git a/OpenRA.Renderer.Null/NullGraphicsDevice.cs b/OpenRA.Platforms.Null/NullGraphicsDevice.cs similarity index 91% rename from OpenRA.Renderer.Null/NullGraphicsDevice.cs rename to OpenRA.Platforms.Null/NullGraphicsDevice.cs index 24d1a2f753..e351859415 100644 --- a/OpenRA.Renderer.Null/NullGraphicsDevice.cs +++ b/OpenRA.Platforms.Null/NullGraphicsDevice.cs @@ -10,21 +10,10 @@ using System; using System.Drawing; -using OpenRA; using OpenRA.Graphics; -[assembly: Renderer(typeof(OpenRA.Renderer.Null.DeviceFactory))] - -namespace OpenRA.Renderer.Null +namespace OpenRA.Platforms.Null { - public class DeviceFactory : IDeviceFactory - { - public IGraphicsDevice Create(Size size, WindowMode windowMode) - { - return new NullGraphicsDevice(size, windowMode); - } - } - public sealed class NullGraphicsDevice : IGraphicsDevice { public Size WindowSize { get; internal set; } diff --git a/OpenRA.Platforms.Null/NullPlatform.cs b/OpenRA.Platforms.Null/NullPlatform.cs new file mode 100644 index 0000000000..93a08bce3a --- /dev/null +++ b/OpenRA.Platforms.Null/NullPlatform.cs @@ -0,0 +1,31 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Drawing; +using OpenRA; + +[assembly: Platform(typeof(OpenRA.Platforms.Null.DeviceFactory))] + +namespace OpenRA.Platforms.Null +{ + public class DeviceFactory : IDeviceFactory + { + public IGraphicsDevice CreateGraphics(Size size, WindowMode windowMode) + { + return new NullGraphicsDevice(size, windowMode); + } + + public ISoundEngine CreateSound() + { + return new NullSoundEngine(); + } + } +} diff --git a/OpenRA.Game/Sound/NullSound.cs b/OpenRA.Platforms.Null/NullSound.cs similarity index 89% rename from OpenRA.Game/Sound/NullSound.cs rename to OpenRA.Platforms.Null/NullSound.cs index 46b6d38acb..41fe831415 100644 --- a/OpenRA.Game/Sound/NullSound.cs +++ b/OpenRA.Platforms.Null/NullSound.cs @@ -10,10 +10,15 @@ using System; -namespace OpenRA +namespace OpenRA.Platforms.Null { class NullSoundEngine : ISoundEngine { + public SoundDevice[] AvailableDevices() + { + return new[] { new SoundDevice("Null", null, "Output Disabled") }; + } + public NullSoundEngine() { Console.WriteLine("Using Null sound engine which disables SFX completely"); diff --git a/OpenRA.Renderer.Null/OpenRA.Renderer.Null.csproj b/OpenRA.Platforms.Null/OpenRA.Platforms.Null.csproj similarity index 91% rename from OpenRA.Renderer.Null/OpenRA.Renderer.Null.csproj rename to OpenRA.Platforms.Null/OpenRA.Platforms.Null.csproj index 19d970f218..56d84e16a0 100644 --- a/OpenRA.Renderer.Null/OpenRA.Renderer.Null.csproj +++ b/OpenRA.Platforms.Null/OpenRA.Platforms.Null.csproj @@ -8,11 +8,10 @@ {0C4AEC1A-E7D5-4114-8CCD-3EEC82872981} Library Properties - OpenRA.Renderer.Null - OpenRA.Renderer.Null + OpenRA.Platforms.Null + OpenRA.Platforms.Null 512 - - + 3.5 publish\ @@ -55,9 +54,14 @@ + + ..\thirdparty\download\Eluant.dll + + + diff --git a/OpenRA.sln b/OpenRA.sln index 17e2c38042..79124b7d44 100644 --- a/OpenRA.sln +++ b/OpenRA.sln @@ -11,13 +11,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Mods.Cnc", "OpenRA.M EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Utility", "OpenRA.Utility\OpenRA.Utility.csproj", "{F33337BE-CB69-4B24-850F-07D23E408DDF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Renderer.Null", "OpenRA.Renderer.Null\OpenRA.Renderer.Null.csproj", "{0C4AEC1A-E7D5-4114-8CCD-3EEC82872981}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Platforms.Null", "OpenRA.Platforms.Null\OpenRA.Platforms.Null.csproj", "{0C4AEC1A-E7D5-4114-8CCD-3EEC82872981}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Mods.D2k", "OpenRA.Mods.D2k\OpenRA.Mods.D2k.csproj", "{C0B0465C-6BE2-409C-8770-3A9BF64C4344}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Mods.TS", "OpenRA.Mods.TS\OpenRA.Mods.TS.csproj", "{5457CBF5-4CE4-421E-A8BF-9FD6C9732E1D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Renderer.Sdl2", "OpenRA.Renderer.Sdl2\OpenRA.Renderer.Sdl2.csproj", "{33D03738-C154-4028-8EA8-63A3C488A651}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Platforms.Default", "OpenRA.Platforms.Default\OpenRA.Platforms.Default.csproj", "{33D03738-C154-4028-8EA8-63A3C488A651}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Mods.Common", "OpenRA.Mods.Common\OpenRA.Mods.Common.csproj", "{FE6C8CC0-2F07-442A-B29F-17617B3B7FC6}" EndProject diff --git a/make.ps1 b/make.ps1 index e1267e583e..dfcdd8a7bc 100644 --- a/make.ps1 +++ b/make.ps1 @@ -150,8 +150,10 @@ elseif ($command -eq "check") { if (Test-Path OpenRA.Utility.exe) { - echo "Checking for code style violations in OpenRA.Renderer.Null..." - ./OpenRA.Utility.exe ra --check-code-style OpenRA.Renderer.Null + echo "Checking for code style violations in OpenRA.Platforms.Default..." + ./OpenRA.Utility.exe cnc --check-code-style OpenRA.Platforms.Default + echo "Checking for code style violations in OpenRA.Platforms.Null..." + ./OpenRA.Utility.exe ra --check-code-style OpenRA.Platforms.Null echo "Checking for code style violations in OpenRA.GameMonitor..." ./OpenRA.Utility.exe ra --check-code-style OpenRA.GameMonitor echo "Checking for code style violations in OpenRA.Game..." @@ -166,8 +168,6 @@ elseif ($command -eq "check") ./OpenRA.Utility.exe cnc --check-code-style OpenRA.Mods.D2k echo "Checking for code style violations in OpenRA.Mods.TS..." ./OpenRA.Utility.exe cnc --check-code-style OpenRA.Mods.TS - echo "Checking for code style violations in OpenRA.Renderer.Sdl2..." - ./OpenRA.Utility.exe cnc --check-code-style OpenRA.Renderer.Sdl2 echo "Checking for code style violations in OpenRA.Utility..." ./OpenRA.Utility.exe cnc --check-code-style OpenRA.Utility echo "Checking for code style violations in OpenRA.Test..." diff --git a/packaging/package-all.sh b/packaging/package-all.sh index 11ffa35bf4..a331836d76 100755 --- a/packaging/package-all.sh +++ b/packaging/package-all.sh @@ -32,7 +32,7 @@ markdown Lua-API.md > Lua-API.html # List of files that are packaged on all platforms FILES=('OpenRA.Game.exe' 'OpenRA.Game.exe.config' 'OpenRA.Utility.exe' \ -'OpenRA.Renderer.Sdl2.dll' 'OpenRA.Renderer.Null.dll' \ +'OpenRA.Platforms.Default.dll' 'OpenRA.Platforms.Null.dll' \ 'lua' 'glsl' 'mods/common' 'mods/ra' 'mods/cnc' 'mods/d2k' 'mods/modchooser' \ 'AUTHORS' 'COPYING' 'README.html' 'CONTRIBUTING.html' 'DOCUMENTATION.html' 'CHANGELOG.html' \ 'global mix database.dat' 'GeoLite2-Country.mmdb.gz') diff --git a/packaging/windows/OpenRA.nsi b/packaging/windows/OpenRA.nsi index 2c5f5d1166..93c97928fa 100644 --- a/packaging/windows/OpenRA.nsi +++ b/packaging/windows/OpenRA.nsi @@ -83,8 +83,8 @@ Section "Game" GAME File "${SRCDIR}\OpenRA.Game.exe" File "${SRCDIR}\OpenRA.Game.exe.config" File "${SRCDIR}\OpenRA.Utility.exe" - File "${SRCDIR}\OpenRA.Renderer.Null.dll" - File "${SRCDIR}\OpenRA.Renderer.Sdl2.dll" + File "${SRCDIR}\OpenRA.Platforms.Null.dll" + File "${SRCDIR}\OpenRA.Platforms.Default.dll" File "${SRCDIR}\ICSharpCode.SharpZipLib.dll" File "${SRCDIR}\FuzzyLogicLibrary.dll" File "${SRCDIR}\Mono.Nat.dll" @@ -188,8 +188,8 @@ Function ${UN}Clean Delete $INSTDIR\OpenRA.Game.exe Delete $INSTDIR\OpenRA.Game.exe.config Delete $INSTDIR\OpenRA.Utility.exe - Delete $INSTDIR\OpenRA.Renderer.Null.dll - Delete $INSTDIR\OpenRA.Renderer.Sdl2.dll + Delete $INSTDIR\OpenRA.Platforms.Null.dll + Delete $INSTDIR\OpenRA.Platforms.Default.dll Delete $INSTDIR\ICSharpCode.SharpZipLib.dll Delete $INSTDIR\FuzzyLogicLibrary.dll Delete $INSTDIR\Mono.Nat.dll