bool CClipboard::setText(int callbackID, const Json::Value& parameters) { // fetch member 'text' of parameters Json::Value text_JSON; FetchObject(parameters, "text", text_JSON); // fetch string std::string text; FetchString(text_JSON, text); // call s3e code if (!s3eClipboardAvailable()) { // call fail callback clipboardError(callbackID); return true; } if (s3eClipboardSetText(text.c_str()) == S3E_RESULT_ERROR) { // call fail callback clipboardError(callbackID); return true; } // call success callback with text clipboardSuccess(callbackID, text.c_str()); return true; }
/// ------------------------------------------------ // /// 长方形 /// [4/18/2014 jianglei.kinly] /// ------------------------------------------------ // xObjectSet XGameMap::CaptureObjectByRectangle( const XVector3& vCenter, xgc_uint32 dwXRadius, xgc_uint32 dwYRadius, const std::function< xgc_bool( xObject ) > &fnFilter ) { XVector3 leftTop( vCenter.x - dwXRadius, vCenter.y - dwYRadius, 0 ); XVector3 rightDown( vCenter.x + dwXRadius, vCenter.y + dwYRadius, 0 ); auto fn = [&]( xObject hObject )->xgc_bool { if( xgc_nullptr == fnFilter || fnFilter( hObject ) ) { XGameObject* pObj = ObjectCast<XGameObject>( hObject ); XGC_ASSERT_RETURN( pObj, false ); return pObj->GetPosX() >= leftTop.x && pObj->GetPosY() >= leftTop.y && pObj->GetPosX() <= rightDown.x && pObj->GetPosY() <= rightDown.y; } return false; }; iRect rc( WorldToArea( vCenter.x - dwXRadius, vCenter.y - dwYRadius ), WorldToArea( vCenter.x + dwXRadius, vCenter.y + dwYRadius ) ); return FetchObject( rc, fn ); }
/// ------------------------------------------------ // /// [4/23/2014 jianglei.kinly] /// 圆环 /// ------------------------------------------------ // xObjectSet XGameMap::CaptureObjectByAnnular( const XVector3& vCenter, xgc_uint32 dwRadiusMax, xgc_uint32 dwRadiusMin, const std::function< xgc_bool( xObject ) > &fnFilter/* = xgc_nullptr*/ ) { auto fn = [&]( xObject hObject )->xgc_bool { if( xgc_nullptr == fnFilter || fnFilter( hObject ) ) { XGameObject* pObj = ObjectCast<XGameObject>( hObject ); XGC_ASSERT_RETURN( pObj, false ); // 计算距离 xgc_real32 fSqurDistance = ( pObj->GetPosition() - vCenter ).SqurLength(); if( fSqurDistance > dwRadiusMax * dwRadiusMax * 1.0f ) return false; if( fSqurDistance < dwRadiusMin * dwRadiusMin * 1.0f ) return false; return true; } return false; }; // 取外切正方形 iRect rc( WorldToArea( vCenter.x - dwRadiusMax, vCenter.y - dwRadiusMax ), WorldToArea( vCenter.x + dwRadiusMax, vCenter.y + dwRadiusMax ) ); return FetchObject( rc, fn ); }
/// ------------------------------------------------ // /// [4/18/2014 jianglei.kinly] /// 扇形 /// ------------------------------------------------ // xObjectSet XGameMap::CaptureObjectBySector( const XVector3& vCenter, const XVector3& vDir, xgc_uint32 dwRadius, xgc_uint16 wAngle, const std::function< xgc_bool( xObject ) > &fnFilter/* = xgc_nullptr*/ ) { // 计算旋转向量 XVector3 vRotate = vDir.RotateZ( DEG2RAD( wAngle / 2 ) ); xgc_real32 fDotValue = vDir.DotProduct( vRotate ); auto fn = [&]( xObject hObject )->xgc_bool { if( xgc_nullptr == fnFilter || fnFilter( hObject ) ) { XGameObject* pObj = ObjectCast<XGameObject>( hObject ); XGC_ASSERT_RETURN( pObj, false ); XVector3 vDistance = pObj->GetPosition() - vCenter; if( vDistance.SqurLength() > dwRadius * dwRadius * 1.0f ) return false; if( vDir.DotProduct( vDistance ) < fDotValue ) return false; return true; } return false; }; iRect rc( WorldToArea( vCenter.x - dwRadius, vCenter.y - dwRadius ), WorldToArea( vCenter.x + dwRadius, vCenter.y + dwRadius ) ); return FetchObject( rc, fn ); }
bool C_coretestBase::TestPhatArray(int callbackID, const Json::Value& parameters) { Json::Value testArray_JSON; FetchObject(parameters, "testArray", testArray_JSON); std::vector<std::vector<int32 > > testArray; for (int array_i=0; array_i<(int)testArray_JSON.size(); array_i++) { Json::Value array_array; FetchArray(testArray_JSON, array_i, array_array); std::vector<int32 > array; for (int param1_i=0; param1_i<(int)array_array.size(); param1_i++) { Json::Value param1_array; FetchArray(array_array, param1_i, param1_array); int32 param1; FetchInt(param1_array, param1); array.push_back(param1); } testArray.push_back(array); } TestPhatArray(callbackID, testArray); return true; }
bool C_coretestBase::TestObject(int callbackID, const Json::Value& parameters) { Json::Value testObject_JSON; FetchObject(parameters, "testObject", testObject_JSON); Json::Value param_JSON; FetchObject(testObject_JSON, "param", param_JSON); int32 param; FetchInt(param_JSON, param); TestObject(callbackID, param); return true; }
bool C_coretestBase::TestChildClass(int callbackID, const Json::Value& parameters) { Json::Value testChildClass_JSON; FetchObject(parameters, "testChildClass", testChildClass_JSON); ChildClassTest testChildClass=ChildClassTest::From_JSON(testChildClass_JSON, this); TestChildClass(callbackID, testChildClass); return true; }
bool C_coretestBase::TestEnum(int callbackID, const Json::Value& parameters) { Json::Value testEnum_JSON; FetchObject(parameters, "testEnum", testEnum_JSON); EnumTest testEnum; FetchUInt(testEnum_JSON, *((unsigned int*)&testEnum)); TestEnum(callbackID, testEnum); return true; }
bool C_coretestBase::TestUInt(int callbackID, const Json::Value& parameters) { Json::Value testUInt_JSON; FetchObject(parameters, "testUInt", testUInt_JSON); uint32 testUInt; FetchUInt(testUInt_JSON, testUInt); TestUInt(callbackID, testUInt); return true; }
bool C_coretestBase::TestULong(int callbackID, const Json::Value& parameters) { Json::Value testULong_JSON; FetchObject(parameters, "testULong", testULong_JSON); uint64 testULong; FetchULong(testULong_JSON, testULong); TestULong(callbackID, testULong); return true; }
bool C_coretestBase::TestString(int callbackID, const Json::Value& parameters) { Json::Value testString_JSON; FetchObject(parameters, "testString", testString_JSON); std::string testString; FetchString(testString_JSON, testString); TestString(callbackID, testString.c_str()); return true; }
bool C_coretestBase::TestBool(int callbackID, const Json::Value& parameters) { Json::Value testBool_JSON; FetchObject(parameters, "testBool", testBool_JSON); bool testBool; FetchBool(testBool_JSON, testBool); TestBool(callbackID, testBool); return true; }
bool C_coretestBase::TestDouble(int callbackID, const Json::Value& parameters) { Json::Value testDouble_JSON; FetchObject(parameters, "testDouble", testDouble_JSON); double testDouble; FetchDouble(testDouble_JSON, testDouble); TestDouble(callbackID, testDouble); return true; }
bool C_coretestBase::TestDict(int callbackID, const Json::Value& parameters) { Json::Value testDict_JSON; FetchObject(parameters, "testDict", testDict_JSON); std::map<std::string, std::string> testDict; FetchDictionary(testDict_JSON, testDict); TestDict(callbackID, testDict); return true; }
/// ------------------------------------------------ // /// [4/25/2014 jianglei.kinly] /// 方向矩形(subCenter) /// ------------------------------------------------ // xObjectSet XGameMap::CaptureObjectByRectangle( const XVector3& vCenter, const XVector3& vDir, xgc_uint32 dwRadiusMax, xgc_uint32 dwRadiusMin, const std::function< xgc_bool( xObject ) > &fnFilter/* = xgc_nullptr*/ ) { /* 0,0 -------------------------------x | | ------ | / / | / / | ---|-- | subCenter | 斜线是dir的方向,dwRadiusMax | 横线是dwRadiusMin y */ // 取中心点坐标 XVector3 newDirect = vDir * ( dwRadiusMax * 1.0f ); XVector3 newCenter = vCenter + newDirect; // 取对角线直径 xgc_uint32 dwDiameter = xgc_uint32( XMath::Sqrt( XMath::Pow( 1.0f * dwRadiusMax, 2.0f ) + XMath::Pow( 1.0f * dwRadiusMin, 2.0f ) ) ); auto fn = [&]( xObject hObject )->xgc_bool { if( xgc_nullptr == fnFilter || fnFilter( hObject ) ) { XGameObject* pObj = ObjectCast<XGameObject>( hObject ); XGC_ASSERT_RETURN( pObj, false ); // 取我和目标连线的向量 XVector3 subVec = pObj->GetPosition() - vCenter; // 判断夹角(我的朝向点乘我和目标连线的向量 > 0 代表夹角在0-90范围内) auto fTemp = vDir.DotProduct( subVec ); if( fTemp < 0 ) return false; // 找两个投影,判断是否在方向矩形内 XVector3 vecy = vDir * fTemp; XVector3 vecx = subVec - vecy; return !( vecy.Length() > dwRadiusMax || vecx.Length() > dwRadiusMin / 2 ); } return false; }; iRect rc( WorldToArea( vCenter.x - dwDiameter / 2, vCenter.y - dwDiameter / 2 ), WorldToArea( vCenter.x + dwDiameter / 2, vCenter.y + dwDiameter / 2 ) ); return FetchObject( rc, fn ); }
bool C_coretestBase::TestPhatObject(int callbackID, const Json::Value& parameters) { Json::Value testObject_JSON; FetchObject(parameters, "testObject", testObject_JSON); Json::Value array_JSON; FetchObject(testObject_JSON, "array", array_JSON); std::vector<int32 > array; for (int param1_i=0; param1_i<(int)array_JSON.size(); param1_i++) { Json::Value param1_array; FetchArray(array_JSON, param1_i, param1_array); int32 param1; FetchInt(param1_array, param1); array.push_back(param1); } Json::Value object_JSON; FetchObject(testObject_JSON, "object", object_JSON); Json::Value param2_JSON; FetchObject(object_JSON, "param2", param2_JSON); int32 param2; FetchInt(param2_JSON, param2); Json::Value klass_JSON; FetchObject(testObject_JSON, "klass", klass_JSON); ClassTest klass=ClassTest::From_JSON(klass_JSON, this); Json::Value string_JSON; FetchObject(testObject_JSON, "string", string_JSON); std::string string; FetchString(string_JSON, string); TestPhatObject(callbackID, array, param2, klass, string.c_str()); return true; }
/// ------------------------------------------------ // /// [4/18/2014 jianglei.kinly] /// 圆形 /// ------------------------------------------------ // xObjectSet XGameMap::CaptureObjectByCircle( const XVector3& vCenter, xgc_uint32 dwRadius, const std::function< xgc_bool( xObject ) > &fnFilter/* = xgc_nullptr*/ ) { auto fn = [&]( xObject hObject )->xgc_bool { if( xgc_nullptr == fnFilter || fnFilter( hObject ) ) { XGameObject* pObj = ObjectCast<XGameObject>( hObject ); XGC_ASSERT_RETURN( pObj, false ); return dwRadius * dwRadius * 1.0f > ( pObj->GetPosition() - vCenter ).SqurLength(); } return false; }; iRect rc( WorldToArea( vCenter.x - dwRadius, vCenter.y - dwRadius ), WorldToArea( vCenter.x + dwRadius, vCenter.y + dwRadius ) ); // 取外切正方形 return FetchObject( rc, fn ); }
bool C_coretestBase::TestPhatArray2(int callbackID, const Json::Value& parameters) { Json::Value testArray_JSON; FetchObject(parameters, "testArray", testArray_JSON); std::vector<ClassTest > testArray; for (int klass_i=0; klass_i<(int)testArray_JSON.size(); klass_i++) { Json::Value klass_array; FetchArray(testArray_JSON, klass_i, klass_array); ClassTest klass=ClassTest::From_JSON(klass_array, this); testArray.push_back(klass); } TestPhatArray2(callbackID, testArray); return true; }
bool C_coretestBase::TestPhatArray1(int callbackID, const Json::Value& parameters) { Json::Value testArray_JSON; FetchObject(parameters, "testArray", testArray_JSON); std::vector<std::string > testArray; for (int string_i=0; string_i<(int)testArray_JSON.size(); string_i++) { Json::Value string_array; FetchArray(testArray_JSON, string_i, string_array); std::string string; FetchString(string_array, string); testArray.push_back(string); } TestPhatArray1(callbackID, testArray); return true; }