Skip to content

Commit

Permalink
Merge remote-tracking branch 'uramer/0.7.1-game-settings' into 0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Feb 29, 2020
2 parents 27d35d7 + bb81826 commit 06a3604
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
21 changes: 19 additions & 2 deletions apps/openmw-mp/Script/Functions/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,30 @@ void SettingFunctions::SetWaitAllowed(unsigned short pid, bool state)
player->waitAllowed = state;
}

void SettingFunctions::SendSettings(unsigned short pid) noexcept
void SettingFunctions::SetGameSettingValue(unsigned short pid, const char* setting, const char* value) {
Player* player;
GET_PLAYER(pid, player, );

player->gameSettings[setting] = value;
}

void SettingFunctions::ClearGameSettingValues(unsigned short pid) {
Player* player;
GET_PLAYER(pid, player, );

player->gameSettings.clear();
}

void SettingFunctions::SendSettings(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept
{
Player *player;
GET_PLAYER(pid, player,);

mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_SETTINGS);
packet->setPlayer(player);

packet->Send(false);
if (!skipAttachedPlayer)
packet->Send(false);
if (sendToOtherPlayers)
packet->Send(true);
}
27 changes: 26 additions & 1 deletion apps/openmw-mp/Script/Functions/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
{"SetWildernessRestAllowed", SettingFunctions::SetWildernessRestAllowed},\
{"SetWaitAllowed", SettingFunctions::SetWaitAllowed},\
\
{"SetGameSettingValue", SettingFunctions::SetGameSettingValue},\
{"ClearGameSettingValues", SettingFunctions::ClearGameSettingValues},\
\
{"SendSettings", SettingFunctions::SendSettings}

class SettingFunctions
Expand Down Expand Up @@ -109,13 +112,35 @@ class SettingFunctions
*/
static void SetWaitAllowed(unsigned short pid, bool state);

/**
* \brief Set value for a game setting.
*
* This overrides the setting value set in OpenMW Launcher. Only applies to the Game category.
*
* \param pid The player ID.
* \param setting Name of a setting in the Game category
* \param value Value of the setting (as a string)
* \return void
*/
static void SetGameSettingValue(unsigned short pid, const char* setting, const char* value);

/**
* \brief Clear the settings values
*
* Clear any changes done by SetGameSettingValue
*
* \param pid The player ID.
* \return void
*/
static void ClearGameSettingValues(unsigned short pid);

/**
* \brief Send a PlayerSettings packet to the player affected by it.
*
* \param pid The player ID to send it to.
* \return void
*/
static void SendSettings(unsigned short pid) noexcept;
static void SendSettings(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept;
};

#endif //OPENMW_SETTINGSAPI_HPP
5 changes: 5 additions & 0 deletions apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace mwmp
{
class ProcessorGameSettings final: public PlayerProcessor
{
const std::string GAME_SETTING_CATEGORY = "Game";
public:
ProcessorGameSettings()
{
Expand Down Expand Up @@ -49,6 +50,10 @@ namespace mwmp
}

MWBase::Environment::get().getWorld()->setPhysicsFramerate(player->physicsFramerate);

for (auto setting : player->gameSettings) {
Settings::Manager::setString(setting.first, GAME_SETTING_CATEGORY, setting.second);
}
}
}
};
Expand Down
1 change: 1 addition & 0 deletions components/openmw-mp/Base/BasePlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ namespace mwmp
std::string birthsign;
std::string chatMessage;
CharGenState charGenState;
std::map<std::string, std::string> gameSettings;

std::string sound;
Animation animation;
Expand Down
27 changes: 27 additions & 0 deletions components/openmw-mp/Packets/Player/PacketGameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,31 @@ void PacketGameSettings::Packet(RakNet::BitStream *newBitstream, bool send)
RW(player->waitAllowed, send);
RW(player->enforcedLogLevel, send);
RW(player->physicsFramerate, send);

uint32_t gameSettingCount = static_cast<uint32_t>(player->gameSettings.size());
RW(gameSettingCount, send);

std::string mapIndex;
std::string mapValue;

if (send)
{
for (auto&& gameSetting : player->gameSettings)
{
mapIndex = gameSetting.first;
mapValue = gameSetting.second;
RW(mapIndex, send, false);
RW(mapValue, send, false);
}
}
else
{
player->gameSettings.clear();
for (unsigned int n = 0; n < gameSettingCount; n++)
{
RW(mapIndex, send, false);
RW(mapValue, send, false);
player->gameSettings[mapIndex] = mapValue;
}
}
}

0 comments on commit 06a3604

Please sign in to comment.