aboutsummaryrefslogtreecommitdiff
path: root/advtrains/textures/advtrains_across.png
diff options
context:
space:
mode:
authorBlockhead <jbis1337@hotmail.com>2020-03-03 22:59:04 +1100
committerBlockhead <jbis1337@hotmail.com>2020-03-03 23:00:20 +1100
commit3b87ac5372c8efa3b8cd3f19a1fc2c9fa88341a2 (patch)
tree59a623fdd8ed509575558bb8579b5e16ed360985 /advtrains/textures/advtrains_across.png
parent0689c70aaccf879e0df59aa7dbedc46be73a445f (diff)
downloadadvtrains-3b87ac5372c8efa3b8cd3f19a1fc2c9fa88341a2.tar.gz
advtrains-3b87ac5372c8efa3b8cd3f19a1fc2c9fa88341a2.tar.bz2
advtrains-3b87ac5372c8efa3b8cd3f19a1fc2c9fa88341a2.zip
Delete train if it ends up off track, show a warning
Diffstat (limited to 'advtrains/textures/advtrains_across.png')
0 files changed, 0 insertions, 0 deletions
d='n143' href='#n143'>143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
Copyright (C) 2018 nerzhul, Loic Blot <loic.blot@unix-experience.fr>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser 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.
*/

#include "porting.h"
#include "profilergraph.h"
#include "util/string.h"

void ProfilerGraph::put(const Profiler::GraphValues &values)
{
	m_log.emplace_back(values);

	while (m_log.size() > m_log_max_size)
		m_log.erase(m_log.begin());
}

void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
		gui::IGUIFont *font) const
{
	// Do *not* use UNORDERED_MAP here as the order needs
	// to be the same for each call to prevent flickering
	std::map<std::string, Meta> m_meta;

	for (const Piece &piece : m_log) {
		for (const auto &i : piece.values) {
			const std::string &id = i.first;
			const float &value = i.second;
			std::map<std::string, Meta>::iterator j = m_meta.find(id);

			if (j == m_meta.end()) {
				m_meta[id] = Meta(value);
				continue;
			}

			if (value < j->second.min)
				j->second.min = value;

			if (value > j->second.max)
				j->second.max = value;
		}
	}

	// Assign colors
	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)};
	static const u32 usable_colors_count =
			sizeof(usable_colors) / sizeof(*usable_colors);
	u32 next_color_i = 0;

	for (auto &i : m_meta) {
		Meta &meta = i.second;
		video::SColor color(255, 200, 200, 200);

		if (next_color_i < usable_colors_count)
			color = usable_colors[next_color_i++];

		meta.color = color;
	}

	s32 graphh = 50;
	s32 textx = x_left + m_log_max_size + 15;
	s32 textx2 = textx + 200 - 15;
	s32 meta_i = 0;

	for (const auto &p : m_meta) {
		const std::string &id = p.first;
		const Meta &meta = p.second;
		s32 x = x_left;
		s32 y = y_bottom - meta_i * 50;
		float show_min = meta.min;
		float show_max = meta.max;

		if (show_min >= -0.0001 && show_max >= -0.0001) {
			if (show_min <= show_max * 0.5)
				show_min = 0;