Skip to content

Commit

Permalink
Sync to latest CF, support pointing to main.lua from cmd line
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyGaul committed Sep 4, 2024
1 parent a02d909 commit a976d8e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
Binary file added content/hit_effect_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ int main(int argc, char* argv[])
luaL_openlibs(L);
REF_BindLua(L);

if (luaL_dofile(L, "../../src/main.lua")) {
//if (luaL_dofile(L, "main.lua")) {
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));
return -1;
}
Expand Down
43 changes: 38 additions & 5 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ function rectangle(x, y, w, h, rs, color, line_width)
if color then draw_pop_color() end
end

function draw_image(canvas, image, x, y, r, sx, sy, color)
-- "Simplest" fix, but rather innefficient.
function draw_image_inefficient(canvas, image, x, y, r, sx, sy, color)
if color then
render_to(canvas, false)
render_settings_push_shader(shader)
draw_push_vertex_attributes(color.r, color.g, color.b, color.a)
end
Expand All @@ -34,6 +36,23 @@ function draw_image(canvas, image, x, y, r, sx, sy, color)
end
end

-- Avoid swapping shaders, more efficient.
function draw_image_suggested(canvas, image, x, y, r, sx, sy, color)
if color then
draw_push_vertex_attributes(color.r, color.g, color.b, color.a)
end
sprite_set_offset_x(image, x)
sprite_set_offset_y(image, y)
push(x, y, r, sx, sy)
draw_sprite(image)
pop()
if color then
draw_pop_vertex_attributes()
end
end

draw_image = draw_image_suggested

function push(x, y, r, sx, sy)
draw_push()
draw_translate(x or 0, y or 0)
Expand All @@ -47,16 +66,17 @@ function pop()
end

function main()
mount_directory_as('/content', '/')
app_set_title('Test')
app_set_size(w*sx, h*sy)
app_set_canvas_size(w*sx, h*sy)
display_width, display_height = display_width(default_display()), display_height(default_display())
app_center_window()

hit_effect_2 = make_easy_sprite('assets/hit_effect_2.png')
hit_effect_2 = make_easy_sprite('hit_effect_2.png')
shader = make_draw_shader_from_source([[
vec4 shader(vec4 color, vec2 pos, vec2 atlas_us, vec2 screen_uv, vec4 params) {
return vec4(params.rgb, color.a);
return params.a == 0 ? color : vec4(params.rgb, color.a);
}
]])

Expand All @@ -81,6 +101,8 @@ function main()
draw_push()
draw_translate(-480/2, 270/2)
draw_scale(1, -1)
draw_push_vertex_attributes(0,0,0,0)
render_settings_push_shader(shader)

rectangle(w/2, h/2, 300, 200, 0, white)
rectangle(w/2 - 80, h/2, 40, 10, 0, red)
Expand All @@ -89,12 +111,23 @@ function main()
draw_image(canvas, hit_effect_2, w/2, h/2, 0, 1, 1, blue)
end

if key_just_pressed(KEY_SPACE) then
if draw_image == draw_image_suggested then
print("Using draw_image_inefficient.")
draw_image = draw_image_inefficient
else
print("Using draw_image_suggested.")
draw_image = draw_image_suggested
end
end

draw_pop_antialias()
draw_pop()

canvas_blit(canvas, 0, 0, 1, 1, screen_canvas, 0, 0, 1, 1)
canvas_blit(screen_canvas, 0, 0, 1, 1, app_get_canvas(), 0, 0, 1, 1)
app_draw_onto_screen(false)
local draw_call_count = app_draw_onto_screen(false)
print(draw_call_count)
end
destroy_app()
end
end
1 change: 0 additions & 1 deletion src/wrap_cf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ REF_FUNCTION(render_settings_pop_shader);
REF_FUNCTION(render_settings_peek_shader);
REF_FUNCTION(render_settings_push_texture);

REF_FUNCTION(cf_render_settings_set_uniform);
REF_FUNCTION_EX(render_settings_set_uniform_int, cf_render_settings_set_uniform_int);
REF_FUNCTION_EX(render_settings_set_uniform_float, cf_render_settings_set_uniform_float);
REF_FUNCTION_EX(render_settings_set_uniform_v2, cf_render_settings_set_uniform_v2);
Expand Down

0 comments on commit a976d8e

Please sign in to comment.