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


C++ MessagePtr::getType方法代码示例

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

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

示例1: processMessage

void ClientGame::processMessage(MessagePtr msg)
{
    switch(msg->getType())
    {
    case MessageType::SRV_ASTEROID_SPAWN:
    {
        print("ClientGame: spawning asteroid\n");
        AsteroidSpawnMessage *spawn_msg = static_cast<AsteroidSpawnMessage*>(msg.get());
        AsteroidPtr ast(new Asteroid(this, spawn_msg->getData(), asteroid_data));
        entities.push_back(ast);
        asteroids.push_back(ast);
    }
    break;
    case MessageType::SRV_SHIP_SPAWN:
    {
        ShipSpawnMessage *spawn_msg = static_cast<ShipSpawnMessage*>(msg.get());
        const ShipSpawnData &d = spawn_msg->getData();

        ShipPtr ship(new Ship(this, d));
        entities.push_back(ship);
        ships.push_back(ship);

        print(format("ClientGame: spawning ship id=%1% name=%2%\n") % ship->getID() % ship->getName());
    }
    break;
    case MessageType::SRV_BULLET_SPAWN:
    {
        BulletSpawnMessage *spawn_msg = static_cast<BulletSpawnMessage*>(msg.get());
        const BulletSpawnData &d = spawn_msg->getData();

        BulletPtr bullet(new Bullet(this, d));
        entities.push_back(bullet);
        if(Audio::distToListener(d.state.position) < 200.0f)
            Audio::playSFX("sounds/laser0.wav", false, d.state.position, 0.5f, 10.0f);
        print(format("ClientGame: spawning bullet id=%1%\n") % bullet->getID());
    }
    break;
    case MessageType::SRV_SHIP_STATE:
    {
        ShipStateMessage *state_msg = static_cast<ShipStateMessage*>(msg.get());
        int id = state_msg->getEntityID();

        //print(format("ClientGame: received ship state data for ship id=%1%\n") % id);

        //TODO use a map?
        for(unsigned int i = 0; i < ships.size(); i++)
            if(ships[i]->getID() == id)
            {
                ships[i]->setStateData(state_msg->getData());
                break;
            }
    }
    break;
    case MessageType::SRV_SHIP_OWNER:
    {
        ShipOwnerMessage *owner_msg = static_cast<ShipOwnerMessage*>(msg.get());
        print("owner message\n");

        for(unsigned int i = 0; i < ships.size(); i++)
            if(ships[i]->getID() == owner_msg->getData().ship_id)
            {
                print("owner message\n");
                player_ship = ships[i];
                ship_cam->setShip(player_ship);
                break;
            }
    }
    case MessageType::SRV_ASTEROID_STATE:
    {
        AsteroidStateMessage *state_msg = static_cast<AsteroidStateMessage*>(msg.get());
        int id = state_msg->getEntityID();

        //print(format("ClientGame: received asteroid state data for asteroid id=%1%\n") % id);

        for(unsigned int i = 0; i < asteroids.size(); i++)
            if(asteroids[i]->getID() == id)
            {
                asteroids[i]->setStateData(state_msg->getData());
                break;
            }
    }
    break;
    case MessageType::SRV_ENTITY_DELETE:
    {
        print("ClientGame: deleting entity\n");
        EntityDeleteMessage *delete_msg = static_cast<EntityDeleteMessage*>(msg.get());
        int id = delete_msg->getData().entity_id;

        for(unsigned int i = 0; i < entities.size(); i++)
            if(entities[i]->getID() == id)
            {
                entities[i]->die();
                entities.erase(entities.begin()+i);
                break;
            }

        if(player_ship && id == player_ship->getID())
            player_ship.reset();

        //TODO do this properly
//.........这里部分代码省略.........
开发者ID:citizen-erased,项目名称:asteroids,代码行数:101,代码来源:client_game.cpp



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