-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert tiles and other high use lightweight classes to inline #104
Comments
Attempted; has a lot of fall out from kotlinx.serializer RC only recently supporting inline classes. Causes other compilation issues having to use IR too; kotlin scripts loose their backing interface and have to be loaded differently, loading scripts wit class loaders breaks internal classes which have to be extracted, the 3rd party kotlinx serialization Yaml library doesn't work with files over 512 in length + many more issues and work arounds. |
There are some work-arounds to get inline classes serializing correctly with jackson class TestSerializer : StdSerializer<Test>(Test::class.java) {
override fun serialize(value: Test, gen: JsonGenerator, provider: SerializerProvider) {
gen.writeNumber(value.value)
}
}
@JsonSerialize(using = TestSerializer::class)
inline class Test(val value: Int)
data class DataThingBuilder(
var id: Int = 0,
var tile: Int = 0,
var string: String = "",
var map: Map<String, Any> = emptyMap()
) {
fun build() = DataThing(id, Test(tile), string, map)
}
@JsonDeserialize(builder = DataThingBuilder::class)
data class DataThing(
val id: Int = 0,
@get:JsonProperty("tile")
val tile: Test = Test(value = 0),
val string: String = "",
val map: Map<String, Any> = emptyMap()
)
@JvmStatic
fun main(args: Array<String>) {
val mapper = ObjectMapper(YAMLFactory()).registerKotlinModule()
val dataThing = DataThing(1234, Test(3087), "word", mapOf("anInt" to 101, "aStr" to "wow", "tile" to Test(2)))
val string = mapper.writeValueAsString(dataThing)
println(string)
val data: DataThing = mapper.readValue(string)
println(data)
println(data.map["tile"])
println(Test(data.map["tile"] as Int))
} |
Converted, one thing I overlooked was that bit packing values together means they can't be negative (without changing ids) meaning I had to break out a separate Delta class for negative numbers. This could be made inline too, or keep it both in Tile and keep the tile id value separate from the bit packed value. Another side affect is GameObject's owner had to be changed from player name String to player index Int which is fine, however GameObject also needed interactionStrategy moving, which isn't optimal, it also doesn't include the despawn timer which is currently located in Objects but should be in the object itself, just like with FloorItems. So I undid GameObjects. Yes while it would work, it's leaning too far towards entity-component-systems again. |
* Replace kotlinx.serialization with jackson * Inline tile * Chunk * Region * Instance * Remove player init * Delta * Start to fix inline class tests * Region plane * Fix inline tests
Blocked by https://youtrack.jetbrains.com/issue/KT-42879 due to
Coordinates2D#add(x, y)
andCoordinates3D#add(x, y, plane)
clashingAnd requires mockk/mockk#152 (comment) workaround for mockking
Classes which should be inline:
Tile, Chunk, Region,
GameObject, InstanceThe text was updated successfully, but these errors were encountered: