This commit is contained in:
2026-03-05 15:20:18 +03:00
parent 70c3459703
commit f8f69d3b88
25 changed files with 261 additions and 31 deletions

View File

@@ -7,12 +7,58 @@
#include "entitymanager.h"
#include "world.h"
#include "game_object.h"
#include "soundsystem.h"
#include <pugixml.hpp>
#include <map>
#include <string>
static Game s_game;
Game* g_game = &s_game;
class GameSoundSystem
{
public:
static GameSoundSystem& GetInstance();
public:
void PlaySound2D(const std::string& filename);
void CacheSound(const std::string& filename);
private:
std::map<std::string, SoundHandle> m_sounds;
};
GameSoundSystem& GameSoundSystem::GetInstance()
{
static GameSoundSystem inst;
return inst;
}
void GameSoundSystem::PlaySound2D(const std::string& filename)
{
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.Play(it->second, false);
}
void GameSoundSystem::CacheSound(const std::string& filename)
{
m_sounds.emplace(filename, g_soundSystem.LoadSound(filename.c_str()));
}
void consoleMsg(const char* msg)
{
Logger::Msg("%s", msg);
@@ -28,6 +74,11 @@ void engineWarning(const char* msg)
Core::Warning("%s", msg);
}
void enginePlaySound(const char* filename)
{
GameSoundSystem::GetInstance().PlaySound2D(filename);
}
LuaPlus::LuaObject engineCreateEntity(const char* classname)
{
Entity* entity = static_cast<Entity*>(g_game->Lua_CreateEntity(classname));
@@ -151,6 +202,7 @@ void registerEngine()
engineTable.RegisterDirect("create_entity", &engineCreateEntity);
engineTable.RegisterDirect("add_entity_to_world", &engineAddEntityToWorld);
engineTable.RegisterDirect("get_entity_from_id", &engineGetEntityFromID);
engineTable.RegisterDirect("play_sound", &enginePlaySound);
LuaObject consoleTable = GetLuaState().GetGlobals().CreateTable("console");
consoleTable.RegisterDirect("print", &consoleMsg);