Skip to content

Utilities

Matt Styles edited this page May 6, 2020 · 6 revisions

xygine also includes some cross-platform utility functions for common tasks such as file manipulation, maths and time/date functions:

xy::Util::Vector

Includes dot and cross product functions, length, rotation and reflection calculations for sf::Vector2 (and some sf::Vector3).

#include <xyginext/util/Vector.hpp>
xy::Util::Random

Contains functions for generating random values from ranges, and distributions such as poisson disk across a given area.

#include <xyginext/util/Random.hpp>
xy::Util::String

Includes a tokeniser and toLower functions for std::string manipulation.

#include <xyginext/util/String.hpp>
xy::ConfigFile

A utility class for reading and writing configuration files. Useful for storing human readable settings which can be updated at runtime. The ConfigFile class is also used when creating a SpriteSheet or particle settings exported by the particle editor.

#include <xyginext/core/ConfigFile.hpp>
xy::FileSystem

Cross platform file manipulation, such as directory listing, file creation and file path parsing. The FileSystem class also contains functions for creating dialogues to open/save files or browse directories on the current file system.

#include <xyginext/core/FileSystem.hpp>
xy::SysTime

Time functions for retrieving the current system time, either as integer values broken down in to days / months / years etc. or formatted string representation

#include <xyginext/core/SysTime.hpp>
xy::Logger

Message logging can be done either by calling xy::Logger::log("Message", xy::Logger::Type, xy::Logger::Output) or by using the C++ streams style interface

xy::Logger::log(xy::Logger::Type, xy::Logger::Output) << "Value is: " << value << std::endl;

Type can be Info, Warning or Error, and changes the colour highlighting in xygine's console output. Warnings are highlighted orange, and errors are red. Output can be Console, File or All. Console output is printed to both xygine's console and stdout. File output is saved to a file named output.log in the current working directory. The stream interface also has 3 shortcuts, all of which print to the console window: LogI, LogW and LogE.

LogI << "This is an information message" << std::endl;
LogW << "This is a warning message" << std::endl;
LogE << "This is an error message" << std::endl;

Logging is enabled by including <xyginext/core/Log.hpp>