Exemplo n.º 1
0
bool CommonScheduleThread::run()
{
    Log.Success("CommonScheduleThread", "Started.");
    m_busy = false;

    if(sWorld.BCSystemEnable && sWorld.BCOrderMode == 1)
        itOrderMSGEntry = objmgr.GetBCTotalItemBegin();
    // cebernic nothing in storage
    if(objmgr.IsBCEntryStorageEmpty()) sWorld.BCSystemEnable = 0;

    BCTimerCount = getMSTime() + ((uint32)sWorld.BCInterval * 1000);

    while(GetThreadState() != THREADSTATE_TERMINATE)
    {
        m_busy = true;
        // do job -------------------
        BroadCastExec();
        // -----------------------
        m_busy = false;
        if(GetThreadState() == THREADSTATE_TERMINATE)
            break;

        cond.Wait(THREAD_LOOP_INTERVAL * 1000);

        if(!m_running)
            break;
    }

    return true;
}
void CBSPLightingThread::Interrupt()
{
	if( GetThreadState() == STATE_LIGHTING )
	{
		m_pVRadDLL->Interrupt();
		
		while( GetThreadState() == STATE_LIGHTING )		
			Sleep( 10 );
	}
}
Exemplo n.º 3
0
void Database::thread_proc_query()
{
	QueryBuffer* q;
	DatabaseConnection* con = GetFreeConnection();

	q = query_buffer.pop();
	while(1)
	{
		if(q != NULL)
		{
			PerformQueryBuffer(q, con);
			delete q;
		}

		if(GetThreadState() == THREADSTATE_TERMINATE)
			break;

		q = query_buffer.pop();
		if(q == NULL)
			arcpro::Sleep(10);
	}

	con->Busy.Release();

	// kill any queries
	q = query_buffer.pop();
	while(q != NULL)
	{
		PerformQueryBuffer(q, NULL);
		delete q;

		q = query_buffer.pop();
	}
}
Exemplo n.º 4
0
bool Thread::Start(ThreadState initialState)
{
    if (initialState == NotRunning)
        return 0;
    if (GetThreadState() != NotRunning)
    {
        OVR_DEBUG_LOG(("Thread::Start failed - thread %p already running", this));
        return 0;
    }

    // Free old thread handle before creating the new one
    CleanupSystemThread();

    ExitCode        = NULL;
    ThreadFlags     = (initialState == Running) ? OVR_THREAD_STARTED : OVR_THREAD_START_SUSPENDED;
    ThreadHandle = (HANDLE) _beginthreadex(0, (unsigned)StackSize,
                                           Thread_Win32StartFn, this, 0, (unsigned*)&IdValue);

    // Failed? Fail the function
    if (ThreadHandle == 0)
    {
        ThreadFlags = 0;
        return 0;
    }
    return 1;
}
Exemplo n.º 5
0
int OCThreadBase::WaitUntilThreadDestroy()
{
	//float fBeginTime = time();
	//DWORD dwElapsedTime;
	while(true)
	{
		int iThreadState = GetThreadState();

		if(iThreadState == THREAD_STATE_END)
		{			
			return iThreadState;
		}
		else
		{
			// wait
			//dwElapsedTime = time() - dwBeginTime;
			//if(dwElapsedTime > 10000)
			//{
			//	assert(0);
			//	return iThreadState;
			//}
		}
	}

	return THREAD_STATE_PROBLEM;
}
Exemplo n.º 6
0
//+---------------------------------------------------------------------------
//
//  Function:   InitScrollbarTiming
//
//  Synopsis:   Get scrollbar's timing info into a thread local storage
//              scrollTimeInfo structure
//
//----------------------------------------------------------------------------
void InitScrollbarTiming()
{
    THREADSTATE* pts = GetThreadState();

    Assert(pts);
    Assert(pts->pSBC);

	pts->scrollTimeInfo.lRepeatDelay = pts->pSBC->GetRepeatDelay();
	pts->scrollTimeInfo.lRepeatRate = pts->pSBC->GetRepeatRate();
	pts->scrollTimeInfo.lFocusRate = pts->pSBC->GetFocusRate();
}
Exemplo n.º 7
0
bool GameEventMgr::GameEventMgrThread::run()
{
    Log.Success("GameEventMgr", "Started.");

    // Do NOT uncomment this unless you know what you're doing, debug code
    //CleanupEntities();

    SpawnActiveEvents();

    THREAD_TRY_EXECUTION

    while (GetThreadState() != THREADSTATE_TERMINATE)
    {
        while (GetThreadState() == THREADSTATE_PAUSED)
        {
            m_IsActive = false;
            Arcemu::Sleep(200);
        }

        m_IsActive = true;

        if (GetThreadState() == THREADSTATE_TERMINATE)
            break;

        ThreadState.SetVal(THREADSTATE_BUSY);
        Update();

        if (GetThreadState() == THREADSTATE_TERMINATE)
            break;

        ThreadState.SetVal(THREADSTATE_SLEEPING);
        Arcemu::Sleep(1 * 1000); // 1 second
    }

    THREAD_HANDLE_CRASH
        return true;
}
Exemplo n.º 8
0
bool DayWatcherThread::run()
{
    Log.Success("DayWatcherThread", "Started.");
    currenttime = UNIXTIME;
    dupe_tm_pointer(localtime(&currenttime), &local_currenttime);
    load_settings();
    set_tm_pointers();
    m_busy = false;

    while (GetThreadState() != THREADSTATE_TERMINATE)
    {
        m_busy = true;
        currenttime = UNIXTIME;
        dupe_tm_pointer(localtime(&currenttime), &local_currenttime);

        if (has_timeout_expired(&local_currenttime, &local_last_arena_time, arena_period))
            update_arena();

        if (has_timeout_expired(&local_currenttime, &local_last_daily_time, daily_period))
            update_daily();

        if (m_dirty)
            update_settings();

        m_busy = false;
        if (GetThreadState() == THREADSTATE_TERMINATE)
            break;

        cond.Wait(THREAD_LOOP_INTERVAL * 1000);

        if (!m_running)
            break;
    }

    return true;
}
Exemplo n.º 9
0
bool Database::run()
{
	SetThreadName("Database Execute Thread");
	SetThreadState(THREADSTATE_BUSY);
	ThreadRunning = true;
	char* query = queries_queue.pop();
	DatabaseConnection* con = GetFreeConnection();
	while(1)
	{

		if(query != NULL)
		{
			if(con == NULL)
				con = GetFreeConnection();
			_SendQuery(con, query, false);
			delete[] query;
		}

		if(GetThreadState() == THREADSTATE_TERMINATE)
			break;
		query = queries_queue.pop();

		if(query == NULL)
		{
			if(con != NULL)
				con->Busy.Release();
			con = NULL;
			arcpro::Sleep(10);
		}
	}

	if(con != NULL)
		con->Busy.Release();

	// execute all the remaining queries
	query = queries_queue.pop();
	while(query)
	{
		con = GetFreeConnection();
		_SendQuery(con, query, false);
		con->Busy.Release();
		delete[] query;
		query = queries_queue.pop();
	}

	ThreadRunning = false;
	return false;
}
Exemplo n.º 10
0
bool Lacrimi::run()
{
    Delay(400);
    if(GetConfigBool("Features", "LuaEngine", true))
    {
        L_LuaEngineMgr = new LuaEngineMgr();
        L_LuaEngineMgr->Startup();
        Delay(100);
        while(LuaEngineIsStarting)
            Delay(100);
    }

    uint32 curTime = getMSTime();
    uint32 m_StatDumpTimer = curTime+15000, m_CleanupDelay = curTime+10000;
    while(GetThreadState() != THREADSTATE_SELF_TERMINATE)
    {
        curTime = getMSTime();
        if(!SetThreadState(THREADSTATE_BUSY))
            break;

        if(dumpstats)
        {
            if(curTime > m_StatDumpTimer)
            {
                DumpStats();
                m_StatDumpTimer = curTime+60000;
            }
        }

        if(curTime > m_CleanupDelay)
            Cleanup();
        if(!SetThreadState(THREADSTATE_SLEEPING))
            break;
        Delay(5);
    }
    sLog.Notice("Lacrimi", "Terminating...");

    FinalCleanup();
    if(database)
        _StopDB();
    OnShutdown();
    return true;
}
Exemplo n.º 11
0
HRESULT CTxtSlave::ComputeFormats(CFormatInfo* pCFI, CTreeNode* pNodeTarget)
{
    HRESULT         hr = S_OK;
    CTreeNode*      pNodeMaster = NULL;
    CElement*       pElemMaster = MarkupMaster();
    CDocument*      pDoc = Doc();
    THREADSTATE*    pts  = GetThreadState();
    BOOL            fComputeFFOnly = pNodeTarget->_iCF != -1;
    COMPUTEFORMATSTYPE eExtraValues = pCFI->_eExtraValues;

    Assert(pCFI);
    Assert(SameScope(this, pNodeTarget));
    Assert(eExtraValues!=ComputeFormatsType_Normal || ((pNodeTarget->_iCF==-1 && pNodeTarget->_iPF==-1) || pNodeTarget->_iFF==-1));

    if(pElemMaster)
    {
        pNodeMaster = pElemMaster->GetFirstBranch();

        // Get the format of our master before applying our own format.
        if(pNodeMaster)
        {
            // If the master node has not computed formats yet, recursively compute them
            if(pNodeMaster->_iCF==-1 || pNodeMaster->_iFF==-1
                || eExtraValues==ComputeFormatsType_GetInheritedValue)
            {

                hr = pElemMaster->ComputeFormats(pCFI, pNodeMaster);

                if(hr)
                {
                    goto Cleanup;
                }
            }

            Assert(pNodeMaster->_iCF >= 0);
            Assert(pNodeMaster->_iPF >= 0);
            Assert(pNodeMaster->_iFF >= 0);
        }
    }

    // NOTE: From this point forward any errors must goto Error instead of Cleanup!
    pCFI->Reset();
    pCFI->_pNodeContext = pNodeTarget;

    if(pNodeMaster)
    {
        // Inherit para format directly from the master node.
        pCFI->_iffSrc = pNodeMaster->_iFF;
        pCFI->_pffSrc = pCFI->_pff = &(*pts->_pFancyFormatCache)[pCFI->_iffSrc];
        pCFI->_fHasExpandos = (pCFI->_pff->_iExpandos >= 0);

        if(!fComputeFFOnly)
        {
            // Inherit the Char and Para formats from the master node
            pCFI->_icfSrc = pNodeMaster->_iCF;
            pCFI->_pcfSrc = pCFI->_pcf = &(*pts->_pCharFormatCache)[pCFI->_icfSrc];
            pCFI->_ipfSrc = pNodeMaster->_iPF;
            pCFI->_ppfSrc = pCFI->_ppf = &(*pts->_pParaFormatCache)[pCFI->_ipfSrc];

            // If the parent had layoutness, clear the inner formats
            if(pCFI->_pcf->_fHasDirtyInnerFormats)
            {
                pCFI->PrepareCharFormat();
                pCFI->_cf().ClearInnerFormats();
                pCFI->UnprepareForDebug();
            }
            if(pCFI->_ppf->_fHasDirtyInnerFormats)
            {
                pCFI->PrepareParaFormat();
                pCFI->_pf().ClearInnerFormats();
                pCFI->UnprepareForDebug();
            }
            if(pCFI->_ppf->_fPre != pCFI->_ppf->_fPreInner
                || pCFI->_ppf->_fInclEOLWhite != pCFI->_ppf->_fInclEOLWhiteInner
                || pCFI->_ppf->_bBlockAlign != pCFI->_ppf->_bBlockAlignInner)
            {
                pCFI->PrepareParaFormat();
                pCFI->_pf()._fPre = pCFI->_pf()._fPreInner;
                pCFI->_pf()._fInclEOLWhite = pCFI->_pf()._fInclEOLWhiteInner;
                pCFI->_pf()._bBlockAlign = pCFI->_pf()._bBlockAlignInner;
                pCFI->UnprepareForDebug();
            }

            if(pCFI->_pcf->_fNoBreak != pCFI->_pcf->_fNoBreakInner)
            {
                pCFI->PrepareCharFormat();
                pCFI->_cf()._fNoBreak = pCFI->_cf()._fNoBreakInner;
                pCFI->UnprepareForDebug();
            }
        }
        else
        {
            pCFI->_icfSrc = pDoc->_icfDefault;
            pCFI->_pcfSrc = pCFI->_pcf = pDoc->_pcfDefault;
            pCFI->_ipfSrc = pts->_ipfDefault;
            pCFI->_ppfSrc = pCFI->_ppf = pts->_ppfDefault;
        }
    }
    else
    {
        pCFI->_iffSrc = pts->_iffDefault;
        pCFI->_pffSrc = pCFI->_pff = pts->_pffDefault;
        pCFI->_icfSrc = pDoc->_icfDefault;
        pCFI->_pcfSrc = pCFI->_pcf = pDoc->_pcfDefault;
        pCFI->_ipfSrc = pts->_ipfDefault;
        pCFI->_ppfSrc = pCFI->_ppf = pts->_ppfDefault;

        Assert(pCFI->_pffSrc->_pszFilters == NULL);
    }

    if(pCFI->_pff->_fHasLayout || !pCFI->_pff->_fBlockNess)
    {
        pCFI->PrepareFancyFormat();
        pCFI->_ff()._fHasLayout = FALSE;
        pCFI->_ff()._fBlockNess = TRUE;
        pCFI->UnprepareForDebug();
    }

    if(eExtraValues == ComputeFormatsType_Normal)
    {
        hr = pNodeTarget->CacheNewFormats(pCFI);
        if(hr)
        {
            goto Error;
        }

        // Cache whether an element is a block element or not for fast retrieval.
        pNodeTarget->_fBlockNess = TRUE;

        pNodeTarget->_fHasLayout = FALSE;
    }

Cleanup:
    RRETURN(hr);

Error:
    pCFI->Cleanup();
    goto Cleanup;
}
Exemplo n.º 12
0
// Draw the src rect of the specified image into the dest rect of the hdc
void CImgBitsDIB::StretchBlt(HDC hdc, RECT* prcDst, RECT* prcSrc, DWORD dwRop, DWORD dwFlags)
{
    HDC         hdcDib          = NULL;
    HBITMAP     hbmSav          = NULL;
    int         xDst            = prcDst->left;
    int         yDst            = prcDst->top;
    int         xDstWid         = prcDst->right - xDst;
    int         yDstHei         = prcDst->bottom - yDst;
    int         xSrc            = prcSrc->left;
    int         ySrc            = prcSrc->top;
    int         xSrcWid         = prcSrc->right - xSrc;
    int         ySrcHei         = prcSrc->bottom - ySrc;
    int         yUseHei         = _yHeight;

    // Cases in which there is nothing to draw
    if((!_pvImgBits && !_pvMaskBits && !_fSolid) || _yHeightValid==0)
    {
        return;
    }

    if(xDstWid<=0 || xSrcWid<=0 || _xWidth<=0 || yDstHei<=0 || ySrcHei<=0 || _yHeight<=0)
    {
        return;
    }

    if(dwRop!=SRCCOPY && (_pvMaskBits || _iTrans>=0))
    {
        return;
    }

    // Step 1: Limit the source and dest rectangles to the visible area only.
    if(_yHeightValid>0 && _yHeightValid<_yHeight)
    {
        yUseHei = _yHeightValid;
    }

    if(xSrc < 0)
    {
        xDst += MulDivQuick(-xSrc, xDstWid, xSrcWid);
        xDstWid = prcDst->right - xDst;
        xSrcWid += xSrc;
        xSrc = 0;        
        if(xDstWid<=0 || xSrcWid<=0)
        {
            return;
        }
    }
    if(ySrc < 0)
    {
        yDst += MulDivQuick(-ySrc, yDstHei, ySrcHei);
        yDstHei = prcDst->bottom - yDst;
        ySrcHei += ySrc;
        ySrc = 0;
        if(yDstHei<=0 || ySrcHei<=0)
        {
            return;
        }
    }
    if(xSrc+xSrcWid > _xWidth)
    {
        xDstWid = MulDivQuick(xDstWid, _xWidth-xSrc, xSrcWid);
        xSrcWid = _xWidth - xSrc;
        if(xDstWid<=0 || xSrcWid<=0)
        {
            return;
        }
    }
    if(ySrc+ySrcHei > yUseHei)
    {
        yDstHei = MulDivQuick(yDstHei, yUseHei-ySrc, ySrcHei);
        ySrcHei = yUseHei - ySrc;
        if(yDstHei<=0 || ySrcHei<=0)
        {
            return;
        }
    }
    // For the mirrored case, we need flip then offset.
    if(_fNeedMirroring)
    {
        // We need to handle clipping correctly and give a right-to-left tiling effect.
        // Let's take the "opposite" slice of the source.
        // The maximum will be the whole image.
        xSrc = - xSrc +_xWidth - xSrcWid;
        xDst += xDstWid - 1;
        xDstWid = - xDstWid;

    }    
    // Optimization: if solid, just patblt the color
    if(_fSolid)
    {
        // Turn on the palette relative bit for palettized devices in order to ensure that dithering
        // doesn't happen here.  The main reason is that is looks ugly, but more importantly we aren't
        // prepared to seam multiple copies of the image so that the dithering looks smooth.
        PatBltBrush(hdc, xDst, yDst, xDstWid, yDstHei, PATCOPY, _crSolid|g_crPaletteRelative);
        return;
    }

    SetStretchBltMode(hdc, COLORONCOLOR);

    // Step 2: For tranparent images, use mask to whiten drawing area
    if(_pvMaskBits || _iTrans>=0)
    {
        if(dwFlags & DRAWIMAGE_NOTRANS)
        {
            goto NoTransparency;
        }

        if(GetDeviceCaps(hdc, TECHNOLOGY) == DT_RASPRINTER)
        {
            // No transparency for printers that we know lie about their support for transparency.
            int iEscapeFunction = POSTSCRIPT_PASSTHROUGH;
            THREADSTATE* pts = GetThreadState();

            if(Escape(hdc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&iEscapeFunction, NULL))
            {
                // Skip transparency unless we are a mask-only image
                if(_pvImgBits || !_pvMaskBits)
                {
                    goto NoTransparency;
                }
            }
        }

        if(_pvMaskBits)
        {
            // 1-bit mask case
            if(_hbmMask)
            {
                // We have an HBITMAP, not just bits
                Assert(!hdcDib && !hbmSav);

                hdcDib = GetMemoryDC();
                if(!hdcDib)
                {
                    goto Cleanup;
                }

                // Special case: use MaskBlt for the whole thing on NT
                if(xSrcWid==xDstWid && ySrcHei==yDstHei && _hbmImg)
                {
                    hbmSav = (HBITMAP)SelectObject(hdcDib, _hbmImg);

                    MaskBlt(hdc, xDst, yDst, xDstWid, yDstHei,
                        hdcDib, xSrc, ySrc, _hbmMask, xSrc, ySrc, 0xAACC0020);

                    goto Cleanup;
                }

                hbmSav = (HBITMAP)SelectObject(hdcDib, _hbmMask);

                if(!_pvImgBits)
                {
                    // a mask-only one-bit image: just draw the "1" bits as black
                    ::StretchBlt(hdc, xDst, yDst, xDstWid, yDstHei,
                        hdcDib, xSrc, ySrc, xSrcWid, ySrcHei, MERGEPAINT);
                }
                else
                {
                    // transparent mask: draw the "1" bits as white
                    ::StretchBlt(hdc, xDst, yDst, xDstWid, yDstHei,
                        hdcDib, xSrc, ySrc, xSrcWid, ySrcHei, SRCPAINT);
                }
            }
            else
            {
                // We have just bits, not an HBITMAP
                struct
                {
                    BITMAPINFOHEADER bmih;
                    union
                    {
                        RGBQUAD rgb[2];
                        WORD    windex[2];
                    };
                } bmiMask;

                // construct mask header
                memset(&bmiMask, 0, sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*2);
                bmiMask.bmih.biSize = sizeof(BITMAPINFOHEADER);
                bmiMask.bmih.biWidth = _xWidth;
                bmiMask.bmih.biHeight = _yHeight;
                bmiMask.bmih.biPlanes = 1;
                bmiMask.bmih.biBitCount = 1;

                if(!_pvImgBits)
                {
                    // a mask-only one-bit image: just draw the "1" bits as black
                    bmiMask.rgb[0] = g_rgbWhite;
                    StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei,
                        xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvMaskBits, (BITMAPINFO*)&bmiMask, DIB_RGB_COLORS, SRCAND);
                }
                else if(_iBitCount<=8 && _fPalColors && !(dwFlags&DRAWIMAGE_NHPALETTE))
                {
                    // this setup only occurs on an 8-bit palettized display; we can use DIB_PAL_COLORS
                    bmiMask.windex[1] = 255;
                    StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei,
                        xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvMaskBits, (BITMAPINFO*)&bmiMask, DIB_PAL_COLORS, SRCPAINT);
                }
                else
                {
                    bmiMask.rgb[1] = g_rgbWhite;
                    StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei,
                        xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvMaskBits, (BITMAPINFO *)&bmiMask, DIB_RGB_COLORS, SRCPAINT);
                }
            }
        }
        else
        {
            // 1- 4- or 8-bit mask case (with _iTrans)
            long cTable = 1 << _iBitCount;

            Assert(_iTrans >= 0);
            Assert(_iTrans < cTable);
            Assert(_iBitCount <= 8);

            if(_hbmImg)
            {
                // We have an HBITMAP, not just bits
                RGBQUAD argbOld[256];
                RGBQUAD argbNew[256];

                memset(argbNew, 0, sizeof(RGBQUAD)*cTable);
                argbNew[_iTrans] = g_rgbWhite;

                Assert(!hdcDib && !hbmSav);

                hdcDib = GetMemoryDC();
                if(!hdcDib)
                {
                    goto Cleanup;
                }

                hbmSav = (HBITMAP)SelectObject(hdcDib, _hbmImg);

                // HBM case: we need to change the color table, which can only be done one-at-a time
                g_csImgTransBlt.Enter();

                Verify(GetDIBColorTable(hdcDib, 0, cTable, argbOld) > 0);
                Verify(SetDIBColorTable(hdcDib, 0, cTable, argbNew) == (unsigned)cTable);

                ::StretchBlt(hdc, xDst, yDst, xDstWid, yDstHei,
                    hdcDib, xSrc, ySrc, xSrcWid, ySrcHei, MERGEPAINT);

                Verify(SetDIBColorTable(hdcDib, 0, cTable, argbOld) == (unsigned)cTable);

                g_csImgTransBlt.Leave();
            }
            else
            {
                // We have just bits, not an HBITMAP
                struct
                {
                    BITMAPINFOHEADER bmih;
                    RGBQUAD          rgb[256];
                } bmiMask;

                // construct mask header
                memset(&bmiMask, 0, sizeof(BITMAPINFOHEADER)+(sizeof(RGBQUAD)*cTable));
                bmiMask.bmih.biSize = sizeof(BITMAPINFOHEADER);
                bmiMask.bmih.biWidth = _xWidth;
                bmiMask.bmih.biHeight = _yHeight;
                bmiMask.bmih.biPlanes = 1;
                bmiMask.bmih.biBitCount = _iBitCount;
                bmiMask.rgb[_iTrans] = g_rgbWhite;

                StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei,
                    xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvImgBits, (BITMAPINFO*)&bmiMask, DIB_RGB_COLORS, MERGEPAINT);
            }
        }

        // prepare for transparent blt: area to be painted is now whitened, so AND-blt on top of it
        dwRop = SRCAND;
    }

NoTransparency:
    // Step 3: Draw the image bits
    if(_pvImgBits)
    {
        if(dwFlags & DRAWIMAGE_MASKONLY)
        {
            goto Cleanup;
        }

        if(_hbmImg)
        {
            // The normal case (not to a Win95 printer): call StretchBlt
            if(!hdcDib)
            {
                hdcDib = GetMemoryDC();
                if(!hdcDib)
                {
                    goto Cleanup;
                }
            }

            HBITMAP hbmOld;

            hbmOld = (HBITMAP)SelectObject(hdcDib, _hbmImg);
            if(!hbmSav)
            {
                hbmSav = hbmOld;
            }

            ::StretchBlt(hdc, xDst, yDst, xDstWid, yDstHei, hdcDib, xSrc, ySrc, xSrcWid, ySrcHei, dwRop);
        }
        else
        {
            // We have just bits, not an HBITMAP
            if(!_pbmih)
            {
                // No color table header: cobble up a standard header [perhaps these should just be globally cached?]
                struct
                {
                    BITMAPINFOHEADER bmih;
                    union
                    {
                        WORD    windex[256];
                        RGBQUAD rgb[256];
                        DWORD   bfmask[3];
                    };
                } bmi;

                DWORD dwDibMode = DIB_RGB_COLORS;

                // construct mask header
                memset(&bmi, 0, sizeof(BITMAPINFOHEADER)+(_iBitCount>8?sizeof(DWORD)*3:sizeof(WORD)*(_iBitCount<<1)));
                bmi.bmih.biSize = sizeof(BITMAPINFOHEADER);
                bmi.bmih.biWidth = _xWidth;
                bmi.bmih.biHeight = _yHeight;
                bmi.bmih.biPlanes = 1;
                bmi.bmih.biBitCount = _iBitCount + (_iBitCount==15);

                if(_iBitCount == 4)
                {
                    // Thanks to Steve Palmer: fix VGA color rendering

                    bmi.bmih.biClrUsed = 16;
                    bmi.bmih.biClrImportant = 16;
                    CopyColorsFromPaletteEntries(bmi.rgb, g_peVga, 16);
                }
                else if(_iBitCount <= 8)
                {
                    if(dwFlags & DRAWIMAGE_NHPALETTE)
                    {
                        // If being drawn on an <= 8-bit surface from a filter, we can make no assumptions about
                        // the selected palette, so use RGB_COLORS
                        LONG c;

                        c = (1 << (_iBitCount-1));

                        memcpy(bmi.rgb, g_rgbHalftone, c*sizeof(RGBQUAD));
                        memcpy(bmi.rgb+c, g_rgbHalftone+256-c, c*sizeof(RGBQUAD));
                    }
                    else
                    {
                        // internal draw, no color table with _iBitCount <= 8 means that the palette selected into hdc
                        // is our standard 8-bit halftone palette and we can use DIB_PAL_COLORS
                        LONG c;
                        LONG d;
                        WORD* pwi;

                        dwDibMode = DIB_PAL_COLORS;

                        for(c=(1<<(_iBitCount-1)),pwi=bmi.windex+c; c; *(--pwi)=(--c));
                        for(c=(1<<(_iBitCount-1)),pwi=bmi.windex+c*2,d=256; c; --c,*(--pwi)=(--d));
                    }
                }
                else if(_iBitCount == 16)
                {
                    // sixteen-bit case: fill in the bitfields mask for 565
                    bmi.bmih.biCompression = BI_BITFIELDS;
                    bmi.bfmask[0] = MASK565_0;
                    bmi.bfmask[1] = MASK565_1;
                    bmi.bfmask[2] = MASK565_2;
                }

                StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei,
                    xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvImgBits, (BITMAPINFO*)&bmi, dwDibMode, dwRop);
            }
            else
            {
                StretchDIBits(hdc, xDst, yDst, xDstWid, yDstHei,
                    xSrc, _yHeight-ySrc-ySrcHei, xSrcWid, ySrcHei, _pvImgBits, (BITMAPINFO*)_pbmih, DIB_RGB_COLORS, dwRop);
            }
        }
    }

Cleanup:
    if(hbmSav)
    {
        SelectObject(hdcDib, hbmSav);
    }
    if(hdcDib)
    {
        ReleaseMemoryDC(hdcDib);
    }
}
int CBSPLightingThread::GetCurrentState()
{
	return GetThreadState();
}
Exemplo n.º 14
0
void fastPoll( void )
	{
	RANDOM_STATE randomState;
	BYTE buffer[ RANDOM_BUFSIZE + 8 ];
/*	BatteryTimeRec batteryTimeInfo; */
	SMStatus soundStatus;
	ThreadID threadID;
	ThreadState threadState;
	EventRecord eventRecord;
	Point point;
	WindowPtr windowPtr;
	PScrapStuff scrapInfo;
	UnsignedWide usSinceStartup;
	BYTE dataBuffer[ 2 + 8 ];
/*	short driverRefNum; */
	UInt32 dateTime;
/*	int count, dummy; */
	NumVersion version;

	initRandomData( randomState, buffer, RANDOM_BUFSIZE );

	/* Get the status of the last alert, how much battery time is remaining
	   and the voltage from all batteries, the internal battery status, the
	   current date and time and time since system startup in ticks, the
	   application heap limit and current and heap zone, free memory in the
	   current and system heap, microseconds since system startup, whether
	   QuickDraw has finished drawing, modem status, SCSI status
	   information, maximum block allocatable without compacting, available
	   stack space, the last QuickDraw error code */
/*	addRandomValue( randomState, GetAlertStage() );
	count = BatteryCount();
	while( count-- > 0 )
		{
		addRandomValue( randomState,
				   GetBatteryVoltage( count ) );
		GetBatteryTimes( count, &batteryTimeInfo );
		addRandomData( randomState, &batteryTimeInfo,
					   sizeof( BatteryTimeRec ) );
		}
	if( !BatteryStatus( buffer, dataBuffer + 1 ) )
		addRandomValue( randomState, dataBuffer );
*/	GetDateTime( &dateTime );
	addRandomValue( randomState, dateTime );
	addRandomValue( randomState, TickCount() );
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
	addRandomValue( randomState, GetApplLimit() );
	addRandomValue( randomState, GetZone() );
	addRandomValue( randomState, SystemZone() );
	addRandomValue( randomState, FreeMem() );
	addRandomValue( randomState, FreeMemSys() );
#endif
/*	MicroSeconds( &usSinceStartup );
	addRandomData( randomState, &usSinceStartup, sizeof( UnsignedWide ) ); */
	addRandomValue( randomState, QDDone( NULL ) );
/*	ModemStatus( dataBuffer );
	addRandomValue( randomState, dataBuffer[ 0 ] ); */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
	addRandomValue( randomState, SCSIStat() );
#endif
	addRandomValue( randomState, MaxBlock() );
	addRandomValue( randomState, StackSpace() );
	addRandomValue( randomState, QDError() );

	/* Get the event code and message, time, and mouse location for the next
	   event in the event queue and the OS event queue */
	if( EventAvail( everyEvent, &eventRecord ) )
		addRandomData( randomState, &eventRecord, sizeof( EventRecord ) );
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
	if( OSEventAvail( everyEvent, &eventRecord ) )
		addRandomData( randomState, &eventRecord, sizeof( EventRecord ) );
#endif

	/* Get all sorts of information such as device-specific info, grafport
	   information, visible and clipping region, pattern, pen, text, and
	   colour information, and other details, on the topmost window.  Also
	   get the window variant.  If there's a colour table record, add the
	   colour table as well */
	if( ( windowPtr = FrontWindow() ) != NULL )
		{
/*		CTabHandle colourHandle; */

#if !defined OPAQUE_TOOLBOX_STRUCTS || !OPAQUE_TOOLBOX_STRUCTS
		addRandomData( randomState, windowPtr, sizeof( GrafPort ) );
#endif
		addRandomValue( randomState, GetWVariant( windowPtr ) );
/*		if( GetAuxWin( windowPtr, colourHandle ) )
			{
			CTabPtr colourPtr;

			HLock( colourHandle );
			colourPtr = *colourHandle;
			addRandomData( randomState, colourPtr, sizeof( ColorTable ) );
			HUnlock( colourHandle );
			} */
		}

	/* Get mouse-related such as the mouse button status and mouse position,
	   information on the window underneath the mouse */
	addRandomValue( randomState, Button() );
	GetMouse( &point );
	addRandomData( randomState, &point, sizeof( Point ) );
	FindWindow( point, &windowPtr );
#if !defined OPAQUE_TOOLBOX_STRUCTS || !OPAQUE_TOOLBOX_STRUCTS
	if( windowPtr != NULL )
		addRandomData( randomState, windowPtr, sizeof( GrafPort ) );
#endif

	/* Get the size, handle, and location of the desk scrap/clipboard */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
	scrapInfo = InfoScrap();
	addRandomData( randomState, scrapInfo, sizeof( ScrapStuff ) );
#endif

	/* Get information on the current thread */
	threadID = kCurrentThreadID; /*GetThreadID( &threadID ); */
	GetThreadState( threadID, &threadState );
	addRandomData( randomState, &threadState, sizeof( ThreadState ) );

	/* Get the sound mananger status.  This gets the number of allocated
	   sound channels and the current CPU load from these channels */
	SndManagerStatus( sizeof( SMStatus ), &soundStatus );
	addRandomData( randomState, &soundStatus, sizeof( SMStatus ) );

	/* Get the speech manager version and status */
/*	version = SpeechManagerVersion();
	addRandomData( randomState, &version, sizeof( NumVersion ) );
	addRandomValue( randomState, SpeechBusy() );
*/
	/* Get the status of the serial port.  This gets information on recent
	   errors, read and write pending status, and flow control values */
/*	if( !OpenDriver( "\p.AIn", &driverRefNum ) )
		{
		SerStaRec serialStatus;

		SetStatus( driverRefNum, &serialStatus );
		addRandomData( randomState, &serialStatus, sizeof( SerStaRec ) );
		}
	if( !OpenDriver( "\p.AOut", &driverRefNum ) )
		{
		SerStaRec serialStatus;

		SetStatus( driverRefNum, &serialStatus );
		addRandomData( randomState, &serialStatus, sizeof( SerStaRec ) );
		} */

	/* Flush any remaining data through */
	endRandomData( randomState, 10 );
	}
Exemplo n.º 15
0
bool WorldRunnable::run()
{
    SetThreadName("WorldRunnable (non-instance/logon)");
    uint32 LastWorldUpdate = getMSTime();
    uint32 LastSessionsUpdate = getMSTime();

    THREAD_TRY_EXECUTION

        while (GetThreadState() != THREADSTATE_TERMINATE)
        {
            // Provision for pausing this thread.
            if (GetThreadState() == THREADSTATE_PAUSED)
            {
                while (GetThreadState() == THREADSTATE_PAUSED)
                {
                    Arcemu::Sleep(200);
                }
            }
            if (GetThreadState() == THREADSTATE_TERMINATE)
                break;

            ThreadState.SetVal(THREADSTATE_BUSY);

            uint32 diff;
            //calc time passed
            uint32 now, execution_start;
            now = getMSTime();
            execution_start = now;

            if (now < LastWorldUpdate) //overrun
                diff = WORLD_UPDATE_DELAY;
            else
                diff = now - LastWorldUpdate;

            LastWorldUpdate = now;
            sWorld.Update(diff);

            now = getMSTime();

            if (now < LastSessionsUpdate) //overrun
                diff = WORLD_UPDATE_DELAY;
            else
                diff = now - LastSessionsUpdate;

            LastSessionsUpdate = now;
            sWorld.UpdateSessions(diff);

            now = getMSTime();
            //we have to wait now

            if (execution_start > now)//overrun
                diff = WORLD_UPDATE_DELAY - now;

            else
                diff = now - execution_start; //time used for updating

            if (GetThreadState() == THREADSTATE_TERMINATE)
                break;

            ThreadState.SetVal(THREADSTATE_SLEEPING);

            /*This is execution time compensating system
                if execution took more than default delay
                no need to make this sleep*/
            if (diff < WORLD_UPDATE_DELAY)
                Arcemu::Sleep(WORLD_UPDATE_DELAY - diff);
        }

    THREAD_HANDLE_CRASH
        return true;
}
Exemplo n.º 16
0
bool MapMgr::Do()
{
#ifdef WIN32
	threadid = GetCurrentThreadId();
#endif

	t_currentMapContext.set(this);

	thread_running = true;
	ThreadState.SetVal(THREADSTATE_BUSY);
	SetThreadName("Map mgr - M%u|I%u", this->_mapId , this->m_instanceID);
	ObjectSet::iterator i;
	uint32 last_exec = getMSTime();

	// Create Instance script
	LoadInstanceScript();

	/* create static objects */
	for(GOSpawnList::iterator itr = _map->staticSpawns.GOSpawns.begin(); itr != _map->staticSpawns.GOSpawns.end(); ++itr)
	{
		GameObject* obj = CreateGameObject((*itr)->entry);
		obj->Load((*itr));
		PushStaticObject(obj);
	}

	// Call script OnLoad virtual procedure
	CALL_INSTANCE_SCRIPT_EVENT(this, OnLoad)();

	for(CreatureSpawnList::iterator itr = _map->staticSpawns.CreatureSpawns.begin(); itr != _map->staticSpawns.CreatureSpawns.end(); ++itr)
	{
		Creature* obj = CreateCreature((*itr)->entry);
		obj->Load(*itr, 0, pMapInfo);
		PushStaticObject(obj);
	}

	/* load corpses */
	objmgr.LoadCorpses(this);
	worldstateshandler.InitWorldStates( objmgr.GetWorldStatesForMap( _mapId ) );
	worldstateshandler.setObserver( this );

	// always declare local variables outside of the loop!
	// otherwise there's a lot of sub esp; going on.

	uint32 exec_time, exec_start;

	while((GetThreadState() != THREADSTATE_TERMINATE) && !_shutdown)
	{
		exec_start = getMSTime();

///////////////////////////////////////////// first push to world new objects ////////////////////////////////////////////

		m_objectinsertlock.Acquire();

		if(m_objectinsertpool.size())
		{
			for(i = m_objectinsertpool.begin(); i != m_objectinsertpool.end(); ++i)
			{
				Object* o = *i;

				o->PushToWorld(this);
			}

			m_objectinsertpool.clear();
		}

		m_objectinsertlock.Release();

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		//Now update sessions of this map + objects
		_PerformObjectDuties();

		last_exec = getMSTime();
		exec_time = last_exec - exec_start;
		if(exec_time < MAP_MGR_UPDATE_PERIOD)
		{

			Arcemu::Sleep(MAP_MGR_UPDATE_PERIOD - exec_time);

		}

		//////////////////////////////////////////////////////////////////////////
		// Check if we have to die :P
		//////////////////////////////////////////////////////////////////////////
		if(InactiveMoveTime && UNIXTIME >= InactiveMoveTime)
			break;
	}

	// Teleport any left-over players out.
	TeleportPlayers();

	// Clear the instance's reference to us.
	if(m_battleground)
	{
		BattlegroundManager.DeleteBattleground(m_battleground);
		sInstanceMgr.DeleteBattlegroundInstance(GetMapId(), GetInstanceID());
	}

	if(pInstance)
	{
		// check for a non-raid instance, these expire after 10 minutes.
		if(GetMapInfo()->type == INSTANCE_NONRAID || pInstance->m_isBattleground)
		{
			pInstance->m_mapMgr = NULL;
			sInstanceMgr._DeleteInstance(pInstance, true);
			pInstance = NULL;
		}
		else
		{
			// just null out the pointer
			pInstance->m_mapMgr = NULL;
		}
	}
	else if(GetMapInfo()->type == INSTANCE_NULL)
		sInstanceMgr.m_singleMaps[GetMapId()] = NULL;

	thread_running = false;
	if(thread_kill_only)
		return false;

	// delete ourselves
	delete this;

	// already deleted, so the threadpool doesn't have to.
	return false;
}