mirror of
https://github.com/Relintai/gdnative_cpp_sample.git
synced 2024-11-20 11:17:18 +01:00
Set up test project.
This commit is contained in:
parent
d42daba6b9
commit
48563b2b19
93
cpp/SConstruct
Normal file
93
cpp/SConstruct
Normal file
@ -0,0 +1,93 @@
|
||||
#!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 = "libgodot-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 + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
|
||||
env.Append(LIBPATH=[cpp_bindings_path + 'bin/'])
|
||||
env.Append(LIBS=[cpp_library])
|
||||
|
||||
# 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')
|
||||
|
||||
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))
|
54
cpp/src/gdexample.cpp
Normal file
54
cpp/src/gdexample.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include "gdexample.h"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void GDExample::_register_methods() {
|
||||
register_method("_process", &GDExample::_process);
|
||||
register_property<GDExample, float>("amplitude", &GDExample::amplitude, 10.0);
|
||||
register_property<GDExample, float>("speed", &GDExample::set_speed, &GDExample::get_speed, 1.0);
|
||||
|
||||
//register_signal<GDExample>((char *)"position_changed", "node", PANDEMONIUM_VARIANT_TYPE_OBJECT, "new_pos", PANDEMONIUM_VARIANT_TYPE_VECTOR2);
|
||||
register_signal<GDExample>("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;
|
||||
}
|
33
cpp/src/gdexample.h
Normal file
33
cpp/src/gdexample.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef GDEXAMPLE_H
|
||||
#define GDEXAMPLE_H
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <Sprite.hpp>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class GDExample : public Sprite {
|
||||
GODOT_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
|
BIN
cpp/src/gdexample.os
Normal file
BIN
cpp/src/gdexample.os
Normal file
Binary file not shown.
15
cpp/src/gdlibrary.cpp
Normal file
15
cpp/src/gdlibrary.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "gdexample.h"
|
||||
|
||||
extern "C" void GDN_EXPORT pandemonium_gdnative_init(pandemonium_gdnative_init_options *o) {
|
||||
godot::Godot::gdnative_init(o);
|
||||
}
|
||||
|
||||
extern "C" void GDN_EXPORT pandemonium_gdnative_terminate(pandemonium_gdnative_terminate_options *o) {
|
||||
godot::Godot::gdnative_terminate(o);
|
||||
}
|
||||
|
||||
extern "C" void GDN_EXPORT pandemonium_nativescript_init(void *handle) {
|
||||
godot::Godot::nativescript_init(handle);
|
||||
|
||||
godot::register_class<godot::GDExample>();
|
||||
}
|
BIN
cpp/src/gdlibrary.os
Normal file
BIN
cpp/src/gdlibrary.os
Normal file
Binary file not shown.
@ -1,3 +1,19 @@
|
||||
[gd_scene format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://gdn/gdexample.gdns" type="Script" id=1]
|
||||
[ext_resource path="res://icon.png" type="Texture" id=2]
|
||||
[ext_resource path="res://Node2D.gd" type="Script" id=3]
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
|
||||
[node name="Node2D" type="Node2D" parent="."]
|
||||
position = Vector2( 392, 232 )
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="Node2D"]
|
||||
texture = ExtResource( 2 )
|
||||
script = ExtResource( 1 )
|
||||
amplitude = 150.0
|
||||
speed = 4.0
|
||||
|
||||
[connection signal="position_changed" from="Node2D/Sprite" to="Node2D" method="_on_Sprite_position_changed"]
|
||||
|
21
game/Node2D.gd
Normal file
21
game/Node2D.gd
Normal file
@ -0,0 +1,21 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a: int = 2
|
||||
# var b: String = "text"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta: float) -> void:
|
||||
# pass
|
||||
|
||||
|
||||
func _on_Sprite_position_changed() -> void:
|
||||
# print("!")
|
||||
pass
|
7
game/gdn/gdexample.gdns
Normal file
7
game/gdn/gdexample.gdns
Normal file
@ -0,0 +1,7 @@
|
||||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://gdn/tgdn.tres" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
class_name = "GDExample"
|
||||
library = ExtResource( 1 )
|
5
game/gdn/tgdn.tres
Normal file
5
game/gdn/tgdn.tres
Normal file
@ -0,0 +1,5 @@
|
||||
[gd_resource type="GDNativeLibrary" format=2]
|
||||
|
||||
[resource]
|
||||
entry/X11.64 = "res://gdn/x11/libgdexample.so"
|
||||
dependency/X11.64 = [ ]
|
@ -11,6 +11,7 @@ config_version=4
|
||||
[application]
|
||||
|
||||
config/name="Sample"
|
||||
run/main_scene="res://Main.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[physics]
|
||||
|
Loading…
Reference in New Issue
Block a user