Skip to content

Commit

Permalink
Add wrapper for render and resolve logic
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed Feb 13, 2024
1 parent c553593 commit 7a17707
Show file tree
Hide file tree
Showing 23 changed files with 291 additions and 229 deletions.
20 changes: 10 additions & 10 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,16 @@ impl InputSystem {

ClickAction::MoveItem(item_source, item) => {
self.mouse_input_mode = MouseInputMode::MoveItem(item_source, item);
// Needs to rerender because some elements will render differently
// Needs to re-render because some elements will render differently
// based on the mouse input mode.
interface.schedule_rerender();
interface.schedule_render();
}

ClickAction::MoveSkill(skill_source, skill) => {
self.mouse_input_mode = MouseInputMode::MoveSkill(skill_source, skill);
// Needs to rerender because some elements will render differently
// Needs to re-render because some elements will render differently
// based on the mouse input mode.
interface.schedule_rerender();
interface.schedule_render();
}

ClickAction::OpenWindow(prototype_window) => interface.open_window(focus_state, prototype_window.as_ref()),
Expand All @@ -315,9 +315,9 @@ impl InputSystem {
}
} else {
let mouse_input_mode = std::mem::take(&mut self.mouse_input_mode);
// Needs to rerender because some elements will render differently
// Needs to re-render because some elements will render differently
// based on the mouse input mode.
interface.schedule_rerender();
interface.schedule_render();

match mouse_input_mode {
MouseInputMode::MoveItem(item_source, item) => {
Expand Down Expand Up @@ -641,21 +641,21 @@ impl InputSystem {

if focus_state.did_hovered_element_change(&hovered_element) {
if let Some(window_index) = focus_state.previous_hovered_window() {
interface.schedule_rerender_window(window_index);
interface.schedule_render_window(window_index);
}

if let Some(window_index) = window_index {
interface.schedule_rerender_window(window_index);
interface.schedule_render_window(window_index);
}
}

if focus_state.did_focused_element_change() {
if let Some(window_index) = focus_state.previous_focused_window() {
interface.schedule_rerender_window(window_index);
interface.schedule_render_window(window_index);
}

if let Some(window_index) = focus_state.focused_window() {
interface.schedule_rerender_window(window_index);
interface.schedule_render_window(window_index);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/containers/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Element for CharacterPreview {
// scrolling would break
self.state.link_back(weak_self, weak_parent);

return Some(ChangeEvent::RERESOLVE_WINDOW);
return Some(ChangeEvent::RESOLVE_WINDOW);
}

None
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/containers/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Element for DialogContainer {

// TODO: link back like in character container

return Some(ChangeEvent::RERESOLVE_WINDOW);
return Some(ChangeEvent::RESOLVE_WINDOW);
}

None
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/containers/equipment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Element for EquipmentContainer {
// scrolling would break
self.link_back(weak_self, weak_parent);

return Some(ChangeEvent::RERESOLVE_WINDOW);
return Some(ChangeEvent::RESOLVE_WINDOW);
}

None
Expand Down
10 changes: 5 additions & 5 deletions src/interface/elements/containers/friends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Element for FriendView {
}

fn update(&mut self) -> Option<ChangeEvent> {
let mut reresolve = false;
let mut resolve = false;

if self.friends.consume_changed() {
// Remove elements of old friends from the start of the list and add new friends
Expand All @@ -110,20 +110,20 @@ impl Element for FriendView {
element.borrow_mut().link_back(Rc::downgrade(&element), self.weak_self.clone());

self.state.elements.insert(index, element);
reresolve = true;
resolve = true;
}
});

// Remove elements of old friends from the end of the list.
let friend_count = self.friends.borrow().len();
if friend_count < self.state.elements.len() {
self.state.elements.truncate(friend_count);
reresolve = true;
resolve = true;
}
}

match reresolve {
true => Some(ChangeEvent::RERESOLVE_WINDOW),
match resolve {
true => Some(ChangeEvent::RESOLVE_WINDOW),
false => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/containers/hotbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Element for HotbarContainer {
// scrolling would break
self.link_back(weak_self, weak_parent);

return Some(ChangeEvent::RERESOLVE_WINDOW);
return Some(ChangeEvent::RESOLVE_WINDOW);
}

None
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/containers/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Element for InventoryContainer {
// scrolling would break
self.link_back(weak_self, weak_parent);

return Some(ChangeEvent::RERESOLVE_WINDOW);
return Some(ChangeEvent::RESOLVE_WINDOW);
}

None
Expand Down
16 changes: 8 additions & 8 deletions src/interface/elements/containers/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<const N: usize> Element for PacketView<N> {
}

fn update(&mut self) -> Option<ChangeEvent> {
let mut reresolve = false;
let mut resolve = false;

if self.show_pings.consume_changed() | self.packets.consume_changed() {
fn compare(linked_element: &UnsafeCell<Option<WeakElementCell>>, element: &ElementCell) -> bool {
Expand All @@ -196,15 +196,15 @@ impl<const N: usize> Element for PacketView<N> {
for _index in 0..self.state.elements.len() {
if !std::ptr::addr_eq(first_visible_element, Rc::downgrade(&self.state.elements[0]).as_ptr()) {
self.state.elements.remove(0);
reresolve = true;
resolve = true;
} else {
break;
}
}
} else {
// This means that there are no visible packets at all, so remove every element.
self.state.elements.clear();
reresolve = true;
resolve = true;
}

let show_pings = *self.show_pings.borrow();
Expand All @@ -226,15 +226,15 @@ impl<const N: usize> Element for PacketView<N> {
element.borrow_mut().link_back(Rc::downgrade(&element), self.weak_self.clone());

self.state.elements.insert(index, element);
reresolve = true;
resolve = true;
}

// Packet was previously visible but now should be hidden.
if !show_packet && !was_hidden {
*linked_element = Rc::downgrade(&self.hidden_element);

self.state.elements.remove(index);
reresolve = true;
resolve = true;
}
} else {
// Getting here means thatt the packet was newly added.
Expand All @@ -245,7 +245,7 @@ impl<const N: usize> Element for PacketView<N> {
element.borrow_mut().link_back(Rc::downgrade(&element), self.weak_self.clone());

self.state.elements.push(element);
reresolve = true;
resolve = true;
}
false => {
unsafe { *linked_element.get() = Some(Rc::downgrade(&self.hidden_element)) };
Expand All @@ -259,8 +259,8 @@ impl<const N: usize> Element for PacketView<N> {
});
}

match reresolve {
true => Some(ChangeEvent::RERESOLVE_WINDOW),
match resolve {
true => Some(ChangeEvent::RESOLVE_WINDOW),
false => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/containers/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Element for ScrollView {
fn scroll(&mut self, delta: f32) -> Option<ChangeEvent> {
self.scroll -= delta * SCROLL_SPEED;
self.scroll = self.scroll.max(0.0);
Some(ChangeEvent::RERENDER_WINDOW)
Some(ChangeEvent::RENDER_WINDOW)
}

fn render(
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/containers/skill_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Element for SkillTreeContainer {
// scrolling would break
self.link_back(weak_self, weak_parent);

return Some(ChangeEvent::RERESOLVE_WINDOW);
return Some(ChangeEvent::RESOLVE_WINDOW);
}

None
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/miscellanious/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Element for Chat {

if messages.len() != self.cached_message_count {
self.cached_message_count = messages.len();
return Some(ChangeEvent::RERESOLVE_WINDOW);
return Some(ChangeEvent::RESOLVE_WINDOW);
}

None
Expand Down
4 changes: 2 additions & 2 deletions src/interface/elements/miscellanious/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<const LENGTH: usize, const HIDDEN: bool> InputField<LENGTH, HIDDEN> {
}

display.pop();
Some(ClickAction::ChangeEvent(ChangeEvent::RERENDER_WINDOW))
Some(ClickAction::ChangeEvent(ChangeEvent::RENDER_WINDOW))
}

fn add_character(&mut self, character: char) -> Option<ClickAction> {
Expand All @@ -38,7 +38,7 @@ impl<const LENGTH: usize, const HIDDEN: bool> InputField<LENGTH, HIDDEN> {
}

display.push(character);
Some(ClickAction::ChangeEvent(ChangeEvent::RERENDER_WINDOW))
Some(ClickAction::ChangeEvent(ChangeEvent::RENDER_WINDOW))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/miscellanious/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<T: Zero + NumOps + NumCast + Copy + PartialOrd> Element for Slider<T> {

if self.cached_value != current_value {
self.cached_value = current_value;
return Some(ChangeEvent::RERENDER_WINDOW);
return Some(ChangeEvent::RENDER_WINDOW);
}

None
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/profiler/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Element for FrameView {

if *self.always_update.borrow() || self.frame_counter == SAVED_FRAME_COUNT {
self.frame_counter = 0;
return Some(ChangeEvent::RERENDER_WINDOW);
return Some(ChangeEvent::RENDER_WINDOW);
}

None
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/profiler/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl Element for FrameInspectorView {
self.start_offset += total_offset.mul_f32(side_bias);
}

Some(ChangeEvent::RERENDER_WINDOW)
Some(ChangeEvent::RENDER_WINDOW)
}

fn render(
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/values/mutable/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Element for MutableColorValue {
"{}, {}, {}, {}",
self.cached_color.red, self.cached_color.green, self.cached_color.blue, self.cached_color.alpha
);
return Some(ChangeEvent::RERENDER_WINDOW);
return Some(ChangeEvent::RENDER_WINDOW);
}

None
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/values/mutable/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<T: Zero + NumOps + NumCast + Copy + PartialOrd + Display + 'static> Element
if self.cached_inner != current_value {
self.cached_inner = current_value;
self.cached_values = format!("{:.1}", self.cached_inner);
return Some(ChangeEvent::RERENDER_WINDOW);
return Some(ChangeEvent::RENDER_WINDOW);
}

None
Expand Down
2 changes: 1 addition & 1 deletion src/interface/elements/values/mutable/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
if self.cached_inner != current_value {
self.cached_inner = current_value;
self.cached_values = self.cached_inner.display();
return Some(ChangeEvent::RERENDER_WINDOW);
return Some(ChangeEvent::RENDER_WINDOW);
}

None
Expand Down
20 changes: 10 additions & 10 deletions src/interface/event/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ use bitflags::bitflags;
bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct ChangeEvent: u8 {
const RERENDER_WINDOW = 0b00000001;
const RERESOLVE_WINDOW = 0b00000010;
const RERENDER = 0b00000100;
const RERESOLVE = 0b00001000;
const RENDER_WINDOW = 0b00000001;
const RESOLVE_WINDOW = 0b00000010;
const RENDER = 0b00000100;
const RESOLVE = 0b00001000;
}
}

pub trait IntoChangeEvent {
fn into_change_event() -> Option<ChangeEvent>;
}

pub struct Rerender {}
pub struct Reresolve {}
pub struct Render {}
pub struct Resolve {}
pub struct Nothing {}

impl IntoChangeEvent for Rerender {
impl IntoChangeEvent for Render {
fn into_change_event() -> Option<ChangeEvent> {
Some(ChangeEvent::RERENDER)
Some(ChangeEvent::RENDER)
}
}

impl IntoChangeEvent for Reresolve {
impl IntoChangeEvent for Resolve {
fn into_change_event() -> Option<ChangeEvent> {
Some(ChangeEvent::RERESOLVE)
Some(ChangeEvent::RESOLVE)
}
}

Expand Down
Loading

0 comments on commit 7a17707

Please sign in to comment.