void saveFull( MultiBlock2D& multiBlock, FileName fName, IndexOrdering::OrderingT ordering )
{
    global::profiler().start("io");
    SparseBlockStructure2D blockStructure(multiBlock.getBoundingBox());
    Box2D bbox = multiBlock.getBoundingBox();
    if (ordering==IndexOrdering::forward) {
        plint nBlocks = std::min(bbox.getNx(), (plint)global::mpi().getSize());
        std::vector<std::pair<plint,plint> > ranges;
        util::linearRepartition(bbox.x0, bbox.x1, nBlocks, ranges);
        for (pluint iRange=0; iRange<ranges.size(); ++iRange) {
            blockStructure.addBlock (
                    Box2D( ranges[iRange].first, ranges[iRange].second,
                           bbox.y0, bbox.y1 ),
                    iRange );
        }
    }
    else if (ordering==IndexOrdering::backward) {
        plint nBlocks = std::min(bbox.getNy(), (plint)global::mpi().getSize());
        std::vector<std::pair<plint,plint> > ranges;
        util::linearRepartition(bbox.y0, bbox.y1, nBlocks, ranges);
        for (pluint iRange=0; iRange<ranges.size(); ++iRange) {
            blockStructure.addBlock (
                    Box2D( bbox.x0, bbox.x1, ranges[iRange].first, ranges[iRange].second ),
                    iRange );
        }
    }
    else {
        // Sparse ordering not defined.
        PLB_ASSERT( false );
    }
    plint envelopeWidth=1;
    MultiBlockManagement2D adjacentMultiBlockManagement (
            blockStructure, new OneToOneThreadAttribution, envelopeWidth );
    MultiBlock2D* multiAdjacentBlock = multiBlock.clone(adjacentMultiBlockManagement);
    
    std::vector<plint> offset;
    std::vector<plint> myBlockIds;
    std::vector<std::vector<char> > data;

    bool dynamicContent = false;
    dumpData(*multiAdjacentBlock, dynamicContent, offset, myBlockIds, data);
    if (ordering==IndexOrdering::backward && myBlockIds.size()==1) {
        PLB_ASSERT( data.size()==1 );
        Box2D domain;
        blockStructure.getBulk(myBlockIds[0], domain);
        plint sizeOfCell = multiAdjacentBlock->sizeOfCell();
        PLB_ASSERT( domain.nCells()*sizeOfCell == (plint)data[0].size() );
        transposeToBackward( sizeOfCell, domain, data[0] );
    }

    plint totalSize = offset[offset.size()-1];
    writeOneBlockXmlSpec(*multiAdjacentBlock, fName, totalSize, ordering);
    writeRawData(fName, myBlockIds, offset, data);
    delete multiAdjacentBlock;
    global::profiler().stop("io");
}
void AtomicBlockUnSerializer2D::commitData() {
    PLB_PRECONDITION( !isFull() );
    if (ordering==IndexOrdering::forward || ordering==IndexOrdering::memorySaving) {
        block.getDataTransfer().receive(Box2D(iX,iX, domain.y0, domain.y1),
                                        buffer, modif::staticVariables);
        ++iX;
    }
    else {
        block.getDataTransfer().receive(Box2D(domain.x0, domain.x1, iY,iY),
                                        buffer, modif::staticVariables);
        ++iY;
    }
}
Beispiel #3
0
  Region2D regionFromXml(XMLreaderProxy const &r)
  {
    std::string id;
    plint x0,x1,y0,y1;
    try{
      r["id"].read(id);
    } catch (PlbIOException &e){
      throw PlbIOException("Invalid Region command: No id specified");
    }

    try{
      r["x0"].read(x0);
      r["x1"].read(x1);
      r["y0"].read(y0);
      r["y1"].read(y1);
    } catch(PlbIOException &e){
      throw PlbIOException("Invalid Region command: size specifications missing");
    }

    if( id.compare("") == 0 )
      throw PlbIOException("Invalid Region command: Unnamed region");
    if( x0<0 || y0<0 || x1<0 || y1<0 || x1<x0 || y1<y0 ){
      std::string errmsg("Invalid Region command: Bad size in region ");
      errmsg.append(id);
      throw PlbIOException(errmsg);
    }
      
    return Region2D(id,Box2D(x0,x1,y0,y1));
  }
const char* AtomicBlockSerializer2D::getNextDataBuffer(pluint& bufferSize) const {
    PLB_PRECONDITION( !isEmpty() );
    if (ordering==IndexOrdering::forward || ordering==IndexOrdering::memorySaving) {
        bufferSize = domain.getNy() * block.getDataTransfer().staticCellSize();
        buffer.resize(bufferSize);
        block.getDataTransfer().send(Box2D(iX,iX, domain.y0, domain.y1),
                                     buffer, modif::staticVariables);
        ++iX;
    }
    else {
        bufferSize = domain.getNx() * block.getDataTransfer().staticCellSize();
        buffer.resize(bufferSize);
        block.getDataTransfer().send(Box2D(domain.x0, domain.x1, iY,iY),
                                           buffer, modif::staticVariables);
        ++iY;
    }
    return &buffer[0];
}
MultiGridManagement2D::MultiGridManagement2D(plint nx, plint ny, 
                                             plint numLevels, plint overlapWidth_, plint referenceLevel_)
                                  : overlapWidth(overlapWidth_),
                                    referenceLevel(referenceLevel_),
                                    boundingBoxes(numLevels),
                                    coarseGridInterfaces(numLevels),
                                    fineGridInterfaces(numLevels),
                                    bulks(numLevels),
                                    coarseInterfaceOrientations(numLevels),
                                    fineInterfaceOrientations(numLevels)
{
    PLB_ASSERT( numLevels > 0 );
    PLB_ASSERT( referenceLevel < numLevels );
    initialize(Box2D(0, nx-1, 0, ny-1));
}
Beispiel #6
0
void GUILevelPathing::Render(float elapsedTime, const RenderInfo& info)
{
    //Overlay a color onto each room based on its proximity to each team.
    for (unsigned int i = 0; i < editor.LevelData.Rooms.size(); ++i)
    {
        const LevelInfo::RoomData& room = editor.LevelData.Rooms[i];

        Vector2f worldCenter = ToV2f(room.MinCornerPos) + (ToV2f(room.Walls.GetDimensions()) * 0.5f);
        SetBounds(Box2D(editor.WorldPosToScreen(worldCenter),
                        editor.WorldSizeToScreen(ToV2f(room.Walls.GetDimensions()))));

        Vector3f colRGB((COLOR_Team1 * (1.0f - powf(roomNormalizedDistsToTeamBases[i][0], COLOR_Exponent))) +
                        (COLOR_Team2 * (1.0f - powf(roomNormalizedDistsToTeamBases[i][1], COLOR_Exponent))));
        SetColor(Vector4f(colRGB, ALPHA_Team));

        GUITexture::Render(elapsedTime, info);
    }
}
Beispiel #7
0
Box2D GUITexture::GetBounds(void) const
{
    Vector2f dims = GetScale();
    if (tex != 0)
    {
        if (rotation == 0.0f)
        {
            dims = ToV2f(Vector2u(tex->GetWidth(), tex->GetHeight()));
            dims.MultiplyComponents(GetScale());
        }
        else
        {
            float diameter = 2.0f * ToV2f(Vector2u(tex->GetWidth(), tex->GetHeight())).Length();
            dims = Vector2f(diameter, diameter);
        }
    }

    return Box2D(Vector2f(), dims);
}
Beispiel #8
0
Vector2 View::ProjectAndClipToScreen( const Vector& Location ) const
{
	const Vector4			ProjectedLocation4D	= Project( Location );
	Vector2					ProjectedLocation2D;

	if( Abs( ProjectedLocation4D.w ) < EPSILON )
	{
		ProjectedLocation2D = ProjectedLocation4D;
	}
	else
	{
		ProjectedLocation2D = ProjectedLocation4D / ProjectedLocation4D.w;

		if( ProjectedLocation4D.w < 0.0f )
		{
			// Project beyond [-1,1] if location is behind view.
			ProjectedLocation2D = ProjectedLocation2D.GetNormalized() * -2.0f;
		}
	}

	static const Vector2	kScreenScale		= Vector2( 0.5f, -0.5f );
	static const Vector2	kScreenOffset		= Vector2( 0.5f, 0.5f );
	static const Vector2	kScreenMin			= Vector2( 0.0f, 0.0f );
	static const Vector2	kScreenMid			= Vector2( 0.5f, 0.5f );
	static const Vector2	kScreenMax			= Vector2( 1.0f, 1.0f );
	static const Box2D		kScreenBox			= Box2D( kScreenMin, kScreenMax );
	Vector2					ScreenLocation		= ( ProjectedLocation2D * kScreenScale ) + kScreenOffset;
	const Segment2D			ScreenSegment		= Segment2D( ScreenLocation, kScreenMid );

	CollisionInfo2D			Info;
	if( ScreenSegment.Intersects( kScreenBox, &Info ) )
	{
		ScreenLocation = Info.m_Intersection;
	}

	ScreenLocation.x = Clamp( ScreenLocation.x, 0.0f, 1.0f );
	ScreenLocation.y = Clamp( ScreenLocation.y, 0.0f, 1.0f );

	return ScreenLocation;
}
cell AMX_NATIVE_CALL Natives::CreateDynamicRectangle(AMX *amx, cell *params)
{
	CHECK_PARAMS(7, "CreateDynamicRectangle");
	if (core->getData()->getGlobalMaxItems(STREAMER_TYPE_AREA) == core->getData()->areas.size())
	{
		return 0;
	}
	int areaID = Item::Area::identifier.get();
	Item::SharedArea area(new Item::Area);
	area->amx = amx;
	area->areaID = areaID;
	area->type = STREAMER_AREA_TYPE_RECTANGLE;
	area->position = Box2D(Eigen::Vector2f(amx_ctof(params[1]), amx_ctof(params[2])), Eigen::Vector2f(amx_ctof(params[3]), amx_ctof(params[4])));
	boost::geometry::correct(boost::get<Box2D>(area->position));
	area->size = static_cast<float>(boost::geometry::comparable_distance(boost::get<Box2D>(area->position).min_corner(), boost::get<Box2D>(area->position).max_corner()));
	Utility::addToContainer(area->worlds, static_cast<int>(params[5]));
	Utility::addToContainer(area->interiors, static_cast<int>(params[6]));
	Utility::addToContainer(area->players, static_cast<int>(params[7]));
	core->getGrid()->addArea(area);
	core->getData()->areas.insert(std::make_pair(areaID, area));
	return static_cast<cell>(areaID);
}
void initializeQuadrant(QuadTree* quadtree, const Box2D& quadrantBounds, unsigned int depth, unsigned int index, unsigned int offset, unsigned int levelWidth)
{
    unsigned int i = offset + index;

    // FIXME: checking boundaries
    if (i >= quadtree->maxQuadrants)
    {
        throw std::exception("max. quadrants overflow");
    }

    Quadrant& quadrant = quadtree->quadrants[i];
    quadrant.depth = depth;
    quadrant.bounds = quadrantBounds;

    if (depth == quadtree->maxDepth - 1) // leaf
    {
        quadrant.edges = quadtree->numQuadrantEdges++;
        return;
    }

    unsigned int baseIndex = (index * 4);
    unsigned int newOffset = offset + levelWidth;
    unsigned int newLevelWidth = levelWidth * 4;
    unsigned int newDepth = depth + 1;
    vml_vec2 subQuadrantSize = quadrantBounds.getExtents() / 2.0f;

    for (unsigned int y = 0, i = 0; y < 2; y++)
    {
        float subQuadrantY = quadrantBounds.min.y + ((float)y * subQuadrantSize.y);

        for (unsigned int x = 0; x < 2; x++, i++)
        {
            initializeQuadrant(quadtree, Box2D(quadrantBounds.min.x + ((float)x * subQuadrantSize.x), subQuadrantY, subQuadrantSize.x, subQuadrantSize.y), newDepth, baseIndex + i, newOffset, newLevelWidth);
        }
    }
}
Beispiel #11
0
Box2D::Box2D(const Vector2& min, const Vector2& max) {
    *this = Box2D(Rect2D::xyxy(min, max));
}
Beispiel #12
0
/*
 * Camera.cpp
 *
 *  Created on: 10/01/2013
 *      Author: bruno
 */

#include "Camera.hpp"
#include <sstream>

Box2D Camera::geometry = Box2D(0, 0, 640, 480);
PointF Camera::lockedPosition = PointF(0, 0);
bool Camera::fullScreen = true;
bool Camera::scrollingX = false;
bool Camera::scrollingY = false;
bool Camera::lockedX = false;
bool Camera::lockedY = false;
bool Camera::lockedRange = false;
bool Camera::translating = false;
PointI Camera::beginRangeLock = PointI(0, 0);
PointI Camera::endRangeLock = PointI(0, 0);

Camera::Camera() {

}

Camera::~Camera() {
}

PointF Camera::getPosition() {
    return PointF(geometry.getLeftSide(), geometry.getTopSide());
Beispiel #13
0
Box2D AtomicBlock2D::getBoundingBox() const {
    return Box2D(0, getNx()-1, 0, getNy()-1);
}
void MultiGridManagement2D::refineMultiGrid(plint coarseLevel, Box2D coarseDomain){
        
    // The finest multi-block, at level bulks.size()-1, cannot be further refined.
    PLB_PRECONDITION( coarseLevel>=0 && coarseLevel< (plint)bulks.size()-1 );
    plint fineLevel = coarseLevel+1;
    
    // First, trim the domain coarseDomain in case it exceeds the extent of the
    //   multi-block, and determine whether coarseDomain touches one of the boundaries
    //   of the multi-block. This information is needed, because the coarse domain
    //   fully replaces the fine domain on boundaries of the multi-block, and there
    //   is therefore no need to create a coarse-fine coupling.
    bool touchLeft=false, touchRight=false, touchBottom=false, touchTop=false;
    trimDomain(coarseLevel, coarseDomain, touchLeft, touchRight, touchBottom, touchTop);

    // The reduced coarse domain is the one which is going to be excluded from
    //   the original coarse lattice.
    Box2D reducedCoarseDomain(coarseDomain.enlarge(-1));
    // The extended coarse domain it the one which is going to be added
    //   to the original fine lattice.
    Box2D extendedCoarseDomain(coarseDomain.enlarge(overlapWidth));
    
    // If the domain in question touches a boundary of the multi-block,
    //   both the reduced and the extended coarse domain are
    //   identified with the boundary location.
    if (touchLeft) {
        reducedCoarseDomain.x0    -= 1;
        extendedCoarseDomain.x0   += overlapWidth;
    }
    if (touchRight) {
        reducedCoarseDomain.x1    += 1;
        extendedCoarseDomain.x1   -= overlapWidth;
    }
    if (touchBottom) {
        reducedCoarseDomain.y0    -= 1;
        extendedCoarseDomain.y0   += overlapWidth;
    }
    if (touchTop) {
        reducedCoarseDomain.y1    += 1;
        extendedCoarseDomain.y1   -= overlapWidth;
    }

    
    // Do not do anything to the coarse domain
    
    
    // Convert the extended coarse domain to fine units,
    //   and add to the original fine multi-block.
    Box2D extendedFineDomain(extendedCoarseDomain.multiply(2));
    bulks[fineLevel].push_back(extendedFineDomain);

    // Define coupling interfaces for all four sides of the coarsened domain, unless they
    //   touch a boundary of the multi-block.
    if (!touchLeft) {

        // it is a right border in the coarse case
        coarseInterfaceOrientations[coarseLevel].push_back(Array<plint,2>(0,1));
        fineGridInterfaces[fineLevel].push_back( Box2D( extendedCoarseDomain.x0, extendedCoarseDomain.x0, 
                                                        extendedCoarseDomain.y0, extendedCoarseDomain.y1 ) );
        // it is a left border in the fine case
        fineInterfaceOrientations[fineLevel].push_back(Array<plint,2>(0,-1));
    }
    if (!touchRight) {

        // it is a left border in the coarse case
        coarseInterfaceOrientations[coarseLevel].push_back(Array<plint,2>(0,-1));
        fineGridInterfaces[fineLevel].push_back( Box2D( extendedCoarseDomain.x1, extendedCoarseDomain.x1, 
                                                        extendedCoarseDomain.y0, extendedCoarseDomain.y1 ) );
        // it is a right border in the fine case
        fineInterfaceOrientations[fineLevel].push_back(Array<plint,2>(0,1));
    }
    if (!touchBottom) {
        
        fineGridInterfaces[fineLevel].push_back( Box2D( extendedCoarseDomain.x0, extendedCoarseDomain.x1, 
                                                        extendedCoarseDomain.y0, extendedCoarseDomain.y0 ) );
        // it is an upper border in the coarse case
        coarseInterfaceOrientations[coarseLevel].push_back(Array<plint,2>(1,1));
        // it is a lower border in the fine case
        fineInterfaceOrientations[fineLevel].push_back(Array<plint,2>(1,-1));
    }
    if (!touchTop) {
        
        // it is a lower border in the coarse case
        coarseInterfaceOrientations[coarseLevel].push_back(Array<plint,2>(1,-1));
        fineGridInterfaces[fineLevel].push_back( Box2D( extendedCoarseDomain.x0, extendedCoarseDomain.x1, 
                                                        extendedCoarseDomain.y1, extendedCoarseDomain.y1 ) );
        // it is an upper border in the fine case
        fineInterfaceOrientations[fineLevel].push_back(Array<plint,2>(1,1));
    }
    
    coarseGridInterfaces[coarseLevel].push_back(coarseDomain);
}
void MultiGridManagement2D::coarsen(plint fineLevel, Box2D coarseDomain){
    // The coarsest multi-block, at level 0, cannot be further coarsened.
    PLB_PRECONDITION( fineLevel>=1 && fineLevel<(plint)bulks.size() );
    plint coarseLevel = fineLevel-1;

    // First, trim the domain coarseDomain in case it exceeds the extent of the
    //   multi-block, and determine whether coarseDomain touches one of the boundaries
    //   of the multi-block. This information is needed, because the coarse domain
    //   fully replaces the fine domain on boundaries of the multi-block, and there
    //   is therefore no need to create a coarse-fine coupling.
    bool touchLeft=false, touchRight=false, touchBottom=false, touchTop=false;
    trimDomain(coarseLevel, coarseDomain, touchLeft, touchRight, touchBottom, touchTop);

    // Convert the coarse domain to fine units.
    Box2D fineDomain(coarseDomain.multiply(2));
    // The reduced fine domain is the one which is going to be excluded from
    //   the original fine lattice.
    Box2D intermediateFineDomain(fineDomain.enlarge(-1));
    // The extended coarse domain it the one which is going to be added
    //   to the original coarse lattice.
    Box2D extendedCoarseDomain(coarseDomain.enlarge(1));
    
    // If the domain in question touches a boundary of the multi-block,
    //   both the reduced fine domain and the extended coarse domain are
    //   identified with the boundary location.
    if (touchLeft) {
        intermediateFineDomain.x0 -= 1;
        extendedCoarseDomain.x0   += 1;
    }
    if (touchRight) {
        intermediateFineDomain.x1 += 1;
        extendedCoarseDomain.x1   -= 1;
    }
    if (touchBottom) {
        intermediateFineDomain.y0 -= 1;
        extendedCoarseDomain.y0   += 1;
    }
    if (touchTop) {
        intermediateFineDomain.y1 += 1;
        extendedCoarseDomain.y1   -= 1;
    }

    // Extract reduced fine domain from the original fine multi-block.
    std::vector<Box2D> exceptedBlocks;
    for (pluint iBlock=0; iBlock<bulks[fineLevel].size(); ++iBlock) {
        except(bulks[fineLevel][iBlock], intermediateFineDomain, exceptedBlocks);
    }
    exceptedBlocks.swap(bulks[fineLevel]);

    // Add extended coarse domain to the original coarse multi-block.
    bulks[coarseLevel].push_back(extendedCoarseDomain);
    
    // Define coupling interfaces for all four sides of the refined domain, unless they
    //   touch a boundary of the multi-block.
    if (!touchLeft) {
        coarseGridInterfaces[coarseLevel].push_back( Box2D( extendedCoarseDomain.x0, extendedCoarseDomain.x0,
                                                            extendedCoarseDomain.y0, extendedCoarseDomain.y1 ) );
        fineGridInterfaces[fineLevel].push_back( Box2D( coarseDomain.x0, coarseDomain.x0, 
                                                        coarseDomain.y0, coarseDomain.y1 ) );
                                                        
        // it is a left border in the coarse case
        coarseInterfaceOrientations[coarseLevel].push_back(Array<plint,2>(0,-1));
        // it is an right border in the fine case
        fineInterfaceOrientations[fineLevel].push_back(Array<plint,2>(0,1));
    }
    if (!touchRight) {
        coarseGridInterfaces[coarseLevel].push_back( Box2D( extendedCoarseDomain.x1, extendedCoarseDomain.x1,
                                                            extendedCoarseDomain.y0, extendedCoarseDomain.y1 ) );
        fineGridInterfaces[fineLevel].push_back( Box2D( coarseDomain.x1, coarseDomain.x1, 
                                                        coarseDomain.y0, coarseDomain.y1 ) );
                                                        
        // it is a right border in the coarse case
        coarseInterfaceOrientations[coarseLevel].push_back(Array<plint,2>(0,1));
        // it is a left border in the fine case
        fineInterfaceOrientations[fineLevel].push_back(Array<plint,2>(0,-1));
    }
    if (!touchBottom) {
        coarseGridInterfaces[coarseLevel].push_back( Box2D( extendedCoarseDomain.x0, extendedCoarseDomain.x1,
                                                            extendedCoarseDomain.y0, extendedCoarseDomain.y0 ) );
        fineGridInterfaces[fineLevel].push_back( Box2D( coarseDomain.x0, coarseDomain.x1, 
                                                        coarseDomain.y0, coarseDomain.y0 ) );
                                                        
        // it is a bottom border in the coarse case
        coarseInterfaceOrientations[coarseLevel].push_back(Array<plint,2>(1,-1)); //TODO check this!!!
        // it is a top border in the fine case
        fineInterfaceOrientations[fineLevel].push_back(Array<plint,2>(1,1));        
    }
    if (!touchTop) {
        coarseGridInterfaces[coarseLevel].push_back( Box2D( extendedCoarseDomain.x0, extendedCoarseDomain.x1,
                                                            extendedCoarseDomain.y1, extendedCoarseDomain.y1 ) );
        fineGridInterfaces[fineLevel].push_back( Box2D( coarseDomain.x0, coarseDomain.x1, 
                                                        coarseDomain.y1, coarseDomain.y1 ) );
                                                        
        // it is a top border in the coarse case
        coarseInterfaceOrientations[coarseLevel].push_back(Array<plint,2>(1,1));
        // it is an bottom border in the fine case
        fineInterfaceOrientations[fineLevel].push_back(Array<plint,2>(1,-1));
    }
}