- Timestamp:
- Apr 10, 2008, 11:08:14 PM (15 years ago)
- Location:
- abuse/trunk/src
- Files:
-
- 35 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/control.cpp
r124 r134 13 13 #include "control.hpp" 14 14 #include "specs.hpp" 15 #include "loader.hpp"16 15 #include "hpoint.hpp" 17 16 #include "ability.hpp" -
abuse/trunk/src/game.cpp
r129 r134 29 29 #include "ability.hpp" 30 30 #include "cache.hpp" 31 #include "loader.hpp"32 31 #include "lisp.hpp" 33 32 #include "jrand.hpp" … … 1219 1218 void do_title() 1220 1219 { 1221 if(cdc_logo != -1) 1222 { 1223 if(sound_avail & MUSIC_INITIALIZED) 1224 { 1225 if(current_song) 1220 if(cdc_logo == -1) 1221 return; 1222 1223 if(sound_avail & MUSIC_INITIALIZED) 1224 { 1225 if(current_song) 1226 { 1227 current_song->stop(); 1228 delete current_song; 1229 } 1230 current_song = new song("music/intro.hmi"); 1231 current_song->play(music_volume); 1232 } 1233 1234 void *logo_snd = symbol_value(make_find_symbol("LOGO_SND")); 1235 1236 if(DEFINEDP(logo_snd) && (sound_avail & SFX_INITIALIZED)) 1237 cache.sfx(lnumber_value(logo_snd))->play(sfx_volume); 1238 1239 // This must be a dynamic allocated image because if it 1240 // is not and the window gets closed during do_title, then 1241 // exit() will try to delete (through the desctructor of 1242 // image_list in image.cpp) the image on the stack -> boom. 1243 image *blank = new image(2, 2); 1244 blank->clear(); 1245 wm->set_mouse_shape(blank->copy(), 0, 0); // hide mouse 1246 delete blank; 1247 fade_in(cache.img(cdc_logo), 32); 1248 1249 milli_wait(400); 1250 1251 void *space_snd = symbol_value(make_find_symbol("SPACE_SND")); 1252 1253 fade_out(32); 1254 milli_wait(100); 1255 1256 int i; 1257 char *str = lstring_value(eval(make_find_symbol("plot_start"))); 1258 1259 bFILE *fp = open_file("art/smoke.spe", "rb"); 1260 if(!fp->open_failure()) 1261 { 1262 spec_directory sd(fp); 1263 palette *old_pal = pal; 1264 pal = new palette(sd.find(SPEC_PALETTE), fp); 1265 pal->shift(1); 1266 1267 image *gray = new image(sd.find("gray_pict"), fp); 1268 image *smoke[5]; 1269 1270 char nm[20]; 1271 for(i = 0; i < 5; i++) 1272 { 1273 sprintf(nm, "smoke%04d.pcx", i + 1); 1274 smoke[i] = new image(sd.find(nm), fp); 1275 } 1276 1277 screen->clear(); 1278 pal->load(); 1279 1280 int dx = (xres + 1) / 2 - gray->width() / 2, dy = (yres + 1) / 2 - gray->height() / 2; 1281 gray->put_image(screen, dx, dy); 1282 smoke[0]->put_image(screen, dx + 24, dy + 5); 1283 1284 fade_in(NULL, 16); 1285 uint8_t cmap[32]; 1286 for(i = 0; i < 32; i++) 1287 cmap[i] = pal->find_closest(i * 256 / 32, i * 256 / 32, i * 256 / 32); 1288 1289 event ev; 1290 ev.type = EV_SPURIOUS; 1291 time_marker start; 1292 1293 for(i = 0; i < 320 && (ev.type != EV_KEY && ev.type != EV_MOUSE_BUTTON); i++) 1294 { 1295 gray->put_image(screen, dx, dy); 1296 smoke[i % 5]->put_image(screen, dx + 24, dy + 5); 1297 text_draw(205 - i, dx + 15, dy, dx + 320 - 15, dy + 199, str, wm->font(), cmap, wm->bright_color()); 1298 wm->flush_screen(); 1299 time_marker now; 1300 1301 while(now.diff_time(&start) < 0.18) 1226 1302 { 1227 current_song->stop();1228 delete current_song;1303 milli_wait(20); // ECS - Added the wait, so CPU utilization stays low during the story 1304 now.get_time(); 1229 1305 } 1230 current_song = new song("music/intro.hmi"); 1231 current_song->play(music_volume); 1232 } 1233 1234 void *logo_snd = symbol_value(make_find_symbol("LOGO_SND")); 1235 1236 if(DEFINEDP(logo_snd) && (sound_avail & SFX_INITIALIZED)) 1237 cache.sfx(lnumber_value(logo_snd))->play(sfx_volume); 1238 1239 // This must be a dynamic allocated image because if it 1240 // is not and the window gets closed during do_title, then 1241 // exit() will try to delete (through the desctructor of 1242 // image_list in image.cpp) the image on the stack -> boom. 1243 image *blank = new image(2, 2); 1244 blank->clear(); 1245 wm->set_mouse_shape(blank->copy(), 0, 0); // hide mouse 1246 delete blank; 1247 fade_in(cache.img(cdc_logo), 32); 1248 1249 milli_wait(400); 1250 1251 void *space_snd = symbol_value(make_find_symbol("SPACE_SND")); 1252 1253 fade_out(32); 1254 milli_wait(100); 1255 1256 int i; 1257 char *str = lstring_value(eval(make_find_symbol("plot_start"))); 1258 1259 bFILE *fp = open_file("art/smoke.spe", "rb"); 1260 if(!fp->open_failure()) 1261 { 1262 spec_directory sd(fp); 1263 palette *old_pal = pal; 1264 pal = new palette(sd.find(SPEC_PALETTE), fp); 1265 pal->shift(1); 1266 1267 image *gray = new image(sd.find("gray_pict"), fp); 1268 image *smoke[5]; 1269 1270 char nm[20]; 1271 for(i = 0; i < 5; i++) 1306 1307 start.get_time(); 1308 1309 while(wm->event_waiting() && ev.type != EV_KEY) 1272 1310 { 1273 sprintf(nm, "smoke%04d.pcx", i + 1); 1274 smoke[i] = new image(sd.find(nm), fp); 1311 wm->get_event(ev); 1275 1312 } 1276 1277 screen->clear(); 1278 pal->load(); 1279 1280 int dx = (xres + 1) / 2 - gray->width() / 2, dy = (yres + 1) / 2 - gray->height() / 2; 1281 gray->put_image(screen, dx, dy); 1282 smoke[0]->put_image(screen, dx + 24, dy + 5); 1283 1284 fade_in(NULL, 16); 1285 uint8_t cmap[32]; 1286 for(i = 0; i < 32; i++) 1287 cmap[i] = pal->find_closest(i * 256 / 32, i * 256 / 32, i * 256 / 32); 1288 1289 event ev; 1290 ev.type = EV_SPURIOUS; 1291 time_marker start; 1292 1293 for(i = 0; i < 320 && (ev.type != EV_KEY && ev.type != EV_MOUSE_BUTTON); i++) 1313 if((i % 5) == 0 && DEFINEDP(space_snd) && (sound_avail & SFX_INITIALIZED)) 1294 1314 { 1295 gray->put_image(screen, dx, dy); 1296 smoke[i % 5]->put_image(screen, dx + 24, dy + 5); 1297 text_draw(205 - i, dx + 15, dy, dx + 320 - 15, dy + 199, str, wm->font(), cmap, wm->bright_color()); 1298 wm->flush_screen(); 1299 time_marker now; 1300 1301 while(now.diff_time(&start) < 0.18) 1302 { 1303 milli_wait(20); // ECS - Added the wait, so CPU utilization stays low during the story 1304 now.get_time(); 1305 } 1306 1307 start.get_time(); 1308 1309 while(wm->event_waiting() && ev.type != EV_KEY) 1310 { 1311 wm->get_event(ev); 1312 } 1313 if((i % 5) == 0 && DEFINEDP(space_snd) && (sound_avail & SFX_INITIALIZED)) 1314 { 1315 cache.sfx(lnumber_value(space_snd))->play(sfx_volume * 90 / 127); 1316 } 1315 cache.sfx(lnumber_value(space_snd))->play(sfx_volume * 90 / 127); 1317 1316 } 1318 1319 the_game->reset_keymap(); 1320 1321 fade_out(16); 1322 1323 for(i = 0; i < 5; i++) 1324 delete smoke[i];1325 delete gray;1326 delete pal;1327 pal = old_pal;1328 }1329 delete fp;1330 1331 if(title_screen >= 0) 1332 fade_in(cache.img(title_screen), 32);1333 }1317 } 1318 1319 the_game->reset_keymap(); 1320 1321 fade_out(16); 1322 1323 for(i = 0; i < 5; i++) 1324 delete smoke[i]; 1325 delete gray; 1326 delete pal; 1327 pal = old_pal; 1328 } 1329 delete fp; 1330 1331 if(title_screen >= 0) 1332 fade_in(cache.img(title_screen), 32); 1334 1333 } 1335 1334 -
abuse/trunk/src/game.hpp
r127 r134 16 16 #include "image.hpp" 17 17 #include "video.hpp" 18 #include "mdlread.hpp"19 18 #include "event.hpp" 20 19 #include "fonts.hpp" 21 #include "loader.hpp"22 20 #include "items.hpp" 23 21 #include "jwindow.hpp" -
abuse/trunk/src/imlib/Makefile.am
r130 r134 4 4 libimlib_a_SOURCES = \ 5 5 filter.cpp filter.hpp \ 6 gifread.cpp gifread.hpp \7 6 globals.cpp \ 8 7 image.cpp image.hpp \ 9 8 linked.cpp linked.hpp \ 10 9 input.cpp input.hpp \ 11 mdlread.cpp mdlread.hpp \12 10 palette.cpp palette.hpp \ 13 ppmread.cpp ppmread.hpp \14 11 include.cpp include.hpp \ 15 xwdread.cpp xwdread.hpp \16 12 fonts.cpp fonts.hpp \ 17 decoder.cpp \18 loader.cpp loader.hpp \19 glread.cpp glread.hpp \20 texture.cpp texture.hpp \21 13 specs.cpp specs.hpp \ 22 14 supmorph.cpp supmorph.hpp \ 23 image24.cpp image24.hpp \24 15 pcxread.cpp pcxread.hpp \ 25 16 timage.cpp timage.hpp \ 26 17 jrand.cpp jrand.hpp \ 27 lbmread.cpp lbmread.hpp \28 targa.cpp targa.hpp \29 18 keys.cpp keys.hpp \ 30 19 dprint.cpp dprint.hpp \ 31 20 status.cpp status.hpp \ 32 visobj.cpp visobj.hpp \33 packet.cpp packet.hpp \34 21 readwav.cpp readwav.hpp \ 35 22 pmenu.cpp pmenu.hpp \ … … 40 27 sprite.cpp sprite.hpp \ 41 28 jwindow.cpp jwindow.hpp \ 42 main.hpp macs.hpp video.hpp gifdecod.hpp event.hpp mouse.hpp timing.hpp \43 jdir.hpp emm.hpp system.h std.h dos.h dir.h errs.h \29 main.hpp macs.hpp video.hpp event.hpp mouse.hpp timing.hpp jdir.hpp \ 30 system.h \ 44 31 $(NULL) 45 32 -
abuse/trunk/src/imlib/jdir.hpp
r57 r134 13 13 void get_directory(char *path, char **&files, int &tfiles, char **&dirs, int &tdirs); 14 14 15 16 15 #endif -
abuse/trunk/src/imlib/palette.cpp
r129 r134 15 15 #include "image.hpp" 16 16 #include "macs.hpp" 17 #include "dos.h"18 17 #include "video.hpp" 19 18 #include "filter.hpp" -
abuse/trunk/src/imlib/pcxread.cpp
r124 r134 23 23 } PCX_header; 24 24 25 int read_PCX_header(FILE *fp)26 {27 if (!fread(&PCX_header.manufactururer,1,1,fp)) return 0;28 if (!fread(&PCX_header.version,1,1,fp)) return 0;29 if (!fread(&PCX_header.encoding,1,1,fp)) return 0;30 if (!fread(&PCX_header.bits_per_pixel,1,1,fp)) return 0;31 PCX_header.xmin=read_uint16(fp);32 PCX_header.ymin=read_uint16(fp);33 PCX_header.xmax=read_uint16(fp);34 PCX_header.ymax=read_uint16(fp);35 PCX_header.hres=read_uint16(fp);36 PCX_header.vres=read_uint16(fp);37 if (!fread(PCX_header.palette,1,48,fp)) return 0;38 if (!fread(&PCX_header.reserved,1,1,fp)) return 0;39 if (!fread(&PCX_header.color_planes,1,1,fp)) return 0;40 PCX_header.bytes_per_line=read_uint16(fp);41 PCX_header.palette_type=read_uint16(fp);42 if (!fread(PCX_header.filter,1,58,fp)) return 0;43 return 1;44 }45 46 25 int write_PCX_header(FILE *fp) 47 26 { … … 65 44 } 66 45 67 68 69 PCX_type PCX_file_type(char const *filename)70 {71 FILE *fp=fopen(filename,"rb");72 if (!fp)73 { set_error(imREAD_ERROR);74 return not_PCX;75 }76 77 if (!read_PCX_header(fp))78 {79 fclose(fp);80 set_error(imREAD_ERROR);81 return not_PCX;82 }83 fclose(fp);84 if (PCX_header.manufactururer!=10)85 return not_PCX;86 if (PCX_header.color_planes==3 && PCX_header.bits_per_pixel==8)87 return PCX_24;88 else if (PCX_header.color_planes==1 && PCX_header.bits_per_pixel==8)89 return PCX_8;90 else return not_PCX;91 }92 93 void read_PCX_line(FILE *fp, unsigned char *start, short skip, int width)94 {95 int c,n=0,i;96 97 do98 {99 c=fgetc(fp)&0xff;100 if ((c&0xc0)==0xc0)101 {102 i=c&0x3f;103 c=fgetc(fp);104 while (i--)105 {106 *start=c;107 start+=skip;108 n++;109 }110 }111 else112 {113 *start=c;114 start+=skip;115 n++;116 }117 } while (n<width);118 }119 120 121 image24 *read_PCX24(char const *filename)122 {123 if (PCX_file_type(filename)!=PCX_24) return NULL;124 FILE *fp=fopen(filename,"rb");125 read_PCX_header(fp);126 image24 *im=new image24(PCX_header.xmax-PCX_header.xmin+1,127 PCX_header.ymax-PCX_header.ymin+1);128 int y;129 for (y=0;y<im->height();y++)130 {131 read_PCX_line(fp,im->scan_line(y),3,PCX_header.bytes_per_line);132 read_PCX_line(fp,im->scan_line(y)+1,3,PCX_header.bytes_per_line);133 read_PCX_line(fp,im->scan_line(y)+2,3,PCX_header.bytes_per_line);134 }135 fclose(fp);136 return im;137 }138 139 image *read_PCX(char const *filename, palette *&pal)140 {141 if (PCX_file_type(filename)!=PCX_8) return NULL;142 FILE *fp=fopen(filename,"rb");143 read_PCX_header(fp);144 145 image *im=new image(PCX_header.xmax-PCX_header.xmin+1,146 PCX_header.ymax-PCX_header.ymin+1);147 int y;148 for (y=0;y<im->height();y++)149 read_PCX_line(fp,im->scan_line(y),1,PCX_header.bytes_per_line);150 unsigned char palette_confirm;151 if (!fread(&palette_confirm,1,1,fp) || palette_confirm!=12)152 {153 pal=new palette;154 pal->defaults();155 }156 else157 {158 pal=new palette;159 fread(pal->addr(),1,256*3,fp);160 }161 fclose(fp);162 return im;163 }164 165 46 void write_PCX(image *im, palette *pal, char const *filename) 166 47 { … … 171 52 return ; 172 53 } 173 174 54 175 55 PCX_header.manufactururer=10; … … 188 68 PCX_header.palette_type=0; 189 69 memset(PCX_header.filter,0,58); 190 191 70 192 71 if (!write_PCX_header(fp)) … … 226 105 } 227 106 228 229 -
abuse/trunk/src/imlib/pcxread.hpp
r57 r134 12 12 13 13 #include "image.hpp" 14 #include "image24.hpp"15 14 #include "palette.hpp" 16 15 17 enum PCX_type { not_PCX, PCX_8, PCX_24 };18 19 PCX_type PCX_file_type(char const *filename);20 image24 *read_PCX24(char const *filename);21 image *read_PCX(char const *filename, palette *&pal);22 16 void write_PCX(image *im, palette *pal, char const *filename); 23 17 -
abuse/trunk/src/imlib/sprite.cpp
r124 r134 13 13 14 14 #include "macs.hpp" 15 #include "mdlread.hpp"16 15 #include "video.hpp" 17 16 #include "image.hpp" 18 17 #include "palette.hpp" 19 18 #include "linked.hpp" 20 #include "glread.hpp"21 #include "gifread.hpp"22 #include "ppmread.hpp"23 #include "emm.hpp"24 19 #include "sprite.hpp" 25 20 -
abuse/trunk/src/sdlport/mouse.cpp
r124 r134 26 26 #include "image.hpp" 27 27 #include "filter.hpp" 28 #include "mdlread.hpp"29 28 #include "mouse.hpp" 30 29 -
abuse/trunk/src/sdlport/video.cpp
r129 r134 21 21 22 22 #include <SDL.h> 23 #ifdef HAVE_OPENGL 24 #ifdef __APPLE__ 25 #include <OpenGL/gl.h> 26 #include <OpenGL/glu.h> 27 #else 28 #include <GL/gl.h> 29 #include <GL/glu.h> 30 #endif /* __APPLE__ */ 23 24 #ifdef HAVE_OPENGL 25 # ifdef __APPLE__ 26 # include <OpenGL/gl.h> 27 # include <OpenGL/glu.h> 28 # else 29 # include <GL/gl.h> 30 # include <GL/glu.h> 31 # endif /* __APPLE__ */ 31 32 #endif /* HAVE_OPENGL */ 33 32 34 #include "filter.hpp" 33 35 #include "system.h" … … 61 63 { 62 64 int value; 63 for( 65 for(value = 1 ; value < input ; value <<= 1); 64 66 return value; 65 67 } … … 69 71 // Set the video mode 70 72 // 71 void set_mode( int mode, int argc, char **argv)73 void set_mode(int mode, int argc, char **argv) 72 74 { 73 75 const SDL_VideoInfo *vidInfo; … … 76 78 // Check for video capabilities 77 79 vidInfo = SDL_GetVideoInfo(); 78 if( vidInfo->hw_available ) 79 { 80 if(vidInfo->hw_available) 80 81 vidFlags |= SDL_HWSURFACE; 81 } 82 else 83 { 82 else 84 83 vidFlags |= SDL_SWSURFACE; 85 } 86 if( flags.fullscreen ) 87 { 84 85 if(flags.fullscreen) 88 86 vidFlags |= SDL_FULLSCREEN; 89 } 90 if( flags.doublebuf ) 91 { 87 88 if(flags.doublebuf) 92 89 vidFlags |= SDL_DOUBLEBUF; 93 }94 90 95 91 // Calculate the window scale … … 98 94 99 95 // Try using opengl hw accell 100 if( flags.gl) {101 #ifdef HAVE_OPENGL 102 printf( "Video : OpenGL enabled\n");96 if(flags.gl) { 97 #ifdef HAVE_OPENGL 98 printf("Video : OpenGL enabled\n"); 103 99 // allow doublebuffering in with gl too 104 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, flags.doublebuf);100 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, flags.doublebuf); 105 101 // set video gl capability 106 102 vidFlags |= SDL_OPENGL; … … 109 105 #else 110 106 // ignore the option if not available 111 printf( 107 printf("Video : OpenGL disabled (Support missing in executable)\n"); 112 108 flags.gl = 0; 113 109 #endif … … 115 111 116 112 // Set the icon for this window. Looks nice on taskbars etc. 117 SDL_WM_SetIcon( SDL_LoadBMP("abuse.bmp"), NULL);113 SDL_WM_SetIcon(SDL_LoadBMP("abuse.bmp"), NULL); 118 114 119 115 // Create the window with a preference for 8-bit (palette animations!), but accept any depth */ 120 window = SDL_SetVideoMode(flags.xres, flags.yres, 8, vidFlags | SDL_ANYFORMAT 121 if( window == NULL)122 { 123 printf( "Video : Unable to set video mode : %s\n", SDL_GetError());124 exit( 1);116 window = SDL_SetVideoMode(flags.xres, flags.yres, 8, vidFlags | SDL_ANYFORMAT); 117 if(window == NULL) 118 { 119 printf("Video : Unable to set video mode : %s\n", SDL_GetError()); 120 exit(1); 125 121 } 126 122 127 123 // Create the screen image 128 screen = new image( xres, yres, NULL, 2);129 if( screen == NULL)124 screen = new image(xres, yres, NULL, 2); 125 if(screen == NULL) 130 126 { 131 127 // Our screen image is no good, we have to bail. 132 printf( "Video : Unable to create screen image.\n");133 exit( 1);128 printf("Video : Unable to create screen image.\n"); 129 exit(1); 134 130 } 135 131 screen->clear(); … … 138 134 { 139 135 #ifdef HAVE_OPENGL 140 int w, h;136 int w, h; 141 137 142 138 // texture width/height should be power of 2 139 // FIXME: we can use GL_ARB_texture_non_power_of_two or 140 // GL_ARB_texture_rectangle to avoid the extra memory allocation 143 141 w = power_of_two(xres); 144 142 h = power_of_two(yres); 145 143 146 144 // create texture surface 147 texture = SDL_CreateRGBSurface( SDL_SWSURFACE, w ,h ,32,145 texture = SDL_CreateRGBSurface(SDL_SWSURFACE, w , h , 32, 148 146 #if SDL_BYTEORDER == SDL_LIL_ENDIAN 149 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 147 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); 150 148 #else 151 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF 149 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); 152 150 #endif 153 151 … … 164 162 glLoadIdentity(); 165 163 166 glOrtho(0.0, (GLdouble)window->w, (GLdouble)window->h, 0.0, 0.0, 1.0);164 glOrtho(0.0, (GLdouble)window->w, (GLdouble)window->h, 0.0, 0.0, 1.0); 167 165 168 166 glMatrixMode(GL_MODELVIEW); … … 181 179 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, flags.antialias); 182 180 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, flags.antialias); 183 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels 181 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels); 184 182 #endif 185 183 } 186 184 187 185 // Create our 8-bit surface 188 surface = SDL_CreateRGBSurface( SDL_SWSURFACE, window->w, window->h, 8, 0xff, 0xff, 0xff, 0xff);189 if( surface == NULL)186 surface = SDL_CreateRGBSurface(SDL_SWSURFACE, window->w, window->h, 8, 0xff, 0xff, 0xff, 0xff); 187 if(surface == NULL) 190 188 { 191 189 // Our surface is no good, we have to bail. 192 printf( "Video : Unable to create 8-bit surface.\n");193 exit( 1);194 } 195 196 printf( "Video : %dx%d %dbpp\n", window->w, window->h, window->format->BitsPerPixel);190 printf("Video : Unable to create 8-bit surface.\n"); 191 exit(1); 192 } 193 194 printf("Video : %dx%d %dbpp\n", window->w, window->h, window->format->BitsPerPixel); 197 195 198 196 // Set the window caption 199 SDL_WM_SetCaption( "Abuse-SDL", "Abuse-SDL");197 SDL_WM_SetCaption("Abuse", "Abuse"); 200 198 201 199 // Grab and hide the mouse cursor 202 SDL_ShowCursor( 0 ); 203 if( flags.grabmouse ) 204 { 205 SDL_WM_GrabInput( SDL_GRAB_ON ); 206 } 207 208 update_dirty( screen ); 200 SDL_ShowCursor(0); 201 if(flags.grabmouse) 202 SDL_WM_GrabInput(SDL_GRAB_ON); 203 204 update_dirty(screen); 209 205 } 210 206 … … 215 211 void close_graphics() 216 212 { 217 if( lastl ) 218 { 213 if(lastl) 219 214 delete lastl; 220 }221 215 lastl = NULL; 222 216 // Free our 8-bit surface 223 if( surface ) 224 { 225 SDL_FreeSurface( surface ); 226 } 227 #ifdef HAVE_OPENGL 228 if ( texture ) 229 { 230 SDL_FreeSurface( texture ); 231 } 217 if(surface) 218 SDL_FreeSurface(surface); 219 220 #ifdef HAVE_OPENGL 221 if (texture) 222 SDL_FreeSurface(texture); 232 223 #endif 233 224 delete screen; … … 237 228 // Draw only dirty parts of the image 238 229 // 239 void put_part_image( image *im, int x, int y, int x1, int y1, int x2, int y2)230 void put_part_image(image *im, int x, int y, int x1, int y1, int x2, int y2) 240 231 { 241 232 int xe, ye; … … 246 237 Uint16 dinset; 247 238 248 if( (unsigned)y > yres || (unsigned)x > xres ) 249 { 239 if((unsigned)y > yres || (unsigned)x > xres) 250 240 return; 251 } 252 CHECK( x1 >= 0 && x2 >= x1 && y1 >= 0 && y2 >= y1);241 242 CHECK(x1 >= 0 && x2 >= x1 && y1 >= 0 && y2 >= y1); 253 243 254 244 // Adjust if we are trying to draw off the screen 255 if( x < 0)245 if(x < 0) 256 246 { 257 247 x1 += -x; … … 259 249 } 260 250 srcrect.x = x1; 261 if( (unsigned)(x + ( x2 - x1 )) >= xres ) 262 { 251 if((unsigned)(x + (x2 - x1)) >= xres) 263 252 xe = xres - x + x1 - 1; 264 } 265 else 266 { 253 else 267 254 xe = x2; 268 } 269 if( y < 0)255 256 if(y < 0) 270 257 { 271 258 y1 += -y; … … 273 260 } 274 261 srcrect.y = y1; 275 if( (unsigned)(y + ( y2 - y1 )) >= yres ) 276 { 262 if((unsigned)(y + (y2 - y1)) >= yres) 277 263 ye = yres - y + y1 - 1; 278 } 279 else 280 { 264 else 281 265 ye = y2; 282 } 283 if( srcrect.x >= xe || srcrect.y >= ye)266 267 if(srcrect.x >= xe || srcrect.y >= ye) 284 268 return; 285 269 … … 299 283 300 284 // Lock the surface if necessary 301 if( SDL_MUSTLOCK( surface ) ) 302 { 303 SDL_LockSurface( surface ); 304 } 285 if(SDL_MUSTLOCK(surface)) 286 SDL_LockSurface(surface); 287 305 288 dpixel = (Uint8 *)surface->pixels; 306 289 dpixel += (dstrect.x + ((dstrect.y) * surface->w)) * surface->format->BytesPerPixel; … … 311 294 srcy = srcrect.y; 312 295 dpixel = ((Uint8 *)surface->pixels) + y * surface->w + x ; 313 for( ii=0 ; ii < srcrect.h; ii++)296 for(ii=0 ; ii < srcrect.h; ii++) 314 297 { 315 memcpy( dpixel, im->scan_line( srcy ) + srcrect.x , srcrect.w);298 memcpy(dpixel, im->scan_line(srcy) + srcrect.x , srcrect.w); 316 299 dpixel += surface->w; 317 300 srcy ++; … … 328 311 dpixel = (Uint8 *)surface->pixels + (dstrect.x + ((dstrect.y) * surface->w)) * surface->format->BytesPerPixel; 329 312 330 for( ii = 0; ii < dstrect.h; ii++)313 for(ii = 0; ii < dstrect.h; ii++) 331 314 { 332 315 srcx = (srcrect.x << 16); 333 for( jj = 0; jj < dstrect.w; jj++)316 for(jj = 0; jj < dstrect.w; jj++) 334 317 { 335 memcpy( dpixel, im->scan_line( (srcy >> 16) ) + ((srcx >> 16) * surface->format->BytesPerPixel), surface->format->BytesPerPixel);318 memcpy(dpixel, im->scan_line((srcy >> 16)) + ((srcx >> 16) * surface->format->BytesPerPixel), surface->format->BytesPerPixel); 336 319 dpixel += surface->format->BytesPerPixel; 337 320 srcx += xstep; … … 345 328 346 329 // Unlock the surface if we locked it. 347 if( SDL_MUSTLOCK( surface ) ) 348 { 349 SDL_UnlockSurface( surface ); 350 } 330 if(SDL_MUSTLOCK(surface)) 331 SDL_UnlockSurface(surface); 351 332 352 333 // Now blit the surface 353 update_window_part( 334 update_window_part(&dstrect); 354 335 } 355 336 … … 358 339 // Draw the entire image 359 340 // 360 void put_image( image * im, int x, int y)361 { 362 put_part_image( im, x, y, 0, 0, im->width() - 1, im->height() - 1);341 void put_image(image * im, int x, int y) 342 { 343 put_part_image(im, x, y, 0, 0, im->width() - 1, im->height() - 1); 363 344 } 364 345 … … 367 348 // Update the dirty parts of the window 368 349 // 369 void update_dirty_window( image *im, int xoff, int yoff)350 void update_dirty_window(image *im, int xoff, int yoff) 370 351 { 371 352 int count; 372 353 dirty_rect *dr, *q; 373 CHECK( im->special); // make sure the image has the ability to contain dirty areas374 if( im->special->keep_dirt == 0)375 { 376 put_image( im, xoff, yoff);354 CHECK(im->special); // make sure the image has the ability to contain dirty areas 355 if(im->special->keep_dirt == 0) 356 { 357 put_image(im, xoff, yoff); 377 358 } 378 359 else 379 360 { 380 361 count = im->special->dirties.number_nodes(); 381 if( !count)362 if(!count) 382 363 return; // if nothing to update, return 383 dr = (dirty_rect *)( im->special->dirties.first());384 while( count > 0)364 dr = (dirty_rect *)(im->special->dirties.first()); 365 while(count > 0) 385 366 { 386 put_part_image( im, xoff + dr->dx1, yoff + dr->dy1, dr->dx1, dr->dy1, dr->dx2 + 1, dr->dy2 + 1);367 put_part_image(im, xoff + dr->dx1, yoff + dr->dy1, dr->dx1, dr->dy1, dr->dx2 + 1, dr->dy2 + 1); 387 368 q = dr; 388 dr = (dirty_rect *)( dr->next());389 im->special->dirties.unlink( ( linked_node *)q);369 dr = (dirty_rect *)(dr->next()); 370 im->special->dirties.unlink((linked_node *)q); 390 371 delete q; 391 372 count--; … … 398 379 // Update the dirty parts of the image 399 380 // 400 void update_dirty( image *im, int xoff, int yoff)401 { 402 update_dirty_window( im, xoff, yoff);381 void update_dirty(image *im, int xoff, int yoff) 382 { 383 update_dirty_window(im, xoff, yoff); 403 384 update_window_done(); 404 385 } … … 407 388 // make_page() 408 389 // 409 void image::make_page( short width, short height, unsigned char *page_buffer)410 { 411 if( page_buffer)390 void image::make_page(short width, short height, unsigned char *page_buffer) 391 { 392 if(page_buffer) 412 393 data = page_buffer; 413 394 else 414 data = (unsigned char *)malloc( width * height);395 data = (unsigned char *)malloc(width * height); 415 396 } 416 397 … … 420 401 void image::delete_page() 421 402 { 422 if( !special || !special->static_mem)423 free( data);403 if(!special || !special->static_mem) 404 free(data); 424 405 } 425 406 … … 430 411 void palette::load() 431 412 { 432 if( lastl ) 433 { 413 if(lastl) 434 414 delete lastl; 435 }436 415 lastl = copy(); 437 416 438 417 // Force to only 256 colours. 439 418 // Shouldn't be needed, but best to be safe. 440 if( ncolors > 256 ) 441 { 419 if(ncolors > 256) 442 420 ncolors = 256; 443 }444 421 445 422 SDL_Color colors[ncolors]; 446 for( int ii = 0; ii < ncolors; ii++)423 for(int ii = 0; ii < ncolors; ii++) 447 424 { 448 425 colors[ii].r = red(ii); … … 450 427 colors[ii].b = blue(ii); 451 428 } 452 SDL_SetColors( surface, colors, 0, ncolors ); 453 if( window->format->BitsPerPixel == 8 ) 454 { 455 SDL_SetColors( window, colors, 0, ncolors ); 456 } 429 SDL_SetColors(surface, colors, 0, ncolors); 430 if(window->format->BitsPerPixel == 8) 431 SDL_SetColors(window, colors, 0, ncolors); 457 432 458 433 // Now redraw the surface 459 update_window_part( NULL);434 update_window_part(NULL); 460 435 update_window_done(); 461 436 } … … 473 448 void update_window_done() 474 449 { 450 #ifdef HAVE_OPENGL 475 451 // opengl blit complete surface to window 476 if (flags.gl) 477 { 478 #ifdef HAVE_OPENGL 452 if(flags.gl) 453 { 479 454 // convert color-indexed surface to RGB texture 480 SDL_BlitSurface( surface, NULL, texture, NULL);455 SDL_BlitSurface(surface, NULL, texture, NULL); 481 456 482 457 // Texturemap complete texture to surface so we have free scaling 483 458 // and antialiasing 484 glTexSubImage2D( GL_TEXTURE_2D,0,485 0,0,texture->w,texture->h,486 GL_RGBA,GL_UNSIGNED_BYTE,texture->pixels);459 glTexSubImage2D(GL_TEXTURE_2D, 0, 460 0, 0, texture->w, texture->h, 461 GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels); 487 462 glBegin(GL_TRIANGLE_STRIP); 488 463 glTexCoord2f(texcoord[0], texcoord[1]); glVertex3i(0, 0, 0); … … 491 466 glTexCoord2f(texcoord[2], texcoord[3]); glVertex3i(window->w, window->h, 0); 492 467 glEnd(); 493 #endif 494 } 495 468 469 if(flags.doublebuf) 470 SDL_GL_SwapBuffers(); 471 } 472 #else 496 473 // swap buffers in case of double buffering 497 if (flags.doublebuf)498 {499 if (flags.gl)500 {501 #ifdef HAVE_OPENGL502 SDL_GL_SwapBuffers();503 #endif504 }505 else506 {507 SDL_Flip(window);508 }509 }510 511 474 // do nothing in case of single buffering 512 } 513 514 void update_window_part( SDL_Rect *rect) 475 if(flags.doublebuf) 476 SDL_Flip(window); 477 #endif 478 } 479 480 void update_window_part(SDL_Rect *rect) 515 481 { 516 482 // no partial blit's in case of opengl 517 483 // complete blit + scaling just before flip 518 484 if (flags.gl) 519 {520 485 return; 521 } 522 523 SDL_BlitSurface( surface, rect, window, rect ); 486 487 SDL_BlitSurface(surface, rect, window, rect); 524 488 525 489 // no window update needed until end of run 526 if( flags.doublebuf) 527 { 490 if(flags.doublebuf) 528 491 return; 529 }530 492 531 493 // update window part for single buffer 532 if( rect == NULL ) 533 { 534 SDL_UpdateRect( window, 0, 0, 0, 0 ); 535 } 536 else 537 { 538 SDL_UpdateRect( window, rect->x, rect->y, rect->w, rect->h ); 539 } 540 } 494 if(rect == NULL) 495 SDL_UpdateRect(window, 0, 0, 0, 0); 496 else 497 SDL_UpdateRect(window, rect->x, rect->y, rect->w, rect->h); 498 }
Note: See TracChangeset
for help on using the changeset viewer.