Don't like ads? PRO users don't see any ads ;-)
Guest

my code is bad and i should feel bad

By: a guest on Aug 19th, 2012  |  syntax: C++  |  size: 1.51 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //check the view rect to see if we need to load or unload any chunk
  2.                 bool tl, tm, tr,
  3.                          ml,     mr,
  4.                          bl, bm, br = false;
  5.  
  6.                 sf::IntRect view = mCamera->GetViewRect();
  7.                 int cx = std::floor(mCamera->GetOffset().x / 2048.0f);
  8.                 int cy = std::floor(mCamera->GetOffset().y / 2048.0f);
  9.                 int cxtl = cx * 2048.0f;
  10.                 int cytl = cy * 2048.0f;
  11.                 int cxbr = (cx + 1) * 2048.0f;
  12.                 int cybr = (cy + 1) * 2048.0f;
  13.  
  14.                 if (view.left < cxtl)
  15.                 {
  16.                         ml = true;
  17.                         if (view.top < cytl)
  18.                         {
  19.                                 tl = true;
  20.                         }
  21.                         if (view.top + view.height > cybr)
  22.                         {
  23.                                 bl = true;
  24.                                 bm = true;
  25.                         }
  26.                 }
  27.                 if (view.left + view.width > cxbr)
  28.                 {
  29.                         mr = true;
  30.                         if (view.top < cytl)
  31.                         {
  32.                                 tr = true;
  33.                                 tm = true;
  34.                         }
  35.                         if (view.top + view.height > cybr)
  36.                         {
  37.                                 br = true;
  38.                                 bm = true;
  39.                         }
  40.                 }
  41.                 if (view.top < cytl)
  42.                 {
  43.                         tm = true;
  44.                 }
  45.  
  46.                 if (tl)
  47.                         loadChunkAt(cx - 1, cy - 1);
  48.                 else
  49.                         unloadChunkAt(cx - 1, cy - 1);
  50.  
  51.                 if (tm)
  52.                         loadChunkAt(cx, cy - 1);
  53.                 else
  54.                         unloadChunkAt(cx, cy - 1);
  55.  
  56.                 if (tr)
  57.                         loadChunkAt(cx + 1, cy - 1);
  58.                 else
  59.                         unloadChunkAt(cx + 1, cy - 1);
  60.  
  61.                 if (ml)
  62.                         loadChunkAt(cx - 1, cy);
  63.                 else
  64.                         unloadChunkAt(cx - 1, cy);
  65.  
  66.                 if (mr)
  67.                         loadChunkAt(cx + 1, cy);
  68.                 else
  69.                         unloadChunkAt(cx + 1, cy);
  70.  
  71.                 if (bl)
  72.                         loadChunkAt(cx - 1, cy + 1);
  73.                 else
  74.                         unloadChunkAt(cx - 1, cy + 1);
  75.  
  76.                 if (bm)
  77.                         loadChunkAt(cx, cy + 1);
  78.                 else
  79.                         unloadChunkAt(cx, cy + 1);
  80.  
  81.                 if (br)
  82.                         loadChunkAt(cx + 1, cy + 1);
  83.                 else
  84.                         unloadChunkAt(cx + 1, cy + 1);