Bind functions for minimum ambient light

This commit is contained in:
Eduardo Bart 2012-11-30 14:31:19 -02:00
parent f851bb7777
commit 5fed08b17e
4 changed files with 17 additions and 7 deletions

View File

@ -521,6 +521,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIMap>("setAnimated", &UIMap::setAnimated); g_lua.bindClassMemberFunction<UIMap>("setAnimated", &UIMap::setAnimated);
g_lua.bindClassMemberFunction<UIMap>("setKeepAspectRatio", &UIMap::setKeepAspectRatio); g_lua.bindClassMemberFunction<UIMap>("setKeepAspectRatio", &UIMap::setKeepAspectRatio);
g_lua.bindClassMemberFunction<UIMap>("setMapShader", &UIMap::setMapShader); g_lua.bindClassMemberFunction<UIMap>("setMapShader", &UIMap::setMapShader);
g_lua.bindClassMemberFunction<UIMap>("setMinimumAmbientLight", &UIMap::setMinimumAmbientLight);
g_lua.bindClassMemberFunction<UIMap>("isMultifloor", &UIMap::isMultifloor); g_lua.bindClassMemberFunction<UIMap>("isMultifloor", &UIMap::isMultifloor);
g_lua.bindClassMemberFunction<UIMap>("isAutoViewModeEnabled", &UIMap::isAutoViewModeEnabled); g_lua.bindClassMemberFunction<UIMap>("isAutoViewModeEnabled", &UIMap::isAutoViewModeEnabled);
g_lua.bindClassMemberFunction<UIMap>("isDrawingTexts", &UIMap::isDrawingTexts); g_lua.bindClassMemberFunction<UIMap>("isDrawingTexts", &UIMap::isDrawingTexts);
@ -539,6 +540,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIMap>("getMaxZoomOut", &UIMap::getMaxZoomOut); g_lua.bindClassMemberFunction<UIMap>("getMaxZoomOut", &UIMap::getMaxZoomOut);
g_lua.bindClassMemberFunction<UIMap>("getZoom", &UIMap::getZoom); g_lua.bindClassMemberFunction<UIMap>("getZoom", &UIMap::getZoom);
g_lua.bindClassMemberFunction<UIMap>("getMapShader", &UIMap::getMapShader); g_lua.bindClassMemberFunction<UIMap>("getMapShader", &UIMap::getMapShader);
g_lua.bindClassMemberFunction<UIMap>("getMinimumAmbientLight", &UIMap::getMinimumAmbientLight);
g_lua.registerClass<UIProgressRect, UIWidget>(); g_lua.registerClass<UIProgressRect, UIWidget>();
g_lua.bindClassStaticFunction<UIProgressRect>("create", []{ return UIProgressRectPtr(new UIProgressRect); } ); g_lua.bindClassStaticFunction<UIProgressRect>("create", []{ return UIProgressRectPtr(new UIProgressRect); } );

View File

@ -57,6 +57,7 @@ MapView::MapView()
m_cachedFirstVisibleFloor = 7; m_cachedFirstVisibleFloor = 7;
m_cachedLastVisibleFloor = 7; m_cachedLastVisibleFloor = 7;
m_updateTilesPos = 0; m_updateTilesPos = 0;
m_minimumAmbientLight = 0;
m_optimizedSize = Size(Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES) * Otc::TILE_PIXELS; m_optimizedSize = Size(Otc::AWARE_X_TILES, Otc::AWARE_Y_TILES) * Otc::TILE_PIXELS;
m_framebuffer = g_framebuffers.createFrameBuffer(); m_framebuffer = g_framebuffers.createFrameBuffer();
@ -102,14 +103,15 @@ void MapView::draw(const Rect& rect)
m_lightView->reset(); m_lightView->reset();
m_lightView->resize(m_framebuffer->getSize()); m_lightView->resize(m_framebuffer->getSize());
if(cameraPosition.z <= 7) Light ambientLight;
m_lightView->setGlobalLight(g_map.getLight()); if(cameraPosition.z <= 7) {
else { ambientLight = g_map.getLight();
Light undergroundLight; } else {
undergroundLight.color = 215; ambientLight.color = 215;
undergroundLight.intensity = 16; ambientLight.intensity = 0;
m_lightView->setGlobalLight(undergroundLight);
} }
ambientLight.intensity = std::max<int>(m_minimumAmbientLight*255, ambientLight.intensity);
m_lightView->setGlobalLight(ambientLight);
} }
} }
g_painter->setColor(Color::white); g_painter->setColor(Color::white);

View File

@ -88,6 +88,9 @@ public:
void setCameraPosition(const Position& pos); void setCameraPosition(const Position& pos);
Position getCameraPosition(); Position getCameraPosition();
void setMinimumAmbientLight(float intensity) { m_minimumAmbientLight = intensity; }
float getMinimumAmbientLight() { return m_minimumAmbientLight; }
// drawing related // drawing related
void setDrawFlags(Otc::DrawFlags drawFlags) { m_drawFlags = drawFlags; requestVisibleTilesCacheUpdate(); } void setDrawFlags(Otc::DrawFlags drawFlags) { m_drawFlags = drawFlags; requestVisibleTilesCacheUpdate(); }
Otc::DrawFlags getDrawFlags() { return m_drawFlags; } Otc::DrawFlags getDrawFlags() { return m_drawFlags; }
@ -149,6 +152,7 @@ private:
Otc::DrawFlags m_drawFlags; Otc::DrawFlags m_drawFlags;
std::vector<Point> m_spiral; std::vector<Point> m_spiral;
LightViewPtr m_lightView; LightViewPtr m_lightView;
float m_minimumAmbientLight;
}; };
#endif #endif

View File

@ -56,6 +56,7 @@ public:
void setAnimated(bool enable) { m_mapView->setAnimated(enable); } void setAnimated(bool enable) { m_mapView->setAnimated(enable); }
void setKeepAspectRatio(bool enable); void setKeepAspectRatio(bool enable);
void setMapShader(const PainterShaderProgramPtr& shader) { m_mapView->setShader(shader); } void setMapShader(const PainterShaderProgramPtr& shader) { m_mapView->setShader(shader); }
void setMinimumAmbientLight(float intensity) { m_mapView->setMinimumAmbientLight(intensity); }
bool isMultifloor() { return m_mapView->isMultifloor(); } bool isMultifloor() { return m_mapView->isMultifloor(); }
bool isAutoViewModeEnabled() { return m_mapView->isAutoViewModeEnabled(); } bool isAutoViewModeEnabled() { return m_mapView->isAutoViewModeEnabled(); }
@ -76,6 +77,7 @@ public:
int getMaxZoomOut() { return m_maxZoomOut; } int getMaxZoomOut() { return m_maxZoomOut; }
int getZoom() { return m_zoom; } int getZoom() { return m_zoom; }
PainterShaderProgramPtr getMapShader() { return m_mapView->getShader(); } PainterShaderProgramPtr getMapShader() { return m_mapView->getShader(); }
float getMinimumAmbientLight() { return m_mapView->getMinimumAmbientLight(); }
protected: protected:
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);