Пример #1
0
//Holds game logic together
int Game::OnStart() {
	//Initialize the game
	if (OnInit() == false) {
        return -1;
    }

	SDL_Event Event;

	//While game is running 
	while (running) {
		while (gameType == 0 && running) {
			while (SDL_PollEvent(&Event)) {
				OnEvent(&Event);
			}
			//meanwhile show menu
			showMenu();
		}
		while (SDL_PollEvent(&Event)) {
			//Handle user input
			OnEvent(&Event);
		}
		OnLoop();
		OnRender();
	}
 
    OnCleanUp();
 
    return 0;
};
Пример #2
0
void EventProcessor::Run() //{{{
{
  DEBUG_TRACER;

  long timeToWait = -1;
  while( true )
  {
    EventPointer event;
    std::pair<bool,long int> needWait = GetMaxWaitTime();
    if( needWait.first )
      timeToWait = needWait.second;
    else
      timeToWait = -1;

    DBGOUT_DEBUG( Debug::Prefix() << "EventProcessor(" << GetID() << ")::Run needWait " << needWait.first << ", " << needWait.second << " timeToWait " << timeToWait << std:: endl );

    if( GetEvent( event, timeToWait ) == EventPresent )
    {
      OnEvent( event );

      if( event->ID() == EVENT_FINISH )
        break;
    }

    std::pair<bool,unsigned char> timer = GetNextTimer();
    DBGOUT_DEBUG( Debug::Prefix() << "EventProcessor(" << GetID() << ")::Run timer " << timer.first << ", " << static_cast<int>( timer.second ) << std:: endl );
    if( timer.first )
    {
      EventPointer ptr = EventPointer( new Event( TIMER_ELAPSED( timer.second ) ) );
      OnEvent( ptr );
    }
  }
} //}}}
Пример #3
0
int AButton::Listener::FilterEvent(wxEvent &event)
{
   if (event.GetEventType() == wxEVT_KEY_DOWN ||
       event.GetEventType() == wxEVT_KEY_UP)
      OnEvent();
   else if (event.GetEventType() == wxEVT_SET_FOCUS)
      // A modal dialog might have eaten the modifier key-up with its own
      // filter before we saw it; this is adequate to fix the button image
      // when the dialog disappears.
      OnEvent();
   return Event_Skip;
}
Пример #4
0
void CCareerTask::OnEvent( GameEventType event, CBasePlayer *pAttacker, CBasePlayer *pVictim )
{
    if( !m_isComplete )
    {
        OnEvent( event, pAttacker, pVictim );
    }
}
Пример #5
0
    int OnExecute()
    {
        if (OnInit() == false)
        {
            return -1;
        }

        SDL_Event Event;

        while(Running)
        {
            if (g_engine)
            {
                for (int x = 0; x < 5 && SDL_WaitEventTimeout(&Event, 10); ++x)
                {
                    if(!g_engine->IsPaused())
                        OnEvent(&Event);
                }
                if(!g_engine->IsPaused())
                    OnUpdate();
            }
        }

        OnCleanup();

        return 0;
    };
Пример #6
0
  int UDPSocket::MainLoop()
  {
    fd_set ReadSet;
    int result = 0;

    while(1)
    {
      FD_ZERO(&ReadSet);
      FD_SET(m_Socket, &ReadSet);

      result = select(0, &ReadSet, 0, 0, 0);
      if(result == 0)
      {
        // Time Out
      }
      else if(result == SOCKET_ERROR)
      {
        break;
      }
      else if(result != 0)
      {
        OnEvent(m_Socket, SE_READ);
      }
    }
    return result;
  }
Пример #7
0
void GameLoop::Loop()
{
	SDL_Event sdlEvent; // Will hold the next event to be parsed

	while (m_bRunning)
	{
		// Events get called one at a time, so if multiple things happen in one frame, they get parsed individually through 'SDL_PollEvent'
		// The next event to parse gets stored into 'sdlEvent', and then passed to the 'EventHandler' class which will call it's appropriate function here
		// 'SDL_PollEvent' returns 0 when there are no more events to parse
		while (SDL_PollEvent(&sdlEvent))
		{
			// Calls the redefined event function for the EventHandler class
			// Refer to its header file and cpp for more information on what each inherited function is capable of
			// and its syntax
			OnEvent(sdlEvent);
		}
		Update();

		LateUpdate();

		Draw();

		Graphics::Flip(); // Required to update the window with all the newly drawn content
	}
}
Пример #8
0
 virtual void OnDisconnectedFromServer() {
     EventObserverInterface* delegated;
     if ((delegated = EventObserverInterfaceDelegated()))
         delegated->OnDisconnectedFromServer();
     else
     OnEvent("DisconnectedFromServer"); 
 }
Пример #9
0
 ///////////////////////////////////////////////////////////////////////
 // Server Connection
 ///////////////////////////////////////////////////////////////////////
 virtual void OnFailedToConnectToServer(const std::string& server) {
     EventObserverInterface* delegated;
     if ((delegated = EventObserverInterfaceDelegated()))
         delegated->OnFailedToConnectToServer(server);
     else
     OnEvent("FailedToConnectToServer"); 
 }
Пример #10
0
int Main::OnExecute(CL_ParamList* pCL_Params)
{
	if(!OnInit(pCL_Params))
		return -1;

	SDL_Event Event;

	Uint32 t1,t2;
	float fTime = 0.0f;

	while(Running)
	{
		t1 = SDL_GetTicks();
		while(SDL_PollEvent(&Event))
		{
			if(Event.type == SDL_QUIT)
				Running = false;
			else OnEvent(&Event);
		}
		OnMove(fTime);
		OnRender();
		t2 = SDL_GetTicks();
		fTime = (float)(t2-t1)/1000.0f;
	}

	OnExit();
	return 1;
}
Пример #11
0
int CInstance_Menu_MJ::OnExecute()
{
  if(!Init())
  {
    cerr << ERROR_STR_INIT << " MENU_MJ" << endl;
    return ERROR_CODE_GENERAL;
  }

  int frame = 0;
  CTemporizador fps;

  int salida = I_SALIDA;

  while(i_running)
  {
    fps.empezar();
    while(SDL_PollEvent(&event))
    {
      OnEvent(salida);
    }
    OnLoop(salida);
    OnRender();

    frame++;
    if((fps.getTicks() < (1000 / FRAMES_PER_SECOND)))
      SDL_Delay((1000 / FRAMES_PER_SECOND ) - fps.getTicks());
  }

  Close();

  return salida;
}
Пример #12
0
int GMSynthDLL::ThreadProc()
{
	if (live)
	{
		if (seqMode & seqPlay)
			ldTm = 0.02;
		else
			ldTm = 0.20;
		OpenWaveDevice();
		inmgr.SetWaveOut(&wvd);
	}
	else
	{
		if (wvf.OpenWaveFile(outFileName, 2))
		{
			OnEvent(SEQEVT_SEQSTOP, NULL);
			return GMSYNTH_ERR_FILEOPEN;
		}
		inmgr.SetWaveOut(&wvf);
	}
	inmgr.Reset();
	seq.SequenceMulti(inmgr, stTime, endTime, seqMode);
	if (live)
	{
		bsInt32 drain = (bsInt32) (synthParams.sampleRate * (ldTm * 4));
		while (--drain > 0)
			inmgr.Tick();
		CloseWaveDevice();
	}
	else
		wvf.CloseWaveFile();
	return GMSYNTH_NOERROR;
}
Пример #13
0
int GameState::Execute() {
    //Initialize all
    if(!Init()) return -1;

    SDL_Event ev;

    //Game loop
    while(GameRunning) {
        while(SDL_PollEvent(&ev)) {
            OnEvent(&ev);
        }
        Update();
        Render();

        if (FPS::FPSControl.GetFPS() > 200) SDL_Delay(3); //Tiny delay if computer is giving high fps. No need for super high fps.
        if (temp_delay > 0) {
            SDL_Delay(temp_delay);
            temp_delay = 0;
        }
    }

    //Cleanup memory and shut down
    Cleanup();
    return 0;
}
Пример #14
0
int CApp::OnExecute(int argc, char **argv) {
	if(OnInit(argc, argv) == false) {
		return -1;
	}

	SDL_Event Event;
	bool calculatedFrame;
    while(Running) {
		//BulletManager::Step();

		while(SDL_PollEvent(&Event)) 
		{
			OnEvent(&Event);
		}
		calculatedFrame= false;
		while ((SDL_GetTicks() - GameBaseTime) > GameTickLength)
		{
			gameTime = SDL_GetTicks() / 1000.0f;
			GameBaseTime += GameTickLength;
			OnUpdate();
			calculatedFrame = true;
		}

		BulletManager::Step();

		OnDraw();

    }
 
    OnCleanup();
 
    return 0;
}
Пример #15
0
	void App::Execute()
	{
		if (m_state != GameState::INIT_SUCCESSFUL)
		{
			std::cerr << "Game INIT was not successful." << std::endl;
			return;
		}

		m_state = GameState::RUNNING;

		SDL_Event event;
		while (m_state == GameState::RUNNING)
		{
			// Input polling
			//
			while (SDL_PollEvent(&event))
			{
				OnEvent(&event);
			}

			//
			Update();
			Render();
		}
	}
Пример #16
0
//---------------------------------------------------------------------------
void TCustomMsgServer::DoEvent(int Sender, longword Code, word RetCode, word Param1, word Param2, word Param3, word Param4) 
{
    TSrvEvent SrvEvent;
    bool GoLog = (Code & LogMask) != 0;
    bool GoEvent = (Code & EventMask) != 0;

    if (!Destroying && (GoLog || GoEvent))
    {
        CSEvent->Enter();

        time(&SrvEvent.EvtTime);
        SrvEvent.EvtSender = Sender;
        SrvEvent.EvtCode = Code;
        SrvEvent.EvtRetCode = RetCode;
        SrvEvent.EvtParam1 = Param1;
        SrvEvent.EvtParam2 = Param2;
        SrvEvent.EvtParam3 = Param3;
        SrvEvent.EvtParam4 = Param4;

        if (GoEvent && (OnEvent != NULL))
            try
            { // callback is outside here, we have to shield it
                OnEvent(FUsrPtr, &SrvEvent, sizeof (TSrvEvent));
            } catch (...)
            {
            };

        if (GoLog)
            FEventQueue->Insert(&SrvEvent);

        CSEvent->Leave();
    };
}
Пример #17
0
void Loop::Run()
{
    Debug::Log("Enter loop");
    char buffer[64];

    while(running)
    {
        while(SDL_PollEvent(&event))
        {
            //Calls the redefined event function for the class
            OnEvent(&event);
        }
        Update();

        //Calls the redefined Draw function for the class
        Draw(); 
			
		FPS::Update();
		FPS::PrintFPS();

		Graphics::Flip();
    }

    Debug::Log("Exit Loop");
}
Пример #18
0
 virtual void OnConnectedToServer(int id, const std::string& name) {
     EventObserverInterface* delegated;
     if ((delegated = EventObserverInterfaceDelegated()))
         delegated->OnConnectedToServer(id, name);
     else
     OnEvent("ConnectedToServer"); 
 }
Пример #19
0
void CApplication::MainLoop()
{
    SDL_Event event;
    Uint32 startTime, elapsedTime;

    while( !m_Quit )
    {
        // Le temps avant l'éxécution
        startTime = SDL_GetTicks();
        // Tant qu'il y a des messages, les traiter
        while( SDL_PollEvent(&event) )
        {
            OnEvent(event);
        }
        // Mise à jour de la scène
        OnUpdate();
        // Démarrer le rendu
        m_Renderer.BeginScene();
        OnRender();
        m_Renderer.EndScene();

        // Si on a mis moins de temps que le nombre de FPS demandé, on attend
        // permet de limiter les fps et de gagner du temps de process CPU
        if( (elapsedTime = SDL_GetTicks()-startTime) < m_FPSLimit )
        {
            SDL_Delay(m_FPSLimit - elapsedTime);
        }
    }
}
Пример #20
0
uint32 UPawnActionsComponent::AbortActionsInstigatedBy(UObject* const Instigator, EAIRequestPriority::Type Priority)
{
    uint32 AbortedActionsCount = 0;

    if (Priority == EAIRequestPriority::MAX)
    {
        // call for every regular priority
        for (int32 PriorityIndex = 0; PriorityIndex < EAIRequestPriority::MAX; ++PriorityIndex)
        {
            AbortedActionsCount += AbortActionsInstigatedBy(Instigator, EAIRequestPriority::Type(PriorityIndex));
        }
    }
    else
    {
        UPawnAction* Action = ActionStacks[Priority].GetTop();
        while (Action)
        {
            if (Action->GetInstigator() == Instigator)
            {
                OnEvent(*Action, EPawnActionEventType::InstantAbort);
                ++AbortedActionsCount;
            }
            Action = Action->ParentAction;
        }
    }

    return AbortedActionsCount;
}
Пример #21
0
int CApp::OnExecute()
{
	// Initialize application.
	int state = OnInit();
	if (state != APP_OK) {
		return state;
	}
	
	// Enter the SDL event loop.
	SDL_Event event;

	running = true;
	
	while (running)
	{
		while (SDL_PollEvent(&event)) {
        	OnEvent(&event);
        }
		
		OnUpdate();
		OnRender();
	}
	
	return state;
}
Пример #22
0
int CApp::OnExecute(){

    if (OnInit() == false){
        return -1;
    }

    SDL_Event Event;

    while(Running){

        while(SDL_PollEvent(&Event)){

            OnEvent(&Event);

        }

        OnLoop();
        OnRender();

    }


    OnCleanup();

    return 0;
}
Пример #23
0
void NET_Thread::Execute()
{
	m_executing = true;
	SetEvent(m_started_event);
	DWORD res, i;
	HANDLE one_event;
	while (true)
	{
		res = WaitForMultipleObjects(m_events_num, m_events, FALSE, INFINITE);
		if (res == WAIT_OBJECT_0)
			return;
		for (i = 0; i < m_events_num - 1; i++)
		{
			one_event = Event(i);
			if (res == WAIT_OBJECT_0 + (i + 1) || WaitForSingleObject(one_event, 0) == WAIT_OBJECT_0)
			{
				WSAResetEvent(one_event);
				{
					//MutexWrap socket_access(m_socket->m_socket_mutex);
					if (m_socket->m_created)
					{
						MutexWrap socket_access(m_socket->m_socket_mutex);
						OnEvent(i);
					}
				}
			}
		}
	}
	CRUSH("Wrong NET_Thread::Execute() exit");
}
Пример #24
0
void NetworkManager::Run()
{
	int threadId;
	struct epoll_event events[100];
	int numOfEvent, n;

	g_networkThreadCountLock.Lock();
	threadId = g_networkThreadCount++;
	g_networkThreadCountLock.Unlock();

	for(;;)
	{
		numOfEvent = epoll_wait(m_epollFdList[threadId], m_epollEvent2DList[threadId], 100, 2000);

		//printf("NW thread %d\n", threadId);
		if(numOfEvent < 0){	
			// critical error
			fprintf(stderr, "[ERROR] epoll_wait() ERROR : %s\n", strerror(errno));
			exit(1);
		}

		if(numOfEvent == 0)
		{
			continue;
		}

		//printf("NT %d activated\n", TC);
		OnEvent(numOfEvent, threadId);
	}
	close(m_serverFd);
	for(int i=0; i<NETWORK_THREAD_NUM; i++)
		close(m_epollFdList[i]);
}
Пример #25
0
//------------------------------------------------------------------------------
int CApp::OnExecute() {
    if(OnInit() == false) {
        return -1;
    }

    SDL_Event Event;

    while(Running) {
        if(AIenabled && CurrentPlayer && GameState == GAME_STATE_RUNNING)
        {
            GameClick(AIMove());
        }

        while(SDL_PollEvent(&Event)) {
            OnEvent(&Event);
        }

        OnLoop();
        OnRender();
    }

    OnCleanup();

    return 0;
}
Пример #26
0
	void Game::OnExecute()
	{
		if (m_state != GameState::INIT_SUCCESSFUL)
		{
			std::cerr << "Game INIT was not successful." << std::endl;
			return;
		}

		m_state = GameState::RUNNING;
		CreateAsteroid(Asteroids::Asteroid::AsteroidSize::BIG, 1);

		SDL_Event event;
		while (m_state == GameState::RUNNING)
		{
			// Input polling
			//
			while (SDL_PollEvent(&event))
			{
				OnEvent(&event);
			}

			//
			OnUpdate();
			OnRender();
		}
	}
Пример #27
0
int App::OnExecute()
{
    if(OnInit() == false)
    {
        return -1;
    }

	controller->Initialize();

    SDL_Event Event;
    while(running)
    {
        Scene* scene = controller->GetCurrentScene();
		if (scene == NULL)
		{
			break;
		}

        if(SDL_PollEvent(&Event))
        {
            OnEvent(scene, &Event);
        }

        OnLoop(scene);
        OnRender(scene);
    }

    OnCleanup();

    return 0;
}
Пример #28
0
void game_sv_GameState::ProcessDelayedEvent		()
{
	GameEvent* ge = NULL;
	while ((ge = m_event_queue->Retreive()) != 0) {
		OnEvent(ge->P,ge->type,ge->time,ge->sender);
		m_event_queue->Release();
	}
}
Пример #29
0
void Control::AttachChild(const ControlHandle& child)
{
	mChilds.InsertBack(child);

	mChilds.Back()->SetParent(this);
	mChilds.Back()->SetFocused(false);

	OnEvent(EventGotChild,(WPARAM)child);
}
Пример #30
0
void GUIAppListBox::FocusSelection () {
    if ( objects.Count()) {
        float sy = objects[selectIndex]->rect.y1 - rect.y1;
        if ( sy <= sepHeight || sy > (clipHeight-sepHeight) ) {
            vscroll->SetValue(vscroll->GetValue() + sy);
            OnEvent(VSCROLL);
        }
    }
}