Advertisement
Guest User

Stonesense Rendering Optimization

a guest
Aug 14th, 2010
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.22 KB | None | 0 0
  1. void WorldSegment::drawAllBlocks()
  2. {
  3.  
  4.     // x,y,z print pricess
  5.     ALLEGRO_BITMAP * temp = al_get_target_bitmap();
  6.     int32_t vsxmax = viewedSegment->sizex-1;
  7.     int32_t vsymax = viewedSegment->sizey-1;
  8.     int32_t vszmax = viewedSegment->sizez-1; // grabbing one tile +z more than we should for tile rules
  9.     //al_hold_bitmap_drawing(true);
  10.     int op, src, dst, alpha_op, alpha_src, alpha_dst;
  11.     ALLEGRO_COLOR color;
  12.     al_get_separate_blender(&op, &src, &dst, &alpha_op, &alpha_src, &alpha_dst);
  13.     al_clear_to_color(al_map_rgb(config.fogr, config.fogg, config.fogb)); //Flicker Fix
  14.     //al_flip_display(); //Anti Flicker for Slow Debug Drawing
  15.     //al_clear_to_color(al_map_rgb(config.fogr, config.fogg, config.fogb)); // Same as above
  16.     for(int32_t vsz=0; vsz < vszmax; vsz++)
  17.     {
  18.         if(config.showRenderStatus)
  19.             SetTitle("Stonesense - Drawing Terrain, Level %d/%d", (vsz+1), vszmax);
  20.         if(config.fogenable && config.foga)
  21.         {
  22.             if(!fog)
  23.             {
  24.                 fog = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp));
  25.                 al_set_target_bitmap(fog);
  26.                 al_clear_to_color(al_map_rgb(config.fogr, config.fogg, config.fogb));
  27.                 al_set_target_bitmap(temp);
  28.             }
  29.             if(!((al_get_bitmap_width(fog) == al_get_bitmap_width(temp)) && (al_get_bitmap_height(fog) == al_get_bitmap_height(temp))))
  30.             {
  31.                 al_destroy_bitmap(fog);
  32.                 fog = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp));
  33.                 al_set_target_bitmap(fog);
  34.                 al_clear_to_color(al_map_rgb(config.fogr, config.fogg, config.fogb));
  35.                 al_set_target_bitmap(temp);
  36.             }
  37.             al_draw_tinted_bitmap(fog, al_map_rgba(255, 255, 255, config.foga), 0, 0, 0);
  38.         }
  39.         if(vsz == vszmax-1)
  40.         {
  41.             if(config.show_osd) DrawCurrentLevelOutline(true);
  42.         }
  43.         if(config.dayNightCycle)
  44.             al_hold_bitmap_drawing(true);
  45.         for(int32_t vsx=1; vsx < vsxmax; vsx++)
  46.         {
  47.             for(int32_t vsy=1; vsy < vsymax; vsy++)
  48.             {
  49.                 Block *b = getBlockLocal(vsx,vsy,vsz);
  50.                 if(b==NULL || (b->floorType == 0 && b->ramp.type == 0 && b->wallType == 0))
  51.                 {
  52.                     Block* bLow = getBlockLocal(vsx,vsy,vsz-1);
  53.                     if(bLow != NULL)
  54.                     {
  55.                         bLow->DrawRamptops();
  56.                     }
  57.                 }
  58.                 if(b)
  59.                 {
  60.                     Block *frontleft = getBlockLocal(vsx,vsy+1,vsz);
  61.                     Block *frontright = getBlockLocal(vsx+1,vsy,vsz);
  62.                     Block *top = getBlockLocal(vsx,vsy,vsz+1);
  63.                     Block *topleft = getBlockLocal(vsx,vsy+1,vsz+1);
  64.                     Block *topright = getBlockLocal(vsx+1,vsy,vsz+1);
  65.                     Block *topfront = getBlockLocal(vsx+1,vsy+1,vsz+1);
  66.                     bool drawtl=false;
  67.                     bool drawtr=false;
  68.                     bool drawtf=false;
  69.                     bool drawt=false;
  70.                     if(topleft!=NULL)
  71.                         drawtl = topleft->wallType||topleft->floorType||topleft->ramp.type; // Is Top Left beeing drawn
  72.                     if(topright!=NULL)
  73.                         drawtr = topright->wallType||topright->floorType||topright->ramp.type; // Is Top Right beeing drawn
  74.                     if(topfront!=NULL)
  75.                         drawtf = topfront->wallType||topfront->floorType||topfront->ramp.type; // Is Top Front beeing drawn
  76.                     if(top!=NULL)
  77.                         drawt = top->wallType||top->floorType||top->ramp.type; // Is Top beeing drawn
  78.                     if(vsx<vsxmax-1&&vsy<vsymax-1&&vsz<vszmax-1) // Draw empty blocks on map edge and on top
  79.                     {
  80.                         if(!(b->wallType||b->floorType||b->ramp.type||b->stairType)) // Nothing to draw, moving on
  81.                             continue;
  82.                         if(!(topleft==NULL||topright==NULL||top==NULL||topfront==NULL)&&(drawtl&&drawtr&&drawtf&&drawt)) //Block is totally covered from above, moving on
  83.                             continue;
  84.                         if(((frontleft!=NULL&&frontleft->wallType)&&(frontright!=NULL&&frontright->wallType)&&(top!=NULL&&(top->wallType||top->floorType)))) //Block is covered by sides and top, moving on
  85.                             continue;
  86.                     }
  87.  
  88.                     b->Draw();
  89.                     /*al_flip_display();  // Slow Debug drawing: You can see every Block as its beeing drawn very useful =)
  90.                     b->Draw();
  91.                     al_flip_display();*/
  92.                 }
  93.             }
  94.         }
  95.         al_hold_bitmap_drawing(false);
  96.         al_hold_bitmap_drawing(true);
  97.         for(int32_t vsx=1; vsx < vsxmax; vsx++)
  98.         {
  99.             for(int32_t vsy=1; vsy < vsymax; vsy++)
  100.             {
  101.                 Block *b = getBlockLocal(vsx,vsy,vsz);
  102.                 if(b)
  103.                 {
  104.                     b->Drawcreaturetext();
  105.                     //while(!key[KEY_SPACE]) ;
  106.                     //rest(100);
  107.                 }
  108.             }
  109.         }
  110.         al_hold_bitmap_drawing(false);
  111.     }
  112.     if(config.showRenderStatus)
  113.         SetTitle("Stonesense");
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement