00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "asIrrHelper.h"
00018 #include "asDimension2d.h"
00019
00020
00021
00025 template<typename T>
00026 void constructor(void *memory)
00027 {
00028 new (memory) dimension2d<T>();
00029 }
00030
00034 template<typename T>
00035 void constructor(T width, T height, void *memory)
00036 {
00037 new (memory) dimension2d<T>(width, height);
00038 }
00039
00043 template<typename T>
00044 void deconstructor(void *memory)
00045 {
00046 ((dimension2d<T>*)memory)->~dimension2d<T>();
00047 }
00048
00049
00054 template<typename T>
00055 void bindDimension2dT(asIScriptEngine *engine, const char *typeName, const char *asType)
00056 {
00057
00058 int r;
00059 std::stringstream ss;
00060
00061
00062 r = engine->RegisterObjectType(typeName, sizeof(dimension2d<T>), asOBJ_VALUE | asOBJ_APP_CLASS_CD); assert(r >= 0);
00063
00064
00065
00066 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(constructor<T>,
00067 (void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00068
00069 ss.str("");
00070 ss << "void f(" << asType << ", " << asType << ")";
00071 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00072 (T, T, void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00073
00074 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_DESTRUCT, "void f()", asFUNCTION(deconstructor<T>),
00075 asCALL_CDECL_OBJLAST); assert(r >= 0);
00076
00077
00078
00079 ss.str("");
00080 ss << typeName << " f(const " << typeName << " &in, const "<< asType << ")";
00081 r = engine->RegisterGlobalBehaviour(asBEHAVE_MULTIPLY, ss.str().c_str(),
00082 asFUNCTIONPR((multiply< dimension2d<T>, dimension2d<T>, T >),
00083 (const dimension2d<T>&, const T&), dimension2d<T>), asCALL_CDECL);
00084 assert(r >= 0);
00085
00086
00087 ss.str("");
00088 ss << typeName << "& f(const " << asType << ")";
00089 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_MUL_ASSIGN, ss.str().c_str(),
00090 asMETHODPR(dimension2d<T>, operator*=, (const T&),
00091 dimension2d<T>&), asCALL_THISCALL); assert(r >= 0);
00092
00093
00094 ss.str("");
00095 ss << typeName << " f(const " << typeName << " &in, const " << typeName << " &in)";
00096 r = engine->RegisterGlobalBehaviour(asBEHAVE_ADD, ss.str().c_str(),
00097 asFUNCTIONPR((add< dimension2d<T>, dimension2d<T>, dimension2d<T> >),
00098 (const dimension2d<T>&, const dimension2d<T>&), dimension2d<T>),
00099 asCALL_CDECL); assert(r >= 0);
00100
00101
00102 ss.str("");
00103 ss << typeName << "& f(const " << typeName << " &in)";
00104 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_ADD_ASSIGN, ss.str().c_str(),
00105 asMETHODPR(dimension2d<T>, operator+=, (const dimension2d<T>&),
00106 dimension2d<T>&), asCALL_THISCALL); assert(r >= 0);
00107
00108
00109 ss.str("");
00110 ss << typeName << " f(const " << typeName << " &in, const " << asType << ")";
00111 r = engine->RegisterGlobalBehaviour(asBEHAVE_DIVIDE, ss.str().c_str(),
00112 asFUNCTIONPR((divide< dimension2d<T>, dimension2d<T>, T >),
00113 (const dimension2d<T>&, const T&), dimension2d<T>),
00114 asCALL_CDECL); assert(r >= 0);
00115
00116
00117 ss.str("");
00118 ss << typeName << "& f(const " << asType << ")";
00119 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_DIV_ASSIGN, ss.str().c_str(),
00120 asMETHODPR(dimension2d<T>, operator/=, (const T&),
00121 dimension2d<T>&), asCALL_THISCALL); assert(r >= 0);
00122
00123
00124 ss.str("");
00125 ss << "bool f(const " << typeName << " &in, const " << typeName << " &in)";
00126 std::string declComparison = ss.str();
00127
00128 r = engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL, declComparison.c_str(), asFUNCTIONPR(equal< dimension2d<T> >,
00129 (const dimension2d<T>&, const dimension2d<T>&), bool), asCALL_CDECL); assert(r >= 0);
00130 r = engine->RegisterGlobalBehaviour(asBEHAVE_NOTEQUAL, declComparison.c_str(), asFUNCTIONPR(not_equal< dimension2d<T> >,
00131 (const dimension2d<T>&, const dimension2d<T>&), bool), asCALL_CDECL); assert(r >= 0);
00132
00133
00134 ss.str("");
00135 ss << asType << " getArea()";
00136 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00137 asMETHOD(dimension2d<T>, getArea), asCALL_THISCALL); assert(r >= 0);
00138
00139 ss.str("");
00140 ss << typeName << " getInterpolated(const " << typeName << " &in, f32)";
00141 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00142 asMETHOD(dimension2d<T>, getInterpolated), asCALL_THISCALL); assert(r >= 0);
00143
00144 ss.str("");
00145 ss << typeName << " getOptimalSize(bool, bool, bool)";
00146 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00147 asMETHOD(dimension2d<T>, getOptimalSize), asCALL_THISCALL); assert(r >= 0);
00148
00149
00150 ss.str("");
00151 ss << asType << " Height";
00152 r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(dimension2d<T>, Height)); assert(r >= 0);
00153
00154 ss.str("");
00155 ss << asType << " Width";
00156 r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(dimension2d<T>, Width)); assert(r >= 0);
00157 }
00158
00161 void bindDimension2d(asIScriptEngine *engine)
00162 {
00163 bindDimension2dT<f32>(engine, "dimension2df", "f32");
00164 bindDimension2dT<s32>(engine, "dimension2di", "s32");
00165 }
00166
00169 std::string getDimension2dName(const std::string &asType)
00170 {
00171 if(asType == "f32") return std::string("dimension2df");
00172 if(asType == "s32") return std::string("dimension2di");
00173 else return std::string("");
00174 }
00175
00176