From ae39daf76a2b7cec9e0ac096b6f45205cba72ccc Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 20 Nov 2016 22:54:49 +0200 Subject: [PATCH] Add and implement ID_MUSIC_PLAY --- apps/openmw-mp/Networking.cpp | 19 +++++++++++++++++-- apps/openmw/mwmp/Networking.cpp | 17 ++++++++++++++--- apps/openmw/mwscript/miscextensions.cpp | 2 +- apps/openmw/mwscript/soundextensions.cpp | 8 ++++++++ components/CMakeLists.txt | 2 +- components/openmw-mp/Base/WorldEvent.hpp | 2 +- .../Controllers/WorldPacketController.cpp | 2 ++ components/openmw-mp/NetworkMessages.hpp | 1 + .../Packets/World/PacketMusicPlay.cpp | 16 ++++++++++++++++ .../Packets/World/PacketMusicPlay.hpp | 17 +++++++++++++++++ .../Packets/World/PacketVideoPlay.cpp | 2 +- 11 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 components/openmw-mp/Packets/World/PacketMusicPlay.cpp create mode 100644 components/openmw-mp/Packets/World/PacketMusicPlay.hpp diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 467d6351c..d316b59fc 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -570,6 +570,21 @@ void Networking::processWorldPacket(RakNet::Packet *packet) break; } + case ID_MUSIC_PLAY: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_MUSIC_PLAY from %s", + player->Npc()->mName.c_str()); + + myPacket->Read(event); + + LOG_APPEND(Log::LOG_WARN, "- filename: %s", + event->filename.c_str()); + + myPacket->Send(event, true); + + break; + } + case ID_VIDEO_PLAY: { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_VIDEO_PLAY from %s", @@ -577,8 +592,8 @@ void Networking::processWorldPacket(RakNet::Packet *packet) myPacket->Read(event); - LOG_APPEND(Log::LOG_WARN, "- video: %s\n- allowSkipping: %s", - event->video.c_str(), + LOG_APPEND(Log::LOG_WARN, "- filename: %s\n- allowSkipping: %s", + event->filename.c_str(), event->allowSkipping ? "true" : "false"); myPacket->Send(event, true); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 469214573..c66956f19 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -10,6 +10,7 @@ #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" +#include "../mwbase/soundmanager.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwworld/cellstore.hpp" @@ -946,14 +947,24 @@ void Networking::processWorldPacket(RakNet::Packet *packet) break; } + case ID_MUSIC_PLAY: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_MUSIC_PLAY"); + LOG_APPEND(Log::LOG_WARN, "- filename: %s", + event->filename.c_str()); + + MWBase::Environment::get().getSoundManager()->streamMusic(event->filename); + + break; + } case ID_VIDEO_PLAY: { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_VIDEO_PLAY"); - LOG_APPEND(Log::LOG_WARN, "- video: %s\n- allowSkipping: %s", - event->video.c_str(), + LOG_APPEND(Log::LOG_WARN, "- filename: %s\n- allowSkipping: %s", + event->filename.c_str(), event->allowSkipping ? "true" : "false"); - MWBase::Environment::get().getWindowManager()->playVideo(event->video, event->allowSkipping); + MWBase::Environment::get().getWindowManager()->playVideo(event->filename, event->allowSkipping); break; } diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index ba368a9ba..68803de45 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -90,7 +90,7 @@ namespace MWScript // Added by tes3mp mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); - event->video = name; + event->filename = name; event->allowSkipping = allowSkipping; mwmp::Main::get().getNetworking()->getWorldPacket(ID_VIDEO_PLAY)->Send(event); diff --git a/apps/openmw/mwscript/soundextensions.cpp b/apps/openmw/mwscript/soundextensions.cpp index a9896d203..a7531cb3d 100644 --- a/apps/openmw/mwscript/soundextensions.cpp +++ b/apps/openmw/mwscript/soundextensions.cpp @@ -1,5 +1,8 @@ #include "extensions.hpp" +#include +#include "../mwmp/Main.hpp" + #include #include @@ -66,6 +69,11 @@ namespace MWScript std::string sound = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); + // Added by tes3mp + mwmp::WorldEvent *event = mwmp::Main::get().getNetworking()->createWorldEvent(); + event->filename = sound; + mwmp::Main::get().getNetworking()->getWorldPacket(ID_MUSIC_PLAY)->Send(event); + MWBase::Environment::get().getSoundManager()->streamMusic (sound); } }; diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 43bd68341..db89cd792 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -162,7 +162,7 @@ add_component_dir (openmw-mp Packets/World/PacketObjectRotate Packets/World/PacketObjectAnimPlay Packets/World/PacketContainerAdd Packets/World/PacketContainerRemove Packets/World/PacketDoorActivate - Packets/World/PacketVideoPlay + Packets/World/PacketMusicPlay Packets/World/PacketVideoPlay Packets/World/PacketScriptLocalShort Packets/World/PacketScriptLocalFloat Packets/World/PacketScriptMemberShort Packets/World/PacketScriptGlobalShort) diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index c02aa6c75..148608639 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -32,7 +32,7 @@ namespace mwmp int lockLevel; float scale; - std::string video; + std::string filename; bool allowSkipping; std::string animGroup; diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp index 661456d6d..9d073e4db 100644 --- a/components/openmw-mp/Controllers/WorldPacketController.cpp +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -14,6 +14,7 @@ #include "../Packets/World/PacketContainerAdd.hpp" #include "../Packets/World/PacketContainerRemove.hpp" #include "../Packets/World/PacketDoorActivate.hpp" +#include "../Packets/World/PacketMusicPlay.hpp" #include "../Packets/World/PacketVideoPlay.hpp" #include "../Packets/World/PacketScriptLocalShort.hpp" @@ -45,6 +46,7 @@ mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *pee AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); + AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index 902995efd..f01aa9b3a 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -45,6 +45,7 @@ enum GameMessages ID_CONTAINER_ADD, ID_CONTAINER_REMOVE, ID_DOOR_ACTIVATE, + ID_MUSIC_PLAY, ID_VIDEO_PLAY, ID_SCRIPT_LOCAL_SHORT, diff --git a/components/openmw-mp/Packets/World/PacketMusicPlay.cpp b/components/openmw-mp/Packets/World/PacketMusicPlay.cpp new file mode 100644 index 000000000..0ae0bb0b9 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketMusicPlay.cpp @@ -0,0 +1,16 @@ +#include +#include "PacketMusicPlay.hpp" + +using namespace mwmp; + +PacketMusicPlay::PacketMusicPlay(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_VIDEO_PLAY; +} + +void PacketMusicPlay::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(event->filename, send); +} diff --git a/components/openmw-mp/Packets/World/PacketMusicPlay.hpp b/components/openmw-mp/Packets/World/PacketMusicPlay.hpp new file mode 100644 index 000000000..d9542bb85 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketMusicPlay.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETMUSICPLAY_HPP +#define OPENMW_PACKETMUSICPLAY_HPP + +#include + +namespace mwmp +{ + class PacketMusicPlay : public WorldPacket + { + public: + PacketMusicPlay(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETMUSICPLAY_HPP diff --git a/components/openmw-mp/Packets/World/PacketVideoPlay.cpp b/components/openmw-mp/Packets/World/PacketVideoPlay.cpp index 26c79a10b..7953a5a72 100644 --- a/components/openmw-mp/Packets/World/PacketVideoPlay.cpp +++ b/components/openmw-mp/Packets/World/PacketVideoPlay.cpp @@ -12,6 +12,6 @@ void PacketVideoPlay::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send { WorldPacket::Packet(bs, event, send); - RW(event->video, send); + RW(event->filename, send); RW(event->allowSkipping, send); }