void VWindowBase::Serialize( VArchive &ar ) { VisTypedEngineObject_cl::Serialize(ar); char iLocalVersion = 0; const char *szScriptFile = NULL; if (ar.IsLoading()) { ar >> iLocalVersion; VASSERT_MSG(iLocalVersion==0,"Invalid version"); ar >> m_pOwner; VMemoryTempBuffer<1024> buffer; m_iID = VGUIManager::GetID(buffer.ReadStringBinary(ar)); ar >> m_iDialogResult >> m_iOrder >> m_iTabOrder >> m_iStatus; ar >> m_vPosition >> m_vSize >> m_ClientAreaBorder; ar >> m_sTooltipText; szScriptFile = buffer.ReadStringBinary(ar); } else
void VTextState::Paint(VGraphicsInfo *pGraphics, VWindowBase *pParentWnd, VColorRef iColor) { m_iNumTextLines = 0; const char *szText = GetText(); if (!m_spFont || !szText || !szText[0]) return; VSimpleRenderState_t state = VGUIManager::DefaultGUIRenderState(); if (m_fFontScaling!=1.0f) state.SetFlag(RENDERSTATEFLAG_FILTERING); VRectanglef v = pParentWnd->GetBoundingBox(); // clipping box of parent control if (m_bTextWrap) { float fMaxWidth = v.GetSizeX()/m_fFontScaling; float fLineHeight = m_spFont->GetFontHeight() * m_fRelativeFontHeight * m_fFontScaling; hkvVec2 vPos = v.m_vMin; const char *szStart = szText; VMemoryTempBuffer<512> tmpBuffer; while (szStart[0]) { // byte offsets int iOffset; int iNextOffset; // search for next newline const char *pCR = strchr(szStart, '\n'); // compute automatic wrap character index int iCharCount = m_spFont->GetCharacterIndexAtPos(szStart, fMaxWidth, -1, false); int iWrapOffset = VString::GetUTF8CharacterOffset(szStart, iCharCount); if (pCR != NULL && (pCR - szStart) < iCharCount) { // newline occurs before automatic text wrap iOffset = static_cast<int>(pCR - szStart); iNextOffset = iOffset + 1; } else { // automatic text wrap iOffset = iWrapOffset; // try to find white space if (iOffset > 0) { while (iOffset > 0 && szStart[iOffset] != 0 && szStart[iOffset] != ' ') iOffset--; if (iOffset == 0) // no whitespace found? then wrap inside word iOffset = iWrapOffset; } else iOffset = 1; iNextOffset = iOffset; } // put together line const int iLineBufferSize = (iOffset+1) * sizeof(char); tmpBuffer.EnsureCapacity(iLineBufferSize); char *szLineBuffer = static_cast<char*>(tmpBuffer.GetBuffer()); memcpy(szLineBuffer, szStart, iLineBufferSize); szLineBuffer[iOffset] = 0; m_iNumTextLines++; // draw line if (pGraphics) { hkvVec2 vAlignedPos = m_spFont->GetTextPositionOfs(szLineBuffer, v.GetSize(), m_hAlign, m_vAlign) * m_fFontScaling; vAlignedPos.set(vAlignedPos.x + vPos.x, vPos.y); // only consider the x-ofs m_spFont->PrintText(&pGraphics->Renderer, vAlignedPos, szLineBuffer, iColor, state, m_fFontScaling, m_pCustomBBox ? m_pCustomBBox : &v); } vPos.y += fLineHeight; szStart = &szStart[iNextOffset]; while (szStart[0] == ' ') szStart++; } return; } // recompute the alignment offset if (!m_bAlignmentValid) { m_vCurrentOfs = m_vOfs + m_spFont->GetTextPositionOfs(szText, v.GetSize(), m_hAlign,m_vAlign) * m_fFontScaling; m_bAlignmentValid = true; } m_iNumTextLines = 1; if (pGraphics) { m_spFont->PrintText(&pGraphics->Renderer, v.m_vMin+m_vCurrentOfs, szText, iColor, state, m_fFontScaling, m_pCustomBBox ? m_pCustomBBox : &v); } }
// --------------------------------------------------------------------------------- // Method: LoadGame // Notes: The file format for save games in this example is as follows: // // "SERIALIZE_API_SAMPLE" magic "number" (a string, really) // <version> // <map_number> the current map number // <time> the current game timer's value // <num_recreate_ent> number of re-creatable entities // <num_full_ent> number of fully serialized entities // <recreate_ent>... re-creatable entity data // <full_ent>... fully serialized entities // "END_OF_ARCHIVE" ending key (useful for validating the file) // // --------------------------------------------------------------------------------- VBool LoadGame(int iNum) { if ( (iNum < 1) || (iNum > 6) ) { return FALSE; } GameLoadData_t snap; int i; char pszLoadFileName[FS_MAX_PATH]; char szArchiveTag[FS_MAX_PATH]; sprintf(pszLoadFileName,SAVEGAME_NAME, iNum); IVFileInStream* pIn = Vision::File.Open(pszLoadFileName); // opening the file didn't work! if (!pIn) return FALSE; VArchive ar( pszLoadFileName, pIn, Vision::GetTypeManager() ); ar.ReadStringBinary(szArchiveTag, FS_MAX_PATH); if (strcmp(szArchiveTag, ARCHIVE_START_TAG) != 0) { return FALSE; } ar >> i; // loading version ar.SetLoadingVersion(i); if (! Vision::IsValidArchive(ar)) { // TODO return FALSE; } ar >> snap.iMapNumber; // map number if (snap.iMapNumber == g_iCurrentMap) snap.bJustReset = TRUE; else snap.bJustReset = FALSE; ar >> snap.fTime; // game timer ar >> snap.iRecreateEntityCount;// number of re-createable entities ar >> snap.iFullEntityCount; // number of fullly serialized entities //snap.bJustReset = FALSE; if (snap.bJustReset == TRUE) { // as it's the same map, we just clean up and re-use it :-) ResetWorld(); } else { // load the other map (without entities) LoadMap(snap.iMapNumber,FALSE); } Vision::GetTimer()->SetTime(snap.fTime); // now re-create all the "RECREATE" entities VMemoryTempBuffer<1024> modelFileName; VMemoryTempBuffer<1024> entityParams; VMemoryTempBuffer<1024> entityKey; VMemoryTempBuffer<1024> className; // now re-create all the "RECREATE" entities for (i = 0; i < snap.iRecreateEntityCount; i++) { char* pszClassName; char* pszEntityKey; hkvVec3 vOrigin; hkvVec3 vOrientation; char* pszModelFile; char* pszEntityParams; // get entity data pszClassName = className.ReadStringBinary(ar); pszEntityKey = entityKey.ReadStringBinary(ar); vOrigin.SerializeAsVisVector (ar); vOrientation.SerializeAsVisVector (ar); pszModelFile = modelFileName.ReadStringBinary(ar); pszEntityParams = entityParams.ReadStringBinary(ar); SerializeBaseEntity_cl* pSerEnt = static_cast<SerializeBaseEntity_cl*>( Vision::Game.CreateEntity(pszClassName, vOrigin, pszModelFile, pszEntityParams)); pSerEnt->SetOrientation(vOrientation); pSerEnt->SetEntityKey(pszEntityKey); } // finally, re-create all the "FULL" entities for (i = 0; i < snap.iFullEntityCount; i++) { SerializeBaseEntity_cl *pSerEnt; // get an entity from the archive... ar >> pSerEnt; } // check if the ARCHIVE_END_TAG exists ar.ReadStringBinary(szArchiveTag, FS_MAX_PATH); if (strcmp(szArchiveTag, ARCHIVE_END_TAG) != 0) { Vision::Error.FatalError("No (or invalid) end tag found in save game!"); ar.Close(); pIn->Close(); return FALSE; } ar.Close(); pIn->Close(); return TRUE; }