mirror of
https://github.com/minetest/minetest.git
synced 2024-08-19 21:14:15 +02:00
Game refactor [4/X]: keycache is now owned by InputHandler
* Make InputHandler own the key cache * Add a helper function InputHandler::cancelPressed to avoid multiple similar calls in game.cpp * Move RandomInputHandler::step definition into cpp file
This commit is contained in:
parent
f5a006dce7
commit
99c9e7a986
@ -158,6 +158,7 @@ LOCAL_SRC_FILES := \
|
||||
jni/src/gui/guiTable.cpp \
|
||||
jni/src/guiscalingfilter.cpp \
|
||||
jni/src/gui/guiVolumeChange.cpp \
|
||||
jni/src/gui/profilergraph.cpp \
|
||||
jni/src/httpfetch.cpp \
|
||||
jni/src/hud.cpp \
|
||||
jni/src/imagefilters.cpp \
|
||||
|
@ -58,22 +58,16 @@ void KeyCache::populate()
|
||||
key[KeyType::SCREENSHOT] = getKeySetting("keymap_screenshot");
|
||||
key[KeyType::TOGGLE_HUD] = getKeySetting("keymap_toggle_hud");
|
||||
key[KeyType::TOGGLE_CHAT] = getKeySetting("keymap_toggle_chat");
|
||||
key[KeyType::TOGGLE_FORCE_FOG_OFF]
|
||||
= getKeySetting("keymap_toggle_force_fog_off");
|
||||
key[KeyType::TOGGLE_UPDATE_CAMERA]
|
||||
= getKeySetting("keymap_toggle_update_camera");
|
||||
key[KeyType::TOGGLE_DEBUG]
|
||||
= getKeySetting("keymap_toggle_debug");
|
||||
key[KeyType::TOGGLE_PROFILER]
|
||||
= getKeySetting("keymap_toggle_profiler");
|
||||
key[KeyType::CAMERA_MODE]
|
||||
= getKeySetting("keymap_camera_mode");
|
||||
key[KeyType::INCREASE_VIEWING_RANGE]
|
||||
= getKeySetting("keymap_increase_viewing_range_min");
|
||||
key[KeyType::DECREASE_VIEWING_RANGE]
|
||||
= getKeySetting("keymap_decrease_viewing_range_min");
|
||||
key[KeyType::RANGESELECT]
|
||||
= getKeySetting("keymap_rangeselect");
|
||||
key[KeyType::TOGGLE_FORCE_FOG_OFF] = getKeySetting("keymap_toggle_force_fog_off");
|
||||
key[KeyType::TOGGLE_UPDATE_CAMERA] = getKeySetting("keymap_toggle_update_camera");
|
||||
key[KeyType::TOGGLE_DEBUG] = getKeySetting("keymap_toggle_debug");
|
||||
key[KeyType::TOGGLE_PROFILER] = getKeySetting("keymap_toggle_profiler");
|
||||
key[KeyType::CAMERA_MODE] = getKeySetting("keymap_camera_mode");
|
||||
key[KeyType::INCREASE_VIEWING_RANGE] =
|
||||
getKeySetting("keymap_increase_viewing_range_min");
|
||||
key[KeyType::DECREASE_VIEWING_RANGE] =
|
||||
getKeySetting("keymap_decrease_viewing_range_min");
|
||||
key[KeyType::RANGESELECT] = getKeySetting("keymap_rangeselect");
|
||||
key[KeyType::ZOOM] = getKeySetting("keymap_zoom");
|
||||
|
||||
key[KeyType::QUICKTUNE_NEXT] = getKeySetting("keymap_quicktune_next");
|
||||
@ -191,3 +185,72 @@ s32 RandomInputHandler::Rand(s32 min, s32 max)
|
||||
{
|
||||
return (myrand() % (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
void RandomInputHandler::step(float dtime)
|
||||
{
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_jump"));
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_special1"));
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_forward"));
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_left"));
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 20);
|
||||
mousespeed = v2s32(Rand(-20, 20), Rand(-15, 20));
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 30);
|
||||
leftdown = !leftdown;
|
||||
if (leftdown)
|
||||
leftclicked = true;
|
||||
if (!leftdown)
|
||||
leftreleased = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 15);
|
||||
rightdown = !rightdown;
|
||||
if (rightdown)
|
||||
rightclicked = true;
|
||||
if (!rightdown)
|
||||
rightreleased = true;
|
||||
}
|
||||
}
|
||||
mousepos += mousespeed;
|
||||
}
|
||||
|
@ -42,7 +42,8 @@ class InputHandler;
|
||||
* (up to 10x faster) key lookup is an asset. Other parts of the codebase
|
||||
* (e.g. formspecs) should continue using getKeySetting().
|
||||
*/
|
||||
struct KeyCache {
|
||||
struct KeyCache
|
||||
{
|
||||
|
||||
KeyCache()
|
||||
{
|
||||
@ -210,12 +211,17 @@ private:
|
||||
class InputHandler
|
||||
{
|
||||
public:
|
||||
InputHandler() = default;
|
||||
InputHandler()
|
||||
{
|
||||
keycache.handler = this;
|
||||
keycache.populate();
|
||||
}
|
||||
|
||||
virtual ~InputHandler() = default;
|
||||
|
||||
virtual bool isKeyDown(const KeyPress &keyCode) = 0;
|
||||
virtual bool wasKeyDown(const KeyPress &keyCode) = 0;
|
||||
virtual bool isKeyDown(GameKeyType k) = 0;
|
||||
virtual bool wasKeyDown(GameKeyType k) = 0;
|
||||
virtual bool cancelPressed() = 0;
|
||||
|
||||
virtual void listenForKey(const KeyPress &keyCode) {}
|
||||
virtual void dontListenForKeys() {}
|
||||
@ -243,6 +249,7 @@ public:
|
||||
virtual void clear() {}
|
||||
|
||||
JoystickController joystick;
|
||||
KeyCache keycache;
|
||||
};
|
||||
/*
|
||||
Separated input handler
|
||||
@ -255,13 +262,17 @@ public:
|
||||
{
|
||||
m_receiver->joystick = &joystick;
|
||||
}
|
||||
virtual bool isKeyDown(const KeyPress &keyCode)
|
||||
virtual bool isKeyDown(GameKeyType k)
|
||||
{
|
||||
return m_receiver->IsKeyDown(keyCode);
|
||||
return m_receiver->IsKeyDown(keycache.key[k]) || joystick.isKeyDown(k);
|
||||
}
|
||||
virtual bool wasKeyDown(const KeyPress &keyCode)
|
||||
virtual bool wasKeyDown(GameKeyType k)
|
||||
{
|
||||
return m_receiver->WasKeyDown(keyCode);
|
||||
return m_receiver->WasKeyDown(keycache.key[k]) || joystick.wasKeyDown(k);
|
||||
}
|
||||
virtual bool cancelPressed()
|
||||
{
|
||||
return wasKeyDown(KeyType::ESC) || m_receiver->WasKeyDown(CancelKey);
|
||||
}
|
||||
virtual void listenForKey(const KeyPress &keyCode)
|
||||
{
|
||||
@ -301,11 +312,13 @@ public:
|
||||
|
||||
virtual bool getLeftClicked()
|
||||
{
|
||||
return m_receiver->leftclicked || joystick.getWasKeyDown(KeyType::MOUSE_L);
|
||||
return m_receiver->leftclicked ||
|
||||
joystick.getWasKeyDown(KeyType::MOUSE_L);
|
||||
}
|
||||
virtual bool getRightClicked()
|
||||
{
|
||||
return m_receiver->rightclicked || joystick.getWasKeyDown(KeyType::MOUSE_R);
|
||||
return m_receiver->rightclicked ||
|
||||
joystick.getWasKeyDown(KeyType::MOUSE_R);
|
||||
}
|
||||
|
||||
virtual void resetLeftClicked()
|
||||
@ -313,18 +326,21 @@ public:
|
||||
m_receiver->leftclicked = false;
|
||||
joystick.clearWasKeyDown(KeyType::MOUSE_L);
|
||||
}
|
||||
virtual void resetRightClicked() {
|
||||
virtual void resetRightClicked()
|
||||
{
|
||||
m_receiver->rightclicked = false;
|
||||
joystick.clearWasKeyDown(KeyType::MOUSE_R);
|
||||
}
|
||||
|
||||
virtual bool getLeftReleased()
|
||||
{
|
||||
return m_receiver->leftreleased || joystick.wasKeyReleased(KeyType::MOUSE_L);
|
||||
return m_receiver->leftreleased ||
|
||||
joystick.wasKeyReleased(KeyType::MOUSE_L);
|
||||
}
|
||||
virtual bool getRightReleased()
|
||||
{
|
||||
return m_receiver->rightreleased || joystick.wasKeyReleased(KeyType::MOUSE_R);
|
||||
return m_receiver->rightreleased ||
|
||||
joystick.wasKeyReleased(KeyType::MOUSE_R);
|
||||
}
|
||||
|
||||
virtual void resetLeftReleased()
|
||||
@ -356,8 +372,9 @@ class RandomInputHandler : public InputHandler
|
||||
public:
|
||||
RandomInputHandler() = default;
|
||||
|
||||
virtual bool isKeyDown(const KeyPress &keyCode) { return keydown[keyCode]; }
|
||||
virtual bool wasKeyDown(const KeyPress &keyCode) { return false; }
|
||||
virtual bool isKeyDown(GameKeyType k) { return keydown[keycache.key[k]]; }
|
||||
virtual bool wasKeyDown(GameKeyType k) { return false; }
|
||||
virtual bool cancelPressed() { return false; }
|
||||
virtual v2s32 getMousePos() { return mousepos; }
|
||||
virtual void setMousePos(s32 x, s32 y) { mousepos = v2s32(x, y); }
|
||||
|
||||
@ -376,74 +393,7 @@ public:
|
||||
|
||||
virtual s32 getMouseWheel() { return 0; }
|
||||
|
||||
virtual void step(float dtime)
|
||||
{
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_jump"));
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_special1"));
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_forward"));
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 40);
|
||||
keydown.toggle(getKeySetting("keymap_left"));
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 20);
|
||||
mousespeed = v2s32(Rand(-20, 20), Rand(-15, 20));
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 30);
|
||||
leftdown = !leftdown;
|
||||
if (leftdown)
|
||||
leftclicked = true;
|
||||
if (!leftdown)
|
||||
leftreleased = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
static float counter1 = 0;
|
||||
counter1 -= dtime;
|
||||
if (counter1 < 0.0) {
|
||||
counter1 = 0.1 * Rand(1, 15);
|
||||
rightdown = !rightdown;
|
||||
if (rightdown)
|
||||
rightclicked = true;
|
||||
if (!rightdown)
|
||||
rightreleased = true;
|
||||
}
|
||||
}
|
||||
mousepos += mousespeed;
|
||||
}
|
||||
virtual void step(float dtime);
|
||||
|
||||
s32 Rand(s32 min, s32 max);
|
||||
|
||||
|
35
src/game.cpp
35
src/game.cpp
@ -757,11 +757,11 @@ protected:
|
||||
|
||||
inline bool isKeyDown(GameKeyType k)
|
||||
{
|
||||
return input->isKeyDown(keycache.key[k]) || input->joystick.isKeyDown(k);
|
||||
return input->isKeyDown(k);
|
||||
}
|
||||
inline bool wasKeyDown(GameKeyType k)
|
||||
{
|
||||
return input->wasKeyDown(keycache.key[k]) || input->joystick.wasKeyDown(k);
|
||||
return input->wasKeyDown(k);
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
@ -859,8 +859,6 @@ private:
|
||||
*/
|
||||
int crack_animation_length;
|
||||
|
||||
KeyCache keycache;
|
||||
|
||||
IntervalLimiter profiler_interval;
|
||||
|
||||
/*
|
||||
@ -1008,8 +1006,7 @@ bool Game::startup(bool *kill,
|
||||
this->chat_backend = chat_backend;
|
||||
this->simple_singleplayer_mode = simple_singleplayer_mode;
|
||||
|
||||
keycache.handler = input;
|
||||
keycache.populate();
|
||||
input->keycache.populate();
|
||||
|
||||
driver = device->getVideoDriver();
|
||||
smgr = RenderingEngine::get_scene_manager();
|
||||
@ -1521,7 +1518,7 @@ bool Game::connectToServer(const std::string &playername,
|
||||
break;
|
||||
}
|
||||
|
||||
if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) {
|
||||
if (input->cancelPressed()) {
|
||||
*connection_aborted = true;
|
||||
infostream << "Connect aborted [Escape]" << std::endl;
|
||||
break;
|
||||
@ -1593,7 +1590,7 @@ bool Game::getServerContent(bool *aborted)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) {
|
||||
if (input->cancelPressed()) {
|
||||
*aborted = true;
|
||||
infostream << "Connect aborted [Escape]" << std::endl;
|
||||
return false;
|
||||
@ -1706,7 +1703,7 @@ inline bool Game::handleCallbacks()
|
||||
}
|
||||
|
||||
if (g_gamecallback->keyconfig_changed) {
|
||||
keycache.populate(); // update the cache with new settings
|
||||
input->keycache.populate(); // update the cache with new settings
|
||||
g_gamecallback->keyconfig_changed = false;
|
||||
}
|
||||
|
||||
@ -1865,7 +1862,7 @@ void Game::processKeyInput()
|
||||
toggleAutoforward();
|
||||
} else if (wasKeyDown(KeyType::INVENTORY)) {
|
||||
openInventory();
|
||||
} else if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) {
|
||||
} else if (input->cancelPressed()) {
|
||||
if (!gui_chat_console->isOpenInhibited()) {
|
||||
showPauseMenu();
|
||||
}
|
||||
@ -2030,7 +2027,7 @@ void Game::openInventory()
|
||||
if (!client->moddingEnabled()
|
||||
|| !client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) {
|
||||
TextDest *txt_dst = new TextDestPlayerInventory(client);
|
||||
GUIFormSpecMenu::create(¤t_formspec, client, &input->joystick, fs_src,
|
||||
GUIFormSpecMenu::create(current_formspec, client, &input->joystick, fs_src,
|
||||
txt_dst);
|
||||
cur_formname = "";
|
||||
current_formspec->setFormSpec(fs_src->getForm(), inventoryloc);
|
||||
@ -2396,10 +2393,10 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
|
||||
// distinguish between the two in order to know when to use joysticks.
|
||||
|
||||
PlayerControl control(
|
||||
input->isKeyDown(keycache.key[KeyType::FORWARD]),
|
||||
input->isKeyDown(keycache.key[KeyType::BACKWARD]),
|
||||
input->isKeyDown(keycache.key[KeyType::LEFT]),
|
||||
input->isKeyDown(keycache.key[KeyType::RIGHT]),
|
||||
input->isKeyDown(KeyType::FORWARD),
|
||||
input->isKeyDown(KeyType::BACKWARD),
|
||||
input->isKeyDown(KeyType::LEFT),
|
||||
input->isKeyDown(KeyType::RIGHT),
|
||||
isKeyDown(KeyType::JUMP),
|
||||
isKeyDown(KeyType::SPECIAL1),
|
||||
isKeyDown(KeyType::SNEAK),
|
||||
@ -2535,7 +2532,7 @@ void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation
|
||||
TextDestPlayerInventory *txt_dst =
|
||||
new TextDestPlayerInventory(client, *(event->show_formspec.formname));
|
||||
|
||||
GUIFormSpecMenu::create(¤t_formspec, client, &input->joystick,
|
||||
GUIFormSpecMenu::create(current_formspec, client, &input->joystick,
|
||||
fs_src, txt_dst);
|
||||
cur_formname = *(event->show_formspec.formname);
|
||||
}
|
||||
@ -2549,7 +2546,7 @@ void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrienta
|
||||
FormspecFormSource *fs_src = new FormspecFormSource(*event->show_formspec.formspec);
|
||||
LocalFormspecHandler *txt_dst =
|
||||
new LocalFormspecHandler(*event->show_formspec.formname, client);
|
||||
GUIFormSpecMenu::create(¤t_formspec, client, &input->joystick, fs_src, txt_dst);
|
||||
GUIFormSpecMenu::create(current_formspec, client, &input->joystick, fs_src, txt_dst);
|
||||
|
||||
delete event->show_formspec.formspec;
|
||||
delete event->show_formspec.formname;
|
||||
@ -3213,7 +3210,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
|
||||
&client->getEnv().getClientMap(), nodepos);
|
||||
TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
|
||||
|
||||
GUIFormSpecMenu::create(¤t_formspec, client, &input->joystick, fs_src,
|
||||
GUIFormSpecMenu::create(current_formspec, client, &input->joystick, fs_src,
|
||||
txt_dst);
|
||||
cur_formname.clear();
|
||||
|
||||
@ -4110,7 +4107,7 @@ void Game::showPauseMenu()
|
||||
FormspecFormSource *fs_src = new FormspecFormSource(os.str());
|
||||
LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
|
||||
|
||||
GUIFormSpecMenu::create(¤t_formspec, client, &input->joystick, fs_src, txt_dst);
|
||||
GUIFormSpecMenu::create(current_formspec, client, &input->joystick, fs_src, txt_dst);
|
||||
current_formspec->setFocus("btn_continue");
|
||||
current_formspec->doPause = true;
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "gettime.h"
|
||||
#include "gettext.h"
|
||||
#include "scripting_server.h"
|
||||
#include "mainmenumanager.h"
|
||||
#include "porting.h"
|
||||
#include "settings.h"
|
||||
#include "client.h"
|
||||
@ -131,13 +132,13 @@ GUIFormSpecMenu::~GUIFormSpecMenu()
|
||||
delete m_text_dst;
|
||||
}
|
||||
|
||||
void GUIFormSpecMenu::create(GUIFormSpecMenu **cur_formspec, Client *client,
|
||||
void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client,
|
||||
JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest)
|
||||
{
|
||||
if (*cur_formspec == 0) {
|
||||
*cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
|
||||
if (cur_formspec == nullptr) {
|
||||
cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
|
||||
client, client->getTextureSource(), fs_src, txt_dest);
|
||||
(*cur_formspec)->doPause = false;
|
||||
cur_formspec->doPause = false;
|
||||
|
||||
/*
|
||||
Caution: do not call (*cur_formspec)->drop() here --
|
||||
@ -148,8 +149,8 @@ void GUIFormSpecMenu::create(GUIFormSpecMenu **cur_formspec, Client *client,
|
||||
*/
|
||||
|
||||
} else {
|
||||
(*cur_formspec)->setFormSource(fs_src);
|
||||
(*cur_formspec)->setTextDest(txt_dest);
|
||||
cur_formspec->setFormSource(fs_src);
|
||||
cur_formspec->setTextDest(txt_dest);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ public:
|
||||
|
||||
~GUIFormSpecMenu();
|
||||
|
||||
static void create(GUIFormSpecMenu **cur_formspec, Client *client,
|
||||
static void create(GUIFormSpecMenu *&cur_formspec, Client *client,
|
||||
JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest);
|
||||
|
||||
void setFormSpec(const std::string &formspec_string,
|
||||
|
@ -56,13 +56,11 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
|
||||
}
|
||||
|
||||
// Assign colors
|
||||
static const video::SColor usable_colors[] = {
|
||||
video::SColor(255, 255, 100, 100),
|
||||
static const video::SColor usable_colors[] = {video::SColor(255, 255, 100, 100),
|
||||
video::SColor(255, 90, 225, 90),
|
||||
video::SColor(255, 100, 100, 255),
|
||||
video::SColor(255, 255, 150, 50),
|
||||
video::SColor(255, 220, 220, 100)
|
||||
};
|
||||
video::SColor(255, 220, 220, 100)};
|
||||
static const u32 usable_colors_count =
|
||||
sizeof(usable_colors) / sizeof(*usable_colors);
|
||||
u32 next_color_i = 0;
|
||||
@ -82,7 +80,7 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
|
||||
s32 textx2 = textx + 200 - 15;
|
||||
s32 meta_i = 0;
|
||||
|
||||
for (const auto &p: m_meta) {
|
||||
for (const auto &p : m_meta) {
|
||||
const std::string &id = p.first;
|
||||
const Meta &meta = p.second;
|
||||
s32 x = x_left;
|
||||
@ -99,17 +97,15 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
|
||||
char buf[10];
|
||||
snprintf(buf, 10, "%.3g", show_max);
|
||||
font->draw(utf8_to_wide(buf).c_str(),
|
||||
core::rect<s32>(textx, y - graphh,
|
||||
textx2, y - graphh + texth),
|
||||
core::rect<s32>(textx, y - graphh, textx2,
|
||||
y - graphh + texth),
|
||||
meta.color);
|
||||
snprintf(buf, 10, "%.3g", show_min);
|
||||
font->draw(utf8_to_wide(buf).c_str(),
|
||||
core::rect<s32>(textx, y - texth,
|
||||
textx2, y),
|
||||
meta.color);
|
||||
core::rect<s32>(textx, y - texth, textx2, y), meta.color);
|
||||
font->draw(utf8_to_wide(id).c_str(),
|
||||
core::rect<s32>(textx, y - graphh / 2 - texth / 2,
|
||||
textx2, y - graphh / 2 + texth / 2),
|
||||
core::rect<s32>(textx, y - graphh / 2 - texth / 2, textx2,
|
||||
y - graphh / 2 + texth / 2),
|
||||
meta.color);
|
||||
s32 graph1y = y;
|
||||
s32 graph1h = graphh;
|
||||
@ -120,8 +116,7 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
|
||||
for (const Piece &piece : m_log) {
|
||||
float value = 0;
|
||||
bool value_exists = false;
|
||||
Profiler::GraphValues::const_iterator k =
|
||||
piece.values.find(id);
|
||||
Profiler::GraphValues::const_iterator k = piece.values.find(id);
|
||||
|
||||
if (k != piece.values.end()) {
|
||||
value = k->second;
|
||||
@ -149,8 +144,10 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
|
||||
if (lastscaledvalue_exists) {
|
||||
s32 ivalue1 = lastscaledvalue * graph1h;
|
||||
s32 ivalue2 = scaledvalue * graph1h;
|
||||
driver->draw2DLine(v2s32(x - 1, graph1y - ivalue1),
|
||||
v2s32(x, graph1y - ivalue2), meta.color);
|
||||
driver->draw2DLine(
|
||||
v2s32(x - 1, graph1y - ivalue1),
|
||||
v2s32(x, graph1y - ivalue2),
|
||||
meta.color);
|
||||
}
|
||||
|
||||
lastscaledvalue = scaledvalue;
|
||||
|
@ -30,22 +30,25 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
class ProfilerGraph
|
||||
{
|
||||
private:
|
||||
struct Piece {
|
||||
struct Piece
|
||||
{
|
||||
Piece(Profiler::GraphValues v) : values(std::move(v)) {}
|
||||
Profiler::GraphValues values;
|
||||
};
|
||||
struct Meta {
|
||||
struct Meta
|
||||
{
|
||||
float min;
|
||||
float max;
|
||||
video::SColor color;
|
||||
Meta(float initial = 0,
|
||||
video::SColor color = video::SColor(255, 255, 255, 255)):
|
||||
video::SColor color = video::SColor(255, 255, 255, 255)) :
|
||||
min(initial),
|
||||
max(initial),
|
||||
color(color)
|
||||
{}
|
||||
max(initial), color(color)
|
||||
{
|
||||
}
|
||||
};
|
||||
std::deque<Piece> m_log;
|
||||
|
||||
public:
|
||||
u32 m_log_max_size = 200;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user