1use wasm_bindgen::prelude::*;
5
6#[cfg(feature = "mmo")]
7use crate::{constants::ErrorCode, prelude::*};
8#[cfg(feature = "mmo")]
9use js_sys::{JsString, Object};
10
11#[wasm_bindgen]
12extern "C" {
13 #[wasm_bindgen(js_name = "cpu")]
14 type Cpu;
15
16 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, getter, js_name = limit)]
17 fn limit() -> u32;
18
19 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, getter, js_name = tickLimit)]
20 fn tick_limit() -> f64;
21
22 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, getter, js_name = bucket)]
23 fn bucket() -> i32;
24
25 #[cfg(feature = "mmo")]
26 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = shardLimits)]
27 fn shard_limits() -> Object;
28
29 #[cfg(feature = "mmo")]
30 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, getter, js_name = unlocked)]
31 fn unlocked() -> bool;
32
33 #[cfg(feature = "mmo")]
34 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, getter, js_name = unlockedTime)]
35 fn unlocked_time() -> Option<u64>;
36
37 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = getHeapStatistics)]
38 fn get_heap_statistics() -> HeapStatistics;
39
40 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = getUsed)]
41 fn get_used() -> f64;
42
43 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = halt)]
44 fn halt();
45
46 #[cfg(feature = "mmo")]
47 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = setShardLimits)]
48 fn set_shard_limits(limits: &Object) -> i8;
49
50 #[cfg(feature = "mmo")]
51 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = unlock)]
52 fn unlock() -> i8;
53
54 #[cfg(feature = "mmo")]
55 #[wasm_bindgen(js_namespace = ["Game"], js_class = "cpu", static_method_of = Cpu, js_name = generatePixel)]
56 fn generate_pixel() -> i8;
57}
58
59pub fn limit() -> u32 {
61 Cpu::limit()
62}
63
64pub fn tick_limit() -> f64 {
71 Cpu::tick_limit()
72}
73
74pub fn bucket() -> i32 {
76 Cpu::bucket()
77}
78
79#[cfg(feature = "mmo")]
83pub fn shard_limits() -> JsHashMap<JsString, u32> {
84 Cpu::shard_limits().into()
85}
86
87#[cfg(feature = "mmo")]
89pub fn unlocked() -> bool {
90 Cpu::unlocked()
91}
92
93#[cfg(feature = "mmo")]
96pub fn unlocked_time() -> Option<u64> {
97 Cpu::unlocked_time()
98}
99
100pub fn get_heap_statistics() -> HeapStatistics {
104 Cpu::get_heap_statistics()
105}
106
107pub fn get_used() -> f64 {
111 Cpu::get_used()
112}
113
114pub fn halt() {
124 Cpu::halt()
125}
126
127#[cfg(feature = "mmo")]
139pub fn set_shard_limits(limits: &Object) -> Result<(), ErrorCode> {
140 ErrorCode::result_from_i8(Cpu::set_shard_limits(limits))
141}
142
143#[cfg(feature = "mmo")]
149pub fn unlock() -> Result<(), ErrorCode> {
150 ErrorCode::result_from_i8(Cpu::unlock())
151}
152
153#[cfg(feature = "mmo")]
160pub fn generate_pixel() -> Result<(), ErrorCode> {
161 ErrorCode::result_from_i8(Cpu::generate_pixel())
162}
163
164#[wasm_bindgen]
165extern "C" {
166 #[wasm_bindgen]
170 pub type HeapStatistics;
171
172 #[wasm_bindgen(method, getter)]
174 pub fn total_heap_size(this: &HeapStatistics) -> u32;
175
176 #[wasm_bindgen(method, getter)]
178 pub fn total_heap_size_executable(this: &HeapStatistics) -> u32;
179
180 #[wasm_bindgen(method, getter)]
182 pub fn total_physical_size(this: &HeapStatistics) -> u32;
183
184 #[wasm_bindgen(method, getter)]
186 pub fn total_available_size(this: &HeapStatistics) -> u32;
187
188 #[wasm_bindgen(method, getter)]
190 pub fn used_heap_size(this: &HeapStatistics) -> u32;
191
192 #[wasm_bindgen(method, getter)]
194 pub fn heap_size_limit(this: &HeapStatistics) -> u32;
195
196 #[wasm_bindgen(method, getter)]
198 pub fn malloced_memory(this: &HeapStatistics) -> u32;
199
200 #[wasm_bindgen(method, getter)]
202 pub fn peak_malloced_memory(this: &HeapStatistics) -> u32;
203
204 #[wasm_bindgen(method, getter)]
207 pub fn does_zap_garbage(this: &HeapStatistics) -> u32;
208
209 #[wasm_bindgen(method, getter)]
212 pub fn externally_allocated_size(this: &HeapStatistics) -> u32;
213}