Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Fix some minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueDoctor committed Apr 12, 2020
1 parent a445563 commit cc451e3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion client/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ workspace = false
condition = { env_set = [ "CARGO_TARGET_DIR" ] }
env = { "RUSTFLAGS" = "-Clink-arg=--no-entry -Clink-arg=--allow-undefined -Clink-arg=--strip-all -Clink-arg=--export-dynamic -Clink-arg=--import-memory -Clink-arg=--shared-memory -Clink-arg=--threads -Clink-arg=--export=__wasm_init_memory -Clink-arg=--no-check-features -Clink-arg=--export=__wasm_init_tls -Clink-arg=--export=__tls_size -Ctarget-feature=+atomics,+bulk-memory" }
script = [
"touch build.rs && cargo make exec-${BUILD_ENV} -- build -p rask-${@} --target wasm32-unknown-unknown",
"touch build.rs #triggers the build.rs to be rebuild every time",
"cargo make exec-${BUILD_ENV} -- build -p rask-${@} --target wasm32-unknown-unknown",
"mkdir -p gen",
"mv $(find $CARGO_TARGET_DIR/ -name mem.json) gen/",
]
Expand Down
27 changes: 14 additions & 13 deletions client/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const fn KiB(n: usize) -> usize {
const fn MiB(n: usize) -> usize {
n * KiB(1024)
}
const fn align(n: usize) -> usize {
/// align the given address to the next 32bit
const fn align32_up(n: usize) -> usize {
(n + 3) & !3
}

Expand All @@ -33,12 +34,12 @@ const ALLOCATOR_SIZE: usize = MiB(1);
const RESOURCE_TABLE_SIZE: usize = KiB(1);

/// Size of the message queue used to communicate between main.js and the logic thread
/// Its address must be exorted to javascript.
/// Its address must be exported to javascript.
const MESSAGE_QUEUE_SIZE: usize = 64;

/// The address memory synchronization area.
/// It contains data needed for synchronization between main thread and logic thread.
/// This address must be exorted to javascript.
/// This address must be exported to javascript.
const SYNCHRONIZATION_MEMORY_SIZE: usize = 32;

/// Number of sprites to store in the double buffer
Expand All @@ -51,23 +52,23 @@ fn main() -> std::io::Result<()> {
Ok(worker) if &worker == "logic" => true,
Ok(worker) if &worker == "graphics" => false,
Ok(key) => panic!(
"{} is no valid value. Possibel values are logic and graphics",
key
"{} is no valid value for {}. Possible values are logic and graphics",
key, WORKER_NAME_VAR,
),
Err(std::env::VarError::NotPresent) => {
panic!("{} is not defined in the environment.", WORKER_NAME_VAR)
}
Err(err) => panic!("env var parsing failed (\"{:?}\")", err),
};

let graphics_stack = align(STACK_ALIGNMENT + GRAPHICS_STACK_SIZE);
let alloc = align(graphics_stack);
let graphics_heap = align(alloc + ALLOCATOR_SIZE);
let sync = align(alloc + GRAPHICS_HEAP_SIZE);
let table = align(sync + SYNCHRONIZATION_MEMORY_SIZE);
let buffer = align(table + RESOURCE_TABLE_SIZE);
let queue = align(buffer + BUFFER_SIZE);
let logic_heap = align(queue + MESSAGE_QUEUE_SIZE);
let graphics_stack = align32_up(STACK_ALIGNMENT + GRAPHICS_STACK_SIZE);
let alloc = align32_up(graphics_stack);
let graphics_heap = align32_up(alloc + ALLOCATOR_SIZE);
let sync = align32_up(alloc + GRAPHICS_HEAP_SIZE);
let table = align32_up(sync + SYNCHRONIZATION_MEMORY_SIZE);
let buffer = align32_up(table + RESOURCE_TABLE_SIZE);
let queue = align32_up(buffer + BUFFER_SIZE);
let logic_heap = align32_up(queue + MESSAGE_QUEUE_SIZE);

println!("cargo:rustc-env=GRAPHICS_STACK={}", graphics_stack);
println!("cargo:rustc-env=ALLOCATOR={}", alloc);
Expand Down
4 changes: 2 additions & 2 deletions rask-engine/src/resources/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ impl ResourceTable {
}

fn index_check(&self, id: usize) -> Result<(), EngineError> {
if id > self.0.len() {
if id >= self.0.len() {
return Err(EngineError::ResourceError(format!(
"The requested texture index: {} is out ouf range, the max id is {}",
"The requested resource index: {} is out ouf range, the max id is {}",
id,
self.0.len() - 1
)));
Expand Down
4 changes: 2 additions & 2 deletions rask-engine/src/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use lazy_static::lazy_static;
# use rask_engine::resources::*;
lazy_static! {
static ref LIB: ResourceTable = unsafe { ResourceTable::new(0, 0) };
static ref TABLE: ResourceTable = unsafe { ResourceTable::new(0, 0) };
}
fn test() {
unsafe {
let _texture: &Texture = LIB.get(0).unwrap();
let _texture: &Texture = TABLE.get(0).unwrap();
}
}
```
Expand Down

0 comments on commit cc451e3

Please sign in to comment.