コード例 #1
0
bool ossimImageSourceSequencer::getTileOrigin(ossim_int32 id,
                                              ossimIpt& origin)const
{
   if(id < 0)
   {
      return false;
   }
   if((theNumberOfTilesHorizontal > 0)&&
      (theCurrentTileNumber < getNumberOfTiles()))
   {
      ossim_int32 y = id/static_cast<ossim_int32>(theNumberOfTilesHorizontal);
      ossim_int32 x = id%static_cast<ossim_int32>(theNumberOfTilesHorizontal);
      if((x < static_cast<ossim_int32>(theNumberOfTilesHorizontal)) &&
         (y < static_cast<ossim_int32>(theNumberOfTilesVertical)))
      {           
         origin.x = theAreaOfInterest.ul().x + x*theTileSize.x;
         origin.y = theAreaOfInterest.ul().y + y*theTileSize.y;
      }
      else
      {
         return false;
      }
   }
   else
   {
      return false;
   }
   
   return true;
}
コード例 #2
0
bool ossimImageSourceSequencer::getTileOrigin(ossim_int64 id, ossimIpt& origin) const
{
   bool result = false;
   if( id >= 0 )
   {
      if( (theNumberOfTilesHorizontal > 0) && (theCurrentTileNumber < getNumberOfTiles()) )
      {
         ossim_int64 y = id / theNumberOfTilesHorizontal;
         ossim_int64 x = id % theNumberOfTilesHorizontal;
         if( (x < theNumberOfTilesHorizontal) && (y < theNumberOfTilesVertical) )
         {
            ossim_int64 ulx = theAreaOfInterest.ul().x;
            ossim_int64 uly = theAreaOfInterest.ul().y;
            ossim_int64 tx  = theTileSize.x;
            ossim_int64 ty  = theTileSize.y; 
            x = ulx + x * tx;
            y = uly + y * ty;

            //---
            // ossimIpt currently signed 32 bit so make sure we didn't bust the
            // bounds.
            //---
            if ( (x <= OSSIM_DEFAULT_MAX_PIX_SINT32) && ( y <= OSSIM_DEFAULT_MAX_PIX_SINT32) )
            {
               origin.x = (ossim_int32)x;
               origin.y = (ossim_int32)y;
               result = true;
            }
         }
      }
   }
   return result;
}
コード例 #3
0
Level::~Level()
{
	//Delete the player object
	if(m_Player != NULL)
	{
		delete m_Player;
		m_Player = NULL;
	}

	//Delete the tiles array, the inheriting class
	//must delete the object in this array itself
	if(m_Tiles != NULL)
	{
		//Cycle through and delete all the tile objects in the array
		for(int i = 0; i < getNumberOfTiles(); i++)
		{
			if(m_Tiles[i] != NULL)
			{
				delete m_Tiles[i];
				m_Tiles[i] = NULL;
			}
		}

		delete[] m_Tiles;
		m_Tiles = NULL;
	}
}
コード例 #4
0
void Level::save(const char* levelName)
{
	//TODO: save the level

	Json::Value root;//root object

    root["width"] = m_HorizontalTiles;//key values being put into the root
    root["height"] = m_VerticalTiles;
    Json::Value tilesType(Json::arrayValue);//array
    Json::Value tileType;
    
    for(int i = 0; i < getNumberOfTiles(); i++)//creates a loop to get the tiles to save
    {
    	tileType["type"] = m_Tiles[i]->getTileType();
    	tilesType.append(tileType);
    }
    
    root["TileType"] = tilesType;
    
    std::ofstream out;//this puts it in a file
    out.open(levelName);
    out << root;
    out.close();	

}
コード例 #5
0
void Level::paint()
{
	//Cycle through and paint all the tiles
	for(int i = 0; i < getNumberOfTiles(); i++)
	{
		//Safety check the tile
		if(m_Tiles[i] != NULL)
		{
			//Paint the tile
			m_Tiles[i]->paint();

			//If the paint tile indexes flag is set to true,
			//draw the index number on the tiles
			if(m_PaintTileIndexes == true)
			{
				m_Tiles[i]->paintIndex(i);
			}
		}
	}

	//Paint the Player
	if(m_Player != NULL)
	{
		//If paint tile scoring flag is set to true,
		//draw the path scoring
		if(m_PaintTileScoring == true)
		{
			//TODO: Paint the tile scores
		}
		//Paint the player
		m_Player->paint();
	}
}
コード例 #6
0
void Level::setSelectedTileIndex(int aSelectedIndex)
{
	//Deselect the previously selected tile
	if(m_SelectedTileIndex >= 0 && m_SelectedTileIndex < getNumberOfTiles())
	{
		m_Tiles[m_SelectedTileIndex]->setIsSelected(false);
	}

	//Set the new tile index
	m_SelectedTileIndex = aSelectedIndex;

	//Selected the newly selected tile
	if(m_SelectedTileIndex >= 0 && m_SelectedTileIndex < getNumberOfTiles())
	{
		m_Tiles[m_SelectedTileIndex]->setIsSelected(true);
	}
}
コード例 #7
0
TileType Level::getTileTypeForIndex(int index)
{
	if(index >= 0 && index < getNumberOfTiles())
	{
		return m_Tiles[index]->getTileType();
	}
	return TileTypeUnknown;
}
コード例 #8
0
void Level::setTileTypeAtIndex(TileType tileType, int index)
{
	//Safety check the index
	if(index >= 0 && index < getNumberOfTiles())
	{
		//Don't replace the tile if its the same type of tile that already exists
		if(m_Tiles[index]->getTileType() == tileType)
		{
			return;
		}

		//Delete the tile at the index, if one exists
		if(m_Tiles[index] != NULL)
		{
			delete m_Tiles[index];
			m_Tiles[index] = NULL;
		}

		//Create the new tile based on the TileType
		switch (tileType)
		{
		case TileTypeGround:
			m_Tiles[index] = new GroundTile();
			break;

		case TileTypeGrass:
			m_Tiles[index] = new GrassTile();
			break;

		case TileTypeStone:
			m_Tiles[index] = new WaterTile();
			break;

		case TileTypeBrick:
			m_Tiles[index] = new BrickTile();
			break;

		case TileTypeHasselhoff:
			m_Tiles[index] = new FireTile();
			break;

		case TileTypeWood:
			m_Tiles[index] = new HardwoodTile();
			break;

		case TileTypeUnknown:
		default:
			m_Tiles[index] = NULL;
			break;
		}

		//Calculate the coordinates and set the tile position and size
		int coordinateX = (index % getNumberOfHorizontalTiles());
		int coordinateY = ((index - coordinateX) / getNumberOfHorizontalTiles());
		m_Tiles[index]->setPosition(coordinateX  * m_TileSize, coordinateY * m_TileSize);
		m_Tiles[index]->setSize(m_TileSize, m_TileSize);
	}
}
コード例 #9
0
Tile* Level::getTileForIndex(int aIndex)
{
	//Safety check the index bounds
	if(aIndex >= 0 && aIndex < getNumberOfTiles())
	{
		return m_Tiles[aIndex];
	}

	//If we got here, it means the index passed in was out of bounds
	return NULL;
}
コード例 #10
0
ossimRefPtr<ossimImageData> ossimImageSourceSequencer::getTile(
   ossim_int64 id, ossim_uint32 resLevel)
{
   static const char* MODULE= "ossimImageSourceSequencer::getTile(id, resLevel)";
   if(traceDebug())
   {
      CLOG << "entering.."<<endl;
   }

   ossimRefPtr<ossimImageData> result = 0;

   if(theInputConnection)
   {
      // if we have no tiles try to initialize.
      if(getNumberOfTiles() == 0)
      {
         initialize();
      }

      ossimIrect tileRect;
      if ( getTileRect( id, tileRect ) )
      {
         result = theInputConnection->getTile(tileRect, resLevel);
         if( !result.valid() || !result->getBuf() )
         {	 
            theBlankTile->setImageRectangle(tileRect);
            result = theBlankTile;
         }
      }
      else // getTileRect failed...
      {
         if(traceDebug())
         {
            CLOG << "was not able to get an origin for id = " << id << endl;
         }
      }
   }
   else // no connection...
   {
      if(traceDebug())
      {
         CLOG << "No input connection so returing NULL" << endl;
      }
   }
   if(traceDebug())
   {
      CLOG << "leaving.."<<endl;
   }
   
   return result;
}
コード例 #11
0
void Level::update(double aDelta)
{
	//Update all the game tiles
	for(int i = 0; i < getNumberOfTiles(); i++)
	{
		if(m_Tiles[i] != NULL)
		{
			m_Tiles[i]->update(aDelta);
		}
	}

	//Update the Player
	if(m_Player != NULL)
	{
		m_Player->update(aDelta);
	}
}
コード例 #12
0
void Level::reset()
{
	//Cycle through and reset all the tiles
	for(int i = 0; i < getNumberOfTiles(); i++)
	{
		if(m_Tiles[i] != NULL)
		{
			m_Tiles[i]->reset();
		}
	}

	//Reset the Player
	if(m_Player != NULL)
	{
		m_Player->reset();
		m_Player->setCurrentTile(m_Tiles[m_PlayerStartingTileIndex]);
	}
}
コード例 #13
0
void ossimImageMpiSWriterSequenceConnection::slaveProcessTiles()
{
#ifdef OSSIM_HAS_MPI
#  if OSSIM_HAS_MPI
    ossimEndian endian;
    ossim_uint32 numberOfTiles    = getNumberOfTiles();
    long currentSendRequest = 0;
    long numberOfTilesSent  = 0;
    int errorValue= 0;
    MPI_Request *requests   = new MPI_Request[theNumberOfTilesToBuffer];
    for (int i = 0; i < theNumberOfTilesToBuffer; ++i)
    {
        requests[i] = MPI_REQUEST_NULL;
    }

    if(traceDebug())
    {
        ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimImageMpiSWriterSequenceConnection::slaveProcessTiles(): entering slave and will look at " << numberOfTiles << " tiles" << std::endl;
    }
    while(theCurrentTileNumber < numberOfTiles)
    {
        ossimRefPtr<ossimImageData> data = ossimImageSourceSequencer::getTile(theCurrentTileNumber);

        // if the current send requests have looped around
        // make sure we wait to see if it was sent
        //
        errorValue = MPI_Wait(&requests[currentSendRequest], MPI_STATUS_IGNORE);
        requests[currentSendRequest] = MPI_REQUEST_NULL;
        if(data.valid() &&
                (data->getDataObjectStatus()!=OSSIM_NULL)&&
                (data->getDataObjectStatus()!=OSSIM_EMPTY))
        {
            theOutputTile[currentSendRequest]->setImageRectangle(data->getImageRectangle());
            theOutputTile[currentSendRequest]->initialize();

            theOutputTile[currentSendRequest]->loadTile(data.get());
            theOutputTile[currentSendRequest]->setDataObjectStatus(data->getDataObjectStatus());

            if(traceDebug())
            {
                if(data->getDataObjectStatus() == OSSIM_EMPTY)
                {
                    ossimNotify(ossimNotifyLevel_DEBUG)
                            << "DEBUG ossimImageMpiSWriterSequenceConnection::slaveProcessTiles(): In salve = "
                            << theRank << " tile is empty" << std::endl;
                }
            }
        }
        else
        {
            if(traceDebug())
            {
                if(!data)
                {
                    ossimNotify(ossimNotifyLevel_DEBUG)
                            << "DEBUG ossimImageMpiSWriterSequenceConnection::slaveProcessTiles(): In slave = "
                            << theRank << " ptr is null " << std::endl;
                }
                else
                {
                    ossimNotify(ossimNotifyLevel_DEBUG)
                            << "DEBUG ossimImageMpiSWriterSequenceConnection::slaveProcessTiles(): In slave = " << theRank << " tile is empty" << std::endl;
                }
            }
            theOutputTile[currentSendRequest]->makeBlank();
        }

        void* buf = theOutputTile[currentSendRequest]->getBuf();
        if((endian.getSystemEndianType()!=OSSIM_BIG_ENDIAN)&&
                (theOutputTile[currentSendRequest]->getScalarType()!=OSSIM_UINT8))
        {
            endian.swap(theOutputTile[currentSendRequest]->getScalarType(),
                        buf,
                        theOutputTile[currentSendRequest]->getSize());
        }
        errorValue = MPI_Isend(buf,
                               theOutputTile[currentSendRequest]->getSizeInBytes(),
                               MPI_UNSIGNED_CHAR,
                               0,
                               0,
                               MPI_COMM_WORLD,
                               &requests[currentSendRequest]);
#if 0
        switch(theOutputTile[currentSendRequest]->getScalarType())
        {
        case OSSIM_UINT8:
        {
            errorValue = MPI_Isend(buf,
                                   theOutputTile[currentSendRequest]->getSize(),
                                   MPI_UNSIGNED_CHAR,
                                   0,
                                   0,
                                   MPI_COMM_WORLD,
                                   &requests[currentSendRequest]);
            break;
        }
        case OSSIM_SINT8:
        {
            errorValue = MPI_Isend(buf,
                                   theOutputTile[currentSendRequest]->getSize(),
                                   MPI_CHAR,
                                   0,
                                   0,
                                   MPI_COMM_WORLD,
                                   &requests[currentSendRequest]);
            break;
        }
        case OSSIM_UINT16:
        {
            errorValue = MPI_Isend(buf,
                                   theOutputTile[currentSendRequest]->getSize(),
                                   MPI_UNSIGNED_SHORT,
                                   0,
                                   0,
                                   MPI_COMM_WORLD,
                                   &requests[currentSendRequest]);
            break;
        }
        case OSSIM_SINT16:
        {
            errorValue = MPI_Isend(buf,
                                   theOutputTile[currentSendRequest]->getSize(),
                                   MPI_SHORT,
                                   0,
                                   0,
                                   MPI_COMM_WORLD,
                                   &requests[currentSendRequest]);
            break;
        }
        case OSSIM_UINT32:
        {
            errorValue = MPI_Isend(buf,
                                   theOutputTile[currentSendRequest]->getSize(),
                                   MPI_UNSIGNED_LONG,
                                   0,
                                   0,
                                   MPI_COMM_WORLD,
                                   &requests[currentSendRequest]);
            break;
        }
        case OSSIM_SINT32:
        {
            errorValue = MPI_Isend(buf,
                                   theOutputTile[currentSendRequest]->getSize(),
                                   MPI_LONG,
                                   0,
                                   0,
                                   MPI_COMM_WORLD,
                                   &requests[currentSendRequest]);
            break;
        }
        case OSSIM_FLOAT32:
        case OSSIM_NORMALIZED_FLOAT:
        {
            errorValue = MPI_Isend(buf,
                                   theOutputTile[currentSendRequest]->getSize(),
                                   MPI_FLOAT,
                                   0,
                                   0,
                                   MPI_COMM_WORLD,
                                   &requests[currentSendRequest]);
            break;
        }
        case OSSIM_FLOAT64:
        case OSSIM_NORMALIZED_DOUBLE:
        {
            errorValue = MPI_Isend(buf,
                                   theOutputTile[currentSendRequest]->getSize(),
                                   MPI_DOUBLE,
                                   0,
                                   0,
                                   MPI_COMM_WORLD,
                                   &requests[currentSendRequest]);
            break;
        }
        default:
            break;
        }
#endif
        theCurrentTileNumber += (theNumberOfProcessors-1);
        numberOfTilesSent++;
        currentSendRequest++;
        currentSendRequest %= theNumberOfTilesToBuffer;
    }
    ossim_int32 tempCount = 0;
    // must wait in the correct order
    //
    while(tempCount < theNumberOfTilesToBuffer)
    {
        currentSendRequest++;
        currentSendRequest %= theNumberOfTilesToBuffer;

        errorValue = MPI_Wait(&requests[currentSendRequest], MPI_STATUS_IGNORE);
        ++tempCount;
    }

//   MPI_Waitall(theNumberOfTilesToBuffer,
//               requests,
//               MPI_STATUS_IGNORE);

    delete [] requests;
#  endif
#endif
}
コード例 #14
0
ossimRefPtr<ossimImageData> ossimImageSourceSequencer::getTile(
   ossim_int32 id, ossim_uint32 resLevel)
{
   static const char* MODULE= "ossimImageSourceSequencer::getTile(id, resLevel)";
   if(traceDebug())
   {
      CLOG << "entering.."<<endl;
   }
   if(!theInputConnection)
   {
      if(traceDebug())
      {
         CLOG << "No input connection so returing NULL" << endl;
      }
      return NULL;
   }
   // if we have no tiles try to initialize.
   if(getNumberOfTiles() == 0)
   {
      initialize();
   }
   ossimIpt origin;
   
   if(getTileOrigin(id, origin))
   {
      if(traceDebug())
      {
         CLOG << "returning tile" << endl;
      }
      ossimIrect tRect(origin.x,
                       origin.y,
                       origin.x + theTileSize.x - 1,
                       origin.y + theTileSize.y - 1);
      
      ossimRefPtr<ossimImageData> temp = theInputConnection->getTile(tRect,
                                                                     resLevel);


      theBlankTile->setImageRectangle(tRect);
      
      if(temp.valid())
      {
         if(!temp->getBuf())
         {
            return theBlankTile;
         }
      }
      else
      {
         return theBlankTile;
      }
      return temp;
   }
   else
   {
      if(traceDebug())
      {
         CLOG << "was not able to get an origin for id = " << id << endl;
      }
   }
   if(traceDebug())
   {
      CLOG << "leaving.."<<endl;
   }
   return 0;
}
コード例 #15
0
rspfRefPtr<rspfImageData> rspfMpiMasterOverviewSequencer::getNextTile()
{
   if ( m_dirtyFlag )
   {
      //---
      // If this happens we have a coding error.  Someone started sequencing
      // without initializing us properly.
      //---
      return rspfRefPtr<rspfImageData>();
   }
   
#if RSPF_HAS_MPI

   //---
   // Using mpi.  The slaves will send us tiles to be returned by this method.
   // They will alway be sent in big endian (network byte order) so we must
   // swap back if the scalar type is not 8 bit and the system byte order is
   // little endian. We will use the endian pointer itself as a flag to swap.
   //---
   rspfEndian* endian = 0;
   if (m_imageHandler.valid())
   {
      if (m_imageHandler->getOutputScalarType() != RSPF_UINT8)
      {
         if (rspf::byteOrder() != RSPF_BIG_ENDIAN)
         {
            endian = new rspfEndian();
         }
      }
   }

   int         errorValue;

   // Buffer to receive the data from slaves.
   void* buf = m_tile->getBuf();

   // Total number of tiles to process...
   rspf_uint32 numberOfTiles = getNumberOfTiles();
   
   if(m_currentTileNumber >= numberOfTiles)
   {
      return rspfRefPtr<rspfImageData>();
   }
   
   errorValue = MPI_Recv(buf,
                         m_tile->getSizeInBytes(),
                         MPI_UNSIGNED_CHAR,
                         m_currentTileNumber%(m_numberOfProcessors-1)+1,
                         0,
                         MPI_COMM_WORLD,
                         MPI_STATUS_IGNORE);

   // Data always sent in big endian order.
   if ( endian )
   {
      endian->swap(m_tile->getScalarType(), buf, m_tile->getSize());
   }

   // Get the output rectangle.
   rspfIrect outputRect;
   getOutputTileRectangle(outputRect);

   // Capture the output rectangle.
   m_tile->setImageRectangle(outputRect);

   // Set the tile status.
   m_tile->validate();

   // Increment the tile index.
   ++m_currentTileNumber;

   // cleanup...
   if ( endian )
   {
      delete endian;
      endian = 0;
   }

   return m_tile;

#else

   // Not compiled with mpi.
   return rspfOverviewSequencer::getNextTile();

#endif /* End of #if RSPF_HAS_MPI */

}