test_MapSerializer.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #include <fstream>
  2. //#include <boost/test/unit_test.hpp>
  3. #include <Ogre.h>
  4. #include "common/TypeDefine.h"
  5. #include "data/worldmap/MapFileSerializer.h"
  6. #include "data/worldmap/MapFile.h"
  7. #include "data/worldmap/MapFileManager.h"
  8. #include "data/VGearsTexCodec.h"
  9. #include <functional>
  10. #include "data/VGearsLGPArchiveFactory.h"
  11. using namespace Ogre;
  12. static void createReferenceFileInstance(std::function<void(Ogre::DataStreamPtr& stream, VGears::WorldMapFile& file)> callBack)
  13. {
  14. class TestFile : public VGears::WorldMapFile
  15. {
  16. public:
  17. TestFile() : VGears::WorldMapFile( NULL, "", 0, "" ) {}
  18. };
  19. const char* file_name = "/home/paul/vgears/v-gears/Tests/FinalFantasy7/misc/reference.map";
  20. std::ifstream ifs( file_name, std::ifstream::binary );
  21. {
  22. // BOOST_REQUIRE( ifs.is_open() );
  23. Ogre::DataStreamPtr stream( OGRE_NEW Ogre::FileStreamDataStream( &ifs, false ) );
  24. // BOOST_REQUIRE( stream->isReadable() );
  25. //Ogre::LogManager log;
  26. TestFile f;
  27. // log.createLog( "Default Log", true, true, true );
  28. callBack(stream, f);
  29. // log.destroyLog( "Default Log" );
  30. }
  31. }
  32. /*
  33. BOOST_AUTO_TEST_CASE( file_size_is_multiple_of_block_size )
  34. {
  35. createReferenceFileInstance([&](Ogre::DataStreamPtr& stream, VGears::WorldMapFile& file)
  36. {
  37. VGears::MapFileSerializer s;
  38. s.importMapFile( stream, file );
  39. });
  40. }
  41. // compare meshes to hand picked data that we know should be in the block
  42. BOOST_AUTO_TEST_CASE( parse_16_meshes_in_one_block )
  43. {
  44. }
  45. BOOST_AUTO_TEST_CASE( parsing_whole_map )
  46. {
  47. }
  48. BOOST_AUTO_TEST_CASE( replace_story_meshes )
  49. {
  50. }
  51. */
  52. Camera *mainCam = nullptr;
  53. class GameFrameListener : public Ogre::FrameListener
  54. {
  55. public:
  56. using Ogre::FrameListener::FrameListener;
  57. bool frameStarted( const Ogre::FrameEvent& evt )
  58. {
  59. auto pos = mainCam->getPosition();
  60. //pos.x += 1.0f;
  61. //pos.z += 1.0f;
  62. mainCam->setPosition(pos);
  63. return true;
  64. }
  65. };
  66. int main(int argc, char **argv)
  67. {
  68. Root *root = new Root();
  69. // choose renderer
  70. // IVV
  71. /*if(!root->showConfigDialog())
  72. {
  73. return 0;
  74. }*/
  75. // initialise root
  76. root->initialise(false);
  77. // create main window
  78. RenderWindow *renderWindow = root->createRenderWindow("Main",320,240,false);
  79. // create the scene
  80. SceneManager *sceneMgr = root->createSceneManager(Ogre::ST_GENERIC);
  81. // add a camera
  82. mainCam = sceneMgr->createCamera("MainCam");
  83. // add viewport
  84. Viewport *vp = renderWindow->addViewport(mainCam);
  85. Ogre::ArchiveManager::getSingleton().addArchiveFactory( new VGears::LGPArchiveFactory() );
  86. Ogre::TextureManager* tm = root->getTextureManager();
  87. VGears::MapFileManager* worldManager = new VGears::MapFileManager();
  88. ResourceGroupManager::getSingleton().addResourceLocation(".", "FileSystem");
  89. ResourceGroupManager::getSingleton().addResourceLocation("/home/paul/vgears/data/cd1pc/wm", "FileSystem", "TEST");
  90. ResourceGroupManager::getSingleton().addResourceLocation("/home/paul/vgears/data/cd1pc/wm/world_us.lgp", VGears::LGPArchiveFactory::ARCHIVE_TYPE, "TEST");
  91. VGears::TexCodec::install();
  92. VGears::TexCodec::initialise();
  93. ResourceGroupManager::getSingleton().declareResource("bridge.tex", "Texture", "TEST");
  94. ResourceGroupManager::getSingleton().declareResource("wm0.map", VGears::WorldMapFile::RESOURCE_TYPE, "TEST");
  95. ResourceGroupManager::getSingleton().declareResource("wm1.map", VGears::WorldMapFile::RESOURCE_TYPE, "TEST");
  96. ResourceGroupManager::getSingleton().declareResource("wm2.map", VGears::WorldMapFile::RESOURCE_TYPE, "TEST");
  97. ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
  98. Ogre::ResourcePtr f = worldManager->load("wm0.map", "TEST");
  99. //worldManager->load("wm/wm0.map", "TEST");
  100. TexturePtr p = tm->load("bridge.tex", "TEST");
  101. int th = p->getSrcHeight();
  102. int tw = p->getSrcWidth();
  103. /*
  104. GameFrameListener *frameListener= new GameFrameListener();
  105. // frameListener->showDebugOverlay(true);
  106. // Create an Entity
  107. Ogre::Entity* ogreHead = sceneMgr->createEntity("axes", "axes.mesh");
  108. // Create a SceneNode and attach the Entity to it
  109. Ogre::SceneNode* headNode = sceneMgr->getRootSceneNode()->createChildSceneNode("HeadNode");
  110. headNode->attachObject(ogreHead);
  111. headNode->setPosition( 0, 0, 0 );
  112. // createColourCube(sceneMgr);
  113. mainCam->setPolygonMode(PM_WIREFRAME);
  114. mainCam->setFarClipDistance(900000.0f);
  115. mainCam->setPosition( 50, 500, 500 );
  116. mainCam->lookAt( 0, 0, 0);
  117. root->addFrameListener(frameListener);
  118. root->startRendering();
  119. */
  120. return 0;
  121. }