Exemplo n.º 1
0
void ImportBinary(void)
{
	// Import the Polygon list from a binary file
	std::fstream Input("SaveFile.tie", std::ios_base::binary | std::ios_base::in);
	if (Input.bad())		return;
	if (!Input.good())		return;
	for (unsigned int i = 0; i < POLYGON_COUNT; i++) Input.read((char*)&PolygonList[i], sizeof(Poly));
	Input.close();

	// Clear the Evolve surface and allow a new fitness to be calculated
	ClearSurface(Evolve);
	Fitness = 0.0;
	
	printf("\n\n\nTriangle List Imported!");

	// Normally after this occurs, a single mutation would be set and the resulting fitness would be higher than
	// what is was before importing. To prevent this, calculate the fitness before returning to the loop
	
	// Draw the Evolve Image
	ClearSurface(Evolve);
	for (unsigned int i = 0; i < POLYGON_COUNT; i++)
		if (PolygonList[i].BitFlag & DEFINED_BIT)
			filledPolygonRGBA(Evolve, PolygonList[i].X, PolygonList[i].Y, VERTEX_COUNT, PolygonList[i].Color[0], PolygonList[i].Color[1], PolygonList[i].Color[2], PolygonList[i].Color[3]);

	Fitness = CalculateFitness();
	memcpy((void*)((Uint32*)Best->pixels), (void*)((Uint32*)Evolve->pixels), Evolve->pitch * Evolve->h);

	GoodMutations = 0;
	Mutations = 0;
	Attempts = 0;
	OpeningTick = SDL_GetTicks();
	OutputInformation(Fitness, GoodMutations, Mutations, Attempts, 0.0);
}
Exemplo n.º 2
0
bool C4MapScriptLayer::CreateSurface(int32_t wdt, int32_t hgt)
{
	// Create new surface of given size. Surface is filled with color 0
	ClearSurface();
	if (wdt<=0 || hgt<=0) return false;
	fg_surface = std::make_unique<CSurface8>();
	bg_surface = std::make_unique<CSurface8>();
	if (!fg_surface->Create(wdt, hgt) || !bg_surface->Create(wdt, hgt))
	{
		ClearSurface();
		return false;
	}
	UpdateSurfaceSize();
	return true;
}
Exemplo n.º 3
0
static void Close(vout_display_t *vd)
{
    vout_display_sys_t *sys = vd->sys;

    /* Check if SPU regions have been properly cleared, and clear them if they
     * were not. */
    if (sys->b_has_subpictures)
    {
        SubpicturePrepare(vd, NULL);
        AndroidWindow_UnlockPicture(sys, sys->p_sub_window, sys->p_sub_pic);
    }

    if (sys->pool)
        picture_pool_Release(sys->pool);

    if (sys->p_window)
    {
        if (sys->b_displayed)
            ClearSurface(vd);
        AndroidWindow_Destroy(vd, sys->p_window);
    }

    if (sys->p_sub_pic)
        picture_Release(sys->p_sub_pic);
    if (sys->p_spu_blend)
        filter_DeleteBlend(sys->p_spu_blend);
    free(sys->p_sub_buffer_bounds);
    if (sys->p_sub_window)
        AndroidWindow_Destroy(vd, sys->p_sub_window);

    if (sys->embed)
        AWindowHandler_setVideoLayout(sys->p_awh, 0, 0, 0, 0, 0, 0);

    free(sys);
}
void	CMissionText::Init()
{
	m_lfDrawData.dwFlags = LTF_DRAW_TIMED | LTF_DRAW_FORMATTED | LTF_TIMED_ALL | LTF_EXTRA_LOCKLAST;
	m_lfDrawData.byJustify = LTF_JUSTIFY_LEFT;
    m_lfDrawData.dwFormatWidth      = (uint32)g_pLayoutMgr->GetMissionTextWidth();
	m_lfDrawData.fLetterDelay		= g_pLayoutMgr->GetMissionTextLetterDelay();
	m_lfDrawData.fLineDelay			= g_pLayoutMgr->GetMissionTextLineDelay();
	m_lfDrawData.fLineScrollTime	= g_pLayoutMgr->GetMissionTextLineScrollTime();
	m_lfDrawData.hColor				= kWhite;

	m_fFadeTime			= g_pLayoutMgr->GetMissionTextFadeTime();
	m_fDelay			= m_fFadeTime + g_pLayoutMgr->GetMissionTextFadeDelay();

	m_pos				= g_pLayoutMgr->GetMissionTextPos();

	m_nLineHeight		= g_pInterfaceResMgr->GetMsgForeFont()->GetHeight();
	int numLines		= g_pLayoutMgr->GetMissionTextNumLines();

	m_dwWidth = m_lfDrawData.dwFormatWidth + 2;
    m_dwHeight = (uint32) (numLines * m_nLineHeight) + 16;

	m_nCursorPos = (int)m_dwHeight - m_nLineHeight;

    m_hForeSurf = g_pLTClient->CreateSurface(m_dwWidth,m_dwHeight);

	ClearSurface();
    g_pLTClient->OptimizeSurface(m_hForeSurf,LTNULL);

	g_pLayoutMgr->GetMissionTextTypeSound(m_TypeSound,sizeof(m_TypeSound));
	g_pLayoutMgr->GetMissionTextScrollSound(m_ScrollSound,sizeof(m_ScrollSound));

	
}
static void SurfaceToMetaTriangles( mapDrawSurface_t *ds ){
	int i;
	metaTriangle_t src;
	bspDrawVert_t a, b, c;


	/* only handle certain types of surfaces */
	if ( ds->type != SURFACE_FACE &&
		 ds->type != SURFACE_META &&
		 ds->type != SURFACE_FORCED_META &&
		 ds->type != SURFACE_DECAL ) {
		return;
	}

	/* speed at the expense of memory */
	firstSearchMetaVert = numMetaVerts;

	/* only handle valid surfaces */
	if ( ds->type != SURFACE_BAD && ds->numVerts >= 3 && ds->numIndexes >= 3 ) {
		/* walk the indexes and create triangles */
		for ( i = 0; i < ds->numIndexes; i += 3 )
		{
			/* sanity check the indexes */
			if ( ds->indexes[ i ] == ds->indexes[ i + 1 ] ||
				 ds->indexes[ i ] == ds->indexes[ i + 2 ] ||
				 ds->indexes[ i + 1 ] == ds->indexes[ i + 2 ] ) {
				//%	Sys_Printf( "%d! ", ds->numVerts );
				continue;
			}

			/* build a metatriangle */
			src.si = ds->shaderInfo;
			src.side = ( ds->sideRef != NULL ? ds->sideRef->side : NULL );
			src.entityNum = ds->entityNum;
			src.surfaceNum = ds->surfaceNum;
			src.planeNum = ds->planeNum;
			src.castShadows = ds->castShadows;
			src.recvShadows = ds->recvShadows;
			src.fogNum = ds->fogNum;
			src.sampleSize = ds->sampleSize;
			VectorCopy( ds->lightmapAxis, src.lightmapAxis );

			/* copy drawverts */
			memcpy( &a, &ds->verts[ ds->indexes[ i ] ], sizeof( a ) );
			memcpy( &b, &ds->verts[ ds->indexes[ i + 1 ] ], sizeof( b ) );
			memcpy( &c, &ds->verts[ ds->indexes[ i + 2 ] ], sizeof( c ) );
			FindMetaTriangle( &src, &a, &b, &c, ds->planeNum );
		}

		/* add to count */
		numMetaSurfaces++;
	}

	/* clear the surface (free verts and indexes, sets it to SURFACE_BAD) */
	ClearSurface( ds );
}
// Any user action will be stored in the engine, keyed on "action"
bool CWidgetDisplay::Display(SDL_Surface* pEntireScreen)
{
   if (m_bClearBackground)
      ClearSurface(pEntireScreen);

   CPaintingParms vParms;
   vParms.m_pDrawingSurface = pEntireScreen;
   vParms.m_vClippingRect.x = 0;
   vParms.m_vClippingRect.y = 0;
   vParms.m_vClippingRect.w = pEntireScreen->w;
   vParms.m_vClippingRect.h = pEntireScreen->h;
   PaintAllWidgets(&vParms, m_pEngine);

   bool bRepaint = false;
   m_pEngine->OnScreenStart(pEntireScreen, bRepaint);
   if (bRepaint)
      PaintAllWidgets(&vParms, m_pEngine);

   // Go into message loop
   int iLastUpdateTime = SDL_GetTicks();
   while (true)
   {
      SDL_Event vEvent;
      while (SDL_PollEvent(&vEvent))
      {
         if (!HandleEvent(vEvent, &vParms))
            return false;
      }

      CHTString sAction = m_pEngine->GetStringValue("action", false);
      if (sAction != "")
         break;

      if (SDL_GetTicks() - iLastUpdateTime > 200)
      {
         OnTimer(&vParms);
         iLastUpdateTime = SDL_GetTicks();
      }

      SDL_Delay(10);
   }

   m_pEngine->OnScreenEnd(pEntireScreen);

   return true;
}
Exemplo n.º 7
0
double CalculateFitness(void)
{
	double			Return;
	//unsigned char	Pixel[2];

	// Draw the Evolve Image
	ClearSurface(Evolve);
	for (unsigned int i = 0; i < POLYGON_COUNT; i++)
		if (PolygonList[i].BitFlag & DEFINED_BIT)
			filledPolygonRGBA(Evolve, PolygonList[i].X, PolygonList[i].Y, VERTEX_COUNT, PolygonList[i].Color[0], PolygonList[i].Color[1], PolygonList[i].Color[2], PolygonList[i].Color[3]);

	// Look through the pixels of both surfaces and determine the fitness of the evolving surface
	Return = 0;
	for (int y = 0; y < Target->h; y++)
		for (int x = 0; x < Target->w; x++)
		{
			ComparisonColor evolve_color(((unsigned char*)Evolve->pixels)[y * Target->pitch + x * TargetPixelSize], ((unsigned char*)Evolve->pixels)[y * Target->pitch + x * TargetPixelSize + 1], ((unsigned char*)Evolve->pixels)[y * Target->pitch + x * TargetPixelSize + 2]);
			ComparisonColor target_color(((unsigned char*)Target->pixels)[y * Target->pitch + x * TargetPixelSize], ((unsigned char*)Target->pixels)[y * Target->pitch + x * TargetPixelSize + 1], ((unsigned char*)Target->pixels)[y * Target->pitch + x * TargetPixelSize + 2]);
			Return += CompareColors(evolve_color, target_color, false);
			//// Red
			//Pixel[0] = ((unsigned char*)Target->pixels)[y * Target->pitch + x * TargetPixelSize];
			//Pixel[1] = ((unsigned char*)Evolve->pixels)[y * Evolve->pitch + x * EvolvePixelSize];
			//Return += (255 - abs((int)(Pixel[0] - Pixel[1]))) / 255.0;
			//
			//// Green
			//Pixel[0] = ((unsigned char*)Target->pixels)[y * Target->pitch + x * TargetPixelSize + 1];
			//Pixel[1] = ((unsigned char*)Evolve->pixels)[y * Evolve->pitch + x * EvolvePixelSize + 1];
			//Return += (255 - abs((int)(Pixel[0] - Pixel[1]))) / 255.0;
			//
			//// Blue
			//Pixel[0] = ((unsigned char*)Target->pixels)[y * Target->pitch + x * TargetPixelSize + 2];
			//Pixel[1] = ((unsigned char*)Evolve->pixels)[y * Evolve->pitch + x * EvolvePixelSize + 2];
			//Return += (255 - abs((int)(Pixel[0] - Pixel[1]))) / 255.0;
		}

	Return = (Return / (double)(Target->w * Target->h * 3) * 100.0);
	return Return;
}
void Intialize()
{
	Velocity = CreatePPSurface(g_iWidth, g_iHeight, 2);
	Density = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Pressure = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Temperature = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Divergence = CreateSurface(g_iWidth, g_iHeight, 3);

	/*Velocity2 = CreatePPSurface(g_iWidth, g_iHeight, 2);
	Density2 = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Pressure2 = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Temperature2 = CreatePPSurface(g_iWidth, g_iHeight, 1);
	Divergence2 = CreateSurface(g_iWidth, g_iHeight, 3);*/

	InitOps();
	DrawProgram = CreateProgram("Vertex.ver","Visualize.frag");
	Boundaries = CreateSurface(g_iWidth, g_iHeight, 3);
	CreateBoundaries(Boundaries, g_iWidth, g_iHeight);
	VertexQuad = DrawQuad();
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	ClearSurface(Temperature.Ping, AmbientTemperature);
	/*ClearSurface(Temperature2.Ping, AmbientTemperature);*/

}
Exemplo n.º 9
0
Arquivo: fog.c Projeto: Elzair/q3map2
qboolean ChopFaceSurfaceByBrush( entity_t *e, mapDrawSurface_t *ds, brush_t *b ){
	int i, j;
	side_t              *s;
	plane_t             *plane;
	winding_t           *w;
	winding_t           *front, *back;
	winding_t           *outside[ MAX_BRUSH_SIDES ];
	int numOutside;
	mapDrawSurface_t    *newds;


	/* dummy check */
	if ( ds->sideRef == NULL || ds->sideRef->side == NULL ) {
		return qfalse;
	}

	/* initial setup */
	w = WindingFromDrawSurf( ds );
	numOutside = 0;

	/* chop by each brush side */
	for ( i = 0; i < b->numsides; i++ )
	{
		/* get brush side and plane */
		s = &b->sides[ i ];
		plane = &mapplanes[ s->planenum ];

		/* handle coplanar outfacing (don't fog) */
		if ( ds->sideRef->side->planenum == s->planenum ) {
			return qfalse;
		}

		/* handle coplanar infacing (keep inside) */
		if ( ( ds->sideRef->side->planenum ^ 1 ) == s->planenum ) {
			continue;
		}

		/* general case */
		ClipWindingEpsilonStrict( w, plane->normal, plane->dist, ON_EPSILON, &front, &back ); /* strict; if plane is "almost identical" to face, both ways to continue can be wrong, so we better not fog it */
		FreeWinding( w );

		if ( back == NULL ) {
			/* nothing actually contained inside */
			for ( j = 0; j < numOutside; j++ )
				FreeWinding( outside[ j ] );
			return qfalse;
		}

		if ( front != NULL ) {
			if ( numOutside == MAX_BRUSH_SIDES ) {
				Error( "MAX_BRUSH_SIDES" );
			}
			outside[ numOutside ] = front;
			numOutside++;
		}

		w = back;
	}

	/* fixme: celshaded surface fragment errata */

	/* all of outside fragments become seperate drawsurfs */
	numFogFragments += numOutside;
	s = ds->sideRef->side;
	for ( i = 0; i < numOutside; i++ )
	{
		newds = DrawSurfaceForSide( e, ds->mapBrush, s, outside[ i ] );
		newds->fogNum = ds->fogNum;
		FreeWinding( outside[ i ] );
	}

	/* ydnar: the old code neglected to snap to 0.125 for the fragment
	          inside the fog brush, leading to sparklies. this new code does
	          the right thing and uses the original surface's brush side */

	/* build a drawsurf for it */
	newds = DrawSurfaceForSide( e, ds->mapBrush, s, w );
	if ( newds == NULL ) {
		return qfalse;
	}

	/* copy new to original */
	ClearSurface( ds );
	memcpy( ds, newds, sizeof( mapDrawSurface_t ) );

	/* didn't really add a new drawsurface... :) */
	numMapDrawSurfs--;

	/* return ok */
	return qtrue;
}
Exemplo n.º 10
0
int main(int argc, char ** argv)
{
  SDL_Surface * psdlsScreen     = NULL;
  SDL_Surface * psdlsWMIcon     = NULL;
  int           nVideoMode      = MODE_WINDOWED;
  bool          bDone           = false;
  char          szFilename[512] = {"default.lvl\0"};
  
  Level         level("fuckyou");
  Cursor        cursor(0, 0);
  Hud           hud;


  // deal with command line shit
  if(argc > 2)
  {
    ShowUsage();
    exit(1);
  }
  if(argc == 2)
  {
    if(!strcmp("--help", argv[1]) || !strcmp("-h", argv[1]) || !strcmp("-help", argv[1]))
    {
      ShowUsage();
      exit(0);
    }
    sprintf(szFilename, "%s", argv[1]);
    if(!level.ReadFromFile(szFilename))
      fprintf(stderr, "Couldn't read level from: %s, assuming file doesn't exist yet\n", szFilename);
    else
      fprintf(stderr, "Level read successfully from: %s\n", szFilename);
  }
  else
    fprintf(stderr, "No file name specified, using: %s\n", szFilename);
  
  InitSDL();
//  SetVideoMode(psdlsScreen, nVideoMode);

  fprintf(stderr, "Setting window icon... ");
  psdlsWMIcon = SDL_LoadBMP(LoadResource("bomn32.bmp", RESOURCE_GRAPHIC));
  if(psdlsWMIcon)
  {
    Uint32 colorkey;
    colorkey = SDL_MapRGB(psdlsWMIcon->format, 0, 0, 0);
    SDL_SetColorKey(psdlsWMIcon, SDL_SRCCOLORKEY, colorkey);
    SDL_WM_SetIcon(psdlsWMIcon, NULL);
    fprintf(stderr, "Success!\n");
  }
  else
    fprintf(stderr, "AW JUNK! Something fishy happened...\n");
  
  // can't f*****g use SetVideoMode here, for SOME REASON
  fprintf(stderr, "Setting video mode to 800x600 %s mode... ", (nVideoMode == MODE_WINDOWED ? "windowed" : "fullscreen"));
  SDL_WM_SetCaption("Bomns for Linux Level Editor", "Bomns for Linux Level Editor");
  if(nVideoMode == MODE_WINDOWED)
    psdlsScreen = SDL_SetVideoMode(800, 600, 0, SDL_HWSURFACE | SDL_DOUBLEBUF); 
  else if(nVideoMode == MODE_FULLSCREEN)
    psdlsScreen = SDL_SetVideoMode(800, 600, 0, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
  else
    QuitWithError("Que?\n");
  if(!psdlsScreen)
    QuitWithError("Error setting GODDAM VIDEO MODE... for some f*****g reason!\n");
  else
    fprintf(stderr, "Success!\n");
  SDL_ShowCursor(false);

  // do this here so the surfaces can read the display format
  cursor.CreateSurfaces();
  hud.CreateSurfaces();
  level.CreateSurfaces();
  
  // main input loop
  while(!bDone)
  {
    SDL_Event sdleEvent;
    Uint8 *   anKeyState  = NULL;
    Uint8     nMouseState = 0;

    while(SDL_PollEvent(&sdleEvent))
    {
      if(sdleEvent.type == SDL_QUIT)
        bDone = true;

      // TODO: use relative mouse motion so it doesn't jump around
      if(sdleEvent.type == SDL_MOUSEMOTION)
        cursor.SetPosition(sdleEvent.motion.x / 10, sdleEvent.motion.y / 10);

      // process mouse input
      nMouseState = SDL_GetMouseState(NULL, NULL);
      if(nMouseState & SDL_BUTTON_LMASK)
        cursor.StampCurrentObject(&level);
      if(nMouseState & SDL_BUTTON_RMASK)
        cursor.DeleteUnderCursor(&level);

      if(sdleEvent.type == SDL_MOUSEBUTTONDOWN)
      {
        switch(sdleEvent.button.button)
        {
          case SDL_BUTTON_WHEELUP:
            cursor.ForwardObject();
            break;
          case SDL_BUTTON_WHEELDOWN:
            cursor.BackwardObject();
            break;
        }
      }
      
      // process keyboard state data
      anKeyState = SDL_GetKeyState(NULL);
      
      if(anKeyState[SDLK_UP])
        cursor.MoveUp();
      if(anKeyState[SDLK_DOWN])
        cursor.MoveDown();
      if(anKeyState[SDLK_LEFT])
        cursor.MoveLeft();
      if(anKeyState[SDLK_RIGHT])
        cursor.MoveRight();

      if(anKeyState[SDLK_SPACE] || anKeyState[SDLK_RETURN] || anKeyState[SDLK_s])
        cursor.StampCurrentObject(&level);
      if(anKeyState[SDLK_DELETE] || anKeyState[SDLK_d])
        cursor.DeleteUnderCursor(&level);

      if(anKeyState[SDLK_PAGEUP])
        cursor.ForwardObject();
      if(anKeyState[SDLK_PAGEDOWN])
        cursor.BackwardObject();

      // 1 - 9 keys select object
      if(anKeyState[SDLK_1])
        cursor.SelectObject(0);
      if(anKeyState[SDLK_2])
        cursor.SelectObject(1);
      if(anKeyState[SDLK_3])
        cursor.SelectObject(2);
      if(anKeyState[SDLK_4])
        cursor.SelectObject(3);
      if(anKeyState[SDLK_5])
        cursor.SelectObject(4);
      if(anKeyState[SDLK_6])
        cursor.SelectObject(5);
      if(anKeyState[SDLK_7])
        cursor.SelectObject(6);
      if(anKeyState[SDLK_8])
        cursor.SelectObject(7);
      if(anKeyState[SDLK_9])
        cursor.SelectObject(8);

      // buttons that should only be pressed, never held down (keyboard event data)
      if(sdleEvent.key.state == SDL_PRESSED)
      {
        switch(sdleEvent.key.keysym.sym)
        {
          case SDLK_ESCAPE:
            bDone = true;
            break;

          case SDLK_f:
            nVideoMode = !nVideoMode;
            SetVideoMode(psdlsScreen, nVideoMode);
            break;

          case SDLK_l:
            char szTmp[520];
            sprintf(szTmp, "bomns %s", szFilename);
            if(!level.WriteToFile(szFilename))
              fprintf(stderr, "Error writing level to: %s\n", szFilename);
            else
              fprintf(stderr, "Level written successfully to: %s\n", szFilename);

            // can't do this while editor is in fullscreen without a pretty big crash
            if(nVideoMode == MODE_FULLSCREEN) // not changing the nVideoMode variable so down there...
              SetVideoMode(psdlsScreen, MODE_WINDOWED);
            
            fprintf(stderr, "Launching level in bomns...\n");
            system(szTmp);
            fprintf(stderr, "Back to editing!\n");
            
            if(nVideoMode == MODE_FULLSCREEN)  // ...we can just read it again and change accordingly
              SetVideoMode(psdlsScreen, nVideoMode);
            break;

          case SDLK_F2:
            if(!level.WriteToFile(szFilename))
              fprintf(stderr, "Error writing level to: %s\n", szFilename);
            else
              fprintf(stderr, "Level successfully written to: %s\n", szFilename);
            break;

          case SDLK_F12: // clear the level... F12 is hard to hit by mistake, right?
            level.DeleteLevel();
            break;

          default:
            break;
        }
      }
    } // SDL_PollEvent

    ClearSurface(psdlsScreen);

    if(!level.DrawLevel(psdlsScreen))
      QuitWithError("Error drawing level to screen!\n");

    if(!hud.DrawHUD(psdlsScreen, 0, 580))
      QuitWithError("Error drawing HUD to screen!\n");

    if(!cursor.DrawCursor(psdlsScreen))
      QuitWithError("Error drawing cursor to screen!\n");

    SDL_Flip(psdlsScreen);

  } // while(!bDone)
  
  ShutDown();

  return 0;
}
void Calculate(int data)
{

	glViewport(0, 0, g_iWidth, g_iHeight);

	Advect(Velocity.Ping, Velocity.Ping, Boundaries, Velocity.Pong, VelocityDissipation);
	SwapSurfaces(&Velocity);

	/*Advect(Velocity2.Ping, Velocity2.Ping, Boundaries, Velocity2.Pong, VelocityDissipation);
	SwapSurfaces(&Velocity2);*/

	Advect(Velocity.Ping, Temperature.Ping, Boundaries, Temperature.Pong, TemperatureDissipation);
    SwapSurfaces(&Temperature);

	/*Advect(Velocity2.Ping, Temperature2.Ping, Boundaries, Temperature2.Pong, TemperatureDissipation);
    SwapSurfaces(&Temperature2);*/

	Advect(Velocity.Ping, Density.Ping, Boundaries, Density.Pong, DensityDissipation);
    SwapSurfaces(&Density);

	/*Advect(Velocity2.Ping, Density2.Ping, Boundaries, Density2.Pong, DensityDissipation);
    SwapSurfaces(&Density2);*/
	
	glutMouseFunc(Mouse);

	ApplyBuoyancy(Velocity.Ping, Temperature.Ping, Density.Ping, Velocity.Pong, ax, ay);
    SwapSurfaces(&Velocity);

	/*ApplyBuoyancy2(Velocity.Ping, Temperature.Ping, Density.Ping, Velocity.Pong);
    SwapSurfaces(&Velocity);*/

	ApplyImpulse(Temperature.Ping, ImpulsePosition, ImpulseTemperature);
    ApplyImpulse(Density.Ping, ImpulsePosition, ImpulseDensity);

	/*ApplyImpulse(Temperature2.Ping, ImpulsePosition2, ImpulseTemperature);
    ApplyImpulse(Density2.Ping, ImpulsePosition2, ImpulseDensity);*/

	ComputeDivergence(Velocity.Ping, Boundaries, Divergence);
    ClearSurface(Pressure.Ping, 0);

	/*ComputeDivergence(Velocity2.Ping, Boundaries, Divergence2);
    ClearSurface(Pressure2.Ping, 0);*/

	for (int i = 0; i < NumJacobiIterations; ++i) {
        Jacobi(Pressure.Ping, Divergence, Boundaries, Pressure.Pong);
        SwapSurfaces(&Pressure);
    }

	/*for (int i = 0; i < NumJacobiIterations; ++i) {
        Jacobi(Pressure2.Ping, Divergence2, Boundaries, Pressure2.Pong);
        SwapSurfaces(&Pressure2);
    }*/

	SubtractGradient(Velocity.Ping, Pressure.Ping, Boundaries, Velocity.Pong);
    SwapSurfaces(&Velocity);

	/*SubtractGradient(Velocity2.Ping, Pressure2.Ping, Boundaries, Velocity2.Pong);
    SwapSurfaces(&Velocity2);*/

	glutPostRedisplay();
	glutTimerFunc(30, Calculate, 1);
}
Exemplo n.º 12
0
nsresult
imgFrame::InitWithDrawable(gfxDrawable* aDrawable,
                           const nsIntSize& aSize,
                           const SurfaceFormat aFormat,
                           SamplingFilter aSamplingFilter,
                           uint32_t aImageFlags)
{
  // Assert for properties that should be verified by decoders,
  // warn for properties related to bad content.
  if (!AllowedImageSize(aSize.width, aSize.height)) {
    NS_WARNING("Should have legal image size");
    mAborted = true;
    return NS_ERROR_FAILURE;
  }

  mImageSize = aSize;
  mFrameRect = IntRect(IntPoint(0, 0), aSize);

  mFormat = aFormat;
  mPaletteDepth = 0;

  RefPtr<DrawTarget> target;

  bool canUseDataSurface =
    gfxPlatform::GetPlatform()->CanRenderContentToDataSurface();

  if (canUseDataSurface) {
    // It's safe to use data surfaces for content on this platform, so we can
    // get away with using volatile buffers.
    MOZ_ASSERT(!mImageSurface, "Called imgFrame::InitWithDrawable() twice?");

    mVBuf = AllocateBufferForImage(mFrameRect.Size(), mFormat);
    if (!mVBuf) {
      mAborted = true;
      return NS_ERROR_OUT_OF_MEMORY;
    }

    int32_t stride = VolatileSurfaceStride(mFrameRect.Size(), mFormat);
    VolatileBufferPtr<uint8_t> ptr(mVBuf);
    if (!ptr) {
      mAborted = true;
      return NS_ERROR_OUT_OF_MEMORY;
    }

    mImageSurface = CreateLockedSurface(mVBuf, mFrameRect.Size(), mFormat);

    if (!mImageSurface) {
      NS_WARNING("Failed to create ImageSurface");
      mAborted = true;
      return NS_ERROR_OUT_OF_MEMORY;
    }

    if (!ClearSurface(mVBuf, mFrameRect.Size(), mFormat)) {
      NS_WARNING("Could not clear allocated buffer");
      mAborted = true;
      return NS_ERROR_OUT_OF_MEMORY;
    }

    target = gfxPlatform::GetPlatform()->
      CreateDrawTargetForData(ptr, mFrameRect.Size(), stride, mFormat);
  } else {
    // We can't use data surfaces for content, so we'll create an offscreen
    // surface instead.  This means if someone later calls RawAccessRef(), we
    // may have to do an expensive readback, but we warned callers about that in
    // the documentation for this method.
    MOZ_ASSERT(!mOptSurface, "Called imgFrame::InitWithDrawable() twice?");

    target = gfxPlatform::GetPlatform()->
      CreateOffscreenContentDrawTarget(mFrameRect.Size(), mFormat);
  }

  if (!target || !target->IsValid()) {
    mAborted = true;
    return NS_ERROR_OUT_OF_MEMORY;
  }

  // Draw using the drawable the caller provided.
  RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(target);
  MOZ_ASSERT(ctx);  // Already checked the draw target above.
  gfxUtils::DrawPixelSnapped(ctx, aDrawable, mFrameRect.Size(),
                             ImageRegion::Create(ThebesRect(mFrameRect)),
                             mFormat, aSamplingFilter, aImageFlags);

  if (canUseDataSurface && !mImageSurface) {
    NS_WARNING("Failed to create VolatileDataSourceSurface");
    mAborted = true;
    return NS_ERROR_OUT_OF_MEMORY;
  }

  if (!canUseDataSurface) {
    // We used an offscreen surface, which is an "optimized" surface from
    // imgFrame's perspective.
    mOptSurface = target->Snapshot();
  }

  // If we reach this point, we should regard ourselves as complete.
  mDecoded = GetRect();
  mFinished = true;

#ifdef DEBUG
  MonitorAutoLock lock(mMonitor);
  MOZ_ASSERT(AreAllPixelsWritten());
#endif

  return NS_OK;
}
Exemplo n.º 13
0
nsresult
imgFrame::InitForDecoder(const nsIntSize& aImageSize,
                         const nsIntRect& aRect,
                         SurfaceFormat aFormat,
                         uint8_t aPaletteDepth /* = 0 */,
                         bool aNonPremult /* = false */)
{
  // Assert for properties that should be verified by decoders,
  // warn for properties related to bad content.
  if (!AllowedImageAndFrameDimensions(aImageSize, aRect)) {
    NS_WARNING("Should have legal image size");
    mAborted = true;
    return NS_ERROR_FAILURE;
  }

  mImageSize = aImageSize;
  mFrameRect = aRect;

  mFormat = aFormat;
  mPaletteDepth = aPaletteDepth;
  mNonPremult = aNonPremult;

  if (aPaletteDepth != 0) {
    // We're creating for a paletted image.
    if (aPaletteDepth > 8) {
      NS_WARNING("Should have legal palette depth");
      NS_ERROR("This Depth is not supported");
      mAborted = true;
      return NS_ERROR_FAILURE;
    }

    // Use the fallible allocator here. Paletted images always use 1 byte per
    // pixel, so calculating the amount of memory we need is straightforward.
    size_t dataSize = PaletteDataLength() + mFrameRect.Area();
    mPalettedImageData = static_cast<uint8_t*>(calloc(dataSize, sizeof(uint8_t)));
    if (!mPalettedImageData) {
      NS_WARNING("Call to calloc for paletted image data should succeed");
    }
    NS_ENSURE_TRUE(mPalettedImageData, NS_ERROR_OUT_OF_MEMORY);
  } else {
    MOZ_ASSERT(!mImageSurface, "Called imgFrame::InitForDecoder() twice?");

    mVBuf = AllocateBufferForImage(mFrameRect.Size(), mFormat);
    if (!mVBuf) {
      mAborted = true;
      return NS_ERROR_OUT_OF_MEMORY;
    }

    mImageSurface = CreateLockedSurface(mVBuf, mFrameRect.Size(), mFormat);

    if (!mImageSurface) {
      NS_WARNING("Failed to create ImageSurface");
      mAborted = true;
      return NS_ERROR_OUT_OF_MEMORY;
    }

    if (!ClearSurface(mVBuf, mFrameRect.Size(), mFormat)) {
      NS_WARNING("Could not clear allocated buffer");
      mAborted = true;
      return NS_ERROR_OUT_OF_MEMORY;
    }
  }

  return NS_OK;
}
void	CMissionText::Update()
{
	if (m_bPause) return;
	if (!m_hText)
	{
		if(m_hSound)
		{
            g_pLTClient->KillSound(m_hSound);
            m_hSound = LTNULL;
		}
		return;
	}

	ClearSurface();
	g_pInterfaceResMgr->GetMsgForeFont()->Draw(m_hText, m_hForeSurf, &m_lfDrawData, 1, m_nCursorPos, &m_lfSaveData);
    g_pLTClient->OptimizeSurface(m_hForeSurf,LTNULL);

	m_fAlpha = 1.0f;

	switch (m_lfSaveData.byLastState)
	{
	case LTF_STATE_DRAW_UPDATING:
		{
			if(!m_hSound)
			{
				m_hSound = 	g_pClientSoundMgr->PlayInterfaceSound(m_TypeSound, (PLAYSOUND_LOOP | PLAYSOUND_GETHANDLE | PLAYSOUND_CLIENT));
			}
            m_bScrolling = LTFALSE;
		} break;

	case LTF_STATE_DRAW_LINE_DELAY:
		if(m_hSound)
		{
            g_pLTClient->KillSound(m_hSound);
            m_hSound = LTNULL;
		}
		break;
	case LTF_STATE_DRAW_SCROLLING:
		if(m_hSound)
		{
            g_pLTClient->KillSound(m_hSound);
            m_hSound = LTNULL;
		}
		if (!m_bScrolling)
		{
			g_pClientSoundMgr->PlayInterfaceSound(m_ScrollSound);
            m_bScrolling = LTTRUE;
		}
		break;

	case LTF_STATE_DRAW_FINISHED:
		{
            m_bScrolling = LTFALSE;
			if(m_hSound)
			{
                g_pLTClient->KillSound(m_hSound);
                m_hSound = LTNULL;
			}
            m_fTimeRemaining -= g_pGameClientShell->GetFrameTime();
			if (m_fTimeRemaining <= 0.0f)
			{
                g_pLTClient->FreeString(m_hText);
                m_hText = LTNULL;
			}
			else if (m_fTimeRemaining <= m_fFadeTime)
			{
				m_fAlpha = (m_fTimeRemaining / m_fFadeTime);
			}
		} break;
	}


}
Exemplo n.º 15
0
void TriangulatePatchSurface( mapDrawSurface_t *ds ){
	int iterations, x, y, pw[ 5 ], r;
	mapDrawSurface_t    *dsNew;
	mesh_t src, *subdivided, *mesh;


	/* try to early out */
	if ( ds->numVerts == 0 || ds->type != SURFACE_PATCH || patchMeta == qfalse ) {
		return;
	}

	/* make a mesh from the drawsurf */
	src.width = ds->patchWidth;
	src.height = ds->patchHeight;
	src.verts = ds->verts;
	//%	subdivided = SubdivideMesh( src, 8, 999 );
	iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions );
	subdivided = SubdivideMesh2( src, iterations ); //%	ds->maxIterations

	/* fit it to the curve and remove colinear verts on rows/columns */
	PutMeshOnCurve( *subdivided );
	mesh = RemoveLinearMeshColumnsRows( subdivided );
	FreeMesh( subdivided );
	//% MakeMeshNormals( mesh );

	/* make a copy of the drawsurface */
	dsNew = AllocDrawSurface( SURFACE_META );
	memcpy( dsNew, ds, sizeof( *ds ) );

	/* if the patch is nonsolid, then discard it */
	if ( !( ds->shaderInfo->compileFlags & C_SOLID ) ) {
		ClearSurface( ds );
	}

	/* set new pointer */
	ds = dsNew;

	/* basic transmogrification */
	ds->type = SURFACE_META;
	ds->numIndexes = 0;
	ds->indexes = safe_malloc( mesh->width * mesh->height * 6 * sizeof( int ) );

	/* copy the verts in */
	ds->numVerts = ( mesh->width * mesh->height );
	ds->verts = mesh->verts;

	/* iterate through the mesh quads */
	for ( y = 0; y < ( mesh->height - 1 ); y++ )
	{
		for ( x = 0; x < ( mesh->width - 1 ); x++ )
		{
			/* set indexes */
			pw[ 0 ] = x + ( y * mesh->width );
			pw[ 1 ] = x + ( ( y + 1 ) * mesh->width );
			pw[ 2 ] = x + 1 + ( ( y + 1 ) * mesh->width );
			pw[ 3 ] = x + 1 + ( y * mesh->width );
			pw[ 4 ] = x + ( y * mesh->width );    /* same as pw[ 0 ] */

			/* set radix */
			r = ( x + y ) & 1;

			/* make first triangle */
			ds->indexes[ ds->numIndexes++ ] = pw[ r + 0 ];
			ds->indexes[ ds->numIndexes++ ] = pw[ r + 1 ];
			ds->indexes[ ds->numIndexes++ ] = pw[ r + 2 ];

			/* make second triangle */
			ds->indexes[ ds->numIndexes++ ] = pw[ r + 0 ];
			ds->indexes[ ds->numIndexes++ ] = pw[ r + 2 ];
			ds->indexes[ ds->numIndexes++ ] = pw[ r + 3 ];
		}
	}

	/* free the mesh, but not the verts */
	free( mesh );

	/* add to count */
	numPatchMetaSurfaces++;

	/* classify it */
	ClassifySurfaces( 1, ds );
}