当前位置: 首页>>代码示例>>C++>>正文


C++ Network::GetServerConnection方法代码示例

本文整理汇总了C++中Network::GetServerConnection方法的典型用法代码示例。如果您正苦于以下问题:C++ Network::GetServerConnection方法的具体用法?C++ Network::GetServerConnection怎么用?C++ Network::GetServerConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Network的用法示例。


在下文中一共展示了Network::GetServerConnection方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ShowPrompt

void GameEconomicServerClientConsole::ShowPrompt(void)
{

    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();

    /// Get serverconnection
    serverConnection =  network->GetServerConnection();

    /// Display prompt to the user
    if(serverConnection&&serverconnection)
    {
        cout << endl << "(serveconnect) Enter Command >> ";
    }
    else
    {
        cout << endl << "(offline) Enter Command >> ";
    }
}
开发者ID:vivienneanthony,项目名称:Urho3D-gameeconomic,代码行数:19,代码来源:GameEconomicServerClientConsole.cpp

示例2: UpdateButtons

void Chat::UpdateButtons()
{
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();
    bool serverRunning = network->IsServerRunning();
    
    // Show and hide buttons so that eg. Connect and Disconnect are never shown at the same time
    sendButton_->SetVisible(serverConnection != 0);
    connectButton_->SetVisible(!serverConnection && !serverRunning);
    disconnectButton_->SetVisible(serverConnection || serverRunning);
    startServerButton_->SetVisible(!serverConnection && !serverRunning);
}
开发者ID:3dicc,项目名称:Urho3D,代码行数:12,代码来源:Chat.cpp

示例3: HandleDisconnect

void Chat::HandleDisconnect(StringHash eventType, VariantMap& eventData)
{
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();
    // If we were connected to server, disconnect
    if (serverConnection)
        serverConnection->Disconnect();
    // Or if we were running a server, stop it
    else if (network->IsServerRunning())
        network->StopServer();
    
    UpdateButtons();
}
开发者ID:3dicc,项目名称:Urho3D,代码行数:13,代码来源:Chat.cpp

示例4: HandleSend

void Chat::HandleSend(StringHash eventType, VariantMap& eventData)
{
    String text = textEdit_->GetText();
    if (text.Empty())
        return; // Do not send an empty message
    
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();
    
    if (serverConnection)
    {
        // A VectorBuffer object is convenient for constructing a message to send
        VectorBuffer msg;
        msg.WriteString(text);
        // Send the chat message as in-order and reliable
        serverConnection->SendMessage(MSG_CHAT, true, true, msg);
        // Empty the text edit after sending
        textEdit_->SetText(String::EMPTY);
    }
}
开发者ID:3dicc,项目名称:Urho3D,代码行数:20,代码来源:Chat.cpp

示例5: HandleDisconnect

void SceneReplication::HandleDisconnect(StringHash eventType, VariantMap& eventData)
{
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();
    // If we were connected to server, disconnect. Or if we were running a server, stop it. In both cases clear the
    // scene of all replicated content, but let the local nodes & components (the static world + camera) stay
    if (serverConnection)
    {
        serverConnection->Disconnect();
        scene_->Clear(true, false);
        clientObjectID_ = 0;
    }
    // Or if we were running a server, stop it
    else if (network->IsServerRunning())
    {
        network->StopServer();
        scene_->Clear(true, false);
    }
    
    UpdateButtons();
}
开发者ID:3dicc,项目名称:Urho3D,代码行数:21,代码来源:SceneReplication.cpp

示例6: SendMessage

void GameEconomicServerClientConsole::SendMessage(String Message)
{
    /// If sending message is empty
    if (Message.Empty())
    {
        return; // Do not send an empty message
    }

    /// Get connection
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();

    /// Send message only if serverconnection and connection is true
    if (serverConnection&&serverconnection)
    {
               // A VectorBuffer object is convenient for constructing a message to send
        VectorBuffer msg;
        msg.WriteString(Message);
        // Send the chat message as in-order and reliable
        serverConnection->SendMessage(NetMessageAdminClientSend, true, true, msg);
    }

    return;
}
开发者ID:vivienneanthony,项目名称:Urho3D-gameeconomic,代码行数:24,代码来源:GameEconomicServerClientConsole.cpp

示例7: HandlePhysicsPreStep

void SceneReplication::HandlePhysicsPreStep(StringHash eventType, VariantMap& eventData)
{
    // This function is different on the client and server. The client collects controls (WASD controls + yaw angle)
    // and sets them to its server connection object, so that they will be sent to the server automatically at a
    // fixed rate, by default 30 FPS. The server will actually apply the controls (authoritative simulation.)
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();
    
    // Client: collect controls
    if (serverConnection)
    {
        UI* ui = GetSubsystem<UI>();
        Input* input = GetSubsystem<Input>();
        Controls controls;
        
        // Copy mouse yaw
        controls.yaw_ = yaw_;
        
        // Only apply WASD controls if there is no focused UI element
        if (!ui->GetFocusElement())
        {
            controls.Set(CTRL_FORWARD, input->GetKeyDown('W'));
            controls.Set(CTRL_BACK, input->GetKeyDown('S'));
            controls.Set(CTRL_LEFT, input->GetKeyDown('A'));
            controls.Set(CTRL_RIGHT, input->GetKeyDown('D'));
        }
        
        serverConnection->SetControls(controls);
        // In case the server wants to do position-based interest management using the NetworkPriority components, we should also
        // tell it our observer (camera) position. In this sample it is not in use, but eg. the NinjaSnowWar game uses it
        serverConnection->SetPosition(cameraNode_->GetPosition());
    }
    // Server: apply controls to client objects
    else if (network->IsServerRunning())
    {
        const Vector<SharedPtr<Connection> >& connections = network->GetClientConnections();
        
        for (unsigned i = 0; i < connections.Size(); ++i)
        {
            Connection* connection = connections[i];
            // Get the object this connection is controlling
            Node* ballNode = serverObjects_[connection];
            if (!ballNode)
                continue;
            
            RigidBody* body = ballNode->GetComponent<RigidBody>();
            
            // Get the last controls sent by the client
            const Controls& controls = connection->GetControls();
            // Torque is relative to the forward vector
            Quaternion rotation(0.0f, controls.yaw_, 0.0f);
            
            const float MOVE_TORQUE = 3.0f;
            
            // Movement torque is applied before each simulation step, which happen at 60 FPS. This makes the simulation
            // independent from rendering framerate. We could also apply forces (which would enable in-air control),
            // but want to emphasize that it's a ball which should only control its motion by rolling along the ground
            if (controls.buttons_ & CTRL_FORWARD)
                body->ApplyTorque(rotation * Vector3::RIGHT * MOVE_TORQUE);
            if (controls.buttons_ & CTRL_BACK)
                body->ApplyTorque(rotation * Vector3::LEFT * MOVE_TORQUE);
            if (controls.buttons_ & CTRL_LEFT)
                body->ApplyTorque(rotation * Vector3::FORWARD * MOVE_TORQUE);
            if (controls.buttons_ & CTRL_RIGHT)
                body->ApplyTorque(rotation * Vector3::BACK * MOVE_TORQUE);
        }
    }
}
开发者ID:3dicc,项目名称:Urho3D,代码行数:68,代码来源:SceneReplication.cpp


注:本文中的Network::GetServerConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。