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

Commit

Permalink
Fix minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueDoctor committed Apr 12, 2020
1 parent d712d46 commit 80ec91c
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 18 deletions.
4 changes: 2 additions & 2 deletions client/graphics/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use rask_wasm_shared::sprite::Frame;

lazy_static! {
pub static ref RESOURCE_TABLE: ResourceTable = unsafe {
let mut table = ResourceTable::new(mem::RESOURCE_TABLE, mem::RESOURCE_TABLE_ELEMENT_COUNT);
table.init();
let mut table = ResourceTable::from_memory(mem::RESOURCE_TABLE, mem::RESOURCE_TABLE_ELEMENT_COUNT);
table.clear();
table
};
}
Expand Down
2 changes: 1 addition & 1 deletion client/logic/src/game_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl GameContext {
state: State::default(),
tick_nr: 0,
resource_table: unsafe {
ResourceTable::new(RESOURCE_TABLE, RESOURCE_TABLE_ELEMENT_COUNT)
ResourceTable::from_memory(RESOURCE_TABLE, RESOURCE_TABLE_ELEMENT_COUNT)
},
})
}
Expand Down
8 changes: 0 additions & 8 deletions client/shared/src/double_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,18 @@ impl<T: Element> DoubleBuffer<T> {
}
}

#[allow(unused_attributes)]
#[inline(always)]
pub extern "C" fn set_reading_at(&mut self, reading_at: Flag) {
unsafe { mem::atomic_write_u8(&mut self.reading_at, reading_at) }
}

#[allow(unused_attributes)]
#[inline(always)]
pub extern "C" fn get_reading_at(&self) -> Flag {
unsafe { mem::atomic_read_u8(&self.reading_at) }
}

#[allow(unused_attributes)]
#[inline(always)]
pub extern "C" fn set_provided(&mut self, provided: Flag) {
unsafe { mem::atomic_write_u8(&mut self.provided, provided) }
}

#[allow(unused_attributes)]
#[inline(always)]
pub extern "C" fn get_provided(&self) -> Flag {
unsafe { mem::atomic_read_u8(&self.provided) }
}
Expand Down
6 changes: 2 additions & 4 deletions client/shared/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ pub const MESSAGE_QUEUE: usize = 0;
#[from_env]
pub const MESSAGE_QUEUE_SIZE: usize = 0;
pub const MESSAGE_QUEUE_ELEMENT_COUNT: usize = (MESSAGE_QUEUE_SIZE as i64
- size_of::<MessageQueue<MessageQueueElement<u8>>>() as i64)
as usize
- size_of::<MessageQueue<u8>>() as i64) as usize
/ size_of::<MessageQueueElement<u8>>();

#[from_env]
Expand Down Expand Up @@ -89,7 +88,6 @@ impl SynchronizationMemory {
}

#[repr(align(4))]
#[derive(Clone)]
struct MessageQueueElement<T: Sized + Clone> {
reading: u8,
writing: u8,
Expand Down Expand Up @@ -127,7 +125,7 @@ pub struct MessageQueue<T: Sized + Clone> {

impl<T: Sized + Clone> MessageQueue<T> {
pub fn length() -> usize {
MESSAGE_QUEUE
MESSAGE_QUEUE_ELEMENT_COUNT
}

fn mem_size() -> usize {
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 @@ -43,14 +43,14 @@ impl ResourceTable {
/// # Safety
///
/// The function is safe as long as the memory from memory_offset to memory_offset + CATALOG_SIZE * sizeof(Resource)
pub unsafe fn new(memory_offset: usize, catalog_size: usize) -> Self {
pub unsafe fn from_memory(memory_offset: usize, catalog_size: usize) -> Self {
ResourceTable(core::slice::from_raw_parts_mut(
memory_offset as *mut Resource,
catalog_size,
))
}

pub unsafe fn init(&mut self) {
pub fn clear(&mut self) {
for i in 0..self.0.len() {
self.0[i] = Resource::None;
}
Expand Down
2 changes: 1 addition & 1 deletion rask-engine/src/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use lazy_static::lazy_static;
# use rask_engine::resources::*;
lazy_static! {
static ref TABLE: ResourceTable = unsafe { ResourceTable::new(0, 0) };
static ref TABLE: ResourceTable = unsafe { ResourceTable::from_memory(0, 0) };
}
fn test() {
Expand Down

0 comments on commit 80ec91c

Please sign in to comment.