Skip to content

Commit

Permalink
Added raycasts/shapecasts to Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyGaul committed Sep 5, 2024
1 parent 7fbbc97 commit 6535679
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
Binary file added content/player.ase
Binary file not shown.
12 changes: 11 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ REF_FUNCTION(dump_lua_api);
// -------------------------------------------------------------------------------------------------
// Main

bool run_from_msvc_for_testing = false;

void mount_directory_as(const char* to_mount, const char* dir)
{
Path path = fs_get_base_directory();
path.normalize();
//path.pop(2); // Pop out of build/debug/
if (run_from_msvc_for_testing) {
path.pop(2); // Pop out of build/debug/
}
path += to_mount;
fs_mount(path.c_str(), dir);
}
Expand Down Expand Up @@ -72,6 +76,12 @@ int main(int argc, char* argv[])
luaL_openlibs(L);
REF_BindLua(L);

if (argc < 2) {
printf("You should supply the path to your `main.lua` file as the first command line parameter.\n");
printf("Now assuming you've run from MSVC's Debug/Release folder for testing CF_Lua development.\n");
run_from_msvc_for_testing = true;
}

const char* path_to_main_lua = argc < 2 ? "../../src/main.lua" : argv[1];
if (luaL_dofile(L, path_to_main_lua)) {
fprintf(stderr, lua_tostring(L, -1));
Expand Down
4 changes: 4 additions & 0 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ end

function main()
mount_directory_as('/content', '/')
print(fs_file_exists("/player.ase"))
local s = fs_read_entire_file_to_memory("/player.ase")
print(s)
make_sprite("player.ase")
app_set_title('Test')
app_set_size(w*sx, h*sy)
app_set_canvas_size(w*sx, h*sy)
Expand Down
35 changes: 35 additions & 0 deletions src/wrap_cf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ REF_FLAT_FLOATS(CF_Ray);
REF_FLAT_FLOATS(CF_Halfspace);
REF_FLAT_FLOATS(CF_SinCos);
REF_FLAT_FLOATS(CF_Transform);
REF_FLAT_FLOATS(CF_ToiResult);

REF_STRUCT(CF_Poly,
REF_MEMBER_ARRAY(verts, count),
Expand Down Expand Up @@ -96,6 +97,40 @@ REF_FUNCTION(poly_to_poly_manifold);

REF_FUNCTION(ortho_2d);

// @TODO Move these into CF?
CF_Raycast cast_ray_to_circle(CF_Ray A, CF_Circle B) { CF_Raycast cast; cast_ray(A, &B, NULL, SHAPE_TYPE_CIRCLE, &cast); return cast; }
CF_Raycast cast_ray_to_aabb(CF_Ray A, CF_Aabb B) { CF_Raycast cast; cast_ray(A, &B, NULL, SHAPE_TYPE_AABB, &cast); return cast; }
CF_Raycast cast_ray_to_capsule(CF_Ray A, CF_Capsule B) { CF_Raycast cast; cast_ray(A, &B, NULL, SHAPE_TYPE_CAPSULE, &cast); return cast; }
CF_Raycast cast_ray_to_poly(CF_Ray A, CF_Poly B) { CF_Raycast cast; cast_ray(A, &B, NULL, SHAPE_TYPE_POLY, &cast); return cast; }
REF_FUNCTION(cast_ray_to_circle);
REF_FUNCTION(cast_ray_to_aabb);
REF_FUNCTION(cast_ray_to_capsule);
REF_FUNCTION(cast_ray_to_poly);
REF_FUNCTION(impact);
REF_FUNCTION(endpoint);

// @TODO Move these into CF?
CF_ToiResult cast_circle_to_circle(CF_Circle A, CF_V2 vA, CF_Circle B, CF_V2 vB, bool use_radius) { return toi(&A, SHAPE_TYPE_CIRCLE, NULL, vA, &B, SHAPE_TYPE_CIRCLE, NULL, vB, (int)use_radius); }
CF_ToiResult cast_circle_to_aabb(CF_Circle A, CF_V2 vA, CF_Aabb B, CF_V2 vB, bool use_radius) { return toi(&A, SHAPE_TYPE_CIRCLE, NULL, vA, &B, SHAPE_TYPE_AABB, NULL, vB, (int)use_radius); }
CF_ToiResult cast_circle_to_capsule(CF_Circle A, CF_V2 vA, CF_Capsule B, CF_V2 vB, bool use_radius) { return toi(&A, SHAPE_TYPE_CIRCLE, NULL, vA, &B, SHAPE_TYPE_CAPSULE, NULL, vB, (int)use_radius); }
CF_ToiResult cast_circle_to_poly(CF_Circle A, CF_V2 vA, CF_Poly B, CF_V2 vB, bool use_radius) { return toi(&A, SHAPE_TYPE_CIRCLE, NULL, vA, &B, SHAPE_TYPE_POLY, NULL, vB, (int)use_radius); }
CF_ToiResult cast_aabb_to_aabb(CF_Aabb A, CF_V2 vA, CF_Aabb B, CF_V2 vB, bool use_radius) { return toi(&A, SHAPE_TYPE_AABB, NULL, vA, &B, SHAPE_TYPE_AABB, NULL, vB, (int)use_radius); }
CF_ToiResult cast_aabb_to_capsule(CF_Aabb A, CF_V2 vA, CF_Capsule B, CF_V2 vB, bool use_radius) { return toi(&A, SHAPE_TYPE_AABB, NULL, vA, &B, SHAPE_TYPE_CAPSULE, NULL, vB, (int)use_radius); }
CF_ToiResult cast_aabb_to_poly(CF_Aabb A, CF_V2 vA, CF_Poly B, CF_V2 vB, bool use_radius) { return toi(&A, SHAPE_TYPE_AABB, NULL, vA, &B, SHAPE_TYPE_POLY, NULL, vB, (int)use_radius); }
CF_ToiResult cast_capsule_to_capsule(CF_Capsule A, CF_V2 vA, CF_Capsule B, CF_V2 vB, bool use_radius) { return toi(&A, SHAPE_TYPE_CAPSULE, NULL, vA, &B, SHAPE_TYPE_CAPSULE, NULL, vB, (int)use_radius); }
CF_ToiResult cast_capsule_to_poly(CF_Capsule A, CF_V2 vA, CF_Poly B, CF_V2 vB, bool use_radius) { return toi(&A, SHAPE_TYPE_CAPSULE, NULL, vA, &B, SHAPE_TYPE_POLY, NULL, vB, (int)use_radius); }
CF_ToiResult cast_poly_to_poly(CF_Poly A, CF_V2 vA, CF_Poly B, CF_V2 vB, bool use_radius) { return toi(&A, SHAPE_TYPE_POLY, NULL, vA, &B, SHAPE_TYPE_POLY, NULL, vB, (int)use_radius); }
REF_FUNCTION(cast_circle_to_circle);
REF_FUNCTION(cast_circle_to_aabb);
REF_FUNCTION(cast_circle_to_capsule);
REF_FUNCTION(cast_circle_to_poly);
REF_FUNCTION(cast_aabb_to_aabb);
REF_FUNCTION(cast_aabb_to_capsule);
REF_FUNCTION(cast_aabb_to_poly);
REF_FUNCTION(cast_capsule_to_capsule);
REF_FUNCTION(cast_capsule_to_poly);
REF_FUNCTION(cast_poly_to_poly);

// -------------------------------------------------------------------------------------------------
// Graphics

Expand Down

0 comments on commit 6535679

Please sign in to comment.