diff --git a/.gitignore b/.gitignore index 00d0f29..f5cd999 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,8 @@ *.pyc *.bc *.os +*.so + +.sconsign.dblite + +gdnative_cpp/ diff --git a/SConstruct b/SConstruct new file mode 100644 index 0000000..05bb11c --- /dev/null +++ b/SConstruct @@ -0,0 +1,105 @@ +#!python +import os, subprocess + +opts = Variables([], ARGUMENTS) + +# Gets the standard flags CC, CCX, etc. +env = DefaultEnvironment() + +# Define our options +opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release'])) +opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx'])) +opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx'])) +opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no')) +opts.Add(PathVariable('target_path', 'The path where the lib is installed.', '../game/gdn/')) +opts.Add(PathVariable('target_name', 'The library name.', 'libgdexample', PathVariable.PathAccept)) + +# Local dependency paths, adapt them to your setup +godot_headers_path = "gdnative_cpp/pandemonium_headers/" +cpp_bindings_path = "gdnative_cpp/" +cpp_library = "libpandemonium-cpp" + +# only support 64 at this time.. +bits = 64 + +# Updates the environment with the option variables. +opts.Update(env) + +# Process some arguments +if env['use_llvm']: + env['CC'] = 'clang' + env['CXX'] = 'clang++' + +if env['p'] != '': + env['platform'] = env['p'] + +if env['platform'] == '': + print("No valid target platform selected.") + quit(); + +# Check our platform specifics +if env['platform'] == "osx": + env['target_path'] += 'osx/' + cpp_library += '.osx' + if env['target'] in ('debug', 'd'): + env.Append(CCFLAGS = ['-g','-O2', '-arch', 'x86_64', '-std=c++17']) + env.Append(LINKFLAGS = ['-arch', 'x86_64']) + else: + env.Append(CCFLAGS = ['-g','-O3', '-arch', 'x86_64', '-std=c++17']) + env.Append(LINKFLAGS = ['-arch', 'x86_64']) + +elif env['platform'] in ('x11', 'linux'): + env['target_path'] += 'x11/' + cpp_library += '.linux' + if env['target'] in ('debug', 'd'): + env.Append(CCFLAGS = ['-fPIC', '-g3','-Og', '-std=c++17']) + else: + env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c++17']) + +elif env['platform'] == "windows": + env['target_path'] += 'win64/' + cpp_library += '.windows' + # This makes sure to keep the session environment variables on windows, + # that way you can run scons in a vs 2017 prompt and it will find all the required tools + env.Append(ENV = os.environ) + + env.Append(CCFLAGS = ['-DWIN32', '-D_WIN32', '-D_WINDOWS', '-W3', '-GR', '-D_CRT_SECURE_NO_WARNINGS']) + if env['target'] in ('debug', 'd'): + env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '-MDd']) + else: + env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '-MD']) + +if env['target'] in ('debug', 'd'): + cpp_library += '.debug' +else: + cpp_library += '.release' + +cpp_library += '.' + str(bits) + +# make sure our binding library is properly includes +env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path, cpp_bindings_path + '/core/', cpp_bindings_path + '/gen/']) +env.Append(LIBPATH=[cpp_bindings_path + 'bin/']) +env.Append(LIBS=[cpp_library]) + +env.Append(CCFLAGS = ['-DGDNATIVE']) + +# tweak this if you want to use different folders, or more folders, to store your source code in. +#env.Append(CPPPATH=['src/']) +#sources = Glob('src/*.cpp') + +sources = [ + "gdlibrary.cpp", + + "mlpp/lin_alg/mlpp_vector.cpp", + "mlpp/lin_alg/mlpp_matrix.cpp", + "mlpp/lin_alg/mlpp_tensor3.cpp", + "mlpp/lin_alg/lin_alg.cpp", + +] + +library = env.SharedLibrary(target=env['target_path'] + env['target_name'] , source=sources) + +Default(library) + +# Generates help for the -h scons option. +Help(opts.GenerateHelpText(env)) diff --git a/gdlibrary.cpp b/gdlibrary.cpp new file mode 100644 index 0000000..f21af41 --- /dev/null +++ b/gdlibrary.cpp @@ -0,0 +1,16 @@ +#include "core/pandemonium_global.h" + + + +extern "C" void GDN_EXPORT pandemonium_gdnative_init(pandemonium_gdnative_init_options *o) { + Pandemonium::gdnative_init(o); +} + +extern "C" void GDN_EXPORT pandemonium_gdnative_terminate(pandemonium_gdnative_terminate_options *o) { + Pandemonium::gdnative_terminate(o); + +} + +extern "C" void GDN_EXPORT pandemonium_nativescript_init(void *handle) { + Pandemonium::nativescript_init(handle); +} diff --git a/mlpp/lin_alg/lin_alg.h b/mlpp/lin_alg/lin_alg.h index 557e05a..3400588 100644 --- a/mlpp/lin_alg/lin_alg.h +++ b/mlpp/lin_alg/lin_alg.h @@ -10,10 +10,21 @@ //TODO Methods here should probably use error macros in a way where they get disabled in non-tools(?) (maybe release?) builds +#ifndef GDNATIVE + #include "core/math/math_defs.h" #include "core/object/reference.h" +#else + +#include "core/defs.h" +#include "core/math_funcs.h" + +#include "gen/resource.h" + +#endif + #include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_vector.h" diff --git a/mlpp/lin_alg/mlpp_matrix.h b/mlpp/lin_alg/mlpp_matrix.h index 3449f09..0e257d0 100644 --- a/mlpp/lin_alg/mlpp_matrix.h +++ b/mlpp/lin_alg/mlpp_matrix.h @@ -1,6 +1,8 @@ #ifndef MLPP_MATRIX_H #define MLPP_MATRIX_H +#ifndef GDNATIVE + #include "core/math/math_defs.h" #include "core/containers/pool_vector.h" @@ -12,6 +14,19 @@ #include "core/object/resource.h" +#else + +#include "core/defs.h" +#include "core/math_funcs.h" +#include "core/pool_arrays.h" +#include "core/containers/vector.h" +#include "core/os/memory.h" + +#include "gen/resource.h" + +#endif + + #include "mlpp_vector.h" class Image; diff --git a/mlpp/lin_alg/mlpp_tensor3.h b/mlpp/lin_alg/mlpp_tensor3.h index de59064..da4371b 100644 --- a/mlpp/lin_alg/mlpp_tensor3.h +++ b/mlpp/lin_alg/mlpp_tensor3.h @@ -1,6 +1,8 @@ #ifndef MLPP_TENSOR3_H #define MLPP_TENSOR3_H +#ifndef GDNATIVE + #include "core/math/math_defs.h" #include "core/containers/pool_vector.h" @@ -12,6 +14,18 @@ #include "core/object/resource.h" +#else + +#include "core/defs.h" +#include "core/math_funcs.h" +#include "core/pool_arrays.h" +#include "core/containers/vector.h" +#include "core/os/memory.h" + +#include "gen/resource.h" + +#endif + #include "mlpp_matrix.h" #include "mlpp_vector.h" diff --git a/mlpp/lin_alg/mlpp_vector.h b/mlpp/lin_alg/mlpp_vector.h index 9619e66..c1258cb 100644 --- a/mlpp/lin_alg/mlpp_vector.h +++ b/mlpp/lin_alg/mlpp_vector.h @@ -1,6 +1,8 @@ #ifndef MLPP_VECTOR_H #define MLPP_VECTOR_H +#ifndef GDNATIVE + #include "core/math/math_defs.h" #include "core/math/math_funcs.h" @@ -12,6 +14,18 @@ #include "core/object/resource.h" +#else + +#include "core/defs.h" +#include "core/math_funcs.h" +#include "core/pool_arrays.h" +#include "core/containers/vector.h" +#include "core/os/memory.h" + +#include "gen/resource.h" + +#endif + //REMOVE #include diff --git a/src/gdexample.cpp b/src/gdexample.cpp new file mode 100644 index 0000000..77bd982 --- /dev/null +++ b/src/gdexample.cpp @@ -0,0 +1,51 @@ +#include "gdexample.h" + +void GDExample::_register_methods() { + register_method("_process", &GDExample::_process); + register_property("amplitude", &GDExample::amplitude, 10.0); + register_property("speed", &GDExample::set_speed, &GDExample::get_speed, 1.0); + + //register_signal((char *)"position_changed", "node", PANDEMONIUM_VARIANT_TYPE_OBJECT, "new_pos", PANDEMONIUM_VARIANT_TYPE_VECTOR2); + register_signal("position_changed"); +} + +GDExample::GDExample() { +} + +GDExample::~GDExample() { + // add your cleanup here +} + +void GDExample::_init() { + // initialize any variables here + time_passed = 0.0; + amplitude = 10.0; + speed = 1.0; +} + +void GDExample::_process(float delta) { + time_passed += speed * delta; + + Vector2 pos = get_position(); + + Vector2 new_position = Vector2( + amplitude * sin(time_passed * speed), + amplitude * cos(time_passed * speed)); + + set_position(new_position); + + time_emit += delta; + if (time_emit > 1.0) { + emit_signal("position_changed"); + + time_emit = 0.0; + } +} + +void GDExample::set_speed(float p_speed) { + speed = p_speed; +} + +float GDExample::get_speed() { + return speed; +} diff --git a/src/gdexample.h b/src/gdexample.h new file mode 100644 index 0000000..9217365 --- /dev/null +++ b/src/gdexample.h @@ -0,0 +1,31 @@ +#ifndef GDEXAMPLE_H +#define GDEXAMPLE_H + +#include "gen/object.h" +#include "gen/sprite.h" + +#include "core/pandemonium.h" + +class GDExample : public Sprite { + PANDEMONIUM_CLASS(GDExample, Sprite) + +private: + float time_passed; + float time_emit; + float amplitude; + float speed; + +public: + static void _register_methods(); + + GDExample(); + ~GDExample(); + + void _init(); // our initializer called by Godot + + void _process(float delta); + void set_speed(float p_speed); + float get_speed(); +}; + +#endif