A 2D tile-based sandbox game.
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.

ResourceManager.cc 804B

1234567891011121314151617181920212223242526272829
  1. #include "ResourceManager.h"
  2. namespace Cygnet {
  3. ResourceManager::ResourceManager(ResourceBuilder &&builder):
  4. rnd_(builder.rnd_), sprites_(std::move(builder.sprites_)),
  5. tileAnims_(std::move(builder.tileAnims_)) {
  6. size_t width, height;
  7. const unsigned char *data = builder.atlas_.getImage(&width, &height);
  8. rnd_.uploadTileAtlas(data, width, height);
  9. }
  10. ResourceManager::~ResourceManager() {
  11. for (auto &[name, sprite]: sprites_) {
  12. rnd_.destroySprite(sprite);
  13. }
  14. }
  15. void ResourceManager::tick() {
  16. // TODO: Maybe do a GPU->GPU copy instead of an upload from the CPU?
  17. for (auto &anim: tileAnims_) {
  18. anim.index = (anim.index + 1) % anim.frames;
  19. unsigned char *data = anim.data.get() +
  20. SwanCommon::TILE_SIZE * SwanCommon::TILE_SIZE * 4 * anim.index;
  21. rnd_.modifyTile(anim.id, data);
  22. }
  23. }
  24. }