Skip to content

Commit

Permalink
Sprite + ortho_2d
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyGaul committed Jul 23, 2024
1 parent 83a737a commit 04a1088
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
Binary file added content/CF_Logo_Pixel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -1030,12 +1030,13 @@ int REF_LuaCFunction(lua_State* L)
}
}

// Pass return value back to Lua.
// Pass return value(s) back to Lua.
if (ret.type->size() > 0) {
ret.type->lua_set(L, ret.v);
return ret.type->flattened_count();
} else {
return 0;
}

return ret.type->size() > 0 ? 1 : 0;
}

// Represents a global constant for binding to Lua.
Expand Down
12 changes: 11 additions & 1 deletion src/main.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
dump_lua_api()

make_app("CF in Lua", 0, 0, 0, 640, 480, APP_OPTIONS_WINDOW_POS_CENTERED, argv0)
make_app("CF in Lua", 0, 0, 0, 640, 480, APP_OPTIONS_WINDOW_POS_CENTERED + APP_OPTIONS_RESIZABLE, argv0)
mount_directory_as("/content", "/")
app_set_icon("CF_Logo_Pixel.png")
load_shaders()

def = b2DefaultWorldDef()
Expand Down Expand Up @@ -155,9 +156,12 @@ end
function main()
set_fixed_timestep(60)
text_effect_register("blue", "blue_text")
local cf_mascot = make_easy_sprite("CF_Logo_Pixel.png")

while app_is_running() do
app_update("on_update")
draw_projection(ortho_2d(0,0,640,480))

draw_push_layer(1)
sprite_update(spr)
draw_sprite(spr)
Expand All @@ -168,10 +172,16 @@ function main()
draw_text(text, 150,0, #text)
end

print(display_bounds(0))

draw_polyline({ -300,200, 0,250, 300,200 }, 5, false)

b2World_Draw(world, debug_draw)

draw_translate(-100,0)
draw_sprite(cf_mascot)
draw_pop()

if DELTA_TIME > 0 then
fps = lerp(1.0 / 10.0, fps, 1.0 / DELTA_TIME)
end
Expand Down
28 changes: 23 additions & 5 deletions src/wrap_cf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ REF_FLAT_FLOATS(v2);
REF_FLAT_FLOATS(CF_M2x2);
REF_FLAT_FLOATS(CF_M3x2);
REF_FLAT_FLOATS(CF_Aabb);
REF_FLAT_FLOATS(CF_Rect);
REF_FLAT_INTS(CF_Rect);
REF_FLAT_FLOATS(CF_Color);
REF_FLAT_FLOATS(CF_Circle);
REF_FLAT_FLOATS(CF_Capsule);
Expand Down Expand Up @@ -96,6 +96,8 @@ REF_FUNCTION(aabb_to_poly_manifold);
REF_FUNCTION(capsule_to_poly_manifold);
REF_FUNCTION(poly_to_poly_manifold);

REF_FUNCTION(ortho_2d);

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

Expand Down Expand Up @@ -263,8 +265,8 @@ REF_FUNCTION(app_get_height);
v2 wrap_app_get_position() { int x, y; app_get_position(&x, &y); return V2((float)x, (float)y); }
REF_FUNCTION_EX(app_get_position, wrap_app_get_position);
REF_FUNCTION(app_set_position);
v2 wrap_app_get_size() { int x, y; app_get_size(&x, &y); return V2((float)x, (float)y); }
REF_FUNCTION(app_set_size);
v2 wrap_app_get_size() { int x, y; app_get_size(&x, &y); return V2((float)x, (float)y); }
REF_FUNCTION_EX(app_get_size, wrap_app_get_size);
REF_FUNCTION(app_get_dpi_scale);
REF_FUNCTION(app_dpi_scaled_was_changed);
Expand All @@ -288,6 +290,11 @@ REF_FUNCTION(app_get_vsync);
REF_FUNCTION(app_init_imgui);
REF_FUNCTION(app_get_canvas);
REF_FUNCTION(app_set_canvas_size);
REF_FUNCTION(app_set_windowed_mode);
REF_FUNCTION(app_set_borderless_fullscreen_mode);
REF_FUNCTION(app_set_fullscreen_mode);
REF_FUNCTION(app_set_title);
REF_FUNCTION(app_set_icon);
CF_PowerState app_get_power_state() { CF_PowerInfo info = app_power_info(); return info.state; }
int app_get_power_seconds_left() { CF_PowerInfo info = app_power_info(); return info.seconds_left; }
int app_get_power_percentage_left() { CF_PowerInfo info = app_power_info(); return info.percentage_left; }
Expand Down Expand Up @@ -996,11 +1003,10 @@ REF_WRAP_MANUAL(wrap_make_demo_sprite);
int wrap_make_sprite(lua_State* L)
{
if (!g_sprite_pool) g_sprite_pool = make_memory_pool(sizeof(CF_Sprite), 1024 * 1024, 8);
char* path;
REF_LuaGet(L, -1, &path);
lua_pop(L, 1);
const char* path = lua_tostring(L, -1);
CF_Sprite* s = (CF_Sprite*)memory_pool_alloc(g_sprite_pool);
*s = make_sprite(path);
lua_pop(L, 1);
REF_LuaSet(L, &s);
return 1;
}
Expand All @@ -1010,8 +1016,20 @@ int wrap_destroy_sprite(lua_State* L)
{
CF_Sprite* s;
REF_LuaGet(L, -1, &s);
assert(s);
lua_pop(L, 1);
memory_pool_free(g_sprite_pool, s);
return 0;
}
REF_WRAP_MANUAL(wrap_destroy_sprite);

int wrap_make_easy_sprite(lua_State* L)
{
if (!g_sprite_pool) g_sprite_pool = make_memory_pool(sizeof(CF_Sprite), 1024 * 1024, 8);
const char* path = lua_tostring(L, -1);
CF_Sprite* s = (CF_Sprite*)memory_pool_alloc(g_sprite_pool);
*s = cf_make_easy_sprite_from_png(path, NULL);
REF_LuaSet(L, &s);
return 1;
}
REF_WRAP_MANUAL(wrap_make_easy_sprite);
2 changes: 0 additions & 2 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Select monitor to spawn upon
Query moniter size
Error reporting missing line numbers sometimes

0 comments on commit 04a1088

Please sign in to comment.