Skip to content

Commit 8cf7d53

Browse files
committed
Switch VM from Point2 to PackedPoint2
1 parent 5a6d003 commit 8cf7d53

File tree

8 files changed

+214
-123
lines changed

8 files changed

+214
-123
lines changed

src/bin/mlog.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use mindustry_rs::{
77
Building, BuildingData, HYPER_PROCESSOR, LOGIC_PROCESSOR, LogicVMBuilder, MEMORY_BANK,
88
MEMORY_CELL, MESSAGE, MICRO_PROCESSOR, WORLD_PROCESSOR,
99
},
10-
types::{Object, Point2, ProcessorConfig, ProcessorLinkConfig},
10+
types::{Object, ProcessorConfig, ProcessorLinkConfig},
1111
};
1212
use strum_macros::EnumString;
1313
use widestring::U16String;
@@ -67,7 +67,7 @@ fn main() -> Result<(), Box<dyn Error>> {
6767
builder.add_buildings([
6868
Building::from_processor_config(
6969
cli.processor.name(),
70-
Point2::new(0, 0),
70+
(0, 0).into(),
7171
&ProcessorConfig {
7272
code: cli.code.contents()?,
7373
links: vec![
@@ -78,9 +78,9 @@ fn main() -> Result<(), Box<dyn Error>> {
7878
},
7979
&builder,
8080
)?,
81-
Building::from_config(MESSAGE, Point2::new(3, 0), &Object::Null, &builder)?,
82-
Building::from_config(MEMORY_CELL, Point2::new(4, 0), &Object::Null, &builder)?,
83-
Building::from_config(MEMORY_BANK, Point2::new(5, 0), &Object::Null, &builder)?,
81+
Building::from_config(MESSAGE, (3, 0).into(), &Object::Null, &builder)?,
82+
Building::from_config(MEMORY_CELL, (4, 0).into(), &Object::Null, &builder)?,
83+
Building::from_config(MEMORY_BANK, (5, 0).into(), &Object::Null, &builder)?,
8484
]);
8585
let vm = builder.build()?;
8686

src/bin/mlogv32.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use mindustry_rs::{
2424
Building, BuildingData, LValue, LogicVM, LogicVMBuilder, MEMORY_BANK, MESSAGE,
2525
MICRO_PROCESSOR, SWITCH, WORLD_PROCESSOR,
2626
},
27-
types::{Object, Point2, ProcessorConfig, Schematic},
27+
types::{Object, PackedPoint2, ProcessorConfig, Schematic},
2828
};
2929
use serde::Deserialize;
3030
use widestring::{U16String, u16str};
@@ -100,13 +100,13 @@ struct Metadata {
100100
}
101101

102102
#[derive(Debug, Clone, Copy, Deserialize)]
103-
struct MetaPoint2(i32, i32);
103+
struct MetaPoint2(i16, i16);
104104

105105
impl MetaPoint2 {
106-
fn x(&self) -> i32 {
106+
fn x(&self) -> i16 {
107107
self.0
108108
}
109-
fn y(&self) -> i32 {
109+
fn y(&self) -> i16 {
110110
self.1
111111
}
112112
}
@@ -117,7 +117,7 @@ impl Display for MetaPoint2 {
117117
}
118118
}
119119

120-
impl From<MetaPoint2> for Point2 {
120+
impl From<MetaPoint2> for PackedPoint2 {
121121
fn from(MetaPoint2(x, y): MetaPoint2) -> Self {
122122
Self { x, y }
123123
}
@@ -477,10 +477,10 @@ fn main() -> Result<(), Box<dyn Error>> {
477477
.into_iter()
478478
.zip(schematic.tiles_mut().iter_mut().filter(|t| {
479479
t.block == MICRO_PROCESSOR
480-
&& (t.position.x as i32) >= meta.memory.x()
481-
&& (t.position.x as i32) < meta.memory.x() + (meta.memory_width as i32)
482-
&& (t.position.y as i32) >= meta.memory.y()
483-
&& (t.position.y as i32) < meta.memory.y() + (meta.memory_height as i32)
480+
&& t.position.x >= meta.memory.x()
481+
&& t.position.x < meta.memory.x() + (meta.memory_width as i16)
482+
&& t.position.y >= meta.memory.y()
483+
&& t.position.y < meta.memory.y() + (meta.memory_height as i16)
484484
}))
485485
.progress_count(bar_count)
486486
{

src/logic/vm/buildings.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::{
99
variables::LValue,
1010
};
1111
use crate::types::{
12-
Object, Point2, ProcessorConfig, SchematicTile,
12+
Object, PackedPoint2, ProcessorConfig, SchematicTile,
1313
content::{self, Block},
1414
};
1515

@@ -34,12 +34,12 @@ const MESSAGE_MAX_LINES: usize = 24;
3434
#[derive(Debug, Clone)]
3535
pub struct Building {
3636
pub block: &'static Block,
37-
pub position: Point2,
37+
pub position: PackedPoint2,
3838
pub data: Rc<RefCell<BuildingData>>,
3939
}
4040

4141
impl Building {
42-
pub fn new(name: &str, position: Point2, data: BuildingData) -> VMLoadResult<Self> {
42+
pub fn new(name: &str, position: PackedPoint2, data: BuildingData) -> VMLoadResult<Self> {
4343
let block = *content::blocks::FROM_NAME
4444
.get(name)
4545
.ok_or_else(|| VMLoadError::UnknownBlockType(name.to_string()))?;
@@ -53,7 +53,7 @@ impl Building {
5353

5454
pub fn from_config(
5555
name: &str,
56-
position: Point2,
56+
position: PackedPoint2,
5757
config: &Object,
5858
builder: &LogicVMBuilder,
5959
) -> VMLoadResult<Self> {
@@ -109,7 +109,7 @@ impl Building {
109109

110110
pub fn from_processor_config(
111111
name: &str,
112-
position: Point2,
112+
position: PackedPoint2,
113113
config: &ProcessorConfig,
114114
builder: &LogicVMBuilder,
115115
) -> VMLoadResult<Self> {
@@ -178,7 +178,7 @@ impl Building {
178178
}: &SchematicTile,
179179
builder: &LogicVMBuilder,
180180
) -> VMLoadResult<Self> {
181-
Self::from_config(name, (*position).into(), config, builder)
181+
Self::from_config(name, *position, config, builder)
182182
}
183183
}
184184

src/logic/vm/instructions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{
2020
},
2121
},
2222
types::{
23-
ContentType, LAccess, Point2, Team,
23+
ContentType, LAccess, PackedPoint2, Team,
2424
colors::{self, f32_to_double_bits, f64_from_double_bits},
2525
content,
2626
},
@@ -1098,9 +1098,9 @@ pub(super) struct GetBlock {
10981098

10991099
impl SimpleInstructionTrait for GetBlock {
11001100
fn execute(&self, state: &mut ProcessorState, vm: &LogicVM) {
1101-
let result = match vm.building(Point2 {
1102-
x: self.x.get(state).numf().round() as i32,
1103-
y: self.y.get(state).numf().round() as i32,
1101+
let result = match vm.building(PackedPoint2 {
1102+
x: self.x.get(state).numf().round() as i16,
1103+
y: self.y.get(state).numf().round() as i16,
11041104
}) {
11051105
Some(building) => match self.layer {
11061106
TileLayer::Floor => Content::Block(&content::blocks::STONE).into(),

0 commit comments

Comments
 (0)