CObjectHandler.cpp 829 B

123456789101112131415161718192021222324252627282930
  1. #include "stdafx.h"
  2. #include "CObjectHandler.h"
  3. void CObjectHandler::loadObjects()
  4. {
  5. std::ifstream inp("H3bitmap.lod\\OBJNAMES.TXT", std::ios::in | std::ios::binary);
  6. inp.seekg(0,std::ios::end); // na koniec
  7. int andame = inp.tellg(); // read length
  8. inp.seekg(0,std::ios::beg); // wracamy na poczatek
  9. char * bufor = new char[andame]; // allocate memory
  10. inp.read((char*)bufor, andame); // read map file to buffer
  11. std::string buf = std::string(bufor);
  12. delete [andame] bufor;
  13. int i = 0; //buf iterator
  14. while(!inp.eof())
  15. {
  16. if(objects.size()>200 && buf.substr(i, buf.size()-i).find('\r')==std::string::npos)
  17. break;
  18. CObject nobj;
  19. int befi=i;
  20. for(i; i<andame; ++i)
  21. {
  22. if(buf[i]=='\r')
  23. break;
  24. }
  25. nobj.name = buf.substr(befi, i-befi);
  26. i+=2;
  27. objects.push_back(nobj);
  28. }
  29. }