コード例 #1
0
ファイル: Application.cpp プロジェクト: jimmiebergmann/Space
	int Application::Run(const int p_Argc, char ** p_Argv)
	{
		// Load the application
		if (!Load(p_Argc, p_Argv))
		{
			std::cout << "Can't load the application." << std::endl;
			Unload();
			return 0;
		}

		// Run the applicaiton while the window is open.
		while (m_pRenderWindow->IsOpen())
		{
			// Update the window
			m_pRenderWindow->Update();

			// Check the window events.
			Bit::Event e;
			while (m_pRenderWindow->PollEvent(e))
			{
				HandleInputs(e);
			}

			// Render to the applications window.
			Render();
		}


		// Unload the application
		if (!Unload())
		{
			std::cout << "Could not unload the application." << std::endl;
		}

		// Exit the applicaiton.
		return 0;
	}
コード例 #2
0
ファイル: Core.cpp プロジェクト: eddietree/tiger
void Core::Run()
{
	VirtualMachine::Get()->RunMain();

	const float secPerFrame = 1.0f / float( m_fps );
	uint32_t msLimit = uint32_t(secPerFrame * 1000.0f);
	uint32_t msBeg = SDL_GetTicks();

	while (m_gameRunning)
	{
		// Calculate change of time
		uint32_t startMs = SDL_GetTicks();
		uint32_t deltaTicks = startMs - msBeg;
		float dt = float(deltaTicks) / 1000.0f;

		Timer timer;
		{
			HandleInputs();
			Update( dt );
			Render();
			ImguiManager::Get()->CleanUp();
		}
		m_msTotal = timer.GetTimeMs();
		m_fpsFrame = 1000.0f / m_msTotal;

		timer.Start();
		Renderer::Get()->Present();

		// Handle waiting so that frame ends correctly
		uint32_t endMs = SDL_GetTicks();
		uint32_t diffMs = endMs-startMs;
		uint32_t msLeftInFrame = msLimit - diffMs;
		while( msLimit > diffMs && SDL_GetTicks() - endMs < msLeftInFrame ) {;}
		msBeg = startMs;
	}	
}
コード例 #3
0
ファイル: game.cpp プロジェクト: naumazeredo/NAFW
bool Game::Run()
{
  SDL_assert(this->init_);

  // Testing area
  // -----

  // Physics
  physics_dt = 10;
  int physics_accum = 0;

  // FIXME networking must be in the network environment
  /*
  bool network_on = false;
  //int local_sequence = 0;
  //int remote_sequence = 0;
  int network_dt = 30;
  int network_accum = 0;
  */

  // Init timer
  timer_->Init();

  // FPS counter
  int framecount=0;
  int frametime=timer_->GetTime();

  bool quit = false;
  while (!quit)
  {
    // Update timer
    timer_->NextFrame();

    // Handle input when network is off
    //if (!network_on)
    {
      if (HandleInputs())
      {
        quit = true;
        break;
      }
    }

    // Networking
    // XXX All networking should be apart
    /*
    network_accum += timer_->GetDelta();
    while (network_on && network_accum >= network_dt)
    {
      // Networking
      // Server->Client
      // TODO Verify if received a socket

      // Client->Server
      if (network_accum >= network_dt)
      {
        // Handle User Inputs
        if (HandleInputs())
        {
          quit = true;

          // TODO Send disconnect to server
          break;
        }

        // TODO Send file

        // Update accumulator
        network_accum -= network_dt;
      }

      // TODO Send update to server
    }
    */

    // Update physics
    physics_accum += timer_->GetDelta();
    while (physics_accum >= physics_dt)
    {
      // Physics
      if (physics_accum >= physics_dt)
      {
        // Testing area
        //

        /* TODO Step physics */
        // Pass timer_->GetTime() + delta_physics to physics

        // Update accumulator
        physics_accum -= physics_dt;
      }
    }

    /* TODO Integrate the exceding time in physics */

    /* TODO Render */
    renderer_->ClearScreen();

    Draw();

    renderer_->RenderScreen();

    // FPS counter
    ++framecount;
    if (timer_->GetTime() - frametime >= 1000)
    {
      // Change window title
      std::ostringstream oss;
      oss << "Not Available Framework - FPS: " << framecount;
      SDL_SetWindowTitle(window_, oss.str().c_str());

      framecount = 0;
      frametime += 1000;
    }
  }

  // Finish game
  return false;
}
コード例 #4
0
ファイル: glow.cpp プロジェクト: vasilenkomike/xray
BOOL ImageFilter_Glow::Control(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)	{

    switch (message) {

    case WM_INITDIALOG:
        CenterWindow(hWnd,GetParent(hWnd));
        SetCursor(LoadCursor(NULL,IDC_ARROW));

        CheckRadioButton(
            hWnd,
            IDC_MTLID_BUTT,
            IDC_NODEID_BUTT,
            data.type
        );

        CheckRadioButton(
            hWnd,
            IDC_MTLCOLOR_BUTT,
            IDC_USERCOLOR_BUTT,
            data.colorsrc
        );

        colorSwatch = GetIColorSwatch(
                          GetDlgItem(hWnd, IDC_COLOR_SWATCH),
                          RGB(data.color.r>>8,data.color.g>>8,data.color.b>>8),
                          GetString(IDS_DB_GLOW_COLOR));

        mtlspin	= GetISpinner(GetDlgItem(hWnd, IDC_MTLID_SPIN));
        mtlspin->LinkToEdit( GetDlgItem(hWnd,IDC_MTLID_EDIT), EDITTYPE_INT );
        mtlspin->SetLimits(	0,15, FALSE );
        mtlspin->SetValue(data.mtl,FALSE);

        nodspin	= GetISpinner(GetDlgItem(hWnd, IDC_NODEID_SPIN));
        nodspin->LinkToEdit( GetDlgItem(hWnd,IDC_NODEID_EDIT), EDITTYPE_INT );
        nodspin->SetLimits(	1,65535, FALSE );
        nodspin->SetValue(data.node,FALSE);

        sizespin = GetISpinner(GetDlgItem(hWnd, IDC_SIZE_SPIN));
        sizespin->LinkToEdit( GetDlgItem(hWnd,IDC_SIZE_EDIT), EDITTYPE_INT );
        sizespin->SetLimits( 1,100, FALSE );
        sizespin->SetValue(data.size,FALSE);

        HandleInputs(hWnd);

        return 1;

    case WM_COMMAND:

        switch (LOWORD(wParam)) {

        case IDC_MTLID_BUTT:
        case IDC_NODEID_BUTT:
        case IDC_MTLCOLOR_BUTT:
        case IDC_USERCOLOR_BUTT:
            HandleInputs(hWnd);
            break;

        case IDOK:
            data.type= (IsDlgButtonChecked(hWnd,IDC_MTLID_BUTT) ? IDC_MTLID_BUTT : IDC_NODEID_BUTT);
            data.mtl= mtlspin->GetIVal();
            data.node= nodspin->GetIVal();
            data.size= sizespin->GetIVal();
            data.colorsrc= (IsDlgButtonChecked(hWnd, IDC_MTLCOLOR_BUTT) ? IDC_MTLCOLOR_BUTT : IDC_USERCOLOR_BUTT);
            colorref = colorSwatch->GetColor();
            data.color.r = GetRValue(colorref)<<8|0xFF;
            data.color.g = GetGValue(colorref)<<8|0xFF;
            data.color.b = GetBValue(colorref)<<8|0xFF;
            EndDialog(hWnd,1);
            break;

        case IDCANCEL:
            EndDialog(hWnd,0);
            break;

        }

        return 1;

    case WM_DESTROY:
        if (mtlspin) {
            ReleaseISpinner(mtlspin);
            mtlspin = NULL;
        }
        if (nodspin) {
            ReleaseISpinner(nodspin);
            nodspin = NULL;
        }
        if (sizespin) {
            ReleaseISpinner(sizespin);
            sizespin = NULL;
        }

        if (colorSwatch) {
            ReleaseIColorSwatch(colorSwatch);
            colorSwatch = NULL;
        }
        break;

    }

    return 0;

}