示例#1
0
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CSoundSystem
//  - prototype : CSound* LoadSound(CInput* pInput, const std::string& strExt)
//
//  - Purpose   : Loads a sound,  setting it ready to play.
//                If succesfull, it returns a valid handle to operate
//                with, otherwise it returns NULL.
//
// -----------------------------------------------------------------------------
CSound* CSoundSystem::LoadSound(CInput* pInput, const std::string& strExt)
{
    if(m_bActive == false)
    {
        return NULL;
    }

    // Put it into a buffer:

    pInput->SetPosition(0, CInput::SEEKFROM_START);
    char* pBuffer = new char[pInput->GetLength()];

    assert(pBuffer);

    if(pInput->ReadRawData(pInput->GetLength(), 1, pBuffer) == 0)
    {
        CLogger::ErrorWindow("ERROR - CSoundSystem::LoadSound():\npInput->ReadRawData() failed");
        SAFE_DELETE_A(pBuffer);
        return NULL;
    }

    CSound* pSound = NULL;

    if(IsModule(strExt))
    {
        HMUSIC module = BASS_MusicLoad(TRUE, pBuffer, 0, pInput->GetLength(), 0);

        if(!module)
        {
            CLogger::ErrorWindow("ERROR - CSoundSystem::LoadSound():\nBASS_MusicLoad() failed");
            return NULL;
        }

        CSound* pSound = new CSoundModule(module, pBuffer);
        m_vecSounds.push_back(pSound);
        return pSound;
    }
    else if(IsStream(strExt))
    {
        HSTREAM stream = BASS_StreamCreateFile(TRUE, pBuffer, 0, pInput->GetLength(), BASS_MP3_SETPOS);

        if(!stream)
        {
            CLogger::ErrorWindow("ERROR - CSoundSystem::LoadSound():\nBASS_StreamCreateFile() failed");
            return NULL;
        }

        CSound* pSound = new CSoundStream(stream, pBuffer);
        m_vecSounds.push_back(pSound);
        return pSound;
    }

    SAFE_DELETE_A(pBuffer);
    CLogger::ErrorWindow("ERROR - CSoundSystem::LoadSound():\nUnknown format (%s)", strExt.data());
    return NULL;
}
示例#2
0
//release de tudo
void ACWinSock::Release() 
{
	Log("shutting down WinSock");

	if (mMode == NetModeType::NMT_Server) 
	{
		for (int i=0; i<mClCount; i++)
		{
			shutdown(mClients[i].skToClient,0x02);
			closesocket(mClients[i].skToClient);
			mClients[i].skToClient = INVALID_SOCKET;
		}
	}

	SAFE_DELETE(mpSockObj);

	SAFE_DELETE_A(mBuffer);

	// clean up winsock
	WSACleanup();

	Log("offline (ok)");

	if (mpLOG!=nullptr)
	{
		fclose(mpLOG);
		mpLOG = nullptr;
	}

	IsRunning = false;
};
bool CFXTelevisionBitmap::Free()
{
	m_pTexture = NULL;

	if(m_pResTexture)
	{
		m_pResTexture->RemoveDependency(this);
		m_pResTexture = NULL;
		return false;
	}

	SAFE_DELETE_A(m_pucOwnTexture);
	return true;
}
示例#4
0
bool CFXRings::Free()
{
	if(m_pResHorTexture)
	{
		m_pResHorTexture->RemoveDependency(this);
		m_pResHorTexture = NULL;
	}

	if(m_pResVertTexture)
	{
		m_pResVertTexture->RemoveDependency(this);
		m_pResVertTexture = NULL;
	}

	SAFE_DELETE_A(m_pv3Circle);
	SAFE_DELETE_A(m_pv3MeshVertices);
	SAFE_DELETE_A(m_pv2MeshMapping);
	SAFE_DELETE_A(m_pnMeshFaceList);

	m_vecRings.clear();

	return true;
}
bool CFXTelevisionBitmap::LoadData(CResourceList* pResourceList)
{
	assert(pResourceList);

	if(!(m_pResTexture = this->FindResource(pResourceList, "Texture", CResourceTexture2D::CLASSNAME)))
	{
		FXLoadError("Can't find texture resource");
		return false;
	}

	m_pResTexture->NotifyDependency(this);
	m_pTexture = (UtilGL::Texturing::CTexture2D*)((CResourceTexture2D*)m_pResTexture)->GetTexture2D();

	SAFE_DELETE_A(m_pucOwnTexture);
	m_pucOwnTexture = new unsigned char[m_pTexture->GetWidth() * m_pTexture->GetHeight() * 4];

	return true;
}
示例#6
0
HRESULT ACD3D::CreateGraphicsDevice(int width, int height)
{
	HRESULT hr;

	Log("Begin Init Graphics Device");

	//inicializa membros
	mDriverType = D3D_DRIVER_TYPE_HARDWARE;
	mFeatureLevel = D3D_FEATURE_LEVEL_11_0;

	ACD3DGlobals::G_pD3dDevice = nullptr;
	ACD3DGlobals::G_pContext = nullptr;

	//tipo de dispositivo debug ou release
	UINT createDeviceFlags = 0;
#ifdef _DEBUG
	createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

    D3D_DRIVER_TYPE driverTypes[] =
    {
        D3D_DRIVER_TYPE_HARDWARE,
        D3D_DRIVER_TYPE_WARP,
        D3D_DRIVER_TYPE_REFERENCE,
    };
    UINT numDriverTypes = ARRAYSIZE( driverTypes );

    D3D_FEATURE_LEVEL featureLevels[] =
    {
        D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1,
        D3D_FEATURE_LEVEL_10_0
    };
	UINT numFeatureLevels = ARRAYSIZE( featureLevels );

	//********************************
	//  cria do dispositivo grafico
	//********************************

	for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
	{
		mDriverType = driverTypes[driverTypeIndex];
		//passa null no adapter ai ele cria automatico, depois eu recupero para pegar algumas configuracoes
		hr = D3D11CreateDevice(nullptr, mDriverType, nullptr, createDeviceFlags, featureLevels, 
							   numFeatureLevels, D3D11_SDK_VERSION, &ACD3DGlobals::G_pD3dDevice, 
							   &mFeatureLevel, &ACD3DGlobals::G_pContext );
		if( SUCCEEDED( hr ) )
		{
			Log("Create graphics device success.");
			break;
		}
	}
	if( FAILED( hr ) )
	{
		MessageBoxA(nullptr, "[ERROR] Create device error. D3DCreateDevice()", "Error", MB_OK | MB_ICONERROR);
		return hr;
	}
	//*********************************
	// fim da criacao do dispositivo grafico
	//*********************************
	IDXGIFactory* pDXGIFactory = ACD3DTools::GetDXGIFactory();
	IDXGIAdapter* pDXGIAdapter = ACD3DTools::GetDXGIAdapter();

	//usando os objetos acima ele retorna algumas configuracoes
	IDXGIOutput*  pAdapterOutput;
	unsigned int numModes, i, stringLength;
	DXGI_MODE_DESC* pDisplayModeList;
	DXGI_ADAPTER_DESC adapterDesc;
	int error;

	// Enumerate the primary adapter output (monitor).
	hr = pDXGIAdapter->EnumOutputs(0, &pAdapterOutput);
	if(FAILED(hr))
	{
		MessageBoxA(nullptr, "[ERROR] EnumOutputs. D3DCreateDevice()", "Error", MB_OK | MB_ICONERROR);
		return hr;
	}

	// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
	hr = pAdapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, nullptr);
	if(FAILED(hr))
	{
		MessageBoxA(nullptr, "[ERROR] GetDisplayModeList", "Error", MB_OK | MB_ICONERROR);
		return hr;
	}

	// Create a list to hold all the possible display modes for this monitor/video card combination.
	pDisplayModeList = new DXGI_MODE_DESC[numModes];
	if(!pDisplayModeList)
		return AC_FAIL;

	// Now fill the display mode list structures.
	hr = pAdapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, pDisplayModeList);
	if(FAILED(hr))
	{
		MessageBoxA(nullptr, "[ERROR] GetDisplayModeList", "Error", MB_OK | MB_ICONERROR);
		return hr;
	}

	// Now go through all the display modes and find the one that matches the screen width and height.
	// When a match is found store the numerator and denominator of the refresh rate for that monitor.
	for(i=0; i<numModes; i++)
	{
		if(pDisplayModeList[i].Width == (unsigned int)width)
		{
			if(pDisplayModeList[i].Height == (unsigned int)height)
			{
				ACD3DGlobals::G_Numerator = pDisplayModeList[i].RefreshRate.Numerator;
				ACD3DGlobals::G_Denomerator = pDisplayModeList[i].RefreshRate.Denominator;
			}
		}
	}

	Log("Width: %i. Height: %i", width, height);

	// Get the adapter (video card) description.
	hr = pDXGIAdapter->GetDesc(&adapterDesc);
	if(FAILED(hr))
		return hr;

	// Store the dedicated video card memory in megabytes.
	VideoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);
	Log("VideoCardMemory: %i (in megabytes).", VideoCardMemory);

	// Convert the name of the video card to a character array and store it.
	error = wcstombs_s(&stringLength, VideoCardDescription, 128, adapterDesc.Description, 128);
	if(error != 0)
	{
		Log("[ERROR] Get videocarddescription.");
		return AC_FAIL;
	}

	// Release the display mode list.
	SAFE_DELETE_A(pDisplayModeList);

	// Release the adapter output.
	pAdapterOutput->Release();
	pAdapterOutput = nullptr;

	// Release the adapter.
	pDXGIAdapter->Release();
	pDXGIAdapter = nullptr;

	// Release the factory.
	pDXGIFactory->Release();
	pDXGIFactory = nullptr;

	Log("End Graphics Device");

	return AC_OK;
};
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CInputZipFile
//  - Prototype : bool Open(const std::string& strZipFile, 
//                          const std::string& strFile)
//
//  - Purpose   : Opens a file inside a zip and sets it ready to read from.
//                Closes the previous opened zip if any.
//
// -----------------------------------------------------------------------------
bool CInputZipFile::Open(const std::string& strZipFile, const std::string& strFile)
{
	assert(strZipFile.data());
	assert(strFile.data());

	if(Ready())
	{
		Close();
	}

	// Open Zip

	unzFile       zipHandle;
	unz_file_info zipInfo;

	if(!(zipHandle = unzOpen(strZipFile.data())))
	{
		LOG.Write("\nERROR - Couldn't open zip %s", strZipFile.data());
		return false;
	}

	// Try to locate the file inside (2 means without case sensivity).

	if(unzLocateFile(zipHandle, strFile.data(), 2) != UNZ_OK)
	{
		LOG.Write("\nERROR - Couldn't locate file %s inside zip %s", strFile.data(), strZipFile.data());
		unzClose(zipHandle);
		return false;
	}

	// Try to open the located file.

	if(unzOpenCurrentFile(zipHandle) != UNZ_OK)
	{
		LOG.Write("\nERROR - Couldn't open file %s inside zip %s", strFile.data(), strZipFile.data());
		unzClose(zipHandle);
		return false;
	}

	// Get length

	if(unzGetCurrentFileInfo(zipHandle, &zipInfo, NULL, 0, NULL, 0, NULL, 0) != UNZ_OK)
	{
		LOG.Write("\nERROR - Couldn't get file %s length. File is inside zip %s", strFile.data(), strZipFile.data());
		unzCloseCurrentFile(zipHandle);
		unzClose(zipHandle);
		return false;
	}

	// Copy file to buffer.

	char* pcBuffer = new char[zipInfo.uncompressed_size];

	if(pcBuffer == NULL)
	{
		LOG.Write("\nERROR - Out of memory reading file %s inside zip %s", strFile.data(), strZipFile.data());
		unzCloseCurrentFile(zipHandle);
		unzClose(zipHandle);
		return false;
	}

	int nBytesRead = unzReadCurrentFile(zipHandle, pcBuffer, zipInfo.uncompressed_size);

	if(nBytesRead != zipInfo.uncompressed_size)
	{
		LOG.Write("\nERROR - File %s inside zip %s not completely read (%u/%u)", strFile.data(), strZipFile.data(), nBytesRead, zipInfo.uncompressed_size);
		unzCloseCurrentFile(zipHandle);
		unzClose(zipHandle);
		SAFE_DELETE_A(pcBuffer);
		return false;
	}

	// Close and open our internal memory reader.

	unzCloseCurrentFile(zipHandle);
	unzClose(zipHandle);

	m_pBuffer = pcBuffer;

	if(m_FileInMemory.Open(m_pBuffer, nBytesRead) == false)
	{
		SAFE_DELETE_A(m_pBuffer);
		return false;
	}

	return true;
}
// --[  Method  ]---------------------------------------------------------------
//
//  - Class     : CInputZipFile
//  - Prototype : bool Close()
//
//  - Purpose   : Closes the file.
//
// -----------------------------------------------------------------------------
bool CInputZipFile::Close()
{
	SAFE_DELETE_A(m_pBuffer);

	return m_FileInMemory.Close();
}
示例#9
0
bool CXml::FindElemEx(const char *pszElemPath)
{
	const char* seps = "/"; // 字符串分隔符
	bool returnFlag = true;

	// 检查传入的路径是否为空
	CHECK_POINTER(pszElemPath,false);
    unsigned int iNewStrLen = strlen(pszElemPath) + 1;

	// 创建临时字符串
    char* pszPath = NULL;
    SAFE_NEW_A(pszPath, char, iNewStrLen);
    CHECK_POINTER(pszPath,false);
    memset(pszPath, 0, iNewStrLen);
    char* pszTmpPath = pszPath;

    // 复制字符串
	strncpy(pszTmpPath, pszElemPath, iNewStrLen);
    //strcpy(pszTmpPath,pszElemPath);
    
    if(*pszTmpPath == '/')
    {
        ++pszTmpPath;   //lint !e810
        this->GetRootPos();
        (void)this->IntoElem();
    }
    else
    {
        // 将xml的指针指向根节点
        (void)this->GetBasePos();
    }
    char *saveptr = NULL;
    char* token = STRTOK( pszTmpPath, seps, &saveptr); 
	while( token != NULL )
    {//lint !e525
	   const char* tmpStr = strstr(token,"[");
	   if(NULL != tmpStr)
	   {   
		    // 处理多个同名节点的情况
            int index = atoi(tmpStr + 1);
			std::string  strTemp(token,static_cast<unsigned int>(tmpStr - token));
			if(!this->FindElem(strTemp.c_str()))
			{
				returnFlag = false;
				break;
			}

			if(!this->NextElemEx(index))
			{
				returnFlag = false;
				break;
			}
	   }
	   else
	   {
		   // 处理单节点的情况
		   if(!this->FindElem(token))
		   {
			   returnFlag = false;
			   break;
		   }
	   }

	   // 进入该节点
       (void)this->IntoElem();
	  // Get next token: 
	  token = STRTOK( NULL, seps, &saveptr); 
    }
    SAFE_DELETE_A(pszPath);//lint !e774 !e1775
    return returnFlag;//lint !e438
}
示例#10
0
bool CXml::MkAndFindElemEx(const char *pszElemPath)
{
	// 创建临时变量
	
	char* token;
	const char* seps = "/"; // 字符串分隔符
	bool returnFlag = true;

	// 检查传入的路径是否为空
	CHECK_POINTER(pszElemPath,true);

	// 将xml的指针指向根节点
	(void)this->GetBasePos();

	// 创建临时字符串
    unsigned int iNewStrLen = strlen(pszElemPath) + 1;
    char* pszPath = NULL;
    SAFE_NEW_A(pszPath, char, iNewStrLen);
    CHECK_POINTER(pszPath, false);
    memset(pszPath, 0, iNewStrLen);
    char* pszTmpPath = pszPath;    

	// 复制字符串
	strncpy(pszTmpPath, pszElemPath, iNewStrLen);
	//strcpy(pszTmpPath,pszElemPath);
    char *saveptr = NULL;
	token = STRTOK( pszTmpPath, seps, &saveptr);
	std::string pszParentNode = "";
	while( token != NULL )
	{
		// 当前指针指向的节点名称
		const char* curNodeName = this->GetElem();
		char* pszTmpNode = strstr(token,"[");
		if(NULL != pszTmpNode)
		{   
			// 处理多个同名节点的情况
			int index = atoi(pszTmpNode + 1);
			std::string  strTemp(token,static_cast<unsigned int>(pszTmpNode - token));
            if(NULL == curNodeName)
            {
                 (void)this->AddElem(strTemp.c_str());
            }
			if(!this->FindElem(strTemp.c_str()))
			{
				returnFlag = false;
				break;

				//// 如果发现没有此节点则创建该节点
    //            if(0 != strcmp(curNodeName,pszParentNode.c_str()))//lint !e527
				//{
    //                 (void)this->AddElem(strTemp.c_str());
				//}else
				//{
    //                 (void)this->AddChildElem(strTemp.c_str());
				//}
    //            (void)this->FindElem(strTemp.c_str());
			}

			if(!this->MkAndNextElemEx(index))
			{
				returnFlag = false;
				break;
			}
			// 记录当前节点为上一节点的父节点
		    pszParentNode = strTemp;
		}
		else
		{
            if(NULL == curNodeName)
            {
                (void)this->AddElem(token);
            }
			// 处理单节点的情况
			if(!this->FindElem(token))
			{
                if (NULL != curNodeName)
                {
				    if(0 != strcmp(curNodeName,pszParentNode.c_str()))
				    {
                         (void)this->AddElem(token);
				    }else
				    {
                         (void)this->AddChildElem(token);
				    }
                }
                (void)this->FindElem(token);
			}
			// 记录当前节点为上一节点的父节点
		    pszParentNode = token;
		}

		// 进入该节点
		(void)this->IntoElem();

		// Get next token: 
		token = STRTOK( NULL, seps, &saveptr ); 
	}
    SAFE_DELETE_A(pszPath);//lint !e424 !e774 !e1775
    return returnFlag;//lint !e438
  //return false;
}