void OMXMLReaderExpat::characterDataHandler(const XML_Char* s, int len) { TRACE("OMXMLReaderExpat::characterDataHandler"); // Note: s is not null terminated #if defined(XML_UNICODE_WCHAR_T) wchar_t* workBuffer = getWorkBuffer(len + 1); memcpy(workBuffer, s, len * sizeof(wchar_t)); workBuffer[len] = L'\0'; setCharacterData(workBuffer); #elif defined(XML_UNICODE) wchar_t* workBuffer = getWorkBuffer(len + 1); const XML_Char* inPtr = s; wchar_t* outPtr = workBuffer; for (int i = 0; i < len; i++) { *outPtr = (wchar_t)*inPtr; outPtr++; inPtr++; } *outPtr = L'\0'; setCharacterData(workBuffer); #else char* workBuffer = (char*)getWorkBuffer(len + 1); memcpy(workBuffer, s, len * sizeof(char)); workBuffer[len] = '\0'; wchar_t* out = utf8ToUTF16(workBuffer); setCharacterData(out); delete [] out; #endif XML_Status status = XML_StopParser(_parser, true); if (status != XML_STATUS_OK) { XML_Error errorCode = XML_GetErrorCode(_parser); if (errorCode != XML_ERROR_SUSPENDED) { throw OMException(getErrorString()); } } registerEvent(CHARACTERS); }
EngineMain::EngineMain(HINSTANCE hInstance, std::wstring winCaption, D3DDEVTYPE devType, DWORD requestedVP) : D3DApp(hInstance, winCaption, devType, requestedVP) { if(!checkDeviceCaps()) { MessageBox(0, L"checkDeviceCaps() Failed", 0, 0); PostQuitMessage(0); } Shaders::InitAll(); InitAllVertexDeclarations(); m_GfxStats = new GfxStats(); m_DirLight.Direction = D3DXVECTOR3(0.0f, 1.0f, 2.0f); D3DXVec3Normalize(&m_DirLight.Direction, &m_DirLight.Direction); m_DirLight.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); m_DirLight.Diffuse = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f); m_DirLight.Specular = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f); camera.SetPosition(D3DXVECTOR3(0.0f, 0.0f, -10.0f)); camera.SetTarget(D3DXVECTOR3(0.0f, 3.0f, 0.0f)); camera.SetRotation(D3DXVECTOR3(0.0f, 1.0f, 0.0f)); dwarf = new Model(L"dwarf.x"); skull = new Model(L"skullocc.x"); tiny = new Model(L"tiny.x"); m_GfxStats->addVertices(skull->m_Model->GetNumVertices()); m_GfxStats->addTriangles(skull->m_Model->GetNumFaces()); m_GfxStats->addVertices(dwarf->m_Model->GetNumVertices()); m_GfxStats->addTriangles(dwarf->m_Model->GetNumFaces()); m_GfxStats->addVertices(tiny->m_Model->GetNumVertices()); m_GfxStats->addTriangles(tiny->m_Model->GetNumFaces()); skull->InitModel(D3DXVECTOR3(-4.0f, 3.0f, 100.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f), 0.0f); skull->Scale(0.5f); dwarf->InitModel(D3DXVECTOR3(0.0f, 3.0f, -10.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f), 0.0f); dwarf->Scale(1.0f); tiny->InitModel(D3DXVECTOR3(0.0f, 3.0f, -10.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f), 0.0f); tiny->Scale(0.01f); #pragma region Grid mLightVecW = D3DXVECTOR3(0.0, 0.707f, -0.707f); mDiffuseMtrl = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mDiffuseLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mAmbientMtrl = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mAmbientLight = D3DXCOLOR(0.6f, 0.6f, 0.6f, 1.0f); mSpecularMtrl = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f); mSpecularLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mSpecularPower = 8.0f; std::wstring groundTex = utf8ToUTF16(std::string("../Render/models/ground0.dds")); HR(D3DXCreateTextureFromFile(g_d3dDevice, groundTex.c_str(), &mGroundTex)); buildFX(); buildGridGeometry(); #pragma endregion onResetDevice(); }
OMUInt32 OMXMLReaderExpat::readCharacters(wchar_t* out, const XML_Char* in, wchar_t terminator) { TRACE("OMXMLReaderExpat::readCharacters(wchar_t*,XML_Char*,wchar_t)"); OMUInt32 len = 0; #if !defined(XML_UNICODE) #if defined (XML_UNICODE_WCHAR_T) wchar_t* src = in; #else wchar_t* src = utf8ToUTF16(in); #endif if (terminator == L'\0') { wcscpy(out, src); len = wcslen(out); } else { wchar_t* atTerminator = wcschr(src, terminator); if (atTerminator == 0) { // no terminator means no data len = 0; *out = L'\0'; } else { wcsncpy(out, src, (OMUInt32)(atTerminator - src)); out[(OMUInt32)(atTerminator - src)] = L'\0'; len = (OMUInt32)(atTerminator - src); } } #if !defined (XML_UNICODE_WCHAR_T) delete [] src; #endif #else // XML_UNICODE wchar_t* outPtr = out; const XML_Char* inPtr = in; *outPtr = (wchar_t)*inPtr; while ((wchar_t)(*inPtr) != L'\0' && (wchar_t)(*inPtr) != terminator) { outPtr++; inPtr++; len++; *outPtr = (wchar_t)*inPtr; } if ((wchar_t)(*inPtr) == terminator) { *outPtr = L'\0'; } else if ((wchar_t)(*inPtr) == L'\0') { // no terminator means no data len = 0; *out = L'\0'; } #endif return len; }