Refactored biome-separated world rendering...

This commit is contained in:
Ognjen Milan Robovic 2024-05-25 06:33:05 -04:00
parent 043dba7c07
commit fc5b64532f
5 changed files with 27 additions and 22 deletions

View File

@ -307,6 +307,7 @@ package body core is
v : in integer := 0;
width : in integer := 0;
height : in integer := 0;
ignore : in boolean := false;
state : in animation := idle;
factor : in integer := zoom;
tint : in colour := (others => 255)) is
@ -316,8 +317,8 @@ package body core is
new_tint : ray.colour := (ray.colour_range (tint.r), ray.colour_range (tint.g), ray.colour_range (tint.b), ray.colour_range (tint.a));
begin
ray.draw_texture (data => texture_array (data.index),
uv => (x => float (if u > 0 then u else (animation_time mod data.frames) * data.width),
y => float (if v > 0 then v else (animation'pos (state) mod data.states) * data.height),
uv => (x => float (if ignore then u else (animation_time mod data.frames) * data.width),
y => float (if ignore then v else (animation'pos (state) mod data.states) * data.height),
width => new_width,
height => new_height),
view => (x => float (x),

View File

@ -158,6 +158,7 @@ package core is
v : in integer := 0;
width : in integer := 0;
height : in integer := 0;
ignore : in boolean := false;
state : in animation := idle;
factor : in integer := zoom;
tint : in colour := (others => 255));

View File

@ -204,7 +204,7 @@ begin
world.configure;
--~ai.configure;
world.make (world.swamp, 240, 180, 8);
world.make (world.rough, 240, 180, 8);
world.add_chad (player);
core.dash;

View File

@ -19,7 +19,8 @@ package body world is
equipment_limit : constant natural := 600;
unit_limit : constant natural := 60;
earth : core.sprite;
tiles : array (biome) of core.sprite;
dark : core.sprite;
border_upper : core.sprite;
border_lower : core.sprite;
@ -36,7 +37,10 @@ package body world is
begin
core.echo (core.comment, "Configuring world components...");
--
earth := core.import_sprite (core.folder & "/game/world/terrain/earth.png", 1, 1);
for index in biome loop
tiles (index) := core.import_sprite (core.folder & "/game/world/terrain/" & core.lowercase (index'image) & ".png", 4, 1);
end loop;
--
dark := core.import_sprite (core.folder & "/game/world/dark.png", 1, 1);
border_upper := core.import_sprite (core.folder & "/game/world/frame/border_upper.png", 1, 1);
border_lower := core.import_sprite (core.folder & "/game/world/frame/border_lower.png", 1, 1);
@ -77,7 +81,7 @@ package body world is
map.chad_limit := chad_limit;
map.chad_count := 0;
--
map.earth := new integer_matrix (0 .. map.width - 1, 0 .. map.height - 1);
map.tiles := new integer_matrix (0 .. map.width - 1, 0 .. map.height - 1);
map.clips := new boolean_matrix (0 .. map.width - 1, 0 .. map.height - 1);
map.views := new boolean_matrix (0 .. map.width - 1, 0 .. map.height - 1);
map.landmarks := new entity_array (1 .. landmark_limit);
@ -89,7 +93,7 @@ package body world is
--
for x in 0 .. width - 1 loop
for y in 0 .. height - 1 loop
map.earth (x, y) := (if core.random (0, 23) < 19 then core.random (0, 11) else core.random (0, 23));
map.tiles (x, y) := (if core.random (0, 17) > 3 then core.random (0, 5) else core.random (0, 17));
map.clips (x, y) := false;
map.views (x, y) := false;
end loop;
@ -192,7 +196,7 @@ package body world is
--
for x in 0 .. map.width - 1 loop
for y in 0 .. map.height - 1 loop
core.io.write (file, map.earth (x, y));
core.io.write (file, map.tiles (x, y));
core.io.write (file, boolean'pos (map.clips (x, y)));
core.io.write (file, boolean'pos (map.views (x, y)));
end loop;
@ -237,7 +241,7 @@ package body world is
--
for x in 0 .. map.width - 1 loop
for y in 0 .. map.height - 1 loop
core.io.read (file, map.earth (x, y));
core.io.read (file, map.tiles (x, y));
core.io.read (file, this); map.clips (x, y) := boolean'val (this);
core.io.read (file, this); map.views (x, y) := boolean'val (this);
end loop;
@ -299,13 +303,14 @@ package body world is
exit when offset.x + (horizontal - core.camera.x) * core.base * core.zoom > core.window_width;
--
if map.views (horizontal, vertical) then
core.draw (data => earth,
core.draw (data => tiles (map.kind),
x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom,
y => offset.y + (vertical - core.camera.y) * core.base * core.zoom,
u => core.base * biome'pos (map.kind) * 4,
v => core.base * map.earth (horizontal, vertical),
u => core.base * map.tiles (horizontal, vertical),
v => core.base * (core.animation_time mod tiles (map.kind).frames),
width => core.base,
height => core.base);
height => core.base,
ignore => true);
--~--
if core.cursor.x > offset.x + (horizontal - core.camera.x ) * core.base * core.zoom - 6
and core.cursor.x < offset.x + (horizontal - core.camera.x + 1) * core.base * core.zoom + 6
@ -342,9 +347,7 @@ package body world is
core.draw (data => locations (location_index'val (map.locations (index).index)),
x => offset.x + (map.locations (index).x - core.camera.x) * core.base * core.zoom,
y => offset.y + (map.locations (index).y - core.camera.y) * core.base * core.zoom,
v => locations (location_index'val (map.locations (index).index)).height * map.locations (index).state,
width => locations (location_index'val (map.locations (index).index)).width,
height => locations (location_index'val (map.locations (index).index)).height);
state => core.animation'val (map.locations (index).state));
if core.cursor_inside (x => offset.x + (map.locations (index).x - core.camera.x) * core.base * core.zoom,
y => offset.y + (map.locations (index).y - core.camera.y) * core.base * core.zoom,
width => locations (location_index'val (map.locations (index).index)).width,
@ -443,11 +446,11 @@ package body world is
--
for vertical in 0 .. map.height - 1 loop
for horizontal in 0 .. map.width - 1 loop
core.render_image (data => earth,
core.render_image (data => tiles (map.kind),
x => horizontal * core.base,
y => vertical * core.base,
u => core.base * biome'pos (map.kind) * 4,
v => core.base * map.earth (horizontal, vertical),
u => core.base * map.tiles (horizontal, vertical),
v => 0,
width => core.base,
height => core.base);
end loop;

View File

@ -56,7 +56,7 @@ package world is
height : natural;
chad_count : natural;
chad_limit : natural;
earth : access integer_matrix;
tiles : access integer_matrix;
clips : access boolean_matrix;
views : access boolean_matrix;
landmarks : access entity_array;