Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5 Copyright 2013-2016 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.org/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
28#pragma once
29
30#include "Application.h"
31
32#include "utf8/checked.h"
33#include "utf8/unchecked.h"
34
35#include <MyGUI.h>
36
37namespace RoR {
38
39Ogre::String sha1sum(const char *key, int len);
40
41Ogre::String HashData(const char *key, int len);
42
43std::string tryConvertUTF(const char* buffer);
44
45std::string formatBytes(double bytes);
46
47std::time_t getTimeStamp();
48
49Ogre::String getVersionString(bool multiline = true);
50
51inline void replaceString(std::string& str, std::string searchString, std::string replaceString)
52{
53 std::string::size_type pos = 0;
54 while ((pos = str.find(searchString, pos)) != std::string::npos)
55 {
56 str.replace(pos, searchString.size(), replaceString);
57 pos++;
58 }
59}
60
61Ogre::Real Round(Ogre::Real value, unsigned short ndigits = 0);
62
63std::string SanitizeUtf8String(std::string const& str_in);
64std::string SanitizeUtf8CString(const char* start, const char* end = nullptr);
65
66std::wstring Utf8ToWideChar(std::string input_utf8);
67
68inline std::string& TrimStr(std::string& s) { Ogre::StringUtil::trim(s); return s; }
69std::string Sha1Hash(std::string const & data);
70
71std::string JoinStrVec(Ogre::StringVector tokens, const std::string& delim);
72
73// for std::vector
74template <class T, class A, class Predicate>
75inline void EraseIf(std::vector<T, A>& c, Predicate pred)
76{
77 c.erase(std::remove_if(c.begin(), c.end(), pred), c.end());
78}
79
83{
84public:
85 World2ScreenConverter(Ogre::Matrix4 view_mtx, Ogre::Matrix4 proj_mtx, Ogre::Vector2 screen_size):
86 m_view_matrix(view_mtx), m_projection_matrix(proj_mtx), m_screen_size(screen_size)
87 {}
88
90 Ogre::Vector3 Convert(Ogre::Vector3 world_pos)
91 {
92 Ogre::Vector3 view_space_pos = m_view_matrix * world_pos;
93 Ogre::Vector3 clip_space_pos = m_projection_matrix * view_space_pos; // Clip space pos is [-1.f, 1.f]
94 float screen_x = ((clip_space_pos.x / 2.f) + 0.5f) * m_screen_size.x;
95 float screen_y = (1.f - ((clip_space_pos.y / 2.f) + 0.5f)) * m_screen_size.y;
96 return Ogre::Vector3(screen_x, screen_y, view_space_pos.z);
97 }
98
99private:
100 Ogre::Matrix4 m_view_matrix;
101 Ogre::Matrix4 m_projection_matrix;
102 Ogre::Vector2 m_screen_size;
103};
104
105bool IsDistanceWithin(Ogre::Vector3 const& a, Ogre::Vector3 const& b, float max);
106
107std::string PrintMeshInfo(std::string const& title, Ogre::MeshPtr mesh);
108
109void CvarAddFileToList(CVar* cvar, const std::string& filename);
110void CvarRemoveFileFromList(CVar* cvar, const std::string& filename);
111
112void SplitBundleQualifiedFilename(const std::string& bundleQualifiedFilename, std::string& out_bundleName, std::string& out_filename);
113
114} // namespace RoR
Central state/object manager and communications hub.
Quake-style console variable, defined in RoR.cfg or crated via Console UI and scripts.
Definition CVar.h:53
< Keeps data close for faster access.
Definition Utils.h:83
Ogre::Matrix4 m_view_matrix
Definition Utils.h:100
World2ScreenConverter(Ogre::Matrix4 view_mtx, Ogre::Matrix4 proj_mtx, Ogre::Vector2 screen_size)
Definition Utils.h:85
Ogre::Vector2 m_screen_size
Definition Utils.h:102
Ogre::Vector3 Convert(Ogre::Vector3 world_pos)
Definition Utils.h:90
Ogre::Matrix4 m_projection_matrix
Definition Utils.h:101
Ogre::String HashData(const char *key, int len)
Definition Utils.cpp:54
bool IsDistanceWithin(Ogre::Vector3 const &a, Ogre::Vector3 const &b, float max)
Definition Utils.cpp:169
void CvarAddFileToList(CVar *cvar, const std::string &filename)
Definition Utils.cpp:217
std::string JoinStrVec(Ogre::StringVector tokens, const std::string &delim)
Definition Utils.cpp:157
std::wstring Utf8ToWideChar(std::string input_utf8)
Definition Utils.cpp:149
std::string & TrimStr(std::string &s)
Definition Utils.h:68
std::string SanitizeUtf8CString(const char *start, const char *end=nullptr)
Definition Utils.cpp:128
void EraseIf(std::vector< T, A > &c, Predicate pred)
Definition Utils.h:75
std::string Sha1Hash(std::string const &data)
Definition Utils.cpp:141
std::string SanitizeUtf8String(std::string const &str_in)
Definition Utils.cpp:120
void CvarRemoveFileFromList(CVar *cvar, const std::string &filename)
Definition Utils.cpp:227
void SplitBundleQualifiedFilename(const std::string &bundleQualifiedFilename, std::string &out_bundleName, std::string &out_filename)
Definition Utils.cpp:239
void replaceString(std::string &str, std::string searchString, std::string replaceString)
Definition Utils.h:51
std::string formatBytes(double bytes)
Definition Utils.cpp:67
Ogre::String getVersionString(bool multiline=true)
Definition Utils.cpp:82
std::string PrintMeshInfo(std::string const &title, Ogre::MeshPtr mesh)
std::string tryConvertUTF(const char *buffer)
Definition Utils.cpp:61
Ogre::Real Round(Ogre::Real value, unsigned short ndigits=0)
Definition Utils.cpp:101
Ogre::String sha1sum(const char *key, int len)
Definition Utils.cpp:46
std::time_t getTimeStamp()
Definition Utils.cpp:77