hoa_utils Namespace Reference

Contains utility code used across the entire source code. More...


Classes

class  Singleton
 Used for transforming a standard class into a singleton class. More...
class  ustring
 Implements unicode strings with uint16 as the character type. More...

Functions

template<class T>
void DataToString (std::string &s, const T &data)
 Converts data to string.
float FloorToFloatMultiple (const float value, const float multiple)
 Rounds down a float to a multiple of another float.
bool IsFloatInRange (float value, float lower, float upper)
 Determines if a floating point number is within a range of two numbers.
bool IsOddNumber (uint32 x)
 Determines if an integer is an odd number or not.
bool IsPowerOfTwo (uint32 x)
 Determines if an unsigned integer is a power of two or not.
bool IsStringNumeric (const string &text)
ustring MakeUnicodeString (const string &text)
template<typename T, size_t N>
size_t NumberElementsArray (T(&)[N])
 A template function that returns the number of elements in an array.
uint32 RoundUpPow2 (uint32 x)
 Rounds an unsigned integer up to the nearest power of two.
Directory and File Manipulation Functions
bool CleanDirectory (const std::string &dir_name)
 Removes all files present in a directory.
bool DoesFileExist (const std::string &file_name)
 Checks if a file exists on the system or not.
bool MakeDirectory (const std::string &dir_name)
 Creates a directory relative to the path of the running application.
bool MoveFile (const std::string &source_name, const std::string &destination_name)
 Moves a file from one location to another.
bool RemoveDirectory (const std::string &dir_name)
 Deletes a directory, as well as any files the directory may contain.
Random Variable Genreator Fucntions
int32 GaussianRandomValue (int32 mean, float std_dev=10.0f, bool positive_value=true)
 Returns a Gaussian random value with specified mean and standard deviation.
bool Probability (uint32 chance)
 Returns true/false depending on the chance.
int32 RandomBoundedInteger (int32 lower_bound, int32 upper_bound)
 Returns a random interger value uniformally distributed between two inclusive bounds.
float RandomFloat ()
 Creates a uniformly distributed random floating point number.
Version Checking Functions
string GetLatestVersion ()
 Gets newest version.
bool IsLatestVersion ()
 Checks version against a remote server.
Sorting Functions
template<typename T>
void InsertionSort (std::vector< T > &swap_vec)
 Performs an insertion sort on a vector of elements.
String Utility Functions
bool IsStringNumeric (const std::string &text)
 Determines if a string is a valid numeric string.
string MakeStandardString (const hoa_utils::ustring &text)
 Creates an starndard string from a ustring.
hoa_utils::ustring MakeUnicodeString (const std::string &text)
 Creates a ustring from a standard string.
template<typename T>
std::string NumberToString (const T t)
 Converts an integer type into a standard string.

Variables

static std::string temp_version_str
bool UTILS_DEBUG
 Determines whether the code in the hoa_utils namespace should print debug statements or not.
bool UTILS_DEBUG = false
 Determines whether the code in the hoa_utils namespace should print debug statements or not.
bool UTILS_DEBUG
Multiples of Pi constants
PI and multiples of PI. Used in various math calculations such as interpolations.

These constants are mostly used in the video engine.

const float UTILS_2PI = 6.283185307f
const float UTILS_HALF_PI = 1.570796326f
const float UTILS_PI = 3.141592653f
const float UTILS_QUARTER_PI = 0.785398163f


Detailed Description

Contains utility code used across the entire source code.

Function Documentation

bool hoa_utils::CleanDirectory ( const std::string &  dir_name  ) 

Removes all files present in a directory.

Parameters:
dir_name The name of the directory to clean (e.g. "img/screnshots")
Returns:
True upon success, false upon failure

Definition at line 417 of file utils.cpp.

Referenced by hoa_video::GameVideo::_DeleteTempTextures(), and RemoveDirectory().

template<class T>
void hoa_utils::DataToString ( std::string &  s,
const T &  data 
)

Converts data to string.

Thi function convers ata to string, if it has the sstring::operator<< implementated

Parameters:
s String to be filled
data Data to convert to string

Definition at line 159 of file utils.h.

Referenced by hoa_video::GameVideo::_LoadMultiImage().

bool hoa_utils::DoesFileExist ( const std::string &  file_name  ) 

Checks if a file exists on the system or not.

Parameters:
file_name The name of the file to check (e.g. "dat/saved_game.lua")
Returns:
True if the file was found, or false if it was not found.

Definition at line 375 of file utils.cpp.

Referenced by hoa_boot::BootMode::_OnLoadGame().

float hoa_utils::FloorToFloatMultiple ( const float  value,
const float  multiple 
)

Rounds down a float to a multiple of another float.

Returns:
Rounded float
Parameters:
value Number to be rounded
multiple Multiple to be considered when rounding

Definition at line 70 of file utils.cpp.

Referenced by hoa_map::MapMode::_CalculateDrawInfo().

int32 hoa_utils::GaussianRandomValue ( int32  mean,
float  std_dev = 10.0f,
bool  positive_value = true 
)

Returns a Gaussian random value with specified mean and standard deviation.

Parameters:
mean 
std_dev The standard deviation of the Gaussian function (optional, default is 10.0f)
positive_value If true the function will not return a negative result (optional, default is true)
Returns:
An Gaussian random integer with a mean and standard deviation as specified by the user

Definition at line 325 of file utils.cpp.

References RandomFloat().

Referenced by hoa_global::GlobalEnemy::Initialize().

Here is the call graph for this function:

std::string hoa_utils::GetLatestVersion (  ) 

Gets newest version.

Returns:
A string containing the version information of the latest version
This should only be called after a call to IsLatestVersion()

Definition at line 563 of file utils.cpp.

References temp_version_str.

Referenced by hoa_boot::BootMode::BootMode(), and hoa_main::ParseProgramOptions().

template<typename T>
void hoa_utils::InsertionSort ( std::vector< T > &  swap_vec  ) 

Performs an insertion sort on a vector of elements.

Parameters:
swap_vec The vector of elements to be sorted.
Insertion sort should *only* be used for vectors that are already nearly sorted, or for vectors of size 10 or less. Otherwise this algorithm becomes computationally expensive and you should probably choose another sorting algorithm at that point. A good example of code that uses this algorithm well can be found in map.cpp, which sorts map objects every frame. Because map objects change position slowly, there is usually no change or little relative change in sorting order from the previous pass.

Note:
The type of element that is passed should have its > and = operators functionally correct (if T is a class, you must overload these operators). In general, its good practice if you overload all comparison operators for these types.

Do not invoke this function with a vector of pointers to class-type objects, as it will cause a compilation error.

Definition at line 456 of file utils.h.

bool hoa_utils::IsFloatInRange ( float  value,
float  lower,
float  upper 
)

Determines if a floating point number is within a range of two numbers.

Parameters:
value The floating point value to compare.
lower The minimum bound (inclusive).
upper The maximum bound (inclusive).
Returns:
True if the value lies within the two bounds. This function should be used in place of direct comparison of two floating point values. The reason for this is that there are small variations in floating point representation across systems and different rounding schemes, so its best to examine numbers within a reasonably sized range. For example, if you want to detect if a number is 1.0f, try 0.999f and 1.001f for the bound arguments.

Definition at line 65 of file utils.cpp.

Referenced by hoa_map::MapMode::_CalculateDrawInfo().

bool hoa_utils::IsLatestVersion (  ) 

Checks version against a remote server.

Returns:
A boolean indicating whether the user is running the latest version
This function will return true to indicate that the user is using the latest version OR that an error occured.

Definition at line 523 of file utils.cpp.

References ALLACROST_MAJOR_VERSION, ALLACROST_MINOR_VERSION, ALLACROST_PATCH, hoa_socket::Socket::Connect(), hoa_socket::Socket::Disconnect(), hoa_socket::Socket::IsConnected(), hoa_socket::Socket::IsQueued(), hoa_socket::Socket::ScanLine(), temp_version_str, VERSION_HOST, VERSION_PATH, and hoa_socket::Socket::Write().

Referenced by hoa_main::ParseProgramOptions().

Here is the call graph for this function:

bool hoa_utils::IsOddNumber ( uint32  x  ) 

Determines if an integer is an odd number or not.

Parameters:
x The unsigned integer to examine.
Returns:
True if the number is odd, false if it is not.
Note:
Using a signed integer with this function will yield the same result.

Definition at line 58 of file utils.cpp.

Referenced by hoa_map::MapMode::_CalculateDrawInfo().

bool hoa_utils::IsPowerOfTwo ( uint32  x  ) 

Determines if an unsigned integer is a power of two or not.

Parameters:
x The number to examine.
Returns:
True if the number if a power of two, false otherwise.

Definition at line 52 of file utils.cpp.

Referenced by hoa_video::GameVideo::_CreateTexSheet().

bool hoa_utils::IsStringNumeric ( const std::string &  text  ) 

Determines if a string is a valid numeric string.

Parameters:
text The string to check
Returns:
A std::string containing the parameter in string form
This function will accept strings with + or - characters as the first string element and strings including a single decimal point. Examples of valid numeric strings are: "50", ".2350", "-252.5"

Referenced by hoa_video::OptionBox::_ConstructOption().

bool hoa_utils::IsStringNumeric ( const string &  text  ) 

Definition at line 229 of file utils.cpp.

bool hoa_utils::MakeDirectory ( const std::string &  dir_name  ) 

Creates a directory relative to the path of the running application.

Parameters:
dir_name The name of the directory to create (e.g. "img/screnshots")
Returns:
True upon success, false upon failure

Definition at line 391 of file utils.cpp.

std::string hoa_utils::MakeStandardString ( const hoa_utils::ustring text  ) 

Creates an starndard string from a ustring.

Parameters:
text The ustring to create the equivalent standard string for
Returns:
A string containing the same information as the ustring
This function is much less likely to be used as MakeUnicodeString. Standard strings are used for resource loading (of images, sounds, etc.) so this may come in use if a ustring contains file information.

Definition at line 276 of file utils.cpp.

References hoa_utils::ustring::length().

Referenced by hoa_video::OptionBox::_ConstructOption(), hoa_menu::private_menu::InventoryWindow::_UpdateItemText(), hoa_menu::private_menu::SkillsWindow::_UpdateSkillList(), and hoa_video::GameVideo::RenderText().

Here is the call graph for this function:

hoa_utils::ustring hoa_utils::MakeUnicodeString ( const std::string &  text  ) 

Creates a ustring from a standard string.

Parameters:
text The standard string to create the ustring equivalent for
Returns:
A ustring containing the same information as the function parameter
This function is useful for hard-coding text to be displayed on the screen, as unicode characters are the only characters allowed to be displayed. This function serves primarily for debugging and diagnostic purposes.

Referenced by hoa_battle::private_battle::ActionWindow::_ConstructActionSelectionList(), hoa_battle::private_battle::ActionWindow::_DrawActionInformation(), hoa_battle::private_battle::ActionWindow::_DrawActionSelection(), hoa_menu::MenuMode::_DrawBottomMenu(), hoa_battle::private_battle::ActionWindow::_DrawTargetSelection(), hoa_menu::private_menu::InventoryWindow::_InitCategory(), hoa_menu::private_menu::EquipWindow::_InitCharSelect(), hoa_menu::private_menu::SkillsWindow::_InitCharSelect(), hoa_menu::private_menu::StatusWindow::_InitCharSelect(), hoa_menu::private_menu::InventoryWindow::_InitCharSelect(), hoa_menu::private_menu::SkillsWindow::_InitSkillsCategories(), hoa_map::MapMode::_Load(), hoa_global::GlobalAttackPoint::_LoadData(), hoa_boot::BootMode::_OnMenuDebug(), hoa_boot::BootMode::_SetupAudioOptionsMenu(), hoa_menu::MenuMode::_SetupEquipOptionBox(), hoa_menu::MenuMode::_SetupInventoryOptionBox(), hoa_boot::BootMode::_SetupJoySetttingsMenu(), hoa_boot::BootMode::_SetupKeySetttingsMenu(), hoa_boot::BootMode::_SetupMainMenu(), hoa_menu::MenuMode::_SetupMainOptionBox(), hoa_boot::BootMode::_SetupOptionsMenu(), hoa_menu::MenuMode::_SetupOptionsOptionBox(), hoa_boot::BootMode::_SetupResolutionMenu(), hoa_menu::MenuMode::_SetupSaveOptionBox(), hoa_menu::MenuMode::_SetupSkillsOptionBox(), hoa_menu::MenuMode::_SetupStatusOptionBox(), hoa_boot::BootMode::_SetupVideoOptionsMenu(), hoa_boot::BootMode::_UpdateAudioOptions(), hoa_menu::private_menu::InventoryWindow::_UpdateItemText(), hoa_boot::BootMode::_UpdateJoySettings(), hoa_boot::BootMode::_UpdateKeySettings(), hoa_menu::private_menu::SkillsWindow::_UpdateSkillList(), hoa_boot::BootMode::_UpdateVideoOptions(), hoa_battle::private_battle::ActionWindow::ActionWindow(), hoa_shop::private_shop::ObjectSellListWindow::AddEntry(), hoa_shop::private_shop::ObjectListWindow::AddEntry(), hoa_map::private_map::MapDialogue::AddText(), hoa_shop::private_shop::ConfirmWindow::ConfirmWindow(), hoa_menu::private_menu::EquipWindow::Draw(), hoa_menu::private_menu::StatusWindow::Draw(), hoa_menu::private_menu::CharacterWindow::Draw(), hoa_battle::private_battle::FinishWindow::Draw(), hoa_battle::private_battle::BattleEnemyActor::DrawStatus(), hoa_battle::private_battle::FinishWindow::FinishWindow(), hoa_global::GlobalArmor::GlobalArmor(), hoa_global::GlobalCharacter::GlobalCharacter(), hoa_global::GlobalEnemy::GlobalEnemy(), hoa_global::GlobalItem::GlobalItem(), hoa_global::GlobalSkill::GlobalSkill(), hoa_global::GlobalWeapon::GlobalWeapon(), hoa_quit::QuitMode::QuitMode(), hoa_shop::private_shop::ShopActionWindow::ShopActionWindow(), hoa_boot::WelcomeScreen::Show(), hoa_boot::CreditsScreen::Show(), hoa_shop::private_shop::ObjectListWindow::Update(), and hoa_shop::private_shop::ShopActionWindow::UpdateFinanceText().

ustring hoa_utils::MakeUnicodeString ( const string &  text  ) 

Definition at line 259 of file utils.cpp.

Referenced by hoa_script::ReadScriptDescriptor::ReadUString(), and hoa_map::private_map::MapSprite::SetName().

bool hoa_utils::MoveFile ( const std::string &  source_name,
const std::string &  destination_name 
)

Moves a file from one location to another.

Parameters:
source_name The name of the file that is to be moved
destination_name The location name to where the file should be moved to
Returns:
True if the file was successfully moved, false if it was not
This function can also be used to rename files.
Note:
If there exists a file with the same name + path as the destination_name, it will be overwritten without warning or indication. Be careful when using this function!

Definition at line 385 of file utils.cpp.

Referenced by hoa_script::ModifyScriptDescriptor::CommitChanges().

template<typename T, size_t N>
size_t hoa_utils::NumberElementsArray ( T(&)  [N]  ) 

A template function that returns the number of elements in an array.

Parameters:
array The array of elements
Returns:
The number of elements in the array

Definition at line 383 of file utils.h.

template<typename T>
std::string hoa_utils::NumberToString ( const T  t  ) 

Converts an integer type into a standard string.

Parameters:
T The integer type to convert to a string
Returns:
A std::string containing the parameter in string form

Definition at line 339 of file utils.h.

Referenced by hoa_battle::private_battle::ActionWindow::_ConstructActionSelectionList(), hoa_battle::private_battle::ActionWindow::_DrawActionInformation(), hoa_menu::MenuMode::_DrawBottomMenu(), hoa_global::GameGlobal::_SaveCharacter(), hoa_global::GameGlobal::_SaveEvents(), hoa_global::GameGlobal::_SaveInventory(), hoa_menu::private_menu::InventoryWindow::_UpdateItemText(), hoa_boot::BootMode::_UpdateJoySettings(), hoa_menu::private_menu::SkillsWindow::_UpdateSkillList(), hoa_boot::BootMode::_UpdateVideoOptions(), hoa_shop::private_shop::ObjectSellListWindow::AddEntry(), hoa_shop::private_shop::ObjectListWindow::AddEntry(), hoa_battle::private_battle::FinishWindow::Draw(), hoa_battle::private_battle::BattleEnemyActor::DrawSprite(), hoa_battle::private_battle::BattleCharacterActor::DrawSprite(), hoa_battle::private_battle::BattleCharacterActor::DrawStatus(), hoa_script::ReadScriptDescriptor::OpenTable(), hoa_shop::private_shop::ObjectInfoWindow::SetObject(), hoa_shop::private_shop::ObjectListWindow::Update(), and hoa_shop::private_shop::ShopActionWindow::UpdateFinanceText().

bool hoa_utils::Probability ( uint32  chance  ) 

Returns true/false depending on the chance.

Parameters:
chance Value between 0..100. 0 will always return false and >=100 will always return true.
Returns:
True if the chance occurs

Definition at line 363 of file utils.cpp.

References RandomBoundedInteger().

Here is the call graph for this function:

int32 hoa_utils::RandomBoundedInteger ( int32  lower_bound,
int32  upper_bound 
)

Returns a random interger value uniformally distributed between two inclusive bounds.

Parameters:
lower_bound The lower inclusive bound
upper_bound The upper inclusive bound
Returns:
An integer between [lower_bound, upper_bound]
Note:
If the user specifies a lower bound that is greater than the upper bound, the two bounds are switched.

Definition at line 307 of file utils.cpp.

References RandomFloat(), and UTILS_DEBUG.

Referenced by hoa_map::private_map::MapZone::_RandomPosition(), Probability(), hoa_map::private_map::VirtualSprite::SetRandomDirection(), hoa_battle::private_battle::BattleActor::TakeDamage(), and hoa_map::private_map::EnemySprite::Update().

Here is the call graph for this function:

float hoa_utils::RandomFloat (  ) 

Creates a uniformly distributed random floating point number.

Returns:
A floating-point value between [0.0f, 1.0f]

Definition at line 301 of file utils.cpp.

Referenced by hoa_defs::BindEngineToLua(), GaussianRandomValue(), and RandomBoundedInteger().

bool hoa_utils::RemoveDirectory ( const std::string &  dir_name  ) 

Deletes a directory, as well as any files the directory may contain.

Parameters:
dir_name The name of the directory to remove (e.g. "img/screnshots")
Returns:
True upon success, false upon failure

Definition at line 493 of file utils.cpp.

References CleanDirectory().

Here is the call graph for this function:

uint32 hoa_utils::RoundUpPow2 ( uint32  x  ) 

Rounds an unsigned integer up to the nearest power of two.

Parameters:
x The number to round up.
Returns:
The nearest power of two rounded up from the argument.

Definition at line 40 of file utils.cpp.

Referenced by hoa_video::GameVideo::_CacheGlyphs(), hoa_video::GameVideo::_GenTexLine(), hoa_video::GameVideo::_InsertImageInTexSheet(), and hoa_video::GameVideo::CaptureScreen().


Variable Documentation

std::string hoa_utils::temp_version_str [static]

Definition at line 521 of file utils.cpp.

Referenced by GetLatestVersion(), and IsLatestVersion().

const float hoa_utils::UTILS_2PI = 6.283185307f

Definition at line 108 of file utils.h.

Referenced by hoa_video::Interpolator::_EaseTransform(), and hoa_video::private_video::ParticleSystem::_RespawnParticle().

bool hoa_utils::UTILS_DEBUG

Determines whether the code in the hoa_utils namespace should print debug statements or not.

Definition at line 34 of file utils.cpp.

bool hoa_utils::UTILS_DEBUG = false

Determines whether the code in the hoa_utils namespace should print debug statements or not.

Definition at line 34 of file utils.cpp.

bool hoa_utils::UTILS_DEBUG

Definition at line 34 of file utils.cpp.

Referenced by hoa_main::EnableDebugging(), RandomBoundedInteger(), hoa_utils::Singleton< hoa_mode_manager::GameModeManager >::SingletonCreate(), and hoa_utils::Singleton< hoa_mode_manager::GameModeManager >::SingletonDestroy().

const float hoa_utils::UTILS_HALF_PI = 1.570796326f

Definition at line 106 of file utils.h.

Referenced by hoa_video::private_video::ParticleSystem::Draw().

const float hoa_utils::UTILS_PI = 3.141592653f

Definition at line 107 of file utils.h.

const float hoa_utils::UTILS_QUARTER_PI = 0.785398163f

Definition at line 105 of file utils.h.


Generated on Fri Jul 6 23:16:07 2007 for Hero of Allacrost by  doxygen 1.5.1