mirror of
https://github.com/godotengine/gdnative-demos.git
synced 2026-01-06 06:09:49 +03:00
Merge pull request #51 from sdtv9507/refactor-cpp-simple
Refactor c++ simple demo
This commit is contained in:
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -7,3 +7,7 @@
|
||||
[submodule "c/instance_binding/godot-headers"]
|
||||
path = c/instance_binding/godot-headers
|
||||
url = https://github.com/godotengine/godot-headers.git
|
||||
[submodule "cpp/simple/godot-cpp"]
|
||||
path = cpp/simple/godot-cpp
|
||||
url = https://github.com/godotengine/godot-cpp.git
|
||||
|
||||
|
||||
@@ -1,40 +1,53 @@
|
||||
#!python
|
||||
import os
|
||||
|
||||
# platform= makes it in line with Godots scons file, keeping p for backwards compatibility
|
||||
platform = ARGUMENTS.get("p", "linux")
|
||||
platform = ARGUMENTS.get("platform", platform)
|
||||
opts = Variables([], ARGUMENTS)
|
||||
|
||||
# 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 = Environment()
|
||||
if platform == "windows":
|
||||
env = Environment(ENV=os.environ)
|
||||
# Gets the standard flags CC, CCX, etc.
|
||||
env = DefaultEnvironment()
|
||||
|
||||
godot_headers_path = ARGUMENTS.get("headers", os.getenv("GODOT_HEADERS", "godot-cpp/godot_headers"))
|
||||
godot_bindings_path = ARGUMENTS.get("cpp_bindings", os.getenv("CPP_BINDINGS", "godot-cpp"))
|
||||
godot_headers_path = "godot-cpp/godot-headers"
|
||||
godot_bindings_path = "godot-cpp"
|
||||
|
||||
# default to debug build, must be same setting as used for cpp_bindings
|
||||
target = ARGUMENTS.get("target", "debug")
|
||||
# Define our options. Use future-proofed names for platforms.
|
||||
platform_array = ["", "windows", "linuxbsd", "macos", "x11", "linux", "osx"]
|
||||
opts.Add(EnumVariable("target", "Compilation target", "debug", ["d", "debug", "r", "release"]))
|
||||
opts.Add(EnumVariable("platform", "Compilation platform", "", platform_array))
|
||||
opts.Add(EnumVariable("p", "Alias for 'platform'", "", platform_array))
|
||||
opts.Add(BoolVariable("use_llvm", "Use the LLVM / Clang compiler", "no"))
|
||||
opts.Add(PathVariable("target_path", "The path where the lib is installed.", "project/gdnative/"))
|
||||
opts.Add(PathVariable("target_name", "The library name.", "libsimple", PathVariable.PathAccept))
|
||||
|
||||
opts.Update(env)
|
||||
|
||||
if ARGUMENTS.get("use_llvm", "no") == "yes":
|
||||
env["CXX"] = "clang++"
|
||||
|
||||
# put stuff that is the same for all first, saves duplication
|
||||
if platform == "osx":
|
||||
env.Append(CCFLAGS=["-g", "-O3", "-std=c++14", "-arch", "x86_64"])
|
||||
env.Append(LINKFLAGS=["-arch", "x86_64", "-framework", "Cocoa", "-Wl,-undefined,dynamic_lookup"])
|
||||
elif platform == "linux":
|
||||
env.Append(CCFLAGS=["-g", "-O3", "-std=c++14", "-Wno-writable-strings"])
|
||||
env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
|
||||
elif platform == "windows":
|
||||
# need to add detection of msvc vs mingw, this is for msvc...
|
||||
env.Append(LINKFLAGS=["/WX"])
|
||||
if target == "debug":
|
||||
env.Append(CCFLAGS=["-EHsc", "-D_DEBUG", "/MDd"])
|
||||
if env["platform"] == "osx":
|
||||
if env["target"] in ("debug", "d"):
|
||||
env.Append(CCFLAGS=["-g", "-O2", "-arch", "x86_64"])
|
||||
env.Append(LINKFLAGS=["-arch", "x86_64"])
|
||||
else:
|
||||
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "/MD"])
|
||||
env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64"])
|
||||
env.Append(LINKFLAGS=["-arch", "x86_64"])
|
||||
elif env["platform"] == "linux":
|
||||
if env["target"] in ("debug", "d"):
|
||||
env.Append(CCFLAGS=["-fPIC", "-g3", "-Og"])
|
||||
else:
|
||||
env.Append(CCFLAGS=["-fPIC", "-g", "-O3"])
|
||||
elif env["platform"] == "windows":
|
||||
# This makes sure to keep the session environment variables
|
||||
# on Windows, so that you can run scons in a VS 2017 prompt
|
||||
# and it will find all the required tools.
|
||||
env = Environment(ENV=os.environ)
|
||||
opts.Update(env)
|
||||
|
||||
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"])
|
||||
|
||||
|
||||
def add_sources(sources, dir):
|
||||
@@ -52,15 +65,22 @@ env.Append(
|
||||
]
|
||||
)
|
||||
|
||||
if target == "debug":
|
||||
env.Append(LIBS=["libgodot-cpp.linux.debug.64"])
|
||||
else:
|
||||
env.Append(LIBS=["libgodot-cpp.linux.release.64"])
|
||||
env.Append(
|
||||
LIBS=[
|
||||
env.File(
|
||||
os.path.join(
|
||||
"godot-cpp/bin", "libgodot-cpp.%s.%s.64%s" % (env["platform"], env["target"], env["LIBSUFFIX"])
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
env.Append(LIBPATH=[godot_bindings_path + "/bin/"])
|
||||
|
||||
sources = []
|
||||
add_sources(sources, "src")
|
||||
|
||||
library = env.SharedLibrary(target="bin/libsimple", source=sources)
|
||||
library = env.SharedLibrary(
|
||||
target=env["target_path"] + "/" + env["platform"] + "/" + env["target_name"], source=sources
|
||||
)
|
||||
Default(library)
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
radiance_size = 4
|
||||
sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 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.101961, 0.145098, 0.188235, 1 )
|
||||
ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 )
|
||||
ground_curve = 0.01
|
||||
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 = 2
|
||||
|
||||
[resource]
|
||||
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
background_sky_custom_fov = 0.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 = 1.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_ao_channel_affect = 0.0
|
||||
ssao_color = Color( 0, 0, 0, 1 )
|
||||
ssao_quality = 0
|
||||
ssao_blur = 3
|
||||
ssao_edge_sharpness = 4.0
|
||||
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_threshold = 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
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://main.gd" type="Script" id=1]
|
||||
[ext_resource path="res://icon.png" type="Texture" id=2]
|
||||
[ext_resource path="res://bin/simple.gdnlib" type="GDNativeLibrary" id=3]
|
||||
|
||||
[sub_resource type="NativeScript" id=1]
|
||||
|
||||
resource_name = "SimpleSprite"
|
||||
class_name = "SimpleSprite"
|
||||
library = ExtResource( 3 )
|
||||
|
||||
[node name="Node" type="Node"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 333.0
|
||||
margin_top = 208.0
|
||||
margin_right = 682.0
|
||||
margin_bottom = 325.0
|
||||
rect_pivot_offset = Vector2( 0, 0 )
|
||||
rect_clip_content = false
|
||||
focus_mode = 2
|
||||
mouse_filter = 0
|
||||
mouse_default_cursor_shape = 0
|
||||
size_flags_horizontal = 1
|
||||
size_flags_vertical = 1
|
||||
toggle_mode = false
|
||||
enabled_focus_mode = 2
|
||||
shortcut = null
|
||||
group = null
|
||||
text = "Press me"
|
||||
flat = false
|
||||
align = 1
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 348.0
|
||||
margin_top = 360.0
|
||||
margin_right = 662.0
|
||||
margin_bottom = 374.0
|
||||
rect_pivot_offset = Vector2( 0, 0 )
|
||||
rect_clip_content = false
|
||||
mouse_filter = 2
|
||||
mouse_default_cursor_shape = 0
|
||||
size_flags_horizontal = 1
|
||||
size_flags_vertical = 4
|
||||
align = 1
|
||||
percent_visible = 1.0
|
||||
lines_skipped = 0
|
||||
max_lines_visible = -1
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 2 )
|
||||
script = SubResource( 1 )
|
||||
|
||||
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
|
||||
18
cpp/simple/project/default_env.tres
Normal file
18
cpp/simple/project/default_env.tres
Normal file
@@ -0,0 +1,18 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
radiance_size = 4
|
||||
sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 )
|
||||
sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 )
|
||||
sky_curve = 0.25
|
||||
ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 )
|
||||
ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 )
|
||||
ground_curve = 0.01
|
||||
sun_energy = 16.0
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
fog_height_min = 0.0
|
||||
fog_height_max = 100.0
|
||||
ssao_quality = 0
|
||||
@@ -1,14 +1,14 @@
|
||||
[entry]
|
||||
|
||||
X11.64="res://bin/libsimple.so"
|
||||
|
||||
[dependencies]
|
||||
|
||||
X11.64=[ ]
|
||||
|
||||
[general]
|
||||
|
||||
singleton=false
|
||||
load_once=true
|
||||
symbol_prefix="godot_"
|
||||
reloadable=true
|
||||
|
||||
[entry]
|
||||
|
||||
Windows.64="res://gdnative/windows/libsimple.dll"
|
||||
|
||||
[dependencies]
|
||||
|
||||
Windows.64=[ ]
|
||||
@@ -1,6 +1,6 @@
|
||||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://bin/simple.gdnlib" type="GDNativeLibrary" id=1]
|
||||
[ext_resource path="res://gdnative/simple.gdnlib" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
|
||||
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
@@ -3,6 +3,9 @@
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends Node
|
||||
|
||||
const Simple = preload("res://bin/simple.gdns")
|
||||
const Simple = preload("res://gdnative/simple.gdns")
|
||||
|
||||
onready var simple_instance = Simple.new()
|
||||
|
||||
26
cpp/simple/project/main.tscn
Normal file
26
cpp/simple/project/main.tscn
Normal file
@@ -0,0 +1,26 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://main.gd" type="Script" id=1]
|
||||
[ext_resource path="res://icon.png" type="Texture" id=2]
|
||||
|
||||
[node name="Node" type="Node"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
margin_left = 333.0
|
||||
margin_top = 208.0
|
||||
margin_right = 682.0
|
||||
margin_bottom = 325.0
|
||||
text = "Press me"
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
margin_left = 348.0
|
||||
margin_top = 360.0
|
||||
margin_right = 662.0
|
||||
margin_bottom = 374.0
|
||||
align = 1
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
|
||||
@@ -10,7 +10,6 @@ config_version=4
|
||||
|
||||
_global_script_classes=[ ]
|
||||
_global_script_class_icons={
|
||||
|
||||
}
|
||||
|
||||
[application]
|
||||
@@ -21,4 +20,5 @@ config/icon="res://icon.png"
|
||||
|
||||
[rendering]
|
||||
|
||||
quality/driver/fallback_to_gles2=true
|
||||
environment/default_environment="res://default_env.tres"
|
||||
Reference in New Issue
Block a user