Files
Leviathan/Client/Game/game/Utility/CommonUtil.h
T
2026-06-01 12:46:52 +02:00

54 lines
1.4 KiB
C++

#pragma once
#include "SLog.h"
// Fraun 7/11/2025 advanced error handle
#include <typeinfo>
#include <string>
int fastf2i_round( float f );
int fastf2i( float fValue );
int Float2Int( float a );
bool isZero( float value );
template <class DEST, class SRC>
DEST dynamicCast( SRC src )
{
if (!src)
{
#ifdef _DEV
assert( 0 && "Type change failed (dynamicCast): the target is not valid." );
SDEBUGLOG( "Type change failed (dynamicCast): the target is not valid" );
#endif
return NULL;
}
// In the distribution version, all type conversion errors should be fixed,
// but it seems difficult to be sure that they are all corrected.
// If dest is not modified, a null reference error may occur because dest becomes null.
// Therefore, it seems that static_cast should be used in the distribution version, as before.
#ifdef _DEV
DEST dest = dynamic_cast<DEST>(src);
if (!dest)
{
// Fraun 7/11/2025 advanced error handle
std::string strOutput = "Type cast failed (dynamicCast) for ";
strOutput += typeid(src).name();
strOutput += " casting to ";
strOutput += typeid(DEST).name();
//assert(NULL && "Type cast failed (dynamicCast) for: %s", );
assert(NULL && strOutput.c_str());
//MessageBox(HWND_DESKTOP, "Type cast failed (dynamicCast)", "Error", MB_OK | MB_ICONERROR );
MessageBox(HWND_DESKTOP, strOutput.c_str(), "Error", MB_OK | MB_ICONERROR );
}
#else
DEST dest = static_cast<DEST>(src);
#endif
return dest;
}