Make finish quicktune and leave it unused (as intended)
parent
18c4a90101
commit
2c9bb06516
|
@ -51,10 +51,14 @@ void set_default_settings(Settings *settings)
|
|||
settings->setDefault("keymap_toggle_update_camera", "KEY_F4");
|
||||
settings->setDefault("keymap_toggle_debug", "KEY_F5");
|
||||
settings->setDefault("keymap_toggle_profiler", "KEY_F6");
|
||||
settings->setDefault("keymap_increase_viewing_range_min", "KEY_PRIOR");
|
||||
settings->setDefault("keymap_decrease_viewing_range_min", "KEY_NEXT");
|
||||
settings->setDefault("keymap_increase_viewing_range_min", "+");
|
||||
settings->setDefault("keymap_decrease_viewing_range_min", "-");
|
||||
// Some (temporary) keys for debugging
|
||||
settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
|
||||
settings->setDefault("keymap_quicktune_prev", "KEY_HOME");
|
||||
settings->setDefault("keymap_quicktune_next", "KEY_END");
|
||||
settings->setDefault("keymap_quicktune_dec", "KEY_NEXT");
|
||||
settings->setDefault("keymap_quicktune_inc", "KEY_PRIOR");
|
||||
|
||||
// Show debug info by default?
|
||||
#ifdef NDEBUG
|
||||
|
|
23
src/game.cpp
23
src/game.cpp
|
@ -52,6 +52,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "tile.h" // For TextureSource
|
||||
#include "logoutputbuffer.h"
|
||||
#include "subgame.h"
|
||||
#include "quicktune_shortcutter.h"
|
||||
|
||||
/*
|
||||
Setting this to 1 enables a special camera mode that forces
|
||||
|
@ -676,9 +677,7 @@ void the_game(
|
|||
s32 hotbar_imagesize = 48;
|
||||
|
||||
// The color of the sky
|
||||
|
||||
//video::SColor skycolor = video::SColor(255,140,186,250);
|
||||
|
||||
video::SColor bgcolor_bright = video::SColor(255,170,200,230);
|
||||
|
||||
/*
|
||||
|
@ -699,6 +698,9 @@ void the_game(
|
|||
// Add chat log output for errors to be shown in chat
|
||||
LogOutputBuffer chat_log_error_buf(LMT_ERROR);
|
||||
|
||||
// Create UI for modifying quicktune values
|
||||
QuicktuneShortcutter quicktune;
|
||||
|
||||
/*
|
||||
Create server.
|
||||
SharedPtr will delete it when it goes out of scope.
|
||||
|
@ -1542,6 +1544,23 @@ void the_game(
|
|||
+ itos(range_new));
|
||||
statustext_time = 0;
|
||||
}
|
||||
|
||||
// Handle QuicktuneShortcutter
|
||||
if(input->wasKeyDown(getKeySetting("keymap_quicktune_next")))
|
||||
quicktune.next();
|
||||
if(input->wasKeyDown(getKeySetting("keymap_quicktune_prev")))
|
||||
quicktune.prev();
|
||||
if(input->wasKeyDown(getKeySetting("keymap_quicktune_inc")))
|
||||
quicktune.inc();
|
||||
if(input->wasKeyDown(getKeySetting("keymap_quicktune_dec")))
|
||||
quicktune.dec();
|
||||
{
|
||||
std::string msg = quicktune.getMessage();
|
||||
if(msg != ""){
|
||||
statustext = narrow_to_wide(msg);
|
||||
statustext_time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Item selection with mouse wheel
|
||||
u16 new_playeritem = client.getPlayerItem();
|
||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -70,6 +70,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "mods.h"
|
||||
#include "utility_string.h"
|
||||
#include "subgame.h"
|
||||
#include "quicktune.h"
|
||||
|
||||
/*
|
||||
Settings.
|
||||
|
@ -1505,6 +1506,22 @@ int main(int argc, char *argv[])
|
|||
// Update configuration file
|
||||
if(configpath != "")
|
||||
g_settings->updateConfigFile(configpath.c_str());
|
||||
|
||||
// Print modified quicktune values
|
||||
{
|
||||
bool header_printed = false;
|
||||
std::vector<std::string> names = getQuicktuneNames();
|
||||
for(u32 i=0; i<names.size(); i++){
|
||||
QuicktuneValue val = getQuicktuneValue(names[i]);
|
||||
if(!val.modified)
|
||||
continue;
|
||||
if(!header_printed){
|
||||
dstream<<"Modified quicktune values:"<<std::endl;
|
||||
header_printed = true;
|
||||
}
|
||||
dstream<<names[i]<<" = "<<val.getString()<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
END_DEBUG_EXCEPTION_HANDLER(errorstream)
|
||||
|
||||
|
|
|
@ -20,6 +20,32 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "quicktune.h"
|
||||
#include <jmutex.h>
|
||||
#include <jmutexautolock.h>
|
||||
#include "utility.h"
|
||||
|
||||
std::string QuicktuneValue::getString()
|
||||
{
|
||||
switch(type){
|
||||
case QVT_NONE:
|
||||
return "(none)";
|
||||
case QVT_FLOAT:
|
||||
return ftos(value_QVT_FLOAT.current);
|
||||
}
|
||||
return "<invalid type>";
|
||||
}
|
||||
void QuicktuneValue::relativeAdd(float amount)
|
||||
{
|
||||
switch(type){
|
||||
case QVT_NONE:
|
||||
break;
|
||||
case QVT_FLOAT:
|
||||
value_QVT_FLOAT.current += amount * (value_QVT_FLOAT.max - value_QVT_FLOAT.min);
|
||||
if(value_QVT_FLOAT.current > value_QVT_FLOAT.max)
|
||||
value_QVT_FLOAT.current = value_QVT_FLOAT.max;
|
||||
if(value_QVT_FLOAT.current < value_QVT_FLOAT.min)
|
||||
value_QVT_FLOAT.current = value_QVT_FLOAT.min;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static std::map<std::string, QuicktuneValue> g_values;
|
||||
static std::vector<std::string> g_names;
|
||||
|
@ -38,13 +64,6 @@ std::vector<std::string> getQuicktuneNames()
|
|||
return g_names;
|
||||
}
|
||||
|
||||
/*std::map<std::string, QuicktuneValue> getQuicktuneValues()
|
||||
{
|
||||
makeMutex();
|
||||
JMutexAutoLock lock(*g_mutex);
|
||||
return g_values;
|
||||
}*/
|
||||
|
||||
QuicktuneValue getQuicktuneValue(const std::string &name)
|
||||
{
|
||||
makeMutex();
|
||||
|
@ -52,7 +71,7 @@ QuicktuneValue getQuicktuneValue(const std::string &name)
|
|||
std::map<std::string, QuicktuneValue>::iterator i = g_values.find(name);
|
||||
if(i == g_values.end()){
|
||||
QuicktuneValue val;
|
||||
val.type = QUICKTUNE_NONE;
|
||||
val.type = QVT_NONE;
|
||||
return val;
|
||||
}
|
||||
return i->second;
|
||||
|
@ -63,6 +82,7 @@ void setQuicktuneValue(const std::string &name, const QuicktuneValue &val)
|
|||
makeMutex();
|
||||
JMutexAutoLock lock(*g_mutex);
|
||||
g_values[name] = val;
|
||||
g_values[name].modified = true;
|
||||
}
|
||||
|
||||
void updateQuicktuneValue(const std::string &name, QuicktuneValue &val)
|
||||
|
@ -76,12 +96,11 @@ void updateQuicktuneValue(const std::string &name, QuicktuneValue &val)
|
|||
return;
|
||||
}
|
||||
QuicktuneValue &ref = i->second;
|
||||
switch(val.type){
|
||||
case QUICKTUNE_NONE:
|
||||
break;
|
||||
case QUICKTUNE_FLOAT:
|
||||
val.value_float.current = ref.value_float.current;
|
||||
break;
|
||||
if(ref.modified)
|
||||
val = ref;
|
||||
else{
|
||||
ref = val;
|
||||
ref.modified = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
149
src/quicktune.h
149
src/quicktune.h
|
@ -17,6 +17,35 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Used for tuning constants when developing.
|
||||
|
||||
Eg. if you have this constant somewhere that you just can't get right
|
||||
by changing it and recompiling all over again:
|
||||
v3f wield_position = v3f(55, -35, 65);
|
||||
|
||||
Make it look like this:
|
||||
v3f wield_position = v3f(55, -35, 65);
|
||||
QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.X, 0, 100);
|
||||
QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.Y, -80, 20);
|
||||
QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.Z, 0, 100);
|
||||
|
||||
Then you can modify the values at runtime, using the keys
|
||||
keymap_quicktune_prev
|
||||
keymap_quicktune_next
|
||||
keymap_quicktune_dec
|
||||
keymap_quicktune_inc
|
||||
|
||||
Once you have modified the values at runtime and then quit, the game
|
||||
will print out all the modified values at the end:
|
||||
Modified quicktune values:
|
||||
wield_position.X = 60
|
||||
wield_position.Y = -30
|
||||
wield_position.Z = 65
|
||||
|
||||
The QUICKTUNE macros shouldn't generally be left in committed code.
|
||||
*/
|
||||
|
||||
#ifndef QUICKTUNE_HEADER
|
||||
#define QUICKTUNE_HEADER
|
||||
|
||||
|
@ -24,11 +53,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "utility.h"
|
||||
|
||||
enum QuicktuneValueType{
|
||||
QUICKTUNE_NONE,
|
||||
QUICKTUNE_FLOAT
|
||||
QVT_NONE,
|
||||
QVT_FLOAT
|
||||
};
|
||||
struct QuicktuneValue
|
||||
{
|
||||
|
@ -38,111 +66,40 @@ struct QuicktuneValue
|
|||
float current;
|
||||
float min;
|
||||
float max;
|
||||
} value_float;
|
||||
} value_QVT_FLOAT;
|
||||
};
|
||||
bool modified;
|
||||
|
||||
QuicktuneValue():
|
||||
type(QVT_NONE),
|
||||
modified(false)
|
||||
{}
|
||||
std::string getString();
|
||||
void relativeAdd(float amount);
|
||||
};
|
||||
|
||||
std::vector<std::string> getQuicktuneNames();
|
||||
//std::map<std::string, QuicktuneValue> getQuicktuneNames();
|
||||
QuicktuneValue getQuicktuneValue(const std::string &name);
|
||||
void setQuicktuneValue(const std::string &name, const QuicktuneValue &val);
|
||||
|
||||
class QuicktuneShortcutter
|
||||
{
|
||||
private:
|
||||
std::vector<std::string> m_names;
|
||||
u32 m_selected_i;
|
||||
std::string m_message;
|
||||
public:
|
||||
std::string getMessage()
|
||||
{
|
||||
std::string s = m_message;
|
||||
m_message = "";
|
||||
return s;
|
||||
}
|
||||
std::string getSelectedName()
|
||||
{
|
||||
if(m_selected_i < m_names.size())
|
||||
return m_names[m_selected_i];
|
||||
return "";
|
||||
}
|
||||
void next()
|
||||
{
|
||||
m_names = getQuicktuneNames();
|
||||
if(m_selected_i < m_names.size()-1)
|
||||
m_selected_i++;
|
||||
else
|
||||
m_selected_i = 0;
|
||||
m_message = std::string("Selected \"")+getSelectedName()+"\"";
|
||||
}
|
||||
void prev()
|
||||
{
|
||||
m_names = getQuicktuneNames();
|
||||
if(m_selected_i > 0)
|
||||
m_selected_i--;
|
||||
else
|
||||
m_selected_i = m_names.size()-1;
|
||||
m_message = std::string("Selected \"")+getSelectedName()+"\"";
|
||||
}
|
||||
void inc()
|
||||
{
|
||||
QuicktuneValue val = getQuicktuneValue(getSelectedName());
|
||||
switch(val.type){
|
||||
case QUICKTUNE_NONE:
|
||||
break;
|
||||
case QUICKTUNE_FLOAT:
|
||||
val.value_float.current += 0.05 * (val.value_float.max - val.value_float.min);
|
||||
if(val.value_float.current > val.value_float.max)
|
||||
val.value_float.current = val.value_float.max;
|
||||
m_message = std::string("\"")+getSelectedName()
|
||||
+"\" = "+ftos(val.value_float.current);
|
||||
break;
|
||||
default:
|
||||
m_message = std::string("\"")+getSelectedName()
|
||||
+"\" has unknown value type";
|
||||
}
|
||||
setQuicktuneValue(getSelectedName(), val);
|
||||
}
|
||||
void dec()
|
||||
{
|
||||
QuicktuneValue val = getQuicktuneValue(getSelectedName());
|
||||
switch(val.type){
|
||||
case QUICKTUNE_NONE:
|
||||
break;
|
||||
case QUICKTUNE_FLOAT:
|
||||
val.value_float.current -= 0.05 * (val.value_float.max - val.value_float.min);
|
||||
if(val.value_float.current < val.value_float.max)
|
||||
val.value_float.current = val.value_float.max;
|
||||
m_message = std::string("\"")+getSelectedName()
|
||||
+"\" = "+ftos(val.value_float.current);
|
||||
break;
|
||||
default:
|
||||
m_message = std::string("\"")+getSelectedName()
|
||||
+"\" has unknown value type";
|
||||
}
|
||||
setQuicktuneValue(getSelectedName(), val);
|
||||
}
|
||||
};
|
||||
|
||||
void updateQuicktuneValue(const std::string &name, QuicktuneValue &val);
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
#define QUICKTUNE_FLOAT(var, min, max, name){\
|
||||
QuicktuneValue qv;\
|
||||
qv.type = QUICKTUNE_FLOAT;\
|
||||
qv.value_float.current = var;\
|
||||
qv.value_float.min = min;\
|
||||
qv.value_float.min = max;\
|
||||
updateQuicktune(name, qv);\
|
||||
var = qv.value_float.current;\
|
||||
}
|
||||
|
||||
#define QUICKTUNE(type_, var, min_, max_, name){\
|
||||
QuicktuneValue qv;\
|
||||
qv.type = type_;\
|
||||
qv.value_##type_.current = var;\
|
||||
qv.value_##type_.min = min_;\
|
||||
qv.value_##type_.max = max_;\
|
||||
updateQuicktuneValue(name, qv);\
|
||||
var = qv.value_##type_.current;\
|
||||
}
|
||||
#else // NDEBUG
|
||||
#define QUICKTUNE(type, var, min_, max_, name){}
|
||||
#endif
|
||||
|
||||
#define QUICKTUNE_FLOAT(var, min, max, name){}
|
||||
|
||||
#endif
|
||||
#define QUICKTUNE_AUTONAME(type_, var, min_, max_)\
|
||||
QUICKTUNE(type_, var, min_, max_, #var)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
Minetest-c55
|
||||
Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef QVT_SHORTCUTTER_HEADER
|
||||
#define QVT_SHORTCUTTER_HEADER
|
||||
|
||||
#include "quicktune.h"
|
||||
#include "utility.h"
|
||||
|
||||
class QuicktuneShortcutter
|
||||
{
|
||||
private:
|
||||
std::vector<std::string> m_names;
|
||||
u32 m_selected_i;
|
||||
std::string m_message;
|
||||
public:
|
||||
std::string getMessage()
|
||||
{
|
||||
std::string s = m_message;
|
||||
m_message = "";
|
||||
if(s != "")
|
||||
return std::string("[quicktune] ") + s;
|
||||
return "";
|
||||
}
|
||||
std::string getSelectedName()
|
||||
{
|
||||
if(m_selected_i < m_names.size())
|
||||
return m_names[m_selected_i];
|
||||
return "(nothing)";
|
||||
}
|
||||
void next()
|
||||
{
|
||||
m_names = getQuicktuneNames();
|
||||
if(m_selected_i < m_names.size()-1)
|
||||
m_selected_i++;
|
||||
else
|
||||
m_selected_i = 0;
|
||||
m_message = std::string("Selected \"")+getSelectedName()+"\"";
|
||||
}
|
||||
void prev()
|
||||
{
|
||||
m_names = getQuicktuneNames();
|
||||
if(m_selected_i > 0)
|
||||
m_selected_i--;
|
||||
else
|
||||
m_selected_i = m_names.size()-1;
|
||||
m_message = std::string("Selected \"")+getSelectedName()+"\"";
|
||||
}
|
||||
void inc()
|
||||
{
|
||||
QuicktuneValue val = getQuicktuneValue(getSelectedName());
|
||||
val.relativeAdd(0.05);
|
||||
m_message = std::string("\"")+getSelectedName()
|
||||
+"\" = "+val.getString();
|
||||
setQuicktuneValue(getSelectedName(), val);
|
||||
}
|
||||
void dec()
|
||||
{
|
||||
QuicktuneValue val = getQuicktuneValue(getSelectedName());
|
||||
val.relativeAdd(-0.05);
|
||||
m_message = std::string("\"")+getSelectedName()
|
||||
+"\" = "+val.getString();
|
||||
setQuicktuneValue(getSelectedName(), val);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue