Annotation of micropolis/src/sim/g_bigmap.c, revision 1.1

1.1     ! root        1: /* g_bigmap.c
        !             2:  *
        !             3:  * Micropolis, Unix Version.  This game was released for the Unix platform
        !             4:  * in or about 1990 and has been modified for inclusion in the One Laptop
        !             5:  * Per Child program.  Copyright (C) 1989 - 2007 Electronic Arts Inc.  If
        !             6:  * you need assistance with this program, you may contact:
        !             7:  *   http://wiki.laptop.org/go/Micropolis  or email  [email protected].
        !             8:  * 
        !             9:  * This program is free software: you can redistribute it and/or modify
        !            10:  * it under the terms of the GNU General Public License as published by
        !            11:  * the Free Software Foundation, either version 3 of the License, or (at
        !            12:  * your option) any later version.
        !            13:  * 
        !            14:  * This program is distributed in the hope that it will be useful, but
        !            15:  * WITHOUT ANY WARRANTY; without even the implied warranty of
        !            16:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
        !            17:  * General Public License for more details.  You should have received a
        !            18:  * copy of the GNU General Public License along with this program.  If
        !            19:  * not, see <http://www.gnu.org/licenses/>.
        !            20:  * 
        !            21:  *             ADDITIONAL TERMS per GNU GPL Section 7
        !            22:  * 
        !            23:  * No trademark or publicity rights are granted.  This license does NOT
        !            24:  * give you any right, title or interest in the trademark SimCity or any
        !            25:  * other Electronic Arts trademark.  You may not distribute any
        !            26:  * modification of this program using the trademark SimCity or claim any
        !            27:  * affliation or association with Electronic Arts Inc. or its employees.
        !            28:  * 
        !            29:  * Any propagation or conveyance of this program must include this
        !            30:  * copyright notice and these terms.
        !            31:  * 
        !            32:  * If you convey this program (or any modifications of it) and assume
        !            33:  * contractual liability for the program to recipients of it, you agree
        !            34:  * to indemnify Electronic Arts for any liability that those contractual
        !            35:  * assumptions impose on Electronic Arts.
        !            36:  * 
        !            37:  * You may not misrepresent the origins of this program; modified
        !            38:  * versions of the program must be marked as such and not identified as
        !            39:  * the original program.
        !            40:  * 
        !            41:  * This disclaimer supplements the one included in the General Public
        !            42:  * License.  TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, THIS
        !            43:  * PROGRAM IS PROVIDED TO YOU "AS IS," WITH ALL FAULTS, WITHOUT WARRANTY
        !            44:  * OF ANY KIND, AND YOUR USE IS AT YOUR SOLE RISK.  THE ENTIRE RISK OF
        !            45:  * SATISFACTORY QUALITY AND PERFORMANCE RESIDES WITH YOU.  ELECTRONIC ARTS
        !            46:  * DISCLAIMS ANY AND ALL EXPRESS, IMPLIED OR STATUTORY WARRANTIES,
        !            47:  * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY,
        !            48:  * FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT OF THIRD PARTY
        !            49:  * RIGHTS, AND WARRANTIES (IF ANY) ARISING FROM A COURSE OF DEALING,
        !            50:  * USAGE, OR TRADE PRACTICE.  ELECTRONIC ARTS DOES NOT WARRANT AGAINST
        !            51:  * INTERFERENCE WITH YOUR ENJOYMENT OF THE PROGRAM; THAT THE PROGRAM WILL
        !            52:  * MEET YOUR REQUIREMENTS; THAT OPERATION OF THE PROGRAM WILL BE
        !            53:  * UNINTERRUPTED OR ERROR-FREE, OR THAT THE PROGRAM WILL BE COMPATIBLE
        !            54:  * WITH THIRD PARTY SOFTWARE OR THAT ANY ERRORS IN THE PROGRAM WILL BE
        !            55:  * CORRECTED.  NO ORAL OR WRITTEN ADVICE PROVIDED BY ELECTRONIC ARTS OR
        !            56:  * ANY AUTHORIZED REPRESENTATIVE SHALL CREATE A WARRANTY.  SOME
        !            57:  * JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF OR LIMITATIONS ON IMPLIED
        !            58:  * WARRANTIES OR THE LIMITATIONS ON THE APPLICABLE STATUTORY RIGHTS OF A
        !            59:  * CONSUMER, SO SOME OR ALL OF THE ABOVE EXCLUSIONS AND LIMITATIONS MAY
        !            60:  * NOT APPLY TO YOU.
        !            61:  */
        !            62: #include "sim.h"
        !            63: 
        !            64: 
        !            65: int dynamicFilter(int c, int r);
        !            66: int WireDrawBeegMapRect(SimView *view, short x, short y, short w, short h);
        !            67: 
        !            68: drawBeegMaps()
        !            69: {
        !            70:   sim_update_editors();
        !            71: }
        !            72: 
        !            73: 
        !            74: MemDrawBeegMapRect(SimView *view, int x, int y, int w, int h)
        !            75: {
        !            76:   int lineBytes = view->line_bytes;
        !            77:   int pixelBytes = view->pixel_bytes;
        !            78:   QUAD ii, mm;
        !            79:   unsigned short *map;
        !            80:   unsigned short tile;
        !            81:   unsigned char blink = (flagBlink <= 0), *bt = view->bigtiles;
        !            82:   short col, row;
        !            83:   short **have, *ha;
        !            84: 
        !            85:   if (x < view->tile_x) {
        !            86:     if ((w -= (view->tile_x - x)) <= 0)
        !            87:       return;
        !            88:     x = view->tile_x;
        !            89:   }
        !            90:   if (y < view->tile_y) {
        !            91:     if ((h -= (view->tile_y - y)) <= 0)
        !            92:       return;
        !            93:     y = view->tile_y;
        !            94:   }
        !            95:   if ((x + w) > (view->tile_x + view->tile_width)) {
        !            96:     if ((w -= ((x + w) - (view->tile_x + view->tile_width))) <= 0)
        !            97:       return;
        !            98:   }
        !            99:   if ((y + h) > (view->tile_y + view->tile_height)) {
        !           100:     if ((h -= ((y + h) - (view->tile_y + view->tile_height))) <= 0)
        !           101:       return;
        !           102:   }
        !           103: 
        !           104:   if (view->x->color) {
        !           105:     register unsigned QUAD *image, *mem;
        !           106: 
        !           107:     image = (unsigned QUAD *)view->data;
        !           108:     ii = ((lineBytes * h * 16) - 16) / sizeof(unsigned QUAD);
        !           109:     map = (unsigned short *)&Map[x][y];
        !           110:     mm = WORLD_Y - h;
        !           111:     have = view->tiles;
        !           112: 
        !           113:     /*
        !           114:      * Huge Berserk Rebel Warthog
        !           115:      */
        !           116: 
        !           117:     for (col = 0; col < w; col++) {
        !           118:       ha = &have[col][0];
        !           119:       image = (unsigned QUAD *)(view->data + (col * 16 * pixelBytes));
        !           120:       for (row = 0; row < h; row++, ha++) {
        !           121:        tile = *(map++);
        !           122:        if ((tile & LOMASK) >= TILE_COUNT) tile -= TILE_COUNT;
        !           123: 
        !           124:        /* Blink lightning bolt in unpowered zone center */
        !           125:        if (blink && (tile & ZONEBIT) && !(tile & PWRBIT)) {
        !           126:          tile = LIGHTNINGBOLT;
        !           127:        } else {
        !           128:          tile &= LOMASK;
        !           129:        } // if
        !           130: 
        !           131:        if (
        !           132:            (tile > 63) &&
        !           133:            (view->dynamic_filter != 0) &&
        !           134:            (dynamicFilter(col + x, row + y) == 0)
        !           135:            ) {
        !           136:          tile = 0;
        !           137:        } // if
        !           138: 
        !           139:        /* XXX */
        !           140:        if (tile == *ha) {
        !           141:          image = (unsigned QUAD *)(((unsigned char *)image) +
        !           142:                                    (lineBytes * 16));
        !           143:        } else {
        !           144:          *ha = tile;
        !           145:          mem = (unsigned QUAD *)&(bt[tile * 256 * pixelBytes]);
        !           146: 
        !           147:          /* XXX: handle depth for big tiles */
        !           148: #if 1
        !           149:          /* Very un-rolled loop. */
        !           150: 
        !           151: #define ROW1_8(n) \
        !           152:          image[0] = mem[0+n]; \
        !           153:          image[1] = mem[1+n]; \
        !           154:          image[2] = mem[2+n]; \
        !           155:          image[3] = mem[3+n]; \
        !           156:          image = (unsigned QUAD *)(((unsigned char *)image) + lineBytes);
        !           157: 
        !           158: #define ROW2_8(n) ROW1_8(n) ROW1_8(n+4)
        !           159: #define ROW4_8(n) ROW2_8(n) ROW2_8(n+8)
        !           160: #define ROW8_8(n) ROW4_8(n) ROW4_8(n+16)
        !           161: #define ROW16_8() ROW8_8(0) ROW8_8(32)
        !           162: 
        !           163: #define ROW1_16(n) \
        !           164:       memcpy((char *)image, (char *)mem + (2 * 16 * (n)), 2 * 16); \
        !           165:       image = (unsigned QUAD *)(((unsigned char *)image) + lineBytes);
        !           166: 
        !           167: #define ROW2_16(n) ROW1_16(n) ROW1_16(n+1)
        !           168: #define ROW4_16(n) ROW2_16(n) ROW2_16(n+2)
        !           169: #define ROW8_16(n) ROW4_16(n) ROW4_16(n+4)
        !           170: #define ROW16_16() ROW8_16(0) ROW8_16(8)
        !           171: 
        !           172:          switch (view->x->depth) {
        !           173: 
        !           174:          case 8:
        !           175:            ROW16_8();
        !           176:            break;
        !           177: 
        !           178:          case 15:
        !           179:          case 16:
        !           180:            ROW16_16();
        !           181:            break;
        !           182: 
        !           183:          case 24:
        !           184:          case 32:
        !           185:          default:
        !           186:            /* XXX: handle different depths */
        !           187:            break;
        !           188: 
        !           189:          } // switch
        !           190: 
        !           191: #else
        !           192:          /* Not so un-rolled loop. */
        !           193: 
        !           194:          { int i;
        !           195:            for (i = 16; i > 0; i--) {
        !           196:              image[0] = mem[0]; image[1] = mem[1];
        !           197:              image[2] = mem[2]; image[3] = mem[3];
        !           198:              image = (unsigned QUAD *)(((unsigned char *)image) + lineBytes);
        !           199:              mem += 4;
        !           200:            }
        !           201:          } // scope
        !           202: #endif
        !           203: 
        !           204:        } // if
        !           205: 
        !           206:       } // for row
        !           207:       image -= ii;
        !           208:       map += mm;
        !           209:     } // for col
        !           210:   } else {
        !           211:     register unsigned short *image, *mem;
        !           212: 
        !           213:     image = (unsigned short *)view->data;
        !           214:     ii = ((lineBytes * h * 16) - 2) / sizeof(unsigned short);
        !           215:     map = (unsigned short *)&Map[x][y];
        !           216:     mm = WORLD_Y - h;
        !           217:     have = view->tiles;
        !           218: 
        !           219:     for (col = 0; col < w; col++) {
        !           220:       ha = &have[col][0];
        !           221:       image = (unsigned short *)(view->data + (col * 2));
        !           222:       for (row = 0; row < h; row++, ha++) {
        !           223:        tile = *(map++);
        !           224:        if ((tile & LOMASK) >= TILE_COUNT) tile -= TILE_COUNT;
        !           225: 
        !           226:        /* Blink lightning bolt in unpowered zone center */
        !           227:        if (blink && (tile & ZONEBIT) && !(tile & PWRBIT))
        !           228:          tile = LIGHTNINGBOLT;
        !           229:        else
        !           230:          tile &= LOMASK;
        !           231: 
        !           232:        if (tile == *ha) {
        !           233:          image = (unsigned short *)
        !           234:            (((unsigned char *)image) + (lineBytes * 16));
        !           235:        } else {
        !           236:          *ha = tile;
        !           237:          mem = (unsigned short *)&(bt[tile * 32]);
        !           238: 
        !           239:          { char i;
        !           240:            for (i = 16; i > 0; i--) {
        !           241:              *image = *mem;
        !           242:              image = (unsigned short *)(((unsigned char *)image) + lineBytes);
        !           243:              mem++;
        !           244:            }
        !           245:          }
        !           246:        }
        !           247:       }
        !           248:       image -= ii;
        !           249:       map += mm;
        !           250:     }
        !           251:   }
        !           252: }
        !           253: 
        !           254: 
        !           255: WireDrawBeegMapRect(SimView *view, short x, short y, short w, short h)
        !           256: {
        !           257:   unsigned short *map;
        !           258:   unsigned short tile;
        !           259:   unsigned char blink = (flagBlink <= 0);
        !           260:   short col, row;
        !           261:   QUAD mm;
        !           262:   short **have, *ha;
        !           263: 
        !           264:   if (x < view->tile_x) {
        !           265:     if ((w -= (view->tile_x - x)) <= 0)
        !           266:       return;
        !           267:     x = view->tile_x;
        !           268:   }
        !           269:   if (y < view->tile_y) {
        !           270:     if ((h -= (view->tile_y - y)) <= 0)
        !           271:       return;
        !           272:     y = view->tile_y;
        !           273:   }
        !           274:   if ((x + w) > (view->tile_x + view->tile_width)) {
        !           275:     if ((w -= ((x + w) - (view->tile_x + view->tile_width))) <= 0)
        !           276:       return;
        !           277:   }
        !           278:   if ((y + h) > (view->tile_y + view->tile_height)) {
        !           279:     if ((h -= ((y + h) - (view->tile_y + view->tile_height))) <= 0)
        !           280:       return;
        !           281:   }
        !           282: 
        !           283:   map = (unsigned short *)&Map[x][y];
        !           284:   mm = WORLD_Y - h;
        !           285:   have = view->tiles;
        !           286: 
        !           287:   for (col = 0; col < w; col++) {
        !           288:     ha = &have[col][0];
        !           289:     for (row = 0; row < h; row++, ha++) {
        !           290:       tile = *(map++);
        !           291:       if ((tile & LOMASK) >= TILE_COUNT) tile -= TILE_COUNT;
        !           292: 
        !           293:       /* Blink lightning bolt in unpowered zone center */
        !           294:       if (blink && (tile & ZONEBIT) && !(tile & PWRBIT))
        !           295:        tile = LIGHTNINGBOLT;
        !           296:       else
        !           297:        tile &= LOMASK;
        !           298: 
        !           299:       if (tile != *ha) {
        !           300:        *ha = tile;
        !           301:        XCopyArea(view->x->dpy, view->x->big_tile_pixmap, view->pixmap,
        !           302:                  view->x->gc, 0, tile * 16, 16, 16,
        !           303:                  col * 16, row * 16);
        !           304:       }
        !           305:     }
        !           306:     map += mm;
        !           307:   }
        !           308: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.