rewrote binding generator in python

This commit is contained in:
Karroffel
2017-05-12 21:53:07 +02:00
parent 3969bcf078
commit cf30b0f39d
47 changed files with 650 additions and 812 deletions

108
include/core/Array.hpp Normal file
View File

@@ -0,0 +1,108 @@
#ifndef ARRAY_H
#define ARRAY_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_array.h>
#include "String.hpp"
namespace godot {
class Variant;
class PoolByteArray;
class PoolIntArray;
class PoolRealArray;
class PoolStringArray;
class PoolVector2Array;
class PoolVector3Array;
class PoolColorArray;
class Object;
class GD_CPP_CORE_API Array {
godot_array _godot_array;
public:
Array();
Array(const PoolByteArray& a);
Array(const PoolIntArray& a);
Array(const PoolRealArray& a);
Array(const PoolStringArray& a);
Array(const PoolVector2Array& a);
Array(const PoolVector3Array& a);
Array(const PoolColorArray& a);
Variant& operator [](const int idx);
Variant operator [](const int idx) const;
void append(const Variant& v);
void clear();
int count(const Variant& v);
bool empty() const;
void erase(const Variant& v);
Variant front() const;
Variant back() const;
int find(const Variant& what, const int from = 0);
int find_last(const Variant& what);
bool has(const Variant& what) const;
uint32_t hash() const;
void insert(const int pos, const Variant& value);
void invert();
bool is_shared() const;
Variant pop_back();
Variant pop_front();
void push_back(const Variant& v);
void push_front(const Variant& v);
void remove(const int idx);
int size() const;
void resize(const int size);
int rfind(const Variant& what, const int from = -1);
void sort();
void sort_custom(Object *obj, const String& func);
~Array();
};
}
#endif // ARRAY_H

146
include/core/Basis.hpp Normal file
View File

@@ -0,0 +1,146 @@
#ifndef BASIS_H
#define BASIS_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Defs.hpp"
#include "Vector3.hpp"
namespace godot {
class Quat;
class GD_CPP_CORE_API Basis {
public:
Vector3 elements[3];
Basis(const Quat& p_quat); // euler
Basis(const Vector3& p_euler); // euler
Basis(const Vector3& p_axis, real_t p_phi);
Basis(const Vector3& row0, const Vector3& row1, const Vector3& row2);
Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
Basis();
const Vector3& operator[](int axis) const;
Vector3& operator[](int axis);
void invert();
bool isequal_approx(const Basis& a, const Basis& b) const;
bool is_orthogonal() const;
bool is_rotation() const;
void transpose();
Basis inverse() const;
Basis transposed() const;
real_t determinant() const;
Vector3 get_axis(int p_axis) const;
void set_axis(int p_axis, const Vector3& p_value);
void rotate(const Vector3& p_axis, real_t p_phi);
Basis rotated(const Vector3& p_axis, real_t p_phi) const;
void scale( const Vector3& p_scale );
Basis scaled( const Vector3& p_scale ) const;
Vector3 get_scale() const;
Vector3 get_euler() const;
void set_euler(const Vector3& p_euler);
// transposed dot products
real_t tdotx(const Vector3& v) const;
real_t tdoty(const Vector3& v) const;
real_t tdotz(const Vector3& v) const;
bool operator==(const Basis& p_matrix) const;
bool operator!=(const Basis& p_matrix) const;
Vector3 xform(const Vector3& p_vector) const;
Vector3 xform_inv(const Vector3& p_vector) const;
void operator*=(const Basis& p_matrix);
Basis operator*(const Basis& p_matrix) const;
void operator+=(const Basis& p_matrix);
Basis operator+(const Basis& p_matrix) const;
void operator-=(const Basis& p_matrix);
Basis operator-(const Basis& p_matrix) const;
void operator*=(real_t p_val);
Basis operator*(real_t p_val) const;
int get_orthogonal_index() const; // down below
void set_orthogonal_index(int p_index); // down below
operator String() const;
void get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const;
/* create / set */
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
Vector3 get_column(int i) const;
Vector3 get_row(int i) const;
Vector3 get_main_diagonal() const;
void set_row(int i, const Vector3& p_row);
Basis transpose_xform(const Basis& m) const;
void orthonormalize();
Basis orthonormalized() const;
bool is_symmetric() const;
Basis diagonalize();
operator Quat() const;
};
}
#endif // BASIS_H

106
include/core/Color.hpp Normal file
View File

@@ -0,0 +1,106 @@
#ifndef COLOR_H
#define COLOR_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_color.h>
#include <cmath>
#include "String.hpp"
namespace godot {
struct GD_CPP_CORE_API Color {
private:
// static float _parse_col(const String& p_str, int p_ofs);
public:
union {
struct {
float r;
float g;
float b;
float a;
};
float components[4];
};
inline bool operator==(const Color &p_color) const { return (r==p_color.r && g==p_color.g && b==p_color.b && a==p_color.a ); }
inline bool operator!=(const Color &p_color) const { return (r!=p_color.r || g!=p_color.g || b!=p_color.b || a!=p_color.a ); }
uint32_t to_32() const;
uint32_t to_ARGB32() const;
float gray() const;
float get_h() const;
float get_s() const;
float get_v() const;
void set_hsv(float p_h, float p_s, float p_v, float p_alpha=1.0);
inline float& operator[](int idx) {
return components[idx];
}
inline const float& operator[](int idx) const {
return components[idx];
}
void invert();
void contrast();
Color inverted() const;
Color contrasted() const;
Color linear_interpolate(const Color& p_b, float p_t) const;
Color blend(const Color& p_over) const;
Color to_linear() const;
static Color hex(uint32_t p_hex);
static Color html(const String& p_color);
static bool html_is_valid(const String& p_color);
String to_html(bool p_alpha=true) const;
bool operator<(const Color& p_color) const; //used in set keys
operator String() const;
/**
* No construct parameters, r=0, g=0, b=0. a=255
*/
inline Color() {
r=0; g=0; b=0; a=1.0;
}
/**
* RGB / RGBA construct parameters. Alpha is optional, but defaults to 1.0
*/
inline Color(float p_r,float p_g,float p_b,float p_a=1.0) { r=p_r; g=p_g; b=p_b; a=p_a; }
};
}
#endif // COLOR_H

View File

@@ -0,0 +1,27 @@
#ifndef CORETYPES_H
#define CORETYPES_H
#include "Defs.hpp"
#include "Array.hpp"
#include "Basis.hpp"
#include "Color.hpp"
#include "Dictionary.hpp"
#include "Image.hpp"
#include "InputEvent.hpp"
#include "NodePath.hpp"
#include "Plane.hpp"
#include "PoolArrays.hpp"
#include "Quat.hpp"
#include "Rect2.hpp"
#include "Rect3.hpp"
#include "RID.hpp"
#include "String.hpp"
#include "Transform.hpp"
#include "Transform2D.hpp"
#include "Variant.hpp"
#include "Vector2.hpp"
#include "Vector3.hpp"
#endif // CORETYPES_H

103
include/core/Defs.hpp Normal file
View File

@@ -0,0 +1,103 @@
#ifndef DEFS_H
#define DEFS_H
namespace godot {
enum Error {
OK,
FAILED, ///< Generic fail error
ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
ERR_UNCONFIGURED, ///< The object being used hasnt been properly set up yet
ERR_UNAUTHORIZED, ///< Missing credentials for requested resource
ERR_PARAMETER_RANGE_ERROR, ///< Parameter given out of range (5)
ERR_OUT_OF_MEMORY, ///< Out of memory
ERR_FILE_NOT_FOUND,
ERR_FILE_BAD_DRIVE,
ERR_FILE_BAD_PATH,
ERR_FILE_NO_PERMISSION, // (10)
ERR_FILE_ALREADY_IN_USE,
ERR_FILE_CANT_OPEN,
ERR_FILE_CANT_WRITE,
ERR_FILE_CANT_READ,
ERR_FILE_UNRECOGNIZED, // (15)
ERR_FILE_CORRUPT,
ERR_FILE_MISSING_DEPENDENCIES,
ERR_FILE_EOF,
ERR_CANT_OPEN, ///< Can't open a resource/socket/file
ERR_CANT_CREATE, // (20)
ERR_QUERY_FAILED,
ERR_ALREADY_IN_USE,
ERR_LOCKED, ///< resource is locked
ERR_TIMEOUT,
ERR_CANT_CONNECT, // (25)
ERR_CANT_RESOLVE,
ERR_CONNECTION_ERROR,
ERR_CANT_AQUIRE_RESOURCE,
ERR_CANT_FORK,
ERR_INVALID_DATA, ///< Data passed is invalid (30)
ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
ERR_ALREADY_EXISTS, ///< When adding, item already exists
ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
ERR_DATABASE_CANT_READ, ///< database is full
ERR_DATABASE_CANT_WRITE, ///< database is full (35)
ERR_COMPILATION_FAILED,
ERR_METHOD_NOT_FOUND,
ERR_LINK_FAILED,
ERR_SCRIPT_FAILED,
ERR_CYCLIC_LINK, // (40)
ERR_INVALID_DECLARATION,
ERR_DUPLICATE_SYMBOL,
ERR_PARSE_ERROR,
ERR_BUSY,
ERR_SKIP, // (45)
ERR_HELP, ///< user requested help!!
ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
};
}
#include <stdio.h>
typedef float real_t;
#define CMP_EPSILON 0.00001
#define CMP_EPSILON2 (CMP_EPSILON*CMP_EPSILON)
#define Math_PI 3.14159265358979323846
#define _PLANE_EQ_DOT_EPSILON 0.999
#define _PLANE_EQ_D_EPSILON 0.0001
#ifndef ERR_FAIL_COND_V
#define ERR_FAIL_COND_V(cond, ret) do { if (cond) { return ret; } } while(0)
#endif
#ifndef ERR_FAIL_V
#define ERR_FAIL_V(a) return a
#endif
#ifndef ERR_FAIL_INDEX
#define ERR_FAIL_INDEX(a, b)
#endif
#ifndef ERR_PRINT
#define ERR_PRINT(msg) fprintf(stderr, "ERROR: %ls\n", (msg).c_string())
#endif
#ifndef ERR_FAIL_INDEX_V
#define ERR_FAIL_INDEX_V(a, b, c)
#endif
#ifndef ERR_FAIL_COND
#define ERR_FAIL_COND(a) do { if (a) { fprintf(stderr, #a); return; } } while(0)
#endif
#endif // DEFS_H

View File

@@ -0,0 +1,59 @@
#ifndef DICTIONARY_H
#define DICTIONARY_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Variant.hpp"
#include "Array.hpp"
#include <godot/godot_dictionary.h>
namespace godot {
class GD_CPP_CORE_API Dictionary {
godot_dictionary _godot_dictionary;
public:
Dictionary();
void clear();
bool empty() const;
void erase(const Variant& key);
bool has(const Variant& key) const;
bool has_all(const Array& keys) const;
uint32_t hash() const;
Array keys() const;
int parse_json(const String& json);
Variant &operator [](const Variant& key);
const Variant &operator [](const Variant& key) const;
int size() const;
String to_json() const;
Array values() const;
~Dictionary();
};
}
#endif // DICTIONARY_H

732
include/core/Godot.hpp Normal file
View File

@@ -0,0 +1,732 @@
#ifndef GODOT_H
#define GODOT_H
#include <cstdlib>
#include <godot.h>
#include <CoreTypes.hpp>
#include <Variant.hpp>
#include <Object.hpp>
namespace godot {
#if !defined(_WIN32)
#define GD_EXPORT
#else
#define GD_EXPORT __declspec(dllexport)
#endif
#define GODOT_NATIVE_INIT(arg) extern "C" void GD_EXPORT godot_native_init(arg)
#define GODOT_NATIVE_TERMINATE(arg) extern "C" void GD_EXPORT godot_native_terminate(arg)
#define GODOT_CLASS(Name, Base) \
public: inline static char *___get_type_name() { return (char *) #Name; } \
inline static char *___get_base_type_name() { return (char *) #Base; } \
Base *self; \
inline Name(godot_object *o) { self = (Base *) o; } \
private:
#define GODOT_SUBCLASS(Name, Base) \
public: inline static char *___get_type_name() { return (char *) #Name; } \
inline static char *___get_base_type_name() { return (char *) #Base; } \
inline Name(godot_object *o) : Base(o) {} \
private:
template<class T>
struct _ArgCast {
static T _arg_cast(Variant a)
{
return (T) a;
}
};
template<class T>
struct _ArgCast<T*> {
static T *_arg_cast(Variant a)
{
return (T *) ((Object *) a);
}
};
template<class T>
T *as(Object *obj)
{
return (T *) godot_native_get_userdata(obj);
}
// instance and destroy funcs
template<class T>
void *_godot_class_instance_func(godot_object *p, void *method_data)
{
T *d = new T(p);
d->_init();
return d;
}
template<class T>
void _godot_class_destroy_func(godot_object *p, void *method_data, void *data)
{
T *d = (T *) data;
delete d;
}
template<class T>
void register_class()
{
godot_instance_create_func create = {};
create.create_func = _godot_class_instance_func<T>;
godot_instance_destroy_func destroy = {};
destroy.destroy_func = _godot_class_destroy_func<T>;
godot_script_register_class(T::___get_type_name(), T::___get_base_type_name(), create, destroy);
T::_register_methods();
}
template<class T>
void register_tool_class()
{
godot_instance_create_func create = {};
create.create_func = _godot_class_instance_func<T>;
godot_instance_destroy_func destroy = {};
destroy.destroy_func = _godot_class_destroy_func<T>;
godot_script_register_tool_class(T::___get_type_name(), T::___get_base_type_name(), create, destroy);
T::_register_methods();
}
// method registering
typedef godot_variant (*__godot_wrapper_method)(godot_object *, void *, void *, int, godot_variant **);
template<class T, class R, class ...args>
char *___get_method_class_name(R (T::*p)(args... a))
{
return T::___get_type_name();
}
// wohooo, let the fun begin.
template<class T, class R>
struct _WrappedMethod0 {
R (T::*f)();
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod0<T, R> *method = (_WrappedMethod0<T, R>*) method_data;
Variant *var = (Variant *) &v;
*var = (obj->*(method->f))();
return v;
}
};
template<class T>
struct _WrappedMethod0<T, void> {
void (T::*f)();
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod0<T, void> *method = (_WrappedMethod0<T, void>*) method_data;
(obj->*(method->f))();
return v;
}
};
template<class T, class R>
void *___make_wrapper_function(R (T::*f)())
{
_WrappedMethod0<T, R> *p = (_WrappedMethod0<T, R> *) malloc(sizeof(_WrappedMethod0<T, R>));
p->f = f;
return (void *) p;
}
template<class T, class R>
__godot_wrapper_method ___get_wrapper_function(R (T::*f)())
{
return (__godot_wrapper_method) &_WrappedMethod0<T, R>::__wrapped_method;
}
template<class T, class R, class A0>
struct _WrappedMethod1 {
R (T::*f)(A0);
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod1<T, R, A0> *method = (_WrappedMethod1<T, R, A0>*) method_data;
Variant *var = (Variant *) &v;
Variant **arg = (Variant **) args;
*var = (obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]));
return v;
}
};
template<class T, class A0>
struct _WrappedMethod1<T, void, A0> {
void (T::*f)(A0);
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod1<T, void, A0> *method = (_WrappedMethod1<T, void, A0>*) method_data;
Variant **arg = (Variant **) args;
(obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]));
return v;
}
};
template<class T, class R, class A0>
void *___make_wrapper_function(R (T::*f)(A0))
{
_WrappedMethod1<T, R, A0> *p = (_WrappedMethod1<T, R, A0> *) malloc(sizeof(_WrappedMethod1<T, R, A0>));
p->f = f;
return (void *) p;
}
template<class T, class R, class A0>
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(A0))
{
return (__godot_wrapper_method) &_WrappedMethod1<T, R, A0>::__wrapped_method;
}
template<class T, class R, class A0, class A1>
struct _WrappedMethod2 {
R (T::*f)(A0, A1);
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod2<T, R, A0, A1> *method = (_WrappedMethod2<T, R, A0, A1>*) method_data;
Variant *var = (Variant *) &v;
Variant **arg = (Variant **) args;
*var = (obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]));
return v;
}
};
template<class T, class A0, class A1>
struct _WrappedMethod2<T, void, A0, A1> {
void (T::*f)(A0, A1);
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod2<T, void, A0, A1> *method = (_WrappedMethod2<T, void, A0, A1>*) method_data;
Variant **arg = (Variant **) args;
(obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]));
return v;
}
};
template<class T, class R, class A0, class A1>
void *___make_wrapper_function(R (T::*f)(A0, A1))
{
_WrappedMethod2<T, R, A0, A1> *p = (_WrappedMethod2<T, R, A0, A1> *) malloc(sizeof(_WrappedMethod2<T, R, A0, A1>));
p->f = f;
return (void *) p;
}
template<class T, class R, class A0, class A1>
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(A0, A1))
{
return (__godot_wrapper_method) &_WrappedMethod2<T, R, A0, A1>::__wrapped_method;
}
template<class T, class R, class A0, class A1, class A2>
struct _WrappedMethod3 {
R (T::*f)(A0, A1, A2);
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod3<T, R, A0, A1, A2> *method = (_WrappedMethod3<T, R, A0, A1, A2>*) method_data;
Variant *var = (Variant *) &v;
Variant **arg = (Variant **) args;
*var = (obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]));
return v;
}
};
template<class T, class A0, class A1, class A2>
struct _WrappedMethod3<T, void, A0, A1, A2> {
void (T::*f)(A0, A1, A2);
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod3<T, void, A0, A1, A2> *method = (_WrappedMethod3<T, void, A0, A1, A2>*) method_data;
Variant **arg = (Variant **) args;
(obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]));
return v;
}
};
template<class T, class R, class A0, class A1, class A2>
void *___make_wrapper_function(R (T::*f)(A0, A1, A2))
{
_WrappedMethod3<T, R, A0, A1, A2> *p = (_WrappedMethod3<T, R, A0, A1, A2> *) malloc(sizeof(_WrappedMethod3<T, R, A0, A1, A2>));
p->f = f;
return (void *) p;
}
template<class T, class R, class A0, class A1, class A2>
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(A0, A1, A2))
{
return (__godot_wrapper_method) &_WrappedMethod3<T, R, A0, A1, A2>::__wrapped_method;
}
template<class T, class R, class A0, class A1, class A2, class A3>
struct _WrappedMethod4 {
R (T::*f)(A0, A1, A2, A3);
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod4<T, R, A0, A1, A2, A3> *method = (_WrappedMethod4<T, R, A0, A1, A2, A3>*) method_data;
Variant *var = (Variant *) &v;
Variant **arg = (Variant **) args;
*var = (obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]), _ArgCast<A3>::_arg_cast(*arg[3]));
return v;
}
};
template<class T, class A0, class A1, class A2, class A3>
struct _WrappedMethod4<T, void, A0, A1, A2, A3> {
void (T::*f)(A0, A1, A2, A3);
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod4<T, void, A0, A1, A2, A3> *method = (_WrappedMethod4<T, void, A0, A1, A2, A3>*) method_data;
Variant **arg = (Variant **) args;
(obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]), _ArgCast<A3>::_arg_cast(*arg[3]));
return v;
}
};
template<class T, class R, class A0, class A1, class A2, class A3>
void *___make_wrapper_function(R (T::*f)(A0, A1, A2, A3))
{
_WrappedMethod4<T, R, A0, A1, A2, A3> *p = (_WrappedMethod4<T, R, A0, A1, A2, A3> *) malloc(sizeof(_WrappedMethod4<T, R, A0, A1, A2, A3>));
p->f = f;
return (void *) p;
}
template<class T, class R, class A0, class A1, class A2, class A3>
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(A0, A1, A2, A3))
{
return (__godot_wrapper_method) &_WrappedMethod4<T, R, A0, A1, A2, A3>::__wrapped_method;
}
template<class T, class R, class A0, class A1, class A2, class A3, class A4>
struct _WrappedMethod5 {
R (T::*f)(A0, A1, A2, A3, A4);
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod5<T, R, A0, A1, A2, A3, A4> *method = (_WrappedMethod5<T, R, A0, A1, A2, A3, A4>*) method_data;
Variant *var = (Variant *) &v;
Variant **arg = (Variant **) args;
*var = (obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]), _ArgCast<A3>::_arg_cast(*arg[3]), _ArgCast<A4>::_arg_cast(*arg[4]));
return v;
}
};
template<class T, class A0, class A1, class A2, class A3, class A4>
struct _WrappedMethod5<T, void, A0, A1, A2, A3, A4> {
void (T::*f)(A0, A1, A2, A3, A4);
static godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot_variant_new_nil(&v);
T *obj = (T *) user_data;
_WrappedMethod5<T, void, A0, A1, A2, A3, A4> *method = (_WrappedMethod5<T, void, A0, A1, A2, A3, A4>*) method_data;
Variant **arg = (Variant **) args;
(obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]), _ArgCast<A3>::_arg_cast(*arg[3]), _ArgCast<A4>::_arg_cast(*arg[4]));
return v;
}
};
template<class T, class R, class A0, class A1, class A2, class A3, class A4>
void *___make_wrapper_function(R (T::*f)(A0, A1, A2, A3, A4))
{
_WrappedMethod5<T, R, A0, A1, A2, A3, A4> *p = (_WrappedMethod5<T, R, A0, A1, A2, A3, A4> *) malloc(sizeof(_WrappedMethod5<T, R, A0, A1, A2, A3, A4>));
p->f = f;
return (void *) p;
}
template<class T, class R, class A0, class A1, class A2, class A3, class A4>
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(A0, A1, A2, A3, A4))
{
return (__godot_wrapper_method) &_WrappedMethod5<T, R, A0, A1, A2, A3, A4>::__wrapped_method;
}
template<class M>
void register_method(char *name, M method_ptr, godot_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED)
{
godot_instance_method method = {};
method.method_data = ___make_wrapper_function(method_ptr);
method.free_func = free;
method.method = (__godot_wrapper_method) ___get_wrapper_function(method_ptr);
godot_method_attributes attr = {};
attr.rpc_type = rpc_type;
godot_script_register_method(___get_method_class_name(method_ptr), name, attr, method);
}
template<class T, class P>
struct _PropertySetFunc {
void (T::*f)(P);
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant value)
{
_PropertySetFunc<T, P> *set_func = (_PropertySetFunc<T, P> *) method_data;
T *obj = (T *) user_data;
Variant *v = (Variant *) &value;
(obj->*(set_func->f))(_ArgCast<P>::_arg_cast(*v));
}
};
template<class T, class P>
struct _PropertyGetFunc {
P (T::*f)();
static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data)
{
_PropertyGetFunc<T, P> *get_func = (_PropertyGetFunc<T, P> *) method_data;
T *obj = (T *) user_data;
godot_variant var;
godot_variant_new_nil(&var);
Variant *v = (Variant *) &var;
*v = (obj->*(get_func->f))();
return var;
}
};
template<class T, class P>
struct _PropertyDefaultSetFunc {
P (T::*f);
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant value)
{
_PropertyDefaultSetFunc<T, P> *set_func = (_PropertyDefaultSetFunc<T, P> *) method_data;
T *obj = (T *) user_data;
Variant *v = (Variant *) &value;
(obj->*(set_func->f)) = _ArgCast<P>::_arg_cast(*v);
}
};
template<class T, class P>
struct _PropertyDefaultGetFunc {
P (T::*f);
static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data)
{
_PropertyDefaultGetFunc<T, P> *get_func = (_PropertyDefaultGetFunc<T, P> *) method_data;
T *obj = (T *) user_data;
godot_variant var;
godot_variant_new_nil(&var);
Variant *v = (Variant *) &var;
*v = (obj->*(get_func->f));
return var;
}
};
template<class T, class P>
void register_property(char *name, P (T::*var), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "")
{
Variant def_val = default_value;
usage = (godot_property_usage_flags) ((int) usage | GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE);
if (def_val.get_type() == Variant::OBJECT) {
Object *o = def_val;
if (o && o->is_class("Resource")) {
hint = (godot_property_hint) ((int) hint | GODOT_PROPERTY_HINT_RESOURCE_TYPE);
hint_string = o->get_class();
}
}
godot_string *_hint_string = (godot_string*) &hint_string;
godot_property_attributes attr = {};
attr.type = def_val.get_type();
attr.default_value = *(godot_variant *) &def_val;
attr.hint = hint;
attr.rset_type = rpc_mode;
attr.usage = usage;
attr.hint_string = *_hint_string;
_PropertyDefaultSetFunc<T, P> *wrapped_set = (_PropertyDefaultSetFunc<T, P> *) malloc(sizeof(_PropertyDefaultSetFunc<T, P>));
wrapped_set->f = var;
_PropertyDefaultGetFunc<T, P> *wrapped_get = (_PropertyDefaultGetFunc<T, P> *) malloc(sizeof(_PropertyDefaultGetFunc<T, P>));
wrapped_get->f = var;
godot_property_set_func set_func = {};
set_func.method_data = (void *) wrapped_set;
set_func.free_func = free;
set_func.set_func = &_PropertyDefaultSetFunc<T, P>::_wrapped_setter;
godot_property_get_func get_func = {};
get_func.method_data = (void *) wrapped_get;
get_func.free_func = free;
get_func.get_func = &_PropertyDefaultGetFunc<T, P>::_wrapped_getter;
godot_script_register_property(T::___get_type_name(), name, &attr, set_func, get_func);
}
template<class T, class P>
void register_property(char *name, void (T::*setter)(P), P (T::*getter)(), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "")
{
Variant def_val = default_value;
godot_property_attributes attr = {};
attr.type = def_val.get_type();
attr.default_value = *(godot_variant *) &def_val;
attr.hint = hint;
attr.rset_type = rpc_mode;
attr.usage = usage;
_PropertySetFunc<T, P> *wrapped_set = (_PropertySetFunc<T, P> *) malloc(sizeof(_PropertySetFunc<T, P>));
wrapped_set->f = setter;
_PropertyGetFunc<T, P> *wrapped_get = (_PropertyGetFunc<T, P> *) malloc(sizeof(_PropertyGetFunc<T, P>));
wrapped_get->f = getter;
godot_property_set_func set_func = {};
set_func.method_data = (void *) wrapped_set;
set_func.free_func = free;
set_func.set_func = &_PropertySetFunc<T, P>::_wrapped_setter;
godot_property_get_func get_func = {};
get_func.method_data = (void *) wrapped_get;
get_func.free_func = free;
get_func.get_func = &_PropertyGetFunc<T, P>::_wrapped_getter;
godot_script_register_property(T::___get_type_name(), name, &attr, set_func, get_func);
}
template<class T>
void register_signal(String name, Dictionary args = Dictionary())
{
godot_signal signal = {};
signal.name = *(godot_string *)&name;
signal.num_args = args.size();
signal.num_default_args = 0;
signal.args = (godot_signal_argument*) godot_alloc(sizeof(godot_signal_argument) * signal.num_args);
memset((void *) signal.args, 0, sizeof(godot_signal_argument) * signal.num_args);
for (int i = 0; i < signal.num_args; i++) {
// Array entry = args[i];
// String name = entry[0];
String name = args.keys()[i];
godot_string *_key = (godot_string *)&name;
godot_string_new(&signal.args[i].name);
godot_string_copy_string(&signal.args[i].name, _key);
// if (entry.size() > 1) {
// signal.args[i].type = entry[1];
// }
signal.args[i].type = args.values()[i];
}
godot_script_register_signal(T::___get_type_name(), &signal);
for (int i = 0; i < signal.num_args; i++) {
godot_string_destroy(&signal.args[i].name);
}
}
}
#endif // GODOT_H

139
include/core/Image.hpp Normal file
View File

@@ -0,0 +1,139 @@
#ifndef IMAGE_H
#define IMAGE_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Defs.hpp"
#include "Vector2.hpp"
#include "Rect2.hpp"
#include "Color.hpp"
#include "String.hpp"
#include <godot/godot_image.h>
namespace godot {
class PoolByteArray;
class GD_CPP_CORE_API Image {
godot_image _godot_image;
public:
enum Format {
FORMAT_L8, //luminance
FORMAT_LA8, //luminance-alpha
FORMAT_R8,
FORMAT_RG8,
FORMAT_RGB8,
FORMAT_RGBA8,
FORMAT_RGB565, //16 bit
FORMAT_RGBA4444,
FORMAT_RGBA5551,
FORMAT_RF, //float
FORMAT_RGF,
FORMAT_RGBF,
FORMAT_RGBAF,
FORMAT_RH, //half float
FORMAT_RGH,
FORMAT_RGBH,
FORMAT_RGBAH,
FORMAT_DXT1, //s3tc bc1
FORMAT_DXT3, //bc2
FORMAT_DXT5, //bc3
FORMAT_ATI1, //bc4
FORMAT_ATI2, //bc5
FORMAT_BPTC_RGBA, //btpc bc6h
FORMAT_BPTC_RGBF, //float /
FORMAT_BPTC_RGBFU, //unsigned float
FORMAT_PVRTC2, //pvrtc
FORMAT_PVRTC2A,
FORMAT_PVRTC4,
FORMAT_PVRTC4A,
FORMAT_ETC, //etc1
FORMAT_ETC2_R11, //etc2
FORMAT_ETC2_R11S, //signed, NOT srgb.
FORMAT_ETC2_RG11,
FORMAT_ETC2_RG11S,
FORMAT_ETC2_RGB8,
FORMAT_ETC2_RGBA8,
FORMAT_ETC2_RGB8A1,
FORMAT_MAX
};
enum Interpolation {
INTERPOLATE_NEAREST,
INTERPOLATE_BILINEAR,
INTERPOLATE_CUBIC,
/* INTERPOLATE GAUSS */
};
enum CompressMode {
COMPRESS_16BIT,
COMPRESS_S3TC,
COMPRESS_PVRTC2,
COMPRESS_PVRTC4,
COMPRESS_ETC,
COMPRESS_ETC2
};
Image();
Image(const int width, const int height, const bool mipmaps, const Format format);
void blit_rect(const Image& src, const Rect2& src_rect, const Vector2& dest = Vector2(0, 0));
void brush_transfer(const Image& src, const Image& brush, const Vector2& pos = Vector2(0, 0));
Image brushed(const Image& src, const Image& brush, const Vector2& pos = Vector2(0, 0));
Image compressed(const Format format);
Image converted(const Format format);
Image decompressed();
bool empty() const;
void fix_alpha_edges();
PoolByteArray get_data();
Format get_format() const;
int get_height() const;
Color get_pixel(const int x, const int y, const int mipmap_level = 0);
Image get_rect(const Rect2& area = Rect2());
Rect2 get_used_rect() const;
int get_width() const;
Error load(const String& path);
void put_pixel(const int x, const int y, const Color& color, int mipmap_level = 0);
Image resized(const int x, const int y, const Interpolation interpolation = INTERPOLATE_NEAREST);
Error save_png(const String& path);
~Image();
};
}
#endif // IMAGE_H

281
include/core/InputEvent.hpp Normal file
View File

@@ -0,0 +1,281 @@
#ifndef INPUTEVENT_H
#define INPUTEVENT_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <cstdint>
#include <memory.h>
#include "String.hpp"
namespace godot {
enum {
BUTTON_LEFT=1,
BUTTON_RIGHT=2,
BUTTON_MIDDLE=3,
BUTTON_WHEEL_UP=4,
BUTTON_WHEEL_DOWN=5,
BUTTON_WHEEL_LEFT=6,
BUTTON_WHEEL_RIGHT=7,
BUTTON_MASK_LEFT=(1<<(BUTTON_LEFT-1)),
BUTTON_MASK_RIGHT=(1<<(BUTTON_RIGHT-1)),
BUTTON_MASK_MIDDLE=(1<<(BUTTON_MIDDLE-1)),
};
enum {
JOY_BUTTON_0 = 0,
JOY_BUTTON_1 = 1,
JOY_BUTTON_2 = 2,
JOY_BUTTON_3 = 3,
JOY_BUTTON_4 = 4,
JOY_BUTTON_5 = 5,
JOY_BUTTON_6 = 6,
JOY_BUTTON_7 = 7,
JOY_BUTTON_8 = 8,
JOY_BUTTON_9 = 9,
JOY_BUTTON_10 = 10,
JOY_BUTTON_11 = 11,
JOY_BUTTON_12 = 12,
JOY_BUTTON_13 = 13,
JOY_BUTTON_14 = 14,
JOY_BUTTON_15 = 15,
JOY_BUTTON_MAX = 16,
JOY_L = JOY_BUTTON_4,
JOY_R = JOY_BUTTON_5,
JOY_L2 = JOY_BUTTON_6,
JOY_R2 = JOY_BUTTON_7,
JOY_L3 = JOY_BUTTON_8,
JOY_R3 = JOY_BUTTON_9,
JOY_SELECT = JOY_BUTTON_10,
JOY_START = JOY_BUTTON_11,
JOY_DPAD_UP = JOY_BUTTON_12,
JOY_DPAD_DOWN = JOY_BUTTON_13,
JOY_DPAD_LEFT = JOY_BUTTON_14,
JOY_DPAD_RIGHT = JOY_BUTTON_15,
// a little history about game controllers (who copied who)
JOY_SNES_B = JOY_BUTTON_0,
JOY_SNES_A = JOY_BUTTON_1,
JOY_SNES_Y = JOY_BUTTON_2,
JOY_SNES_X = JOY_BUTTON_3,
JOY_SONY_CIRCLE=JOY_SNES_A,
JOY_SONY_X=JOY_SNES_B,
JOY_SONY_SQUARE=JOY_SNES_Y,
JOY_SONY_TRIANGLE=JOY_SNES_X,
JOY_SEGA_B=JOY_SNES_A,
JOY_SEGA_A=JOY_SNES_B,
JOY_SEGA_X=JOY_SNES_Y,
JOY_SEGA_Y=JOY_SNES_X,
JOY_XBOX_B=JOY_SEGA_B,
JOY_XBOX_A=JOY_SEGA_A,
JOY_XBOX_X=JOY_SEGA_X,
JOY_XBOX_Y=JOY_SEGA_Y,
JOY_DS_A = JOY_SNES_A,
JOY_DS_B = JOY_SNES_B,
JOY_DS_X = JOY_SNES_X,
JOY_DS_Y = JOY_SNES_Y,
JOY_WII_C = JOY_BUTTON_5,
JOY_WII_Z = JOY_BUTTON_6,
JOY_WII_MINUS = JOY_BUTTON_9,
JOY_WII_PLUS = JOY_BUTTON_10,
// end of history
JOY_AXIS_0=0,
JOY_AXIS_1=1,
JOY_AXIS_2=2,
JOY_AXIS_3=3,
JOY_AXIS_4=4,
JOY_AXIS_5=5,
JOY_AXIS_6=6,
JOY_AXIS_7=7,
JOY_AXIS_MAX=8,
JOY_ANALOG_0_X = JOY_AXIS_0,
JOY_ANALOG_0_Y = JOY_AXIS_1,
JOY_ANALOG_1_X = JOY_AXIS_2,
JOY_ANALOG_1_Y = JOY_AXIS_3,
JOY_ANALOG_2_X = JOY_AXIS_4,
JOY_ANALOG_2_Y = JOY_AXIS_5,
JOY_ANALOG_L2 = JOY_AXIS_6,
JOY_ANALOG_R2 = JOY_AXIS_7,
};
/**
* Input Modifier Status
* for keyboard/mouse events.
*/
struct GD_CPP_CORE_API InputModifierState {
bool shift;
bool alt;
#ifdef APPLE_STYLE_KEYS
union {
bool command;
bool meta; //< windows/mac key
};
bool control;
#else
union {
bool command; //< windows/mac key
bool control;
};
bool meta; //< windows/mac key
#endif
inline bool operator==(const InputModifierState& rvalue) const {
return ( (shift==rvalue.shift) && (alt==rvalue.alt) && (control==rvalue.control) && (meta==rvalue.meta));
}
};
struct InputEventKey {
InputModifierState mod;
bool pressed; /// otherwise release
uint32_t scancode; ///< check keyboard.h , KeyCode enum, without modifier masks
uint32_t unicode; ///unicode
bool echo; /// true if this is an echo key
};
struct InputEventMouse {
InputModifierState mod;
int button_mask;
float x,y;
float global_x,global_y;
int pointer_index;
};
struct InputEventMouseButton : public InputEventMouse {
int button_index;
bool pressed; //otherwise released
bool doubleclick; //last even less than doubleclick time
};
struct InputEventMouseMotion : public InputEventMouse {
float relative_x,relative_y;
float speed_x,speed_y;
};
struct InputEventJoypadMotion {
int axis; ///< Joypad axis
float axis_value; ///< -1 to 1
};
struct InputEventJoypadButton {
int button_index;
bool pressed;
float pressure; //0 to 1
};
struct InputEventScreenTouch {
int index;
float x,y;
bool pressed;
};
struct InputEventScreenDrag {
int index;
float x,y;
float relative_x,relative_y;
float speed_x,speed_y;
};
struct InputEventAction {
int action;
bool pressed;
};
class Transform2D;
struct GD_CPP_CORE_API InputEvent {
enum Type {
NONE,
KEY,
MOUSE_MOTION,
MOUSE_BUTTON,
JOYPAD_MOTION,
JOYPAD_BUTTON,
SCREEN_TOUCH,
SCREEN_DRAG,
ACTION,
TYPE_MAX
};
uint32_t ID;
int type;
int device;
union {
InputEventMouseMotion mouse_motion;
InputEventMouseButton mouse_button;
InputEventJoypadMotion joy_motion;
InputEventJoypadButton joy_button;
InputEventKey key;
InputEventScreenTouch screen_touch;
InputEventScreenDrag screen_drag;
InputEventAction action;
};
bool is_pressed() const;
bool is_action(const String& p_action) const;
bool is_action_pressed(const String& p_action) const;
bool is_action_released(const String& p_action) const;
bool is_echo() const;
void set_as_action(const String& p_action, bool p_pressed);
InputEvent xform_by(const Transform2D& p_xform) const;
bool operator==(const InputEvent &p_event) const;
operator String() const;
inline InputEvent() { memset(this,0,sizeof(InputEvent)); }
};
}
#endif // INPUTEVENT_H

58
include/core/NodePath.hpp Normal file
View File

@@ -0,0 +1,58 @@
#ifndef NODEPATH_H
#define NODEPATH_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "String.hpp"
#include <godot/godot_node_path.h>
namespace godot {
class GD_CPP_CORE_API NodePath
{
godot_node_path _node_path;
public:
NodePath();
NodePath(const NodePath &other);
NodePath(const String& from);
NodePath(const char *contents);
String get_name(const int idx) const;
int get_name_count() const;
String get_property() const;
String get_subname(const int idx) const;
int get_subname_count() const;
bool is_absolute() const;
bool is_empty() const;
operator String() const;
void operator =(const NodePath& other);
~NodePath();
};
}
#endif // NODEPATH_H

79
include/core/Plane.hpp Normal file
View File

@@ -0,0 +1,79 @@
#ifndef PLANE_H
#define PLANE_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Vector3.hpp"
#include <cmath>
namespace godot {
enum ClockDirection {
CLOCKWISE,
COUNTERCLOCKWISE
};
class GD_CPP_CORE_API Plane {
public:
Vector3 normal;
real_t d;
void set_normal(const Vector3& p_normal);
inline Vector3 get_normal() const { return normal; } ///Point is coplanar, CMP_EPSILON for precision
void normalize();
Plane normalized() const;
/* Plane-Point operations */
inline Vector3 center() const { return normal*d; }
Vector3 get_any_point() const;
Vector3 get_any_perpendicular_normal() const;
bool is_point_over(const Vector3 &p_point) const; ///< Point is over plane
real_t distance_to(const Vector3 &p_point) const;
bool has_point(const Vector3 &p_point,real_t _epsilon=CMP_EPSILON) const;
/* intersections */
bool intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result=0) const;
bool intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3* p_intersection) const;
bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3* p_intersection) const;
Vector3 project(const Vector3& p_point) const;
/* misc */
inline Plane operator-() const { return Plane(-normal,-d); }
bool is_almost_like(const Plane& p_plane) const;
bool operator==(const Plane& p_plane) const;
bool operator!=(const Plane& p_plane) const;
operator String() const;
inline Plane() { d=0; }
inline Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) : normal(p_a,p_b,p_c), d(p_d) { }
Plane(const Vector3 &p_normal, real_t p_d);
Plane(const Vector3 &p_point, const Vector3& p_normal);
Plane(const Vector3 &p_point1, const Vector3 &p_point2,const Vector3 &p_point3,ClockDirection p_dir = CLOCKWISE);
};
}
#endif // PLANE_H

249
include/core/PoolArrays.hpp Normal file
View File

@@ -0,0 +1,249 @@
#ifndef POOLARRAYS_H
#define POOLARRAYS_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Defs.hpp"
#include "String.hpp"
#include "Color.hpp"
#include "Vector2.hpp"
#include "Vector3.hpp"
#include <godot/godot_pool_arrays.h>
namespace godot {
class Array;
class GD_CPP_CORE_API PoolByteArray {
godot_pool_byte_array _godot_array;
public:
PoolByteArray();
PoolByteArray(const Array& array);
void append(const uint8_t data);
void append_array(const PoolByteArray& array);
int insert(const int idx, const uint8_t data);
void invert();
void push_back(const uint8_t data);
void remove(const int idx);
void resize(const int size);
void set(const int idx, const uint8_t data);
uint8_t operator [](const int idx);
int size();
~PoolByteArray();
};
class GD_CPP_CORE_API PoolIntArray {
godot_pool_int_array _godot_array;
public:
PoolIntArray();
PoolIntArray(const Array& array);
void append(const int data);
void append_array(const PoolIntArray& array);
int insert(const int idx, const int data);
void invert();
void push_back(const int data);
void remove(const int idx);
void resize(const int size);
void set(const int idx, const int data);
int operator [](const int idx);
int size();
~PoolIntArray();
};
class GD_CPP_CORE_API PoolRealArray {
godot_pool_real_array _godot_array;
public:
PoolRealArray();
PoolRealArray(const Array& array);
void append(const real_t data);
void append_array(const PoolRealArray& array);
int insert(const int idx, const real_t data);
void invert();
void push_back(const real_t data);
void remove(const int idx);
void resize(const int size);
void set(const int idx, const real_t data);
real_t operator [](const int idx);
int size();
~PoolRealArray();
};
class GD_CPP_CORE_API PoolStringArray {
godot_pool_string_array _godot_array;
public:
PoolStringArray();
PoolStringArray(const Array& array);
void append(const String& data);
void append_array(const PoolStringArray& array);
int insert(const int idx, const String& data);
void invert();
void push_back(const String& data);
void remove(const int idx);
void resize(const int size);
void set(const int idx, const String& data);
String operator [](const int idx);
int size();
~PoolStringArray();
};
class GD_CPP_CORE_API PoolVector2Array {
godot_pool_vector2_array _godot_array;
public:
PoolVector2Array();
PoolVector2Array(const Array& array);
void append(const Vector2& data);
void append_array(const PoolVector2Array& array);
int insert(const int idx, const Vector2& data);
void invert();
void push_back(const Vector2& data);
void remove(const int idx);
void resize(const int size);
void set(const int idx, const Vector2& data);
Vector2 operator [](const int idx);
int size();
~PoolVector2Array();
};
class GD_CPP_CORE_API PoolVector3Array {
godot_pool_vector3_array _godot_array;
public:
PoolVector3Array();
PoolVector3Array(const Array& array);
void append(const Vector3& data);
void append_array(const PoolVector3Array& array);
int insert(const int idx, const Vector3& data);
void invert();
void push_back(const Vector3& data);
void remove(const int idx);
void resize(const int size);
void set(const int idx, const Vector3& data);
Vector3 operator [](const int idx);
int size();
~PoolVector3Array();
};
class GD_CPP_CORE_API PoolColorArray {
godot_pool_color_array _godot_array;
public:
PoolColorArray();
PoolColorArray(const Array& array);
void append(const Color& data);
void append_array(const PoolColorArray& array);
int insert(const int idx, const Color& data);
void invert();
void push_back(const Color& data);
void remove(const int idx);
void resize(const int size);
void set(const int idx, const Color& data);
Color operator [](const int idx);
int size();
~PoolColorArray();
};
}
#endif // POOLARRAYS_H

93
include/core/Quat.hpp Normal file
View File

@@ -0,0 +1,93 @@
#ifndef QUAT_H
#define QUAT_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <cmath>
#include "Vector3.hpp"
// #include "Basis.h"
namespace godot {
class GD_CPP_CORE_API Quat{
public:
real_t x,y,z,w;
real_t length_squared() const;
real_t length() const;
void normalize();
Quat normalized() const;
Quat inverse() const;
void set_euler(const Vector3& p_euler);
real_t dot(const Quat& q) const;
Vector3 get_euler() const;
Quat slerp(const Quat& q, const real_t& t) const;
Quat slerpni(const Quat& q, const real_t& t) const;
Quat cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const real_t& t) const;
void get_axis_and_angle(Vector3& r_axis, real_t &r_angle) const;
void operator*=(const Quat& q);
Quat operator*(const Quat& q) const;
Quat operator*(const Vector3& v) const;
Vector3 xform(const Vector3& v) const;
void operator+=(const Quat& q);
void operator-=(const Quat& q);
void operator*=(const real_t& s);
void operator/=(const real_t& s);
Quat operator+(const Quat& q2) const;
Quat operator-(const Quat& q2) const;
Quat operator-() const;
Quat operator*(const real_t& s) const;
Quat operator/(const real_t& s) const;
bool operator==(const Quat& p_quat) const;
bool operator!=(const Quat& p_quat) const;
operator String() const;
inline void set( real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
x=p_x; y=p_y; z=p_z; w=p_w;
}
inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
x=p_x; y=p_y; z=p_z; w=p_w;
}
Quat(const Vector3& axis, const real_t& angle);
Quat(const Vector3& v0, const Vector3& v1) ;
inline Quat() {x=y=z=0; w=1; }
};
}
#endif // QUAT_H

35
include/core/RID.hpp Normal file
View File

@@ -0,0 +1,35 @@
#ifndef RID_H
#define RID_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_rid.h>
namespace godot {
class Object;
class GD_CPP_CORE_API RID {
godot_rid _godot_rid;
public:
inline RID() {}
RID(Object *p);
int32_t get_rid() const;
~RID();
};
}
#endif // RID_H

143
include/core/Rect2.hpp Normal file
View File

@@ -0,0 +1,143 @@
#ifndef RECT2_H
#define RECT2_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Vector2.hpp"
#include <cmath>
#include <cstdlib>
namespace godot {
class String;
typedef Vector2 Size2;
typedef Vector2 Point2;
class Transform2D;
struct GD_CPP_CORE_API Rect2 {
Point2 pos;
Size2 size;
inline const Vector2& get_pos() const { return pos; }
inline void set_pos(const Vector2& p_pos) { pos=p_pos; }
inline const Vector2& get_size() const { return size; }
inline void set_size(const Vector2& p_size) { size=p_size; }
inline real_t get_area() const { return size.width*size.height; }
inline bool intersects(const Rect2& p_rect) const {
if ( pos.x >= (p_rect.pos.x + p_rect.size.width) )
return false;
if ( (pos.x+size.width) <= p_rect.pos.x )
return false;
if ( pos.y >= (p_rect.pos.y + p_rect.size.height) )
return false;
if ( (pos.y+size.height) <= p_rect.pos.y )
return false;
return true;
}
real_t distance_to(const Vector2& p_point) const;
bool intersects_transformed(const Transform2D& p_xform, const Rect2& p_rect) const;
bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=NULL, Point2* r_normal=NULL) const;
inline bool encloses(const Rect2& p_rect) const {
return (p_rect.pos.x>=pos.x) && (p_rect.pos.y>=pos.y) &&
((p_rect.pos.x+p_rect.size.x)<(pos.x+size.x)) &&
((p_rect.pos.y+p_rect.size.y)<(pos.y+size.y));
}
inline bool has_no_area() const {
return (size.x<=0 || size.y<=0);
}
Rect2 clip(const Rect2& p_rect) const;
Rect2 merge(const Rect2& p_rect) const;
inline bool has_point(const Point2& p_point) const {
if (p_point.x < pos.x)
return false;
if (p_point.y < pos.y)
return false;
if (p_point.x >= (pos.x+size.x) )
return false;
if (p_point.y >= (pos.y+size.y) )
return false;
return true;
}
inline bool no_area() const { return (size.width<=0 || size.height<=0 ); }
inline bool operator==(const Rect2& p_rect) const { return pos==p_rect.pos && size==p_rect.size; }
inline bool operator!=(const Rect2& p_rect) const { return pos!=p_rect.pos || size!=p_rect.size; }
inline Rect2 grow(real_t p_by) const {
Rect2 g=*this;
g.pos.x-=p_by;
g.pos.y-=p_by;
g.size.width+=p_by*2;
g.size.height+=p_by*2;
return g;
}
inline Rect2 expand(const Vector2& p_vector) const {
Rect2 r = *this;
r.expand_to(p_vector);
return r;
}
inline void expand_to(const Vector2& p_vector) { //in place function for speed
Vector2 begin=pos;
Vector2 end=pos+size;
if (p_vector.x<begin.x)
begin.x=p_vector.x;
if (p_vector.y<begin.y)
begin.y=p_vector.y;
if (p_vector.x>end.x)
end.x=p_vector.x;
if (p_vector.y>end.y)
end.y=p_vector.y;
pos=begin;
size=end-begin;
}
operator String() const;
inline Rect2() {}
inline Rect2( real_t p_x, real_t p_y, real_t p_width, real_t p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); }
inline Rect2( const Point2& p_pos, const Size2& p_size ) { pos=p_pos; size=p_size; }
};
}
#endif // RECT2_H

93
include/core/Rect3.hpp Normal file
View File

@@ -0,0 +1,93 @@
#ifndef RECT3_H
#define RECT3_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Vector3.hpp"
#include "Plane.hpp"
#include <cstdlib>
namespace godot {
class GD_CPP_CORE_API Rect3 {
public:
Vector3 pos;
Vector3 size;
real_t get_area() const; /// get area
inline bool has_no_area() const {
return (size.x<=CMP_EPSILON || size.y<=CMP_EPSILON || size.z<=CMP_EPSILON);
}
inline bool has_no_surface() const {
return (size.x<=CMP_EPSILON && size.y<=CMP_EPSILON && size.z<=CMP_EPSILON);
}
inline const Vector3& get_pos() const { return pos; }
inline void set_pos(const Vector3& p_pos) { pos=p_pos; }
inline const Vector3& get_size() const { return size; }
inline void set_size(const Vector3& p_size) { size=p_size; }
bool operator==(const Rect3& p_rval) const;
bool operator!=(const Rect3& p_rval) const;
bool intersects(const Rect3& p_aabb) const; /// Both AABBs overlap
bool intersects_inclusive(const Rect3& p_aabb) const; /// Both AABBs (or their faces) overlap
bool encloses(const Rect3 & p_aabb) const; /// p_aabb is completely inside this
Rect3 merge(const Rect3& p_with) const;
void merge_with(const Rect3& p_aabb); ///merge with another AABB
Rect3 intersection(const Rect3& p_aabb) const; ///get box where two intersect, empty if no intersection occurs
bool intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const;
bool intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const;
bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, real_t t0, real_t t1) const;
bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const;
bool intersects_plane(const Plane &p_plane) const;
bool has_point(const Vector3& p_point) const;
Vector3 get_support(const Vector3& p_normal) const;
Vector3 get_longest_axis() const;
int get_longest_axis_index() const;
real_t get_longest_axis_size() const;
Vector3 get_shortest_axis() const;
int get_shortest_axis_index() const;
real_t get_shortest_axis_size() const;
Rect3 grow(real_t p_by) const;
void grow_by(real_t p_amount);
void get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const;
Vector3 get_endpoint(int p_point) const;
Rect3 expand(const Vector3& p_vector) const;
void project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const;
void expand_to(const Vector3& p_vector); /** expand to contain a point if necesary */
operator String() const;
inline Rect3() {}
inline Rect3(const Vector3 &p_pos,const Vector3& p_size) { pos=p_pos; size=p_size; }
};
}
#endif // RECT3_H

79
include/core/String.hpp Normal file
View File

@@ -0,0 +1,79 @@
#ifndef STRING_H
#define STRING_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_string.h>
namespace godot {
class NodePath;
class GD_CPP_CORE_API String
{
godot_string _godot_string;
public:
String();
String(const char *contents);
String(const wchar_t *contents);
String(const wchar_t c);
String(const String& other);
~String();
String substr(int p_from,int p_chars) const;
wchar_t &operator [](const int idx);
wchar_t operator [](const int idx) const;
int length() const;
void operator =(const String &s);
bool operator ==(const String &s);
bool operator !=(const String &s);
String operator +(const String &s);
void operator +=(const String &s);
void operator +=(const wchar_t c);
bool operator <(const String &s);
bool operator <=(const String &s);
bool operator >(const String &s);
bool operator >=(const String &s);
operator NodePath() const;
const char *c_string() const;
};
String operator +(const char *a, const String& b);
}
#endif // STRING_H

View File

@@ -0,0 +1,91 @@
#ifndef TRANSFORM_H
#define TRANSFORM_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Basis.hpp"
#include "Plane.hpp"
#include "Rect3.hpp"
namespace godot {
class GD_CPP_CORE_API Transform {
public:
Basis basis;
Vector3 origin;
void invert();
Transform inverse() const;
void affine_invert();
Transform affine_inverse() const;
Transform rotated(const Vector3& p_axis,real_t p_phi) const;
void rotate(const Vector3& p_axis,real_t p_phi);
void rotate_basis(const Vector3& p_axis,real_t p_phi);
void set_look_at( const Vector3& p_eye, const Vector3& p_target, const Vector3& p_up );
Transform looking_at( const Vector3& p_target, const Vector3& p_up ) const;
void scale(const Vector3& p_scale);
Transform scaled(const Vector3& p_scale) const;
void scale_basis(const Vector3& p_scale);
void translate( real_t p_tx, real_t p_ty, real_t p_tz );
void translate( const Vector3& p_translation );
Transform translated( const Vector3& p_translation ) const;
inline const Basis& get_basis() const { return basis; }
inline void set_basis(const Basis& p_basis) { basis=p_basis; }
inline const Vector3& get_origin() const { return origin; }
inline void set_origin(const Vector3& p_origin) { origin=p_origin; }
void orthonormalize();
Transform orthonormalized() const;
bool operator==(const Transform& p_transform) const;
bool operator!=(const Transform& p_transform) const;
Vector3 xform(const Vector3& p_vector) const;
Vector3 xform_inv(const Vector3& p_vector) const;
Plane xform(const Plane& p_plane) const;
Plane xform_inv(const Plane& p_plane) const;
Rect3 xform(const Rect3& p_aabb) const;
Rect3 xform_inv(const Rect3& p_aabb) const;
void operator*=(const Transform& p_transform);
Transform operator*(const Transform& p_transform) const;
Transform interpolate_with(const Transform& p_transform, real_t p_c) const;
Transform inverse_xform(const Transform& t) const;
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz,real_t tx, real_t ty, real_t tz);
operator String() const;
inline Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz,real_t tx, real_t ty, real_t tz) {
set(xx, xy, xz, yx, yy, yz, zx, zy, zz,tx, ty, tz);
}
Transform(const Basis& p_basis, const Vector3& p_origin=Vector3());
inline Transform() {}
};
}
#endif // TRANSFORM_H

View File

@@ -0,0 +1,104 @@
#ifndef TRANSFORM2D_H
#define TRANSFORM2D_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Vector2.hpp"
namespace godot {
typedef Vector2 Size2;
class Rect2;
struct GD_CPP_CORE_API Transform2D {
// Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper":
// M = (elements[0][0] elements[1][0])
// (elements[0][1] elements[1][1])
// This is such that the columns, which can be interpreted as basis vectors of the coordinate system "painted" on the object, can be accessed as elements[i].
// Note that this is the opposite of the indices in mathematical texts, meaning: $M_{12}$ in a math book corresponds to elements[1][0] here.
// This requires additional care when working with explicit indices.
// See https://en.wikipedia.org/wiki/Row-_and_column-major_order for further reading.
// Warning #2: 2D be aware that unlike 3D code, 2D code uses a left-handed coordinate system: Y-axis points down,
// and angle is measure from +X to +Y in a clockwise-fashion.
Vector2 elements[3];
inline real_t tdotx(const Vector2& v) const { return elements[0][0] * v.x + elements[1][0] * v.y; }
inline real_t tdoty(const Vector2& v) const { return elements[0][1] * v.x + elements[1][1] * v.y; }
inline const Vector2& operator[](int p_idx) const { return elements[p_idx]; }
inline Vector2& operator[](int p_idx) { return elements[p_idx]; }
inline Vector2 get_axis(int p_axis) const { ERR_FAIL_INDEX_V(p_axis,3,Vector2()); return elements[p_axis]; }
inline void set_axis(int p_axis,const Vector2& p_vec) { ERR_FAIL_INDEX(p_axis,3); elements[p_axis]=p_vec; }
void invert();
Transform2D inverse() const;
void affine_invert();
Transform2D affine_inverse() const;
void set_rotation(real_t p_phi);
real_t get_rotation() const;
void set_rotation_and_scale(real_t p_phi,const Size2& p_scale);
void rotate(real_t p_phi);
void scale(const Size2& p_scale);
void scale_basis(const Size2& p_scale);
void translate( real_t p_tx, real_t p_ty);
void translate( const Vector2& p_translation );
real_t basis_determinant() const;
Size2 get_scale() const;
inline const Vector2& get_origin() const { return elements[2]; }
inline void set_origin(const Vector2& p_origin) { elements[2]=p_origin; }
Transform2D scaled(const Size2& p_scale) const;
Transform2D basis_scaled(const Size2& p_scale) const;
Transform2D translated(const Vector2& p_offset) const;
Transform2D rotated(real_t p_phi) const;
Transform2D untranslated() const;
void orthonormalize();
Transform2D orthonormalized() const;
bool operator==(const Transform2D& p_transform) const;
bool operator!=(const Transform2D& p_transform) const;
void operator*=(const Transform2D& p_transform);
Transform2D operator*(const Transform2D& p_transform) const;
Transform2D interpolate_with(const Transform2D& p_transform, real_t p_c) const;
Vector2 basis_xform(const Vector2& p_vec) const;
Vector2 basis_xform_inv(const Vector2& p_vec) const;
Vector2 xform(const Vector2& p_vec) const;
Vector2 xform_inv(const Vector2& p_vec) const;
Rect2 xform(const Rect2& p_vec) const;
Rect2 xform_inv(const Rect2& p_vec) const;
operator String() const;
Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy);
Transform2D(real_t p_rot, const Vector2& p_pos);
inline Transform2D() { elements[0][0]=1.0; elements[1][1]=1.0; }
};
}
#endif // TRANSFORM2D_H

251
include/core/Variant.hpp Normal file
View File

@@ -0,0 +1,251 @@
#ifndef VARIANT_H
#define VARIANT_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_variant.h>
#include "Defs.hpp"
#include "Basis.hpp"
#include "Color.hpp"
#include "Image.hpp"
#include "InputEvent.hpp"
#include "NodePath.hpp"
#include "Plane.hpp"
#include "PoolArrays.hpp"
#include "Quat.hpp"
#include "Rect2.hpp"
#include "Rect3.hpp"
#include "RID.hpp"
#include "String.hpp"
#include "Transform.hpp"
#include "Transform2D.hpp"
#include "Vector2.hpp"
#include "Vector3.hpp"
#include <iostream>
namespace godot {
class Dictionary;
class Array;
class GD_CPP_CORE_API Variant {
godot_variant _godot_variant;
public:
enum Type {
NIL,
// atomic types
BOOL,
INT,
REAL,
STRING,
// math types
VECTOR2, // 5
RECT2,
VECTOR3,
TRANSFORM2D,
PLANE,
QUAT, // 10
RECT3, //sorry naming convention fail :( not like it's used often
BASIS,
TRANSFORM,
// misc types
COLOR,
IMAGE, // 15
NODE_PATH,
_RID,
OBJECT,
INPUT_EVENT,
DICTIONARY, // 20
ARRAY,
// arrays
POOL_BYTE_ARRAY,
POOL_INT_ARRAY,
POOL_REAL_ARRAY,
POOL_STRING_ARRAY, // 25
POOL_VECTOR2_ARRAY,
POOL_VECTOR3_ARRAY,
POOL_COLOR_ARRAY,
VARIANT_MAX
};
Variant();
Variant(const Variant& v);
Variant(bool p_bool);
Variant(signed int p_int);
Variant(unsigned int p_int);
Variant(signed short p_short);
inline Variant(unsigned short p_short) : Variant((unsigned int) p_short) {}
inline Variant(signed char p_char) : Variant((signed int) p_char) {}
inline Variant(unsigned char p_char) : Variant((unsigned int) p_char) {}
Variant(int64_t p_char);
Variant(uint64_t p_char);
Variant(float p_float);
Variant(double p_double);
Variant(const String& p_string);
Variant(const char * const p_cstring);
Variant(const wchar_t * p_wstring);
Variant(const Vector2& p_vector2);
Variant(const Rect2& p_rect2);
Variant(const Vector3& p_vector3);
Variant(const Plane& p_plane);
Variant(const Rect3& p_aabb);
Variant(const Quat& p_quat);
Variant(const Basis& p_transform);
Variant(const Transform2D& p_transform);
Variant(const Transform& p_transform);
Variant(const Color& p_color);
Variant(const Image& p_image);
Variant(const NodePath& p_path);
Variant(const RID& p_rid);
Variant(const Object* p_object);
Variant(const InputEvent& p_input_event);
Variant(const Dictionary& p_dictionary);
Variant(const Array& p_array);
Variant(const PoolByteArray& p_raw_array);
Variant(const PoolIntArray& p_int_array);
Variant(const PoolRealArray& p_real_array);
Variant(const PoolStringArray& p_string_array);
Variant(const PoolVector2Array& p_vector2_array);
Variant(const PoolVector3Array& p_vector3_array);
Variant(const PoolColorArray& p_color_array);
Variant &operator =(const Variant& v);
operator bool() const;
operator signed int() const;
operator unsigned int() const ;
operator signed short() const;
operator unsigned short() const;
operator signed char() const;
operator unsigned char() const;
operator int64_t() const;
operator uint64_t() const;
operator wchar_t() const;
operator float() const;
operator double() const;
operator String() const;
operator Vector2() const;
operator Rect2() const;
operator Vector3() const;
operator Plane() const;
operator Rect3() const;
operator Quat() const;
operator Basis() const;
operator Transform() const;
operator Transform2D() const;
operator Color() const;
operator Image() const;
operator NodePath() const;
operator RID() const;
operator InputEvent() const;
operator Object*() const;
operator Dictionary() const;
operator Array() const;
operator PoolByteArray() const;
operator PoolIntArray() const;
operator PoolRealArray() const;
operator PoolStringArray() const;
operator PoolVector2Array() const;
operator PoolVector3Array() const;
operator PoolColorArray() const;
Type get_type() const;
Variant call(const String& method, const Variant **args, const int arg_count);
bool has_method(const String& method);
bool operator ==(const Variant& b) const;
bool operator !=(const Variant& b) const;
bool operator <(const Variant& b) const;
bool operator <=(const Variant& b) const;
bool operator >(const Variant& b) const;
bool operator >=(const Variant& b) const;
bool hash_compare(const Variant& b) const;
bool booleanize(bool &valid) const;
~Variant();
};
}
#endif // VARIANT_H

139
include/core/Vector2.hpp Normal file
View File

@@ -0,0 +1,139 @@
#ifndef VECTOR2_H
#define VECTOR2_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include <godot/godot_vector2.h>
#include "Defs.hpp"
namespace godot {
class String;
struct GD_CPP_CORE_API Vector2 {
union {
real_t x;
real_t width;
};
union {
real_t y;
real_t height;
};
inline real_t& operator[](int p_idx) {
return p_idx?y:x;
}
inline const real_t& operator[](int p_idx) const {
return p_idx?y:x;
}
Vector2 operator+(const Vector2& p_v) const;
void operator+=(const Vector2& p_v);
Vector2 operator-(const Vector2& p_v) const;
void operator-=(const Vector2& p_v);
Vector2 operator*(const Vector2 &p_v1) const;
Vector2 operator*(const real_t &rvalue) const;
void operator*=(const real_t &rvalue);
inline void operator*=(const Vector2 &rvalue) { *this = *this * rvalue; }
Vector2 operator/(const Vector2 &p_v1) const;
Vector2 operator/(const real_t &rvalue) const;
void operator/=(const real_t &rvalue);
Vector2 operator-() const;
bool operator==(const Vector2& p_vec2) const;
bool operator!=(const Vector2& p_vec2) const;
inline bool operator<(const Vector2& p_vec2) const { return (x==p_vec2.x)?(y<p_vec2.y):(x<p_vec2.x); }
inline bool operator<=(const Vector2& p_vec2) const { return (x==p_vec2.x)?(y<=p_vec2.y):(x<=p_vec2.x); }
void normalize();
Vector2 normalized() const;
real_t length() const;
real_t length_squared() const;
real_t distance_to(const Vector2& p_vector2) const;
real_t distance_squared_to(const Vector2& p_vector2) const;
real_t angle_to(const Vector2& p_vector2) const;
real_t angle_to_point(const Vector2& p_vector2) const;
real_t dot(const Vector2& p_other) const;
real_t cross(const Vector2& p_other) const;
Vector2 cross(real_t p_other) const;
Vector2 project(const Vector2& p_vec) const;
Vector2 plane_project(real_t p_d, const Vector2& p_vec) const;
Vector2 clamped(real_t p_len) const;
static Vector2 linear_interpolate(const Vector2& p_a, const Vector2& p_b,real_t p_t);
Vector2 linear_interpolate(const Vector2& p_b,real_t p_t) const;
Vector2 cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,real_t p_t) const;
Vector2 slide(const Vector2& p_vec) const;
Vector2 reflect(const Vector2& p_vec) const;
real_t angle() const;
void set_rotation(real_t p_radians);
Vector2 abs() const;
Vector2 rotated(real_t p_by) const;
Vector2 tangent() const;
Vector2 floor() const;
Vector2 snapped(const Vector2& p_by) const;
inline real_t aspect() const { return width/height; }
operator String() const;
inline Vector2(real_t p_x,real_t p_y) { x=p_x; y=p_y; }
inline Vector2() { x=0; y=0; }
};
inline Vector2 operator*(real_t p_scalar, const Vector2& p_vec)
{
return p_vec*p_scalar;
}
}
#endif // VECTOR2_H

146
include/core/Vector3.hpp Normal file
View File

@@ -0,0 +1,146 @@
#ifndef VECTOR3_H
#define VECTOR3_H
#if defined(_WIN32)
# ifdef _GD_CPP_CORE_API_IMPL
# define GD_CPP_CORE_API __declspec(dllexport)
# else
# define GD_CPP_CORE_API __declspec(dllimport)
# endif
#else
# define GD_CPP_CORE_API
#endif
#include "Defs.hpp"
#include "String.hpp"
namespace godot {
struct GD_CPP_CORE_API Vector3 {
enum Axis {
AXIS_X,
AXIS_Y,
AXIS_Z,
};
union {
struct {
real_t x;
real_t y;
real_t z;
};
real_t coord[3];
};
Vector3(real_t x, real_t y, real_t z);
Vector3();
Vector3(const Vector3& b);
const real_t& operator[](int p_axis) const;
real_t& operator[](int p_axis);
Vector3& operator+=(const Vector3& p_v);
Vector3 operator+(const Vector3& p_v) const;
Vector3& operator-=(const Vector3& p_v);
Vector3 operator-(const Vector3& p_v) const;
Vector3& operator*=(const Vector3& p_v);
Vector3 operator*(const Vector3& p_v) const;
Vector3& operator/=(const Vector3& p_v);
Vector3 operator/(const Vector3& p_v) const;
Vector3& operator*=(real_t p_scalar);
Vector3 operator*(real_t p_scalar) const;
Vector3& operator/=(real_t p_scalar);
Vector3 operator/(real_t p_scalar) const;
Vector3 operator-() const;
bool operator==(const Vector3& p_v) const;
bool operator!=(const Vector3& p_v) const;
bool operator<(const Vector3& p_v) const;
bool operator<=(const Vector3& p_v) const;
Vector3 abs() const;
Vector3 ceil() const;
Vector3 cross(const Vector3& b) const;
Vector3 linear_interpolate(const Vector3& p_b,real_t p_t) const;
Vector3 cubic_interpolate(const Vector3& b, const Vector3& pre_a, const Vector3& post_b, const real_t t) const;
real_t length() const;
real_t length_squared() const;
real_t distance_squared_to(const Vector3& b) const;
real_t distance_to(const Vector3& b) const;
real_t dot(const Vector3& b) const;
Vector3 floor() const;
Vector3 inverse() const;
int max_axis() const;
int min_axis() const;
void normalize();
Vector3 normalized() const;
Vector3 reflect(const Vector3& by) const;
Vector3 rotated(const Vector3& axis, const real_t phi) const;
void rotate(const Vector3& p_axis,real_t p_phi);
Vector3 slide(const Vector3& by) const;
void snap(real_t p_val);
Vector3 snapped(const float by);
operator String() const;
};
inline Vector3 operator*(real_t p_scalar, const Vector3& p_vec)
{
return p_vec * p_scalar;
}
inline Vector3 vec3_cross(const Vector3& p_a, const Vector3& p_b) {
return p_a.cross(p_b);
}
}
#endif // VECTOR3_H