Skip to content

Commit

Permalink
(WIP) Transition to morton indices in one large buffer, lots of optim…
Browse files Browse the repository at this point in the history
…izations, better fog culling, compact visibility model
  • Loading branch information
burgerindividual committed Jul 30, 2023
1 parent 777b5a4 commit 48d7cc3
Show file tree
Hide file tree
Showing 22 changed files with 1,093 additions and 891 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ tasks.register('remapApiJar', RemapJarTask) {

build.dependsOn apiJar
build.dependsOn remapApiJar
build.dependsOn buildNatives
//build.dependsOn buildNatives

jar {
from sourceSets.api.output.classesDirs
Expand Down
14 changes: 13 additions & 1 deletion native/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ debug = true

[profile.release]
panic = "abort"
lto = "thin"

[profile.asm]
inherits = "release"
panic = "abort"
debug = true
lto = "off"

[profile.production]
inherits = "release"
lto = true
lto = "fat"

[profile.profiling]
inherits = "release"
lto = "fat"
debug = true

[dependencies]
rustc-hash = "1.1.0"
Expand Down
36 changes: 15 additions & 21 deletions native/core/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::boxed::Box;
use std::mem::MaybeUninit;
use std::ptr;

use crate::frustum::Frustum;
use crate::graph::frustum::LocalFrustum;
use crate::graph::*;
use crate::jni::types::*;
use crate::math::*;
Expand Down Expand Up @@ -67,12 +67,6 @@ impl<T, const LEN: usize> CInlineVec<T, LEN> {
}
}

#[repr(C)]
pub struct CGraphNode {
connections: u64,
flags: u32,
}

#[allow(non_snake_case)]
mod java {
use std::boxed::Box;
Expand All @@ -82,7 +76,7 @@ mod java {
use core_simd::simd::f32x4;

use crate::ffi::*;
use crate::frustum::Frustum;
use crate::graph::frustum::LocalFrustum;
use crate::graph::*;
use crate::jni::types::*;
use crate::math::*;
Expand Down Expand Up @@ -124,7 +118,7 @@ mod java {
}

#[no_mangle]
pub unsafe extern "C" fn Java_me_jellysquid_mods_sodium_core_CoreLibFFI_graphAddChunk(
pub unsafe extern "C" fn Java_me_jellysquid_mods_sodium_core_CoreLibFFI_graphAddSection(
_: *mut JEnv,
_: *mut JClass,
graph: JPtrMut<Graph>,
Expand All @@ -133,30 +127,30 @@ mod java {
z: Jint,
) {
let graph = graph.into_mut_ref();
graph.add_chunk(i32x3::from_xyz(x, y, z));
graph.add_chunk(LocalSectionCoord::from_xyz(x, y, z));
}

#[no_mangle]
pub unsafe extern "C" fn Java_me_jellysquid_mods_sodium_core_CoreLibFFI_graphUpdateChunk(
pub unsafe extern "C" fn Java_me_jellysquid_mods_sodium_core_CoreLibFFI_graphUpdateSection(
_: *mut JEnv,
_: *mut JClass,
graph: JPtrMut<Graph>,
x: Jint,
y: Jint,
z: Jint,
node: JPtr<CGraphNode>,
node: JPtr<CSectionData>,
) {
let node = node.as_ref();

let graph = graph.into_mut_ref();
graph.update_chunk(
i32x3::from_xyz(x, y, z),
Node::new(VisibilityData::from_u64(node.connections), node.flags as u8),
LocalSectionCoord::from_xyz(x, y, z),
Node::new(VisibilityData::pack(node.connections), node.flags as u8),
);
}

#[no_mangle]
pub unsafe extern "C" fn Java_me_jellysquid_mods_sodium_core_CoreLibFFI_graphRemoveChunk(
pub unsafe extern "C" fn Java_me_jellysquid_mods_sodium_core_CoreLibFFI_graphRemoveSection(
_: *mut JEnv,
_: *mut JClass,
graph: JPtrMut<Graph>,
Expand All @@ -165,15 +159,15 @@ mod java {
z: Jint,
) {
let graph = graph.into_mut_ref();
graph.remove_chunk(i32x3::from_xyz(x, y, z));
graph.remove_chunk(LocalSectionCoord::from_xyz(x, y, z));
}

#[no_mangle]
pub unsafe extern "C" fn Java_me_jellysquid_mods_sodium_core_CoreLibFFI_graphSearch(
_: *mut JEnv,
_: *mut JClass,
graph: JPtrMut<Graph>,
frustum: JPtr<Frustum>,
frustum: JPtr<LocalFrustum>,
view_distance: Jint,
out_results: JPtrMut<CVec<RegionDrawBatch>>,
) {
Expand All @@ -197,15 +191,15 @@ mod java {
pub unsafe extern "C" fn Java_me_jellysquid_mods_sodium_core_CoreLibFFI_frustumCreate(
_: *mut JEnv,
_: *mut JClass,
out_frustum: JPtrMut<*const Frustum>,
out_frustum: JPtrMut<*const LocalFrustum>,
planes: JPtr<[[f32; 4]; 6]>,
offset: JPtr<[f32; 3]>,
) {
let planes = planes.as_ref().map(f32x4::from_array);
let planes = planes.as_ref().map(f32x3::from_array);

let offset = f32x3::from_array(*offset.as_ref());

let frustum = Box::new(Frustum::new(planes, offset));
let frustum = Box::new(LocalFrustum::new(planes, offset));

let out_frustum = out_frustum.into_mut_ref();
*out_frustum = Box::into_raw(frustum);
Expand All @@ -215,7 +209,7 @@ mod java {
pub unsafe extern "C" fn Java_me_jellysquid_mods_sodium_core_CoreLibFFI_frustumDelete(
_: *mut JEnv,
_: *mut JClass,
frustum: JPtrMut<Frustum>,
frustum: JPtrMut<LocalFrustum>,
) {
std::mem::drop(Box::from_raw(frustum.into_mut_ref()));
}
Expand Down
83 changes: 0 additions & 83 deletions native/core/src/frustum.rs

This file was deleted.

Loading

0 comments on commit 48d7cc3

Please sign in to comment.