Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd WindowMessages resource #387
Conversation
Xaeroxe
requested review from
torkleyy and
omni-viral
Oct 2, 2017
Xaeroxe
added
project: rendering
status: ready
type: improvement
labels
Oct 2, 2017
| + #[cfg(feature = "opengl")] | ||
| + pub fn window(&self) -> &WinitWindow { | ||
| + self.window.window() | ||
| + } |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
torkleyy
reviewed
Oct 2, 2017
Looks good, only a few nits. While this is not the solution I suggested, I won't vote against this solutions since the maintenance and implementation cost wouldn't be on my side. After comments addressed, r=me.
| +/// renderer internal window. | ||
| +pub struct WindowCommander { | ||
| + // It's unlikely we'll get more than two commands per frame | ||
| + // 2 Boxes also make this the same size as a Vec, so this costs |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Xaeroxe
Oct 2, 2017
Member
Every vector is a combination of ptr, length, and capacity. Each of these is WORD size long. When a SmallVec is inline it does not store a ptr, or capacity, it just stores the given array type and the length. Box is WORD size long so if you make the inline array type (2 * WORD size) then even the inline variant doesn't take any more space than it would if it were on the heap. Structure size isn't bloated, and you still get your smallvec optimization.
Xaeroxe
Oct 2, 2017
•
Member
Every vector is a combination of ptr, length, and capacity. Each of these is WORD size long. When a SmallVec is inline it does not store a ptr, or capacity, it just stores the given array type and the length. Box is WORD size long so if you make the inline array type (2 * WORD size) then even the inline variant doesn't take any more space than it would if it were on the heap. Structure size isn't bloated, and you still get your smallvec optimization.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
torkleyy
Oct 2, 2017
Member
The two-element array somehow made me think it's two times pointer-size.
torkleyy
Oct 2, 2017
Member
The two-element array somehow made me think it's two times pointer-size.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
omni-viral
Oct 2, 2017
Member
Hmm. So the SmallVec copies data from stack to heap if you push more elements than array can hold... Is it a good choice? Why not storing only exceeding amount of elements on heap?
Anyway. Two boxed traits have size of 4 pointers though. So your structure is 5 pointers in size. While Vec is 3.
omni-viral
Oct 2, 2017
•
Member
Hmm. So the SmallVec copies data from stack to heap if you push more elements than array can hold... Is it a good choice? Why not storing only exceeding amount of elements on heap?
Anyway. Two boxed traits have size of 4 pointers though. So your structure is 5 pointers in size. While Vec is 3.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Xaeroxe
Oct 2, 2017
Member
Oh hm I guess that's true. I'll remove my comment then. As for storing what you can inline even when it spills, I had the same thought but then you can't operate on a SmallVec as if it were a slice because the memory is not contiguous.
Xaeroxe
Oct 2, 2017
Member
Oh hm I guess that's true. I'll remove my comment then. As for storing what you can inline even when it spills, I had the same thought but then you can't operate on a SmallVec as if it were a slice because the memory is not contiguous.
| + // 2 Boxes also make this the same size as a Vec, so this costs | ||
| + // no more space in the structure than a Vec would. | ||
| + // | ||
| + // NOTE TO FUTURE AUTHORS: This could be an FnOnce but that's not possible |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
torkleyy
Oct 2, 2017
Member
I solved this in https://github.com/slide-rs/specs/pull/214/files , maybe you can use that.
torkleyy
Oct 2, 2017
Member
I solved this in https://github.com/slide-rs/specs/pull/214/files , maybe you can use that.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| + } | ||
| + } | ||
| + | ||
| + /// Execute this closure on the winit::Window next frame. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| +} | ||
| + | ||
| +impl WindowCommander { | ||
| + /// Create a new WindowCommander |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| + pub(crate) queue: SmallVec<[Box<FnMut(&Window) + Send + Sync + 'static>; 2]>, | ||
| +} | ||
| + | ||
| +impl WindowCommander { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
torkleyy
Oct 2, 2017
Member
Meh, this name sounds more like a strategy RTS game's name. Could we rename it? Maybe WindowMessages?
torkleyy
Oct 2, 2017
Member
Meh, this name sounds more like a strategy RTS game's name. Could we rename it? Maybe WindowMessages?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Xaeroxe
Oct 2, 2017
Member
Hahaha
I'll rename it :P
Xaeroxe
Oct 2, 2017
Member
Hahaha
I'll rename it :P
jojolepro
approved these changes
Oct 2, 2017
Not a big fan of having two types of message passing methods, but I guess its fine.
Aceeri
approved these changes
Oct 2, 2017
Looks good to me, just address torkleyys comments.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
bors r=@torkleyy |
Xaeroxe
dismissed
torkleyy’s
stale review
Oct 3, 2017
Addressed
bot
added a commit
that referenced
this pull request
Oct 3, 2017
Xaeroxe
changed the title from
Add WindowCommander resource
to
Add WindowMessages resource
Oct 3, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Canceled |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
bors r=@torkleyy Had to fix my commit message real quick. |
Xaeroxe commentedOct 2, 2017
This is my take on #386
So there's a few benefits to this approach:
cc @Rhuagh @jojolepro