Skip to content

Instantly share code, notes, and snippets.

@clarvalon
clarvalon / ContentTypeReaderManager.cs
Created April 22, 2021 20:26
ContentTypeReaderManager.cs Tweak for FNA WASM
// WASM BUG: https://github.com/mono/mono/issues/20258
// We need to find the types manually as per: https://gist.github.com/TheSpydog/e94c8c23c01615a5a3b2cc1a0857415c
// Following types needed for loading SpriteFonts
if (l_readerType == null)
{
if (readerTypeString == "Microsoft.Xna.Framework.Content.SpriteFontReader, FNA")
{
l_readerType = typeof(SpriteFontReader);
}
@clarvalon
clarvalon / gist:95dfc426838cb60d95dea1abc558d824
Created January 21, 2020 09:54
FNA Net Core 3 using NativeLibrary v3
// in Program.cs
DllMap.Initialise(false);
// in DllMap.cs (contains some XAGE-specific optimisations that can be removed for general use)
using Clarvalon.XAGE.Global;
using System;
using System.Collections;
using System.Collections.Generic;
@clarvalon
clarvalon / ScreenShot.asc
Created October 5, 2019 19:28
ScreenShot.asc
// Use in script as follows to trigger screenshots being saved
SetScreenshotMode("EVERYFRAME");
// ----------------------------------
// ScreenShot.ash
import void SetScreenshotMode(String mode);
// ----------------------------------
// ScreenShot.asc
String previousValue;
@clarvalon
clarvalon / gist:1b11a43e0e002cd7c6bae5df14f4782b
Created September 24, 2019 23:06
FNA Net Core 3 using NativeLibrary (proof of concept v2)
// in Program.cs
// Get FNA Assembly
var fnaAssembly = Assembly.GetAssembly(typeof(Microsoft.Xna.Framework.Graphics.ColorWriteChannels));
// Register mechanism for determining native libraries based on NativeLibrary instead of DllImport
DllMap.Register(fnaAssembly);
// in DllMap.cs
using System;
@clarvalon
clarvalon / Gist.cs
Created September 24, 2019 22:11
FNA Net Core 3 using NativeLibrary (proof of concept - see TODOs)
// in Program.cs
// Get FNA Assembly
var fnaAssembly = Assembly.GetAssembly(typeof(Microsoft.Xna.Framework.Graphics.ColorWriteChannels));
// Register mechanism for determining native libraries based on NativeLibrary instead of DllImport
DllMap.Register(fnaAssembly);
// in DllMap.cs
using System;
@clarvalon
clarvalon / gist:6d36c2ed9af6d607a04b76a662571405
Last active November 6, 2018 23:53
Loading Ogg Vorbis via FAudio
// Not profiled and undoubtedly could be improved ...
public SoundEffect LoadOgg(Stream stream)
{
// Turn .ogg stream into byte buffer
byte[] rawData = new byte[stream.Length];
stream.Read(rawData, 0, (int)stream.Length);
// Access byte buffer as a pointer
GCHandle rawDataHandle = GCHandle.Alloc(rawData, GCHandleType.Pinned);
IntPtr address = rawDataHandle.AddrOfPinnedObject();
@clarvalon
clarvalon / IntegerBool.cs
Created February 24, 2018 10:31
IntegerBool
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Clarvalon.XAGE.Global
{
/// <summary>
/// Can operate as both an integer and a bool (as a workaround for lax AGS typing).
/// </summary>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Platforms>AnyCPU;x86;x64</Platforms>
</PropertyGroup>
<PropertyGroup>
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
@clarvalon
clarvalon / gist:3c787100d88086054a4dd5551b93d0bb
Created October 9, 2017 20:43 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream