pikaGameplay.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #pragma once
  2. #include <iostream>
  3. #include <gl2d/gl2d.h>
  4. #include <imgui.h>
  5. #include <baseContainer.h>
  6. #include <shortcutApi/shortcutApi.h>
  7. #include <pikaSizes.h>
  8. #include <imgui_spinner.h>
  9. struct Test
  10. {
  11. int *ptr = 0;
  12. Test() { ptr = new int(5); }
  13. };
  14. struct Gameplay : public Container
  15. {
  16. gl2d::Renderer2D renderer;
  17. float *r =0;
  18. //todo user can request imgui ids; shortcut manager context; allocators
  19. static ContainerStaticInfo containerInfo()
  20. {
  21. ContainerStaticInfo info = {};
  22. info.defaultHeapMemorySize = pika::MB(10);
  23. info.requestImguiFbo = true; //todo this should not affect the compatibility of input recording
  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. void create(RequestedContainerInfo &requestedInfo)
  41. {
  42. renderer.create();
  43. //pika::initShortcutApi();
  44. r = new float(0);
  45. //void *test = new char[pika::MB(10)]; //todo let the allocator tell the engine somehow that it is out of memory
  46. }
  47. void update(pika::Input input, pika::WindowState windowState,
  48. RequestedContainerInfo &requestedInfo)
  49. {
  50. //todo keep window on top stuff
  51. glClear(GL_COLOR_BUFFER_BIT);
  52. if (pika::shortcut(input, "Ctrl + S"))
  53. {
  54. std::cout << "save \n";
  55. }
  56. //std::cout << "save\n";
  57. if (input.buttons[pika::Button::P].held())
  58. {
  59. std::cout << input.deltaTime;
  60. }
  61. gl2d::enableNecessaryGLFeatures();
  62. renderer.updateWindowMetrics(windowState.w, windowState.h);
  63. *r += input.deltaTime * 4.f;
  64. renderer.renderRectangle({10, 10, 100, 100}, Colors_Red, {}, *r);
  65. //if (input.lMouse.pressed())
  66. //{
  67. // std::cout << "pressed\n";
  68. //}
  69. //if (input.lMouse.released())
  70. //{
  71. // std::cout << "released\n";
  72. //}
  73. //if (input.lMouse.typed())
  74. //{
  75. // std::cout << "typed\n";
  76. //}
  77. //if (input.buttons[pika::Button::E].typed())
  78. //{
  79. // std::cout << "e";
  80. //}
  81. //std::cout << state.deltaTime << "\n";
  82. renderer.flush();
  83. //ImGui::SetAllocatorFunctions(userMalloc, userFree);
  84. //ImGui::Begin("window from gameplay");
  85. //ImGui::Spinner("spinner", 10, 2);
  86. //ImGui::ProgressBar(0.4);
  87. //ImGui::BufferingBar("buffering bar", 0.4, {100, 5});
  88. //ImGui::LoadingIndicatorCircle("circle", 20, 8, 8);
  89. //ImGui::End();
  90. //ImGui::ShowDemoWindow();
  91. }
  92. };
  93. //todo flag to clear screen from engine
  94. //todo error popup
  95. //todo error popup disable in release