Esempio n. 1
0
const std::string &DeferredRenderer::light_vert_src() {
  if(light_vert_src_.empty()) {
    const char *vert_file = "shader/deferred/deferred_light.vs";
    string vert_path = Filesystem::GetAppPath(vert_file);
    MemoryFile mem_file(vert_path);
    bool opened = mem_file.Open();
    SR_ASSERT(opened == true);
    const char *src = (const char*)(mem_file.start);
    light_vert_src_ = src;
    mem_file.Close();
  }
  return light_vert_src_;
}
Esempio n. 2
0
	bool MemDumper::dump(QFile *_file) const
	{
#ifdef Q_WS_WIN
		return false;
#endif
		Q_CHECK_PTR(_file);
		Q_ASSERT(_file -> isOpen());
		QRegExp mem_addr_regex("^([0-9a-fA-F]+)-([0-9a-fA-F]+)\\sr");
		QDir system_proc_dir("/proc");
		QDir proc_dir(system_proc_dir.absoluteFilePath(QString::number(m_pid)));
		QString maps_file_str(proc_dir.absoluteFilePath("maps"));
		QString mem_file_str(proc_dir.absoluteFilePath("mem"));
		
		QFile maps_file(maps_file_str);
		QFile mem_file(mem_file_str);

		if(!maps_file.open(QIODevice::ReadOnly) || !mem_file.open(QIODevice::ReadOnly))
		{
			qCritical("ERROR: Open file error: %s", maps_file.errorString().toLocal8Bit().data());
			return false;
		}
		QTextStream maps_str(&maps_file);
		for(QString line = maps_str.readLine(); !line.isNull(); line = maps_str.readLine())
		{
			qint32 pos = mem_addr_regex.indexIn(line);
			if(!pos)
			{
				qint64 start = mem_addr_regex.capturedTexts()[1].toLongLong(NULL, 16);
				qint64 end = mem_addr_regex.capturedTexts()[2].toLongLong(NULL, 16);
				qint64 size = end - start;
				for(qint64 read = 0; read < size;)
				{
					start += read;
					mem_file.seek(start);
					QByteArray buf;
					buf = mem_file.read(size - read);
					if(buf.size() < size - read && mem_file.error() != QFile::NoError)
					{
						qCritical("ERROR: Open file error: %s", mem_file.errorString().toLocal8Bit().data());
						return false;
					}
					_file -> write(buf);
					read += buf.size();
				}
				
			}
		}
		return true;
	}
Esempio n. 3
0
const std::string &DeferredRenderer::light_frag_src() {
  if(light_frag_src_.empty()) {
    const char *frag_file = "shader/deferred/deferred_light.fs";
    string frag_path = Filesystem::GetAppPath(frag_file);
    MemoryFile mem_file(frag_path);
    bool opened = mem_file.Open();
    SR_ASSERT(opened == true);
    const char *src = (const char*)(mem_file.start);

    const std::string &light_model_src = Light::GetLightModelFragSrc();
    light_frag_src_ = light_model_src;
    light_frag_src_ += src;

    mem_file.Close();
  }
  return light_frag_src_;
}
Esempio n. 4
0
int main()
{
  mem_filesystem fs;
  //REV: Make fake filesystem

  std::string bname="memfiletest.binary";
  std::string tname="memfiletest.txt";
  
  std::ofstream bin( bname, std::ios::binary | std::ios::out );
  double xd=3.0, yd=2.5, zd=5.0;
  int xi=1, yi=15, zi=30000;
  long int xl=5999333, yl=1, zl=483;

  //bin << xd << yd << zd << xi << yi << zi << xl << yl << zl;
  bin.write( (char*)&xd, sizeof(xd) );
  bin.write( (char*)&yd, sizeof(yd) );
  bin.write( (char*)&zd, sizeof(zd) );
  bin.write( (char*)&xi, sizeof(xi) );
  bin.write( (char*)&yi, sizeof(yi) );
  bin.write( (char*)&zi, sizeof(zi) );
  bin.write( (char*)&xl, sizeof(xl) );
  bin.write( (char*)&yl, sizeof(yl) );
  bin.write( (char*)&zl, sizeof(zl) );

  bin.close();

  std::ofstream txt( tname );

  txt << xd << " " << yd << " " << zd << " " << xi << " " << yi << " " << zi <<
    " " << xl << " " << yl << " " << zl; //no endl.

  txt.close();
  
  //make a double then int file.
  fs.add_file_from_disk( bname );
  fs.add_file_from_disk( tname );
  
  memfile_ptr binptr = fs.get_ptr( bname );
  memfile_ptr txtptr = fs.get_ptr( tname );

  
  
  xd=binptr.consume_from_binary<double>(), yd=binptr.consume_from_binary<double>(), zd=binptr.consume_from_binary<double>(), xi=binptr.consume_from_binary<int>(), yi=binptr.consume_from_binary<int>(), zi=binptr.consume_from_binary<int>(), xl=binptr.consume_from_binary<long int>(), yl=binptr.consume_from_binary<long int>(), zl=binptr.consume_from_binary<long int>();
  //REV: HOLY SHIT, fprintf optional args are read in opposite order (maybe)!!!!!!!!!!
  
  //fprintf( stdout, "From binary: %lf %lf %lf %d %d %d %ld %ld %ld", binptr.consume_from_binary<double>(), binptr.consume_from_binary<double>(), binptr.consume_from_binary<double>(), binptr.consume_from_binary<int>(), binptr.consume_from_binary<int>(), binptr.consume_from_binary<int>(), binptr.consume_from_binary<long int>(), binptr.consume_from_binary<long int>(), binptr.consume_from_binary<long int>() );
  fprintf( stdout, "From binary: %lf %lf %lf %d %d %d %ld %ld %ld\n", xd,yd,zd,xi,yi,zi,xl,yl,zl);

  std::istringstream iss = txtptr.get_string_stream();

  double ds[3];
  int di[3];
  long int dl[3];

  
  iss >> xd  >> yd  >> zd  >> xi  >> yi  >> zi >> xl  >> yl  >> zl;

  fprintf(stdout, "FROM TXT:\n");
  std::cout << xd << " " << yd << " " << zd << " " << xi << " " << yi << " " << zi << " " << xl << " " << yl << " " << zl << std::endl;


  fs.add_file( mem_file("testout.out", false) );
  memfile_ptr outptr = fs.get_ptr( "testout.out" );

  outptr.print( "HERE IS THE DATA:\n" );

  //std::ostringstream ss = outptr.get_out_string_stream();
  //ss << xd << " " << yd << " " << zd << " " << xi << " " << yi << " " << zi << " " << xl << " " << yl << " " << zl << std::endl;

  outptr.printf("%lf %lf %lf %d %d %d %ld %ld %ld\n", xd,yd,zd,xi,yi,zi,xl,yl,zl);
  
  outptr.mfile->tofile( ".", outptr.mfile->filename );
  
  
}