Skip to content

Instantly share code, notes, and snippets.

@prime31
prime31 / ldtk.zig
Created November 4, 2023 23:57
LDtk export from json schema
pub const Ld = struct {
description: []const u8,
title: []const u8,
// renamed from: "$schema
schema: []const u8,
// renamed from: "$ref
ref: []const u8,
version: []const u8,
// renamed from: "LdtkJsonRoot
ldtk_json_root: LdtkJsonRoot,
@prime31
prime31 / glowy.wgsl
Created March 28, 2023 14:34
Bevy Material Example
#import bevy_pbr::mesh_view_bindings
#import bevy_pbr::mesh_bindings
#import bevy_pbr::pbr_types
#import bevy_pbr::utils
#import bevy_pbr::clustered_forward
#import bevy_pbr::lighting
#import bevy_pbr::shadows
#import bevy_pbr::pbr_functions
@prime31
prime31 / Blobs.cs
Created March 17, 2021 23:07
Unmanaged Resources
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Nez.Unmanaged
{
unsafe public struct BlobAllocator : IDisposable
{
byte* m_RootPtr;
@prime31
prime31 / Program.cs
Last active November 16, 2023 10:32
C# Basic ECS implementation example. Not production ready, optimized or even fully functional. It is here to illustrate the patterns for creating an ECS from scratch.
using System;
namespace SimpleECS
{
struct Position
{
public float X, Y;
}
struct Velocity
@prime31
prime31 / FilePicker.cs
Last active November 20, 2023 02:03
Simple file and folder picker for ImGui.Net
using ImGuiNET;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using Num = System.Numerics;
namespace Nez.ImGuiTools
{
public class FilePicker
const int C2_GJK_ITERS = 20;
public const int C2_MAX_POLYGON_VERTS = 8;
// position of impact p = ray.p + ray.d * raycast.t
public static c2v c2Impact(c2Ray ray, float t) => c2Add(ray.p, c2Mulvs(ray.d, t));
#region Wrapper Methods
public static unsafe bool c2Collided(void* A, c2x* ax, C2_TYPE typeA, void* B, c2x* bx, C2_TYPE typeB)
@prime31
prime31 / Game2.cs
Last active December 16, 2016 04:50
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Nez;
namespace TheWall
{
public class Game2 : Game
{
using Microsoft.Xna.Framework;
using Nez;
using Nez.Sprites;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vapor.Code.Utility;
@prime31
prime31 / 2DDeferredLighting.fx
Last active April 15, 2016 05:33
2D deferred lighting implementation (first pass, not optimized)
// ##### ##### ##### ##### ##### ##### #####
// ##### ##### Common Uniforms ##### #####
// ##### ##### ##### ##### ##### ##### #####
float4x4 _objectToWorld;
float4x4 _worldToView;
float4x4 _projection; // viewToCamera?
float4x4 _screenToWorld; // this is used to compute the world-position
// color of the light
@prime31
prime31 / gist:ab89f2d0b759dc11a315
Created December 10, 2015 18:38 — forked from anonymous/gist:8bb64b0556fecd13769f
Swept AABB Collisions C#
public static bool TestAABBSweep(Vector2 extents1, Vector2 centre1, Vector2 velocity1, Vector2 extents2, Vector2 centre2, Vector2 velocity2, out float t0, out float t1)
{
var aabb1 = new AABB(centre1, extents1);
var aabb2 = new AABB(centre2, extents2);
//Check if the boxes are currently overlapping
if (aabb1.Overlaps(aabb2))
{
t0 = t1 = 0;
return true;