diff --git a/source/core.adb b/source/core.adb index 0a777ea..10309be 100644 --- a/source/core.adb +++ b/source/core.adb @@ -110,6 +110,31 @@ package body core is ------------------------------------------------------------------------------------------ + procedure view (data : in sprite; x, y, u, v, width, height : in integer) is + crop_u, crop_v, crop_width, crop_height : integer; + begin + if x > u + width + or y > v + height + or x < u - data.width + or y < v - data.height then + return; + end if; + -- + --~if x < u + width - data.width then crop_width := data.width; else crop_width := data.width - (x + data.width) mod (width + u); end if; + --~if x < u + width - data.width then crop_width := data.width; else crop_width := data.width - (x + data.width) mod (width + u); end if; + crop_width := data.width - (if x < u + width - data.width then 0 else (x + data.width) mod (width + u)); + crop_height := data.height - (if y < v + height - data.height then 0 else (y + data.height) mod (height + v)); + crop_u := 0; + crop_v := 0; + --~if y + data.height < v + height then crop_height := (if y + data.height < height then data.height else data.height - (y + data.height) mod height); end if; + --~if x + data.width > u then crop_u := (x + data.width) mod u; end if; + --~if y + data.height > v then crop_v := (y + data.height) mod v; end if; + -- + render_sprite (data.index, x, y, crop_u, crop_v, crop_width, crop_height); + end view; + + ------------------------------------------------------------------------------------------ + procedure draw (data : in sprite; x, y : in integer) is begin render_sprite (data.index, x, y, 0, 0, data.width, data.height); diff --git a/source/core.ads b/source/core.ads index 8459ddb..527c2d0 100644 --- a/source/core.ads +++ b/source/core.ads @@ -102,6 +102,7 @@ package core is function load_sprite (file_path : in string; frames, states : in integer) return sprite; procedure crop (data : in sprite; x, y, u, v, width, height : in integer); + procedure view (data : in sprite; x, y, u, v, width, height : in integer); procedure draw (data : in sprite; x, y : in integer); procedure move (data : in sprite; x, y, frame, state : in integer); diff --git a/source/world.adb b/source/world.adb index 6ade6b6..a22dde4 100644 --- a/source/world.adb +++ b/source/world.adb @@ -101,29 +101,6 @@ package body world is ------------------------------------------------------------------------------------------ - procedure crop (data : in core.sprite; x, y, view_x, view_y, view_width, view_height : in integer) is - crop_u, crop_v, crop_width, crop_height : integer; - begin - if x > view_x + view_width - or y > view_y + view_height - or x < view_x - data.width - or y < view_y - data.height then - return; - end if; - -- - --~if x + data.width < view_x + view_width then crop_width := data.width - (view_x + data.width) mod view_width; end if; - --~if y + data.height < view_y + view_height then crop_height := data.height - (view_y + data.height) mod view_height; end if; - -- - --~core.crop (data, x, y, 0, 0, crop_width, crop_height); - -- - if (x + data.width) > view_width then crop_width := data.width - (x + data.width) mod view_width; end if; - if (y + data.height) > view_height then crop_height := data.height - (y + data.height) mod view_height; end if; - -- - core.crop (data, x + view_x, y + view_y, 0, 0, crop_width, crop_height); - end crop; - - ------------------------------------------------------------------------------------------ - procedure draw (x, y, width, height : in integer; show_grid : in boolean) is crop_width : integer := width mod core.base; crop_height : integer := height mod core.base; @@ -160,26 +137,7 @@ package body world is -- for object in 0 .. landmark_limit loop - --~if map.landmark (object).x > width - --~or map.landmark (object).y > height then - --~goto skip_drawing_out_of_view_landmark; - --~end if; - --~-- - --~crop_width := landmarks (map.terrain) (map.landmark (object).index).width; - --~crop_height := landmarks (map.terrain) (map.landmark (object).index).height; - --~-- - --~if (map.landmark (object).x + landmarks (map.terrain) (map.landmark (object).index).width) > width then - --~crop_width := crop_width - (map.landmark (object).x + landmarks (map.terrain) (map.landmark (object).index).width) mod width; - --~end if; - --~-- - --~if (map.landmark (object).y + landmarks (map.terrain) (map.landmark (object).index).height) > height then - --~crop_height := crop_height - (map.landmark (object).y + landmarks (map.terrain) (map.landmark (object).index).height) mod height; - --~end if; - --~-- - --~core.crop (landmarks (map.terrain) (map.landmark (object).index), x + map.landmark (object).x, y + map.landmark (object).y, 0, 0, crop_width, crop_height); - --~-- - --~<> - crop (landmarks (map.terrain) (map.landmark (object).index), map.landmark (object).x, map.landmark (object).y, x, y, width, height); + core.view (landmarks (map.terrain) (map.landmark (object).index), map.landmark (object).x - core.camera.x * core.base, map.landmark (object).y - core.camera.y * core.base, x, y, width, height); end loop; -- if show_grid then @@ -187,17 +145,17 @@ package body world is core.hexagonal_grid (x, y, width, height, true); end if; -- - for object in 0 .. construction_limit - loop - if map.construction (object).x > width - or map.construction (object).y > height then - goto skip_drawing_out_of_view_construction; - end if; - -- - construction.draw (construction.codex'val (map.construction (object).index), map.construction (object).x, map.construction (object).y); - -- - <> - end loop; + --~for object in 0 .. construction_limit + --~loop + --~if map.construction (object).x > width + --~or map.construction (object).y > height then + --~goto skip_drawing_out_of_view_construction; + --~end if; + --~-- + --~construction.draw (construction.codex'val (map.construction (object).index), map.construction (object).x, map.construction (object).y); + --~-- + --~<> + --~end loop; end draw; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------