Main.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. int KSGStart Framework::Start(Framework::Startparam p)
  120. {
  121. Network::Start(20);
  122. initVariables();
  123. setDebugDX(1);
  124. #ifdef _DEBUG
  125. Logging::LoggingChannel* outputDebugLoggingChannel
  126. = new Framework::Logging::OutputDebugStringLoggingChannel();
  127. Framework::Logging::zLoggingHandler()->addChannel(
  128. Logging::LogLevel::Error, outputDebugLoggingChannel);
  129. Framework::Logging::zLoggingHandler()->addChannel(Logging::LogLevel::Debug,
  130. dynamic_cast<Logging::LoggingChannel*>(
  131. outputDebugLoggingChannel->getThis()));
  132. Framework::Logging::zLoggingHandler()->addChannel(Logging::LogLevel::Info,
  133. dynamic_cast<Logging::LoggingChannel*>(
  134. outputDebugLoggingChannel->getThis()));
  135. Framework::Logging::zLoggingHandler()->addChannel(
  136. Logging::LogLevel::Warning,
  137. dynamic_cast<Logging::LoggingChannel*>(
  138. outputDebugLoggingChannel->getThis()));
  139. Framework::Logging::zLoggingHandler()->addChannel(Logging::LogLevel::Trace,
  140. dynamic_cast<Logging::LoggingChannel*>(
  141. outputDebugLoggingChannel->getThis()));
  142. #endif
  143. File d;
  144. d.setFile("data/schriften");
  145. auto list = d.getFileList();
  146. for (Text* fontFile : *list)
  147. {
  148. LTDSFile dat;
  149. dat.setPfad(
  150. new Text(Text("data/schriften/").operator+(fontFile->getText())));
  151. dat.readData();
  152. Text* name = fontFile->getTeilText(0, fontFile->getLength() - 5);
  153. fontRegister->put(*name, RCPointer<Font>::of(dat.loadFont()));
  154. name->release();
  155. }
  156. list->release();
  157. NativeWindow window;
  158. ::window = &window;
  159. WNDCLASS wc = Framework::F_Normal(p.hinst);
  160. wc.lpszClassName = "Factory Craft";
  161. window.create(WS_POPUPWINDOW, wc);
  162. Monitor m = Framework::getMonitor(0);
  163. window.setBounds(Point(m.x, m.y), Point(m.width, m.height));
  164. window.setDisplayMode(SW_SHOWNORMAL);
  165. window.setPreCloseAction([&window](void* p, void* f) {
  166. StopMessageLoop(window.getWindowHandle());
  167. });
  168. window.setMouseAction(_ret1ME);
  169. window.setKeyboardAction(_ret1TE);
  170. Screen3D screen(
  171. dynamic_cast<NativeWindow*>(window.getThis()), new CustomDX11API());
  172. screen.setHandleUserInputsOnTick(1);
  173. window.setScreen(dynamic_cast<Screen*>(screen.getThis()));
  174. screen.setFillColor(0);
  175. screen.setTestRend(0);
  176. uiFactory = Framework::defaultUI(fontRegister->get("normal"), &screen);
  177. uiFactory.createButton = createButton;
  178. uiFactory.createTextField = createTextField;
  179. uiFactory.createCheckBox = createCheckBox;
  180. uiFactory.createObjTable = createObjTable;
  181. uiFactory.createWindow = createWindow;
  182. initMenus();
  183. RenderTh rTh;
  184. rTh.setMaxFps(-1);
  185. rTh.setQuiet(0);
  186. rTh.setScreen(dynamic_cast<Screen*>(screen.getThis()));
  187. rTh.setTickFunktion([](void* p, void* o, double time) {
  188. if (World::INSTANCE)
  189. {
  190. World::INSTANCE->onTick(time);
  191. }
  192. });
  193. rTh.beginn();
  194. StartMessageLoop();
  195. rTh.terminate();
  196. releaseVariables();
  197. Network::Exit();
  198. return 0;
  199. }