Browse Source

made script "inheritance" less OOP

Karroffel 8 years ago
parent
commit
fad8f7c9eb
6 changed files with 84 additions and 9 deletions
  1. 1 0
      .gitignore
  2. 2 1
      binding_generator.py
  3. 26 7
      include/core/Godot.hpp
  4. 30 0
      include/core/GodotGlobal.hpp
  5. 24 0
      src/core/GodotGlobal.cpp
  6. 1 1
      src/core/Variant.cpp

+ 1 - 0
.gitignore

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

+ 2 - 1
binding_generator.py

@@ -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)

+ 26 - 7
include/core/Godot.hpp

@@ -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;
 }

+ 30 - 0
include/core/GodotGlobal.hpp

@@ -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 - 0
src/core/GodotGlobal.cpp

@@ -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);
+}
+
+};

+ 1 - 1
src/core/Variant.cpp

@@ -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;
 }