-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimental structure cache improvements (2x speed?)
- Loading branch information
1 parent
6e261bb
commit f83bb81
Showing
6 changed files
with
208 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export function do_classify_find(room_name) { | ||
let room = Game.rooms[room_name]; | ||
|
||
if (room) { | ||
let res = room.find(FIND_STRUCTURES); | ||
|
||
let all_structures = []; | ||
let repairable = []; | ||
let container = []; | ||
let link = []; | ||
|
||
res.forEach((structure) => { | ||
all_structures.push(structure); | ||
|
||
//let can_own = switch(structure.structureType) { | ||
// case: | ||
//} | ||
|
||
if (structure.hits < structure.hitsMax && structure.structureType != STRUCTURE_WALL) { | ||
repairable.push(structure) | ||
} | ||
|
||
if (structure.structureType == STRUCTURE_LINK) { | ||
link.push(structure) | ||
} | ||
|
||
if (structure.structureType == STRUCTURE_CONTAINER) { | ||
container.push(structure); | ||
} | ||
}) | ||
|
||
return [all_structures, repairable, container, link]; | ||
} else { | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::str::FromStr; | ||
|
||
use js_sys::{Array, JsString}; | ||
use screeps::{RoomName, StructureContainer, StructureLink, StructureObject}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(module = "test")] | ||
extern "C" { | ||
// Returns an array 4 long: | ||
// 0 - All Structures | ||
// 1 - Repairable | ||
// 2 - Container | ||
// 3 - Link | ||
fn do_classify_find(room_name: JsString) -> Array; | ||
} | ||
|
||
pub fn do_find(room_name: &RoomName) -> (Vec<StructureObject>, Vec<StructureObject>, Vec<StructureContainer>, Vec<StructureLink>) { | ||
let res = do_classify_find(JsString::from_str(room_name.to_string().as_str()).unwrap()); | ||
|
||
if res.length() == 0 { | ||
return (vec![], vec![], vec![], vec![]); | ||
} | ||
|
||
let all_js: Array = res.get(0).into(); | ||
let repairable_js: Array = res.get(1).into(); | ||
let container: Array = res.get(2).into(); | ||
let links: Array = res.get(3).into(); | ||
|
||
let all_rs: Vec<StructureObject> = all_js.iter().map(|structure| structure.into()).collect(); | ||
let repairable_rs: Vec<StructureObject> = repairable_js.iter().map(|structure| structure.into()).collect(); | ||
let container_rs: Vec<StructureContainer> = container.iter().map(|structure| structure.into()).collect(); | ||
let links_rs: Vec<StructureLink> = links.iter().map(|structure| structure.into()).collect(); | ||
|
||
(all_rs, repairable_rs, container_rs, links_rs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters