add get hills

This commit is contained in:
Love 2024-08-04 15:33:49 +02:00
parent 5e9082b327
commit 3c4dc154b1
2 changed files with 29 additions and 2 deletions

25
src/utils.cpp Normal file
View 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;
}

View File

@ -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();