int32 onAdAction(void* systemData, void* userData) { QTrace("amazonAds::onAdAction"); s3eAmazonAdsCallbackActionData* data = static_cast<s3eAmazonAdsCallbackActionData*>(systemData); if (data == NULL) { QTrace("onAdAction error: callback data is NULL."); return 1; } LUA_EVENT_PREPARE("amazonAds"); LUA_EVENT_SET_STRING("type", "action"); LUA_EVENT_SET_INTEGER("adId", data->m_Id); const char* type; if (data->m_Type == S3E_AMAZONADS_ACTION_EXPANDED) type = "expanded"; else if (data->m_Type == S3E_AMAZONADS_ACTION_COLLAPSED) type = "collapsed"; else type = "dismissed"; LUA_EVENT_SET_STRING("actionType", type); LUA_EVENT_SEND(); lua_pop(g_L, 1); return 0; }
//------------------------------------------------------------------------------ void QContactListener::EndContact(b2Contact* pContact) { QNode* pNodeA = (QNode*)pContact->GetFixtureA()->GetBody()->GetUserData(); QNode* pNodeB = (QNode*)pContact->GetFixtureB()->GetBody()->GetUserData(); lua_gettop(g_L); LUA_EVENT_PREPARE("collision"); // On stack: event LUA_EVENT_SET_STRING("phase", "ended"); LUA_EVENT_SET_TOLUA_PTR("nodeA", (void*)pNodeA, pNodeA->_getToLuaClassName()); LUA_EVENT_SET_TOLUA_PTR("nodeB", (void*)pNodeB, pNodeB->_getToLuaClassName()); LUA_EVENT_SET_TOLUA_PTR("target", (void*)pNodeA, pNodeA->_getToLuaClassName()); lua_getfield(g_L, LUA_GLOBALSINDEX, "handleNodeEvent"); lua_pushvalue(g_L, -2); // On stack: handleNodeEvent(event) tolua_pushusertype(g_L, (void*)pNodeA, pNodeA->_getToLuaClassName()); // On stack: handleNodeEvent(event, node) lua_gettop(g_L); int s = lua_pcall(g_L, 2, 1, 0); lua_gettop(g_L); LUA_REPORT_ERRORS(g_L, s); lua_gettop(g_L); lua_pop(g_L, 3); lua_gettop(g_L); }
//------------------------------------------------------------------------------ // QContactListener //------------------------------------------------------------------------------ void QContactListener::BeginContact(b2Contact* pContact) { QNode* pNodeA = (QNode*)pContact->GetFixtureA()->GetBody()->GetUserData(); QNode* pNodeB = (QNode*)pContact->GetFixtureB()->GetBody()->GetUserData(); lua_gettop(g_L); LUA_EVENT_PREPARE("collision"); // On stack: event LUA_EVENT_SET_STRING("phase", "began"); LUA_EVENT_SET_TOLUA_PTR("nodeA", (void*)pNodeA, pNodeA->_getToLuaClassName()); LUA_EVENT_SET_TOLUA_PTR("nodeB", (void*)pNodeB, pNodeB->_getToLuaClassName()); LUA_EVENT_SET_TOLUA_PTR("target", (void*)pNodeA, pNodeA->_getToLuaClassName()); // World point of collision... is this correct? b2WorldManifold wm; pContact->GetWorldManifold(&wm); float dx = g_Sim->scaleP2D(wm.points[0].x); float dy = g_Sim->scaleP2D(wm.points[0].y); LUA_EVENT_SET_NUMBER("x", dx); LUA_EVENT_SET_NUMBER("y", dy); lua_getfield(g_L, LUA_GLOBALSINDEX, "handleNodeEvent"); lua_pushvalue(g_L, -2); // On stack: handleNodeEvent(event) tolua_pushusertype(g_L, (void*)pNodeA, pNodeA->_getToLuaClassName()); // On stack: handleNodeEvent(event, node) lua_gettop(g_L); int s = lua_pcall(g_L, 2, 1, 0); lua_gettop(g_L); LUA_REPORT_ERRORS(g_L, s); lua_gettop(g_L); lua_pop(g_L, 3); lua_gettop(g_L); }
//------------------------------------------------------------------------------ void QContactListener::PostSolve(b2Contact* pContact, const b2ContactImpulse* pImpulse) { QNode* pNodeA = (QNode*)pContact->GetFixtureA()->GetBody()->GetUserData(); QNode* pNodeB = (QNode*)pContact->GetFixtureB()->GetBody()->GetUserData(); LUA_EVENT_PREPARE("collisionPostSolve"); // On stack: event LUA_EVENT_SET_STRING("phase", "ended"); LUA_EVENT_SET_TOLUA_PTR("nodeA", (void*)pNodeA, pNodeA->_getToLuaClassName()); LUA_EVENT_SET_TOLUA_PTR("nodeB", (void*)pNodeB, pNodeB->_getToLuaClassName()); LUA_EVENT_SET_TOLUA_PTR("target", (void*)pNodeA, pNodeA->_getToLuaClassName()); QContact con(pContact); LUA_EVENT_SET_TOLUA_PTR("contact", (void*)&con, "quick::QPhysics::Contact"); // Force (impulse) float f = g_Sim->scaleP2D(pImpulse->normalImpulses[0]); LUA_EVENT_SET_NUMBER("impulse", f); lua_getfield(g_L, LUA_GLOBALSINDEX, "handleNodeEvent"); lua_pushvalue(g_L, -2); // On stack: handleNodeEvent(event) tolua_pushusertype(g_L, (void*)pNodeA, pNodeA->_getToLuaClassName()); // On stack: handleNodeEvent(event, node) int s = lua_pcall(g_L, 2, 1, 0); LUA_REPORT_ERRORS(g_L, s); lua_pop(g_L, 2); lua_gettop(g_L); }
//------------------------------------------------------------------------------ void QSystem::_sendTouchEvent(float x, float y, const char* phase) { // SEND EVENT TO LUA //QTrace("QSystem::_sendTouchEvent"); LUA_EVENT_PREPARE("touch"); LUA_EVENT_SET_NUMBER("x", x); LUA_EVENT_SET_NUMBER("y", y); LUA_EVENT_SET_STRING("phase", phase); LUA_EVENT_SEND(); }
int32 onAdLoad(void* systemData, void* userData) { QTrace("amazonAds::onAdLoad"); s3eAmazonAdsCallbackLoadedData* data = static_cast<s3eAmazonAdsCallbackLoadedData*>(systemData); if (data == NULL || data->m_Properties == NULL) { QTrace("onAdLoad error: callback data is NULL."); return 1; } LUA_EVENT_PREPARE("amazonAds"); //here we have "defined" an event called "amazonAds" //Chosen to have a single event for amazon ads and use "type" to switch //between the 3 callbacks. Keeps the API small/manageable LUA_EVENT_SET_STRING("type", "loaded"); LUA_EVENT_SET_INTEGER("adId", data->m_Id); const char* type; if (data->m_Properties->m_AdType == S3E_AMAZONADS_TYPE_IMAGE_BANNER) type = "imageBanner"; else if (data->m_Properties->m_AdType == S3E_AMAZONADS_TYPE_RICH_MEDIA_MRAID1) type = "richMediaMraid1"; else if (data->m_Properties->m_AdType == S3E_AMAZONADS_TYPE_RICH_MEDIA_MRAID2) type = "richMediaMraid2"; else if (data->m_Properties->m_AdType == S3E_AMAZONADS_TYPE_INTERSTITIAL) type = "interstitial"; else type = "unknown"; LUA_EVENT_SET_STRING("adType", type); LUA_EVENT_SET_BOOLEAN("canPlayAudio", data->m_Properties->m_CanPlayAudio); LUA_EVENT_SET_BOOLEAN("canPlayAudio", data->m_Properties->m_CanPlayVideo); LUA_EVENT_SET_BOOLEAN("canExpand", data->m_Properties->m_CanExpand); LUA_EVENT_SEND(); lua_pop(g_L, 1); return 0; }
int32 onAdError(void* systemData, void* userData) { QTrace("amazonAds::onAdError"); s3eAmazonAdsCallbackErrorData* data = static_cast<s3eAmazonAdsCallbackErrorData*>(systemData); if (data == NULL) { QTrace("onAdError error: callback data is NULL."); return 1; } LUA_EVENT_PREPARE("amazonAds"); LUA_EVENT_SET_STRING("type", "error"); LUA_EVENT_SET_INTEGER("adId", data->m_Id); const char* error; if (data->m_Error == S3E_AMAZONADS_ERR_LOAD_NETWORK_ERROR) error = "networkError"; else if (data->m_Error == S3E_AMAZONADS_ERR_LOAD_NETWORK_TIMEOUT) error = "networkTimeout"; else if (data->m_Error == S3E_AMAZONADS_ERR_LOAD_NO_FILL) error = "noFill"; else if (data->m_Error == S3E_AMAZONADS_ERR_LOAD_INTERNAL_ERROR) error = "internalError"; else if (data->m_Error == S3E_AMAZONADS_ERR_LOAD_REQUEST_ERROR) error = "requestError"; else error = "unknown"; LUA_EVENT_SET_STRING("error", error); LUA_EVENT_SEND(); lua_pop(g_L, 1); return 0; }