Path: chuka.playstation.co.uk!news From: "Alex Herbert" Newsgroups: scee.yaroze.beginners Subject: Re: map-tastic tile question Date: Thu, 17 Jun 1999 23:06:53 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 90 Message-ID: <7kbrdi$4fj7@chuka.playstation.co.uk> References: <7kalnc$4fj2@chuka.playstation.co.uk> NNTP-Posting-Host: 195.166.145.136 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Derek da Silva wrote in message news:7kalnc$4fj2@chuka.playstation.co.uk... > Hi > > I'm looking to make some optimizations to a simple tile based game I'm > working on - specifically the method used to draw the visible part of the > map. > > At the moment I just run through my array of tiles and check each one to see > if it should be drawn to the screen... > > cell_struct cell[map.numcells]; > > // scroll map by changing map.scrollx and map.scrolly > > void Draw_Map_Graphics(void) > { > u_long register i; > > for(i=0; i > > map_sprt.x = cell[i].px + map.scrollx; > map_sprt.y = cell[i].py + map.scrolly; > > if(clip_sprite(map_sprt.x, map_sprt.y, 16, 16)) // check if tile on > screen > { > map_sprt.u = ((cell[i].timindex%8) << 5); > map_sprt.v = ((cell[i].timindex/8) << 5); > GsSortFastSprite(&map_sprt, &WorldOT[activebuff], 2); > } > } > } > > I realise this is very inefficient. Any tips on how to do this better, > smarter and quicker would be greatly appreciated. > > Thanks > > Derek > > > Is this a standard tile based map? If so, then you'd probably be better off using a 2 dimensional array, where the array indexes are directly linked to the cell position. // assuming screen res is 320x256 and cell size is 32x32 mx=map.scrollx>>5; // map x index my=map.scrolly>>5; // map y index ox=map.scrollx&31; // screen offset oy=map.scrolly&31; // screen offset for(y=0;y<=8;y++) { map_sprt.y=(y<<5)-oy; // get screen y pos for(x=0;x<=10;x++) { map_sprt.x=(x<<5)-ox; // get screen x pos i=cell[y][x].timindex; // get tim index from cell array map_sprt.u = ((i%8)<<5); map_sprt.v = ((i/8)<<5); GsSortFastSprite(&map_sprt, &WorldOT[activebuff], 2); } } This way you know which cells are going to be drawn (from the scroll position), and don't need to bother with the undrawn cells at all. And you won't need the .px and .py in the cell structure. This will also make collision detection with the background much simpler. But, I get the feeling I'm missing the point. Your method will allow the cells to be positioned individually at any location, and not necessarily aligned to a grid - hence the .px and .py components. If this is necessary and the map is quite large, then all I can suggest is to break the map up into smaller regions and only bother with the regions which fall within the screen area. Like I say, I feel like I've missed the point, so sorry if this is not what you are looking for. Herbs