Textures and sprites are now managed by a single module in textures.hpp, and even though it is a _single_ location to access all sprites it is NOT a singleton. Those are illegal.

This commit is contained in:
Zed A. Shaw 2025-02-21 03:32:44 -05:00
parent f3e1413022
commit 0260e3d345
15 changed files with 142 additions and 170 deletions

38
textures.hpp Normal file
View file

@ -0,0 +1,38 @@
#pragma once
#include <cstdint>
#include <vector>
#include <string>
#include <SFML/Graphics.hpp>
#include <unordered_map>
#include <memory>
#include "matrix.hpp"
namespace textures {
struct SpriteTexture {
std::shared_ptr<sf::Sprite> sprite = nullptr;
std::shared_ptr<sf::Texture> texture = nullptr;
};
struct TextureManager {
std::vector<sf::Image> surfaces;
std::unordered_map<std::string, SpriteTexture> sprite_textures;
std::unordered_map<wchar_t, int> char_to_texture;
sf::Image floor;
sf::Image ceiling;
};
void init();
SpriteTexture get(std::string name);
sf::Image load_image(std::string filename);
const uint32_t* get_surface(size_t num);
matrix::Matrix convert_char_to_texture(matrix::Matrix &from);
const uint32_t* get_floor();
const uint32_t* get_ceiling();
}