-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michael Pollind <[email protected]>
- Loading branch information
Showing
6 changed files
with
145 additions
and
18 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
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,69 @@ | ||
use smallvec; | ||
|
||
pub struct Range { | ||
start: u32, | ||
end: u32 | ||
} | ||
|
||
pub struct IDPool { | ||
used: u32, | ||
free: Vec<Range> | ||
} | ||
|
||
impl IDPool { | ||
pub fn fetch_id(&mut self) -> u32 { | ||
match self.free.last_mut() { | ||
Some(range) => { | ||
let id = range.start; | ||
range.start += 1; | ||
if range.start > range.end { | ||
self.free.pop(); | ||
} | ||
id | ||
}, | ||
None => { | ||
let id = self.used; | ||
self.used += 1; | ||
id | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
pub fn return_id(&mut self, id: u32) { | ||
if self.free.is_empty() { | ||
self.free.push(Range { start: id, end: id}) | ||
} | ||
|
||
match self.free.binary_search_by(|probe| { | ||
if id >= probe.start && id <= probe.end { | ||
std::cmp::Ordering::Equal | ||
} else { | ||
probe.start.cmp(&id) | ||
} | ||
}) { | ||
Ok(_index) => { | ||
panic!("id returned multiple times to the pool"); | ||
}, | ||
Err(index) => { | ||
let current_range = &mut self.free[index]; | ||
if id + 1 == current_range.start { | ||
current_range.start -= 1; | ||
if index > 0 { | ||
let update_end = current_range.end; | ||
let previous_range = &mut self.free[index - 1]; | ||
if previous_range.end + 1 == id { | ||
previous_range.end = update_end; | ||
self.free.remove(index); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
} | ||
|
||
} | ||
} |
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ mod math; | |
#[macro_use] | ||
extern crate log; | ||
mod scene; | ||
mod id_pool; |
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 |
---|---|---|
@@ -1,21 +1,82 @@ | ||
use glam::u32; | ||
use jni::sys::jlong; | ||
use crate::id_pool::IDPool; | ||
use crate::resource::chunk_mesh_resource::ChunkMeshResource; | ||
use std::sync::Arc; | ||
use crate::ui::{JavaHandle, arc_from_handle, arc_to_handle, arc_dispose_handle}; | ||
use std::sync::{Weak,Arc, Mutex}; | ||
|
||
pub struct Scene { | ||
opaque_chunks: Vec<Arc<ChunkMeshResource>> | ||
pub struct SceneChunk { | ||
pub transform: glam::Mat4, | ||
pub mesh: Option<std::sync::Weak<Mutex<ChunkMeshResource>>> | ||
} | ||
|
||
impl Scene { | ||
impl SceneChunk { | ||
} | ||
|
||
pub fn cmd_prepare(&mut self) { | ||
|
||
impl JavaHandle<Arc<SceneChunk>> for SceneChunk { | ||
fn from_handle(ptr: jlong) -> Option<Arc<SceneChunk>> { | ||
arc_from_handle(ptr) | ||
} | ||
|
||
pub fn cmd_dispatch(&mut self) { | ||
fn to_handle(from: Arc<SceneChunk>) -> jlong { | ||
arc_to_handle(from) | ||
} | ||
|
||
fn drop_handle(ptr: jlong) { | ||
arc_dispose_handle::<SceneChunk>(ptr); | ||
} | ||
} | ||
|
||
pub fn cmd_queue_opaque_chunk() { | ||
pub struct Scene { | ||
chunk_uniform_buffer: wgpu::Buffer, | ||
|
||
chunk_id_pool: IDPool, | ||
chunk_pool: smallvec::SmallVec<[SceneChunk; 1024]> | ||
} | ||
|
||
} | ||
|
||
pub struct ChunkMutator<'a>{ | ||
chunk: &'a SceneChunk, | ||
scene: &'a Scene, | ||
index: u32 | ||
} | ||
|
||
impl<'a> ChunkMutator<'a> { | ||
|
||
} | ||
|
||
pub type ChunkHandle = u32; | ||
impl Scene { | ||
// pub fn register_chunk<'a>(&mut self) -> ChunkHandle { | ||
// let chunk_id = self.chunk_id_pool.fetch_id(); | ||
// let new_chunk = SceneChunk { | ||
// transform: glam::Mat4::IDENTITY, | ||
// mesh: None | ||
// }; | ||
// | ||
// match self.chunk_pool.get_mut(chunk_id as usize) { | ||
// Some(view) => { | ||
// (*view) = new_chunk; | ||
// }, | ||
// None => { | ||
// self.chunk_pool.push(new_chunk); | ||
// } | ||
// } | ||
// return chunk_id ; | ||
// } | ||
// | ||
// pub fn return_chunk(&mut self, id: ChunkHandle) { | ||
// self.chunk_id_pool.return_id(id); | ||
// } | ||
// pub fn fetch_chunk<'a>(&'a mut self, id: ChunkHandle) -> ChunkMutator<'a> { | ||
// ChunkMutator { | ||
// chunk: &self.chunk_pool[id as usize], | ||
// scene: self, | ||
// index: id | ||
// } | ||
// } | ||
|
||
} | ||
|
||
|
||
|