Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/client/lightview.cpp b/src/client/lightview.cpp
- index 381d07e..a7c346b 100644
- --- a/src/client/lightview.cpp
- +++ b/src/client/lightview.cpp
- @@ -70,12 +70,16 @@ TexturePtr LightView::generateLightBubble(float centerFactor)
- void LightView::reset()
- {
- + m_lastLightMap = m_lightMap;
- m_lightMap.clear();
- }
- void LightView::setGlobalLight(const Light& light)
- {
- - m_globalLight = light;
- + if(light != m_globalLight) {
- + m_globalLight = light;
- + m_mustRedraw = true;
- + }
- }
- void LightView::addLightSource(const Point& center, float scaleFactor, const Light& light)
- @@ -91,7 +95,7 @@ void LightView::addLightSource(const Point& center, float scaleFactor, const Lig
- color.setBlue(color.bF() * brightness);
- if(m_blendEquation == Painter::BlendEquation_Add && m_lightMap.size() > 0) {
- - LightSource prevSource = m_lightMap.back();
- + const LightSource& prevSource = m_lightMap.back();
- if(prevSource.center == center && prevSource.color == color && prevSource.radius == radius)
- return;
- }
- @@ -101,6 +105,10 @@ void LightView::addLightSource(const Point& center, float scaleFactor, const Lig
- source.color = color;
- source.radius = radius;
- m_lightMap.push_back(source);
- +
- + size_t index = m_lightMap.size() - 1;
- + if(m_lastLightMap.size() >= index+1 && m_lastLightMap[index] != source)
- + m_mustRedraw = true;
- }
- void LightView::drawGlobalLight(const Light& light)
- @@ -127,20 +135,28 @@ void LightView::drawLightSource(const Point& center, const Color& color, int rad
- void LightView::resize(const Size& size)
- {
- + if(m_lightbuffer->getTexture() && m_lightbuffer->getSize() != size)
- + m_mustRedraw = true;
- m_lightbuffer->resize(size);
- }
- void LightView::draw(const Rect& dest, const Rect& src)
- {
- + if(m_lastLightMap.size() != m_lightMap.size())
- + m_mustRedraw = true;
- +
- g_painter->saveAndResetState();
- - m_lightbuffer->bind();
- - g_painter->setCompositionMode(Painter::CompositionMode_Replace);
- - drawGlobalLight(m_globalLight);
- - g_painter->setBlendEquation(m_blendEquation);
- - g_painter->setCompositionMode(Painter::CompositionMode_Add);
- - for(const LightSource& source : m_lightMap)
- - drawLightSource(source.center, source.color, source.radius);
- - m_lightbuffer->release();
- + if(m_mustRedraw) {
- + m_lightbuffer->bind();
- + g_painter->setCompositionMode(Painter::CompositionMode_Replace);
- + drawGlobalLight(m_globalLight);
- + g_painter->setBlendEquation(m_blendEquation);
- + g_painter->setCompositionMode(Painter::CompositionMode_Add);
- + for(const LightSource& source : m_lightMap)
- + drawLightSource(source.center, source.color, source.radius);
- + m_lightbuffer->release();
- + m_mustRedraw = false;
- + }
- g_painter->setCompositionMode(Painter::CompositionMode_Light);
- m_lightbuffer->draw(dest, src);
- g_painter->restoreSavedState();
- diff --git a/src/client/lightview.h b/src/client/lightview.h
- index c14363e..9250284 100644
- --- a/src/client/lightview.h
- +++ b/src/client/lightview.h
- @@ -32,6 +32,9 @@ struct LightSource {
- Color color;
- Point center;
- int radius;
- +
- + bool operator==(const LightSource& other) const { return other.color == color && other.center == center && other.radius == radius; }
- + bool operator!=(const LightSource& other) const { return other.color != color || other.center != center || other.radius != radius; }
- };
- class LightView : public LuaObject
- @@ -57,6 +60,8 @@ private:
- FrameBufferPtr m_lightbuffer;
- Light m_globalLight;
- std::vector<LightSource> m_lightMap;
- + std::vector<LightSource> m_lastLightMap;
- + bool m_mustRedraw = true;
- };
- #endif
- diff --git a/src/client/thingtype.h b/src/client/thingtype.h
- index b5fe4d3..59b6e02 100644
- --- a/src/client/thingtype.h
- +++ b/src/client/thingtype.h
- @@ -110,6 +110,9 @@ struct Light {
- Light() { intensity = 0; color = 215; }
- uint8 intensity;
- uint8 color;
- +
- + bool operator==(const Light& other) const { return other.intensity == intensity && other.color == color; }
- + bool operator!=(const Light& other) const { return other.intensity != intensity || other.color != color; }
- };
- class ThingType : public LuaObject
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement