void MainGameLoop::Run()
{
   FrameCounter fc;

   // main game loop
   while (!m_bExitLoop)
   {
      OnTick();

      ProcessEvents();
      if (m_bExitLoop)
         break;

      if (!m_bAppActive)
      {
         // as we're not visible, just wait for next event
         SDL_WaitEvent(NULL);
         continue;
      }

      // render the scene
      {
         OpenGL::ResetPolycount();

         OnRender();

         fc.OnNextFrame();
      }

      // count ticks for fps
      double dFramesPerSecond;
      if (m_bUpdateFrameCount && fc.GetUpdatedCount(dFramesPerSecond))
         UpdateCaption(dFramesPerSecond);
   }
}
//-----------------------------------------------------------------------------
// Attach to a new entity
//-----------------------------------------------------------------------------
void CEntityPanel::SetEntity( C_BaseEntity* pEntity )
{
	m_pBaseEntity = pEntity;

	// Recompute position
	OnTick();
}
Example #3
0
int main(int argc, char **argv)
{
	if (!Init())
	{
		LOG::Message("Initialization failed.");
		AppRunning = false;
	}
	
	for (unsigned i = 0; i < argc; i++) 
		LOG::Message(argv[i]);
	
	time_t lastTime = time(0);
	while(AppRunning)
	{
		SDL_Event event;
		while (SDL_PollEvent(&event)) 
			Listen(event);
		
		time_t newTime = time(0);
		if (newTime > lastTime)
		{
			OnTick();
			OnFrame();
			lastTime = newTime;
		}
	}

	if (!Uninit()) 
		LOG::Message("Uninitialization failed.");
	return 0;
}
Example #4
0
void CSector::GoAwake()
{
    ADDTOCALLSTACK("CSector::GoAwake");
    ProfileTask charactersTask(PROFILE_TIMERS);
    CTimedObject::GoAwake();  // Awake it first, otherwise other things won't work.

    CChar * pCharNext = nullptr;
    CChar * pChar = static_cast <CChar*>(m_Chars_Active.GetHead());
    for (; pChar != nullptr; pChar = pCharNext)
    {
        pCharNext = pChar->GetNext();
        if (pChar->IsSleeping())
            pChar->GoAwake();
    }

    pChar = static_cast<CChar*>(m_Chars_Disconnect.GetHead());
    for (; pChar != nullptr; pChar = pCharNext)
    {
        pCharNext = pChar->GetNext();
        if (pChar->IsSleeping())
            pChar->GoAwake();
    }

    CItem * pItemNext = nullptr;
    CItem * pItem = static_cast <CItem*>(m_Items_Timer.GetHead());
    for (; pItem != nullptr; pItem = pItemNext)
    {
        pItemNext = pItem->GetNext();
		if (pItem->IsSleeping())
        	pItem->GoAwake();
    }
    pItem = static_cast <CItem*>(m_Items_Inert.GetHead());
    for (; pItem != nullptr; pItem = pItemNext)
    {
        pItemNext = pItem->GetNext();
        if (pItem->IsSleeping())
			pItem->GoAwake();
    }

    /*
    * Awake adjacent sectors when awaking this one to avoid the effect
    * of NPCs being stop until you enter the sector, or all the spawns
    * generating NPCs at once.
    */
    static CSector *pCentral = nullptr;   // do this only for the awaken sector
    if (!pCentral)
    {
        pCentral = this;  
        for (int i = 0; i < (int)DIR_QTY; ++i)
        {
            CSector *pSector = GetAdjacentSector((DIR_TYPE)i);
            if (pSector && !pSector->IsSleeping())
            {
                pSector->GoAwake();
            }
        }
        pCentral = nullptr;
    }
    OnTick();   // Unknown time passed, make the sector tick now to reflect any possible environ changes.
}
void nglTimer::TimerAction()
{
  nglTime now;
  OnTick(now - mLastTime);
  mLastTime = now;
  mCallCnt++;
}
Example #6
0
	Bool HawkAppFrame::Run()
	{
		if (HawkApp::Run())
		{
			UInt32 iTickTime = 0;
			while (m_bRunning && !m_bBreakLoop)
			{
				m_iSysTime	  = (UInt32)HawkOSOperator::GetSysTime();
				iTickTime	  = HawkOSOperator::GetTickCount();
				m_iElapseTime = iTickTime - m_iTickTime;
				m_iTickTime   = iTickTime;

				//Hawk体系帧更新
				HawkUtil::Tick(m_iElapseTime);
			
				//网关代理器更新
				if (m_pGateProxy && !m_pGateProxy->Update())
				{
					HawkSleep(DEFAULT_SLEEP);
				}

				//逻辑帧更新
				OnTick(m_iElapseTime);
			}

			//服务器关闭异常
			OnException(0);

			//关闭服务器
			Stop();
			
			return true;
		}
		return false;
	}
Example #7
0
File: Dmm.cpp Project: fredzo/DS203
/* virtual */ void CWndDmm::OnMessage(CWnd* pSender, ui16 code, ui32 data)
{
	// LAYOUT ENABLE/DISABLE FROM TOP MENU BAR
	if ((code == ToWord('L', 'D') )||(code == ToWord('S', 'H') && data == 0))
	{	// TODO restore channel settings
		bTimer = false;
		KillTimer();
		return;
	}

	if ((code == ToWord('L', 'E') )||(code == ToWord('S', 'H') && data == 1 ))
	{	// TODO backup channel settings
		// Configure ADC accrding to DMM settings
		MainWnd.m_wndDmmMeas.ConfigureAdc();
		bRefresh = true;
		return;
	}

	if ( pSender == NULL && code == WmBroadcast && data == ToWord('d', 'g') )
	{
		OnPaint(false);
		return;
	}

	if (code == ToWord('t', 'i') )
	{
		// OnTick
		OnTick(false);
		return;
	}
}
Example #8
0
void nglTimer::TimerAction()
{
  nglTime now;
  double elapsed = now.GetValue() - mLastTime.GetValue();
  OnTick(elapsed);
  mLastTime = now;
  mCallCnt++;
}
Example #9
0
int main()
{
	glfwInit();
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

	GLFWwindow * window = glfwCreateWindow(screenWidth, screenHeight, "LearnOpenGL", nullptr, nullptr);
	glfwMakeContextCurrent(window);
	if (window == NULL)
	{
		std::cout << "Failed to create GLFW window" << std::endl;
		glfwTerminate();
		return -1;
	}

	camera = new Camera(glm::radians(90.0f), (float)screenWidth / (float)screenHeight);

	glfwSetKeyCallback(window, key_callback);
	glfwSetCursorPosCallback(window, mouse_callback);
	glfwSetScrollCallback(window, scroll_callback);

	// Options
	glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

	glewExperimental = GL_TRUE;
	if (glewInit() != GLEW_OK)
	{
		std::cout << "Failed to initialize GLEW" << std::endl;
		return -1;
	}

	glViewport(0, 0, screenWidth, screenHeight);

	GLuint uboId = GetCommonUniformBuffer();
	glBindBufferBase(GL_UNIFORM_BUFFER, 0, uboId);
	
	//auto example = new ExampleIBL();
	//auto example = new ExampleDeferred();
	auto example = new ExampleSSAO();
	example->Init(camera, uboId);

	while (!glfwWindowShouldClose(window))
	{
		glfwPollEvents();

		DoMovement(camera, keys);

		example->OnTick();

		glfwSwapBuffers(window);
	}

	glfwTerminate();

	return 0;
}
Example #10
0
	void ResourceImpl::Tick()
	{
		if (m_state != ResourceState::Started)
		{
			return;
		}

		OnTick();
	}
void CIOSUpdatePanel::Activate(UpdateState_t updateState)
{
	BaseClass::Activate();

	m_eUpdateState = updateState;

	OnTick();

	m_bGoToTextStart = true;
}
Example #12
0
bool BaseApp::InternalTick()
{
	if(!_running)
		return false;

	Time::Update();
	OnTick();

	if(_tick_sleep > 0)
		std::this_thread::sleep_for(std::chrono::milliseconds((_tick_sleep)));
	return _running;
}
Example #13
0
void Player::Start(int heartbeat)
{
	mIsAlive = true;
	mHeartBeat = heartbeat;
	
	/// ID 발급 및 플레잉어 맵에 등록
	mPlayerId = GPlayerManager->RegisterPlayer(GetSharedFromThis<Player>());

	/// 생명 불어넣기 ㄱㄱ
	OnTick();

}
Example #14
0
void EditorBase::Init()
{
    mWorldManager->Init();

    InitTools();

    LoadWorkspace();

    mLastTime = SystemInfo::Instance()->GetSeconds();

    QTimer* refreshTimer = new QTimer( this );
    connect( refreshTimer, SIGNAL(timeout()), SLOT(OnTick()) );
    refreshTimer->start( 1000 / 30 );    
}
Example #15
0
void nglTimer::CallOnTick()
{
  if (mRunning)
  {
    mCounter--;
    if (!mCounter)
    {
      nglTime tick;
      mCallCnt++;
      tick = nglTime::GetTime();

      OnTick(tick-mLastTick);

      mLastTick=tick;
      mCounter = mRoundsPerTick;
    }
  }
}
bool CEntityImagePanel::Init( KeyValues* pInitData, C_BaseEntity* pEntity )
{
	if (!BaseClass::Init( pInitData, pEntity))
		return false;

	// modulation color
	if (!ParseRGBA( pInitData, "color", m_r, m_g, m_b, m_a ))
		return false;

	// get the size...
	int w, h;
	if (!ParseCoord( pInitData, "offset", m_OffsetX, m_OffsetY ))
		return false;

	if (!ParseCoord( pInitData, "size", w, h ))
		return false;

	char const* pClassImage = pInitData->GetString( "material" );
	if ( !pClassImage || !pClassImage[ 0 ] )
		return false;

	const char *mouseover = pInitData->GetString( "mousehint", "" );
	if ( mouseover && mouseover[ 0 ] )
	{
		Q_strncpy( m_szMouseOverText, mouseover, sizeof( m_szMouseOverText ) );
	}

	// hook in the bitmap
	m_pImage = new BitmapImage( GetVPanel(), pClassImage );

	// Set the size...
	SetSize( w, h );

	m_iOrgWidth = w;
	m_iOrgHeight = h;
	m_iOrgOffsetX = m_OffsetX;
	m_iOrgOffsetY = m_OffsetY;

	// we need updating
	vgui::ivgui()->AddTickSignal( GetVPanel() );

	OnTick();
	return true;
}
Example #17
0
void CItemSpawn::KillChildren()
{
	ADDTOCALLSTACK("CitemSpawn:KillChildren");
	WORD iTotal = GetType() == IT_SPAWN_CHAR ? static_cast<WORD>(m_itSpawnChar.m_current) : GetAmount(); //m_itSpawnItem doesn't have m_current, it uses more2 to set the amount of items spawned in each tick, so i'm using its amount to perform the loop
	if ( iTotal <= 0 )
		return;
	for ( WORD i = 0; i < iTotal; i++ )
	{
		CObjBase * pObj = m_obj[i].ObjFind();
		if ( !pObj )
			continue;
		pObj->m_uidSpawnItem.InitUID();
		pObj->Delete();
		m_obj[i].InitUID();

	}
	m_itSpawnChar.m_current = 0;
	OnTick(false);
}
Example #18
0
void CWndUserMonitor::OnMessage(CWnd* pSender, ui16 code, ui32 data)
{
	if ( code == ToWord('t', 'i') )
	{
		OnTick();
		return;
	}

	// LAYOUT ENABLE/DISABLE FROM TOP MENU BAR
	if (code == ToWord('L', 'D') )
	{
		KillTimer();
		return;
	}

	if (code == ToWord('L', 'E') )
	{
		m_x = 0;
		m_y = 0;
		SetTimer(500);
		return;
	}
	
	if ( pSender == &m_itmBaud && code == ToWord('u', 'p') )
	{
		int nBaudrate = m_pnValueBaud[m_nBaud];
		BIOS::SERIAL::Configure( nBaudrate );
	}

	if ( pSender == &m_btnClear && code == CWnd::WmKey && data == BIOS::KEY::KeyEnter )
	{
		m_x = 0;
		m_y = 0;
		BIOS::LCD::Bar( 4, 24, 4+32*8, 24 + 12*16, RGB565(000000) );
	}
	/*
	if ( pSender == &m_btnSend && code == CWnd::WmKey && data == BIOS::KEY::KeyEnter )
	{
		BIOS::SERIAL::Send("Hello");
	}
	*/
}
Example #19
0
bool nglTimer::Start(bool Immediate, bool Reset)
{
  if (mRunning)
    return false;

  {
    mCounter = MIN(mRoundsPerTick, mCounter);
    if (Reset)
    {
      mCallCnt = 0;
      mCounter = mRoundsPerTick;
    }
    mRunning = true;
    mLastTick = nglTime::GetTime();
    if (Immediate)
      OnTick(0);
  }

  return mRunning;
}
Example #20
0
void CItemSpawn::KillChildren()
{
	ADDTOCALLSTACK("CitemSpawn:KillChildren");
	if (m_currentSpawned <= 0 )
		return;

	for (BYTE i = 0; i < m_currentSpawned; i++ )
	{
		CObjBase *pObj = m_obj[i].ObjFind();
		if ( !pObj )
			continue;
		pObj->m_uidSpawnItem.InitUID();
		pObj->Delete();
		m_obj[i].InitUID();

	}
	m_currentSpawned = 0;

	OnTick(false);
}
Example #21
0
void VDVideoDisplayWindow::FlushBuffers() {
	vdlist<VDVideoDisplayFrame> frames;
	if (mpLastFrame) {
		frames.push_back(mpLastFrame);
		mpLastFrame = NULL;
	}

	// wait for any current frame to clear
	for(;;) {
		bool idle;
		vdsynchronized(mMutex) {
			// clear existing pending frames so the display doesn't start another render
			if (!mPendingFrames.empty())
				frames.splice(frames.end(), mIdleFrames);

			idle = !mpActiveFrame;
		}

		if (idle)
			break;

		::Sleep(1);
		OnTick();
	}

	vdsynchronized(mMutex) {
		frames.splice(frames.end(), mIdleFrames);
		frames.splice(frames.end(), mPendingFrames);
	}

	while(!frames.empty()) {
		VDVideoDisplayFrame *p = frames.back();
		frames.pop_back();

		p->Release();
	}
}
Example #22
0
File: Dmm.cpp Project: fredzo/DS203
void CWndDmm::OnPaint(bool updateBg)
{
	if ( CWnd::m_rcOverlay.IsValid() )
	{	// Do not redraw screen if modal window is active, but prepare for a refresh when it's closed
		bRefresh = true;
		return;
	}

	bool refreshValue = false;
	// TODO make refresh rate configurable
	// No more than one refresh each 500 ms for values
	if (!bTimer)
	{	// Only delay next update if we were not refreshing
		if(!updateBg && !bRefresh)
		{
			KillTimer();
			SetTimer(500);
			bTimer = true;
		}
		refreshValue = true;
	}
	// Draw values
	DisplayValue(&Settings.DmmMeas[0][Settings.Dmm.Mode],false,0,bRefresh,refreshValue);
	DisplayValue(&Settings.DmmMeas[1][Settings.Dmm.Mode],false,1,bRefresh,refreshValue);
	DisplayValue(&Settings.DmmMeas[2][Settings.Dmm.Mode],false,2,bRefresh,refreshValue);
	

	float fullRange;
	int fullScale;
	computeFullRange(&Settings.DmmMeas[0][Settings.Dmm.Mode],&fullRange,&fullScale);
	UpdateBargraphValue(fullRange);
	OnTick(true);

	// Draw Graduation
	if(updateBg)
	{
		int x = CWndDmm::cBargraphLeft;
		int y = CWndDmm::cBargraphTop;
		fullScale*=5;
		for(int i = 0 ; i <= 20 ; i++)
		{
			if(i%5 == 0)
			{
				if(i%10 == 0)
				{
                    BIOS::LCD::Bar( x-1, y-4, x+1, y+2,  CWndDmm::cOn );
				}
				else
				{
					BIOS::LCD::Bar( x-1, y-4, x+1, y,  CWndDmm::cOn );
				}
				int labelValue = i*fullScale/100;
				int xPos;
				if(labelValue < 10) 
				{
					xPos = x-12;
				} 
				else if(labelValue < 100)
				{
					xPos = x-16;
				}
				else
				{
					xPos = x-20;
				}
				BIOS::LCD::Printf(xPos,y+2,CWndDmm::cLabel, CWndDmm::cOff, " %d ", labelValue);
			}
			else
			{
				BIOS::LCD::Bar( x-1, y-4, x, y-2,  CWndDmm::cOn );
			}
			x+=15;
		}
	}
	
	// Draw bottom line
	//BIOS::LCD::Printf( 8, 220, RGB565(808080), RGB565(ffffff), "adc=%3f cal=%3f var=%3f range=%s ", m_fAverage, fCorrect, m_fVariance, CSettings::AnalogChannel::ppszTextResolution[Settings.CH1.Resolution]);
	if(updateBg || bRefresh)
	{
		int x = 34, y = 226;
		int _x = x;
		x += BIOS::LCD::Print( x, y, Settings.CH1.u16Color, RGB565(000000), "CH1: " );
		x += BIOS::LCD::Print( x, y, RGB565(ffffff), RGB565(000000), 
			CSettings::AnalogChannel::ppszTextResolution[ Settings.CH1.Resolution ]);
		x += BIOS::LCD::Print( x, y, RGB565(ffffff), RGB565(000000), " " );
		x += BIOS::LCD::Draw( x, y, RGB565(ffffff), RGB565(000000), Settings.CH1.Coupling == CSettings::AnalogChannel::_AC ? CShapes::sig_ac : CShapes::sig_dc);
		x += BIOS::LCD::Print( x, y, RGB565(ffffff), RGB565(000000), "    " );
		
		x = _x + 120;
		x += BIOS::LCD::Print( x, y, Settings.CH2.u16Color, RGB565(000000), "CH2: " );
		x += BIOS::LCD::Print( x, y, RGB565(ffffff), RGB565(000000), 
			CSettings::AnalogChannel::ppszTextResolution[ Settings.CH2.Resolution ]);
		x += BIOS::LCD::Print( x, y, RGB565(ffffff), RGB565(000000), " " );
		x += BIOS::LCD::Draw( x, y, RGB565(ffffff), RGB565(000000), Settings.CH2.Coupling == CSettings::AnalogChannel::_AC ? CShapes::sig_ac : CShapes::sig_dc);
		x += BIOS::LCD::Print( x, y, RGB565(ffffff), RGB565(000000), "    " );

		x = _x + 240;
		x += BIOS::LCD::Print( x, y, RGB565(b0b0b0), RGB565(000000), "T: " );
		x += BIOS::LCD::Print( x, y, RGB565(ffffff), RGB565(000000), 
			CSettings::TimeBase::ppszTextResolution[ Settings.Time.Resolution ]);
		x += BIOS::LCD::Print( x, y, RGB565(ffffff), RGB565(000000), "    " );
	}

	bRefresh = false;
}
Example #23
0
// 语法糖,单纯是为了完成
// while(timer)  这个语法糖。。。
// 返回 true  表示 等待完成
//      false 表示 计时间隔为0,没有等待
CTimer::operator bool()
{
    WaitForTimer();
    OnTick();
    return m_Inteval != 0;
}
Example #24
0
 GameApplication::GameApplication(QString name, int argc, char* argv[])
     : Application(name, argc, argv)
     , m_TickTimer()
 {
     connect(&m_TickTimer, SIGNAL(timeout()), this, SLOT(OnTick()));
 }
Example #25
0
//+---------------------------------------------------------------------------
//
//  Member:     CScrollbarController::MouseMove
//              
//  Synopsis:   Handle mouse move events.
//              
//  Arguments:  pt      new mouse location
//              
//  Notes:      
//              
//----------------------------------------------------------------------------
void CScrollbarController::MouseMove(const CPoint& pt)
{
	_ptMouse = pt;
	_pDispScroller->TransformPoint(&_ptMouse, COORDSYS_GLOBAL, COORDSYS_CONTAINER);

	switch(_partPressedStart)
	{
	case SBP_NONE:
	case SBP_TRACK:
		AssertSz(FALSE, "unexpected call to CScrollbarController::MouseMoved");
		break;

	case SBP_THUMB:
		{
			LONG contentSize = _pDispScroller->GetContentSize()[_direction];
			Assert(contentSize >= 0);
			LONG trackSize =
				GetTrackSize(_direction, _rcScrollbar, _buttonWidth) -
				GetThumbSize(_direction, _rcScrollbar, contentSize,
				_rcScrollbar.Size(_direction), _buttonWidth,
				&_drawInfo);
			if(trackSize <= 0)
			{
				break; // can't move thumb
			}

			// NOTE: we're not currently checking to see if the mouse point
			// is out of range perpendicular to the scroll bar axis
			BOOL fRightToLeft = (_direction==0 && _pDispScroller->IsRightToLeft());
			LONG trackPos;
			if(!fRightToLeft)
			{
				trackPos = _ptMouse[_direction] - _rcScrollbar[_direction] -
					GetScaledButtonWidth(_direction, _rcScrollbar, _buttonWidth) - _mouseInThumb;
			}
			else
			{
				trackPos = _rcScrollbar.right -
					GetScaledButtonWidth(_direction, _rcScrollbar, _buttonWidth) -
					_mouseInThumb - _ptMouse.x;
			}
			LONG scrollOffset;
			if(trackPos <= 0)
			{
				scrollOffset = 0;
			}
			else
			{
				contentSize -= _rcScrollbar.Size(_direction);
				scrollOffset = MulDivQuick(trackPos, contentSize, trackSize);
				if(fRightToLeft)
				{
					scrollOffset = -scrollOffset;
				}
			}

			_pLayout->OnScroll(_direction, SB_THUMBPOSITION, scrollOffset);
		}
		break;

	default:
		{
			// find out what the mouse would be pressing in its new location.
			// If it's not the same as it used to be, invalidate the part.
			SCROLLBARPART partPressedOld = _partPressed;
			LONG contentSize, containerSize, scrollAmount;
			GetScrollInfo(&contentSize, &containerSize, &scrollAmount);
			_partPressed = GetPart(
				_direction,
				_rcScrollbar,
				_ptMouse,
				contentSize,
				containerSize,
				scrollAmount,
				_buttonWidth,
				&_drawInfo,
				_pDispScroller->IsRightToLeft());
			if(_partPressed != _partPressedStart)
			{
				_partPressed = SBP_NONE;
			}
			if(_partPressed != partPressedOld)
			{
				SCROLLBARPART invalidPart = _partPressed;
				if(_partPressed != SBP_NONE)
				{
					// perform scroll action and set timer
					OnTick(SB_REPEAT_TIMER);
				}
				else
				{
					invalidPart = partPressedOld;
				}
				Verify(_pLayout->OpenView());
				InvalidatePart(
					invalidPart,
					_direction,
					_rcScrollbar,
					contentSize,
					containerSize,
					scrollAmount,
					_buttonWidth,
					_pDispScroller,
					&_drawInfo);
			}
		}
		break;
	}
}