boot_config.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "boot_config.h"
  6. #include "json_object.h"
  7. #include "map.h"
  8. #include "platform.h"
  9. #include "sjson.h"
  10. #include "temp_allocator.h"
  11. namespace crown
  12. {
  13. BootConfig::BootConfig()
  14. : boot_script_name(u64(0))
  15. , boot_package_name(u64(0))
  16. , window_w(CROWN_DEFAULT_WINDOW_WIDTH)
  17. , window_h(CROWN_DEFAULT_WINDOW_HEIGHT)
  18. , vsync(true)
  19. {
  20. }
  21. bool BootConfig::parse(const char* json)
  22. {
  23. TempAllocator4096 ta;
  24. JsonObject cfg(ta);
  25. sjson::parse(json, cfg);
  26. // General configs
  27. boot_script_name = sjson::parse_resource_id(cfg["boot_script"]);
  28. boot_package_name = sjson::parse_resource_id(cfg["boot_package"]);
  29. // Platform-specific configs
  30. if (json_object::has(cfg, CROWN_PLATFORM_NAME))
  31. {
  32. JsonObject platform(ta);
  33. sjson::parse(cfg[CROWN_PLATFORM_NAME], platform);
  34. if (json_object::has(platform, "renderer"))
  35. {
  36. JsonObject renderer(ta);
  37. sjson::parse(platform["renderer"], renderer);
  38. if (json_object::has(renderer, "window_width"))
  39. window_w = (u16)sjson::parse_int(renderer["window_width"]);
  40. if (json_object::has(renderer, "window_height"))
  41. window_h = (u16)sjson::parse_int(renderer["window_height"]);
  42. if (json_object::has(renderer, "vsync"))
  43. vsync = sjson::parse_bool(renderer["vsync"]);
  44. }
  45. }
  46. return true;
  47. }
  48. } // namespace crown