virtualx-engine/modules/mono/glue/cs_files/GD.cs

197 lines
4.9 KiB
C#
Raw Normal View History

2017-10-02 23:24:00 +02:00
using System;
#if REAL_T_IS_DOUBLE
using real_t = System.Double;
#else
using real_t = System.Single;
#endif
2017-10-02 23:24:00 +02:00
// TODO: Add comments describing what this class does. It is not obvious.
2017-10-02 23:24:00 +02:00
namespace Godot
{
public static partial class GD
2017-10-02 23:24:00 +02:00
{
2017-11-21 23:32:19 +01:00
public static object Bytes2Var(byte[] bytes)
2017-10-02 23:24:00 +02:00
{
return NativeCalls.godot_icall_Godot_bytes2var(bytes);
}
2017-11-21 23:32:19 +01:00
public static object Convert(object what, int type)
2017-10-02 23:24:00 +02:00
{
return NativeCalls.godot_icall_Godot_convert(what, type);
}
public static real_t Db2Linear(real_t db)
2017-10-02 23:24:00 +02:00
{
return (real_t)Math.Exp(db * 0.11512925464970228420089957273422);
2017-10-02 23:24:00 +02:00
}
public static real_t DecTime(real_t value, real_t amount, real_t step)
2017-10-02 23:24:00 +02:00
{
real_t sgn = Mathf.Sign(value);
real_t val = Mathf.Abs(value);
2017-10-02 23:24:00 +02:00
val -= amount * step;
if (val < 0)
val = 0;
2017-10-02 23:24:00 +02:00
return val * sgn;
}
public static FuncRef FuncRef(Object instance, string funcname)
2017-10-02 23:24:00 +02:00
{
var ret = new FuncRef();
ret.SetInstance(instance);
ret.SetFunction(funcname);
return ret;
}
2017-11-21 23:32:19 +01:00
public static int Hash(object var)
2017-10-02 23:24:00 +02:00
{
return NativeCalls.godot_icall_Godot_hash(var);
}
2017-11-21 23:32:19 +01:00
public static Object InstanceFromId(int instanceId)
2017-10-02 23:24:00 +02:00
{
2017-11-21 23:32:19 +01:00
return NativeCalls.godot_icall_Godot_instance_from_id(instanceId);
2017-10-02 23:24:00 +02:00
}
public static real_t Linear2Db(real_t linear)
2017-10-02 23:24:00 +02:00
{
return (real_t)(Math.Log(linear) * 8.6858896380650365530225783783321);
2017-10-02 23:24:00 +02:00
}
2017-11-21 23:32:19 +01:00
public static Resource Load(string path)
2017-10-02 23:24:00 +02:00
{
return ResourceLoader.Load(path);
}
2017-11-21 23:32:19 +01:00
public static void Print(params object[] what)
2017-10-02 23:24:00 +02:00
{
NativeCalls.godot_icall_Godot_print(what);
}
2017-11-21 23:32:19 +01:00
public static void PrintStack()
2017-10-02 23:24:00 +02:00
{
2017-11-21 23:32:19 +01:00
Print(System.Environment.StackTrace);
2017-10-02 23:24:00 +02:00
}
public static void PrintErr(params object[] what)
2017-10-02 23:24:00 +02:00
{
NativeCalls.godot_icall_Godot_printerr(what);
}
public static void PrintRaw(params object[] what)
2017-10-02 23:24:00 +02:00
{
NativeCalls.godot_icall_Godot_printraw(what);
}
public static void PrintS(params object[] what)
2017-10-02 23:24:00 +02:00
{
NativeCalls.godot_icall_Godot_prints(what);
}
public static void PrintT(params object[] what)
2017-10-02 23:24:00 +02:00
{
NativeCalls.godot_icall_Godot_printt(what);
}
2017-11-21 23:32:19 +01:00
public static int[] Range(int length)
2017-10-02 23:24:00 +02:00
{
2018-04-08 05:30:43 +02:00
var ret = new int[length];
2017-10-02 23:24:00 +02:00
for (int i = 0; i < length; i++)
2017-10-02 23:24:00 +02:00
{
ret[i] = i;
}
return ret;
}
2017-11-21 23:32:19 +01:00
public static int[] Range(int from, int to)
2017-10-02 23:24:00 +02:00
{
if (to < from)
return new int[0];
2018-04-08 05:30:43 +02:00
var ret = new int[to - from];
2017-10-02 23:24:00 +02:00
for (int i = from; i < to; i++)
2017-10-02 23:24:00 +02:00
{
ret[i - from] = i;
}
return ret;
}
2017-11-21 23:32:19 +01:00
public static int[] Range(int from, int to, int increment)
2017-10-02 23:24:00 +02:00
{
if (to < from && increment > 0)
return new int[0];
if (to > from && increment < 0)
return new int[0];
// Calculate count
int count;
2017-10-02 23:24:00 +02:00
if (increment > 0)
count = (to - from - 1) / increment + 1;
2017-10-02 23:24:00 +02:00
else
count = (from - to - 1) / -increment + 1;
2017-10-02 23:24:00 +02:00
2018-04-08 05:30:43 +02:00
var ret = new int[count];
2017-10-02 23:24:00 +02:00
if (increment > 0)
{
int idx = 0;
for (int i = from; i < to; i += increment)
2017-10-02 23:24:00 +02:00
{
ret[idx++] = i;
}
}
else
{
int idx = 0;
for (int i = from; i > to; i += increment)
2017-10-02 23:24:00 +02:00
{
ret[idx++] = i;
}
}
return ret;
}
2017-11-21 23:32:19 +01:00
public static void Seed(int seed)
2017-10-02 23:24:00 +02:00
{
NativeCalls.godot_icall_Godot_seed(seed);
}
2017-11-21 23:32:19 +01:00
public static string Str(params object[] what)
2017-10-02 23:24:00 +02:00
{
return NativeCalls.godot_icall_Godot_str(what);
}
2017-11-21 23:32:19 +01:00
public static object Str2Var(string str)
2017-10-02 23:24:00 +02:00
{
return NativeCalls.godot_icall_Godot_str2var(str);
}
2017-11-21 23:32:19 +01:00
public static bool TypeExists(string type)
2017-10-02 23:24:00 +02:00
{
return NativeCalls.godot_icall_Godot_type_exists(type);
}
2017-11-21 23:32:19 +01:00
public static byte[] Var2Bytes(object var)
2017-10-02 23:24:00 +02:00
{
return NativeCalls.godot_icall_Godot_var2bytes(var);
}
2017-11-21 23:32:19 +01:00
public static string Var2Str(object var)
2017-10-02 23:24:00 +02:00
{
return NativeCalls.godot_icall_Godot_var2str(var);
}
public static WeakRef WeakRef(Object obj)
2017-10-02 23:24:00 +02:00
{
return NativeCalls.godot_icall_Godot_weakref(Object.GetPtr(obj));
}
}
}