Skip to content

Commit

Permalink
Draw other players #122
Browse files Browse the repository at this point in the history
fix #122
  • Loading branch information
demoth committed Jan 25, 2025
1 parent c35b85b commit 4ce5d14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 15 additions & 1 deletion cake/core/src/main/java/org/demoth/cake/stages/Game3dScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class Game3dScreen : KtxScreen, InputProcessor, ServerMessageProcessor {

private var lerpFrac: Float = 0f

// todo: make proper player loader
private val playerModelPath = "players/male/tris.md2"
private val playerSkinPath = "players/male/grunt.pcx"
private lateinit var playerModel: Model

init {
camera.position.set(0f, 0f, 0f);
camera.near = 1f
Expand Down Expand Up @@ -166,6 +171,12 @@ class Game3dScreen : KtxScreen, InputProcessor, ServerMessageProcessor {
}
}

// temporary: load one fixed player model
playerModel = Md2ModelLoader().loadMd2Model(
modelFile = File("$basedir/$gameName/$playerModelPath"),
playerSkin = "$basedir/$gameName/$playerSkinPath"
)

gameConfig.getSounds().forEach { s ->
if (s != null) {
if (s.value.isNotEmpty()) {
Expand Down Expand Up @@ -591,7 +602,10 @@ class Game3dScreen : KtxScreen, InputProcessor, ServerMessageProcessor {
// Store in the entity_state_t?
if (cent.modelInstance == null) {
val modelIndex = s1.modelindex
if (modelIndex != 0) {
if (modelIndex == 255) { // this is a player
// fixme: how to get which skin does the player have?
cent.modelInstance = ModelInstance(playerModel)
} else if (modelIndex != 0) {
//configStrings[CS_MODELS + modelIndex]?.resource as? Model
val model = gameConfig[CS_MODELS + modelIndex]?.resource as? Model
if (model != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.nio.ByteBuffer
import java.nio.ByteOrder

class Md2ModelLoader {
fun loadMd2Model(modelFile: File): Model { // fixme: should return Model instead, model instance can be created externally
fun loadMd2Model(modelFile: File, playerSkin: String? = null): Model {
val md2Model: Md2Model = readMd2Model(modelFile.absolutePath)
// strip skin names and expect them to be located along with the .md2 file
val skins = md2Model.skinNames.map {
Expand All @@ -34,14 +34,21 @@ class Md2ModelLoader {

val modelBuilder = ModelBuilder()
modelBuilder.begin()
val modelSkin = if (skins.isNotEmpty()) {
skins.first()
} else {
if (playerSkin != null) {
File(playerSkin)
} else throw IllegalStateException("No skin found in the model, no player skin provided")
}
val meshBuilder = modelBuilder.part(
"part1",
GL_TRIANGLES,
VertexAttributes(VertexAttribute.Position(), VertexAttribute.TexCoords(0)),
Material(
TextureAttribute(
TextureAttribute.Diffuse,
Texture(PCXTextureData(fromPCX(PCX(skins.first().readBytes())))),
Texture(PCXTextureData(fromPCX(PCX(modelSkin.readBytes())))),
)
)
)
Expand Down

0 comments on commit 4ce5d14

Please sign in to comment.