Engine:
* Updated clouds and flakes to fill the whole visible map (and borders)
* Added simple clipping to most drawing functions (might need some testing) which should improve performance on low end graphic cards
--- a/hedgewars/VGSHandlers.inc Tue Aug 24 13:24:37 2010 +0200
+++ b/hedgewars/VGSHandlers.inc Tue Aug 24 17:03:44 2010 +0200
@@ -34,8 +34,8 @@
Y:= Y + (dY + tdY + cGravityf * vobFallSpeed) * Steps;
Angle:= Angle + dAngle * Steps;
- if (round(X) >= -cScreenWidth - 64) and
- (round(X) <= cScreenWidth + LAND_WIDTH) and
+ if (round(X) >= cLeftScreenBorder) and
+ (round(X) <= cRightScreenBorder) and
(round(Y) <= (LAND_HEIGHT + 75)) and
(Timer > 0) and (Timer-Steps > 0) then
begin
@@ -51,8 +51,8 @@
end
else
begin
- if round(X) < -cScreenWidth - 64 then X:= float(cScreenWidth + LAND_WIDTH) else
- if round(X) > cScreenWidth + LAND_WIDTH then X:= float(-cScreenWidth - 64);
+ if round(X) < cLeftScreenBorder then X:= X + cScreenSpace else
+ if round(X) > cRightScreenBorder then X:= X - cScreenSpace;
// if round(Y) < (LAND_HEIGHT - 1024 - 75) then Y:= Y + float(25); // For if flag is set for flakes rising upwards?
if round(Y) > (LAND_HEIGHT + 75) then Y:= Y - float(1024 + 150); // TODO - configure in theme (jellies for example could use limited range)
Timer:= 0;
@@ -86,8 +86,8 @@
Gear^.Y := LAND_HEIGHT-1184 + Gear^.Timer mod 8 + t;
-if round(Gear^.X) < -cScreenWidth - 256 then Gear^.X:= float(cScreenWidth + LAND_WIDTH) else
-if round(Gear^.X) > cScreenWidth + LAND_WIDTH then Gear^.X:= float(-cScreenWidth - 256)
+if round(Gear^.X) < cLeftScreenBorder then Gear^.X:= Gear^.X + cScreenSpace else
+if round(Gear^.X) > cRightScreenBorder then Gear^.X:= Gear^.X - cScreenSpace
end;
////////////////////////////////////////////////////////////////////////////////
@@ -152,7 +152,7 @@
if (Gear^.State and gstTmpFlag) = 0 then
begin
Gear^.dY:= Gear^.dY + cGravityf * Steps;
- if ((GameTicks mod 100) < Steps + 1) then
+ if ((GameTicks mod 200) < Steps + 1) then
begin
vgt:= AddVisualGear(round(Gear^.X), round(Gear^.Y), vgtFire);
if vgt <> nil then
--- a/hedgewars/hwengine.pas Tue Aug 24 13:24:37 2010 +0200
+++ b/hedgewars/hwengine.pas Tue Aug 24 17:03:44 2010 +0200
@@ -263,6 +263,11 @@
ShowMainWindow();
{$ENDIF}
+ // those values still aren't perfect
+ cLeftScreenBorder:= round(-cMinZoomLevel * cScreenWidth);
+ cRightScreenBorder:= round(cMinZoomLevel * cScreenWidth + LAND_WIDTH);
+ cScreenSpace:= cRightScreenBorder - cLeftScreenBorder;
+
AddProgress();
ControllerInit(); // has to happen before InitKbdKeyTable to map keys
--- a/hedgewars/uLandObjects.pas Tue Aug 24 13:24:37 2010 +0200
+++ b/hedgewars/uLandObjects.pas Tue Aug 24 17:03:44 2010 +0200
@@ -403,7 +403,10 @@
ReadLn(f, cCloudsNumber);
// TODO - adjust all the theme cloud numbers. This should not be a permanent fix
-cCloudsNumber:= cCloudsNumber * (LAND_WIDTH div 2048);
+//cCloudsNumber:= cCloudsNumber * (LAND_WIDTH div 2048);
+
+// scale number of clouds depending on screen space (two times land width)
+cCloudsNumber:= cCloudsNumber * cScreenSpace div LAND_WIDTH;
Readln(f, ThemeObjects.Count);
for i:= 0 to Pred(ThemeObjects.Count) do
@@ -450,12 +453,16 @@
Readln(f, vobCount);
if vobCount > 0 then
Readln(f, vobFramesCount, vobFrameTicks, vobVelocity, vobFallSpeed);
+
+// adjust amount of flakes scaled by screen space
+vobCount:= vobCount * cScreenSpace div LAND_WIDTH;
+
if (cReducedQuality and rqKillFlakes) <> 0 then
vobCount:= 0;
for i:= 0 to Pred(vobCount) do
- AddVisualGear( -cScreenWidth + random(cScreenWidth * 2 + LAND_WIDTH), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake);
+ AddVisualGear(cLeftScreenBorder + random(cScreenSpace), random(1024+200) - 100 + LAND_HEIGHT, vgtFlake);
Close(f);
{$I+}
--- a/hedgewars/uMisc.pas Tue Aug 24 13:24:37 2010 +0200
+++ b/hedgewars/uMisc.pas Tue Aug 24 17:03:44 2010 +0200
@@ -98,6 +98,10 @@
//userNick is in uChat
recordFileName : shortstring = '';
+ cLeftScreenBorder : LongInt = 0;
+ cRightScreenBorder : LongInt = 0;
+ cScreenSpace : LongInt = 0;
+
cCaseFactor : Longword;
cLandAdditions : Longword;
cExplosives : Longword;
--- a/hedgewars/uStore.pas Tue Aug 24 13:24:37 2010 +0200
+++ b/hedgewars/uStore.pas Tue Aug 24 17:03:44 2010 +0200
@@ -493,6 +493,13 @@
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
begin
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit;
+
+// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then
+ exit;
+if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then
+ exit;
+
rr.x:= X;
rr.y:= Y;
rr.w:= W;
@@ -531,6 +538,7 @@
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
begin
+
glPushMatrix;
glTranslatef(X, Y, 0);
glScalef(Scale, Scale, 1);
@@ -554,6 +562,12 @@
hw, nx, ny: LongInt;
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
begin
+// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) > cScreenWidth / cScaleFactor) then
+ exit;
+if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) > cScreenHeight / cScaleFactor) then
+ exit;
+
glPushMatrix;
glTranslatef(X, Y, 0);
@@ -635,6 +649,12 @@
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
var VertexBuffer: array [0..3] of TVertex2f;
begin
+// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
+ exit;
+if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
+ exit;
+
glPushMatrix;
glTranslatef(X, Y, 0);
@@ -728,6 +748,11 @@
var l, r, t, b: real;
TextureBuffer: array [0..3] of TVertex2f;
begin
+// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+if (abs(X) > 32) and ((abs(X) - 16)> cScreenWidth / cScaleFactor) then
+ exit;
+if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) > cScreenHeight / cScaleFactor) then
+ exit;
t:= Pos * 32 / HHTexture^.h;
b:= (Pos + 1) * 32 / HHTexture^.h;
@@ -768,6 +793,12 @@
procedure DrawFillRect(r: TSDL_Rect);
var VertexBuffer: array [0..3] of TVertex2f;
begin
+// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) > cScreenWidth / cScaleFactor) then
+ exit;
+if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) > cScreenHeight / cScaleFactor) then
+ exit;
+
glDisable(GL_TEXTURE_2D);
Tint($00, $00, $00, $80);
--- a/hedgewars/uVisualGears.pas Tue Aug 24 13:24:37 2010 +0200
+++ b/hedgewars/uVisualGears.pas Tue Aug 24 17:03:44 2010 +0200
@@ -494,7 +494,7 @@
var i: LongInt;
begin
for i:= 0 to cCloudsNumber - 1 do
- AddVisualGear( - cScreenWidth + i * ((cScreenWidth * 2 + (LAND_WIDTH+256)) div (cCloudsNumber + 1)), LAND_HEIGHT-1184, vgtCloud)
+ AddVisualGear(cLeftScreenBorder + i * cScreenSpace div (cCloudsNumber + 1), LAND_HEIGHT-1184, vgtCloud)
end;
procedure initModule;
--- a/hedgewars/uWorld.pas Tue Aug 24 13:24:37 2010 +0200
+++ b/hedgewars/uWorld.pas Tue Aug 24 17:03:44 2010 +0200
@@ -96,7 +96,7 @@
AddGoal:= s;
end;
begin
- missionTimer:= 0;
+missionTimer:= 0;
if (GameFlags and gfRandomOrder) <> 0 then // shuffle them up a bit
begin