Beispiel #1
0
void ProcessFrame(){ //process a frame of animation
  const int LOGO_DISPLAY_TIME=5500; //duration of logo
  const int TITLE_DISPLAY_TIME=20000; //duration of title
  static int not_first = 0;
  static int last_time = Timer.time();
  
  //check for lost surfaces, eg alt+tab
  if(lpPrimary->IsLost()){
    RestoreSurfaces(); Redraw();
  }
  


  switch(GamePhase){ //what phase are we in?
    case LOGO_PHASE: //displaying logo screen
      Sleep(100); //surrender time to other processes
      if(endphase||Timer.elapsed(PhaseTime,LOGO_DISPLAY_TIME))
        change_phase(TITLE_PHASE); //go to title screen
      break;
    case TITLE_PHASE: //displaying title screen
      Sleep(100); //surrender time to other processes
      if(endphase||Timer.elapsed(PhaseTime,TITLE_DISPLAY_TIME))
        change_phase(MENU_PHASE); //go to menu
      break;
	case HELP_PHASE: if(endphase)
					  change_phase(ENEMY_PHASE); //go to menu
    case ENEMY_PHASE: if(endphase)
					  change_phase(MENU_PHASE); //go to menu
      
    case MENU_PHASE: //main menu
	
      Sleep(100); //surrender time to other processes
      if(endphase){
		  if(not_first){
		   CurrentLevel = 0;
		  theObjects.reset(0);
		  }
		  else{
			   not_first = 1;

		  }

		  change_phase(PLAYING_PHASE); //play game
	  }
      break;
    case PLAYING_PHASE: //game engine
	  
		if(Timer.elapsed(last_time,35)){
			if(mouse_mode){
			g_input.Update();	//update the input
			ProcessInput();	//process it
			}
			last_time = Timer.time();
		}

	  ComposeFrame(); //compose a frame in back surface
	  //PutText(temp.c_str(),lpPrimary);
      if(endphase) 
        change_phase(MENU_PHASE); 
	  if(theObjects.lives_remaining < 0){

		  change_phase(GAMEOVER_PHASE);
	  }
	  if(theObjects.won()) {
		 //change_phase(MENU_PHASE);
		  theObjects.reset(++CurrentLevel);
	  }
	  
	  
	  
      break;
	case GAMEOVER_PHASE:
		Sleep(100);
		if(endphase){
			change_phase(MENU_PHASE);
		}
		break;
	default: break;
  }
} //ProcessFrame
Beispiel #2
0
/**
 * Use DirectDraw to return an HDC object for invoking GDI functions
 * on the pixel buffer (could be a screen back buffer or a
 * MIDP off-screen image). The horizontal pitch is assumed to
 * be the same as the (width * sizeof(gxj_pixel_type).
 */
HDC getScreenBufferHDC(gxj_pixel_type *buffer, int width, int height) {
#if JWC_WINCE_USE_DIRECT_DRAW
    /*  pDDS and cachedHDC must both be NULL or both be non-NULL */
    static LPDIRECTDRAWSURFACE pDDS = NULL;
    static HDC cachedHDC = NULL;
    static gxj_pixel_type *cachedBuffer;

    DDSURFACEDESC ddsd;
    HRESULT hRet;

    if (buffer == cachedBuffer && cachedHDC != NULL && !pDDS->IsLost()) {
        /* Note: after screen rotation has happened, the pDDS surface may
         * be lost, even if it's using a client-defined pixel buffer!
         */
        return cachedHDC;
    }

    if (pDDS != NULL && (buffer != cachedBuffer || pDDS->IsLost())) {
        pDDS->ReleaseDC(cachedHDC);
        pDDS->Release();
        pDDS = NULL;
        cachedHDC = NULL;
    }

    ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE |
                   DDSD_PITCH | DDSD_PIXELFORMAT | DDSD_CAPS;
    ddsd.dwWidth = width;
    ddsd.dwHeight= height;
    ddsd.lPitch  = (LONG)sizeof(gxj_pixel_type) * width;
    ddsd.lpSurface = buffer;
    ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;

    /* Set up the pixel format for 16-bit RGB (5-6-5). */
    ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
    ddsd.ddpfPixelFormat.dwFlags= DDPF_RGB;
    ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
    ddsd.ddpfPixelFormat.dwRBitMask    = 0x1f << 11;
    ddsd.ddpfPixelFormat.dwGBitMask    = 0x3f << 5;
    ddsd.ddpfPixelFormat.dwBBitMask    = 0x1f;

    /* Create the surface */
    hRet = g_pDD->CreateSurface(&ddsd, &pDDS, NULL);
    if (hRet != DD_OK) {
        pDDS = NULL;
        cachedHDC = NULL;
        return NULL;
    }

    hRet = pDDS->GetDC(&cachedHDC);
    if (hRet != DD_OK) {
        pDDS->Release();
        pDDS = NULL;
        cachedHDC = NULL;
        return NULL;
    }

    cachedBuffer = buffer;
    return cachedHDC;
#endif /* JWC_WINCE_USE_DIRECT_DRAW */
    return NULL;
}
Beispiel #3
0
/********************************************************************
* Function : SimLoop()
* Purpose : Performs a single Simulation Loop iteration. Includes
*           drawing.
********************************************************************/
int SimLoop(void)
{
	static int nFramesPerSecond = 0;
	static int nFramesSinceLastTick;
	static DWORD LastTicks = 0;
	DWORD Ticks;
	HDC hDC;
	HFONT hOldFont;
	char s[80];
	int slen;

	DDSURFACEDESC ddsd;
	DDBLTFX	BltFx;
	HRESULT ddreturn;

	/* Perform a single step in our world. */
	if (StepWorld(bForwardKey, bBackKey, bLeftKey, bRightKey, nState, nGauge))
	{
		if (lpPrimary->IsLost() == DDERR_SURFACELOST)
			lpPrimary->Restore();

		/* Clear the backbuffer. */
#if CLEARBCKGRND
		BltFx.dwSize = sizeof(BltFx);
		BltFx.dwFillColor = 255;
		ddreturn = lpBackbuffer->Blt(NULL,
											  NULL,
											  NULL,
											  DDBLT_COLORFILL | DDBLT_WAIT,
											  &BltFx);
#else
		ddreturn = DD_OK;
#endif
		if (ddreturn == DD_OK)
		{	/* While this is running, prepare
			 * the drawing. */
			if (PrepDrawWorld())
			{
				/* Lock the surface. */
				memset(&ddsd, 0, sizeof(DDSURFACEDESC));
				ddsd.dwSize = sizeof(ddsd);
				ddreturn = lpBackbuffer->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL);
				if (ddreturn == DD_OK)
				{
					DrawWorld((unsigned char *)ddsd.lpSurface, (int)ddsd.lPitch);

					int nX, nY;
					static unsigned char dummy;
					unsigned char ni;
					ni = 0;
					for (nY = 0; nY < 16; nY++)
						for (nX = 0; nX < 16; nX++)
						{
							/* Draw a small block at (nX * 3, nY * 3) */
							((unsigned char *)ddsd.lpSurface)[(nY * 3 * ddsd.lPitch) + (nX * 3)] = ni;
							((unsigned char *)ddsd.lpSurface)[(nY * 3 * ddsd.lPitch) + (nX * 3 + 1)] = ni;
							((unsigned char *)ddsd.lpSurface)[((nY * 3 + 1) * ddsd.lPitch) + (nX * 3)] = ni;
							((unsigned char *)ddsd.lpSurface)[((nY * 3 + 1) * ddsd.lPitch) + (nX * 3 + 1)] = ni;
							ni++;
						}
					lpBackbuffer->Unlock(NULL);

					/* And now write Frames per second. */
					/* Increment Frame counter. */
					nFramesSinceLastTick++;
					/* Get system tick count. */
					Ticks = GetTickCount();
					/* Update fps value every second. */
					if (Ticks > (LastTicks + 1000))
					{	nFramesPerSecond = nFramesSinceLastTick;
						nFramesSinceLastTick = 0;
						LastTicks = Ticks;
					}

					/* Get a DC to the buffer & write count. */
					if (DD_OK == lpBackbuffer->GetDC(&hDC))
					{	
						SetBkMode(hDC, TRANSPARENT);
						hOldFont = SelectObject(hDC, AppFont);
						/* Build a string for display. */
						slen = wsprintf(s, "FPS : %d", nFramesPerSecond);
						/* And draw the text. */
						SetTextColor(hDC, RGB(0,0,0));
						SIZE sz;
						GetTextExtentPoint32(hDC, s, slen, &sz);
						RECT rc;
						rc.top = 0;
						rc.left = 16 * 3;
						rc.right = 16 * 3 + sz.cx + 10;
						rc.bottom = sz.cy + 10;
						DrawFrameControl(hDC, &rc, DFC_BUTTON, DFCS_BUTTONPUSH);
						TextOut(hDC, 16*3 + 5, 5, s, slen);
						SelectObject(hDC, hOldFont);
						lpBackbuffer->ReleaseDC(hDC);
					}
					/* Perform required pageflipping to make the surface
					 * we drawed visible. */
					ddreturn = lpPrimary->Flip(NULL, DDFLIP_WAIT);
					if (ddreturn == DD_OK)
					{
						return 1;
					}
				} 
			}
		}
	}

	return 0;
}