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