示例#1
0
CMainFrame::~CMainFrame()
{
	delete m_pBitmap;

	ReleaseNodes(m_pLive);
	ReleaseNodes(m_pDie);
	ReleaseNodes(m_pNextLive);
	ReleaseNodes(m_pNextDie);

	delete m_pLive;
	delete m_pDie;
	delete m_pNextLive;
	delete m_pNextDie;
}
示例#2
0
void CMainFrame::TransferList (CPtrList** pDestList, CPtrList** pSrcList)
{
	ReleaseNodes(*pDestList);
	CPtrList *pTempList = *pDestList;
	*pDestList = *pSrcList;
	*pSrcList = pTempList;
}
示例#3
0
void CMainFrame::CreateLists()
{
	int c,r;
	CPoint* pCell;

	ReleaseNodes(m_pLive);
	ReleaseNodes(m_pDie);
	ReleaseNodes(m_pNextLive);
	ReleaseNodes(m_pNextDie);

	// Suzdaveme nov spisuk s jivi kletki...
	for (c=0;c<NUMBEROFCOLS;++c)
		for(r=0;r<NUMBEROFROWS;++r)
		{
			m_nbrs[r][c]=0;
			if (m_world[r][c]==ALIVE)
			{
				pCell=new CPoint(c,r);
				m_pLive->AddTail (pCell);
			}
		}

		// Izchisliavame broia na susedite na tekushtata...
		AddNbrs();

		for (c=0;c<NUMBEROFCOLS;++c)
		{
			for(r=0;r<NUMBEROFROWS;++r)
			{
				if(((m_nbrs[r][c]<2)||(m_nbrs[r][c]>3)) && (m_world[r][c]==ALIVE) )
				{
					pCell=new CPoint(c,r);
					m_pNextDie->AddTail (pCell);
				}
			}
		}

		TransferList(&m_pLive,&m_pNextLive);
		TransferList(&m_pDie,&m_pNextDie);
}
bool CGoldminenodeSync::IsBlockchainSynced(bool fBlockAccepted)
{
    static bool fBlockchainSynced = false;
    static int64_t nTimeLastProcess = GetTime();
    static int nSkipped = 0;
    static bool fFirstBlockAccepted = false;

    // if the last call to this function was more than 60 minutes ago (client was in sleep mode) reset the sync process
    if(GetTime() - nTimeLastProcess > 60*60) {
        Reset();
        fBlockchainSynced = false;
    }

    if(!pCurrentBlockIndex || !pindexBestHeader || fImporting || fReindex) return false;

    if(fBlockAccepted) {
        // this should be only triggered while we are still syncing
        if(!IsSynced()) {
            // we are trying to download smth, reset blockchain sync status
            if(fDebug) LogPrintf("CGoldminenodeSync::IsBlockchainSynced -- reset\n");
            fFirstBlockAccepted = true;
            fBlockchainSynced = false;
            nTimeLastProcess = GetTime();
            return false;
        }
    } else {
        // skip if we already checked less than 1 tick ago
        if(GetTime() - nTimeLastProcess < GOLDMINENODE_SYNC_TICK_SECONDS) {
            nSkipped++;
            return fBlockchainSynced;
        }
    }

    if(fDebug) LogPrintf("CGoldminenodeSync::IsBlockchainSynced -- state before check: %ssynced, skipped %d times\n", fBlockchainSynced ? "" : "not ", nSkipped);

    nTimeLastProcess = GetTime();
    nSkipped = 0;

    if(fBlockchainSynced) return true;

    if(fCheckpointsEnabled && pCurrentBlockIndex->nHeight < Checkpoints::GetTotalBlocksEstimate(Params().Checkpoints()))
        return false;

    std::vector<CNode*> vNodesCopy;
    {
        LOCK(cs_vNodes);
        vNodesCopy = vNodes;
        BOOST_FOREACH(CNode* pnode, vNodesCopy)
            pnode->AddRef();
    }

    // We have enough peers and assume most of them are synced
    if(vNodes.size() >= GOLDMINENODE_SYNC_ENOUGH_PEERS) {
        // Check to see how many of our peers are (almost) at the same height as we are
        int nNodesAtSameHeight = 0;
        BOOST_FOREACH(CNode* pnode, vNodesCopy)
        {
            // Make sure this peer is presumably at the same height
            if(!CheckNodeHeight(pnode)) continue;
            nNodesAtSameHeight++;
            // if we have decent number of such peers, most likely we are synced now
            if(nNodesAtSameHeight >= GOLDMINENODE_SYNC_ENOUGH_PEERS) {
                LogPrintf("CGoldminenodeSync::IsBlockchainSynced -- found enough peers on the same height as we are, done\n");
                fBlockchainSynced = true;
                ReleaseNodes(vNodesCopy);
                return true;
            }
        }
    }