bool NFCTileModule::LoadTileData(const NFGUID & self, const int nSceneID)
{
	mxTileData.RemoveElement(self);

	std::string strData;
	if (m_pPlayerRedisModule->LoadPlayerTile(nSceneID, self, strData))
	{
		NFMsg::AckMiningTitle xData;
		if (xData.ParseFromString(strData))
		{
			for (int i = 0; i <  xData.tile_size(); ++i)
			{
				const NFMsg::TileState& xTile = xData.tile(i);
				AddTile(self, xTile.x(), xTile.y(), xTile.opr());
			}

			for (int i = 0; i < xData.building_size(); ++i)
			{
				const NFMsg::TileBuilding& xTile = xData.building(i);
				AddBuilding(self, xTile.x(), xTile.y(), NFINetModule::PBToNF(xTile.guid()), xTile.configid());
			}

			for (int i = 0; i < xData.npc_size(); ++i)
			{
				const NFMsg::TileNPC& xTile = xData.npc(i);
				AddNPC(self, xTile.x(), xTile.y(), NFINetModule::PBToNF(xTile.guid()), xTile.configid());
			}

			return true;
		}
	}
	return false;
}
//==================================================================================================================================
void PlatformerMap::InitializeTiles(PlatformerMapLoadData pmld, GameDirectory2D* gd, HWND hwndPB)
{
	int tile_id = 0;
	int size = m_EngineOptions->TILE_SIZE;
	
	//if (bEditor)
	{
		/*int tileX = PlatformerMap::PixelsToTiles(m_EngineOptions->m_screenWidth / 2 - m_EngineOptions->TILE_SIZE);
		int tileY = PlatformerMap::PixelsToTiles(m_EngineOptions->m_screenHeight / 2 - m_EngineOptions->TILE_SIZE);

		int pixelX = PlatformerMap::TilesToPixels(tileX);
		int pixelY = PlatformerMap::TilesToPixels(tileY);

		XMFLOAT3 pp(pixelX, pixelY, 0);
		AISprite* m_MapSprite = new AISprite(m_D3DSystem);
		m_MapSprite->Initialize(gd->m_required_textures, "player_cover.png", pp, m_EngineOptions->TILE_SIZE, m_EngineOptions->TILE_SIZE, DYNAMIC);
		m_MapSprite->CreateHardBoxSpr(gd->m_required_textures);
		m_MapSprite->Speed() = 2;
		m_MapSprite->PlatformerSprite() = true;
		AddPlayer(m_MapSprite);*/
	}

	int tileX = PlatformerMap::PixelsToTiles(0);
	int tileY = PlatformerMap::PixelsToTiles(0);

	startTile = new PlatformerTile(m_D3DSystem);
	startTile->Initialize(size, false, XMFLOAT3(tileX, tileY, 0));

	tileX = PlatformerMap::PixelsToTiles(m_MapWidth - 1);
	tileY = PlatformerMap::PixelsToTiles(m_MapHeight - 1);

	endTile = new PlatformerTile(m_D3DSystem);
	endTile->Initialize(size, false, XMFLOAT3(tileX, tileY, 0));

	for (int y = 0; y < m_MapHeight; y++)
	{
		for (int x = 0; x < m_MapWidth; x++)
		{
			if (tile_id >= pmld.imageNames.size()) break;

			//if (pmld.exists[XMFLOAT2EXT(x, y)] == 0) continue;
			if (pmld.exists.get(XMFLOAT2EXT(x, y)) == 0) continue;

			string textureFilename = pmld.imageNames[tile_id];
			string animProfileName = pmld.animProfileNames[tile_id];
			int animSpeed = pmld.animSpeeds[tile_id];
			bool hard = pmld.hards[tile_id];

			int test_x = pmld.xs[tile_id];
			int test_y = pmld.ys[tile_id];
			
			//if (test_x == x && test_y == y)
			{
				AddTile(x, y, size, hard, false, gd, textureFilename, animProfileName, animSpeed, size, size);

				tile_id++;
			}
		}
	}
}
uint64_t TileStorage::AddTileOrGetSimiliar(uint8_t* data, float th, int compresslevel)
{
  uint64_t checksum = tilechecksum(data);
  if ( m_tiles.find(checksum) != m_tiles.end() )
  {
    //std::cout << "Debug(AddTileOrGetSimiliar): " << checksum << " already exists" << std::endl;
    return checksum;
    
  }
  if ( compresslevel == COMPRESS_INSANE )
  {
    for ( std::map<uint64_t,uint8_t*>::iterator it = m_tiles.begin(); it != m_tiles.end(); it++ )
    {
      if ( tilediff(data,(*it).second) < th )
      {
	return (*it).first;
	
      }
      
      
    }
  }else if ( compresslevel == COMPRESS_REASONABLE )
  {
    for ( std::list<uint64_t>::iterator it = m_lasttiles.begin(); it != m_lasttiles.end(); it++ )
    {
      if ( tilediff(data,m_tiles[(*it)]) < th )
      {
	return (*it);
	
      }
    }
    
    
  }else if ( compresslevel == COMPRESS_SHITTY )
  {
    //do nothing...
    
  }else if ( compresslevel == COMPRESS_REASONABLE_BESTQUALITY )
  {
    float mindiff = 9999999.0f;
    uint64_t besttile;
    for ( std::list<uint64_t>::iterator it = m_lasttiles.begin(); it != m_lasttiles.end(); it++ )
    {
      float diff = tilediff(data,m_tiles[(*it)]);
      if ( diff < mindiff )
      {
	besttile = (*it);
	mindiff = diff;
	
      }
    }
    if ( mindiff <= th )
      return besttile;
    
    
  }
  return AddTile(data);
}
Beispiel #4
0
///////////////////////////////////////////////////////////////////////////////
// ein neues Objekt zum Baum hinzufügen
bool CSpatialTreeNode::AddTile(CPgrTile *pTile, int nMaxDepth)
{
// If there are subnodes, then consider wether this object
// will fit in them.
	if (nMaxDepth > 1 && m_nSubNodes > 0) {
		for (int i = 0; i < m_nSubNodes; ++i) {
			_ASSERTE(NULL != m_apsSubNode[i]);
			if (m_apsSubNode[i] -> CheckObjectContained(pTile)) 
				return m_apsSubNode[i] -> AddTile(pTile, nMaxDepth - 1);
		}
	}
	else if (nMaxDepth > 1 && 0 == m_nSubNodes)	{
	// Otherwise, consider creating four subnodes if could fit into	
	// them, and adding to the appropriate subnode.
	double adfBoundsMinH1[SPATIALTREE_DIMENSION], adfBoundsMaxH1[SPATIALTREE_DIMENSION];
	double adfBoundsMinH2[SPATIALTREE_DIMENSION], adfBoundsMaxH2[SPATIALTREE_DIMENSION];
	double adfBoundsMin1[SPATIALTREE_DIMENSION], adfBoundsMax1[SPATIALTREE_DIMENSION];
	double adfBoundsMin2[SPATIALTREE_DIMENSION], adfBoundsMax2[SPATIALTREE_DIMENSION];
	double adfBoundsMin3[SPATIALTREE_DIMENSION], adfBoundsMax3[SPATIALTREE_DIMENSION];
	double adfBoundsMin4[SPATIALTREE_DIMENSION], adfBoundsMax4[SPATIALTREE_DIMENSION];

		SplitBounds(m_dBoundsMin, m_dBoundsMax, adfBoundsMinH1, adfBoundsMaxH1, adfBoundsMinH2, adfBoundsMaxH2);
		SplitBounds(adfBoundsMinH1, adfBoundsMaxH1, adfBoundsMin1, adfBoundsMax1, adfBoundsMin2, adfBoundsMax2);
		SplitBounds(adfBoundsMinH2, adfBoundsMaxH2, adfBoundsMin3, adfBoundsMax3, adfBoundsMin4, adfBoundsMax4);

		if (CheckObjectContained(pTile, adfBoundsMin1, adfBoundsMax1) ||
			CheckObjectContained(pTile, adfBoundsMin2, adfBoundsMax2) ||
			CheckObjectContained(pTile, adfBoundsMin3, adfBoundsMax3) ||
			CheckObjectContained(pTile, adfBoundsMin4, adfBoundsMax4))
		{
			m_nSubNodes = 4;
			ATLTRY((
				m_apsSubNode[0] = new CSpatialTreeNode(adfBoundsMin1, adfBoundsMax1),
				m_apsSubNode[1] = new CSpatialTreeNode(adfBoundsMin2, adfBoundsMax2),
				m_apsSubNode[2] = new CSpatialTreeNode(adfBoundsMin3, adfBoundsMax3),
				m_apsSubNode[3] = new CSpatialTreeNode(adfBoundsMin4, adfBoundsMax4)
			));

		// recurse back on this node now that it has subnodes
			return AddTile(pTile, nMaxDepth);
		}
	}

// If none of that worked, just add it to this nodes list.
	++m_nFeatureCount;

CPgrTile * *pFeatureIds = SfRealloc(m_pFeatureIds, sizeof(CPgrTile *) * m_nFeatureCount);

	if (NULL != pFeatureIds) {
		m_pFeatureIds =	pFeatureIds;
		ATLTRY(m_pFeatureIds[m_nFeatureCount - 1] = new CPgrTile(*pTile));
		return true;
	}
	return false;
}
Beispiel #5
0
//------------------------------------------------------------------------------
void
Background2D::load( const QGears::Background2DFile::TileList& tiles )
{
    QGears::Background2DFile::TileList::const_iterator it( tiles.begin() );
    QGears::Background2DFile::TileList::const_iterator it_end( tiles.end() );
    size_t tile_index( 0 );
    while( it != it_end )
    {
        AddTile( *it );
        load( tile_index++, it->animations );
        ++it;
    }
}
Beispiel #6
0
void AddTileToMap(TileMap* tilemap, Rectf tile_rect)
{
    Tile* tile = tilemap->tiles + tilemap->num_tiles;
    tile->aabb = tile_rect;
    ++tilemap->num_tiles;

    if(!AddTile(tilemap->tile_quadtree, &tilemap->quadtree_memory, tile))
    {
        // Didn't add the tile to anything, reuse this for a future allocation
        --tilemap->num_tiles;
        memset(tile, 0, sizeof(Tile));
    }
}
void NFCTileModule::ReqMineTile(const NFSOCK nSockIndex, const int nMsgID, const char * msg, const uint32_t nLen)
{
	CLIENT_MSG_PROCESS( nMsgID, msg, nLen, NFMsg::ReqMiningTitle);

	NFGUID xViewOppnentID = m_pKernelModule->GetPropertyObject(nPlayerID, NFrame::Player::ViewOppnent());
	NFGUID xFightOppnentID = m_pKernelModule->GetPropertyObject(nPlayerID, NFrame::Player::FightOppnent());
	if (!xViewOppnentID.IsNull() || !xFightOppnentID.IsNull())
	{
		return;
	}

	int nX = xMsg.x();
	int nY = xMsg.y();
	int nOpr = xMsg.opr();
	if (1 == nOpr)//add
	{
		////consume diamond
		AddTile(nPlayerID, nX, nY, nOpr);
	}
	else if (0 == nOpr)//rem
	{
		//get money
		AddTile(nPlayerID, nX, nY, nOpr);
	}

	NFMsg::AckMiningTitle xData;
	NFMsg::TileState* pTile = xData.add_tile();
	if (pTile)
	{
		pTile->set_x(nX);
		pTile->set_y(nY);
		pTile->set_opr(nOpr);
	}

	SaveTileData(nPlayerID);
	m_pGameServerNet_ServerModule->SendMsgPBToGate(NFMsg::EGEC_ACK_MINING_TITLE, xData, nPlayerID);
}
//=================================================================================================================
void PlatformerMap::AddTile(GameDirectory2D* gd, int x, int y)
{
	if (!InBounds(x, y)) return;
	
	int size = m_EngineOptions->TILE_SIZE;
	//int sX = PlatformerMap::PixelsToTiles(x);
	//int sY = PlatformerMap::PixelsToTiles(y);

	//int sX = (x + m_Offset.x) / size;
	//int sY = (y + m_Offset.y) / size;

	AddTile(x, y, size, true, true, gd, "PlatformTile.png", "NONE", 0, size, size);
	/*for (int tileY = 0; tileY < m_MapHeight; tileY++)
	{
		for (int tileX = 0; tileX < m_MapWidth; tileX++)
		{
			PlatformerTile* tile = m_TempTiles(tileX, tileY);

			if (tile == NULL) continue;

			//int realTileX = PlatformerMap::TilesToPixels(tileX) + m_Offset.x;
			//int realTileY = PlatformerMap::TilesToPixels(tileY) + m_Offset.y;
			float realTileX = tile->GetPosition().x;
			float realTileY = tile->GetPosition().y;
			
			// Look at the BodyBox for the point x,y to see if
			// it lies inside
			if (tile->BBodyBox().Inside(x, y))
			{
					AddTile(tile->GetPosition().x, tile->GetPosition().y, size, true, true, gd, "PlatformTile.png", "NONE", 0, size, size, false);
					return;
			}
			
			if (x >= realTileX && x <= realTileX + m_EngineOptions->TILE_SIZE)
			{
				if (y >= realTileY && y <= realTileY + m_EngineOptions->TILE_SIZE)
				{
					AddTile(tile->GetPosition().x, tile->GetPosition().y, size, true, true, gd, "PlatformTile.png", "NONE", 0, size, size, false);
					return;
				}
			}
		}
	}*/
}
void Game_2048::GameEndCheck() {
	FindMaxTile();
	if (maxTile == winTile) {
		TCHAR scr_txt[50] = L"You\'ve won!!\nScore: ";
		TCHAR scr[10];
		_itow_s(score, scr, 10);
		wcscat_s(scr_txt, 50, scr);
		MessageBox(0, scr_txt, TEXT("Victory"), MB_OK | MB_ICONINFORMATION | MB_DEFBUTTON1);
	}
	else if (FieldIsFull()) {
		if (MovedTiles() == 0 && AreThereAnyOptions() == 0) {
			TCHAR scr_txt[50] = L"You\'ve lost\nScore: ";
			TCHAR scr[10];
			_itow_s(score, scr, 10);
			wcscat_s(scr_txt, 50, scr);
			MessageBox(0, scr_txt, TEXT("Game over"), MB_OK | MB_ICONSTOP | MB_DEFBUTTON1);
		}
	}
	else if (MovedTiles()) {
		AddTile();
	}
}
Beispiel #10
0
//------------------------------------------------------------------------------
void
Background2D::AddTile(  const QGears::Tile& tile )
{
    // TODO: move depth calculation to flevelBackgroundLoader maybe? and let Backgorund2D only handle 0 <= depth <= 1 or so?
    // maybe just move the < 4095 part to flevel background loader?
    Ogre::Real depth( 0.0001 );
    if( tile.depth >= 1 )
    {
        if( tile.depth < 4095 )
        {
            const Ogre::Matrix4 &cam_projection( CameraManager::getSingleton().GetCurrentCamera()->getProjectionMatrixWithRSDepth() );
            Ogre::Vector4 res( 0, 0, -tile.depth, 1 );
            res = cam_projection * res;
            res /= res.w;
            depth = res.z;
        }
        else
        {
            depth = 0.9999;
        }
    }
    AddTile( tile.destination, tile.width, tile.height, depth, tile.uv, tile.blending );
}
Beispiel #11
0
Level::Level(std::string filename)
{
	entCount = 0;
	actCount = 0;

	selectedTile = NULL;
	targetedTile = NULL;
	
	//load XML file
	std::ifstream inFile;
	inFile.open(filename);

	if(!inFile)
		throw "Could not load level";

	std::string xmlContents;
	std::string line;
	while(std::getline(inFile, line))
		xmlContents += line;

	//Convert string to RapidXML-readable char pointer
	std::vector<char> xmlData = std::vector<char>(xmlContents.begin(), xmlContents.end());
	xmlData.push_back('\0');

	//create parsed document with &XMLDATA[0], which is equialent to char pointer
	rapidxml::xml_document<> doc;
	doc.parse<rapidxml::parse_no_data_nodes>(&xmlData[0]);

	//get root node
	rapidxml::xml_node<>* root = doc.first_node();

	//get level attributes
	int width = atoi(root->first_attribute("width")->value());
	int height = atoi(root->first_attribute("height")->value());

	//resize level
	this->w = width;
	this->h = height;
	SetDimensions(width, height);

	//Load each necessary tileset
	rapidxml::xml_node<>* tileset = root->first_node("tileset", 0, true);
	while(tileset)
	{
		std::string path = tileset->first_attribute("path", 0, true)->value();
		//load tileset
		textureManager.LoadTileset(path);
		//go to next tileset
		tileset = tileset->next_sibling("tileset", 0, true);
	}

	//Create selector sprite
	selectorSprite.setTexture(textureManager.GetTexture(4), true);

	//Create hover sprite
	hoverSprite.setTexture(textureManager.GetTexture(6), true);

	//Create grid sprite
	gridSprite.setTexture(textureManager.GetTexture(5), true);

	//Create move sprite
	moveSprite.setTexture(textureManager.GetTexture(7), true);

	//Create no-move sprite
	noMoveSprite.setTexture(textureManager.GetTexture(8), true);

	//Create target sprite
	targetSprite.setTexture(textureManager.GetTexture(9), true);

	//go through each tile
	rapidxml::xml_node<>* tile = root->first_node("tile", 0, true);
	while(tile)
	{
		//get all attributes
		int x = atoi(tile->first_attribute("x", 0, true)->value());
		int y = atoi(tile->first_attribute("y", 0, true)->value());
		int baseid = atoi(tile->first_attribute("baseid", 0, true)->value());

		//check if tile is a wall or otherwise impassible
		bool wall = baseid == 1;

		//create tile and add to level
		Tile* newTile = new Tile(textureManager.GetTexture(baseid), wall, x, y);
		AddTile(x, y, newTile);

		//next tile
		tile = tile->next_sibling();
	}

	//load actors
	rapidxml::xml_node<>* actorXml = root->first_node("actor", 0, true);
	for( ; actorXml; actorXml = actorXml->next_sibling("actor", 0, true))
	{
		//****************
		//Begin XML readin
		//****************

		//get XML filename
		std::string actorFilename = actorXml->first_attribute("path", 0, true)->value();
		//load XML file
		std::ifstream actorInFile;
		actorInFile.open(actorFilename);

		if(!actorInFile)
			throw "Could not load actor";

		std::string actorLine;
		std::string actorXmlContents;
		while(std::getline(actorInFile, actorLine))
			actorXmlContents += actorLine;

		//Convert string to RapidXML-readable char pointer
		std::vector<char> actorXmlData = std::vector<char>(actorXmlContents.begin(), actorXmlContents.end());
		actorXmlData.push_back('\0');

		//create parsed document with &XMLDATA[0], which is equialent to char pointer
		rapidxml::xml_document<> actorDoc;
		actorDoc.parse<rapidxml::parse_no_data_nodes>(&actorXmlData[0]);

		//get root node
		rapidxml::xml_node<>* actorRoot = actorDoc.first_node("actor", 0, true);

		//****************
		//End XML readin
		//****************

		if(actorRoot)
			AddActor(actorRoot);
	}

	//load entities
	rapidxml::xml_node<>* entityXml = root->first_node("entity", 0, true);
	for( ; entityXml; entityXml = entityXml->next_sibling("entity", 0, true))
	{
		//****************
		//Begin XML readin
		//****************

		//get XML filename
		std::string entityFilename = entityXml->first_attribute("path", 0, true)->value();
		//load XML file
		std::ifstream entityInFile;
		entityInFile.open(entityFilename);

		if(!entityInFile)
			throw "Could not load entity";

		std::string entityLine;
		std::string entityXmlContents;
		while(std::getline(entityInFile, entityLine))
			entityXmlContents += entityLine;

		//Convert string to RapidXML-readable char pointer
		std::vector<char> entityXmlData = std::vector<char>(entityXmlContents.begin(), entityXmlContents.end());
		entityXmlData.push_back('\0');

		//create parsed document with &XMLDATA[0], which is equialent to char pointer
		rapidxml::xml_document<> entityDoc;
		entityDoc.parse<rapidxml::parse_no_data_nodes>(&entityXmlData[0]);

		//get root node
		rapidxml::xml_node<>* entityRoot = entityDoc.first_node("entity", 0, true);

		//****************
		//End XML readin
		//****************
		if(entityRoot)
			AddEntity(entityRoot);
	}
}
Beispiel #12
0
//------------------------------------------------------------------------------
void
Background2D::AddTile( const Ogre::Vector2& destination, const int width, const int height, const float depth, const Ogre::Vector4& uv, const Blending blending )
{
    AddTile( destination.x, destination.y, width, height, depth, uv.x, uv.y, uv.z, uv.w, blending );
}
Beispiel #13
0
// ----------------------------------------------------------------
//	SampleData
// ----------------------------------------------------------------
void CMapInfo::SampleData()
{
	const UINT COLUMN = 24;
	const UINT ROW = 16;

	m_MapId = L"map_village";

	SetTileSize( 128, 128 );

	AddTile( L"map_village_0000_1.png" );	// 0
	AddTile( L"map_village_0000_2.png" );
	AddTile( L"map_village_0000_3.png" );
	AddTile( L"map_village_0000_4.png" );

	AddTile( L"map_village_0001_1.png" );	// 4
	AddTile( L"map_village_0001_2.png" );
	AddTile( L"map_village_0001_3.png" );
	AddTile( L"map_village_0001_4.png" );

	AddTile( L"map_village_0010_1.png" );	// 8
	AddTile( L"map_village_0010_2.png" );
	AddTile( L"map_village_0010_3.png" );
	AddTile( L"map_village_0010_4.png" );

	AddTile( L"map_village_0011_1.png" );	// 12
	AddTile( L"map_village_0011_2.png" );
	AddTile( L"map_village_0011_3.png" );
	AddTile( L"map_village_0011_4.png" );

	AddTile( L"map_village_0100_1.png" );	// 16
	AddTile( L"map_village_0100_2.png" );
	AddTile( L"map_village_0100_3.png" );
	AddTile( L"map_village_0100_4.png" );

	AddTile( L"map_village_0101_1.png" );	// 20
	AddTile( L"map_village_0101_2.png" );
	AddTile( L"map_village_0101_3.png" );
	AddTile( L"map_village_0101_4.png" );

	AddTile( L"map_village_0111_1.png" );	// 24
	AddTile( L"map_village_0111_2.png" );
	AddTile( L"map_village_0111_3.png" );
	AddTile( L"map_village_0111_4.png" );

	AddTile( L"map_village_1000_1.png" );	// 28
	AddTile( L"map_village_1000_2.png" );
	AddTile( L"map_village_1000_3.png" );
	AddTile( L"map_village_1000_4.png" );

	AddTile( L"map_village_1010_1.png" );	// 32
	AddTile( L"map_village_1010_2.png" );
	AddTile( L"map_village_1010_3.png" );
	AddTile( L"map_village_1010_4.png" );

	AddTile( L"map_village_1011_1.png" );	// 36
	AddTile( L"map_village_1011_2.png" );
	AddTile( L"map_village_1011_3.png" );
	AddTile( L"map_village_1011_4.png" );

	AddTile( L"map_village_1100_1.png" );	// 40
	AddTile( L"map_village_1100_2.png" );
	AddTile( L"map_village_1100_3.png" );
	AddTile( L"map_village_1100_4.png" );

	AddTile( L"map_village_1101_1.png" );	// 44
	AddTile( L"map_village_1101_2.png" );
	AddTile( L"map_village_1101_3.png" );
	AddTile( L"map_village_1101_4.png" );

	AddTile( L"map_village_1110_1.png" );	// 48
	AddTile( L"map_village_1110_2.png" );
	AddTile( L"map_village_1110_3.png" );
	AddTile( L"map_village_1110_4.png" );

	AddTile( L"map_village_1111_1.png" );	// 52
	AddTile( L"map_village_1111_2.png" );
	AddTile( L"map_village_1111_3.png" );
	AddTile( L"map_village_1111_4.png" );

	AddTile( L"map_tree_0011.png" );	// 56
	AddTile( L"map_tree_0101.png" );	// 57
	AddTile( L"map_tree_0111.png" );	// 58
	AddTile( L"map_tree_1010.png" );	// 59
	AddTile( L"map_tree_1011.png" );	// 60
	AddTile( L"map_tree_1100.png" );	// 61
	AddTile( L"map_tree_1101.png" );	// 62
	AddTile( L"map_tree_1110.png" );	// 63
	AddTile( L"map_tree_1111.png" );	// 64

	CreateMapData( COLUMN, ROW );

	UINT fildTileNo[ROW][COLUMN] = {
		{ 0, 0, 0, 0, 25, 37, 11, 16, 40, 28, 7, 24, 39, 12, 14, 15, 25, 33, 16, 42, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 53, 49, 28, 7, 10, 2, 22, 55, 48, 42, 42, 42, 47, 32, 7, 15, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 48, 28, 1, 23, 32, 0, 21, 50, 28, 0, 7, 8, 18, 30, 23, 55, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 38, 15, 9, 17, 28, 1, 21, 34, 0, 0, 21, 37, 10, 2, 19, 47, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 51, 41, 29, 2, 6, 15, 26, 34, 6, 11, 21, 49, 29, 1, 3, 21, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 38, 12, 14, 10, 22, 51, 43, 28, 16, 31, 18, 31, 6, 15, 9, 20, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 42, 41, 46, 35, 21, 33, 1, 2, 1, 0, 0, 5, 26, 48, 31, 19, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 4, 9, 22, 39, 24, 35, 5, 9, 0, 1, 3, 17, 45, 33, 5, 9, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 19, 28, 17, 43, 42, 28, 20, 32, 0, 5, 13, 12, 24, 36, 25, 39, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 8, 5, 10, 7, 8, 3, 22, 39, 9, 23, 51, 41, 46, 55, 53, 52, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 33, 23, 37, 26, 39, 8, 19, 43, 28, 16, 29, 0, 17, 46, 53, 55, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 39, 24, 48, 46, 50, 31, 1, 5, 13, 14, 12, 15, 12, 27, 54, 50, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 43, 42, 31, 17, 28, 4, 14, 25, 48, 46, 50, 44, 54, 51, 43, 30, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 9, 3, 3, 0, 1, 19, 41, 43, 30, 18, 31, 18, 42, 30, 3, 4, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 28, 1, 1, 3, 5, 15, 14, 14, 10, 5, 11, 2, 2, 5, 15, 27, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 11, 7, 15, 12, 27, 51, 42, 42, 31, 17, 31, 0, 4, 26, 51, 43, 0, 0, 0, 0 }
	};

	UINT treeTileNo[ROW][COLUMN] = {
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 63, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 60, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 58, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }
	};

	UINT fildMovement[ROW][COLUMN] = {
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF }
	};

	for ( UINT row = 0; row < ROW; ++row )
	{
		for ( UINT col = 0; col < COLUMN; ++col )
		{
			m_Maps[0]->m_Tiles[row * COLUMN + col].m_TileNo		= fildTileNo[row][col] + treeTileNo[row][col] * 128;
			m_Maps[0]->m_Tiles[row * COLUMN + col].m_Movement	= fildMovement[row][col];
		}
	}

	for ( UINT row = 0; row < ROW; ++row )
	{
		printf( "{" );
		for ( UINT col = 0; col < COLUMN; ++col )
		{
			if ( col != 0 )
				printf(",");

			printf( " %d", m_Maps[0]->m_Tiles[row * COLUMN + col].m_TileNo );
		}
		printf( " },\n" );
	}

}
Beispiel #14
0
// Returns true if it was added to at least one quadtree, false if you are trying to add out of bounds
static bool AddTile(TileGroup* tile_group, MemoryArena* arena, Tile* tile)
{
    if(!Contains(tile_group, tile->aabb))
    {
        // didn't add here, return false;
        return false;
    }

    if(IsLeaf(tile_group))
    {
        if(tile_group->contained_colliders < MAX_LEAF_SIZE)
        {
            tile_group->colliders[tile_group->contained_colliders] = tile;
            ++tile_group->contained_colliders;
        }
        else
        {
            // Split the node into 4
            Tile* temp_colliders[MAX_LEAF_SIZE];
            memcpy(temp_colliders, tile_group->colliders, sizeof(temp_colliders));

            tile_group->child_nodes = PushArray(arena, TileGroup, QUADTREE_CHILDREN);
            tile_group->is_parent = true;

            uint16 new_depth = tile_group->depth + 1;
            TileGroup* new_node = tile_group->child_nodes;

            Rectf r = tile_group->aabb;
            float half_width = r.w / 2.f;
            float half_height = r.h / 2.f;

            Rectf divided_rects[QUADTREE_CHILDREN] = {
                { r.x              , r.y              , half_width, half_height },
                { r.x + half_height, r.y              , half_width, half_height },
                { r.x              , r.y + half_height, half_width, half_height },
                { r.x + half_height, r.y + half_height, half_width, half_height },
            };

            for(uint32 i = 0; i < QUADTREE_CHILDREN; ++i, ++new_node)
            {
                new_node->aabb  = divided_rects[i];
                new_node->depth = new_depth;
                new_node->is_parent = false;
            }

            // Add the original tile that was passed in.
            AddTile(tile_group, arena, tile);

            // re-add the old pointers to the new child nodes.
            for(uint32 i = 0; i < MAX_LEAF_SIZE; ++i)
            {
                AddTile(tile_group, arena, temp_colliders[i]);
            }
        }
    }
    else
    { // Not a leaf, recurse
        TileGroup* child = tile_group->child_nodes;
        for(uint32 j = 0; j < QUADTREE_CHILDREN; ++j, ++child)
        {
            if(Contains(child, tile->aabb))
            {
                AddTile(child, arena, tile);
            }
        }
    }

    // Either added here or in a child
    return true;
}