├── .gitattributes ├── .gitignore ├── BeefSpace.toml ├── LICENSE ├── README.md ├── samples ├── BeefSpace.toml ├── HelloWorld │ ├── BeefProj.toml │ ├── imgui.ini │ └── src │ │ └── Program.bf ├── NeonShooter │ ├── BeefProj.toml │ ├── content │ │ ├── fonts │ │ │ └── PressStart2P.ttf │ │ ├── music │ │ │ └── Music.mp3 │ │ ├── shaders │ │ │ ├── BloomCombine.frag │ │ │ ├── BloomCombine.vert │ │ │ ├── BloomExtract.frag │ │ │ ├── BloomExtract.vert │ │ │ ├── GaussianBlur.frag │ │ │ ├── GaussianBlur.vert │ │ │ ├── Vignette.frag │ │ │ ├── Vignette.vert │ │ │ ├── sprite.frag │ │ │ └── sprite.vert │ │ ├── sounds │ │ │ ├── explosion-01.wav │ │ │ ├── explosion-02.wav │ │ │ ├── explosion-03.wav │ │ │ ├── explosion-04.wav │ │ │ ├── explosion-05.wav │ │ │ ├── explosion-06.wav │ │ │ ├── explosion-07.wav │ │ │ ├── explosion-08.wav │ │ │ ├── shoot-01.wav │ │ │ ├── shoot-02.wav │ │ │ ├── shoot-03.wav │ │ │ ├── shoot-04.wav │ │ │ ├── spawn-01.wav │ │ │ ├── spawn-02.wav │ │ │ ├── spawn-03.wav │ │ │ ├── spawn-04.wav │ │ │ ├── spawn-05.wav │ │ │ ├── spawn-06.wav │ │ │ ├── spawn-07.wav │ │ │ └── spawn-08.wav │ │ └── textures │ │ │ ├── BlackHole.png │ │ │ ├── Bullet.png │ │ │ ├── Glow.png │ │ │ ├── Laser.png │ │ │ ├── Player.png │ │ │ ├── Pointer.png │ │ │ ├── Seeker.png │ │ │ ├── Wanderer.png │ │ │ └── shipa.aseprite │ ├── imgui.ini │ └── src │ │ ├── Components │ │ ├── GridComponent.bf │ │ ├── ParticleManager.bf │ │ ├── PlayerCamera.bf │ │ └── PlayerStatus.bf │ │ ├── Core.bf │ │ ├── Entities │ │ ├── BlackHole.bf │ │ ├── Bullet.bf │ │ ├── Enemy.bf │ │ ├── Entity.bf │ │ ├── Player.bf │ │ ├── Seeker.bf │ │ └── Wanderer.bf │ │ ├── Extensions.bf │ │ ├── NeonGame.bf │ │ ├── PostEffects │ │ ├── BloomCombineEffect.bf │ │ ├── BloomExtractEffect.bf │ │ ├── GaussianBlurEffect.bf │ │ └── VignetteEffect.bf │ │ ├── PostProcessors │ │ ├── Bloom.bf │ │ └── Vignette.bf │ │ └── Program.bf └── ParticleSim │ ├── BeefProj.toml │ ├── imgui.ini │ └── src │ └── Program.bf ├── src ├── Atma.Common │ ├── BeefProj.toml │ ├── dist │ │ ├── Debug-Linux64 │ │ │ └── cimgui.a │ │ ├── Debug-Win64 │ │ │ └── cimgui.lib │ │ ├── Debug-macOS │ │ │ └── cimgui.a │ │ ├── Release-Linux64 │ │ │ └── cimgui.a │ │ ├── Release-Win64 │ │ │ └── cimgui.lib │ │ ├── Release-macOS │ │ │ └── cimgui.a │ │ └── Test-Win64 │ │ │ └── cimgui.lib │ ├── generator │ │ ├── Atma.Math.Generator.csproj │ │ ├── Extensions.cs │ │ ├── Members │ │ │ ├── AggregatedProperty.cs │ │ │ ├── ComponentWiseOperator.cs │ │ │ ├── ComponentWiseStaticFunction.cs │ │ │ ├── Constructor.cs │ │ │ ├── ExplicitOperator.cs │ │ │ ├── Field.cs │ │ │ ├── Function.cs │ │ │ ├── ImplicitOperator.cs │ │ │ ├── Indexer.cs │ │ │ ├── Member.cs │ │ │ ├── Operator.cs │ │ │ ├── Property.cs │ │ │ └── StaticProperty.cs │ │ ├── Program.cs │ │ ├── Tests │ │ │ ├── DistributionTestFunc.cs │ │ │ ├── InvariantTestFunc.cs │ │ │ └── TestFunc.cs │ │ └── Types │ │ │ ├── AbstractType.cs │ │ │ ├── AnyType.cs │ │ │ ├── ArrayType.cs │ │ │ ├── BuiltinType.cs │ │ │ ├── MatrixType.cs │ │ │ ├── QuaternionType.cs │ │ │ ├── SwizzleType.Code.cs │ │ │ ├── SwizzleType.Tests.cs │ │ │ ├── SwizzleType.cs │ │ │ ├── VectorType.Code.cs │ │ │ ├── VectorType.Tests.cs │ │ │ └── VectorType.cs │ └── src │ │ ├── Assert.bf │ │ ├── Collections │ │ ├── CircularBuffer.bf │ │ ├── LookupList.bf │ │ ├── NativeList.bf │ │ ├── SizedList.bf │ │ └── StringPool.bf │ │ ├── DearImGui │ │ ├── ImGui.bf │ │ ├── ImGuiHelper.bf │ │ ├── ImGuiImpl.bf │ │ ├── ImGuiImplOpenGL3.bf │ │ └── ImGuiInspect.bf │ │ ├── Extensions.bf │ │ ├── Graphics │ │ ├── Drawing │ │ │ ├── Animation.bf │ │ │ ├── Batch2D.bf │ │ │ ├── SpriteAtlas.bf │ │ │ ├── SpriteFont.bf │ │ │ └── Subtexture.bf │ │ ├── Images │ │ │ ├── Aseprite.bf │ │ │ ├── Image.bf │ │ │ └── Packer.bf │ │ └── Rendering │ │ │ ├── Camera2D.bf │ │ │ ├── DynamicMesh.bf │ │ │ ├── Enums │ │ │ ├── BlendMode.bf │ │ │ ├── Clear.bf │ │ │ ├── CullMode.bf │ │ │ ├── DepthCompare.bf │ │ │ └── SpriteEffects.bf │ │ │ ├── GraphicsContext.bf │ │ │ ├── GraphicsManager.bf │ │ │ ├── IndexBuffer.bf │ │ │ ├── PostEffect.bf │ │ │ ├── PostProcessor.bf │ │ │ ├── RenderPass.bf │ │ │ ├── RenderPipeline.bf │ │ │ ├── RenderTarget.bf │ │ │ ├── RenderTexture.bf │ │ │ ├── Renderer.bf │ │ │ ├── Shader │ │ │ ├── Material.bf │ │ │ ├── Shader.bf │ │ │ ├── ShaderAttribute.bf │ │ │ ├── ShaderSource.bf │ │ │ ├── ShaderUniform.bf │ │ │ └── UniformType.bf │ │ │ ├── Texture │ │ │ ├── Texture.bf │ │ │ ├── TextureFilter.bf │ │ │ ├── TextureFormat.bf │ │ │ └── TextureWrap.bf │ │ │ ├── Vertex │ │ │ ├── VertexAttrib.bf │ │ │ ├── VertexAttribute.bf │ │ │ ├── VertexComponents.bf │ │ │ ├── VertexFormat.bf │ │ │ └── VertexType.bf │ │ │ └── VertexBuffer.bf │ │ ├── Input │ │ ├── Axes.bf │ │ ├── Buttons.bf │ │ ├── Cursors.bf │ │ ├── Input.bf │ │ ├── Keys.bf │ │ ├── MouseButtons.bf │ │ ├── MouseState.bf │ │ ├── VirtualAxis.bf │ │ ├── VirtualButton.bf │ │ └── VirtualInput.bf │ │ ├── Linq.bf │ │ ├── Math │ │ ├── HLSColor.bf │ │ ├── Line.bf │ │ ├── Mat2x2 │ │ │ ├── bool2x2.cs │ │ │ ├── bool2x2.glm.cs │ │ │ ├── double2x2.cs │ │ │ ├── double2x2.glm.cs │ │ │ ├── float2x2.cs │ │ │ ├── float2x2.glm.cs │ │ │ ├── int2x2.cs │ │ │ ├── int2x2.glm.cs │ │ │ ├── long2x2.cs │ │ │ ├── long2x2.glm.cs │ │ │ ├── uint2x2.cs │ │ │ └── uint2x2.glm.cs │ │ ├── Mat2x3 │ │ │ ├── bool2x3.cs │ │ │ ├── bool2x3.glm.cs │ │ │ ├── double2x3.cs │ │ │ ├── double2x3.glm.cs │ │ │ ├── float2x3.cs │ │ │ ├── float2x3.glm.cs │ │ │ ├── int2x3.cs │ │ │ ├── int2x3.glm.cs │ │ │ ├── long2x3.cs │ │ │ ├── long2x3.glm.cs │ │ │ ├── uint2x3.cs │ │ │ └── uint2x3.glm.cs │ │ ├── Mat2x4 │ │ │ ├── bool2x4.cs │ │ │ ├── bool2x4.glm.cs │ │ │ ├── double2x4.cs │ │ │ ├── double2x4.glm.cs │ │ │ ├── float2x4.cs │ │ │ ├── float2x4.glm.cs │ │ │ ├── int2x4.cs │ │ │ ├── int2x4.glm.cs │ │ │ ├── long2x4.cs │ │ │ ├── long2x4.glm.cs │ │ │ ├── uint2x4.cs │ │ │ └── uint2x4.glm.cs │ │ ├── Mat3x2 │ │ │ ├── bool3x2.cs │ │ │ ├── bool3x2.glm.cs │ │ │ ├── double3x2.cs │ │ │ ├── double3x2.glm.cs │ │ │ ├── float3x2.cs │ │ │ ├── float3x2.glm.cs │ │ │ ├── int3x2.cs │ │ │ ├── int3x2.glm.cs │ │ │ ├── long3x2.cs │ │ │ ├── long3x2.glm.cs │ │ │ ├── uint3x2.cs │ │ │ └── uint3x2.glm.cs │ │ ├── Mat3x3 │ │ │ ├── bool3x3.cs │ │ │ ├── bool3x3.glm.cs │ │ │ ├── double3x3.cs │ │ │ ├── double3x3.glm.cs │ │ │ ├── float3x3.cs │ │ │ ├── float3x3.glm.cs │ │ │ ├── int3x3.cs │ │ │ ├── int3x3.glm.cs │ │ │ ├── long3x3.cs │ │ │ ├── long3x3.glm.cs │ │ │ ├── uint3x3.cs │ │ │ └── uint3x3.glm.cs │ │ ├── Mat3x4 │ │ │ ├── bool3x4.cs │ │ │ ├── bool3x4.glm.cs │ │ │ ├── double3x4.cs │ │ │ ├── double3x4.glm.cs │ │ │ ├── float3x4.cs │ │ │ ├── float3x4.glm.cs │ │ │ ├── int3x4.cs │ │ │ ├── int3x4.glm.cs │ │ │ ├── long3x4.cs │ │ │ ├── long3x4.glm.cs │ │ │ ├── uint3x4.cs │ │ │ └── uint3x4.glm.cs │ │ ├── Mat4x2 │ │ │ ├── bool4x2.cs │ │ │ ├── bool4x2.glm.cs │ │ │ ├── double4x2.cs │ │ │ ├── double4x2.glm.cs │ │ │ ├── float4x2.cs │ │ │ ├── float4x2.glm.cs │ │ │ ├── int4x2.cs │ │ │ ├── int4x2.glm.cs │ │ │ ├── long4x2.cs │ │ │ ├── long4x2.glm.cs │ │ │ ├── uint4x2.cs │ │ │ └── uint4x2.glm.cs │ │ ├── Mat4x3 │ │ │ ├── bool4x3.cs │ │ │ ├── bool4x3.glm.cs │ │ │ ├── double4x3.cs │ │ │ ├── double4x3.glm.cs │ │ │ ├── float4x3.cs │ │ │ ├── float4x3.glm.cs │ │ │ ├── int4x3.cs │ │ │ ├── int4x3.glm.cs │ │ │ ├── long4x3.cs │ │ │ ├── long4x3.glm.cs │ │ │ ├── uint4x3.cs │ │ │ └── uint4x3.glm.cs │ │ ├── Mat4x4 │ │ │ ├── bool4x4.cs │ │ │ ├── bool4x4.glm.cs │ │ │ ├── double4x4.cs │ │ │ ├── double4x4.glm.cs │ │ │ ├── float4x4.cs │ │ │ ├── float4x4.glm.cs │ │ │ ├── int4x4.cs │ │ │ ├── int4x4.glm.cs │ │ │ ├── long4x4.cs │ │ │ ├── long4x4.glm.cs │ │ │ ├── uint4x4.cs │ │ │ └── uint4x4.glm.cs │ │ ├── MathExt.bf │ │ ├── Quat │ │ │ ├── qbool.cs │ │ │ ├── qbool.glm.cs │ │ │ ├── qdouble.cs │ │ │ ├── qdouble.glm.cs │ │ │ ├── qfloat.cs │ │ │ ├── qfloat.glm.cs │ │ │ ├── qint.cs │ │ │ ├── qint.glm.cs │ │ │ ├── qlong.cs │ │ │ ├── qlong.glm.cs │ │ │ ├── quint.cs │ │ │ └── quint.glm.cs │ │ ├── SimplexNoise.bf │ │ ├── Swizzle │ │ │ ├── swizzle_bool2.cs │ │ │ ├── swizzle_bool2.glm.cs │ │ │ ├── swizzle_bool3.cs │ │ │ ├── swizzle_bool3.glm.cs │ │ │ ├── swizzle_bool4.cs │ │ │ ├── swizzle_bool4.glm.cs │ │ │ ├── swizzle_double2.cs │ │ │ ├── swizzle_double2.glm.cs │ │ │ ├── swizzle_double3.cs │ │ │ ├── swizzle_double3.glm.cs │ │ │ ├── swizzle_double4.cs │ │ │ ├── swizzle_double4.glm.cs │ │ │ ├── swizzle_float2.cs │ │ │ ├── swizzle_float2.glm.cs │ │ │ ├── swizzle_float3.cs │ │ │ ├── swizzle_float3.glm.cs │ │ │ ├── swizzle_float4.cs │ │ │ ├── swizzle_float4.glm.cs │ │ │ ├── swizzle_int2.cs │ │ │ ├── swizzle_int2.glm.cs │ │ │ ├── swizzle_int3.cs │ │ │ ├── swizzle_int3.glm.cs │ │ │ ├── swizzle_int4.cs │ │ │ ├── swizzle_int4.glm.cs │ │ │ ├── swizzle_long2.cs │ │ │ ├── swizzle_long2.glm.cs │ │ │ ├── swizzle_long3.cs │ │ │ ├── swizzle_long3.glm.cs │ │ │ ├── swizzle_long4.cs │ │ │ ├── swizzle_long4.glm.cs │ │ │ ├── swizzle_uint2.cs │ │ │ ├── swizzle_uint2.glm.cs │ │ │ ├── swizzle_uint3.cs │ │ │ ├── swizzle_uint3.glm.cs │ │ │ ├── swizzle_uint4.cs │ │ │ └── swizzle_uint4.glm.cs │ │ ├── Types.bf │ │ ├── aabb2.bf │ │ ├── axis.bf │ │ ├── bezier.bf │ │ ├── cardinals.bf │ │ ├── color.bf │ │ ├── facings.bf │ │ ├── float2_ext.bf │ │ ├── mtv.bf │ │ ├── rect.bf │ │ ├── vec2 │ │ │ ├── bool2.cs │ │ │ ├── bool2.glm.cs │ │ │ ├── double2.cs │ │ │ ├── double2.glm.cs │ │ │ ├── float2.cs │ │ │ ├── float2.glm.cs │ │ │ ├── int2.cs │ │ │ ├── int2.glm.cs │ │ │ ├── long2.cs │ │ │ ├── long2.glm.cs │ │ │ ├── uint2.cs │ │ │ └── uint2.glm.cs │ │ ├── vec3 │ │ │ ├── bool3.cs │ │ │ ├── bool3.glm.cs │ │ │ ├── double3.cs │ │ │ ├── double3.glm.cs │ │ │ ├── float3.cs │ │ │ ├── float3.glm.cs │ │ │ ├── int3.cs │ │ │ ├── int3.glm.cs │ │ │ ├── long3.cs │ │ │ ├── long3.glm.cs │ │ │ ├── uint3.cs │ │ │ └── uint3.glm.cs │ │ └── vec4 │ │ │ ├── bool4.cs │ │ │ ├── bool4.glm.cs │ │ │ ├── double4.cs │ │ │ ├── double4.glm.cs │ │ │ ├── float4.cs │ │ │ ├── float4.glm.cs │ │ │ ├── int4.cs │ │ │ ├── int4.glm.cs │ │ │ ├── long4.cs │ │ │ ├── long4.glm.cs │ │ │ ├── uint4.cs │ │ │ └── uint4.glm.cs │ │ ├── Platform │ │ ├── OpenGL │ │ │ ├── GL.bf │ │ │ ├── GLEnum.bf │ │ │ ├── GLHelper.bf │ │ │ └── Graphics │ │ │ │ └── Rendering │ │ │ │ ├── GL_Graphics.bf │ │ │ │ ├── GL_IndexBuffer.bf │ │ │ │ ├── GL_RenderTexture.bf │ │ │ │ ├── GL_Shader.bf │ │ │ │ ├── GL_Texture.bf │ │ │ │ ├── GL_VertexArray.bf │ │ │ │ └── GL_VertexBuffer.bf │ │ ├── Platform.bf │ │ └── SDL2 │ │ │ ├── SDL_Audio.bf │ │ │ ├── SDL_Core.bf │ │ │ ├── SDL_FontLoader.bf │ │ │ ├── SDL_GLContext.bf │ │ │ ├── SDL_Graphics.bf │ │ │ ├── SDL_ImageLoader.bf │ │ │ ├── SDL_Input.bf │ │ │ └── SDL_Window.bf │ │ ├── Release.bf │ │ ├── Sound │ │ ├── Audio.bf │ │ ├── Music.bf │ │ └── SoundEffect.bf │ │ ├── Systems │ │ ├── Assets.bf │ │ ├── Core.bf │ │ ├── Integration.bf │ │ ├── Screen.bf │ │ ├── Time.bf │ │ └── Window.bf │ │ └── Utils │ │ ├── BitOperations.bf │ │ ├── Calc.bf │ │ ├── CoreEvents.bf │ │ ├── Delegates.bf │ │ ├── Display.bf │ │ ├── Ease.bf │ │ ├── Emitter.bf │ │ ├── Flags.bf │ │ ├── HashCode.bf │ │ ├── Log.bf │ │ ├── Mask.bf │ │ ├── Rand.bf │ │ ├── StringId.bf │ │ ├── TimeRuler.bf │ │ ├── Timer.bf │ │ └── Wrap.bf ├── Atma.Entities │ ├── BeefProj.toml │ └── src │ │ ├── Component.bf │ │ ├── ComponentList.bf │ │ ├── Components │ │ ├── CameraComponent.bf │ │ ├── GraphicsComponent.bf │ │ ├── Renderable.bf │ │ └── Sprite.bf │ │ ├── Core.bf │ │ ├── Entity.bf │ │ ├── EntityList.bf │ │ ├── Game.bf │ │ ├── PostProcessor.bf │ │ ├── RenderableComponentList.bf │ │ ├── Scene.bf │ │ ├── SceneRenderer.bf │ │ └── Sorting.bf └── Atma.Systems │ ├── BeefProj.toml │ └── src │ ├── ComponentDataArray.bf │ ├── ComponentPackedArray.bf │ ├── ComponentType.bf │ ├── Entity.bf │ ├── EntityArrayList.bf │ ├── EntityChunk.bf │ ├── EntityChunkList.bf │ ├── EntityCommandBuffer.bf │ ├── EntityManager.bf │ ├── EntityPool.bf │ ├── EntitySpec.bf │ ├── SpanExtensions.bf │ └── UnmanagedType.bf └── tests ├── Atma.Common.Tests └── BeefProj.toml ├── Atma.Entities.Tests └── BeefProj.toml ├── Atma.Math.Tests └── BeefProj.toml └── Atma.Systems.Tests ├── BeefProj.toml └── src ├── ComponentDataArrayTests.bf ├── ComponentPackedArrayTests.bf ├── EntityChunkTests.bf └── EntitySpecTests.bf /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /BeefSpace.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | Projects = {"Atma.Common" = {Path = "src/Atma.Common"}, "Atma.Entities" = {Path = "src/Atma.Entities"}, "Atma.Math" = {Path = "src/Atma.Math"}, MiniZ = "*", SDL2 = "*", "Atma.OpenGL" = {Path = "src/Atma.OpenGL"}, "Atma.SDL2" = {Path = "src/Atma.SDL2"}} 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GameEngine for BeefLang 2 | 3 | To try the sample program, open the workspace at `Atma.Framewor\samples` and try the `NeonShooter` project. 4 | 5 | This engine is very much work-in-progress and will have continious breaking changes for the time being. 6 | 7 | 8 | The current plan is to clean up the engine code and provide documentation. This clean up process will reorganize and create breaking changes but the samples should always work. 9 | 10 | . -------------------------------------------------------------------------------- /samples/BeefSpace.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | Projects = {NeonShooter = {Path = "NeonShooter"}, SDL2 = "*", MiniZ = "*", "Atma.Common" = {Path = "../src/Atma.Common"}, HelloWorld = {Path = "HelloWorld"}, "Atma.Entities" = {Path = "../src/Atma.Entities"}, ParticleSim = {Path = "ParticleSim"}} 3 | Unlocked = ["corlib"] 4 | 5 | [Workspace] 6 | StartupProject = "ParticleSim" 7 | -------------------------------------------------------------------------------- /samples/HelloWorld/BeefProj.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | Dependencies = {corlib = "*", "Atma.Common" = "*"} 3 | 4 | [Project] 5 | Name = "HelloWorld" 6 | StartupObject = "HelloWorld.Program" 7 | -------------------------------------------------------------------------------- /samples/HelloWorld/imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][Debug##Default] 2 | Pos=60,60 3 | Size=400,400 4 | Collapsed=0 5 | 6 | -------------------------------------------------------------------------------- /samples/HelloWorld/src/Program.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using Atma; 3 | 4 | namespace HelloWorld 5 | { 6 | class Program : Core 7 | { 8 | protected override void Initialize() 9 | { 10 | } 11 | 12 | protected override void Render() 13 | { 14 | 15 | //move the rect to the center of the screen 16 | var pos = (float2)Screen.Size / 2f; 17 | 18 | //Note: turn is 0-1 instead of 0 to 2pi 19 | //lets offset the rect in a circle motion 20 | pos += Calc.Turn(Time.Elapsedf / 4f) * 50; 21 | 22 | Core.Draw.Rect(aabb2.FromDimensions(pos, Screen.Size / 2), .White); 23 | Core.Draw.Render(Core.Window, Screen.Matrix); 24 | } 25 | 26 | protected override void Update() 27 | { 28 | } 29 | 30 | protected override void FixedUpdate() 31 | { 32 | } 33 | 34 | protected override void Unload() 35 | { 36 | } 37 | 38 | public static int Main(String[] args) 39 | { 40 | let game = scope Program("Hello World", 400, 300); 41 | return game.Run(); 42 | } 43 | 44 | public this(StringView title, int width, int height, Window.WindowFlags windowFlags = .Hidden) : base(title, width, height, windowFlags) 45 | { 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /samples/NeonShooter/BeefProj.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | Dependencies = {corlib = "*", "Atma.Common" = "*", "Atma.Entities" = "*"} 3 | 4 | [Project] 5 | Name = "NeonShooter" 6 | StartupObject = "NeonShooter.Program" 7 | 8 | [Configs.Debug.Win64] 9 | CLibType = "Static" 10 | -------------------------------------------------------------------------------- /samples/NeonShooter/content/fonts/PressStart2P.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/fonts/PressStart2P.ttf -------------------------------------------------------------------------------- /samples/NeonShooter/content/music/Music.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/music/Music.mp3 -------------------------------------------------------------------------------- /samples/NeonShooter/content/shaders/BloomCombine.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform sampler2D u_texture; 3 | uniform sampler2D u_bloom; 4 | 5 | uniform float BloomIntensity; 6 | uniform float BaseIntensity; 7 | uniform float BloomSaturation; 8 | uniform float BaseSaturation; 9 | 10 | in vec2 v_tex; 11 | out vec4 o_color; 12 | 13 | vec4 AdjustSaturation(vec4 color, float saturation) 14 | { 15 | // The constants 0.3, 0.59, and 0.11 are chosen because the 16 | // human eye is more sensitive to green light, and less to blue. 17 | float grey = dot(color.xyz, vec3(0.3, 0.59, 0.11)); 18 | 19 | return vec4(mix(vec3(grey), color.xyz, saturation), 1); 20 | } 21 | 22 | vec4 saturate(vec4 color) 23 | { 24 | return clamp(color, 0.0f, 1.0f); 25 | } 26 | 27 | void main(void) 28 | { 29 | 30 | // Look up the bloom and original base image colors. 31 | vec4 base = texture(u_texture, v_tex); 32 | vec4 bloom = texture(u_bloom, v_tex); 33 | 34 | // Adjust color saturation and intensity. 35 | bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity; 36 | base = AdjustSaturation(base, BaseSaturation) * BaseIntensity; 37 | 38 | // Darken down the base image in areas where there is a lot of bloom, 39 | // to prevent things looking excessively burned-out. 40 | base *= (1 - saturate(bloom)); 41 | 42 | // Combine the two images. 43 | o_color = base + bloom; 44 | 45 | } -------------------------------------------------------------------------------- /samples/NeonShooter/content/shaders/BloomCombine.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform mat4 u_matrix; 3 | layout(location=0) in vec2 a_position; 4 | layout(location=1) in vec2 a_tex; 5 | out vec2 v_tex; 6 | 7 | void main(void) 8 | { 9 | gl_Position = u_matrix * vec4(a_position.xy, 0, 1); 10 | v_tex = a_tex; 11 | } 12 | -------------------------------------------------------------------------------- /samples/NeonShooter/content/shaders/BloomExtract.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform sampler2D u_texture; 3 | uniform float u_bloomThreshold; 4 | 5 | in vec2 v_tex; 6 | out vec4 o_color; 7 | 8 | vec4 saturate(vec4 color) 9 | { 10 | return clamp(color, 0.0f, 1.0f); 11 | } 12 | 13 | void main(void) 14 | { 15 | vec2 tex = vec2(v_tex.x, v_tex.y); 16 | vec4 color = texture(u_texture, tex); 17 | 18 | // Adjust it to keep only values brighter than the specified threshold. 19 | o_color = saturate((color - u_bloomThreshold) / (1 - u_bloomThreshold)); 20 | } -------------------------------------------------------------------------------- /samples/NeonShooter/content/shaders/BloomExtract.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform mat4 u_matrix; 3 | layout(location=0) in vec2 a_position; 4 | layout(location=1) in vec2 a_tex; 5 | out vec2 v_tex; 6 | void main(void) 7 | { 8 | gl_Position = u_matrix * vec4(a_position.xy, 0, 1); 9 | v_tex = a_tex; 10 | } 11 | -------------------------------------------------------------------------------- /samples/NeonShooter/content/shaders/GaussianBlur.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | #define SAMPLE_COUNT 15 3 | 4 | uniform sampler2D u_texture; 5 | 6 | uniform vec2 u_sampleOffsets[SAMPLE_COUNT]; 7 | uniform float u_sampleWeights[SAMPLE_COUNT]; 8 | 9 | in vec2 v_tex; 10 | out vec4 o_color; 11 | 12 | void main(void) 13 | { 14 | vec4 c = vec4(0,0,0,0); 15 | // Combine a number of weighted image filter taps. 16 | for (int i = 0; i < SAMPLE_COUNT; i++) 17 | { 18 | c += texture(u_texture, v_tex + u_sampleOffsets[i]) * u_sampleWeights[i]; 19 | } 20 | 21 | o_color = c; 22 | } -------------------------------------------------------------------------------- /samples/NeonShooter/content/shaders/GaussianBlur.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform mat4 u_matrix; 3 | layout(location=0) in vec2 a_position; 4 | layout(location=1) in vec2 a_tex; 5 | out vec2 v_tex; 6 | void main(void) 7 | { 8 | gl_Position = u_matrix * vec4(a_position.xy, 0, 1); 9 | v_tex = a_tex; 10 | } 11 | -------------------------------------------------------------------------------- /samples/NeonShooter/content/shaders/Vignette.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform sampler2D u_texture; 3 | uniform float u_power ; 4 | uniform float u_radius ; 5 | uniform vec2 u_resolution; 6 | 7 | in vec2 v_tex; 8 | out vec4 o_color; 9 | void main(void) 10 | { 11 | vec2 uv = gl_FragCoord.xy / u_resolution; 12 | 13 | uv *= 1.0 - uv.yx; 14 | 15 | float vig = uv.x*uv.y * u_power; // multiply with sth for intensity 16 | float t = 1 - pow(vig, u_radius); // change pow for modifying the extend of the vignette 17 | 18 | vec4 tcolor = texture(u_texture, v_tex); 19 | vec4 vcolor = vec4(0,0,0,1); 20 | 21 | o_color = mix(tcolor, vcolor, t); 22 | } -------------------------------------------------------------------------------- /samples/NeonShooter/content/shaders/Vignette.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform mat4 u_matrix; 3 | layout(location=0) in vec2 a_position; 4 | layout(location=1) in vec2 a_tex; 5 | 6 | out vec2 v_tex; 7 | 8 | void main(void) 9 | { 10 | vec4 p = u_matrix * vec4(a_position.xy, 0, 1); 11 | gl_Position = p; 12 | v_tex = a_tex; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /samples/NeonShooter/content/shaders/sprite.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform sampler2D u_texture; 3 | in vec2 v_tex; 4 | in vec4 v_col; 5 | in vec3 v_type; 6 | out vec4 o_color; 7 | void main(void) 8 | { 9 | vec4 color = texture(u_texture, v_tex); 10 | o_color = 11 | v_type.x * color * v_col + 12 | v_type.y * color.a * v_col + 13 | v_type.z * v_col; 14 | 15 | //o_color = color; 16 | } -------------------------------------------------------------------------------- /samples/NeonShooter/content/shaders/sprite.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform mat4 u_matrix; 3 | layout(location=0) in vec2 a_position; 4 | layout(location=1) in vec2 a_tex; 5 | layout(location=2) in vec4 a_color; 6 | layout(location=3) in vec3 a_type; 7 | out vec2 v_tex; 8 | out vec4 v_col; 9 | out vec3 v_type; 10 | void main(void) 11 | { 12 | gl_Position = u_matrix * vec4(a_position.xy, 0, 1); 13 | v_tex = a_tex; 14 | v_col = a_color; 15 | v_type = a_type; 16 | } 17 | -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/explosion-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/explosion-01.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/explosion-02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/explosion-02.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/explosion-03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/explosion-03.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/explosion-04.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/explosion-04.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/explosion-05.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/explosion-05.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/explosion-06.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/explosion-06.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/explosion-07.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/explosion-07.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/explosion-08.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/explosion-08.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/shoot-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/shoot-01.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/shoot-02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/shoot-02.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/shoot-03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/shoot-03.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/shoot-04.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/shoot-04.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/spawn-01.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/spawn-01.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/spawn-02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/spawn-02.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/spawn-03.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/spawn-03.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/spawn-04.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/spawn-04.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/spawn-05.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/spawn-05.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/spawn-06.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/spawn-06.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/spawn-07.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/spawn-07.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/sounds/spawn-08.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/sounds/spawn-08.wav -------------------------------------------------------------------------------- /samples/NeonShooter/content/textures/BlackHole.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/textures/BlackHole.png -------------------------------------------------------------------------------- /samples/NeonShooter/content/textures/Bullet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/textures/Bullet.png -------------------------------------------------------------------------------- /samples/NeonShooter/content/textures/Glow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/textures/Glow.png -------------------------------------------------------------------------------- /samples/NeonShooter/content/textures/Laser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/textures/Laser.png -------------------------------------------------------------------------------- /samples/NeonShooter/content/textures/Player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/textures/Player.png -------------------------------------------------------------------------------- /samples/NeonShooter/content/textures/Pointer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/textures/Pointer.png -------------------------------------------------------------------------------- /samples/NeonShooter/content/textures/Seeker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/textures/Seeker.png -------------------------------------------------------------------------------- /samples/NeonShooter/content/textures/Wanderer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/textures/Wanderer.png -------------------------------------------------------------------------------- /samples/NeonShooter/content/textures/shipa.aseprite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/samples/NeonShooter/content/textures/shipa.aseprite -------------------------------------------------------------------------------- /samples/NeonShooter/imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][Debug##Default] 2 | Pos=184,8 3 | Size=401,400 4 | Collapsed=1 5 | 6 | [Window][Dear ImGui Demo] 7 | Pos=663,7 8 | Size=447,688 9 | Collapsed=1 10 | 11 | [Window][Dear ImGui Metrics] 12 | Pos=60,60 13 | Size=338,256 14 | Collapsed=0 15 | 16 | [Window][Render List] 17 | Pos=60,60 18 | Size=339,533 19 | Collapsed=0 20 | 21 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/Components/PlayerCamera.bf: -------------------------------------------------------------------------------- 1 | using Atma; 2 | namespace NeonShooter.Components 3 | { 4 | public class PlayerCamera : Component 5 | { 6 | public float2 WorldTarget; 7 | 8 | public this() : base(true) 9 | { 10 | } 11 | 12 | public override void FixedUpdate() 13 | { 14 | let camera = Scene.Camera; 15 | //let cameraEntity = camera.Entity; 16 | 17 | //cameraEntity.Position = this.Entity.Position; 18 | WorldTarget = camera.ScreenToWorld(Core.Input.MousePosition); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/Components/PlayerStatus.bf: -------------------------------------------------------------------------------- 1 | using Atma; 2 | using System; 3 | using NeonShooter.Entities; 4 | namespace NeonShooter.Components 5 | { 6 | public class PlayerStatus : Component 7 | { 8 | // amount of time it takes, in seconds, for a multiplier to expire. 9 | private const float multiplierExpiryTime = 0.8f; 10 | private const int maxMultiplier = 20; 11 | 12 | public int Lives; 13 | public int Score; 14 | public int Multiplier; 15 | 16 | private float multiplierTimeLeft;// time until the current multiplier expires 17 | public int scoreForExtraLife;// score required to gain an extra life 18 | 19 | 20 | public bool IsGameOver => Lives <= 0; 21 | 22 | public int HighScore = 0; 23 | 24 | // Static constructor 25 | public this() : base(true, true) 26 | { 27 | Reset(); 28 | } 29 | 30 | public void Reset() 31 | { 32 | if (Score > HighScore) 33 | HighScore = Score; 34 | 35 | Score = 0; 36 | Multiplier = 1; 37 | Lives = 4; 38 | scoreForExtraLife = 20000; 39 | multiplierTimeLeft = 0; 40 | } 41 | 42 | public override void FixedUpdate() 43 | { 44 | if (Multiplier > 1) 45 | { 46 | // update the multiplier timer 47 | if ((multiplierTimeLeft -= Time.Delta) <= 0) 48 | { 49 | multiplierTimeLeft = multiplierExpiryTime; 50 | ResetMultiplier(); 51 | } 52 | } 53 | } 54 | 55 | public void AddPoints(int basePoints) 56 | { 57 | let player = Entity as Player; 58 | if (player?.IsDead == true) 59 | return; 60 | 61 | Score += basePoints * Multiplier; 62 | while (Score >= scoreForExtraLife) 63 | { 64 | scoreForExtraLife += scoreForExtraLife * 3 / 2; 65 | Lives++; 66 | } 67 | } 68 | 69 | public void IncreaseMultiplier(int amount = 1) 70 | { 71 | let player = Entity as Player; 72 | if (player.IsDead == true) 73 | return; 74 | 75 | multiplierTimeLeft = multiplierExpiryTime; 76 | Multiplier = Math.Min(Multiplier + amount, maxMultiplier); 77 | } 78 | 79 | public void ResetMultiplier() 80 | { 81 | Multiplier = 1; 82 | } 83 | 84 | public void RemoveLife() 85 | { 86 | Lives--; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/Core.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public extension Core 4 | { 5 | static this() 6 | { 7 | Core.Emitter.AddObserver(new => Initialize); 8 | } 9 | 10 | static ~this() 11 | { 12 | Core.Emitter.RemoveObserver(scope => Initialize); 13 | } 14 | 15 | static void Initialize(CoreEvents.Initialize e) 16 | { 17 | DefaultFont = Core.Assets.LoadFont(@"fonts/PressStart2P.ttf", 16); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/Entities/Bullet.bf: -------------------------------------------------------------------------------- 1 | using Atma; 2 | using NeonShooter.Components; 3 | namespace NeonShooter.Entities 4 | { 5 | public class Bullet : Entity 6 | { 7 | private Sprite sprite; 8 | 9 | public this(float2 position, float2 velocity) 10 | { 11 | sprite = Components.Add(new Sprite(Core.Atlas["main/Bullet"])); 12 | 13 | Velocity = velocity; 14 | Rotation = Calc.Turn(Velocity); 15 | Position = position; 16 | } 17 | 18 | protected override void OnFixedUpdate() 19 | { 20 | base.OnFixedUpdate(); 21 | 22 | if (!this.Scene.Camera.WorldBounds.Intersects(WorldPosition)) 23 | { 24 | let scene = this.Scene as NeonGame; 25 | let particles = scene.Particles; 26 | let line = Core.Atlas["main/Laser"]; 27 | let position = WorldPosition; 28 | for (int i = 0; i < 30; i++) 29 | { 30 | let state = ParticleState(Calc.Turn(Core.Random.nextFloat()) * Core.Random.nextFloat(0, 9), .Bullet, 1); 31 | particles.CreateParticle(line, position, Color.CornflowerBlue, 50, float2(1), state, Calc.Turn(state.Velocity)); 32 | } 33 | 34 | this.Destroy(); 35 | } 36 | else 37 | { 38 | let scene = this.Scene as NeonGame; 39 | 40 | Position += Velocity; 41 | 42 | if (Velocity.LengthSqr > 0) 43 | { 44 | scene.Grid.ApplyExplosiveForce(0.5f * Velocity.Length, Position, 80); 45 | Rotation = Calc.Turn(Velocity.NormalizedSafe); 46 | } 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/Entities/Enemy.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using Atma; 3 | using NeonShooter.Components; 4 | using System.Collections; 5 | 6 | namespace NeonShooter.Entities 7 | { 8 | public abstract class Enemy : Entity 9 | { 10 | private int timeUntilStart = 60; 11 | public bool IsActive { get { return timeUntilStart <= 0; } } 12 | public int PointValue; 13 | 14 | protected Sprite sprite; 15 | 16 | public this(Subtexture texture, float2 position, int points) 17 | { 18 | PointValue = points; 19 | sprite = Components.Add(new Sprite(texture)); 20 | Radius = sprite.Width / 2f; 21 | Position = position; 22 | 23 | sprite.Tint = .Transparent; 24 | } 25 | 26 | protected override void OnFixedUpdate() 27 | { 28 | base.OnFixedUpdate(); 29 | 30 | if (timeUntilStart <= 0) 31 | { 32 | Logic(); 33 | } 34 | else 35 | { 36 | timeUntilStart--; 37 | sprite.Tint = Color.White * (1 - timeUntilStart / 60f); 38 | } 39 | 40 | Position += Velocity; 41 | 42 | var bounds = this.Scene.Camera.WorldBounds.Inflate(-sprite.Width, -sprite.Height); 43 | if (!bounds.Contains(WorldPosition)) 44 | TouchedWall(bounds); 45 | 46 | Position = float2.Clamp(Position, sprite.Size / 2, Screen.Size - sprite.Size / 2); 47 | Velocity *= 0.8f; 48 | } 49 | 50 | public abstract void Logic(); 51 | 52 | public virtual void WasShot() 53 | { 54 | if (!IsDestroying) 55 | { 56 | let player = this.EntityList.FindFirstByType(); 57 | let scene = this.Scene as NeonGame; 58 | float hue1 = Core.Random.nextFloat(0, 6); 59 | float hue2 = (hue1 + Core.Random.nextFloat(0, 2)) % 6f; 60 | Color color1 = Color.HSVToColor(hue1, 0.5f, 1); 61 | Color color2 = Color.HSVToColor(hue2, 0.5f, 1); 62 | 63 | let position = WorldPosition; 64 | for (int i = 0; i < 120; i++) 65 | { 66 | float speed = 18f * (1f - 1 / Core.Random.nextFloat(1f, 10f)); 67 | var state = ParticleState(Calc.Turn(Core.Random.nextFloat()) * speed, .Enemy, 1); 68 | let color = Color.Lerp(color1, color2, Core.Random.nextFloat()); 69 | scene.Particles?.CreateParticle(Core.Atlas["main/Laser"], position, color, 190, float2(1.5f), state, Calc.Turn(state.Velocity)); 70 | } 71 | 72 | if (PointValue > 0) 73 | { 74 | player?.status.AddPoints(PointValue); 75 | player?.status.IncreaseMultiplier(); 76 | } 77 | 78 | let sound = scene.Explosion; 79 | sound.Play(0.5f, Core.Random.nextFloat(-0.2f, 0.2f), 0); 80 | 81 | Destroy(); 82 | } 83 | } 84 | 85 | public void HandleCollision(Enemy other) 86 | { 87 | if (!IsDestroying) 88 | { 89 | var d = Position - other.Position; 90 | Velocity += 10 * d / (d.LengthSqr + 1); 91 | } 92 | } 93 | 94 | public virtual void TouchedWall(aabb2 bounds) { } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/Entities/Entity.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public extension Entity 4 | { 5 | public float2 Velocity; 6 | public float Radius = 8; 7 | 8 | public static bool IsColliding(Entity a, Entity b) 9 | { 10 | if (a == b) return false; 11 | float radius = a.Radius + b.Radius; 12 | return (a.WorldPosition - b.WorldPosition).LengthSqr < radius * radius; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/Entities/Seeker.bf: -------------------------------------------------------------------------------- 1 | using Atma; 2 | namespace NeonShooter.Entities 3 | { 4 | public class Seeker : Enemy 5 | { 6 | private Player player; 7 | 8 | public this(float2 position) : base(Core.Atlas["main/Seeker"], position, 10) 9 | { 10 | } 11 | 12 | protected override void OnReady() 13 | { 14 | base.OnReady(); 15 | player = Scene.Entities.FindFirstByType(); 16 | } 17 | 18 | public override void Logic() 19 | { 20 | Velocity += (player.WorldPosition - WorldPosition).Limit(1f); 21 | if (Velocity.LengthSqr > 0) 22 | Rotation = Calc.Turn(Velocity); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/Entities/Wanderer.bf: -------------------------------------------------------------------------------- 1 | using Atma; 2 | using System; 3 | 4 | namespace NeonShooter.Entities 5 | { 6 | public class Wanderer : Enemy 7 | { 8 | private float direction; 9 | private int state = 0; 10 | 11 | public this(float2 position) : base(Core.Atlas["main/Wanderer"], position, 5) 12 | { 13 | direction = gRand.nextFloat(0, 1); 14 | } 15 | 16 | public override void Logic() 17 | { 18 | if (state == 0) 19 | direction += gRand.nextFloat(-0.01f, 0.01f); 20 | 21 | Velocity += Calc.Turn(direction).Limit(0.4f); 22 | Rotation -= 0.05f; 23 | 24 | if (state++ > 6) 25 | state = 0; 26 | } 27 | 28 | public override void TouchedWall(aabb2 bounds) 29 | { 30 | var vdir = Calc.Turn(direction); 31 | 32 | // if the enemy is outside the bounds, make it move away from the edge 33 | if (WorldPosition.x < bounds.x0) 34 | vdir.x = Math.Abs(vdir.x); 35 | else if (WorldPosition.x > bounds.x1) 36 | vdir.x = -Math.Abs(vdir.x); 37 | 38 | if (WorldPosition.y < bounds.y0) 39 | vdir.y = Math.Abs(vdir.y); 40 | else if (WorldPosition.y > bounds.y1) 41 | vdir.y = -Math.Abs(vdir.y); 42 | 43 | direction = Calc.Turn(vdir); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/PostEffects/BloomCombineEffect.bf: -------------------------------------------------------------------------------- 1 | using Atma; 2 | namespace NeonShooter.PostEffects 3 | { 4 | public class BloomCombineEffect : PostEffect 5 | { 6 | private Material _material ~ delete _; 7 | public readonly MaterialParam BloomTexture ~ delete _; 8 | public readonly MaterialParam BloomIntensity ~ delete _; 9 | public readonly MaterialParam BaseIntensity ~ delete _; 10 | public readonly MaterialParam BloomSaturation ~ delete _; 11 | public readonly MaterialParam BaseSaturation ~ delete _; 12 | 13 | protected override Material ShaderMaterial => _material; 14 | 15 | public this() 16 | { 17 | _material = new .(Core.Assets.LoadShader("shaders/bloomcombine")); 18 | BloomIntensity = new .(_material, "BloomIntensity"); 19 | BaseIntensity = new .(_material, "BaseIntensity"); 20 | BloomSaturation = new .(_material, "BloomSaturation"); 21 | BaseSaturation = new .(_material, "BaseSaturation"); 22 | BloomTexture = new .(_material, "u_bloom"); 23 | 24 | BloomIntensity.Value = 1.25f; 25 | BaseIntensity.Value = 1f; 26 | BloomSaturation.Value = 1f; 27 | BaseSaturation.Value = 1f; 28 | } 29 | 30 | public override void Render(Texture source, RenderTexture destination) 31 | { 32 | base.Render(source, destination); 33 | } 34 | 35 | protected override void OnInspect() 36 | { 37 | base.OnInspect(); 38 | BloomIntensity.Inspect(0, 5); 39 | BaseIntensity.Inspect(0, 5); 40 | BloomSaturation.Inspect(0, 5); 41 | BaseSaturation.Inspect(0, 5); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/PostEffects/BloomExtractEffect.bf: -------------------------------------------------------------------------------- 1 | using Atma; 2 | 3 | namespace NeonShooter.PostEffects 4 | { 5 | public class BloomExtractEffect : PostEffect 6 | { 7 | private Material _material ~ delete _; 8 | public readonly MaterialParam BloomThreshold ~ delete _; 9 | 10 | protected override Material ShaderMaterial => _material; 11 | 12 | public this() 13 | { 14 | _material = new .(Core.Assets.LoadShader("shaders/bloomextract")); 15 | BloomThreshold = new .(_material, "u_bloomThreshold"); 16 | 17 | BloomThreshold.Value = 0.5f; 18 | } 19 | 20 | protected override void OnInspect() 21 | { 22 | base.OnInspect(); 23 | BloomThreshold.Inspect(0, 1); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/PostEffects/VignetteEffect.bf: -------------------------------------------------------------------------------- 1 | using Atma; 2 | //TODO IMGUI using ImGui; 3 | 4 | namespace NeonShooter.PostEffects 5 | { 6 | public class VignetteEffect : PostEffect 7 | { 8 | private Material material ~ delete _; 9 | 10 | protected override Material ShaderMaterial => material; 11 | 12 | public readonly MaterialParam Power ~ delete _; 13 | public readonly MaterialParam Radius ~ delete _; 14 | public readonly MaterialParam Resolution ~ delete _; 15 | 16 | public this() 17 | { 18 | material = new .(Core.Assets.LoadShader("shaders/vignette")); 19 | Power = new .(material, "u_power"); 20 | Radius = new .(material, "u_radius"); 21 | Resolution = new .(material, "u_resolution"); 22 | 23 | Power.Value = 25; 24 | Radius.Value = 0.15f; 25 | } 26 | 27 | protected override void OnInspect() 28 | { 29 | base.OnInspect(); 30 | Power.Inspect(0, 100); 31 | Radius.Inspect(0, 1); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/PostProcessors/Vignette.bf: -------------------------------------------------------------------------------- 1 | using Atma; 2 | using NeonShooter.PostEffects; 3 | 4 | namespace NeonShooter.PostProcessors 5 | { 6 | public class Vignette : PostProcessor 7 | { 8 | public this() 9 | { 10 | } 11 | 12 | protected override void OnProcess(Texture source, RenderTexture destination) 13 | { 14 | _effect.Resolution.Value = destination.Size; 15 | base.OnProcess(source, destination); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /samples/NeonShooter/src/Program.bf: -------------------------------------------------------------------------------- 1 | namespace NeonShooter 2 | { 3 | using System; 4 | using Atma; 5 | using System.Collections; 6 | 7 | public static class Program 8 | { 9 | static public int Main(String[] args) 10 | { 11 | return Core.RunInitialScene("NeonShooter", 1280, 760); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /samples/ParticleSim/BeefProj.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | Dependencies = {corlib = "*", "Atma.Common" = "*"} 3 | 4 | [Project] 5 | Name = "ParticleSim" 6 | StartupObject = "ParticleSim.Program" 7 | -------------------------------------------------------------------------------- /samples/ParticleSim/imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][Debug##Default] 2 | Pos=60,60 3 | Size=400,400 4 | Collapsed=0 5 | 6 | -------------------------------------------------------------------------------- /src/Atma.Common/BeefProj.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | Dependencies = {corlib = "*", corlib = "*", MiniZ = "*", SDL2 = "*"} 3 | 4 | [Project] 5 | Name = "Atma.Common" 6 | TargetType = "BeefLib" 7 | StartupObject = "Atma.Common.Program" 8 | DefaultNamespace = "Atma" 9 | 10 | [Configs.Debug.Win64] 11 | CLibType = "Dynamic" 12 | LibPaths = ["$(ProjectDir)/dist/$(Configuration)-$(Platform)/cimgui.lib"] 13 | 14 | [Configs.Debug.Win32] 15 | LibPaths = ["$(ProjectDir)/dist/$(Configuration)-$(Platform)/cimgui.lib"] 16 | 17 | [Configs.Release.Win64] 18 | LibPaths = ["$(ProjectDir)/dist/$(Configuration)-$(Platform)/cimgui.lib"] 19 | 20 | [Configs.Release.Win32] 21 | LibPaths = ["$(ProjectDir)/dist/$(Configuration)-$(Platform)/cimgui.lib"] 22 | 23 | [Configs.Paranoid.Win32] 24 | LibPaths = ["$(ProjectDir)/dist/$(Configuration)-$(Platform)/cimgui.lib"] 25 | 26 | [Configs.Paranoid.Win64] 27 | LibPaths = ["$(ProjectDir)/dist/$(Configuration)-$(Platform)/cimgui.lib"] 28 | 29 | [Configs.Test.Win32] 30 | LibPaths = ["$(ProjectDir)/dist/$(Configuration)-$(Platform)/cimgui.lib"] 31 | 32 | [Configs.Test.Win64] 33 | LibPaths = ["$(ProjectDir)/dist/$(Configuration)-$(Platform)/cimgui.lib"] 34 | -------------------------------------------------------------------------------- /src/Atma.Common/dist/Debug-Linux64/cimgui.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/src/Atma.Common/dist/Debug-Linux64/cimgui.a -------------------------------------------------------------------------------- /src/Atma.Common/dist/Debug-Win64/cimgui.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/src/Atma.Common/dist/Debug-Win64/cimgui.lib -------------------------------------------------------------------------------- /src/Atma.Common/dist/Debug-macOS/cimgui.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/src/Atma.Common/dist/Debug-macOS/cimgui.a -------------------------------------------------------------------------------- /src/Atma.Common/dist/Release-Linux64/cimgui.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/src/Atma.Common/dist/Release-Linux64/cimgui.a -------------------------------------------------------------------------------- /src/Atma.Common/dist/Release-Win64/cimgui.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/src/Atma.Common/dist/Release-Win64/cimgui.lib -------------------------------------------------------------------------------- /src/Atma.Common/dist/Release-macOS/cimgui.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/src/Atma.Common/dist/Release-macOS/cimgui.a -------------------------------------------------------------------------------- /src/Atma.Common/dist/Test-Win64/cimgui.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/src/Atma.Common/dist/Test-Win64/cimgui.lib -------------------------------------------------------------------------------- /src/Atma.Common/generator/Atma.Math.Generator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | false 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Members/AggregatedProperty.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Types; 7 | 8 | namespace Atma.Math.Members 9 | { 10 | class AggregatedProperty : Property 11 | { 12 | public AggregatedProperty(IEnumerable fields, string name, AbstractType type, string sep, string comment) : base(name, type) 13 | { 14 | GetterLine = fields.Aggregated(" " + sep + " "); 15 | Comment = comment; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Members/Constructor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Types; 7 | 8 | namespace Atma.Math.Members 9 | { 10 | class Constructor : Member 11 | { 12 | /// 13 | /// Constructor type 14 | /// 15 | public AbstractType Type { get; set; } 16 | 17 | /// 18 | /// ctor parameters 19 | /// 20 | public IEnumerable Parameters { get; set; } 21 | 22 | /// 23 | /// Single parameter 24 | /// 25 | public string ParameterString { set { Parameters = new[] { value }; } } 26 | 27 | /// 28 | /// Constructor chain 29 | /// 30 | public string ConstructorChain { get; set; } 31 | 32 | /// 33 | /// Fields to initialize 34 | /// 35 | public IEnumerable Fields { get; set; } 36 | 37 | /// 38 | /// Initializer ienumerable 39 | /// 40 | public IEnumerable Initializers { get; set; } 41 | 42 | public IEnumerable Code { get; set; } 43 | 44 | public override IEnumerable Lines 45 | { 46 | get 47 | { 48 | foreach (var line in base.Lines) 49 | yield return line; 50 | 51 | yield return $"{MemberPrefix} this({Parameters.CommaSeparated()})"; 52 | if (!string.IsNullOrEmpty(ConstructorChain)) 53 | yield return (": " + ConstructorChain).Indent(); 54 | yield return "{"; 55 | if (Code != null) 56 | foreach (var code in Code) 57 | yield return code.Indent(); 58 | if (string.IsNullOrEmpty(ConstructorChain)) 59 | { 60 | var it = Initializers.GetEnumerator(); 61 | var initializer = Fields.Select(x => (it.MoveNext() ? it.Current : Type.ZeroValue)); 62 | yield return $"values = .({string.Join(",", initializer)});".Indent(); 63 | 64 | // foreach (var c in Fields) 65 | // yield return $"this.{c} = {(it.MoveNext() ? it.Current : Type.ZeroValue)};".Indent(); 66 | } 67 | yield return "}"; 68 | } 69 | } 70 | 71 | public Constructor(AbstractType type, IEnumerable fields) 72 | { 73 | Fields = fields; 74 | Type = type; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Members/ExplicitOperator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Types; 7 | 8 | namespace Atma.Math.Members 9 | { 10 | class ExplicitOperator : Function 11 | { 12 | public override string MemberPrefix => base.MemberPrefix + " explicit"; 13 | public override string FunctionName => ReturnType.NameThat; 14 | public override string ReturnName => "operator"; 15 | 16 | public ExplicitOperator(AbstractType type) : base(type, type.Name) 17 | { 18 | Static = true; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Members/Field.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Types; 7 | 8 | namespace Atma.Math.Members 9 | { 10 | class Field : Member 11 | { 12 | /// 13 | /// Member type 14 | /// 15 | public AbstractType Type { get; set; } 16 | 17 | /// 18 | /// True iff field is readonly 19 | /// 20 | public bool Readonly { get; set; } 21 | 22 | public override string MemberPrefix => base.MemberPrefix + (Readonly ? " readonly" : ""); 23 | 24 | public override IEnumerable Lines 25 | { 26 | get 27 | { 28 | foreach (var line in base.Lines) 29 | yield return line; 30 | 31 | yield return $"{MemberPrefix} {Type.NameThat} {Name};"; 32 | } 33 | } 34 | 35 | public Field(string name, AbstractType type) 36 | { 37 | Name = name; 38 | Type = type; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Members/ImplicitOperator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Types; 7 | 8 | namespace Atma.Math.Members 9 | { 10 | class ImplicitOperator : Function 11 | { 12 | public override string MemberPrefix => base.MemberPrefix + " implicit"; 13 | public override string FunctionName => ReturnType.NameThat; 14 | public override string ReturnName => "operator"; 15 | 16 | public ImplicitOperator(AbstractType type) : base(type, type.Name) 17 | { 18 | Static = true; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Members/Member.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Types; 7 | 8 | namespace Atma.Math.Members 9 | { 10 | abstract class Member 11 | { 12 | /// 13 | /// Original type ref 14 | /// 15 | public AbstractType OriginalType { get; set; } 16 | 17 | /// 18 | /// Name of the member 19 | /// 20 | public string Name { get; set; } 21 | 22 | /// 23 | /// Comment of the member 24 | /// 25 | public string Comment { get; set; } 26 | 27 | /// 28 | /// Visibility modifier 29 | /// 30 | public string Visibility { get; set; } = "public"; 31 | 32 | /// 33 | /// True iff member is static 34 | /// 35 | public bool Static { get; set; } 36 | 37 | /// 38 | /// Attributes of this member 39 | /// 40 | //public string[] Attributes { get; set; } = new string[] { }; 41 | public virtual IEnumerable Attributes 42 | { 43 | get 44 | { 45 | if (Inline) 46 | yield return "Inline"; 47 | } 48 | } 49 | 50 | public bool Inline { get; set; } = false; 51 | 52 | /// 53 | /// All lines of this member 54 | /// 55 | public virtual IEnumerable Lines 56 | { 57 | get 58 | { 59 | foreach (var line in Comment.AsComment()) 60 | yield return line; 61 | foreach (var attribute in Attributes) 62 | yield return $"[{attribute}]"; 63 | } 64 | } 65 | 66 | /// 67 | /// Prefix for members (visibility, static) 68 | /// 69 | public virtual string MemberPrefix => Visibility + (Static ? " static" : ""); 70 | 71 | 72 | /// 73 | /// Returns an enumeration of members used for the "glm" class 74 | /// 75 | public virtual IEnumerable GlmMembers() { yield break; } 76 | 77 | 78 | public override string ToString() 79 | { 80 | return Comment; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Members/Operator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Types; 7 | 8 | namespace Atma.Math.Members 9 | { 10 | class Operator : Function 11 | { 12 | public Operator(AbstractType type, string op) : base(type, "operator" + op) 13 | { 14 | Static = true; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Members/StaticProperty.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Types; 7 | 8 | namespace Atma.Math.Members 9 | { 10 | class StaticProperty : Property 11 | { 12 | public StaticProperty(string name, AbstractType type) : base(name, type) 13 | { 14 | Static = true; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Tests/DistributionTestFunc.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Types; 7 | 8 | namespace Atma.Math.Tests 9 | { 10 | /// 11 | /// Random distribution tests 12 | /// 13 | class DistributionTestFunc : TestFunc 14 | { 15 | public DistributionTestFunc(VectorType type, string name, string randomFuncName, string funcArgs, double avg, double variance) : base(type, name) 16 | { 17 | var dtype = new VectorType(BuiltinType.TypeDouble, type.Components); 18 | 19 | var code = new List(); 20 | 21 | code.Add($"var random = new Random({AbstractType.Random.Next()});"); 22 | code.Add($"var sum = {dtype.Construct(dtype, dtype.ZeroValue)};"); 23 | code.Add($"var sumSqr = {dtype.Construct(dtype, dtype.ZeroValue)};"); 24 | 25 | code.Add(""); 26 | code.Add("const int count = 50000;"); 27 | code.Add("for (var _ = 0; _ < count; ++_)"); 28 | code.Add("{"); 29 | code.Add($" var v = {type.Name}.{randomFuncName}(random{(string.IsNullOrEmpty(funcArgs) ? "" : ", " + funcArgs)});"); 30 | code.Add($" sum += ({dtype.Name})v;"); 31 | code.Add($" sumSqr += glm.Pow2(({dtype.Name})v);"); 32 | code.Add("}"); 33 | 34 | code.Add(""); 35 | code.Add("var avg = sum / (double)count;"); 36 | code.Add("var variance = sumSqr / (double)count - avg * avg;"); 37 | 38 | code.Add(""); 39 | for (var c = 0; c < type.Components; ++c) 40 | code.Add($"Assert.AreEqual(avg.{type.ArgOf(c)}, {avg}, 1.0);"); 41 | 42 | code.Add(""); 43 | for (var c = 0; c < type.Components; ++c) 44 | code.Add($"Assert.AreEqual(variance.{type.ArgOf(c)}, {variance}, 3.0);"); 45 | 46 | Code = code; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Tests/TestFunc.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Types; 7 | 8 | namespace Atma.Math.Tests 9 | { 10 | class TestFunc 11 | { 12 | public string Name { get; set; } 13 | public IEnumerable Code { get; set; } 14 | 15 | 16 | public TestFunc(AbstractType type, string name, params string[] code) 17 | : this(type, name, code as IEnumerable) 18 | { 19 | } 20 | public TestFunc(AbstractType type, string name, IEnumerable code) 21 | { 22 | type.ResetRandom(name.GetHashCode()); 23 | Name = name; 24 | Code = code.ToArray(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Types/AnyType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Members; 7 | 8 | namespace Atma.Math.Types 9 | { 10 | class AnyType : AbstractType 11 | { 12 | public AnyType(string name) 13 | { 14 | Name = name; 15 | } 16 | 17 | public override string Name { get; } 18 | 19 | public override string TypeComment 20 | { 21 | get { throw new NotSupportedException(); } 22 | } 23 | 24 | public override IEnumerable GenerateMembers() 25 | { 26 | throw new NotSupportedException(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Types/ArrayType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Members; 7 | 8 | namespace Atma.Math.Types 9 | { 10 | class ArrayType : AbstractType 11 | { 12 | /// 13 | /// Array suffix 14 | /// 15 | public string ArraySuffix { get; set; } 16 | 17 | public override string GenericSuffix => ""; // no suffix 18 | 19 | public ArrayType(BuiltinType type, string suffix = "[]") 20 | { 21 | BaseType = type; 22 | ArraySuffix = suffix; 23 | } 24 | 25 | public override string Name => BaseType.Name + ArraySuffix; 26 | 27 | public override string TypeComment 28 | { 29 | get { throw new NotSupportedException(); } 30 | } 31 | 32 | public override IEnumerable GenerateMembers() 33 | { 34 | throw new NotSupportedException(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Types/SwizzleType.Code.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Atma.Math.Members; 7 | 8 | namespace Atma.Math.Types 9 | { 10 | partial class SwizzleType 11 | { 12 | public override IEnumerable GenerateMembers() 13 | { 14 | // fields 15 | // yield return new Field("values", new ArrayType(BaseType, $"[{Components}]")) 16 | // { 17 | // Comment = $"component data" 18 | // }; 19 | foreach (var f in Fields) 20 | yield return new Field(f, BaseType) 21 | { 22 | Visibility = "private", 23 | Readonly = true, 24 | Comment = $"{f}-component" 25 | }; 26 | 27 | // // ctor 28 | // yield return new Constructor(this, Fields) 29 | // { 30 | // Visibility = "private", 31 | // Parameters = Fields.TypedArgs(BaseType), 32 | // Initializers = Fields, 33 | // Comment = $"Constructor for {Name}." 34 | // }; 35 | 36 | // properties 37 | foreach (var swizzle in Swizzle(0)) 38 | { 39 | var type = VectorTypeFor(swizzle.Length); 40 | 41 | // xyzw 42 | yield return new Property(swizzle, type) 43 | { 44 | GetterLine = Construct(type, swizzle.CommaSeparated()), 45 | Comment = $"Returns {VectorType.Name}.{swizzle} swizzling.", 46 | Inline = true 47 | 48 | }; 49 | 50 | // rgba 51 | yield return new Property(ToRgba(swizzle), type) 52 | { 53 | GetterLine = Construct(type, swizzle.CommaSeparated()), 54 | Comment = string.Format("Returns {0}.{1} swizzling (equivalent to {0}.{2}).", VectorType.Name, ToRgba(swizzle), swizzle), 55 | Inline = true 56 | }; 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Atma.Common/generator/Types/SwizzleType.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Atma.Math.Members; 4 | 5 | namespace Atma.Math.Types 6 | { 7 | partial class SwizzleType : AbstractType 8 | { 9 | public int Components { get; set; } 10 | 11 | public override string Name => BaseName + Components; 12 | 13 | public override string Namespace { get; } = Program.Namespace;//+ ".Swizzle"; 14 | 15 | public override string Folder => "Swizzle"; 16 | public override string DataContractArg { get; } = "(Namespace = \"swizzle\")"; 17 | 18 | public IEnumerable Fields => "xyzw".Substring(0, Components).Select(c => c.ToString()); 19 | 20 | public override string TypeComment => $"Temporary vector of type {BaseTypeName} with {Components} components, used for implementing swizzling for {VectorType.Name}."; 21 | 22 | /// 23 | /// Class name for tests 24 | /// 25 | public override string TestClassName => BaseTypeName.Capitalized() + Folder + VectorType.Folder + "Test"; 26 | 27 | /// 28 | /// Type for swizzling 29 | /// 30 | public VectorType VectorType => Types[BaseType.TypeName + Components] as VectorType; 31 | /// 32 | /// Type for swizzling 33 | /// 34 | public VectorType VectorTypeFor(int comps) => Types[BaseType.TypeName + comps] as VectorType; 35 | 36 | private IEnumerable Swizzle(int i) 37 | { 38 | if (i >= 4) 39 | { 40 | yield return ""; 41 | yield break; 42 | } 43 | 44 | if (i > 1) 45 | yield return ""; 46 | 47 | for (var a = 0; a < Components; ++a) 48 | foreach (var sw in Swizzle(i + 1)) 49 | yield return "xyzw"[a] + sw; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Collections/LookupList.bf: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | namespace Atma 3 | { 4 | typealias LookupList = LookupList; 5 | 6 | public class LookupList 7 | where bool : operator Key == Key 8 | { 9 | private List _indexLookup ~ Release(_); 10 | private List _data ~ Release(_); 11 | 12 | public int Count => _indexLookup.Count; 13 | 14 | public this(int initialSize = 8) 15 | { 16 | _indexLookup = new List(initialSize); 17 | _data = new List(initialSize); 18 | } 19 | 20 | public List.Enumerator AllKeys => _indexLookup.GetEnumerator(); 21 | public List.Enumerator AllObjects => _data.GetEnumerator(); 22 | 23 | public Value this[Key id] 24 | { 25 | get 26 | { 27 | var index = IndexOf(id); 28 | Assert.GreaterThanEqualTo(index, 0); 29 | 30 | return _data[index]; 31 | } 32 | set 33 | { 34 | var index = IndexOf(id); 35 | Assert.GreaterThanEqualTo(index, 0); 36 | 37 | _data[index] = value; 38 | } 39 | } 40 | 41 | public void Add(Key id, Value t) 42 | { 43 | _indexLookup.Add(id); 44 | _data.Add(t); 45 | } 46 | 47 | public int IndexOf(Key id) 48 | { 49 | for (var i = 0; i < _indexLookup.Count; i++) 50 | if (_indexLookup[i] == id) 51 | return i; 52 | 53 | return -1; 54 | } 55 | 56 | public bool TryGetValue(Key id, out Value t) 57 | { 58 | var index = IndexOf(id); 59 | if (index == -1) 60 | { 61 | t = default; 62 | return false; 63 | } 64 | 65 | t = _data[index]; 66 | return true; 67 | } 68 | 69 | public void Remove(Key id) 70 | { 71 | var index = IndexOf(id); 72 | Assert.GreaterThanEqualTo(index, 0); 73 | 74 | _indexLookup.RemoveAt(index); 75 | _data.RemoveAt(index); 76 | } 77 | 78 | public void RemoveFast(Key id) 79 | { 80 | var index = IndexOf(id); 81 | Assert.GreaterThanEqualTo(index, 0); 82 | 83 | _indexLookup.RemoveAtFast(index); 84 | _data.RemoveAtFast(index); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Collections/NativeList.bf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xposure/Atma.Framework/b687d0596a98aa1286a661d2188f70508dedbb5f/src/Atma.Common/src/Collections/NativeList.bf -------------------------------------------------------------------------------- /src/Atma.Common/src/Collections/SizedList.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public struct SizedList 4 | where SIZE : const int 5 | where T : struct 6 | { 7 | private int _count = 0; 8 | private T[SIZE] _data; 9 | 10 | public int Size => SIZE; 11 | 12 | public int Count => _count; 13 | 14 | public ref T this[int index] 15 | { 16 | get mut 17 | { 18 | Assert.IsTrue(index >= 0 && index < SIZE); 19 | return ref _data[index]; 20 | } 21 | } 22 | 23 | public void Add(T value) mut 24 | { 25 | Assert.IsTrue(_count < SIZE); 26 | _data[_count++] = value; 27 | } 28 | 29 | public T PopBack() mut 30 | { 31 | Assert.IsTrue(_count > 0); 32 | return _data[--_count]; 33 | } 34 | 35 | public void Clear() mut 36 | { 37 | _count = 0; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Collections/StringPool.bf: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System; 3 | namespace Atma 4 | { 5 | public class StringPool 6 | { 7 | private HashSet _pool = new .() ~ DeleteContainerAndItems!(_); 8 | 9 | public String Get(StringView str) 10 | { 11 | if (_pool.TryAdd(scope String(str), var ptr)) 12 | *ptr = new String(str); 13 | 14 | return *ptr; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Atma.Common/src/DearImGui/ImGuiHelper.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public extension float2 4 | { 5 | public static operator ImGui.Vec2(float2 it) => .(it.x, it.y); 6 | public static operator float2(ImGui.Vec2 it) => .(it.x, it.y); 7 | } 8 | 9 | public extension ImGui 10 | { 11 | /*public extension Vec2 12 | { 13 | public readonly static Vec2 Zero = .(0, 0); 14 | public readonly static Vec2 Ones = .(1, 1); 15 | public readonly static Vec2 OneZero = .(1, 0); 16 | public readonly static Vec2 ZeroOne = .(0, 1); 17 | public readonly static Vec2 NOneZero = .(-1, 0); 18 | } 19 | 20 | public extension Vec4 21 | { 22 | public readonly static Vec4 Zero = .(0, 0, 0, 0); 23 | public readonly static Vec4 Ones = .(1, 1, 1, 1); 24 | }*/ 25 | 26 | 27 | 28 | public static void Image(Atma.Subtexture texture, Atma.Color tint = .White) 29 | { 30 | let s = texture.Source.Size; 31 | let t0 = texture.TexCoords[0]; 32 | let t1 = texture.TexCoords[2]; 33 | 34 | if (texture.Texture != null) 35 | Image((.)texture.Texture.ID, .(s.x, s.y), .(t0.x, t0.y), .(t1.x, t1.y)); 36 | } 37 | 38 | public static void ColorEdit3(char8* label, ref Atma.Color color, ColorEditFlags flags = 0) 39 | { 40 | float[3] c = .(color.Rf, color.Gf, color.Bf); 41 | ColorEdit3(label, c, flags); 42 | color.Rf = c[0]; 43 | color.Gf = c[1]; 44 | color.Bf = c[2]; 45 | } 46 | 47 | public static void ColorEdit4(char8* label, ref Atma.Color color, ColorEditFlags flags = 0) 48 | { 49 | float[4] c = .(color.Rf, color.Gf, color.Bf, color.Af); 50 | ColorEdit4(label, c, flags); 51 | color.Rf = c[0]; 52 | color.Gf = c[1]; 53 | color.Bf = c[2]; 54 | color.Af = c[3]; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Atma.Common/src/DearImGui/ImGuiImplOpenGL3.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Atma 4 | { 5 | public static class ImGuiImplOpenGL3 6 | { 7 | private typealias char = char8; 8 | private typealias DrawData = ImGui.DrawData; 9 | 10 | [LinkName("gladLoadGL")] 11 | private static extern int GladLoadGL(); 12 | 13 | [LinkName("ImGui_ImplOpenGL3_CreateDeviceObjects")] 14 | private static extern bool CreateDeviceObjectsImpl(); 15 | public static bool CreateDeviceObjects() => CreateDeviceObjectsImpl(); 16 | 17 | [LinkName("ImGui_ImplOpenGL3_CreateFontsTexture")] 18 | private static extern bool CreateFontsTextureImpl(); 19 | public static bool CreateFontsTexture() => CreateFontsTextureImpl(); 20 | 21 | [LinkName("ImGui_ImplOpenGL3_DestroyDeviceObjects")] 22 | private static extern void DestroyDeviceObjectsImpl(); 23 | public static void DestroyDeviceObjects() => DestroyDeviceObjectsImpl(); 24 | 25 | [LinkName("ImGui_ImplOpenGL3_DestroyFontsTexture")] 26 | private static extern void DestroyFontsTextureImpl(); 27 | public static void DestroyFontsTexture() => DestroyFontsTextureImpl(); 28 | 29 | [LinkName("ImGui_ImplOpenGL3_Init")] 30 | private static extern bool InitImpl(char* glsl_version); 31 | public static bool Init(char* glsl_version = default) 32 | { 33 | GladLoadGL(); 34 | return InitImpl(glsl_version); 35 | } 36 | 37 | [LinkName("ImGui_ImplOpenGL3_NewFrame")] 38 | private static extern void NewFrameImpl(); 39 | public static void NewFrame() => NewFrameImpl(); 40 | 41 | [LinkName("ImGui_ImplOpenGL3_RenderDrawData")] 42 | private static extern void RenderDrawDataImpl(DrawData* draw_data); 43 | public static void RenderDrawData(DrawData* draw_data) => RenderDrawDataImpl(draw_data); 44 | 45 | [LinkName("ImGui_ImplOpenGL3_Shutdown")] 46 | private static extern void ShutdownImpl(); 47 | public static void Shutdown() => ShutdownImpl(); 48 | } 49 | } -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Images/Image.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace Atma 7 | { 8 | public class Image 9 | { 10 | private Color[] _pixels ~ delete _; 11 | private int _width, _height; 12 | 13 | public int Width => _width; 14 | public int Height => _height; 15 | 16 | public int2 Size => .(Width, Height); 17 | 18 | public int Count => _width * _height; 19 | 20 | public int BufferSize => sizeof(Color) * Count; 21 | 22 | public Span Pixels => _pixels; 23 | 24 | public Color* PixelsPtr => &_pixels[0]; 25 | 26 | public this(int2 size) : this(size.x, size.y) 27 | { 28 | } 29 | 30 | public this(int width, int height, Color color) : this(width, height) 31 | { 32 | for (var it in ref _pixels) 33 | it = color; 34 | } 35 | 36 | public this(int width, int height) 37 | { 38 | _width = width; 39 | _height = height; 40 | _pixels = new Color[width * height]; 41 | } 42 | 43 | 44 | public this(int width, int height, Color[] pixels) 45 | { 46 | _width = width; 47 | _height = height; 48 | _pixels = pixels; 49 | } 50 | 51 | public ref Color this[int index] 52 | { 53 | get 54 | { 55 | System.Diagnostics.Debug.Assert(index >= 0 && index < Count, "index was out of range"); 56 | return ref _pixels[index]; 57 | } 58 | } 59 | 60 | public ref Color this[int x, int y] 61 | { 62 | get 63 | { 64 | System.Diagnostics.Debug.Assert(x >= 0 && x < Width, "x was out of range"); 65 | System.Diagnostics.Debug.Assert(y >= 0 && y < Height, "y was out of range"); 66 | return ref _pixels[y * Width + x]; 67 | } 68 | } 69 | 70 | public void SetPixels(rect area, Color[] data) 71 | { 72 | for (var y < area.Height) 73 | for (var x < area.Width) 74 | this[x + area.X, y + area.Y] = data[y * area.Width + x]; 75 | } 76 | 77 | 78 | public void Premultiply() 79 | { 80 | for (var i < _pixels.Count) 81 | _pixels[i].Premultiply(); 82 | } 83 | 84 | public void Clear(Color clearColor) 85 | { 86 | for (var y < _height) 87 | for (var x < _width) 88 | _pixels[y * _width + x] = clearColor; 89 | } 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Enums/Clear.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | /// 4 | /// Clear Flags 5 | /// 6 | public enum Clear 7 | { 8 | None = 0, 9 | Color = 1, 10 | Depth = 2, 11 | Stencil = 4, 12 | All = 7 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Enums/CullMode.bf: -------------------------------------------------------------------------------- 1 | 2 | namespace Atma 3 | { 4 | /// 5 | /// Cull Modes 6 | /// 7 | public enum CullMode 8 | { 9 | None = 0, 10 | Front = 1, 11 | Back = 2, 12 | Both = 3 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Enums/DepthCompare.bf: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | namespace Atma 4 | { 5 | /// 6 | /// Compare Methods used during Rendering 7 | /// 8 | public enum DepthCompare 9 | { 10 | /// 11 | /// The Comparison is ignored 12 | /// 13 | None, 14 | 15 | /// 16 | /// The Comparison always passes. 17 | /// 18 | Always, 19 | 20 | /// 21 | /// The Comparison never passes. 22 | /// 23 | Never, 24 | 25 | /// 26 | /// Passes if the value is less than the stored value. 27 | /// 28 | Less, 29 | 30 | /// 31 | /// Passes if the value is equal to the stored value. 32 | /// 33 | Equal, 34 | 35 | /// 36 | /// Passes if the value is less than or equal to the stored value. 37 | /// 38 | LessOrEqual, 39 | 40 | /// 41 | /// Passes if the value is greater than the stored value. 42 | /// 43 | Greater, 44 | 45 | /// 46 | /// Passes if the value is not equal to the stored value. 47 | /// 48 | NotEqual, 49 | 50 | /// 51 | /// Passes if the value is greater than or equal to the stored value. 52 | /// 53 | GreaterOrEqual 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Enums/SpriteEffects.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public enum SpriteEffects 4 | { 5 | case None = 0; 6 | case Vert = 1; 7 | case Hort = 2; 8 | 9 | public static SpriteEffects Flip(bool flipX, bool flipY) => (flipX ? .Hort : .None) | (flipY ? .Vert : .None); 10 | 11 | public void Apply(ref float2[4] texCoordsIn, float2 t0, float2 t1, float2 t2, float2 t3) 12 | { 13 | /*switch(this){ 14 | case .None: 15 | texCoordsIn = texCoordsOut; 16 | case .Vert: 17 | texCo 18 | }*/ 19 | if (this == .None) 20 | { 21 | texCoordsIn[0] = t0; 22 | texCoordsIn[1] = t1; 23 | texCoordsIn[2] = t2; 24 | texCoordsIn[3] = t3; 25 | } 26 | else 27 | { 28 | if ((this & .Vert) == .Vert) 29 | { 30 | texCoordsIn[0].y = t3.y; 31 | texCoordsIn[1].y = t2.y; 32 | texCoordsIn[2].y = t1.y; 33 | texCoordsIn[3].y = t0.y; 34 | } 35 | else 36 | { 37 | texCoordsIn[0].y = t0.y; 38 | texCoordsIn[1].y = t1.y; 39 | texCoordsIn[2].y = t2.y; 40 | texCoordsIn[3].y = t3.y; 41 | } 42 | 43 | if ((this & .Hort) == .Hort) 44 | { 45 | texCoordsIn[0].x = t1.x; 46 | texCoordsIn[1].x = t0.x; 47 | texCoordsIn[2].x = t3.x; 48 | texCoordsIn[3].x = t2.x; 49 | } 50 | else 51 | { 52 | texCoordsIn[0].x = t0.x; 53 | texCoordsIn[1].x = t1.x; 54 | texCoordsIn[2].x = t2.x; 55 | texCoordsIn[3].x = t3.x; 56 | } 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/GraphicsContext.bf: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System; 3 | namespace Atma 4 | { 5 | /// 6 | /// An Implementation of the Graphics Module that supports the OpenGL Graphics API 7 | /// 8 | public abstract class GraphicsContext//: IGraphicsContext 9 | { 10 | private static int _mainContextThread = -1; 11 | public static int MainContextThread => _mainContextThread; 12 | 13 | private bool _isMainContext = false; 14 | 15 | public this() 16 | { 17 | if (MainContextThread == -1) 18 | { 19 | _isMainContext = true; 20 | _mainContextThread = Thread.CurrentThread.Id; 21 | MakeActiveInternal(); 22 | } 23 | } 24 | 25 | public virtual void MakeActive() 26 | { 27 | Runtime.Assert( 28 | (IsMainContext && _mainContextThread == Thread.CurrentThread.Id) || 29 | (IsBackgroundContext && _mainContextThread != Thread.CurrentThread.Id), 30 | "MainContext can only be used on the main thread and background context on off threads"); 31 | 32 | if (!_isMainContext) 33 | MakeActiveInternal(); 34 | } 35 | 36 | protected bool IsMainContext => _isMainContext; 37 | protected bool IsBackgroundContext => !_isMainContext; 38 | 39 | protected abstract void MakeActiveInternal(); 40 | 41 | public readonly Monitor Lock = new .() ~ delete _; 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/IndexBuffer.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | 5 | public class IndexBuffer 6 | { 7 | private GraphicsManager _graphics; 8 | 9 | protected uint _id; 10 | public uint ID => _id; 11 | 12 | public readonly IndexElementSize ElementSize; 13 | 14 | private uint _elementCount; 15 | public uint ElementCount => _elementCount; 16 | 17 | public uint BufferSize => (uint)ElementSize.Stride * ElementCount; 18 | 19 | public this(IndexElementSize indexSize, uint elementCount) : this(GraphicsManager.Current, indexSize, elementCount) { } 20 | public this(GraphicsManager graphics, IndexElementSize indexSize, uint elementCount) 21 | { 22 | _graphics = GraphicsManager.Current; 23 | 24 | ElementSize = indexSize; 25 | _elementCount = elementCount; 26 | Platform_Init(); 27 | } 28 | 29 | public ~this() 30 | { 31 | Platform_Destroy(); 32 | } 33 | 34 | public void Resize(uint elements) 35 | { 36 | Log.Debug("IndexBuffer resize: {0} -> {1}", _elementCount, elements); 37 | _elementCount = elements; 38 | Platform_Resize(elements); 39 | } 40 | 41 | public void Set(T[] indices) 42 | { 43 | Set(Span(indices)); 44 | } 45 | 46 | public void Set(Span indices) 47 | { 48 | Runtime.Assert((uint)indices.Length <= ElementCount); 49 | Platform_SetData(&indices[0], indices.Length); 50 | } 51 | 52 | public void Bind(GraphicsContext context, Material material) 53 | { 54 | Platform_Bind(context, material); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/PostEffect.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Atma 4 | { 5 | /// 6 | /// Reusable post effects 7 | /// 8 | public abstract class PostEffect 9 | { 10 | protected abstract Material ShaderMaterial { get; } 11 | private Texture _debugInput ~ delete _; 12 | private Texture _debugOutput ~ delete _; 13 | private bool _captureInput = Core.DebugRenderEnabled, _captureOutput = Core.DebugRenderEnabled; 14 | 15 | public virtual void Render(Texture source, RenderTexture destination) 16 | { 17 | Render(source, destination, ShaderMaterial); 18 | } 19 | 20 | protected void Render(Texture texture, RenderTexture renderTarget, Material material) 21 | { 22 | Core.Draw.SetMaterial(material); 23 | Core.Draw.ImageScaled(texture, .FromRect(.Zero, renderTarget.Size), .White); 24 | Core.Draw.Render(renderTarget, renderTarget.Matrix); 25 | 26 | if (_captureInput) 27 | { 28 | if (_debugInput == null) _debugInput = new .(renderTarget.Width, renderTarget.Height); 29 | _debugInput.Resize(texture.Width, texture.Height); 30 | 31 | let color = new Color[texture.Width * texture.Height]; 32 | texture.GetData(color); 33 | _debugInput.SetData(color); 34 | delete color; 35 | } 36 | 37 | if (_captureOutput) 38 | { 39 | if (_debugOutput == null) _debugOutput = new .(renderTarget.Width, renderTarget.Height); 40 | _debugOutput.Resize(renderTarget.Width, renderTarget.Height); 41 | 42 | let color = new Color[renderTarget.Width * renderTarget.Height]; 43 | renderTarget.ColorAttachment.GetData(color); 44 | _debugOutput.SetData(color); 45 | delete color; 46 | } 47 | } 48 | 49 | public static implicit operator Material(Self it) => it.ShaderMaterial; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/RenderPass.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Text; 4 | 5 | namespace Atma 6 | { 7 | public enum IndexElementSize 8 | { 9 | /// 10 | /// 16-bit short/ushort indices. 11 | /// 12 | case SixteenBits; 13 | /// 14 | /// 32-bit int/uint indices. 15 | /// 16 | case ThirtyTwoBits; 17 | 18 | public int Stride 19 | { 20 | get 21 | { 22 | switch (this) { 23 | case .SixteenBits: return sizeof(uint16); 24 | case .ThirtyTwoBits: return sizeof(uint32); 25 | } 26 | } 27 | } 28 | } 29 | 30 | /// 31 | /// A Structure which describes a single Render Pass / Render Call 32 | /// 33 | public struct RenderPass 34 | { 35 | /// 36 | /// Render Target 37 | /// 38 | public RenderTarget Target; 39 | 40 | /*/// 41 | /// Render Viewport 42 | /// 43 | public rect? Viewport;*/ 44 | 45 | /// 46 | /// Material to use 47 | /// 48 | public Material Material; 49 | 50 | /// 51 | /// VertexBuffer to use 52 | /// 53 | public VertexBuffer VertexBuffer; 54 | 55 | /// 56 | /// IndexBuffer to use 57 | /// 58 | public IndexBuffer IndexBuffer; 59 | 60 | /// 61 | /// The Index to begin rendering 62 | /// 63 | public uint IndexStart; 64 | 65 | /// 66 | /// The total number of Indices to draw 67 | /// 68 | public uint IndexCount; 69 | 70 | /// 71 | /// The Render State Blend Mode 72 | /// 73 | public BlendMode BlendMode; 74 | 75 | /// 76 | /// The Render State Culling Mode 77 | /// 78 | public CullMode CullMode; 79 | 80 | /// 81 | /// The Render State Depth comparison Function 82 | /// 83 | public DepthCompare DepthFunction; 84 | 85 | /// 86 | /// The Render State Scissor Rectangle 87 | /// 88 | public rect? Scissor; 89 | 90 | /// 91 | /// Creates a Render Pass based on the given mesh and material 92 | /// 93 | public this(RenderTarget target, VertexBuffer vertexBuffer, IndexBuffer indexBuffer, uint indexStart, uint indexCount, Material material) 94 | { 95 | Target = target; 96 | VertexBuffer = vertexBuffer; 97 | IndexBuffer = indexBuffer; 98 | Material = material; 99 | IndexStart = indexStart; 100 | IndexCount = indexCount; 101 | Scissor = null; 102 | BlendMode = .Normal; 103 | DepthFunction = DepthCompare.None; 104 | CullMode = .None; 105 | } 106 | } 107 | } 108 | 109 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/RenderTarget.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | /// 4 | /// An Object that can be rendered to (ex. a FrameBuffer or a Window) 5 | /// 6 | public abstract class RenderTarget 7 | { 8 | /// 9 | /// The Width of the Target 10 | /// 11 | public abstract int Width { get; } 12 | 13 | /// 14 | /// The Height of the Target 15 | /// 16 | public abstract int Height { get; } 17 | 18 | /// 19 | /// Whether the Target can be rendered to. 20 | /// 21 | public bool Renderable { get; protected set; } 22 | 23 | public int2 Size => .(Width, Height); 24 | 25 | public bool Resize(int2 size) => InternalResize(size); 26 | 27 | public bool Resize(int width, int height) => InternalResize(.(width, height)); 28 | 29 | protected abstract bool InternalResize(int2 size); 30 | 31 | public virtual float4x4 Matrix => .Ortho(0, Width, 0, Height); 32 | 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/RenderTexture.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Text; 4 | 5 | namespace Atma 6 | { 7 | 8 | 9 | /// 10 | /// A 2D buffer that can be drawn to 11 | /// 12 | public class RenderTexture : RenderTarget 13 | { 14 | 15 | 16 | /// 17 | /// Render Target Width 18 | /// 19 | public override int Width => width; 20 | 21 | /// 22 | /// Render Target Height 23 | /// 24 | public override int Height => height; 25 | 26 | private int width; 27 | private int height; 28 | 29 | protected uint _id; 30 | public uint ID => _id; 31 | 32 | protected List _attachments = new .() ~ DeleteContainerAndItems!(_); 33 | 34 | public Texture GetAttachment(TextureFormat format) 35 | { 36 | for (var it in _attachments) 37 | if (it.Format == format) 38 | return it; 39 | return null; 40 | } 41 | 42 | public Texture ColorAttachment => GetAttachment(.Color); 43 | public Texture RGBA16F => GetAttachment(.RGBA16F); 44 | public Texture DepthAttachment => GetAttachment(.DepthStencil); 45 | 46 | public static implicit operator Texture(RenderTexture buffer) => buffer.ColorAttachment; 47 | 48 | public this(int2 size) : this(size.x, size.y) { } 49 | public this(int width, int height) 50 | : this(width, height, TextureFormat.Color) 51 | { 52 | } 53 | 54 | public this(int width, int height, params TextureFormat[] attachments) 55 | { 56 | Initialize(.(width, height), params attachments); 57 | } 58 | 59 | protected this() 60 | { 61 | //used to init later 62 | } 63 | 64 | protected void Initialize(int2 size, params TextureFormat[] attachments) 65 | { 66 | this.width = size.width; 67 | this.height = size.height; 68 | 69 | Runtime.Assert(width > 0 && height > 0, "FrameBuffer must have a size larger than 0"); 70 | Renderable = true; 71 | Platform_Init(attachments); 72 | } 73 | 74 | public ~this() 75 | { 76 | Platform_Destroy(); 77 | } 78 | 79 | protected override bool InternalResize(int2 size) 80 | { 81 | Runtime.Assert(size.width > 0 && size.height > 0, "FrameBuffer must have a size larger than 0"); 82 | 83 | if (this.width != size.width || this.height != size.height) 84 | { 85 | this.width = size.width; 86 | this.height = size.height; 87 | 88 | Platform_Resize(width, height); 89 | return true; 90 | } 91 | 92 | return false; 93 | } 94 | 95 | public void Bind(GraphicsContext ctx) 96 | { 97 | Platform_Bind(); 98 | } 99 | 100 | public aabb2 Bounds => aabb2.FromRect(0, 0, width, height); 101 | 102 | public void Inpsect() 103 | { 104 | OnInspect(); 105 | } 106 | 107 | protected virtual void OnInspect() { } 108 | } 109 | } 110 | 111 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Renderer.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma 3 | { 4 | public abstract class Renderer 5 | { 6 | /// 7 | /// if renderTarget is not null this Color will be used to clear the screen 8 | /// 9 | public Color ClearColor = Color.Transparent; 10 | 11 | /// 12 | /// flag for this renderer that decides if it should debug render or not. The render method receives a bool 13 | // (debugRenderEnabled) letting the renderer know if the global debug rendering is on/off. The renderer then 14 | // uses the local bool to decide if it should debug render or not. 15 | public bool ShouldDebugRender = false; 16 | 17 | /// 18 | /// if true, the Scene will call the render method AFTER all PostProcessors have finished. This must be set to 19 | // true BEFORE calling Scene.addRenderer to take effect and the Renderer should NOT have a renderTexture. The 20 | // main reason for this type of Renderer is so that you can render your UI without post processing on top of the 21 | // rest of your Scene. The ScreenSpaceRenderer is an example Renderer that sets this to true; 22 | public bool WantsToRenderAfterPostProcessors; 23 | 24 | public abstract void Render(RenderPipeline pipeline); 25 | 26 | public void Inspect() 27 | { 28 | //TODO: Add IMGUI 29 | OnInspect(); 30 | } 31 | 32 | protected virtual void OnInspect() 33 | { 34 | } 35 | 36 | protected internal virtual void PipelineResize(int2 oldSize, int2 newSize) { } 37 | protected internal virtual void OnAddedToPipeline(RenderPipeline pipeline) { } 38 | protected internal virtual void OnRemovedFromPipeline(RenderPipeline pipeline) { } 39 | } 40 | 41 | public class DefaultRenderer : Renderer 42 | { 43 | private Camera2D _camera; 44 | public this(Camera2D camera) 45 | { 46 | _camera = camera; 47 | } 48 | 49 | public override void Render(RenderPipeline pipeline) 50 | { 51 | Core.Draw.Render(_camera, _camera.ProjectionViewMatrix); 52 | //pipeline.Execute(_camera.ProjectionViewMatrix); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Shader/Shader.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | using System.Collections; 5 | 6 | /// 7 | /// A Shader used for Rendering 8 | /// 9 | public class Shader : Assets.IAsset 10 | { 11 | private Assets _assets; 12 | private int _assetKey; 13 | 14 | private Material _material ~ delete _; 15 | public Material DefaultMaterial 16 | { 17 | get 18 | { 19 | if (_material == null) 20 | _material = new .(this); 21 | 22 | return _material; 23 | } 24 | } 25 | 26 | public int Version = 0; 27 | 28 | 29 | 30 | protected readonly GraphicsManager _graphics; 31 | 32 | protected readonly List _attributes = new .() ~ delete _; 33 | protected readonly List _uniforms = new .() ~ delete _; 34 | 35 | /// 36 | /// Dictionary of all the attributes. 37 | /// 38 | public ReadOnlyList Attributes => .(_attributes); 39 | 40 | /// 41 | /// Tries to get a shader attribute out of the dictionary. 42 | /// 43 | public bool TryGetAttribute(StringView name, out ShaderAttribute attr) 44 | { 45 | var list = Attributes; 46 | for (var i < list.Count) 47 | { 48 | attr = list[i]; 49 | if (attr.Name == name) 50 | return true; 51 | } 52 | attr = default; 53 | return false; 54 | } 55 | 56 | /// 57 | /// Dictionary of all the attributes. 58 | /// 59 | public ReadOnlyList Uniforms => .(_uniforms); 60 | 61 | /// 62 | /// List of all Uniforms, by Name 63 | /// 64 | public bool TryGetUniform(StringView name, out ShaderUniform uniform) 65 | { 66 | var list = Uniforms; 67 | for (var i < list.Count) 68 | { 69 | uniform = list[i]; 70 | if (uniform.Name == name) 71 | return true; 72 | } 73 | uniform = default; 74 | return false; 75 | } 76 | 77 | public this(ShaderSource source, bool log = true) 78 | { 79 | _graphics = GraphicsManager.Current; 80 | Platform_Init(source, log); 81 | } 82 | 83 | public ~this() 84 | { 85 | Platform_Destroy(); 86 | _assets?.Unload(this); 87 | } 88 | 89 | public void Bind(GraphicsContext context, Material material) 90 | { 91 | Platform_Bind(context, material); 92 | } 93 | 94 | public bool Reload(Atma.Assets.AssetPath[] pathes) 95 | { 96 | Version++; 97 | System.Diagnostics.Debug.Assert(pathes.Count == 2); 98 | 99 | _attributes.Clear(); 100 | _uniforms.Clear(); 101 | 102 | Platform_Destroy(); 103 | 104 | let vert = scope String(); 105 | let frag = scope String(); 106 | 107 | if (pathes[0].ReadAllText(vert) && pathes[1].ReadAllText(frag)) 108 | { 109 | let source = scope ShaderSource(vert, frag); 110 | Platform_Init(source, true); 111 | //DefaultMaterial.[Friend]BuildParamsList(); 112 | return true; 113 | } 114 | 115 | return false; 116 | } 117 | } 118 | } 119 | 120 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Shader/ShaderAttribute.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | 5 | /// 6 | /// A Shader Attribute 7 | /// 8 | public struct ShaderAttribute 9 | { 10 | /// 11 | /// The name of the Attribute 12 | /// 13 | public readonly String Name; 14 | 15 | /// 16 | /// The Location of the Attribute in the Shader 17 | /// 18 | public readonly uint Location; 19 | 20 | public this(String name, uint location) 21 | { 22 | Name = name; 23 | Location = location; 24 | } 25 | 26 | public override void ToString(String buffer) 27 | { 28 | buffer.AppendF("{{ Name: {0}, Location: {1} }}", Name, Location); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Shader/ShaderSource.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma 3 | { 4 | public class ShaderSource 5 | { 6 | public String Vertex = new .() ~ delete _; 7 | public String Fragment = new .() ~ delete _; 8 | //public String Geometry; 9 | 10 | //Copies the string source data to local variables 11 | public this(StringView vertexSource, StringView fragmentSource/*, String? geomSource = null*/) 12 | { 13 | Vertex.Set(vertexSource); 14 | Fragment.Set(fragmentSource); 15 | } 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Shader/ShaderUniform.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | 5 | /// 6 | /// A Shader Uniform Value 7 | /// 8 | public struct ShaderUniform 9 | { 10 | /// 11 | /// The Name of the Uniform 12 | /// 13 | public readonly String Name; 14 | 15 | /// 16 | /// The Location of the Uniform in the Shader 17 | /// 18 | public readonly int Location; 19 | 20 | /// 21 | /// The Array length of the uniform 22 | /// 23 | public readonly int Length; 24 | 25 | /// 26 | /// The Type of Uniform 27 | /// 28 | public readonly UniformType Type; 29 | 30 | /// 31 | /// The total length of the data for this uniform (typesize * length) 32 | /// 33 | public int Size => Type.Size(Length); 34 | 35 | public this(String name, int location, int length, UniformType type) 36 | { 37 | Name = name; 38 | Location = location; 39 | Length = length; 40 | Type = type; 41 | } 42 | 43 | public override void ToString(String buffer) 44 | { 45 | buffer.AppendF("{{ Name: {0}, Location: {1}, Length: {2}, Type: {3}, Size: {4} }}", Name, Location, Length, Type, Size); 46 | } 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Shader/UniformType.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | 5 | public enum UniformType 6 | { 7 | case Unknown; 8 | case Int; 9 | case Float; 10 | case Float2; 11 | case Float3; 12 | case Float4; 13 | case Matrix3x2; 14 | case Matrix4x4; 15 | case Sampler; 16 | 17 | public bool IsFloat 18 | { 19 | get 20 | { 21 | switch (this) { 22 | case Float: fallthrough; 23 | case Float2: fallthrough; 24 | case Float3: fallthrough; 25 | case Float4: fallthrough; 26 | case Matrix3x2: fallthrough; 27 | case Matrix4x4: return true; 28 | default: 29 | } 30 | return false; 31 | } 32 | } 33 | 34 | public int Elements 35 | { 36 | get 37 | { 38 | switch (this) { 39 | case Int: return 1; 40 | case Float: return 1; 41 | case Float2: return 2; 42 | case Float3: return 3; 43 | case Float4: return 4; 44 | case Matrix3x2: return 3 * 2; 45 | case Matrix4x4: return 4 * 4; 46 | default: 47 | Runtime.Assert(false, "Unsupported type"); 48 | } 49 | 50 | return 0; 51 | } 52 | } 53 | 54 | public int Size(int length = 1) 55 | { 56 | switch (this) { 57 | case Int: return sizeof(int32) * length; 58 | case Float: return sizeof(float) * length; 59 | case Float2: return sizeof(float) * 2 * length; 60 | case Float3: return sizeof(float) * 3 * length; 61 | case Float4: return sizeof(float) * 4 * length; 62 | case Matrix3x2: return sizeof(float) * 3 * 2 * length; 63 | case Matrix4x4: return sizeof(float) * 4 * 4 * length; 64 | case Sampler: return 0; 65 | default: 66 | Runtime.Assert(false, "Unsupported type"); 67 | } 68 | return 0; 69 | } 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Texture/TextureFilter.bf: -------------------------------------------------------------------------------- 1 | 2 | namespace Atma 3 | { 4 | /// 5 | /// Texture Filter 6 | /// 7 | public enum TextureFilter 8 | { 9 | Linear = 0, 10 | Nearest = 1 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Texture/TextureFormat.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | 5 | /// 6 | /// Texture Format 7 | /// 8 | public enum TextureFormat 9 | { 10 | /*/// 11 | /// No Texture Format 12 | /// 13 | case None;*/ 14 | 15 | /// 16 | /// Single 8-bit component stored in the Red channel 17 | /// 18 | case Red; 19 | 20 | /// 21 | /// Two 8-bit components stored in the Red, Green channels 22 | /// 23 | case RG; 24 | 25 | /// 26 | /// Three 8-bit components stored in the Red, Green, Blue channels 27 | /// 28 | case RGB; 29 | 30 | /// 31 | /// Three 16-bit components stored in the Red, Green, Blue, Alpha channels 32 | /// 33 | case RGBA16F; 34 | 35 | /// 36 | /// ARGB uint32 Color 37 | /// 38 | case Color; 39 | 40 | /// 41 | /// Depth 24-bit Stencil 8-bit 42 | /// 43 | case DepthStencil; 44 | 45 | public int ElementSize 46 | { 47 | get 48 | { 49 | switch (this) { 50 | case .RGBA16F: return sizeof(float); 51 | case .Color: return sizeof(char8); 52 | case .Red: return sizeof(char8); 53 | case .RG: return sizeof(char8); 54 | case .RGB: return sizeof(char8); 55 | case .DepthStencil: return sizeof(float); 56 | /*case .None: 57 | Runtime.FatalError("Invalid Texture Format");*/ 58 | } 59 | } 60 | } 61 | 62 | 63 | public int ElementCount 64 | { 65 | get 66 | { 67 | switch (this) { 68 | case .RGBA16F: return 4; 69 | case .Color: return 4; 70 | case .Red: return 1; 71 | case .RG: return 2; 72 | case .RGB: return 3; 73 | case .DepthStencil: return 1; 74 | /*case .None: 75 | Runtime.FatalError("Invalid Texture Format");*/ 76 | } 77 | } 78 | } 79 | 80 | public int Size => ElementSize * ElementCount 81 | 82 | public bool IsTextureColorFormat 83 | { 84 | get => this != .DepthStencil; 85 | } 86 | 87 | public bool IsDepthStencilFormat 88 | { 89 | get => this == .DepthStencil; 90 | } 91 | } 92 | } 93 | 94 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Texture/TextureWrap.bf: -------------------------------------------------------------------------------- 1 | 2 | namespace Atma 3 | { 4 | /// 5 | /// Texture Wrap 6 | /// 7 | public enum TextureWrap 8 | { 9 | Wrap = 0, 10 | Clamp = 1 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Vertex/VertexAttrib.bf: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Collections; 4 | using System.Text; 5 | 6 | namespace Atma 7 | { 8 | public enum VertexAttrib 9 | { 10 | case Position; 11 | case Normal; 12 | case Bitangent; 13 | case Color0; 14 | case Color1; 15 | case Color2; 16 | case Color3; 17 | case Indices; 18 | case Weight; 19 | case TexCoord0; 20 | case TexCoord1; 21 | case TexCoord2; 22 | case TexCoord3; 23 | case TexCoord4; 24 | case TexCoord5; 25 | case TexCoord6; 26 | case TexCoord7; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Vertex/VertexAttribute.bf: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | 4 | namespace Atma 5 | { 6 | /// 7 | /// Describes a Vertex Attribute for a Shader 8 | /// 9 | public struct VertexAttribute 10 | { 11 | 12 | /// 13 | /// The name of the Attribute 14 | /// Depending on the Graphics Implementation, this may or may not be respected 15 | /// 16 | public readonly String Name; 17 | 18 | /// 19 | /// The Vertex Attribute Type 20 | /// Depending on the Graphics Implementation, this may or may not be respected 21 | /// 22 | public readonly VertexAttrib Attrib; 23 | 24 | /// 25 | /// The Vertex Type of the Attribute 26 | /// 27 | public readonly VertexType Type; 28 | 29 | /// 30 | /// The number of Components 31 | /// 32 | public readonly VertexComponents Components; 33 | 34 | /// 35 | /// The size of a single Component, in bytes 36 | /// 37 | public readonly int ComponentSize; 38 | 39 | /// 40 | /// The size of the entire Attribute, in bytes 41 | /// 42 | public readonly int AttributeSize; 43 | 44 | /// 45 | /// Whether the Attribute value should be normalized 46 | /// 47 | public readonly bool Normalized; 48 | 49 | public this(String name, VertexAttrib attrib, VertexType type, VertexComponents components, bool normalized = false) 50 | { 51 | Name = name; 52 | Attrib = attrib; 53 | Type = type; 54 | Components = components; 55 | Normalized = normalized; 56 | 57 | ComponentSize = type.Size; 58 | 59 | AttributeSize = (int)Components * ComponentSize; 60 | } 61 | 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Vertex/VertexComponents.bf: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Collections; 4 | using System.Text; 5 | 6 | namespace Atma 7 | { 8 | public enum VertexComponents 9 | { 10 | case One = 1; 11 | case Two = 2; 12 | case Three = 3; 13 | case Four = 4; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Vertex/VertexFormat.bf: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | namespace Atma 4 | { 5 | /// 6 | /// Describes a Vertex Format for a Shader 7 | /// This tells the Shader what Attributes, and in what order, are to be expected 8 | /// 9 | public class VertexFormat 10 | { 11 | 12 | /// 13 | /// The list of Attributes 14 | /// 15 | public readonly VertexAttribute[] Attributes ~ delete _; 16 | 17 | /// 18 | /// The stride of each Vertex (all the Attributes combined) 19 | /// 20 | public readonly int Stride; 21 | 22 | public this(params VertexAttribute[] attributes) 23 | { 24 | Attributes = new VertexAttribute[attributes.Count]; 25 | attributes.CopyTo(Attributes); 26 | 27 | Stride = 0; 28 | for (var i < Attributes.Count) 29 | Stride += Attributes[i].AttributeSize; 30 | } 31 | 32 | /// 33 | /// Attempts to find an attribute by name, and returns its relative pointer (offset) 34 | /// 35 | public bool TryGetAttribute(String name, out VertexAttribute element, out int pointer) 36 | { 37 | pointer = 0; 38 | for (var i < Attributes.Count) 39 | { 40 | if (Attributes[i].Name == name) 41 | { 42 | element = Attributes[i]; 43 | return true; 44 | } 45 | pointer += Attributes[i].AttributeSize; 46 | } 47 | 48 | element = default; 49 | return false; 50 | } 51 | 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/Vertex/VertexType.bf: -------------------------------------------------------------------------------- 1 | 2 | namespace Atma 3 | { 4 | /// 5 | /// Represents the type of Data in a Vertex 6 | /// 7 | public enum VertexType 8 | { 9 | case Byte; 10 | case Short; 11 | case Int; 12 | case Float; 13 | 14 | public int Size 15 | { 16 | get 17 | { 18 | switch (this) { 19 | case .Byte: return 1; 20 | case .Short: return 2; 21 | case .Int: return 4; 22 | case .Float: return 4; 23 | } 24 | } 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Graphics/Rendering/VertexBuffer.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | 5 | public class VertexBuffer 6 | { 7 | protected readonly GraphicsManager _graphics; 8 | 9 | protected uint _id; 10 | public uint ID => _id; 11 | 12 | private uint _vertexCount; 13 | public uint VertexCount => _vertexCount; 14 | public uint BufferSize => (uint)Format.Stride * VertexCount; 15 | public readonly VertexFormat Format; 16 | 17 | public this(VertexFormat format, uint vertexCount) : this(Core.Graphics, format, vertexCount) { } 18 | public this(GraphicsManager graphics, VertexFormat format, uint vertexCount) 19 | { 20 | _graphics = GraphicsManager.Current; 21 | _vertexCount = vertexCount; 22 | 23 | Format = format; 24 | Platform_Init(); 25 | } 26 | 27 | public ~this() 28 | { 29 | Platform_Destroy(); 30 | } 31 | 32 | public void Resize(uint elements) 33 | { 34 | Log.Debug("VertexBuffer resize: {0} -> {1}", _vertexCount, elements); 35 | 36 | _vertexCount = elements; 37 | Platform_Resize(elements); 38 | } 39 | 40 | public void Set(T[] vertices) 41 | { 42 | Set(Span(vertices)); 43 | } 44 | 45 | public void Set(Span vertices) 46 | { 47 | Runtime.Assert((uint)vertices.Length <= VertexCount); 48 | Platform_SetData(&vertices[0], vertices.Length); 49 | } 50 | 51 | public void Bind(GraphicsContext context, Material material) 52 | { 53 | Platform_Bind(context, material); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Input/Axes.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public enum Axes : int32 4 | { 5 | case Invalid = -1; 6 | case LeftX; 7 | case LeftY; 8 | case RightX; 9 | case RightY; 10 | case TriggerLeft; 11 | case TriggerRight; 12 | 13 | public const int Count = (.)TriggerRight + 1; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Input/Buttons.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | enum Buttons : int32 4 | { 5 | case Invalid = -1; 6 | case A; 7 | case B; 8 | case X; 9 | case Y; 10 | case Back; 11 | case Guide; 12 | case Start; 13 | case LeftStick; 14 | case RightStick; 15 | case LeftShoulder; 16 | case RightShoulder; 17 | case DpadUp; 18 | case DpadDown; 19 | case DpadLeft; 20 | case DpadRight; 21 | public const int Count = (.)DpadRight + 1; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Input/Cursors.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | /// 4 | /// Mouse Cursor Styles 5 | /// 6 | public enum Cursors 7 | { 8 | /*case Hidden = -1; 9 | case Default = 0; 10 | case IBeam = 1; 11 | case Crosshair = 2; 12 | case Hand = 3; 13 | case HorizontalResize = 4; 14 | case VerticalResize = 5;*/ 15 | 16 | case Hidden = -1; 17 | case Arrow = 0; 18 | case TextInput = 1; 19 | case ResizeAll = 2; 20 | case ResizeNS = 3; 21 | case ResizeEW = 4; 22 | case ResizeNESW = 5; 23 | case ResizeNWSE = 6; 24 | case Hand = 7; 25 | case NotAllowed = 8; 26 | public const int COUNT = 9; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Input/MouseButtons.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | /// 4 | /// Mouse Buttons 5 | /// 6 | public enum MouseButtons : int32 7 | { 8 | case None = 0; 9 | case Unknown = 1; 10 | case Left = 2; 11 | case Middle = 3; 12 | case Right = 4; 13 | 14 | public const int Count = (.)Right + 1; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Input/MouseState.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace Atma 5 | { 6 | /// 7 | /// Stores a Mouse State 8 | /// 9 | public struct MouseState 10 | { 11 | private readonly bool[MouseButtons.Count] _buttons; 12 | public readonly int2 WheelValue; 13 | public readonly int2 Position; 14 | 15 | public this() 16 | { 17 | this = default; 18 | } 19 | 20 | public this(int2 position, int2 wheelValue, bool[MouseButtons.Count] buttons) 21 | { 22 | Position = position; 23 | WheelValue = wheelValue; 24 | _buttons = buttons; 25 | } 26 | 27 | public bool IsDown(MouseButtons button) => _buttons[(int)button]; 28 | } 29 | 30 | 31 | /*/// 32 | /// Stores a Mouse State 33 | /// 34 | public struct Mouse 35 | { 36 | public const int MaxButtons = 5; 37 | 38 | private bool[MaxButtons] pressed; 39 | private bool[MaxButtons] down; 40 | private bool[MaxButtons] released; 41 | private int64[MaxButtons] timestamp; 42 | private float2 wheelValue; 43 | 44 | public bool Pressed(MouseButtons button) => pressed[(int)button]; 45 | public bool Down(MouseButtons button) => down[(int)button]; 46 | public bool Released(MouseButtons button) => released[(int)button]; 47 | 48 | public int64 Timestamp(MouseButtons button) 49 | { 50 | return timestamp[(int)button]; 51 | } 52 | 53 | public bool Repeated(MouseButtons button, float delay, float interval) 54 | { 55 | if (Pressed(button)) 56 | return true; 57 | 58 | var time = timestamp[(int)button] / (float)TimeSpan.TicksPerSecond; 59 | 60 | return Down(button) && (Time.Duration.TotalSeconds - time) > delay && Time.OnInterval(interval, time); 61 | } 62 | 63 | 64 | 65 | public bool LeftPressed => pressed[(int)MouseButtons.Left]; 66 | public bool LeftDown => down[(int)MouseButtons.Left]; 67 | public bool LeftReleased => released[(int)MouseButtons.Left]; 68 | 69 | public bool RightPressed => pressed[(int)MouseButtons.Right]; 70 | public bool RightDown => down[(int)MouseButtons.Right]; 71 | public bool RightReleased => released[(int)MouseButtons.Right]; 72 | 73 | public bool MiddlePressed => pressed[(int)MouseButtons.Middle]; 74 | public bool MiddleDown => down[(int)MouseButtons.Middle]; 75 | public bool MiddleReleased => released[(int)MouseButtons.Middle]; 76 | 77 | public float2 Wheel => wheelValue; 78 | 79 | /*private void Copy(Mouse other) mut 80 | { 81 | pressed = other.pressed; 82 | down = other.down; 83 | released = other.released; 84 | timestamp = other.timestamp; 85 | 86 | wheelValue = other.wheelValue; 87 | } 88 | 89 | private void Step() mut 90 | { 91 | pressed = default; 92 | released = default; 93 | 94 | wheelValue = float2.Zero; 95 | }*/ 96 | 97 | }*/ 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Input/VirtualInput.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public abstract class VirtualInput 4 | { 5 | public enum OverlapBehaviors { TakeNewer, TakeOlder, CancelOut } 6 | public enum ThresholdConditions { GreaterThan, LessThan } 7 | 8 | protected bool fromGamepad = false; 9 | public bool FromGamepad => fromGamepad; 10 | 11 | public this() 12 | { 13 | Core.Input.VirtualInputs.Add(this); 14 | } 15 | 16 | public ~this() 17 | { 18 | Core.Input.VirtualInputs.Remove(this); 19 | } 20 | 21 | public virtual void Update() 22 | { 23 | fromGamepad = false; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Linq.bf: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | namespace Atma 3 | { 4 | public static 5 | { 6 | /*public static K Min(this List items, Func dlg) 7 | where bool : operator K < K 8 | { 9 | var enumerator = items.GetEnumerator(); 10 | 11 | if (!enumerator.MoveNext()) 12 | return default; 13 | 14 | var t = dlg(enumerator.Current); 15 | while (enumerator.MoveNext()) 16 | { 17 | let r = dlg(enumerator.Current); 18 | if (r < t) 19 | t = r; 20 | } 21 | 22 | return t; 23 | }*/ 24 | 25 | /*public static T Min(this List items) 26 | where bool : operator T < T 27 | { 28 | var first = true; 29 | T current = default; 30 | for (var it in items) 31 | { 32 | if (first) 33 | { 34 | current = it; 35 | first = false; 36 | } 37 | else if (it < current) 38 | { 39 | current = it; 40 | } 41 | } 42 | 43 | return current; 44 | }*/ 45 | 46 | 47 | //public void ForEach(K dlg) where K : delegate void(T item) 48 | 49 | public static K Max(this List items, F dlg) 50 | where bool : operator K > K 51 | where F : delegate K(T item) 52 | { 53 | var first = true; 54 | K current = default; 55 | for (var it in items) 56 | { 57 | let r = dlg(it); 58 | 59 | if (first) 60 | { 61 | current = r; 62 | first = false; 63 | } 64 | else if (r > current) 65 | { 66 | current = r; 67 | } 68 | } 69 | 70 | return current; 71 | } 72 | 73 | /*public static T Max(this List items) 74 | where bool : operator T > T 75 | { 76 | var first = true; 77 | T current = default; 78 | for (var it in items) 79 | { 80 | if (first) 81 | { 82 | current = it; 83 | first = false; 84 | } 85 | else if (it > current) 86 | { 87 | current = it; 88 | } 89 | } 90 | 91 | return current; 92 | }*/ 93 | 94 | /*public static mixin Max(var items) 95 | { 96 | var current = items[0]; 97 | for(var i = 1; i < items.Count;i++) 98 | { 99 | if (items[i] > current) 100 | { 101 | current = items[i]; 102 | } 103 | } 104 | 105 | return current; 106 | }*/ 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x2/bool2x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static bool[,] ToArray(bool2x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static bool[] ToArray1D(bool2x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x2/double2x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static double[,] ToArray(double2x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static double[] ToArray1D(double2x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x2/float2x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static float[,] ToArray(float2x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static float[] ToArray1D(float2x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x2/int2x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static int[,] ToArray(int2x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static int[] ToArray1D(int2x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x2/long2x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static long[,] ToArray(long2x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static long[] ToArray1D(long2x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x2/uint2x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static uint[,] ToArray(uint2x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static uint[] ToArray1D(uint2x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x3/bool2x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static bool[,] ToArray(bool2x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static bool[] ToArray1D(bool2x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x3/double2x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static double[,] ToArray(double2x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static double[] ToArray1D(double2x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x3/float2x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static float[,] ToArray(float2x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static float[] ToArray1D(float2x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x3/int2x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static int[,] ToArray(int2x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static int[] ToArray1D(int2x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x3/long2x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static long[,] ToArray(long2x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static long[] ToArray1D(long2x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x3/uint2x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static uint[,] ToArray(uint2x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static uint[] ToArray1D(uint2x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x4/bool2x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static bool[,] ToArray(bool2x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static bool[] ToArray1D(bool2x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x4/double2x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static double[,] ToArray(double2x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static double[] ToArray1D(double2x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x4/float2x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static float[,] ToArray(float2x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static float[] ToArray1D(float2x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x4/int2x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static int[,] ToArray(int2x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static int[] ToArray1D(int2x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x4/long2x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static long[,] ToArray(long2x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static long[] ToArray1D(long2x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat2x4/uint2x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static uint[,] ToArray(uint2x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static uint[] ToArray1D(uint2x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x2/bool3x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static bool[,] ToArray(bool3x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static bool[] ToArray1D(bool3x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x2/double3x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static double[,] ToArray(double3x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static double[] ToArray1D(double3x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x2/float3x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static float[,] ToArray(float3x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static float[] ToArray1D(float3x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x2/int3x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static int[,] ToArray(int3x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static int[] ToArray1D(int3x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x2/long3x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static long[,] ToArray(long3x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static long[] ToArray1D(long3x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x2/uint3x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static uint[,] ToArray(uint3x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static uint[] ToArray1D(uint3x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x3/bool3x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static bool[,] ToArray(bool3x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static bool[] ToArray1D(bool3x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x3/double3x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static double[,] ToArray(double3x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static double[] ToArray1D(double3x3 m) => m.ToArray1D(); 21 | 22 | /// 23 | /// Creates a quaternion from the rotational part of this matrix. 24 | /// 25 | [Inline] 26 | public static qdouble ToQuaternion(double3x3 m) => m.ToQuaternion; 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x3/float3x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static float[,] ToArray(float3x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static float[] ToArray1D(float3x3 m) => m.ToArray1D(); 21 | 22 | /// 23 | /// Creates a quaternion from the rotational part of this matrix. 24 | /// 25 | [Inline] 26 | public static qfloat ToQuaternion(float3x3 m) => m.ToQuaternion; 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x3/int3x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static int[,] ToArray(int3x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static int[] ToArray1D(int3x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x3/long3x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static long[,] ToArray(long3x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static long[] ToArray1D(long3x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x3/uint3x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static uint[,] ToArray(uint3x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static uint[] ToArray1D(uint3x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x4/bool3x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static bool[,] ToArray(bool3x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static bool[] ToArray1D(bool3x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x4/double3x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static double[,] ToArray(double3x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static double[] ToArray1D(double3x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x4/float3x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static float[,] ToArray(float3x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static float[] ToArray1D(float3x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x4/int3x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static int[,] ToArray(int3x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static int[] ToArray1D(int3x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x4/long3x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static long[,] ToArray(long3x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static long[] ToArray1D(long3x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat3x4/uint3x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static uint[,] ToArray(uint3x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static uint[] ToArray1D(uint3x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x2/bool4x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static bool[,] ToArray(bool4x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static bool[] ToArray1D(bool4x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x2/double4x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static double[,] ToArray(double4x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static double[] ToArray1D(double4x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x2/float4x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static float[,] ToArray(float4x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static float[] ToArray1D(float4x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x2/int4x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static int[,] ToArray(int4x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static int[] ToArray1D(int4x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x2/long4x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static long[,] ToArray(long4x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static long[] ToArray1D(long4x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x2/uint4x2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static uint[,] ToArray(uint4x2 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static uint[] ToArray1D(uint4x2 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x3/bool4x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static bool[,] ToArray(bool4x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static bool[] ToArray1D(bool4x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x3/double4x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static double[,] ToArray(double4x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static double[] ToArray1D(double4x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x3/float4x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static float[,] ToArray(float4x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static float[] ToArray1D(float4x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x3/int4x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static int[,] ToArray(int4x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static int[] ToArray1D(int4x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x3/long4x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static long[,] ToArray(long4x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static long[] ToArray1D(long4x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x3/uint4x3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static uint[,] ToArray(uint4x3 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static uint[] ToArray1D(uint4x3 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x4/bool4x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static bool[,] ToArray(bool4x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static bool[] ToArray1D(bool4x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x4/double4x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static double[,] ToArray(double4x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static double[] ToArray1D(double4x4 m) => m.ToArray1D(); 21 | 22 | /// 23 | /// Creates a quaternion from the rotational part of this matrix. 24 | /// 25 | [Inline] 26 | public static qdouble ToQuaternion(double4x4 m) => m.ToQuaternion; 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x4/float4x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static float[,] ToArray(float4x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static float[] ToArray1D(float4x4 m) => m.ToArray1D(); 21 | 22 | /// 23 | /// Creates a quaternion from the rotational part of this matrix. 24 | /// 25 | [Inline] 26 | public static qfloat ToQuaternion(float4x4 m) => m.ToQuaternion; 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x4/int4x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static int[,] ToArray(int4x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static int[] ToArray1D(int4x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x4/long4x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static long[,] ToArray(long4x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static long[] ToArray1D(long4x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Mat4x4/uint4x4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | /// 11 | /// Creates a 2D array with all values (address: Values[x, y]) 12 | /// 13 | [Inline] 14 | public static uint[,] ToArray(uint4x4 m) => m.ToArray(); 15 | 16 | /// 17 | /// Creates a 1D array with all values (internal order) 18 | /// 19 | [Inline] 20 | public static uint[] ToArray1D(uint4x4 m) => m.ToArray1D(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/MathExt.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public static 4 | { 5 | public static T SmoothStep(T a, T b, float t) 6 | where T : operator T - T, operator T + T, operator T * float 7 | { 8 | if (t <= 0) 9 | return a; 10 | else if (t >= 0) 11 | return b; 12 | 13 | let v = (3 - 2 * t) * t * t; 14 | return a + (b - a) * v; 15 | } 16 | 17 | public static T SmootherStep(T a, T b, float t) 18 | where T : operator T - T, operator T + T, operator T * float 19 | { 20 | if (t <= 0) 21 | return a; 22 | else if (t >= 0) 23 | return b; 24 | 25 | let v = ((6 * t - 15) * t + 10) * t * t * t; 26 | return a + (b - a) * v; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_bool2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_bool3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_bool4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_double2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_double3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_double4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_float2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_float3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_float4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_int2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_int3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_int4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_long2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_long3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_long4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_uint2.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_uint3.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Swizzle/swizzle_uint4.glm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma.glm 3 | { 4 | /// 5 | /// Static class that contains static glm functions 6 | /// 7 | static 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/Types.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | typealias long = int64; 4 | 5 | static class IntConsts 6 | { 7 | public const int MaxValue = sizeof(int) == 8 ? int64.MaxValue : int32.MaxValue; 8 | public const int MinValue = sizeof(int) == 8 ? int64.MinValue : int32.MinValue; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/axis.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace Atma 5 | { 6 | public struct axis 7 | { 8 | public float2 normal; 9 | public float2 unit; 10 | public float2 edge; 11 | 12 | public readonly static axis Zero = .(float2.Zero, float2.Zero, float2.Zero); 13 | 14 | public this() 15 | { 16 | this = default; 17 | } 18 | 19 | public this(float2 n, float2 u, float2 e) 20 | { 21 | this.normal = n; 22 | this.unit = u; 23 | this.edge = e; 24 | } 25 | 26 | public override void ToString(String output) 27 | { 28 | output.AppendF("N:{0}, U:{1}, E:{2}", normal, unit, edge); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/bezier.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public struct Bezier 4 | { 5 | public float2 Start; 6 | public float2 Control; 7 | public float2 End; 8 | 9 | public this(float2 start, float2 control, float2 end) 10 | { 11 | Start = start; 12 | Control = control; 13 | End = end; 14 | } 15 | 16 | public float2 this[float t] 17 | { 18 | get => (Start * (1 - t) * (1 - t)) + (Control * 2f * (1 - t) * t) + (End * t * t); 19 | } 20 | 21 | public float GetLengthParametric(int resolution) 22 | { 23 | float2 last = Start; 24 | float length = 0; 25 | for (int i = 1; i <= resolution; i++) 26 | { 27 | float2 at = this[i / (float)resolution]; 28 | length += (at - last).Length; 29 | last = at; 30 | } 31 | 32 | return length; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/facings.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public enum Facings 4 | { 5 | case Right = 1; 6 | case Left = -1; 7 | 8 | public Facings Opposite() 9 | { 10 | if (this == .Right) 11 | return .Left; 12 | else 13 | return .Right; 14 | } 15 | 16 | static public Facings FromInt(int i, Facings ifZero = .Right) 17 | { 18 | if (i == 0) 19 | return ifZero; 20 | else 21 | return i; 22 | } 23 | 24 | static public implicit operator Facings(int i) 25 | { 26 | if (i < 0) 27 | return .Left; 28 | else 29 | return .Right; 30 | } 31 | 32 | static public implicit operator int2(Facings f) 33 | { 34 | return .((int)f, 0); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/float2_ext.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public extension float2 4 | { 5 | public float2 Limit(float length) 6 | { 7 | let sqr = length * length; 8 | if (this.LengthSqr <= sqr) 9 | return this; 10 | 11 | return this.Normalized * length; 12 | } 13 | 14 | public static float2 Truncate(float2 vector, float length) 15 | { 16 | if (vector.LengthSqr <= length * length) 17 | return vector; 18 | 19 | return vector.Normalized * length; 20 | } 21 | 22 | public float2 Rotated(float angleInRad) => (float2.FromAngle(Angle + angleInRad) * Length); 23 | 24 | public float2 Rotate(float2 pivot, float anglesInRad) => float2(this - pivot).Rotated(anglesInRad) + pivot; 25 | 26 | public static float2 Rotate(float2 position, float2 point, float anglesInRad) => float2(position - point).Rotated(anglesInRad) + point; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Math/mtv.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace Atma 5 | { 6 | public struct mtv 7 | { 8 | public double overlap; 9 | public axis smallest; 10 | 11 | public bool intersects { get { return overlap != 0; } } 12 | 13 | public readonly static mtv Zero = .(axis.Zero, 0); 14 | 15 | public this(axis smallest, double overlap) 16 | { 17 | this.smallest = smallest; 18 | this.overlap = overlap; 19 | } 20 | 21 | public override void ToString(String output) 22 | { 23 | output.AppendF("O: {0}, A:{{{1}}}", overlap, smallest); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Atma.Common/src/Platform/OpenGL/GLHelper.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma 3 | { 4 | public struct PushFrameBuffer : IDisposable 5 | { 6 | private int32 _value; 7 | public this(uint framebuffer) 8 | { 9 | _value = default; 10 | GL.GetIntegerv(GL.GL_FRAMEBUFFER, &_value); 11 | GL.BindBuffer(GL.GL_FRAMEBUFFER, (.)framebuffer); 12 | } 13 | 14 | public void Dispose() 15 | { 16 | GL.BindBuffer(GL.GL_FRAMEBUFFER, (.)_value); 17 | } 18 | } 19 | 20 | public struct PushElementArrayBuffer : IDisposable 21 | { 22 | private int32 _value; 23 | public this(uint arraybuffer) 24 | { 25 | _value = default; 26 | GL.GetIntegerv(GL.GL_ELEMENT_ARRAY_BUFFER, &_value); 27 | GL.BindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, (.)arraybuffer); 28 | } 29 | 30 | public void Dispose() 31 | { 32 | GL.BindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, (.)_value); 33 | } 34 | } 35 | 36 | public struct PushArrayBuffer : IDisposable 37 | { 38 | private int32 _value; 39 | public this(uint arraybuffer) 40 | { 41 | _value = default; 42 | GL.GetIntegerv(GL.GL_ARRAY_BUFFER, &_value); 43 | GL.BindBuffer(GL.GL_ARRAY_BUFFER, (.)arraybuffer); 44 | } 45 | 46 | public void Dispose() 47 | { 48 | GL.BindBuffer(GL.GL_ARRAY_BUFFER, (.)_value); 49 | } 50 | } 51 | 52 | public struct PushVertexArray : IDisposable 53 | { 54 | private int32 _value; 55 | public this(uint vertexArray) 56 | { 57 | _value = ?; 58 | GL.GetIntegerv(GL.GL_VERTEX_ARRAY_BINDING, &_value); 59 | GL.BindVertexArray((.)vertexArray); 60 | } 61 | 62 | public void Dispose() 63 | { 64 | GL.BindVertexArray((.)_value); 65 | } 66 | } 67 | 68 | public struct PushShader : IDisposable 69 | { 70 | private int32 _currentShader; 71 | public this(uint shader) 72 | { 73 | _currentShader = default; 74 | GL.GetIntegerv(GL.GL_CURRENT_PROGRAM, &_currentShader); 75 | GL.UseProgram(shader); 76 | } 77 | 78 | public void Dispose() 79 | { 80 | GL.UseProgram((.)_currentShader); 81 | } 82 | } 83 | 84 | public struct PushTexture : IDisposable 85 | { 86 | private int32 last_active_texture; 87 | private int32 last_texture; 88 | private int _index; 89 | 90 | public this(uint32 texture, int index) 91 | { 92 | this = ?; 93 | _index = index; 94 | GL.GetIntegerv(GL.GL_ACTIVE_TEXTURE, &last_active_texture); 95 | GL.ActiveTexture(GL.GL_TEXTURE0 + (uint)index); 96 | 97 | GL.GetIntegerv(GL.GL_TEXTURE_BINDING_2D, &last_texture); 98 | GL.BindTexture(GL.GL_TEXTURE_2D, (uint)texture); 99 | } 100 | 101 | public void Dispose(){ 102 | GL.ActiveTexture(GL.GL_TEXTURE0 + (uint)last_active_texture); 103 | GL.BindTexture(GL.GL_TEXTURE_2D, (uint)last_texture); 104 | } 105 | } 106 | 107 | 108 | 109 | public static class GLHelper 110 | { 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Platform/OpenGL/Graphics/Rendering/GL_IndexBuffer.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | 5 | public extension IndexBuffer 6 | { 7 | private uint32 _indexBuffer; 8 | 9 | protected override void Platform_SetData(void* indices, int count) 10 | { 11 | using (PushElementArrayBuffer(_indexBuffer)) 12 | { 13 | GL.BufferSubData(GL.GL_ELEMENT_ARRAY_BUFFER, 0, ElementSize.Stride * count, indices); 14 | } 15 | } 16 | 17 | protected override void Platform_Bind(GraphicsContext context, Material material) 18 | { 19 | GL.BindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, _indexBuffer); 20 | } 21 | 22 | protected override void Platform_Resize(uint elements) 23 | { 24 | Platform_Destroy(); 25 | Platform_Init(); 26 | } 27 | 28 | protected override void Platform_Init() 29 | { 30 | GL.GenBuffers(1, &_indexBuffer); 31 | _id = _indexBuffer; 32 | 33 | using (PushElementArrayBuffer(_indexBuffer)) 34 | { 35 | GL.BufferData(GL.GL_ELEMENT_ARRAY_BUFFER, (.)BufferSize, null, (.)GL.GL_DYNAMIC_DRAW); 36 | } 37 | } 38 | 39 | protected override void Platform_Destroy() 40 | { 41 | GL.DeleteBuffers(1, &_indexBuffer); 42 | _id = _indexBuffer = 0; 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Platform/OpenGL/Graphics/Rendering/GL_RenderTexture.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | using System.Collections; 5 | 6 | public extension RenderTexture 7 | { 8 | private uint32 _frameBuffer; 9 | 10 | protected override void Platform_Init(TextureFormat[] attachments) 11 | { 12 | for (var i < attachments.Count) 13 | { 14 | var attachment = new Texture(width, height, attachments[i]); 15 | attachment.[Friend]_isFrameBuffer = true; 16 | _attachments.Add(attachment); 17 | } 18 | 19 | GL.GenFramebuffers(1, &_frameBuffer); 20 | _id = _frameBuffer; 21 | } 22 | 23 | protected override void Platform_Resize(int width, int height) 24 | { 25 | for (int i = 0; i < _attachments.Count; i++) 26 | _attachments[i].Resize(width, height); 27 | } 28 | 29 | //[AlwaysInclude, LinkName("FrameBuffer_Bind")] 30 | //protected void FrameBuffer_Bind() 31 | protected override void Platform_Bind() 32 | { 33 | GL.BindFramebuffer((.)GLEnum.FRAMEBUFFER, _frameBuffer); 34 | 35 | // color attachments 36 | int i = 0; 37 | for (Texture texture in _attachments) 38 | { 39 | if (texture.Format.IsTextureColorFormat) 40 | { 41 | GL.FramebufferTexture2D((.)GLEnum.FRAMEBUFFER, (.)(GLEnum.COLOR_ATTACHMENT0 + i), (.)GLEnum.TEXTURE_2D, texture.[Friend]glId, 0); 42 | i++; 43 | } 44 | else 45 | { 46 | GL.FramebufferTexture2D((.)GLEnum.FRAMEBUFFER, (.)GLEnum.DEPTH_STENCIL_ATTACHMENT, (.)GLEnum.TEXTURE_2D, texture.[Friend]glId, 0); 47 | } 48 | } 49 | } 50 | 51 | protected override void Platform_Destroy() 52 | { 53 | GL.DeleteFramebuffers(1, &_frameBuffer); 54 | 55 | _id = _frameBuffer = 0; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Platform/OpenGL/Graphics/Rendering/GL_VertexArray.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma 3 | { 4 | class GL_VertexArray 5 | { 6 | private readonly uint32 ID; 7 | private readonly Shader shader; 8 | private readonly VertexFormat format; 9 | 10 | public ~this() 11 | { 12 | var id = ID; 13 | GL.DeleteVertexArrays(1, &id); 14 | } 15 | 16 | public this(Shader shader, VertexFormat format) 17 | { 18 | this.shader = shader; 19 | this.format = format; 20 | 21 | GL.GenVertexArrays(1, &ID); 22 | //Log.Debug("gen vertex array: {0}", ID); 23 | GL.BindVertexArray(ID); 24 | 25 | //using (PushVertexArray(ID)) 26 | { 27 | for (var attribute in shader.Attributes) 28 | { 29 | if (TrySetupAttribPointer(attribute, format, 0)) 30 | continue; 31 | 32 | // nothing is using this so disable it 33 | GL.DisableVertexAttribArray((.)attribute.Location); 34 | } 35 | } 36 | } 37 | 38 | bool TrySetupAttribPointer(ShaderAttribute attribute, VertexFormat format, uint divisor) 39 | { 40 | if (format.TryGetAttribute(attribute.Name, let element, var ptr)) 41 | { 42 | // this is kind of messy because some attributes can take up multiple slots 43 | // ex. a marix4x4 actually takes up 4 (size 16) 44 | for (int i = 0,uint loc = 0; i < (int)element.Components; i += 4,loc++) 45 | { 46 | var components = Math.Min((int)element.Components - i, 4); 47 | var location = (uint)(attribute.Location + loc); 48 | 49 | GL.EnableVertexAttribArray(location); 50 | GL.VertexAttribPointer(location, components, (.)ConvertVertexType(element.Type), element.Normalized ? 1 : 0, format.Stride, (.)ptr); 51 | 52 | // //GL.VertexAttribDivisor(location, divisor); 53 | 54 | ptr += components * element.ComponentSize; 55 | } 56 | 57 | return true; 58 | } 59 | 60 | return false; 61 | } 62 | 63 | private static GLEnum ConvertVertexType(VertexType value) 64 | { 65 | switch (value) 66 | { 67 | case VertexType.Byte: return GLEnum.UNSIGNED_BYTE; 68 | case VertexType.Short: return GLEnum.SHORT; 69 | case VertexType.Int: return GLEnum.INT; 70 | case VertexType.Float: return GLEnum.FLOAT; 71 | default: 72 | Runtime.Assert(false, "Not implemented"); 73 | } 74 | 75 | return default; 76 | } 77 | 78 | public void Bind() 79 | { 80 | GL.BindVertexArray(ID); 81 | 82 | for (var attribute in shader.Attributes) 83 | { 84 | if (TrySetupAttribPointer(attribute, format, 0)) 85 | continue; 86 | 87 | // nothing is using this so disable it 88 | GL.DisableVertexAttribArray((.)attribute.Location); 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Platform/OpenGL/Graphics/Rendering/GL_VertexBuffer.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | using System.Collections; 5 | 6 | public extension VertexBuffer 7 | { 8 | protected override void Platform_SetData(void* vertices, int count) 9 | { 10 | using (PushArrayBuffer(_vertexBuffer)) 11 | { 12 | GL.BufferSubData(GL.GL_ARRAY_BUFFER, 0, Format.Stride * count, vertices); 13 | } 14 | } 15 | 16 | protected override void Platform_Bind(GraphicsContext context, Material material) 17 | { 18 | GL.BindBuffer(GL.GL_ARRAY_BUFFER, _vertexBuffer); 19 | material.Shader.[Friend]BindVertexArray(Format); 20 | } 21 | 22 | protected override void Platform_Resize(uint elements) 23 | { 24 | Platform_Destroy(); 25 | Platform_Init(); 26 | } 27 | 28 | protected override void Platform_Init() 29 | { 30 | GL.GenBuffers(1, &_vertexBuffer); 31 | _id = _vertexBuffer; 32 | 33 | using (PushArrayBuffer(_vertexBuffer)) 34 | { 35 | GL.BufferData((.)GL.GL_ARRAY_BUFFER, (.)BufferSize, null, (.)GL.GL_DYNAMIC_DRAW); 36 | } 37 | } 38 | 39 | protected override void Platform_Destroy() 40 | { 41 | GL.DeleteBuffers(1, &_vertexBuffer); 42 | _id = _vertexBuffer = 0; 43 | } 44 | 45 | private uint32 _vertexBuffer; 46 | 47 | private static GLEnum ConvertVertexType(VertexType value) 48 | { 49 | switch (value) 50 | { 51 | case VertexType.Byte: return GLEnum.UNSIGNED_BYTE; 52 | case VertexType.Short: return GLEnum.SHORT; 53 | case VertexType.Int: return GLEnum.INT; 54 | case VertexType.Float: return GLEnum.FLOAT; 55 | default: 56 | Runtime.Assert(false, "Not implemented"); 57 | } 58 | 59 | return default; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Platform/SDL2/SDL_Audio.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | using internal Atma; 5 | 6 | public extension Assets 7 | { 8 | protected static override SoundEffect PlatformLoadSoundEffect(StringView path) 9 | { 10 | var sound = new SoundEffect(); 11 | 12 | sound.audioChunk = SDL2.SDLMixer.LoadWAV(path); 13 | if (sound.audioChunk == null) 14 | Log.Warning($"Failed to load sound {path}"); 15 | 16 | return sound; 17 | } 18 | 19 | protected static override Music PlatformLoadMusic(StringView path) 20 | { 21 | var music = new Music(); 22 | 23 | music.musicChunk = SDL2.SDLMixer.LoadMUS(path.Ptr); 24 | if (music.musicChunk == null) 25 | Log.Warning($"Failed to load music {path}"); 26 | 27 | return music; 28 | } 29 | } 30 | 31 | public extension SoundEffect 32 | { 33 | internal SDL2.SDLMixer.Chunk* audioChunk; 34 | 35 | protected override void PlatformPlay() 36 | { 37 | SDL2.SDLMixer.PlayChannel(-1, audioChunk, 0); 38 | } 39 | 40 | public ~this() 41 | { 42 | SDL2.SDLMixer.FreeChunk(audioChunk); 43 | } 44 | } 45 | 46 | public extension Music 47 | { 48 | internal SDL2.SDLMixer.Music* musicChunk; 49 | 50 | protected override void PlatformPlay() 51 | { 52 | SDL2.SDLMixer.PlayMusic(musicChunk, int32.MaxValue); 53 | } 54 | 55 | public ~this() 56 | { 57 | SDL2.SDLMixer.FreeMusic(musicChunk); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Platform/SDL2/SDL_FontLoader.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace Atma 7 | { 8 | public extension Assets 9 | { 10 | typealias byte = uint8; 11 | typealias sbyte = int8; 12 | typealias char = char8; 13 | 14 | private readonly GraphicsManager _graphics; 15 | public this(GraphicsManager graphics) 16 | { 17 | _graphics = graphics; 18 | } 19 | 20 | protected override static SpriteFont PlatformLoadFont(StringView path, int size) 21 | { 22 | let font = SDL2.SDLTTF.OpenFont(path.ToScopeCStr!(), (.)size); 23 | Runtime.Assert(font != null, "Could not init the font"); 24 | 25 | //let glyphBounds = scope List(); 26 | //let cropping = scope List(); 27 | let lineSpacing = SDL2.SDLTTF.FontHeight(font); 28 | //let spacing = 0f; 29 | //let advance = scope List(); 30 | let defaultCharacter = ' '; 31 | 32 | let characters = scope List(); 33 | characters.AddRange("abcdefghijklmnopqrstuvwxyz"); 34 | characters.AddRange("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 35 | characters.AddRange("0123456789"); 36 | characters.AddRange("!@#$%^&*()"); 37 | characters.AddRange(" `~-_=+[{]};:'\",<.>/?\\|"); 38 | 39 | //let glyphs = scope List(characters.Count); 40 | let packer = new Packer(path); 41 | packer.Trim = false; 42 | defer delete packer; 43 | 44 | for (var i = 0; i < characters.Count; i++) 45 | { 46 | let surface = SDL2.SDLTTF.RenderGlyph_Blended(font, (.)characters[i], .(255, 255, 255, 255)); 47 | let pixels = Span((Color*)surface.pixels, surface.w * surface.h); 48 | 49 | packer.AddPixels(StringView(&characters[i], 1), surface.w, surface.h, pixels); 50 | SDL2.SDL.FreeSurface(surface); 51 | } 52 | 53 | let output = packer.Packed; 54 | if (output != null) 55 | { 56 | let page = output.Page; 57 | page.Premultiply(); 58 | 59 | let texture = new Texture(page.Width, page.Height); 60 | texture.SetData(page.Pixels); 61 | 62 | let glyphs = scope List(characters.Count); 63 | 64 | for (var ch in characters) 65 | { 66 | SDL2.SDLTTF.GlyphMetrics(font, (.)ch, let minx, let maxx, let miny, let maxy, let adv); 67 | //let metrics = SDL2.SDLTTF.GlyphMetrics(font, (.)ch, let minx, let maxx, let miny, let maxy, let 68 | // adv); 69 | 70 | var glyph = SpriteFont.Glyph(); 71 | glyph.Advance = adv; 72 | glyph.Character = ch; 73 | let entry = output.Entries[scope String(ch, 1)]; 74 | 75 | glyph.Image = Subtexture(texture, entry.Source, entry.Frame); 76 | glyphs.Add(glyph); 77 | } 78 | texture.Filter = .Linear; 79 | return new SpriteFont(texture, glyphs, defaultCharacter, lineSpacing); 80 | } 81 | 82 | 83 | return null; 84 | } 85 | 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Platform/SDL2/SDL_GLContext.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using SDL2; 4 | 5 | class SDL_GraphicsContext : GraphicsContext 6 | { 7 | public readonly SDL.SDL_GLContext context; 8 | public readonly SDL.Window* window; 9 | 10 | public uint32 LastVertexBuffer = 0; 11 | 12 | public this(SDL.Window* window) 13 | { 14 | this.window = window; 15 | context = SDL.GL_CreateContext(window); 16 | } 17 | 18 | public ~this() 19 | { 20 | SDL.GL_DeleteContext(context); 21 | } 22 | 23 | protected override void MakeActiveInternal() 24 | { 25 | SDL.SDL_GL_MakeCurrent(window, context); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Platform/SDL2/SDL_Graphics.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using SDL2; 4 | using System; 5 | 6 | public extension GraphicsManager 7 | { 8 | public static void* SdlGetProcAddress(StringView string) 9 | { 10 | return SDL.SDL_GL_GetProcAddress(string.ToScopeCStr!()); 11 | } 12 | 13 | public this 14 | { 15 | GL.Init( => SdlGetProcAddress); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Platform/SDL2/SDL_ImageLoader.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace Atma 5 | { 6 | public extension Assets 7 | { 8 | protected static override Image PlatformLoadImage(StringView path) 9 | { 10 | return SDLImage.Load(path); 11 | } 12 | } 13 | } 14 | 15 | namespace Atma 16 | { 17 | using static SDL2.SDL; 18 | 19 | static class SDLImage 20 | { 21 | typealias Color = Atma.Color; 22 | 23 | public static Image Load(StringView path) 24 | { 25 | let sr = scope StreamReader(); 26 | 27 | if (sr.Open(path) case .Err(let err)) 28 | { 29 | Log.Error($"Failed to read file [{path}] err: {err}"); 30 | return null; 31 | } 32 | 33 | let text = scope String(); 34 | if (sr.ReadToEnd(text) case .Err) 35 | { 36 | Log.Error($"Failed to read to end of file [{path}]"); 37 | return null; 38 | } 39 | 40 | let rw = SDL2.SDL.RWFromMem(text.Ptr, (.)text.Length); 41 | let image = SDL2.SDLImage.Load_RW(rw, 1); 42 | 43 | #if false 44 | let rmask = 0xff000000; 45 | let gmask = 0x00ff0000; 46 | let bmask = 0x0000ff00; 47 | let amask = 0x000000ff; 48 | #else 49 | let rmask = 0x000000ff; 50 | let gmask = 0x0000ff00; 51 | let bmask = 0x00ff0000; 52 | let amask = 0xff000000; 53 | #endif 54 | let newSurface = CreateRGBSurface(0, image.w, image.h, 32, rmask, gmask, bmask, amask); 55 | 56 | var rect = SDL2.SDL.Rect(0, 0, image.w, image.h); 57 | SDL_BlitSurface(image, &rect, newSurface, &rect); 58 | 59 | var pixels = new Color[rect.w * rect.h]; 60 | var srcPixels = Span((Color*)newSurface.pixels, pixels.Count); 61 | srcPixels.CopyTo(pixels); 62 | 63 | var imageData = new Image(rect.w, rect.h, pixels); 64 | 65 | FreeSurface(image); 66 | FreeSurface(newSurface); 67 | 68 | return imageData; 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /src/Atma.Common/src/Release.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | public static 5 | { 6 | /*// Common case for any value type 7 | public static void Release(ref T value) where T : struct, IDisposable 8 | { 9 | // do nothing 10 | value.Dispose(); 11 | }*/ 12 | 13 | // Common case for any value type 14 | [SkipCall] 15 | public static void Release(T value) where T : struct 16 | { 17 | // do nothing 18 | } 19 | 20 | public static void Release(T value) where T : struct, IDisposable 21 | { 22 | var value; 23 | value.Dispose(); 24 | } 25 | 26 | // Delete deletable types 27 | public static void Release(T value) where T : class, delete 28 | { 29 | delete value; 30 | } 31 | 32 | // Delete deletable types 33 | public static void Release((K key, V value) kv) where K : var where V : var 34 | { 35 | Release(kv.key); 36 | Release(kv.value); 37 | } 38 | 39 | // Delete array items and then the array itself 40 | public static void Release(T[] value) where T : var 41 | { 42 | if (value == null) 43 | return; 44 | for (int i = 0; i < value.Count; i++) 45 | Release(value[i]); 46 | delete value; 47 | } 48 | 49 | // Delete fixed array items 50 | public static void Release(T[U] value) where T : var where U : const int 51 | { 52 | for (int i = 0; i < U; i++) 53 | Release(value[i]); 54 | } 55 | 56 | // Delete list items and then the list itself 57 | public static void Release(List value) where T : var 58 | { 59 | if (value == null) 60 | return; 61 | for (int i = 0; i < value.Count; i++) 62 | Release(value[i]); 63 | 64 | //value.Clear(); 65 | delete value; 66 | } 67 | 68 | // Delete dictionary keys and values and then the dictionary itself 69 | public static void Release(Dictionary value) where K : var, IHashable where V : var 70 | { 71 | if (value == null) 72 | return; 73 | for (var kv in ref value) 74 | { 75 | Release(kv.key); 76 | Release(*kv.valueRef); 77 | } 78 | delete value; 79 | } 80 | } -------------------------------------------------------------------------------- /src/Atma.Common/src/Sound/Audio.bf: -------------------------------------------------------------------------------- 1 | /*using System; 2 | using System.Collections; 3 | namespace Atma 4 | { 5 | public class Audio 6 | { 7 | public const int MAXSOUNDS = 2; 8 | 9 | private List _activeSounds = new .() ~ delete _; 10 | 11 | static void mixaudio(void* unused, uint8* stream, int len) 12 | { 13 | } 14 | 15 | public this() 16 | { 17 | PlatformInitialize(); 18 | } 19 | 20 | public ~this() 21 | { 22 | PlatformDestroy(); 23 | } 24 | 25 | protected extern static void PlatformInitialize(); 26 | 27 | protected extern static void PlatformDestroy(); 28 | } 29 | }*/ 30 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Sound/Music.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | //As far as I know SDL2 only supports a single music file being played 4 | //we need to eventually write an audio manager to track this sort of think 5 | //and fade things in and out 6 | public class Music 7 | { 8 | public void Play() => PlatformPlay(); 9 | 10 | protected extern void PlatformPlay(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Sound/SoundEffect.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | //We should eventually write an audio manager to track all the sound effects 4 | //we are playing 5 | public class SoundEffect 6 | { 7 | public void Play(float x, float y, float z) => PlatformPlay(); 8 | 9 | protected extern void PlatformPlay(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Utils/Display.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | 5 | /// 6 | /// A Wrapper around a specific Monitor 7 | /// 8 | public struct Display 9 | { 10 | public readonly int Index; 11 | 12 | /// 13 | /// Whether this Monitor is the Primary Monitor 14 | /// 15 | public readonly bool IsPrimary; 16 | 17 | /// 18 | /// The name of the Monitor 19 | /// 20 | public readonly StringView Name;// = new .() ~ delete _; 21 | 22 | /// 23 | /// The bounds of the Monitor, in Screen Coordinates 24 | /// 25 | public readonly rect Bounds; 26 | 27 | /// 28 | /// The Content Scale of the Monitor 29 | /// 30 | public readonly float2 Scale; 31 | 32 | public this(int index, bool isPrimary, StringView name, rect bounds, float2 scale) 33 | { 34 | Index = index; 35 | IsPrimary = isPrimary; 36 | Name = name; 37 | Bounds = bounds; 38 | Scale = scale; 39 | } 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Utils/Emitter.bf: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System; 3 | using System.Reflection; 4 | namespace Atma 5 | { 6 | public class Emitter 7 | { 8 | public abstract class AbstractObserverList 9 | { 10 | public abstract void Emit(void* ptr); 11 | } 12 | 13 | public class ObserverList : AbstractObserverList 14 | { 15 | public delegate void Observer(K k); 16 | public readonly List Observers = new .() ~ DeleteContainerAndItems!(_); 17 | 18 | public override void Emit(void* ptr) 19 | { 20 | for (var it in Observers) 21 | it(*(K*)ptr); 22 | } 23 | 24 | public int IndexOf(Observer o) 25 | { 26 | for (var i < Observers.Count) 27 | if (Delegate.Equals(o, Observers[i])) 28 | return i; 29 | 30 | return -1; 31 | } 32 | } 33 | 34 | private Dictionary _observers = new .() ~ DeleteDictionaryAndValues!(_); 35 | 36 | private List _data = new .() ~ delete _; 37 | 38 | public void AddObserver(ObserverList.Observer o) 39 | where K : struct 40 | { 41 | if (_observers.TryAdd(typeof(K), ?, var ptr)) 42 | *ptr = new ObserverList(); 43 | 44 | let list = *(ObserverList*)ptr; 45 | list.Observers.Add(o); 46 | } 47 | 48 | public void RemoveObserver(ObserverList.Observer o) 49 | where K : struct 50 | { 51 | if (!_observers.TryGetValue(typeof(K), var ptr)) 52 | return; 53 | 54 | let list = (ObserverList)ptr; 55 | let index = list.IndexOf(o); 56 | Assert.IsFalse(index == -1); 57 | 58 | delete list.Observers[index]; 59 | list.Observers.RemoveAt(index); 60 | } 61 | 62 | public void Signal() 63 | { 64 | var buffer = _data.Ptr; 65 | let endBuffer = buffer + _data.Count; 66 | 67 | while (buffer < endBuffer) 68 | { 69 | let typeId = *((TypeId*)buffer); 70 | let type = Type.[Friend]GetType(typeId); 71 | buffer += sizeof(int32); 72 | 73 | if (_observers.TryGetValue(type, var list)) 74 | list.Emit((void*)buffer); 75 | 76 | buffer += type.Stride; 77 | } 78 | _data.Clear(); 79 | } 80 | 81 | public void Emit(K k) 82 | where K : struct 83 | { 84 | Log.Debug(scope $"Emit :: {k}"); 85 | 86 | let type = typeof(K); 87 | if (!_observers.TryGetValue(type, var ptr)) 88 | return; 89 | 90 | let size = type.Stride + sizeof(int32); 91 | let addr = (TypeId*)_data.GrowUnitialized(size); 92 | *addr = type.TypeId; 93 | 94 | let payload = (K*)(addr + 1); 95 | *payload = k; 96 | } 97 | 98 | public void EmitNow(K k) 99 | where K : struct 100 | { 101 | let type = typeof(K); 102 | if (!_observers.TryGetValue(type, var list)) 103 | return; 104 | 105 | var k; 106 | list.Emit((void*)&k); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Utils/Flags.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public struct Flags 4 | { 5 | public uint64 Value; 6 | 7 | public void Set(uint64 flags) mut 8 | { 9 | Value |= flags; 10 | } 11 | 12 | public void Clear(uint64 flags) mut 13 | { 14 | Value &= (uint64.MaxValue ^ flags); 15 | } 16 | 17 | public bool Has(uint64 flags) => (Value & flags) == flags; 18 | 19 | public bool Any(uint64 flags) => (Value & flags) != 0; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Utils/Mask.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Atma 4 | { 5 | /// 6 | /// A Struct for managing Masks 7 | /// 8 | public struct Mask : uint64 9 | { 10 | public const uint64 All = 0xFFFFFFFFFFFFFFFF; 11 | public const uint64 None = 0; 12 | //public const uint64 Default = (1 << 0); 13 | 14 | public this(uint64 value) 15 | { 16 | this = value; 17 | } 18 | 19 | [Inline] 20 | public void Set(uint64 mask, bool state) mut 21 | { 22 | if (state) 23 | Add(mask); 24 | else 25 | Remove(mask); 26 | } 27 | 28 | [Inline] 29 | public void Set(Mask mask, bool state) mut 30 | { 31 | if (state) 32 | Add(mask); 33 | else 34 | Remove(mask); 35 | } 36 | 37 | [Inline] 38 | public void Add(Mask mask) mut 39 | { 40 | this |= mask; 41 | } 42 | 43 | 44 | [Inline] 45 | public void Add(uint64 mask) mut 46 | { 47 | this |= mask; 48 | } 49 | 50 | [Inline] 51 | public void Remove(Mask mask) mut 52 | { 53 | this &= ~mask; 54 | } 55 | 56 | [Inline] 57 | public void Remove(uint64 mask) mut 58 | { 59 | this &= ~mask; 60 | } 61 | 62 | [Inline] 63 | public bool Has(uint64 mask) 64 | { 65 | return (this & mask) > 0; 66 | } 67 | 68 | [Inline] 69 | public bool Has(Mask mask) 70 | { 71 | return (this & mask) > 0; 72 | } 73 | 74 | [Inline] 75 | public static Mask Make(int index) 76 | { 77 | System.Diagnostics.Debug.Assert(index >= 0 && index < 64); 78 | 79 | return (((uint64)1 << index)); 80 | } 81 | 82 | /*[Inline] 83 | public static Mask operator|(Mask a, Mask b) => (a | b); 84 | 85 | [Inline] 86 | public static Mask operator&(Mask a, Mask b) => (a & b);*/ 87 | 88 | /*public static implicit operator uint64(Mask mask) => mask; 89 | public static implicit operator Mask(uint64 val) => (val);*/ 90 | 91 | } 92 | } 93 | 94 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Utils/StringId.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma 3 | { 4 | public struct StringId : int 5 | { 6 | public this(StringView s) 7 | { 8 | this = s.GetHashCode(); 9 | } 10 | 11 | public static implicit operator StringId(StringView it) => it.GetHashCode(); 12 | public static implicit operator StringId(String it) => it.GetHashCode(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Utils/Timer.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Atma 4 | { 5 | public struct Timer 6 | { 7 | private int64 _duration; 8 | private int64 _end; 9 | 10 | public this(float duration) 11 | { 12 | _duration = ?; 13 | _end = ?; 14 | Reset(duration); 15 | } 16 | 17 | public float t => 1f - (Remaining / (float)_duration); 18 | public int64 Remaining => Math.Max(_end - Time.Time, 0); 19 | public bool Completed => _end > 0 && Remaining == 0; 20 | 21 | public static implicit operator bool(Timer it) => it.Completed; 22 | 23 | public void Reset() mut 24 | { 25 | _end = Time.Time + _duration; 26 | } 27 | 28 | public void Reset(float duration) mut 29 | { 30 | 31 | _duration = (.)(duration * Time.MicroToSeconds) ; 32 | _end = Time.Time + _duration; 33 | } 34 | 35 | public void Clear() mut 36 | { 37 | _end = 0; 38 | } 39 | } 40 | 41 | public struct Duration 42 | { 43 | private int64 _duration; 44 | private int64 _end; 45 | 46 | public this(float duration) 47 | { 48 | _duration = ?; 49 | _end = ?; 50 | Reset(duration); 51 | } 52 | 53 | public float t => 1f - (Math.Max(_end - Time.Time, 0) / (float)_duration); 54 | public float Remaining => Math.Max(_end - Time.Time, 0); 55 | public bool Completed => _end > 0 && Remaining > 0; 56 | 57 | public static implicit operator bool(Duration it) => it.Completed; 58 | 59 | public void Reset() mut 60 | { 61 | _end = Time.Time + _duration; 62 | } 63 | 64 | public void Reset(float duration) mut 65 | { 66 | _duration = (.)(duration * Time.MicroToSeconds); 67 | _end = Time.Time + _duration; 68 | } 69 | 70 | public void Clear() mut 71 | { 72 | _end = 0; 73 | } 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /src/Atma.Common/src/Utils/Wrap.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public struct Wrap 4 | where T : operator -- T 5 | where T : operator ++ T 6 | where T : operator T - T 7 | where T : operator T + T 8 | where T : operator T % T 9 | where bool : operator T < T 10 | { 11 | private T _min; 12 | private T _max; 13 | private T _value; 14 | 15 | public this(T value, T min, T max) 16 | { 17 | _value = value; 18 | _min = min; 19 | _max = max; 20 | } 21 | 22 | public this(T min, T max) : this(default, min, max) 23 | { 24 | } 25 | 26 | public this(T max) : this(default, default, max) 27 | { 28 | } 29 | 30 | public static implicit operator T(Wrap t) => t._value; 31 | 32 | public static Wrap operator++(Wrap t) 33 | { 34 | var x = t._value; 35 | x++; 36 | return .(Calc.Wrap(x, t._min, t._max), t._min, t._max); 37 | } 38 | 39 | public static Wrap operator--(Wrap t) 40 | { 41 | var x = t._value; 42 | x--; 43 | return .(Calc.Wrap(x, t._min, t._max), t._min, t._max); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Atma.Entities/BeefProj.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | Dependencies = {corlib = "*", "Atma.Common" = "*"} 3 | 4 | [Project] 5 | Name = "Atma.Entities" 6 | TargetType = "BeefLib" 7 | StartupObject = "Atma.Entities.Program" 8 | -------------------------------------------------------------------------------- /src/Atma.Entities/src/Component.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma 3 | { 4 | public class Component 5 | { 6 | internal Entity _entity; 7 | internal bool _inComponentList = false; 8 | 9 | public Entity Entity => _entity; 10 | public Scene Scene => _entity?.Scene; 11 | 12 | protected IntegratorList Integrations = .(); 13 | 14 | private bool _active; 15 | internal bool _track; 16 | 17 | public bool Active 18 | { 19 | get => _active == true; 20 | set => _active = value; 21 | } 22 | 23 | protected float2 Position => _entity.Position; 24 | protected float2 WorldPosition => _entity.WorldPosition; 25 | 26 | protected float Rotation => _entity.Rotation; 27 | protected float WorldRotation => _entity.WorldRotation; 28 | 29 | protected float2 Direction => float2.FromAngle(_entity.Rotation); 30 | protected float2 WorldDirection => float2.FromAngle(_entity.WorldRotation); 31 | 32 | protected this(bool active, bool track = false) 33 | { 34 | _active = active; 35 | _track = track; 36 | } 37 | 38 | public virtual void Added(Entity entity) 39 | { 40 | System.Diagnostics.Debug.Assert(_entity == null); 41 | _entity = entity; 42 | } 43 | 44 | public virtual void Removed(Entity entity) 45 | { 46 | System.Diagnostics.Debug.Assert(_entity == entity); 47 | _entity = null; 48 | } 49 | 50 | 51 | public virtual void Update() { } 52 | 53 | public virtual void FixedUpdate() { } 54 | 55 | public virtual void Inspect() { } 56 | 57 | public virtual void DebugRender() { } 58 | 59 | public virtual void Destroying() { } 60 | 61 | public virtual void Ready() { } 62 | 63 | public ~this() 64 | { 65 | Integrations.Dispose(); 66 | } 67 | 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Atma.Entities/src/Components/CameraComponent.bf: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System; 3 | namespace Atma 4 | { 5 | public class Camera2DComponent : Component 6 | { 7 | private Camera2D _camera; 8 | 9 | public static implicit operator Camera2D(Camera2DComponent it) => it._camera; 10 | 11 | public this(Camera2D camera) : base(false, true) 12 | { 13 | _camera = camera; 14 | } 15 | 16 | public bool RendersLayer(int renderLayer) => _camera.RendersLayer(renderLayer); 17 | 18 | public override void Added(Entity entity) 19 | { 20 | base.Added(entity); 21 | 22 | if (_camera.RendererCount == 0) 23 | { 24 | _camera.AddRenderer(new SceneRenderer(this.Entity.Scene)); 25 | Log.Debug("Scene has begun with no renderer. A DefaultRenderer was added automatically so that something is visible. "); 26 | } 27 | } 28 | 29 | public void Render() 30 | { 31 | _camera.Render(); 32 | } 33 | 34 | public override void Inspect() 35 | { 36 | let wp = _camera.ScreenToWorld(Core.Input.MousePosition); 37 | ImGui.Text(scope $"MouseToWorld: {wp}"); 38 | 39 | base.Inspect(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Atma.Entities/src/Components/Renderable.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma 3 | { 4 | public interface IRenderable 5 | { 6 | public void Render(); 7 | 8 | //public int RenderLayer { get; } 9 | public int RenderLayer { get; } 10 | public float Depth { get; } 11 | public Material Material { get; } 12 | public void Inspect(); 13 | } 14 | 15 | public interface IRenderableComponent : IRenderable 16 | { 17 | public bool Visible { get; } 18 | public aabb2 LocalBounds { get; } 19 | } 20 | 21 | /// 22 | /// interface that when applied to a Component will register it to be rendered by the Scene Renderers. Implement 23 | // this very carefully! Changing things like layerDepth/renderLayer/material need to update the Scene 24 | // RenderableComponentList 25 | public abstract class Renderable : Component, IRenderableComponent 26 | { 27 | public static int Compare(IRenderable self, IRenderable other) 28 | { 29 | var res = self.RenderLayer <=> other.RenderLayer; 30 | if (res == 0) 31 | { 32 | res = self.Depth <=> other.Depth; 33 | if (res == 0) 34 | { 35 | // both null or equal 36 | if (ReferenceEquals(self.Material, other.Material)) 37 | return 0; 38 | 39 | if (other.Material == null) 40 | return -1; 41 | 42 | return 1; 43 | } 44 | } 45 | 46 | return res; 47 | } 48 | 49 | public this(bool active = false) : base(active) 50 | { 51 | } 52 | 53 | private bool _visible; 54 | public bool Visible 55 | { 56 | get => _visible == true; 57 | set => _visible = value; 58 | } 59 | 60 | public abstract aabb2 LocalBounds { get; } 61 | public aabb2 WorldBounds 62 | { 63 | get 64 | { 65 | var bounds = LocalBounds; 66 | bounds.Center = Entity.WorldPosition; 67 | return bounds; 68 | } 69 | } 70 | 71 | private int _renderLayer = 0; 72 | public int RenderLayer => _renderLayer + Entity.RenderLayer; 73 | public void SetRenderLayer(int layer) => _renderLayer = layer; 74 | 75 | 76 | private float _depth = 0; 77 | public float Depth => _depth + Entity.Depth; 78 | public void SetDepth(float depth) => _depth = depth; 79 | 80 | /// 81 | /// used by Renderers to specify how this sprite should be rendered. If non-null, it is automatically disposed 82 | // of when the Component is removed from the Entity. 83 | public Material Material { get; set; } 84 | 85 | 86 | /// 87 | /// called by a Renderer. The Camera can be used for culling and the Batcher instance to draw with. 88 | /// 89 | public abstract void Render(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Atma.Entities/src/Components/Sprite.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | public class Sprite : GraphicsComponent 4 | { 5 | public Subtexture Subtexture; 6 | public Color Outline = Color.Transparent; 7 | 8 | public this(Subtexture subtexture, bool active = false) 9 | { 10 | Subtexture = subtexture; 11 | CenterOrigin(); 12 | } 13 | 14 | public override void Render() 15 | { 16 | if (Subtexture.Texture != null) 17 | RenderAt(RenderPosition); 18 | } 19 | 20 | public void RenderOutlineAt(float2 position) 21 | { 22 | Core.Draw.Image(.(Subtexture, position, Scale, Origin, TotalRotation, Outline, Skew, .Filled)); 23 | //Subtexture.DrawOutline(position, Origin, Tint, Scale, TotalRotation, Effects, Outline); 24 | } 25 | 26 | public void RenderAt(float2 position) 27 | { 28 | let mode = Washed ? DrawMode.Washed : DrawMode.Multiplied; 29 | RenderAt(position, mode, Tint); 30 | } 31 | 32 | public void RenderAt(float2 position, DrawMode mode, Color color) 33 | { 34 | if (Outline.A > 0) 35 | RenderOutlineAt(position); 36 | 37 | Core.Draw.Image(.(Subtexture, position, Scale, Origin, TotalRotation, color.Premultiplied, Skew, mode)); 38 | } 39 | 40 | public override void DebugRender() 41 | { 42 | base.DebugRender(); 43 | 44 | Core.Draw.Pixel(WorldPosition, .Red); 45 | } 46 | 47 | public override float Width 48 | { 49 | get { return Subtexture.Width; } 50 | } 51 | 52 | public override float Height 53 | { 54 | get { return Subtexture.Height; } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Atma.Entities/src/Core.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma 3 | { 4 | using internal Atma; 5 | 6 | public extension Core 7 | { 8 | public static Scene Scene; 9 | 10 | internal static Func _initialScene ~ delete _; 11 | 12 | public static int RunInitialScene(StringView title, int width, int height, Window.WindowFlags flags = .Hidden) 13 | where InitialScene : Scene 14 | { 15 | _initialScene = new () => new InitialScene(); 16 | return scope Game(title, width, height, flags).Run(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Atma.Entities/src/Game.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Atma 3 | { 4 | using internal Atma; 5 | 6 | public class Game : Core 7 | { 8 | protected override void Update() 9 | { 10 | Scene.InternalUpdate(); 11 | } 12 | 13 | protected override void FixedUpdate() 14 | { 15 | Scene.InternalFixedUpdate(); 16 | } 17 | 18 | protected override void Render() 19 | { 20 | Scene.Render(); 21 | } 22 | 23 | protected override void Initialize() 24 | { 25 | Scene = _initialScene(); 26 | DeleteAndNullify!(_initialScene); 27 | } 28 | 29 | protected override void Unload() 30 | { 31 | delete Scene; 32 | } 33 | 34 | public this(StringView title, int width, int height, Window.WindowFlags windowFlags) : base(title, width, height, windowFlags) 35 | { 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Atma.Entities/src/RenderableComponentList.bf: -------------------------------------------------------------------------------- 1 | /*using System.Collections; 2 | using System; 3 | using internal Atma; 4 | 5 | namespace Atma 6 | { 7 | public class RenderableComponentList 8 | { 9 | typealias FastList = System.Collections.List; 10 | typealias RenderList = (int RenderLayer, List Renderables, Comparison Sorter); 11 | 12 | // global updateOrder sort for the IRenderable lists 13 | public static Comparison DefaultRenderableSort = (new => Renderable.Compare) ~ delete _; 14 | 15 | private List _renderList = new .(); 16 | 17 | #region array access 18 | 19 | private int _count = 0; 20 | public int Count => _count;// _components.Count; 21 | 22 | //public Renderable this[int index] => _components.Ptr[index]; 23 | public List.Enumerator GetEnumerator() => _renderList.GetEnumerator(); 24 | 25 | #endregion 26 | 27 | public ~this() 28 | { 29 | for (var it in _renderList) 30 | { 31 | delete it.Renderables; 32 | delete it.Sorter; 33 | } 34 | 35 | delete _renderList; 36 | } 37 | 38 | 39 | public void Add(Renderable component) 40 | { 41 | _count++; 42 | 43 | if (component._renderList != null) 44 | Remove(component); 45 | 46 | component._renderList = this; 47 | let layer = GetLayer(component.RenderLayer); 48 | layer.Renderables.Add(component); 49 | } 50 | 51 | public void Remove(Renderable component) 52 | { 53 | _count--; 54 | let layer = GetLayer(component.RenderLayer); 55 | layer.Renderables.RemoveFast(component); 56 | } 57 | 58 | private RenderList GetLayer(int renderLayer) 59 | { 60 | for (var it in _renderList) 61 | if (it.RenderLayer == renderLayer) 62 | return it; 63 | 64 | RenderList layer = (renderLayer, new .(), null); 65 | _renderList.Add(layer); 66 | _renderList.Sort(scope (lhs, rhs) => lhs.RenderLayer <=> rhs.RenderLayer); 67 | return layer; 68 | } 69 | 70 | public void UpdateLists() 71 | { 72 | for (var it in _renderList) 73 | { 74 | let sorter = it.Sorter ?? DefaultRenderableSort; 75 | it.Renderables.Sort(sorter); 76 | } 77 | } 78 | } 79 | }*/ -------------------------------------------------------------------------------- /src/Atma.Entities/src/Sorting.bf: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | 3 | namespace Atma 4 | { 5 | public static class Sort 6 | { 7 | public static void SortByDepthThenY(List self) where T : var 8 | { 9 | //dst sqr is probably going to skew the depth bias? 10 | self.Sort(scope (a, b) => 11 | { 12 | let d = a.Depth - b.Depth; 13 | if (d == 0) 14 | { 15 | let y = a.SortKey - b.SortKey; 16 | 17 | if (y < 0) 18 | return -1; 19 | else if (y > 0) 20 | return 1; 21 | 22 | return 0; 23 | } 24 | else if (d < 0) 25 | return -1; 26 | 27 | return 1; 28 | }); 29 | } 30 | 31 | public static void SortByY(List self) where T : var 32 | { 33 | //dst sqr is probably going to skew the depth bias? 34 | self.Sort(scope (a, b) => 35 | { 36 | let y = a.SortKey - b.SortKey; 37 | 38 | if (y < 0) 39 | return -1; 40 | else if (y > 0) 41 | return 1; 42 | 43 | return 0; 44 | }); 45 | } 46 | 47 | public static void SortByClosest(List self, float2 worldPosition) where T : var 48 | { 49 | //dst sqr is probably going to skew the depth bias? 50 | self.Sort(scope (a, b) => 51 | { 52 | var ad = float2.DistanceSqr(worldPosition, a.WorldPosition); 53 | var bd = float2.DistanceSqr(worldPosition, b.WorldPosition); 54 | if (ad < bd) 55 | return -1; 56 | else if (ad > bd) 57 | return 1; 58 | 59 | return 0; 60 | }); 61 | } 62 | 63 | /*public static void SortBy(List self, K dlg) 64 | where T : var 65 | where K: delegate int (T t) 66 | { 67 | self.Sort(scope (a, b) => 68 | { 69 | let av = dlg(a); 70 | let bv = dlg(b); 71 | if(av < bv) return -1; 72 | if(av > bv) return 1; 73 | return 0; 74 | }); 75 | }*/ 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Atma.Systems/BeefProj.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | Dependencies = {corlib = "*", "Atma.Common" = "*"} 3 | 4 | [Project] 5 | Name = "Atma.Systems" 6 | TargetType = "BeefLib" 7 | StartupObject = "Atma.Systems.Program" 8 | -------------------------------------------------------------------------------- /src/Atma.Systems/src/EntityChunk.bf: -------------------------------------------------------------------------------- 1 | namespace Atma 2 | { 3 | using System; 4 | using System.Collections; 5 | using internal Atma; 6 | 7 | public sealed class EntityChunk 8 | { 9 | private List _entityRefs ~ delete _; 10 | 11 | internal ReadOnlySpan Entities => _entityRefs.Slice(); 12 | internal readonly ComponentPackedArray PackedArray ~ delete _; 13 | 14 | public int Count => _entityRefs.Count; 15 | public int Free => Entity.ENTITY_MAX - Count; 16 | 17 | public readonly EntitySpec Specification; 18 | 19 | public readonly int SpecIndex; 20 | public readonly int ChunkIndex; 21 | 22 | 23 | internal this(EntitySpec specifcation, int specIndex, int chunkIndex) 24 | { 25 | Specification = new EntitySpec(specifcation); 26 | PackedArray = new ComponentPackedArray(specifcation); 27 | _entityRefs = new List(PackedArray.Length); 28 | SpecIndex = specIndex; 29 | ChunkIndex = chunkIndex; 30 | } 31 | 32 | internal void Create(EntityRef entity) 33 | { 34 | Create(scope EntityRef[](entity)); 35 | } 36 | 37 | internal int Create(Span entities) 38 | { 39 | var amountToCreate = entities.Length > Free ? Free : entities.Length; 40 | for (var i = 0; i < amountToCreate; i++) 41 | { 42 | var entity = ref entities[i]; 43 | var id = entity.ID; 44 | 45 | entity.Replace(Entity(id, SpecIndex, ChunkIndex, _entityRefs.Count)); 46 | _entityRefs.Add(entity); 47 | } 48 | return amountToCreate; 49 | } 50 | 51 | internal void Delete(EntityRef entity) 52 | { 53 | Delete(scope EntityRef[](entity)); 54 | } 55 | 56 | internal void Delete(Span entities) 57 | { 58 | for (var i = 0; i < entities.Length; i++) 59 | { 60 | var entity = ref entities[i]; 61 | var index = entity.Index; 62 | if (_entityRefs.RemoveAtWithSwap(index, true)) 63 | { 64 | PackedArray.Move(_entityRefs.Count, index); 65 | _entityRefs[index].Index = index; 66 | } 67 | } 68 | } 69 | 70 | public Span GetComponentData(int index = -1) 71 | where T : struct 72 | { 73 | return PackedArray.GetComponentData(index).Slice(0, _entityRefs.Count); 74 | } 75 | 76 | internal Span GetComponentData(int index, ComponentType componentType = default) 77 | where T : struct 78 | { 79 | return PackedArray.GetComponentData(index, componentType).Slice(0, _entityRefs.Count); 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /src/Atma.Systems/src/SpanExtensions.bf: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Atma 4 | { 5 | public static 6 | { 7 | public static (int Size, int Stride) EntitySize(this Span components) 8 | { 9 | var size = 0; 10 | var stride = 0; 11 | for (var it in ref components) 12 | { 13 | size += it.Size; 14 | stride += it.Stride; 15 | } 16 | 17 | return (size, stride); 18 | } 19 | 20 | public static void InsertionSort(this Span span) 21 | { 22 | for (var i = 0; i < span.Length - 1; i++) 23 | { 24 | for (var j = i + 1; j > 0; j--) 25 | { 26 | if (span[j - 1] > span[j]) 27 | { 28 | var temp = span[j - 1]; 29 | span[j - 1] = span[j]; 30 | span[j] = temp; 31 | } 32 | } 33 | } 34 | } 35 | 36 | public static void InsertionSort(this Span span) 37 | where T : struct, IHashable 38 | { 39 | for (var i = 0; i < span.Length - 1; i++) 40 | { 41 | for (var j = i + 1; j > 0; j--) 42 | { 43 | if (span[j - 1].GetHashCode() > span[j].GetHashCode()) 44 | { 45 | var temp = span[j - 1]; 46 | span[j - 1] = span[j]; 47 | span[j] = temp; 48 | } 49 | } 50 | } 51 | } 52 | 53 | public static void Sort(this Span span) 54 | where T : struct 55 | where int : operator T <=> T 56 | { 57 | for (var i = 0; i < span.Length; ++i) 58 | { 59 | for (var j = 0; j < span.Length - 1; ++j) 60 | //TODO: this code doesn't appear correct to me, j shouldn't start at 0? 61 | { 62 | if (span[j] <=> span[j + 1] > 0) 63 | { 64 | var temp = span[j]; 65 | span[j] = span[j + 1]; 66 | span[j + 1] = temp; 67 | } 68 | } 69 | } 70 | } 71 | 72 | public static void Sort(this Span span, TComparer comparer) 73 | where T : struct 74 | where TComparer : Comparison 75 | { 76 | for (var i = 0; i < span.Length; ++i) 77 | { 78 | //TODO: this code doesn't appear correct to me, j shouldn't start at 0? 79 | for (var j = 0; j < span.Length - 1; ++j) 80 | { 81 | if (comparer(span[j], span[j + 1]) > 0) 82 | { 83 | var temp = span[j]; 84 | span[j] = span[j + 1]; 85 | span[j + 1] = temp; 86 | } 87 | } 88 | } 89 | } 90 | 91 | //public static void Sort(this Span keys, Span items); 92 | 93 | //public static void Sort(this Span keys, 94 | // Span items, TComparer comparer) 95 | // where TComparer : IComparer; 96 | 97 | //public static void Sort(this Span keys, 98 | // Span items, System.Comparison comparison); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/Atma.Systems/src/UnmanagedType.bf: -------------------------------------------------------------------------------- 1 | /*namespace Atma 2 | { 3 | using System; 4 | using System.Reflection; 5 | using System.Threading; 6 | using System.Collections; 7 | using internal Atma; 8 | 9 | public struct UnmanagedType 10 | { 11 | internal static int UniqueID; 12 | 13 | public readonly int32 ID; 14 | public readonly int32 Size; 15 | 16 | internal this(Type type, int32 size) 17 | { 18 | ID = (.)type.TypeId;// type.FullName.StableHashCode(); 19 | Size = size; 20 | } 21 | /*internal this(int32 id, int32 size) 22 | { 23 | ID = id;// type.GetHashCode();// type.FullName.StableHashCode(); 24 | Size = size; 25 | }*/ 26 | } 27 | 28 | public static class UnmanagedType 29 | where T : struct 30 | { 31 | public static readonly UnmanagedType Type; 32 | 33 | static this() 34 | { 35 | var size = sizeof(T); 36 | //var type = UnmanagedType.UniqueID++; 37 | Type = UnmanagedType(typeof(T), size); 38 | } 39 | } 40 | 41 | public struct UnknownType 42 | { 43 | } 44 | 45 | public sealed class UnmanagedHelper 46 | { 47 | internal static LookupList _typeLookup = new LookupList(); 48 | 49 | public static Type LookUp(int id) 50 | { 51 | if (!_typeLookup.TryGetValue(id, let type)) 52 | return typeof(UnknownType); 53 | 54 | return type; 55 | } 56 | 57 | private Dictionary _unmanagedCache = new Dictionary(); 58 | private Dictionary _cacheTypes = new Dictionary(); 59 | 60 | public bool IsUnManaged(Type t) 61 | { 62 | var result = false; 63 | if (_unmanagedCache.ContainsKey(t)) 64 | return _unmanagedCache[t]; 65 | else if (t.IsPrimitive || t.IsPointer || t.IsEnum) 66 | result = true; 67 | else if (t.IsGenericType || !t.IsValueType) 68 | result = false; 69 | else 70 | result = t.GetFields(BindingFlags.Public | 71 | BindingFlags.NonPublic | BindingFlags.Instance) 72 | .All(x => IsUnManaged(x.FieldType)); 73 | 74 | _unmanagedCache.Add(t, result); 75 | return result; 76 | } 77 | 78 | public bool GetInfo(Type t, out UnmanagedType unmanagedType) 79 | { 80 | unmanagedType = default; 81 | if (!IsUnManaged(t)) 82 | return false; 83 | 84 | if (!_cacheTypes.TryGetValue(t, out unmanagedType)) 85 | { 86 | var size = Size.Of(t); 87 | unmanagedType = new UnmanagedType(t, size); 88 | _cacheTypes.Add(t, unmanagedType); 89 | _typeLookup.TryAdd(unmanagedType.ID, t); 90 | } 91 | 92 | return true; 93 | } 94 | } 95 | }*/ 96 | -------------------------------------------------------------------------------- /tests/Atma.Common.Tests/BeefProj.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | 3 | [Project] 4 | Name = "Atma.Common.Tests" 5 | TargetType = "BeefTest" 6 | StartupObject = "Atma.Common.Tests.Program" 7 | -------------------------------------------------------------------------------- /tests/Atma.Entities.Tests/BeefProj.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | 3 | [Project] 4 | Name = "Atma.Entities.Tests" 5 | TargetType = "BeefTest" 6 | StartupObject = "Atma.Entities.Tests.Program" 7 | -------------------------------------------------------------------------------- /tests/Atma.Math.Tests/BeefProj.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | Dependencies = {corlib = "*", "Atma.Math" = "*"} 3 | 4 | [Project] 5 | Name = "Atma.Math.Tests" 6 | TargetType = "BeefTest" 7 | StartupObject = "Atma.Math.Tests.Program" 8 | -------------------------------------------------------------------------------- /tests/Atma.Systems.Tests/BeefProj.toml: -------------------------------------------------------------------------------- 1 | FileVersion = 1 2 | Dependencies = {corlib = "*", "Atma.Common" = "*", "Atma.Systems" = "*"} 3 | 4 | [Project] 5 | Name = "Atma.Systems.Tests" 6 | TargetType = "BeefTest" 7 | StartupObject = "Atma.Systems.Tests.Program" 8 | --------------------------------------------------------------------------------