What is your guys' opinion on this scenario: should I write the code for my own MD2 animation loader/skeletal animation renderer, or use ASSIMP? I'm not too big on using other libraries to do my work, but it is a pretty hefty subject..
[QUOTE=The Inzuki;47499190]What is your guys' opinion on this scenario: should I write the code for my own MD2 animation loader/skeletal animation renderer, or use ASSIMP? I'm not too big on using other libraries to do my work, but it is a pretty hefty subject..[/QUOTE]
Depends. Do you want to learn how to write model loading code? Or do you want to move on to other parts of your project?
[QUOTE=The Inzuki;47499190]What is your guys' opinion on this scenario: should I write the code for my own MD2 animation loader/skeletal animation renderer, or use ASSIMP? I'm not too big on using other libraries to do my work, but it is a pretty hefty subject..[/QUOTE]
Use AssImp as a separate stage, a seperate program that loads in any kind of model, and outputs it in your own format, and then have your engine only load your format. It's a nice separation, and will make your model loading code a lot cleaner.
[QUOTE=BackwardSpy;47499314]Depends. Do you want to learn how to write model loading code? Or do you want to move on to other parts of your project?[/QUOTE]
I already wrote an .obj file loader so that's not a problem, I just don't know if I want to deal with bone animations and the such.
[QUOTE=Dr Magnusson;47499625]Use AssImp as a separate stage, a seperate program that loads in any kind of model, and outputs it in your own format, and then have your engine only load your format. It's a nice separation, and will make your model loading code a lot cleaner.[/QUOTE]
That's a pretty good idea, thank you!
I've made a stupid mistake once again
I've been redesigning the interface for my level editor for the past week, but I ran into a bug where an element of my UI was stretching really far across my screen. That element contained an icon normally, but this texture got replaced with a 1920x1080 screenshot, causing my editor to try to re-size horizontally [I]around that texture[/I].
This whole time I thought I was dealing with a bug, but I guess it just goes to show that my layouts are actually doing what they were designed to do.
the worst bug to fix is the one that doesn't exist
I have just paid a visit to the depths of reflection hell and emerged, triumphant, with this [I]delightfully skin-melting masterpiece[/I]:
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Rant.Engine.Delegates
{
internal abstract class Witchcraft
{
private static readonly Type[] _funcTypes;
private static readonly Type[] _voidTypes;
static Witchcraft()
{
var ass = Assembly.GetAssembly(typeof(Witchcraft));
var lstFuncTypes = new List<Type>();
var lstVoidTypes = new List<Type>();
foreach (var type in ass.GetTypes().Where(t => t.IsSubclassOf(typeof(Witchcraft)) && t.IsGenericTypeDefinition))
{
if (type.IsSubclassOf(typeof(WitchcraftVoid)))
{
lstVoidTypes.Add(type);
}
else
{
lstFuncTypes.Add(type);
}
}
_funcTypes = lstFuncTypes.OrderBy(t => t.GetGenericArguments().Length).ToArray();
_voidTypes = lstVoidTypes.OrderBy(t => t.GetGenericArguments().Length).ToArray();
}
public static Witchcraft Create(MethodInfo methodInfo)
{
bool isVoid = methodInfo.ReturnType == typeof(void);
var types = methodInfo.GetParameters().Select(p => p.ParameterType).ToArray();
if (types.Length == 0 || types[0] != typeof(Sandbox))
throw new ArgumentException("Method must have a Sandbox parameter come first.", nameof(methodInfo));
var argTypes = types.Skip(1).ToArray();
if (argTypes.Length >= _funcTypes.Length) return null;
if (argTypes.Length == 0)
{
if (isVoid)
{
return new WitchcraftNoParamsVoid(methodInfo);
}
else
{
return new WitchcraftNoParams(methodInfo);
}
}
Type type = isVoid
? _voidTypes[argTypes.Length - 1].MakeGenericType(argTypes)
: _funcTypes[argTypes.Length - 1].MakeGenericType(argTypes);
return (Witchcraft)Activator.CreateInstance(type, methodInfo);
}
public abstract object Invoke(Sandbox sb, object[] args);
}
internal abstract class WitchcraftVoid : Witchcraft
{
}
internal class WitchcraftNoParams : Witchcraft
{
private readonly Func<Sandbox, object> _func;
public WitchcraftNoParams(MethodInfo methodInfo)
{
_func = (Func<Sandbox, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) => _func(sb);
}
internal class WitchcraftNoParamsVoid : WitchcraftVoid
{
private readonly Action<Sandbox> _func;
public WitchcraftNoParamsVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox>)Delegate.CreateDelegate(typeof(Action<Sandbox>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb);
return null;
}
}
internal class Witchcraft<A> : Witchcraft
{
private readonly Func<Sandbox, A, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) => _func(sb, (A)args[0]);
}
internal class WitchcraftVoid<A> : WitchcraftVoid
{
private readonly Action<Sandbox, A> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A>)Delegate.CreateDelegate(typeof(Action<Sandbox, A>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0]);
return null;
}
}
internal class Witchcraft<A, B> : Witchcraft
{
private readonly Func<Sandbox, A, B, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1]);
}
internal class WitchcraftVoid<A, B> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1]);
return null;
}
}
internal class Witchcraft<A, B, C> : Witchcraft
{
private readonly Func<Sandbox, A, B, C, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, C, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, C, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1], (C)args[2]);
}
internal class WitchcraftVoid<A, B, C> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B, C> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B, C>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B, C>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1], (C)args[2]);
return null;
}
}
internal class Witchcraft<A, B, C, D> : Witchcraft
{
private readonly Func<Sandbox, A, B, C, D, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, C, D, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, C, D, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3]);
}
internal class WitchcraftVoid<A, B, C, D> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B, C, D> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B, C, D>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B, C, D>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3]);
return null;
}
}
internal class Witchcraft<A, B, C, D, E> : Witchcraft
{
private readonly Func<Sandbox, A, B, C, D, E, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, C, D, E, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, C, D, E, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3], (E)args[4]);
}
internal class WitchcraftVoid<A, B, C, D, E> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B, C, D, E> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B, C, D, E>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B, C, D, E>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3], (E)args[4]);
return null;
}
}
}[/code]
What you are witnessing before you is a set of classes designed to generate delegates from reflected Rant methods, allowing them to be invoked with an object array that provides the necessary arguments. The horrific torrent of generic classes spurting forth from this page of code is instantiated purely through reflection, extracting the parameter types from the MethodInfo instances themselves and applying them to the type arguments on the classes. No generics are used by hand. This model is much faster than MethodInfo.Invoke, and prevents spontaneous human combustion by casting the boxed invocation arguments to their proper types before invoking the delegate. Unfortunately, it also means that I have to write two new classes for every parameter count possibility. But I went crazy long ago, so I don't mind.
Thanks to Tamschi for sharing his vast expertise on [del]the ritual[/del] reflection.
[QUOTE=Berkin;47502133]I have just paid a visit to the depths of reflection hell and emerged, triumphant, with this [I]delightfully skin-melting masterpiece[/I]:
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Rant.Engine.Delegates
{
internal abstract class Witchcraft
{
private static readonly Type[] _funcTypes;
private static readonly Type[] _voidTypes;
static Witchcraft()
{
var ass = Assembly.GetAssembly(typeof(Witchcraft));
var lstFuncTypes = new List<Type>();
var lstVoidTypes = new List<Type>();
foreach (var type in ass.GetTypes().Where(t => t.IsSubclassOf(typeof(Witchcraft)) && t.IsGenericTypeDefinition))
{
if (type.IsSubclassOf(typeof(WitchcraftVoid)))
{
lstVoidTypes.Add(type);
}
else
{
lstFuncTypes.Add(type);
}
}
_funcTypes = lstFuncTypes.OrderBy(t => t.GetGenericArguments().Length).ToArray();
_voidTypes = lstVoidTypes.OrderBy(t => t.GetGenericArguments().Length).ToArray();
}
public static Witchcraft Create(MethodInfo methodInfo)
{
bool isVoid = methodInfo.ReturnType == typeof(void);
var types = methodInfo.GetParameters().Select(p => p.ParameterType).ToArray();
if (types.Length == 0 || types[0] != typeof(Sandbox))
throw new ArgumentException("Method must have a Sandbox parameter come first.", nameof(methodInfo));
var argTypes = types.Skip(1).ToArray();
if (argTypes.Length >= _funcTypes.Length) return null;
if (argTypes.Length == 0)
{
if (isVoid)
{
return new WitchcraftNoParamsVoid(methodInfo);
}
else
{
return new WitchcraftNoParams(methodInfo);
}
}
Type type = isVoid
? _voidTypes[argTypes.Length - 1].MakeGenericType(argTypes)
: _funcTypes[argTypes.Length - 1].MakeGenericType(argTypes);
return (Witchcraft)Activator.CreateInstance(type, methodInfo);
}
public abstract object Invoke(Sandbox sb, object[] args);
}
internal abstract class WitchcraftVoid : Witchcraft
{
}
internal class WitchcraftNoParams : Witchcraft
{
private readonly Func<Sandbox, object> _func;
public WitchcraftNoParams(MethodInfo methodInfo)
{
_func = (Func<Sandbox, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) => _func(sb);
}
internal class WitchcraftNoParamsVoid : WitchcraftVoid
{
private readonly Action<Sandbox> _func;
public WitchcraftNoParamsVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox>)Delegate.CreateDelegate(typeof(Action<Sandbox>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb);
return null;
}
}
internal class Witchcraft<A> : Witchcraft
{
private readonly Func<Sandbox, A, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) => _func(sb, (A)args[0]);
}
internal class WitchcraftVoid<A> : WitchcraftVoid
{
private readonly Action<Sandbox, A> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A>)Delegate.CreateDelegate(typeof(Action<Sandbox, A>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0]);
return null;
}
}
internal class Witchcraft<A, B> : Witchcraft
{
private readonly Func<Sandbox, A, B, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1]);
}
internal class WitchcraftVoid<A, B> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1]);
return null;
}
}
internal class Witchcraft<A, B, C> : Witchcraft
{
private readonly Func<Sandbox, A, B, C, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, C, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, C, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1], (C)args[2]);
}
internal class WitchcraftVoid<A, B, C> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B, C> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B, C>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B, C>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1], (C)args[2]);
return null;
}
}
internal class Witchcraft<A, B, C, D> : Witchcraft
{
private readonly Func<Sandbox, A, B, C, D, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, C, D, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, C, D, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3]);
}
internal class WitchcraftVoid<A, B, C, D> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B, C, D> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B, C, D>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B, C, D>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3]);
return null;
}
}
internal class Witchcraft<A, B, C, D, E> : Witchcraft
{
private readonly Func<Sandbox, A, B, C, D, E, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, C, D, E, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, C, D, E, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3], (E)args[4]);
}
internal class WitchcraftVoid<A, B, C, D, E> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B, C, D, E> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B, C, D, E>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B, C, D, E>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3], (E)args[4]);
return null;
}
}
}[/code]
What you are witnessing before you is a set of classes designed to generate delegates from reflected Rant methods, allowing them to be invoked with an object array that provides the necessary arguments. The horrific torrent of generic classes spurting forth from this page of code is instantiated purely through reflection, extracting the parameter types from the MethodInfo instances themselves and applying them to the type arguments on the classes. No generics are used by hand. This model is much faster than MethodInfo.Invoke, and prevents spontaneous human combustion by casting the boxed invocation arguments to their proper types before invoking the delegate. Unfortunately, it also means that I have to write two new classes for every parameter count possibility. But I went crazy long ago, so I don't mind.
Thanks to Tamschi for sharing his vast expertise on [del]the ritual[/del] reflection.[/QUOTE]
Oh wow, this must be what you guys feel like when I post convoluted templates. I am so, so, sorry :(
[QUOTE=Dr Magnusson;47502226]Oh wow, this must be what you guys feel like when I post convoluted templates. I am so, so, sorry :([/QUOTE]
Nobody can truly appreciate the delicate art of templating until they have transcended the mortal realm and turned into a cucumber.
[QUOTE=Berkin;47502319]Nobody can truly appreciate the delicate art of templating until they have transcended the mortal realm and turned into a cucumber.[/QUOTE]
Amen brother
[img]http://i.imgur.com/NcUnZPF.png[/img]
[QUOTE=Berkin;47502133][/QUOTE]
[code]internal abstract class Witchcraft[/code]
Remind me to use this next time I write anything
[QUOTE=Berkin;47502133]I have just paid a visit to the depths of reflection hell and emerged, triumphant, with this [I]delightfully skin-melting masterpiece[/I]:
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Rant.Engine.Delegates
{
internal abstract class Witchcraft
{
private static readonly Type[] _funcTypes;
private static readonly Type[] _voidTypes;
static Witchcraft()
{
var ass = Assembly.GetAssembly(typeof(Witchcraft));
var lstFuncTypes = new List<Type>();
var lstVoidTypes = new List<Type>();
foreach (var type in ass.GetTypes().Where(t => t.IsSubclassOf(typeof(Witchcraft)) && t.IsGenericTypeDefinition))
{
if (type.IsSubclassOf(typeof(WitchcraftVoid)))
{
lstVoidTypes.Add(type);
}
else
{
lstFuncTypes.Add(type);
}
}
_funcTypes = lstFuncTypes.OrderBy(t => t.GetGenericArguments().Length).ToArray();
_voidTypes = lstVoidTypes.OrderBy(t => t.GetGenericArguments().Length).ToArray();
}
public static Witchcraft Create(MethodInfo methodInfo)
{
bool isVoid = methodInfo.ReturnType == typeof(void);
var types = methodInfo.GetParameters().Select(p => p.ParameterType).ToArray();
if (types.Length == 0 || types[0] != typeof(Sandbox))
throw new ArgumentException("Method must have a Sandbox parameter come first.", nameof(methodInfo));
var argTypes = types.Skip(1).ToArray();
if (argTypes.Length >= _funcTypes.Length) return null;
if (argTypes.Length == 0)
{
if (isVoid)
{
return new WitchcraftNoParamsVoid(methodInfo);
}
else
{
return new WitchcraftNoParams(methodInfo);
}
}
Type type = isVoid
? _voidTypes[argTypes.Length - 1].MakeGenericType(argTypes)
: _funcTypes[argTypes.Length - 1].MakeGenericType(argTypes);
return (Witchcraft)Activator.CreateInstance(type, methodInfo);
}
public abstract object Invoke(Sandbox sb, object[] args);
}
internal abstract class WitchcraftVoid : Witchcraft
{
}
internal class WitchcraftNoParams : Witchcraft
{
private readonly Func<Sandbox, object> _func;
public WitchcraftNoParams(MethodInfo methodInfo)
{
_func = (Func<Sandbox, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) => _func(sb);
}
internal class WitchcraftNoParamsVoid : WitchcraftVoid
{
private readonly Action<Sandbox> _func;
public WitchcraftNoParamsVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox>)Delegate.CreateDelegate(typeof(Action<Sandbox>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb);
return null;
}
}
internal class Witchcraft<A> : Witchcraft
{
private readonly Func<Sandbox, A, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) => _func(sb, (A)args[0]);
}
internal class WitchcraftVoid<A> : WitchcraftVoid
{
private readonly Action<Sandbox, A> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A>)Delegate.CreateDelegate(typeof(Action<Sandbox, A>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0]);
return null;
}
}
internal class Witchcraft<A, B> : Witchcraft
{
private readonly Func<Sandbox, A, B, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1]);
}
internal class WitchcraftVoid<A, B> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1]);
return null;
}
}
internal class Witchcraft<A, B, C> : Witchcraft
{
private readonly Func<Sandbox, A, B, C, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, C, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, C, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1], (C)args[2]);
}
internal class WitchcraftVoid<A, B, C> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B, C> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B, C>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B, C>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1], (C)args[2]);
return null;
}
}
internal class Witchcraft<A, B, C, D> : Witchcraft
{
private readonly Func<Sandbox, A, B, C, D, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, C, D, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, C, D, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3]);
}
internal class WitchcraftVoid<A, B, C, D> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B, C, D> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B, C, D>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B, C, D>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3]);
return null;
}
}
internal class Witchcraft<A, B, C, D, E> : Witchcraft
{
private readonly Func<Sandbox, A, B, C, D, E, object> _func;
public Witchcraft(MethodInfo methodInfo)
{
_func = (Func<Sandbox, A, B, C, D, E, object>)Delegate.CreateDelegate(typeof(Func<Sandbox, A, B, C, D, E, object>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args) =>
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3], (E)args[4]);
}
internal class WitchcraftVoid<A, B, C, D, E> : WitchcraftVoid
{
private readonly Action<Sandbox, A, B, C, D, E> _func;
public WitchcraftVoid(MethodInfo methodInfo)
{
_func = (Action<Sandbox, A, B, C, D, E>)Delegate.CreateDelegate(typeof(Action<Sandbox, A, B, C, D, E>), methodInfo);
}
public override object Invoke(Sandbox sb, object[] args)
{
_func(sb, (A)args[0], (B)args[1], (C)args[2], (D)args[3], (E)args[4]);
return null;
}
}
}[/code]
What you are witnessing before you is a set of classes designed to generate delegates from reflected Rant methods, allowing them to be invoked with an object array that provides the necessary arguments. The horrific torrent of generic classes spurting forth from this page of code is instantiated purely through reflection, extracting the parameter types from the MethodInfo instances themselves and applying them to the type arguments on the classes. No generics are used by hand. This model is much faster than MethodInfo.Invoke, and prevents spontaneous human combustion by casting the boxed invocation arguments to their proper types before invoking the delegate. Unfortunately, it also means that I have to write two new classes for every parameter count possibility. But I went crazy long ago, so I don't mind.
Thanks to Tamschi for sharing his vast expertise on [del]the ritual[/del] reflection.[/QUOTE]
Didn't read the code, just the summary. Is there something wrong with Expression.GetDelegateType [url]https://msdn.microsoft.com/en-us/library/system.linq.expressions.expression.getdelegatetype%28v=vs.110%29.aspx[/url] ?
[QUOTE=andrewmcwatters;47500230]the worst bug to fix is the one that doesn't exist[/QUOTE]
Wrong. It's worse when you fix bug that doesn't exists and with that fix you create actual bug.
[QUOTE=ben1066;47502777]Didn't read the code, just the summary. Is there something wrong with Expression.GetDelegateType [url]https://msdn.microsoft.com/en-us/library/system.linq.expressions.expression.getdelegatetype%28v=vs.110%29.aspx[/url] ?[/QUOTE]
The problem is that you can only invoke those dynamically through ([I]Multicast[/I])[I]Delegate.DynamicInvoke[/I], which is, as far as I've heard, really slow.
The wrappers are probably still nowhere close to a direct call due to downcasting each parameter past the first, but they are still likely to be [URL="http://stackoverflow.com/a/1118823/410020"]a lot[/URL] more efficient for all parameter counts.
[QUOTE=ben1066;47502777]Didn't read the code, just the summary. Is there something wrong with Expression.GetDelegateType [url]https://msdn.microsoft.com/en-us/library/system.linq.expressions.expression.getdelegatetype%28v=vs.110%29.aspx[/url] ?[/QUOTE]
As far as I'm aware, I would not be able to instantiate and invoke a delegate given just the type object. That's why I had to make explicit cases for different numbers of parameters, because then I could create a delegate for every specific case and invoke them directly.
If there's a better way to do this that doesn't involve MethodInfo.Invoke, I'd certainly love to know!
[QUOTE=geel9;47496447][code]
for(i = 0; i != 0; ;);
for(i = 100; i > 0; i--) print(i);
[/code]
:smug:[/QUOTE]
Weak.
[code]
for(int i=0;true;Console.Write("100 to 1"));
[/code]
[IMG]https://i.imgur.com/Qm84kJU.png[/IMG]
Yet another recusive fibonacci... but this time in my own LISP.
TODO:
1. Parser
2. Quoting
3. Bigger standard library
4. .NET interop
5. Tail calls
Why LISP? Is that just exercise (because it has really easy syntax)?
[QUOTE=Fourier;47503332]Why LISP? Is that just exercise (because it has really easy syntax)?[/QUOTE]
Mostly for fun & learning. I have made non-LISPish languages (both compiled and interpreted) before, but this is the first proper LISP I've made. Last time I tried to implement one I had no idea what I was doing, so something broke every time I tried to add a new feature.
[QUOTE=Fourier;47503332]Why LISP? Is that just exercise (because it has really easy syntax)?[/QUOTE]
It's a pretty big win if your syntax is that uniform. You can treat code as data without any special distinction which makes for great macros.
[QUOTE=Darwin226;47503450]It's a pretty big win if your syntax is that uniform. You can treat code as data without any special distinction which makes for great macros.[/QUOTE]
I heard that argument many times and wanted to learned LISP/Scheme because of it, but it sadly never clicked.
:(
Anyone else doing Google Code Jam? :)
Tried out making a trailer. WIP obviously.
[video=youtube;vJm4UV8J7Go]http://www.youtube.com/watch?v=vJm4UV8J7Go[/video]
Needs better music and title text
Those problems are quite hard.. but first one with audience looks easy
@Google code jam
I added a few helper methods and support for [I]where[/I] clauses: [code]var axa =
from _ in Template.Few<IScanner<int, char>, int, char>(any)
from a1 in any
from x in any
from a2 in any
where a1 == 'a'
where a2 == 'a'
select a1.ToString() + x + a2;
Console.WriteLine("axa on \"abaaacabca\":");
foreach (var match in axa.MatchOn("abaaacabca".GetScanner()))
{ Console.WriteLine(match); }[/code][code]axa on "abaaacabca":
aba
aaa
aca[/code]
wrote past the array bounds inside my driver haha not too kind windows kernel :<
[t]https://dl.dropboxusercontent.com/u/10798900/Pictures/20150409_194048.jpg[/t]
working on driver stuff
Well I know this isn't the most efficient use of Rakefiles, but here is a hacky way to get rails style generators for your web or build projects
[CODE]
desc 'delete a file'
task do :delete do
file = ARGV.last
FileUtils.rm("#{file}")
task file.to_sym do ; end
end
[/CODE]
Pretty simple.
[CODE]
rake delete filename
[/CODE]
[QUOTE=cra0kalo;47504229]wrote past the array bounds inside my driver haha not too kind windows kernel :<
[t]https://dl.dropboxusercontent.com/u/10798900/Pictures/20150409_194048.jpg[/t]
working on driver stuff[/QUOTE]
I recently finally passed a driver-writing course. It was mostly Linux, but holy shit writing kernelspace code is like the most frustrating thing ever save writing Assembly-code.
I stubbed out my modifiers to their own files now:
[IMG]http://i.imgur.com/Os6kWhK.png[/IMG]
You don't even need to build my dictionary for it, all modifiers have an overload for a string input of a sentence! Although capitalization and typos take only the string, so that way capitalization (which is programmed to happen in bursts) can span multiple words and same for typos.
Also did some more UI work, wired up the random chances to sliders:
[IMG]http://i.imgur.com/hqvAqG6.png[/IMG]
With everything set on 100% it's just unintelligible gibberish and i love it :v:
[IMG]http://i.imgur.com/68vveqg.png[/IMG]
Pretty sure that violates my max character count constraint. Oops!
Learning math..
I don't know what fucking retard decided to use u and v symbols together.
Sorry, you need to Log In to post a reply to this thread.