Re-implementation of Izanami game engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.0 KiB

  1. #include "IZ_app.h"
  2. /**
  3. * Logs the application command-line arguments.
  4. * @param argc The argument count.
  5. * @param argv The argument values.
  6. */
  7. void IZ_LogArguments(int argc, char** argv) {
  8. unsigned int i;
  9. for (i = 0; i < argc; i += 1) {
  10. IZ_Log("Argument(%d)=%s", i, argv[i]);
  11. }
  12. }
  13. typedef enum {
  14. IZ_INITIALIZE_FRAMEWORK_RESULT_OK,
  15. IZ_INITIALIZE_FRAMEWORK_RESULT_ERROR,
  16. } IZ_InitializeFrameworkResult;
  17. IZ_InitializeFrameworkResult IZ_InitializeFramework() {
  18. IZ_LogInfo(IZ_LOG_CATEGORY_GENERIC, "Initializing framework...");
  19. if (SDL_Init(
  20. SDL_INIT_VIDEO
  21. | SDL_INIT_GAMECONTROLLER
  22. | SDL_INIT_AUDIO
  23. | SDL_INIT_EVENTS
  24. | SDL_INIT_TIMER
  25. ) < 0) {
  26. IZ_LogError("ERROR! %s", SDL_GetError());
  27. return IZ_INITIALIZE_FRAMEWORK_RESULT_ERROR;
  28. }
  29. IZ_LogInfo(IZ_LOG_CATEGORY_GENERIC, "OK!");
  30. return IZ_INITIALIZE_FRAMEWORK_RESULT_OK;
  31. }
  32. typedef enum {
  33. IZ_INITIALIZE_CONFIG_RESULT_OK,
  34. IZ_INITIALIZE_CONFIG_RESULT_ERROR,
  35. } IZ_InitializeConfigResult;
  36. IZ_InitializeConfigResult IZ_InitializeConfig(IZ_App* app) {
  37. IZ_LogInfo(IZ_LOG_CATEGORY_GENERIC, "Initializing config...");
  38. if (IZ_ConfigLoad(&app->config, IZ_CONFIG_FILE_PATH)) {
  39. return IZ_INITIALIZE_CONFIG_RESULT_ERROR;
  40. }
  41. IZ_LogInfo(IZ_LOG_CATEGORY_GENERIC, "OK!");
  42. return IZ_INITIALIZE_CONFIG_RESULT_OK;
  43. }
  44. IZ_AppResult IZ_Initialize(IZ_App* app, const char* app_name) {
  45. if (IZ_InitializeFramework()) {
  46. return IZ_APP_RESULT_FRAMEWORK_ERROR;
  47. }
  48. if (IZ_InitializeConfig(app)) {
  49. return IZ_APP_RESULT_CONFIG_ERROR;
  50. }
  51. return IZ_APP_RESULT_OK;
  52. }
  53. IZ_AppResult IZ_AppRun(
  54. IZ_App* app,
  55. int argc,
  56. char** argv,
  57. const char* app_name,
  58. unsigned int major_version,
  59. unsigned int minor_version,
  60. unsigned int patch_version
  61. ) {
  62. IZ_TimerStart();
  63. IZ_LogInfo(
  64. IZ_LOG_CATEGORY_GLOBAL,
  65. "Application started (%s v.%d.%d.%d).",
  66. app_name,
  67. major_version,
  68. minor_version,
  69. patch_version
  70. );
  71. IZ_LogArguments(argc, argv);
  72. unsigned int status = IZ_Initialize(app, app_name);
  73. if (status) {
  74. return status;
  75. }
  76. return IZ_APP_RESULT_OK;
  77. }