Otclient 1.0  14/8/2020
lightview.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef LIGHTVIEW_H
24 #define LIGHTVIEW_H
25 
28 #include "declarations.h"
29 #include "thingtype.h"
30 
31 struct LightSource {
34  int radius;
35 };
36 
37 class LightView : public LuaObject
38 {
39 public:
40  LightView();
41 
42  void reset();
43  void setGlobalLight(const Light& light);
44  void addLightSource(const Point& center, float scaleFactor, const Light& light);
45  void resize(const Size& size);
46  void draw(const Rect& dest, const Rect& src);
47 
48  void setBlendEquation(Painter::BlendEquation blendEquation) { m_blendEquation = blendEquation; }
49  void requestDrawing(const bool force) { if(force || m_minTimeRender.ticksElapsed() > 10) m_redraw = true; }
50 
51  bool isDark() const { return m_globalLight.intensity < 250; }
52 
53 private:
54  void drawGlobalLight(const Light& light);
55  void drawLightSource(const Point& center, const Color& color, int radius);
56  TexturePtr generateLightBubble(float centerFactor);
57 
58  Painter::BlendEquation m_blendEquation;
59  TexturePtr m_lightTexture;
60  FrameBufferPtr m_lightbuffer;
61  Light m_globalLight;
62  std::vector<LightSource> m_lightMap;
63 
64  bool m_redraw;
65 
66  Timer m_minTimeRender;
67 };
68 
69 #endif
LightView::setGlobalLight
void setGlobalLight(const Light &light)
Definition: lightview.cpp:75
Color
Definition: color.h:32
LightView::resize
void resize(const Size &size)
Definition: lightview.cpp:129
Timer::ticksElapsed
ticks_t ticksElapsed()
Definition: timer.cpp:33
TRect< int >
LightSource::color
Color color
Definition: lightview.h:32
LightView::addLightSource
void addLightSource(const Point &center, float scaleFactor, const Light &light)
Definition: lightview.cpp:80
LightView::isDark
bool isDark() const
Definition: lightview.h:51
LightView
Definition: lightview.h:37
painter.h
Light::intensity
uint8 intensity
Definition: thingtype.h:122
LightSource::center
Point center
Definition: lightview.h:33
declarations.h
LightView::LightView
LightView()
Definition: lightview.cpp:35
LightView::setBlendEquation
void setBlendEquation(Painter::BlendEquation blendEquation)
Definition: lightview.h:48
Painter::BlendEquation
BlendEquation
Definition: painter.h:34
LightSource
Definition: lightview.h:31
LightView::requestDrawing
void requestDrawing(const bool force)
Definition: lightview.h:49
declarations.h
LightView::draw
void draw(const Rect &dest, const Rect &src)
Definition: lightview.cpp:134
stdext::shared_object_ptr< Texture >
LightView::reset
void reset()
Definition: lightview.cpp:70
Light
Definition: thingtype.h:120
Timer
Definition: timer.h:28
TPoint< int >
thingtype.h
LuaObject
LuaObject, all script-able classes have it as base.
Definition: luaobject.h:30
TSize< int >
LightSource::radius
int radius
Definition: lightview.h:34