main.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include <iostream>
  2. #include <irrlicht/irrlicht.h>
  3. #include <sstream>
  4. #include <wallpaperengine/config.h>
  5. #include <wallpaperengine/video/renderer.h>
  6. #include <wallpaperengine/video/material.h>
  7. #include <wallpaperengine/irr/CPkgReader.h>
  8. #include "wallpaperengine/shaders/compiler.h"
  9. #include "wallpaperengine/project.h"
  10. #include "wallpaperengine/irrlicht.h"
  11. #include "wallpaperengine/irr/CImageLoaderTEX.h"
  12. int WinID = 0;
  13. irr::SIrrlichtCreationParameters _irr_params;
  14. irr::f32 g_Time = 0;
  15. int init_irrlicht()
  16. {
  17. // prepare basic configuration for irrlicht
  18. _irr_params.AntiAlias = 8;
  19. _irr_params.Bits = 16;
  20. // _irr_params.DeviceType = irr::EIDT_X11;
  21. _irr_params.DriverType = irr::video::EDT_OPENGL;
  22. _irr_params.Doublebuffer = true;
  23. _irr_params.EventReceiver = nullptr;
  24. _irr_params.Fullscreen = false;
  25. _irr_params.HandleSRGB = false;
  26. _irr_params.IgnoreInput = true;
  27. _irr_params.Stencilbuffer = true;
  28. _irr_params.UsePerformanceTimer = false;
  29. _irr_params.Vsync = false;
  30. _irr_params.WithAlphaChannel = false;
  31. _irr_params.ZBufferBits = 24;
  32. _irr_params.LoggingLevel = irr::ELL_DEBUG;
  33. _irr_params.WindowId = reinterpret_cast<void*> (WinID);
  34. wp::irrlicht::device = irr::createDeviceEx (_irr_params);
  35. if (wp::irrlicht::device == nullptr)
  36. {
  37. return 1;
  38. }
  39. wp::irrlicht::device->setWindowCaption (L"Test game");
  40. wp::irrlicht::driver = wp::irrlicht::device->getVideoDriver();
  41. // check for ps and vs support
  42. if (
  43. wp::irrlicht::driver->queryFeature (irr::video::EVDF_PIXEL_SHADER_1_1) == false &&
  44. wp::irrlicht::driver->queryFeature (irr::video::EVDF_ARB_FRAGMENT_PROGRAM_1) == false)
  45. {
  46. wp::irrlicht::device->getLogger ()->log ("WARNING: Pixel shaders disabled because of missing driver/hardware support");
  47. }
  48. if (
  49. wp::irrlicht::driver->queryFeature (irr::video::EVDF_VERTEX_SHADER_1_1) == false &&
  50. wp::irrlicht::driver->queryFeature (irr::video::EVDF_ARB_VERTEX_PROGRAM_1) == false)
  51. {
  52. wp::irrlicht::device->getLogger ()->log ("WARNING: Vertex shaders disabled because of missing driver/hardware support");
  53. }
  54. return 0;
  55. }
  56. void preconfigure_wallpaper_engine ()
  57. {
  58. wp::config::path::base = wp::irrlicht::device->getFileSystem ()->getAbsolutePath ("../");
  59. wp::config::path::resources = wp::config::path::base + "/res";
  60. wp::config::path::shaders = wp::config::path::resources + "/shaders";
  61. }
  62. int main (int argc, char* argv[])
  63. {
  64. // parse the integer if it exists
  65. if (argc >= 1)
  66. {
  67. std::stringstream ss;
  68. ss << std::hex << argv[1];
  69. ss >> WinID;
  70. }
  71. printf ("Initializing X11 to %d\n", WinID);
  72. if (init_irrlicht())
  73. {
  74. return 1;
  75. }
  76. preconfigure_wallpaper_engine ();
  77. // do_decompress ();
  78. irr::io::path _wp_engine_folder = "/home/almamu/Development/tmp/nier__automata_-_become_as_gods_edition/";
  79. irr::io::path _wp_project_file = _wp_engine_folder + "project.json";
  80. // load the assets folder from wallpaper engine
  81. wp::irrlicht::device->getFileSystem ()->addFileArchive ("../assets.zip", true, false);
  82. // set our working directory
  83. wp::irrlicht::device->getFileSystem ()->changeWorkingDirectoryTo (_wp_engine_folder);
  84. // register custom loader
  85. wp::irrlicht::driver->addExternalImageLoader (new irr::video::CImageLoaderTex ());
  86. wp::irrlicht::device->getFileSystem ()->addArchiveLoader (new CArchiveLoaderPkg (wp::irrlicht::device->getFileSystem ()));
  87. // wp::irrlicht::device->getFileSystem ()->addFileArchive (_wp_engine_folder + "scene.pkg", true, false); // add the pkg file to the lookup list
  88. wp::project* wp_project = new wp::project (_wp_project_file);
  89. if (wp_project->getScene ()->isOrthogonal() == true)
  90. {
  91. wp::video::renderer::setupOrthographicCamera (wp_project->getScene ());
  92. }
  93. else
  94. {
  95. wp::irrlicht::device->getLogger ()->log ("Non-orthogonal cameras not supported yet!!");
  96. return 0;
  97. }
  98. // register nodes
  99. wp::video::renderer::queueNode (wp_project->getScene ());
  100. int32_t lastTime = 0;
  101. int32_t minimumTime = 1000 / 90;
  102. int32_t currentTime = 0;
  103. while (wp::irrlicht::device->run () && wp::irrlicht::driver)
  104. {
  105. // if (device->isWindowActive ())
  106. {
  107. currentTime = wp::irrlicht::device->getTimer ()->getTime ();
  108. g_Time = currentTime / 1000.0f;
  109. if (currentTime - lastTime > minimumTime)
  110. {
  111. wp::video::renderer::render ();
  112. lastTime = currentTime;
  113. }
  114. else
  115. {
  116. wp::irrlicht::device->sleep (1, false);
  117. }
  118. }
  119. }
  120. return 0;
  121. }