Commits

stqn committed c90c1db

View now draws big objects when they are partially out of the view.

Comments (0)

Files changed (2)

src/gameobjectmanager.d

 
 class GameObjectManager {
 
+	int mMaxObjectWidth; // Biggest object seen this frame (needed by View)
+	int mMaxObjectHeight;
+
 	this() {
 		gGameObjectManager = this;
 	}
 		if( xmax >= gMap.mWidth ) xmax = gMap.mWidth - 1;
 		if( ymax >= gMap.mHeight ) ymax = gMap.mHeight - 1;
 
+		mMaxObjectWidth = Map.TILE_WIDTH;
+		mMaxObjectHeight = Map.TILE_HEIGHT;
+
 		// mise à jour des objets
 		foreach( o; gMap.getObjects( xmin, ymin, xmax, ymax, GameObject.Flags.UPDATED ) ) {
 
 							}
 						}
 					}
+					// Update max object size so that View knows how much to
+					// draw around the view.
+					if( o.mCollBox.xMax > mMaxObjectWidth )
+						mMaxObjectWidth = cast(int) o.mCollBox.xMax;
+					if( o.mCollBox.yMax > mMaxObjectHeight )
+						mMaxObjectHeight = cast(int) o.mCollBox.yMax;
 				}
 			}
 		}
 import derelict.sdl.sdl;
 
 import gameobject;
+import gameobjectmanager;
 import gameobjects.updatedgameobject;
 import map;
 import screen;
 
 
 	void draw() {
-
-		int xMapMin = cast(int) (mX / Map.TILE_WIDTH) - 1;
-		int yMapMin = cast(int) (mY / Map.TILE_HEIGHT) - 1;
-		int xMapMax = xMapMin + mWidth + 1;
-		int yMapMax = yMapMin + mHeight + 1;
+		int xMapMin = cast(int) ((mX - gGameObjectManager.mMaxObjectWidth + 1) / Map.TILE_WIDTH);
+		int yMapMin = cast(int) ((mY - gGameObjectManager.mMaxObjectHeight + 1) / Map.TILE_HEIGHT);
+		int xMapMax = xMapMin + mWidth + gGameObjectManager.mMaxObjectWidth / Map.TILE_WIDTH;
+		int yMapMax = yMapMin + mHeight + gGameObjectManager.mMaxObjectHeight / Map.TILE_HEIGHT;
 
 		if( xMapMin < 0 ) xMapMin = 0;
 		if( yMapMin < 0 ) yMapMin = 0;