コード例 #1
0
ファイル: Mesh.cpp プロジェクト: patrickmortensen/theEngine
void Mesh::LoadTextureFromFile(char* filepath)
{
	RemoveTexture();
	if (!filepath)
		return;
	HRESULT result;
	result = D3DXCreateTextureFromFile(gfx.GetDevice(), filepath, &tex);
	
	int fileLen = 0;
	for (; filepath[fileLen] != '\0'; fileLen++);

	char* temp = new char[fileLen + 1];
	for (int i = 0; i < fileLen + 1; i++){ temp[i] = filepath[i]; }

	if (TextureFilePath)
		delete TextureFilePath;
	
	TextureFilePath = new char[fileLen + 1];
	for (int i = 0; i < fileLen + 1; i++)
	{
		TextureFilePath[i] = temp[i];
	}

	if (result != D3D_OK)
		MessageBox(NULL, "Failed To Create Texture \n(function: Mesh::LoadTextureFromFile File: Mesh.cpp)",
		"Error", MB_OK | MB_ICONEXCLAMATION);
}
コード例 #2
0
ファイル: GameSettings.cpp プロジェクト: Deflect57/Turnz
void Update_restext(void)
{
    RemoveTexture(restext, "Options: Resolutions");
    Unstack_Texture(Op_TStack, restext);
    restext = LoadText(Resolutions[Sel_Resolution], 26, "Options: Resolutions");
    Stack_Text(Op_TStack, restext, 950, 400);
}
コード例 #3
0
// Purge any textures whos last usage was over 5 seconds ago
void CTextureManager::PurgeOldTextures()
{
    if (m_pCacheTxtrList == NULL)
        return;
    
    if (g_bUseSetTextureMem)
        return;

    static const uint32 dwFramesToKill = 5*30;          // 5 secs at 30 fps
    static const uint32 dwFramesToDelete = 30*30;       // 30 secs at 30 fps
    
    for ( uint32 i = 0; i < m_numOfCachedTxtrList; i++ )
    {
        TxtrCacheEntry * pEntry;
        TxtrCacheEntry * pNext;
        
        pEntry = m_pCacheTxtrList[i];
        while (pEntry)
        {
            pNext = pEntry->pNext;
            
            if ( status.gDlistCount - pEntry->FrameLastUsed > dwFramesToKill && !TCacheEntryIsLoaded(pEntry))
            {
                RemoveTexture(pEntry);
            }
            pEntry = pNext;
        }
    }
    
    
    // Remove any old textures that haven't been recycled in 1 minute or so
    // Normally these would be reused
    TxtrCacheEntry * pPrev;
    TxtrCacheEntry * pCurr;
    TxtrCacheEntry * pNext;
    
    
    pPrev = NULL;
    pCurr = m_pHead;
    
    while (pCurr)
    {
        pNext = pCurr->pNext;
        
        if ( status.gDlistCount - pCurr->FrameLastUsed > dwFramesToDelete && !TCacheEntryIsLoaded(pCurr) )
        {
            if (pPrev != NULL) pPrev->pNext        = pCurr->pNext;
            else               m_pHead = pCurr->pNext;
            
            delete pCurr;
            pCurr = pNext;  
        }
        else
        {
            pPrev = pCurr;
            pCurr = pNext;
        }
    }
}
コード例 #4
0
ファイル: MainMenu.cpp プロジェクト: Deflect57/Turnz
void MM_Unload(void)
{
    RemoveTexture(bg_MainMenu, "Main Menu: Background");

    RemoveTexture(MM_Btx[0], "Main Menu: OPTIONS text"); //Button 1
    RemoveTexture(MM_Btx[1], "Main Menu: EDITOR text"); //Button 2
    RemoveTexture(MM_Btx[2], "Main Menu: PLAY text"); //Button 3


    Clear_Tx_Stack(MM_Stack);
    Clear_Tx_Stack(MM_TStack);
    Clear_BStack(MM_BStack);

    Unstack_Stack(MM_Stack);
    Unstack_TStack(MM_TStack);
    Unstack_BStack(MM_BStack);


    Exit_Sequence_Remove(MM_Unload);
}
コード例 #5
0
ファイル: GameSettings.cpp プロジェクト: Deflect57/Turnz
void Op_Unload(void)
{
    RemoveTexture(T_Resolution, "Options: Resolution");
    RemoveTexture(bg_Options, "Options Background");
    RemoveTexture(restext, "Options: Resolutions");

    RemoveTexture(GS_Words[0], "GS: Text");
    RemoveTexture(GS_Words[1], "GS: Text");


    Exit_Sequence.erase(Exit_Sequence.end() - 1);

    Clear_BStack(Op_BStack);
    Clear_Tx_Stack(Op_Stack);
    Clear_Tx_Stack(Op_TStack);

    Unstack_Stack(Op_Stack);
    Unstack_BStack(Op_BStack);
    Unstack_TStack(Op_TStack);
    return;
}
コード例 #6
0
void TextureHelper::CleanAllPackImages()
{
	RemoveTexture("logo.png");
	RemoveTexture("utils.png");
	RemoveTexture("dirt.png");
	RemoveTexture("glass.png");
	RemoveTexture("terrain_medium.png");
	RemoveTexture("blue.png");
	RemoveTexture("sky.png");
	RemoveTexture("sun.png");
	RemoveTexture("moon.png");

	GetTextureFromZip("logo.png");
	GetTextureFromZip("utils.png");
	GetTextureFromZip("dirt.png");
	GetTextureFromZip("glass.png");
	GetTextureFromZip("terrain_medium.png");
	GetTextureFromZip("blue.png");
	GetTextureFromZip("sky.png");
	GetTextureFromZip("sun.png");
	GetTextureFromZip("moon.png");
}
コード例 #7
0
TxtrCacheEntry * CTextureManager::CreateNewCacheEntry(uint32 dwAddr, uint32 dwWidth, uint32 dwHeight)
{
    TxtrCacheEntry * pEntry = NULL;

    if (g_bUseSetTextureMem)
    {
        uint32 widthToCreate = dwWidth;
        uint32 heightToCreate = dwHeight;
        unsigned int freeUpSize = (widthToCreate * heightToCreate * 4) + g_amountToFree;

        // make sure there is enough room for the new texture by deleting old textures
        while ((m_currentTextureMemUsage + freeUpSize) > g_maxTextureMemUsage && m_pOldestTexture != NULL)
        {
            TxtrCacheEntry *nextYoungest = m_pOldestTexture->pNextYoungest;

            RemoveTexture(m_pOldestTexture);

            m_pOldestTexture = nextYoungest;

        //printf("Freeing Texture\n");
        }

        m_currentTextureMemUsage += widthToCreate * heightToCreate * 4;
    }
    else
    {
    // Find a used texture
    pEntry = ReviveTexture(dwWidth, dwHeight);
    }

    if (pEntry == NULL || g_bUseSetTextureMem)
    {
        // Couldn't find on - recreate!
        pEntry = new TxtrCacheEntry;
        if (pEntry == NULL)
        {
            _VIDEO_DisplayTemporaryMessage("Error to create an texture entry");
            return NULL;
        }

        pEntry->pTexture = CDeviceBuilder::GetBuilder()->CreateTexture(dwWidth, dwHeight);
        if (pEntry->pTexture == NULL || pEntry->pTexture->GetTexture() == NULL)
        {
            _VIDEO_DisplayTemporaryMessage("Error to create an texture");
            TRACE2("Warning, unable to create %d x %d texture!", dwWidth, dwHeight);
        }
        else
        {
            pEntry->pTexture->m_bScaledS = false;
            pEntry->pTexture->m_bScaledT = false;
        }
    }
    
    // Initialize
    pEntry->ti.Address = dwAddr;
    pEntry->pNext = NULL;
    pEntry->pNextYoungest = NULL;
    pEntry->pLastYoungest = NULL;
    pEntry->dwUses = 0;
    pEntry->dwTimeLastUsed = status.gRDPTime;
    pEntry->dwCRC = 0;
    pEntry->FrameLastUsed = status.gDlistCount;
    pEntry->FrameLastUpdated = 0;
    pEntry->lastEntry = NULL;
    pEntry->bExternalTxtrChecked = false;
    pEntry->maxCI = -1;

    // Add to the hash table
    AddTexture(pEntry);
    return pEntry;  
}
コード例 #8
0
ファイル: texture.cpp プロジェクト: endoalir/ValyriaTear
bool VariableTexSheet::InsertTexture(BaseTexture *img)
{
    if(img == nullptr) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "nullptr pointer was given as function argument" << std::endl;
        return false;
    }

    // Don't allow insertions into a texture sheet containing a texture larger than 512x512.
    // Texture sheets with this property may only be used by one texture at a time
    if(_block_width > 32 || _block_height > 32) {  // 32 blocks == 512 pixels
        if(_blocks[0].free_image == false)
            return false;
    }

    // Attempt to find an open region in the texture sheet to fit this texture
    int32 block_x = -1, block_y = -1;
    int32 w = (img->width + 15) / 16;
    int32 h = (img->height + 15) / 16;

    // This is a brute force algorithm to try and find space to allocate the texture.
    // If this becomes a bottleneck, we may wish to use a more intellegent algorithm here.
    bool continue_search = true;
    for(int32 y = 0; y < _block_height - h + 1 && continue_search; y++) {
        for(int32 x = 0; x < _block_width - w + 1; x++) {
            int32 furthest_blocker = -1;

            bool continue_neighbor_search = true;
            for(int32 dy = 0; dy < h && continue_neighbor_search; dy++) {
                for(int32 dx = 0; dx < w; dx++) {
                    if(_blocks[(x + dx) + ((y + dy) * _block_width)].free_image == false) {
                        furthest_blocker = x + dx;
                        continue_neighbor_search = false;
                        break;
                    }
                }
            }

            if(furthest_blocker == -1) {
                block_x = x;
                block_y = y;
                continue_search = false;
                break;
            }
        }
    }

    // If either of these conditions is true, it means we were unable to allocate enough space to insert this texture
    if(block_x == -1 || block_y == -1)
        return false;

    // Go through each block that is to be occupied by the new texture and set its properties
    for(int32 y = block_y; y < block_y + h; y++) {
        for(int32 x = block_x; x < block_x + w; x++) {
            int32 index = x + (y * _block_width);

            // If the texture pointer for the block is not nullptr, this means it contains a freed texture.
            // Now we must remove that texture entirely since we are overwriting at least one of its blocks.
            if(_blocks[index].image) {
                RemoveTexture(_blocks[index].image);
            }

            _blocks[index].free_image = false;
            _blocks[index].image = img;
        }
    }

    // Calculate the pixel and uv coordinates for the newly inserted texture
    img->x = block_x * 16;
    img->y = block_y * 16;

    float sheet_width = static_cast<float>(width);
    float sheet_height = static_cast<float>(height);

    img->u1 = static_cast<float>(img->x + 0.5f) / sheet_width;
    img->u2 = static_cast<float>(img->x + img->width - 0.5f) / sheet_width;
    img->v1 = static_cast<float>(img->y + 0.5f) / sheet_height;
    img->v2 = static_cast<float>(img->y + img->height - 0.5f) / sheet_height;

    img->texture_sheet = this;
    _textures.insert(img);

    return true;
} // bool VariableTexSheet::InsertTexture(BaseTexture* img)
コード例 #9
0
//Events System
void 
CTextureAtlasCreatorContext::OnEvent(ASCIEvent* pEvent)
{
	switch(pEvent->TypeID())
	{
	case ET_GUI:
		{
			UINT32 uEventID = pEvent->ID();
			if(uEventID == m_uMainButtons[EMB_NEW])
			{
				New();
			}
			else if(uEventID == m_uMainButtons[EMB_ADD])
			{
				LoadTexture();
			}
			else if(uEventID == m_uMainButtons[EMB_REMOVE])
			{
				RemoveTexture();
			}
			else if(uEventID == m_uMainButtons[EMB_SAVE])
			{
				Save();
			}
			else if(uEventID == m_uMainButtons[EMB_LOAD])
			{
				Load();
			}
			else if(uEventID == m_uBigButtons[EBB_UPDATE])
			{
				m_pAtlasLayers[m_uActiveLayer]->UpdateCurrentTexture();
			}
			else if(uEventID == m_uBigButtons[EBB_UPDATE_ALL])
			{
				m_pAtlasLayers[m_uActiveLayer]->UpdateAllTextures();
			}
			else
			{
				for(UINT32 i = 0; i < ALTAS_MAX_LAYERS; ++i)
				{
					if(uEventID == m_uLayerButtons[i])
					{
						if(i != m_uActiveLayer)
						{
							m_pAtlasLayers[m_uActiveLayer]->Deactivate();
							m_uActiveLayer = i;
							m_pAtlasLayers[m_uActiveLayer]->Activate();
						}
						break;
					}
				}
			}
			break;
		}
	case ET_INPUT:
		{
			ASCInputEvent* pInputEvent = reinterpret_cast<ASCInputEvent*>(pEvent);
			UINT32 uID = pEvent->ID();
			if(uID == m_uMouseLeftButton)
			{
				m_bMouseDown = pInputEvent->GetState() == KS_Pressed || pInputEvent->GetState() == KS_Held;
			}
			else if(uID == m_uMouseRightButton)
			{
				m_bMouseRightDown = pInputEvent->GetState() == KS_Pressed || pInputEvent->GetState() == KS_Held;
			}
			else if (uID == m_uMouseXY)
			{
				FLOAT32 fX = pInputEvent->GetPos().m_fX;
				FLOAT32 fY = pInputEvent->GetPos().m_fY;
				if(m_bMouseDown)
				{
					if(fX >= ATLAS_CENTER_X - ATLAS_AREA_H_WIDTH && fX <= ATLAS_CENTER_X + ATLAS_AREA_H_WIDTH && fY >= ATLAS_CENTER_Y - ATLAS_AREA_H_HEIGHT && fY <= ATLAS_CENTER_Y + ATLAS_AREA_H_HEIGHT)
					{
						m_pAtlasLayers[m_uActiveLayer]->MoveCurrentTexture(fX - m_fMouseX, fY - m_fMouseY);
					}
				}
				else if( m_bMouseRightDown )
				{
					if(fX >= ATLAS_CENTER_X - ATLAS_AREA_H_WIDTH && fX <= ATLAS_CENTER_X + ATLAS_AREA_H_WIDTH && fY >= ATLAS_CENTER_Y - ATLAS_AREA_H_HEIGHT && fY <= ATLAS_CENTER_Y + ATLAS_AREA_H_HEIGHT)
					{
						m_pAtlasLayers[m_uActiveLayer]->PanAtlas(fX - m_fMouseX, fY - m_fMouseY);
					}
				}
				m_fMouseX = fX;
				m_fMouseY = fY;
			}
			else if (uID == m_uSroll)
			{
				FLOAT32 fWheel = pInputEvent->GetScrollWheel();

				
				if(m_fMouseX >= ATLAS_CENTER_X - ATLAS_AREA_H_WIDTH && m_fMouseX <= ATLAS_CENTER_X + ATLAS_AREA_H_WIDTH && m_fMouseY >= ATLAS_CENTER_Y - ATLAS_AREA_H_HEIGHT && m_fMouseY <= ATLAS_CENTER_Y + ATLAS_AREA_H_HEIGHT)
				{
					m_fMouseScrollWheel += fWheel * 0.005f;
					if(m_fMouseScrollWheel > 0.05f)
					{
						//m_pAtlasLayers[m_uActiveLayer]->Zoom(m_fMouseScrollWheel);
					}
					else
					{
						m_fMouseScrollWheel -= fWheel * 0.005f;
					}
				}
			}
			break;
		}
	default:break;
	}
}