dspbp icon indicating copy to clipboard operation
dspbp copied to clipboard

Add a feature to round building floats

Open Wesmania opened this issue 1 year ago • 4 comments

The new flag will round locations and rotations of buildings to 1/64th of a tile and 1 degree respectively. It decreases blueprint size by 30% or so. Also, the game tends to put "on-grid" buildings an epsilon off-grid, so this helps perfectly align them.

We explicitly give no guarantees for the changed blueprints to work.

Kudos to @Neutron3529 for suggesting and initially implementing this feature.

Wesmania avatar Dec 21 '23 12:12 Wesmania

@Neutron3529 does this cover your use case?

Wesmania avatar Dec 21 '23 12:12 Wesmania

IMHO, 1/64 seems not the good choice, since 64 is not a multiple of 3 and 5. In case you really like 1/64 scale, maybe 1/60 is better.

And rounding seems to be 3 degree seems more reasonable (original game code)

	public bool CopyFromFactoryObject(int objectId, PlanetFactory factory, bool copyInserters = true, bool copyAllSettings = false)
	{
		...
		if (objectId <= 0 || entityPool[objectId].id != objectId)
		{
			if (num > 0 && prebuildPool[num].id == num)
			{
				this.type = BuildingType.None;
				this.itemId = (int)prebuildPool[num].protoId;
				this.modelIndex = (int)prebuildPool[num].modelIndex;
				this.yaw = (Quaternion.Inverse(Maths.SphericalRotation(prebuildPool[num].pos, 0f)) * prebuildPool[num].rot).eulerAngles.y;
				this.yaw = Mathf.Round(this.yaw / 3f) * 3f;

1 degree might be too aggressive since I've found some building's rounding error (towards 90 degree) larger than 1.

Maybe change the switch to a configuable number is better. A invalid number(such as 0) means no rounding, and therefore people could adjust their rounding factor to a more reasonable one.

Neutron3529 avatar Dec 23 '23 17:12 Neutron3529

I picked 1/64 because it rounds nicely in terms of float's binary representation. I guess it might be a problem for off-grid belt segments? I'm not sure, 1/64 is still very small. I can bump angle rounding to 3 degrees, sure. I'd like to avoid making this configurable, it'd be better to have some reasonable defaults.

Another idea: as a compromise, make rounding "snap" to whole tiles and 90 degree angles while ignoring everything else. I experimented a bit, 3 degrees and 1/64th of a tile of snapping give me only about 20% compression on some of my blueprints.

Wesmania avatar Dec 23 '23 20:12 Wesmania

A bit of investigation suggests that sorters are usually off-grid, so with that approach they wouldn't be compressed. Same for belt pieces that go into splitters. Rest of belts aligns nicely though. I guess that's a good reason to only align things that are close to half-a-tile/90 degrees. Would need experiments really.

Wesmania avatar Dec 23 '23 20:12 Wesmania