From 3f247d11a467c5c41c77ab0a4971885bf2b6a52b Mon Sep 17 00:00:00 2001 From: Ewpratten Date: Mon, 4 Apr 2022 03:06:35 +0000 Subject: [PATCH] deploy: 00fa6edb20beeb2875551a39ba217e92dcda18bc --- .../rendering/utilities/map_render/index.html | 2 +- .../map_render/struct.MapRenderer.html | 6 +- .../rendering/utilities/map_render.rs.html | 338 ++++++++++-------- 3 files changed, 190 insertions(+), 156 deletions(-) diff --git a/rustdoc/game_logic/rendering/utilities/map_render/index.html b/rustdoc/game_logic/rendering/utilities/map_render/index.html index 5c7ba22b..7cb35c80 100644 --- a/rustdoc/game_logic/rendering/utilities/map_render/index.html +++ b/rustdoc/game_logic/rendering/utilities/map_render/index.html @@ -1,6 +1,6 @@ game_logic::rendering::utilities::map_render - Rust

Module game_logic::rendering::utilities::map_render[][src]

Structs

+

Module map_render

Module game_logic::rendering::utilities::map_render[][src]

Structs

Enums

Possible errors generated by the map loading process

diff --git a/rustdoc/game_logic/rendering/utilities/map_render/struct.MapRenderer.html b/rustdoc/game_logic/rendering/utilities/map_render/struct.MapRenderer.html index 9ef5eb49..7099a746 100644 --- a/rustdoc/game_logic/rendering/utilities/map_render/struct.MapRenderer.html +++ b/rustdoc/game_logic/rendering/utilities/map_render/struct.MapRenderer.html @@ -6,10 +6,10 @@ world_objects: WorldObjectPackage, world_end: Vector2<i32>, cup_icon: Texture2D, -}

Fields

map: Maptile_textures: HashMap<PathBuf, Texture2D>world_objects: WorldObjectPackageworld_end: Vector2<i32>cup_icon: Texture2D

Implementations

Construct a new MapRenderer.

+}

Fields

map: Maptile_textures: HashMap<PathBuf, Texture2D>world_objects: WorldObjectPackageworld_end: Vector2<i32>cup_icon: Texture2D

Implementations

Construct a new MapRenderer.

Gets the map size

-

Get the list of world colliders

-

Trait Implementations

Formats the value using the given formatter. Read more

+

Get the list of world colliders

+

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

diff --git a/rustdoc/src/game_logic/rendering/utilities/map_render.rs.html b/rustdoc/src/game_logic/rendering/utilities/map_render.rs.html index 2118691f..35ed2436 100644 --- a/rustdoc/src/game_logic/rendering/utilities/map_render.rs.html +++ b/rustdoc/src/game_logic/rendering/utilities/map_render.rs.html @@ -598,6 +598,23 @@ 596 597 598 +599 +600 +601 +602 +603 +604 +605 +606 +607 +608 +609 +610 +611 +612 +613 +614 +615
use std::{collections::HashMap, path::PathBuf, sync::Arc};
 
 use crate::{
@@ -879,6 +896,9 @@
             camera,
         );
         let player_position = na::Vector2::new(player_position.x, player_position.y * -1.0);
+        // Get the tile width and height
+        let tile_width = 128;
+        let tile_height = 128;
 
         // Handle each layer from the bottom up
         for layer in self.map.layers() {
@@ -889,10 +909,6 @@
                     let mut sampler_x = 0;
                     let mut sampler_y = 0;
 
-                    // Get the tile width and height
-                    let tile_width = 128;
-                    let tile_height = 128;
-
                     // Loop until we have covered all tiles on the screen
                     for y in (world_win_top_left.y as i64)..(world_win_bottom_right.y as i64) {
                         // Convert the pixel coordinates to tile coordinates
@@ -931,154 +947,6 @@
                                             Color::WHITE,
                                         );
                                     }
-
-                                    // Check if there is an object at this tile
-                                    for obj_ref in &self.world_objects.object_references {
-                                        if obj_ref.get_tile_space_position().x == sampler_x as f32
-                                            && obj_ref.get_tile_space_position().y
-                                                == sampler_y as f32
-                                        {
-                                            // Get access to the actual object definition
-                                            let object_key = obj_ref.into_key();
-                                            // debug!("Found object: {}", object_key);
-                                            let obj_def = self
-                                                .world_objects
-                                                .object_definitions
-                                                .get(&object_key)
-                                                .unwrap();
-
-                                            // We need to render the base layer of the object
-                                            if obj_def.bottom_texture.animated.unwrap_or(false) {
-                                                let tex = self
-                                                    .world_objects
-                                                    .bottom_animated_textures
-                                                    .get_mut(&object_key)
-                                                    .unwrap();
-                                                tex.render_automatic(
-                                                    draw_handle,
-                                                    obj_ref.get_world_space_position()
-                                                        - (tex.size() / 2.0),
-                                                    None,
-                                                    Some(tex.size() / 2.0),
-                                                    Some(obj_ref.rotation_degrees),
-                                                    None,
-                                                );
-                                            } else {
-                                                let tex = self
-                                                    .world_objects
-                                                    .bottom_static_textures
-                                                    .get_mut(&object_key)
-                                                    .unwrap();
-                                                let p: Vector2 =
-                                                    obj_ref.get_world_space_position().into();
-                                                let r1 = Rectangle {
-                                                    x: 0.0,
-                                                    y: 0.0,
-                                                    width: tex.width as f32,
-                                                    height: tex.height as f32,
-                                                };
-                                                let r2 = Rectangle {
-                                                    x: p.x,
-                                                    y: p.y,
-                                                    width: tex.width as f32,
-                                                    height: tex.height as f32,
-                                                };
-
-                                                draw_handle.draw_texture_pro(
-                                                    &tex,
-                                                    r1,
-                                                    r2,
-                                                    Vector2::new(
-                                                        tex.width as f32 / 2.0,
-                                                        tex.height as f32 / 2.0,
-                                                    ),
-                                                    obj_ref.rotation_degrees,
-                                                    Color::WHITE,
-                                                );
-                                            }
-
-                                            // If needed we can render the top layer of the object
-                                            if let Some(top_texture) = &obj_def.top_texture {
-                                                // We need to detect if the player is in the footprint of the object
-                                                let mut tint = Color::WHITE;
-                                                if let Some(footprint_radius) =
-                                                    obj_def.visualization_radius
-                                                {
-                                                    let player_dist_to_object = (obj_ref
-                                                        .get_world_space_position()
-                                                        - player_position)
-                                                        .norm();
-                                                    // debug!(
-                                                    //     "Player dist to object: {}",
-                                                    //     player_dist_to_object
-                                                    // );
-                                                    if player_dist_to_object <= footprint_radius {
-                                                        tint.a = 128;
-                                                    }
-                                                }
-
-                                                if top_texture.animated.unwrap_or(false) {
-                                                    let tex = self
-                                                        .world_objects
-                                                        .top_animated_textures
-                                                        .get_mut(&object_key)
-                                                        .unwrap();
-                                                    tex.render_automatic(
-                                                        draw_handle,
-                                                        obj_ref.get_world_space_position()
-                                                            - (tex.size() / 2.0),
-                                                        None,
-                                                        Some(tex.size() / 2.0),
-                                                        Some(obj_ref.rotation_degrees),
-                                                        Some(tint),
-                                                    );
-                                                } else {
-                                                    let tex = self
-                                                        .world_objects
-                                                        .top_static_textures
-                                                        .get_mut(&object_key)
-                                                        .unwrap();
-                                                    let p: Vector2 =
-                                                        obj_ref.get_world_space_position().into();
-                                                    let r1 = Rectangle {
-                                                        x: 0.0,
-                                                        y: 0.0,
-                                                        width: tex.width as f32,
-                                                        height: tex.height as f32,
-                                                    };
-                                                    let r2 = Rectangle {
-                                                        x: p.x,
-                                                        y: p.y,
-                                                        width: tex.width as f32,
-                                                        height: tex.height as f32,
-                                                    };
-
-                                                    draw_handle.draw_texture_pro(
-                                                        &tex,
-                                                        r1,
-                                                        r2,
-                                                        Vector2::new(
-                                                            tex.width as f32 / 2.0,
-                                                            tex.height as f32 / 2.0,
-                                                        ),
-                                                        obj_ref.rotation_degrees,
-                                                        tint,
-                                                    );
-                                                }
-                                            }
-                                        }
-                                    }
-
-                                    if show_debug_grid {
-                                        draw_handle.draw_rectangle_lines(
-                                            tile_x * tile_width as i32,
-                                            tile_y * tile_height as i32,
-                                            self.map.tile_width as i32,
-                                            self.map.tile_height as i32,
-                                            Color::RED,
-                                        );
-                                        draw_handle.draw_pixel(x as i32, y as i32, Color::BLUE);
-                                    }
                                 }
                             }
                         }
@@ -1089,6 +957,172 @@
                 tiled::LayerType::GroupLayer(_) => todo!(),
             }
         }
+
+        // Keep track of our sampler X and Y values
+        let mut sampler_x = 0;
+        let mut sampler_y = 0;
+
+        // Loop until we have covered all tiles on the screen
+        for y in (world_win_top_left.y as i64)..(world_win_bottom_right.y as i64) {
+            // Convert the pixel coordinates to tile coordinates
+            let tile_y = (y as f32 / tile_height as f32).floor() as i32;
+
+            // If we are looking at a new tile, update the sampler
+            if sampler_y != tile_y {
+                sampler_y = tile_y;
+
+                for x in (world_win_top_left.x as i64)..(world_win_bottom_right.x as i64) {
+                    // Convert the pixel coordinates to tile coordinates
+                    let tile_x = (x as f32 / tile_width as f32).floor() as i32;
+                    // debug!("Tile: ({}, {})", tile_x, tile_y);
+
+                    // If we are looking at a new tile, update the sampler
+                    if sampler_x != tile_x {
+                        sampler_x = tile_x;
+
+                        // Check if there is an object at this tile
+                        for obj_ref in &self.world_objects.object_references {
+                            if obj_ref.get_tile_space_position().x == sampler_x as f32
+                                && obj_ref.get_tile_space_position().y == sampler_y as f32
+                            {
+                                // Get access to the actual object definition
+                                let object_key = obj_ref.into_key();
+                                // debug!("Found object: {}", object_key);
+                                let obj_def = self
+                                    .world_objects
+                                    .object_definitions
+                                    .get(&object_key)
+                                    .unwrap();
+
+                                // We need to render the base layer of the object
+                                if obj_def.bottom_texture.animated.unwrap_or(false) {
+                                    let tex = self
+                                        .world_objects
+                                        .bottom_animated_textures
+                                        .get_mut(&object_key)
+                                        .unwrap();
+                                    tex.render_automatic(
+                                        draw_handle,
+                                        obj_ref.get_world_space_position() - (tex.size() / 2.0),
+                                        None,
+                                        Some(tex.size() / 2.0),
+                                        Some(obj_ref.rotation_degrees),
+                                        None,
+                                    );
+                                } else {
+                                    let tex = self
+                                        .world_objects
+                                        .bottom_static_textures
+                                        .get_mut(&object_key)
+                                        .unwrap();
+                                    let p: Vector2 = obj_ref.get_world_space_position().into();
+                                    let r1 = Rectangle {
+                                        x: 0.0,
+                                        y: 0.0,
+                                        width: tex.width as f32,
+                                        height: tex.height as f32,
+                                    };
+                                    let r2 = Rectangle {
+                                        x: p.x,
+                                        y: p.y,
+                                        width: tex.width as f32,
+                                        height: tex.height as f32,
+                                    };
+
+                                    draw_handle.draw_texture_pro(
+                                        &tex,
+                                        r1,
+                                        r2,
+                                        Vector2::new(
+                                            tex.width as f32 / 2.0,
+                                            tex.height as f32 / 2.0,
+                                        ),
+                                        obj_ref.rotation_degrees,
+                                        Color::WHITE,
+                                    );
+                                }
+
+                                // If needed we can render the top layer of the object
+                                if let Some(top_texture) = &obj_def.top_texture {
+                                    // We need to detect if the player is in the footprint of the object
+                                    let mut tint = Color::WHITE;
+                                    if let Some(footprint_radius) = obj_def.visualization_radius {
+                                        let player_dist_to_object =
+                                            (obj_ref.get_world_space_position() - player_position)
+                                                .norm();
+                                        // debug!(
+                                        //     "Player dist to object: {}",
+                                        //     player_dist_to_object
+                                        // );
+                                        if player_dist_to_object <= footprint_radius {
+                                            tint.a = 128;
+                                        }
+                                    }
+
+                                    if top_texture.animated.unwrap_or(false) {
+                                        let tex = self
+                                            .world_objects
+                                            .top_animated_textures
+                                            .get_mut(&object_key)
+                                            .unwrap();
+                                        tex.render_automatic(
+                                            draw_handle,
+                                            obj_ref.get_world_space_position() - (tex.size() / 2.0),
+                                            None,
+                                            Some(tex.size() / 2.0),
+                                            Some(obj_ref.rotation_degrees),
+                                            Some(tint),
+                                        );
+                                    } else {
+                                        let tex = self
+                                            .world_objects
+                                            .top_static_textures
+                                            .get_mut(&object_key)
+                                            .unwrap();
+                                        let p: Vector2 = obj_ref.get_world_space_position().into();
+                                        let r1 = Rectangle {
+                                            x: 0.0,
+                                            y: 0.0,
+                                            width: tex.width as f32,
+                                            height: tex.height as f32,
+                                        };
+                                        let r2 = Rectangle {
+                                            x: p.x,
+                                            y: p.y,
+                                            width: tex.width as f32,
+                                            height: tex.height as f32,
+                                        };
+
+                                        draw_handle.draw_texture_pro(
+                                            &tex,
+                                            r1,
+                                            r2,
+                                            Vector2::new(
+                                                tex.width as f32 / 2.0,
+                                                tex.height as f32 / 2.0,
+                                            ),
+                                            obj_ref.rotation_degrees,
+                                            tint,
+                                        );
+                                    }
+                                }
+                            }
+                        }
+
+                        if show_debug_grid {
+                            draw_handle.draw_rectangle_lines(
+                                tile_x * tile_width as i32,
+                                tile_y * tile_height as i32,
+                                self.map.tile_width as i32,
+                                self.map.tile_height as i32,
+                                Color::RED,
+                            );
+                            draw_handle.draw_pixel(x as i32, y as i32, Color::BLUE);
+                        }
+                    }
+                }
+            }
+        }
     }
 
     /// Get the list of world colliders