SDL SPOOKY PLATFORMER ENGINE  0.2.0
An implementation of a platformer using sdl, implemented using an entity component system and efficient collision management.
ImageManager.hpp
Go to the documentation of this file.
1 #ifndef IMAGE_MANAGER_HPP
2 #define IMAGE_MANAGER_HPP
3 
4 #include <SDL2/SDL.h>
5 #include <ResourceManager.hpp>
6 
10 class ImageManager : public ResourceManager<ImageManager, TextureWrapper>
11 {
12 public:
17  {
18  static ImageManager *instance = new ImageManager();
19  return *instance;
20  }
21 
25  int shutDown()
26  {
28  IMG_Quit();
29  return 1;
30  }
31 
37  int startUp(SDL_Renderer *in)
38  {
39  int imgFlags = IMG_INIT_PNG;
40  if (!(IMG_Init(imgFlags) & imgFlags))
41  {
42  SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Couldn't start image manager");
43  return 0;
44  }
45  ren = in;
46  fileMap.emplace("background", "./Assets/images/background.png");
47  return 1;
48  }
49 
55  std::shared_ptr<TextureWrapper> Load(const std::string &path)
56  {
57  SDL_Texture* img = IMG_LoadTexture(ren, path.c_str());
58 
59  if (img == NULL)
60  {
61  printf("%s\n", IMG_GetError());
62  return NULL;
63  }
64  else
65  {
66  SDL_Log("Allocated image memory for %s", path.c_str());
67  std::shared_ptr<SDL_Texture> surface = std::shared_ptr<SDL_Texture>(img, SDL_DestroyTexture);
68  return std::make_shared<TextureWrapper>(surface);
69  }
70  }
71 
72  ImageManager(ImageManager const &) = delete;
73  void operator=(ImageManager const &) = delete;
74 private:
75  SDL_Renderer *ren;
76  ImageManager() {
77  printf("Constructing image manager\n");
78  };
79 };
80 
81 #endif
void operator=(ImageManager const &) = delete
don't allow assignment
std::shared_ptr< TextureWrapper > Load(const std::string &path)
Definition: ImageManager.hpp:55
std::map< std::string, std::string > fileMap
stores location of resources
Definition: ResourceManager.hpp:156
int startUp(SDL_Renderer *in)
Definition: ImageManager.hpp:37
int shutDown()
Definition: ResourceManager.hpp:69
int shutDown()
Definition: ImageManager.hpp:25
static ImageManager & instance()
Definition: ImageManager.hpp:16
Definition: ResourceManager.hpp:62
Definition: ImageManager.hpp:10