hedgewars/uWorld.pas
branchqmlfrontend
changeset 10515 7705784902e1
parent 10510 9329dab04490
child 10523 00ac079fa51f
equal deleted inserted replaced
10458:f7a199346c3e 10515:7705784902e1
    77     CountTicks: Longword;
    77     CountTicks: Longword;
    78     prevPoint{, prevTargetPoint}: TPoint;
    78     prevPoint{, prevTargetPoint}: TPoint;
    79     amSel: TAmmoType = amNothing;
    79     amSel: TAmmoType = amNothing;
    80     missionTex: PTexture;
    80     missionTex: PTexture;
    81     missionTimer: LongInt;
    81     missionTimer: LongInt;
    82     stereoDepth: GLfloat;
       
    83     isFirstFrame: boolean;
    82     isFirstFrame: boolean;
    84     AMAnimType: LongInt;
    83     AMAnimType: LongInt;
    85     recTexture: PTexture;
    84     recTexture: PTexture;
    86     AmmoMenuTex     : PTexture;
    85     AmmoMenuTex     : PTexture;
    87     HorizontOffset: LongInt;
    86     HorizontOffset: LongInt;
   985     d:= d / 5;
   984     d:= d / 5;
   986     if rm = rmDefault then
   985     if rm = rmDefault then
   987         exit
   986         exit
   988     else if rm = rmLeftEye then
   987     else if rm = rmLeftEye then
   989         d:= -d;
   988         d:= -d;
   990     stereoDepth:= stereoDepth + d;
   989     cStereoDepth:= cStereoDepth + d;
   991     openglTranslProjMatrix(d, 0, 0);
   990     openglTranslProjMatrix(d, 0, 0);
   992 {$ENDIF}
   991 {$ENDIF}
   993 end;
   992 end;
   994 
   993 
   995 procedure ResetDepth(rm: TRenderMode);
   994 procedure ResetDepth(rm: TRenderMode);
   996 begin
   995 begin
   997     rm:= rm; // avoid hint
   996     rm:= rm; // avoid hint
   998 {$IFDEF USE_S3D_RENDERING}
   997 {$IFDEF USE_S3D_RENDERING}
   999     if rm = rmDefault then
   998     if rm = rmDefault then
  1000         exit;
   999         exit;
  1001     openglTranslProjMatrix(-stereoDepth, 0, 0);
  1000     openglTranslProjMatrix(-cStereoDepth, 0, 0);
  1002     cStereoDepth:= 0;
  1001     cStereoDepth:= 0;
  1003 {$ENDIF}
  1002 {$ENDIF}
  1004 end;
  1003 end;
  1005 
  1004 
  1006 procedure RenderWorldEdge(Lag: Longword);
  1005 procedure RenderWorldEdge;
  1007 var
  1006 var
  1008     //VertexBuffer: array [0..3] of TVertex2f;
  1007     //VertexBuffer: array [0..3] of TVertex2f;
  1009     tmp, w: LongInt;
  1008     tmp, w: LongInt;
  1010     rect: TSDL_Rect;
  1009     rect: TSDL_Rect;
  1011     //c1, c2: LongWord; // couple of colours for edges
  1010     //c1, c2: LongWord; // couple of colours for edges
  1014     begin
  1013     begin
  1015 (* I think for a bounded world, will fill the left and right areas with black or something. Also will probably want various border effects/animations based on border type.  Prob also, say, trigger a border animation timer on an impact. *)
  1014 (* I think for a bounded world, will fill the left and right areas with black or something. Also will probably want various border effects/animations based on border type.  Prob also, say, trigger a border animation timer on an impact. *)
  1016 
  1015 
  1017     rect.y:= ViewTopY;
  1016     rect.y:= ViewTopY;
  1018     rect.h:= ViewHeight;
  1017     rect.h:= ViewHeight;
  1019     tmp:= leftX + WorldDx;
  1018     tmp:= LongInt(leftX) + WorldDx;
  1020     w:= tmp - ViewLeftX;
  1019     w:= tmp - ViewLeftX;
  1021 
  1020 
  1022     if w > 0 then
  1021     if w > 0 then
  1023         begin
  1022         begin
  1024         rect.w:= w;
  1023         rect.w:= w;
  1026         DrawRect(rect, $30, $30, $30, $40, true);
  1025         DrawRect(rect, $30, $30, $30, $40, true);
  1027         if WorldEdge = weBounce then
  1026         if WorldEdge = weBounce then
  1028             DrawLineOnScreen(tmp - 1, ViewTopY, tmp - 1, ViewBottomY, 2, $54, $54, $FF, $FF);
  1027             DrawLineOnScreen(tmp - 1, ViewTopY, tmp - 1, ViewBottomY, 2, $54, $54, $FF, $FF);
  1029         end;
  1028         end;
  1030 
  1029 
  1031     tmp:= rightX + WorldDx;
  1030     tmp:= LongInt(rightX) + WorldDx;
  1032     w:= ViewRightX - tmp;
  1031     w:= ViewRightX - tmp;
  1033 
  1032 
  1034     if w > 0 then
  1033     if w > 0 then
  1035         begin
  1034         begin
  1036         rect.w:= w;
  1035         rect.w:= w;
  1264 end;
  1263 end;
  1265 
  1264 
  1266 
  1265 
  1267 var preShiftWorldDx: LongInt;
  1266 var preShiftWorldDx: LongInt;
  1268 
  1267 
  1269 procedure ShiftWorld(Dir: LongInt; Flip: Boolean);
  1268 procedure ShiftWorld(Dir: LongInt); inline;
  1270 begin
  1269 begin
  1271     preShiftWorldDx:= WorldDx;
  1270     preShiftWorldDx:= WorldDx;
  1272 
  1271     WorldDx:= WorldDx + Dir * LongInt(playWidth);
  1273     if Flip then
  1272 
  1274         begin
  1273 end;
  1275         WorldDx:= -WorldDx - playWidth - Dir * playWidth;
  1274 
  1276         openglPushMatrix();
  1275 procedure UnshiftWorld(); inline;
  1277         openglScalef(-1, 1, 1);
       
  1278         end
       
  1279     else
       
  1280         WorldDx:= WorldDx + Dir * playWidth;
       
  1281 
       
  1282 end;
       
  1283 
       
  1284 procedure UnshiftWorld(Dir: LongInt; Flip: Boolean);
       
  1285 begin
  1276 begin
  1286     WorldDx:= preShiftWorldDx;
  1277     WorldDx:= preShiftWorldDx;
  1287 
       
  1288     if Flip then
       
  1289         openglPopMatrix();
       
  1290 
       
  1291 end;
  1278 end;
  1292 
  1279 
  1293 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
  1280 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
  1294 var i, t: LongInt;
  1281 var i, t: LongInt;
  1295     r: TSDL_Rect;
  1282     r: TSDL_Rect;
  1296     tdx, tdy: Double;
  1283     tdx, tdy: Double;
  1297     s: shortstring;
  1284     s: shortstring;
  1298     offsetX, offsetY, screenBottom: LongInt;
  1285     offsetX, offsetY, screenBottom: LongInt;
  1299     VertexBuffer: array [0..3] of TVertex2f;
  1286     VertexBuffer: array [0..3] of TVertex2f;
  1300     replicateToLeft, replicateToRight, tmp, flip: boolean;
  1287     replicateToLeft, replicateToRight, tmp: boolean;
  1301 begin
  1288 begin
  1302 if (WorldEdge <> weWrap) {and (WorldEdge <> weBounce)} then
  1289 if WorldEdge <> weWrap then
  1303     begin
  1290     begin
  1304     replicateToLeft := false;
  1291     replicateToLeft := false;
  1305     replicateToRight:= false;
  1292     replicateToRight:= false;
  1306     flip:= false;
       
  1307     end
  1293     end
  1308 else
  1294 else
  1309     begin
  1295     begin
  1310     replicateToLeft := (leftX  + WorldDx > ViewLeftX);
  1296     replicateToLeft := (LongInt(leftX)  + WorldDx > ViewLeftX);
  1311     replicateToRight:= (rightX + WorldDx < ViewRightX);
  1297     replicateToRight:= (LongInt(rightX) + WorldDx < ViewRightX);
  1312     flip:= (WorldEdge = weBounce);
       
  1313     end;
  1298     end;
  1314 
  1299 
  1315 ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine);
  1300 ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine);
  1316 
  1301 
  1317 // note: offsetY is negative!
  1302 // note: offsetY is negative!
  1360     DrawVisualGears(5);
  1345     DrawVisualGears(5);
  1361     DrawLand(WorldDx, WorldDy);
  1346     DrawLand(WorldDx, WorldDy);
  1362 
  1347 
  1363     if replicateToLeft then
  1348     if replicateToLeft then
  1364         begin
  1349         begin
  1365         ShiftWorld(-1, flip);
  1350         ShiftWorld(-1);
  1366         DrawLand(WorldDx, WorldDy);
  1351         DrawLand(WorldDx, WorldDy);
  1367         UnshiftWorld(-1, flip);
  1352         UnshiftWorld();
  1368         end;
  1353         end;
  1369 
  1354 
  1370     if replicateToRight then
  1355     if replicateToRight then
  1371         begin
  1356         begin
  1372         ShiftWorld(1, flip);
  1357         ShiftWorld(1);
  1373         DrawLand(WorldDx, WorldDy);
  1358         DrawLand(WorldDx, WorldDy);
  1374         UnshiftWorld(1, flip);
  1359         UnshiftWorld();
  1375         end;
  1360         end;
  1376 
  1361 
  1377     DrawWater(255, 0, 0);
  1362     DrawWater(255, 0, 0);
  1378 
  1363 
  1379 (*
  1364 (*
  1403 tmp:= bShowFinger;
  1388 tmp:= bShowFinger;
  1404 bShowFinger:= false;
  1389 bShowFinger:= false;
  1405 
  1390 
  1406 if replicateToLeft then
  1391 if replicateToLeft then
  1407     begin
  1392     begin
  1408     ShiftWorld(-1, flip);
  1393     ShiftWorld(-1);
  1409     DrawVisualGears(1);
  1394     DrawVisualGears(1);
  1410     DrawGears();
  1395     DrawGears();
  1411     DrawVisualGears(6);
  1396     DrawVisualGears(6);
  1412     UnshiftWorld(-1, flip);
  1397     UnshiftWorld();
  1413     end;
  1398     end;
  1414 
  1399 
  1415 if replicateToRight then
  1400 if replicateToRight then
  1416     begin
  1401     begin
  1417     ShiftWorld(1, flip);
  1402     ShiftWorld(1);
  1418     DrawVisualGears(1);
  1403     DrawVisualGears(1);
  1419     DrawGears();
  1404     DrawGears();
  1420     DrawVisualGears(6);
  1405     DrawVisualGears(6);
  1421     UnshiftWorld(1, flip);
  1406     UnshiftWorld();
  1422     end;
  1407     end;
  1423 
  1408 
  1424 bShowFinger:= tmp;
  1409 bShowFinger:= tmp;
  1425 
  1410 
  1426 DrawVisualGears(1);
  1411 DrawVisualGears(1);
  1462 // note: negative parallax gears should last very little for a smooth stereo effect
  1447 // note: negative parallax gears should last very little for a smooth stereo effect
  1463     ChangeDepth(RM, cStereo_Outside);
  1448     ChangeDepth(RM, cStereo_Outside);
  1464 
  1449 
  1465     if replicateToLeft then
  1450     if replicateToLeft then
  1466         begin
  1451         begin
  1467         ShiftWorld(-1, flip);
  1452         ShiftWorld(-1);
  1468         DrawVisualGears(2);
  1453         DrawVisualGears(2);
  1469         UnshiftWorld(-1, flip);
  1454         UnshiftWorld();
  1470         end;
  1455         end;
  1471 
  1456 
  1472     if replicateToRight then
  1457     if replicateToRight then
  1473         begin
  1458         begin
  1474         ShiftWorld(1, flip);
  1459         ShiftWorld(1);
  1475         DrawVisualGears(2);
  1460         DrawVisualGears(2);
  1476         UnshiftWorld(1, flip);
  1461         UnshiftWorld();
  1477         end;
  1462         end;
  1478 
  1463 
  1479     DrawVisualGears(2);
  1464     DrawVisualGears(2);
  1480 
  1465 
  1481 // everything after this ResetDepth will be drawn at screen level (depth = 0)
  1466 // everything after this ResetDepth will be drawn at screen level (depth = 0)
  1482 // note: everything that needs to be readable should be on this level
  1467 // note: everything that needs to be readable should be on this level
  1483     ResetDepth(RM);
  1468     ResetDepth(RM);
  1484 
  1469 
  1485     if replicateToLeft then
  1470     if replicateToLeft then
  1486         begin
  1471         begin
  1487         ShiftWorld(-1, flip);
  1472         ShiftWorld(-1);
  1488         DrawVisualGears(3);
  1473         DrawVisualGears(3);
  1489         UnshiftWorld(-1, flip);
  1474         UnshiftWorld();
  1490         end;
  1475         end;
  1491 
  1476 
  1492     if replicateToRight then
  1477     if replicateToRight then
  1493         begin
  1478         begin
  1494         ShiftWorld(1, flip);
  1479         ShiftWorld(1);
  1495         DrawVisualGears(3);
  1480         DrawVisualGears(3);
  1496         UnshiftWorld(1, flip);
  1481         UnshiftWorld();
  1497         end;
  1482         end;
  1498 
  1483 
  1499     DrawVisualGears(3);
  1484     DrawVisualGears(3);
  1500 
  1485 
  1501 {$WARNINGS OFF}
  1486 {$WARNINGS OFF}
  1510             DrawSpriteRotatedF(sprTargetP, TargetPoint.X + WorldDx, TargetPoint.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360)
  1495             DrawSpriteRotatedF(sprTargetP, TargetPoint.X + WorldDx, TargetPoint.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360)
  1511         end
  1496         end
  1512     end;
  1497     end;
  1513 {$WARNINGS ON}
  1498 {$WARNINGS ON}
  1514 
  1499 
  1515 RenderWorldEdge(Lag);
  1500 RenderWorldEdge();
  1516 
  1501 
  1517 // this scale is used to keep the various widgets at the same dimension at all zoom levels
  1502 // this scale is used to keep the various widgets at the same dimension at all zoom levels
  1518 SetScale(cDefaultZoomLevel);
  1503 SetScale(cDefaultZoomLevel);
  1519 
  1504 
  1520 // Turn time
  1505 // Turn time
  1834                     DrawSprite(PosSprite, TargetCursorPoint.X - (SpritesData[PosSprite].Width shr 1), cScreenHeight - TargetCursorPoint.Y - (SpritesData[PosSprite].Height shr 1),i);
  1819                     DrawSprite(PosSprite, TargetCursorPoint.X - (SpritesData[PosSprite].Width shr 1), cScreenHeight - TargetCursorPoint.Y - (SpritesData[PosSprite].Height shr 1),i);
  1835                     Untint();
  1820                     Untint();
  1836                     end;
  1821                     end;
  1837                 end;
  1822                 end;
  1838         //DrawSprite(sprArrow, TargetCursorPoint.X, cScreenHeight - TargetCursorPoint.Y, (RealTicks shr 6) mod 8)
  1823         //DrawSprite(sprArrow, TargetCursorPoint.X, cScreenHeight - TargetCursorPoint.Y, (RealTicks shr 6) mod 8)
  1839         DrawTextureF(SpritesData[sprArrow].Texture, cDefaultZoomLevel / cScaleFactor, TargetCursorPoint.X + round(SpritesData[sprArrow].Width / cScaleFactor), cScreenHeight - TargetCursorPoint.Y + round(SpritesData[sprArrow].Height / cScaleFactor), (RealTicks shr 6) mod 8, 1, SpritesData[sprArrow].Width, SpritesData[sprArrow].Height);
  1824         DrawTextureF(SpritesData[sprArrow].Texture, cDefaultZoomLevel / cScaleFactor, TargetCursorPoint.X + round(SpritesData[sprArrow].Width / cScaleFactor), cScreenHeight + round(SpritesData[sprArrow].Height / cScaleFactor) - TargetCursorPoint.Y, (RealTicks shr 6) mod 8, 1, SpritesData[sprArrow].Width, SpritesData[sprArrow].Height);
  1840         end
  1825         end
  1841     end;
  1826     end;
  1842 
  1827 
  1843 // debug stuff
  1828 // debug stuff
  1844 if cViewLimitsDebug then
  1829 if cViewLimitsDebug then
  1874         end
  1859         end
  1875     else
  1860     else
  1876         begin
  1861         begin
  1877         if abs(prevPoint.X - WorldDx - hwRound(FollowGear^.X)) > rightX - leftX - 100 then
  1862         if abs(prevPoint.X - WorldDx - hwRound(FollowGear^.X)) > rightX - leftX - 100 then
  1878             begin
  1863             begin
  1879             if (prevPoint.X - WorldDx) * 2 < rightX + leftX then
  1864             if (prevPoint.X - WorldDx) * 2 < LongInt(rightX + leftX) then
  1880                 cameraJump:= rightX - leftX
  1865                 cameraJump:= rightX - leftX
  1881                 else
  1866                 else
  1882                 cameraJump:= leftX - rightX;
  1867                 cameraJump:= leftX - rightX;
  1883             WorldDx:= WorldDx - cameraJump;
  1868             WorldDx:= WorldDx - cameraJump;
  1884             end;
  1869             end;
  2054     else UndampenAudio();
  2039     else UndampenAudio();
  2055     end;
  2040     end;
  2056 end;
  2041 end;
  2057 
  2042 
  2058 procedure updateCursorVisibility;
  2043 procedure updateCursorVisibility;
  2059 begin       
  2044 begin
  2060     if isPaused or isAFK then
  2045     if isPaused or isAFK then
  2061         SDL_ShowCursor(1)
  2046         SDL_ShowCursor(1)
  2062     else
  2047     else
  2063         SDL_ShowCursor(ord(GameState = gsConfirm))
  2048         SDL_ShowCursor(ord(GameState = gsConfirm))
  2064 end;
  2049 end;
  2134     prevPoint.X:= 0;
  2119     prevPoint.X:= 0;
  2135     prevPoint.Y:= 0;
  2120     prevPoint.Y:= 0;
  2136     missionTimer:= 0;
  2121     missionTimer:= 0;
  2137     missionTex:= nil;
  2122     missionTex:= nil;
  2138     cOffsetY:= 0;
  2123     cOffsetY:= 0;
  2139     stereoDepth:= 0;
       
  2140     AMState:= AMHidden;
  2124     AMState:= AMHidden;
  2141     isFirstFrame:= true;
  2125     isFirstFrame:= true;
  2142 
  2126 
  2143     FillChar(WorldFade, sizeof(WorldFade), 0);
  2127     FillChar(WorldFade, sizeof(WorldFade), 0);
  2144     WorldFade[0].a:= 255;
  2128     WorldFade[0].a:= 255;