Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
aeplay committed Dec 22, 2018
1 parent 4097dab commit 09533ad
Show file tree
Hide file tree
Showing 19 changed files with 264 additions and 246 deletions.
15 changes: 3 additions & 12 deletions cb_browser_ui/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use stdweb::serde::Serde;
use stdweb::js_export;
use SYSTEM;

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn plan_grid(project_id: Serde<::planning::ProjectID>, n: usize, spacing: Serde<f32>) {
let system = unsafe { &mut *SYSTEM };
let world = &mut system.world();
Expand Down Expand Up @@ -49,10 +46,7 @@ pub fn plan_grid(project_id: Serde<::planning::ProjectID>, n: usize, spacing: Se
}
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn spawn_cars(tries_per_lane: usize) {
let system = unsafe { &mut *SYSTEM };
let world = &mut system.world();
Expand Down Expand Up @@ -113,10 +107,7 @@ impl LogRecipient for LogUI {
}
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn get_newest_log_messages() {
let system = unsafe { &mut *SYSTEM };
let world = &mut system.world();
Expand Down
7 changes: 2 additions & 5 deletions cb_browser_ui/src/households_browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use stdweb::serde::Serde;
use stdweb::js_export;
use SYSTEM;

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn get_household_info(household_id: Serde<::economy::households::HouseholdID>) {
let system = unsafe { &mut *SYSTEM };
let world = &mut system.world();
Expand Down Expand Up @@ -36,7 +33,7 @@ impl HouseholdUI for BrowserHouseholdUI {
core: &::economy::households::HouseholdCore,
_world: &mut World,
) {
js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
households: {
householdInfo: {
Expand Down
19 changes: 6 additions & 13 deletions cb_browser_ui/src/land_use_browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use browser_utils::to_js_mesh;
use SYSTEM;
use ::std::collections::HashMap;

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn get_building_info(building_id: Serde<::land_use::buildings::BuildingID>) {
let system = unsafe { &mut *SYSTEM };
let world = &mut system.world();
Expand Down Expand Up @@ -46,12 +43,8 @@ impl LandUseUI for BrowserLandUseUI {
style: ::land_use::buildings::BuildingStyle,
world: &mut World,
) {
let meshes = ::land_use::buildings::architecture::build_building(
lot,
style,
households,
world,
);
let meshes =
::land_use::buildings::architecture::build_building(lot, style, households, world);

let material_updates: ::stdweb::Object = meshes
.0
Expand All @@ -70,7 +63,7 @@ impl LandUseUI for BrowserLandUseUI {
.collect::<HashMap<_, _>>()
.into();

js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
landUse: {rendering: @{material_updates}},
households: {
Expand Down Expand Up @@ -99,7 +92,7 @@ impl LandUseUI for BrowserLandUseUI {
.map(|material| (material.to_string(), unset_op.clone()))
.collect::<HashMap<_, _>>()
.into();
js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
landUse: {rendering: @{unsets}},
households: {buildingPositions: {"$unset": [@{Serde(id)}]}}
Expand All @@ -114,7 +107,7 @@ impl LandUseUI for BrowserLandUseUI {
households: &CVec<::economy::households::HouseholdID>,
_world: &mut World,
) {
js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
households: {
inspectedBuildingState: {"$set": {
Expand Down
27 changes: 9 additions & 18 deletions cb_browser_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,20 @@ pub mod browser_utils;
// TODO: not thread safe for now
static mut SYSTEM: *mut ActorSystem = 0 as *mut ActorSystem;

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn start() {
panic::set_hook(Box::new(|info| console!(error, info.to_string())));

js!{ console.log("Before setup") }
js! { console.log("Before setup") }

let server_host = js!{
let server_host = js! {
return window.location.hostname;
}
.into_string()
.unwrap();

let mut network_settings = ::std::collections::HashMap::from(
js!{
js! {
return window.cbNetworkSettings;
}
.into_object()
Expand Down Expand Up @@ -75,7 +72,7 @@ pub fn start() {
households_browser::setup(&mut system);
vegetation_browser::setup(&mut system);

js!{
js! {
window.cbTypeIdMapping = @{Serde(system.get_actor_type_id_to_name_mapping())}
}

Expand All @@ -91,7 +88,7 @@ pub fn start() {

system.process_all_messages();

js!{ console.log("After setup") }
js! { console.log("After setup") }

let mut main_loop = MainLoop { skip_turns: 0 };

Expand Down Expand Up @@ -124,7 +121,7 @@ impl MainLoop {

use ::stdweb::serde::Serde;

js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
system: {
networkingTurns: {"$set": @{Serde(system.networking_debug_all_n_turns())}},
Expand Down Expand Up @@ -157,19 +154,13 @@ impl MainLoop {

use stdweb::serde::Serde;

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn point_in_area(point: Serde<descartes::P2>, area: Serde<descartes::Area>) -> bool {
use ::descartes::PointContainer;
area.0.contains(point.0)
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn point_close_to_path(
point: Serde<descartes::P2>,
path: Serde<descartes::LinePath>,
Expand Down
50 changes: 10 additions & 40 deletions cb_browser_ui/src/planning_browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use browser_utils::{updated_groups_to_js, to_js_mesh, FrameListener, FrameListen
use stdweb::js_export;
use SYSTEM;

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn move_gesture_point(
project_id: Serde<::planning::ProjectID>,
gesture_id: Serde<::planning::GestureID>,
Expand All @@ -37,10 +34,7 @@ pub fn move_gesture_point(
);
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn start_new_gesture(
project_id: Serde<::planning::ProjectID>,
gesture_id: Serde<::planning::GestureID>,
Expand All @@ -59,10 +53,7 @@ pub fn start_new_gesture(
)
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn add_control_point(
project_id: Serde<::planning::ProjectID>,
gesture_id: Serde<::planning::GestureID>,
Expand All @@ -82,10 +73,7 @@ pub fn add_control_point(
)
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn insert_control_point(
project_id: Serde<::planning::ProjectID>,
gesture_id: Serde<::planning::GestureID>,
Expand All @@ -103,10 +91,7 @@ pub fn insert_control_point(
)
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn split_gesture(
project_id: Serde<::planning::ProjectID>,
gesture_id: Serde<::planning::GestureID>,
Expand All @@ -124,10 +109,7 @@ pub fn split_gesture(
)
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn set_n_lanes(
project_id: Serde<::planning::ProjectID>,
gesture_id: Serde<::planning::GestureID>,
Expand All @@ -149,40 +131,28 @@ pub fn set_n_lanes(
)
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn finish_gesture() {
let system = unsafe { &mut *SYSTEM };
let world = &mut system.world();
::planning::PlanManagerID::global_first(world).finish_gesture(::kay::MachineID(0), world)
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn undo(project_id: Serde<::planning::ProjectID>) {
let system = unsafe { &mut *SYSTEM };
let world = &mut system.world();
::planning::PlanManagerID::global_first(world).undo(project_id.0, world)
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn redo(project_id: Serde<::planning::ProjectID>) {
let system = unsafe { &mut *SYSTEM };
let world = &mut system.world();
::planning::PlanManagerID::global_first(world).redo(project_id.0, world)
}

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn implement_project(project_id: Serde<::planning::ProjectID>) {
let system = unsafe { &mut *SYSTEM };
let world = &mut system.world();
Expand Down
5 changes: 1 addition & 4 deletions cb_browser_ui/src/time_browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use stdweb::js_export;
use SYSTEM;
use browser_utils::{FrameListener, FrameListenerID};

#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
js_export
)]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), js_export)]
pub fn set_sim_speed(new_speed: u16) {
let system = unsafe { &mut *SYSTEM };
let world = &mut system.world();
Expand Down
12 changes: 6 additions & 6 deletions cb_browser_ui/src/transport_browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl TransportUI for BrowserTransportUI {
.lane_marker_gaps_grouper
.update(None, Some((id, switch_marker_gap_mesh(lane_path))));

js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
transport: {rendering: {
laneMarkerGapGroups: {
Expand All @@ -129,7 +129,7 @@ impl TransportUI for BrowserTransportUI {
let updated_asphalt_groups = self.asphalt_grouper.update(None, Some((id, mesh)));

if on_intersection {
js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
transport: {rendering: {
laneAsphaltGroups: {
Expand All @@ -145,7 +145,7 @@ impl TransportUI for BrowserTransportUI {
let updated_lane_marker_groups = self
.lane_marker_grouper
.update(None, Some((id, marker_meshes.0 + marker_meshes.1)));
js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
transport: {rendering: {
laneAsphaltGroups: {
Expand Down Expand Up @@ -176,7 +176,7 @@ impl TransportUI for BrowserTransportUI {
let updated_lane_marker_gaps_groups =
self.lane_marker_gaps_grouper.update(Some(id), None);

js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
transport: {rendering: {
laneMarkerGapGroups: {
Expand All @@ -191,7 +191,7 @@ impl TransportUI for BrowserTransportUI {
let updated_asphalt_groups = self.asphalt_grouper.update(Some(id), None);

if on_intersection {
js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
transport: {rendering: {
laneAsphaltGroups: {
Expand All @@ -204,7 +204,7 @@ impl TransportUI for BrowserTransportUI {
}
} else {
let updated_lane_marker_groups = self.lane_marker_grouper.update(Some(id), None);
js!{
js! {
window.cbReactApp.boundSetState(oldState => update(oldState, {
transport: {rendering: {
laneAsphaltGroups: {
Expand Down
2 changes: 1 addition & 1 deletion cb_simulation/src/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pub mod vegetation;

pub fn setup(system: &mut ActorSystem) {
vegetation::setup(system);
}
}
Loading

0 comments on commit 09533ad

Please sign in to comment.