X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/micropolis/blobdiff_plain/3fec6683f3fb3d8354310bb1010511d200752e6c..e049e4ba47308629d2233fdd3f85d49352463d9c:/src/sim/w_x.c?ds=inline diff --git a/src/sim/w_x.c b/src/sim/w_x.c index 3d8dd48..336a425 100644 --- a/src/sim/w_x.c +++ b/src/sim/w_x.c @@ -91,7 +91,11 @@ unsigned char ColorIntensities[] = { /* COLOR_BLACK */ 0, }; +void FreeTiles(SimView *view); +void AllocTiles(SimView *view); +void DoAdjustPan(struct SimView *view); +void ViewToTileCoords(SimView *view, int x, int y, int *outx, int *outy) { x = (view->pan_x - ((view->w_width >>1) - x)) >>4; @@ -120,6 +124,7 @@ ViewToTileCoords(SimView *view, int x, int y, int *outx, int *outy) } +void ViewToPixelCoords(SimView *view, int x, int y, int *outx, int *outy) { x = view->pan_x - ((view->w_width >>1) - x); @@ -148,7 +153,8 @@ ViewToPixelCoords(SimView *view, int x, int y, int *outx, int *outy) } -UpdateFlush() +void +UpdateFlush(void) { struct XDisplay *xd; @@ -216,7 +222,8 @@ printf("GOT X ERROR code %d request code %d %d\n", } -DoStopMicropolis() +void +DoStopMicropolis(void) { (void)XSetErrorHandler(CatchXError); @@ -244,7 +251,8 @@ DoStopMicropolis() } -DoTimeoutListen() +void +DoTimeoutListen(void) { while (Tk_DoOneEvent(TK_DONT_WAIT)) ; } @@ -273,10 +281,7 @@ XDisplay * FindXDisplay(Tk_Window tkwin) { XDisplay *xd; - int d = 8; - unsigned long valuemask = 0; - XGCValues values; - XColor rgb, *color; + XColor *color; Display *dpy = Tk_Display(tkwin); Screen *screen = Tk_Screen(tkwin); #ifdef IS_LINUX @@ -333,6 +338,7 @@ FindXDisplay(Tk_Window tkwin) (((color->green >> (8 + 2)) & 0x1f) << (5)) | \ (((color->blue >> (8 + 3)) & 0x1f) << (0)); \ } else { \ + xd->pixels[i] = \ (((color->blue >> (8 + 3)) & 0x1f) << (5 + 5)) | \ (((color->green >> (8 + 2)) & 0x1f) << (5)) | \ (((color->red >> (8 + 3)) & 0x1f) << (0)); \ @@ -456,9 +462,7 @@ FindXDisplay(Tk_Window tkwin) } else { fprintf(stderr, "Cool, I found the shared memory extension!\n"); - fprintf(stderr, - "Disabled SHM, because it is currently broken!\n"); - xd->shared = 0; + xd->shared = 1; } } } @@ -487,12 +491,14 @@ FindXDisplay(Tk_Window tkwin) } +void IncRefDisplay(XDisplay *xd) { xd->references++; } +void DecRefDisplay(XDisplay *xd) { if ((--xd->references) == 0) { @@ -504,14 +510,8 @@ DecRefDisplay(XDisplay *xd) SimView * InitNewView(SimView *view, char *title, int class, int w, int h) { - int type, i; int test = 1; - int d = 8; - unsigned long valuemask = 0; char *t; - struct XDisplay *xd; - XGCValues values; - XColor rgb, *color; t = (char *)ckalloc(strlen(title) + 1); strcpy(t, title); @@ -581,7 +581,7 @@ InitNewView(SimView *view, char *title, int class, int w, int h) view->update_context = 0; view->auto_goto = 0; view->auto_going = 0; - view->auto_x_goal = view->auto_x_goal = 0; + view->auto_x_goal = view->auto_y_goal = 0; view->auto_speed = 75; view->follow = NULL; view->sound = 1; @@ -601,6 +601,7 @@ InitNewView(SimView *view, char *title, int class, int w, int h) } view->x->needs_swap = !(*(unsigned char*) (&test)); + view->x->x_big_endian = (ImageByteOrder(view->x->dpy) == MSBFirst); GetPixmaps(view->x); @@ -612,12 +613,11 @@ InitNewView(SimView *view, char *title, int class, int w, int h) view->pan_x = w / 2; view->pan_y = h / 2; DoResizeView(view, w, h); - GetViewTiles(view); - return (view); } +void DestroyView(SimView *view) { SimView **vp; @@ -726,6 +726,7 @@ AllocPixels(int len, unsigned char pixel) } +void DoResizeView(SimView *view, int w, int h) { int resize = 0; @@ -905,7 +906,7 @@ DoResizeView(SimView *view, int w, int h) } view->data = (unsigned char *)shmat(view->shminfo->shmid, 0, 0); - if ((int)view->data == -1) { + if ((char*)view->data == (char*)-1) { perror("shmat"); fprintf(stderr, "Darn, Micropolis can't find any memory to share with display \"%s\".\n", @@ -937,7 +938,7 @@ DoResizeView(SimView *view, int w, int h) if (!GotXError) { attached = 1; view->pixmap = XShmCreatePixmap(view->x->dpy, view->x->root, - view->data, view->shminfo, + (char*)view->data, view->shminfo, view->m_width, view->m_height, view->x->depth); XSync(view->x->dpy, False); @@ -1245,15 +1246,20 @@ DoResizeView(SimView *view, int w, int h) } } } + + GetViewTiles(view); + } +void DoPanBy(struct SimView *view, int dx, int dy) { DoPanTo(view, view->pan_x + dx, view->pan_y + dy); } +void DoPanTo(struct SimView *view, int x, int y) { if (view->class != Editor_Class) { @@ -1274,12 +1280,12 @@ DoPanTo(struct SimView *view, int x, int y) /* #define DEBUG_PAN */ +void DoAdjustPan(struct SimView *view) { int ww2 = view->w_width >>1, wh2 = view->w_height >>1; int px = view->pan_x, py = view->pan_y; int last_tile_x = view->tile_x, last_tile_y = view->tile_y; - int last_tile_width = view->tile_width, last_tile_height = view->tile_height; int total_width = view->m_width >>4, total_height = view->m_height >>4; //fprintf(stderr, "DoAdjustPan\n"); @@ -1392,6 +1398,7 @@ DoAdjustPan(struct SimView *view) } +void AllocTiles(SimView *view) { int row, col; @@ -1423,6 +1430,7 @@ AllocTiles(SimView *view) } +void FreeTiles(SimView *view) { int col; @@ -1467,6 +1475,7 @@ NewInk() } +void FreeInk(Ink *ink) { ink->next = OldInk; @@ -1474,6 +1483,7 @@ FreeInk(Ink *ink) } +void StartInk(Ink *ink, int x, int y) { ink->length = 1; @@ -1482,6 +1492,7 @@ StartInk(Ink *ink, int x, int y) } +void AddInk(Ink *ink, int x, int y) { int dx = x - ink->last_x; @@ -1515,7 +1526,7 @@ AddInk(Ink *ink, int x, int y) ink->points[ink->length].y = dy; ink->length++; - ADJUST: + /* ADJUST: */ if (x < ink->left) ink->left = x; if (x > ink->right) @@ -1553,7 +1564,8 @@ AddInk(Ink *ink, int x, int y) } -EraseOverlay() +void +EraseOverlay(void) { Ink *ink;