Пример #1
0
/* MapArchClipboardItem::addLines
 * Copies [lines] and all related map structures
 *******************************************************************/
void MapArchClipboardItem::addLines(vector<MapLine*> lines)
{
    // Get sectors and sides to copy
    vector<MapSector*> copy_sectors;
    vector<MapSide*> copy_sides;
    for (unsigned a = 0; a < lines.size(); a++)
    {
        MapSide* s1 = lines[a]->s1();
        MapSide* s2 = lines[a]->s2();

        // Front side
        if (s1)
        {
            copy_sides.push_back(s1);
            if (std::find(copy_sectors.begin(), copy_sectors.end(), s1->getSector()) == copy_sectors.end())
                copy_sectors.push_back(s1->getSector());
        }

        // Back side
        if (s2)
        {
            copy_sides.push_back(s2);
            if (std::find(copy_sectors.begin(), copy_sectors.end(), s2->getSector()) == copy_sectors.end())
                copy_sectors.push_back(s2->getSector());
        }
    }

    // Copy sectors
    for (unsigned a = 0; a < copy_sectors.size(); a++)
    {
        MapSector* copy = new MapSector(NULL);
        copy->copy(copy_sectors[a]);
        sectors.push_back(copy);
    }

    // Copy sides
    for (unsigned a = 0; a < copy_sides.size(); a++)
    {
        MapSide* copy = new MapSide();
        copy->copy(copy_sides[a]);

        // Set relative sector
        for (unsigned b = 0; b < copy_sectors.size(); b++)
        {
            if (copy_sides[a]->getSector() == copy_sectors[b])
            {
                copy->setSector(sectors[b]);
                break;
            }
        }

        sides.push_back(copy);
    }

    // Get vertices to copy (and determine midpoint)
    double min_x = 9999999;
    double max_x = -9999999;
    double min_y = 9999999;
    double max_y = -9999999;
    vector<MapVertex*> copy_verts;
    for (unsigned a = 0; a < lines.size(); a++)
    {
        MapVertex* v1 = lines[a]->v1();
        MapVertex* v2 = lines[a]->v2();

        // Add vertices to copy list
        if (std::find(copy_verts.begin(), copy_verts.end(), v1) == copy_verts.end())
            copy_verts.push_back(v1);
        if (std::find(copy_verts.begin(), copy_verts.end(), v2) == copy_verts.end())
            copy_verts.push_back(v2);

        // Update min/max
        if (v1->xPos() < min_x) min_x = v1->xPos();
        if (v1->xPos() > max_x) max_x = v1->xPos();
        if (v1->yPos() < min_y) min_y = v1->yPos();
        if (v1->yPos() > max_y) max_y = v1->yPos();
        if (v2->xPos() < min_x) min_x = v2->xPos();
        if (v2->xPos() > max_x) max_x = v2->xPos();
        if (v2->yPos() < min_y) min_y = v2->yPos();
        if (v2->yPos() > max_y) max_y = v2->yPos();
    }

    // Determine midpoint
    double mid_x = min_x + ((max_x - min_x) * 0.5);
    double mid_y = min_y + ((max_y - min_y) * 0.5);
    this->midpoint.set(mid_x, mid_y);

    // Copy vertices
    for (unsigned a = 0; a < copy_verts.size(); a++)
    {
        MapVertex* copy = new MapVertex(copy_verts[a]->xPos() - mid_x, copy_verts[a]->yPos() - mid_y);
        copy->copy(copy_verts[a]);
        vertices.push_back(copy);
    }

    // Copy lines
    for (unsigned a = 0; a < lines.size(); a++)
    {
        // Get relative sides
        MapSide* s1 = NULL;
        MapSide* s2 = NULL;
        bool s1_found = false;
        bool s2_found = !(lines[a]->s2());
        for (unsigned b = 0; b < copy_sides.size(); b++)
        {
            if (lines[a]->s1() == copy_sides[b])
            {
                s1 = sides[b];
                s1_found = true;
            }
            if (lines[a]->s2() == copy_sides[b])
            {
                s2 = sides[b];
                s2_found = true;
            }

            if (s1_found && s2_found)
                break;
        }

        // Get relative vertices
        MapVertex* v1 = NULL;
        MapVertex* v2 = NULL;
        for (unsigned b = 0; b < copy_verts.size(); b++)
        {
            if (lines[a]->v1() == copy_verts[b])
                v1 = vertices[b];
            if (lines[a]->v2() == copy_verts[b])
                v2 = vertices[b];

            if (v1 && v2)
                break;
        }

        // Copy line
        MapLine* copy = new MapLine(v1, v2, s1, s2);
        copy->copy(lines[a]);
        this->lines.push_back(copy);
    }
}
Пример #2
0
/* MapArchClipboardItem::pasteToMap
 * Pastes copied architecture to [map] at [position]
 *******************************************************************/
vector<MapVertex*> MapArchClipboardItem::pasteToMap(SLADEMap* map, fpoint2_t position)
{
    std::map<MapVertex*, MapVertex*> vertMap;
    std::map<MapSector*, MapSector*> sectMap;
    std::map<MapSide*, MapSide*> sideMap;
    // Not used yet...
    // std::map<MapLine*, MapLine*> lineMap;

    // Add vertices
    vector<MapVertex*> new_verts;
    for (unsigned a = 0; a < vertices.size(); a++)
    {
        new_verts.push_back(map->createVertex(position.x + vertices[a]->xPos(), position.y + vertices[a]->yPos()));
        new_verts.back()->copy(vertices[a]);
        vertMap[vertices[a]] = new_verts.back();
    }

    // Add sectors
    for (unsigned a = 0; a < sectors.size(); a++)
    {
        MapSector* new_sector = map->createSector();
        new_sector->copy(sectors[a]);
        sectMap[sectors[a]] = new_sector;
    }

    // Add sides
    int first_new_side = map->nSides();
    for (unsigned a = 0; a < sides.size(); a++)
    {
        // Get relative sector
        MapSector* sector = findInMap(sectMap, sides[a]->getSector());

        MapSide* new_side = map->createSide(sector);
        new_side->copy(sides[a]);
        sideMap[sides[a]] = new_side;
    }

    // Add lines
    int first_new_line = map->nLines();
    for (unsigned a = 0; a < lines.size(); a++)
    {
        // Get relative vertices
        MapVertex* v1 = findInMap(vertMap, lines[a]->v1());
        MapVertex* v2 = findInMap(vertMap, lines[a]->v2());

        if (!v1)
        {
            wxLogMessage("no v1");
            continue;
        }
        if (!v2)
        {
            wxLogMessage("no v2");
        }

        MapLine* newline = map->createLine(v1, v2, true);
        newline->copy(lines[a]);
        // lineMap[lines[a]] = newline;

        // Set relative sides
        bool s1 = false;
        bool s2 = !(lines[a]->s2());
        MapSide* newS1 = findInMap(sideMap, lines[a]->s1());
        MapSide* newS2 = findInMap(sideMap, lines[a]->s2());
        if(newS1)
            newline->setS1(newS1);
        if(newS2)
            newline->setS2(newS2);

        // Set important flags (needed when copying from Doom/Hexen format to UDMF)
        // Won't be needed when proper map format conversion stuff is implemented
        theGameConfiguration->setLineBasicFlag(
            "twosided",
            newline,
            map->currentFormat(),
            (newS1 && newS2)
        );
        theGameConfiguration->setLineBasicFlag(
            "blocking",
            newline,
            map->currentFormat(),
            !newS2
        );
    }

    // TODO:
    // - Split lines
    // - Merge lines

    //// Fix sector references
    //// TODO: figure out what lines are 'outside' on copy, only fix said lines
    //for (unsigned a = first_new_line; a < map->nLines(); a++)
    //{
    //	MapLine* line = map->getLine(a);
    //	MapSector* sec1 = map->getLineSideSector(line, true);
    //	MapSector* sec2 = map->getLineSideSector(line, false);
    //	int i1 = -1;
    //	int i2 = -2;
    //	if (sec1) i1 = sec1->getIndex();
    //	if (sec2) i2 = sec2->getIndex();
    //	map->setLineSector(a, i1, true);
    //	map->setLineSector(a, i2, false);
    //}

    return new_verts;
}
Пример #3
0
/* MapArchClipboardItem::pasteToMap
 * Pastes copied architecture to [map] at [position]
 *******************************************************************/
vector<MapVertex*> MapArchClipboardItem::pasteToMap(SLADEMap* map, fpoint2_t position)
{
	std::map<MapVertex*, MapVertex*> vertMap;
	std::map<MapSector*, MapSector*> sectMap;
	std::map<MapSide*, MapSide*> sideMap;
	// Not used yet...
	// std::map<MapLine*, MapLine*> lineMap;

	// Add vertices
	vector<MapVertex*> new_verts;
	for (unsigned a = 0; a < vertices.size(); a++)
	{
		new_verts.push_back(map->createVertex(position.x + vertices[a]->xPos(), position.y + vertices[a]->yPos()));
		new_verts.back()->copy(vertices[a]);
		vertMap[vertices[a]] = new_verts.back();
	}

	// Add sectors
	for (unsigned a = 0; a < sectors.size(); a++)
	{
		MapSector* new_sector = map->createSector();
		new_sector->copy(sectors[a]);
		sectMap[sectors[a]] = new_sector;
	}

	// Add sides
	int first_new_side = map->nSides();
	for (unsigned a = 0; a < sides.size(); a++)
	{
		// Get relative sector
		MapSector* sector = findInMap(sectMap, sides[a]->getSector());

		MapSide* new_side = map->createSide(sector);
		new_side->copy(sides[a]);
		sideMap[sides[a]] = new_side;
	}

	// Add lines
	int first_new_line = map->nLines();
	for (unsigned a = 0; a < lines.size(); a++)
	{
		// Get relative vertices
		MapVertex* v1 = findInMap(vertMap, lines[a]->v1());
		MapVertex* v2 = findInMap(vertMap, lines[a]->v2());

		if (!v1)
		{
			wxLogMessage("no v1");
			continue;
		}
		if (!v2)
		{
			wxLogMessage("no v2");
		}

		MapLine* newline = map->createLine(v1, v2, true);
		newline->copy(lines[a]);
		// lineMap[lines[a]] = newline;

		// Set relative sides
		bool s1 = false;
		bool s2 = !(lines[a]->s2());
		MapSide* newS1 = findInMap(sideMap, lines[a]->s1());
		MapSide* newS2 = findInMap(sideMap, lines[a]->s2());
		if(newS1)
			newline->setS1(newS1);
		if(newS2)
			newline->setS2(newS2);
	}

	// TODO:
	// - Split lines
	// - Merge lines

	// Fix sector references
	// TODO: figure out what lines are 'outside' on copy, only fix said lines
	for (unsigned a = first_new_line; a < map->nLines(); a++)
	{
		MapLine* line = map->getLine(a);
		MapSector* sec1 = map->getLineSideSector(line, true);
		MapSector* sec2 = map->getLineSideSector(line, false);
		int i1 = -1;
		int i2 = -2;
		if (sec1) i1 = sec1->getIndex();
		if (sec2) i2 = sec2->getIndex();
		map->setLineSector(a, i1, true);
		map->setLineSector(a, i2, false);
	}

	return new_verts;
}