FastLoader.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "FastLoader.h"
  2. #include "../FileSystem/ConfigFile.h"
  3. #include "../Constants.h"
  4. #include <stdio.h>
  5. #include "../framework.h"
  6. namespace TLAC::Components
  7. {
  8. FastLoader::FastLoader()
  9. {
  10. }
  11. FastLoader::~FastLoader()
  12. {
  13. }
  14. const char* FastLoader::GetDisplayName()
  15. {
  16. return "fast_loader";
  17. }
  18. void FastLoader::Initialize(ComponentsManager*)
  19. {
  20. TLAC::FileSystem::ConfigFile componentsConfig(TLAC::framework::GetModuleDirectory(), COMPONENTS_CONFIG_FILE_NAME);
  21. bool success = componentsConfig.OpenRead();
  22. if (success)
  23. {
  24. int speed = componentsConfig.GetIntegerValue("fast_loader_speed");
  25. if (speed >= 2 && speed <= 1024) updatesPerFrame = speed;
  26. }
  27. printf("[Fast Loader] Speed: %d\n", updatesPerFrame);
  28. }
  29. void FastLoader::Update()
  30. {
  31. if (dataInitialized)
  32. return;
  33. previousGameState = currentGameState;
  34. currentGameState = *(GameState*)CURRENT_GAME_STATE_ADDRESS;
  35. if (currentGameState == GS_STARTUP)
  36. {
  37. typedef void UpdateTask();
  38. UpdateTask* updateTask = (UpdateTask*)UPDATE_TASKS_ADDRESS;
  39. // speed up TaskSystemStartup
  40. for (int i = 0; i < updatesPerFrame; i++)
  41. updateTask();
  42. constexpr int DATA_INITIALIZED = 3;
  43. // skip TaskDataInit
  44. *(int*)(DATA_INIT_STATE_ADDRESS) = DATA_INITIALIZED;
  45. // skip TaskWarning
  46. *(int*)(SYSTEM_WARNING_ELAPSED_ADDRESS) = 3939;
  47. }
  48. else if (previousGameState == GS_STARTUP)
  49. {
  50. dataInitialized = true;
  51. printf("[TLAC] FastLoader::Update(): Data Initialized\n");
  52. }
  53. }
  54. void FastLoader::UpdateInput()
  55. {
  56. return;
  57. }
  58. }