Beispiel #1
0
wxString GOrgueStdPath::GetResourceDir()
{
#ifdef __WXMAC__
	return wxStandardPaths::Get().GetResourcesDir();
#else
	return GetBaseDir() + wxFILE_SEP_PATH +  wxT("share") + wxFILE_SEP_PATH + wxT("GrandOrgue");
#endif
}
Beispiel #2
0
void CSAStatusLog::Init(const char *pOutputFilename)
{
	m_bEnable = TRUE;

   // get application path and name
	char buf[MAX_PATH+1];
	DWORD res = GetModuleFileName(AfxGetInstanceHandle(), buf, MAX_PATH);

	CString appDir = GetBaseDir(buf);

   m_csAppName = GetBaseName(buf);

   m_csFileName.Format("%s\\%s", appDir, pOutputFilename);

   // overwrite the old one!
   remove(m_csFileName);
}
Beispiel #3
0
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
	// Must add 'bin' to the path....
	char* pPath = getenv("PATH");

	// Use the .EXE name to determine the root directory
	char moduleName[ MAX_PATH ];
	char szBuffer[ 4096 ];
	if ( !GetModuleFileName( hInstance, moduleName, MAX_PATH ) )
	{
		MessageBox( 0, "Failed calling GetModuleFileName", "Launcher Error", MB_OK );
		return 0;
	}

	// Get the root directory the .exe is in
	char* pRootDir = GetBaseDir( moduleName );

#ifdef _DEBUG
	int len = 
#endif
		sprintf( szBuffer, "PATH=%s\\bin\\;%s", pRootDir, pPath );
	assert( len < 4096 );
	_putenv( szBuffer );

	HINSTANCE launcher = LoadLibrary("launcher.dll"); // STEAM OK ... filesystem not mounted yet
	if (!launcher)
	{
		char *pszError;
		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&pszError, 0, NULL);

		char szBuf[1024];
		sprintf(szBuf, "Failed to load the launcher DLL:\n\n%s", pszError);
		MessageBox( 0, szBuf, "Launcher Error", MB_OK );

		LocalFree(pszError);
		return 0;
	}

	LauncherMain_t main = (LauncherMain_t)GetProcAddress( launcher, "LauncherMain" );
	return main( hInstance, hPrevInstance, lpCmdLine, nCmdShow );
}
//
// Load template with specified name
//
INT_32 CTPP2FileSourceLoader::LoadTemplate(CCHAR_P szTemplateName)
{
	sNormalizedFileName.erase();
	INT_32 iStatCode = 0;
	STLW::vector<STLW::string>::const_iterator itvIncludeDirs = vIncludeDirs.begin();
	while(itvIncludeDirs != vIncludeDirs.end())
	{
		STLW::string sTMP = *itvIncludeDirs;
#ifdef WIN32
		if ( sTMP.length() && sTMP[sTMP.length() - 1] != '/' && sTMP[sTMP.length() - 1] != '\\' ) { sTMP.append("\\", 1); }
#else
		if (sTMP.length() && sTMP[sTMP.length() - 1] != '/') { sTMP.append("/", 1); }
#endif
		sTMP.append(szTemplateName);

		sCurrentDir = GetBaseDir(sTMP, sNormalizedFileName);
		if (sNormalizedFileName.length() == 0)
		{
			STLW::string sError("invalid file name `");
			sError.append(sTMP);
			sError.append("`");
			throw CTPPLogicError(sError.c_str());
		}

		// Get file size
		struct stat oStat;
		iStatCode = stat(sNormalizedFileName.c_str(), &oStat);
		if (iStatCode == 0)
		{
			iTemplateSize = oStat.st_size;
			break;
		}
		++itvIncludeDirs;
	}

	if (iStatCode == -1)
	{
		STLW::string sError("cannot find file in include directories ");
		itvIncludeDirs = vIncludeDirs.begin();
		for (;;)
		{
			sError.append("`");
			if (itvIncludeDirs -> size() != 0) { sError.append(*itvIncludeDirs); }
			else
			{
				CHAR_P szPWD = getcwd(NULL, 0);
				sError.append(szPWD);
				free(szPWD);
			}
			sError.append("`");

			++itvIncludeDirs;
			if (itvIncludeDirs == vIncludeDirs.end()) { break; }

			sError.append(", ");
		}
		throw CTPPLogicError(sError.c_str());
	}

	if (iTemplateSize == 0)
	{
		STLW::string sError("empty file `");
		sError.append(sNormalizedFileName);
		sError.append("` found");
		throw CTPPLogicError(sError.c_str());
	}

	// Load file
	FILE * F = fopen(sNormalizedFileName.c_str(), "rb");
	if (F == NULL) { throw CTPPUnixException("fopen", errno); }

	if (sTemplate != NULL) { free(sTemplate); }

	// Allocate memory
	sTemplate = (CHAR_P)malloc(iTemplateSize);

	// Read from file
	if (fread(sTemplate, iTemplateSize, 1, F) != 1)
	{
		if (ferror(F) != 0)
		{
			free(sTemplate);
			fclose(F);
			throw CTPPUnixException("fread", errno);
		}
		else
		{
			free(sTemplate);
			fclose(F);
			throw CTPPLogicError("Cannot read from file");
		}
	}

	fclose(F);

return 0;
}
Beispiel #5
0
int RunTest(XMLCONFPARSER *xcp, char *uri) 
{
	LPXMLRUNTIMEATT att, tatt;
	XMLCH testuri[MAX_PATH];
	XMLCH xmlbase[MAX_PATH];
	XMLCH id[256];
	XMLCH *s;
	FILE *f;
	RUNPARSERDATA rdata;
	int result, expect;
	LPXMLPARSER parser = xcp->runParser;
	int type;

	if ((s = XMLParser_GetPrefixMapping(xcp->parser, "xml:base")))
		strcpy(xmlbase, s); /* we save current xmlbase
							   (although it shouldn't get modified 'cos
							   main parser isn't running during RunTest()) */
	else {
		/* rmt-e2e-18: 
		External entity containing start of entity declaration is 
		base URI for system identifier, so:  */
		XMLCH *sysID = XMLParser_GetSystemID(xcp->parser);
		if (!sysID) xmlbase[0] = '\0';
		else GetBaseDir(sysID, xmlbase);
	}
	
	strcpy(testuri, xmlbase);
	strcat(testuri, uri);

	puts(testuri);
	
	/* resolve basedir for external entities, DTD and for canonxml */
	GetBaseDir(testuri, rdata.testbasedir);
	
	tatt = XMLParser_GetNamedItem(xcp->parser, "TYPE");
	if (tatt) {
		/* "Nonvalidating parsers must also accept "invalid" testcases,
       but validating ones must reject them." */
		if (!strcmp(tatt->value, "valid")) type = TYPE_VALID;
		else if (!strcmp(tatt->value, "invalid")) type = TYPE_INVALID;
		else type = TYPE_OTHER; /* error, not-wf */
	}

	if ((f = fopen(testuri, "rb"))) {
#ifdef TEST_VALIDATING		
		xcp->v->UserData = &rdata;
		xcp->v->UserFlag = type;
		xcp->v->startElementHandlerFilter = StartElementDetermineValidation;
		result = XMLParser_ParseValidateDTD(xcp->v, parser, cstream, f, 0);
#else	
		parser->UserData = &rdata; 
		result = XMLParser_Parse(parser, cstream, f, 0);
#endif
		fclose(f);
	}
	else {
		fprintf(PFERR, "Error opening file %s\n", testuri);
		return 0;
	}

	xcp->testCount++;

	/* 1 row columns: ID, TYPE, PASS/FAIL, ERRORSTRING 
	   2 row columns: ENTITIES + OUTPUT in one col, 3 empty cols
	   3 row: test description, 3 empty cols
	*/	
	att = XMLParser_GetNamedItem(xcp->parser, "ID");
	strcpy(id, (att) ? att->value : "unknown");
	fputs((xcp->testCount % 2) ? "<tr bgcolor='#EEEEEE'>" : "<tr>", xcp->pfout);	
	fprintf(xcp->pfout, "<td><a href='%s'>%s</a></td>", testuri, id); 
	
	if (tatt) {
		if (type == TYPE_VALID) expect = 1; 
		else if (type == TYPE_INVALID)
#ifdef TEST_VALIDATING
			expect = 0;
#else
			expect = 1; 
#endif
		else expect = 0;
		fprintf(xcp->pfout, "<td>%s</td>", tatt->value);
		if (result == expect) xcp->testSuccess++;
	}
int main(int argc, char* argv[])
{	
	NSVALIDPARSER nsparser;
	LPXMLPARSER parser;	
	LPXMLDTDVALIDATOR vp;
	FILE *f;
	int i;
	XMLCH *filename = NULL;
	
	if (argc < 2 || argc > 4) goto USAGE;

	nsparser.elemCount = 0;
	nsparser.wantedUri = "";
	*nsparser.userDTD = '\0';
	*nsparser.base = '\0';
		
	for (i=1; i<argc; i++) {
		if (!strncmp(argv[i], "/DTD:", 5))
			strcpy(nsparser.userDTD, argv[i]+5);
		else if (!strncmp(argv[i], "/URI:", 5))
			nsparser.wantedUri = argv[i]+5;
		else {
			if (filename) goto USAGE;
			filename = argv[i];
		}
	}
	
	if (!filename) goto USAGE;
		
	if (!XMLParser_Create(&parser)) {
		puts("Out of memory!");
		return 1;
	}
	
	vp = XMLParser_CreateDTDValidator();
	if (!vp) {
		puts("Out of memory!");
		return 1;
	}

	if (!XMLVector_Create(&nsparser.filteredAtts, 0, sizeof(XMLRUNTIMEATT))) {
		puts("Out of memory!");
		return 1;
	}

	vp->UserData = &nsparser;
	parser->errorHandler = ErrorHandler;
	parser->resolveEntityHandler = ResolveEntity;
	parser->externalEntityParsedHandler = FreeInputData;

	if (*nsparser.userDTD) {
		int filepos = GetBaseDir(nsparser.base, nsparser.userDTD);
		if (filepos) strcpy(nsparser.userDTD, nsparser.userDTD+filepos);		
		XMLParser_SetExternalSubset(parser, NULL, nsparser.userDTD);
	}

	if (!*nsparser.base) 
		GetBaseDir(nsparser.base, filename);
	
	if (*nsparser.wantedUri) {
		vp->startElementHandlerFilter = StartElement;
		vp->endElementHandlerFilter = EndElement;
		vp->charactersHandlerFilter = Characters;
		vp->ignorableWhitespaceHandlerFilter = IgnorableWS;
	}
	else /* simple validator w/o namespace filter: */
		parser->startElementHandler = StartElementSimple;

	if (!(f = fopen(filename, "rb"))) {
		printf("Error opening file %s\n", filename);
		return 1;
	}
	
	if (XMLParser_ParseValidateDTD(vp, parser, cstream, f, 0)) {
		printf("Elements (total: %d) in namespace \"%s\" were valid\nin the" 
			" document %s\n", nsparser.elemCount, 
			((*nsparser.wantedUri) ? nsparser.wantedUri : "not specified"),
			filename);		
	}
		
	fclose(f);
	XMLVector_Free(nsparser.filteredAtts);
	XMLParser_FreeDTDValidator(vp);
	XMLParser_Free(parser);
	return 0;

USAGE:
	puts("Usage: nsvalid document.xml /DTD:<optional> /URI:<optional>\n"
		"Example: nsvalid my.xml /DTD:/home/my.dtd /URI:http://my.org");
	return 1;
}
/**
* Handle Stereo Drawing.
***/
void* StereoPresenter::Provoke(void* pThis, int eD3D, int eD3DInterface, int eD3DMethod, DWORD dwNumberConnected, int& nProvokerIndex)
{
#ifdef _DEBUG_STP
	{ wchar_t buf[128]; wsprintf(buf, L"[STP] ifc %u mtd %u", eD3DInterface, eD3DMethod); OutputDebugString(buf); }
#endif

	// update our global time
	static float fGlobalTime = 0.0f;
	static DWORD dwTimeStart = 0;
	DWORD dwTimeCur = GetTickCount();
	if (dwTimeStart == 0)
		dwTimeStart = dwTimeCur;
	fGlobalTime = (dwTimeCur - dwTimeStart) / 1000.0f;

	// only present accepted
	bool bValid = false;
	if (((eD3DInterface == INTERFACE_IDXGISWAPCHAIN) && (eD3DMethod == METHOD_IDXGISWAPCHAIN_PRESENT)) ||
		((eD3DInterface == INTERFACE_IDIRECT3DDEVICE9) && (eD3DMethod == METHOD_IDIRECT3DDEVICE9_PRESENT))) bValid = true;
	if (!bValid) return nullptr;

	// clear all previous menu events
	ZeroMemory(&m_abMenuEvents[0], sizeof(VireioMenuEvent)* (int)VireioMenuEvent::NumberOfEvents);

	// main menu update ?
	if ((m_sMainMenu.bOnChanged) && (!m_sMenuControl.eSelectionMovement))
	{
		m_sMainMenu.bOnChanged = false;

		// loop through entries
		for (size_t nIx = 0; nIx < m_sMainMenu.asEntries.size(); nIx++)
		{
			// entry index changed ?
			if (m_sMainMenu.asEntries[nIx].bOnChanged)
			{
				m_sMainMenu.asEntries[nIx].bOnChanged = false;

				// set new menu index.. selection to zero
				m_sMenuControl.nMenuIx = (INT)nIx;
				m_sMenuControl.unSelectionFormer = m_sMenuControl.unSelection = 0;
			}
		}
	}

	// sub menu update ?
	if ((m_sSubMenu.bOnChanged) && (!m_sMenuControl.eSelectionMovement))
	{
		m_sSubMenu.bOnChanged = false;

		// exit ?
		if (m_sSubMenu.bOnExit)
			m_sMenuControl.nMenuIx = -1;

		// loop through entries
		for (size_t nIx = 0; nIx < m_sSubMenu.asEntries.size(); nIx++)
		{
			// entry index changed ?
			if (m_sSubMenu.asEntries[nIx].bOnChanged)
			{
				m_sSubMenu.asEntries[nIx].bOnChanged = false;

				// font ?
				if (nIx == ENTRY_FONT)
				{
					// get device and context
					ID3D11Device* pcDevice = nullptr;
					ID3D11DeviceContext* pcContext = nullptr;
					HRESULT nHr = S_OK;
					if ((eD3DInterface == INTERFACE_IDXGISWAPCHAIN) && (eD3DMethod == METHOD_IDXGISWAPCHAIN_PRESENT))
						nHr = GetDeviceAndContext((IDXGISwapChain*)pThis, &pcDevice, &pcContext);
					else
					{
						if (m_ppcTexView11[0])
						{
							if (*(m_ppcTexView11[0]))
								(*(m_ppcTexView11[0]))->GetDevice(&pcDevice);
							if (pcDevice)
								pcDevice->GetImmediateContext(&pcContext);
							else nHr = E_FAIL;
							if (!pcContext) nHr = E_FAIL;
						}
						else
							nHr = E_FAIL;
					}
					if (SUCCEEDED(nHr))
					{
						HRESULT nHr;
						// get base directory
						std::string strVireioPath = GetBaseDir();

						// add file path
						strVireioPath += "font//";
						strVireioPath += m_sSubMenu.asEntries[nIx].astrValueEnumeration[m_sSubMenu.asEntries[nIx].unValue];
						strVireioPath += ".spritefont";
						OutputDebugStringA(strVireioPath.c_str());

						// create font, make backup
						VireioFont* pcOldFont = m_pcFontSegeo128;
						m_pcFontSegeo128 = new VireioFont(pcDevice, pcContext, strVireioPath.c_str(), 128.0f, 1.0f, nHr, 1);
						if (FAILED(nHr))
						{
							delete m_pcFontSegeo128; m_pcFontSegeo128 = pcOldFont;
						}
						else
						{
							// set new font name
							m_strFontName = m_sSubMenu.asEntries[nIx].astrValueEnumeration[m_sSubMenu.asEntries[nIx].unValue];

							// write to ini file
							char szFilePathINI[1024];
							GetCurrentDirectoryA(1024, szFilePathINI);
							strcat_s(szFilePathINI, "\\VireioPerception.ini");
							WritePrivateProfileStringA("Stereo Presenter", "strFontName", m_strFontName.c_str(), szFilePathINI);
						}
					}
					SAFE_RELEASE(pcDevice);
					SAFE_RELEASE(pcContext);
				}

			}
		}
	}

	// get xbox controller input
	XINPUT_STATE sControllerState;
	bool bControllerAttached = false;
	ZeroMemory(&sControllerState, sizeof(XINPUT_STATE));
	if (XInputGetState(0, &sControllerState) == ERROR_SUCCESS)
	{
		bControllerAttached = true;
	}

	if (true)
	{
#pragma region menu hotkeys
		static bool bReleased = true;
		static bool s_bOnMenu = false;

		// keyboard menu on/off event + get hand poses
		UINT uIxHandPoses = 0, uIxPoseRequest = 0;
		s_bOnMenu = GetAsyncKeyState(VK_LCONTROL) && GetAsyncKeyState(0x51);
		for (UINT unIx = 0; unIx < 32; unIx++)
		{
			// set menu bool event
			if (m_apsSubMenues[unIx])
			{
				if (m_apsSubMenues[unIx]->bOnBack)
				{
					// main menu ? exit
					if ((m_sMenuControl.nMenuIx == -1) && (!m_sMenuControl.eSelectionMovement))
						s_bOnMenu = true;
					else
						m_abMenuEvents[VireioMenuEvent::OnExit] = TRUE;

					m_apsSubMenues[unIx]->bOnBack = false;
				}

				// hand poses ?
				if (m_apsSubMenues[unIx]->bHandPosesPresent)
					uIxHandPoses = unIx;
				if (m_apsSubMenues[unIx]->bHandPosesRequest)
					uIxPoseRequest = unIx;
			}
		}
		if ((m_apsSubMenues[uIxHandPoses]) && (m_apsSubMenues[uIxPoseRequest]))
		{
			// copy the hand pose data to the request node
			m_apsSubMenues[uIxPoseRequest]->sPoseMatrix[0] = m_apsSubMenues[uIxHandPoses]->sPoseMatrix[0];
			m_apsSubMenues[uIxPoseRequest]->sPoseMatrix[1] = m_apsSubMenues[uIxHandPoses]->sPoseMatrix[1];
			m_apsSubMenues[uIxPoseRequest]->sPosition[0] = m_apsSubMenues[uIxHandPoses]->sPosition[0];
			m_apsSubMenues[uIxPoseRequest]->sPosition[1] = m_apsSubMenues[uIxHandPoses]->sPosition[1];
		}

		// static hotkeys :  LCTRL+Q - toggle vireio menu
		//                   F12 - toggle stereo output
		if (GetAsyncKeyState(VK_F12))
		{
			m_bHotkeySwitch = true;
		}
		else
		if (s_bOnMenu)
		{
			m_bMenuHotkeySwitch = true;
		}
		else
		if (m_bMenuHotkeySwitch)
		{
			m_bMenuHotkeySwitch = false;
			m_bMenu = !m_bMenu;
			for (UINT unIx = 0; unIx < 32; unIx++)
			{
				// set sub menu active if menu is active
				if (m_apsSubMenues[unIx])
					m_apsSubMenues[unIx]->bIsActive = m_bMenu;
			}
		}
		else
		if (m_bHotkeySwitch)
		{
			if (m_eStereoMode) m_eStereoMode = VireioMonitorStereoModes::Vireio_Mono; else m_eStereoMode = VireioMonitorStereoModes::Vireio_SideBySide;
			m_bHotkeySwitch = false;
		}
		else
			bReleased = true;
#pragma endregion
#pragma region menu events
		// menu is shown ?
		if (m_bMenu)
		{
			// handle controller
			if (bControllerAttached)
			{
				if (sControllerState.Gamepad.wButtons & XINPUT_GAMEPAD_BACK)
				{
					m_abMenuEvents[VireioMenuEvent::OnExit] = TRUE;
				}
				if (sControllerState.Gamepad.wButtons & XINPUT_GAMEPAD_A)
				{
					m_abMenuEvents[VireioMenuEvent::OnAccept] = TRUE;
				}
				if (sControllerState.Gamepad.sThumbLY > 28000)
					m_abMenuEvents[VireioMenuEvent::OnUp] = TRUE;
				if (sControllerState.Gamepad.sThumbLY < -28000)
					m_abMenuEvents[VireioMenuEvent::OnDown] = TRUE;
				if (sControllerState.Gamepad.sThumbLX > 28000)
					m_abMenuEvents[VireioMenuEvent::OnRight] = TRUE;
				if (sControllerState.Gamepad.sThumbLX < -28000)
					m_abMenuEvents[VireioMenuEvent::OnLeft] = TRUE;
			}

			// loop through sub menues
			for (UINT unIx = 0; unIx < 32; unIx++)
			{
				// set bool events
				if (m_apsSubMenues[unIx])
				{
					if (m_apsSubMenues[unIx]->bOnUp) m_abMenuEvents[VireioMenuEvent::OnUp] = TRUE;
					if (m_apsSubMenues[unIx]->bOnDown) m_abMenuEvents[VireioMenuEvent::OnDown] = TRUE;
					if (m_apsSubMenues[unIx]->bOnLeft) m_abMenuEvents[VireioMenuEvent::OnLeft] = TRUE;
					if (m_apsSubMenues[unIx]->bOnRight) m_abMenuEvents[VireioMenuEvent::OnRight] = TRUE;
					if (m_apsSubMenues[unIx]->bOnAccept) m_abMenuEvents[VireioMenuEvent::OnAccept] = TRUE;

					// clear events
					m_apsSubMenues[unIx]->bOnUp = false;
					m_apsSubMenues[unIx]->bOnDown = false;
					m_apsSubMenues[unIx]->bOnLeft = false;
					m_apsSubMenues[unIx]->bOnRight = false;
					m_apsSubMenues[unIx]->bOnAccept = false;
					m_apsSubMenues[unIx]->bOnBack = false;
				}
			}
#pragma endregion
#pragma region menu update/render

			// update
			UpdateMenu(fGlobalTime);

			// get device and context
			ID3D11Device* pcDevice = nullptr;
			ID3D11DeviceContext* pcContext = nullptr;
			HRESULT nHr = S_OK;
			if ((eD3DInterface == INTERFACE_IDXGISWAPCHAIN) && (eD3DMethod == METHOD_IDXGISWAPCHAIN_PRESENT))
				nHr = GetDeviceAndContext((IDXGISwapChain*)pThis, &pcDevice, &pcContext);
			else
			{
				if (m_ppcTexView11[0])
				{
					if (*(m_ppcTexView11[0]))
						(*(m_ppcTexView11[0]))->GetDevice(&pcDevice);
					if (pcDevice)
						pcDevice->GetImmediateContext(&pcContext);
					else nHr = E_FAIL;
					if (!pcContext) nHr = E_FAIL;
				}
				else
					nHr = E_FAIL;
			}
			if (FAILED(nHr))
			{
				// release frame texture+view
				if (pcDevice) { pcDevice->Release(); pcDevice = nullptr; }
				if (pcContext) { pcContext->Release(); pcContext = nullptr; }
				return nullptr;
			}
			// create the depth stencil... if D3D11
			if ((eD3DInterface == INTERFACE_IDXGISWAPCHAIN) && (eD3DMethod == METHOD_IDXGISWAPCHAIN_PRESENT) && (!m_pcDSGeometry11))
			{
				ID3D11Texture2D* pcBackBuffer = nullptr;
				((IDXGISwapChain*)pThis)->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pcBackBuffer);

				if (pcBackBuffer)
				{
					D3D11_TEXTURE2D_DESC sDesc;
					pcBackBuffer->GetDesc(&sDesc);
					pcBackBuffer->Release();

					// Create depth stencil texture
					D3D11_TEXTURE2D_DESC descDepth;
					ZeroMemory(&descDepth, sizeof(descDepth));
					descDepth.Width = sDesc.Width;
					descDepth.Height = sDesc.Height;
					descDepth.MipLevels = 1;
					descDepth.ArraySize = 1;
					descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
					descDepth.SampleDesc.Count = 1;
					descDepth.SampleDesc.Quality = 0;
					descDepth.Usage = D3D11_USAGE_DEFAULT;
					descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
					descDepth.CPUAccessFlags = 0;
					descDepth.MiscFlags = 0;
					if (FAILED(pcDevice->CreateTexture2D(&descDepth, NULL, &m_pcDSGeometry11)))
						OutputDebugString(L"[STP] Failed to create depth stencil.");

					// Create the depth stencil view
					D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
					ZeroMemory(&descDSV, sizeof(descDSV));
					descDSV.Format = descDepth.Format;
					descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
					descDSV.Texture2D.MipSlice = 0;
					if (FAILED(pcDevice->CreateDepthStencilView(m_pcDSGeometry11, &descDSV, &m_pcDSVGeometry11)))
						OutputDebugString(L"[STP] Failed to create depth stencil view.");
				}
			}

			// get the viewport
			UINT dwNumViewports = 1;
			D3D11_VIEWPORT psViewport[16];
			pcContext->RSGetViewports(&dwNumViewports, psViewport);

			// backup all states
			D3DX11_STATE_BLOCK sStateBlock;
			CreateStateblock(pcContext, &sStateBlock);

			// clear all states, set targets
			ClearContextState(pcContext);

			// set the menu texture (if present)
			if (m_ppcTexViewMenu)
			{
				if (*m_ppcTexViewMenu)
				{
					// set render target
					ID3D11RenderTargetView* pcRTView = *m_ppcTexViewMenu;
					pcContext->OMSetRenderTargets(1, &pcRTView, NULL);

					// set viewport
					D3D11_VIEWPORT sViewport = {};
					sViewport.TopLeftX = 0;
					sViewport.TopLeftY = 0;
					sViewport.Width = 1024;
					sViewport.Height = 1024;
					sViewport.MinDepth = 0.0f;
					sViewport.MaxDepth = 1.0f;
					pcContext->RSSetViewports(1, &sViewport);

					// clear render target...zero alpha
					FLOAT afColorRgba[4] = { 0.5f, 0.4f, 0.2f, 0.4f };
					pcContext->ClearRenderTargetView(*m_ppcTexViewMenu, afColorRgba);
				}
			}
			else
			if ((eD3DInterface == INTERFACE_IDXGISWAPCHAIN) && (eD3DMethod == METHOD_IDXGISWAPCHAIN_PRESENT))
			{
				// set first active render target - the stored back buffer - get the stored private data view
				ID3D11Texture2D* pcBackBuffer = nullptr;
				((IDXGISwapChain*)pThis)->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pcBackBuffer);
				ID3D11RenderTargetView* pcView = nullptr;
				UINT dwSize = sizeof(pcView);
				pcBackBuffer->GetPrivateData(PDIID_ID3D11TextureXD_RenderTargetView, &dwSize, (void*)&pcView);
				if (dwSize)
				{
					pcContext->OMSetRenderTargets(1, (ID3D11RenderTargetView**)&pcView, m_pcDSVGeometry11);
					pcView->Release();
				}
				else
				{
					// create render target view for the back buffer
					ID3D11RenderTargetView* pcRTV = nullptr;
					pcDevice->CreateRenderTargetView(pcBackBuffer, NULL, &pcRTV);
					if (pcRTV)
					{
						pcBackBuffer->SetPrivateDataInterface(PDIID_ID3D11TextureXD_RenderTargetView, pcRTV);
						pcRTV->Release();
					}
				}
				pcContext->RSSetViewports(dwNumViewports, psViewport);
				pcBackBuffer->Release();

				// clear the depth stencil
				pcContext->ClearDepthStencilView(m_pcDSVGeometry11, D3D11_CLEAR_DEPTH, 1.0f, 0);
			}

			// create the font class if not present 
			nHr = S_OK;
			if (!m_pcFontSegeo128)
			{
				// get base directory
				std::string strVireioPath = GetBaseDir();

				// add file path
				strVireioPath += "font//";
				strVireioPath += m_strFontName;
				strVireioPath += ".spritefont";
				OutputDebugStringA(strVireioPath.c_str());

				// create font
				m_pcFontSegeo128 = new VireioFont(pcDevice, pcContext, strVireioPath.c_str(), 128.0f, 1.0f, nHr, 1);
			}
			if (FAILED(nHr)) { delete m_pcFontSegeo128; m_pcFontSegeo128 = nullptr; }

			// render text (if font present)
			if (m_pcFontSegeo128)
			{
				m_pcFontSegeo128->SetTextAttributes(0.0f, 0.2f, 0.0001f);

				// set additional tremble for "accepted" event
				float fDepthTremble = 0.0f;
				if (m_sMenuControl.eSelectionMovement == MenuControl::SelectionMovement::Accepted)
				{
					float fActionTimeElapsed = (fGlobalTime - m_sMenuControl.fActionStartTime) / m_sMenuControl.fActionTime;
					fDepthTremble = sin(fActionTimeElapsed*PI_F) * -3.0f;
				}

				m_pcFontSegeo128->ToRender(pcContext, fGlobalTime, m_sMenuControl.fYOrigin, 30.0f, fDepthTremble);
				RenderMenu(pcDevice, pcContext);
			}
			else OutputDebugString(L"Failed to create font!");

			// set back device
			ApplyStateblock(pcContext, &sStateBlock);

			if (pcDevice) { pcDevice->Release(); pcDevice = nullptr; }
			if (pcContext) { pcContext->Release(); pcContext = nullptr; }
		}
#pragma endregion
#pragma region draw stereo (optionally)

		// draw stereo target to screen (optionally)
		if ((m_eStereoMode) && (eD3DInterface == INTERFACE_IDXGISWAPCHAIN) && (eD3DMethod == METHOD_IDXGISWAPCHAIN_PRESENT))
		{
			// DX 11
			if ((m_ppcTexView11[0]) && (m_ppcTexView11[1]))
			{
				// get device and context
				ID3D11Device* pcDevice = nullptr;
				ID3D11DeviceContext* pcContext = nullptr;
				if (FAILED(GetDeviceAndContext((IDXGISwapChain*)pThis, &pcDevice, &pcContext)))
				{
					// release frame texture+view
					if (pcDevice) { pcDevice->Release(); pcDevice = nullptr; }
					if (pcContext) { pcContext->Release(); pcContext = nullptr; }
					return nullptr;
				}

				// get the viewport
				UINT dwNumViewports = 1;
				D3D11_VIEWPORT psViewport[16];
				pcContext->RSGetViewports(&dwNumViewports, psViewport);

				// backup all states
				D3DX11_STATE_BLOCK sStateBlock;
				CreateStateblock(pcContext, &sStateBlock);

				// clear all states, set targets
				ClearContextState(pcContext);

				// set first active render target - the stored back buffer - get the stored private data view
				ID3D11Texture2D* pcBackBuffer = nullptr;
				((IDXGISwapChain*)pThis)->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pcBackBuffer);
				ID3D11RenderTargetView* pcView = nullptr;
				UINT dwSize = sizeof(pcView);
				pcBackBuffer->GetPrivateData(PDIID_ID3D11TextureXD_RenderTargetView, &dwSize, (void*)&pcView);
				if (dwSize)
				{
					pcContext->OMSetRenderTargets(1, (ID3D11RenderTargetView**)&pcView, m_pcDSVGeometry11);
					pcView->Release();
				}
				else
				{
					// create render target view for the back buffer
					ID3D11RenderTargetView* pcRTV = nullptr;
					pcDevice->CreateRenderTargetView(pcBackBuffer, NULL, &pcRTV);
					if (pcRTV)
					{
						pcBackBuffer->SetPrivateDataInterface(PDIID_ID3D11TextureXD_RenderTargetView, pcRTV);
						pcRTV->Release();
					}
				}
				pcContext->RSSetViewports(dwNumViewports, psViewport);
				pcBackBuffer->Release();

				// clear the depth stencil
				pcContext->ClearDepthStencilView(m_pcDSVGeometry11, D3D11_CLEAR_DEPTH, 1.0f, 0);

				// create all bool
				bool bAllCreated = true;

				// create vertex shader
				if (!m_pcVertexShader11)
				{
					if (FAILED(CreateVertexShaderTechnique(pcDevice, &m_pcVertexShader11, &m_pcVertexLayout11, VertexShaderTechnique::PosUV2D)))
						bAllCreated = false;
				}
				// create pixel shader... TODO !! add option to switch output
				if (!m_pcPixelShader11)
				{
					if (FAILED(CreatePixelShaderEffect(pcDevice, &m_pcPixelShader11, PixelShaderTechnique::FullscreenSimple)))
						bAllCreated = false;
				}
				// Create vertex buffer
				if (!m_pcVertexBuffer11)
				{
					if (FAILED(CreateFullScreenVertexBuffer(pcDevice, &m_pcVertexBuffer11)))
						bAllCreated = false;
				}
				// create constant buffer
				if (!m_pcConstantBufferDirect11)
				{
					if (FAILED(CreateGeometryConstantBuffer(pcDevice, &m_pcConstantBufferDirect11, (UINT)sizeof(GeometryConstantBuffer))))
						bAllCreated = false;
				}

				if (bAllCreated)
				{
					// left/right eye
					for (int nEye = 0; nEye < 2; nEye++)
					{
						// Set the input layout
						pcContext->IASetInputLayout(m_pcVertexLayout11);

						// Set vertex buffer
						UINT stride = sizeof(TexturedVertex);
						UINT offset = 0;
						pcContext->IASetVertexBuffers(0, 1, &m_pcVertexBuffer11, &stride, &offset);

						// Set constant buffer, first update it... scale and translate the left and right image
						D3DXMATRIX sScale;
						D3DXMatrixScaling(&sScale, 0.5f, 1.0f, 1.0f);
						D3DXMATRIX sTrans;
						if (nEye == 0)
							D3DXMatrixTranslation(&sTrans, -0.5f, 0.0f, 0.0f);
						else
							D3DXMatrixTranslation(&sTrans, 0.5f, 0.0f, 0.0f);
						D3DXMatrixTranspose(&sTrans, &sTrans);
						D3DXMATRIX sProj;
						D3DXMatrixMultiply(&sProj, &sTrans, &sScale);
						pcContext->UpdateSubresource((ID3D11Resource*)m_pcConstantBufferDirect11, 0, NULL, &sProj, 0, 0);
						pcContext->VSSetConstantBuffers(0, 1, &m_pcConstantBufferDirect11);

						// Set primitive topology
						pcContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

						// set texture
						pcContext->PSSetShaderResources(0, 1, m_ppcTexView11[nEye]);

						// set shaders
						pcContext->VSSetShader(m_pcVertexShader11, 0, 0);
						pcContext->PSSetShader(m_pcPixelShader11, 0, 0);

						// Render a triangle
						pcContext->Draw(6, 0);
					}
				}

				// set back device
				ApplyStateblock(pcContext, &sStateBlock);

				if (pcDevice) { pcDevice->Release(); pcDevice = nullptr; }
				if (pcContext) { pcContext->Release(); pcContext = nullptr; }
			}
		}
#pragma endregion
	}

	return nullptr;
}
Beispiel #8
0
//------------------------------------------------------------------------------
bool WxMainApp::OnInit()
{
	//get base dir
    wxString strDir;
	wxSplitPath(wxGetFullModuleName(), &strDir, NULL, NULL);
	m_strBaseDir = strDir.char_str(wxConvUTF8).data();
	m_strBaseDir += "\\";

	///////////////////////////////////////////////////////////////////////////////////////////////////
	//initialize guiex system
	try
	{
		CGUIFrameworkEditor::ms_pFramework = new CGUIFrameworkEditor( );
		CGUIFrameworkEditor::ms_pFramework->Initialize( CGUIIntSize(1024,768), "" );

		GSystem->SetDrawExtraInfo( false );
		GSystem->SetPlayingAs( false );
		GSystem->SetEditorMode( true );
	}
	catch (CGUIBaseException& rError)
	{
		wxMessageBox( Gui2wxString(rError.what()), _T("error") );

		if( CGUIFrameworkEditor::ms_pFramework )
		{
			CGUIFrameworkEditor::ms_pFramework->Release();
			delete CGUIFrameworkEditor::ms_pFramework;
			CGUIFrameworkEditor::ms_pFramework = NULL;
		}
	}

	//load scintilla dll
	m_hSciDll = LoadLibrary(_T("SciLexer.DLL"));
	if (m_hSciDll==NULL)
	{
		wxMessageBox(_T("The Scintilla DLL could not be loaded."),
			_T("Error loading Scintilla"), wxOK|wxCENTER|wxICON_ERROR,NULL);
		return false;
	}

	//load localization config file
	if( 0 != CPropertyConfigMgr::Instance()->ReadLocalizationConfig(GetBaseDir() + "../editorconfig/localization_config.xml"))
	{
		wxMessageBox(_T("failed to read config file localization_config.xml!"), _T("error"));
		return false;
	}

	//load base config file
	std::vector<wxFileName> vecBaseConfigFile;
	vecBaseConfigFile.push_back( Gui2wxString(GetBaseDir() + "../editorconfig/libguiex_editor_config.xml"));
	vecBaseConfigFile.push_back( Gui2wxString(GetBaseDir() + "../editorconfig/libguiex_editor_config_box2d.xml"));
	vecBaseConfigFile.push_back( Gui2wxString(GetBaseDir() + "../editorconfig/libguiex_editor_config_game.xml"));

	for( uint32 i=0; i<vecBaseConfigFile.size(); ++i )
	{
		if( 0 != CPropertyConfigMgr::Instance()->ReadPropertyConfig( vecBaseConfigFile[i].GetFullPath()))
		{
			wxMessageBox( wxString::Format( _T("failed to read property config file: %s"), vecBaseConfigFile[i].GetFullPath() ), _T("error"));
			return false;
		}
	}

	//load extend config file
	if( wxMessageBox( _T("Do you want to load extend widget config file?"), _T("Questing"), wxYES_NO | wxICON_QUESTION) == wxYES )
	{
		wxFileDialog aDlg(NULL, _T("Choose widget config files"), Gui2wxString(GetBaseDir() + "../editorconfig/"), wxEmptyString, _T("widget config files (*.xml)|*.xml"), wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST );
		if( wxID_OK == aDlg.ShowModal())
		{
			//try load
			wxArrayString arrayFiles;
			aDlg.GetPaths( arrayFiles );
			for( uint32 i=0; i<arrayFiles.size(); ++i )
			{
				if( std::find(vecBaseConfigFile.begin(), vecBaseConfigFile.end(), arrayFiles[i]) != vecBaseConfigFile.end() )
				{
					//base config file, ignore it
					continue;
				}

				if( 0 != CPropertyConfigMgr::Instance()->ReadPropertyConfig( arrayFiles[i]))
				{
					wxMessageBox( wxString::Format( _T("failed to read property config file: %s"), arrayFiles[i] ), _T("error"));
					return false;
				}
			}
		}
	}

	//check default property
	if( false == CheckProperty() )
	{
		wxMessageBox(_T("check default property!"), _T("error"));
		return false;
	}

	//create frame
	wxFrame* frame = new WxMainFrame(NULL,
		wxID_ANY,
		wxT("libguiex editor"),
		wxDefaultPosition,
		wxSize(1024, 768));
	SetTopWindow(frame);
	frame->Show();

	wxToolTip::Enable(true);
	wxToolTip::SetDelay(1000);

	return true;
}
Beispiel #9
0
void GOrgueStdPath::InitLocaleDir()
{
#ifndef __WXMAC__
	wxLocale::AddCatalogLookupPathPrefix(GetBaseDir() + wxFILE_SEP_PATH +  wxT("share") + wxFILE_SEP_PATH + wxT("locale"));
#endif
}