-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoader.cpp
More file actions
61 lines (50 loc) · 1.17 KB
/
Loader.cpp
File metadata and controls
61 lines (50 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "Loader.h"
/**
* @brief Constructor
*/
Loader::Loader(IFetcher* fetcher, int buffer_dimension, int grid_dimension)
{
this->m_fetcher = fetcher;
this->m_buffer_dimension = buffer_dimension;
this->m_grid_dimension = grid_dimension;
}
Loader::~Loader()
{
}
void Loader::initialize(int initialPosition)
{
this->m_position = initialPosition;
}
void Loader::changePosition(int position, DIRECTION direction)
{
this->m_oldPosition = m_position;
this->m_direction = direction;
this->m_position = position;
}
SDL_Surface* Loader::loadSDLSurface(std::string fileName)
{
SDL_Surface* surface;
FILE *fp = fopen(fileName.data(), "rb");
if( fp == NULL ) {
SDL_SetError("Couldn't open %s", fp);
}
else
{
temp_rwop = SDL_RWFromFP(fp, 0);
surface = IMG_LoadJPG_RW(temp_rwop);
SDL_FreeRW(temp_rwop);
temp_rwop = NULL;
fclose(fp);
return surface;
}
return NULL;
}
SDL_Surface* Loader::getCurrentSDLSurface(int a_position, std::string a_domain)
{
m_fetcher->SetPrefix(a_domain);
// Get file name
std::string fileNameLinkedToPosition =
m_fetcher->GetFileNameLinkedToPosition(a_position);
// Get surface
return(this->loadSDLSurface(fileNameLinkedToPosition));
}