Main.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #include <File.h>
  2. #include <FileSystem.h>
  3. #include <Font.h>
  4. #include <GraphicsApi.h>
  5. #include <HttpRequest.h>
  6. #include <JSON.h>
  7. #include <main.h>
  8. #include <Network.h>
  9. #include <RenderThread.h>
  10. #include <Screen.h>
  11. #include <Texture.h>
  12. #include <Window.h>
  13. #include "CustomDX11API.h"
  14. #include "Globals.h"
  15. #include "Initialization.h"
  16. void createModels(Screen* zScreen);
  17. /* Test rendering of specific block types
  18. int KSGStart Framework::Start(Framework::Startparam p)
  19. {
  20. Network::Start(20);
  21. initVariables();
  22. setDebugDX(1);
  23. File d;
  24. d.setFile("data/schriften");
  25. auto list = d.getFileList();
  26. for (Text* fontFile : *list)
  27. {
  28. LTDSFile dat;
  29. dat.setPfad(
  30. new Text(Text("data/schriften/").operator+(fontFile->getText())));
  31. dat.readData();
  32. Text* name = fontFile->getTeilText(0, fontFile->getLength() - 5);
  33. fontRegister->put(*name, RCPointer<Font>::of(dat.loadFont()));
  34. name->release();
  35. }
  36. list->release();
  37. NativeWindow window;
  38. ::window = &window;
  39. WNDCLASS wc = Framework::F_Normal(p.hinst);
  40. wc.lpszClassName = "Factory Craft";
  41. window.create(WS_POPUPWINDOW, wc);
  42. Monitor m = Framework::getMonitor(0);
  43. window.setBounds(Point(m.x, m.y), Point(m.width, m.height));
  44. window.setDisplayMode(SW_SHOWNORMAL);
  45. window.setPreCloseAction([&window](void* p, void* f) {
  46. StopMessageLoop(window.getWindowHandle());
  47. });
  48. window.setMouseAction(_ret1ME);
  49. window.setKeyboardAction(_ret1TE);
  50. Screen3D screen(
  51. dynamic_cast<NativeWindow*>(window.getThis()), new CustomDX11API());
  52. screen.setHandleUserInputsOnTick(1);
  53. window.setScreen(dynamic_cast<Screen*>(screen.getThis()));
  54. screen.setFillColor(0);
  55. uiFactory = Framework::defaultUI(fontRegister->get("normal"), &screen);
  56. createModels(&screen);
  57. // loading textures
  58. File texturF;
  59. texturF.setFile("data/textures");
  60. RCArray<Text>* files = texturF.getFileList();
  61. if (files)
  62. {
  63. int count = 0;
  64. for (Text* fileName : *files)
  65. {
  66. LTDBFile dat;
  67. dat.setFile(new Text(Text("data/textures/") + *fileName));
  68. dat.readData(0);
  69. count += dat.getImageCount();
  70. }
  71. for (Text* fileName : *files)
  72. {
  73. LTDBFile dat;
  74. dat.setFile(new Text(Text("data/textures/") + *fileName));
  75. dat.readData(0);
  76. for (Text* name : *dat.zImageListe())
  77. {
  78. Image* b = dat.load(0, new Text(*name));
  79. screen.zGraphicsApi()
  80. ->createOrGetTexture(*fileName + "/" + *name, b)
  81. ->release();
  82. }
  83. }
  84. files->release();
  85. }
  86. BlockType* type = new BlockType(
  87. 26, 1, ModelInfo("cube", "fluids.ltdb/water.png", 0, 6), 10, 1); //
  88. block type to render Block* b = type->createBlock(Vec3<float>(0, 0, 0));
  89. unsigned char light[] = {255, 255, 255, 255, 255, 255};
  90. b->setLightData(TOP, light);
  91. b->setLightData(NORTH, light);
  92. b->setLightData(EAST, light);
  93. b->setLightData(SOUTH, light);
  94. b->setLightData(WEST, light);
  95. b->setLightData(BOTTOM, light);
  96. Chunk *c = new Chunk(Point(0, 0));
  97. c->setBlock(b);
  98. World3D* w = new World3D();
  99. w->addCollection(c);
  100. Cam3D* kam = new Cam3D();
  101. kam->setStyle(
  102. Cam3D::Style::Movable | Cam3D::Style::Rotatable | Cam3D::Style::Tick);
  103. kam->setPosition(Vec3<float>(10, 0, 0));
  104. kam->setAusrichtung(Vec3<float>(0, 0, 0));
  105. kam->setWorld(w);
  106. screen.addKamera(kam);
  107. RenderTh rTh;
  108. rTh.setMaxFps(60);
  109. rTh.setQuiet(1);
  110. rTh.setScreen(dynamic_cast<Screen*>(screen.getThis()));
  111. rTh.beginn();
  112. StartMessageLoop();
  113. rTh.terminate();
  114. releaseVariables();
  115. Network::Exit();
  116. return 0;
  117. }
  118. */
  119. RenderTh* renderThread;
  120. int KSGStart Framework::Start(Framework::Startparam p)
  121. {
  122. Network::Start(20);
  123. initVariables();
  124. setDebugDX(1);
  125. #ifdef _DEBUG
  126. Logging::LoggingChannel* outputDebugLoggingChannel
  127. = new Framework::Logging::OutputDebugStringLoggingChannel();
  128. Framework::Logging::zLoggingHandler()->addChannel(
  129. Logging::LogLevel::Error, outputDebugLoggingChannel);
  130. Framework::Logging::zLoggingHandler()->addChannel(Logging::LogLevel::Debug,
  131. dynamic_cast<Logging::LoggingChannel*>(
  132. outputDebugLoggingChannel->getThis()));
  133. Framework::Logging::zLoggingHandler()->addChannel(Logging::LogLevel::Info,
  134. dynamic_cast<Logging::LoggingChannel*>(
  135. outputDebugLoggingChannel->getThis()));
  136. Framework::Logging::zLoggingHandler()->addChannel(
  137. Logging::LogLevel::Warning,
  138. dynamic_cast<Logging::LoggingChannel*>(
  139. outputDebugLoggingChannel->getThis()));
  140. Framework::Logging::zLoggingHandler()->addChannel(Logging::LogLevel::Trace,
  141. dynamic_cast<Logging::LoggingChannel*>(
  142. outputDebugLoggingChannel->getThis()));
  143. #endif
  144. File d;
  145. d.setFile("data/schriften");
  146. auto list = d.getFileList();
  147. for (Text* fontFile : *list)
  148. {
  149. LTDSFile dat;
  150. dat.setPfad(
  151. new Text(Text("data/schriften/").operator+(fontFile->getText())));
  152. dat.readData();
  153. Text* name = fontFile->getTeilText(0, fontFile->getLength() - 5);
  154. fontRegister->put(*name, RCPointer<Font>::of(dat.loadFont()));
  155. name->release();
  156. }
  157. list->release();
  158. NativeWindow window;
  159. ::window = &window;
  160. WNDCLASS wc = Framework::F_Normal(p.hinst);
  161. wc.lpszClassName = "Factory Craft";
  162. window.create(WS_POPUPWINDOW, wc);
  163. Monitor m = Framework::getMonitor(0);
  164. window.setBounds(Point(m.x, m.y), Point(m.width, m.height));
  165. window.setDisplayMode(SW_SHOWNORMAL);
  166. window.setPreCloseAction([&window](void* p, void* f) {
  167. StopMessageLoop(window.getWindowHandle());
  168. });
  169. window.setMouseAction(_ret1ME);
  170. window.setKeyboardAction(_ret1TE);
  171. Screen3D screen(
  172. dynamic_cast<NativeWindow*>(window.getThis()), new CustomDX11API());
  173. screen.setHandleUserInputsOnTick(0);
  174. window.setScreen(dynamic_cast<Screen*>(screen.getThis()));
  175. screen.setFillColor(0);
  176. screen.setTestRend(0);
  177. uiFactory = Framework::defaultUI(fontRegister->get("normal"), &screen);
  178. uiFactory.createButton = createButton;
  179. uiFactory.createTextField = createTextField;
  180. uiFactory.createCheckBox = createCheckBox;
  181. uiFactory.createObjTable = createObjTable;
  182. uiFactory.createWindow = createWindow;
  183. initMenus();
  184. RenderTh rTh;
  185. rTh.setMaxFps(-1);
  186. rTh.setQuiet(0);
  187. rTh.setScreen(dynamic_cast<Screen*>(screen.getThis()));
  188. rTh.setTickFunktion([](void* p, void* o, double time) {
  189. if (World::INSTANCE)
  190. {
  191. World::INSTANCE->onTick(time);
  192. }
  193. });
  194. renderThread = &rTh;
  195. rTh.beginn();
  196. StartMessageLoop();
  197. rTh.terminate();
  198. releaseVariables();
  199. Network::Exit();
  200. return 0;
  201. }