вторник, 10 сентября 2024 г.

Godot Extension (GDExtension) with Swift language

 

 

 

 

 

 

 

 

 

 

 

Swift 5.10.1 Windows toolchain. (www.swift.org)

1. Run:
>>swift package init
(In folder "C:\my_GD_Extensions\myShip")

Edit file: Package.swift

// swift-tools-version: 5.10
import PackageDescription

let package = Package(
    name: "myShip",
    products: [
        .library(
            name: "myShip",
            type: .dynamic,
            targets: ["myShip"]),
    ],
    dependencies: [
        .package(url: "https://github.com/migueldeicaza/SwiftGodot", branch: "main")
    ],
    targets: [
        .target(
            name: "myShip",
            dependencies: [
                "SwiftGodot",
            ]
        ),
        .testTarget(
            name: "myShipTests",
            dependencies: ["myShip"]
        ),
    ]
)

2. Run and wait):
>>swift build

Edit file: C:\my_GD_Extensions\myShip\Sources\myShip.swift

import SwiftGodot
#initSwiftExtension(cdecl: "swift_entry_point", types: [ShipController.self])

Edit file: C:\my_GD_Extensions\myShip\Sources\ShipController.swift

import SwiftGodot
@Godot(.tool)
class ShipController: Node3D {
    public override func _ready () {
        let meshRender = MeshInstance3D()
        meshRender.mesh = BoxMesh()
        addChild(node: meshRender)
    }

    public override func _process(delta: Double) {
        rotateY(angle: delta * 5)
    }
}

3. Compile and copy files to Godot project
>>swift build

Make file: res://bin/myShip.gdextensions:

[configuration]
entry_symbol = "swift_entry_point"
compatibility_minimum = 4.2

[icons]
ShipController = "res://bin/my_extension.svg"

[libraries]
windows.debug.x86_64 = "res://bin/myShip.dll"

[dependencies]
windows.debug.x86_64 = "res://bin/SwiftGodot.dll"

Attention!

Copy files from "C:\Swift\Runtimes\5.10.1\usr\bin"
to folder with your extension ("res://bin")
(and copy to game Export folder).

понедельник, 9 сентября 2024 г.

Compilation SwiftGodot on Windows

Swift 5.10.1 Windows toolchain. (www.swift.org)
Download SwiftGodot (v0.45)

Run compilation
(in folder "C:\SwiftGodot-0.45")

- for DEBUG
>> swift build
(C:\SwiftGodot-0.45\.build\debug\SwiftGodot.dll)
(Copy to "res://bin/SwiftGodot_debug.x86_64.dll")

- for RELEASE
>> swift build -c release
(C:\SwiftGodot-0.45\.build\release\SwiftGodot.dll)
(Copy to "res://bin/SwiftGodot_release.x86_64.dll")

Edit file: my_extension.gdextension

[configuration]
entry_symbol = "swift_entry_point"
compatibility_minimum = 4.2
compatibility_maximum = 4.3
reloadable = true

[icons]
MyExtension = "res://bin/my_extension.svg"

[libraries]
windows.debug.x86_64 = "res://bin/my_extension_debug.x86_64.dll"
windows.release.x86_64 = "res://bin/my_extension_release.x86_64.dll"

[dependencies]
windows.debug = {
    "res://bin/SwiftGodot_debug.x86_64.dll" : "",
}

windows.release = {
    "res://bin/SwiftGodot_release.x86_64.dll" : "",
}

Attention!

Copy files from "C:\Swift\Runtimes\5.10.1\usr\bin"
to folder with your extension ("res://bin")
(and put them in [dependencies] section or copy to game Export folder).

воскресенье, 8 сентября 2024 г.

Debugging Swift in VSCode on Windows

Swift 5.10.1 Windows toolchain. (www.swift.org)

Environment Variable: SDKROOT "C:\Swift5\Platforms\5.10.1\Windows.platform\Developer\SDKs\Windows.sdk\"

Debugging in VSCode maybe needs:
    - CodeLLDB Extension
   
- Swift Extension with Setting: Swift › Debugger: Use Debug Adapter From Toolchain - "C:/Swift/Toolchains/5.10.1+Asserts/usr/bin/lldb-vscode.exe"
    - Python 3.9 installed.