diff --git a/.gitignore b/.gitignore index ea8c4bf..03d24c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/target +libraylib.a diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4219e8c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "3rdparty/raylib"] + path = 3rdparty/raylib + url = https://github.com/raysan5/raylib +[submodule "3rdparty/raygui"] + path = 3rdparty/raygui + url = https://github.com/raysan5/raygui.git diff --git a/3rdparty/raygui b/3rdparty/raygui new file mode 160000 index 0000000..865bb29 --- /dev/null +++ b/3rdparty/raygui @@ -0,0 +1 @@ +Subproject commit 865bb293764073c01e74314ef647464f1f10fd96 diff --git a/3rdparty/raylib b/3rdparty/raylib new file mode 160000 index 0000000..ca12ef4 --- /dev/null +++ b/3rdparty/raylib @@ -0,0 +1 @@ +Subproject commit ca12ef48e9e9f4eae03b1ca43ec3eb0a78d63dd3 diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index da7da67..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "doggo" -version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index 0eb72ca..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "doggo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..bf46761 --- /dev/null +++ b/build.zig @@ -0,0 +1,49 @@ +const std = @import("std"); +const raylib = @import("./3rdparty/raylib/src/build.zig"); + +pub fn build(b: *std.build.Builder) void { + // Standard target options allows the person running `zig build` to choose + // what target to build for. Here we do not override the defaults, which + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); + + // Standard release options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. + const mode = b.standardReleaseOptions(); + + const exe = b.addExecutable("doggo", "src/main.zig"); + exe.setTarget(target); + + const ray = raylib.addRaylib(b, exe.target); + exe.linkLibrary(ray); + exe.addIncludeDir("3rdparty/raylib/src"); + exe.addIncludeDir("3rdparty/raygui/src"); + exe.addIncludeDir("3rdparty/raygui/examples"); + const raylib_flags = &[_][]const u8{ + "-std=gnu99", + "-DPLATFORM_DESKTOP", + "-DGL_SILENCE_DEPRECATION=199309L", + "-fno-sanitize=undefined", + }; + exe.addCSourceFile("src/raylib.c", raylib_flags); + + exe.setBuildMode(mode); + exe.install(); + + const run_cmd = exe.run(); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); + + const exe_tests = b.addTest("src/main.zig"); + exe_tests.setTarget(target); + exe_tests.setBuildMode(mode); + + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&exe_tests.step); +} diff --git a/flake.lock b/flake.lock index 7112d9a..79a3116 100644 --- a/flake.lock +++ b/flake.lock @@ -1,63 +1,23 @@ { "nodes": { - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1712211755, - "narHash": "sha256-KIJA4OvXFDXEeu7wstFDCxqZEfjaPQIowpzNww48TUw=", - "owner": "nix-community", - "repo": "fenix", - "rev": "39763c6e23a8423af316b85a74bad0cc5bc88d86", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1712163089, - "narHash": "sha256-Um+8kTIrC19vD4/lUCN9/cU9kcOsD1O1m+axJqQPyMM=", + "lastModified": 1651369430, + "narHash": "sha256-d86uUm0s11exU9zLo2K1AwtJQJDKubFpoF0Iw767uT4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "fd281bd6b7d3e32ddfa399853946f782553163b5", + "rev": "b283b64580d1872333a99af2b4cef91bb84580cf", "type": "github" }, "original": { "id": "nixpkgs", - "ref": "nixos-unstable", "type": "indirect" } }, "root": { "inputs": { - "fenix": "fenix", "nixpkgs": "nixpkgs" } - }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1712156296, - "narHash": "sha256-St7ZQrkrr5lmQX9wC1ZJAFxL8W7alswnyZk9d1se3Us=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "8e581ac348e223488622f4d3003cb2bd412bf27e", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index b458c0f..bd43ca3 100644 --- a/flake.nix +++ b/flake.nix @@ -1,32 +1,41 @@ { description = "Doggo flake"; - - inputs = { - fenix = { - url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - nixpkgs.url = "nixpkgs/nixos-unstable"; - }; - outputs = { self, fenix, nixpkgs }: + outputs = { self, nixpkgs }: let pkgs = nixpkgs.legacyPackages.x86_64-linux; + + # godot-alpha = (with pkgs; stdenv.mkDerivation { + # pname = "godot-alpha"; + # version = "4.0.0-a8"; + # src = fetchzip { + # url = "https://downloads.tuxfamily.org/godotengine/4.0/alpha8/Godot_v4.0-alpha8_linux.64.zip"; + # hash = "sha512-qkUpt1reFgVDt5u9zLHYLoJAzC0D/YdtNpQhWLarpTW0e+Vzlqy7kna2plIeddybNsn+tS+QqTmYJExA7aT3zw=="; + # }; + # installPhase = '' + # mkdir -p $out/bin + # mv Godot_v4.0-alpha8_linux.64 $out/bin/godot-v4-alpha + # ''; + # }); in { + devShell.x86_64-linux = with pkgs; - mkShell { - nativeBuildInputs = [ - just - (fenix.packages.x86_64-linux.fromToolchainFile { - dir = ./.; - sha256 = "sha256-3St/9/UKo/6lz2Kfq2VmlzHyufduALpiIKaaKX4Pq0g="; - }) - ]; - - buildInputs = [ - ]; - }; - - formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt; + mkShell { + buildInputs = [ + just + # zig + # godot + # godot-alpha + # + # xorg.libX11 + # xorg.libXcursor + # xorg.libXi + # xorg.libXext + # xorg.libXrandr + # xorg.libXinerama + # libGL + # libGLU + ]; + }; }; } diff --git a/godot-impl/Main.gd b/godot-impl/Main.gd new file mode 100644 index 0000000..fa44d4d --- /dev/null +++ b/godot-impl/Main.gd @@ -0,0 +1,26 @@ +extends Control + + +# Called when the node enters the scene tree for the first time. +func _ready(): + $HTTPRequest.connect("request_completed", self._on_request_completed) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + var bodySize = $HTTPRequest.get_body_size() + var downloadedBytes = $HTTPRequest.get_downloaded_bytes() + + var percent = downloadedBytes * 100 / bodySize + $Label.text = "Progress: %d %%" % percent + pass + +func download_cpp_dap(): + var url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz" + $HTTPRequest.download_file = "user://lldb.tar.xz" + $HTTPRequest.request(url) + + +func _on_request_completed(result, response_code, headers, body): +# TODO: decompress archive +# OS.execute("") + pass diff --git a/godot-impl/Main.tscn b/godot-impl/Main.tscn new file mode 100644 index 0000000..d2c0b76 --- /dev/null +++ b/godot-impl/Main.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=2 format=3 uid="uid://cirquj62osi4v"] + +[ext_resource type="Script" path="res://Main.gd" id="1_6lnje"] + +[node name="Control" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( "1_6lnje" ) + +[node name="Button" type="Button" parent="."] +offset_left = 148.0 +offset_top = 70.0 +offset_right = 296.0 +offset_bottom = 162.0 +text = "Download C++ DAP (lldb)" + +[node name="HTTPRequest" type="HTTPRequest" parent="."] +use_threads = true + +[node name="Label" type="Label" parent="."] +offset_left = 359.0 +offset_top = 90.0 +offset_right = 598.0 +offset_bottom = 136.0 +text = "Progress: 0%" + +[connection signal="pressed" from="Button" to="." method="download_cpp_dap"] diff --git a/godot-impl/icon.png b/godot-impl/icon.png new file mode 100644 index 0000000..836bc8b Binary files /dev/null and b/godot-impl/icon.png differ diff --git a/godot-impl/icon.png.import b/godot-impl/icon.png.import new file mode 100644 index 0000000..f57c70d --- /dev/null +++ b/godot-impl/icon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dda5wstjh822x" +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/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +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 diff --git a/godot-impl/project.godot b/godot-impl/project.godot new file mode 100644 index 0000000..1852a43 --- /dev/null +++ b/godot-impl/project.godot @@ -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="Doggo" +run/main_scene="res://Main.tscn" +config/icon="res://icon.png" +config/features=PackedStringArray("4.0", "Vulkan Clustered") diff --git a/justfile b/justfile index c2d78d2..4867e8c 100644 --- a/justfile +++ b/justfile @@ -1,7 +1,21 @@ -alias b := build -build: - cargo build +godot_project := "./godot-impl/project.godot" +godot_url := "https://downloads.tuxfamily.org/godotengine/4.0/alpha8/Godot_v4.0-alpha8_linux.64.zip" +godot_exe := "Godot_v4.0-alpha8_linux.64" +godot_exe_dir := "~/bin" +godot_path := godot_exe_dir + "/" + godot_exe -alias r := run -run: - cargo run +setup: + #!/usr/bin/env bash + set -euo pipefail + if [ ! -e {{godot_path}} ]; then + curl {{godot_url}} -O + unzip Godot*.zip + mv {{godot_exe}} {{godot_exe_dir}} + rm Godot*.zip + fi + +#run: +# nixGL zig build run + +edit: setup + {{godot_exe}} {{godot_project}} diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 02cb8fc..0000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,3 +0,0 @@ -[toolchain] -channel = "stable" -profile = "default" diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..9b4a4bc --- /dev/null +++ b/src/main.zig @@ -0,0 +1,40 @@ +const std = @import("std"); +const r = @import("raylib.zig"); + +pub fn main() anyerror!void { + r.InitWindow(800, 450, "doggo"); + defer r.CloseWindow(); + + // var selected_filename: [512]u8 = undefined; + var file_dialog_state = r.InitGuiFileDialog(420, 310, r.GetWorkingDirectory(), false); + + while (!r.WindowShouldClose()) { + // Update + if (file_dialog_state.SelectFilePressed) { + std.log.info("{s} / {s}", .{ file_dialog_state.dirPathText, file_dialog_state.fileNameText }); + } + + // Draw + r.BeginDrawing(); + defer r.EndDrawing(); + + r.ClearBackground(r.RAYWHITE); + r.DrawText("Congrats! You created your first window!", 190, 200, 20, r.LIGHTGRAY); + + if (file_dialog_state.fileDialogActive) { + r.GuiLock(); + } + + if (r.GuiButton(r.Rectangle{ .x = 190, .y = 250, .width = 150, .height = 30 }, "Button")) { + std.log.info("Button pressed", .{}); + file_dialog_state.fileDialogActive = true; + } + r.GuiUnlock(); + + r.GuiFileDialog(&file_dialog_state); + } +} + +test "basic test" { + try std.testing.expectEqual(10, 3 + 7); +} diff --git a/src/raylib.c b/src/raylib.c new file mode 100644 index 0000000..0dec298 --- /dev/null +++ b/src/raylib.c @@ -0,0 +1,6 @@ +#define RAYGUI_IMPLEMENTATION +#include +#undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again + +#define GUI_FILE_DIALOG_IMPLEMENTATION +#include diff --git a/src/raylib.zig b/src/raylib.zig new file mode 100644 index 0000000..78660e4 --- /dev/null +++ b/src/raylib.zig @@ -0,0 +1,5 @@ +pub usingnamespace @cImport({ + @cInclude("raylib.h"); + @cInclude("raygui.h"); + @cInclude("custom_file_dialog/gui_file_dialog.h"); +});