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
64
|
#include "SDL/SDL_stdinc.h"
#include "SDL/SDL_image.h"
#include "graphic.h"
#include "utils.h"
#define SDLSURF_OPTS SDL_HWSURFACE|SDL_HWACCEL|/*SDL_ASYNCBLIT|*/SDL_RLEACCEL
SDL_Surface * createSurface(int width, int height) {
Uint32 rmask, gmask, bmask, amask;
/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
return SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_HWACCEL|/*SDL_ASYNCBLIT|*/SDL_RLEACCEL, width, height, 24, rmask, gmask, bmask, amask);
}
SDL_Surface * makeTerrain(gameIni_t *gIni, gameRess_t *gRess) {
int res, i;
SDL_Rect dstRect;
SDL_Surface *terrain, *tile;
terrain=createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
if (terrain==NULL) {
logs(LOG_ERROR, "makeTerrain(), SDL_CreateRGBSurface() returns NULL");
return NULL;
}
res=SDL_FillRect(terrain, &(terrain->clip_rect), gIni->style.bgColor);
if (res!=0) {
logs(LOG_WARN, "makeTerrain(), SDL_FillRect() failed");
return NULL;
}
for(i=0 ; i < gIni->level.terrainCount ; i++) {
//FIXME : check sanity for id value
tile=gRess->style.tiles[gIni->level.terrains[i].id];
if (tile==NULL) {
logs(LOG_ERROR, "makeTerrain(), tile==NULL");
return NULL;
}
dstRect.x=gIni->level.terrains[i].xpos;
dstRect.y=gIni->level.terrains[i].ypos;
res=SDL_BlitSurface(tile, NULL, terrain, &dstRect);
if (res!=0) {
logs2(LOG_WARN, "makeTerrain(), SDL_BlitSurface()", SDL_GetError());
return NULL;
}
}
return terrain;
}
|