Skip to content

Commit d6dd88a

Browse files
committed
feat: extract bigworlds-core
1 parent 04d60d1 commit d6dd88a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1010
-520
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
resolver = "2"
33
members = [
44
"bigworlds",
5+
"bigworlds-core",
56
"bigworlds-cli",
67
"clients/grpc-client",
78
"examples/*/viewers/*",
8-
"examples/*/behaviors/*",
9+
"examples/*/behaviors/*",
910
]
1011

1112
exclude = [

bigworlds-cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ path = "src/main.rs"
1616
[features]
1717
default = ["ws_client"]
1818
ws_client = ["bigworlds/ws_transport"]
19-
archive = ["bigworlds/archive"]
2019
msgpack = ["bigworlds/msgpack_encoding"]
2120

2221
[dependencies]

bigworlds-cli/src/interactive/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tokio_util::sync::CancellationToken;
2020
use uuid::Uuid;
2121

2222
use bigworlds::client::r#async::AsyncClient;
23-
use bigworlds::query;
23+
use bigworlds::{query, Query};
2424

2525
use crate::interactive::config::{Config, CONFIG_FILE};
2626

@@ -323,6 +323,15 @@ pub async fn start(
323323
.inspect_err(|e| error!("{}", e));
324324
}
325325
}
326+
"count" => {
327+
let prod = client
328+
.query(Query {
329+
mappings: vec![query::Map::Var("position".to_owned())],
330+
..Default::default()
331+
})
332+
.await?;
333+
println!("current entity count: {}", prod.to_vec().len());
334+
}
326335
// Write an uncompressed snapshot to disk.
327336
"snap" => {
328337
if args.contains(" ") {

bigworlds-core/Cargo.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[package]
2+
name = "bigworlds-core"
3+
version = "0.1.1"
4+
edition = "2024"
5+
6+
[features]
7+
# use fixed-size string ids (23 chars long)
8+
small_stringid = []
9+
# use fixed-size string ids (10 chars long)
10+
tiny_stringid = []
11+
# use 64 bit integers and floats instead of default 32 bit
12+
big_nums = []
13+
14+
[dependencies]
15+
serde = "1"
16+
serde_repr = "0.1"
17+
serde_json = { version = "1" }
18+
19+
uuid = { version = "1", features = ["v4", "serde"] }
20+
fnv = "1"
21+
22+
thiserror = "1"
23+
24+
rkyv = { version = "0.8", features = [
25+
"uuid-1",
26+
"smallvec-1",
27+
"arrayvec-0_7",
28+
], optional = true }
29+
30+
[target.'cfg(target_arch = "wasm32")'.dependencies]
31+
uuid = { version = "1.13.1", default-features = false, features = ["js"] }
32+
wasm-bindgen = "0.2.101"

bigworlds/src/address.rs renamed to bigworlds-core/src/address.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ use std::str::FromStr;
55

66
use serde::{Deserialize, Serialize};
77

8-
use crate::entity::StorageIndex;
8+
use crate::StorageIndex;
99
use crate::error::{Error, Result};
10-
use crate::{CompName, EntityName, VarName, VarType};
10+
use crate::var::VarType;
11+
use crate::{CompName, EntityName, VarName};
1112

1213
pub const SEPARATOR_SYMBOL: &'static str = ".";
1314

1415
/// Entity-scope address that can also handle component-scope locality.
1516
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1617
#[cfg_attr(
17-
feature = "archive",
18+
feature = "rkyv",
1819
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
1920
)]
2021
pub struct ShortLocalAddress {
@@ -60,7 +61,7 @@ impl ShortLocalAddress {
6061
var_name: s.to_owned(),
6162
})
6263
} else {
63-
Err(Error::InvalidData("".to_owned()))
64+
Err(Error::Other("".to_owned()))
6465
}
6566
}
6667

@@ -140,10 +141,10 @@ impl ShortLocalAddress {
140141
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
141142
#[cfg_attr(feature = "small_stringid", derive(Copy))]
142143
#[cfg_attr(
143-
feature = "archive",
144+
feature = "rkyv",
144145
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
145146
)]
146-
#[cfg_attr(feature = "archive", rkyv(derive(Hash, PartialEq, Eq)))]
147+
#[cfg_attr(feature = "rkyv", rkyv(derive(Hash, PartialEq, Eq)))]
147148
pub struct LocalAddress {
148149
pub comp: CompName,
149150
pub var_type: VarType,
@@ -193,10 +194,10 @@ impl LocalAddress {
193194
/// Globally unique reference to simulation variable.
194195
#[derive(Debug, Hash, Eq, PartialEq, Clone, Serialize, Deserialize)]
195196
#[cfg_attr(
196-
feature = "archive",
197+
feature = "rkyv",
197198
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
198199
)]
199-
#[cfg_attr(feature = "archive", rkyv(derive(Hash, PartialEq, Eq)))]
200+
#[cfg_attr(feature = "rkyv", rkyv(derive(Hash, PartialEq, Eq)))]
200201
pub struct Address {
201202
pub entity: EntityName,
202203
pub comp: CompName,
@@ -227,7 +228,7 @@ impl FromStr for Address {
227228
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
228229
let split = s.split(SEPARATOR_SYMBOL).collect::<Vec<&str>>();
229230
if split.len() != 4 {
230-
return Err(Error::FailedCreatingAddress(s.to_string()));
231+
return Err(Error::InvalidAddress(s.to_string()));
231232
}
232233
Ok(Address {
233234
entity: split[0].to_owned(),
@@ -265,7 +266,7 @@ impl Address {
265266
#[derive(Debug, Clone, Serialize, Deserialize)]
266267
#[cfg_attr(feature = "small_stringid", derive(Copy))]
267268
#[cfg_attr(
268-
feature = "archive",
269+
feature = "rkyv",
269270
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
270271
)]
271272
pub struct PartialAddress {
@@ -298,7 +299,7 @@ impl FromStr for PartialAddress {
298299
var_name: split[2].to_owned(),
299300
})
300301
} else {
301-
Err(Error::FailedCreatingAddress(s.to_string()))
302+
Err(Error::InvalidPartialAddress(s.to_string()))
302303
}
303304
}
304305
}

bigworlds-core/src/error.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use thiserror::Error;
2+
3+
pub type Result<T> = core::result::Result<T, Error>;
4+
5+
/// Enumeration of all possible errors.
6+
#[derive(Error, Clone, Debug, Serialize, Deserialize)]
7+
pub enum Error {
8+
#[error("parsing error: {0}")]
9+
ParsingError(String),
10+
#[error("failed parsing int: {0}")]
11+
ParseIntError(String),
12+
#[error("failed parsing float: {0}")]
13+
ParseFloatError(String),
14+
#[error("failed parsing bool: {0}")]
15+
ParseBoolError(String),
16+
17+
#[error("invalid var type: {0}")]
18+
InvalidVarType(String),
19+
#[error("failed creating var: {0}")]
20+
FailedCreatingVar(String),
21+
22+
#[error("invalid address: {0}")]
23+
InvalidAddress(String),
24+
#[error("invalid partial address: {0}")]
25+
InvalidPartialAddress(String),
26+
#[error("invalid local address: {0}")]
27+
InvalidLocalAddress(String),
28+
29+
#[error("failed conversion: {0}")]
30+
FailedConversion(String),
31+
32+
#[error("serde json error: {0}")]
33+
SerdeJsonError(String),
34+
35+
#[error("other: {0}")]
36+
Other(String),
37+
}
38+
39+
#[cfg(feature = "rkyv")]
40+
impl From<rkyv::rancor::Error> for Error {
41+
fn from(e: rkyv::rancor::Error) -> Self {
42+
Self::RkyvError(e.to_string())
43+
}
44+
}
45+
46+
impl From<serde_json::Error> for Error {
47+
fn from(e: serde_json::Error) -> Self {
48+
Self::SerdeJsonError(e.to_string())
49+
}
50+
}
51+
52+
impl From<std::num::ParseFloatError> for Error {
53+
fn from(e: std::num::ParseFloatError) -> Self {
54+
Self::ParseFloatError(e.to_string())
55+
}
56+
}
57+
58+
impl From<std::num::ParseIntError> for Error {
59+
fn from(e: std::num::ParseIntError) -> Self {
60+
Self::ParseIntError(e.to_string())
61+
}
62+
}
63+
64+
impl From<std::str::ParseBoolError> for Error {
65+
fn from(e: std::str::ParseBoolError) -> Self {
66+
Self::ParseBoolError(e.to_string())
67+
}
68+
}

bigworlds-core/src/lib.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// NOTE: extern crate syntax is obsolete, but still provides global macro
2+
// imports.
3+
#[macro_use]
4+
extern crate serde;
5+
// #[macro_use]
6+
// extern crate log;
7+
8+
pub mod address;
9+
pub mod error;
10+
pub mod query;
11+
pub mod var;
12+
13+
pub mod time;
14+
15+
pub type StorageIndex = (CompName, VarName);
16+
17+
/// Floating point numer type used throughout the library.
18+
#[cfg(feature = "big_nums")]
19+
pub type Float = f64;
20+
/// Floating point numer type used throughout the library.
21+
#[cfg(not(feature = "big_nums"))]
22+
pub type Float = f32;
23+
24+
/// Integer number type used throughout the library.
25+
#[cfg(feature = "big_nums")]
26+
pub type Int = i64;
27+
/// Integer number type used throughout the library.
28+
#[cfg(not(feature = "big_nums"))]
29+
pub type Int = i32;
30+
31+
/// Entity string identifier.
32+
pub type EntityName = String;
33+
/// Entity prefab string identifier.
34+
pub type PrefabName = String;
35+
/// Component string identifier.
36+
pub type CompName = String;
37+
/// Variable string identifier.
38+
pub type VarName = String;
39+
/// Event string identifier.
40+
pub type EventName = String;
41+
42+
/// Entity unique integer identifier.
43+
pub type EntityId = u32;

0 commit comments

Comments
 (0)