Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua API: Add sound_pause and sound_resume to minetest api #5124

Closed
wants to merge 33 commits into from
Closed
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
70b5bd5
Update client.h
14NGiestas Jan 28, 2017
08bc581
Update guiEngine.cpp
14NGiestas Jan 28, 2017
a55d21f
Update guiEngine.h
14NGiestas Jan 28, 2017
e25e7c1
Update clientopcodes.h
14NGiestas Jan 28, 2017
b405ad0
Update clientpackethandler.cpp
14NGiestas Jan 28, 2017
6fdab7c
Update networkprotocol.h
14NGiestas Jan 28, 2017
bd32f60
Update l_mainmenu.cpp
14NGiestas Jan 28, 2017
d8efe4a
Update l_mainmenu.h
14NGiestas Jan 28, 2017
efaffa1
Update l_server.cpp
14NGiestas Jan 28, 2017
f85ea57
Update l_server.h
14NGiestas Jan 28, 2017
8e2eb08
Update server.cpp
14NGiestas Jan 28, 2017
b57bc59
Update server.h
14NGiestas Jan 28, 2017
2aab9be
Update sound.h
14NGiestas Jan 28, 2017
54d622a
Update sound_openal.cpp
14NGiestas Jan 28, 2017
2a4d48c
Update clientopcodes.h
14NGiestas Jan 28, 2017
55a2e0b
Update clientopcodes.cpp
14NGiestas Jan 28, 2017
c178ebd
Removed unnecessary cout streams;
14NGiestas Jan 28, 2017
c4b0237
Fixed identation
14NGiestas Jan 31, 2017
8ab56cb
Fixed code style issues
14NGiestas Jan 31, 2017
dc9deeb
Removed useless space between two functions
14NGiestas Jan 31, 2017
7e267a4
Fixed identation issue in guiEngine.h
14NGiestas Jan 31, 2017
e93cca2
Added sending rule into serveropcodes.cpp
14NGiestas Jan 31, 2017
e42b862
Fixed code style in sound_openal.cpp
14NGiestas Jan 31, 2017
a354c55
Update sound_openal.cpp
14NGiestas Jan 31, 2017
975f3ac
Update clientpackethandler.cpp
14NGiestas Feb 1, 2017
6a33ffe
Update clientopcodes.cpp
14NGiestas Feb 1, 2017
d954cfd
Fixed more style and naming convention issues
14NGiestas Feb 18, 2017
b516965
Update lua_api.txt
14NGiestas Feb 18, 2017
1b8a778
Merge branch 'master' into master
14NGiestas Jun 11, 2017
437221c
Switch "UNORDERED_MAP" to "std::unordered_map" data type
14NGiestas Jul 2, 2017
b9c0852
Switch "UNORDERED_MAP" to "std::unordered_map" data type
14NGiestas Jul 2, 2017
a8ed61e
Update server.cpp
14NGiestas Jul 2, 2017
1fff782
Update sound_openal.cpp
14NGiestas Jul 2, 2017
File filter...
Filter file types
Jump to鈥
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -388,6 +388,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void handleCommand_ItemDef(NetworkPacket* pkt);
void handleCommand_PlaySound(NetworkPacket* pkt);
void handleCommand_StopSound(NetworkPacket* pkt);
void handleCommand_PauseSound(NetworkPacket* pkt);

This comment has been minimized.

Copy link
@Dumbeldor

Dumbeldor Jul 4, 2017

Contributor

void handleCommand_PauseSound(NetworkPacket *pkt);

void handleCommand_ResumeSound(NetworkPacket* pkt);

This comment has been minimized.

Copy link
@Dumbeldor

Dumbeldor Jul 4, 2017

Contributor

void handleCommand_PauseSound(NetworkPacket *pkt);

void handleCommand_Privileges(NetworkPacket* pkt);
void handleCommand_InventoryFormSpec(NetworkPacket* pkt);
void handleCommand_DetachedInventory(NetworkPacket* pkt);
@@ -601,10 +601,22 @@ void GUIEngine::stopSound(s32 handle)
m_sound_manager->stopSound(handle);
}

/******************************************************************************/
void GUIEngine::pauseSound(s32 handle)
{
m_sound_manager->pauseSound(handle);
}

/******************************************************************************/
void GUIEngine::resumeSound(s32 handle)
{
m_sound_manager->resumeSound(handle);
}


/******************************************************************************/
unsigned int GUIEngine::queueAsync(std::string serialized_func,
std::string serialized_params)
{
return m_script->queueAsync(serialized_func, serialized_params);
}

@@ -308,8 +308,8 @@ class GUIEngine {
s32 playSound(SimpleSoundSpec spec, bool looped);
/** stop playing a sound started with playSound() */
void stopSound(s32 handle);


void pauseSound(s32 handle);
void resumeSound(s32 handle);
};


@@ -108,8 +108,8 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_LOCAL_PLAYER_ANIMATIONS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_LocalPlayerAnimations }, // 0x51
{ "TOCLIENT_EYE_OFFSET", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_EyeOffset }, // 0x52
{ "TOCLIENT_DELETE_PARTICLESPAWNER", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_DeleteParticleSpawner }, // 0x53
null_command_handler,
null_command_handler,
{ "TOCLIENT_PAUSE_SOUND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_PauseSound }, // 0x54
{ "TOCLIENT_RESUME_SOUND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ResumeSound }, // 0x55
null_command_handler,
null_command_handler,
null_command_handler,
@@ -812,13 +812,43 @@ void Client::handleCommand_StopSound(NetworkPacket* pkt)

*pkt >> server_id;

UNORDERED_MAP<s32, int>::iterator i = m_sounds_server_to_client.find(server_id);
if (i != m_sounds_server_to_client.end()) {
int client_id = i->second;
UNORDERED_MAP<s32, int>::iterator it = m_sounds_server_to_client.find(server_id);
if (it != m_sounds_server_to_client.end()) {
int client_id = it->second;
m_sound->stopSound(client_id);
}
}



void Client::handleCommand_PauseSound(NetworkPacket* pkt)
{
s32 server_id;

*pkt >> server_id;

UNORDERED_MAP<s32, int>::iterator it = m_sounds_server_to_client.find(server_id);
if (it != m_sounds_server_to_client.end()) {
int client_id = it->second;
m_sound->pauseSound(client_id);
}
}

void Client::handleCommand_ResumeSound(NetworkPacket* pkt)
{
s32 server_id;

*pkt >> server_id;

UNORDERED_MAP<s32, int>::iterator it = m_sounds_server_to_client.find(server_id);
if (it != m_sounds_server_to_client.end()) {
int client_id = it->second;
m_sound->resumeSound(client_id);
}
}



void Client::handleCommand_Privileges(NetworkPacket* pkt)
{
m_privileges.clear();
@@ -426,6 +426,17 @@ enum ToClientCommand
s32 sound_id
*/

TOCLIENT_PAUSE_SOUND = 0x54,
/*
s32 sound_id
*/

TOCLIENT_RESUME_SOUND = 0x55,
/*
s32 sound_id
*/


TOCLIENT_PRIVILEGES = 0x41,
/*
u16 number of privileges
@@ -197,8 +197,8 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_LOCAL_PLAYER_ANIMATIONS", 0, true }, // 0x51
{ "TOCLIENT_EYE_OFFSET", 0, true }, // 0x52
{ "TOCLIENT_DELETE_PARTICLESPAWNER", 0, true }, // 0x53
null_command_factory,
null_command_factory,
{ "TOCLIENT_PAUSE_SOUND", 0, true }, // 0x54
{ "TOCLIENT_RESUME_SOUND", 0, true }, // 0x55
null_command_factory,
null_command_factory,
null_command_factory,
@@ -982,6 +982,29 @@ int ModApiMainMenu::l_sound_stop(lua_State *L)
return 1;
}

/******************************************************************************/
int ModApiMainMenu::l_sound_pause(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);

u32 handle = luaL_checkinteger(L, 1);
engine->pauseSound(handle);

return 1;
}

/******************************************************************************/
int ModApiMainMenu::l_sound_resume(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);

u32 handle = luaL_checkinteger(L, 1);
engine->resumeSound(handle);

return 1;
}


/******************************************************************************/
int ModApiMainMenu::l_download_file(lua_State *L)
{
@@ -83,6 +83,10 @@ class ModApiMainMenu : public ModApiBase {

static int l_sound_stop(lua_State *L);

static int l_sound_pause(lua_State *L);

static int l_sound_resume(lua_State *L);

static int l_gettext(lua_State *L);

//gui
@@ -438,6 +438,24 @@ int ModApiServer::l_sound_stop(lua_State *L)
return 0;
}

// sound_pause(handle)
int ModApiServer::l_sound_pause(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
int handle = luaL_checkinteger(L, 1);
getServer(L)->pauseSound(handle);
return 0;
}

// sound_resume(handle)
int ModApiServer::l_sound_resume(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
int handle = luaL_checkinteger(L, 1);
getServer(L)->resumeSound(handle);
return 0;
}

// is_singleplayer()
int ModApiServer::l_is_singleplayer(lua_State *L)
{
@@ -531,6 +549,8 @@ void ModApiServer::Initialize(lua_State *L, int top)
API_FCT(show_formspec);
API_FCT(sound_play);
API_FCT(sound_stop);
API_FCT(sound_pause);
API_FCT(sound_resume);

API_FCT(get_player_information);
API_FCT(get_player_privs);
@@ -67,6 +67,12 @@ class ModApiServer : public ModApiBase {
// sound_stop(handle)
static int l_sound_stop(lua_State *L);

// sound_resume(handle)
static int l_sound_resume(lua_State *L);

// sound_pause(handle)
static int l_sound_pause(lua_State *L);

// get_player_privs(name, text)
static int l_get_player_privs(lua_State *L);

@@ -2080,6 +2080,44 @@ void Server::stopSound(s32 handle)
m_playing_sounds.erase(i);
}


void Server::pauseSound(s32 handle)
{
// Get sound reference
UNORDERED_MAP<s32, ServerPlayingSound>::iterator i = m_playing_sounds.find(handle);
if (i == m_playing_sounds.end())
return;
ServerPlayingSound &psound = i->second;

NetworkPacket pkt(TOCLIENT_PAUSE_SOUND, 4);
pkt << handle;

for (UNORDERED_SET<u16>::iterator i = psound.clients.begin();
i != psound.clients.end(); ++i) {
// Send as reliable
m_clients.send(*i, 0, &pkt, true);
}
}


void Server::resumeSound(s32 handle)
{
// Get sound reference
UNORDERED_MAP<s32, ServerPlayingSound>::iterator i = m_playing_sounds.find(handle);
if (i == m_playing_sounds.end())
return;
ServerPlayingSound &psound = i->second;

NetworkPacket pkt(TOCLIENT_RESUME_SOUND, 4);
pkt << handle;

for (UNORDERED_SET<u16>::iterator i = psound.clients.begin();
i != psound.clients.end(); ++i) {
// Send as reliable
m_clients.send(*i, 0, &pkt, true);
}
}

void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
std::vector<u16> *far_players, float far_d_nodes)
{
@@ -236,6 +236,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
// Envlock
s32 playSound(const SimpleSoundSpec &spec, const ServerSoundParams &params);
void stopSound(s32 handle);
void pauseSound(s32 handle);
void resumeSound(s32 handle);

// Envlock
std::set<std::string> getPlayerEffectivePrivs(const std::string &name);
@@ -576,6 +578,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
float m_time_of_day_send_timer;
// Uptime of server in seconds
MutexedVariable<double> m_uptime;

/*
Client interface
*/
@@ -661,4 +664,3 @@ class Server : public con::PeerHandler, public MapEventReceiver,
void dedicated_server_loop(Server &server, bool &kill);

#endif

@@ -67,11 +67,14 @@ class ISoundManager
virtual int playSoundAt(const std::string &name, bool loop,
float volume, v3f pos) = 0;
virtual void stopSound(int sound) = 0;
virtual void resumeSound(int sound) = 0;
virtual void pauseSound(int sound) = 0;
virtual bool soundExists(int sound) = 0;
virtual void updateSoundPosition(int sound, v3f pos) = 0;

int playSound(const SimpleSoundSpec &spec, bool loop)
{ return playSound(spec.name, loop, spec.gain); }

int playSoundAt(const SimpleSoundSpec &spec, bool loop, v3f pos)
{ return playSoundAt(spec.name, loop, spec.gain, pos); }
};
@@ -90,6 +93,8 @@ class DummySoundManager: public ISoundManager
int playSoundAt(const std::string &name, bool loop,
float volume, v3f pos) {return 0;}
void stopSound(int sound) {}
void resumeSound(int sound) {}
void pauseSound(int sound) {}
bool soundExists(int sound) {return false;}
void updateSoundPosition(int sound, v3f pos) {}
};
@@ -98,4 +103,3 @@ class DummySoundManager: public ISoundManager
extern DummySoundManager dummySoundManager;

#endif

ProTip! Use n and p to navigate between commits in a pull request.
You can鈥檛 perform that action at this time.