Minor edits
parent
fa46c76fd2
commit
81dc7b170c
|
@ -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()
|
||||
|
|
|
@ -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<f32>,
|
||||
|
@ -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 {
|
||||
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(),
|
||||
}]),
|
||||
);
|
||||
state.vertex_buffers.ui_counter += 1;
|
||||
});
|
||||
|
||||
// Draw system objects
|
||||
let system = input.ct.get_system(input.current_system);
|
||||
|
@ -101,17 +86,8 @@ 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 {
|
||||
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)))
|
||||
|
@ -120,10 +96,8 @@ impl Radar {
|
|||
size,
|
||||
color: [0.5, 0.5, 0.5, 1.0],
|
||||
sprite_index: planet_sprite.get_index(),
|
||||
}]),
|
||||
);
|
||||
state.vertex_buffers.ui_counter += 1;
|
||||
}
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
// 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 {
|
||||
state.push_ui_buffer(UiInstance {
|
||||
anchor: PositionAnchor::NwC.to_int(),
|
||||
position: position.into(),
|
||||
angle: -angle, // TODO: consistent angles
|
||||
angle: r.rotation().angle(),
|
||||
size,
|
||||
color,
|
||||
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 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.queue.write_buffer(
|
||||
&state.vertex_buffers.ui.instances,
|
||||
UiInstance::SIZE * state.vertex_buffers.ui_counter,
|
||||
bytemuck::cast_slice(&[UiInstance {
|
||||
state.push_ui_buffer(UiInstance {
|
||||
anchor: PositionAnchor::NwNw.to_int(),
|
||||
position: Point2::new(
|
||||
(radar_size / 2.0 + 10.0) - d.x,
|
||||
|
@ -225,14 +176,9 @@ impl Radar {
|
|||
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 {
|
||||
state.push_ui_buffer(UiInstance {
|
||||
anchor: PositionAnchor::NwSw.to_int(),
|
||||
position: Point2::new(
|
||||
(radar_size / 2.0 + 10.0) - d.x,
|
||||
|
@ -243,14 +189,9 @@ impl Radar {
|
|||
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 {
|
||||
state.push_ui_buffer(UiInstance {
|
||||
anchor: PositionAnchor::NwSe.to_int(),
|
||||
position: Point2::new(
|
||||
(radar_size / 2.0 + 10.0) + d.x,
|
||||
|
@ -261,14 +202,9 @@ impl Radar {
|
|||
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 {
|
||||
state.push_ui_buffer(UiInstance {
|
||||
anchor: PositionAnchor::NwNe.to_int(),
|
||||
position: Point2::new(
|
||||
(radar_size / 2.0 + 10.0) + d.x,
|
||||
|
@ -279,9 +215,7 @@ impl Radar {
|
|||
size,
|
||||
color,
|
||||
sprite_index: sprite.get_index(),
|
||||
}]),
|
||||
);
|
||||
state.vertex_buffers.ui_counter += 1;
|
||||
});
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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(),
|
||||
}]),
|
||||
);
|
||||
state.vertex_buffers.ui_counter += 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
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(),
|
||||
}]),
|
||||
);
|
||||
state.vertex_buffers.ui_counter += 1;
|
||||
});
|
||||
|
||||
// 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.queue.write_buffer(
|
||||
&state.vertex_buffers.radialbar.instances,
|
||||
RadialBarInstance::SIZE * state.vertex_buffers.radialbar_counter,
|
||||
bytemuck::cast_slice(&[RadialBarInstance {
|
||||
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.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 {
|
||||
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,
|
||||
}]),
|
||||
);
|
||||
state.vertex_buffers.radialbar_counter += 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue