-
Notifications
You must be signed in to change notification settings - Fork 1
/
DataStream.cpp
63 lines (52 loc) · 998 Bytes
/
DataStream.cpp
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
61
62
63
#include "DataStream.h"
DataStream::DataStream()
{
mImages[0] = NULL;
mImages[1] = NULL;
mImages[2] = NULL;
mImages[3] = NULL;
mCurrentImage = 0;
mDelayFrames = 4;
}
bool DataStream::loadMedia()
{
bool success = true;
for (int i = 0; i < 4; ++i)
{
char path[64] = "";
sprintf_s(path, "42_texture_streaming/foo_walk_%d.png", i);
SDL_Surface* loadedSurface = IMG_Load(path);
if (loadedSurface == NULL)
{
printf("Unable to load %s! SDL_image error: %s\n", path, IMG_GetError());
success = false;
}
else
{
mImages[i] = SDL_ConvertSurfaceFormat(loadedSurface, SDL_PIXELFORMAT_RGBA8888, NULL);
}
SDL_FreeSurface(loadedSurface);
}
return success;
}
void DataStream::free()
{
for (int i = 0; i < 4; ++i)
{
SDL_FreeSurface(mImages[i]);
}
}
void* DataStream::getBuffer()
{
--mDelayFrames;
if (mDelayFrames == 0)
{
++mCurrentImage;
mDelayFrames = 4;
}
if (mCurrentImage == 4)
{
mCurrentImage = 0;
}
return mImages[mCurrentImage]->pixels;
}