Rehti MMORPG  1.0.0
Rehti MMORPG is a free and open source MMORPG game.
rehtiLib/assets/loader/src/Utils.hpp File Reference
#include <exception>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <ranges>
#include <vector>
#include "../lodepng/lodepng.h"
Include dependency graph for rehtiLib/assets/loader/src/Utils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::vector< std::string > readDirectory (std::string path, std::string extension)
 Reads all the files in the directory and returns a vector of the filenames. Only returns files with the given extension. More...
 
void readPng (std::vector< unsigned char > &image, unsigned &width, unsigned &height, std::string filepath)
 Reads a PNG file and returns the image data, width and height. More...
 
template<typename T >
void rotateMatrix (std::vector< std::vector< T >> &matrix, uint8_t rotation)
 Rotates the matrix 90 degrees counter-clockwise. Rotation is calculated by rotation-param * 90 degrees. More...
 
template<typename T >
void populateMatrix (std::vector< std::vector< T >> &matrix, const std::vector< std::vector< std::string >> &areaMap, T defaultValue, unsigned AREA_WIDTH, unsigned AREA_HEIGHT)
 Populates a matrix with a default value. The matrix is all the areas combined and expanded e.g. the whole map. The matrix row sizes DO NOT need to match. More...
 
template<typename T , typename K >
void populateMatrixFromReference (std::vector< std::vector< T >> &matrix, const std::vector< std::vector< K >> &referenceMatrix, T defaultValue)
 Populates a matrix from a reference matrix. Uses a default value for empty cells. Reference matrix is given (instead of it's dimensions) because the row sizes might not match. More...
 
template<typename T >
void writeMatrixToFile (const std::vector< std::vector< T >> &matrix, const std::string &filepath)
 Takes in a matrix<T> and writes that to a text file. Values are separated by commas and rows by newlines. More...
 

Function Documentation

◆ populateMatrix()

template<typename T >
void populateMatrix ( std::vector< std::vector< T >> &  matrix,
const std::vector< std::vector< std::string >> &  areaMap,
defaultValue,
unsigned  AREA_WIDTH,
unsigned  AREA_HEIGHT 
)

Populates a matrix with a default value. The matrix is all the areas combined and expanded e.g. the whole map. The matrix row sizes DO NOT need to match.

Parameters
matrix
areaMap
defaultValue
AREA_WIDTH
AREA_HEIGHT
Here is the caller graph for this function:

◆ populateMatrixFromReference()

template<typename T , typename K >
void populateMatrixFromReference ( std::vector< std::vector< T >> &  matrix,
const std::vector< std::vector< K >> &  referenceMatrix,
defaultValue 
)

Populates a matrix from a reference matrix. Uses a default value for empty cells. Reference matrix is given (instead of it's dimensions) because the row sizes might not match.

Parameters
matrix
referenceMatrix
defaultValueto fill the matrix with
Here is the caller graph for this function:

◆ readDirectory()

std::vector<std::string> readDirectory ( std::string  path,
std::string  extension 
)

Reads all the files in the directory and returns a vector of the filenames. Only returns files with the given extension.

Parameters
pathPath to the directory
extensionFile extension to filter the files
Returns
std::vector<std::string> Vector of filenames

◆ readPng()

void readPng ( std::vector< unsigned char > &  image,
unsigned &  width,
unsigned &  height,
std::string  filepath 
)

Reads a PNG file and returns the image data, width and height.

Parameters
imageVector to store the image data
widthWidth of the image
heightHeight of the image
filepathFilepath to the PNG file
Here is the caller graph for this function:

◆ rotateMatrix()

template<typename T >
void rotateMatrix ( std::vector< std::vector< T >> &  matrix,
uint8_t  rotation 
)

Rotates the matrix 90 degrees counter-clockwise. Rotation is calculated by rotation-param * 90 degrees.

Parameters
matrixMatrix to rotate
rotationNumber of 90 degree rotations
Here is the caller graph for this function:

◆ writeMatrixToFile()

template<typename T >
void writeMatrixToFile ( const std::vector< std::vector< T >> &  matrix,
const std::string &  filepath 
)

Takes in a matrix<T> and writes that to a text file. Values are separated by commas and rows by newlines.

Row sizes do not need to match.

Parameters
matrixMatrix to write to file
filepathFilepath to write to