Skip to content

Commit

Permalink
Remove redundant time property
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett committed Dec 17, 2024
1 parent 56dc41b commit 5a87801
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 24 deletions.
8 changes: 1 addition & 7 deletions src/render/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy::render::{mesh::BaseMeshPipelineKey, primitives::Aabb};
use bevy::{math::Mat4, render::mesh::PrimitiveTopology};
use bevy::{
math::{UVec2, UVec3, UVec4, Vec2, Vec3Swizzles, Vec4, Vec4Swizzles},
prelude::{Component, Entity, GlobalTransform, Mesh, Vec3},
prelude::{Component, Entity, GlobalTransform, Mesh},
render::{
mesh::{Indices, RenderMesh, RenderMeshBufferInfo, VertexAttributeValues},
render_resource::{BufferInitDescriptor, BufferUsages, ShaderType},
Expand Down Expand Up @@ -480,8 +480,6 @@ pub struct TilemapUniformData {
pub spacing: Vec2,
pub chunk_pos: Vec2,
pub map_size: Vec2,
pub time: f32,
pub pad: Vec3,
}

impl From<&RenderChunk2d> for TilemapUniformData {
Expand All @@ -497,8 +495,6 @@ impl From<&RenderChunk2d> for TilemapUniformData {
spacing: chunk.spacing,
chunk_pos: chunk_ix * chunk_size,
map_size: map_size * tile_size,
time: 0.0,
pad: Vec3::ZERO,
}
}
}
Expand All @@ -516,8 +512,6 @@ impl From<&mut RenderChunk2d> for TilemapUniformData {
spacing: chunk.spacing,
chunk_pos: chunk_pos * chunk_size,
map_size: map_size * tile_size,
time: 0.0,
pad: Vec3::ZERO,
}
}
}
4 changes: 1 addition & 3 deletions src/render/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy::{prelude::*, render::Extract, utils::HashMap};

use crate::prelude::TilemapGridSize;
use crate::prelude::TilemapRenderSettings;
use crate::render::{DefaultSampler, SecondsSinceStartup};
use crate::render::DefaultSampler;
use crate::tiles::AnimatedTile;
use crate::tiles::TilePosOld;
use crate::{
Expand Down Expand Up @@ -229,7 +229,6 @@ pub fn extract(
>,
camera_query: Extract<Query<(&RenderEntity, &Frustum), With<Camera>>>,
images: Extract<Res<Assets<Image>>>,
time: Extract<Res<Time>>,
) {
let mut extracted_tiles = Vec::new();
let mut extracted_tilemaps = HashMap::default();
Expand Down Expand Up @@ -367,7 +366,6 @@ pub fn extract(
commands.insert_batch(extracted_tiles);
commands.insert_batch(extracted_tilemaps);
commands.insert_batch(extracted_tilemap_textures);
commands.insert_resource(SecondsSinceStartup(time.elapsed_secs_f64() as f32));
}

pub fn remove_changed(mut commands: Commands, query: Query<Entity, With<ChangedInMainWorld>>) {
Expand Down
4 changes: 0 additions & 4 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ impl RenderChunkSize {

pub struct TilemapRenderingPlugin;

#[derive(Resource, Default, Deref, DerefMut)]
pub struct SecondsSinceStartup(pub f32);

pub const COLUMN_EVEN_HEX: Handle<Shader> = Handle::weak_from_u128(7704924705970804993);
pub const COLUMN_HEX: Handle<Shader> = Handle::weak_from_u128(11710877199891728627);
pub const COLUMN_ODD_HEX: Handle<Shader> = Handle::weak_from_u128(6706359414982022142);
Expand Down Expand Up @@ -251,7 +248,6 @@ impl Plugin for TilemapRenderingPlugin {
render_app
.insert_resource(DefaultSampler(sampler))
.insert_resource(RenderChunk2dStorage::default())
.insert_resource(SecondsSinceStartup(0.0))
.add_systems(
ExtractSchedule,
(extract::extract, extract_resource::<ModifiedImageIds>),
Expand Down
8 changes: 2 additions & 6 deletions src/render/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use crate::map::{
};
use crate::prelude::TilemapRenderSettings;
use crate::render::extract::ExtractedFrustum;
use crate::{
prelude::TilemapGridSize, render::RenderChunkSize, render::SecondsSinceStartup, FrustumCulling,
};
use crate::{prelude::TilemapGridSize, render::RenderChunkSize, FrustumCulling};
use bevy::log::trace;
use bevy::prelude::{InheritedVisibility, Resource, With};
use bevy::render::mesh::MeshVertexBufferLayouts;
Expand Down Expand Up @@ -69,7 +67,6 @@ pub(crate) fn prepare(
extracted_frustum_query: Query<&ExtractedFrustum>,
render_device: Res<RenderDevice>,
render_queue: Res<RenderQueue>,
seconds_since_startup: Res<SecondsSinceStartup>,
mut mesh_vertex_buffer_layouts: ResMut<MeshVertexBufferLayouts>,
) {
for tile in extracted_tiles.iter() {
Expand Down Expand Up @@ -197,8 +194,7 @@ pub(crate) fn prepare(

chunk.prepare(&render_device, &mut mesh_vertex_buffer_layouts);

let mut chunk_uniform: TilemapUniformData = chunk.into();
chunk_uniform.time = **seconds_since_startup;
let chunk_uniform: TilemapUniformData = chunk.into();

commands.spawn((
chunk.texture.clone_weak(),
Expand Down
2 changes: 0 additions & 2 deletions src/render/shaders/common.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ struct TilemapData {
spacing: vec2<f32>,
chunk_pos: vec2<f32>,
map_size: vec2<f32>,
time: f32,
_padding: vec3<f32>, // hack for webgl2 16 byte alignment
};
@group(1) @binding(1)
var<uniform> tilemap_data: TilemapData;
Expand Down
4 changes: 2 additions & 2 deletions src/render/shaders/tilemap_vertex.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import bevy_ecs_tilemap::common::{VertexInput, tilemap_data}
#import bevy_ecs_tilemap::mesh_output::MeshOutput
#import bevy_sprite::mesh2d_view_bindings::view
#import bevy_sprite::mesh2d_view_bindings::{view, globals}
#import bevy_ecs_tilemap::vertex_output::MeshVertexOutput

#ifdef SQUARE
Expand Down Expand Up @@ -49,7 +49,7 @@ fn vertex(vertex_input: VertexInput) -> MeshVertexOutput {

let frames: f32 = f32(vertex_input.uv.w - vertex_input.uv.z);

var current_animation_frame = fract(tilemap_data.time * animation_speed) * frames;
var current_animation_frame = fract(globals.time * animation_speed) * frames;

current_animation_frame = clamp(f32(vertex_input.uv.z) + current_animation_frame, f32(vertex_input.uv.z), f32(vertex_input.uv.w));

Expand Down

0 comments on commit 5a87801

Please sign in to comment.