level.cpp 1006 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "level.h"
  6. #include "level_resource.h"
  7. #include "unit_manager.h"
  8. #include "unit_resource.h"
  9. #include "world.h"
  10. namespace crown
  11. {
  12. Level::Level(Allocator& a, UnitManager& um, World& w, const LevelResource& lr)
  13. : _marker(MARKER)
  14. , _allocator(&a)
  15. , _unit_manager(&um)
  16. , _world(&w)
  17. , _resource(&lr)
  18. , _unit_lookup(a)
  19. {
  20. }
  21. Level::~Level()
  22. {
  23. _marker = 0;
  24. }
  25. void Level::load(const Vector3& pos, const Quaternion& rot)
  26. {
  27. const UnitResource* ur = level_resource::unit_resource(_resource);
  28. const u32 num_units = ur->num_units;
  29. array::resize(_unit_lookup, num_units);
  30. for (u32 i = 0; i < num_units; ++i)
  31. _unit_lookup[i] = _unit_manager->create();
  32. spawn_units(*_world, *ur, pos, rot, array::begin(_unit_lookup));
  33. // Post events
  34. for (u32 i = 0; i < num_units; ++i)
  35. _world->post_unit_spawned_event(_unit_lookup[i]);
  36. }
  37. } // namespace crown