pikaGameplay.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #pragma once
  2. #include <gl2d/gl2d.h>
  3. #include <imgui.h>
  4. #include <baseContainer.h>
  5. #include <shortcutApi/shortcutApi.h>
  6. #include <pikaSizes.h>
  7. #include <imgui_spinner.h>
  8. struct Test
  9. {
  10. int *ptr = 0;
  11. Test() { ptr = new int(5); }
  12. };
  13. struct Gameplay : public Container
  14. {
  15. gl2d::Renderer2D renderer;
  16. float *r = 0;
  17. //todo user can request imgui ids; shortcut manager context; allocators
  18. static ContainerStaticInfo containerInfo()
  19. {
  20. ContainerStaticInfo info = {};
  21. info.defaultHeapMemorySize = pika::MB(10);
  22. info.requestImguiFbo = true; //todo this should not affect the compatibility of input recording
  23. //info.openOnApplicationStartup = true;
  24. //info.bonusAllocators.push_back(100);
  25. //info.bonusAllocators.push_back(200);
  26. //info.bonusAllocators.push_back(300);
  27. //info.bonusAllocators.push_back(400);
  28. //info.bonusAllocators.push_back(100);
  29. //info.bonusAllocators.push_back(200);
  30. //info.bonusAllocators.push_back(300);
  31. //info.bonusAllocators.push_back(400);
  32. //info.bonusAllocators.push_back(100);
  33. //info.bonusAllocators.push_back(200);
  34. //info.bonusAllocators.push_back(300);
  35. //info.bonusAllocators.push_back(400);
  36. //info.bonusAllocators.push_back(200);
  37. //info.bonusAllocators.push_back(200);
  38. return info;
  39. }
  40. bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
  41. {
  42. renderer.create(requestedInfo.requestedFBO.fbo);
  43. //pika::initShortcutApi();
  44. r = new float;
  45. //void *test = new char[pika::MB(10)]; //todo let the allocator tell the engine somehow that it is out of memory
  46. return true;
  47. }
  48. bool update(pika::Input input, pika::WindowState windowState,
  49. RequestedContainerInfo &requestedInfo)
  50. {
  51. //todo keep window on top stuff
  52. if (input.buttons[pika::Button::A].released())
  53. {
  54. //.. A button was released
  55. }
  56. glClear(GL_COLOR_BUFFER_BIT);
  57. if (pika::shortcut(input, "Ctrl + S"))
  58. {
  59. requestedInfo.consoleWrite("save\n");
  60. }
  61. //if (input.buttons[pika::Button::S].released())
  62. //{
  63. // requestedInfo.consoleWrite("save\n");
  64. //}
  65. if (input.buttons[pika::Button::G].released())
  66. {
  67. requestedInfo.createContainer("Gameplay");
  68. }
  69. requestedInfo.consoleWrite(input.typedInput);
  70. if (input.buttons[pika::Button::P].held())
  71. {
  72. requestedInfo.consoleWrite(std::to_string(input.deltaTime).c_str());
  73. }
  74. gl2d::enableNecessaryGLFeatures();
  75. renderer.updateWindowMetrics(windowState.windowW, windowState.windowH);
  76. *r += input.deltaTime * 4.f;
  77. if (input.hasFocus)
  78. {
  79. renderer.renderRectangle({10, 10, 100, 100}, Colors_Green, {}, *r);
  80. }
  81. else
  82. {
  83. renderer.renderRectangle({10, 10, 100, 100}, Colors_Blue, {}, *r);
  84. }
  85. int size = 11;
  86. renderer.renderRectangle({input.mouseX-size/2, input.mouseY-size/2, size, size},
  87. Colors_Red, {}, 0.f);
  88. //requestedInfo.consoleWrite((std::string("Mouse: ") + std::to_string(input.mouseX) + " " +
  89. // std::to_string(input.mouseY) + "\n").c_str());
  90. //if (input.lMouse.pressed())
  91. //{
  92. // std::cout << "pressed\n";
  93. //}
  94. //if (input.lMouse.released())
  95. //{
  96. // std::cout << "released\n";
  97. //}
  98. //if (input.lMouse.typed())
  99. //{
  100. // std::cout << "typed\n";
  101. //}
  102. //if (input.buttons[pika::Button::E].typed())
  103. //{
  104. // std::cout << "e";
  105. //}
  106. //std::cout << state.deltaTime << "\n";
  107. renderer.flush();
  108. //ImGui::SetAllocatorFunctions(userMalloc, userFree);
  109. //ImGui::Begin("window from gameplay");
  110. //ImGui::Spinner("spinner", 10, 2);
  111. //ImGui::ProgressBar(0.4);
  112. //ImGui::BufferingBar("buffering bar", 0.4, {100, 5});
  113. //ImGui::LoadingIndicatorCircle("circle", 20, 8, 8);
  114. //ImGui::End();
  115. //ImGui::ShowDemoWindow();
  116. return true;
  117. }
  118. //optional
  119. void destruct(RequestedContainerInfo &requestedInfo)
  120. {
  121. }
  122. };
  123. //todo flag to clear screen from engine
  124. //todo error popup
  125. //todo error popup disable in release