-
Notifications
You must be signed in to change notification settings - Fork 1
Restructure build process to simplify the wasm memory fragmentation #62
Conversation
fix typos fix Rbox::new fix From<&SRT> impl for RBox remove smallvec dependency add conversions from and to arrays for Vec2, Vec3 update docs NOTE: the Collide impl is currently not working properly
rename variables in tests add ratatosk.iml to .gitignore
3600d04
to
457dc0c
Compare
rask-engine/src/resources/library.rs
Outdated
} | ||
|
||
fn index_check(&self, id: usize) -> Result<(), EngineError> { | ||
if id > self.0.len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of of using a return
-statement, use
if blah {
Err(foo)
} else {
Ok(bar)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it does not make the cod any faster, shorter or more readable
impl GetStore<$type> for ResourceTable { | ||
unsafe fn get(&'static self, id: usize) -> Result<&'static $type, EngineError> { | ||
self.index_check(id)?; | ||
match &self.0[id] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using Index
, you could use get
(and get_mut
in store
) for indexing (self.0.get(id)
), which returns an Option
. That would be much cleaner than the index_check
-function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree if the requested resource is out of bounds, an error should be raised, because it is unexpected behaviour. It is essentially a fancy panic.
And I don't like the approach of get_mut(), because with the current implementation we do all the wrapping in the library which would then needed to be done by the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Panic? I thought a panic could not occur in your function. I don't get your point. You could do something like
match self.0.get(id).ok_or(myerrorblahblah)? {
}
This does not make any difference for the user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is also relevant, whether the error occured because of an out of bounds, or because of a resource type mismatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, but that does not change anything on my point. See, you could do the following:
unsafe fn get(&'a self, id: usize) -> Result<&'a $type, EngineError> {
match self.0.get(id) {
Some(Resource::$enum_type(value)) => Ok(&value),
Some(_) => Err("Wrong resource type".into()),
None => Err("Invalid resource id")
}
}
791b113
to
457dc0c
Compare
a806f75
to
a49727d
Compare
3310940
to
2610d0e
Compare
rask-engine/src/resources/library.rs
Outdated
} | ||
|
||
fn index_check(&self, id: usize) -> Result<(), EngineError> { | ||
if id > self.0.len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not?
impl GetStore<$type> for ResourceTable { | ||
unsafe fn get(&'static self, id: usize) -> Result<&'static $type, EngineError> { | ||
self.index_check(id)?; | ||
match &self.0[id] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Panic? I thought a panic could not occur in your function. I don't get your point. You could do something like
match self.0.get(id).ok_or(myerrorblahblah)? {
}
This does not make any difference for the user
632b3ff
to
80ec91c
Compare
80ec91c
to
5c7ed15
Compare
Todo:
fix bodged find function