Пример #1
0
    void MapBuilder::buildMap(uint32 mapID)
    {
#ifndef __APPLE__
        //printf("[Thread %u] Building map %03u:\n", uint32(ACE_Thread::self()), mapID);
#endif

        std::set<uint32>* tiles = getTileList(mapID);

        // make sure we process maps which don't have tiles
        if (!tiles->size())
        {
            // convert coord bounds to grid bounds
            uint32 minX, minY, maxX, maxY;
            getGridBounds(mapID, minX, minY, maxX, maxY);

            // add all tiles within bounds to tile list.
            for (uint32 i = minX; i <= maxX; ++i)
                for (uint32 j = minY; j <= maxY; ++j)
                    tiles->insert(StaticMapTree::packTileID(i, j));
        }

        if (!tiles->empty())
        {
            // build navMesh
            dtNavMesh* navMesh = NULL;
            buildNavMesh(mapID, navMesh);
            if (!navMesh)
            {
                printf("[Map %04i] Failed creating navmesh!\n", mapID);
                return;
            }

            // now start building mmtiles for each tile
            printf("[Map %04i] We have %u tiles.                          \n", mapID, (unsigned int)tiles->size());
            for (std::set<uint32>::iterator it = tiles->begin(); it != tiles->end(); ++it)
            {
                uint32 tileX, tileY;

                // unpack tile coords
                StaticMapTree::unpackTileID((*it), tileX, tileY);

                if (shouldSkipTile(mapID, tileX, tileY))
                    continue;

                buildTile(mapID, tileX, tileY, navMesh);
            }

            dtFreeNavMesh(navMesh);
        }

        printf("[Map %04u] Complete!\n", mapID);
    }
Пример #2
0
    void MapBuilder::buildMap(int mapID)
    {
        printf("Building map %03u:\n", mapID);

        set<int>* tiles = getTileList(mapID);

        // make sure we process maps which don't have tiles
        if (!tiles->size())
        {
            // convert coord bounds to grid bounds
            int minX, minY, maxX, maxY;
            getGridBounds(mapID, minX, minY, maxX, maxY);

            // add all tiles within bounds to tile list.
            for (int i = minX; i <= maxX; ++i)
                for (int j = minY; j <= maxY; ++j)
                    { tiles->insert(StaticMapTree::packTileID(i, j)); }
        }

        if (!tiles->size())
            { return; }

        // build navMesh
        dtNavMesh* navMesh = NULL;
        buildNavMesh(mapID, navMesh);
        if (!navMesh)
        {
            printf("Failed creating navmesh!              \n");
            return;
        }

        // now start building mmtiles for each tile
        printf("We have %u tiles.                          \n", (unsigned int)tiles->size());
        for (set<int>::iterator it = tiles->begin(); it != tiles->end(); ++it)
        {
            int tileX, tileY;

            // unpack tile coords
            StaticMapTree::unpackTileID((*it), tileX, tileY);

            if (shouldSkipTile(mapID, tileX, tileY))
                { continue; }

            buildTile(mapID, tileX, tileY, navMesh);
        }

        dtFreeNavMesh(navMesh);

        printf("Complete!                               \n\n");
    }
Пример #3
0
    void MapBuilder::buildMap(int mapID, bool standAlone)
    {
        set<uint32>* tiles = getTileList(mapID);

        // make sure we process maps which don't have tiles
        if (!tiles->size())
        {
            // convert coord bounds to grid bounds
            uint32 minX, minY, maxX, maxY;
            getGridBounds(mapID, minX, minY, maxX, maxY);

            // add all tiles within bounds to tile list.
            for (uint32 i = minX; i <= maxX; ++i)
                for (uint32 j = minY; j <= maxY; ++j)
                    { tiles->insert(StaticMapTree::packTileID(i, j)); }
        }

        if (!tiles->size())
            { return; }

        // build navMesh
        dtNavMesh* navMesh = NULL;
        dtNavMeshParams* meshParams = NULL;
        buildNavMesh(mapID, navMesh, meshParams);
        if (!navMesh)
        {
            printf("Failed creating navmesh for map %03u!              \n", mapID);
            if (meshParams)
                { delete meshParams; }
            return;
        }

        if (activated())
          { dtFreeNavMesh(navMesh); }  // each tile will get it's own pointer to navMesh 

        // now start building/scheduling mmtiles for each tile
        printf(" %s map %03u [%u tiles]\n", activated() ? "Scheduling" : "Building", mapID, (unsigned int)tiles->size());
        for (set<uint32>::iterator it = tiles->begin(); it != tiles->end(); ++it)
        {
            uint32 tileX, tileY;

            // unpack tile coords
            StaticMapTree::unpackTileID((*it), tileX, tileY);

            if (shouldSkipTile(mapID, tileX, tileY))
                { continue; }

            if (!activated())
            {
                buildTile(mapID, tileX, tileY, navMesh);
            }
            else
            {
                dtNavMesh *mesh = NULL;
                buildNavMesh(mapID, mesh, meshParams); //meshParams is not null, so we get a new pointer to dtNavMesh
                if (mesh)
                {
                    TileBuilder* tb = new TileBuilder(this, mapID, tileX, tileY, mesh);
                    Tile_Message_Block *mb = new Tile_Message_Block(tb);
                    if (m_threadPool->putq(mb) == -1)
                      { break; }
                }
            }
        }
        if (activated() && standAlone)
        {
            Tile_Message_Block *finish_mb = new Tile_Message_Block(NULL);
            finish_mb->msg_type(ACE_Message_Block::MB_HANGUP);
            m_threadPool->putq(finish_mb);
            m_threadPool->wait();
        }

        if (!activated())
          { dtFreeNavMesh(navMesh); }

        if (meshParams)
            { delete meshParams; }

        if (!activated())
          { printf(" Map %03u complete!\n\n", mapID); }
    }