author | sudonix <sudonix> | 2004-02-26 02:25:15 (UTC) |
---|---|---|
committer | sudonix <sudonix> | 2004-02-26 02:25:15 (UTC) |
commit | b339031e14a607ff18e404e0395b1c2782b92fdc (patch) (unidiff) | |
tree | ecd65299976322166ee5dfb2c30f045dd542c1e1 /noncore/games/sfcave-sdl/util.cpp | |
parent | cb72ff620022306e493421006b024b971449f864 (diff) | |
download | opie-b339031e14a607ff18e404e0395b1c2782b92fdc.zip opie-b339031e14a607ff18e404e0395b1c2782b92fdc.tar.gz opie-b339031e14a607ff18e404e0395b1c2782b92fdc.tar.bz2 |
SDL includes corrected, CRs in some files removed, just for consistency :)
Diffstat (limited to 'noncore/games/sfcave-sdl/util.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/sfcave-sdl/util.cpp | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/noncore/games/sfcave-sdl/util.cpp b/noncore/games/sfcave-sdl/util.cpp index f73e256..743f16e 100644 --- a/noncore/games/sfcave-sdl/util.cpp +++ b/noncore/games/sfcave-sdl/util.cpp | |||
@@ -1,75 +1,75 @@ | |||
1 | #include "SDL.h" | 1 | #include <SDL/SDL.h> |
2 | 2 | ||
3 | #include <dirent.h> | 3 | #include <dirent.h> |
4 | 4 | ||
5 | #include <vector> | 5 | #include <vector> |
6 | using namespace std; | 6 | using namespace std; |
7 | 7 | ||
8 | #include "util.h" | 8 | #include "util.h" |
9 | #include "random.h" | 9 | #include "random.h" |
10 | 10 | ||
11 | Uint32 getpixel(SDL_Surface *surface, int x, int y) | 11 | Uint32 getpixel(SDL_Surface *surface, int x, int y) |
12 | { | 12 | { |
13 | int bpp = surface->format->BytesPerPixel; | 13 | int bpp = surface->format->BytesPerPixel; |
14 | /* Here p is the address to the pixel we want to retrieve */ | 14 | /* Here p is the address to the pixel we want to retrieve */ |
15 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; | 15 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
16 | 16 | ||
17 | switch(bpp) { | 17 | switch(bpp) { |
18 | case 1: | 18 | case 1: |
19 | return *p; | 19 | return *p; |
20 | 20 | ||
21 | case 2: | 21 | case 2: |
22 | return *(Uint16 *)p; | 22 | return *(Uint16 *)p; |
23 | 23 | ||
24 | case 3: | 24 | case 3: |
25 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | 25 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) |
26 | return p[0] << 16 | p[1] << 8 | p[2]; | 26 | return p[0] << 16 | p[1] << 8 | p[2]; |
27 | else | 27 | else |
28 | return p[0] | p[1] << 8 | p[2] << 16; | 28 | return p[0] | p[1] << 8 | p[2] << 16; |
29 | 29 | ||
30 | case 4: | 30 | case 4: |
31 | return *(Uint32 *)p; | 31 | return *(Uint32 *)p; |
32 | 32 | ||
33 | default: | 33 | default: |
34 | return 0; /* shouldn't happen, but avoids warnings */ | 34 | return 0; /* shouldn't happen, but avoids warnings */ |
35 | } | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
38 | string chooseRandomFile( string path, string fileType ) | 38 | string chooseRandomFile( string path, string fileType ) |
39 | { | 39 | { |
40 | vector<string> files; | 40 | vector<string> files; |
41 | DIR *d = opendir( path.c_str() ); | 41 | DIR *d = opendir( path.c_str() ); |
42 | if ( !d ) | 42 | if ( !d ) |
43 | return ""; | 43 | return ""; |
44 | 44 | ||
45 | struct dirent *item = readdir( d ); | 45 | struct dirent *item = readdir( d ); |
46 | while ( item ) | 46 | while ( item ) |
47 | { | 47 | { |
48 | string file = string( path ) + item->d_name; | 48 | string file = string( path ) + item->d_name; |
49 | 49 | ||
50 | // Rip extension from file | 50 | // Rip extension from file |
51 | int pos = file.find( ".", 1 ) + 1; | 51 | int pos = file.find( ".", 1 ) + 1; |
52 | string tmp = file.substr( pos ); | 52 | string tmp = file.substr( pos ); |
53 | if ( tmp.size() > 0 && fileType.find( tmp ) != -1 ) | 53 | if ( tmp.size() > 0 && fileType.find( tmp ) != -1 ) |
54 | { | 54 | { |
55 | files.push_back( file ); | 55 | files.push_back( file ); |
56 | } | 56 | } |
57 | item = readdir( d ); | 57 | item = readdir( d ); |
58 | } | 58 | } |
59 | 59 | ||
60 | closedir( d ); | 60 | closedir( d ); |
61 | return files[nextInt( files.size() )]; | 61 | return files[nextInt( files.size() )]; |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
65 | string getHomeDir() | 65 | string getHomeDir() |
66 | { | 66 | { |
67 | string home; | 67 | string home; |
68 | #ifdef QWS | 68 | #ifdef QWS |
69 | home = getenv( "HOME" ); | 69 | home = getenv( "HOME" ); |
70 | #else | 70 | #else |
71 | home = "."; | 71 | home = "."; |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | return home; | 74 | return home; |
75 | } | 75 | } |