Skip to content

Commit

Permalink
First refactor milestone
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrdacor committed Mar 2, 2023
1 parent de6d1be commit 4b4a43b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 36 deletions.
5 changes: 3 additions & 2 deletions Ambermoon.Core/Render/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Ambermoon
{
public enum Layer
{
// Note: Don't add aliases here as this is used for enumerating over all layers.
None = -1,
Map3DBackground, // Color floor, sky, etc
Map3DCeiling,
Expand Down Expand Up @@ -66,13 +67,13 @@ public enum Layer
Cursor,
DrugEffect,
Misc, // general purpose layer
Images, // non-palette high-resolution images
Last = Images
Images // non-palette high-resolution images
}

public partial class Global
{
public const Layer First2DLayer = Layer.MapBackground1;
public const Layer Last2DLayer = Layer.MapForeground10;
public const Layer LastLayer = Layer.Images;
}
}
5 changes: 4 additions & 1 deletion Ambermoon.Renderer.OpenGL/AlphaTextureShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ internal class AlphaTextureShader : TextureShader
$"flat in float maskColIndex;",
$"flat in float a;",
$"",
$" vec4 pixelColor;",
$"void main()",
$"{{",
$" vec4 pixelColor = vec4(0);",
$" if ({DefaultUsePaletteName} > 0.5f)",
$" {{",
$" float colorIndex = texture({DefaultSamplerName}, varTexCoord).r * 255.0f;",
Expand All @@ -61,6 +63,7 @@ internal class AlphaTextureShader : TextureShader
$" if (maskColIndex > 0.5f)",
$" pixelColor = texture({DefaultPaletteName}, vec2((maskColIndex + 0.5f) / 32.0f, (palIndex + 0.5f) / {Shader.PaletteCount}));",
$" {DefaultFragmentOutColorName} = vec4(pixelColor.rgb, pixelColor.a * a);",
$"}}"
};

protected static string[] AlphaTextureVertexShader(State state) => new string[]
Expand Down
2 changes: 1 addition & 1 deletion Ambermoon.Renderer.OpenGL/RenderView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public void Render(FloatPosition viewportOffset)
set2DViewport = true;
}

if (useEffectFrameBuffer && layer.Key == Layer.Last)
if (useEffectFrameBuffer && layer.Key == Global.LastLayer)
{
State.Gl.BindFramebuffer(FramebufferTarget.Framebuffer, 0u);
var viewport = frameBufferWindowArea;
Expand Down
2 changes: 1 addition & 1 deletion Ambermoon.Renderer.OpenGL/TextShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class TextShader : TextureShader
$" }}",
$" else",
$" {{",
$" vec4 pixelColor = texture({DefaultSamplerName}, varTexCoor);",
$" vec4 pixelColor = texture({DefaultSamplerName}, varTexCoord);",
$" if (pixelColor.a < 0.5f)",
$" discard;",
$" else",
Expand Down
4 changes: 2 additions & 2 deletions Ambermoon.Renderer.OpenGL/TextureShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal class TextureShader : ColorShader
$"",
$"void main()",
$"{{",
$" vec4 pixelColor;",
$" vec4 pixelColor = vec4(0);",
$" if ({DefaultUsePaletteName} > 0.5f)",
$" {{",
$" float colorIndex = texture({DefaultSamplerName}, varTexCoord).r * 255.0f;",
Expand Down Expand Up @@ -119,7 +119,7 @@ protected TextureShader(State state, string[] fragmentShaderLines, string[] vert

public void UsePalette(bool use)
{
shaderProgram.SetInput(DefaultPaletteName, use ? 1.0f : 0.0f);
shaderProgram.SetInput(DefaultUsePaletteName, use ? 1.0f : 0.0f);
}

public void SetSampler(int textureUnit = 0)
Expand Down
7 changes: 4 additions & 3 deletions Ambermoon.net/FantasyIntro.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ambermoon.Data.Legacy.Serialization;
using Ambermoon.Data;
using Ambermoon.Data.Legacy.Serialization;
using Ambermoon.Render;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -30,7 +31,7 @@ internal class FantasyIntro
bool playFairyAnimation = false;
uint fairyAnimationIndex = 0;

static void EnsureTextures(IRenderView renderView, FantasyIntroData fantasyIntroData)
static void EnsureTextures(IRenderView renderView, IFantasyIntroData fantasyIntroData)
{
if (textureAtlas == null)
{
Expand All @@ -41,7 +42,7 @@ static void EnsureTextures(IRenderView renderView, FantasyIntroData fantasyIntro
}
}

public FantasyIntro(IRenderView renderView, FantasyIntroData fantasyIntroData, Action finishAction)
public FantasyIntro(IRenderView renderView, IFantasyIntroData fantasyIntroData, Action finishAction)
{
this.finishAction = finishAction;
this.renderView = renderView;
Expand Down
27 changes: 9 additions & 18 deletions Ambermoon.net/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,23 +689,19 @@ void PlayMusic(Song song)
void StartGame(IGameData gameData, string savePath, GameLanguage gameLanguage, Features features, BinaryReader advancedDiffsReader)
{
// Load fantasy intro data
var fantasyIntroData = new FantasyIntroData(gameData);
var fantasyIntroData = gameData.FantasyIntroData;

// Load intro data
var introData = new IntroData(gameData);
var introData = gameData.IntroData;
var introFont = new Font(Resources.IntroFont, 12);

// Load outro data
var outroData = new OutroData(gameData);
var outroData = gameData.OutroData;
var outroFont = new Font(outroData.Glyphs, 6, 0);
var outroFontLarge = new Font(outroData.LargeGlyphs, 10, (uint)outroData.Glyphs.Count);

// Load game data
var additionalPalettes = new List<Graphic>();
additionalPalettes.AddRange(introData.IntroPalettes);
additionalPalettes.AddRange(outroData.OutroPalettes);
additionalPalettes.AddRange(fantasyIntroData.FantasyIntroPalettes);
var graphicProvider = gameData.GetGraphicProvider(additionalPalettes);
var graphicProvider = gameData.GraphicProvider;

if (audioOutput == null)
{
Expand Down Expand Up @@ -757,7 +753,6 @@ void StartGame(IGameData gameData, string savePath, GameLanguage gameLanguage, F
{
try
{
var textDictionary = TextDictionary.Load(new TextDictionaryReader(), gameData.GetDictionary());
var savegameManager = new SavegameManager(savePath);
savegameManager.GetSavegameNames(gameData, out int currentSavegame, 10);
if (currentSavegame == 0 && configuration.ExtendedSavegameSlots)
Expand All @@ -776,8 +771,8 @@ void SetupGameCreator(bool continueGame)
gameCreator = () =>
{
var game = new Game(configuration, gameLanguage, renderView, graphicProvider,
savegameManager, savegameSerializer, textDictionary, cursor, audioOutput, musicManager,
FullscreenChangeRequest, ChangeResolution, QueryPressedKeys,
savegameManager, savegameSerializer, gameData.Dictionary, cursor, audioOutput,
musicManager, FullscreenChangeRequest, ChangeResolution, QueryPressedKeys,
new OutroFactory(renderView, outroData, outroFont, outroFontLarge), features);
game.QuitRequested += window.Close;
game.MousePositionChanged += position =>
Expand Down Expand Up @@ -1013,11 +1008,8 @@ GameData LoadGameDataFromDataPath()
builtinVersionDataProviders[1] = () => configuration.GameVersionIndex == 1 ? gameData : LoadBuiltinVersionData(versions[1], builtinVersionDataProviders[0]);
builtinVersionDataProviders[2] = () => configuration.GameVersionIndex == 2 ? gameData : LoadBuiltinVersionData(versions[2], null);
builtinVersionDataProviders[3] = () => configuration.GameVersionIndex == 3 ? gameData : LoadBuiltinVersionData(versions[3], builtinVersionDataProviders[2]);
var executableData = ExecutableData.FromGameData(gameData);
var graphicProvider = new GraphicProvider(gameData, executableData, null, null, null);
var textureAtlasManager = TextureAtlasManager.CreateEmpty();
createdTextureAtlasManager = textureAtlasManager;
var fontProvider = new FontProvider(executableData);

audioOutput = new AudioOutput();
audioOutput.Volume = Util.Limit(0, configuration.Volume, 100) / 100.0f;
Expand All @@ -1032,9 +1024,9 @@ GameData LoadGameDataFromDataPath()
logoPalettes = new Graphic[1] { new Graphic { Width = 32, Height = 1, IndexedGraphic = false, Data = new byte[32 * 4] } };
}

renderView = CreateRenderView(gameData, configuration, graphicProvider, logoPalettes, () =>
renderView = CreateRenderView(gameData, configuration, gameData.GraphicProvider, logoPalettes, () =>
{
textureAtlasManager.AddUIOnly(graphicProvider, fontProvider);
textureAtlasManager.AddUIOnly(gameData.GraphicProvider, gameData.FontProvider);
logoPyrdacor?.Initialize(textureAtlasManager);
AdvancedLogo.Initialize(textureAtlasManager);
return textureAtlasManager;
Expand Down Expand Up @@ -1065,8 +1057,7 @@ GameData LoadGameDataFromDataPath()
Features = additionalVersionInfo.Value.Advanced ? Features.AmbermoonAdvanced : Features.None
});
}
var cursor = new Render.Cursor(renderView, executableData.Cursors.Entries.Select(c => new Position(c.HotspotX, c.HotspotY)).ToList().AsReadOnly(),
textureAtlasManager);
var cursor = new Render.Cursor(renderView, gameData.CursorHotspots, textureAtlasManager);

RunTask(() =>
{
Expand Down
6 changes: 3 additions & 3 deletions Ambermoon.net/MainMenu.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Ambermoon.Data.Enumerations;
using Ambermoon.Data.Legacy.Serialization;
using Ambermoon.Data;
using Ambermoon.Data.Enumerations;
using Ambermoon.Render;
using System;
using System.Collections.Generic;
Expand All @@ -26,7 +26,7 @@ public enum CloseAction
Fader fader;
Fader mainMenuFader;
UI.UIText loadingText;
List<KeyValuePair<Rect, Text>> mainMenuTexts = new List<KeyValuePair<Rect, Text>>(4);
List<KeyValuePair<Rect, Text>> mainMenuTexts = new(4);
int hoveredTextIndex = -1;
DateTime? hoverStartTime = null;
const int HoverColorTime = 125;
Expand Down
10 changes: 5 additions & 5 deletions Ambermoon.net/Outro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class Outro : IOutro
{
static ITextureAtlas textureAtlas = null;
readonly Action finishAction;
readonly OutroData outroData;
readonly IOutroData outroData;
readonly Font outroFont;
readonly Font outroFontLarge;
readonly IRenderView renderView;
Expand All @@ -34,7 +34,7 @@ internal class Outro : IOutro
long fadeStartTicks = 0;
const long HalfFadeDurationInTicks = 3 * Game.TicksPerSecond / 4;

static void EnsureTextures(IRenderView renderView, OutroData outroData, Font outroFont, Font outroFontLarge)
static void EnsureTextures(IRenderView renderView, IOutroData outroData, Font outroFont, Font outroFontLarge)
{
if (textureAtlas == null)
{
Expand All @@ -48,7 +48,7 @@ static void EnsureTextures(IRenderView renderView, OutroData outroData, Font out
}
}

public Outro(IRenderView renderView, OutroData outroData, Font outroFont, Font outroFontLarge, Action finishAction)
public Outro(IRenderView renderView, IOutroData outroData, Font outroFont, Font outroFontLarge, Action finishAction)
{
this.finishAction = finishAction;
this.outroData = outroData;
Expand Down Expand Up @@ -305,11 +305,11 @@ public void Destroy()
internal class OutroFactory : IOutroFactory
{
readonly IRenderView renderView;
readonly OutroData outroData;
readonly IOutroData outroData;
readonly Font outroFont;
readonly Font outroFontLarge;

public OutroFactory(IRenderView renderView, OutroData outroData, Font outroFont, Font outroFontLarge)
public OutroFactory(IRenderView renderView, IOutroData outroData, Font outroFont, Font outroFontLarge)
{
this.renderView = renderView;
this.outroData = outroData;
Expand Down

0 comments on commit 4b4a43b

Please sign in to comment.