Skip to content

Commit

Permalink
fix: client rotation is overwritten by server updates
Browse files Browse the repository at this point in the history
update rotation from server only for entities without EF_ROTATE
  • Loading branch information
demoth committed Jan 27, 2025
1 parent 25444f7 commit 06f0c51
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions cake/core/src/main/java/org/demoth/cake/stages/Game3dScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Game3dScreen : KtxScreen, InputProcessor, ServerMessageProcessor {
private var precached: Boolean = false

// model instances to be drawn - updated on every server frame
private val models = ArrayList<ClientEntity>()
private val visibleEntities = ArrayList<ClientEntity>()
private val modelBatch: ModelBatch
private var levelModel: ClientEntity? = null
private val collisionModel = CM()
Expand Down Expand Up @@ -105,7 +105,7 @@ class Game3dScreen : KtxScreen, InputProcessor, ServerMessageProcessor {
updatePlayerView()

modelBatch.begin(camera)
models.forEach {
visibleEntities.forEach {

// apply client side effects
if (it.current.effects and EF_ROTATE != 0) {
Expand Down Expand Up @@ -584,12 +584,12 @@ class Game3dScreen : KtxScreen, InputProcessor, ServerMessageProcessor {
// apply entity transform to the model instance
// AddPacketEntities
fun postReceive() {
models.clear()
visibleEntities.clear()
// todo: put to a persistent client entities list?
models += ClientEntity().apply { modelInstance = createGrid(16f, 8) }
models += ClientEntity().apply { modelInstance = createOriginArrows(16f) }
visibleEntities += ClientEntity().apply { modelInstance = createGrid(16f, 8) }
visibleEntities += ClientEntity().apply { modelInstance = createOriginArrows(16f) }
if (levelModel != null) {
models += levelModel!!
visibleEntities += levelModel!!
}

// entities in the current frame
Expand Down Expand Up @@ -619,11 +619,15 @@ class Game3dScreen : KtxScreen, InputProcessor, ServerMessageProcessor {
val origin = s1.origin
// set the model instance position as origin
// transform the translation vector from q2 to libgdx
modelInstance.transform.setToRotation(Vector3.X, s1.angles[PITCH])
modelInstance.transform.rotate(Vector3.Z, s1.angles[YAW])
if (cent.current.effects and EF_ROTATE == 0) {
modelInstance.transform.setToRotation(Vector3.X, s1.angles[PITCH])
modelInstance.transform.rotate(Vector3.Z, s1.angles[YAW])
} else {
// will be autorotated in render loop on the client
}
// todo apply roll
modelInstance.transform.setTranslation(origin[0], origin[1], origin[2])
models += cent
visibleEntities += cent
}
}

Expand Down

0 comments on commit 06f0c51

Please sign in to comment.