Esempio n. 1
0
cTexture *cTextureManager::Get(const std::string &str)
{
    vTextureResource *res= NULL;

    int index = FindResource(str);
    if(index < 0)
    {
        res = CreateResource(str, LoadTexture(str));
        if(res != NULL)
        {
            m_Resources.push_back(res);
            m_Resources.back()->SetStorageIndex(m_Resources.size() - 1);
        }
    }
    else
        res = m_Resources[index];

    return new cTexture(res);
}
    ResourceWeakPtr IResourceManager::LoadResource(xst_castring& strResName, xst_castring& strResGroupName, xst_castring &strFileName, xst_castring &strFileGroupName, bool bFullLoad)
    {
        xst_assert( m_pResFileMgr, "(IResourceManager::LoadResource) File manager not created" );
        
        ResourceHandle ResHandle = CalcHandle( strResName.c_str(), strResName.length() );
        GroupHandle GrHandle = CalcHandle( strResGroupName.c_str(), strResName.length() );
        ResourceWeakPtr pRes = GetResource( ResHandle, GrHandle );
        if( pRes.IsValid() )
        {
            return pRes;
        }

        pRes = CreateResource( strResName, strResGroupName );
        if( XST_FAILED( LoadResource( &pRes, strFileName, strFileGroupName, bFullLoad ) ) )
        {
            DestroyResource( pRes );
            pRes = XSE_NULLRES;
        }
        return pRes;
    }
Esempio n. 3
0
dd::Resource* dd::ResourceManager::Load(std::string resourceType, std::string resourceName, dd::Resource* parent /*= nullptr*/)
{
	auto it = m_ResourceCache.find(std::make_pair(resourceType, resourceName));
	if (it != m_ResourceCache.end())
		return it->second;

	if (m_Preloading) {
		LOG_INFO("Preloading resource \"%s\"", resourceName.c_str());
	} else {
		LOG_WARNING("Hot-loading resource \"%s\"", resourceName.c_str());

		if (!resourceType.empty() && !resourceName.empty()) {
			std::replace(resourceName.begin(), resourceName.end(), '\\', '/');
			if (m_Preloads.find(std::make_pair(resourceType, resourceName)) == m_Preloads.end()) {
				std::ofstream f("PreloadResources", std::ofstream::app);
				f << resourceType << " " << resourceName << std::endl;
				f.close();
				m_Preloads.insert(std::make_pair(resourceType, resourceName));
			}
		}
	}

	return CreateResource(resourceType, resourceName, parent);
}
//
// LoadAssets goes through the texture asset directory and attempts to load all files
// as images for the application to stream in. Texture assets are located in
// Assets\Textures, relative to the sample binary.
//
HRESULT D3D12MemoryManagement::LoadAssets()
{
    WCHAR FileName[MAX_PATH];
    GetWorkingDir(FileName, MAX_PATH);

    wcscat_s(FileName, L"Assets\\Textures\\*");
    WCHAR* pEnd = FileName + wcslen(FileName) - 1;

    WIN32_FIND_DATA ffd;
    HANDLE hFind = FindFirstFile(FileName, &ffd);

    if (INVALID_HANDLE_VALUE == hFind)
    {
        //
        // Does the directory not exist?
        //
        LOG_ERROR("Failed to load texture assets");
        return E_FAIL;
    }

    UINT ImageIndex = 0;

    do
    {
        if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            //
            // Ignore directories.
            //
            continue;
        }
        else
        {
            //
            // Try to create the resource from the file. This may not be a valid image file,
            // and if this is the case, we will fail to create the resource, and continue
            // with the next file.
            //
            *pEnd = L'\0';
            wcscat_s(FileName, ffd.cFileName);

            Resource* pResource = nullptr;

            HRESULT hr = CreateResource(FileName, &pResource);
            if (FAILED(hr))
            {
                continue;
            }

            Image Img;
            InitializeImage(&Img, pResource, ImageIndex);
            m_Images.push_back(Img);

            ++ImageIndex;
        }
    } while (FindNextFile(hFind, &ffd) != 0);

    FindClose(hFind);

    for (UINT GeneratedImage = 0; GeneratedImage < MAX_GENERATED_IMAGES; ++GeneratedImage)
    {
        Resource* pResource = nullptr;
        HRESULT hr = CreateResource(L"", &pResource);
        if (FAILED(hr))
        {
            LOG_WARNING("Unable to generate image %d", GeneratedImage);
            continue;
        }

        Image Img;
        InitializeImage(&Img, pResource, ImageIndex);
        m_Images.push_back(Img);

        ++ImageIndex;
    }

    return S_OK;
}
 ResourceWeakPtr IResourceManager::CreateResource(xst_castring& strName, xst_castring& strGroupName)
 {
     GroupWeakPtr pGr = this->GetOrCreateGroup( strGroupName );
     m_pStrTmp = strGroupName.c_str();
     return CreateResource( strName, pGr );
 }
Esempio n. 6
0
	bool painter<Derived>::WindowProc(Derived &, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT &r)
	{
		switch(msg){
		case WM_CREATE:
			{
				/*if(::IsWindowsVersionOrGreater(6, 2, 0)){
					HINSTANCE module = ::LoadLibrary(L"user32.dll");

					if(module == nullptr)
						break;

					using lpfnSetWindowCompositionAttribute = BOOL(WINAPI *)(HWND, detail::WINDOWCOMPOSITIONATTRIBUTEDATA*);
					auto SetWindowCompositionAttribute = (lpfnSetWindowCompositionAttribute)::GetProcAddress(module, "SetWindowCompositionAttribute");

					if(SetWindowCompositionAttribute == nullptr){
						::FreeLibrary(module);
						break;
					}

					detail::ACCENTPOLICY policy = {3, 0, 0, 0};
					detail::WINDOWCOMPOSITIONATTRIBUTEDATA data = {19, &policy, sizeof(policy)};

					SetWindowCompositionAttribute(hwnd, &data);

					::FreeLibrary(module);
				}else{
					DWM_BLURBEHIND bb = {};
					bb.dwFlags = DWM_BB_ENABLE;
					bb.fEnable = TRUE;
					::DwmEnableBlurBehindWindow(
						get_hwnd(),
						&bb);
					htheme = ::OpenThemeData(hwnd, VSCLASS_WINDOW);

					BOOL b;
					::DwmIsCompositionEnabled(&b);
					aero_glass = b != FALSE;
				}*/
			}
			break;
		case WM_DESTROY:
			::CloseThemeData(htheme);
			DestroyResource();
			break;
		case WM_PAINT:
			if(CreateResource()){
				mutex.lock();

				paint_params pp = {
					target
				};

				HWND hwnd = get_hwnd();
				RECT rc;
				::GetClientRect(hwnd, &rc);

				PAINTSTRUCT ps;
				::BeginPaint(hwnd, &ps);

				target->BindDC(ps.hdc, &rc);
				target->BeginDraw();

				if(!aero_glass)
					target->Clear(color(255, 255, 255, 255));

				static_cast<Derived*>(this)->draw(pp);

				if(target->EndDraw() == D2DERR_RECREATE_TARGET){
					DestroyResource();
					repaint();
				}

				::EndPaint(hwnd, &ps);

				mutex.unlock();
			}else{
				throw std::runtime_error("an error occurred when creating Direct2D resources.");
			}
			break;
		case WM_SIZE:
			::InvalidateRect(hwnd, nullptr, FALSE);
			break;
		case WM_DWMCOMPOSITIONCHANGED:
			{
				BOOL b;
				::DwmIsCompositionEnabled(&b);
				aero_glass = b != FALSE;
			}
			break;
		}
		return true;
	}
Esempio n. 7
0
void DumpNEResourceTable(MPanelItem *pRoot, PIMAGE_DOS_HEADER dosHeader, LPBYTE pResourceTable)
{
	PBYTE pImageBase = (PBYTE)dosHeader;

	MPanelItem* pChild = pRoot->AddFolder(_T("Resource Table"));
	pChild->AddText(_T("<Resource Table>\n"));

	// минимальный размер
	size_t nReqSize = sizeof(OS2RC_TYPEINFO)+12;
	if (!ValidateMemory(pResourceTable, nReqSize)) {
		pChild->printf(_T("!!! Can't read memory at offset:  0x%08X\n"),
			(DWORD)(pResourceTable - pImageBase));
		return;
	}

	//
	USHORT rscAlignShift = *(USHORT*)pResourceTable;
	OS2RC_TYPEINFO* pTypeInfo = (OS2RC_TYPEINFO*)(pResourceTable+2);
	char szTypeName[128], szResName[256];
	UINT nResLength = 0, nResOffset = 0;
	LPBYTE pNames;

	// —начала нужно найти начало имен
	pTypeInfo = (OS2RC_TYPEINFO*)(pResourceTable+2);
	while (pTypeInfo->rtTypeID) {
		OS2RC_TNAMEINFO* pResName = pTypeInfo->rtNameInfo;

		// Next resource type
		pTypeInfo = (OS2RC_TYPEINFO*)(pResName+pTypeInfo->rtResourceCount);
		if (!ValidateMemory(pTypeInfo, 2)) {
			pChild->printf(_T("!!! Can't read memory at offset:  0x%08X\n"),
				(DWORD)(((LPBYTE)pTypeInfo) - pImageBase));
			return;
		}
	}
	pNames = ((LPBYTE)pTypeInfo)+2;

	// “еперь, собственно ресурсы
	pTypeInfo = (OS2RC_TYPEINFO*)(pResourceTable+2);
	while (pTypeInfo->rtTypeID) {
		szTypeName[0] = 0;
		GetOS2ResourceTypeName(pTypeInfo->rtTypeID, szTypeName, sizeof(szTypeName));

		MPanelItem* pType = pChild->AddFolder(szTypeName);
		pType->printf("  <%s>:\n", szTypeName);

		pType->printf(_T("    Resource count:   %i\n"), pTypeInfo->rtResourceCount);

		OS2RC_TNAMEINFO* pResName = pTypeInfo->rtNameInfo;
		for (USHORT i = pTypeInfo->rtResourceCount; i--; pResName++) {
			nResLength = pResName->rnLength * (1 << rscAlignShift);
			nResOffset = pResName->rnOffset * (1 << rscAlignShift);

			szResName[0] = 0;
			if (pNames) {
				if (!ValidateMemory(pNames, 1)) {
					pChild->printf(_T("!!! Can't read memory at offset:  0x%08X\n"),
						(DWORD)(pNames - pImageBase));
					pNames = NULL;
				} else if (!ValidateMemory(pNames, 1+(*pNames))) {
					pChild->printf(_T("!!! Can't read memory at offset:  0x%08X\n"),
						(DWORD)(pNames - pImageBase));
					pNames = NULL;
				} else if (*pNames) {
					memmove(szResName, pNames+1, *pNames);
					szResName[*pNames] = 0;
					pNames += (*pNames)+1;
				} else {
					pNames++;
				}
			}
			if (szResName[0]) {
				sprintf(szResName+strlen(szResName), ".0x%08X", pResName->rnID);
			} else {
				sprintf(szResName, "ResID=0x%08X", pResName->rnID);
			}

			MPanelItem* pRes = NULL;
			if (nResLength && nResOffset) {
				pRes = CreateResource(pType, pTypeInfo->rtTypeID, 
					pImageBase+nResOffset, nResLength,
					szResName, NULL, 0, 0);
			} else {
				pRes = pType->AddFile(szResName, nResOffset ? nResLength : 0);
			}
			pType->printf("    <%s>\n", szResName);
			pType->printf("      Resource Name:    %s\n", szResName);
			pType->printf("      Resource ID:      0x%08X\n", pResName->rnID);
			pType->printf("      Resource length:  %u bytes\n", nResLength);
			pType->printf("      Resource offset:  0x%08X\n", nResOffset);
			pType->printf("      Handle(reserved): 0x%04X\n", (DWORD)pResName->rnHandle);
			pType->printf("      Usage(reserved):  0x%04X\n", (DWORD)pResName->rnUsage);
			//if (nResLength && nResOffset) {
			//	pRes->SetData(pImageBase+nResOffset, nResLength);
			//}
		}


		// Next resource type
		pTypeInfo = (OS2RC_TYPEINFO*)pResName;
	}
}