void IXMLWriterTest::writeXMLHeader() { IWriteFile* fWrite = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite); if (fWrite) fWrite->drop(); fxml->writeXMLHeader(); if (fxml) fxml->drop(); IReadFile* fRead = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead); fxmlR->read(); if (fxmlR->getNodeType() != EXNT_UNKNOWN) mes.append( "\n writeXMLHeader: does not write the XMLHeader"); if (fxmlR) fxmlR->drop(); if (fRead) fRead->drop(); }
//! returns fileindex s32 CUnZipReader::findFile(const c8* filename) { IReadFile *file = openFile ( filename ); if ( 0 == file ) return -1; file->drop (); return 1; }
//! Creates a XML Reader from a file. IXMLReaderUTF8* CFileSystem::createXMLReaderUTF8(const c8* filename) { IReadFile* file = createAndOpenFile(filename); if (!file) return 0; IXMLReaderUTF8* reader = createIXMLReaderUTF8(file); file->drop(); return reader; }
//! Creates a XML Reader from a file. IXMLReader* CFileSystem::createXMLReader(const io::path& filename) { IReadFile* file = createAndOpenFile(filename); if (!file) return 0; IXMLReader* reader = createXMLReader(file); file->drop(); return reader; }
//! Creates a XML Reader from a file. IXMLReader* CFileSystem::createXMLReader(const core::string<c16>& filename) { IReadFile* file = createAndOpenFile(filename); if (!file) return 0; IXMLReader* reader = createXMLReader(file); file->drop(); return reader; }
/** \param file File handle to check. \return Pointer to newly created archive, or 0 upon error. */ IFileArchive* CArchiveLoaderNPK::createArchive(const path& filename, bool ignoreCase, bool ignorePaths) const { IFileArchive *archive = 0; IReadFile* file = FileSystem->createAndOpenFile(filename); if (file) { archive = createArchive(file, ignoreCase, ignorePaths); file->drop(); } return archive; }
/** See IXMLReader for more information on how to use the parser. \return 0, if file could not be opened, otherwise a pointer to the created IXMLReader is returned. After use, the reader has to be deleted using its IXMLReader::drop() method. See IReferenceCounted::drop() for more information. */ IXMLReader* SharedFileSystem::createXMLReader( const core::stringc& filename) { // Create the file using an absolute path so that it matches // the scheme used by CNullDriver::getTexture(). IReadFile * file = createReadFile(this->getAbsolutePath(filename)); IXMLReader* reader = irrgame::io::createXMLReader(file); if (file) file->drop(); return reader; }
//! adds an pak archive to the filesystem bool CFileSystem::addPakFileArchive(const c8* filename, bool ignoreCase, bool ignorePaths) { CPakReader* zr = 0; IReadFile* file = createAndOpenFile(filename); if (file) { zr = new CPakReader(file, ignoreCase, ignorePaths); if (zr) PakFileSystems.push_back(zr); file->drop(); } #ifdef _DEBUG else os::Printer::log("Could not open file. Pakfile not added", filename, ELL_ERROR); #endif _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; return (zr != 0); }
//! adds an zip archive to the filesystem bool CFileSystem::addZipFileArchive(const c8* filename, bool ignoreCase, bool ignorePaths) { IReadFile* file = createReadFile(filename); if (file) { CZipReader* zr = new CZipReader(file, ignoreCase, ignorePaths); if (zr) ZipFileSystems.push_back(zr); file->drop(); bool ret = (zr != 0); _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; return ret; } #ifdef _DEBUG os::Printer::log("Could not open file. Zipfile not added", filename, ELL_ERROR); #endif _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; return false; }
bool disambiguateTextures(void) { IrrlichtDevice *device = createDevice( video::EDT_SOFTWARE, dimension2d<s32>(640, 480), 16, false, false, false, 0); if (!device) return false; IVideoDriver * driver = device->getVideoDriver(); ITexture * tex1 = driver->getTexture("../media/tools.png"); ITexture * tex2 = driver->getTexture("../media/tools.png"); IReadFile * readFile = device->getFileSystem()->createAndOpenFile("../media/tools.png"); assert(readFile); ITexture * tex3 = driver->getTexture(readFile); readFile->drop(); // Expects an empty tmp/tmp directory under this app's wd and // a media directory under this apps' directory with tools.png in it. stringc wd = device->getFileSystem()->getWorkingDirectory(); stringc newWd = wd + "/empty/empty"; bool changed = device->getFileSystem()->changeWorkingDirectoryTo(newWd.c_str()); assert(changed); ITexture * tex4 = driver->getTexture("../../media/tools.png"); assert(tex4); assert(tex1 == tex2 && tex1 == tex3 && tex1 != tex4); changed &= device->getFileSystem()->changeWorkingDirectoryTo(wd.c_str()); device->drop(); return (changed && tex1 == tex2 && tex1 == tex3 && tex1 != tex4) ? true : false; }
/** This tests verifies that textures opened from different places in the filesystem can be distinguished, even if they have the same filename. */ bool disambiguateTextures(void) { IrrlichtDevice *device = createDevice( video::EDT_NULL, dimension2d<s32>(640, 480)); if (!device) { logTestString("Unable to create EDT_NULL device\n"); return false; } // Expects an empty tmp/tmp directory under this app's wd and // a media directory under this apps' directory with tools.png in it. stringc wd = device->getFileSystem()->getWorkingDirectory(); if(-1 == wd.find("/tests") && -1 == wd.find("\\tests")) { logTestString("The tests must be run from the /tests directory, regardless of where\n"\ "the test executable was built.\n"); device->drop(); return false; } IVideoDriver * driver = device->getVideoDriver(); ITexture * tex1 = driver->getTexture("../media/tools.png"); assert(tex1); if(!tex1) logTestString("Unable to open ../media/tools.png\n"); ITexture * tex2 = driver->getTexture("../media/tools.png"); assert(tex2); if(!tex2) logTestString("Unable to open ../media/tools.png\n"); IReadFile * readFile = device->getFileSystem()->createAndOpenFile("../media/tools.png"); assert(readFile); if(!readFile) logTestString("Unable to open ../media/tools.png\n"); ITexture * tex3 = driver->getTexture(readFile); assert(tex3); if(!readFile) logTestString("Unable to create texture from ../media/tools.png\n"); readFile->drop(); // All 3 of the above textures should be identical. assert(tex1 == tex2 && tex1 == tex3); stringc newWd = wd + "/empty/empty"; bool changed = device->getFileSystem()->changeWorkingDirectoryTo(newWd.c_str()); assert(changed); ITexture * tex4 = driver->getTexture("../../media/tools.png"); assert(tex4); if(!tex4) logTestString("Unable to open ../../media/tools.png\n"); assert(tex1 != tex4); // The working directory must be restored for the other tests to work. changed &= device->getFileSystem()->changeWorkingDirectoryTo(wd.c_str()); device->drop(); return (changed && tex1 == tex2 && tex1 == tex3 && tex1 != tex4) ? true : false; }
int main(int argc, char **argv) { // Help? if (argv[1] && argv[1][0] == '-') die(helpmsg); putenv((char *) "vblank_mode=0"); // No vsync for us, thanks. MyEventReceiver *r = new MyEventReceiver(); IrrlichtDevice *dev = createDevice(EDT_OPENGL, core::dimension2d<u32>(1024,768), 32, false, false, false, r); if (!dev) die("Can't initialize Irrlicht"); IVideoDriver *drv = dev->getVideoDriver(); ISceneManager *smgr = dev->getSceneManager(); IGPUProgrammingServices *gpu = drv->getGPUProgrammingServices(); ICameraSceneNode *cam = NULL; ITexture *pic = NULL; IMeshSceneNode *ball = NULL; bool showpic = false; IReadFile *areamap = createMemoryReadFile(AreaMap33, sizeof(AreaMap33), "AreaMap33", false); if (!areamap) die("Failed to load areamap"); ITexture *areamaptex = drv->getTexture(areamap); areamap->drop(); // If there's an argument, assume it is a pic to load; otherwise, draw a sphere if (argv[1] && access(argv[1], R_OK) == 0) { showpic = true; pic = drv->getTexture(argv[1]); if (!pic) die("Can't load image"); cam = smgr->addCameraSceneNode(); } else { cam = smgr->addCameraSceneNodeMaya(); cam->setTarget(vector3df(0, 0, 0)); ball = smgr->addSphereSceneNode(40, 8); int ballshader = gpu->addHighLevelShaderMaterial(rnd,0,EVST_VS_1_1,0); ball->setMaterialType((E_MATERIAL_TYPE) ballshader); ISceneNodeAnimator *cool = smgr->createRotationAnimator(vector3df(-0.1, 0.1, -0.1)); ball->addAnimator(cool); cool->drop(); } // Set up static defines, RTTs, quads dimension2d<u32> screensize = drv->getScreenSize(); char defines[128]; snprintf(defines, 128, "#define PIXEL_SIZE vec2(1.0f / %u.0, 1.0f / %u.0)\n" "#define MAX_SEARCH_STEPS 8.0\n#define MAX_DISTANCE 33.0\n", screensize.Width, screensize.Height); ITexture *rt1 = drv->addRenderTargetTexture(screensize, "rt1", ECF_A8R8G8B8); ITexture *rt2 = drv->addRenderTargetTexture(screensize, "rt2", ECF_A8R8G8B8); ITexture *rt3 = drv->addRenderTargetTexture(screensize, "rt3", ECF_A8R8G8B8); if (!rt1 || !rt2 || !rt3) die("No RTT"); ScreenQuad *def = new ScreenQuad(drv); ScreenQuad *sq = new ScreenQuad(drv); ScreenQuad *sq2 = new ScreenQuad(drv); ScreenQuad *sq3 = new ScreenQuad(drv); ScreenQuad *norm = new ScreenQuad(drv); if (showpic) def->SetTexture(pic); sq->SetTexture(rt1); sq->GetMaterial().setFlag(EMF_BILINEAR_FILTER, false); norm->SetTexture(rt1); norm->GetMaterial().setFlag(EMF_BILINEAR_FILTER, false); sq2->SetTexture(rt2); sq2->SetTexture(rt2, 1); sq2->SetTexture(areamaptex, 2); sq2->GetMaterial().TextureLayer[2].BilinearFilter = false; sq3->SetTexture(rt3); sq3->GetMaterial().setFlag(EMF_BILINEAR_FILTER, false); sq3->SetTexture(rt1,1); state_t state = MLAA_OFF; stringc tmp1, tmp2; tmp1 = defines; tmp1 += offsetvs; tmp2 = defines; tmp2 += color1fs; // Load shaders int edge = gpu->addHighLevelShaderMaterial(tmp1.c_str(),0,EVST_VS_1_1,tmp2.c_str()); sq->SetMaterialType((E_MATERIAL_TYPE) edge); tmp2 = defines; tmp2 += blend2fs; blendcb *bcb = new blendcb(); edge = gpu->addHighLevelShaderMaterial(tmp1.c_str(),0,EVST_VS_1_1,tmp2.c_str(),0,EPST_PS_1_1,bcb); sq2->SetMaterialType((E_MATERIAL_TYPE) edge); tmp2 = defines; tmp2 += neigh3fs; neighcb *ncb = new neighcb(); edge = gpu->addHighLevelShaderMaterial(tmp1.c_str(),0,EVST_VS_1_1,tmp2.c_str(),0,EPST_PS_1_1,ncb); sq3->SetMaterialType((E_MATERIAL_TYPE) edge); // Record start time int lastfps = -1, minfps = 10000; unsigned long long total_frames = 0, fxtimer = 0, tmplong, onframes = 0; struct timeval starttime, tick1, tick2; float glsltime = 0; gettimeofday(&starttime, NULL); wchar_t cap[20]; glEnable(GL_STENCIL_TEST); unsigned char firstrun = 1; // To avoid the glsl compiler in the timing // Main loop while (dev->run()) { gettimeofday(&tick1, NULL); drv->beginScene(); switch (state) { case MLAA_OFF: if (showpic) def->Render(false); else smgr->drawAll(); break; case MLAA_ON: if (showpic) def->Render(rt1); else { drv->setRenderTarget(rt1); smgr->drawAll(); } glClear(GL_STENCIL_BUFFER_BIT); glStencilFunc(GL_ALWAYS, 1, ~0); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); sq->Render(rt2); glStencilFunc(GL_EQUAL, 1, ~0); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); sq2->Render(rt3); drv->setRenderTarget(rt1, false, false); // Overlay the smoothed edges on the initial image sq3->Render(false); // Blit the final image to the framebuffer glStencilFunc(GL_ALWAYS, 1, ~0); norm->Render(); break; } drv->endScene(); if (state == MLAA_ON) { gettimeofday(&tick2, NULL); if (!firstrun) { tmplong = (tick2.tv_sec - tick1.tv_sec) * 10000; tmplong += (tick2.tv_usec - tick1.tv_usec) / 100; fxtimer += tmplong; onframes++; } else { firstrun = 0; glsltime = tick2.tv_sec - tick1.tv_sec; glsltime += (tick2.tv_usec - tick1.tv_usec) / 1000000.0; } } int fps = drv->getFPS(); if (minfps > fps) minfps = fps; if (lastfps != fps) { swprintf(cap, 20, L"%d fps, MLAA %s", fps, state == MLAA_ON ? "on" : "off"); dev->setWindowCaption(cap); lastfps = fps; } if (r->IsKeyDown(KEY_KEY_M)) { if (state == MLAA_ON) state = MLAA_OFF; else state = MLAA_ON; lastfps++; } usleep(1); // 16? total_frames++; } dev->drop(); delete ncb; delete bcb; delete def; delete sq; delete sq2; delete sq3; delete norm; delete r; struct timeval endtime; gettimeofday(&endtime, NULL); float sec = endtime.tv_sec - starttime.tv_sec; sec += ((float) endtime.tv_usec - starttime.tv_usec) / 1000000; printf("\nRan %.3fs, ", sec); sec -= glsltime; printf("average fps %.2f, min %d\n", (float) total_frames/sec, minfps); if (onframes) { printf("\nAverage on fps %.2f, average off fps %.2f\n\n", (float) onframes/(fxtimer/10000.0), (float) (total_frames - onframes)/(sec - (fxtimer/10000.0))); // printf("MLAA took on average %.1fms\n", (float) (fxtimer / onframes) / 10.0); } return 0; }
/** This tests verifies that textures opened from different places in the filesystem don't create duplicated textures. */ bool loadFromFileFolder(void) { IrrlichtDevice *device = createDevice( video::EDT_NULL, dimension2du(160, 120)); if (!device) { logTestString("Unable to create EDT_NULL device\n"); return false; } IVideoDriver * driver = device->getVideoDriver(); u32 numTexs = driver->getTextureCount(); ITexture * tex1 = driver->getTexture("../media/tools.png"); assert_log(tex1); if(!tex1) logTestString("Unable to open ../media/tools.png\n"); if (driver->getTextureCount()!=numTexs+1) { logTestString("No additional texture in the texture cache %s:%d\n", __FILE__, __LINE__); return false; } IReadFile * readFile = device->getFileSystem()->createAndOpenFile("../media/tools.png"); assert_log(readFile); if(!readFile) logTestString("Unable to open ../media/tools.png\n"); if (driver->getTextureCount()!=numTexs+1) { logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__); return false; } ITexture * tex2 = driver->getTexture(readFile); assert_log(tex2); if(!readFile) logTestString("Unable to create texture from ../media/tools.png\n"); if (driver->getTextureCount()!=numTexs+1) { logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__); return false; } readFile->drop(); // adding a folder archive device->getFileSystem()->addFileArchive( "../media/" ); ITexture * tex3 = driver->getTexture("tools.png"); assert_log(tex3); if(!tex3) logTestString("Unable to open tools.png\n"); if (driver->getTextureCount()!=numTexs+1) { logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__); return false; } ITexture * tex4 = driver->getTexture("tools.png"); assert_log(tex4); if(!tex4) logTestString("Unable to open tools.png\n"); if (driver->getTextureCount()!=numTexs+1) { logTestString("Additional texture in the texture cache %s:%d\n", __FILE__, __LINE__); return false; } device->closeDevice(); device->run(); device->drop(); return ((tex1 == tex2) && (tex1 == tex3) && (tex1 == tex4)); }
void IXMLWriterTest::writeElement() { IWriteFile* fWrite = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite); if (fWrite) fWrite->drop(); fxml->writeElement("fff", true, "attr1", "attrValue1"); if (fxml) fxml->drop(); IReadFile* fRead = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead); fxmlR->read(); if (fxmlR->getNodeType() != EXNT_ELEMENT) mes.append( "\n writeElement: incorrectly indicates the type of node"); if (fxmlR->getAttributeCount() != 1) mes.append( "\n writeElement: correctly returns the number of attributes"); core::stringc strA = core::stringc("attr1"); if (!strA.equalsn(fxmlR->getAttributeName(0), 4)) mes.append( "\n writeElement: correctly returns the name of attributes"); core::stringc strV = core::stringc("attrValue1"); if (!strV.equalsn(fxmlR->getAttributeValue(0), 10)) mes.append( "\n writeElement: correctly returns the value of attributes"); if (fxmlR) fxmlR->drop(); if (fRead) fRead->drop(); //TODO should not create an element with no name IWriteFile* fWrite1 = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml1 = IFileSystem::createXMLWriter(fWrite1); if (fWrite1) fWrite1->drop(); fxml1->writeElement("", true); if (fxml1) fxml1->drop(); IReadFile* fRead1 = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR1 = IFileSystem::createXMLReader(fRead1); fxmlR1->read(); core::stringc strN = core::stringc(""); if (strN.equalsn(fxmlR1->getNodeName(), 1)) mes.append("\n writeElement: node name can not be empty"); if (fxmlR1->getAttributeCount() != 0) mes.append("\n writeElement: sees non-existent attributes"); if (fxmlR1) fxmlR1->drop(); if (fRead1) fRead1->drop(); core::array<core::stringc> atr; atr.insert(core::stringc("atr1")); atr.insert(core::stringc("atr2")); atr.insert(core::stringc("7")); atr.insert(core::stringc(0)); atr.insert(core::stringc("art5")); atr.insert(core::stringc("</>")); atr.insert(core::stringc("art7")); core::array<core::stringc> atrValue; atrValue.insert(core::stringc("atrValue1")); atrValue.insert(core::stringc("atrValue2")); atrValue.insert(core::stringc("atrValue3")); atrValue.insert(core::stringc("atrValue4")); atrValue.insert(core::stringc("atrValue5")); atrValue.insert(core::stringc("6")); atrValue.insert(core::stringc("")); IWriteFile* fWrite3 = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml3 = IFileSystem::createXMLWriter(fWrite3); if (fWrite3) fWrite3->drop(); fxml3->writeElement("fff", true, atr, atrValue); if (fxml3) fxml3->drop(); IReadFile* fRead3 = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR3 = IFileSystem::createXMLReader(fRead3); fxmlR3->read(); if (fxmlR3->getAttributeCount() != 7) mes.append( "\n writeElement: correctly returns the number of attributes"); //TODO attribute name can not be a 0 if (fxmlR3->getAttributeName(3) == 0) mes.append( "\n writeElement: attribute name can not be a 0"); //TODO attribute value can not be empty core::stringc strAV = core::stringc(""); if (strAV.equalsn(fxmlR3->getAttributeValue(6), 1)) mes.append( "\n writeElement: attribute value can not be empty"); if (fxmlR3) { fxmlR3->drop(); } }