1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 06:47:45 +00:00

Fixed zone updates being extremly slow, fixed crash with wrong item reward field, fixed wrong casttime for eventAction

This commit is contained in:
Mordred 2018-02-01 23:32:59 +01:00
parent 7a23d24336
commit ab30d8b344
7 changed files with 45 additions and 34 deletions

View file

@ -28,7 +28,7 @@ Core::Action::EventAction::EventAction( Entity::ActorPtr pActor, uint32_t eventI
m_handleActionType = HandleActionType::Event; m_handleActionType = HandleActionType::Event;
m_eventId = eventId; m_eventId = eventId;
m_id = action; m_id = action;
m_castTime = g_exdDataGen.getEventAction( action )->castTime; // TODO: Add security checks. m_castTime = g_exdDataGen.getEventAction( action )->castTime * 100; // TODO: Add security checks.
m_onActionFinishClb = finishRef; m_onActionFinishClb = finishRef;
m_onActionInterruptClb = interruptRef; m_onActionInterruptClb = interruptRef;
m_pSource = pActor; m_pSource = pActor;

View file

@ -1043,7 +1043,7 @@ bool Core::Entity::Player::giveQuestRewards( uint32_t questId, uint32_t optional
for( uint32_t i = 0; i < questInfo->itemReward0.size(); i++ ) for( uint32_t i = 0; i < questInfo->itemReward0.size(); i++ )
{ {
// TODO: add the correct amount of items instead of 1 // TODO: add the correct amount of items instead of 1
addItem( -1, questInfo->itemReward0.at( i ), questInfo->itemReward1.at( i ) ); addItem( -1, questInfo->itemReward0.at( i ), questInfo->itemCountReward0.at( i ) );
} }
} }

View file

@ -282,7 +282,7 @@ void Core::ServerZone::mainLoop()
auto it = this->m_sessionMapById.begin(); auto it = this->m_sessionMapById.begin();
for( ; it != this->m_sessionMapById.end(); ) for( ; it != this->m_sessionMapById.end(); )
{ {
uint32_t diff = currTime - it->second->getLastDataTime(); int64_t diff = currTime - it->second->getLastDataTime();
auto pPlayer = it->second->getPlayer(); auto pPlayer = it->second->getPlayer();

View file

@ -126,6 +126,7 @@ bool Core::TerritoryMgr::createDefaultTerritories()
instanceMap[guid] = pZone; instanceMap[guid] = pZone;
m_instanceIdToZonePtrMap[guid] = pZone; m_instanceIdToZonePtrMap[guid] = pZone;
m_territoryInstanceMap[territoryId] = instanceMap; m_territoryInstanceMap[territoryId] = instanceMap;
m_zoneSet.insert( { pZone } );
} }
@ -180,6 +181,7 @@ Core::ZonePtr Core::TerritoryMgr::createInstanceContent( uint32_t instanceConten
m_instanceContentToInstanceMap[instanceContentId][pZone->getGuId()] = pZone; m_instanceContentToInstanceMap[instanceContentId][pZone->getGuId()] = pZone;
m_instanceIdToZonePtrMap[pZone->getGuId()] = pZone; m_instanceIdToZonePtrMap[pZone->getGuId()] = pZone;
m_instanceZoneSet.insert( { pZone } );
return pZone; return pZone;
} }
@ -192,6 +194,9 @@ bool Core::TerritoryMgr::removeTerritoryInstance( uint32_t instanceId )
m_instanceIdToZonePtrMap.erase( pZone->getGuId() ); m_instanceIdToZonePtrMap.erase( pZone->getGuId() );
if( m_instanceZoneSet.count( pZone ) )
m_instanceZoneSet.erase( pZone );
if( isInstanceContentTerritory( pZone->getTerritoryId() ) ) if( isInstanceContentTerritory( pZone->getTerritoryId() ) )
{ {
auto instance = boost::dynamic_pointer_cast< InstanceContent >( pZone ); auto instance = boost::dynamic_pointer_cast< InstanceContent >( pZone );
@ -268,16 +273,14 @@ Core::ZonePtr Core::TerritoryMgr::getZoneByTerriId( uint32_t territoryId ) const
void Core::TerritoryMgr::updateTerritoryInstances( uint32_t currentTime ) void Core::TerritoryMgr::updateTerritoryInstances( uint32_t currentTime )
{ {
for( auto zoneMap : m_territoryInstanceMap ) for( auto& zone : m_zoneSet )
{ {
for( auto zone : zoneMap.second ) zone->runZoneLogic( currentTime );
zone.second->runZoneLogic( currentTime );
} }
for( auto zoneMap : m_instanceContentToInstanceMap ) for( auto& zone : m_instanceZoneSet )
{ {
for( auto zone: zoneMap.second ) zone->runZoneLogic( currentTime );
zone.second->runZoneLogic( currentTime );
} }
} }

View file

@ -3,6 +3,7 @@
#include <common/Exd/ExdData.h> #include <common/Exd/ExdData.h>
#include "Forwards.h" #include "Forwards.h"
#include <set>
namespace Core namespace Core
{ {
@ -139,6 +140,12 @@ namespace Core
/*! internal counter for instanceIds */ /*! internal counter for instanceIds */
uint32_t m_lastInstanceId; uint32_t m_lastInstanceId;
/*! set of ZonePtrs for quick iteration*/
std::set< ZonePtr > m_zoneSet;
/*! set of ZonePtrs for quick iteration*/
std::set< ZonePtr > m_instanceZoneSet;
public: public:
/*! returns a list of instanceContent InstanceIds currently active */ /*! returns a list of instanceContent InstanceIds currently active */
InstanceIdList getInstanceContentIdList( uint16_t instanceContentId ) const; InstanceIdList getInstanceContentIdList( uint16_t instanceContentId ) const;

View file

@ -62,8 +62,27 @@ Zone::Zone( uint16_t territoryId, uint32_t guId, const std::string& internalName
m_placeName = placeName; m_placeName = placeName;
m_lastMobUpdate = 0; m_lastMobUpdate = 0;
m_currentWeather = getNextWeather();
m_weatherOverride = 0; m_weatherOverride = 0;
m_territoryTypeInfo = g_exdDataGen.getTerritoryType( territoryId );
uint8_t weatherRateId = m_territoryTypeInfo->weatherRate > g_exdDataGen.getWeatherRateIdList().size() ?
uint8_t{ 0 } : m_territoryTypeInfo->weatherRate;
uint8_t sumPc = 0;
auto weatherRateFields = g_exdDataGen.m_WeatherRateDat.get_row( weatherRateId );
for( size_t i = 0; i < 16; )
{
int32_t weatherId = boost::get< int32_t >( weatherRateFields[i] );
if( weatherId == 0 )
break;
sumPc += boost::get< uint8_t >( weatherRateFields[i + 1] );
m_weatherRateMap[sumPc] = weatherId;
i += 2;
}
m_currentWeather = getNextWeather();
} }
Zone::~Zone() Zone::~Zone()
@ -207,8 +226,6 @@ void Zone::loadCellCache()
uint8_t Zone::getNextWeather() uint8_t Zone::getNextWeather()
{ {
auto zoneInfo = g_exdDataGen.getTerritoryType( getTerritoryId() );
uint32_t unixTime = static_cast< uint32_t >( Util::getTimeSeconds() ); uint32_t unixTime = static_cast< uint32_t >( Util::getTimeSeconds() );
// Get Eorzea hour for weather start // Get Eorzea hour for weather start
uint32_t bell = unixTime / 175; uint32_t bell = unixTime / 175;
@ -225,28 +242,7 @@ uint8_t Zone::getNextWeather()
auto rate = static_cast< uint8_t >( step2 % 0x64 ); auto rate = static_cast< uint8_t >( step2 % 0x64 );
uint8_t weatherRateNum = zoneInfo->weatherRate > g_exdDataGen.getWeatherRateIdList().size() ? 0 : zoneInfo->weatherRate; for( auto entry : m_weatherRateMap )
auto weatherRate = g_exdDataGen.getWeatherRate( weatherRateNum );
auto weatherRateFields = g_exdDataGen.m_WeatherRateDat.get_row( weatherRateNum );
std::map< uint8_t, int32_t> weatherRateMap;
uint8_t sumPc = 0;
for( size_t i = 0; i < 16; )
{
int32_t weatherId = boost::get< int32_t >( weatherRateFields[i] );
if( weatherId == 0 )
break;
sumPc += boost::get< uint8_t >( weatherRateFields[i + 1] );
weatherRateMap[sumPc] = weatherId;
i += 2;
}
for( auto entry : weatherRateMap )
{ {
uint8_t sRate = entry.first; uint8_t sRate = entry.first;
auto weatherId = static_cast< uint8_t >( entry.second ); auto weatherId = static_cast< uint8_t >( entry.second );

View file

@ -14,6 +14,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <common/Exd/ExdDataGenerated.h>
namespace Core { namespace Core {
class Session; class Session;
@ -50,6 +51,10 @@ protected:
uint64_t m_lastMobUpdate; uint64_t m_lastMobUpdate;
boost::shared_ptr< Data::TerritoryType > m_territoryTypeInfo;
std::map< uint8_t, int32_t> m_weatherRateMap;
public: public:
Zone(); Zone();