Skip to content

Commit

Permalink
Some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerfulBacon committed May 12, 2024
1 parent 83d33e1 commit d70e2e3
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 101 deletions.
30 changes: 4 additions & 26 deletions CorgEng.Core/CorgEng.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CorgEng.Lighting", "..\Corg
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CorgEng.EntityQuery", "..\CorgEng.EntityQuery\CorgEng.EntityQuery.csproj", "{CD4E414F-536D-454B-8423-9631952EF705}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CorgEng.Functional", "..\CorgEng.Functional\CorgEng.Functional.csproj", "{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -215,8 +213,8 @@ Global
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM32.ActiveCfg = Debug|ARM32
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM32.Build.0 = Debug|ARM32
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM64.ActiveCfg = Debug|ARM64
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM64.Build.0 = Debug|ARM64
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|ARM64.Build.0 = Debug|Any CPU
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|x64.ActiveCfg = Debug|Any CPU
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|x64.Build.0 = Debug|Any CPU
{14E8A473-E0B8-4CB2-BA76-B322FA0EDADF}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -415,8 +413,8 @@ Global
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM32.ActiveCfg = Debug|ARM32
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM32.Build.0 = Debug|ARM32
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM64.ActiveCfg = Debug|ARM64
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM64.Build.0 = Debug|ARM64
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|ARM64.Build.0 = Debug|Any CPU
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|x64.ActiveCfg = Debug|Any CPU
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|x64.Build.0 = Debug|Any CPU
{EB32BAE1-083D-4ECC-9627-BC83B8300A40}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -651,26 +649,6 @@ Global
{CD4E414F-536D-454B-8423-9631952EF705}.Release|x64.Build.0 = Release|Any CPU
{CD4E414F-536D-454B-8423-9631952EF705}.Release|x86.ActiveCfg = Release|Any CPU
{CD4E414F-536D-454B-8423-9631952EF705}.Release|x86.Build.0 = Release|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|ARM32.ActiveCfg = Debug|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|ARM32.Build.0 = Debug|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|ARM64.Build.0 = Debug|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|x64.ActiveCfg = Debug|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|x64.Build.0 = Debug|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|x86.ActiveCfg = Debug|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Debug|x86.Build.0 = Debug|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|Any CPU.Build.0 = Release|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|ARM32.ActiveCfg = Release|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|ARM32.Build.0 = Release|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|ARM64.ActiveCfg = Release|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|ARM64.Build.0 = Release|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|x64.ActiveCfg = Release|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|x64.Build.0 = Release|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|x86.ActiveCfg = Release|Any CPU
{0C23728A-E2A5-48A7-BF6F-C6EC865900D0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
58 changes: 40 additions & 18 deletions CorgEng.Core/CorgEngMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using CorgEng.Core.Rendering.Exceptions;
using CorgEng.GenericInterfaces.EntityComponentSystem;
using CorgEng.GenericInterfaces.Logging;
using CorgEng.GenericInterfaces.Networking.Networking.Client;
using CorgEng.GenericInterfaces.Networking.Networking.Server;
using CorgEng.GenericInterfaces.Rendering;
using CorgEng.GenericInterfaces.Rendering.Renderers;
using CorgEng.GenericInterfaces.Rendering.Renderers.SpriteRendering;
Expand Down Expand Up @@ -79,6 +81,12 @@ public static class CorgEngMain
[UsingDependency]
private static ILogger Logger;

/// <summary>
/// The thing that we use to create the world
/// </summary>
[UsingDependency]
private static IWorldFactory WorldFactory;

/// <summary>
/// Time of the last frame
/// </summary>
Expand All @@ -103,17 +111,17 @@ public static class CorgEngMain

public static event Action OnReadyEvents = null;

private static IWorld primaryWorld = null;
private static IWorld _primaryWorld = null;

/// <summary>
/// The main world to use for the game for when one isn't accessible
/// </summary>
public static IWorld PrimaryWorld
public static IWorld World
{
get => primaryWorld;
get => _primaryWorld;
set {
primaryWorld = value;
WorldInit(primaryWorld);
_primaryWorld = value;
WorldInit(_primaryWorld);
}
}
/// <summary>
Expand All @@ -130,13 +138,14 @@ public static IWorld PrimaryWorld
/// Initializes the CorgEng game engine.
/// Will call initialization on all CorgEng modules.
/// </summary>
public static void Initialize(bool disableRendering = false)
public static void Initialize(string filePath, bool disableRendering = false, bool awaitOnError = true)
{
LoadConfig(filePath, awaitOnError);
try
{
// Reset the world list
WorldList.Clear();
//Load priority modules (Logging)
// Load priority modules (Logging)
PriorityModuleInit();
Logger?.WriteLine("Starting CorgEng Application", LogType.DEBUG);
if (disableRendering)
Expand All @@ -145,21 +154,33 @@ public static void Initialize(bool disableRendering = false)
ModuleInit();
return;
}
//Enable rendering functionality
// Enable rendering functionality
IsRendering = true;
//Create a new window
// Create a new window
GameWindow = new CorgEngWindow();
GameWindow.Open();
Logger?.WriteLine("Successfully created primary window", LogType.DEBUG);
//Create the internal render master
// Create the internal render master
InternalRenderMaster = new RenderMaster();
InternalRenderMaster.Initialize();
Logger?.WriteLine("Successfully initialized render master", LogType.DEBUG);
//Bind the render master size to the game window
// Bind the render master size to the game window
GameWindow.OnWindowResized += InternalRenderMaster.SetWindowRenderSize;
GameWindow.OnWindowResized += activeSizeDelegate;
//Load non-priority modules
// Load non-priority modules
ModuleInit();
// Create the world
if (World == null)
{
if (WorldFactory != null)
{
World = WorldFactory.CreateWorld();
}
else
{
Logger?.WriteLine($"The world module is not loaded, meaning that no base game was created.", LogType.WARNING);
}
}
}
catch (System.Exception e)
{
Expand Down Expand Up @@ -300,7 +321,7 @@ public static IRenderer GetRendererForPlane(int renderCorePlane)
{
return renderCores.GetOrAdd(renderCorePlane, plane => {
// Fetch a default render core implementation
var spriteRenderer = SpriteRendererFactory.CreateSpriteRenderer(primaryWorld, plane);
var spriteRenderer = SpriteRendererFactory.CreateSpriteRenderer(_primaryWorld, plane);
lock (stagedRenderPlanes)
{
stagedRenderPlanes.Add(plane, spriteRenderer);
Expand Down Expand Up @@ -335,14 +356,14 @@ public static void Shutdown()
/// TODO: Whitelist/blacklist types and add sandboxing
/// </summary>
/// <param name="filePath"></param>
public static void LoadConfig(string filePath, bool embeddedResource = true, bool awaitOnError = true)
private static void LoadConfig(string filePath, bool awaitOnError = true)
{
try
{
string resourceName;
Stream resourceStream;
//Locate the config resources file
if (embeddedResource)
if (!File.Exists(filePath))
{
resourceName = Assembly.GetEntryAssembly().GetManifestResourceNames().Single(str => str.EndsWith(filePath));
resourceStream = Assembly.GetEntryAssembly().GetManifestResourceStream(resourceName);
Expand Down Expand Up @@ -384,6 +405,9 @@ public static void LoadConfig(string filePath, bool embeddedResource = true, boo
}
LoadedAssemblyModules = loadedAssemblies;
break;
case "WindowName":
WindowName = childElement.Value;
break;
default:
Console.Error.WriteLine($"[CorgEng Config Error]: Error parsing config, unknown config attribute {childElement.Name}.");
break;
Expand Down Expand Up @@ -561,7 +585,6 @@ public static void ExecuteIn(Action action, double executeTime)
}
}
double timeToFire = Time + executeTime * 0.001;
Logger.WriteLine($"Action queued to fire at {timeToFire}", LogType.WARNING);
// 0 or negative execution time
if (timeToFire <= Time)
{
Expand Down Expand Up @@ -614,7 +637,7 @@ internal static void CheckQueuedExecutions()
public static void Cleanup()
{
MainCamera = null;
primaryWorld = null;
_primaryWorld = null;
foreach (IWorld world in WorldList)
{
world.Cleanup();
Expand All @@ -623,6 +646,5 @@ public static void Cleanup()
queuedActions.Clear();
Logger.WriteLine("Full cleanup of CorgEng application completed.", LogType.DEBUG);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal class EntitySystemManager : IEntitySystemManager
/// </summary>
internal Dictionary<EventComponentPair, List<SystemEventHandlerDelegate>> RegisteredSystemSignalHandlers { get; } = new Dictionary<EventComponentPair, List<SystemEventHandlerDelegate>>();

private EntitySystemThreadManager entitySystemThreadManager = new EntitySystemThreadManager(4);
private EntitySystemThreadManager entitySystemThreadManager = new EntitySystemThreadManager(1);

private IWorld world;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public void EnqueueSystemForProcessing(EntitySystem system)
public void FireSystemIn(EntitySystem system, double fireTime)
{
CorgEngMain.ExecuteIn(() => {
Logger.WriteLine($"Attempting to queue system {system} for processing fire at {CorgEngMain.Time}", LogType.TEMP);
system.QueueProcessing();
}, fireTime);
}
Expand Down
4 changes: 4 additions & 0 deletions CorgEng.Example.Server/CorgEngConfig.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<CorgEngConfig>

<!--Specify which modules we need to load dynamically-->
<DependencyModules>
<Module>CorgEng.ContentLoading</Module>
Expand All @@ -18,4 +19,7 @@
<Module>CorgEng.UserInterface</Module>
<Module>CorgEng.World</Module>
</DependencyModules>

<WindowName>CorgEngApplication Server</WindowName>

</CorgEngConfig>
30 changes: 9 additions & 21 deletions CorgEng.Example.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,21 @@ class Program
[UsingDependency]
private static INetworkConfig NetworkConfig;

[UsingDependency]
private static IWorldFactory WorldFactory;

public static IWorld ServerWorld;

static void Main(string[] args)
{
//Load the application config
CorgEngMain.LoadConfig("CorgEngConfig.xml");
CorgEngMain.WindowName = "CorgEngApplication Server";
//Initialize CorgEng in headless mode
#if !DEBUG_RENDERING
CorgEngMain.Initialize(true);
CorgEngMain.Initialize("CorgEngConfig.xml", true);
#else
CorgEngMain.Initialize();

// Create the program world
ServerWorld = WorldFactory.CreateWorld();
CorgEngMain.PrimaryWorld = ServerWorld;
CorgEngMain.Initialize("CorgEngConfig.xml");

//Start networking server
ServerWorld.ServerInstance.StartHosting(5000);
CorgEngMain.World.ServerInstance.StartHosting(5000);

//Debug
NetworkConfig.ProcessClientSystems = true;

ServerWorld.EntityManager.CreateEmptyEntity(entity => {
CorgEngMain.World.EntityManager.CreateEmptyEntity(entity => {
IIsometricCamera camera = IsometricCameraFactory.CreateCamera();
camera.Width = 30;
camera.Height = 30;
Expand All @@ -95,7 +83,7 @@ static void Main(string[] args)
});

// Create a lighting debugger
ServerWorld.EntityManager.CreateEmptyEntity(entity => {
CorgEngMain.World.EntityManager.CreateEmptyEntity(entity => {
entity.AddComponent(new TransformComponent());
entity.AddComponent(new FollowCursorComponent());
entity.AddComponent(new SpriteRenderComponent());
Expand Down Expand Up @@ -161,7 +149,7 @@ private static void BuildWorld()
{
for (int yv = Math.Min(start_y, end_y); yv <= Math.Max(start_y, end_y); yv++)
{
ServerWorld.EntityManager.CreateEmptyEntity(testingEntity => {
CorgEngMain.World.EntityManager.CreateEmptyEntity(testingEntity => {
//Add components
testingEntity.AddComponent(new NetworkTransformComponent());
testingEntity.AddComponent(new SpriteRenderComponent());
Expand All @@ -178,7 +166,7 @@ private static void BuildWorld()
});

//Create a testing entity
ServerWorld.EntityManager.CreateEmptyEntity(testingEntity => {
CorgEngMain.World.EntityManager.CreateEmptyEntity(testingEntity => {
//Add components
testingEntity.AddComponent(new NetworkTransformComponent());
testingEntity.AddComponent(new SpriteRenderComponent());
Expand All @@ -192,13 +180,13 @@ private static void BuildWorld()

private static void SetPlayerPrototype()
{
ServerWorld.EntityManager.CreateEmptyEntity(playerPrototype => {
CorgEngMain.World.EntityManager.CreateEmptyEntity(playerPrototype => {
playerPrototype.AddComponent(new ClientComponent());
playerPrototype.AddComponent(new NetworkTransformComponent());
playerPrototype.AddComponent(new SpriteRenderComponent() { Sprite = IconFactory.CreateIcon("human.ghost", 5, Constants.RenderingConstants.DEFAULT_RENDERER_PLANE), SpriteRendererIdentifier = 1 });
playerPrototype.AddComponent(new PlayerMovementComponent());
IPrototype prototype = PrototypeManager.GetPrototype(playerPrototype);
ServerWorld.ServerInstance.SetClientPrototype(prototype);
CorgEngMain.World.ServerInstance.SetClientPrototype(prototype);
new DeleteEntityEvent().Raise(playerPrototype);
});
}
Expand Down
25 changes: 2 additions & 23 deletions CorgEng.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,18 @@ class Program

static void Main(string[] args)
{
//Load the application config
CorgEngMain.LoadConfig("CorgEngConfig.xml");
//Initialize CorgEng
//This creates the window and loads all
//modules that are dependencies
CorgEngMain.Initialize();

// Create the world
IWorld world = WorldFactory.CreateWorld();
CorgEngMain.PrimaryWorld = world;

//Set the render core

// Prevent failures
//Thread.Sleep(5000);
CorgEngMain.Initialize("CorgEngConfig.xml");

//Camera an isometric camera
IIsometricCamera camera = isometricCameraFactory.CreateCamera();
CameraScrollSystem.IsometricCamera = camera;

//Connect to our server
world.ClientInstance.AttemptConnection("127.0.0.1", 5000);
CorgEngMain.World.ClientInstance.AttemptConnection("127.0.0.1", 5000);

//Create the entity to hold and move the camera
/*Entity mainCameraEntity = new Entity();
mainCameraEntity.AddComponent(new TransformComponent());
mainCameraEntity.AddComponent(new PlayerMovementComponent());
mainCameraEntity.AddComponent(new CameraComponent(camera));
mainCameraEntity.AddComponent(new SpriteRenderComponent());*/
/*
new SetSpriteEvent("human.ghost").Raise(mainCameraEntity);
new SetSpriteRendererEvent(erc.spriteRenderer).Raise(mainCameraEntity);
*/
//Set the main camera
CorgEngMain.SetMainCamera(camera);
//Transfer control of the main thread to the CorgEng
Expand Down
Loading

0 comments on commit d70e2e3

Please sign in to comment.