Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5127: Move the algorithm to create a speaker to the core module, add…
… corresponding "CreateSpeaker" command.
- Loading branch information
1 parent
f8ce09d
commit 4518031
Showing
5 changed files
with
93 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma once | ||
|
||
#include "icommandsystem.h" | ||
#include "itextstream.h" | ||
#include "iundo.h" | ||
#include "iselection.h" | ||
#include "isound.h" | ||
#include "fmt/format.h" | ||
#include "command/ExecutionFailure.h" | ||
#include "string/convert.h" | ||
|
||
namespace entity | ||
{ | ||
|
||
namespace algorithm | ||
{ | ||
|
||
inline void CreateSpeaker(const cmd::ArgumentList& args) | ||
{ | ||
constexpr const char* SPEAKER_CLASSNAME = "speaker"; | ||
|
||
if (args.size() != 2) | ||
{ | ||
rWarning() << "Usage: CreateSpeaker <soundShader:string> <position:Vector3>" << std::endl; | ||
return; | ||
} | ||
|
||
UndoableCommand command("addSpeaker"); | ||
|
||
// Cancel all selection | ||
GlobalSelectionSystem().setSelectedAll(false); | ||
|
||
// Create the speaker entity (exceptions are allowed to leak) | ||
auto spkNode = GlobalEntityModule().createEntityFromSelection( | ||
SPEAKER_CLASSNAME, args[1].getVector3() | ||
); | ||
|
||
auto shader = args[0].getString(); | ||
|
||
if (shader.empty() || !module::GlobalModuleRegistry().moduleExists(MODULE_SOUNDMANAGER)) | ||
{ | ||
return; // done here | ||
} | ||
|
||
auto soundShader = GlobalSoundManager().getSoundShader(shader); | ||
|
||
if (!soundShader) | ||
{ | ||
throw cmd::ExecutionFailure(fmt::format(_("Cannot find sound shader: {0}"), shader)); | ||
} | ||
|
||
// Set the shader keyvalue | ||
auto& entity = spkNode->getEntity(); | ||
|
||
entity.setKeyValue("s_shader", soundShader->getName()); | ||
|
||
// Initialise the speaker with suitable distance values | ||
auto radii = soundShader->getRadii(); | ||
|
||
entity.setKeyValue("s_mindistance", string::to_string(radii.getMin(true))); | ||
entity.setKeyValue("s_maxdistance", radii.getMax(true) > 0 ? string::to_string(radii.getMax(true)) : "10"); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters