Пример #1
0
void TestSerialize(VisBaseEntity_cl *pEntity)
{
  // create a clone of the entity via serializing it to a memory stream
  VClipboardPtr m_spClipboard = new VClipboard(); // for memory streams
  {
    // write the entity into a memory clipboard
    IVFileOutStream *pMemStream = m_spClipboard->Create("MemoryStream");
    VArchive ar("TestArchive",pMemStream,Vision::GetTypeManager());
      ar << Vision::GetArchiveVersion();
      ar << pEntity;
    ar.Close();
    pMemStream->Close();
  }
  {
    // ...and load again as a separate instance running parallel
    IVFileInStream *pMemStream = m_spClipboard->Open("MemoryStream");
    VArchive ar("TestArchive",pMemStream,Vision::GetTypeManager());
      int iVers;
      ar >> iVers;
      ar.SetLoadingVersion(iVers);
      VisBaseEntity_cl *pEntity1 = (VisBaseEntity_cl *)ar.ReadObject(NULL);
    ar.Close();
    pMemStream->Close();
    pEntity1->IncPosition(10.f,0,0); // shift to the side so we can see whether both are synchronous
  }
}
bool VTerrainSectorRenderer::SaveRenderTarget(VTerrainSector* pSector, VisRenderableTexture_cl *pTex, const char *szFilePath)
{
  VASSERT(pSector);

  // since the functions below require an absolute path, we somehow need to get from a relative path to an absolute path
  // opening a file and getting its then final path is the only way, that I found, to accomplish this
  char szAbsFilename[FS_MAX_PATH];

  // create the file and convert the relative path into an absolute path
  IVFileOutStream* pStream = Vision::File.Create (szFilePath);
  if (!pStream)
    return false;

  strcpy (szAbsFilename, pStream->GetFileName());
  pStream->Close();

  VRCSHelper::RCSEditFile(szAbsFilename);

  if (pTex==NULL)
    return false;

  int sx = pTex->GetTextureWidth();
  int sy = pTex->GetTextureHeight();

  Image_cl image;
  VMemoryTempBuffer<512*512*3> buffer(sx*sy*3);
  UBYTE* pDest = (UBYTE*)buffer.GetBuffer();
  Vision::Game.WriteScreenToBuffer(0, 0, sx, sy, pDest, pTex);
  if(Vision::Renderer.GetSRGBMode() == V_SRGB_ASSUME_FOR_DIFFUSE)
  {
    for (int i = 0; i < sx*sy*3; ++i)
      pDest[i] = (UBYTE) (LinearToSrgb (((float) pDest[i]) / 255.0f) * 255.0f);
  }

  // The terrain sector renderer leaves a border area around the sector being rendered,
  // this is required to ensure proper texture filtering on sector edges. Into this border area
  // the neighbor sectors are rendered to, but not each sector has a neighbor on each side, thus the next
  // step fills all the pixels where nothing has been rendered to.
  FillBorders(pSector, sx, sy, m_iBorderWidth, pDest);

  image.AddColorMap(sx,sy,COLORDEPTH_24BPP,pDest);

  int iSavingResult = -1;

  if (VFileHelper::HasExtension(szAbsFilename,"BMP"))
    iSavingResult = image.SaveBMP(szAbsFilename);
  else if (VFileHelper::HasExtension(szAbsFilename,"JPG"))
    iSavingResult = image.SaveJPEG(szAbsFilename);
  else if (VFileHelper::HasExtension(szAbsFilename,"JPEG"))
    iSavingResult = image.SaveJPEG(szAbsFilename);
  else if (VFileHelper::HasExtension(szAbsFilename,"TGA"))
    iSavingResult = image.SaveTGA(szAbsFilename);
  else if (VFileHelper::HasExtension(szAbsFilename,"DDS"))
    iSavingResult = image.SaveUncompressedDDS(szAbsFilename);

  VRCSHelper::RCSAddFile(szAbsFilename, true /* Binary file */);

  return iSavingResult == 0;
}
Пример #3
0
inline void VGroupInstanceFile::Close(bool bCloseStream)
{
  VASSERT_MSG(m_iInstanceCount==0, "mismatch number of instances read or written");
  if (m_pIn) {if (bCloseStream) m_pIn->Close();m_pIn=NULL;}
  if (m_pOut) {if (bCloseStream) m_pOut->Close();m_pOut=NULL;}
  m_iInstanceCount = 0;
  m_eFlags = VGroupInstance::INSTANCE_UNDEFINED;
}
void VRestoreScreen::SaveBackgroundScreenshot()
{
  // GrabBackgroundScreenshot() needs to be called before
  if (m_pScreenshotBuffer == NULL)
    return;

  const int iScreenWidth = Vision::Video.GetXRes();
  const int iScreenHeight = Vision::Video.GetYRes();
  ColorCorrect(m_pScreenshotBuffer, iScreenWidth, iScreenHeight, m_fBrightness, m_fSaturation);

  // use VTEX to scale and save the image
  Image_cl image;
  ImageMap_cl colorMap(iScreenWidth, iScreenHeight, 24, static_cast<UBYTE*>(m_pScreenshotBuffer));
  image.AddColorMap(colorMap);

  // Decide which resolution to use for the saved image.
  int iScaledWidth = 512;
  while (iScaledWidth > iScreenWidth || iScaledWidth > iScreenHeight)
  {
    iScaledWidth /= 2;
    VASSERT(iScaledWidth > 0);
  }

  image.Scale(iScaledWidth, iScaledWidth);

  const char* szFilename = ":app_cache/vision_background.bmp";
  IVFileOutStream* pOut = Vision::File.Create(szFilename);
  const bool bSaved = (image.SaveBMP(pOut) == VERR_NOERROR);
  V_SAFE_DELETE_ARRAY(m_pScreenshotBuffer);

  if (pOut != NULL)
    pOut->Close();

  if (bSaved)
  {
    // Set up loading screen settings.
    Settings settings(szFilename);
    settings.m_eAspectRatioAlignment = ALIGN_NONE;
    SetSettings(settings);
  }
  else
  {
    hkvLog::Dev("VRestoreScreen: Could not save backgrounding screenshot\n");
  }
}
Пример #5
0
BOOL VDialog::SaveToBinaryFile(const char *szFilename)
{
  // no file extension? Then add default binary extension
  char szBuffer[FS_MAX_PATH];
  if (VFileHelper::GetExtensionPos(szFilename)<0)
  {
    VFileHelper::AddExtension(szBuffer, szFilename, DIALOG_BINARYFILEEXT);
    szFilename = szBuffer;
  }

  IVFileOutStream *pOut = Vision::File.Create(szFilename);
  if (!pOut)
    return FALSE;

  VArchive ar(NULL, pOut, Vision::GetTypeManager());
  ar << (int)Vision::GetArchiveVersion();
  ar.WriteObject(this);
  ar.Close();
  pOut->Close();
  return TRUE;
}
Пример #6
0
bool hkvPrefabAsset::GenerateThumbnail(const char* libraryPath, const char* assetPath, const char* thumbnailPath)
{
  hkStringBuf sFilename(libraryPath);
  sFilename.pathAppend(assetPath);

  TiXmlDocument doc;
  if (!doc.LoadFile(sFilename.cString()))
  {
    return true;
  }

  if (doc.RootElement() == NULL)
    return true;

  // Proceed if any only if there is actually a thumbnail node
  TiXmlElement* pThumbnailNode = doc.RootElement()->FirstChildElement("thumbnail");
  if (pThumbnailNode == NULL)
    return true;

  IVFileOutStream* pFile = VFileAccessManager::GetInstance()->Create(thumbnailPath);
  if (pFile == NULL)
    return true;

  int iSize = 0;
  pThumbnailNode->QueryIntAttribute("size", &iSize);

  // Convert base64 encoded data back to binary form
  char* imageData = new char[iSize];
  hkXmlObjectReader::base64read(hkIstream(pThumbnailNode->GetText(), (int)strlen(pThumbnailNode->GetText())).getStreamReader(), imageData, iSize);

  // Write image to disk
  pFile->Write(imageData, iSize);
  pFile->Close();

  delete[] imageData;

  return true;
}
Пример #7
0
VBool SaveGame(int iNum)
{
  if ( (iNum < 1) || (iNum > 4) )
  {
    // we just allow 4 save games
    return FALSE;
  }

  int i;
  char pszSaveFileName[FS_MAX_PATH];

  sprintf(pszSaveFileName,SAVEGAME_NAME, iNum);
  IVFileOutStream* pOut = Vision::File.Create(pszSaveFileName);
  // creating the file didn't work!
  if (!pOut)
  {
    return FALSE;
  }

  VArchive ar( pszSaveFileName, pOut, Vision::GetTypeManager() );

  // serialize global game data
  ar << ARCHIVE_START_TAG; 		      // magic number
  int iSavingVersion = Vision::GetArchiveVersion();
  ar << iSavingVersion;             // archive class version
  ar << g_iCurrentMap;              // current map number
  ar << Vision::GetTimer()->GetTime();		// current time

  // count entities
  SerializeBaseEntity_cl *pSerEnt = NULL;
  VisBaseEntity_cl *pEnt = NULL;
  int iFullCtr = 0;
  int iReCreateCtr = 0;
  int iNumOfAllEntities = VisBaseEntity_cl::ElementManagerGetSize();
  for (i = 0; i < iNumOfAllEntities; i++)
  {
    pEnt = VisBaseEntity_cl::ElementManagerGet(i);
    if ( pEnt )
    {
      if ( pEnt->IsOfType(SerializeBaseEntity_cl::GetClassTypeId()) )
      {
        pSerEnt = static_cast<SerializeBaseEntity_cl*>(pEnt);
        if ( pSerEnt->GetSerializeType() == SERIALIZE_FULL )
          iFullCtr++;
        else
          iReCreateCtr++;
      }
    }
  }

  // serialize number of entities
  ar << iReCreateCtr;
  ar << iFullCtr;

  hkvVec3 vTemp;

  // do ReCreate serialization of entities
  for (i = 0; i < iNumOfAllEntities; i++)
  {
    pEnt = VisBaseEntity_cl::ElementManagerGet(i);
    if ( pEnt )
    {
      if ( pEnt->IsOfType(SerializeBaseEntity_cl::GetClassTypeId()) )
      {
        pSerEnt = (SerializeBaseEntity_cl *) pEnt;
        if ( pSerEnt->GetSerializeType() == SERIALIZE_RECREATE )
        {
          char pszEntityParams[4000];
          GetEntityParameters( pSerEnt, pszEntityParams );
          VDynamicMesh* pMesh = pSerEnt->GetMesh();
          ar << pSerEnt->GetClassFullName() << pSerEnt->GetEntityKey();
          vTemp = pSerEnt->GetPosition();
          vTemp.SerializeAsVisVector (ar);
          vTemp = pSerEnt->GetOrientation();
          vTemp.SerializeAsVisVector (ar);
          const char *szFilename = pMesh ? pMesh->GetFilename() : NULL;
          ar << szFilename << pszEntityParams;
        }
      }
    }
  }

  // do full serialization of entities
  for (i = 0; i < iNumOfAllEntities; i++)
  {
    pEnt = VisBaseEntity_cl::ElementManagerGet(i);
    if ( pEnt )
    {
      if ( pEnt->IsOfType(SerializeBaseEntity_cl::GetClassTypeId()) )
      {
        pSerEnt = (SerializeBaseEntity_cl *) pEnt;
        if ( pSerEnt->GetSerializeType() == SERIALIZE_FULL )
        {
          ar << pSerEnt;
        }
      }
    }
  }

  // store end tag - useful to verify a valid archive
  ar << ARCHIVE_END_TAG;

  ar.Close();
  pOut->Close();

  g_SaveSlot[iNum-1].SaveScreenShotPreview();

  return TRUE;
}