1use wasm_bindgen::prelude::*;
5
6#[cfg(feature = "mmo")]
7use crate::{enums::action_error_codes::game::cpu::*, 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<f64>;
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")]
97pub fn unlocked_time() -> Option<f64> {
98 Cpu::unlocked_time()
99}
100
101pub fn get_heap_statistics() -> HeapStatistics {
105 Cpu::get_heap_statistics()
106}
107
108pub fn get_used() -> f64 {
112 Cpu::get_used()
113}
114
115pub fn halt() {
125 Cpu::halt()
126}
127
128#[cfg(feature = "mmo")]
140pub fn set_shard_limits(limits: &Object) -> Result<(), SetShardLimitsErrorCode> {
141 SetShardLimitsErrorCode::result_from_i8(Cpu::set_shard_limits(limits))
142}
143
144#[cfg(feature = "mmo")]
150pub fn unlock() -> Result<(), UnlockErrorCode> {
151 UnlockErrorCode::result_from_i8(Cpu::unlock())
152}
153
154#[cfg(feature = "mmo")]
161pub fn generate_pixel() -> Result<(), GeneratePixelErrorCode> {
162 GeneratePixelErrorCode::result_from_i8(Cpu::generate_pixel())
163}
164
165#[wasm_bindgen]
166extern "C" {
167 #[wasm_bindgen]
171 pub type HeapStatistics;
172
173 #[wasm_bindgen(method, getter)]
175 pub fn total_heap_size(this: &HeapStatistics) -> u32;
176
177 #[wasm_bindgen(method, getter)]
179 pub fn total_heap_size_executable(this: &HeapStatistics) -> u32;
180
181 #[wasm_bindgen(method, getter)]
183 pub fn total_physical_size(this: &HeapStatistics) -> u32;
184
185 #[wasm_bindgen(method, getter)]
187 pub fn total_available_size(this: &HeapStatistics) -> u32;
188
189 #[wasm_bindgen(method, getter)]
191 pub fn used_heap_size(this: &HeapStatistics) -> u32;
192
193 #[wasm_bindgen(method, getter)]
195 pub fn heap_size_limit(this: &HeapStatistics) -> u32;
196
197 #[wasm_bindgen(method, getter)]
199 pub fn malloced_memory(this: &HeapStatistics) -> u32;
200
201 #[wasm_bindgen(method, getter)]
203 pub fn peak_malloced_memory(this: &HeapStatistics) -> u32;
204
205 #[wasm_bindgen(method, getter)]
208 pub fn does_zap_garbage(this: &HeapStatistics) -> u32;
209
210 #[wasm_bindgen(method, getter)]
213 pub fn externally_allocated_size(this: &HeapStatistics) -> u32;
214}