Broken bullshit
This commit is contained in:
108
assets/assets.go
108
assets/assets.go
@ -1,10 +1,25 @@
|
||||
package assets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"gitea.boner.be/bdnugget/goonscape/logging"
|
||||
"gitea.boner.be/bdnugget/goonscape/types"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
var (
|
||||
assetMutex sync.RWMutex
|
||||
loadedModels map[string]types.ModelAsset
|
||||
audioMutex sync.Mutex
|
||||
audioInitialized bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
loadedModels = make(map[string]types.ModelAsset)
|
||||
}
|
||||
|
||||
// Helper function to load animations for a model
|
||||
func loadModelAnimations(animPaths map[string]string) (types.AnimationSet, error) {
|
||||
var animSet types.AnimationSet
|
||||
@ -33,9 +48,28 @@ func loadModelAnimations(animPaths map[string]string) (types.AnimationSet, error
|
||||
}
|
||||
|
||||
func LoadModels() ([]types.ModelAsset, error) {
|
||||
logging.Info.Println("Loading models")
|
||||
assetMutex.Lock()
|
||||
defer assetMutex.Unlock()
|
||||
|
||||
if len(loadedModels) > 0 {
|
||||
logging.Info.Println("Returning cached models")
|
||||
models := make([]types.ModelAsset, 0, len(loadedModels))
|
||||
for _, model := range loadedModels {
|
||||
models = append(models, model)
|
||||
}
|
||||
return models, nil
|
||||
}
|
||||
|
||||
// Goonion model and animations
|
||||
goonerModel := rl.LoadModel("resources/models/gooner/walk_no_y_transform.glb")
|
||||
goonerAnims, _ := loadModelAnimations(map[string]string{"idle": "resources/models/gooner/idle_no_y_transform.glb", "walk": "resources/models/gooner/walk_no_y_transform.glb"})
|
||||
goonerAnims, err := loadModelAnimations(map[string]string{
|
||||
"idle": "resources/models/gooner/idle_no_y_transform.glb",
|
||||
"walk": "resources/models/gooner/walk_no_y_transform.glb",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Apply transformations
|
||||
transform := rl.MatrixIdentity()
|
||||
@ -46,25 +80,30 @@ func LoadModels() ([]types.ModelAsset, error) {
|
||||
|
||||
// Coomer model (ready for animations)
|
||||
coomerModel := rl.LoadModel("resources/models/coomer/idle_notransy.glb")
|
||||
// coomerTexture := rl.LoadTexture("resources/models/coomer.png")
|
||||
// rl.SetMaterialTexture(coomerModel.Materials, rl.MapDiffuse, coomerTexture)
|
||||
// When you have animations, add them like:
|
||||
coomerAnims, _ := loadModelAnimations(map[string]string{"idle": "resources/models/coomer/idle_notransy.glb", "walk": "resources/models/coomer/unsteadywalk_notransy.glb"})
|
||||
coomerAnims, err := loadModelAnimations(map[string]string{
|
||||
"idle": "resources/models/coomer/idle_notransy.glb",
|
||||
"walk": "resources/models/coomer/unsteadywalk_notransy.glb",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
coomerModel.Transform = transform
|
||||
|
||||
// Shreke model (ready for animations)
|
||||
shrekeModel := rl.LoadModel("resources/models/shreke.obj")
|
||||
shrekeTexture := rl.LoadTexture("resources/models/shreke.png")
|
||||
rl.SetMaterialTexture(shrekeModel.Materials, rl.MapDiffuse, shrekeTexture)
|
||||
// When you have animations, add them like:
|
||||
// shrekeAnims, _ := loadModelAnimations("resources/models/shreke.glb",
|
||||
// map[string]string{
|
||||
// "idle": "resources/models/shreke_idle.glb",
|
||||
// "walk": "resources/models/shreke_walk.glb",
|
||||
// })
|
||||
shrekeModel := rl.LoadModel("resources/models/shreke/Animation_Slow_Orc_Walk_withSkin.glb")
|
||||
shrekeAnims, err := loadModelAnimations(map[string]string{
|
||||
"idle": "resources/models/shreke/Animation_Slow_Orc_Walk_withSkin.glb",
|
||||
"walk": "resources/models/shreke/Animation_Excited_Walk_M_withSkin.glb",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
shrekeModel.Transform = transform
|
||||
|
||||
return []types.ModelAsset{
|
||||
// Store loaded models
|
||||
models := []types.ModelAsset{
|
||||
{
|
||||
Name: "gooner",
|
||||
Model: goonerModel,
|
||||
Animation: append(goonerAnims.Idle, goonerAnims.Walk...),
|
||||
AnimFrames: int32(len(goonerAnims.Idle) + len(goonerAnims.Walk)),
|
||||
@ -78,15 +117,47 @@ func LoadModels() ([]types.ModelAsset, error) {
|
||||
Animations: coomerAnims,
|
||||
YOffset: -4.0,
|
||||
},
|
||||
{Model: shrekeModel, Texture: shrekeTexture},
|
||||
}, nil
|
||||
{
|
||||
Model: shrekeModel,
|
||||
Animation: append(shrekeAnims.Idle, shrekeAnims.Walk...),
|
||||
AnimFrames: int32(len(shrekeAnims.Idle) + len(shrekeAnims.Walk)),
|
||||
Animations: shrekeAnims,
|
||||
YOffset: 0.0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
loadedModels[model.Name] = model
|
||||
}
|
||||
|
||||
return models, nil
|
||||
}
|
||||
|
||||
func LoadMusic(filename string) (rl.Music, error) {
|
||||
return rl.LoadMusicStream(filename), nil
|
||||
logging.Info.Printf("Loading music from %s", filename)
|
||||
audioMutex.Lock()
|
||||
defer audioMutex.Unlock()
|
||||
|
||||
if !rl.IsAudioDeviceReady() {
|
||||
err := fmt.Errorf("audio device not initialized")
|
||||
logging.Error.Println(err)
|
||||
return rl.Music{}, err
|
||||
}
|
||||
|
||||
music := rl.LoadMusicStream(filename)
|
||||
if music.CtxType == 0 {
|
||||
err := fmt.Errorf("failed to load music stream")
|
||||
logging.Error.Println(err)
|
||||
return rl.Music{}, err
|
||||
}
|
||||
logging.Info.Println("Music loaded successfully")
|
||||
return music, nil
|
||||
}
|
||||
|
||||
func UnloadModels(models []types.ModelAsset) {
|
||||
assetMutex.Lock()
|
||||
defer assetMutex.Unlock()
|
||||
|
||||
for _, model := range models {
|
||||
if model.Animation != nil {
|
||||
for i := int32(0); i < model.AnimFrames; i++ {
|
||||
@ -95,6 +166,7 @@ func UnloadModels(models []types.ModelAsset) {
|
||||
}
|
||||
rl.UnloadModel(model.Model)
|
||||
rl.UnloadTexture(model.Texture)
|
||||
delete(loadedModels, model.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user