Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Behavior/DotRPG.Behavior.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<FileVersion>1.3.6.0</FileVersion>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Routines\**" />
<EmbeddedResource Remove="Routines\**" />
<None Remove="Routines\**" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Objects\DotRPG.Objects.csproj" />
</ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions Behavior/Routines/DotRPG.Behavior.Routines.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Product>DotRPG</Product>
<Company>red-the-random-dev</Company>
<Authors>red-the-random-dev</Authors>
<AssemblyVersion>1.3.6.0</AssemblyVersion>
<FileVersion>1.3.6.0</FileVersion>
</PropertyGroup>

</Project>
52 changes: 52 additions & 0 deletions Behavior/Routines/FrameLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace DotRPG.Behavior.Routines
{
public class FrameLoader
{
public ILoadable Loaded;

public Single LoadPercentage
{
get
{
if (Loaded.ContentTasks_Total + Loaded.ObjectTasks_Total == 0)
{
return Single.NaN;
}
return (Single)Math.Round((100.0m * Loaded.ContentTasks_Done + Loaded.ObjectTasks_Done) / (Loaded.ContentTasks_Total + Loaded.ObjectTasks_Total), 1);
}
}

public void Update()
{
if (Loaded.Loaded)
{
return;
}
else if (!Loaded.ReadyForLoad)
{
Loaded.PreloadTask();
}
else if (Loaded.ContentTasks_Done < Loaded.ContentTasks_Total)
{
Loaded.PerformContentTask();
}
else if (Loaded.ObjectTasks_Done < Loaded.ObjectTasks_Total)
{
Loaded.PerformObjectTask();
}
else
{
Loaded.PostLoadTask();
}
}
public FrameLoader(ILoadable il)
{
Loaded = il;
}
}
}
25 changes: 25 additions & 0 deletions Behavior/Routines/ILoadable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace DotRPG.Behavior.Routines
{
public interface ILoadable
{
public Boolean ReadyForLoad { get; }
public Boolean Loaded { get; }
public Int32 ContentTasks_Total { get; }
public Int32 ObjectTasks_Total { get; }
public Int32 ContentTasks_Done { get; }
public Int32 ObjectTasks_Done { get; }
// Do single task per call
public void PerformContentTask();
public void PerformObjectTask();

public Boolean SupportsMultiLoading { get; }
// Do multiple tasks at once
public void PerformContentTasks(Int32 step);
public void PerformObjectTasks(Int32 step);

public void PreloadTask();
public void PostLoadTask();
}
}
8 changes: 7 additions & 1 deletion DotRPG.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotRPG.Scripting.Pipeline",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotRPG.Scripting", "Scripting\DotRPG.Scripting.csproj", "{610FDEAE-E1EB-475C-A095-2F337FBB5A2C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotRPG.Behavior", "Behavior\DotRPG.Behavior.csproj", "{7D48C09E-EDCF-4D41-9687-F32BC4F8DFC6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotRPG.Behavior", "Behavior\DotRPG.Behavior.csproj", "{7D48C09E-EDCF-4D41-9687-F32BC4F8DFC6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotRPG.Behavior.Routines", "Behavior\Routines\DotRPG.Behavior.Routines.csproj", "{67A8F31C-34A8-4DEC-9AB6-57F5A41018C7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -51,6 +53,10 @@ Global
{7D48C09E-EDCF-4D41-9687-F32BC4F8DFC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D48C09E-EDCF-4D41-9687-F32BC4F8DFC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D48C09E-EDCF-4D41-9687-F32BC4F8DFC6}.Release|Any CPU.Build.0 = Release|Any CPU
{67A8F31C-34A8-4DEC-9AB6-57F5A41018C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67A8F31C-34A8-4DEC-9AB6-57F5A41018C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67A8F31C-34A8-4DEC-9AB6-57F5A41018C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67A8F31C-34A8-4DEC-9AB6-57F5A41018C7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions _Example/DotRPG.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Behavior\DotRPG.Behavior.csproj" />
<ProjectReference Include="..\Behavior\Routines\DotRPG.Behavior.Routines.csproj" />
<ProjectReference Include="..\Objects\DotRPG.Objects.csproj" />
<ProjectReference Include="..\Objects\Dynamics\DotRPG.Objects.Dynamics.csproj" />
<ProjectReference Include="..\Scripting\DotRPG.Scripting.csproj" />
Expand Down
26 changes: 23 additions & 3 deletions _Example/Game1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Xml.Linq;
using System.IO;
using System.Reflection;
using DotRPG.Behavior.Routines;

namespace DotRPG._Example
{
Expand Down Expand Up @@ -166,10 +167,29 @@ protected override void Update(GameTime gameTime)
}
if (ActiveFrame != null)
{
if (ActiveFrame.FrameID == -128 && stageSelect.SelectedOption != -1)
if (ActiveFrame is LoadingScreen l)
{
ActiveFrame = Frames[stageSelect.SelectedOption];
ActiveFrame.LoadContent();
if (l.LoadedFrame.Loaded)
{
ActiveFrame = l.LoadedFrame as Frame;
}
if (ActiveFrame == null)
{
ActiveFrame = stageSelect;
}
}
else if (ActiveFrame.FrameID == -128 && stageSelect.SelectedOption != -1)
{
Frame toLoad = Frames[stageSelect.SelectedOption];
if (toLoad is ILoadable load)
{
ActiveFrame = new LoadingScreen(load, this, ResourceHGlobal, LogicEventSet);
}
else
{
ActiveFrame = toLoad;
ActiveFrame.LoadContent();
}
}
else if (ActiveFrame.FrameID != -128 && Keyboard.GetState().IsKeyDown(Keys.F2))
{
Expand Down
83 changes: 83 additions & 0 deletions _Example/LoadingScreen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Text;
using DotRPG.Behavior;
using DotRPG.Behavior.Routines;
using DotRPG.Behavior.Routines;
using DotRPG.Objects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace DotRPG._Example
{
class LoadingScreen : Frame
{
public FrameLoader Loader;
TextObject percentage;
public ILoadable LoadedFrame
{
get
{
return Loader.Loaded;
}
set
{
Loader = new FrameLoader(value);
}
}
public override int FrameID
{
get
{
return -129;
}
}
public LoadingScreen(ILoadable il, Game owner, ResourceHeap globalGameResources, HashSet<TimedEvent> globalEventSet) : base(owner, globalGameResources, globalEventSet)
{
Loader = new FrameLoader(il);
percentage = new TextObject(globalGameResources.Fonts["vcr_large"], "00.0%", 0.5f, 0.35f, Color.White, AlignMode.BottomCenter, 1080);
}
public override void SetPlayerPosition(object sender, EventArgs e, GameTime gameTime)
{
throw new NotImplementedException();
}
public override void Update(GameTime gameTime, bool[] controls)
{
Loader.Update();
percentage.Text = Loader.LoadPercentage.ToString() + "%";
base.Update(gameTime, controls);
}
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, Rectangle drawZone)
{
Vector2 v = new Vector2(drawZone.X + (drawZone.Width / 8), drawZone.Y + (drawZone.Height / 2));
Texture2D t1 = new Texture2D(spriteBatch.GraphicsDevice, drawZone.Width * 3 / 4, drawZone.Height / 20);
Texture2D t2 = new Texture2D(spriteBatch.GraphicsDevice, Math.Max(drawZone.Width * 3 / 4 * (Int32)Loader.LoadPercentage/100, 1), drawZone.Height / 20);

Color[] d1 = new Color[drawZone.Width * 3 / 4 * drawZone.Height / 20];
Color[] d2 = new Color[Math.Max(drawZone.Width * 3 / 4 * (Int32)Loader.LoadPercentage / 100, 1) * drawZone.Height / 20];

for (int i = 0; i < d1.Length; i++) d1[i] = Color.Gray;
for (int i = 0; i < d2.Length; i++) d2[i] = Color.White;

t1.SetData(d1);
t2.SetData(d2);

spriteBatch.Draw(t1, v, Color.White);
spriteBatch.Draw(t2, v, Color.White);

percentage.Draw(spriteBatch, Owner.Window);
}
public override void Initialize()
{

}
public override void LoadContent()
{

}
public override void UnloadContent()
{

}
}
}
Loading