int main() { // f(); // f(1, 2); // f(1, 2.5, ""); // print(1, 2, 3, 4); // expand(1, 2, 3, 4); // expand([](int i) {std::cout<<i<<std::endl;}, 1, 2, 3); // std::tuple<> tp; // std::tuple<int> tp1 = std::make_tuple(1); // std::tuple<int, double> tp2 = std::make_tuple(1, 2.5); // std::tuple<int, double, std::string> tp3 = std::make_tuple(1, 2.5, ""); // Sum1<int, double, short>::value; //值为14 // using T = MakeIndexes<3>::type; // std::cout << typeid(T).name() << std::endl; // A* pa = Instance<A>(1); // B* pb = Instance<B>(1, 2); App a; auto d = CreateDelegate(&a, &App::Fun); //创建委托 d(1); //调用委托,将输出1 auto d1 = CreateDelegate(&a, &App::Fun1); //创建委托 d1(1, 2.5); //调用委托,将输出3.5 return 0; }
LobbyClient::LobbyClient() : _sessionKey(GenerateKey(LOBBY_KEY_LENGTH)) , _redirectCount(0) , _timer(CreateWaitableTimer(NULL, FALSE, NULL)) , _state(STATE_IDLE) { // setup timer if( !_timer || INVALID_HANDLE_VALUE == _timer ) { throw std::runtime_error("lobby: failed to create waitable timer"); } g_app->RegisterHandle(_timer, CreateDelegate(&LobbyClient::OnTimer, this)); }
Desktop::Desktop(LayoutManager* manager) : Window(NULL, manager) , _font(GetManager()->GetTextureManager()->FindSprite("font_default")) { SetTexture("ui/window", false); _msg = new MessageArea(this, 100, 100); _editor = new EditorLayout(this); _editor->SetVisible(false); _con = Console::Create(this, 10, 0, 100, 100, &GetConsole()); _con->eventOnSendCommand = std::bind( &Desktop::OnCommand, this, _1 ); _con->eventOnRequestCompleteCommand = std::bind( &Desktop::OnCompleteCommand, this, _1, _2, _3 ); _con->SetVisible(false); _con->SetTopMost(true); SpriteColor colors[] = {0xffffffff, 0xffff7fff}; _con->SetColors(colors, sizeof(colors) / sizeof(colors[0])); _con->SetHistory(&_history); _score = new ScoreTable(this); _score->SetVisible(false); _fps = new FpsCounter(this, 0, 0, alignTextLB); g_conf.ui_showfps.eventChange = std::bind(&Desktop::OnChangeShowFps, this); OnChangeShowFps(); _time = new TimeElapsed(this, 0, 0, alignTextRB); g_conf.ui_showtime.eventChange = std::bind(&Desktop::OnChangeShowTime, this); OnChangeShowTime(); if( g_conf.dbg_graph.Get() ) { float xx = 200; float yy = 3; float hh = 50; for( size_t i = 0; i < CounterBase::GetMarkerCountStatic(); ++i ) { Oscilloscope *os = new Oscilloscope(this, xx, yy); os->Resize(400, hh); os->SetRange(-1/15.0f, 1/15.0f); os->SetTitle(CounterBase::GetMarkerInfoStatic(i).title); CounterBase::SetMarkerCallbackStatic(i, CreateDelegate(&Oscilloscope::Push, os)); yy += hh+5; } } OnRawChar(VK_ESCAPE); // to invoke main menu dialog }
//----------------------------------------------------------------------------- stWindowEventDelegate* GGUIWindowManager::GetWindowEventDelegate(WindowID theWindowID) { stWindowEventDelegate* pDelegate = NULL; GGUIWindow* pTheWindow = GetUIWindow(theWindowID); if (pTheWindow) { DelegateID theDelegateID = pTheWindow->GetDelegateID(); if (theDelegateID == Invalid_DelegateID) { theDelegateID = CreateDelegate(); pTheWindow->SetDelegateID(theDelegateID); } if (theDelegateID >= 0 && theDelegateID < m_nDelegateIndexEnd) { pDelegate = m_pDelegateID2Delegate[theDelegateID]; } } return pDelegate; }
static void ScriptFunction_CreateDelegate_Generic(asIScriptGeneric *gen) { asCScriptFunction *func = (asCScriptFunction*)gen->GetArgAddress(0); void *obj = gen->GetArgAddress(1); gen->SetReturnAddress(CreateDelegate(func, obj)); }
void TankClient::Connect(const string_t &hostaddr) { g_app->InitNetwork(); // // get ip address // std::istringstream buf(hostaddr); string_t sv; std::getline(buf, sv, ':'); unsigned short port = g_conf.sv_port.GetInt(); buf >> port; sockaddr_in addr = {0}; addr.sin_family = AF_INET; addr.sin_port = htons(port); // try to convert string to ip address addr.sin_addr.s_addr = inet_addr(sv.c_str()); if( addr.sin_addr.s_addr == INADDR_NONE ) { // try to resolve string as host name hostent* he = gethostbyname(sv.c_str()); if( NULL == he ) { int err = WSAGetLastError(); TRACE("client: ERROR - Unable to resolve IP-address (%u)", err); OnDisconnect(NULL, err ? err : -1); return; } addr.sin_addr.s_addr = *((u_long*)he->h_addr_list[0]); } // // connect // SOCKET s = socket(AF_INET, SOCK_STREAM, 0); if( INVALID_SOCKET == s ) { int err = WSAGetLastError(); TRACE("cl: ERROR - Unable to create socket (%u)", WSAGetLastError()); OnDisconnect(NULL, err ? err : -1); return; } TRACE("cl: connecting to %s", inet_ntoa(addr.sin_addr)); ClTextMessage(NULL, -1, Variant(g_lang.net_msg_connecting.Get())); _peer = new Peer(s); _peer->eventDisconnect.bind(&TankClient::OnDisconnect, this); _peer->RegisterHandler<std::string>(CL_POST_TEXTMESSAGE, CreateDelegate(&TankClient::ClTextMessage, this)); _peer->RegisterHandler<std::string>(CL_POST_ERRORMESSAGE, CreateDelegate(&TankClient::ClErrorMessage, this)); _peer->RegisterHandler<GameInfo>(CL_POST_GAMEINFO, CreateDelegate(&TankClient::ClGameInfo, this)); _peer->RegisterHandler<unsigned short>(CL_POST_PLAYERQUIT, CreateDelegate(&TankClient::ClPlayerQuit, this)); _peer->RegisterHandler<ControlPacketVector>(CL_POST_CONTROL, CreateDelegate(&TankClient::ClControl, this)); _peer->RegisterHandler<PlayerReady>(CL_POST_PLAYER_READY, CreateDelegate(&TankClient::ClPlayerReady, this)); _peer->RegisterHandler<bool>(CL_POST_STARTGAME, CreateDelegate(&TankClient::ClStartGame, this)); _peer->RegisterHandler<PlayerDesc>(CL_POST_ADDHUMAN, CreateDelegate(&TankClient::ClAddHuman, this)); _peer->RegisterHandler<BotDesc>(CL_POST_ADDBOT, CreateDelegate(&TankClient::ClAddBot, this)); _peer->RegisterHandler<PlayerDescEx>(CL_POST_PLAYERINFO, CreateDelegate(&TankClient::ClSetPlayerInfo, this)); _peer->RegisterHandler<float>(CL_POST_SETBOOST, CreateDelegate(&TankClient::ClSetBoost, this)); if( int err = _peer->Connect(&addr) ) { OnDisconnect(NULL, err); } }