Minor edits

master
Mark 2024-01-17 10:25:03 -08:00
parent fa46c76fd2
commit 81dc7b170c
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
3 changed files with 112 additions and 218 deletions

View File

@ -238,6 +238,7 @@ impl crate::Build for System {
.unwrap_or("".to_string()), .unwrap_or("".to_string()),
// TODO: better linebreaks, handle double spaces // TODO: better linebreaks, handle double spaces
// Tabs
desc: obj desc: obj
.desc .desc
.as_ref() .as_ref()

View File

@ -1,12 +1,8 @@
use galactica_system::data::ShipState; 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 nalgebra::{Point2, Rotation2, Vector2};
use crate::{ use crate::{vertexbuffer::types::UiInstance, PositionAnchor, RenderInput, RenderState};
datastructs::RenderState,
vertexbuffer::{types::UiInstance, BufferObject},
PositionAnchor, RenderInput,
};
pub(super) struct Radar { pub(super) struct Radar {
last_player_position: Point2<f32>, last_player_position: Point2<f32>,
@ -64,26 +60,15 @@ impl Radar {
let ship_sprite = input.ct.get_sprite_handle("ui::shipblip"); let ship_sprite = input.ct.get_sprite_handle("ui::shipblip");
let arrow_sprite = input.ct.get_sprite_handle("ui::centerarrow"); 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 // Push this object's instance
state.queue.write_buffer( state.push_ui_buffer(UiInstance {
&state.vertex_buffers.ui.instances,
UiInstance::SIZE * state.vertex_buffers.ui_counter,
bytemuck::cast_slice(&[UiInstance {
anchor: PositionAnchor::NwNw.to_int(), anchor: PositionAnchor::NwNw.to_int(),
position: [10.0, -10.0], position: [10.0, -10.0],
angle: 0.0, angle: 0.0,
size: radar_size, size: radar_size,
color: [1.0, 1.0, 1.0, 1.0], color: [1.0, 1.0, 1.0, 1.0],
sprite_index: input.ct.get_sprite_handle("ui::radar").get_index(), sprite_index: input.ct.get_sprite_handle("ui::radar").get_index(),
}]), });
);
state.vertex_buffers.ui_counter += 1;
// Draw system objects // Draw system objects
let system = input.ct.get_system(input.current_system); let system = input.ct.get_system(input.current_system);
@ -101,17 +86,8 @@ impl Radar {
continue; 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 // Push this object's instance
state.queue.write_buffer( state.push_ui_buffer(UiInstance {
&state.vertex_buffers.ui.instances,
UiInstance::SIZE * state.vertex_buffers.ui_counter,
bytemuck::cast_slice(&[UiInstance {
anchor: PositionAnchor::NwC.to_int(), anchor: PositionAnchor::NwC.to_int(),
position: (Point2::new(radar_size / 2.0 + 10.0, radar_size / -2.0 - 10.0) position: (Point2::new(radar_size / 2.0 + 10.0, radar_size / -2.0 - 10.0)
+ (d * (radar_size / 2.0))) + (d * (radar_size / 2.0)))
@ -120,10 +96,8 @@ impl Radar {
size, size,
color: [0.5, 0.5, 0.5, 1.0], color: [0.5, 0.5, 0.5, 1.0],
sprite_index: planet_sprite.get_index(), sprite_index: planet_sprite.get_index(),
}]), })
); };
state.vertex_buffers.ui_counter += 1;
}
} }
// Draw ships // Draw ships
@ -164,32 +138,18 @@ impl Radar {
if size < 2.0 { if size < 2.0 {
continue; continue;
} }
let angle = r.rotation().angle();
let position = Point2::new(radar_size / 2.0 + 10.0, radar_size / -2.0 - 10.0) let position = Point2::new(radar_size / 2.0 + 10.0, radar_size / -2.0 - 10.0)
+ (d * (radar_size / 2.0)); + (d * (radar_size / 2.0));
// Enforce buffer limit state.push_ui_buffer(UiInstance {
// 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(), anchor: PositionAnchor::NwC.to_int(),
position: position.into(), position: position.into(),
angle: -angle, // TODO: consistent angles angle: r.rotation().angle(),
size, size,
color, color,
sprite_index: ship_sprite.get_index(), sprite_index: ship_sprite.get_index(),
}]), });
);
state.vertex_buffers.ui_counter += 1;
} }
} }
@ -205,16 +165,7 @@ impl Radar {
let sprite = input.ct.get_sprite_handle("ui::radarframe"); let sprite = input.ct.get_sprite_handle("ui::radarframe");
let size = 7.0f32.min((0.8 - m) * 70.0); let size = 7.0f32.min((0.8 - m) * 70.0);
// Enforce buffer limit (this section adds four items) state.push_ui_buffer(UiInstance {
if state.vertex_buffers.ui_counter as u64 + 4 > 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::NwNw.to_int(), anchor: PositionAnchor::NwNw.to_int(),
position: Point2::new( position: Point2::new(
(radar_size / 2.0 + 10.0) - d.x, (radar_size / 2.0 + 10.0) - d.x,
@ -225,14 +176,9 @@ impl Radar {
size, size,
color, color,
sprite_index: sprite.get_index(), sprite_index: sprite.get_index(),
}]), });
);
state.vertex_buffers.ui_counter += 1;
state.queue.write_buffer( state.push_ui_buffer(UiInstance {
&state.vertex_buffers.ui.instances,
UiInstance::SIZE * state.vertex_buffers.ui_counter,
bytemuck::cast_slice(&[UiInstance {
anchor: PositionAnchor::NwSw.to_int(), anchor: PositionAnchor::NwSw.to_int(),
position: Point2::new( position: Point2::new(
(radar_size / 2.0 + 10.0) - d.x, (radar_size / 2.0 + 10.0) - d.x,
@ -243,14 +189,9 @@ impl Radar {
size, size,
color, color,
sprite_index: sprite.get_index(), sprite_index: sprite.get_index(),
}]), });
);
state.vertex_buffers.ui_counter += 1;
state.queue.write_buffer( state.push_ui_buffer(UiInstance {
&state.vertex_buffers.ui.instances,
UiInstance::SIZE * state.vertex_buffers.ui_counter,
bytemuck::cast_slice(&[UiInstance {
anchor: PositionAnchor::NwSe.to_int(), anchor: PositionAnchor::NwSe.to_int(),
position: Point2::new( position: Point2::new(
(radar_size / 2.0 + 10.0) + d.x, (radar_size / 2.0 + 10.0) + d.x,
@ -261,14 +202,9 @@ impl Radar {
size, size,
color, color,
sprite_index: sprite.get_index(), sprite_index: sprite.get_index(),
}]), });
);
state.vertex_buffers.ui_counter += 1;
state.queue.write_buffer( state.push_ui_buffer(UiInstance {
&state.vertex_buffers.ui.instances,
UiInstance::SIZE * state.vertex_buffers.ui_counter,
bytemuck::cast_slice(&[UiInstance {
anchor: PositionAnchor::NwNe.to_int(), anchor: PositionAnchor::NwNe.to_int(),
position: Point2::new( position: Point2::new(
(radar_size / 2.0 + 10.0) + d.x, (radar_size / 2.0 + 10.0) + d.x,
@ -279,9 +215,7 @@ impl Radar {
size, size,
color, color,
sprite_index: sprite.get_index(), sprite_index: sprite.get_index(),
}]), });
);
state.vertex_buffers.ui_counter += 1;
} }
// Arrow to center of system // 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)) 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); + 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 { state.push_ui_buffer(UiInstance {
// 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(), anchor: PositionAnchor::NwC.to_int(),
position: position.into(), position: position.into(),
angle, angle,
size: 10.0, size: 10.0,
color: [1.0, 1.0, 1.0, 1f32.min((m - 200.0) / 400.0)], color: [1.0, 1.0, 1.0, 1f32.min((m - 200.0) / 400.0)],
sprite_index: arrow_sprite.get_index(), sprite_index: arrow_sprite.get_index(),
}]), });
);
state.vertex_buffers.ui_counter += 1;
} }
} }
} }

View File

@ -1,14 +1,9 @@
use galactica_system::data::ShipState; use galactica_system::data::ShipState;
use galactica_util::constants::{RADIALBAR_SPRITE_INSTANCE_LIMIT, UI_SPRITE_INSTANCE_LIMIT};
use std::f32::consts::TAU; use std::f32::consts::TAU;
use crate::{ use crate::{
datastructs::RenderState, vertexbuffer::types::{RadialBarInstance, UiInstance},
vertexbuffer::{ PositionAnchor, RenderInput, RenderState,
types::{RadialBarInstance, UiInstance},
BufferObject,
},
PositionAnchor, RenderInput,
}; };
pub(super) struct Status {} pub(super) struct Status {}
@ -20,11 +15,6 @@ impl Status {
impl Status { impl Status {
pub fn draw(&mut self, input: &RenderInput, state: &mut RenderState) { 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 max_shields;
let current_shields; let current_shields;
let current_hull; let current_hull;
@ -55,52 +45,31 @@ impl Status {
} }
} }
state.queue.write_buffer( state.push_ui_buffer(UiInstance {
&state.vertex_buffers.ui.instances,
UiInstance::SIZE * state.vertex_buffers.ui_counter,
bytemuck::cast_slice(&[UiInstance {
anchor: PositionAnchor::NeNe.to_int(), anchor: PositionAnchor::NeNe.to_int(),
position: [-10.0, -10.0], position: [-10.0, -10.0],
angle: 0.0, angle: 0.0,
size: 200.0, size: 200.0,
color: [1.0, 1.0, 1.0, 1.0], color: [1.0, 1.0, 1.0, 1.0],
sprite_index: input.ct.get_sprite_handle("ui::status").get_index(), sprite_index: input.ct.get_sprite_handle("ui::status").get_index(),
}]), });
);
state.vertex_buffers.ui_counter += 1;
// We add two items here, so +2 state.push_radialbar_buffer(RadialBarInstance {
if state.vertex_buffers.radialbar_counter as u64 + 2 > RADIALBAR_SPRITE_INSTANCE_LIMIT {
// TODO: no panic, handle this better.
panic!("Radialbar limit exceeded!")
}
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], position: [-19.0, -19.0],
anchor: PositionAnchor::NeNe.to_int(), anchor: PositionAnchor::NeNe.to_int(),
diameter: 182.0, diameter: 182.0,
stroke: 5.0, stroke: 5.0,
color: [0.3, 0.6, 0.8, 1.0], color: [0.3, 0.6, 0.8, 1.0],
angle: (current_shields / max_shields) * TAU, angle: (current_shields / max_shields) * TAU,
}]), });
);
state.vertex_buffers.radialbar_counter += 1;
state.queue.write_buffer( state.push_radialbar_buffer(RadialBarInstance {
&state.vertex_buffers.radialbar.instances,
RadialBarInstance::SIZE * state.vertex_buffers.radialbar_counter,
bytemuck::cast_slice(&[RadialBarInstance {
position: [-27.0, -27.0], position: [-27.0, -27.0],
anchor: PositionAnchor::NeNe.to_int(), anchor: PositionAnchor::NeNe.to_int(),
diameter: 166.0, diameter: 166.0,
stroke: 5.0, stroke: 5.0,
color: [0.8, 0.7, 0.5, 1.0], color: [0.8, 0.7, 0.5, 1.0],
angle: (current_hull / max_hull) * TAU, angle: (current_hull / max_hull) * TAU,
}]), });
);
state.vertex_buffers.radialbar_counter += 1;
} }
} }