You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.6 KiB
124 lines
4.6 KiB
using System; |
|
using System.Diagnostics; |
|
using System.Globalization; |
|
using System.Numerics; |
|
using System.Threading; |
|
using gaemstone; |
|
using gaemstone.Bloxel; |
|
using gaemstone.ECS; |
|
using gaemstone.Utility; |
|
using Silk.NET.Windowing; |
|
using static gaemstone.Bloxel.Components.CoreComponents; |
|
using static gaemstone.Client.Components.CameraComponents; |
|
using static gaemstone.Client.Components.RenderingComponents; |
|
using static gaemstone.Client.Components.ResourceComponents; |
|
using static gaemstone.Client.Systems.FreeCameraController; |
|
using static gaemstone.Client.Systems.Windowing; |
|
using static gaemstone.Components.TransformComponents; |
|
|
|
var culture = CultureInfo.InvariantCulture; |
|
Thread.CurrentThread.CurrentCulture = culture; |
|
CultureInfo.DefaultThreadCurrentCulture = culture; |
|
|
|
var universe = new Universe(); |
|
var game = universe.LookupByTypeOrThrow<Game>(); |
|
|
|
universe.Modules.Register<gaemstone.Flecs.Systems.Rest>(); |
|
universe.Modules.Register<gaemstone.Flecs.Systems.Monitor>(); |
|
|
|
var window = Window.Create(WindowOptions.Default with { |
|
Title = "gæmstone", |
|
Size = new(1280, 720), |
|
PreferredDepthBufferBits = 24, |
|
}); |
|
window.Initialize(); |
|
window.Center(); |
|
|
|
// universe.Modules.Register<ObserverTest>(); |
|
|
|
universe.Modules.Register<gaemstone.Client.Systems.Windowing>(); |
|
universe.Modules.Register<gaemstone.Components.TransformComponents>(); |
|
|
|
universe.Modules.Register<gaemstone.Client.Components.RenderingComponents>(); |
|
universe.Modules.Register<gaemstone.Client.Systems.Renderer>(); |
|
universe.Modules.Register<gaemstone.Client.Systems.ImGuiManager>(); |
|
universe.Modules.Register<gaemstone.Client.Systems.ImGuiDemoWindow>(); |
|
|
|
universe.Modules.Register<gaemstone.Client.Components.ResourceComponents>(); |
|
universe.Modules.Register<gaemstone.Client.Systems.TextureManager>(); |
|
universe.Modules.Register<gaemstone.Client.Systems.MeshManager>(); |
|
|
|
universe.Modules.Register<gaemstone.Client.Components.InputComponents>(); |
|
universe.Modules.Register<gaemstone.Client.Systems.InputManager>(); |
|
universe.Modules.Register<gaemstone.Client.Systems.ImGuiInputDebug>(); |
|
universe.Modules.Register<gaemstone.Client.Systems.EntityInspector>(); |
|
|
|
universe.Modules.Register<gaemstone.Client.Components.CameraComponents>(); |
|
universe.Modules.Register<gaemstone.Client.Systems.FreeCameraController>(); |
|
|
|
game.Set(new Canvas(Silk.NET.OpenGL.ContextSourceExtensions.CreateOpenGL(window))); |
|
game.Set(new GameWindow(window)); |
|
|
|
universe.New("MainCamera") |
|
.Set(Camera.Default3D) |
|
.Set((GlobalTransform)Matrix4x4.CreateTranslation(0.0F, 2.0F, 0.0F)) |
|
.Set(new CameraController { MouseSensitivity = 12.0F }) |
|
.Build(); |
|
|
|
var heartMesh = universe.New("/Immersion/Resources/heart.glb").Add<Mesh>().Build(); |
|
var swordMesh = universe.New("/Immersion/Resources/sword.glb").Add<Mesh>().Build(); |
|
|
|
var entities = universe.New("Entities").Build(); |
|
var rnd = new Random(); |
|
for (var x = -12; x <= 12; x++) |
|
for (var z = -12; z <= 12; z++) { |
|
var position = Matrix4x4.CreateTranslation(x * 2, 0.0F, z * 2); |
|
var rotation = Matrix4x4.CreateRotationY(rnd.NextFloat(MathF.PI * 2)); |
|
var (type, mesh) = rnd.Pick(("Heart", heartMesh), ("Sword", swordMesh)); |
|
entities.NewChild() |
|
.Set((GlobalTransform)(rotation * position)) |
|
.Add<Mesh>(mesh) |
|
.Build(); |
|
} |
|
|
|
universe.Modules.Register<gaemstone.Bloxel.Components.CoreComponents>(); |
|
universe.Modules.Register<gaemstone.Bloxel.Systems.BasicWorldGenerator>(); |
|
universe.Modules.Register<gaemstone.Bloxel.Client.Systems.ChunkMeshGenerator>(); |
|
|
|
var texture = universe.New("/Immersion/Resources/terrain.png").Add<Texture>().Build(); |
|
|
|
var stone = universe.New("Stone").Set(TextureCoords4.FromGrid(4, 4, 1, 0)).Build(); |
|
var dirt = universe.New("Dirt" ).Set(TextureCoords4.FromGrid(4, 4, 2, 0)).Build(); |
|
var grass = universe.New("Grass").Set(TextureCoords4.FromGrid(4, 4, 3, 0)).Build(); |
|
|
|
var chunks = universe.New("Chunks").Build(); |
|
var sizeH = 4; var sizeY = 2; |
|
for (var cx = -sizeH; cx < sizeH; cx++) |
|
for (var cy = -sizeY; cy < sizeY; cy++) |
|
for (var cz = -sizeH; cz < sizeH; cz++) { |
|
var pos = new ChunkPos(cx, cy - 2, cz); |
|
var storage = new ChunkStoreBlocks(); |
|
chunks.NewChild() |
|
.Set((GlobalTransform)Matrix4x4.CreateTranslation(pos.GetOrigin())) |
|
.Set(new Chunk(pos)) |
|
.Set(storage) |
|
.Add<Texture>(texture) |
|
.Build(); |
|
} |
|
|
|
// universe.Modules.Register<ObserverTest>(); |
|
|
|
var stopwatch = Stopwatch.StartNew(); |
|
var minFrameTime = TimeSpan.FromSeconds(1) / 30; |
|
window.Run(() => { |
|
var delta = stopwatch.Elapsed; |
|
stopwatch.Restart(); |
|
|
|
if (!universe.Progress(delta)) |
|
window.Close(); |
|
|
|
var requiredTime = stopwatch.Elapsed; |
|
while (stopwatch.Elapsed < minFrameTime) Thread.Sleep(0); |
|
var totalTime = stopwatch.Elapsed; |
|
// Console.WriteLine($"Frame time: req={requiredTime.TotalMilliseconds:F2}ms, total={totalTime.TotalMilliseconds:F2}ms"); |
|
});
|
|
|