Beispiel #1
0
void MapBackground::CreateMapTileImage(MapTile* pMapTile, void* gResult, uint32 gResultLen, bool isJpg)
{
	if (!IsTileVisible(pMapTile))
	{
		return;
	}
	CIwImage image;
	if (!isJpg)
	{
		//pMapTile->pTexture = g_pNotFoundTexture;
		s3eFile* tempfile = s3eFileOpenFromMemory((void*)gResult, gResultLen);
		image.ReadFile(tempfile);

		//image.LoadFromFile("tiles/r0302322130033033130.png");

		if (image.GetWidth())
		{
			pMapTile->pTexture = new CIwTexture;
			pMapTile->pTexture->CopyFromImage(&image);
			pMapTile->pTexture->Upload();
		}

		s3eFileClose(tempfile);
	}
	else
	{
		JPEGImage(gResult, gResultLen, image);
		pMapTile->pTexture = new CIwTexture;
		pMapTile->pTexture->CopyFromImage(&image);
		pMapTile->pTexture->Upload();
	}
}
Beispiel #2
0
/**
**  Remove wood from the map.
**
**  @param type  TileType to clear
**  @param pos   Map tile-position.
*/
void CMap::ClearTile(unsigned short type, const Vec2i &pos)
{
	int removedtile;
	int flags;

	unsigned int index = getIndex(pos);
	CMapField &mf = *this->Field(index);

	// Select Table to lookup
	switch (type) {
		case MapFieldForest:
			removedtile = this->Tileset.RemovedTree;
			flags = (MapFieldForest | MapFieldUnpassable);
			break;
		case MapFieldRocks:
			removedtile = this->Tileset.RemovedRock;
			flags = (MapFieldRocks | MapFieldUnpassable);
			break;
		default:
			removedtile = flags = 0;
	}
	mf.Tile = removedtile;
	mf.Flags &= ~flags;
	mf.Value = 0;

	UI.Minimap.UpdateXY(pos);
	FixNeighbors(type, 0, pos);

	//maybe isExplored
	if (IsTileVisible(*ThisPlayer, index) > 0) {
		UI.Minimap.UpdateSeenXY(pos);
		MarkSeenTile(pos);
	}
}
Beispiel #3
0
MapTile* MapBackground::GetNextDownload(MapTile* pCurrent)
{
	std::list<MapTile*>::iterator iter = gVectorImageUrls.begin();

	for (int i = 0; i < 2; ++i)
	{
		bool bFirstPass = (i == 0);
		while (iter != gVectorImageUrls.end())
		{
			MapTile* pTile = *iter;
			
			if ((!pTile->pTexture || pTile->pTexture == g_pLoadingTexture) && pTile != pCurrent)
			{
				bool isVisible = IsTileVisible(pTile);

				if (!bFirstPass || isVisible)
				{
					return pTile;
				}
			}

			iter++;
		}
	}
	return NULL;
}
Beispiel #4
0
void Chat::PostSimpleText(const std::string& str, size_t tile_id)
{
    if (!IsTileVisible(tile_id))
        return;

    SetCursorAtEnd();

    tb_->insertHtml(QString::fromStdString(str + "<br>"));

    SetCursorAtEnd();
}
Beispiel #5
0
void RenderCache::ClearQueueForDisplayModel(DisplayModel* dm, int pageNo, TilePosition* tile) {
    ScopedCritSec scope(&requestAccess);
    int reqCount = requestCount;
    int curPos = 0;
    for (int i = 0; i < reqCount; i++) {
        PageRenderRequest* req = &(requests[i]);
        bool shouldRemove = req->dm == dm && (pageNo == INVALID_PAGE_NO || req->pageNo == pageNo) &&
                            (!tile || req->tile.res != tile->res || !IsTileVisible(dm, req->pageNo, *tile, 0.5));
        if (i != curPos)
            requests[curPos] = requests[i];
        if (shouldRemove) {
            if (req->renderCb)
                req->renderCb->Callback();
            requestCount--;
        } else
            curPos++;
    }
}
/* Free all bitmaps in the cache that are of a specific page (or all pages
   of the given DisplayModel, or even all invisible pages). Returns TRUE if freed
   at least one item. */
bool RenderCache::FreePage(DisplayModel *dm, int pageNo, TilePosition *tile)
{
    ScopedCritSec scope(&cacheAccess);
    int cacheCountTmp = cacheCount;
    bool freedSomething = false;
    int curPos = 0;

    for (int i = 0; i < cacheCountTmp; i++) {
        BitmapCacheEntry* entry = cache[i];
        bool shouldFree;
        if (dm && pageNo != INVALID_PAGE_NO) {
            // a specific page
            shouldFree = (entry->dm == dm) && (entry->pageNo == pageNo);
            if (tile)
                // a given tile of the page or all tiles not rendered at a given resolution
                // (and at resolution 0 for quick zoom previews)
                shouldFree = shouldFree && (entry->tile == *tile ||
                    tile->row == (USHORT)-1 && entry->tile.res > 0 && entry->tile.res != tile->res);
        } else if (dm) {
            // all pages of this DisplayModel
            shouldFree = (cache[i]->dm == dm);
        } else {
            // all invisible pages resp. page tiles
            shouldFree = !entry->dm->PageVisibleNearby(entry->pageNo);
            if (!shouldFree && entry->tile.res > 1)
                shouldFree = !IsTileVisible(entry->dm, entry->pageNo, entry->rotation,
                                            entry->zoom, entry->tile, 2.0);
        }

        if (shouldFree) {
            freedSomething = true;
            DropCacheEntry(entry);
            cache[i] = NULL;
            cacheCount--;
        }

        if (curPos != i)
            cache[curPos] = cache[i];
        if (!shouldFree)
            curPos++;
    }
    return freedSomething;
}
Beispiel #7
0
void Chat::PostWords(const std::string& who, const std::string& text, size_t tile_id)
{
    if (!IsTileVisible(tile_id))
        return;

    SetCursorAtEnd();

    QString q_who = QString::fromStdString(who).toHtmlEscaped();
    QString q_text = QString::fromStdString(text).toHtmlEscaped();

    tb_->insertHtml
        (
           "<b>"
         + q_who
         + "</b>: "
         + "<span>"
         + q_text
         + "</span><br>");

    SetCursorAtEnd();
}
Beispiel #8
0
void MapBackground::CreateMapTileImage2(MapTile* pMapTile, char* szPath, bool isJpg)
{
	if (!IsTileVisible(pMapTile))
	{
		return;
	}
	CIwImage image;
	if (!isJpg)
	{
		image.LoadFromFile(szPath);
		if (image.GetWidth())
		{
			pMapTile->pTexture = new CIwTexture;
			pMapTile->pTexture->CopyFromImage(&image);
			pMapTile->pTexture->Upload();
		}
	}
	else
	{
		s3eFile* pFile = s3eFileOpen(szPath, "r");

		if (pFile)
		{
			uint32 gResultLen = s3eFileGetSize(pFile);
			void* gResult = (void*)s3eMalloc(gResultLen + 1);

			uint32 test = s3eFileRead(gResult, sizeof(char), gResultLen, pFile);
			gResultLen = test;
			s3eFileClose(pFile);

			JPEGImage(gResult, gResultLen, image);
			pMapTile->pTexture = new CIwTexture;
			pMapTile->pTexture->CopyFromImage(&image);
			pMapTile->pTexture->Upload();

			delete gResult;
		}
	}
}
Beispiel #9
0
void Chat::PostDamage(const std::string& by, const std::string& who, const std::string& object, size_t tile_id)
{
    if (!IsTileVisible(tile_id))
        return;

    SetCursorAtEnd();

    QString q_by = QString::fromStdString(by).toHtmlEscaped();
    QString q_who = QString::fromStdString(who).toHtmlEscaped();
    QString q_object = QString::fromStdString(object).toHtmlEscaped();

    tb_->insertHtml
        (
           "<font color=\"red\">"
         + q_who
         + " is attacked by "
         + q_by
         + " with "
         + q_object
         + "</font><br>");

    SetCursorAtEnd();
}
Beispiel #10
0
/**
**  Correct the seen wood field, depending on the surrounding.
**
**  @param type  type fo tile to update
**  @param seen  1 if updating seen value, 0 for real
**  @param pos   Map tile-position.
*/
void CMap::FixTile(unsigned short type, int seen, const Vec2i &pos)
{
	//  Outside of map or no wood.
	if (!Info.IsPointOnMap(pos)) {
		return;
	}
	unsigned int index = getIndex(pos);
	CMapField *mf = this->Field(index);

	if (seen && !Tileset.IsSeenTile(type, mf->SeenTile)) {
		return;
	} else if (!seen && !(mf->Flags & type)) {
		return;
	}

	// Select Table to lookup
	int *lookuptable;
	int removedtile;
	int flags;
	switch (type) {
		case MapFieldForest:
			lookuptable = this->Tileset.WoodTable;
			removedtile = this->Tileset.RemovedTree;
			flags = (MapFieldForest | MapFieldUnpassable);
			break;
		case MapFieldRocks:
			lookuptable = this->Tileset.RockTable;
			removedtile = this->Tileset.RemovedRock;
			flags = (MapFieldRocks | MapFieldUnpassable);
			break;
		default:
			lookuptable = NULL;
			removedtile = 0;
			flags = 0;
	}
	//
	//  Find out what each tile has with respect to wood, or grass.
	//
	int tile = 0;
	int ttup;
	int ttdown;
	int ttleft;
	int ttright;

	if (pos.y - 1 < 0) {
		ttup = 15; //Assign trees in all directions
	} else {
		CMapField *new_mf = (mf - this->Info.MapWidth);
		if (seen) {
			ttup = this->Tileset.MixedLookupTable[new_mf->SeenTile];
		} else {
			ttup = this->Tileset.MixedLookupTable[new_mf->Tile];
		}
	}
	if (pos.x + 1 >= this->Info.MapWidth) {
		ttright = 15; //Assign trees in all directions
	} else {
		CMapField *new_mf = (mf + 1);
		if (seen) {
			ttright = this->Tileset.MixedLookupTable[new_mf->SeenTile];
		} else {
			ttright = this->Tileset.MixedLookupTable[new_mf->Tile];
		}
	}
	if (pos.y + 1 >= this->Info.MapHeight) {
		ttdown = 15; //Assign trees in all directions
	} else {
		CMapField *new_mf = (mf + this->Info.MapWidth);
		if (seen) {
			ttdown = this->Tileset.MixedLookupTable[new_mf->SeenTile];
		} else {
			ttdown = this->Tileset.MixedLookupTable[new_mf->Tile];
		}
	}
	if (pos.x - 1 < 0) {
		ttleft = 15; //Assign trees in all directions
	} else {
		CMapField *new_mf = (mf - 1);
		if (seen) {
			ttleft = this->Tileset.MixedLookupTable[new_mf->SeenTile];
		} else {
			ttleft = this->Tileset.MixedLookupTable[new_mf->Tile];
		}
	}

	//
	//  Check each of the corners to ensure it has both connecting
	//  ?**?
	//  *mm*
	//  *mm*
	//  ?**?
	//  *
	//   *  type asterixs must match for wood to be present

	tile += ((ttup & 0x01) && (ttleft & 0x04)) * 8;
	tile += ((ttup & 0x02) && (ttright & 0x08)) * 4;
	tile += ((ttright & 0x01) && (ttdown & 0x04)) * 2;
	tile += ((ttleft & 0x02) && (ttdown & 0x08)) * 1;

	//Test if we have top tree, or bottom tree, they are special
	if ((ttdown & 0x10) && 1) {
		tile |= ((ttleft & 0x06) && 1) * 1;
		tile |= ((ttright & 0x09) && 1) * 2;
	}

	if ((ttup & 0x20) && 1) {
		tile |= ((ttleft & 0x06) && 1) * 8;
		tile |= ((ttright & 0x09) && 1) * 4;
	}

	tile = lookuptable[tile];

	//If tile is -1, then we should check if we are to draw just one tree
	//Check for tile about, or below or both...
	if (tile == -1) {
		tile = 16;
		tile += ((ttup & 0x01) || (ttup & 0x02)) * 1;
		tile += ((ttdown & 0x04) || (ttdown & 0x08)) * 2;
		tile = lookuptable[tile];
	}

	//Update seen tile.
	if (tile == -1) { // No valid wood remove it.
		if (seen) {
			mf->SeenTile = removedtile;
			this->FixNeighbors(type, seen, pos);
		} else {
			mf->Tile = removedtile;
			mf->Flags &= ~flags;
			mf->Value = 0;
			UI.Minimap.UpdateXY(pos);
		}
	} else if (seen && this->Tileset.MixedLookupTable[mf->SeenTile] ==
			   this->Tileset.MixedLookupTable[tile]) { //Same Type
		return;
	} else {
		if (seen) {
			mf->SeenTile = tile;
		} else {
			mf->Tile = tile;
		}
	}

	//maybe isExplored
	if (IsTileVisible(*ThisPlayer, index) > 0) {
		UI.Minimap.UpdateSeenXY(pos);
		if (!seen) {
			MarkSeenTile(pos);
		}
	}
}
Beispiel #11
0
void PlaySoundIfVisible(const std::string& name, size_t tile_id)
{
    if (IsTileVisible(tile_id))
        PlaySound(name);
}