Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
terminal-cs committed Jun 3, 2023
1 parent 3d1cb2f commit 64fd82a
Show file tree
Hide file tree
Showing 30 changed files with 385 additions and 382 deletions.
2 changes: 1 addition & 1 deletion PrismAPI/Audio/AudioPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Cosmos.HAL.Drivers.Audio;
using Cosmos.System.Audio;
using PrismAPI.Tools;
using PrismAPI.Tools.Diagnostics;

namespace PrismAPI.Audio;

Expand Down
2 changes: 1 addition & 1 deletion PrismAPI/Filesystem/FilesystemManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Cosmos.System.FileSystem.VFS;
using Cosmos.System.FileSystem;
using Cosmos.HAL.BlockDevice;
using PrismAPI.Tools;
using PrismAPI.Tools.Diagnostics;

namespace PrismAPI.Filesystem;

Expand Down
2 changes: 1 addition & 1 deletion PrismAPI/Graphics/Image.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using PrismAPI.Processing.Compression;
using PrismAPI.Tools.Compression;
using System.Runtime.InteropServices;
using System.Text;

Expand Down
6 changes: 6 additions & 0 deletions PrismAPI/Graphics/Physics/Colisions/CubeColider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace PrismAPI.Graphics.Physics.Colisions;

public class CubeColider
{
// To-Do
}
32 changes: 32 additions & 0 deletions PrismAPI/Graphics/Physics/Gravity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Numerics;

namespace PrismAPI.Graphics.Physics;

public class Gravity
{
public Gravity()
{
Velocity = Vector3.Zero;
}

#region Methods

public void Next()
{
Velocity += Force - new Vector3(Mass);
Velocity.Z -= 9.80665f;

Speed = (Velocity.X + Velocity.Y + Velocity.Z) / 3;
}

#endregion

#region Fields

public Vector3 Velocity;
public Vector3 Force;
public float Speed;
public float Mass;

#endregion
}
9 changes: 0 additions & 9 deletions PrismAPI/Graphics/Rasterizer/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public Engine(ushort Width, ushort Height, float FOV) : base(Width, Height)
Lights = new();
Objects = new();
Camera = new(FOV);
Gravity = 1f;
Zoom = 0f;
}

Expand All @@ -56,13 +55,6 @@ public void Render()
// Calculate Objects - Loops over all triangle in every mesh.
foreach (Mesh M in Objects)
{
// Check if the mesh has physics.
if (M.HasPhysics)
{
// Apply physics.
M.Step(Gravity, 1.0f);
}

// Create a rotation matrix for the mesh - Separate from camera rotation.
Matrix4x4 Rotation = M.GetRotationMatrix();

Expand Down Expand Up @@ -102,7 +94,6 @@ public void Render()
public List<Mesh> Objects;
public Color SkyColor;
public Camera Camera;
public float Gravity;
public float Zoom;

#endregion
Expand Down
21 changes: 0 additions & 21 deletions PrismAPI/Graphics/Rasterizer/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ public Mesh()
Triangles = new();
Position = Vector3.Zero;
Rotation = Vector3.Zero;
Velocity = Vector3.Zero;
Force = Vector3.Zero;

HasCollision = true;
HasPhysics = false;
Mass = 1f;
}

#endregion
Expand Down Expand Up @@ -208,15 +202,6 @@ public void TestLogic(float ElapsedTime)
Rotation.X += ElapsedTime;
}

public void Step(float Gravity, float DT)
{
// Increment gravity.
Force.Y += Mass * Gravity;
Velocity.Y += Force.Y / Mass * DT;
Position.Y += Velocity.Y * DT;
Force = Vector3.Zero;
}

#endregion

#region Fields
Expand All @@ -225,12 +210,6 @@ public void Step(float Gravity, float DT)
public List<Triangle> Triangles;
public Vector3 Position;
public Vector3 Rotation;
public Vector3 Velocity;
public Vector3 Force;

public bool HasCollision;
public bool HasPhysics;
public float Mass;

#endregion
}
2 changes: 1 addition & 1 deletion PrismAPI/Network/NetworkManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Cosmos.System.Network.IPv4.UDP.DHCP;
using Cosmos.System.Network.IPv4.TCP;
using Cosmos.System.Network.IPv4;
using PrismAPI.Tools;
using PrismAPI.Tools.Diagnostics;

namespace PrismAPI.Network;

Expand Down
5 changes: 3 additions & 2 deletions PrismAPI/Runtime/Executable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using PrismAPI.Filesystem.Formats.ELF.ELFProgramHeader;
using PrismAPI.Filesystem.Formats.ELF.ELFHeader;
using PrismAPI.Filesystem.Formats.ELF;
using PrismAPI.Runtime.SystemCall;

namespace PrismAPI.Runtime;

Expand All @@ -13,7 +14,7 @@ public unsafe class Executable
public Executable()
{
Main = (delegate* unmanaged<void>)0;
Permissions = PermissionLevel.User;
Permissions = AccessLevel.User;
}

#region Methods
Expand Down Expand Up @@ -122,7 +123,7 @@ public static Executable FromBIN(byte[] Binary)
#region Fields

public delegate* unmanaged<void> Main;
public PermissionLevel Permissions;
public AccessLevel Permissions;

#endregion
}
3 changes: 2 additions & 1 deletion PrismAPI/Runtime/SSharp/Compiler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using PrismAPI.Runtime.SSharp.Structure;
using PrismAPI.Tools;
using PrismAPI.Tools.Diagnostics;
using PrismAPI.Tools.Extentions;

namespace PrismAPI.Runtime.SSharp;

Expand Down
2 changes: 1 addition & 1 deletion PrismAPI/Runtime/SSharp/Tokenizer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using PrismAPI.Runtime.SSharp.Structure;
using PrismAPI.Tools;
using PrismAPI.Tools.Extentions;

namespace PrismAPI.Runtime.SSharp;

Expand Down
2 changes: 1 addition & 1 deletion PrismAPI/Runtime/SShell/Scripts/Locker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using PrismAPI.Processing;
using PrismAPI.Tools;

namespace PrismAPI.Runtime.SShell.Scripts;

Expand Down
2 changes: 1 addition & 1 deletion PrismAPI/Runtime/SShell/Shell.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using PrismAPI.Filesystem.Formats.ELF.ELFHeader;
using PrismAPI.Runtime.SShell.Scripts;
using PrismAPI.Runtime.SSharp;
using PrismAPI.Tools;
using PrismAPI.Tools.Diagnostics;

namespace PrismAPI.Runtime.SShell;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PrismAPI.Runtime;
namespace PrismAPI.Runtime.SystemCall;

public enum PermissionLevel
public enum AccessLevel
{
/// <summary>
/// Full access to all files and features. No access to full system memory.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Runtime.InteropServices;
using PrismAPI.Tools;
using PrismAPI.Tools.Diagnostics;
using Cosmos.Core;
using TinyMath;

namespace PrismAPI.Runtime;
namespace PrismAPI.Runtime.SystemCall;

public static unsafe class SystemCalls
public static unsafe class Handler
{
#region Methods

Expand Down Expand Up @@ -35,91 +35,91 @@ public static void SystemCall(ref INTs.IRQContext Context /*, ref Executable Cal
// can just do the action anyway due to them being core apps, it will be good so
// the user knows it is going to be doing special access.

switch ((SystemCallKind)Context.EAX)
switch ((Kind)Context.EAX)
{
#region Console

case SystemCallKind.System_Console_WriteLine_string:
case Kind.System_Console_WriteLine_string:
Console.WriteLine(GetString((char*)Context.EBX));
break;
case SystemCallKind.System_Console_Write_string:
case Kind.System_Console_Write_string:
Console.Write(GetString((char*)Context.EBX));
break;
case SystemCallKind.System_Console_Clear:
case Kind.System_Console_Clear:
Console.Clear();
break;
case SystemCallKind.System_Console_SetColor:
case Kind.System_Console_SetColor:
Console.ForegroundColor = (ConsoleColor)Context.EBX;
Console.BackgroundColor = (ConsoleColor)Context.ECX;
break;
case SystemCallKind.System_Console_ResetColor:
case Kind.System_Console_ResetColor:
Console.ResetColor();
break;

#endregion

#region Memory

case SystemCallKind.System_Runtime_InteropServices_NativeMemory_Realloc: // Realloc
case Kind.System_Runtime_InteropServices_NativeMemory_Realloc: // Realloc
Context.EAX = (uint)NativeMemory.Realloc((byte*)Context.EBX, Context.EDX);
break;

case SystemCallKind.System_Runtime_InteropServices_NativeMemory_Alloc: // Alloc
case Kind.System_Runtime_InteropServices_NativeMemory_Alloc: // Alloc
Context.EAX = (uint)NativeMemory.Alloc(Context.EBX);
break;

case SystemCallKind.System_Runtime_InteropServices_NativeMemory_Free: // Free
case Kind.System_Runtime_InteropServices_NativeMemory_Free: // Free
NativeMemory.Free((uint*)Context.EBX);
break;

case SystemCallKind.System_Buffer_MemoryCopy64: // Copy64
case Kind.System_Buffer_MemoryCopy64: // Copy64
System.Buffer.MemoryCopy((void*)Context.EBX, (void*)Context.ECX, Context.EDX * 8, Context.EDX * 8);
break;

case SystemCallKind.System_Buffer_MemoryCopy32: // Copy32
case Kind.System_Buffer_MemoryCopy32: // Copy32
System.Buffer.MemoryCopy((void*)Context.EBX, (void*)Context.ECX, Context.EDX * 4, Context.EDX * 4);
break;

case SystemCallKind.System_Buffer_MemoryCopy16: // Copy16
case Kind.System_Buffer_MemoryCopy16: // Copy16
System.Buffer.MemoryCopy((void*)Context.EBX, (void*)Context.ECX, Context.EDX * 2, Context.EDX * 2);
break;

case SystemCallKind.System_Buffer_MemoryCopy8: // Copy8
case Kind.System_Buffer_MemoryCopy8: // Copy8
System.Buffer.MemoryCopy((void*)Context.EBX, (void*)Context.ECX, Context.EDX, Context.EDX);
break;

case SystemCallKind.Core_Fill64: // Fill64
case Kind.Core_Fill64: // Fill64
for (int I = 0; I < (int)(int*)Context.EDX; I++)
{
*((long**)Context.EBX)[I] = (long)(long*)Context.ECX;
}
break;

case SystemCallKind.Core_Fill32: // Fill32
case Kind.Core_Fill32: // Fill32
MemoryOperations.Fill((uint*)Context.EBX, Context.ECX, (int)(int*)Context.EDX);
break;

case SystemCallKind.Core_Fill16: // Fill16
case Kind.Core_Fill16: // Fill16
MemoryOperations.Fill((ushort*)Context.EBX, (ushort)(ushort*)Context.ECX, (int)(int*)Context.EDX);
break;

case SystemCallKind.Core_Fill8: // Fill8
case Kind.Core_Fill8: // Fill8
MemoryOperations.Fill((byte*)Context.EBX, (byte)(byte*)Context.ECX, (int)(int*)Context.EDX);
break;

#endregion

#region Files

case SystemCallKind.System_IO_File_ReadAllBytes_string:
case Kind.System_IO_File_ReadAllBytes_string:
fixed (byte* PTR = File.ReadAllBytes(GetString((char*)Context.EBX)))
{
Context.EAX = (uint)new FileInfo(GetString((char*)Context.EBX)).Length;
MemoryOperations.Copy((uint*)Context.ECX, (uint*)PTR, (int)Context.EAX);
}
break;

case SystemCallKind.System_IO_File_WriteeAllBytes_string_bytes:
case Kind.System_IO_File_WriteeAllBytes_string_bytes:
byte[] Buffer = new byte[Context.EDX];
fixed (byte* PTR = Buffer)
{
Expand All @@ -128,46 +128,46 @@ public static void SystemCall(ref INTs.IRQContext Context /*, ref Executable Cal
File.WriteAllBytes(GetString((char*)Context.EBX), Buffer);
break;

case SystemCallKind.System_IO_Directory_Delete:
case Kind.System_IO_Directory_Delete:
Directory.Delete(GetString((char*)Context.EBX));
break;

case SystemCallKind.System_IO_File_Delete:
case Kind.System_IO_File_Delete:
File.Delete(GetString((char*)Context.EBX));
break;

case SystemCallKind.System_IO_Directory_Create:
case Kind.System_IO_Directory_Create:
Directory.CreateDirectory(GetString((char*)Context.EBX));
break;

case SystemCallKind.System_IO_File_Create:
case Kind.System_IO_File_Create:
File.Create(GetString((char*)Context.EBX));
break;

case SystemCallKind.System_IO_Directory_Exists:
case Kind.System_IO_Directory_Exists:
Context.EAX = (uint)(Directory.Exists(GetString((char*)Context.EBX)) ? 1 : 0);
break;

case SystemCallKind.System_IO_File_Exists:
case Kind.System_IO_File_Exists:
Context.EAX = (uint)(File.Exists(GetString((char*)Context.EBX)) ? 1 : 0);
break;

#endregion

#region Core

case SystemCallKind.Core_Set_Permissions:
case Kind.Core_Set_Permissions:
// If CallingBinary.Permissions == Kernel
// CallingBinary.Permissions = Requested permissions
// Else ask user permission
// If answer is yes or correct password is in...
// CallingBinary.Permissions = Requested permissions
// Else, do nothing and return.
break;
case SystemCallKind.Core_Get_Permissions:
case Kind.Core_Get_Permissions:
// Return CallingBinary.Permissions
break;
case SystemCallKind.Core_Math_Eval:
case Kind.Core_Math_Eval:
fixed (char* C = SyntaxParser.Evaluate(GetString((char*)Context.EBX)).ToString())
{
Context.EAX = (uint)C;
Expand Down
Loading

0 comments on commit 64fd82a

Please sign in to comment.