[cpp_constructors] added C++ demo

This commit is contained in:
Karroffel
2017-06-19 02:29:21 +02:00
parent 6605c32f9b
commit 9bf4ab6777
8 changed files with 253 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
extends Control
onready var TestClass = preload("res://TestClass.gdn")
func _ready():
var test_object = TestClass.new()
test_object.test_method("Hello World")

View File

@@ -0,0 +1,13 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Main.gd" type="Script" id=1]
[node name="Main" type="Control"]
margin_right = 40.0
margin_bottom = 40.0
rect_clip_content = false
mouse_filter = 0
script = ExtResource( 1 )

View File

@@ -0,0 +1,21 @@
[gd_resource type="GDNativeScript" load_steps=2 format=2]
[sub_resource type="GDNativeLibrary" id=1]
platform/unix = ""
platform/x11 = "res://lib/libtest.so"
platform/server = ""
platform/android = ""
platform/haiku = ""
platform/mac = ""
platform/ios = ""
platform/osx = ""
platform/html5 = ""
platform/windows = ""
platform/uwp = ""
[resource]
library = SubResource( 1 )
script_name = "TestClass"

View File

@@ -0,0 +1,99 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
radiance_size = 1
sky_top_color = Color( 0.301961, 0.403922, 0.909804, 1 )
sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 )
sky_curve = 0.25
sky_energy = 1.0
ground_bottom_color = Color( 0.196078, 0.152941, 0.0980392, 1 )
ground_horizon_color = Color( 0.329412, 0.211765, 0.0627451, 1 )
ground_curve = 0.25
ground_energy = 1.0
sun_color = Color( 1, 1, 1, 1 )
sun_latitude = 35.0
sun_longitude = 0.0
sun_angle_min = 1.0
sun_angle_max = 100.0
sun_curve = 0.05
sun_energy = 16.0
texture_size = 0
[resource]
background_mode = 2
background_sky = SubResource( 1 )
background_sky_scale = 1.0
background_color = Color( 0, 0, 0, 1 )
background_energy = 1.0
background_canvas_max_layer = 0
ambient_light_color = Color( 0, 0, 0, 1 )
ambient_light_energy = 1.0
ambient_light_sky_contribution = 0.0
fog_enabled = false
fog_color = Color( 0.5, 0.6, 0.7, 1 )
fog_sun_color = Color( 1, 0.9, 0.7, 1 )
fog_sun_amount = 0.0
fog_depth_enabled = true
fog_depth_begin = 10.0
fog_depth_curve = 1.0
fog_transmit_enabled = false
fog_transmit_curve = 1.0
fog_height_enabled = false
fog_height_min = 0.0
fog_height_max = 100.0
fog_height_curve = 1.0
tonemap_mode = 0
tonemap_exposure = 1.0
tonemap_white = 1.0
auto_exposure_enabled = false
auto_exposure_scale = 0.4
auto_exposure_min_luma = 0.05
auto_exposure_max_luma = 8.0
auto_exposure_speed = 0.5
ss_reflections_enabled = false
ss_reflections_max_steps = 64
ss_reflections_fade_in = 0.15
ss_reflections_fade_out = 2.0
ss_reflections_depth_tolerance = 0.2
ss_reflections_roughness = true
ssao_enabled = false
ssao_radius = 1.0
ssao_intensity = 1.0
ssao_radius2 = 0.0
ssao_intensity2 = 1.0
ssao_bias = 0.01
ssao_light_affect = 0.0
ssao_color = Color( 0, 0, 0, 1 )
ssao_blur = true
dof_blur_far_enabled = false
dof_blur_far_distance = 10.0
dof_blur_far_transition = 5.0
dof_blur_far_amount = 0.1
dof_blur_far_quality = 1
dof_blur_near_enabled = false
dof_blur_near_distance = 2.0
dof_blur_near_transition = 1.0
dof_blur_near_amount = 0.1
dof_blur_near_quality = 1
glow_enabled = false
glow_levels/1 = false
glow_levels/2 = false
glow_levels/3 = true
glow_levels/4 = false
glow_levels/5 = true
glow_levels/6 = false
glow_levels/7 = false
glow_intensity = 0.8
glow_strength = 1.0
glow_bloom = 0.0
glow_blend_mode = 2
glow_hdr_treshold = 1.0
glow_hdr_scale = 2.0
glow_bicubic_upscale = false
adjustment_enabled = false
adjustment_brightness = 1.0
adjustment_contrast = 1.0
adjustment_saturation = 1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@@ -0,0 +1,16 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
[application]
name="cpp_constructors"
icon="res://icon.png"
[rendering]
viewport/default_environment="res://default_env.tres"

View File

@@ -0,0 +1,36 @@
#!python
import os
env = Environment()
if ARGUMENTS.get("use_llvm", "no") == "yes":
env["CXX"] = "clang++"
platform = ARGUMENTS.get("p", "linux")
def add_sources(sources, dir):
for f in os.listdir(dir):
if f.endswith(".cpp"):
sources.append(dir + "/" + f)
if platform == "linux":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-Wno-writable-strings'])
env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\''])
env.Append(CPPPATH=['/usr/include/godot/', '/usr/include/godot/godot_cpp/', '/usr/include/godot/godot_cpp/core'])
env.Append(LIBS=['godot_cpp_core', 'godot_cpp_bindings'])
env.Append(LIBPATH=["../lib"])
if platform == "windows":
env.Append(LIBS=['godot.windows.tools.64'])
sources = ["init.cpp"]
library = env.SharedLibrary(target='../lib/test', source=sources)
Default(library)

View File

@@ -0,0 +1,60 @@
#include <Godot.hpp>
#include <Reference.hpp>
#include <Timer.hpp>
#include <File.hpp>
#include <Ref.hpp>
#include <stdio.h>
using namespace godot;
class TestClass : public GodotScript<Reference> {
GODOT_CLASS(TestClass)
int count;
public:
int test_method(const String s)
{
Godot::print(s);
count++;
Timer *t = new Timer;
t->set_wait_time(13.36 * count);
// sorry, no String::num() yet
char str[128];
snprintf(str, 128, "wait time: %f", t->get_wait_time());
Godot::print(String(str));
delete t;
// test Ref<T>
Ref<File> file = new File;
file->open("res://test.txt", File::WRITE);
file->close();
// ref should free the memory automatically
return count;
}
static void _register_methods()
{
register_method("test_method", &TestClass::test_method);
}
};
GODOT_NATIVE_INIT(godot_native_init_options *options)
{
register_class<TestClass>();
}