add get hills
This commit is contained in:
parent
5e9082b327
commit
3c4dc154b1
25
src/utils.cpp
Normal file
25
src/utils.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdexcept>
|
||||
#include "utils.hpp"
|
||||
#include "SDL_image.h"
|
||||
#include "data/hills.hpp"
|
||||
|
||||
|
||||
std::vector<SDL_Surface *> get_hills() {
|
||||
std::vector<SDL_Surface *> surfaces;
|
||||
|
||||
for (int i = 0; i < hills_length; i++) {
|
||||
HillData png = hills[i];
|
||||
SDL_RWops *rw = SDL_RWFromMem(const_cast<unsigned char *>(png.data), png.length);
|
||||
if (!rw)
|
||||
throw std::runtime_error("Failed to create RWops from memory");
|
||||
|
||||
SDL_Surface *surface = IMG_Load_RW(rw, 1);
|
||||
if (!surface) {
|
||||
SDL_RWclose(rw);
|
||||
throw std::runtime_error("Failed to load image from memory: " + std::string(IMG_GetError()));
|
||||
}
|
||||
surfaces.push_back(surface);
|
||||
}
|
||||
|
||||
return surfaces;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include "SDL_surface.h"
|
||||
|
||||
template<typename T>
|
||||
constexpr size_t array_len(T *array[]) {
|
||||
@ -10,3 +10,5 @@ constexpr size_t array_len(T *array[]) {
|
||||
i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
std::vector<SDL_Surface*> get_hills();
|
||||
|
Loading…
x
Reference in New Issue
Block a user