diff --git a/.idea/runConfigurations/PublishServer.xml b/.idea/runConfigurations/PublishServer.xml
deleted file mode 100644
index ca40c38..0000000
--- a/.idea/runConfigurations/PublishServer.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/client/src/plugins/camera/systems/camera_system.rs b/client/src/plugins/camera/systems/camera_system.rs
index 01c0300..45f458b 100644
--- a/client/src/plugins/camera/systems/camera_system.rs
+++ b/client/src/plugins/camera/systems/camera_system.rs
@@ -112,10 +112,10 @@ pub fn camera_controller_system(
let word = random_word::get(Lang::En);
- if keyboard_input.just_pressed(KeyCode::Numpad1) {
+ if keyboard_input.just_pressed(KeyCode::KeyQ) {
ctx.0.reducers.set_name(word.to_string()).unwrap();
}
- if keyboard_input.just_pressed(KeyCode::Numpad2) {
+ if keyboard_input.just_pressed(KeyCode::KeyE) {
let rand_position = random_vec3(-10.0,10.0);
ctx.0.reducers.spawn_entity(DbVector3{
x: rand_position.x,
diff --git a/client/src/plugins/network/network_plugin.rs b/client/src/plugins/network/network_plugin.rs
index 904cbb2..d3b3492 100644
--- a/client/src/plugins/network/network_plugin.rs
+++ b/client/src/plugins/network/network_plugin.rs
@@ -10,7 +10,7 @@ pub struct NetworkPlugin;
impl Plugin for NetworkPlugin {
fn build(&self, app: &mut App) {
app.add_systems(PreStartup, setup_database);
- /*app.add_systems(Startup, init);
- app.add_systems(Update, sync_entities_system);*/
+ app.add_systems(Startup, init);
+ app.add_systems(Update, sync_entities_system);
}
}
diff --git a/client/src/plugins/network/systems/database.rs b/client/src/plugins/network/systems/database.rs
index 8956754..2dbe0df 100644
--- a/client/src/plugins/network/systems/database.rs
+++ b/client/src/plugins/network/systems/database.rs
@@ -8,10 +8,10 @@ use crate::plugins::network::systems::connection::*;
use crate::plugins::network::systems::subscriptions::*;
/// The URI of the SpacetimeDB instance hosting our chat module.
-const HOST: &str = "http://192.168.178.10:3000";
+const HOST: &str = "http://100.85.241.101:3000";
/// The database name we chose when we published our module.
-const DB_NAME: &str = "horror-game-test";
+const DB_NAME: &str = "network-game";
#[derive(Resource)]
pub struct DbConnectionResource(pub(crate) DbConnection);
diff --git a/client/src/plugins/network/systems/entities.rs b/client/src/plugins/network/systems/entities.rs
index d686139..77a0482 100644
--- a/client/src/plugins/network/systems/entities.rs
+++ b/client/src/plugins/network/systems/entities.rs
@@ -1,20 +1,25 @@
use std::collections::HashSet;
use bevy::math::Vec3;
use bevy::pbr::{MeshMaterial3d, StandardMaterial};
-use bevy::prelude::{default, Commands, Component, Cuboid, DespawnRecursiveExt, Entity, GlobalTransform, Mesh, Query, Res, ResMut, Sphere, Transform};
+use bevy::prelude::{default, Bundle, Commands, Component, Cuboid, DespawnRecursiveExt, Entity, GlobalTransform, Mesh, Query, Res, ResMut, Sphere, Transform};
use bevy_asset::Assets;
+use bevy_reflect::Reflect;
use bevy_render::mesh::Mesh3d;
use spacetimedb_sdk::Table;
-use crate::module_bindings::{DbVector3, EntityTableAccess, EntityType};
+use crate::module_bindings::{DbTransform, DbVector3, EntityTableAccess, EntityType};
use crate::plugins::network::systems::database::DbConnectionResource;
#[derive(Component)]
pub struct EntityDto {
pub entity_id: u32,
- pub position: DbVector3,
+
+
+ pub transform: DbTransform,
}
+
+
pub fn init(mut commands: Commands,
ctx: Res,
mut meshes: ResMut>,
@@ -29,13 +34,13 @@ pub fn init(mut commands: Commands,
Mesh3d(meshes.add(Cuboid::default()),),
MeshMaterial3d(debug_material.clone ()),
Transform::from_xyz(
- entity.position.x,
- entity.position.y,
- entity.position.z,
+ entity.transform.position.x,
+ entity.transform.position.y,
+ entity.transform.position.z,
),
EntityDto{
entity_id: entity.entity_id,
- position: entity.position,
+ transform: entity.transform
}
));
@@ -70,11 +75,11 @@ pub fn sync_entities_system(
query.iter_mut().find(|(_, _, dto)| dto.entity_id == db_entity.entity_id)
{
// Update fields
- dto.position = db_entity.position.clone();
+ dto.transform.position = db_entity.transform.position.clone();
transform.translation = Vec3::new(
- db_entity.position.x,
- db_entity.position.y,
- db_entity.position.z,
+ db_entity.transform.position.x,
+ db_entity.transform.position.y,
+ db_entity.transform.position.z,
);
} else {
@@ -92,18 +97,19 @@ pub fn sync_entities_system(
};
commands.spawn((
- EntityDto {
- entity_id: db_entity.entity_id,
- position: db_entity.position.clone(),
- },
+
Transform::from_xyz(
- db_entity.position.x,
- db_entity.position.y,
- db_entity.position.z,
+ db_entity.transform.position.x,
+ db_entity.transform.position.y,
+ db_entity.transform.position.z,
),
GlobalTransform::default(),
entity_type,
MeshMaterial3d(debug_material),
+ EntityDto {
+ entity_id: db_entity.entity_id,
+ transform: db_entity.transform.clone(),
+ },
));
}
diff --git a/publish_server.sh b/publish_server.sh
new file mode 100644
index 0000000..3214618
--- /dev/null
+++ b/publish_server.sh
@@ -0,0 +1,5 @@
+
+
+spacetime publish -c --project-path server network-game -y
+rm client\src\module_bindings\*
+spacetime generate --lang rust --out-dir client/src/module_bindings --project-path server
\ No newline at end of file
diff --git a/server/src/lib.rs b/server/src/lib.rs
index 4b98a7f..bdb33fc 100644
--- a/server/src/lib.rs
+++ b/server/src/lib.rs
@@ -3,7 +3,7 @@ mod types;
use spacetimedb::{reducer, ReducerContext, Table};
use crate::types::entity::{entity, entity__TableHandle, Entity, EntityType};
use crate::types::player::{player, player__TableHandle, Player};
-use crate::types::vec3::DbVector3;
+use crate::types::types::{DBVector4, DbTransform, DbVector3};
#[spacetimedb::table(name = config, public)]
pub struct Config {
@@ -30,11 +30,12 @@ pub fn client_connected(ctx: &ReducerContext) {
// which is online, but hasn't set a name.
let entity = ctx.db.entity().try_insert(Entity{
entity_id: 0,
- position: DbVector3 {
- x: 0.0,
- y: 0.0,
- z: 10.0,
+ transform: DbTransform{
+ position: DbVector3{x: 0.0, y: 0.0, z: 10.0},
+ rotation: DBVector4{x: 0.0, y: 0.0, z: 0.0, w: 1.0},
+ scale: DbVector3{x: 1.0, y: 1.0, z: 1.0},
},
+
entity_type: EntityType::Sphere,
}).expect("TODO: panic message");
diff --git a/server/src/types/entity.rs b/server/src/types/entity.rs
index e664447..e7cb282 100644
--- a/server/src/types/entity.rs
+++ b/server/src/types/entity.rs
@@ -1,6 +1,6 @@
use spacetimedb::{Identity, ReducerContext, SpacetimeType, Table};
-use crate::types::vec3::{DbVector3};
+use crate::types::types::{DbVector3, DbTransform, DBVector4};
#[spacetimedb::table(name = entity, public)]
#[derive(Debug, Clone, )]
@@ -8,7 +8,7 @@ pub struct Entity {
#[auto_inc]
#[primary_key]
pub entity_id: u32,
- pub position: DbVector3,
+ pub transform: DbTransform,
pub entity_type: EntityType,
}
@@ -28,7 +28,12 @@ pub fn spawn_entity(ctx: &ReducerContext, position: DbVector3) -> Result<(), Str
ctx.db.entity().try_insert(Entity {
entity_id: 0,
- position,
+ transform: DbTransform{
+ position: position,
+ rotation: DBVector4{x: 0.0, y: 0.0, z: 0.0, w: 1.0},
+ scale: DbVector3 {x: 1.0, y: 1.0, z: 1.0 },
+
+ },
entity_type: EntityType::Cube,
}).expect("TODO: panic message");
diff --git a/server/src/types/mod.rs b/server/src/types/mod.rs
index 100e619..f2ac8b5 100644
--- a/server/src/types/mod.rs
+++ b/server/src/types/mod.rs
@@ -1,3 +1,3 @@
-pub mod vec3;
+pub mod types;
pub mod player;
pub mod entity;
\ No newline at end of file
diff --git a/server/src/types/player.rs b/server/src/types/player.rs
index 38727de..9ed8d0a 100644
--- a/server/src/types/player.rs
+++ b/server/src/types/player.rs
@@ -1,6 +1,7 @@
+use crate::types::entity::*;
+use std::io::empty;
use spacetimedb::{reducer, Identity, ReducerContext, Table};
-use crate::types::entity::{entity, Entity};
-use crate::types::vec3::DbVector3;
+use crate::types::types::{DbTransform, DbVector3};
#[spacetimedb::table(name = player, public)]
#[derive(Debug, Clone)]
@@ -34,7 +35,10 @@ pub fn set_position(ctx: &ReducerContext, position: DbVector3) -> Result<(), Str
if let Some(entity) = ctx.db.entity().iter().find(|e| e.entity_id == ctx.db.player().identity().find(ctx.sender).unwrap().entity_id) {
ctx.db.entity().entity_id()
.update(Entity{
- position,
+ transform: DbTransform{
+ position: position,
+ ..entity.transform
+ },
..entity
});
}
diff --git a/server/src/types/types.rs b/server/src/types/types.rs
new file mode 100644
index 0000000..29d3897
--- /dev/null
+++ b/server/src/types/types.rs
@@ -0,0 +1,25 @@
+use spacetimedb::SpacetimeType;
+
+#[derive(SpacetimeType, Clone, Debug)]
+pub struct DbVector3 {
+ pub x: f32,
+ pub y: f32,
+ pub z: f32,
+}
+
+
+#[derive(SpacetimeType, Clone, Debug)]
+pub struct DBVector4 {
+ pub x: f32,
+ pub y: f32,
+ pub z: f32,
+ pub w: f32,
+}
+
+
+#[derive(SpacetimeType, Clone, Debug)]
+pub struct DbTransform {
+ pub position: DbVector3,
+ pub rotation: DBVector4,
+ pub scale: DbVector3,
+}
\ No newline at end of file
diff --git a/server/src/types/vec3.rs b/server/src/types/vec3.rs
deleted file mode 100644
index 0f75fd1..0000000
--- a/server/src/types/vec3.rs
+++ /dev/null
@@ -1,8 +0,0 @@
-use spacetimedb::SpacetimeType;
-
-#[derive(SpacetimeType, Clone, Debug)]
-pub struct DbVector3 {
- pub x: f32,
- pub y: f32,
- pub z: f32,
-}
\ No newline at end of file
diff --git a/watch_logs.bat b/watch_logs.bat
deleted file mode 100644
index 58d16de..0000000
--- a/watch_logs.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-
-for /l %g in () do @( spacetime logs horror-game-test )
diff --git a/watch_logs.sh b/watch_logs.sh
new file mode 100644
index 0000000..25ffb86
--- /dev/null
+++ b/watch_logs.sh
@@ -0,0 +1,2 @@
+
+watch spacetime logs network-game