Esempio n. 1
0
BOOL VPrefab::Reload()
{
  if (IsMissing())
    return FALSE;
  IVFileInStream *pIn;
  if (GetParentManager()!=NULL)
    pIn = GetParentManager()->CreateFileInStream(GetFilename(),this);
  else
    pIn = Vision::File.Open(GetFilename());
  if (pIn==NULL)
  {
    FlagAsMissing();
    return FALSE;
  }
  // must match saving code by vForge
  pIn->Read(&m_Header,sizeof(m_Header),"6i");
  m_iSize = pIn->GetSize() - sizeof(m_Header);

  // header validation:
  if (m_iSize<0 || m_Header.m_iArchiveVersion<0 || m_Header.m_iArchiveVersion>Vision::GetArchiveVersion() 
   || m_Header.m_iLocalVersion<0 || m_Header.m_iLocalVersion>VPREFAB_BINARY_VERSION_CURRENT)
  {
    pIn->Close();
    hkvLog::Warning("Cannot load VPrefab '%s': Invalid version or broken file", GetFilename());
    FlagAsMissing();
    return FALSE;
  }

  m_BinaryBlock.EnsureCapacity(m_iSize);
  pIn->Read(m_BinaryBlock.GetBuffer(),m_iSize);

  pIn->Close();

  return TRUE;
}
void vHavokBehaviorScriptAssetLoader::loadScript(char const *filePath, bool forceLoad)
{
  hkStorageStringMap<ScriptEntry*>& scriptEntries = accessScriptEntries();

  // Check for cached script
  ScriptEntry* cachedEntry = HK_NULL;
  if(scriptEntries.hasKey(filePath))
  {
    if( !forceLoad )
    {
      //Already loaded.
      return;
    }
		
    // Want to force load the script asset
    scriptEntries.get(filePath, &cachedEntry);
  }

  // Load the stream
  IVFileInStream *pIn = m_resourceManager->CreateFileInStream(filePath, HK_NULL);
  if(!pIn)
  {
    return;
  }

  LONG const size = pIn->GetSize();

  if(forceLoad && cachedEntry != HK_NULL)
  {
    // Clear out current cached entry
    cachedEntry->m_content.clearAndDeallocate();

    // Set new entry
    cachedEntry->m_content.setSize(size);
    pIn->Read(cachedEntry->m_content.begin(), size);
  }
  else
  {
    // Create new script entry
    ScriptEntry* entry = new ScriptEntry(filePath, size);
    pIn->Read(entry->m_content.begin(), size);

    // Add to map
    scriptEntries.insert(filePath, entry);
  }

  pIn->Close();
}
Esempio n. 3
0
FMOD_RESULT F_CALLBACK VisionFM_Read(void *handle, void *buffer, unsigned int sizebytes, unsigned int *bytesread, void *userdata)
{
  if (!handle)
    return FMOD_ERR_INVALID_PARAM;

  IVFileInStream *pStream = (IVFileInStream *)handle;
  *bytesread = (unsigned int)pStream->Read(buffer, sizebytes);
  if (*bytesread == 0)
    return FMOD_ERR_FILE_EOF;

  return FMOD_OK;
}
  static bool LoadScript(lua_State *L, const char * szFileName) 
  {
    IVFileInStream *pIn = Vision::File.Open(szFileName);
    if (!pIn) return false;

    int iScriptLen = pIn->GetSize();
    VMemoryTempBuffer<16*1024> buffer(iScriptLen+1);
    char *szBuffer = (char *)buffer.GetBuffer();
    pIn->Read(szBuffer,iScriptLen);
    szBuffer[iScriptLen] = 0;
    pIn->Close();

    if (!VScriptResourceManager::LuaErrorCheck(L, luaL_loadbuffer(L, szBuffer, iScriptLen, szFileName)))
      return false;

    if (!VScriptResourceManager::LuaErrorCheck(L, lua_pcall (L, 0, LUA_MULTRET, 0)))
      return false;

    return true;
  }
Esempio n. 5
0
// ReadPlacesFile: Reads in the PLACES_FILE and sets up all the WorldPlace_t
//                 objects.
void WorldLanguages_cl::ReadPlacesFile()
{
  IVFileInStream* pIn = Vision::File.Open(PLACES_FILE);
  char *buffer = NULL;
  
  if (pIn)
  {
    int fsize= pIn->GetSize();
    
    buffer = new char[fsize+1];
    pIn->Read(buffer, fsize);
    buffer[fsize] = 0;
    
    pIn->Close();
  }
  // if we couldn't read anything, return here!
  if (!buffer)
    return;

  static const char Newline[] = "\r\n";
  // tokenize buffer line-wise
  char *line = strtok(buffer, Newline);
  
  // skip first character, it only marks the UTF8 file (Byte Order Mark)
  line += 3;
  // read number of places
  sscanf(line, "%d", &m_iNumPlaces);
  // no places -> return without doing anything
  if (m_iNumPlaces < 1)
  {
    V_SAFE_DELETE_ARRAY(buffer);
    return;
  }
  // create m_iNumPlaces WorldPlace_t structs
  m_pPlaces = new WorldPlace_t[m_iNumPlaces];
  m_iCurrentPlace = 0;

  // get all places
  while (m_iCurrentPlace < m_iNumPlaces)
  {
    WorldPlace_t &pThisPlace = m_pPlaces[m_iCurrentPlace];
    // get next line
    line = strtok(NULL, Newline);
    if (line == NULL)
    {
      V_SAFE_DELETE_ARRAY(buffer);
      return;
    }

    // skip comments
    if (line[0] == ';')
      continue;
    // skip empty lines
    if (line[0] == '\0')
      continue;
    // find [
    if (line[0] == '[')
    {
      // the next line contains the name of the place
      line = strtok(NULL, Newline);
      pThisPlace.m_PlaceName = line;

      //is it Arabic?
      bool bArabic = strcmp(line, "UAE - Arabic") == 0;

      // the next line contains the font type
      line = strtok(NULL, Newline);

      // load font type with resource manager
      pThisPlace.m_spFont = Vision::Fonts.LoadFont(line);

      //left to right or right to left?
      line = strtok(line + strlen(line) + 1, Newline); // LoadFont() seems to use strtok too -> reinitialize
      bool bIsRightToLeft = strcmp(line,"RTL") == 0;

      // the next line contains the alphabet index, x position and y position
      // read alphabet, x_pos, y_pos;
      line = strtok(NULL, Newline);
      float x,y;
      sscanf(line, "%f,%f", &x, &y);
      
      // fix up angles (convert from long/lat to yaw/pitch)
      pThisPlace.m_angleY = -x;
      pThisPlace.m_angleZ = -y-90;
      // the next line(s) contain(s) the text
      // read text
      line = strtok(NULL, Newline);
      pThisPlace.m_Text.Reset();
      // until text is ]
      while (line[0] != ']')
      {
        pThisPlace.m_Text += line;
        pThisPlace.m_Text += "\n";
        line = strtok(NULL, Newline);
      }

      // Init Arabic support helper and set text which gets transformed from uniform to contextual Arabic
      if(bArabic)
      {
        pThisPlace.m_pRTLSupport = new VArabicSupport_cl(pThisPlace.m_spFont, pThisPlace.m_Text);
      }
      else if(bIsRightToLeft)
      {
        pThisPlace.m_pRTLSupport = new VRTLSupport_cl(pThisPlace.m_spFont, pThisPlace.m_Text);
      }

    }

    m_iCurrentPlace++;
  }
  V_SAFE_DELETE_ARRAY(buffer);

}