diff --git a/crates/content/src/part/system.rs b/crates/content/src/part/system.rs index 4d013d6..7cc8695 100644 --- a/crates/content/src/part/system.rs +++ b/crates/content/src/part/system.rs @@ -238,6 +238,7 @@ impl crate::Build for System { .unwrap_or("".to_string()), // TODO: better linebreaks, handle double spaces + // Tabs desc: obj .desc .as_ref() diff --git a/crates/render/src/ui/radar.rs b/crates/render/src/ui/radar.rs index 42b34b2..aebfebc 100644 --- a/crates/render/src/ui/radar.rs +++ b/crates/render/src/ui/radar.rs @@ -1,12 +1,8 @@ use galactica_system::data::ShipState; -use galactica_util::{clockwise_angle, constants::UI_SPRITE_INSTANCE_LIMIT, to_radians}; +use galactica_util::{clockwise_angle, to_radians}; use nalgebra::{Point2, Rotation2, Vector2}; -use crate::{ - datastructs::RenderState, - vertexbuffer::{types::UiInstance, BufferObject}, - PositionAnchor, RenderInput, -}; +use crate::{vertexbuffer::types::UiInstance, PositionAnchor, RenderInput, RenderState}; pub(super) struct Radar { last_player_position: Point2, @@ -64,26 +60,15 @@ impl Radar { let ship_sprite = input.ct.get_sprite_handle("ui::shipblip"); let arrow_sprite = input.ct.get_sprite_handle("ui::centerarrow"); - // Enforce buffer limit - if state.vertex_buffers.ui_counter as u64 > UI_SPRITE_INSTANCE_LIMIT { - // TODO: no panic, handle this better. - panic!("UI limit exceeded!") - } - // Push this object's instance - state.queue.write_buffer( - &state.vertex_buffers.ui.instances, - UiInstance::SIZE * state.vertex_buffers.ui_counter, - bytemuck::cast_slice(&[UiInstance { - anchor: PositionAnchor::NwNw.to_int(), - position: [10.0, -10.0], - angle: 0.0, - size: radar_size, - color: [1.0, 1.0, 1.0, 1.0], - sprite_index: input.ct.get_sprite_handle("ui::radar").get_index(), - }]), - ); - state.vertex_buffers.ui_counter += 1; + state.push_ui_buffer(UiInstance { + anchor: PositionAnchor::NwNw.to_int(), + position: [10.0, -10.0], + angle: 0.0, + size: radar_size, + color: [1.0, 1.0, 1.0, 1.0], + sprite_index: input.ct.get_sprite_handle("ui::radar").get_index(), + }); // Draw system objects let system = input.ct.get_system(input.current_system); @@ -101,29 +86,18 @@ impl Radar { continue; } - // Enforce buffer limit - if state.vertex_buffers.ui_counter as u64 > UI_SPRITE_INSTANCE_LIMIT { - // TODO: no panic, handle this better. - panic!("UI limit exceeded!") - } - // Push this object's instance - state.queue.write_buffer( - &state.vertex_buffers.ui.instances, - UiInstance::SIZE * state.vertex_buffers.ui_counter, - bytemuck::cast_slice(&[UiInstance { - anchor: PositionAnchor::NwC.to_int(), - position: (Point2::new(radar_size / 2.0 + 10.0, radar_size / -2.0 - 10.0) - + (d * (radar_size / 2.0))) - .into(), - angle: o.angle, - size, - color: [0.5, 0.5, 0.5, 1.0], - sprite_index: planet_sprite.get_index(), - }]), - ); - state.vertex_buffers.ui_counter += 1; - } + state.push_ui_buffer(UiInstance { + anchor: PositionAnchor::NwC.to_int(), + position: (Point2::new(radar_size / 2.0 + 10.0, radar_size / -2.0 - 10.0) + + (d * (radar_size / 2.0))) + .into(), + angle: o.angle, + size, + color: [0.5, 0.5, 0.5, 1.0], + sprite_index: planet_sprite.get_index(), + }) + }; } // Draw ships @@ -164,32 +138,18 @@ impl Radar { if size < 2.0 { continue; } - let angle = r.rotation().angle(); let position = Point2::new(radar_size / 2.0 + 10.0, radar_size / -2.0 - 10.0) + (d * (radar_size / 2.0)); - // Enforce buffer limit - // TODO: cleaner solution. don't do this everywhere. - if state.vertex_buffers.ui_counter as u64 > UI_SPRITE_INSTANCE_LIMIT { - // TODO: no panic, handle this better. - panic!("UI limit exceeded!") - } - - // Push this object's instance - state.queue.write_buffer( - &state.vertex_buffers.ui.instances, - UiInstance::SIZE * state.vertex_buffers.ui_counter, - bytemuck::cast_slice(&[UiInstance { - anchor: PositionAnchor::NwC.to_int(), - position: position.into(), - angle: -angle, // TODO: consistent angles - size, - color, - sprite_index: ship_sprite.get_index(), - }]), - ); - state.vertex_buffers.ui_counter += 1; + state.push_ui_buffer(UiInstance { + anchor: PositionAnchor::NwC.to_int(), + position: position.into(), + angle: r.rotation().angle(), + size, + color, + sprite_index: ship_sprite.get_index(), + }); } } @@ -205,83 +165,57 @@ impl Radar { let sprite = input.ct.get_sprite_handle("ui::radarframe"); let size = 7.0f32.min((0.8 - m) * 70.0); - // Enforce buffer limit (this section adds four items) - if state.vertex_buffers.ui_counter as u64 + 4 > UI_SPRITE_INSTANCE_LIMIT { - // TODO: no panic, handle this better. - panic!("UI limit exceeded!") - } + state.push_ui_buffer(UiInstance { + anchor: PositionAnchor::NwNw.to_int(), + position: Point2::new( + (radar_size / 2.0 + 10.0) - d.x, + (radar_size / -2.0 - 10.0) + d.y, + ) + .into(), + angle: to_radians(90.0), + size, + color, + sprite_index: sprite.get_index(), + }); - state.queue.write_buffer( - &state.vertex_buffers.ui.instances, - UiInstance::SIZE * state.vertex_buffers.ui_counter, - bytemuck::cast_slice(&[UiInstance { - anchor: PositionAnchor::NwNw.to_int(), - position: Point2::new( - (radar_size / 2.0 + 10.0) - d.x, - (radar_size / -2.0 - 10.0) + d.y, - ) - .into(), - angle: to_radians(90.0), - size, - color, - sprite_index: sprite.get_index(), - }]), - ); - state.vertex_buffers.ui_counter += 1; + state.push_ui_buffer(UiInstance { + anchor: PositionAnchor::NwSw.to_int(), + position: Point2::new( + (radar_size / 2.0 + 10.0) - d.x, + (radar_size / -2.0 - 10.0) - d.y, + ) + .into(), + angle: to_radians(180.0), + size, + color, + sprite_index: sprite.get_index(), + }); - state.queue.write_buffer( - &state.vertex_buffers.ui.instances, - UiInstance::SIZE * state.vertex_buffers.ui_counter, - bytemuck::cast_slice(&[UiInstance { - anchor: PositionAnchor::NwSw.to_int(), - position: Point2::new( - (radar_size / 2.0 + 10.0) - d.x, - (radar_size / -2.0 - 10.0) - d.y, - ) - .into(), - angle: to_radians(180.0), - size, - color, - sprite_index: sprite.get_index(), - }]), - ); - state.vertex_buffers.ui_counter += 1; + state.push_ui_buffer(UiInstance { + anchor: PositionAnchor::NwSe.to_int(), + position: Point2::new( + (radar_size / 2.0 + 10.0) + d.x, + (radar_size / -2.0 - 10.0) - d.y, + ) + .into(), + angle: to_radians(270.0), + size, + color, + sprite_index: sprite.get_index(), + }); - state.queue.write_buffer( - &state.vertex_buffers.ui.instances, - UiInstance::SIZE * state.vertex_buffers.ui_counter, - bytemuck::cast_slice(&[UiInstance { - anchor: PositionAnchor::NwSe.to_int(), - position: Point2::new( - (radar_size / 2.0 + 10.0) + d.x, - (radar_size / -2.0 - 10.0) - d.y, - ) - .into(), - angle: to_radians(270.0), - size, - color, - sprite_index: sprite.get_index(), - }]), - ); - state.vertex_buffers.ui_counter += 1; - - state.queue.write_buffer( - &state.vertex_buffers.ui.instances, - UiInstance::SIZE * state.vertex_buffers.ui_counter, - bytemuck::cast_slice(&[UiInstance { - anchor: PositionAnchor::NwNe.to_int(), - position: Point2::new( - (radar_size / 2.0 + 10.0) + d.x, - (radar_size / -2.0 - 10.0) + d.y, - ) - .into(), - angle: to_radians(0.0), - size, - color, - sprite_index: sprite.get_index(), - }]), - ); - state.vertex_buffers.ui_counter += 1; + state.push_ui_buffer(UiInstance { + anchor: PositionAnchor::NwNe.to_int(), + position: Point2::new( + (radar_size / 2.0 + 10.0) + d.x, + (radar_size / -2.0 - 10.0) + d.y, + ) + .into(), + angle: to_radians(0.0), + size, + color, + sprite_index: sprite.get_index(), + }); } // Arrow to center of system @@ -292,24 +226,14 @@ impl Radar { let position = Point2::new(10.0 + (radar_size / 2.0), -10.0 - (radar_size / 2.0)) + Rotation2::new(angle) * Vector2::new(0.915 * (radar_size / 2.0), 0.0); - if state.vertex_buffers.ui_counter as u64 > UI_SPRITE_INSTANCE_LIMIT { - // TODO: no panic, handle this better. - panic!("UI limit exceeded!") - } - - state.queue.write_buffer( - &state.vertex_buffers.ui.instances, - UiInstance::SIZE * state.vertex_buffers.ui_counter, - bytemuck::cast_slice(&[UiInstance { - anchor: PositionAnchor::NwC.to_int(), - position: position.into(), - angle, - size: 10.0, - color: [1.0, 1.0, 1.0, 1f32.min((m - 200.0) / 400.0)], - sprite_index: arrow_sprite.get_index(), - }]), - ); - state.vertex_buffers.ui_counter += 1; + state.push_ui_buffer(UiInstance { + anchor: PositionAnchor::NwC.to_int(), + position: position.into(), + angle, + size: 10.0, + color: [1.0, 1.0, 1.0, 1f32.min((m - 200.0) / 400.0)], + sprite_index: arrow_sprite.get_index(), + }); } } } diff --git a/crates/render/src/ui/status.rs b/crates/render/src/ui/status.rs index 3a1cf47..7f41612 100644 --- a/crates/render/src/ui/status.rs +++ b/crates/render/src/ui/status.rs @@ -1,14 +1,9 @@ use galactica_system::data::ShipState; -use galactica_util::constants::{RADIALBAR_SPRITE_INSTANCE_LIMIT, UI_SPRITE_INSTANCE_LIMIT}; use std::f32::consts::TAU; use crate::{ - datastructs::RenderState, - vertexbuffer::{ - types::{RadialBarInstance, UiInstance}, - BufferObject, - }, - PositionAnchor, RenderInput, + vertexbuffer::types::{RadialBarInstance, UiInstance}, + PositionAnchor, RenderInput, RenderState, }; pub(super) struct Status {} @@ -20,11 +15,6 @@ impl Status { impl Status { pub fn draw(&mut self, input: &RenderInput, state: &mut RenderState) { - if state.vertex_buffers.ui_counter as u64 > UI_SPRITE_INSTANCE_LIMIT { - // TODO: no panic, handle this better. - panic!("UI limit exceeded!") - } - let max_shields; let current_shields; let current_hull; @@ -55,52 +45,31 @@ impl Status { } } - state.queue.write_buffer( - &state.vertex_buffers.ui.instances, - UiInstance::SIZE * state.vertex_buffers.ui_counter, - bytemuck::cast_slice(&[UiInstance { - anchor: PositionAnchor::NeNe.to_int(), - position: [-10.0, -10.0], - angle: 0.0, - size: 200.0, - color: [1.0, 1.0, 1.0, 1.0], - sprite_index: input.ct.get_sprite_handle("ui::status").get_index(), - }]), - ); - state.vertex_buffers.ui_counter += 1; + state.push_ui_buffer(UiInstance { + anchor: PositionAnchor::NeNe.to_int(), + position: [-10.0, -10.0], + angle: 0.0, + size: 200.0, + color: [1.0, 1.0, 1.0, 1.0], + sprite_index: input.ct.get_sprite_handle("ui::status").get_index(), + }); - // We add two items here, so +2 - if state.vertex_buffers.radialbar_counter as u64 + 2 > RADIALBAR_SPRITE_INSTANCE_LIMIT { - // TODO: no panic, handle this better. - panic!("Radialbar limit exceeded!") - } + state.push_radialbar_buffer(RadialBarInstance { + position: [-19.0, -19.0], + anchor: PositionAnchor::NeNe.to_int(), + diameter: 182.0, + stroke: 5.0, + color: [0.3, 0.6, 0.8, 1.0], + angle: (current_shields / max_shields) * TAU, + }); - state.queue.write_buffer( - &state.vertex_buffers.radialbar.instances, - RadialBarInstance::SIZE * state.vertex_buffers.radialbar_counter, - bytemuck::cast_slice(&[RadialBarInstance { - position: [-19.0, -19.0], - anchor: PositionAnchor::NeNe.to_int(), - diameter: 182.0, - stroke: 5.0, - color: [0.3, 0.6, 0.8, 1.0], - angle: (current_shields / max_shields) * TAU, - }]), - ); - state.vertex_buffers.radialbar_counter += 1; - - state.queue.write_buffer( - &state.vertex_buffers.radialbar.instances, - RadialBarInstance::SIZE * state.vertex_buffers.radialbar_counter, - bytemuck::cast_slice(&[RadialBarInstance { - position: [-27.0, -27.0], - anchor: PositionAnchor::NeNe.to_int(), - diameter: 166.0, - stroke: 5.0, - color: [0.8, 0.7, 0.5, 1.0], - angle: (current_hull / max_hull) * TAU, - }]), - ); - state.vertex_buffers.radialbar_counter += 1; + state.push_radialbar_buffer(RadialBarInstance { + position: [-27.0, -27.0], + anchor: PositionAnchor::NeNe.to_int(), + diameter: 166.0, + stroke: 5.0, + color: [0.8, 0.7, 0.5, 1.0], + angle: (current_hull / max_hull) * TAU, + }); } }