Skip to content

Commit

Permalink
Fully break dep on autocxx
Browse files Browse the repository at this point in the history
Add benchmarks to README for fun
  • Loading branch information
VirxEC committed May 16, 2024
1 parent 1296b8c commit c024beb
Show file tree
Hide file tree
Showing 19 changed files with 713 additions and 678 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ exclude = [".git*", "CMake*", "collision_meshes", "rustfmt.toml", "*.py", "pytho
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
autocxx = "0.26.0"
cxx = { version = "1.0.83", features = ["c++20"] }
glam = { version = "0.27.0", optional = true }
serde = { version = "1.0.195", optional = true, features = ["derive"] }

[build-dependencies]
glob = "0.3.0"
autocxx-build = "0.26.0"
miette = { version = "5", features = ["fancy"] }
cc = { version = "1.0.83", features = ["parallel"] }
cxx-build = "1.0.122"

[profile.release]
lto = true
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,32 @@ fn main() {
println!("New ball location: {}", arena.pin_mut().get_ball().pos);
}
```

## Benchmarks

Numbers are from a system running Ubuntu 23.10 with a Ryzen 9 5900X and 3600MHz CL18 RAM.

Numbers _will_ vary depending on your system. Only default features are enabled.

- `real_bench`:

```bash
Running on 24 threads
Simulated 2.78 hours in 1.485 seconds
FPS: 808348.4
```

- `cpu_bench`:

```bash
Running on 24 threads
Simulated 55.56 hours in 0.893 seconds
FPS: 26883894
```

- `thread_bench` (1 thread):

```bash
Simulated 0.58 hours in 3.556 seconds
FPS: 70312.516
```
2 changes: 1 addition & 1 deletion arenar/arenar.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "RocketSim.h"
#include "cxx.h"
#include "rust/cxx.h"

using namespace RocketSim;

Expand Down
43 changes: 28 additions & 15 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
use autocxx_build::Builder;
use cxx_build::bridges;
use glob::glob;
use miette::{IntoDiagnostic, Result};
use std::path::PathBuf;

fn main() -> Result<()> {
let mut builder = Builder::new("src/lib.rs", ["RocketSim/src/", "arenar/"])
.extra_clang_args(&["-std=c++20", "-march=native"])
.build()?;
fn main() {
println!("cargo:rerun-if-changed=src/lib.rs");

let cpp_files = glob("RocketSim/libsrc/bullet3-3.24/**/*.cpp")
.unwrap()
.chain(glob("RocketSim/src/**/*.cpp").unwrap())
.flatten()
.chain([PathBuf::from("arenar/arenar.cpp")])
.collect::<Vec<_>>();

for file in &cpp_files {
println!("cargo:rerun-if-changed={}", file.display());
}

let rust_files: Vec<PathBuf> = glob("src/sim/*.rs")
.unwrap()
.chain(glob("RocketSim/src/**/*.rs").unwrap())
.flatten()
.filter(|path| !path.ends_with("mod.rs"))
.chain([PathBuf::from("src/math.rs"), PathBuf::from("src/lib.rs")])
.collect::<Vec<_>>();

let mut builder = bridges(rust_files);

if !cfg!(debug_assertions) || !cfg!(feature = "debug_logging") {
builder.define("RS_DONT_LOG", "1");
Expand All @@ -16,18 +35,12 @@ fn main() -> Result<()> {
}

builder
.includes(["RocketSim/src/", "arenar/"])
.std("c++20")
.use_plt(false)
.flag_if_supported("-march=native")
.flag_if_supported("-std=c++20")
.flag_if_supported("/std:c++20")
.flag_if_supported("-w")
.files(glob("RocketSim/libsrc/bullet3-3.24/**/*.cpp").into_diagnostic()?.flatten())
.files(glob("RocketSim/src/**/*.cpp").into_diagnostic()?.flatten())
.file("arenar/arenar.cpp")
.files(cpp_files)
.warnings(false)
.compile("rocketsim");

println!("cargo:rerun-if-changed=src/lib.rs");

Ok(())
}
2 changes: 1 addition & 1 deletion examples/cpu_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

fn main() {
const TICKS: u32 = 600_000;
const TICKS: u32 = 1_000_000;

rocketsim_rs::init(None);

Expand Down
2 changes: 1 addition & 1 deletion examples/thread_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rocketsim_rs::sim::{Arena, CarConfig, Team};
use std::time::Instant;

fn main() {
const TICKS: u32 = 50000;
const TICKS: u32 = 250_000;

// load in assets
rocketsim_rs::init(None);
Expand Down
46 changes: 41 additions & 5 deletions src/ext.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::{
consts,
extra::AngleFromRotMat,
extra::CreateArena,
base, consts,
math::{Angle, RotMat, Vec3},
sim::{
Arena, ArenaConfig, ArenaMemWeightMode, BallHitInfo, BallState, BoostPadState, CarConfig, CarContact, CarControls,
Expand All @@ -17,6 +15,44 @@ use crate::serde_utils;
#[cfg(feature = "serde_utils")]
use serde::{Deserialize, Serialize};

impl CarConfig {
#[inline]
#[must_use]
pub fn octane() -> &'static Self {
base::get_octane()
}

#[inline]
#[must_use]
pub fn dominus() -> &'static Self {
base::get_dominus()
}

#[inline]
#[must_use]
pub fn plank() -> &'static Self {
base::get_plank()
}

#[inline]
#[must_use]
pub fn breakout() -> &'static Self {
base::get_breakout()
}

#[inline]
#[must_use]
pub fn hybrid() -> &'static Self {
base::get_hybrid()
}

#[inline]
#[must_use]
pub fn merc() -> &'static Self {
base::get_merc()
}
}

impl Default for ArenaConfig {
fn default() -> Self {
Self {
Expand Down Expand Up @@ -149,7 +185,7 @@ impl Arena {
///
/// Tick rate MUST be equal to or between 15 and 120
pub fn new(game_mode: GameMode, config: ArenaConfig, tick_rate: u8) -> UniquePtr<Self> {
CreateArena(game_mode, config, tick_rate)
base::CreateArena(game_mode, config, tick_rate)
}

#[inline]
Expand Down Expand Up @@ -480,7 +516,7 @@ impl Angle {
#[inline]
#[must_use]
pub fn from_rotmat(rot_mat: RotMat) -> Self {
AngleFromRotMat(rot_mat)
base::AngleFromRotMat(rot_mat)
}
}

Expand Down
Loading

0 comments on commit c024beb

Please sign in to comment.