/[projectaxis]/projectaxis/IsoEngine/IsoRenderer.cpp
ViewVC logotype

Diff of /projectaxis/IsoEngine/IsoRenderer.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by vovansim, Sat Jun 7 03:59:06 2003 UTC revision 1.2 by vovansim, Sat Sep 13 21:40:20 2003 UTC
# Line 1  Line 1 
 /** \file IsoRenderer.h  
  * Defines the IsoRenderer class, which combines several blitting optimizations into one easy-to-use package.  
  *  
  * @author <A href="mailto:vovansim@hotmail.com">Vovansim (aka Scorpion)</A>  
  * @version 1.0  
  * @date June 6, 2003  
  */  
   
1  #include "IsoRenderer.h"  #include "IsoRenderer.h"
2    
3  IsoRenderer::IsoRenderer() {  IsoRenderer::IsoRenderer() {
# Line 43  void IsoRenderer::setScroller(IsoScrolle Line 35  void IsoRenderer::setScroller(IsoScrolle
35          scroller = newScroller;          scroller = newScroller;
36  }  }
37    
 /** @todo delete the old array or rectangles if it exists. */  
38  void IsoRenderer::setUpdateRectCount(int maxRects) {  void IsoRenderer::setUpdateRectCount(int maxRects) {
39          //Set the number of update rectangles to the new value:          //Set the number of update rectangles to the new value:
40          updateRectCount = maxRects;          updateRectCount = maxRects;
# Line 56  void IsoRenderer::setUpdateRectCount(int Line 47  void IsoRenderer::setUpdateRectCount(int
47          updateRectIndex = 0;          updateRectIndex = 0;
48  }  }
49    
 /** @todo Delete the old map before creating a new one if it exists. */  
50  void IsoRenderer::setMapSize(int newMapWidth, int newMapHeight) {  void IsoRenderer::setMapSize(int newMapWidth, int newMapHeight) {
51          //TODO: Delete the old map if it exists.          //TODO: Delete the old map if it exists.
52          //Allocate the new update map of the appropriate size:          //Allocate the new update map of the appropriate size:
# Line 75  void IsoRenderer::setExtentRect(RECT* ne Line 65  void IsoRenderer::setExtentRect(RECT* ne
65          CopyRect(&extentRectangle, newExtent);          CopyRect(&extentRectangle, newExtent);
66  }  }
67    
68  /** @todo Do something more useful than returning if we have exceeded the maximum number of update rectangles. Maybe merge some rectangles to make room or set the whole screen to update. */  //add rect to list
69  void IsoRenderer::addRect(RECT* updateRect) {  void IsoRenderer::addRect(RECT* updateRect) {
70          //TODO: Do something more useful than returning. Maybe merge some rectangles to make room or set the whole screen to update.          //TODO: Do something more useful than returning. Maybe merge some rectangles to make room or set the whole screen to update.
71          //If there is no more room in the array of update rectangles, return:          //If there is no more room in the array of update rectangles, return:
# Line 97  void IsoRenderer::addRect(RECT* updateRe Line 87  void IsoRenderer::addRect(RECT* updateRe
87          CopyRect(&updateList[updateRectIndex], &relevantRect);          CopyRect(&updateList[updateRectIndex], &relevantRect);
88          updateRectIndex ++; //Increment the current index          updateRectIndex ++; //Increment the current index
89    
90          //Temporary calculation point:          //Temporary calculation variables:
91          POINT tempPoint;          POINT tempPoint;
92            POINT coarsePoint;
93            POINT mapPoint;
94                    
95          //Corner points          //Corner points
96          POINT upperLeftCorner;          POINT upperLeftCorner;
# Line 110  void IsoRenderer::addRect(RECT* updateRe Line 102  void IsoRenderer::addRect(RECT* updateRe
102          //Upper-left          //Upper-left
103          tempPoint.x = relevantRect.left;          tempPoint.x = relevantRect.left;
104          tempPoint.y = relevantRect.top;          tempPoint.y = relevantRect.top;
105          upperLeftCorner = mouseMap->mapMouse(tempPoint);          //Convert screen coordinates to world coordinates:
106            tempPoint = scroller->ScreenToWorld(tempPoint);
107            //Subtract the mousemap reference point:
108            tempPoint.x -= mouseMap->getReferencePoint()->x;
109            tempPoint.y -= mouseMap->getReferencePoint()->y;
110            //Calculate the coarse coordinates:
111            coarsePoint.x = tempPoint.x / mouseMap->getWidth();
112            coarsePoint.y = tempPoint.y / mouseMap->getHeight();
113            //Calculate the fine coordinates:
114            tempPoint.x %= mouseMap->getWidth();
115            tempPoint.y %= mouseMap->getHeight();
116            //If fine coordinates are negative, move over:
117            if(tempPoint.x < 0) {
118                    coarsePoint.x --;
119            }
120            if(tempPoint.y < 0) {
121                    coarsePoint.y --;
122            }
123            //Initialize the map point:
124            mapPoint.x = 0;
125            mapPoint.y = 0;
126            //move to the east
127            mapPoint = tileWalker->walkTile(mapPoint, IDIR_EAST);
128            //assign the corner point
129            upperLeftCorner.x = mapPoint.x * coarsePoint.x;
130            upperLeftCorner.y = mapPoint.y * coarsePoint.x;
131            //reset map point
132            mapPoint.x = 0;
133            mapPoint.y = 0;
134            //move to the south
135            mapPoint = tileWalker->walkTile(mapPoint, IDIR_SOUTH);
136            upperLeftCorner.x += (mapPoint.x * coarsePoint.y);
137            upperLeftCorner.y += (mapPoint.y * coarsePoint.y);
138    
139          //upper right          //upper right
140          tempPoint.x = relevantRect.right;          tempPoint.x = relevantRect.right;
141          tempPoint.y = relevantRect.top;          tempPoint.y = relevantRect.top;
142          upperRightCorner = mouseMap->mapMouse(tempPoint);          //screen->world
143            tempPoint = scroller->ScreenToWorld(tempPoint);
144            //subtract mousemap reference point
145            tempPoint.x -= mouseMap->getReferencePoint()->x;
146            tempPoint.y -= mouseMap->getReferencePoint()->y;
147            //calculate coarse coordinates
148            coarsePoint.x = tempPoint.x / mouseMap->getWidth();
149            coarsePoint.y = tempPoint.y / mouseMap->getHeight();
150            //calculate fine cordinates
151            tempPoint.x %= mouseMap->getWidth();
152            tempPoint.y %= mouseMap->getHeight();
153            //check for negative fine coordinates
154            if(tempPoint.x < 0) {
155                    coarsePoint.x--;
156            }
157            if(tempPoint.y < 0) {
158                    coarsePoint.y--;
159            }
160            //reset map point
161            mapPoint.x = 0;
162            mapPoint.y = 0;
163            //move to the east
164            mapPoint = tileWalker->walkTile(mapPoint, IDIR_EAST);
165            //assign the corner point
166            upperRightCorner.x = mapPoint.x * coarsePoint.x;
167            upperRightCorner.y = mapPoint.y * coarsePoint.x;
168            //reset map point
169            mapPoint.x = 0;
170            mapPoint.y = 0;
171            //move to the south
172            mapPoint = tileWalker->walkTile(mapPoint, IDIR_SOUTH);
173            upperRightCorner.x += (mapPoint.x * coarsePoint.y);
174            upperRightCorner.y += (mapPoint.y * coarsePoint.y);
175    
176          //lower left          //lower left
177          tempPoint.x = relevantRect.left;          tempPoint.x = relevantRect.left;
178          tempPoint.y = relevantRect.bottom;          tempPoint.y = relevantRect.bottom;
179          lowerLeftCorner = mouseMap->mapMouse(tempPoint);          //screen->world
180            tempPoint = scroller->ScreenToWorld(tempPoint);
181            //subtract mousemap reference point
182            tempPoint.x -= mouseMap->getReferencePoint()->x;
183            tempPoint.y -= mouseMap->getReferencePoint()->y;
184            //calculate coarse coordinates
185            coarsePoint.x = tempPoint.x / mouseMap->getWidth();
186            coarsePoint.y = tempPoint.y / mouseMap->getHeight();
187            //calculate fine cordinates
188            tempPoint.x %= mouseMap->getWidth();
189            tempPoint.y %= mouseMap->getHeight();
190            //check for negative fine coordinates
191            if(tempPoint.x < 0) {
192                    coarsePoint.x--;
193            }
194            if(tempPoint.y < 0) {
195                    coarsePoint.y--;
196            }
197            //reset map point
198            mapPoint.x = 0;
199            mapPoint.y = 0;
200            //move to the east
201            mapPoint = tileWalker->walkTile(mapPoint, IDIR_EAST);
202            //assign the corner point
203            lowerLeftCorner.x = mapPoint.x * coarsePoint.x;
204            lowerLeftCorner.y = mapPoint.y * coarsePoint.x;
205            //reset map point
206            mapPoint.x = 0;
207            mapPoint.y = 0;
208            //move to the south
209            mapPoint = tileWalker->walkTile(mapPoint, IDIR_SOUTH);
210            lowerLeftCorner.x += (mapPoint.x * coarsePoint.y);
211            lowerLeftCorner.y += (mapPoint.y * coarsePoint.y);
212    
213          //lower right          //lower right
214          tempPoint.x = relevantRect.right;          tempPoint.x = relevantRect.right;
215          tempPoint.y = relevantRect.bottom;          tempPoint.y = relevantRect.bottom;
216          lowerRightCorner = mouseMap->mapMouse(tempPoint);          //screen->world
217            tempPoint = scroller->ScreenToWorld(tempPoint);
218            //subtract mousemap reference point
219            tempPoint.x -= mouseMap->getReferencePoint()->x;
220            tempPoint.y -= mouseMap->getReferencePoint()->y;
221            //calculate coarse coordinates
222            coarsePoint.x = tempPoint.x / mouseMap->getWidth();
223            coarsePoint.y = tempPoint.y / mouseMap->getHeight();
224            //calculate fine cordinates
225            tempPoint.x %= mouseMap->getWidth();
226            tempPoint.y %= mouseMap->getHeight();
227            //check for negative fine coordinates
228            if(tempPoint.x < 0) {
229                    coarsePoint.x--;
230            }
231            if(tempPoint.y < 0) {
232                    coarsePoint.y--;
233            }
234            //reset map point
235            mapPoint.x = 0;
236            mapPoint.y = 0;
237            //move to the east
238            mapPoint = tileWalker->walkTile(mapPoint, IDIR_EAST);
239            //assign the corner point
240            lowerRightCorner.x = mapPoint.x * coarsePoint.x;
241            lowerRightCorner.y = mapPoint.y * coarsePoint.x;
242            //reset map point
243            mapPoint.x = 0;
244            mapPoint.y = 0;
245            //move to the south
246            mapPoint = tileWalker->walkTile(mapPoint, IDIR_SOUTH);
247            lowerRightCorner.x += (mapPoint.x * coarsePoint.y);
248            lowerRightCorner.y += (mapPoint.y * coarsePoint.y);
249    
250            //move the corners away from screenspace one step
251            upperLeftCorner = tileWalker->walkTile(upperLeftCorner, IDIR_NORTHWEST);
252            upperRightCorner = tileWalker->walkTile(upperRightCorner, IDIR_NORTHEAST);
253            lowerLeftCorner = tileWalker->walkTile(lowerLeftCorner, IDIR_SOUTHWEST);
254            lowerRightCorner = tileWalker->walkTile(lowerRightCorner, IDIR_SOUTHEAST);
255    
256          //move the left corners to the west          //move the left corners to the west
257          upperLeftCorner = tileWalker->walkTile(upperLeftCorner, IDIR_WEST);          upperLeftCorner = tileWalker->walkTile(upperLeftCorner, IDIR_WEST);
# Line 162  void IsoRenderer::addRect(RECT* updateRe Line 288  void IsoRenderer::addRect(RECT* updateRe
288                  }                  }
289    
290                  //If we have reached the lower-left corner, we are done with the rectangle:                  //If we have reached the lower-left corner, we are done with the rectangle:
291                  if(startRow.x == lowerLeftCorner.x && startRow.y == lowerRightCorner.y) {                  if(/*startRow.x == lowerLeftCorner.x && */startRow.y == lowerRightCorner.y) {
292                          break;                          break;
293                  }                  }
294    
295                  //Move down a row:                  //Move down a row:
296                  startRow = tileWalker->walkTile(startRow, IDIR_SOUTH);                  if(rowCount & 1) {
297                  endRow = tileWalker->walkTile(endRow, IDIR_SOUTH);                          //This is an odd row
298                            //Move outwards:
299                            startRow = tileWalker->walkTile(startRow, IDIR_SOUTHWEST);
300                            endRow = tileWalker->walkTile(endRow, IDIR_SOUTHEAST);
301                    } else {
302                            //This is an even row; move inwards:
303                            startRow = tileWalker->walkTile(startRow, IDIR_SOUTHEAST);
304                            endRow = tileWalker->walkTile(endRow, IDIR_SOUTHWEST);
305                    }
306    
307                  //Increment the row counter:                  //Increment the row counter:
308                  rowCount ++;                  rowCount ++;
# Line 292  void IsoRenderer::scrollFrame(int scroll Line 426  void IsoRenderer::scrollFrame(int scroll
426                          sourceRectangle.top += scrollY;                          sourceRectangle.top += scrollY;
427                  }                  }
428          }          }
429    
430    
431            ////////////////// TEST //////////////////////////
432            //sourceRectangle.left = 200;
433            //sourceRectangle.top = 10;
434            //sourceRectangle.right = 500;
435            //sourceRectangle.bottom = 310;
436    
437            //destinationRectangle.left = 50;
438            //destinationRectangle.top = 50;
439            //destinationRectangle.right = 250;
440            //destinationRectangle.bottom = 250;
441            /////////////////// TEST //////////////////
442                    
443          //perform the blit          //perform the blit
444          SDL_Rect* dest = GetSDLRect(&destinationRectangle);          SDL_BlitSurface(frameBuffer, GetSDLRect(&sourceRectangle), backBuffer, GetSDLRect(&destinationRectangle));
         SDL_BlitSurface(frameBuffer, GetSDLRect(&sourceRectangle), backBuffer, dest);  
445    
446          //perform the scroll          //perform the scroll
447          scroller->moveAnchor(scrollX, scrollY);          scroller->moveAnchor(scrollX, scrollY);
# Line 313  void IsoRenderer::updateFrame() { Line 459  void IsoRenderer::updateFrame() {
459    
460          //Temporary points:          //Temporary points:
461          POINT tempPoint;          POINT tempPoint;
462            POINT coarsePoint;
463            POINT mapPoint;
464          POINT plotPoint;          POINT plotPoint;
465                    
466          //Corner points          //Corner points
# Line 325  void IsoRenderer::updateFrame() { Line 473  void IsoRenderer::updateFrame() {
473          //Upper-left          //Upper-left
474          tempPoint.x = relevantRect.left;          tempPoint.x = relevantRect.left;
475          tempPoint.y = relevantRect.top;          tempPoint.y = relevantRect.top;
476          upperLeftCorner = mouseMap->mapMouse(tempPoint);          //Convert screen coordinates to world coordinates:
477            tempPoint = scroller->ScreenToWorld(tempPoint);
478            //Subtract the mousemap reference point:
479            tempPoint.x -= mouseMap->getReferencePoint()->x;
480            tempPoint.y -= mouseMap->getReferencePoint()->y;
481            //Calculate the coarse coordinates:
482            coarsePoint.x = tempPoint.x / mouseMap->getWidth();
483            coarsePoint.y = tempPoint.y / mouseMap->getHeight();
484            //Calculate the fine coordinates:
485            tempPoint.x %= mouseMap->getWidth();
486            tempPoint.y %= mouseMap->getHeight();
487            //If fine coordinates are negative, move over:
488            if(tempPoint.x < 0) {
489                    coarsePoint.x --;
490            }
491            if(tempPoint.y < 0) {
492                    coarsePoint.y --;
493            }
494            //Initialize the map point:
495            mapPoint.x = 0;
496            mapPoint.y = 0;
497            //move to the east
498            mapPoint = tileWalker->walkTile(mapPoint, IDIR_EAST);
499            //assign the corner point
500            upperLeftCorner.x = mapPoint.x * coarsePoint.x;
501            upperLeftCorner.y = mapPoint.y * coarsePoint.x;
502            //reset map point
503            mapPoint.x = 0;
504            mapPoint.y = 0;
505            //move to the south
506            mapPoint = tileWalker->walkTile(mapPoint, IDIR_SOUTH);
507            upperLeftCorner.x += (mapPoint.x * coarsePoint.y);
508            upperLeftCorner.y += (mapPoint.y * coarsePoint.y);
509    
510          //upper right          //upper right
511          tempPoint.x = relevantRect.right;          tempPoint.x = relevantRect.right;
512          tempPoint.y = relevantRect.top;          tempPoint.y = relevantRect.top;
513          upperRightCorner = mouseMap->mapMouse(tempPoint);          //screen->world
514            tempPoint = scroller->ScreenToWorld(tempPoint);
515            //subtract mousemap reference point
516            tempPoint.x -= mouseMap->getReferencePoint()->x;
517            tempPoint.y -= mouseMap->getReferencePoint()->y;
518            //calculate coarse coordinates
519            coarsePoint.x = tempPoint.x / mouseMap->getWidth();
520            coarsePoint.y = tempPoint.y / mouseMap->getHeight();
521            //calculate fine cordinates
522            tempPoint.x %= mouseMap->getWidth();
523            tempPoint.y %= mouseMap->getHeight();
524            //check for negative fine coordinates
525            if(tempPoint.x < 0) {
526                    coarsePoint.x--;
527            }
528            if(tempPoint.y < 0) {
529                    coarsePoint.y--;
530            }
531            //reset map point
532            mapPoint.x = 0;
533            mapPoint.y = 0;
534            //move to the east
535            mapPoint = tileWalker->walkTile(mapPoint, IDIR_EAST);
536            //assign the corner point
537            upperRightCorner.x = mapPoint.x * coarsePoint.x;
538            upperRightCorner.y = mapPoint.y * coarsePoint.x;
539            //reset map point
540            mapPoint.x = 0;
541            mapPoint.y = 0;
542            //move to the south
543            mapPoint = tileWalker->walkTile(mapPoint, IDIR_SOUTH);
544            upperRightCorner.x += (mapPoint.x * coarsePoint.y);
545            upperRightCorner.y += (mapPoint.y * coarsePoint.y);
546    
547          //lower left          //lower left
548          tempPoint.x = relevantRect.left;          tempPoint.x = relevantRect.left;
549          tempPoint.y = relevantRect.bottom;          tempPoint.y = relevantRect.bottom;
550          lowerLeftCorner = mouseMap->mapMouse(tempPoint);          //screen->world
551            tempPoint = scroller->ScreenToWorld(tempPoint);
552            //subtract mousemap reference point
553            tempPoint.x -= mouseMap->getReferencePoint()->x;
554            tempPoint.y -= mouseMap->getReferencePoint()->y;
555            //calculate coarse coordinates
556            coarsePoint.x = tempPoint.x / mouseMap->getWidth();
557            coarsePoint.y = tempPoint.y / mouseMap->getHeight();
558            //calculate fine cordinates
559            tempPoint.x %= mouseMap->getWidth();
560            tempPoint.y %= mouseMap->getHeight();
561            //check for negative fine coordinates
562            if(tempPoint.x < 0) {
563                    coarsePoint.x--;
564            }
565            if(tempPoint.y < 0) {
566                    coarsePoint.y--;
567            }
568            //reset map point
569            mapPoint.x = 0;
570            mapPoint.y = 0;
571            //move to the east
572            mapPoint = tileWalker->walkTile(mapPoint, IDIR_EAST);
573            //assign the corner point
574            lowerLeftCorner.x = mapPoint.x * coarsePoint.x;
575            lowerLeftCorner.y = mapPoint.y * coarsePoint.x;
576            //reset map point
577            mapPoint.x = 0;
578            mapPoint.y = 0;
579            //move to the south
580            mapPoint = tileWalker->walkTile(mapPoint, IDIR_SOUTH);
581            lowerLeftCorner.x += (mapPoint.x * coarsePoint.y);
582            lowerLeftCorner.y += (mapPoint.y * coarsePoint.y);
583    
584          //lower right          //lower right
585          tempPoint.x = relevantRect.right;          tempPoint.x = relevantRect.right;
586          tempPoint.y = relevantRect.bottom;          tempPoint.y = relevantRect.bottom;
587          lowerRightCorner = mouseMap->mapMouse(tempPoint);          //screen->world
588            tempPoint = scroller->ScreenToWorld(tempPoint);
589            //subtract mousemap reference point
590            tempPoint.x -= mouseMap->getReferencePoint()->x;
591            tempPoint.y -= mouseMap->getReferencePoint()->y;
592            //calculate coarse coordinates
593            coarsePoint.x = tempPoint.x / mouseMap->getWidth();
594            coarsePoint.y = tempPoint.y / mouseMap->getHeight();
595            //calculate fine cordinates
596            tempPoint.x %= mouseMap->getWidth();
597            tempPoint.y %= mouseMap->getHeight();
598            //check for negative fine coordinates
599            if(tempPoint.x < 0) {
600                    coarsePoint.x--;
601            }
602            if(tempPoint.y < 0) {
603                    coarsePoint.y--;
604            }
605            //reset map point
606            mapPoint.x = 0;
607            mapPoint.y = 0;
608            //move to the east
609            mapPoint = tileWalker->walkTile(mapPoint, IDIR_EAST);
610            //assign the corner point
611            lowerRightCorner.x = mapPoint.x * coarsePoint.x;
612            lowerRightCorner.y = mapPoint.y * coarsePoint.x;
613            //reset map point
614            mapPoint.x = 0;
615            mapPoint.y = 0;
616            //move to the south
617            mapPoint = tileWalker->walkTile(mapPoint, IDIR_SOUTH);
618            lowerRightCorner.x += (mapPoint.x * coarsePoint.y);
619            lowerRightCorner.y += (mapPoint.y * coarsePoint.y);
620    
621            //move the corners away from screenspace one step
622            upperLeftCorner = tileWalker->walkTile(upperLeftCorner, IDIR_NORTHWEST);
623            upperRightCorner = tileWalker->walkTile(upperRightCorner, IDIR_NORTHEAST);
624            lowerLeftCorner = tileWalker->walkTile(lowerLeftCorner, IDIR_SOUTHWEST);
625            lowerRightCorner = tileWalker->walkTile(lowerRightCorner, IDIR_SOUTHEAST);
626    
627          //move the left corners to the west          //move the left corners to the west
628          upperLeftCorner = tileWalker->walkTile(upperLeftCorner, IDIR_WEST);          upperLeftCorner = tileWalker->walkTile(upperLeftCorner, IDIR_WEST);
# Line 384  void IsoRenderer::updateFrame() { Line 666  void IsoRenderer::updateFrame() {
666                  }                  }
667    
668                  //If we have reached the lower-left corner, we are done with the rectangle:                  //If we have reached the lower-left corner, we are done with the rectangle:
669                  if(startRow.x == lowerLeftCorner.x && startRow.y == lowerRightCorner.y) {                  if(/*startRow.x == lowerLeftCorner.x && */startRow.y == lowerRightCorner.y) {
670                          break;                          break;
671                  }                  }
672    
673                  //Move down a row:                  //Move down a row:
674                  startRow = tileWalker->walkTile(startRow, IDIR_SOUTH);                  if(rowCount & 1) {
675                  endRow = tileWalker->walkTile(endRow, IDIR_SOUTH);                          //This is an odd row
676                            //Move outwards:
677                            startRow = tileWalker->walkTile(startRow, IDIR_SOUTHWEST);
678                            endRow = tileWalker->walkTile(endRow, IDIR_SOUTHEAST);
679                    } else {
680                            //This is an even row; move inwards:
681                            startRow = tileWalker->walkTile(startRow, IDIR_SOUTHEAST);
682                            endRow = tileWalker->walkTile(endRow, IDIR_SOUTHWEST);
683                    }
684    
685                  //Increment the row counter:                  //Increment the row counter:
686                  rowCount ++;                  rowCount ++;
# Line 409  void IsoRenderer::updateFrame() { Line 699  void IsoRenderer::updateFrame() {
699          //set rectangle index to 0          //set rectangle index to 0
700          updateRectIndex = 0;          updateRectIndex = 0;
701  }  }
702    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26