2015-09-30 02:56:11 +02:00
|
|
|
#ifndef _BASE_SHARED_HPP_
|
|
|
|
#define _BASE_SHARED_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
#include "SqBase.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <vcmp.h>
|
|
|
|
#include <sqrat.h>
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
extern const SQChar * g_EmptyStr;
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2015-11-01 09:55:47 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Proxies to comunicate with the server.
|
2015-11-01 09:55:47 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
extern PluginFuncs* _Func;
|
|
|
|
extern PluginCallbacks* _Clbk;
|
|
|
|
extern PluginInfo* _Info;
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
template < typename T > struct NumLimit;
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template <> struct NumLimit< char > { static const char Min, Max; };
|
|
|
|
template <> struct NumLimit< signed char > { static const signed char Min, Max; };
|
|
|
|
template <> struct NumLimit< unsigned char > { static const unsigned char Min, Max; };
|
|
|
|
template <> struct NumLimit< signed short > { static const signed short Min, Max; };
|
|
|
|
template <> struct NumLimit< unsigned short > { static const unsigned short Min, Max; };
|
|
|
|
template <> struct NumLimit< signed int > { static const signed int Min, Max; };
|
|
|
|
template <> struct NumLimit< unsigned int > { static const unsigned int Min, Max; };
|
|
|
|
template <> struct NumLimit< signed long > { static const signed long Min, Max; };
|
|
|
|
template <> struct NumLimit< unsigned long > { static const unsigned long Min, Max; };
|
|
|
|
template <> struct NumLimit< signed long long > { static const signed long long Min, Max; };
|
|
|
|
template <> struct NumLimit< unsigned long long > { static const unsigned long long Min, Max; };
|
|
|
|
template <> struct NumLimit< float > { static const float Min, Max; };
|
|
|
|
template <> struct NumLimit< double > { static const double Min, Max; };
|
|
|
|
template <> struct NumLimit< long double > { static const long double Min, Max; };
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
template< typename T > inline bool EpsEq(const T a, const T b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return abs(a - b) <= 0;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
template <> inline bool EpsEq(const Float32 a, const Float32 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return fabs(a - b) <= 0.000001f;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
template <> inline bool EpsEq(const Float64 a, const Float64 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return fabs(a - b) <= 0.000000001d;
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template< typename T > inline bool EpsLt(const T a, const T b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a < b);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsLt(const Float32 a, const Float32 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a - b) < 0.000001f;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsLt(const Float64 a, const Float64 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a - b) < 0.000000001d;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template< typename T > inline bool EpsGt(const T a, const T b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a > b);
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsGt(const Float32 a, const Float32 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a - b) > 0.000001f;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsGt(const Float64 a, const Float64 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a - b) > 0.000000001d;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template< typename T > inline bool EpsLtEq(const T a, const T b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a < b);
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsLtEq(const Float32 a, const Float32 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a - b) < 0.000001f;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsLtEq(const Float64 a, const Float64 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a - b) < 0.000000001d;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template< typename T > inline bool EpsGtEq(const T a, const T b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a > b);
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsGtEq(const Float32 a, const Float32 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a - b) > 0.000001f;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsGtEq(const Float64 a, const Float64 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a - b) > 0.000000001d;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template< typename T > inline T Clamp(T val, T min, T max)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return val < min ? min : (val > max ? max : val);
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Compute the next power of two for the specified number.
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
inline Uint32 NextPow2(Uint32 num)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
--num;
|
|
|
|
num |= num >> 1;
|
|
|
|
num |= num >> 2;
|
|
|
|
num |= num >> 4;
|
|
|
|
num |= num >> 8;
|
|
|
|
num |= num >> 16;
|
|
|
|
return ++num;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void LogDbg(CCStr fmt, ...);
|
|
|
|
void LogUsr(CCStr fmt, ...);
|
|
|
|
void LogScs(CCStr fmt, ...);
|
|
|
|
void LogInf(CCStr fmt, ...);
|
|
|
|
void LogWrn(CCStr fmt, ...);
|
|
|
|
void LogErr(CCStr fmt, ...);
|
|
|
|
void LogFtl(CCStr fmt, ...);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void LogSDbg(CCStr fmt, ...);
|
|
|
|
void LogSUsr(CCStr fmt, ...);
|
|
|
|
void LogSScs(CCStr fmt, ...);
|
|
|
|
void LogSInf(CCStr fmt, ...);
|
|
|
|
void LogSWrn(CCStr fmt, ...);
|
|
|
|
void LogSErr(CCStr fmt, ...);
|
|
|
|
void LogSFtl(CCStr fmt, ...);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool cLogDbg(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogUsr(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogScs(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogInf(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogWrn(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogErr(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogFtl(bool cond, CCStr fmt, ...);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool cLogSDbg(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSUsr(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSScs(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSInf(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSWrn(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSErr(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSFtl(bool cond, CCStr fmt, ...);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void SqThrow(CCStr fmt, ...);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object & NullObject();
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Array & NullArray();
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Function & NullFunction();
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template < typename T > Object MakeObject(const T & v)
|
|
|
|
{
|
|
|
|
PushVar< T >(DefaultVM::Get(), v);
|
|
|
|
Var< Object > var(DefaultVM::Get(), -1);
|
|
|
|
sq_pop(DefaultVM::Get(), 1);
|
|
|
|
return var.value;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template < typename T > Object MakeObject(HSQUIRRELVM vm, const T & v)
|
|
|
|
{
|
|
|
|
PushVar< T >(vm, v);
|
|
|
|
Var< Object > var(vm, -1);
|
|
|
|
sq_pop(vm, 1);
|
|
|
|
return var.value;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Simple function to check whether the specified string can be considered as a boolean value
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
bool SToB(CSStr str);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
*
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
CSStr ToStrF(CCStr fmt, ...);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
*
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
CSStr ToStringF(CCStr fmt, ...);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const Color3 & GetRandomColor();
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Value extractors.
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
Color3 GetColor(CSStr name);
|
|
|
|
AABB GetAABB(CSStr str, SQChar delim);
|
|
|
|
Circle GetCircle(CSStr str, SQChar delim);
|
|
|
|
Color3 GetColor3(CSStr str, SQChar delim);
|
|
|
|
Color4 GetColor4(CSStr str, SQChar delim);
|
|
|
|
Quaternion GetQuaternion(CSStr str, SQChar delim);
|
|
|
|
Sphere GetSphere(CSStr str, SQChar delim);
|
|
|
|
Vector2 GetVector2(CSStr str, SQChar delim);
|
|
|
|
Vector2i GetVector2i(CSStr str, SQChar delim);
|
|
|
|
Vector3 GetVector3(CSStr str, SQChar delim);
|
|
|
|
Vector4 GetVector4(CSStr str, SQChar delim);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _BASE_SHARED_HPP_
|