No Description
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.

main.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* The MIT License
  2. *
  3. * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. #include "engine.h"
  24. #include "const.h"
  25. #include "logger.h"
  26. #include "configmanager.h"
  27. #include "resourcemanager.h"
  28. #include "platform.h"
  29. #include "menustate.h"
  30. #include <csignal>
  31. #include <boost/scoped_ptr.hpp>
  32. /// Catches signals so we can exit nicely
  33. void signal_handler(int sig)
  34. {
  35. switch(sig) {
  36. case SIGTERM:
  37. case SIGINT:
  38. case SIGQUIT:
  39. {
  40. static bool stopping = false;
  41. if(!stopping) {
  42. stopping = true;
  43. g_engine.stop();
  44. }
  45. break;
  46. }
  47. }
  48. }
  49. /// Default configurations
  50. void setDefaultConfigs()
  51. {
  52. g_config.setValue("width", 640);
  53. g_config.setValue("height", 480);
  54. }
  55. int main(int argc, const char *argv[])
  56. {
  57. // install our signal handler
  58. signal(SIGTERM, signal_handler);
  59. signal(SIGINT, signal_handler);
  60. signal(SIGQUIT, signal_handler);
  61. // setup resources
  62. g_resources.init(argv[0]);
  63. if(g_resources.setWriteDir(Platform::getAppUserDir()))
  64. g_resources.addToSearchPath(Platform::getAppUserDir());
  65. // before loading configurations set the default ones
  66. setDefaultConfigs();
  67. // load configurations
  68. if(!g_config.load("config.yml"))
  69. notice("Could not read configuration file, default configurations will be used.");
  70. notice(APP_LONGNAME);
  71. // setup the engine
  72. g_engine.init();
  73. // create initial state
  74. boost::scoped_ptr<MenuState> menuState(new MenuState);
  75. g_engine.changeState(menuState.get());
  76. // run
  77. g_engine.run();
  78. // terminate stuff
  79. g_engine.terminate();
  80. // save configurations before exiting
  81. g_config.save();
  82. // unload resources
  83. g_resources.terminate();
  84. return 0;
  85. }