commit e05d380be2997ff8ed1a71b727480ce0422931ec Author: Ruslan Mustakov Date: Tue Aug 1 22:46:14 2017 +0700 Initial version diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f449553 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/.import +/_dlls +/nakefile +/_godotapi +nimcache +.nimcache diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..59eae73 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "editor.tabSize": 2, + "editor.rulers": [80], + "editor.insertSpaces": true, + "editor.detectIndentation": false, + "files.eol": "\n", + "files.trimTrailingWhitespace": true, + "nim.buildOnSave": false, + "nim.lintOnSave": true, + "nim.project": ["src/stub.nim"], + "files.exclude": { + "**/.nimcache/**": true + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..cd1a033 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +Stub project to demonstrate usage of the [godot-nim](https://github.com/pragmagic/godot-nim) library. + +Prerequisites: + +1. Install [nake](https://github.com/fowlmouth/nake): `nimble install nake -n`. +2. Ensure `~/.nimble/bin` is in your PATH (On Windows: `C:\Users\\.nimble\bin`). +3. Set `GODOT_BIN` environment varible to point to Godot executable (requires Godot 3.0 changeset [d28e9c3](https://github.com/godotengine/godot/commit/d28e9c3c0813e729195357dbb9ccd337494bc6d7) or newer). +4. Install godot-nim: `nimble install godot` +5. (Windows only) Set `GODOT_LIB` environment variable to point to Godot's .lib file. It should be in the `bin` folder after you build Godot. + +Run `nake build` in any directory within the project to compile for the current platform. diff --git a/default_env.tres b/default_env.tres new file mode 100644 index 0000000..a22ed59 --- /dev/null +++ b/default_env.tres @@ -0,0 +1,99 @@ +[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_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_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 + diff --git a/fonts/Roboto/RobotoRegular.tres b/fonts/Roboto/RobotoRegular.tres new file mode 100644 index 0000000..a1126e5 --- /dev/null +++ b/fonts/Roboto/RobotoRegular.tres @@ -0,0 +1,5 @@ +[gd_resource type="DynamicFontData" format=2] + +[resource] + +font_path = "res://fonts/Roboto/ttf/Roboto-Regular.ttf" diff --git a/fonts/Roboto/ttf/LICENSE.txt b/fonts/Roboto/ttf/LICENSE.txt new file mode 100755 index 0000000..75b5248 --- /dev/null +++ b/fonts/Roboto/ttf/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/fonts/Roboto/ttf/Roboto-Regular.ttf b/fonts/Roboto/ttf/Roboto-Regular.ttf new file mode 100755 index 0000000..2c97eea Binary files /dev/null and b/fonts/Roboto/ttf/Roboto-Regular.ttf differ diff --git a/fps_counter.tscn b/fps_counter.tscn new file mode 100644 index 0000000..67fc001 --- /dev/null +++ b/fps_counter.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://fonts/Roboto/RobotoRegular.tres" type="DynamicFontData" id=1] +[ext_resource path="res://scripts/FPSCounter.gdns" type="Script" id=2] + +[sub_resource type="DynamicFont" id=1] + +size = 40 +use_mipmaps = false +use_filter = false +font_data = ExtResource( 1 ) +_sections_unfolded = [ "Extra Spacing", "Font", "Settings" ] + +[node name="Label" type="Label"] + +anchor_left = 1 +anchor_right = 1 +margin_top = 10.0 +margin_right = 10.0 +grow_horizontal = 0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 2 +size_flags_horizontal = 1 +size_flags_vertical = 4 +custom_fonts/font = SubResource( 1 ) +text = "FPS: 9000" +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 +script = ExtResource( 2 ) +_sections_unfolded = [ "Anchor", "Grow Direction", "Margin", "custom_colors", "custom_fonts" ] + + diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..21a097a Binary files /dev/null and b/icon.png differ diff --git a/icon.png.import b/icon.png.import new file mode 100644 index 0000000..627820b --- /dev/null +++ b/icon.png.import @@ -0,0 +1,23 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +stream=false +size_limit=0 +detect_3d=true diff --git a/main.tscn b/main.tscn new file mode 100644 index 0000000..7e4e390 --- /dev/null +++ b/main.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://scripts/MainPanel.gdns" type="Script" id=1] +[ext_resource path="res://fonts/Roboto/RobotoRegular.tres" type="DynamicFontData" id=2] +[ext_resource path="res://fps_counter.tscn" type="PackedScene" id=3] + +[sub_resource type="DynamicFont" id=1] + +size = 80 +use_mipmaps = false +use_filter = false +font_data = ExtResource( 2 ) +_sections_unfolded = [ "Font", "Settings" ] + +[node name="Panel" type="Panel"] + +anchor_right = 1 +anchor_bottom = 1 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 +script = ExtResource( 1 ) +_sections_unfolded = [ "Anchor", "Margin" ] + +[node name="Label" type="Label" parent="."] + +anchor_right = 1 +anchor_bottom = 1 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 2 +size_flags_horizontal = 1 +size_flags_vertical = 4 +custom_fonts/font = SubResource( 1 ) +text = "Click me to load scene" +align = 1 +valign = 1 +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 +_sections_unfolded = [ "Anchor", "Margin", "custom_fonts" ] + +[node name="FPS" parent="." instance=ExtResource( 3 )] + +margin_left = 189.0 +margin_bottom = 58.0 + + diff --git a/nakefile.nim b/nakefile.nim new file mode 100644 index 0000000..93b6c64 --- /dev/null +++ b/nakefile.nim @@ -0,0 +1,38 @@ +# Copyright 2017 Xored Software, Inc. + +import nake +import os, ospaths, times +import godotapigen + +proc genGodotApi() = + let godotBin = getEnv("GODOT_BIN") + if godotBin.isNil or godotBin.len == 0: + echo "GODOT_BIN environment variable is not set" + quit(-1) + if not fileExists(godotBin): + echo "Invalid GODOT_BIN path: " & godotBin + quit(-1) + + const targetDir = "_godotapi" + createDir(targetDir) + const jsonFile = targetDir/"api.json" + if not fileExists(jsonFile) or + godotBin.getLastModificationTime() > jsonFile.getLastModificationTime(): + direShell(godotBin, "--gdnative-generate-json-api", jsonFile) + if not fileExists(jsonFile): + echo "Failed to generate api.json" + quit(-1) + + genApi(targetDir, jsonFile) + +task "build", "Builds the client for the current platform": + genGodotApi() + withDir "src": + direShell("nimble", "make") + +task "clean", "Remove files produced by build": + removeDir(".nimcache") + removeDir("src"/".nimcache") + removeDir("_godotapi") + removeDir("_dlls") + removeFile("nakefile") diff --git a/nakefile.nim.cfg b/nakefile.nim.cfg new file mode 100644 index 0000000..ea0483d --- /dev/null +++ b/nakefile.nim.cfg @@ -0,0 +1 @@ +nimcache=".nimcache" \ No newline at end of file diff --git a/nimlib.tres b/nimlib.tres new file mode 100644 index 0000000..f95a4f3 --- /dev/null +++ b/nimlib.tres @@ -0,0 +1,12 @@ +[gd_resource type="GDNativeLibrary" format=2] + +[resource] + +platform/X11_32bit = "res://_dlls/nim_linux_32.so" +platform/X11_64bit = "res://_dlls/nim_linux_64.so" +platform/Windows_32bit = "res://_dlls/nim_32.dll" +platform/Windows_64bit = "res://_dlls/nim_64.dll" +platform/OSX = "res://_dlls/nim_mac.dylib" +platform/Android = "res://_dlls/nim_android.so" +platform/iOS = "res://_dlls/nim_ios.dylib" +platform/WebAssembly = "" diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..658204c --- /dev/null +++ b/project.godot @@ -0,0 +1,14 @@ +config_version=3 +[application] + +config/name="Godot-Nim Stub" +run/main_scene="res://main.tscn" +config/icon="res://icon.png" + +[autoload] + +NimRuntime="*res://scripts/NimRuntime.gdns" + +[rendering] + +environment/default_environment="res://default_env.tres" diff --git a/scene.tscn b/scene.tscn new file mode 100644 index 0000000..07b4429 --- /dev/null +++ b/scene.tscn @@ -0,0 +1,48 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://fps_counter.tscn" type="PackedScene" id=1] + +[sub_resource type="CapsuleMesh" id=1] + +radius = 1.0 +mid_height = 1.0 +radial_segments = 64 +rings = 8 + +[node name="Node" type="Node"] + +[node name="MeshInstance" type="MeshInstance" parent="."] + +layers = 1 +material_override = null +cast_shadow = 1 +extra_cull_margin = 0.0 +visible_in_all_rooms = false +use_in_baked_light = false +lod_min_distance = 0.0 +lod_min_hysteresis = 0.0 +lod_max_distance = 0.0 +lod_max_hysteresis = 0.0 +mesh = SubResource( 1 ) +skeleton = NodePath("..") +material/0 = null +_sections_unfolded = [ "Geometry", "material" ] + +[node name="Label" parent="." instance=ExtResource( 1 )] + +[node name="Camera" type="Camera" parent="."] + +transform = Transform( 0.930689, 0.16529, -0.326338, 0, 0.892097, 0.451845, 0.365811, -0.420527, 0.830265, -0.972205, 1.19673, 2.59579 ) +projection = 0 +fov = 65.0 +near = 0.1 +far = 100.0 +keep_aspect = 1 +current = true +cull_mask = 1048575 +environment = null +h_offset = 0.0 +v_offset = 0.0 +doppler/tracking = 0 + + diff --git a/scripts/FPSCounter.gdns b/scripts/FPSCounter.gdns new file mode 100644 index 0000000..bae69db --- /dev/null +++ b/scripts/FPSCounter.gdns @@ -0,0 +1,9 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://nimlib.tres" type="GDNativeLibrary" id=1] + +[resource] + +resource_name = "FPSCounter" +library = ExtResource( 1 ) +class_name = "FPSCounter" \ No newline at end of file diff --git a/scripts/MainPanel.gdns b/scripts/MainPanel.gdns new file mode 100644 index 0000000..4458a47 --- /dev/null +++ b/scripts/MainPanel.gdns @@ -0,0 +1,9 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://nimlib.tres" type="GDNativeLibrary" id=1] + +[resource] + +resource_name = "MainPanel" +library = ExtResource( 1 ) +class_name = "MainPanel" \ No newline at end of file diff --git a/scripts/NimRuntime.gdns b/scripts/NimRuntime.gdns new file mode 100644 index 0000000..34656e9 --- /dev/null +++ b/scripts/NimRuntime.gdns @@ -0,0 +1,9 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://nimlib.tres" type="GDNativeLibrary" id=1] + +[resource] + +resource_name = "NimRuntime" +library = ExtResource( 1 ) +class_name = "NimRuntime" \ No newline at end of file diff --git a/src/config.nims b/src/config.nims new file mode 100644 index 0000000..0e164e3 --- /dev/null +++ b/src/config.nims @@ -0,0 +1,43 @@ +import ospaths + +switch("nimcache", ".nimcache"/hostOS/hostCPU) + +when defined(macosx): + switch("passL", "-framework Cocoa -Wl,-undefined,dynamic_lookup") +elif defined(android): + let ndk = getEnv("ANDROID_NDK_ROOT") + let toolchain = getEnv("ANDROID_TOOLCHAIN") + + if ndk.len == 0: + raise newException(OSError, + "ANDROID_NDK_ROOT environment variable is necessary for android build") + if toolchain.len == 0: + raise newException(OSError, + "ANDROID_TOOLCHAIN environment variable is necessary for android build") + + const level = $16 # change this to the necessary API level + const arch = "arm" + let sysroot = "--sysroot=\"" & ndk & "/platforms/android-" & level & "/arch-" & arch & "/\"" + switch("passL", sysroot) + switch("passC", sysroot) + + switch("cc", "clang") + switch("arm.linux.clang.path", toolchain / "bin") + switch("arm.linux.clang.exe", arch & "-linux-androideabi-clang") + switch("arm.linux.clang.compilerexe", arch & "-linux-androideabi-clang") + switch("arm.linux.clang.linkerexe", arch & "-linux-androideabi-clang") +elif defined(windows): + assert(sizeof(int) == 8) + switch("cc", "vcc") + let godotLib = getEnv("GODOT_LIB") + if godotLib.len == 0: + raise newException(OSError, + "GODOT_LIB must be specified and point to the .lib file") + switch("clib", godotLib.changeFileExt("")) +elif defined(linux): + switch("passC", "-fPIC") +else: + raise newException(OSError, "Unsupported platform: " & hostOS) + +when not defined(release): + switch("debugger", "native") diff --git a/src/fpscounter.nim b/src/fpscounter.nim new file mode 100644 index 0000000..01be84f --- /dev/null +++ b/src/fpscounter.nim @@ -0,0 +1,17 @@ +# Copyright 2017 Xored Software, Inc. + +import strutils +import godot +import engine, label + +gdobj FPSCounter of Label: + var lastFPS: float32 + + method ready*() = + setProcess(true) + + method process*(delta: float64) = + let fps = getFramesPerSecond() + if int(fps * 10) != int(lastFPS * 10): + lastFPS = fps + self.text = "FPS: " & formatFloat(fps, ffDecimal, 1) diff --git a/src/mainpanel.nim b/src/mainpanel.nim new file mode 100644 index 0000000..8f6c16e --- /dev/null +++ b/src/mainpanel.nim @@ -0,0 +1,18 @@ +# Copyright 2017 Xored Software, Inc. + +import godot +import scene_tree, resource_loader, packed_scene, panel, global_constants, + input_event_mouse_button + +gdobj MainPanel of Panel: + method ready*() = + setProcessInput(true) + + method input*(event: InputEvent) = + if event of InputEventMouseButton: + let ev = event as InputEventMouseButton + if ev.buttonIndex == BUTTON_LEFT: + getTree().setInputAsHandled() + let scene = load("res://scene.tscn") as PackedScene + getTree().getRoot().addChild(scene.instance()) + queueFree() diff --git a/src/nim.cfg b/src/nim.cfg new file mode 100644 index 0000000..02e75de --- /dev/null +++ b/src/nim.cfg @@ -0,0 +1,6 @@ +--path:"$projectdir" +--path:"$projectdir/../_godotapi" +--app:lib +-d:useRealtimeGc +--noMain +--warning[LockLevel]:off \ No newline at end of file diff --git a/src/stub.nim b/src/stub.nim new file mode 100644 index 0000000..5e725b8 --- /dev/null +++ b/src/stub.nim @@ -0,0 +1,12 @@ +# Copyright 2017 Xored Software, Inc. + +## Import independent scene objects here +## (no need to import everything, just independent roots) + +when not defined(release): + import segfaults # converts segfaults into NilAccessError + +import nimruntime + +import fpscounter +import mainpanel diff --git a/src/stub.nimble b/src/stub.nimble new file mode 100644 index 0000000..b36bf97 --- /dev/null +++ b/src/stub.nimble @@ -0,0 +1,34 @@ +version = "0.1.0" +author = "Xored Software, Inc." +description = "Godot-Nim Project Stub" +license = "MIT" +bin = @["stub"] + +requires "godot >= 0.3.0 & < 0.4.0" + +task make, "build": + const bitsPostfix = when sizeof(int) == 8: "_64" else: "_32" + const libFile = + when defined(windows): + "nim" & bitsPostfix & ".dll" + elif defined(ios): + "nim_ios.dylib" + elif defined(macosx): + "nim_mac.dylib" + elif defined(android): + "nim_android.so" + elif defined(linux): + "nim_linux" & bitsPostfix & ".so" + else: nil + if libFile.isNil: + raise newException(OSError, "Unsupported platform") + + exec "nimble build -y" + const dir = "../_dlls/" + const target = dir & libFile + mkDir(dir) + when defined(windows): + rmFile(target) + mvFile(bin[0] & ".exe", target) + else: + mvFile(bin[0], target)