Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into batching
Browse files Browse the repository at this point in the history
# Conflicts:
#	Hypercube.Example.Client/Example.cs
  • Loading branch information
JerryImMouse committed Jul 31, 2024
2 parents 5278225 + ffc36f4 commit 9adb3bb
Show file tree
Hide file tree
Showing 44 changed files with 534 additions and 109 deletions.
7 changes: 7 additions & 0 deletions .idea/.idea.Hypercube/.idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 4 additions & 27 deletions Hypercube.Client/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@
using Hypercube.Client.Graphics.Viewports;
using Hypercube.Client.Input.Handler;
using Hypercube.Client.Input.Manager;
using Hypercube.Client.Resources.Caching;
using Hypercube.Client.Runtimes;
using Hypercube.Client.Runtimes.Loop;
using Hypercube.Shared;
using Hypercube.Shared.Dependency;
using Hypercube.Shared.Entities.Realisation.EventBus;
using Hypercube.Shared.Entities.Realisation.Manager;
using Hypercube.Shared.EventBus;
using Hypercube.Shared.Physics;
using Hypercube.Shared.Resources.Container;
using Hypercube.Shared.Resources.Manager;
using Hypercube.Shared.Resources.Preloader;
using Hypercube.Shared.Timing;
using Hypercube.Shared.Runtimes;
using Hypercube.Shared.Runtimes.Loop;

namespace Hypercube.Client;

Expand All @@ -30,17 +24,8 @@ public static class Dependencies
{
public static void Register(DependenciesContainer rootContainer)
{
// Timing
rootContainer.Register<ITiming, Timing>();
SharedDependencies.Register(rootContainer);

// EventBus
rootContainer.Register<IEventBus, EventBus>();

// Resources
rootContainer.Register<IResourceLoader, ResourceLoader>();
rootContainer.Register<IResourceContainer, ResourceContainer>();
rootContainer.Register<IResourcePreloader, ResourcePreloader>();

// Input
rootContainer.Register<IInputHandler, InputHandler>();
rootContainer.Register<IInputManager, InputManager>();
Expand All @@ -55,18 +40,10 @@ public static void Register(DependenciesContainer rootContainer)
// Camera
rootContainer.Register<ICameraManager, CameraManager>();

// Physics
rootContainer.Register<IPhysicsManager, PhysicsManager>();

// Rendering
rootContainer.Register<IRenderer, Renderer>();

// ECS
rootContainer.Register<IEntitiesComponentManager, EntitiesComponentManager>();
rootContainer.Register<IEntitiesSystemManager, EntitiesSystemManager>();
rootContainer.Register<IEntitiesEventBus, EntitiesEventBus>();
rootContainer.Register<IEntitiesManager, EntitiesManager>();

// Runtime
rootContainer.Register<IRuntimeLoop, RuntimeLoop>();
rootContainer.Register<IRuntime, Runtime>();
Expand Down
30 changes: 3 additions & 27 deletions Hypercube.Client/EntryPoint.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
using Hypercube.Client.Runtimes;
using Hypercube.Shared;
using Hypercube.Shared.Dependency;
using Hypercube.Shared.Entities.Realisation.Systems;
using Hypercube.Shared.Utilities.ArgumentsParser;

namespace Hypercube.Client;

public static class EntryPoint
public sealed class EntryPoint : SharedEntryPoint
{
/// <summary>
/// The entry point to the engine, starts it in the current thread,
/// once started, the thread will be frozen by the execution of the loop,
/// until the engine is shut down.
/// </summary>
/// <param name="args">
/// Input arguments to the engine.
/// </param>
/// <param name="callback">
/// Callback that will be called after the current <see cref="DependencyManager"/> thread is initialized,
/// allowing its dependencies to be used, but before entering the game loop.
/// This is the only way to get into the engine,
/// not through the <see cref="IEntitySystem"/>.
/// </param>
public static void Enter(string[] args, Action<string[], DependenciesContainer>? callback = null)
protected override void Enter(ArgumentParser parser, DependenciesContainer rootContainer)
{
var parser = new ArgumentParser(args);
parser.TryParse();

var rootContainer = DependencyManager.InitThread();
Dependencies.Register(rootContainer);

callback?.Invoke(args, rootContainer);

var runtime = rootContainer.Resolve<IRuntime>();
runtime.Run();
}
}
9 changes: 5 additions & 4 deletions Hypercube.Client/Runtimes/Loop/RuntimeLoop.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Hypercube.Shared.Dependency;
using Hypercube.Shared.EventBus;
using Hypercube.Shared.Runtimes.Loop;
using Hypercube.Shared.Runtimes.Loop.Event;
using Hypercube.Shared.Timing;

Expand All @@ -9,21 +10,21 @@ public sealed class RuntimeLoop : IRuntimeLoop
{
[Dependency] private readonly ITiming _timing = default!;
[Dependency] private readonly IEventBus _eventBus = default!;

public bool Running { get; private set; }

public void Run()
{
if (Running)
throw new InvalidOperationException();

Running = true;
while (Running)
{
_timing.StartFrame();

var deltaTime = (float)_timing.RealFrameTime.TotalSeconds;

_eventBus.Raise(new InputFrameEvent(deltaTime));
_eventBus.Raise(new TickFrameEvent(deltaTime));
_eventBus.Raise(new UpdateFrameEvent(deltaTime));
Expand Down
2 changes: 2 additions & 0 deletions Hypercube.Client/Runtimes/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using Hypercube.Shared.Dependency;
using Hypercube.Shared.EventBus;
using Hypercube.Shared.Logging;
using Hypercube.Shared.Runtimes;
using Hypercube.Shared.Runtimes.Event;
using Hypercube.Shared.Runtimes.Loop;

namespace Hypercube.Client.Runtimes;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Hypercube.Client.Graphics.Viewports;
using Hypercube.Shared.Entities.Realisation.Components;

namespace Hypercube.Example.Camera;
namespace Hypercube.Example.Client.Camera;

public sealed class CameraComponent : Component
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Hypercube.Shared.Entities.Systems.Transform;
using Hypercube.Shared.Runtimes.Loop.Event;

namespace Hypercube.Example.Camera;
namespace Hypercube.Example.Client.Camera;

public sealed class CameraSystem : EntitySystem
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Hypercube.Shared.Entities.Realisation.Components;

namespace Hypercube.Example.Controls;
namespace Hypercube.Example.Client.Controls;

public sealed class ControlsComponent : Component
{
public float Speed = 10;
public float Speed = 60;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Hypercube.Shared.Entities.Systems.Physics;
using Hypercube.Shared.Runtimes.Loop.Event;

namespace Hypercube.Example.Controls;
namespace Hypercube.Example.Client.Controls;

public sealed class ControlsSystem : EntitySystem
{
Expand All @@ -22,7 +22,7 @@ public override void FrameUpdate(UpdateFrameEvent args)
foreach (var entity in GetEntities<ControlsComponent>())
{
var physics = GetComponent<PhysicsComponent>(entity);
physics.LinearVelocity = new Vector2(inputX, inputY) * entity.Component.Speed;
physics.Force = new Vector2(inputX, inputY) * entity.Component.Speed;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Hypercube.Client.Entities.Systems.Sprite;
using Hypercube.Client.Graphics.Rendering;
using Hypercube.Client.Graphics.Viewports;
using Hypercube.Example.Controls;
using Hypercube.Example.Client.Controls;
using Hypercube.Math.Vectors;
using Hypercube.Shared.Dependency;
using Hypercube.Shared.Entities.Realisation.Manager;
Expand All @@ -17,7 +17,7 @@
using Hypercube.Shared.Runtimes.Event;
using Hypercube.Shared.Scenes;

namespace Hypercube.Example;
namespace Hypercube.Example.Client;

public sealed class Example : IEventSubscriber, IPostInject
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Hypercube.Shared.Entities.Realisation.Components;

namespace Hypercube.Example;
namespace Hypercube.Example.Client;

public sealed class ExampleComponent : Component
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Hypercube.Shared.Runtimes.Loop.Event;
using Hypercube.Shared.Timing;

namespace Hypercube.Example;
namespace Hypercube.Example.Client;

public sealed class ExampleSystem : EntitySystem
{
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions Hypercube.Example.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Hypercube.Shared.EventBus;

namespace Hypercube.Example.Client;

internal class Program : IEventSubscriber
{
public static void Main(string[] args)
{
var example = new Example();
var entry = new Hypercube.Client.EntryPoint();
entry.Enter(args, example.Start);
}
}
15 changes: 15 additions & 0 deletions Hypercube.Example.Server/Hypercube.Example.Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Hypercube.Server\Hypercube.Server.csproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions Hypercube.Example.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Hypercube.Shared.EventBus;

namespace Hypercube.Example.Server;

internal class Program : IEventSubscriber
{
public static void Main(string[] args)
{
var entry = new Hypercube.Server.EntryPoint();
entry.Enter(args);
}
}
12 changes: 0 additions & 12 deletions Hypercube.Example/EntryPoint.cs

This file was deleted.

25 changes: 25 additions & 0 deletions Hypercube.Server/Dependencies.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Hypercube.Server.Runtimes;
using Hypercube.Server.Runtimes.Loop;
using Hypercube.Shared;
using Hypercube.Shared.Dependency;
using Hypercube.Shared.Runtimes;
using Hypercube.Shared.Runtimes.Loop;

namespace Hypercube.Server;

/// <summary>
/// Provide all server hypercube dependencies for registration.
/// </summary>
public static class Dependencies
{
public static void Register(DependenciesContainer rootContainer)
{
SharedDependencies.Register(rootContainer);

// Runtime
rootContainer.Register<IRuntimeLoop, RuntimeLoop>();
rootContainer.Register<IRuntime, Runtime>();

rootContainer.InstantiateAll();
}
}
13 changes: 13 additions & 0 deletions Hypercube.Server/EntryPoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Hypercube.Shared;
using Hypercube.Shared.Dependency;
using Hypercube.Shared.Utilities.ArgumentsParser;

namespace Hypercube.Server;

public sealed class EntryPoint : SharedEntryPoint
{
protected override void Enter(ArgumentParser parser, DependenciesContainer rootContainer)
{
Dependencies.Register(rootContainer);
}
}
15 changes: 15 additions & 0 deletions Hypercube.Server/Hypercube.Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Hypercube.Shared\Hypercube.Shared.csproj" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions Hypercube.Server/Runtimes/Loop/RuntimeLoop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Hypercube.Shared.Dependency;
using Hypercube.Shared.EventBus;
using Hypercube.Shared.Runtimes.Loop;
using Hypercube.Shared.Runtimes.Loop.Event;
using Hypercube.Shared.Timing;

namespace Hypercube.Server.Runtimes.Loop;

public class RuntimeLoop : IRuntimeLoop
{
[Dependency] private readonly ITiming _timing = default!;
[Dependency] private readonly IEventBus _eventBus = default!;

public bool Running { get; private set; }

public void Run()
{
if (Running)
throw new InvalidOperationException();

Running = true;
while (Running)
{
_timing.StartFrame();

var deltaTime = (float)_timing.RealFrameTime.TotalSeconds;

_eventBus.Raise(new TickFrameEvent(deltaTime));
_eventBus.Raise(new UpdateFrameEvent(deltaTime));
}
}

public void Shutdown()
{
Running = false;
}
}
Loading

0 comments on commit 9adb3bb

Please sign in to comment.