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, anchor: PositionAnchor::NwNw.to_int(),
UiInstance::SIZE * state.vertex_buffers.ui_counter, position: [10.0, -10.0],
bytemuck::cast_slice(&[UiInstance { angle: 0.0,
anchor: PositionAnchor::NwNw.to_int(), size: radar_size,
position: [10.0, -10.0], color: [1.0, 1.0, 1.0, 1.0],
angle: 0.0, sprite_index: input.ct.get_sprite_handle("ui::radar").get_index(),
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;
// 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,29 +86,18 @@ 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, anchor: PositionAnchor::NwC.to_int(),
UiInstance::SIZE * state.vertex_buffers.ui_counter, position: (Point2::new(radar_size / 2.0 + 10.0, radar_size / -2.0 - 10.0)
bytemuck::cast_slice(&[UiInstance { + (d * (radar_size / 2.0)))
anchor: PositionAnchor::NwC.to_int(), .into(),
position: (Point2::new(radar_size / 2.0 + 10.0, radar_size / -2.0 - 10.0) angle: o.angle,
+ (d * (radar_size / 2.0))) size,
.into(), color: [0.5, 0.5, 0.5, 1.0],
angle: o.angle, sprite_index: planet_sprite.get_index(),
size, })
color: [0.5, 0.5, 0.5, 1.0], };
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. anchor: PositionAnchor::NwC.to_int(),
if state.vertex_buffers.ui_counter as u64 > UI_SPRITE_INSTANCE_LIMIT { position: position.into(),
// TODO: no panic, handle this better. angle: r.rotation().angle(),
panic!("UI limit exceeded!") size,
} color,
sprite_index: ship_sprite.get_index(),
// 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;
} }
} }
@ -205,83 +165,57 @@ 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 { anchor: PositionAnchor::NwNw.to_int(),
// TODO: no panic, handle this better. position: Point2::new(
panic!("UI limit exceeded!") (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.push_ui_buffer(UiInstance {
&state.vertex_buffers.ui.instances, anchor: PositionAnchor::NwSw.to_int(),
UiInstance::SIZE * state.vertex_buffers.ui_counter, position: Point2::new(
bytemuck::cast_slice(&[UiInstance { (radar_size / 2.0 + 10.0) - d.x,
anchor: PositionAnchor::NwNw.to_int(), (radar_size / -2.0 - 10.0) - d.y,
position: Point2::new( )
(radar_size / 2.0 + 10.0) - d.x, .into(),
(radar_size / -2.0 - 10.0) + d.y, angle: to_radians(180.0),
) size,
.into(), color,
angle: to_radians(90.0), sprite_index: sprite.get_index(),
size, });
color,
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, anchor: PositionAnchor::NwSe.to_int(),
UiInstance::SIZE * state.vertex_buffers.ui_counter, position: Point2::new(
bytemuck::cast_slice(&[UiInstance { (radar_size / 2.0 + 10.0) + d.x,
anchor: PositionAnchor::NwSw.to_int(), (radar_size / -2.0 - 10.0) - d.y,
position: Point2::new( )
(radar_size / 2.0 + 10.0) - d.x, .into(),
(radar_size / -2.0 - 10.0) - d.y, angle: to_radians(270.0),
) size,
.into(), color,
angle: to_radians(180.0), sprite_index: sprite.get_index(),
size, });
color,
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, anchor: PositionAnchor::NwNe.to_int(),
UiInstance::SIZE * state.vertex_buffers.ui_counter, position: Point2::new(
bytemuck::cast_slice(&[UiInstance { (radar_size / 2.0 + 10.0) + d.x,
anchor: PositionAnchor::NwSe.to_int(), (radar_size / -2.0 - 10.0) + d.y,
position: Point2::new( )
(radar_size / 2.0 + 10.0) + d.x, .into(),
(radar_size / -2.0 - 10.0) - d.y, angle: to_radians(0.0),
) size,
.into(), color,
angle: to_radians(270.0), sprite_index: sprite.get_index(),
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;
} }
// 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. anchor: PositionAnchor::NwC.to_int(),
panic!("UI limit exceeded!") position: position.into(),
} angle,
size: 10.0,
state.queue.write_buffer( color: [1.0, 1.0, 1.0, 1f32.min((m - 200.0) / 400.0)],
&state.vertex_buffers.ui.instances, sprite_index: arrow_sprite.get_index(),
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;
} }
} }
} }

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, anchor: PositionAnchor::NeNe.to_int(),
UiInstance::SIZE * state.vertex_buffers.ui_counter, position: [-10.0, -10.0],
bytemuck::cast_slice(&[UiInstance { angle: 0.0,
anchor: PositionAnchor::NeNe.to_int(), size: 200.0,
position: [-10.0, -10.0], color: [1.0, 1.0, 1.0, 1.0],
angle: 0.0, sprite_index: input.ct.get_sprite_handle("ui::status").get_index(),
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;
// 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 { position: [-19.0, -19.0],
// TODO: no panic, handle this better. anchor: PositionAnchor::NeNe.to_int(),
panic!("Radialbar limit exceeded!") 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.push_radialbar_buffer(RadialBarInstance {
&state.vertex_buffers.radialbar.instances, position: [-27.0, -27.0],
RadialBarInstance::SIZE * state.vertex_buffers.radialbar_counter, anchor: PositionAnchor::NeNe.to_int(),
bytemuck::cast_slice(&[RadialBarInstance { diameter: 166.0,
position: [-19.0, -19.0], stroke: 5.0,
anchor: PositionAnchor::NeNe.to_int(), color: [0.8, 0.7, 0.5, 1.0],
diameter: 182.0, angle: (current_hull / max_hull) * TAU,
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;
} }
} }