1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 22:19:54 +00:00

Merge branch '0.7.0reset' of https://github.com/uramer/openmw into 0.7.1

# Conflicts:
#	apps/openmw-mp/Script/Functions/Worldstate.cpp
#	apps/openmw-mp/Script/Functions/Worldstate.hpp
#	apps/openmw/mwbase/world.hpp
#	apps/openmw/mwmp/CellController.cpp
#	apps/openmw/mwworld/cellstore.cpp
#	apps/openmw/mwworld/worldimp.cpp
#	apps/openmw/mwworld/worldimp.hpp
This commit is contained in:
David Cernat 2020-02-11 15:41:38 +02:00
commit a13cef9913
10 changed files with 338 additions and 2 deletions

View file

@ -3,8 +3,11 @@
#include <apps/openmw-mp/Networking.hpp>
#include <apps/openmw-mp/Player.hpp>
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
#include <apps/openmw-mp/CellController.hpp>
#include <fstream>
#include <apps/openmw-mp/Utils.hpp>
#include "Worldstate.hpp"
using namespace std;
@ -262,6 +265,12 @@ void WorldstateFunctions::ClearSynchronizedClientGlobalIds() noexcept
writeWorldstate.synchronizedClientGlobalIds.clear();
}
void WorldstateFunctions::AddCellToReset(const char *cellDescription) noexcept
{
ESM::Cell cell = Utils::getCellFromDescription(cellDescription);
writeWorldstate.cellsToReset.push_back(cell);
}
void WorldstateFunctions::ClearEnforcedCollisionRefIds() noexcept
{
writeWorldstate.enforcedCollisionRefIds.clear();
@ -272,6 +281,11 @@ void WorldstateFunctions::ClearDestinationOverrides() noexcept
writeWorldstate.destinationOverrides.clear();
}
void WorldstateFunctions::ClearCellsToReset() noexcept
{
writeWorldstate.cellsToReset.clear();
}
void WorldstateFunctions::SaveMapTileImageFile(unsigned int index, const char *filePath) noexcept
{
if (index >= readWorldstate->mapTiles.size())
@ -449,6 +463,41 @@ void WorldstateFunctions::SendWorldRegionAuthority(unsigned short pid) noexcept
packet->Send(true);
}
void WorldstateFunctions::SendCellReset(unsigned short pid, bool sendToOtherPlayers) noexcept
{
mwmp::WorldstatePacket *packet = mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_CELL_RESET);
Player *player;
GET_PLAYER(pid, player, );
writeWorldstate.guid = player->guid;
packet->setWorldstate(&writeWorldstate);
packet->Send(sendToOtherPlayers);
if (sendToOtherPlayers)
{
packet->Send(false);
}
CellController * cellController = CellController::get();
for (ESM::Cell cell : writeWorldstate.cellsToReset)
{
if (sendToOtherPlayers)
{
TPlayers * players = Players::getPlayers();
for (TPlayers::iterator iter = players->begin(); iter != players->end(); iter++)
{
cellController->getCell(&cell)->removePlayer((*iter).second, true);
}
}
else
cellController->getCell(&cell)->removePlayer(Players::getPlayer(pid), true);
}
}
// All methods below are deprecated versions of methods from above

View file

@ -81,6 +81,10 @@
{"SendWorldDestinationOverride", WorldstateFunctions::SendWorldDestinationOverride},\
{"SendWorldRegionAuthority", WorldstateFunctions::SendWorldRegionAuthority},\
\
{"AddCellToReset", WorldstateFunctions::AddCellToReset},\
{"ClearCellsToReset", WorldstateFunctions::ClearCellsToReset},\
{"SendCellReset", WorldstateFunctions::SendCellReset},\
\
{"ReadLastWorldstate", WorldstateFunctions::ReadLastWorldstate},\
{"CopyLastWorldstateToStore", WorldstateFunctions::CopyLastWorldstateToStore}
@ -485,6 +489,14 @@ public:
/**
* \brief Clear the list of refIds for which collision should be enforced irrespective
* \brief Add a cell with given cellDescription to the list of cells that should be reset on the client.
*
* \return void
*/
static void AddCellToReset(const char * cellDescription) noexcept;
/**
* \brief Clear the list of refIdsd for which collision should be enforced irrespective
* of other settings.
*
* \return void
@ -498,6 +510,13 @@ public:
*/
static void ClearDestinationOverrides() noexcept;
/**
* \brief Clear the list of cells which should be reset on the client.
*
* \return void
*/
static void ClearCellsToReset() noexcept;
/**
* \brief Save the .png image data of the map tile at a certain index in the read worldstate's
* map changes.
@ -569,6 +588,14 @@ public:
*/
static void SendWorldRegionAuthority(unsigned short pid) noexcept;
/**
* \brief Send a CellReset packet with a list of cells,
*
* \param pid The player ID attached to the packet.
* \return void
*/
static void SendCellReset(unsigned short pid, bool sendToOtherPlayers) noexcept;
/**
* \brief Send a WorldMap packet with the current set of map changes in the write-only
* worldstate.

View file

@ -620,6 +620,16 @@ namespace MWBase
End of tes3mp addition
*/
/*
Start of tes3mp addition
Make it possible to reload active cells (e.g. for CellReset)
*/
virtual void reloadCells(std::vector<ESM::Cell> *cells) = 0;
/*
End of tes3mp addition
*/
virtual void getActorsStandingOn (const MWWorld::ConstPtr& object, std::vector<MWWorld::Ptr> &actors) = 0; ///< get a list of actors standing on \a object
virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if the player is standing on \a object
virtual bool getActorStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if any actor is standing on \a object

View file

@ -2,6 +2,7 @@
#define OPENMW_PROCESSORCELLRESET_HPP
#include "../WorldstateProcessor.hpp"
#include <apps/openmw/mwworld/player.hpp>
namespace mwmp
{
@ -15,7 +16,19 @@ namespace mwmp
virtual void Do(WorldstatePacket &packet, Worldstate &worldstate)
{
// Placeholder
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_CELL_RESET");
CellController* cellController = Main::get().getCellController();
MWBase::World * world = MWBase::Environment::get().getWorld();
world->reloadCells(&worldstate.cellsToReset);
/*for (ESM::Cell cell : worldstate.cellsToReset)
{
Main::get().getLocalPlayer()->storeCellState(cell, CellState::LOAD);
}
Main::get().getLocalPlayer()->sendCellStates();
Main::get().getLocalPlayer()->clearCellStates();*/
}
};
}

View file

@ -621,6 +621,41 @@ namespace MWWorld
End of tes3mp addition
*/
/*
Start of tes3mp addition
Make it possible to get mMovedHere in the CellStore from elsewhere in the code
*/
std::vector<Ptr> CellStore::getMovedHere()
{
std::vector<Ptr> hereVector;
for (CellStore::MovedRefTracker::iterator iter = mMovedHere.begin(); iter != mMovedHere.end(); ++iter)
{
hereVector.push_back(Ptr(iter->first, iter->second));
}
return hereVector;
}
/*
End of tes3mp addition
*/
/*
Start of tes3mp addition
Make it possible to return all NPCs back to this cell from elsewhere in the code
*/
void CellStore::returnFromOtherCells()
{
for (CellStore::MovedRefTracker::iterator iter = mMovedToAnotherCell.begin(); iter != mMovedToAnotherCell.end(); ++iter)
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Returning actor from %d, %d!", iter->second->getCell()->getGridX(), iter->second->getCell()->getGridY());
iter->second->moveTo(iter->first, this);
}
}
/*
End of tes3mp addition
*/
float CellStore::getWaterLevel() const
{
if (isExterior())
@ -1320,4 +1355,66 @@ namespace MWWorld
|| enchantment->mData.mType == ESM::Enchantment::WhenStrikes)
mRechargingItems.emplace_back(ptr.getBase(), static_cast<float>(enchantment->mData.mCharge));
}
/*
Start of tes3mp addition
Make it possible to clear cell data (e.g. to reset cells)
*/
void CellStore::clear()
{
if (mState != State_Unloaded)
{
mState = State_Unloaded;
mIds.clear();
mActivators.mList.clear();
mPotions.mList.clear();
mAppas.mList.clear();
mArmors.mList.clear();
mBooks.mList.clear();
mClothes.mList.clear();
mContainers.mList.clear();
mDoors.mList.clear();
mIngreds.mList.clear();
mCreatureLists.mList.clear();
mItemLists.mList.clear();
mLights.mList.clear();
mLockpicks.mList.clear();
mMiscItems.mList.clear();
mProbes.mList.clear();
mRepairs.mList.clear();
mStatics.mList.clear();
mWeapons.mList.clear();
mBodyParts.mList.clear();
mwmp::CellController * cellController = mwmp::Main::get().getCellController();
for (std::list<LiveCellRef<ESM::Creature>>::iterator ref = mCreatures.mList.begin(); ref != mCreatures.mList.end(); ref++)
{
if (!cellController->isDedicatedActor(MWWorld::Ptr(&*ref, this)))
{
mCreatures.mList.erase(ref);
}
}
for (std::list<LiveCellRef<ESM::NPC>>::iterator ref = mNpcs.mList.begin(); ref != mNpcs.mList.end(); ref++)
{
if (!cellController->isDedicatedActor(MWWorld::Ptr(&*ref, this)))
{
mNpcs.mList.erase(ref);
}
}
mMovedHere.clear();
mMovedToAnotherCell.clear();
mMergedRefs.clear();
mFogState = NULL;
}
}
/*
End of tes3mp addition
*/
}

View file

@ -302,6 +302,26 @@ namespace MWWorld
End of tes3mp addition
*/
/*
Start of tes3mp addition
Make it possible to get the mContainers in the CellStore from elsewhere in the code
*/
std::vector<Ptr> getMovedHere();
/*
End of tes3mp addition
*/
/*
Start of tes3mp addition
Make it possible to get mMovedHere in the CellStore from elsewhere in the code
*/
void returnFromOtherCells();
/*
End of tes3mp addition
*/
float getWaterLevel() const;
bool movedHere(const MWWorld::Ptr& ptr) const;
@ -450,6 +470,16 @@ namespace MWWorld
void respawn ();
///< Check mLastRespawn and respawn references if necessary. This is a no-op if the cell is not loaded.
/*
Start of tes3mp addition
Make it possible to clear cell data (e.g. to reset cells).
*/
void clear ();
/*
End of tes3mp addition
*/
private:
/// Run through references and store IDs

View file

@ -2986,6 +2986,87 @@ namespace MWWorld
End of tes3mp addition
*/
/*
Start of tes3mp addition
Make it possible to reload active cells (e.g. for CellReset)
*/
void World::reloadCells(std::vector<ESM::Cell> * cells)
{
mwmp::CellController* cellController = mwmp::Main::get().getCellController();
MWWorld::Scene::CellStoreCollection activeCells = (*mWorldScene).getActiveCells();
MWWorld::Scene::CellStoreCollection activeToReset;
for (MWWorld::Scene::CellStoreCollection::iterator iter = activeCells.begin(); iter != activeCells.end(); iter++)
{
ESM::Cell iterCell = *(*iter)->getCell();
for (ESM::Cell cell : *cells)
{
if (cellController->isSameCell(iterCell, cell))
{
activeToReset.insert(*iter);
break;
}
}
}
if (!activeToReset.empty())
{
typedef std::pair<Ptr, CellStore*> returnPtr;
std::map<Ptr, CellStore*> moveBack;
for (MWWorld::Scene::CellStoreCollection::iterator iter = activeToReset.begin(); iter != activeToReset.end(); iter++)
{
ESM::Cell iterCell = *(*iter)->getCell();
MWWorld::CellStore * cellStore = cellController->getCellStore(iterCell);
cellStore->returnFromOtherCells();
std::vector<Ptr> movedRefs = cellStore->getMovedHere();
for (Ptr ref : movedRefs)
{
moveBack.insert(returnPtr(ref, cellStore));
}
}
for (MWWorld::Scene::CellStoreCollection::iterator iter = activeCells.begin(); iter != activeCells.end(); iter++)
{
ESM::Cell iterCell = *(*iter)->getCell();
MWWorld::CellStore * cellStore = cellController->getCellStore(iterCell);
mWorldScene->unloadCell(iter);
cellController->getCell(iterCell)->uninitializeLocalActors();
cellController->getCell(iterCell)->uninitializeDedicatedActors();
if (activeToReset.count(*iter) > 0)
{
cellStore->clear();
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Resetting cell %s!", iterCell.getDescription().c_str());
}
}
ESM::CellId pCellId = getPlayerPtr().getCell()->getCell()->getCellId();
changeToCell(pCellId, getPlayerPtr().getRefData().getPosition(), false, true);
for (returnPtr ret : moveBack)
{
ret.first.getCell()->moveTo(ret.first, ret.second);
cellController->getCell(*ret.second->getCell())->initializeDedicatedActor(ret.first);
}
}
else
{
for (ESM::Cell cell : *cells)
{
MWWorld::CellStore * cellStore = cellController->getCellStore(cell);
cellStore->clear();
}
}
}
/*
End of tes3mp addition
*/
bool World::getPlayerStandingOn (const MWWorld::ConstPtr& object)
{
MWWorld::Ptr player = getPlayerPtr();

View file

@ -706,6 +706,16 @@ namespace MWWorld
End of tes3mp addition
*/
/*
Start of tes3mp addition
Make it possible to reload active cells (e.g. for CellReset)
*/
void reloadCells(std::vector<ESM::Cell> * cells) override;
/*
End of tes3mp addition
*/
/*
Start of tes3mp addition

View file

@ -396,6 +396,8 @@ namespace mwmp
std::vector<StaticRecord> staticRecords;
std::vector<WeaponRecord> weaponRecords;
std::vector<ESM::Cell> cellsToReset;
bool isValid;
};
}

View file

@ -13,5 +13,22 @@ void PacketCellReset::Packet(RakNet::BitStream *newBitstream, bool send)
{
WorldstatePacket::Packet(newBitstream, send);
// Placeholder
uint32_t cellCount;
if (send)
cellCount = static_cast<uint32_t>(worldstate->cellsToReset.size());
RW(cellCount, send);
if (!send)
{
worldstate->cellsToReset.clear();
worldstate->cellsToReset.resize(cellCount);
}
for (auto &&cellToReset : worldstate->cellsToReset)
{
RW(cellToReset.mData, send, true);
RW(cellToReset.mName, send, true);
}
}