Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.33 KB | None | 0 0
  1. diff --git a/src/client/lightview.cpp b/src/client/lightview.cpp
  2. index 381d07e..a7c346b 100644
  3. --- a/src/client/lightview.cpp
  4. +++ b/src/client/lightview.cpp
  5. @@ -70,12 +70,16 @@ TexturePtr LightView::generateLightBubble(float centerFactor)
  6.  
  7.  void LightView::reset()
  8.  {
  9. +    m_lastLightMap = m_lightMap;
  10.      m_lightMap.clear();
  11.  }
  12.  
  13.  void LightView::setGlobalLight(const Light& light)
  14.  {
  15. -    m_globalLight = light;
  16. +    if(light != m_globalLight) {
  17. +        m_globalLight = light;
  18. +        m_mustRedraw = true;
  19. +    }
  20.  }
  21.  
  22.  void LightView::addLightSource(const Point& center, float scaleFactor, const Light& light)
  23. @@ -91,7 +95,7 @@ void LightView::addLightSource(const Point& center, float scaleFactor, const Lig
  24.      color.setBlue(color.bF() * brightness);
  25.  
  26.      if(m_blendEquation == Painter::BlendEquation_Add && m_lightMap.size() > 0) {
  27. -        LightSource prevSource = m_lightMap.back();
  28. +        const LightSource& prevSource = m_lightMap.back();
  29.          if(prevSource.center == center && prevSource.color == color && prevSource.radius == radius)
  30.              return;
  31.      }
  32. @@ -101,6 +105,10 @@ void LightView::addLightSource(const Point& center, float scaleFactor, const Lig
  33.      source.color = color;
  34.      source.radius = radius;
  35.      m_lightMap.push_back(source);
  36. +
  37. +    size_t index = m_lightMap.size() - 1;
  38. +    if(m_lastLightMap.size() >= index+1 && m_lastLightMap[index] != source)
  39. +        m_mustRedraw = true;
  40.  }
  41.  
  42.  void LightView::drawGlobalLight(const Light& light)
  43. @@ -127,20 +135,28 @@ void LightView::drawLightSource(const Point& center, const Color& color, int rad
  44.  
  45.  void LightView::resize(const Size& size)
  46.  {
  47. +    if(m_lightbuffer->getTexture() && m_lightbuffer->getSize() != size)
  48. +        m_mustRedraw = true;
  49.      m_lightbuffer->resize(size);
  50.  }
  51.  
  52.  void LightView::draw(const Rect& dest, const Rect& src)
  53.  {
  54. +    if(m_lastLightMap.size() != m_lightMap.size())
  55. +        m_mustRedraw = true;
  56. +
  57.      g_painter->saveAndResetState();
  58. -    m_lightbuffer->bind();
  59. -    g_painter->setCompositionMode(Painter::CompositionMode_Replace);
  60. -    drawGlobalLight(m_globalLight);
  61. -    g_painter->setBlendEquation(m_blendEquation);
  62. -    g_painter->setCompositionMode(Painter::CompositionMode_Add);
  63. -    for(const LightSource& source : m_lightMap)
  64. -        drawLightSource(source.center, source.color, source.radius);
  65. -    m_lightbuffer->release();
  66. +    if(m_mustRedraw) {
  67. +        m_lightbuffer->bind();
  68. +        g_painter->setCompositionMode(Painter::CompositionMode_Replace);
  69. +        drawGlobalLight(m_globalLight);
  70. +        g_painter->setBlendEquation(m_blendEquation);
  71. +        g_painter->setCompositionMode(Painter::CompositionMode_Add);
  72. +        for(const LightSource& source : m_lightMap)
  73. +            drawLightSource(source.center, source.color, source.radius);
  74. +        m_lightbuffer->release();
  75. +        m_mustRedraw = false;
  76. +    }
  77.      g_painter->setCompositionMode(Painter::CompositionMode_Light);
  78.      m_lightbuffer->draw(dest, src);
  79.      g_painter->restoreSavedState();
  80. diff --git a/src/client/lightview.h b/src/client/lightview.h
  81. index c14363e..9250284 100644
  82. --- a/src/client/lightview.h
  83. +++ b/src/client/lightview.h
  84. @@ -32,6 +32,9 @@ struct LightSource {
  85.      Color color;
  86.      Point center;
  87.      int radius;
  88. +
  89. +    bool operator==(const LightSource& other) const { return other.color == color && other.center == center && other.radius == radius; }
  90. +    bool operator!=(const LightSource& other) const { return other.color != color || other.center != center || other.radius != radius; }
  91.  };
  92.  
  93.  class LightView : public LuaObject
  94. @@ -57,6 +60,8 @@ private:
  95.      FrameBufferPtr m_lightbuffer;
  96.      Light m_globalLight;
  97.      std::vector<LightSource> m_lightMap;
  98. +    std::vector<LightSource> m_lastLightMap;
  99. +    bool m_mustRedraw = true;
  100.  };
  101.  
  102.  #endif
  103. diff --git a/src/client/thingtype.h b/src/client/thingtype.h
  104. index b5fe4d3..59b6e02 100644
  105. --- a/src/client/thingtype.h
  106. +++ b/src/client/thingtype.h
  107. @@ -110,6 +110,9 @@ struct Light {
  108.      Light() { intensity = 0; color = 215; }
  109.      uint8 intensity;
  110.      uint8 color;
  111. +
  112. +    bool operator==(const Light& other) const { return other.intensity == intensity && other.color == color; }
  113. +    bool operator!=(const Light& other) const { return other.intensity != intensity || other.color != color; }
  114.  };
  115.  
  116.  class ThingType : public LuaObject
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement