Created
December 15, 2020 13:21
-
-
Save Mr00Anderson/bcc598a08a469d747fe431e528bf85cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app.virtualhex.gdx.engine.maps; | |
import app.virtualhex.math.VLQUtilsNative; | |
import app.virtualhex.types.Decoder; | |
import app.virtualhex.types.Encoder; | |
import java.nio.ByteBuffer; | |
/** | |
* Used to describe the parameters of a playable section of the game | |
*/ | |
public class ChunkedMapConfig implements Encoder<ByteBuffer>, Decoder<ByteBuffer> { | |
/** | |
* Name | |
*/ | |
public String _id; | |
public int chunkWidthInPoints; | |
public int chunkHeightInPoints ; | |
public int widthInChunks; | |
public int heightInChunks; | |
public int textureWidth; | |
public int textureHeight; | |
public ChunkedMapConfig() { | |
} | |
public ChunkedMapConfig(ByteBuffer in) { | |
decode(in); | |
} | |
public ChunkedMapConfig(String name, int chunkWidthInPoints, int chunkHeightInPoints, int widthInChunks, int heightInChunks, int textureWidth, int textureHeight) { | |
this._id = name; | |
this.chunkWidthInPoints = chunkWidthInPoints; | |
this.chunkHeightInPoints = chunkHeightInPoints; | |
this.widthInChunks = widthInChunks; | |
this.heightInChunks = heightInChunks; | |
this.textureWidth = textureWidth; | |
this.textureHeight = textureHeight; | |
} | |
@Override | |
public String toString() { | |
return "ChunkedMapConfig{" + | |
"_id='" + _id + '\'' + | |
", chunkWidthInPoints=" + chunkWidthInPoints + | |
", chunkHeightInPoints=" + chunkHeightInPoints + | |
", widthInChunks=" + widthInChunks + | |
", heightInChunks=" + heightInChunks + | |
", textureWidth=" + textureWidth + | |
", textureHeight=" + textureHeight + | |
'}'; | |
} | |
@Override | |
public void decode(ByteBuffer in) { | |
_id = VLQUtilsNative.decodeString(in); | |
chunkWidthInPoints = VLQUtilsNative.getVarInt(in); | |
chunkHeightInPoints = VLQUtilsNative.getVarInt(in); | |
widthInChunks = VLQUtilsNative.getVarInt(in); | |
heightInChunks = VLQUtilsNative.getVarInt(in); | |
textureWidth = VLQUtilsNative.getVarInt(in); | |
textureHeight = VLQUtilsNative.getVarInt(in); | |
} | |
@Override | |
public void encode(ByteBuffer out) { | |
VLQUtilsNative.encode(out, _id); | |
VLQUtilsNative.putVarInt(out, chunkWidthInPoints); | |
VLQUtilsNative.putVarInt(out, chunkHeightInPoints); | |
VLQUtilsNative.putVarInt(out, widthInChunks); | |
VLQUtilsNative.putVarInt(out, heightInChunks); | |
VLQUtilsNative.putVarInt(out, textureWidth); | |
VLQUtilsNative.putVarInt(out, textureHeight); | |
} | |
public int getSize() { | |
return VLQUtilsNative.varIntSize(_id.length()) + | |
VLQUtilsNative.varIntSize(chunkWidthInPoints) + | |
VLQUtilsNative.varIntSize(chunkHeightInPoints) + | |
VLQUtilsNative.varIntSize(widthInChunks) + | |
VLQUtilsNative.varIntSize(heightInChunks) + | |
VLQUtilsNative.varIntSize(textureWidth) + | |
VLQUtilsNative.varIntSize(textureHeight); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment