Skip to content

Commit

Permalink
fold oort_shared into oort_api
Browse files Browse the repository at this point in the history
  • Loading branch information
rlane committed Oct 2, 2022
1 parent 4deae09 commit 9545617
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 148 deletions.
8 changes: 1 addition & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions Cargo.lock.user

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ members = [
"app",
"renderer",
"ai",
"shared",
"api",
"tools",
"analyzer",
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml.user
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
members = [
"ai",
"api",
"shared",
]

[profile.release]
Expand Down
1 change: 0 additions & 1 deletion ai/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
oort_shared = { path = "../shared" }
oort_api = { path = "../api" }
oorandom = "11.1.3"
Binary file modified ai/builtin-ai.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion ai/fuzz.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use oort_api::prelude::*;
use oort_shared::SystemState;
use oort_api::SystemState;

pub struct Ship {}

Expand Down
1 change: 0 additions & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ license = "GPL-3.0-or-later"
repository = "http://github.com/rlane/oort3"

[dependencies]
oort_shared = { version = "0.6.0", path = "../shared" }
oorandom = "11.1.3"
132 changes: 121 additions & 11 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,120 @@
#![warn(missing_docs)]
mod vec;

#[allow(missing_docs)]
#[derive(Copy, Clone)]
pub enum SystemState {
Class,
Seed,
Orders,
PositionX,
PositionY,
VelocityX,
VelocityY,
Heading,
AngularVelocity,

AccelerateX,
AccelerateY,
Torque,

Gun0Aim,
Gun0Fire,
Gun1Aim,
Gun1Fire,
Gun2Aim,
Gun2Fire,
Gun3Aim,
Gun3Fire,

Missile0Launch,
Missile0Orders,
Missile1Launch,
Missile1Orders,
Missile2Launch,
Missile2Orders,
Missile3Launch,
Missile3Orders,

Explode,

RadarHeading,
RadarWidth,
RadarContactFound,
RadarContactClass,
RadarContactPositionX,
RadarContactPositionY,
RadarContactVelocityX,
RadarContactVelocityY,

DebugTextPointer,
DebugTextLength,

MaxAccelerationX,
MaxAccelerationY,
MaxAngularAcceleration,

RadioChannel,
RadioSend,
RadioReceive,

DebugLinesPointer,
DebugLinesLength,

RadarMinDistance,
RadarMaxDistance,

CurrentTick,
Energy,

Size,
MaxSize = 128,
}

/// Identifiers for each class of ship.
#[allow(missing_docs)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Class {
Fighter,
Frigate,
Cruiser,
Asteroid,
Target,
Missile,
Torpedo,
Unknown,
}

impl Class {
#[allow(missing_docs)]
pub fn from_f64(v: f64) -> Class {
match v as u32 {
0 => Class::Fighter,
1 => Class::Frigate,
2 => Class::Cruiser,
3 => Class::Asteroid,
4 => Class::Target,
5 => Class::Missile,
6 => Class::Torpedo,
_ => Class::Unknown,
}
}
}

#[allow(missing_docs)]
#[derive(Default, Clone)]
pub struct Line {
pub x0: f64,
pub y0: f64,
pub x1: f64,
pub y1: f64,
pub color: u32,
}

// Public for fuzzer.
#[doc(hidden)]
pub mod sys {
use oort_shared::SystemState;
use super::SystemState;

#[no_mangle]
pub static mut SYSTEM_STATE: [f64; SystemState::MaxSize as usize] =
Expand Down Expand Up @@ -60,8 +170,8 @@ mod rng {

mod api {
use super::sys::{read_system_state, write_system_state};
use super::{Class, SystemState};
use crate::vec::*;
use oort_shared::{Class, SystemState};

/// The time between each simulation tick.
pub const TICK_LENGTH: f64 = 1.0 / 60.0;
Expand All @@ -73,12 +183,12 @@ mod api {

/// Returns a random number useful for initializing a random number generator.
pub fn seed() -> u128 {
read_system_state(oort_shared::SystemState::Seed) as u128
read_system_state(super::SystemState::Seed) as u128
}

/// Returns the value passed from the parent ship when launching a missile.
pub fn orders() -> f64 {
read_system_state(oort_shared::SystemState::Orders)
read_system_state(super::SystemState::Orders)
}

/// Returns the current position (in meters).
Expand Down Expand Up @@ -328,9 +438,9 @@ mod api {
#[doc(hidden)]
#[macro_use]
pub mod dbg {
use super::Line;
use crate::sys::write_system_state;
use crate::vec::*;
use oort_shared::Line;
use std::f64::consts::TAU;

static mut TEXT_BUFFER: String = String::new();
Expand Down Expand Up @@ -419,22 +529,22 @@ pub mod dbg {
{
let slice = unsafe { TEXT_BUFFER.as_bytes() };
write_system_state(
oort_shared::SystemState::DebugTextPointer,
super::SystemState::DebugTextPointer,
slice.as_ptr() as u32 as f64,
);
write_system_state(
oort_shared::SystemState::DebugTextLength,
super::SystemState::DebugTextLength,
slice.len() as u32 as f64,
);
}
{
let slice = unsafe { LINE_BUFFER.as_slice() };
write_system_state(
oort_shared::SystemState::DebugLinesPointer,
super::SystemState::DebugLinesPointer,
slice.as_ptr() as u32 as f64,
);
write_system_state(
oort_shared::SystemState::DebugLinesLength,
super::SystemState::DebugLinesLength,
slice.len() as u32 as f64,
);
}
Expand Down Expand Up @@ -462,7 +572,7 @@ pub mod prelude {
#[doc(inline)]
pub use super::vec::*;
#[doc(inline)]
pub use crate::debug;
pub use super::Class;
#[doc(inline)]
pub use oort_shared::Class;
pub use crate::debug;
}
1 change: 0 additions & 1 deletion scripts/build-ai-fast.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exec rustc --crate-name oort_ai \
-C strip=debuginfo \
-L dependency=target/wasm32-unknown-unknown/release/deps \
--extern oorandom=$(echo target/wasm32-unknown-unknown/release/deps/liboorandom-*.rlib) \
--extern oort_shared=$(echo target/wasm32-unknown-unknown/release/deps/liboort_shared-*.rlib) \
--extern oort_api=$(echo target/wasm32-unknown-unknown/release/deps/liboort_api-*.rlib) \
--extern wee_alloc=$(echo target/wasm32-unknown-unknown/release/deps/libwee_alloc-*.rlib) \
-C opt-level=s \
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-builtin-ai.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rm -rf scratch/builtin_ai_sandbox
mkdir -p scratch/builtin_ai_sandbox
cp Cargo.toml.user scratch/builtin_ai_sandbox/Cargo.toml
cp Cargo.lock.user scratch/builtin_ai_sandbox/Cargo.lock
cp -a ai api shared scratch/builtin_ai_sandbox
cp -a ai api scratch/builtin_ai_sandbox
mkdir scratch/builtin_ai_sandbox/scripts
cp scripts/build-ai.sh scripts/build-ai-fast.sh scratch/builtin_ai_sandbox/scripts/
cd scratch/builtin_ai_sandbox
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-local-compiler-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rm -rf scratch/compiler_service_sandbox
mkdir -p scratch/compiler_service_sandbox
cp Cargo.toml.user scratch/compiler_service_sandbox/Cargo.toml
cp Cargo.lock.user scratch/compiler_service_sandbox/Cargo.lock
cp -a ai api shared scratch/compiler_service_sandbox
cp -a ai api scratch/compiler_service_sandbox
mkdir scratch/compiler_service_sandbox/scripts
cp scripts/build-ai.sh scripts/build-ai-fast.sh scratch/compiler_service_sandbox/scripts/
cargo build -p oort_compiler_service
Expand Down
1 change: 0 additions & 1 deletion services/compiler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ COPY --from=builder /registry /usr/local/cargo/registry
COPY --from=builder /usr/local/cargo/bin/oort_compiler_service /usr/local/bin/oort_compiler_service
COPY ai ai
COPY api api
COPY shared shared
RUN cargo fetch
RUN ./scripts/build-ai.sh
ENV PORT 8080
Expand Down
8 changes: 0 additions & 8 deletions shared/Cargo.toml

This file was deleted.

Loading

0 comments on commit 9545617

Please sign in to comment.