2 "$Id: map.c 11117 2009-01-05 07:11:04Z mwedel $";
41 #include <glade/glade.h>
46 #include <gdk/gdkwin32.h>
48 #include <gdk/gdkkeysyms.h>
88 int gettimeofday(
struct timeval* tp,
void* tzp) {
91 tp->tv_sec = t / 1000;
92 tp->tv_usec = t % 1000;
107 xml_tree = glade_get_widget_tree(GTK_WIDGET(window_root));
110 map_notebook = glade_xml_get_widget(xml_tree,
"map_notebook");
114 g_signal_connect ((gpointer) map_drawing_area,
"button_press_event",
116 g_signal_connect ((gpointer) map_drawing_area,
"configure_event",
120 gtk_widget_set_size_request (map_drawing_area,
124 mapgc = gdk_gc_new(map_drawing_area->window);
125 gtk_widget_show(map_drawing_area);
126 gtk_widget_add_events (map_drawing_area, GDK_BUTTON_PRESS_MASK);
135 dark = gdk_pixmap_new(map_drawing_area->window, map_image_size, map_image_size, -1);
136 gdk_draw_rectangle(
dark, map_drawing_area->style->black_gc,
TRUE, 0, 0, map_image_size, map_image_size);
137 dark1 = gdk_pixmap_new(map_drawing_area->window, map_image_size, map_image_size, 1);
138 dark2 = gdk_pixmap_new(map_drawing_area->window, map_image_size, map_image_size, 1);
139 dark3 = gdk_pixmap_new(map_drawing_area->window, map_image_size, map_image_size, 1);
144 darkgc = gdk_gc_new(
dark1);
147 gdk_draw_rectangle(
dark1, darkgc,
TRUE, 0, 0, map_image_size, map_image_size);
148 gdk_draw_rectangle(
dark2, darkgc,
TRUE, 0, 0, map_image_size, map_image_size);
149 gdk_draw_rectangle(
dark3, darkgc,
TRUE, 0, 0, map_image_size, map_image_size);
163 gdk_draw_point(
dark1, darkgc, x, y);
166 gdk_draw_point(
dark2, darkgc, x, y);
169 gdk_draw_point(
dark3, darkgc, x, y);
182 gdk_gc_unref(darkgc);
218 static void draw_pixmap(
int srcx,
int srcy,
int dstx,
int dsty,
int clipx,
int clipy,
219 void *
mask,
void *image,
int sizex,
int sizey)
221 gdk_gc_set_clip_mask(
mapgc, mask);
222 gdk_gc_set_clip_origin(
mapgc, clipx, clipy);
252 static int dx[8]={0,1,1,1,0,-1,-1,-1};
253 static int dy[8]={-1,-1,0,1,1,1,0,-1};
254 static int bweights[8]={2,0,4,0,8,0,1,0};
255 static int cweights[8]={0,2,0,4,0,8,0,1};
256 static int bc_exclude[8]={
266 int partdone[8]={0,0,0,0,0,0,0,0};
269 int i,lowest,weight,weightC;
273 for (i=0;i<=layer;i++)
303 if ( (slevels[i]>0) && (!partdone[i]) &&
304 ((lowest<0) || (slevels[i]<slevels[lowest]))
323 if ( (slevels[i]==slevels[lowest]) &&
324 (sfaces[i]==sfaces[lowest])){
326 weight=weight+bweights[i];
327 weightC&=~bc_exclude[i];
330 weightC&=~cweights[i];
334 if (sfaces[lowest]<=0)
336 smoothface=sfaces[lowest];
345 if ( (!
pixmaps[smoothface]->map_image) ||
352 picx-weight*map_image_size, picy,
353 pixmaps[smoothface]->map_mask,
pixmaps[smoothface]->map_image, map_image_size, map_image_size);
359 picx-weightC*map_image_size, picy-map_image_size,
360 pixmaps[smoothface]->map_mask,
pixmaps[smoothface]->map_image, map_image_size, map_image_size);
383 for (layer=0; layer<
MAXLAYERS; layer++) {
388 if (face > 0 &&
pixmaps[face]->map_image != NULL) {
391 int off_x=0, off_y=0;
410 ax*map_image_size + off_x, ay*map_image_size + off_y,
411 ax*map_image_size+map_image_size-
pixmaps[face]->map_width,
412 ay*map_image_size+map_image_size-
pixmaps[face]->map_height,
414 pixmaps[face]->map_width>map_image_size?map_image_size:
pixmaps[face]->map_width,
415 pixmaps[face]->map_height>map_image_size?map_image_size:
pixmaps[face]->map_height);
426 drawsmooth (mx, my, layer, ax*map_image_size, ay*map_image_size);
431 if (face > 0 &&
pixmaps[face]->map_image != NULL) {
454 int dx, dy, sourcex, sourcey, offx, offy, clipx, clipy;
457 offx = dx?(map_image_size -dx):0;
458 clipx = (ax - sx)*map_image_size + offx;
461 sourcex = sx * map_image_size - offx ;
468 offy = dy?(map_image_size -dy):0;
469 clipy = (ay - sy)*map_image_size + offy;
472 sourcey = sy * map_image_size - offy;
480 ax*map_image_size+offx, ay*map_image_size + offy,
483 map_image_size - offx, map_image_size - offy);
492 draw_pixmap(0, 0, ax*map_image_size, ay*map_image_size, ax*map_image_size, ay*map_image_size,
dark1,
dark, map_image_size, map_image_size);
496 TRUE,map_image_size*ax, map_image_size*ay,
497 map_image_size, map_image_size);
499 draw_pixmap(0, 0, ax*map_image_size, ay*map_image_size, ax*map_image_size, ay*map_image_size,
dark1,
dark, map_image_size, map_image_size);
501 draw_pixmap(0, 0, ax*map_image_size, ay*map_image_size, ax*map_image_size, ay*map_image_size,
dark2,
dark, map_image_size, map_image_size);
503 draw_pixmap(0, 0, ax*map_image_size, ay*map_image_size, ax*map_image_size, ay*map_image_size,
dark3,
dark, map_image_size, map_image_size);
514 struct timeval tv1, tv2,tv3;
515 long elapsed1, elapsed2;
521 gettimeofday(&tv1, NULL);
544 gettimeofday(&tv2, NULL);
547 gettimeofday(&tv3, NULL);
548 elapsed1 = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
549 elapsed2 = (tv3.tv_sec - tv2.tv_sec)*1000000 + (tv3.tv_usec - tv2.tv_usec);
554 if ((elapsed1 + elapsed2)>10000)
555 LOG(
LOG_INFO,
"gtk::sdl_gen_map",
"gen took %7ld, flip took %7ld, total = %7ld",
556 elapsed1, elapsed2, elapsed1 + elapsed2);
587 GdkEventConfigure *
event,
622 static GdkPixmap *splash;
623 static int have_init=0;
624 GdkBitmap *aboutgdkmask;
627 #include "../../pixmaps/crossfiretitle.xpm"
633 (gchar **)crossfiretitle_xpm);
637 gdk_drawable_get_size(splash, &w, &h);
644 gdk_gc_set_clip_mask(
mapgc, NULL);
679 GdkEventExpose *
event,
695 GdkEventButton *
event,
698 int dx, dy, i, x, y, xmidl, xmidh, ymidl, ymidh;
709 switch (event->button) {
727 if (event->button==2) {
#define CAN_SMOOTH(__SQUARE, __LEVEL)
GtkWidget * map_drawing_area
void resize_map_window(int x, int y)
void display_map_doneupdate(int redraw, int notice)
void init_SDL(GtkWidget *sdl_window, int just_lightmap)
void move_player(int dir)
void map_init(GtkWidget *window_root)
#define DEFAULT_IMAGE_SIZE
void display_map_startupdate(void)
PixmapInfo * pixmaps[MAXPIXMAPNUM]
void LOG(LogLevel level, const char *origin, const char *format,...)
gboolean on_drawingarea_map_button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
gboolean on_drawingarea_map_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
void look_at(int x, int y)
int sdl_mapscroll(int dx, int dy)
int cs_print_string(int fd, const char *str,...)
static void draw_pixmap(int srcx, int srcy, int dstx, int dsty, int clipx, int clipy, void *mask, void *image, int sizex, int sizey)
sint16 use_config[CONFIG_NUMS]
sint16 mapdata_face(int x, int y, int layer)
const char *const rcsid_gtk2_map_c
gboolean on_drawingarea_map_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data)
void draw_map(int redraw)
void drawsmooth(int mx, int my, int layer, int picx, int picy)
void init_opengl(GtkWidget *drawingarea)
void display_map_newmap(void)
sint16 mapdata_bigface(int x, int y, int layer, int *ww, int *hh)
void opengl_gen_map(int redraw)
int display_mapscroll(int dx, int dy)
#define CONFIG_DISPLAYMODE
void gtk_draw_map(int redraw)
struct MapCellLayer heads[MAXLAYERS]
void mapdata_set_size(int viewx, int viewy)
static void display_mapcell(int ax, int ay, int mx, int my)
void sdl_gen_map(int redraw)