Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove generate-pixel and inter-shard-memory features, restrict more CPU functions #507

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Unreleased
- Change name of `LocalRoomTerrain::get` to `get_xy` for consistency with `RoomTerrain`
- Change name of `constants::extra::CONSTRUCTION_SITE_STOMP_RATIO` to
`CONSTRUCTION_SITE_DROP_RATIO`
- Remove features `generate-pixel` and `inter-shard-memory`, use the `mmo` feature instead
- Place `game::cpu::{shard_limits, unlocked, unlocked_time, set_shard_limits, unlock}` functions
behind the `mmo` feature

### Additions:

Expand Down Expand Up @@ -35,7 +38,8 @@ Unreleased

### Misc:

- Change `PhantomData` in `screeps::local::ObjectId` to better model `ObjectId`'s relationship with the wrapped type.
- Change `PhantomData` in `screeps::local::ObjectId` to better model `ObjectId`'s relationship with
the wrapped type.
- This allows `ObjectId` to be `Send + Sync` regardless of the wrapped type
- Update `enum-iterator` to 2.0

Expand Down
12 changes: 2 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ wasm-bindgen-test = "0.3"
[features]
## Specific features to enable conditional API endpoints

# Enable the function call for pixel generation - only present on official MMO servers
generate-pixel = []

# Enable the interface for inter-shard memory - only present on official MMO servers
inter-shard-memory = []
# Official MMO server features, not present on other environments
mmo = []

# Seasonal server, season 1 - enable score container, collector, and resource
seasonal-season-1 = []
Expand All @@ -69,8 +66,3 @@ sim = []
# Enable unsafe conversions of return codes with undefined behavior when values
# aren't in the expected range
unsafe-return-conversion = []

## Sets of the above features for different server environments

# Official MMO server features, not present on other environments
mmo = ["generate-pixel", "inter-shard-memory"]
18 changes: 15 additions & 3 deletions src/game/cpu.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Information about, and functions to manage, your code's resource utilization
//!
//! [Screeps documentation](http://docs.screeps.com/api/#Game.cpu)
use js_sys::{JsString, Object};
use wasm_bindgen::prelude::*;

#[cfg(feature = "mmo")]
use crate::{constants::ErrorCode, prelude::*};
#[cfg(feature = "mmo")]
use js_sys::{JsString, Object};

#[wasm_bindgen]
extern "C" {
Expand All @@ -20,12 +22,15 @@ extern "C" {
#[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, getter, js_name = bucket)]
fn bucket() -> i32;

#[cfg(feature = "mmo")]
#[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = shardLimits)]
fn shard_limits() -> Object;

#[cfg(feature = "mmo")]
#[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, getter, js_name = unlocked)]
fn unlocked() -> bool;

#[cfg(feature = "mmo")]
#[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, getter, js_name = unlockedTime)]
fn unlocked_time() -> Option<u64>;

Expand All @@ -38,13 +43,15 @@ extern "C" {
#[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = halt)]
fn halt();

#[cfg(feature = "mmo")]
#[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = setShardLimits)]
fn set_shard_limits(limits: &Object) -> i8;

#[cfg(feature = "mmo")]
#[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = unlock)]
fn unlock() -> i8;

#[cfg(feature = "generate-pixel")]
#[cfg(feature = "mmo")]
#[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = generatePixel)]
fn generate_pixel() -> i8;
}
Expand All @@ -71,17 +78,20 @@ pub fn bucket() -> i32 {
/// Your assigned CPU limits for each shard in an [`Object`], with shard
/// names in [`JsString`] form as keys and numbers as values. This is the
/// same format accepted by [`set_shard_limits`].
#[cfg(feature = "mmo")]
pub fn shard_limits() -> JsHashMap<JsString, u32> {
Cpu::shard_limits().into()
}

/// Whether your account is unlocked to have full CPU.
#[cfg(feature = "mmo")]
pub fn unlocked() -> bool {
Cpu::unlocked()
}

/// If your account has been unlocked for a limited time, contains the time
/// it's unlocked until in milliseconds since epoch.
#[cfg(feature = "mmo")]
pub fn unlocked_time() -> Option<u64> {
Cpu::unlocked_time()
}
Expand Down Expand Up @@ -122,6 +132,7 @@ pub fn halt() {
/// [Screeps documentation](https://docs.screeps.com/api/#Game.cpu.setShardLimits)
///
/// [`CPU_SET_SHARD_LIMITS_COOLDOWN`]: crate::constants::CPU_SET_SHARD_LIMITS_COOLDOWN
#[cfg(feature = "mmo")]
pub fn set_shard_limits(limits: &Object) -> Result<(), ErrorCode> {
ErrorCode::result_from_i8(Cpu::set_shard_limits(limits))
}
Expand All @@ -131,6 +142,7 @@ pub fn set_shard_limits(limits: &Object) -> Result<(), ErrorCode> {
/// [Screeps documentation](https://docs.screeps.com/api/#Game.cpu.unlock)
///
/// [`CpuUnlock`]: crate::constants::IntershardResourceType::CpuUnlock
#[cfg(feature = "mmo")]
pub fn unlock() -> Result<(), ErrorCode> {
ErrorCode::result_from_i8(Cpu::unlock())
}
Expand All @@ -141,7 +153,7 @@ pub fn unlock() -> Result<(), ErrorCode> {
///
/// [`Pixel`]: crate::constants::IntershardResourceType::Pixel
/// [`PIXEL_CPU_COST`]: crate::constants::PIXEL_CPU_COST
#[cfg(feature = "generate-pixel")]
#[cfg(feature = "mmo")]
pub fn generate_pixel() -> Result<(), ErrorCode> {
ErrorCode::result_from_i8(Cpu::generate_pixel())
}
Expand Down
19 changes: 5 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@
//!
//! # Cargo Features
//!
//! ## `generate-pixel`
//!
//! Enables the function to generate pixels, which is only present on the
//! Screeps: World official servers.
//!
//! ## `inter-shard-memory`
//! ## `mmo`
//!
//! Enables interacting with `IntershardMemory`, which is not present in most
//! private server environments.
//! Enables a number of functions for CPU management and inter-shard
//! communication present on the Screeps: World official servers but not on
//! private servers.
//!
//! ## `seasonal-season-1`
//!
Expand Down Expand Up @@ -87,11 +83,6 @@
//! Enables return code conversion from game functions that presumes all return
//! code values are in the expected ranges skipping checks, and risks undefined
//! behavior if they are not.
//!
//! ## `mmo`
//!
//! Enables the `generate-pixel` and `inter-shard-memory` features, which are
//! present on the Screeps: World official servers but not on private servers.
#![recursion_limit = "128"]
// to build locally with doc_cfg enabled, run:
// `RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features`
Expand All @@ -107,7 +98,7 @@ pub mod console;
pub mod constants;
pub mod enums;
pub mod game;
#[cfg(feature = "inter-shard-memory")]
#[cfg(feature = "mmo")]
pub mod inter_shard_memory;
pub mod js_collections;
pub mod local;
Expand Down
Loading