This commit is contained in:
2026-03-07 07:48:16 +03:00
parent a998771486
commit 95daf12fc5
48 changed files with 4613 additions and 66 deletions

View File

@@ -11,6 +11,10 @@
#include "world.h"
#include "game_object.h"
#include "soundsystem.h"
#include "animation.h"
#include "scenemanager.h"
#include "game_world_objects.h"
#include "actor_base.h"
#include <pugixml.hpp>
@@ -27,6 +31,7 @@ public:
public:
void PlaySound2D(const std::string& filename);
void PlaySound3D(const std::string& filename, const glm::vec3& pos);
void CacheSound(const std::string& filename);
private:
@@ -57,6 +62,24 @@ void GameSoundSystem::PlaySound2D(const std::string& filename)
g_soundSystem.Play(it->second, false);
}
void GameSoundSystem::PlaySound3D(const std::string& filename, const glm::vec3& pos)
{
auto it = m_sounds.find(filename);
if (it == m_sounds.end())
{
CacheSound(filename);
it = m_sounds.find(filename);
}
SDL_assert(it != m_sounds.end());
// .hack due unimplemented sound sources^
if (g_soundSystem.IsPlaying(it->second))
g_soundSystem.Stop(it->second);
g_soundSystem.Play3D(it->second, pos.x, pos.y, pos.z, true);
}
void GameSoundSystem::CacheSound(const std::string& filename)
{
m_sounds.emplace(filename, g_soundSystem.LoadSound(filename.c_str()));
@@ -82,6 +105,11 @@ void enginePlaySound(const char* filename)
GameSoundSystem::GetInstance().PlaySound2D(filename);
}
void enginePlaySound3D(const char* filename, float x, float y, float z)
{
GameSoundSystem::GetInstance().PlaySound3D(filename, glm::vec3(x, y, z));
}
LuaPlus::LuaObject engineCreateEntity(const char* classname)
{
Entity* entity = static_cast<Entity*>(g_game->Lua_CreateEntity(classname));
@@ -157,6 +185,7 @@ void registerEngine()
engineTable.RegisterDirect("add_entity_to_world", &engineAddEntityToWorld);
engineTable.RegisterDirect("get_entity_from_id", &engineGetEntityFromID);
engineTable.RegisterDirect("play_sound", &enginePlaySound);
engineTable.RegisterDirect("play_sound_3d", &enginePlaySound3D);
engineTable.RegisterDirect("get_delta", &engineGetDelta);
engineTable.RegisterDirect("trace_ray", &engineTraceRay);
@@ -231,6 +260,20 @@ void registerInput()
inputTable.RegisterDirect("get_lock_mouse", &inputGetLock);
}
void toggleNoclip()
{
static bool s_noclip = false;
s_noclip = !s_noclip;
LuaPlus::LuaObject player = GetLuaState().GetGlobal("g_player");
if (player.IsTable())
{
ActorBase* actor = (ActorBase*)player["__object"].GetLightUserdata();
actor->SetNoclip(s_noclip);
}
}
int cameraGetPos(LuaPlus::LuaState* state)
{
glm::vec3 v = glm::vec3(0.0f);
@@ -494,6 +537,16 @@ void Game::LoadLevelXML(const char* mapname)
entity->LoadModel(filename);
}
pugi::xml_node animation = entitynode.child("Animation");
if (animation)
{
const char* name = animation.attribute("name").as_string();
int mode = animation.attribute("mode").as_int();
SkeletonInstance* skeleton = entity->GetSkeletonInstance();
if (skeleton)
skeleton->PlayAnimation(skeleton->FindAnimation(name), mode);
}
pugi::xml_node physics = entitynode.child("Physics");
if (physics)
{
@@ -502,6 +555,10 @@ void Game::LoadLevelXML(const char* mapname)
entity->CreateTestBody();
}
Light* light = dynamic_cast<Light*>(entity); // BAD!!!
if (light)
light->InitFromXML(entitynode);
entity->Init();
//IEntityBase* entity = g_entityManager->CreateEntity(classname.as_string());