Skip to content

Commit

Permalink
chore: update deps & refactor code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
shiryel committed Jan 17, 2025
1 parent 6ab3964 commit cf70346
Show file tree
Hide file tree
Showing 27 changed files with 183 additions and 440 deletions.
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,c_src,test}/**/*.{ex,exs}"],
inputs: ["{mix,.formatter}.exs", "{config,lib,c_src,examples,test}/**/*.{ex,exs}"],
locals_without_parens: [
# unifex
module: :*,
Expand Down
20 changes: 0 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,3 @@ jobs:

- name: Check Dialyzer
run: mix dialyzer

- name: Check 3D Picking example
run: |
cd examples/3d_picking
mix deps.get
mix compile --warnings-as-errors
mix credo --strict
mix format --check-formatted
mix dialyzer --force-check
cd ../..
- name: Check Scale Rectangle example
run: |
cd examples/scale_rectangle
mix deps.get
mix compile --warnings-as-errors
mix credo --strict
mix format --check-formatted
mix dialyzer --force-check
cd ../..
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Rayex provides Elixir NIF bindings to [Raylib](https://www.raylib.com/)

> NOTE: some of the functions on raylib are not implemented yet, check the [contributing section](#contributing) to help
![](examples/3d_picking.gif)
![](examples/resources/3d_picking.gif)

## Installation

Expand Down
145 changes: 1 addition & 144 deletions c_src/rayex/rayex.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "rayex.h"
#include <raylib.h>
#include "structs.h"

/*
* Payloads let us ignore some structs when binding data from Elixir <-> C
Expand All @@ -23,150 +24,6 @@
return result; \
}

// NOTE: "E_" when converting back to NIF struct

#define VECTOR2(v) ((Vector2){.x = v.x, .y = v.y})
#define E_VECTOR2(v) ((vector2){.x = v.x, .y = v.y})

#define VECTOR3(v) ((Vector3){.x = v.x, .y = v.y, .z = v.z})
#define E_VECTOR3(v) ((vector3){.x = v.x, .y = v.y, .z = v.z})

#define VECTOR4(v) ((Vector4){.x = v.x, .y = v.y, .z = v.z, .w = v.w})
#define E_VECTOR4(v) ((vector4){.x = v.x, .y = v.y, .z = v.z, .w = v.w})

#define QUATERNION(q) ((Quaternion){.x = q.x, .y = q.y, .z = q.z, .w = q.w})
#define E_QUATERNION(q) ((quaternion){.x = q.x, .y = q.y, .z = q.z, .w = q.w})

#define MATRIX(m) \
((Matrix){.m0 = m.m0, \
.m1 = m.m1, \
.m2 = m.m2, \
.m3 = m.m3, \
.m4 = m.m4, \
.m5 = m.m5, \
.m6 = m.m6, \
.m7 = m.m7, \
.m8 = m.m8, \
.m9 = m.m9, \
.m10 = m.m10, \
.m11 = m.m11, \
.m12 = m.m12, \
.m13 = m.m13, \
.m14 = m.m14, \
.m15 = m.m15})
#define E_MATRIX(m) \
((matrix){.m0 = m.m0, \
.m1 = m.m1, \
.m2 = m.m2, \
.m3 = m.m3, \
.m4 = m.m4, \
.m5 = m.m5, \
.m6 = m.m6, \
.m7 = m.m7, \
.m8 = m.m8, \
.m9 = m.m9, \
.m10 = m.m10, \
.m11 = m.m11, \
.m12 = m.m12, \
.m13 = m.m13, \
.m14 = m.m14, \
.m15 = m.m15})

#define COLOR(c) ((Color){.r = c.r, .g = c.g, .b = c.b, .a = c.a})
#define E_COLOR(c) ((color){.r = c.r, .g = c.g, .b = c.b, .a = c.a})

#define RECTANGLE(r) \
((Rectangle){.x = r.x, .y = r.y, .width = r.width, .height = r.height})
#define E_RECTANGLE(r) \
((rectangle){.x = r.x, .y = r.y, .width = r.width, .height = r.height})

// XXX: maybe data will not work because is a (void *) and elixir sends a
// payload
#define IMAGE(i) \
((Image){.data = i.data, \
.width = i.width, \
.height = i.height, \
.mipmaps = i.mipmaps, \
.format = i.format})
#define E_IMAGE(i) \
((image){.data = i.data, \
.width = i.width, \
.height = i.height, \
.mipmaps = i.mipmaps, \
.format = i.format})

#define TEXTURE(t) \
((Texture){.id = t.id, \
.width = t.width, \
.height = t.height, \
.mipmaps = t.mipmaps, \
.format = t.format})
#define E_TEXTURE(t) \
((texture){.id = t.id, \
.width = t.width, \
.height = t.height, \
.mipmaps = t.mipmaps, \
.format = t.format})

#define TEXTURE_2D(t) \
((Texture2D){.id = t.id, \
.width = t.width, \
.height = t.height, \
.mipmaps = t.mipmaps, \
.format = t.format})
#define E_TEXTURE_2D(t) \
((texture_2d){.id = t.id, \
.width = t.width, \
.height = t.height, \
.mipmaps = t.mipmaps, \
.format = t.format})

#define CAMERA3D(c) \
((Camera3D){.position = VECTOR3(c.position), \
.target = VECTOR3(c.target), \
.up = VECTOR3(c.up), \
.fovy = c.fovy, \
.projection = c.projection})
#define E_CAMERA3D(c) \
((camera_3d){.position = E_VECTOR3(c.position), \
.target = E_VECTOR3(c.target), \
.up = E_VECTOR3(c.up), \
.fovy = c.fovy, \
.projection = c.projection})

#define CAMERA2D(c) \
((Camera2D){.offset = VECTOR2(c.offset), \
.target = VECTOR2(c.target), \
.rotation = c.rotation, \
.zoom = c.zoom})
#define E_CAMERA2D(c) \
((camera_2d){.offset = E_VECTOR2(c.offset), \
.target = E_VECTOR2(c.target), \
.rotation = c.rotation, \
.zoom = c.zoom})

#define RAY(v) \
((Ray){.position = VECTOR3(v.position), .direction = VECTOR3(v.direction)})
#define E_RAY(v) \
((ray){.position = E_VECTOR3(v.position), \
.direction = E_VECTOR3(v.direction)})

#define RAY_COLLISION(v) \
((RayCollision){.hit = v.hit, \
.distance = v.distance, \
.point = VECTOR3(v.point), \
.normal = VECTOR3(v.normal)})
#define E_RAY_COLLISION(v) \
((ray_collision){.hit = v.hit, \
.distance = v.distance, \
.point = E_VECTOR3(v.point), \
.normal = E_VECTOR3(v.normal)})

#define BOUNDING_BOX(v) \
((BoundingBox){.min = VECTOR3(v.min), .max = VECTOR3(v.max)})
#define E_BOUNDING_BOX(v) \
((bounding_box){.min = E_VECTOR3(v.min), .max = E_VECTOR3(v.max)})

/********
* CORE *
********/
Expand Down
Loading

0 comments on commit cf70346

Please sign in to comment.