diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fa1e688..5569269 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,13 +23,16 @@ jobs: with: path: _build/ key: ${{runner.os}}-${{hashFiles('mix.lock')}}-build - - - name: Get deps - if: steps.cache-deps.outputs.cache-hit != 'true' - run: | + + - name: Arch install deps + run: | pacman --noconfirm -Sy elixir raylib git clang pkg-config mix local.rebar --force mix local.hex --force + + - name: Get deps + if: steps.cache-deps.outputs.cache-hit != 'true' + run: | mix deps.get - name: Compile diff --git a/README.md b/README.md index ec6bef5..693951a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Rayex +[![Hex.pm](https://img.shields.io/hexpm/v/rayex.svg)](https://hex.pm/packages/rayex) +[![API Docs](https://img.shields.io/badge/api-docs-blue.svg?style=flat)](https://hexdocs.pm/rayex/) +[![Run Tests](https://github.com/shiryel/rayex/actions/workflows/test.yml/badge.svg)](https://github.com/shiryel/rayex/actions/workflows/test.yml) + +[![Twitter](https://img.shields.io/twitter/follow/shiryel_.svg?style=social)](https://twitter.com/shiryel_) + Rayex provides Elixir NIF bindings to [Raylib](https://www.raylib.com/) > WIP: many of the functions on raylib are yet not implemented, check the [contributing section](#contributing) to help @@ -13,7 +19,7 @@ The package can be installed by adding `rayex` to your list of dependencies in ` ```elixir def deps do [ - {:rayex, "~> 0.0.1"} + {:rayex, "~> 0.0.2"} ] end ``` diff --git a/examples/3d_picking/Makefile b/examples/3d_picking/Makefile new file mode 100644 index 0000000..da940ed --- /dev/null +++ b/examples/3d_picking/Makefile @@ -0,0 +1,8 @@ +.PHONY: test +test: + mix compile --warnings-as-errors + mix test + mix format + mix format --check-formatted + mix credo --strict + mix dialyzer diff --git a/examples/3d_picking/lib/the3d_picking.ex b/examples/3d_picking/lib/the3d_picking.ex index 75f4c01..ef32c00 100644 --- a/examples/3d_picking/lib/the3d_picking.ex +++ b/examples/3d_picking/lib/the3d_picking.ex @@ -7,35 +7,33 @@ defmodule The3dPicking do use Rayex - @cube_position %{x: 0.0, y: 1.0, z: 0.0} + @cube_position %S.Vector3{x: 0.0, y: 1.0, z: 0.0} @mouse_left 0 - @color_white %{r: 245, g: 245, b: 245, a: 255} - @color_darkgray %{r: 80, g: 80, b: 80, a: 255} - @color_gray %{r: 130, g: 130, b: 130, a: 255} - @color_red %{r: 230, g: 41, b: 55, a: 255} - @color_maroon %{r: 190, g: 33, b: 55, a: 255} - @color_green %{r: 0, g: 228, b: 48, a: 255} + @color_white %S.Color{r: 245, g: 245, b: 245, a: 255} + @color_darkgray %S.Color{r: 80, g: 80, b: 80, a: 255} + @color_gray %S.Color{r: 130, g: 130, b: 130, a: 255} + @color_red %S.Color{r: 230, g: 41, b: 55, a: 255} + @color_maroon %S.Color{r: 190, g: 33, b: 55, a: 255} + @color_green %S.Color{r: 0, g: 228, b: 48, a: 255} def run do init_window(800, 450, "raylib [core] example - 3d picking") set_target_fps(60) camera = %S.Camera3D{ - position: %{x: 10.0, y: 10.0, z: 10.0}, - target: %{x: 0.0, y: 0.0, z: 0.0}, - up: %{x: 0.0, y: 1.0, z: 0.0}, + position: %S.Vector3{x: 10.0, y: 10.0, z: 10.0}, + target: %S.Vector3{x: 0.0, y: 0.0, z: 0.0}, + up: %S.Vector3{x: 0.0, y: 1.0, z: 0.0}, fovy: 45.0, projection: 0 } - camera_id = set_camera_mode(camera, 1) + set_camera_mode(camera, 1) - game_loop(%{camera: camera, camera_id: camera_id, hit?: false}) + game_loop(%{camera: camera, hit?: false}) end defp game_loop(%{camera: camera, hit?: hit?} = state) do - Logger.debug(inspect(camera)) - ray = get_mouse_position() |> get_mouse_ray(camera) hit? = @@ -87,8 +85,16 @@ defmodule The3dPicking do get_ray_collision_box( ray, %S.BoundingBox{ - min: %{x: @cube_position.x - 1.0, y: @cube_position.y - 1.0, z: @cube_position.z - 1.0}, - max: %{x: @cube_position.x + 1.0, y: @cube_position.y + 1.0, z: @cube_position.z + 1.0} + min: %S.Vector3{ + x: @cube_position.x - 1.0, + y: @cube_position.y - 1.0, + z: @cube_position.z - 1.0 + }, + max: %S.Vector3{ + x: @cube_position.x + 1.0, + y: @cube_position.y + 1.0, + z: @cube_position.z + 1.0 + } } ) diff --git a/examples/3d_picking/mix.exs b/examples/3d_picking/mix.exs index a4c09ce..cdd2f65 100644 --- a/examples/3d_picking/mix.exs +++ b/examples/3d_picking/mix.exs @@ -23,7 +23,11 @@ defmodule The3dPicking.MixProject do [ # {:dep_from_hexpm, "~> 0.3.0"}, # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} - {:rayex, path: "../.."} + {:rayex, path: "../.."}, + # CI + {:credo, "~> 1.5", only: [:dev, :test], runtime: false}, + {:dialyxir, "~> 1.0", only: [:dev], runtime: false}, + {:ex_doc, "~> 0.24", only: :dev, runtime: false} ] end end diff --git a/examples/3d_picking/mix.lock b/examples/3d_picking/mix.lock index 6f9100c..901d515 100644 --- a/examples/3d_picking/mix.lock +++ b/examples/3d_picking/mix.lock @@ -1,8 +1,20 @@ %{ "bunch": {:hex, :bunch, "1.3.0", "51b4423088b7fb9e21eae6d6bc5e5d219d955ea5556fbd6130bfb6213df4be32", [:mix], [], "hexpm", "9ad233a2bacc0dae8aa6553a9b9057f27446443b1c5903c3479b6f9f3820ce2d"}, "bunch_native": {:hex, :bunch_native, "0.4.0", "9214f73b753c7c4201fc0a1145d9720a15e45effa02d9eea8237d98ae53b36e5", [:mix], [{:bundlex, "~> 0.5.0", [hex: :bundlex, repo: "hexpm", optional: false]}], "hexpm", "4bf7e84250614994383870092e883bc8b7e213c3854506b1a03493bd9a6a1ba2"}, - "bundlex": {:git, "https://github.com/shiryel/bundlex", "9557966c0df48999ed1608089a47a0372fabd785", [branch: "master"]}, - "qex": {:hex, :qex, "0.5.0", "5a3a9becf67d4006377c4c247ffdaaa8ae5b3634a0caadb788dc24d6125068f4", [:mix], [], "hexpm", "4ad6f6421163cd8204509a119a5c9813cbb969cfb8d802a9dc49b968bffbac2a"}, + "bundlex": {:hex, :bundlex, "0.5.1", "a164ba822102476db7a11db8bb7e8adca0630bdff448e00e5ba1138e3df27839", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:qex, "~> 0.5", [hex: :qex, repo: "hexpm", optional: false]}, {:secure_random, "~> 0.5", [hex: :secure_random, repo: "hexpm", optional: false]}], "hexpm", "b3348db967dfa880c9e3d311af7e366ab515202429264334baeeaef04fa7a4e2"}, + "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, + "credo": {:hex, :credo, "1.6.1", "7dc76dcdb764a4316c1596804c48eada9fff44bd4b733a91ccbf0c0f368be61e", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "698607fb5993720c7e93d2d8e76f2175bba024de964e160e2f7151ef3ab82ac5"}, + "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.18", "e1b2be73eb08a49fb032a0208bf647380682374a725dfb5b9e510def8397f6f2", [:mix], [], "hexpm", "114a0e85ec3cf9e04b811009e73c206394ffecfcc313e0b346de0d557774ee97"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, + "ex_doc": {:hex, :ex_doc, "0.26.0", "1922164bac0b18b02f84d6f69cab1b93bc3e870e2ad18d5dacb50a9e06b542a3", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2775d66e494a9a48355db7867478ffd997864c61c65a47d31c4949459281c78d"}, + "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, + "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.2.0", "b44d75e2a6542dcb6acf5d71c32c74ca88960421b6874777f79153bbbbd7dccc", [:mix], [], "hexpm", "52b2871a7515a5ac49b00f214e4165a40724cf99798d8e4a65e4fd64ebd002c1"}, + "qex": {:hex, :qex, "0.5.1", "0d82c0f008551d24fffb99d97f8299afcb8ea9cf99582b770bd004ed5af63fd6", [:mix], [], "hexpm", "935a39fdaf2445834b95951456559e9dc2063d0a055742c558a99987b38d6bab"}, "secure_random": {:hex, :secure_random, "0.5.1", "c5532b37c89d175c328f5196a0c2a5680b15ebce3e654da37129a9fe40ebf51b", [:mix], [], "hexpm", "1b9754f15e3940a143baafd19da12293f100044df69ea12db5d72878312ae6ab"}, "shmex": {:hex, :shmex, "0.4.0", "8a074a984bbd45808d80eddfa0f037d7dfb4d4046e6566cd40adf41e13decf74", [:mix], [{:bunch_native, "~> 0.4.0", [hex: :bunch_native, repo: "hexpm", optional: false]}, {:bundlex, "~> 0.5.0", [hex: :bundlex, repo: "hexpm", optional: false]}], "hexpm", "1018c4eca1db5352ed4dec4813e1ee212b98fc851e1edd302906892538bbfaa8"}, "unifex": {:hex, :unifex, "0.7.0", "43b876f19a6f9e1849762d90ac2242698a8318199e4b6b92d18274873c733bec", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:bundlex, "~> 0.5.0", [hex: :bundlex, repo: "hexpm", optional: false]}, {:shmex, "~> 0.4.0", [hex: :shmex, repo: "hexpm", optional: false]}], "hexpm", "dac9366611d82d647df5c604638caac0c26951d62892e19cacff3bf7d37556f8"}, diff --git a/examples/3d_picking/test/the3d_picking_test.exs b/examples/3d_picking/test/the3d_picking_test.exs index 314f389..d405fe6 100644 --- a/examples/3d_picking/test/the3d_picking_test.exs +++ b/examples/3d_picking/test/the3d_picking_test.exs @@ -1,8 +1,4 @@ defmodule The3dPickingTest do use ExUnit.Case doctest The3dPicking - - test "greets the world" do - assert The3dPicking.hello() == :world - end end diff --git a/examples/scale_rectangle/Makefile b/examples/scale_rectangle/Makefile new file mode 100644 index 0000000..da940ed --- /dev/null +++ b/examples/scale_rectangle/Makefile @@ -0,0 +1,8 @@ +.PHONY: test +test: + mix compile --warnings-as-errors + mix test + mix format + mix format --check-formatted + mix credo --strict + mix dialyzer diff --git a/examples/scale_rectangle/lib/scale_rectangle.ex b/examples/scale_rectangle/lib/scale_rectangle.ex index 481d361..5551da4 100644 --- a/examples/scale_rectangle/lib/scale_rectangle.ex +++ b/examples/scale_rectangle/lib/scale_rectangle.ex @@ -3,15 +3,18 @@ defmodule ScaleRectangle do Documentation for `ScaleRectangle`. """ + alias Rayex.Structs, as: S + require Logger + use Rayex @mouse_mark_size 12.0 @mouse_left 0 - @color_white %{r: 245, g: 245, b: 245, a: 255} - @color_gray %{r: 130, g: 130, b: 130, a: 255} - @color_red %{r: 230, g: 41, b: 55, a: 255} - @color_green_a %{r: 0, g: 228, b: 48, a: 126} + @color_white %S.Color{r: 245, g: 245, b: 245, a: 255} + @color_gray %S.Color{r: 130, g: 130, b: 130, a: 255} + @color_red %S.Color{r: 230, g: 41, b: 55, a: 255} + @color_green_a %S.Color{r: 0, g: 228, b: 48, a: 126} def run do init_window(700, 700, "scale rectangle example") @@ -21,11 +24,11 @@ defmodule ScaleRectangle do end defp game_loop( - %{rec: rec, should_scale?: should_scale?} = state \\ %{ - rec: %{x: 100.0, y: 100.0, width: 200.0, height: 80.0}, - should_scale?: false - } - ) do + %{rec: rec, should_scale?: should_scale?} = state \\ %{ + rec: %S.Rectangle{x: 100.0, y: 100.0, width: 200.0, height: 80.0}, + should_scale?: false + } + ) do # # update states # @@ -62,9 +65,9 @@ defmodule ScaleRectangle do draw_rectangle_lines_ex(rec, 1, @color_red) draw_triangle( - %{x: rec.x + rec.width - @mouse_mark_size, y: rec.y + rec.height}, - %{x: rec.x + rec.width, y: rec.y + rec.height}, - %{x: rec.x + rec.width, y: rec.y + rec.height - @mouse_mark_size}, + %S.Vector2{x: rec.x + rec.width - @mouse_mark_size, y: rec.y + rec.height}, + %S.Vector2{x: rec.x + rec.width, y: rec.y + rec.height}, + %S.Vector2{x: rec.x + rec.width, y: rec.y + rec.height - @mouse_mark_size}, @color_red ) end @@ -78,7 +81,7 @@ defmodule ScaleRectangle do end defp mouse_scale_ready?(mouse, rec) do - border_rec = %{ + border_rec = %S.Rectangle{ x: rec.x + rec.width - @mouse_mark_size, y: rec.y + rec.height - @mouse_mark_size, width: @mouse_mark_size, diff --git a/examples/scale_rectangle/mix.exs b/examples/scale_rectangle/mix.exs index 8bf9610..6c71fdb 100644 --- a/examples/scale_rectangle/mix.exs +++ b/examples/scale_rectangle/mix.exs @@ -23,7 +23,11 @@ defmodule ScaleRectangle.MixProject do [ # {:dep_from_hexpm, "~> 0.3.0"}, # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} - {:rayex, path: "../.."} + {:rayex, path: "../.."}, + # CI + {:credo, "~> 1.5", only: [:dev, :test], runtime: false}, + {:dialyxir, "~> 1.0", only: [:dev], runtime: false}, + {:ex_doc, "~> 0.24", only: :dev, runtime: false} ] end end diff --git a/examples/scale_rectangle/mix.lock b/examples/scale_rectangle/mix.lock index 6f9100c..901d515 100644 --- a/examples/scale_rectangle/mix.lock +++ b/examples/scale_rectangle/mix.lock @@ -1,8 +1,20 @@ %{ "bunch": {:hex, :bunch, "1.3.0", "51b4423088b7fb9e21eae6d6bc5e5d219d955ea5556fbd6130bfb6213df4be32", [:mix], [], "hexpm", "9ad233a2bacc0dae8aa6553a9b9057f27446443b1c5903c3479b6f9f3820ce2d"}, "bunch_native": {:hex, :bunch_native, "0.4.0", "9214f73b753c7c4201fc0a1145d9720a15e45effa02d9eea8237d98ae53b36e5", [:mix], [{:bundlex, "~> 0.5.0", [hex: :bundlex, repo: "hexpm", optional: false]}], "hexpm", "4bf7e84250614994383870092e883bc8b7e213c3854506b1a03493bd9a6a1ba2"}, - "bundlex": {:git, "https://github.com/shiryel/bundlex", "9557966c0df48999ed1608089a47a0372fabd785", [branch: "master"]}, - "qex": {:hex, :qex, "0.5.0", "5a3a9becf67d4006377c4c247ffdaaa8ae5b3634a0caadb788dc24d6125068f4", [:mix], [], "hexpm", "4ad6f6421163cd8204509a119a5c9813cbb969cfb8d802a9dc49b968bffbac2a"}, + "bundlex": {:hex, :bundlex, "0.5.1", "a164ba822102476db7a11db8bb7e8adca0630bdff448e00e5ba1138e3df27839", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:qex, "~> 0.5", [hex: :qex, repo: "hexpm", optional: false]}, {:secure_random, "~> 0.5", [hex: :secure_random, repo: "hexpm", optional: false]}], "hexpm", "b3348db967dfa880c9e3d311af7e366ab515202429264334baeeaef04fa7a4e2"}, + "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, + "credo": {:hex, :credo, "1.6.1", "7dc76dcdb764a4316c1596804c48eada9fff44bd4b733a91ccbf0c0f368be61e", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "698607fb5993720c7e93d2d8e76f2175bba024de964e160e2f7151ef3ab82ac5"}, + "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.18", "e1b2be73eb08a49fb032a0208bf647380682374a725dfb5b9e510def8397f6f2", [:mix], [], "hexpm", "114a0e85ec3cf9e04b811009e73c206394ffecfcc313e0b346de0d557774ee97"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, + "ex_doc": {:hex, :ex_doc, "0.26.0", "1922164bac0b18b02f84d6f69cab1b93bc3e870e2ad18d5dacb50a9e06b542a3", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2775d66e494a9a48355db7867478ffd997864c61c65a47d31c4949459281c78d"}, + "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, + "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.2.0", "b44d75e2a6542dcb6acf5d71c32c74ca88960421b6874777f79153bbbbd7dccc", [:mix], [], "hexpm", "52b2871a7515a5ac49b00f214e4165a40724cf99798d8e4a65e4fd64ebd002c1"}, + "qex": {:hex, :qex, "0.5.1", "0d82c0f008551d24fffb99d97f8299afcb8ea9cf99582b770bd004ed5af63fd6", [:mix], [], "hexpm", "935a39fdaf2445834b95951456559e9dc2063d0a055742c558a99987b38d6bab"}, "secure_random": {:hex, :secure_random, "0.5.1", "c5532b37c89d175c328f5196a0c2a5680b15ebce3e654da37129a9fe40ebf51b", [:mix], [], "hexpm", "1b9754f15e3940a143baafd19da12293f100044df69ea12db5d72878312ae6ab"}, "shmex": {:hex, :shmex, "0.4.0", "8a074a984bbd45808d80eddfa0f037d7dfb4d4046e6566cd40adf41e13decf74", [:mix], [{:bunch_native, "~> 0.4.0", [hex: :bunch_native, repo: "hexpm", optional: false]}, {:bundlex, "~> 0.5.0", [hex: :bundlex, repo: "hexpm", optional: false]}], "hexpm", "1018c4eca1db5352ed4dec4813e1ee212b98fc851e1edd302906892538bbfaa8"}, "unifex": {:hex, :unifex, "0.7.0", "43b876f19a6f9e1849762d90ac2242698a8318199e4b6b92d18274873c733bec", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:bundlex, "~> 0.5.0", [hex: :bundlex, repo: "hexpm", optional: false]}, {:shmex, "~> 0.4.0", [hex: :shmex, repo: "hexpm", optional: false]}], "hexpm", "dac9366611d82d647df5c604638caac0c26951d62892e19cacff3bf7d37556f8"}, diff --git a/examples/scale_rectangle/test/scale_rectangle_test.exs b/examples/scale_rectangle/test/scale_rectangle_test.exs index e805e2d..79ab325 100644 --- a/examples/scale_rectangle/test/scale_rectangle_test.exs +++ b/examples/scale_rectangle/test/scale_rectangle_test.exs @@ -1,8 +1,4 @@ defmodule ScaleRectangleTest do use ExUnit.Case doctest ScaleRectangle - - test "greets the world" do - assert ScaleRectangle.hello() == :world - end end diff --git a/lib/rayex/core.ex b/lib/rayex/core.ex index f6f7e25..bb5c62d 100644 --- a/lib/rayex/core.ex +++ b/lib/rayex/core.ex @@ -13,7 +13,7 @@ defmodule Rayex.Core do defdelegate init_window(width, height, title), to: Raylib @doc "Check if KEY_ESCAPE pressed or Close icon pressed" - @spec window_should_close() :: :ok + @spec window_should_close() :: boolean() defdelegate window_should_close, to: Raylib @doc "Close window and unload OpenGL context" @@ -49,15 +49,15 @@ defmodule Rayex.Core do defdelegate window_resized?, to: Raylib, as: :is_window_resized @doc "Check if one specific window flag is enabled" - @spec window_state?(pos_integer()) :: boolean() + @spec window_state?(non_neg_integer()) :: boolean() defdelegate window_state?(flag), to: Raylib, as: :is_window_state @doc "Set window configuration state using flags" - @spec set_window_state(pos_integer()) :: :ok + @spec set_window_state(non_neg_integer()) :: :ok defdelegate set_window_state(flag), to: Raylib @doc "Clear window configuration state flags" - @spec clear_window_state(pos_integer()) :: :ok + @spec clear_window_state(non_neg_integer()) :: :ok defdelegate clear_window_state(flag), to: Raylib @doc "Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP)" @@ -87,7 +87,7 @@ defmodule Rayex.Core do # Screen-space-related functions @doc "Get a ray trace from mouse position" - @spec get_mouse_ray(S.Vector2.t(), S.Color.t()) :: S.Ray.t() + @spec get_mouse_ray(S.Vector2.t(), S.Camera3D.t()) :: S.Ray.t() defdelegate get_mouse_ray(mouse_position, camera), to: Raylib @doc "Begin 2D mode with custom camera (2D)" @@ -109,11 +109,11 @@ defmodule Rayex.Core do # Timing-related functions @doc "Set target FPS (maximum)" - @spec set_target_fps(pos_integer()) :: :ok + @spec set_target_fps(non_neg_integer()) :: :ok defdelegate set_target_fps(fps), to: Raylib @doc "Get current FPS" - @spec get_fps() :: pos_integer() + @spec get_fps() :: non_neg_integer() defdelegate get_fps, to: Raylib @doc "Get time in seconds for last frame drawn (delta time)" diff --git a/lib/rayex/models.ex b/lib/rayex/models.ex index a3b3a5a..b5b2502 100644 --- a/lib/rayex/models.ex +++ b/lib/rayex/models.ex @@ -21,7 +21,7 @@ defmodule Rayex.Models do defdelegate draw_ray(ray, color), to: Raylib @doc "Draw a grid (centered at (0, 0, 0))" - @spec draw_grid(pos_integer(), integer()) :: :ok + @spec draw_grid(non_neg_integer(), float()) :: :ok defdelegate draw_grid(slices, spacing), to: Raylib # Model loading/unloading functions diff --git a/lib/rayex/shapes.ex b/lib/rayex/shapes.ex index 6ff540c..b099bce 100644 --- a/lib/rayex/shapes.ex +++ b/lib/rayex/shapes.ex @@ -39,10 +39,10 @@ defmodule Rayex.Shapes do # Basic shapes collision detection functions @doc "Check if point is inside rectangle" - @spec check_collision_point_rec(S.Vector2.t(), S.Rectangle.t()) :: :ok + @spec check_collision_point_rec(S.Vector2.t(), S.Rectangle.t()) :: boolean() defdelegate check_collision_point_rec(point, rectangle), to: Raylib @doc "Get collision info between ray and box" - @spec check_collision_point_rec(S.Ray.t(), S.BoundingBox.t()) :: S.RayCollision.t() + @spec get_ray_collision_box(S.Ray.t(), S.BoundingBox.t()) :: S.RayCollision.t() defdelegate get_ray_collision_box(ray, bounding_box), to: Raylib end diff --git a/lib/rayex/structs.ex b/lib/rayex/structs.ex index 212d019..08657fb 100644 --- a/lib/rayex/structs.ex +++ b/lib/rayex/structs.ex @@ -64,7 +64,12 @@ defmodule Rayex.Structs.Color do @enforce_keys ~w[r g b a]a defstruct ~w[r g b a]a - @type t :: %__MODULE__{r: pos_integer, g: pos_integer, b: pos_integer, a: pos_integer} + @type t :: %__MODULE__{ + r: non_neg_integer(), + g: non_neg_integer(), + b: non_neg_integer(), + a: non_neg_integer() + } end defmodule Rayex.Structs.Rectangle do @@ -97,7 +102,7 @@ defmodule Rayex.Structs.Texture2D do defstruct ~w[id width height mipmaps format]a @type t :: %__MODULE__{ - id: pos_integer(), + id: non_neg_integer(), width: float(), height: float(), mipmaps: integer(), @@ -112,7 +117,7 @@ defmodule Rayex.Structs.TextureCubemap do defstruct ~w[id width height mipmaps format]a @type t :: %__MODULE__{ - id: pos_integer(), + id: non_neg_integer(), width: float(), height: float(), mipmaps: integer(), @@ -126,7 +131,7 @@ defmodule Rayex.Structs.RenderTexture do defstruct ~w[id texture depth]a @type t :: %__MODULE__{ - id: pos_integer, + id: non_neg_integer(), texture: Rayex.Structs.Texture2D.t(), depth: Rayex.Structs.Texture2D.t() } @@ -139,7 +144,7 @@ defmodule Rayex.Structs.RenderTexture2D do defstruct ~w[id texture depth]a @type t :: %__MODULE__{ - id: pos_integer(), + id: non_neg_integer(), texture: Rayex.Structs.Texture2D.t(), depth: Rayex.Structs.Texture2D.t() } @@ -235,18 +240,18 @@ defmodule Rayex.Structs.Mesh do texcoords2: [float], normals: [float], tangents: [float], - colors: [pos_integer], - indices: [pos_integer], + colors: [non_neg_integer()], + indices: [non_neg_integer()], # Animation vertex data anim_vertices: [float], anim_normals: [float], - bone_ids: [pos_integer], + bone_ids: [non_neg_integer()], bone_weights: [float], # OpenGL identifiers - vao_id: [pos_integer], - vbo_id: [pos_integer] + vao_id: [non_neg_integer()], + vbo_id: [non_neg_integer()] } end @@ -256,7 +261,7 @@ defmodule Rayex.Structs.Shader do defstruct ~w[id locs]a @type t :: %__MODULE__{ - id: pos_integer(), + id: non_neg_integer(), locs: [integer()] } end @@ -381,10 +386,10 @@ defmodule Rayex.Structs.Wave do defstruct ~w[frame_count sample_rate sample_size channels data]a @type t :: %__MODULE__{ - frame_count: pos_integer(), - sample_rate: pos_integer(), - sample_size: pos_integer(), - channels: pos_integer(), + frame_count: non_neg_integer(), + sample_rate: non_neg_integer(), + sample_size: non_neg_integer(), + channels: non_neg_integer(), data: binary() } end @@ -405,9 +410,9 @@ defmodule Rayex.Structs.AudioStream do @type t :: %__MODULE__{ buffer: [Rayex.Structs.RAudioBuffer.t()], - sample_rate: pos_integer(), - sample_size: pos_integer(), - channels: pos_integer() + sample_rate: non_neg_integer(), + sample_size: non_neg_integer(), + channels: non_neg_integer() } end @@ -418,7 +423,7 @@ defmodule Rayex.Structs.Sound do @type t :: %__MODULE__{ stream: Rayex.Structs.AudioStream.t(), - frame_count: pos_integer() + frame_count: non_neg_integer() } end @@ -429,7 +434,7 @@ defmodule Rayex.Structs.Music do @type t :: %__MODULE__{ stream: Rayex.Structs.AudioStream.t(), - frame_count: pos_integer(), + frame_count: non_neg_integer(), looping: boolean(), ctx_type: integer(), ctx_data: binary() diff --git a/mix.exs b/mix.exs index d6547d4..806aeb0 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Rayex.MixProject do def project do [ app: :rayex, - version: "0.0.1", + version: "0.0.2", elixir: "~> 1.12", start_permanent: Mix.env() == :prod, compilers: [:unifex, :bundlex] ++ Mix.compilers(), @@ -38,7 +38,7 @@ defmodule Rayex.MixProject do {:ex_doc, "~> 0.24", only: :dev, runtime: false}, # Deps {:unifex, "~> 0.7.0"}, - {:bundlex, git: "https://github.com/shiryel/bundlex", branch: "master", override: true} + {:bundlex, "~> 0.5.1"} ] end diff --git a/mix.lock b/mix.lock index e97fa5e..901d515 100644 --- a/mix.lock +++ b/mix.lock @@ -1,20 +1,20 @@ %{ "bunch": {:hex, :bunch, "1.3.0", "51b4423088b7fb9e21eae6d6bc5e5d219d955ea5556fbd6130bfb6213df4be32", [:mix], [], "hexpm", "9ad233a2bacc0dae8aa6553a9b9057f27446443b1c5903c3479b6f9f3820ce2d"}, "bunch_native": {:hex, :bunch_native, "0.4.0", "9214f73b753c7c4201fc0a1145d9720a15e45effa02d9eea8237d98ae53b36e5", [:mix], [{:bundlex, "~> 0.5.0", [hex: :bundlex, repo: "hexpm", optional: false]}], "hexpm", "4bf7e84250614994383870092e883bc8b7e213c3854506b1a03493bd9a6a1ba2"}, - "bundlex": {:git, "https://github.com/shiryel/bundlex", "9557966c0df48999ed1608089a47a0372fabd785", [branch: "master"]}, + "bundlex": {:hex, :bundlex, "0.5.1", "a164ba822102476db7a11db8bb7e8adca0630bdff448e00e5ba1138e3df27839", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:qex, "~> 0.5", [hex: :qex, repo: "hexpm", optional: false]}, {:secure_random, "~> 0.5", [hex: :secure_random, repo: "hexpm", optional: false]}], "hexpm", "b3348db967dfa880c9e3d311af7e366ab515202429264334baeeaef04fa7a4e2"}, "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, - "credo": {:hex, :credo, "1.5.6", "e04cc0fdc236fefbb578e0c04bd01a471081616e741d386909e527ac146016c6", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4b52a3e558bd64e30de62a648518a5ea2b6e3e5d2b164ef5296244753fc7eb17"}, + "credo": {:hex, :credo, "1.6.1", "7dc76dcdb764a4316c1596804c48eada9fff44bd4b733a91ccbf0c0f368be61e", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "698607fb5993720c7e93d2d8e76f2175bba024de964e160e2f7151ef3ab82ac5"}, "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.16", "607709303e1d4e3e02f1444df0c821529af1c03b8578dfc81bb9cf64553d02b9", [:mix], [], "hexpm", "69fcf696168f5a274dd012e3e305027010658b2d1630cef68421d6baaeaccead"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.18", "e1b2be73eb08a49fb032a0208bf647380682374a725dfb5b9e510def8397f6f2", [:mix], [], "hexpm", "114a0e85ec3cf9e04b811009e73c206394ffecfcc313e0b346de0d557774ee97"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, - "ex_doc": {:hex, :ex_doc, "0.25.5", "ac3c5425a80b4b7c4dfecdf51fa9c23a44877124dd8ca34ee45ff608b1c6deb9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "688cfa538cdc146bc4291607764a7f1fcfa4cce8009ecd62de03b27197528350"}, + "ex_doc": {:hex, :ex_doc, "0.26.0", "1922164bac0b18b02f84d6f69cab1b93bc3e870e2ad18d5dacb50a9e06b542a3", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2775d66e494a9a48355db7867478ffd997864c61c65a47d31c4949459281c78d"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, "makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, - "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, - "qex": {:hex, :qex, "0.5.0", "5a3a9becf67d4006377c4c247ffdaaa8ae5b3634a0caadb788dc24d6125068f4", [:mix], [], "hexpm", "4ad6f6421163cd8204509a119a5c9813cbb969cfb8d802a9dc49b968bffbac2a"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.2.0", "b44d75e2a6542dcb6acf5d71c32c74ca88960421b6874777f79153bbbbd7dccc", [:mix], [], "hexpm", "52b2871a7515a5ac49b00f214e4165a40724cf99798d8e4a65e4fd64ebd002c1"}, + "qex": {:hex, :qex, "0.5.1", "0d82c0f008551d24fffb99d97f8299afcb8ea9cf99582b770bd004ed5af63fd6", [:mix], [], "hexpm", "935a39fdaf2445834b95951456559e9dc2063d0a055742c558a99987b38d6bab"}, "secure_random": {:hex, :secure_random, "0.5.1", "c5532b37c89d175c328f5196a0c2a5680b15ebce3e654da37129a9fe40ebf51b", [:mix], [], "hexpm", "1b9754f15e3940a143baafd19da12293f100044df69ea12db5d72878312ae6ab"}, "shmex": {:hex, :shmex, "0.4.0", "8a074a984bbd45808d80eddfa0f037d7dfb4d4046e6566cd40adf41e13decf74", [:mix], [{:bunch_native, "~> 0.4.0", [hex: :bunch_native, repo: "hexpm", optional: false]}, {:bundlex, "~> 0.5.0", [hex: :bundlex, repo: "hexpm", optional: false]}], "hexpm", "1018c4eca1db5352ed4dec4813e1ee212b98fc851e1edd302906892538bbfaa8"}, "unifex": {:hex, :unifex, "0.7.0", "43b876f19a6f9e1849762d90ac2242698a8318199e4b6b92d18274873c733bec", [:mix], [{:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, {:bundlex, "~> 0.5.0", [hex: :bundlex, repo: "hexpm", optional: false]}, {:shmex, "~> 0.4.0", [hex: :shmex, repo: "hexpm", optional: false]}], "hexpm", "dac9366611d82d647df5c604638caac0c26951d62892e19cacff3bf7d37556f8"},