made script "inheritance" less OOP

pull/8/head
Karroffel 2017-05-13 13:55:04 +02:00
parent cf30b0f39d
commit fad8f7c9eb
6 changed files with 84 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
src/*.cpp
src/*.hpp
include/*.hpp
*.os
*.so

View File

@ -441,7 +441,7 @@ def generate_icall_implementation(icalls):
source.append("")
source.append("")
source.append("using namespace godot;")
source.append("namespace godot {")
source.append("")
for icall in icalls:
@ -497,6 +497,7 @@ def generate_icall_implementation(icalls):
source.append("}")
source.append("}")
source.append("")
return "\n".join(source)

View File

@ -1,5 +1,5 @@
#ifndef GODOT_H
#define GODOT_H
#ifndef GODOT_HPP
#define GODOT_HPP
#include <cstdlib>
@ -11,9 +11,30 @@
#include <Object.hpp>
#include <GodotGlobal.hpp>
namespace godot {
template<class T>
class GodotScript {
public:
T *owner;
// GodotScript() {}
void _init() {}
static char *___get_base_type_name()
{
return T::___get_class_name();
}
static void _register_methods() {}
};
#if !defined(_WIN32)
@ -28,11 +49,8 @@ namespace godot {
#define GODOT_CLASS(Name, Base) \
#define GODOT_CLASS(Name) \
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) \
@ -73,7 +91,8 @@ T *as(Object *obj)
template<class T>
void *_godot_class_instance_func(godot_object *p, void *method_data)
{
T *d = new T(p);
T *d = new T();
*(godot_object **) &d->owner = p;
d->_init();
return d;
}

View File

@ -0,0 +1,30 @@
#ifndef GODOT_GLOBAL_HPP
#define GODOT_GLOBAL_HPP
#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"
namespace godot {
class GD_CPP_CORE_API Godot {
public:
static void print(const String& message);
static void print_warning(const String& description, const String& function, const String& file, int line);
static void print_error(const String& description, const String& function, const String& file, int line);
};
}
#endif

24
src/core/GodotGlobal.cpp Normal file
View File

@ -0,0 +1,24 @@
#include "GodotGlobal.hpp"
#include "String.hpp"
#include <godot.h>
namespace godot {
void Godot::print(const String& message)
{
godot_print((godot_string *) &message);
}
void Godot::print_warning(const String& description, const String& function, const String& file, int line)
{
godot_print_warning(description.c_string(), function.c_string(), file.c_string(), line);
}
void Godot::print_error(const String& description, const String& function, const String& file, int line)
{
godot_print_error(description.c_string(), function.c_string(), file.c_string(), line);
}
};

View File

@ -399,7 +399,7 @@ Variant::Type Variant::get_type() const
Variant Variant::call(const String& method, const Variant **args, const int arg_count)
{
Variant v;
*(godot_variant *) &v = godot_variant_call(&_godot_variant, (godot_string *) &method, (const godot_variant **)args, arg_count);
*(godot_variant *) &v = godot_variant_call(&_godot_variant, (godot_string *) &method, (const godot_variant **)args, arg_count, nullptr);
return v;
}