Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Project environment is setup
  • Loading branch information
patrickdown committed Feb 26, 2023
1 parent 57bf756 commit f0d9151
Show file tree
Hide file tree
Showing 42 changed files with 6,294 additions and 88 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Godot 4+ specific ignores
.godot/
build/*
.sconsign*.dblite
.vscode

# Binaries
*.o
*.os
*.so
*.obj
*.bc
*.pyc
*.dblite
*.pdb
*.lib
*.config
*.creator
*.creator.user
*.files
*.includes
*.idb
*.exp


!extension/TiltFiveNDK/lib/*/*
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Patrick H Down

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
135 changes: 47 additions & 88 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,68 @@
# GDExtension-Summator
<div id="badges" align="center">
<a href="https://ko-fi.com/flamelizard">
<img src="https://img.shields.io/badge/Support my work-red?style=for-the-badge&logo=kofi&logoColor=white" alt="Ko-Fi Badge"/>
</a>
<a href="https://twitter.com/patrick_exe">
<img src="https://img.shields.io/badge/Twitter-blue?style=for-the-badge&logo=twitter&logoColor=white" alt="Twitter Badge"/>
</a>
<a href="https://mastodon.gamedev.place/@flamelizard">
<img src="https://img.shields.io/badge/Mastodon-purple?style=for-the-badge&logo=mastodon&logoColor=white" alt="Mastodon Badge"/>
</a>
</div>

This repository is for showcasing the new GDExtension system in Godot 4.
The C++ code is from the [Custom modules example](https://docs.godotengine.org/en/latest/development/cpp/custom_modules_in_cpp.html "Click to get to the docs") of the Godot docs.

----> **Feel free to use this repository as a template for your GDExtensions**

## :tada: Using the extension
After compiling the extension succesfully, you can now use the Summator Class inside Godot
```gdscript
func _ready() -> void:
var s = Summator.new()
s.add(10)
s.add(20)
s.add(30)
print(s.get_total())
# outputs 60 in the console
s.reset()
```
# TiltFiveGodot

## 🔢 Versioning
This repository is being updated regularly to work with the latest beta release of the master (4.0) branch. If you can't compile the extension, please open an issue.
TiltFiveGodot is **GDNative** extension for the Godot engine to connect to the [Tilt Five](https://www.tiltfive.com/)
system. It implements Godot's **ARVRinterface** and has GDNative class called TiltFiveManager for scripts to connect
glasses and handle connection events.

----> **Most Recent Update: Godot 4 RC 4 working**
## Platforms

## ❓ What? How? Why?
If you are not sure what each file in this project does or if you want to know in detail: I wrote a blog post about the purpose of each file on [my Ko-Fi page](https://ko-fi.com/post/GDExtension--Godot-SUPERCHARGED--How-to-get-star-Z8Z4GLUSE).
Currently only Windows 10/11 is supported because that is the only platform supported by Tilt Five. T5 linux support
is supposed to come at some point in the future and support for that platform will revisited when it becomes available.

## Alternative templates
If you want to work with the latest master and godot-cpp version, check out this [GDExtension template by Nathan Franke](https://github.com/nathanfranke/gdextension).
If you are more used to CMake than Scons you can use [this template here by asmalone](https://github.com/asmaloney/GDExtensionTemplate)
## Build

### Prerequisites

## ℹ️ Contributing
If you can't compile the extension, please open an issue with the error log in your terminal and/or the error log in the editor (if you can't run the example scene).
Make sure you have [SCons](https://scons.org/) installed and a C++20 compatible
compiler like Visual C++ 2022.

PRs for improvements are very welcome!
After cloning this repository be sure to get and build the submodules

## ⚙️ Building the extension
```
git submodule init
git submodule update
cd godot-cpp
git submodule init
git submodule update
scons
scons target=release
```

### VSCode Compilation (only applicable if you are using VSCode as your code editor)
For the initial build you can run the vscode task `initial-build-extension`. This compiles both godot-cpp and the extension. For all subsequent builds, you only need to run the task `build-extension`.
### Building the extension

### Manual Compilation
Scons should be run from an environment that has the Microsoft x64 development tools setup.

To compile the extension you need to follow these steps:
> `scons target=[debug | release]` Build the shared library. Result is in `build\bin`
0. Click on the green "Use this template" button to generate the repository for you
> `scons example target=[debug | release]` Copy build products to the `example\addons\tilt-five`
1. Clone the extension recursively from this repository
```bash
# --recursive to automatically load the submodule godot-cpp
# The git adress can be found under the green "Code" dropdown menu
git clone --recursive (--GITHUB ADRESS--)
```
> `scons zip target=[debug | release]` Create a zip archive of `example\addons`
2. Make sure you are on the right commit of the godot-cpp repository
```bash
git status
# this show's you the commit. Make sure that it is released to a similar/the same time as the master branch (especially during the beta)
```
To make sure you have the right commit, here the [link to the pinned updated issue with the commit hashes](https://github.com/godotengine/godot-cpp/issues/874)
Note that currently due to bugs the zip archive is not compatible with godot's import function.

3. Make sure you are in the top level of the repository so `pwd` returns the following
```bash
pwd
.../GDExtensionSummator
```
## Basic usage

4. Go inside the godot-cpp folder
```bash
cd godot-cpp
```
After building the example you should be able to open the Godot project in the example directory
and run the default scene.

5. Compile godot-cpp and generate the bindings (only needed once when starting development or when there is an update of the submodule)
```bash
scons target=template_debug
# OR simpler (the above is the default configuration):
scons
If you want to use the extension in your own project follow these steps.

# For beta 2 and earlier:
scons target=debug generate_bindings=yes
```
1) Copy `example\addons` to your own projects root directory.

6. Go back to the top level of the directory
```bash
cd ..
```
2) From `addons\tilt-five\scenes` load the `t5-scene` and run.

7. Compile the extension
```bash
scons target=template_debug
# OR simpler (the above is the default configuration):
scons
3) From here you should be able to follow documentation for usage of Godot's AR/VR system.

# For beta 2 and earlier:
scons target=debug
```
## Dependencies

- Uses the godot-cpp headers
- Uses the Tilt Five NDK

## TODO

- Better docs and examples

## Acknowledgments

This was written by referring a lot to [GodotVR](https://github.com/GodotVR) code and reading
[Godot's](https://github.com/godotengine/godot) source code.
43 changes: 43 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python
import os
import sys

tilt_five_headers_path = "extension/TiltFiveNDK/include/include"
tilt_five_library_path = "extension/TiltFiveNDK/lib/win64"
tilt_five_library = "TiltFiveNative.dll.if"

VariantDir("build/src","extension/src", duplicate=False)
VariantDir("build/T5Integration","extension/T5Integration", duplicate=False)

env = SConscript("godot-cpp/SConstruct")
env['CXXFLAGS'].remove('/std:c++17')

# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags

# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=["extension/src/","extension/T5Integration/",tilt_five_headers_path])
sources = Glob("build/src/*.cpp")
sources += Glob('build/T5Integration/*.cpp')

env.Append(LIBPATH=[tilt_five_library_path])
env.Append(LIBS=[tilt_five_library, "Opengl32"])

if env['platform'] == "windows":
env.Append(CXXFLAGS=['/std:c++20', '/Zc:__cplusplus'])
library = env.SharedLibrary(
"build/bin/libgdtiltfive{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
source=sources,
)

f1 = env.Command("example/addons/tiltfive/libgdtiltfive{}{}".format(env["suffix"], env["SHLIBSUFFIX"]), library, Copy('$TARGET', '$SOURCE') )
f2 = env.Command("example/addons/tiltfive/TiltFiveNative.dll", "extension/TiltFiveNDK/lib/win64/TiltFiveNative.dll", Copy('$TARGET', '$SOURCE') )

env.Alias('example', [f1, f2])

Default(library)
Binary file added example/addons/tiltfive/TiltFiveNative.dll
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions example/addons/tiltfive/tiltfive.gdextension
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[configuration]

entry_symbol = "tiltfive_library_init"

[libraries]

linux.x86_64.debug = "res://addons/tiltfive/libgdtiltfive.linux.template_debug.x86_64.so"
linux.x86_64.release = "res://addons/tiltfive/libgdtiltfive.linux.template_release.x86_64.so"
linux.debug.arm64 = "res://addons/tiltfive/libgdtiltfive.linux.template_debug.arm64.so"
linux.release.arm64 = "res://addons/tiltfive/libgdtiltfive.linux.template_release.arm64.so"
windows.x86_64.debug = "res://addons/tiltfive/libgdtiltfive.windows.template_debug.x86_64.dll"
windows.x86_64.release = "res://addons/tiltfive/libgdtiltfive.windows.template_release.x86_64.dll"
macos.debug = "res://addons/tiltfive/libgdtiltfive.macos.template_debug.framework"
macos.release = "res://addons/tiltfive/libgdtiltfive.macos.template_release.framework"
Binary file added example/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions example/icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cx1mscuegq1lo"
path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.png"
dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
9 changes: 9 additions & 0 deletions example/main.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends Node


func _ready():
$TiltFiveManager.add(10)
$TiltFiveManager.add(20)
$TiltFiveManager.add(30)
print($TiltFiveManager.get_total())

8 changes: 8 additions & 0 deletions example/main.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://dgm4ah3j8jxke"]

[ext_resource type="Script" path="res://main.gd" id="1_ptcg0"]

[node name="Main" type="Node"]
script = ExtResource("1_ptcg0")

[node name="TiltFiveManager" type="TiltFiveManager" parent="."]
16 changes: 16 additions & 0 deletions example/project.godot
Original file line number Diff line number Diff line change
@@ -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

config_version=5

[application]

config/name="TiltFiveGodot4"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.0")
config/icon="res://icon.png"
Loading

0 comments on commit f0d9151

Please sign in to comment.