Skip to content

Commit 45dfb8e

Browse files
committed
wip: disable bevy_egui
1 parent 94016cb commit 45dfb8e

File tree

20 files changed

+611
-1470
lines changed

20 files changed

+611
-1470
lines changed

Cargo.lock

Lines changed: 377 additions & 1318 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sandpolis-account/src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,21 @@ use native_db::*;
77
use native_model::{Model, native_model};
88
use sandpolis_core::InstanceId;
99
use sandpolis_database::{Data, DataIdentifier, DatabaseLayer, Resident};
10-
use sandpolis_macros::Data;
10+
use sandpolis_macros::data;
1111
use serde::{Deserialize, Serialize};
1212
use validator::Validate;
1313

14-
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Debug, Data)]
15-
#[native_model(id = 27, version = 1)]
16-
#[native_db]
17-
pub struct AccountLayerData {
18-
#[primary_key]
19-
pub _id: DataIdentifier,
20-
}
14+
#[data]
15+
pub struct AccountLayerData {}
2116

2217
#[derive(Clone)]
2318
pub struct AccountLayer {
2419
database: DatabaseLayer,
2520
}
2621

2722
impl AccountLayer {
28-
pub async fn new() -> Result<Self> {
29-
Ok(Self { database: todo!() })
23+
pub async fn new(database: DatabaseLayer) -> Result<Self> {
24+
Ok(Self { database })
3025
}
3126
}
3227

sandpolis-agent/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl AgentLayer {
3535

3636
/// Polls data periodically.
3737
pub trait Collector {
38-
fn refresh(&mut self) -> Result<()>;
38+
async fn refresh(&mut self) -> Result<()>;
3939
//start
4040
//stop
4141
}

sandpolis-client/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ sandpolis-instance = { path = "../sandpolis-instance", version = "0.0.1" }
1919
sandpolis-database = { path = "../sandpolis-database", version = "0.0.1" }
2020

2121
# GUI dependencies
22-
bevy = { version = "0.16", optional = true }
22+
bevy = { version = "0.16.1", optional = true }
2323
bevy_svg = { version = "0.16.0-rc1", optional = true, features = ["2d"] }
24-
bevy_rapier2d = { version = "0.29.0", optional = true }
24+
bevy_rapier2d = { version = "0.30.0", optional = true }
2525

2626
# TUI dependencies
2727
ratatui = { workspace = true, optional = true }

sandpolis-client/src/gui/input.rs

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use super::{CurrentLayer, ZoomLevel};
2+
use crate::core::layer::Layer;
13
use bevy::{
24
input::{
35
gestures::RotationGesture,
@@ -6,13 +8,8 @@ use bevy::{
68
},
79
prelude::*,
810
};
9-
use bevy_egui::EguiContexts;
1011
use std::ops::Range;
1112

12-
use crate::core::layer::Layer;
13-
14-
use super::{CurrentLayer, ZoomLevel};
15-
1613
#[derive(Resource)]
1714
pub struct MousePressed(pub bool);
1815

@@ -127,38 +124,38 @@ pub fn handle_camera(
127124

128125
/// Show a help window with keyboard shortcuts.
129126
pub fn handle_keymap(
130-
mut contexts: EguiContexts,
127+
// mut contexts: EguiContexts,
131128
keyboard_input: Res<ButtonInput<KeyCode>>,
132129
mut windows: Query<&mut Window>,
133130
) {
134131
if keyboard_input.pressed(KeyCode::KeyK) {
135132
let window_size = windows.single_mut().size();
136133

137134
// TODO separate window for layers and highlight active (HUD)
138-
egui::Window::new("Keyboard shortcuts")
139-
.id(egui::Id::new("keymap"))
140-
.pivot(egui::Align2::CENTER_CENTER)
141-
.resizable(false)
142-
.movable(false)
143-
.collapsible(false)
144-
.fixed_pos(egui::Pos2::new(window_size.x / 2.0, window_size.y / 2.0))
145-
.show(contexts.ctx_mut(), |ui| {
146-
ui.label("W - Pan camera upwards");
147-
ui.label("A - Pan camera upwards");
148-
ui.label("S - Pan camera upwards");
149-
ui.label("D - Pan camera upwards");
150-
ui.label("> - Next layer");
151-
ui.label("< - Previous layer");
152-
ui.label("M - Meta layer");
153-
ui.label("F - Filesystem layer");
154-
});
135+
// egui::Window::new("Keyboard shortcuts")
136+
// .id(egui::Id::new("keymap"))
137+
// .pivot(egui::Align2::CENTER_CENTER)
138+
// .resizable(false)
139+
// .movable(false)
140+
// .collapsible(false)
141+
// .fixed_pos(egui::Pos2::new(window_size.x / 2.0, window_size.y /
142+
// 2.0)) .show(contexts.ctx_mut(), |ui| {
143+
// ui.label("W - Pan camera upwards");
144+
// ui.label("A - Pan camera upwards");
145+
// ui.label("S - Pan camera upwards");
146+
// ui.label("D - Pan camera upwards");
147+
// ui.label("> - Next layer");
148+
// ui.label("< - Previous layer");
149+
// ui.label("M - Meta layer");
150+
// ui.label("F - Filesystem layer");
151+
// });
155152
}
156153
}
157154

158155
/// Switch to another layer from keypress
159156
pub fn handle_layer_change(
160157
commands: Commands,
161-
mut contexts: EguiContexts,
158+
// mut contexts: EguiContexts,
162159
keyboard_input: Res<ButtonInput<KeyCode>>,
163160
mut current_layer: ResMut<CurrentLayer>,
164161
time: Res<Time>,
@@ -187,16 +184,16 @@ pub fn handle_layer_change(
187184
if !timer.tick(time.delta()).finished() {
188185
let window_size = windows.single_mut().size();
189186
// TODO util
190-
egui::Window::new("Current layer")
191-
.id(egui::Id::new("current_layer"))
192-
.pivot(egui::Align2::CENTER_CENTER)
193-
.resizable(false)
194-
.movable(false)
195-
.collapsible(false)
196-
.title_bar(false)
197-
.fixed_pos(egui::Pos2::new(window_size.x / 2.0, window_size.y - 30.0))
198-
.show(contexts.ctx_mut(), |ui| {
199-
ui.label(format!("{:?}", **current_layer));
200-
});
187+
// egui::Window::new("Current layer")
188+
// .id(egui::Id::new("current_layer"))
189+
// .pivot(egui::Align2::CENTER_CENTER)
190+
// .resizable(false)
191+
// .movable(false)
192+
// .collapsible(false)
193+
// .title_bar(false)
194+
// .fixed_pos(egui::Pos2::new(window_size.x / 2.0, window_size.y -
195+
// 30.0)) .show(contexts.ctx_mut(), |ui| {
196+
// ui.label(format!("{:?}", **current_layer));
197+
// });
201198
}
202199
}

sandpolis-client/src/gui/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct CurrentLayer(Layer);
2323
pub struct ZoomLevel(f32);
2424

2525
/// Initialize and start rendering the UI.
26-
pub async fn main(args: CommandLine) -> Result<()> {
26+
pub async fn main(config: Configuration, state: InstanceState) -> Result<()> {
2727
let mut app = App::new();
2828
app.add_plugins(
2929
DefaultPlugins
@@ -82,7 +82,7 @@ fn setup(
8282
mut rapier_config: Query<&mut RapierConfiguration>,
8383
asset_server: Res<AssetServer>,
8484
db: Res<Database>,
85-
contexts: EguiContexts,
85+
// contexts: EguiContexts,
8686
) {
8787
for mut rapier_config in &mut rapier_config {
8888
rapier_config.gravity = Vec2::ZERO;

sandpolis-client/src/gui/node.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use bevy::prelude::*;
2-
use bevy_egui::EguiContexts;
32
use bevy_rapier2d::{
43
dynamics::RigidBody,
54
geometry::{Collider, Restitution},
@@ -51,25 +50,25 @@ pub struct WindowStack {}
5150

5251
pub fn handle_window_stacks(
5352
commands: Commands,
54-
mut contexts: EguiContexts,
53+
// mut contexts: EguiContexts,
5554
mut nodes: Query<(&mut Transform, (&InstanceId, &WindowStack)), With<InstanceId>>,
5655
mut windows: Query<&mut Window>,
5756
cameras: Query<&Transform, (With<Camera2d>, Without<InstanceId>)>,
5857
) {
5958
let window_size = windows.single_mut().size();
6059
let camera_transform = cameras.single();
6160

62-
for (transform, (id, window_stack)) in nodes.iter_mut() {
63-
egui::Window::new("Hello")
64-
.movable(false)
65-
.resizable(false)
66-
.pivot(egui::Align2::CENTER_TOP)
67-
.current_pos(egui::Pos2::new(
68-
window_size.x / 2.0 + transform.translation.x - camera_transform.translation.x,
69-
window_size.y / 2.0 + transform.translation.y + camera_transform.translation.y,
70-
))
71-
.show(contexts.ctx_mut(), |ui| {
72-
ui.label("world");
73-
});
74-
}
61+
// for (transform, (id, window_stack)) in nodes.iter_mut() {
62+
// egui::Window::new("Hello")
63+
// .movable(false)
64+
// .resizable(false)
65+
// .pivot(egui::Align2::CENTER_TOP)
66+
// .current_pos(egui::Pos2::new(
67+
// window_size.x / 2.0 + transform.translation.x -
68+
// camera_transform.translation.x, window_size.y / 2.0 +
69+
// transform.translation.y + camera_transform.translation.y, ))
70+
// .show(contexts.ctx_mut(), |ui| {
71+
// ui.label("world");
72+
// });
73+
// }
7574
}

sandpolis-client/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pub mod cli;
22
pub mod config;
33

4-
// #[cfg(feature = "client-gui")]
5-
// pub mod gui;
4+
#[cfg(feature = "client-gui")]
5+
pub mod gui;
66

77
#[cfg(feature = "client-tui")]
88
pub mod tui;

sandpolis-database/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@ Entries in the database (uncreatively called `Data`) are defined by Rust
1515
structs:
1616

1717
```rs
18-
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Data)]
19-
#[native_model(id = 15, version = 1)]
20-
#[native_db]
18+
#[data]
2119
pub struct ExampleData {
22-
#[primary_key]
23-
pub _id: DataIdentifier,
24-
2520
pub value: u32,
2621
}
2722
```

sandpolis-database/src/lib.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ where
178178
T: Data,
179179
{
180180
db: Arc<native_db::Database<'static>>,
181-
cache: Arc<RwLock<T>>,
181+
inner: Arc<RwLock<T>>,
182182

183183
/// Used to stop the database from sending updates
184184
watch_id: u64,
@@ -251,15 +251,19 @@ impl<T: Data + 'static> Resident<T> {
251251
});
252252

253253
Ok(Self {
254-
cache,
254+
inner: cache,
255255
watch_id,
256256
cancel_token,
257257
db,
258258
})
259259
}
260260

261261
pub async fn read(&self) -> RwLockReadGuard<'_, T> {
262-
self.cache.read().await
262+
self.inner.read().await
263+
}
264+
265+
pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
266+
self.inner.write().await
263267
}
264268
}
265269

@@ -268,7 +272,7 @@ impl<T: Data> Resident<T> {
268272
where
269273
F: Fn(&mut T) -> Result<()>,
270274
{
271-
let cache = self.cache.read().await;
275+
let cache = self.inner.read().await;
272276
let mut next = cache.clone();
273277
mutator(&mut next)?;
274278

@@ -279,7 +283,7 @@ impl<T: Data> Resident<T> {
279283

280284
drop(cache);
281285

282-
let mut cache = self.cache.write().await;
286+
let mut cache = self.inner.write().await;
283287
*cache = next;
284288
}
285289

@@ -290,7 +294,7 @@ impl<T: Data> Resident<T> {
290294
impl<T: HistoricalData> Resident<T> {
291295
pub async fn history(&self, range: RangeFrom<DbTimestamp>) -> Result<Vec<T>> {
292296
// Get values of all secondary keys
293-
let mut secondary_keys = (*self.cache.read().await).native_db_secondary_keys();
297+
let mut secondary_keys = (*self.inner.read().await).native_db_secondary_keys();
294298

295299
// Remove timestamp because we're going to set that one manually
296300
secondary_keys.retain(|key_def, _| *key_def != T::timestamp_key());
@@ -445,7 +449,7 @@ where
445449
T: Data,
446450
{
447451
db: Arc<native_db::Database<'static>>,
448-
cache: Arc<RwLock<Vec<Resident<T>>>>,
452+
inner: Arc<RwLock<Vec<Resident<T>>>>,
449453

450454
/// Used to stop the database from sending updates
451455
watch_id: u64,
@@ -465,4 +469,12 @@ impl<T: Data> ResidentVec<T> {
465469
pub fn is_detached(&self) -> bool {
466470
false
467471
}
472+
473+
pub async fn read(&self) -> RwLockReadGuard<'_, Vec<Resident<T>>> {
474+
self.inner.read().await
475+
}
476+
477+
pub async fn write(&self) -> RwLockWriteGuard<'_, Vec<Resident<T>>> {
478+
self.inner.write().await
479+
}
468480
}

0 commit comments

Comments
 (0)