Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kanerogers committed Oct 25, 2021
1 parent 986cad5 commit fd1bb2a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
6 changes: 6 additions & 0 deletions examples/beat-saber-clone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ target_sdk_version = 26
[package.metadata.android.application]
debuggable = true

[[package.metadata.android.uses_permission]]
name = "android.permission.INTERNET"

[[package.metadata.android.uses_permission]]
name = "android.permission.ACCESS_NETWORK_STATE"

[[package.metadata.android.application.intent_filter]]
actions = ["android.intent.action.MAIN"]
categories = ["com.oculus.intent.category.VR", "android.intent.category.LAUNCHER"]
13 changes: 13 additions & 0 deletions examples/beat-saber-clone/run_on_device.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
${env:RUST_BACKTRACE} = 1
adb shell am force-stop rust.hotham_beat_saber_example

cargo apk run --release

if ($?) {
Start-Sleep -Seconds 2
$processIdStr = (adb shell pidof rust.beat_saber_example) | Out-String
Write-Output $processIdStr
$processId = $processIdStr -as [int]
Write-Output $processId
adb logcat --pid=$processId
}
17 changes: 9 additions & 8 deletions examples/beat-saber-clone/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use hotham::systems::{
update_transform_matrix_system,
};
use hotham::{gltf_loader, App, HothamResult};
use hotham_debug_server::{create_server, run_server, DebugServer};
use hotham_debug_server::DebugServer;

#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))]
pub fn main() {
Expand All @@ -29,7 +29,7 @@ pub fn real_main() -> HothamResult<()> {
&vulkan_context,
&render_context.descriptor_set_layouts,
)?;
let debug_server = create_server::<SceneParams, SceneData>();
let debug_server: DebugServer<SceneParams, SceneData> = DebugServer::new();

add_model_to_world("Blue Cube", &models, &mut world, None).expect("Unable to add Blue Cube");
add_model_to_world("Red Cube", &models, &mut world, None).expect("Unable to add Red Cube");
Expand All @@ -50,16 +50,17 @@ pub fn real_main() -> HothamResult<()> {
let schedule = Schedule::builder()
.add_thread_local_fn(begin_frame)
.add_thread_local_fn(|_, resources| {
let mut render_context = resources.get_mut::<RenderContext>().unwrap();
let render_context = resources.get::<RenderContext>().unwrap();
let vulkan_context = resources.get::<VulkanContext>().unwrap();
let mut debug_server = resources
.get_mut::<DebugServer<SceneParams, SceneData>>()
.unwrap();
let updated = run_server(
&render_context.scene_data,
&mut debug_server.sender,
&mut debug_server.receiver,
);
if let Some(updated) = debug_server.sync(&render_context.scene_data) {
render_context
.scene_params_buffer
.update(&vulkan_context, &[updated])
.expect("Unable to update data");
};
})
.add_system(collision_system())
.add_thread_local_fn(physics_step)
Expand Down
22 changes: 11 additions & 11 deletions hotham-debug-frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import './App.css';
import { JSONSchema7 } from 'json-schema';
import Box from '@material-ui/core/Box';
import Button from '@material-ui/core/Button';
const ws = new WebSocket('ws://localhost:8080');
const SERVER_IP = 'localhost';
const ws = new WebSocket(`ws://${SERVER_IP}:8080`);

const Form = withTheme<Record<any, string>>(MaterialUITheme);

Expand Down Expand Up @@ -44,6 +45,8 @@ function Container(props: { children: JSX.Element }): JSX.Element {
return <div className="App">{props.children}</div>;
}

let lastUpdate = new Date().getTime();

function App() {
const [editableData, setEditableData] = useState<
Record<string, any> | undefined
Expand All @@ -67,8 +70,11 @@ function App() {
setEditableData(message.Data.editable);
}
if (message.Data.non_editable) {
console.log('Received non data!');
setNonEditableData(message.Data.non_editable);
const deltaTime = lastUpdate - new Date().getTime();
if (deltaTime > 500) {
setNonEditableData(message.Data.non_editable);
lastUpdate = new Date().getTime();
}
}
}
if (message.Init) {
Expand Down Expand Up @@ -98,21 +104,15 @@ function App() {
<></>
</Form>
<Form
liveValidate
noHtml5Validate
formData={editableData}
schema={schema.editable}
onChange={(e, _) => {
setEditableData(e.formData);
}}
onSubmit={(e) => {
if (e.errors.length === 0) update(e.formData);
}}
>
<Box marginTop={3}>
<Button type="submit" variant="contained" color="primary">
Submit
</Button>
</Box>
{null}
</Form>
</>
</Container>
Expand Down
4 changes: 2 additions & 2 deletions hotham/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<T> Buffer<T>
where
T: Sized + Copy,
{
pub(crate) fn new(
pub fn new(
vulkan_context: &VulkanContext,
data: &[T],
usage: vk::BufferUsageFlags,
Expand All @@ -41,7 +41,7 @@ where

/// **NOTE**: If passing in a Vec, you MUST use vec.as_ptr(), passing in
/// a reference will result in A Very Bad Time.
pub(crate) fn update(&self, vulkan_context: &VulkanContext, data: &[T]) -> Result<()> {
pub fn update(&self, vulkan_context: &VulkanContext, data: &[T]) -> Result<()> {
vulkan_context.update_buffer(
data,
self.device_memory,
Expand Down
2 changes: 1 addition & 1 deletion run_on_simulator.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
${env:RUST_BACKTRACE} = 1

if ($?) {
cargo run --bin simple_scene_example --release
cargo run --bin hotham_beat_saber_example --release
}

0 comments on commit fd1bb2a

Please sign in to comment.