fixed clippy warnings

This commit is contained in:
Dmitry
2019-08-17 11:11:21 +03:00
parent fbec1c35cd
commit ff31f24838
20 changed files with 24420 additions and 21688 deletions
+14 -2
View File
@@ -6,13 +6,25 @@
<component name="ChangeListManager">
<list default="true" id="1932b2c4-d6ff-413c-9558-19959667326b" name="Default Changelist" comment="scene graph">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/save.json" beforeDir="false" afterPath="$PROJECT_DIR$/save.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/game/level.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/game/level.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/engine/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/engine/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/game/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/game/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/game/player.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/game/player.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/gui/draw.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/gui/draw.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/gui/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/gui/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/math/mat4.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/math/mat4.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/math/triangulator.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/math/triangulator.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/math/vec2.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/math/vec2.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/physics/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/physics/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/renderer/gl.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/renderer/gl.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/renderer/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/renderer/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/renderer/renderer.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/renderer/render.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/renderer/surface.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/renderer/surface.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/resource/fbx/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/resource/fbx/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/resource/ttf.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/resource/ttf.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/scene/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/scene/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils/pool.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/pool.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils/rcpool.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/rcpool.rs" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
+3 -3
View File
@@ -8,7 +8,7 @@ use crate::{
}
},
renderer::{
renderer::*,
render::*,
surface::SurfaceSharedData
},
resource::{
@@ -345,7 +345,7 @@ impl Engine {
scene.update(aspect_ratio, dt);
}
self.user_interface.update(&Vec2::make(client_size.width as f32, client_size.height as f32));
self.user_interface.update(Vec2::make(client_size.width as f32, client_size.height as f32));
}
pub fn poll_events(&mut self) {
@@ -410,7 +410,7 @@ impl Engine {
}
pub fn duration_to_seconds_f64(duration: Duration) -> f64 {
duration.as_secs() as f64 + duration.subsec_nanos() as f64 / 1_000_000_000.0
duration.as_secs() as f64 + f64::from(duration.subsec_nanos()) / 1_000_000_000.0
}
pub fn duration_to_seconds_f32(duration: Duration) -> f32 {
+9 -4
View File
@@ -85,6 +85,11 @@ impl Game {
.with_desired_position(Vec2::make(550.0, 300.0))
.with_width(300.0)
.with_height(200.0)
.with_content(ButtonBuilder::new()
.with_width(300.0)
.with_height(300.0)
.with_text("TEST BUTTON")
.build(ui))
.build(ui);
GridBuilder::new()
@@ -203,20 +208,20 @@ impl Game {
pub fn update_menu(&mut self) {
if let Ok(mut state) = self.menu.state.clone().try_borrow_mut() {
if let Some(_) = state.start_new_game.take() {
if state.start_new_game.take().is_some() {
self.start_new_game();
}
if let Some(_) = state.quit_game.take() {
if state.quit_game.take().is_some() {
self.destroy_level();
self.engine.stop();
}
if let Some(_) = state.save_game.take() {
if state.save_game.take().is_some() {
self.save_game();
}
if let Some(_) = state.load_game.take() {
if state.load_game.take().is_some() {
self.load_game();
}
}
+12 -18
View File
@@ -266,31 +266,25 @@ impl Player {
}
WindowEvent::MouseInput { button, state, .. } => {
match button {
MouseButton::Left => {
match state {
ElementState::Pressed => {
self.controller.shoot = true;
}
ElementState::Released => {
self.controller.shoot = false;
}
if let MouseButton::Left = button {
match state {
ElementState::Pressed => {
self.controller.shoot = true;
}
ElementState::Released => {
self.controller.shoot = false;
}
}
_ => ()
}
}
WindowEvent::MouseWheel { delta, .. } => {
match delta {
MouseScrollDelta::LineDelta(_, y) => {
if *y < 0.0 {
self.prev_weapon();
} else if *y > 0.0 {
self.next_weapon();
}
if let MouseScrollDelta::LineDelta(_, y) = delta {
if *y < 0.0 {
self.prev_weapon();
} else if *y > 0.0 {
self.next_weapon();
}
_ => ()
}
}
+25 -25
View File
@@ -152,7 +152,7 @@ impl FormattedText {
}
}
fn build(&mut self, text: &str, font: &Font, size: &Vec2, color: Color,
fn build(&mut self, text: &str, font: &Font, size: Vec2, color: Color,
vertical_alignment: VerticalAlignment, horizontal_alignment: HorizontalAlignment) {
// Convert text to UTF32.
self.text.clear();
@@ -170,10 +170,10 @@ impl FormattedText {
Some(glyph) => glyph.get_advance(),
None => font.get_height()
};
let is_new_line = *code == b'\n' as u32 || *code == '\r' as u32;
let is_new_line = *code == u32::from(b'\n') || *code == u32::from(b'\r');
let new_width = current_line.width + advance;
if new_width > size.x || is_new_line {
self.lines.push(current_line.clone());
self.lines.push(current_line);
current_line.begin = if is_new_line { i + 1 } else { i };
current_line.end = current_line.begin + 1;
current_line.width = advance;
@@ -231,7 +231,7 @@ impl FormattedText {
};
let text_glyph = TextGlyph {
bounds: rect,
tex_coords: glyph.get_tex_coords().clone(),
tex_coords: *glyph.get_tex_coords(),
color,
};
self.glyphs.push(text_glyph);
@@ -343,7 +343,7 @@ impl<'a> FormattedTextBuilder<'a> {
self.formatted_text.build(
text,
font,
&self.size,
self.size,
self.color,
self.vertical_alignment,
self.horizontal_alignment,
@@ -355,8 +355,8 @@ impl<'a> FormattedTextBuilder<'a> {
}
}
fn get_line_thickness_vector(a: &Vec2, b: &Vec2, thickness: f32) -> Vec2 {
if let Some(dir) = (*b - *a).normalized() {
fn get_line_thickness_vector(a: Vec2, b: Vec2, thickness: f32) -> Vec2 {
if let Some(dir) = (b - a).normalized() {
dir.perpendicular().scale(thickness * 0.5)
} else {
Vec2::new()
@@ -458,7 +458,7 @@ impl DrawingContext {
&self.command_buffer
}
pub fn is_command_contains_point(&self, command: &Command, pos: &Vec2) -> bool {
pub fn is_command_contains_point(&self, command: &Command, pos: Vec2) -> bool {
let last = command.index_offset + command.triangle_count * 3;
// Check each triangle from command for intersection with mouse pointer
@@ -479,7 +479,7 @@ impl DrawingContext {
// Check if point is in triangle.
let v0 = vc.pos - va.pos;
let v1 = vb.pos - va.pos;
let v2 = *pos - va.pos;
let v2 = pos - va.pos;
let dot00 = v0.dot(v0);
let dot01 = v0.dot(v1);
@@ -506,12 +506,12 @@ impl DrawingContext {
false
}
pub fn push_line(&mut self, a: &Vec2, b: &Vec2, thickness: f32, color: Color) {
pub fn push_line(&mut self, a: Vec2, b: Vec2, thickness: f32, color: Color) {
let perp = get_line_thickness_vector(a, b, thickness);
self.push_vertex(*a - perp, Vec2::make(0.0, 0.0), color);
self.push_vertex(*b - perp, Vec2::make(1.0, 0.0), color);
self.push_vertex(*a + perp, Vec2::make(1.0, 1.0), color);
self.push_vertex(*b + perp, Vec2::make(0.0, 1.0), color);
self.push_vertex(a - perp, Vec2::make(0.0, 0.0), color);
self.push_vertex(b - perp, Vec2::make(1.0, 0.0), color);
self.push_vertex(a + perp, Vec2::make(1.0, 1.0), color);
self.push_vertex(b + perp, Vec2::make(0.0, 1.0), color);
let index = self.get_index_origin();
self.push_triangle(index, index + 1, index + 2);
@@ -531,12 +531,12 @@ impl DrawingContext {
let left_bottom_off = Vec2::make(rect.x, rect.y + rect.h - offset);
// Horizontal lines
self.push_line(&left_top_off, &right_top_off, thickness, color);
self.push_line(&right_bottom_off, &left_bottom_off, thickness, color);
self.push_line(left_top_off, right_top_off, thickness, color);
self.push_line(right_bottom_off, left_bottom_off, thickness, color);
// Vertical lines
self.push_line(&right_top, &right_bottom, thickness, color);
self.push_line(&left_bottom, &left_top, thickness, color);
// Vertical line
self.push_line(right_top, right_bottom, thickness, color);
self.push_line(left_bottom, left_top, thickness, color);
}
pub fn push_rect_vary(&mut self, rect: &Rect<f32>, thickness: Thickness, color: Color) {
@@ -550,12 +550,12 @@ impl DrawingContext {
let left_bottom_off = Vec2::make(rect.x, rect.y + rect.h - thickness.bottom * 0.5);
// Horizontal lines
self.push_line(&left_top_off, &right_top_off, thickness.top, color);
self.push_line(&right_bottom_off, &left_bottom_off, thickness.bottom, color);
self.push_line(left_top_off, right_top_off, thickness.top, color);
self.push_line(right_bottom_off, left_bottom_off, thickness.bottom, color);
// Vertical lines
self.push_line(&right_top, &right_bottom, thickness.right, color);
self.push_line(&left_bottom, &left_top, thickness.left, color);
self.push_line(right_top, right_bottom, thickness.right, color);
self.push_line(left_bottom, left_top, thickness.left, color);
}
pub fn push_rect_filled(&mut self, rect: &Rect<f32>, tex_coords: Option<&[Vec2; 4]>, color: Color) {
@@ -575,7 +575,7 @@ impl DrawingContext {
kind,
texture,
nesting: self.current_nesting,
index_offset: if self.index_buffer.len() > 0 {
index_offset: if !self.index_buffer.is_empty() {
self.index_buffer.len() - self.triangles_to_commit * 3
} else { 0 },
triangle_count: self.triangles_to_commit,
@@ -616,7 +616,7 @@ impl DrawingContext {
if let Some(last_clip_command) = self.command_buffer.get(*last_index) {
assert_eq!(last_clip_command.kind, CommandKind::Clip);
// Re-commit last clipping command
let clip_command = last_clip_command.clone();
let clip_command = *last_clip_command;
self.command_buffer.push(clip_command);
}
}
+235 -238
View File
@@ -23,12 +23,7 @@ use crate::{
},
math,
};
use glutin::{
VirtualKeyCode,
MouseButton,
WindowEvent,
ElementState,
};
use glutin::{VirtualKeyCode, MouseButton, WindowEvent, ElementState, MouseScrollDelta};
use std::collections::VecDeque;
use std::cell::{Cell, RefCell};
use std::any::{TypeId, Any};
@@ -464,8 +459,8 @@ impl BorderBuilder {
}
trait Layout {
fn measure_override(&self, ui: &UserInterface, available_size: &Vec2) -> Vec2;
fn arrange_override(&self, ui: &UserInterface, final_size: &Vec2) -> Vec2;
fn measure_override(&self, ui: &UserInterface, available_size: Vec2) -> Vec2;
fn arrange_override(&self, ui: &UserInterface, final_size: Vec2) -> Vec2;
}
trait Drawable {
@@ -488,7 +483,7 @@ impl Drawable for Border {
}
impl Layout for Border {
fn measure_override(&self, ui: &UserInterface, available_size: &Vec2) -> Vec2 {
fn measure_override(&self, ui: &UserInterface, available_size: Vec2) -> Vec2 {
let margin_x = self.stroke_thickness.left + self.stroke_thickness.right;
let margin_y = self.stroke_thickness.top + self.stroke_thickness.bottom;
@@ -500,7 +495,7 @@ impl Layout for Border {
if let Some(node) = ui.nodes.borrow(&self.owner_handle) {
for child_handle in node.children.iter() {
ui.measure(child_handle, &size_for_child);
ui.measure(child_handle, size_for_child);
if let Some(child) = ui.nodes.borrow(child_handle) {
let child_desired_size = child.desired_size.get();
@@ -520,7 +515,7 @@ impl Layout for Border {
desired_size
}
fn arrange_override(&self, ui: &UserInterface, final_size: &Vec2) -> Vec2 {
fn arrange_override(&self, ui: &UserInterface, final_size: Vec2) -> Vec2 {
let rect_for_child = Rect::new(
self.stroke_thickness.left, self.stroke_thickness.top,
final_size.x - (self.stroke_thickness.right + self.stroke_thickness.left),
@@ -533,7 +528,7 @@ impl Layout for Border {
}
}
*final_size
final_size
}
}
@@ -830,11 +825,11 @@ impl ScrollBar {
}
impl Layout for ScrollBar {
fn measure_override(&self, ui: &UserInterface, available_size: &Vec2) -> Vec2 {
fn measure_override(&self, ui: &UserInterface, available_size: Vec2) -> Vec2 {
ui.default_measure_override(&self.owner_handle, available_size)
}
fn arrange_override(&self, ui: &UserInterface, final_size: &Vec2) -> Vec2 {
fn arrange_override(&self, ui: &UserInterface, final_size: Vec2) -> Vec2 {
let size = ui.default_arrange_override(&self.owner_handle, final_size);
@@ -1170,7 +1165,7 @@ pub struct ScrollContentPresenter {
}
impl Layout for ScrollContentPresenter {
fn measure_override(&self, ui: &UserInterface, available_size: &Vec2) -> Vec2 {
fn measure_override(&self, ui: &UserInterface, available_size: Vec2) -> Vec2 {
let size_for_child = Vec2::make(
if self.horizontal_scroll_allowed {
std::f32::INFINITY
@@ -1188,7 +1183,7 @@ impl Layout for ScrollContentPresenter {
if let Some(node) = ui.nodes.borrow(&self.owner_handle) {
for child_handle in node.children.iter() {
ui.measure(child_handle, &size_for_child);
ui.measure(child_handle, size_for_child);
if let Some(child) = ui.nodes.borrow(child_handle) {
let child_desired_size = child.desired_size.get();
@@ -1205,7 +1200,7 @@ impl Layout for ScrollContentPresenter {
desired_size
}
fn arrange_override(&self, ui: &UserInterface, final_size: &Vec2) -> Vec2 {
fn arrange_override(&self, ui: &UserInterface, final_size: Vec2) -> Vec2 {
let child_rect = Rect::new(
-self.scroll.x,
-self.scroll.y,
@@ -1219,7 +1214,7 @@ impl Layout for ScrollContentPresenter {
}
}
*final_size
final_size
}
}
@@ -1261,7 +1256,7 @@ impl ScrollContentPresenter {
pub struct ScrollContentPresenterBuilder {
vertical_scroll_allowed: Option<bool>,
horizontal_scroll_allowed: Option<bool>,
content: Option<Handle<UINode>>,
content: Handle<UINode>,
common: CommonBuilderFields,
}
@@ -1271,14 +1266,14 @@ impl ScrollContentPresenterBuilder {
vertical_scroll_allowed: None,
horizontal_scroll_allowed: None,
common: CommonBuilderFields::new(),
content: None,
content: Handle::none(),
}
}
impl_default_builder_methods!();
pub fn with_content(mut self, content: Handle<UINode>) -> Self {
self.content = Some(content);
self.content = content;
self
}
@@ -1301,13 +1296,14 @@ impl ScrollContentPresenterBuilder {
scp.horizontal_scroll_allowed = horizontal_scroll_allowed;
}
GenericNodeBuilder::new(UINodeKind::ScrollContentPresenter(scp), self.common)
.with_child(self.content.unwrap_or(Handle::none()))
.with_child(self.content)
.build(ui)
}
}
pub struct ScrollViewer {
owner_handle: Handle<UINode>,
content: Handle<UINode>,
content_presenter: Handle<UINode>,
v_scroll_bar: Handle<UINode>,
h_scroll_bar: Handle<UINode>,
@@ -1349,31 +1345,27 @@ impl ScrollViewer {
pub struct ScrollViewerBuilder {
common: CommonBuilderFields,
content: Option<Handle<UINode>>,
content: Handle<UINode>,
}
impl ScrollViewerBuilder {
pub fn new() -> Self {
Self {
common: CommonBuilderFields::new(),
content: None,
content: Handle::none(),
}
}
impl_default_builder_methods!();
pub fn with_content(mut self, content: Handle<UINode>) -> Self {
self.content = Some(content);
self.content = content;
self
}
pub fn build(self, ui: &mut UserInterface) -> Handle<UINode> {
let content_presenter = ScrollContentPresenterBuilder::new()
.with_child(ButtonBuilder::new()
.with_text("TEST CONTENT")
.with_width(300.0)
.with_height(300.0)
.build(ui))
.with_child(self.content.clone())
.on_row(0)
.on_column(0)
.build(ui);
@@ -1402,7 +1394,8 @@ impl ScrollViewerBuilder {
})
.build(ui);
let mut scroll_viewer = ScrollViewer {
let scroll_viewer = ScrollViewer {
content: self.content.clone(),
owner_handle: Handle::none(),
v_scroll_bar: v_scroll_bar.clone(),
h_scroll_bar: h_scroll_bar.clone(),
@@ -1537,7 +1530,7 @@ impl Grid {
}
impl Layout for Grid {
fn measure_override(&self, ui: &UserInterface, available_size: &Vec2) -> Vec2 {
fn measure_override(&self, ui: &UserInterface, available_size: Vec2) -> Vec2 {
// In case of no rows or columns, grid acts like default panel.
if self.columns.borrow().is_empty() || self.rows.borrow().is_empty() {
return ui.default_measure_override(&self.owner_handle, available_size);
@@ -1689,7 +1682,7 @@ impl Layout for Grid {
}
}
};
ui.measure(child_handle, &size_for_child);
ui.measure(child_handle, size_for_child);
}
// Step 4. Calculate desired size of grid.
@@ -1704,14 +1697,14 @@ impl Layout for Grid {
desired_size
}
fn arrange_override(&self, ui: &UserInterface, final_size: &Vec2) -> Vec2 {
fn arrange_override(&self, ui: &UserInterface, final_size: Vec2) -> Vec2 {
if let Some(node) = ui.nodes.borrow(&self.owner_handle) {
if self.columns.borrow().is_empty() || self.rows.borrow().is_empty() {
let rect = Rect::new(0.0, 0.0, final_size.x, final_size.y);
for child_handle in node.children.iter() {
ui.arrange(child_handle, &rect);
}
return *final_size;
return final_size;
}
for child_handle in node.children.iter() {
@@ -1736,7 +1729,7 @@ impl Layout for Grid {
}
}
*final_size
final_size
}
}
@@ -1815,7 +1808,7 @@ impl Canvas {
}
impl Layout for Canvas {
fn measure_override(&self, ui: &UserInterface, _available_size: &Vec2) -> Vec2 {
fn measure_override(&self, ui: &UserInterface, _available_size: Vec2) -> Vec2 {
let size_for_child = Vec2::make(
std::f32::INFINITY,
std::f32::INFINITY,
@@ -1823,14 +1816,14 @@ impl Layout for Canvas {
if let Some(node) = ui.nodes.borrow(&self.owner_handle) {
for child_handle in node.children.iter() {
ui.measure(child_handle, &size_for_child);
ui.measure(child_handle, size_for_child);
}
}
Vec2::new()
}
fn arrange_override(&self, ui: &UserInterface, final_size: &Vec2) -> Vec2 {
fn arrange_override(&self, ui: &UserInterface, final_size: Vec2) -> Vec2 {
if let Some(node) = ui.nodes.borrow(&self.owner_handle) {
for child_handle in node.children.iter() {
let mut final_rect = None;
@@ -1849,7 +1842,7 @@ impl Layout for Canvas {
}
}
*final_size
final_size
}
}
@@ -1885,6 +1878,7 @@ pub enum RoutedEventHandlerType {
MouseLeave,
MouseDown,
MouseUp,
MouseWheel,
Count,
}
@@ -1960,7 +1954,7 @@ pub enum RoutedEventKind {
},
MouseWheel {
pos: Vec2,
amount: u32,
amount: f32,
},
MouseLeave,
MouseEnter,
@@ -2124,12 +2118,12 @@ impl UserInterface {
&mut self.drawing_context
}
fn default_measure_override(&self, handle: &Handle<UINode>, available_size: &Vec2) -> Vec2 {
fn default_measure_override(&self, handle: &Handle<UINode>, available_size: Vec2) -> Vec2 {
let mut size = Vec2::new();
if let Some(node) = self.nodes.borrow(handle) {
for child_handle in node.children.iter() {
self.measure(child_handle, &available_size);
self.measure(child_handle, available_size);
if let Some(child) = self.nodes.borrow(child_handle) {
let child_desired_size = child.desired_size.get();
@@ -2146,97 +2140,94 @@ impl UserInterface {
size
}
fn measure(&self, node_handle: &Handle<UINode>, available_size: &Vec2) {
match self.nodes.borrow(&node_handle) {
None => return,
Some(node) => {
let margin = Vec2 {
x: node.margin.left + node.margin.right,
y: node.margin.top + node.margin.bottom,
};
fn measure(&self, node_handle: &Handle<UINode>, available_size: Vec2) {
if let Some(node) = self.nodes.borrow(&node_handle) {
let margin = Vec2 {
x: node.margin.left + node.margin.right,
y: node.margin.top + node.margin.bottom,
};
let size_for_child = Vec2 {
x: {
let w = if node.width.get() > 0.0 {
node.width.get()
} else {
maxf(0.0, available_size.x - margin.x)
};
if w > node.max_size.x {
node.max_size.x
} else if w < node.min_size.x {
node.min_size.x
} else {
w
}
},
y: {
let h = if node.height.get() > 0.0 {
node.height.get()
} else {
maxf(0.0, available_size.y - margin.y)
};
if h > node.max_size.y {
node.max_size.y
} else if h < node.min_size.y {
node.min_size.y
} else {
h
}
},
};
if node.visibility == Visibility::Visible {
let mut desired_size = match &node.kind {
UINodeKind::Border(border) => border.measure_override(self, &size_for_child),
UINodeKind::Canvas(canvas) => canvas.measure_override(self, &size_for_child),
UINodeKind::Grid(grid) => grid.measure_override(self, &size_for_child),
UINodeKind::ScrollContentPresenter(scp) => scp.measure_override(self, &size_for_child),
UINodeKind::ScrollBar(scroll_bar) => scroll_bar.measure_override(self, &size_for_child),
_ => self.default_measure_override(node_handle, &size_for_child)
let size_for_child = Vec2 {
x: {
let w = if node.width.get() > 0.0 {
node.width.get()
} else {
maxf(0.0, available_size.x - margin.x)
};
if !node.width.get().is_nan() {
desired_size.x = node.width.get();
if w > node.max_size.x {
node.max_size.x
} else if w < node.min_size.x {
node.min_size.x
} else {
w
}
},
y: {
let h = if node.height.get() > 0.0 {
node.height.get()
} else {
maxf(0.0, available_size.y - margin.y)
};
if desired_size.x > node.max_size.x {
desired_size.x = node.max_size.x;
} else if desired_size.x < node.min_size.x {
desired_size.x = node.min_size.x;
if h > node.max_size.y {
node.max_size.y
} else if h < node.min_size.y {
node.min_size.y
} else {
h
}
},
};
if desired_size.y > node.max_size.y {
desired_size.y = node.max_size.y;
} else if desired_size.y < node.min_size.y {
desired_size.y = node.min_size.y;
}
if node.visibility == Visibility::Visible {
let mut desired_size = match &node.kind {
UINodeKind::Border(border) => border.measure_override(self, size_for_child),
UINodeKind::Canvas(canvas) => canvas.measure_override(self, size_for_child),
UINodeKind::Grid(grid) => grid.measure_override(self, size_for_child),
UINodeKind::ScrollContentPresenter(scp) => scp.measure_override(self, size_for_child),
UINodeKind::ScrollBar(scroll_bar) => scroll_bar.measure_override(self, size_for_child),
_ => self.default_measure_override(node_handle, size_for_child)
};
if !node.height.get().is_nan() {
desired_size.y = node.height.get();
}
desired_size += margin;
// Make sure that node won't go outside of available bounds.
if desired_size.x > available_size.x {
desired_size.x = available_size.x;
}
if desired_size.y > available_size.y {
desired_size.y = available_size.y;
}
node.desired_size.set(desired_size);
} else {
node.desired_size.set(Vec2::make(0.0, 0.0));
if !node.width.get().is_nan() {
desired_size.x = node.width.get();
}
if desired_size.x > node.max_size.x {
desired_size.x = node.max_size.x;
} else if desired_size.x < node.min_size.x {
desired_size.x = node.min_size.x;
}
if desired_size.y > node.max_size.y {
desired_size.y = node.max_size.y;
} else if desired_size.y < node.min_size.y {
desired_size.y = node.min_size.y;
}
if !node.height.get().is_nan() {
desired_size.y = node.height.get();
}
desired_size += margin;
// Make sure that node won't go outside of available bounds.
if desired_size.x > available_size.x {
desired_size.x = available_size.x;
}
if desired_size.y > available_size.y {
desired_size.y = available_size.y;
}
node.desired_size.set(desired_size);
} else {
node.desired_size.set(Vec2::make(0.0, 0.0));
}
}
}
fn default_arrange_override(&self, handle: &Handle<UINode>, final_size: &Vec2) -> Vec2 {
fn default_arrange_override(&self, handle: &Handle<UINode>, final_size: Vec2) -> Vec2 {
let final_rect = Rect::new(0.0, 0.0, final_size.x, final_size.y);
if let Some(node) = self.nodes.borrow(handle) {
@@ -2245,83 +2236,80 @@ impl UserInterface {
}
}
*final_size
final_size
}
fn arrange(&self, node_handle: &Handle<UINode>, final_rect: &Rect<f32>) {
match self.nodes.borrow(node_handle) {
None => return,
Some(node) => {
if node.visibility != Visibility::Visible {
return;
}
let margin_x = node.margin.left + node.margin.right;
let margin_y = node.margin.top + node.margin.bottom;
let mut origin_x = final_rect.x + node.margin.left;
let mut origin_y = final_rect.y + node.margin.top;
let mut size = Vec2 {
x: maxf(0.0, final_rect.w - margin_x),
y: maxf(0.0, final_rect.h - margin_y),
};
let size_without_margin = size;
if node.horizontal_alignment != HorizontalAlignment::Stretch {
size.x = minf(size.x, node.desired_size.get().x - margin_x);
}
if node.vertical_alignment != VerticalAlignment::Stretch {
size.y = minf(size.y, node.desired_size.get().y - margin_y);
}
if node.width.get() > 0.0 {
size.x = node.width.get();
}
if node.height.get() > 0.0 {
size.y = node.height.get();
}
size = match &node.kind {
UINodeKind::Border(border) => border.arrange_override(self, &size),
UINodeKind::Canvas(canvas) => canvas.arrange_override(self, &size),
UINodeKind::Grid(grid) => grid.arrange_override(self, &size),
UINodeKind::ScrollContentPresenter(scp) => scp.arrange_override(self, &size),
UINodeKind::ScrollBar(scroll_bar) => scroll_bar.arrange_override(self, &size),
_ => self.default_arrange_override(node_handle, &size)
};
if size.x > final_rect.w {
size.x = final_rect.w;
}
if size.y > final_rect.h {
size.y = final_rect.h;
}
match node.horizontal_alignment {
HorizontalAlignment::Center | HorizontalAlignment::Stretch => {
origin_x += (size_without_margin.x - size.x) * 0.5;
}
HorizontalAlignment::Right => {
origin_x += size_without_margin.x - size.x;
}
_ => ()
}
match node.vertical_alignment {
VerticalAlignment::Center | VerticalAlignment::Stretch => {
origin_y += (size_without_margin.y - size.y) * 0.5;
}
VerticalAlignment::Bottom => {
origin_y += size_without_margin.y - size.y;
}
_ => ()
}
node.actual_size.set(size);
node.actual_local_position.set(Vec2 { x: origin_x, y: origin_y });
if let Some(node) = self.nodes.borrow(node_handle) {
if node.visibility != Visibility::Visible {
return;
}
let margin_x = node.margin.left + node.margin.right;
let margin_y = node.margin.top + node.margin.bottom;
let mut origin_x = final_rect.x + node.margin.left;
let mut origin_y = final_rect.y + node.margin.top;
let mut size = Vec2 {
x: maxf(0.0, final_rect.w - margin_x),
y: maxf(0.0, final_rect.h - margin_y),
};
let size_without_margin = size;
if node.horizontal_alignment != HorizontalAlignment::Stretch {
size.x = minf(size.x, node.desired_size.get().x - margin_x);
}
if node.vertical_alignment != VerticalAlignment::Stretch {
size.y = minf(size.y, node.desired_size.get().y - margin_y);
}
if node.width.get() > 0.0 {
size.x = node.width.get();
}
if node.height.get() > 0.0 {
size.y = node.height.get();
}
size = match &node.kind {
UINodeKind::Border(border) => border.arrange_override(self, size),
UINodeKind::Canvas(canvas) => canvas.arrange_override(self, size),
UINodeKind::Grid(grid) => grid.arrange_override(self, size),
UINodeKind::ScrollContentPresenter(scp) => scp.arrange_override(self, size),
UINodeKind::ScrollBar(scroll_bar) => scroll_bar.arrange_override(self, size),
_ => self.default_arrange_override(node_handle, size)
};
if size.x > final_rect.w {
size.x = final_rect.w;
}
if size.y > final_rect.h {
size.y = final_rect.h;
}
match node.horizontal_alignment {
HorizontalAlignment::Center | HorizontalAlignment::Stretch => {
origin_x += (size_without_margin.x - size.x) * 0.5;
}
HorizontalAlignment::Right => {
origin_x += size_without_margin.x - size.x;
}
_ => ()
}
match node.vertical_alignment {
VerticalAlignment::Center | VerticalAlignment::Stretch => {
origin_y += (size_without_margin.y - size.y) * 0.5;
}
VerticalAlignment::Bottom => {
origin_y += size_without_margin.y - size.y;
}
_ => ()
}
node.actual_size.set(size);
node.actual_local_position.set(Vec2 { x: origin_x, y: origin_y });
}
}
@@ -2330,7 +2318,7 @@ impl UserInterface {
let mut screen_position = Vec2::new();
if let Some(node) = self.nodes.borrow(node_handle) {
children = UnsafeCollectionView::from_vec(&node.children);
children = UnsafeCollectionView::from_slice(&node.children);
if let Some(parent) = self.nodes.borrow(&node.parent) {
screen_position = node.actual_local_position.get() + parent.screen_position;
} else {
@@ -2349,7 +2337,7 @@ impl UserInterface {
}
pub fn update(&mut self, screen_size: &Vec2) {
pub fn update(&mut self, screen_size: Vec2) {
let root_canvas_handle = self.root_canvas.clone();
self.measure(&root_canvas_handle, screen_size);
self.arrange(&root_canvas_handle, &Rect::new(0.0, 0.0, screen_size.x, screen_size.y));
@@ -2386,7 +2374,7 @@ impl UserInterface {
node.kind.draw(&mut self.drawing_context, font_cache, &bounds, node.color);
children = UnsafeCollectionView::from_vec(&node.children);
children = UnsafeCollectionView::from_slice(&node.children);
let end_index = self.drawing_context.get_commands().len();
for i in start_index..end_index {
@@ -2427,7 +2415,7 @@ impl UserInterface {
&self.drawing_context
}
fn is_node_clipped(&self, node_handle: &Handle<UINode>, pt: &Vec2) -> bool {
fn is_node_clipped(&self, node_handle: &Handle<UINode>, pt: Vec2) -> bool {
let mut clipped = true;
if let Some(node) = self.nodes.borrow(node_handle) {
@@ -2453,7 +2441,7 @@ impl UserInterface {
clipped
}
fn is_node_contains_point(&self, node_handle: &Handle<UINode>, pt: &Vec2) -> bool {
fn is_node_contains_point(&self, node_handle: &Handle<UINode>, pt: Vec2) -> bool {
if let Some(node) = self.nodes.borrow(node_handle) {
if node.visibility != Visibility::Visible {
return false;
@@ -2473,7 +2461,7 @@ impl UserInterface {
false
}
fn pick_node(&self, node_handle: &Handle<UINode>, pt: &Vec2, level: &mut i32) -> Handle<UINode> {
fn pick_node(&self, node_handle: &Handle<UINode>, pt: Vec2, level: &mut i32) -> Handle<UINode> {
let mut picked = Handle::none();
let mut topmost_picked_level = 0;
@@ -2496,7 +2484,7 @@ impl UserInterface {
picked
}
pub fn hit_test(&self, pt: &Vec2) -> Handle<UINode> {
pub fn hit_test(&self, pt: Vec2) -> Handle<UINode> {
if self.nodes.is_valid_handle(&self.captured_node) {
self.captured_node.clone()
} else {
@@ -2616,51 +2604,49 @@ impl UserInterface {
}
pub fn process_event(&mut self, event: &glutin::WindowEvent) -> bool {
match event {
WindowEvent::CursorMoved { position, .. } => {
self.mouse_position = Vec2::make(position.x as f32, position.y as f32);
self.picked_node = self.hit_test(&self.mouse_position);
if let WindowEvent::CursorMoved { position, .. } = event {
self.mouse_position = Vec2::make(position.x as f32, position.y as f32);
self.picked_node = self.hit_test(self.mouse_position);
// Fire mouse leave for previously picked node
if self.picked_node != self.prev_picked_node {
let mut fire_mouse_leave = false;
if let Some(prev_picked_node) = self.nodes.borrow_mut(&self.prev_picked_node) {
if prev_picked_node.is_mouse_over {
prev_picked_node.is_mouse_over = false;
fire_mouse_leave = true;
}
}
if fire_mouse_leave {
let mut evt = RoutedEvent::new(RoutedEventKind::MouseLeave);
self.route_event(self.prev_picked_node.clone(), RoutedEventHandlerType::MouseLeave, &mut evt);
// Fire mouse leave for previously picked node
if self.picked_node != self.prev_picked_node {
let mut fire_mouse_leave = false;
if let Some(prev_picked_node) = self.nodes.borrow_mut(&self.prev_picked_node) {
if prev_picked_node.is_mouse_over {
prev_picked_node.is_mouse_over = false;
fire_mouse_leave = true;
}
}
if !self.picked_node.is_none() {
let mut fire_mouse_enter = false;
if let Some(picked_node) = self.nodes.borrow_mut(&self.picked_node) {
if !picked_node.is_mouse_over {
picked_node.is_mouse_over = true;
fire_mouse_enter = true;
}
}
if fire_mouse_enter {
let mut evt = RoutedEvent::new(RoutedEventKind::MouseEnter);
self.route_event(self.picked_node.clone(), RoutedEventHandlerType::MouseEnter, &mut evt);
}
// Fire mouse move
let mut evt = RoutedEvent::new(RoutedEventKind::MouseMove {
pos: self.mouse_position
});
self.route_event(self.picked_node.clone(), RoutedEventHandlerType::MouseMove, &mut evt);
if fire_mouse_leave {
let mut evt = RoutedEvent::new(RoutedEventKind::MouseLeave);
self.route_event(self.prev_picked_node.clone(), RoutedEventHandlerType::MouseLeave, &mut evt);
}
}
_ => ()
if !self.picked_node.is_none() {
let mut fire_mouse_enter = false;
if let Some(picked_node) = self.nodes.borrow_mut(&self.picked_node) {
if !picked_node.is_mouse_over {
picked_node.is_mouse_over = true;
fire_mouse_enter = true;
}
}
if fire_mouse_enter {
let mut evt = RoutedEvent::new(RoutedEventKind::MouseEnter);
self.route_event(self.picked_node.clone(), RoutedEventHandlerType::MouseEnter, &mut evt);
}
// Fire mouse move
let mut evt = RoutedEvent::new(RoutedEventKind::MouseMove {
pos: self.mouse_position
});
self.route_event(self.picked_node.clone(), RoutedEventHandlerType::MouseMove, &mut evt);
}
}
if !self.picked_node.is_none() {
match event {
WindowEvent::MouseInput { button, state, .. } => {
@@ -2681,6 +2667,17 @@ impl UserInterface {
}
}
}
WindowEvent::MouseWheel { delta, .. } => {
if let MouseScrollDelta::LineDelta(_, y) = delta {
let mut evt = RoutedEvent::new(RoutedEventKind::MouseWheel {
pos: self.mouse_position,
amount: *y,
});
self.route_event(self.picked_node.clone(), RoutedEventHandlerType::MouseWheel, &mut evt);
}
}
_ => ()
}
}
+2 -2
View File
@@ -200,10 +200,10 @@ impl Mat4 {
};
let mut det = f[0] * temp.f[0] + f[4] * temp.f[1] + f[8] * temp.f[2] + f[12] * temp.f[3];
if det.abs() > 0.000001 {
if det.abs() > 0.000_001 {
det = 1.0 / det;
for i in 0..16 {
temp.f[i] = temp.f[i] * det;
temp.f[i] *= det;
}
return Ok(temp);
}
+1 -4
View File
@@ -98,10 +98,7 @@ fn is_ear(poly: &Polygon, prev: &Vertex, ear: &Vertex, next: &Vertex) -> bool {
///
pub fn triangulate(vertices: &[Vec3], out_triangles: &mut Vec<(usize, usize, usize)>) {
out_triangles.clear();
if vertices.len() < 3 {
// Nothing to do
return;
} else if vertices.len() == 3 {
if vertices.len() == 3 {
// Triangulating a triangle?
out_triangles.push((0, 1, 2));
} else if vertices.len() == 4 {
+7 -7
View File
@@ -21,32 +21,32 @@ impl Vec2 {
}
#[inline]
pub fn dot(&self, other: Self) -> f32 {
pub fn dot(self, other: Self) -> f32 {
self.x * other.x + self.y * other.y
}
#[inline]
pub fn len(&self) -> f32 {
self.dot(*self).sqrt()
pub fn len(self) -> f32 {
self.dot(self).sqrt()
}
#[inline]
pub fn angle(&self, other: Self) -> f32 {
pub fn angle(self, other: Self) -> f32 {
(self.dot(other) / (self.len() * other.len())).acos()
}
#[inline]
pub fn perpendicular(&self) -> Vec2 {
pub fn perpendicular(self) -> Vec2 {
Vec2 { x: self.y, y: -self.x }
}
#[inline]
pub fn scale(&self, scalar: f32) -> Vec2 {
pub fn scale(self, scalar: f32) -> Vec2 {
Vec2 { x: self.x * scalar, y: self.y * scalar }
}
#[inline]
pub fn normalized(&self) -> Option<Vec2> {
pub fn normalized(self) -> Option<Vec2> {
let len = self.len();
if len >= std::f32::EPSILON {
let inv_len = 1.0 / len;
+1 -1
View File
@@ -206,7 +206,7 @@ impl Body {
pub fn verlet(&mut self, sqr_delta_time: f32, air_friction: f32) {
let friction =
if self.contacts.len() > 0 {
if !self.contacts.is_empty() {
self.friction
} else {
air_friction
+24018 -21281
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,4 +1,4 @@
pub mod renderer;
pub mod render;
pub mod surface;
#[allow(clippy::all)]
pub mod gl;
@@ -315,8 +315,8 @@ impl Renderer {
let primary_monitor = events_loop.get_primary_monitor();
let mut monitor_dimensions = primary_monitor.get_dimensions();
monitor_dimensions.height = monitor_dimensions.height * 0.6;
monitor_dimensions.width = monitor_dimensions.width * 0.6;
monitor_dimensions.height *= 0.6;
monitor_dimensions.width *= 0.6;
let window_size = monitor_dimensions.to_logical(primary_monitor.get_hidpi_factor());
let window_builder = glutin::WindowBuilder::new()
@@ -649,7 +649,7 @@ impl Renderer {
}
gl::StencilOp(gl::KEEP, gl::KEEP, gl::INCR);
// Make sure that clipping rect will be drawn at previous nesting level only (clip to parent)
gl::StencilFunc(gl::EQUAL, (cmd.get_nesting() - 1) as i32, 0xFF);
gl::StencilFunc(gl::EQUAL, i32::from(cmd.get_nesting() - 1), 0xFF);
gl::BindTexture(gl::TEXTURE_2D, self.white_dummy);
// Draw clipping geometry to stencil buffer
gl::StencilMask(0xFF);
@@ -657,7 +657,7 @@ impl Renderer {
}
CommandKind::Geometry => {
// Make sure to draw geometry only on clipping geometry with current nesting level
gl::StencilFunc(gl::EQUAL, cmd.get_nesting() as i32, 0xFF);
gl::StencilFunc(gl::EQUAL, i32::from(cmd.get_nesting()), 0xFF);
if cmd.get_texture() != 0 {
gl::ActiveTexture(gl::TEXTURE0);
+3 -3
View File
@@ -344,9 +344,9 @@ impl SurfaceSharedData {
impl Drop for SurfaceSharedData {
fn drop(&mut self) {
unsafe {
gl::DeleteBuffers(1, &mut self.vbo);
gl::DeleteBuffers(1, &mut self.ebo);
gl::DeleteVertexArrays(1, &mut self.vao);
gl::DeleteBuffers(1, &self.vbo);
gl::DeleteBuffers(1, &self.ebo);
gl::DeleteVertexArrays(1, &self.vao);
}
}
}
+36 -46
View File
@@ -6,6 +6,7 @@ use crate::{
renderer::surface::{SurfaceSharedData, Surface, Vertex},
engine::State,
};
use std::any::{Any, TypeId};
pub enum FbxAttribute {
Double(f64),
@@ -16,7 +17,7 @@ pub enum FbxAttribute {
String(String), // ASCII Fbx always have every attribute in string form
}
const FBX_TIME_UNIT: f64 = 1.0 / 46186158000.0;
const FBX_TIME_UNIT: f64 = 1.0 / 46_186_158_000.0;
impl FbxAttribute {
pub fn as_i32(&self) -> Result<i32, String> {
@@ -39,7 +40,7 @@ impl FbxAttribute {
match self {
FbxAttribute::Double(val) => Ok(*val as i64),
FbxAttribute::Float(val) => Ok(*val as i64),
FbxAttribute::Integer(val) => Ok(*val as i64),
FbxAttribute::Integer(val) => Ok(i64::from(*val)),
FbxAttribute::Long(val) => Ok(*val as i64),
FbxAttribute::Bool(val) => Ok(*val as i64),
FbxAttribute::String(val) => {
@@ -54,8 +55,8 @@ impl FbxAttribute {
pub fn as_f64(&self) -> Result<f64, String> {
match self {
FbxAttribute::Double(val) => Ok(*val),
FbxAttribute::Float(val) => Ok(*val as f64),
FbxAttribute::Integer(val) => Ok(*val as f64),
FbxAttribute::Float(val) => Ok(f64::from(*val)),
FbxAttribute::Integer(val) => Ok(f64::from(*val)),
FbxAttribute::Long(val) => Ok(*val as f64),
FbxAttribute::Bool(val) => Ok((*val as i64) as f64),
FbxAttribute::String(val) => {
@@ -563,20 +564,6 @@ impl FbxModel {
}
}
#[derive(Copy, Clone, PartialEq)]
enum FbxComponentTypeId {
Unknown,
Deformer,
SubDeformer,
Texture,
Light,
Model,
Material,
AnimationCurveNode,
AnimationCurve,
Geometry,
}
enum FbxComponent {
Deformer(FbxDeformer),
SubDeformer(FbxSubDeformer),
@@ -590,17 +577,17 @@ enum FbxComponent {
}
impl FbxComponent {
fn type_id(&self) -> FbxComponentTypeId {
fn type_id(&self) -> TypeId {
match self {
FbxComponent::Deformer(_) => FbxComponentTypeId::Deformer,
FbxComponent::SubDeformer(_) => FbxComponentTypeId::SubDeformer,
FbxComponent::Texture(_) => FbxComponentTypeId::Texture,
FbxComponent::Light(_) => FbxComponentTypeId::Light,
FbxComponent::Model(_) => FbxComponentTypeId::Model,
FbxComponent::Material(_) => FbxComponentTypeId::Material,
FbxComponent::AnimationCurveNode(_) => FbxComponentTypeId::AnimationCurveNode,
FbxComponent::AnimationCurve(_) => FbxComponentTypeId::AnimationCurve,
FbxComponent::Geometry(_) => FbxComponentTypeId::Geometry
FbxComponent::Deformer(deformer) => deformer.type_id(),
FbxComponent::SubDeformer(subdeformer) => subdeformer.type_id(),
FbxComponent::Texture(texture) => texture.type_id(),
FbxComponent::Light(light) => light.type_id(),
FbxComponent::Model(model) => model.type_id(),
FbxComponent::Material(material) => material.type_id(),
FbxComponent::AnimationCurveNode(anim_curve_node) => anim_curve_node.type_id(),
FbxComponent::AnimationCurve(anim_curve) => anim_curve.type_id(),
FbxComponent::Geometry(geometry) => geometry.type_id()
}
}
}
@@ -655,46 +642,49 @@ fn find_and_borrow_node<'a>(pool: &'a Pool<FbxNode>, stack: &mut Vec<Handle<FbxN
}
/// Links child component with parent component so parent will know about child
fn link_child_with_parent_component(parent: &mut FbxComponent, child_handle: &Handle<FbxComponent>, child_type_id: FbxComponentTypeId) {
fn link_child_with_parent_component(parent: &mut FbxComponent, child_handle: &Handle<FbxComponent>, child_type_id: TypeId) {
match parent {
// Link model with other components
FbxComponent::Model(model) => {
match child_type_id {
FbxComponentTypeId::Geometry => model.geoms.push(child_handle.clone()),
FbxComponentTypeId::Material => model.materials.push(child_handle.clone()),
FbxComponentTypeId::AnimationCurveNode => model.animation_curve_nodes.push(child_handle.clone()),
FbxComponentTypeId::Light => model.light = child_handle.clone(),
FbxComponentTypeId::Model => model.children.push(child_handle.clone()),
_ => ()
if child_type_id == TypeId::of::<FbxGeometry>() {
model.geoms.push(child_handle.clone())
} else if child_type_id == TypeId::of::<FbxMaterial>() {
model.materials.push(child_handle.clone())
} else if child_type_id == TypeId::of::<FbxAnimationCurveNode>() {
model.animation_curve_nodes.push(child_handle.clone())
}else if child_type_id == TypeId::of::<FbxLight>() {
model.light = child_handle.clone()
} else if child_type_id == TypeId::of::<FbxModel>() {
model.children.push(child_handle.clone())
}
}
// Link material with textures
FbxComponent::Material(material) => {
if child_type_id == FbxComponentTypeId::Texture {
if child_type_id == TypeId::of::<FbxTexture>() {
material.diffuse_texture = child_handle.clone();
}
}
// Link animation curve node with animation curve
FbxComponent::AnimationCurveNode(anim_curve_node) => {
if child_type_id == FbxComponentTypeId::AnimationCurve {
if child_type_id == TypeId::of::<FbxAnimationCurve>() {
anim_curve_node.curves.push(child_handle.clone());
}
}
// Link deformer with sub-deformers
FbxComponent::Deformer(deformer) => {
if child_type_id == FbxComponentTypeId::SubDeformer {
if child_type_id == TypeId::of::<FbxSubDeformer>() {
deformer.sub_deformers.push(child_handle.clone());
}
}
// Link geometry with deformers
FbxComponent::Geometry(geometry) => {
if child_type_id == FbxComponentTypeId::Deformer {
if child_type_id == TypeId::of::<FbxDeformer>() {
geometry.deformers.push(child_handle.clone());
}
}
// Link sub-deformer with model
FbxComponent::SubDeformer(sub_deformer) => {
if child_type_id == FbxComponentTypeId::Model {
if child_type_id == TypeId::of::<FbxModel>() {
sub_deformer.model = child_handle.clone();
}
}
@@ -740,7 +730,7 @@ fn read_ascii(path: &Path) -> Result<Fbx, String> {
}
// Ignore comments and empty lines
if buffer.len() == 0 || buffer[0] == b';' {
if buffer.is_empty() || buffer[0] == b';' {
continue;
}
@@ -773,7 +763,7 @@ fn read_ascii(path: &Path) -> Result<Fbx, String> {
// Enter child scope
parent_handle = node_handle.clone();
// Commit attribute if we have one
if value.len() > 0 {
if !value.is_empty() {
if let Some(node) = nodes.borrow_mut(&node_handle) {
if let Ok(string_value) = String::from_utf8(value.clone()) {
let attrib = FbxAttribute::String(string_value);
@@ -1059,9 +1049,9 @@ impl Fbx {
}
fn convert_light(&self, light: &mut Light, fbx_light: &FbxLight) {
light.set_color(Vec3::make(fbx_light.color.r as f32 / 255.0,
fbx_light.color.g as f32 / 255.0,
fbx_light.color.b as f32 / 255.0));
light.set_color(Vec3::make(f32::from(fbx_light.color.r) / 255.0,
f32::from(fbx_light.color.g) / 255.0,
f32::from(fbx_light.color.b) / 255.0));
light.set_radius(fbx_light.radius);
}
+44 -44
View File
@@ -214,7 +214,7 @@ impl Bitmap {
return 0.0;
}
self.pixels[y * self.width + x] as f32 / 255.0
f32::from(self.pixels[y * self.width + x]) / 255.0
}
}
@@ -222,7 +222,7 @@ fn get_u16(p: *const u8) -> u16
{
unsafe {
let b0 = u32::from(*p);
let b1 = *p.offset(1) as u32;
let b1 = u32::from(*p.offset(1));
(b0 * 256 + b1) as u16
}
}
@@ -230,8 +230,8 @@ fn get_u16(p: *const u8) -> u16
fn get_i16(p: *const u8) -> i16
{
unsafe {
let b0 = *p as i32;
let b1 = *p.offset(1) as i32;
let b0 = i32::from(*p);
let b1 = i32::from(*p.offset(1));
(b0 * 256 + b1) as i16
}
}
@@ -239,21 +239,21 @@ fn get_i16(p: *const u8) -> i16
fn get_u32(p: *const u8) -> u32
{
unsafe {
let b0 = *p as u32;
let b1 = *p.offset(1) as u32;
let b2 = *p.offset(2) as u32;
let b3 = *p.offset(3) as u32;
let b0 = u32::from(*p);
let b1 = u32::from(*p.offset(1));
let b2 = u32::from(*p.offset(2));
let b3 = u32::from(*p.offset(3));
(b0 << 24) + (b1 << 16) + (b2 << 8) + b3
}
}
fn fourcc(d: u8, c: u8, b: u8, a: u8) -> u32 {
((d as u32) << 24) | ((c as u32) << 16) | ((b as u32) << 8) | (a as u32)
(u32::from(d) << 24) | (u32::from(c) << 16) | (u32::from(b) << 8) | (u32::from(a))
}
fn segmented_mapping(subtable: *const u8, unicode: u32) -> usize {
unsafe {
let segment_count = (get_u16(subtable.offset(6)) / 2) as u32;
let segment_count = u32::from(get_u16(subtable.offset(6)) / 2);
let end_codes = subtable.offset(14);
let start_codes = subtable.offset((16 + 2 * segment_count) as isize);
let id_delta = subtable.offset((16 + 4 * segment_count) as isize);
@@ -261,18 +261,18 @@ fn segmented_mapping(subtable: *const u8, unicode: u32) -> usize {
let mut segment = 0;
while segment < segment_count {
if get_u16(end_codes.offset(2 * segment as isize)) as u32 >= unicode {
if u32::from(get_u16(end_codes.offset(2 * segment as isize))) >= unicode {
break;
}
segment += 1;
}
if segment != segment_count {
let start_code = get_u16(start_codes.offset(2 * segment as isize)) as u32;
let start_code = u32::from(get_u16(start_codes.offset(2 * segment as isize)));
if start_code <= unicode {
let range_offset = (get_u16(id_range_offset.offset(2 * segment as isize)) / 2) as u32;
let range_offset = u32::from(get_u16(id_range_offset.offset(2 * segment as isize)) / 2);
if range_offset == 0 {
return ((unicode + get_u16(id_delta.offset(2 * segment as isize)) as u32) & 0xFFFF) as usize;
return ((unicode + u32::from(get_u16(id_delta.offset(2 * segment as isize)))) & 0xFFFF) as usize;
} else {
let offset = 2 * (segment + range_offset + (unicode - start_code));
return get_u16(id_range_offset.offset(offset as isize)) as usize;
@@ -297,8 +297,8 @@ fn direct_mapping(subtable: *const u8, unicode: u32) -> usize {
fn dense_mapping(subtable: *const u8, unicode: u32) -> usize {
unsafe {
let first = get_u16(subtable.offset(6)) as u32;
let entry_count = get_u16(subtable.offset(8)) as u32;
let first = u32::from(get_u16(subtable.offset(6)));
let entry_count = u32::from(get_u16(subtable.offset(8)));
let indices = subtable.offset(10);
if unicode > first && unicode < first + entry_count {
@@ -327,7 +327,7 @@ fn line_line_intersection(a: &Line2, b: &Line2) -> Option<Point> {
}
}
fn polygons_to_scanlines(polys: &Vec<Polygon>, width: f32, height: f32, scale: f32) -> Vec<Line2> {
fn polygons_to_scanlines(polys: &[Polygon], width: f32, height: f32, scale: f32) -> Vec<Line2> {
let bias = 0.0001;
let y_oversample = 5.0;
let y_step = 1.0 / y_oversample;
@@ -351,7 +351,7 @@ fn polygons_to_scanlines(polys: &Vec<Polygon>, width: f32, height: f32, scale: f
scanline.end.y = y;
/* Find all intersection points for current y */
for poly in polys.iter() {
for poly in polys {
for j in (0..poly.points.len()).step_by(2) {
let begin = poly.points.get(j).unwrap();
let end = poly.points.get(j + 1).unwrap();
@@ -390,7 +390,7 @@ fn polygons_to_scanlines(polys: &Vec<Polygon>, width: f32, height: f32, scale: f
}
/* Convert intersection points into scanlines */
if intersections.len() > 0 {
if !intersections.is_empty() {
for i in (0..(intersections.len() - 1)).step_by(2) {
let line = Line2 {
begin: Point { x: intersections[i].x, y, flags: 0 },
@@ -406,19 +406,19 @@ fn polygons_to_scanlines(polys: &Vec<Polygon>, width: f32, height: f32, scale: f
lines
}
fn raster_scanlines(w: usize, h: usize, lines: &Vec<Line2>) -> Bitmap {
fn raster_scanlines(w: usize, h: usize, lines: &[Line2]) -> Bitmap {
let mut bitmap = Bitmap::new(w, h);
/* Antialised scanline rasterization. */
for scanline in lines.iter() {
// Antialised scanline rasterization.
for scanline in lines {
let yi = scanline.begin.y as usize;
/* Calculate new opacity for pixel at the begin of scanline. */
// Calculate new opacity for pixel at the begin of scanline.
let bx = scanline.begin.x;
let begin_opacity = 0.5 * ((bx.ceil() - bx) + bitmap.get_fpixel(bx as usize, yi));
bitmap.set_pixel(bx as usize, yi, (255.0 * begin_opacity) as u8);
/* Calculate new opacity for pixel at the end of scanline. */
// Calculate new opacity for pixel at the end of scanline.
let ex = scanline.end.x;
let end_opacity = 0.5 * ((ex - ex.floor()) + bitmap.get_fpixel(ex as usize, yi));
bitmap.set_pixel(ex as usize, yi, (255.0 * end_opacity) as u8);
@@ -537,7 +537,7 @@ impl TrueType {
fn em_to_pixels(&self, pixels: f32) -> f32 {
unsafe {
let units_per_em = get_u16(self.head_table.offset(18)) as f32;
let units_per_em = f32::from(get_u16(self.head_table.offset(18)));
pixels / units_per_em
}
}
@@ -556,13 +556,13 @@ impl TrueType {
};
}
let height = ((scale * (glyph.y_max - glyph.y_min) as f32) + 1.0) as usize;
let width = ((scale * (glyph.x_max - glyph.x_min) as f32) + 1.0) as usize;
let height = ((scale * f32::from(glyph.y_max - glyph.y_min)) + 1.0) as usize;
let width = ((scale * f32::from(glyph.x_max - glyph.x_min)) + 1.0) as usize;
let lines = polygons_to_scanlines(
&glyph.contours,
(glyph.x_max - glyph.x_min) as f32,
(glyph.y_max - glyph.y_min) as f32,
f32::from(glyph.x_max - glyph.x_min),
f32::from(glyph.y_max - glyph.y_min),
scale,
);
@@ -571,9 +571,9 @@ impl TrueType {
pixels: final_bitmap.pixels,
bitmap_width: final_bitmap.width as f32,
bitmap_height: final_bitmap.height as f32,
advance: glyph.advance as f32 * scale,
bitmap_left: glyph.x_min as f32 * scale,
bitmap_top: glyph.y_min as f32 * scale,
advance: f32::from(glyph.advance) * scale,
bitmap_left: f32::from(glyph.x_min) * scale,
bitmap_top: f32::from(glyph.y_min) * scale,
has_outline: glyph.has_outline,
tex_coords: [Vec2::new(); 4],
}
@@ -670,11 +670,11 @@ impl TrueType {
for j in 0..(point_count as usize) {
let pt = points.get_mut(j).unwrap();
if (pt.flags & 2) != 0 {
let dx = *coords as i32;
let dx = i32::from(*coords);
coords = coords.offset(1);
x += if (pt.flags & 16) != 0 { dx } else { -dx };
} else if (pt.flags & 16) == 0 {
x += get_i16(coords) as i32;
x += i32::from(get_i16(coords));
coords = coords.offset(2);
}
pt.x = x as f32;
@@ -685,11 +685,11 @@ impl TrueType {
for j in 0..(point_count as usize) {
let pt = points.get_mut(j).unwrap();
if (pt.flags & 4) != 0 {
let dy = *coords as i32;
let dy = i32::from(*coords);
coords = coords.offset(1);
y += if (pt.flags & 32) != 0 { dy } else { -dy };
} else if (pt.flags & 32) == 0 {
y += get_i16(coords) as i32;
y += i32::from(get_i16(coords));
coords = coords.offset(2);
}
@@ -805,8 +805,8 @@ impl TtfGlyph {
let pt = points.get_unchecked(k as usize);
let off_pt = Point {
x: pt.x - self.x_min as f32,
y: pt.y - self.y_min as f32,
x: pt.x - f32::from(self.x_min),
y: pt.y - f32::from(self.y_min),
flags: pt.flags,
};
@@ -834,7 +834,7 @@ impl TtfGlyph {
let middle = Point {
flags: ON_CURVE_POINT,
x: (first.x + last.x) / 2.0,
y: glyph_height as f32 - (first.y + last.y) / 2.0,
y: f32::from(glyph_height) - (first.y + last.y) / 2.0,
};
unpacked_contour.points.push(middle);
@@ -855,7 +855,7 @@ impl TtfGlyph {
let flipped = Point {
flags: p0.flags,
x: p0.x,
y: glyph_height as f32 - p0.y,
y: f32::from(glyph_height) - p0.y,
};
unpacked_contour.points.push(flipped);
@@ -863,7 +863,7 @@ impl TtfGlyph {
let middle = Point {
flags: ON_CURVE_POINT,
x: (p0.x + p1.x) / 2.0,
y: glyph_height as f32 - (p0.y + p1.y) / 2.0,
y: f32::from(glyph_height) - (p0.y + p1.y) / 2.0,
};
unpacked_contour.points.push(middle);
}
@@ -888,9 +888,9 @@ impl Font {
let mut font = Font {
height,
glyphs: Vec::new(),
ascender: scale * ttf.get_ascender() as f32,
descender: scale * ttf.get_descender() as f32,
line_gap: scale * ttf.get_line_gap() as f32,
ascender: scale * f32::from(ttf.get_ascender()),
descender: scale * f32::from(ttf.get_descender()),
line_gap: scale * f32::from(ttf.get_line_gap()),
char_map: HashMap::new(),
texture_id: 0,
atlas: Vec::new(),
+1 -1
View File
@@ -75,7 +75,7 @@ impl Scene {
state.release_resource(node.get_resource());
children = UnsafeCollectionView::from_vec(&node.children);
children = UnsafeCollectionView::from_slice(&node.children);
}
// Free children recursively
+2 -2
View File
@@ -16,7 +16,7 @@ impl<T> UnsafeCollectionView<T> {
}
}
pub fn from_vec(vec: &Vec<T>) -> UnsafeCollectionView<T> {
pub fn from_slice(vec: &[T]) -> UnsafeCollectionView<T> {
UnsafeCollectionView {
items: vec.as_ptr(),
len: vec.len(),
@@ -27,7 +27,7 @@ impl<T> UnsafeCollectionView<T> {
unsafe {
UnsafeCollectionViewIterator {
current: self.items,
end: self.items.offset(self.len as isize),
end: self.items.add(self.len),
marker: PhantomData,
}
}
+1 -1
View File
@@ -298,7 +298,7 @@ impl<T> Pool<T> {
unsafe {
PoolIteratorMut {
ptr: self.records.as_mut_ptr(),
end: self.records.as_mut_ptr().offset(self.records.len() as isize),
end: self.records.as_mut_ptr().add(self.records.len()),
marker: PhantomData,
}
}
+1 -1
View File
@@ -317,7 +317,7 @@ impl<T> RcPool<T> {
unsafe {
RcPoolIteratorMut {
ptr: self.records.as_mut_ptr(),
end: self.records.as_mut_ptr().offset(self.records.len() as isize),
end: self.records.as_mut_ptr().add(self.records.len()),
marker: PhantomData,
}
}