Merge pull request #1862 from konstin/lights

Make the lights adjustable in a race via the debug menu
This commit is contained in:
auriamg 2015-01-01 20:17:09 -05:00
commit ca822199b3
8 changed files with 158 additions and 45 deletions

View File

@ -2,37 +2,37 @@
<stkgui>
<div x="2%" y="10%" width="96%" height="80%" layout="vertical-row" >
<div proportion="1" width="100%" layout="horizontal-row">
<label id="Red" raw_text="Red"/>
<label id="Red" raw_text="Red" width="200"/>
<spacer width="25"/>
<gauge id="red_slider" min_value="0" max_value="100" proportion="1"/>
</div>
<div proportion="1" width="100%" layout="horizontal-row">
<label id="Green" raw_text="Green"/>
<label id="Green" raw_text="Green" width="200"/>
<spacer width="25"/>
<gauge id="green_slider" min_value="0" max_value="100" proportion="1"/>
</div>
<div proportion="1" width="100%" layout="horizontal-row">
<label id="Blue" raw_text="Blue"/>
<label id="Blue" raw_text="Blue" width="200"/>
<spacer width="25"/>
<gauge id="blue_slider" min_value="0" max_value="100" proportion="1"/>
</div>
<div proportion="1" width="100%" layout="horizontal-row">
<label id="SSAO radius" raw_text="SSAO Radius"/>
<label id="SSAO radius" raw_text="SSAO Radius" width="200"/>
<spacer width="50"/>
<gauge id="ssao_radius" min_value="0" max_value="100" proportion="1" />
</div>
<div proportion="1" width="100%" layout="horizontal-row">
<label id="SSAO k" raw_text="SSAO K"/>
<label id="SSAO k" raw_text="SSAO K" width="200"/>
<spacer width="25"/>
<gauge id="ssao_k" min_value="0" max_value="100" proportion="1"/>
</div>
<div proportion="1" width="100%" layout="horizontal-row">
<label id="SSAO Sigma" raw_text="SSAO sigma"/>
<label id="SSAO Sigma" raw_text="SSAO sigma" width="200"/>
<spacer width="50"/>
<gauge id="ssao_sigma" min_value="0" max_value="100" proportion="1"/>
</div>

View File

@ -358,13 +358,13 @@ void IrrDriver::initDevice()
core::dimension2d<u32> res = core::dimension2du(UserConfigParams::m_width,
UserConfigParams::m_height);
if (UserConfigParams::m_fullscreen)
{
if (modes->getVideoModeCount() > 0)
{
res = modes->getVideoModeResolution(res, res);
UserConfigParams::m_width = res.Width;
UserConfigParams::m_height = res.Height;
}
@ -896,7 +896,7 @@ scene::IMesh *IrrDriver::getMesh(const std::string &filename)
* joints data.
* \param mesh Original mesh
* \return Newly created skinned mesh. You should call drop() when you don't
* need it anymore.
* need it anymore.
*/
scene::IAnimatedMesh *IrrDriver::copyAnimatedMesh(scene::IAnimatedMesh *orig)
{
@ -950,7 +950,7 @@ void IrrDriver::setAllMaterialFlags(scene::IMesh *mesh) const
material_manager->setAllUntexturedMaterialFlags(mb);
}
}
} // for i<getMeshBufferCount()
} // setAllMaterialFlags

View File

@ -102,15 +102,15 @@ enum TypeFBO
FBO_SCALAR_1024,
FBO_BLOOM_512,
FBO_TMP_512,
FBO_LENS_512,
FBO_LENS_512,
FBO_BLOOM_256,
FBO_TMP_256,
FBO_LENS_256,
FBO_TMP_256,
FBO_LENS_256,
FBO_BLOOM_128,
FBO_TMP_128,
FBO_LENS_128,
FBO_LENS_128,
FBO_COUNT
};
@ -164,13 +164,13 @@ enum TypeRTT
RTT_SCALAR_1024,
RTT_BLOOM_512,
RTT_TMP_512,
RTT_LENS_512,
RTT_LENS_512,
RTT_BLOOM_256,
RTT_TMP_256,
RTT_LENS_256,
RTT_LENS_256,
RTT_BLOOM_128,
RTT_TMP_128,
RTT_LENS_128,
RTT_LENS_128,
RTT_COUNT
};
@ -626,6 +626,8 @@ public:
// ------------------------------------------------------------------------
u32 getRenderPass() { return m_renderpass; }
// ------------------------------------------------------------------------
std::vector<LightNode *> getLights() { return m_lights; }
// ------------------------------------------------------------------------
void addGlowingNode(scene::ISceneNode *n, float r = 1.0f, float g = 1.0f, float b = 1.0f)
{
GlowData dat;

View File

@ -62,7 +62,11 @@ public:
void setColor(float r, float g, float b) { m_color[0] = r; m_color[1] = g; m_color[2] = b; }
float getEnergyMultiplier() const { return m_energy_multiplier; }
void setEnergyMultiplier(float newval) { m_energy_multiplier = newval; }
void setEnergyMultiplier(float newval) { m_energy_multiplier = newval; }
// For the debug menu
void setEnergy(float energy) { m_energy = energy; }
void setRadius(float radius) { m_radius = radius; }
protected:
static core::aabbox3df box;

View File

@ -589,7 +589,7 @@ void Kart::createPhysics()
const Vec3 &bevel = m_kart_properties->getBevelFactor();
Vec3 wheel_pos[4];
assert(bevel.getX() || bevel.getY() || bevel.getZ());
Vec3 orig_factor(1, 1, 1 - bevel.getZ());
Vec3 bevel_factor(1.0f - bevel.getX(), 1.0f - bevel.getY(), 1.0f);
btConvexHullShape *hull = new btConvexHullShape();
@ -1346,7 +1346,7 @@ void Kart::update(float dt)
// A jump starts only the kart isn't already jumping, is on a new
// (or no) texture.
if (!m_is_jumping && last_m && last_m != m &&
if (!m_is_jumping && last_m && last_m != m &&
m_kart_model->getAnimation() == KartModel::AF_DEFAULT)
{
float v = getVelocity().getY();
@ -1477,7 +1477,7 @@ void Kart::handleMaterialSFX(const Material *material)
// In multiplayer mode sounds are NOT positional, because we have
// multiple listeners. This would make the sounds of all AIs be
// audible at all times. So silence AI karts.
if (s.size()!=0 && (race_manager->getNumPlayers()==1 ||
if (s.size()!=0 && (race_manager->getNumPlayers()==1 ||
m_controller->isPlayerController() ) )
{
m_terrain_sound = SFXManager::get()->createSoundSource(s);
@ -1899,10 +1899,10 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
"to enter this challenge!\n"
"Check the minimap for\n"
"available challenges.");
std::vector<core::stringw> parts =
std::vector<core::stringw> parts =
StringUtils::split(msg, '\n', false);
// For now, until we have scripting, special-case
// For now, until we have scripting, special-case
// the overworld... (TODO)
if (dynamic_cast<OverWorld*>(World::getWorld()) != NULL)
{
@ -2393,6 +2393,7 @@ void Kart::loadData(RaceManager::KartType type, bool is_animated_model)
m_nitro_light = irr_driver->addLight(core::vector3df(0.0f, 0.5f, m_kart_model->getLength()*-0.5f - 0.05f),
0.6f /* force */, 5.0f /* radius */, 0.0f, 0.4f, 1.0f, false, m_node);
m_nitro_light->setVisible(false);
m_nitro_light->setName( ("nitro emitter (" + getIdent() + ")").c_str() );
#ifdef DEBUG
m_node->setName( (getIdent()+"(lod-node)").c_str() );
@ -2611,7 +2612,7 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
float xx = fabsf(m_speed)* getKartProperties()->getDownwardImpulseFactor()*0.0006f;
Vec3 center_shift = Vec3(0, m_skidding->getGraphicalJumpOffset()
+ lean_height +m_graphical_y_offset+xx, 0);
// Try to prevent the graphical chassis to be inside of the terrain:
if(m_kart_properties->getPreventChassisInTerrain())
{
@ -2626,14 +2627,14 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
} // for i<num_wheels
const btWheelInfo &w = getVehicle()->getWheelInfo(0);
// Recompute the default average suspension length, see
// Recompute the default average suspension length, see
// kartIsInRestNow() how to get from y-offset to susp. len.
float av_sus_len = -m_graphical_y_offset
+ w.m_chassisConnectionPointCS.getY()
- w.m_wheelsRadius;
float delta = av_sus_len - min_susp_len;
// If the suspension length is so short, that it is less than the
// If the suspension length is so short, that it is less than the
// lowest point of the kart, it indicates that the graphical chassis
// would be inside of the track:
if (delta > m_kart_model->getLowestPoint())

View File

@ -51,12 +51,9 @@ void DebugSliderDialog::setSliderHook(std::string id, unsigned min, unsigned max
// ------------------------------------------------------------------------------------------------------
DebugSliderDialog::~DebugSliderDialog()
void DebugSliderDialog::changeLabel(std::string id, std::string new_label)
{
//if (StateManager::get()->getGameState() == GUIEngine::GAME)
//{
// World::getWorld()->scheduleUnpause();
//}
getWidget<LabelWidget>(id.c_str())->setText(stringw(new_label.c_str()), true);
}
// ------------------------------------------------------------------------------------------------------
@ -71,13 +68,14 @@ GUIEngine::EventPropagation DebugSliderDialog::processEvent(const std::string& e
{
#if !defined(__APPLE__)
if (Setters.find(eventSource) == Setters.end())
#endif
return GUIEngine::EVENT_LET;
#if !defined(__APPLE__)
int value = getWidget<SpinnerWidget>(eventSource.c_str())->getValue();
Log::info("DebugSlider", "Value for <%s> : %i", eventSource.c_str(), value);
Setters[eventSource](value);
return GUIEngine::EVENT_BLOCK;
#else
return GUIEngine::EVENT_LET;
#endif
}

View File

@ -40,10 +40,11 @@ private:
public:
DebugSliderDialog();
~DebugSliderDialog();
~DebugSliderDialog() {};
#if !defined(__APPLE__)
void setSliderHook(std::string id, unsigned min, unsigned max, std::function<int()> G, std::function<void(int)> S);
#endif
void changeLabel(std::string id, std::string new_label);
virtual void onEnterPressedInternal() OVERRIDE;
virtual void onUpdate(float dt) OVERRIDE;

View File

@ -21,6 +21,7 @@
#include "config/user_config.hpp"
#include "graphics/camera.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/light.hpp"
#include "items/powerup_manager.hpp"
#include "items/attachment.hpp"
#include "karts/abstract_kart.hpp"
@ -39,6 +40,8 @@
#include <IGUIEnvironment.h>
#include <IGUIContextMenu.h>
#include <cmath>
using namespace irr;
using namespace gui;
@ -98,10 +101,11 @@ enum DebugMenuCommand
DEBUG_THROTTLE_FPS,
DEBUG_VISUAL_VALUES,
DEBUG_PRINT_START_POS,
DEBUG_ADJUST_LIGHTS,
}; // DebugMenuCommand
// -----------------------------------------------------------------------------
// Add powerup selected from debug menu for all player karts
/** Add powerup selected from debug menu for all player karts */
void addPowerup(PowerupManager::PowerupType powerup)
{
World* world = World::getWorld();
@ -145,7 +149,51 @@ void addAttachment(Attachment::AttachmentType type)
} // addAttachment
// -----------------------------------------------------------------------------
// Debug menu handling
/** returns the light node with the lowest distance to the player kart (excluding
* nitro emitters) */
LightNode* findNearestLight()
{
World* world = World::getWorld();
if (!world) return NULL;
AbstractKart* player_kart = NULL;
for (unsigned int i = 0; i < world->getNumKarts(); i++)
{
AbstractKart *kart = world->getKart(i);
if (kart->getController()->isPlayerController())
player_kart = kart;
}
if (!player_kart)
{
Log::error("Debug", "No player kart found.");
return NULL;
}
core::vector3df kart_pos = player_kart->getNode()->getAbsolutePosition();
LightNode* nearest = 0;
float nearest_dist = 1000000.0; // big enough
for (unsigned int i = 0; i < irr_driver->getLights().size(); i++)
{
LightNode* light = irr_driver->getLights()[i];
// Avoid modifying the nitro emitter or another invisible light
if (std::string(light->getName()).find("nitro emitter") == 0 || !light->isVisible())
continue;
core::vector3df light_pos = light->getAbsolutePosition();
if ( kart_pos.getDistanceFrom(light_pos) < nearest_dist)
{
nearest = irr_driver->getLights()[i];
nearest_dist = kart_pos.getDistanceFrom(light_pos);
}
}
return nearest;
}
// -----------------------------------------------------------------------------
/** Debug menu handling */
bool onEvent(const SEvent &event)
{
// Only activated in artist debug mode
@ -215,15 +263,16 @@ bool onEvent(const SEvent &event)
mnu->addItem(L"Adjust values", DEBUG_VISUAL_VALUES);
mnu->addItem(L"Profiler",DEBUG_PROFILER);
mnu->addItem(L"Profiler", DEBUG_PROFILER);
if (UserConfigParams::m_profiler_enabled)
mnu->addItem(L"Toggle capture profiler report",
DEBUG_PROFILER_GENERATE_REPORT);
mnu->addItem(L"Do not limit FPS", DEBUG_THROTTLE_FPS);
mnu->addItem(L"FPS",DEBUG_FPS);
mnu->addItem(L"Toggle FPS", DEBUG_FPS);
mnu->addItem(L"Save replay", DEBUG_SAVE_REPLAY);
mnu->addItem(L"Save history", DEBUG_SAVE_HISTORY);
mnu->addItem(L"Print position", DEBUG_PRINT_START_POS);
mnu->addItem(L"Adjust Lights", DEBUG_ADJUST_LIGHTS);
g_debug_menu_visible = true;
irr_driver->showPointer();
@ -507,7 +556,7 @@ bool onEvent(const SEvent &event)
{
#if !defined(__APPLE__)
DebugSliderDialog *dsd = new DebugSliderDialog();
dsd->setSliderHook( "red_slider", 0, 255,
dsd->setSliderHook("red_slider", 0, 255,
[](){ return int(irr_driver->getAmbientLight().r * 255.f); },
[](int v){
video::SColorf ambient = irr_driver->getAmbientLight();
@ -540,6 +589,64 @@ bool onEvent(const SEvent &event)
[](){ return int(irr_driver->getSSAOSigma() * 10.f); },
[](int v){irr_driver->setSSAOSigma(v / 10.f); }
);
#endif
}
else if (cmdID == DEBUG_ADJUST_LIGHTS)
{
#if !defined(__APPLE__)
// Some sliders use multipliers because the spinner widget
// only supports integers
DebugSliderDialog *dsd = new DebugSliderDialog();
dsd->changeLabel("Red", "Red (x10)");
dsd->setSliderHook("red_slider", 0, 100,
[]()
{
return findNearestLight()->getColor().X * 100;
},
[](int intensity)
{
LightNode* nearest = findNearestLight();
core::vector3df color = nearest->getColor();
nearest->setColor(intensity / 100.0, color.Y, color.Z);
}
);
dsd->changeLabel("Green", "Green (x10)");
dsd->setSliderHook("green_slider", 0, 100,
[]()
{
return findNearestLight()->getColor().Y * 100;
},
[](int intensity)
{
LightNode* nearest = findNearestLight();
core::vector3df color = nearest->getColor();
nearest->setColor(color.X, intensity / 100.0, color.Z);
}
);
dsd->changeLabel("Blue", "Blue (x10)");
dsd->setSliderHook("blue_slider", 0, 100,
[]()
{
return findNearestLight()->getColor().Z * 100;
},
[](int intensity)
{
LightNode* nearest = findNearestLight();
core::vector3df color = nearest->getColor();
nearest->setColor(color.X, color.Y, intensity / 100.0);
}
);
dsd->changeLabel("SSAO radius", "energy (x10)");
dsd->setSliderHook("ssao_radius", 0, 100,
[]() { return findNearestLight()->getEnergy() * 10; },
[](int v){ findNearestLight()->setEnergy(v / 10.0); }
);
dsd->changeLabel("SSAO k", "radius");
dsd->setSliderHook("ssao_k", 0, 100,
[]() { return findNearestLight()->getRadius(); },
[](int v){ findNearestLight()->setRadius(v); }
);
dsd->changeLabel("SSAO Sigma", "[None]");
#endif
}
}