示例#1
0
void Resource::ResourceFileModified()
{
    QFileInfo newFileInfo(m_FullFilePath);
    const QDateTime lastModifiedDate = newFileInfo.lastModified();
    qint64 latestWrittenTo = lastModifiedDate.isValid() ? lastModifiedDate.toMSecsSinceEpoch() : 0;
    qint64 latestWrittenSize = newFileInfo.size();

    if (latestWrittenTo == m_LastSaved) {
        // The FileChangedOnDisk has triggered even though the data in the file has not changed.
        // This can happen if the FileWatcher is monitoring a file that Sigil has just performed
        // a disk operation with, such as Saving before a Merge. In this circumstance the data
        // loaded in memory by Sigil may be more up to date than that on disk (such as after the
        // merge but before user has chosen to Save) so we want to ignore the file change notification.
        return;
    }

    if ((latestWrittenTo != m_LastWrittenTo) || (latestWrittenSize != m_LastWrittenSize)) {
        // The file is still being written to.
        m_LastWrittenTo = latestWrittenTo;
        m_LastWrittenSize = latestWrittenSize;
        QTimer::singleShot(WAIT_FOR_WRITE_DELAY, this, SLOT(ResourceFileModified()));
    } else {
        if (LoadFromDisk()) {
            // will trigger marking the book as modified
            emit ResourceUpdatedFromDisk(this);
        }

        // will trigger updates in other resources that link to this resource
        emit ResourceUpdatedOnDisk();
    }
}
示例#2
0
void StateCache::Reload()
{
  m_small_pso_map.clear();

  s_pso_disk_cache.Sync();
  s_pso_disk_cache.Close();
  LoadFromDisk();
}
示例#3
0
void StateCache::Init()
{
  if (!s_gx_state_cache.m_enable_disk_cache)
  {
    return;
  }

  LoadFromDisk();
}
示例#4
0
/*****************************************************************************
 * FUNCTION - LoadFromFlash
 * DESCRIPTION: Returns true on success
 ****************************************************************************/
bool FlashBlock::LoadFromFlash(void)
{
  bool success = false;

#ifndef __PC__
  FlashControl* pFlashControl = FlashControl::GetInstance();
  FLASH_BLOCK_HEADER_TYPE header;

  // flash block valid?
  if (pFlashControl->IsBlockValid(mFlashControlBlockId))
  {
    // read header
    if (pFlashControl->ReadData((U8*)&header, 0, FLASH_BLOCK_HEADER_SIZE, mFlashControlBlockId))
    {
      // validate and set header
      if (ValidateAndSetBlockHeader(&header))
      {
        int count = mpBlockHdr->blockSize - FLASH_BLOCK_HEADER_SIZE;

        // flash is 16-bit - adjust to 2-byte boundary if necessary
        if ((count % 2) != 0)
        {
          count++;
        }

        // read data
        if (pFlashControl->ReadData(mpBlockData, FLASH_BLOCK_HEADER_SIZE, count, mFlashControlBlockId))
        {
          // validate block data
  				if (ValidateBlockData())
  				{
            // success so far, load all subjects
  					success = LoadAllSubjectsFromCache();
  				}
        }
      }
    }
  }
#else
  success = LoadFromDisk();
#endif

	// always save all subjects to cache after loaf to ensure proper organisation of the flash block
  SaveAllSubjectsToCache();

  // set / reset error flag
  if (success)
  {
    mErrorFlags &= ~ERROR_FLAG_LOAD_FROM_FLASH_FAILED;
  }
  else
  {
    mErrorFlags |= ERROR_FLAG_LOAD_FROM_FLASH_FAILED;
  }

  return success;
}
示例#5
0
//-------------------------------------------------------------------------------------------------
NiNodePtr sdNifResourcePool::LoadNifFile(const std::string& kFileName, EResUsageType eUsageType, NiStream* spStream)
{
	NiNodePtr spNifInstance = 0;

	m_kLock.Lock();
	spNifInstance = m_kCacheNifMap[kFileName].m_spRootNode;
	if (!spNifInstance)
	{
		m_kLock.Unlock();

		// 从磁盘加载资源
		spNifInstance = LoadFromDisk(kFileName, eUsageType, spStream);

		// 将资源加入缓存
		m_kLock.Lock();
		CacheNifInfo kCacheNifInfo;
		kCacheNifInfo.m_iCloneCount = 0;
		kCacheNifInfo.m_bKFMRoot = (eUsageType == E_RES_USAGE_NIF_KFMROOT);
		kCacheNifInfo.m_spRootNode = spNifInstance;
		m_kCacheNifMap[kFileName] = kCacheNifInfo;
	}

	CacheNifInfo& kCacheNifInfo = m_kCacheNifMap[kFileName];
	kCacheNifInfo.m_iCloneCount++;

	NiNodePtr spRootNode = 0;
	if (spNifInstance)
	{
		spRootNode = (NiNode*)spNifInstance->Clone(m_kCloingProcess);

		// Remove all cloned instance
		m_kCloingProcess.m_pkProcessMap->RemoveAll();
		m_kCloingProcess.m_pkCloneMap->RemoveAll();
	}
	
	m_kLock.Unlock();

	return spRootNode;
}
示例#6
0
cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
	: super(etPlayer, 0.6, 1.8)
	, m_bVisible(true)
	, m_FoodLevel(MAX_FOOD_LEVEL)
	, m_FoodSaturationLevel(5)
	, m_FoodTickTimer(0)
	, m_FoodExhaustionLevel(0)
	, m_FoodPoisonedTicksRemaining(0)
	, m_LastJumpHeight(0)
	, m_LastGroundHeight(0)
	, m_bTouchGround(false)
	, m_Stance(0.0)
	, m_Inventory(*this)
	, m_CurrentWindow(NULL)
	, m_InventoryWindow(NULL)
	, m_Color('-')
	, m_GameMode(eGameMode_NotSet)
	, m_IP("")
	, m_ClientHandle(a_Client)
	, m_NormalMaxSpeed(1.0)
	, m_SprintingMaxSpeed(1.3)
	, m_FlyingMaxSpeed(1.0)
	, m_IsCrouched(false)
	, m_IsSprinting(false)
	, m_IsFlying(false)
	, m_IsSwimming(false)
	, m_IsSubmerged(false)
	, m_IsFishing(false)
	, m_CanFly(false)
	, m_EatingFinishTick(-1)
	, m_LifetimeTotalXp(0)
	, m_CurrentXp(0)
	, m_bDirtyExperience(false)
	, m_IsChargingBow(false)
	, m_BowCharge(0)
	, m_FloaterID(-1)
	, m_Team(NULL)
{
	LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d", 
		a_PlayerName.c_str(), a_Client->GetIPString().c_str(),
		this, GetUniqueID()
	);
	
	m_InventoryWindow = new cInventoryWindow(*this);
	m_CurrentWindow = m_InventoryWindow;
	m_InventoryWindow->OpenedByPlayer(*this);

	SetMaxHealth(MAX_HEALTH);
	m_Health = MAX_HEALTH;
	
	cTimer t1;
	m_LastPlayerListTime = t1.GetNowTime();
	
	m_PlayerName = a_PlayerName;

	if (!LoadFromDisk())
	{
		m_Inventory.Clear();
		cWorld * DefaultWorld = cRoot::Get()->GetDefaultWorld();
		SetPosX(DefaultWorld->GetSpawnX());
		SetPosY(DefaultWorld->GetSpawnY());
		SetPosZ(DefaultWorld->GetSpawnZ());
		
		LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}",
			a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
		);
	}

	m_LastJumpHeight = (float)(GetPosY());
	m_LastGroundHeight = (float)(GetPosY());
	m_Stance = GetPosY() + 1.62;

	if (m_GameMode == gmNotSet)
	{
		cWorld * World = cRoot::Get()->GetWorld(GetLoadedWorldName());
		if (World == NULL)
		{
			World = cRoot::Get()->GetDefaultWorld();
		}
		if (World->IsGameModeCreative())
		{
			m_CanFly = true;
		}
	}
	
	cRoot::Get()->GetServer()->PlayerCreated(this);
}
示例#7
0
cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
    : super(etPlayer, 0.6, 1.8)
    , m_GameMode(eGameMode_NotSet)
    , m_IP("")
    , m_LastBlockActionTime( 0 )
    , m_LastBlockActionCnt( 0 )
    , m_AirLevel( MAX_AIR_LEVEL )
    , m_AirTickTimer( DROWNING_TICKS )
    , m_bVisible( true )
    , m_LastGroundHeight( 0 )
    , m_bTouchGround( false )
    , m_Stance( 0.0 )
    , m_Inventory(*this)
    , m_CurrentWindow(NULL)
    , m_InventoryWindow(NULL)
    , m_TimeLastPickupCheck( 0.f )
    , m_Color('-')
    , m_ClientHandle( a_Client )
    , m_FoodLevel(MAX_FOOD_LEVEL)
    , m_FoodSaturationLevel(5)
    , m_FoodTickTimer(0)
    , m_FoodExhaustionLevel(0)
    , m_FoodPoisonedTicksRemaining(0)
    , m_NormalMaxSpeed(0.1)
    , m_SprintingMaxSpeed(0.13)
    , m_IsCrouched(false)
    , m_IsSprinting(false)
    , m_IsSwimming(false)
    , m_IsSubmerged(false)
    , m_EatingFinishTick(-1)
    , m_IsChargingBow(false)
    , m_BowCharge(0)
    , m_CurrentXp(0)
    , m_LifetimeTotalXp(0)
    , m_bDirtyExperience(false)
{
    LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d",
         a_PlayerName.c_str(), a_Client->GetIPString().c_str(),
         this, GetUniqueID()
        );

    m_InventoryWindow = new cInventoryWindow(*this);
    m_CurrentWindow = m_InventoryWindow;
    m_InventoryWindow->OpenedByPlayer(*this);

    SetMaxHealth(MAX_HEALTH);
    m_Health = MAX_HEALTH;

    cTimer t1;
    m_LastPlayerListTime = t1.GetNowTime();

    m_TimeLastTeleportPacket = 0;
    m_TimeLastPickupCheck = 0;

    m_PlayerName = a_PlayerName;
    m_bDirtyPosition = true; // So chunks are streamed to player at spawn

    if (!LoadFromDisk())
    {
        m_Inventory.Clear();
        SetPosX(cRoot::Get()->GetDefaultWorld()->GetSpawnX());
        SetPosY(cRoot::Get()->GetDefaultWorld()->GetSpawnY());
        SetPosZ(cRoot::Get()->GetDefaultWorld()->GetSpawnZ());

        LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}",
             a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
            );
    }
    m_LastJumpHeight = (float)(GetPosY());
    m_LastGroundHeight = (float)(GetPosY());
    m_Stance = GetPosY() + 1.62;

    cRoot::Get()->GetServer()->PlayerCreated(this);
}
示例#8
0
cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) :
	super(etPlayer, 0.6, 1.8),
	m_bVisible(true),
	m_FoodLevel(MAX_FOOD_LEVEL),
	m_FoodSaturationLevel(5.0),
	m_FoodTickTimer(0),
	m_FoodExhaustionLevel(0.0),
	m_LastJumpHeight(0),
	m_LastGroundHeight(0),
	m_bTouchGround(false),
	m_Stance(0.0),
	m_Inventory(*this),
	m_EnderChestContents(9, 3),
	m_CurrentWindow(NULL),
	m_InventoryWindow(NULL),
	m_GameMode(eGameMode_NotSet),
	m_IP(""),
	m_ClientHandle(a_Client),
	m_NormalMaxSpeed(1.0),
	m_SprintingMaxSpeed(1.3),
	m_FlyingMaxSpeed(1.0),
	m_IsCrouched(false),
	m_IsSprinting(false),
	m_IsFlying(false),
	m_IsSwimming(false),
	m_IsSubmerged(false),
	m_IsFishing(false),
	m_CanFly(false),
	m_EatingFinishTick(-1),
	m_LifetimeTotalXp(0),
	m_CurrentXp(0),
	m_bDirtyExperience(false),
	m_IsChargingBow(false),
	m_BowCharge(0),
	m_FloaterID(-1),
	m_Team(NULL),
	m_TicksUntilNextSave(PLAYER_INVENTORY_SAVE_INTERVAL),
	m_bIsTeleporting(false),
	m_UUID((a_Client != NULL) ? a_Client->GetUUID() : "")
{
	m_InventoryWindow = new cInventoryWindow(*this);
	m_CurrentWindow = m_InventoryWindow;
	m_InventoryWindow->OpenedByPlayer(*this);

	SetMaxHealth(MAX_HEALTH);
	m_Health = MAX_HEALTH;
	
	cTimer t1;
	m_LastPlayerListTime = t1.GetNowTime();
	
	m_PlayerName = a_PlayerName;

	cWorld * World = NULL;
	if (!LoadFromDisk(World))
	{
		m_Inventory.Clear();
		SetPosX(World->GetSpawnX());
		SetPosY(World->GetSpawnY());
		SetPosZ(World->GetSpawnZ());
		SetBedPos(Vector3i((int)World->GetSpawnX(), (int)World->GetSpawnY(), (int)World->GetSpawnZ()));
		
		LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}",
			a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
		);
	}

	m_LastJumpHeight = (float)(GetPosY());
	m_LastGroundHeight = (float)(GetPosY());
	m_Stance = GetPosY() + 1.62;

	if (m_GameMode == gmNotSet)
	{
		if (World->IsGameModeCreative())
		{
			m_CanFly = true;
		}
	}
	
	cRoot::Get()->GetServer()->PlayerCreated(this);
}
示例#9
0
//-------------------------------------------------------------------------------------------------
NiActorManagerPtr sdKfmResourcePool::LoadKfmFile(const std::string& kFileName, EResUsageType eUsageType, bool bReleaseOnGC /* = true */, bool bMainThreadLoad /* = false */)
{
	NiActorManagerPtr spActorMgrInstance = 0;

	m_kLock.Lock();
	spActorMgrInstance = m_kCacheKfmInfoMap[kFileName].m_spActorMgr;
	if (!spActorMgrInstance)
	{
		m_kLock.Unlock();

		// 从磁盘加载资源
		spActorMgrInstance = LoadFromDisk(kFileName, bMainThreadLoad);

		// 将资源加入缓存
		m_kLock.Lock();
		CacheKfmInfo kCacheKfmInfo;
		kCacheKfmInfo.m_iCloneCount = 0;
		kCacheKfmInfo.m_bReleaseOnGC = bReleaseOnGC;
		kCacheKfmInfo.m_spActorMgr = spActorMgrInstance;
		m_kCacheKfmInfoMap[kFileName] = kCacheKfmInfo;
	}

	CacheKfmInfo& kCacheKfmInfo = m_kCacheKfmInfoMap[kFileName];
	kCacheKfmInfo.m_iCloneCount++;

	NiActorManagerPtr spActorMgr = 0;
	if (spActorMgrInstance)
	{
		//// 根据Usage类型决定追加文本
		//BYTE byAppend = 0;
		//switch(eUsageType)
		//{
		//case E_RES_USAGE_KFM_COMMON:
		//	byAppend = TEXT_KEY_NONE;
		//	break;
		//case E_RES_USAGE_KFM_SELF:
		//	byAppend = TEXT_KEY_SELF;
		//	break;
		//case E_RES_USAGE_KFM_PLAYER:
		//	byAppend = TEXT_KEY_PLAYER;
		//	break;
		//case E_RES_USAGE_KFM_NPC:
		//	byAppend = TEXT_KEY_NPC;
		//	break;
		//default:
		//	byAppend = TEXT_KEY_ALL;
		//}
		//
		//m_kCloingProcess.m_cAppendChar = GetTypeFromUsage(eUsageType);

		// 克隆
		spActorMgr = (NiActorManager*)spActorMgrInstance->Clone(&m_kCloingProcess);

		// Remove all cloned instance
		m_kCloingProcess.m_pkProcessMap->RemoveAll();
		m_kCloingProcess.m_pkCloneMap->RemoveAll();
	}

	m_kLock.Unlock();

	return spActorMgr;
}