X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_gfx.pas;h=bd8d9ae5567495f7b857f9f3a77575c024d4596a;hb=a7daeef3855f07c8302a60ab31cb20ab74aefc45;hp=d3cc071ad5f4a0a4c1598884ad276bb2176ac699;hpb=6927c30da0ee60acd089fdbed9b1de52692060de;p=d2df-sdl.git diff --git a/src/game/g_gfx.pas b/src/game/g_gfx.pas index d3cc071..bd8d9ae 100644 --- a/src/game/g_gfx.pas +++ b/src/game/g_gfx.pas @@ -121,6 +121,8 @@ type procedure freeze (); inline; // remove velocities and acceleration procedure sleep (); inline; // switch to sleep mode + function checkAirStreams (): Boolean; // `true`: affected by air stream + function alive (): Boolean; inline; procedure die (); inline; procedure think (); inline; @@ -228,11 +230,50 @@ begin end; +// `true`: affected by air stream +function TParticle.checkAirStreams (): Boolean; +var + pan: TPanel; +begin + pan := g_Map_PanelAtPoint(x, y, GridTagLift); + result := (pan <> nil); + if result then + begin + if ((pan.PanelType and PANEL_LIFTUP) <> 0) then + begin + if (velY > -4-Random(3)) then velY -= 0.8; + if (abs(velX) > 0.1) then velX -= velX/10.0; + velX += (Random-Random)*0.2; + accelY := 0.15; + end + else if ((pan.PanelType and PANEL_LIFTLEFT) <> 0) then + begin + if (velX > -8-Random(3)) then velX -= 0.8; + accelY := 0.15; + end + else if ((pan.PanelType and PANEL_LIFTRIGHT) <> 0) then + begin + if (velX < 8+Random(3)) then velX += 0.8; + accelY := 0.15; + end + else + begin + result := false; + end; + // awake + if result and (state = TPartState.Sleeping) then state := TPartState.Normal; + end; +end; + + // switch to sleep mode procedure TParticle.sleep (); inline; begin - state := TPartState.Sleeping; - freeze(); + if not checkAirStreams() then + begin + state := TPartState.Sleeping; + freeze(); + end; end; @@ -317,20 +358,25 @@ end; procedure TParticle.think (); inline; + procedure awake (); + begin + state := TPartState.Normal; + floorY := Unknown; + ceilingY := Unknown; + wallEndY := Unknown; + if (velY = 0) then velY := 0.1; + if (accelY = 0) then accelY := 0.5; + end; + begin // awake sleeping particle, if necessary if awakeDirty then begin case state of TPartState.Sleeping, TPartState.Stuck: - if awmIsSet(x, y) then - begin - state := TPartState.Normal; - floorY := Unknown; - ceilingY := Unknown; - if (velY = 0) then velY := 0.1; - if (accelY = 0) then accelY := 0.5; - end; + if awmIsSet(x, y) then awake(); + else + if (env = TEnvType.EWall) and awmIsSet(x, y) then awake(); end; end; case particleType of @@ -380,41 +426,12 @@ procedure TParticle.thinkerBloodAndWater (); TPartType.Water: result := (Random(30) = 15); else raise Exception.Create('internal error in particle engine: drip'); end; - if result then begin velY := 0.5; accelY := 0.15; end; - end; - - // `true`: affected by air stream - function checkAirStreams (): Boolean; - var - pan: TPanel; - begin - pan := g_Map_PanelAtPoint(x, y, GridTagLift); - result := (pan <> nil); if result then begin - if ((pan.PanelType and PANEL_LIFTUP) <> 0) then - begin - if (velY > -4-Random(3)) then velY -= 0.8; - if (abs(velX) > 0.1) then velX -= velX/10.0; - velX += (Random-Random)*0.2; - accelY := 0.15; - end - else if ((pan.PanelType and PANEL_LIFTLEFT) <> 0) then - begin - if (velX > -8-Random(3)) then velX -= 0.8; - accelY := 0.15; - end - else if ((pan.PanelType and PANEL_LIFTRIGHT) <> 0) then - begin - if (velX < 8+Random(3)) then velX += 0.8; - accelY := 0.15; - end - else - begin - result := false; - end; - // awake - if result and (state = TPartState.Sleeping) then state := TPartState.Normal; + velY := 0.5; + accelY := 0.15; + // if we're falling from ceiling, switch to normal mode + if (state = TPartState.Stuck) and (stickDX = 0) then state := TPartState.Normal; end; end; @@ -429,7 +446,7 @@ procedure TParticle.thinkerBloodAndWater (); procedure applyGravity (inLiquid: Boolean); begin state := TPartState.Normal; - if (inLiquid) then + if inLiquid then begin velY := 0.5; accelY := 0.15; @@ -442,18 +459,20 @@ procedure TParticle.thinkerBloodAndWater (); end; label - _done; + _done, _gravityagain, _stuckagain; var pan: TPanel; dX, dY: SmallInt; ex, ey: Integer; + checkEnv: Boolean; + floorJustTraced: Boolean; begin if not gpart_dbg_phys_enabled then goto _done; if gAdvBlood then begin - // still check for air streams when sleeping - if (state = TPartState.Sleeping) then begin checkAirStreams(); goto _done; end; // so blood will dissolve + // still check for air streams when sleeping (no) + if (state = TPartState.Sleeping) then begin {checkAirStreams();} goto _done; end; // so blood will dissolve // process stuck particles if (state = TPartState.Stuck) then @@ -480,7 +499,14 @@ begin else begin // stuck to a wall - assert(wallEndY <> Unknown); + if (wallEndY = Unknown) then + begin + // this can happen if mplat was moved out; find new `wallEndY` + findFloor(true); // force trace, just in case + if (floorType = TFloorType.LiquidOut) then env := TEnvType.ELiquid else env := TEnvType.EAir; + mapGrid.traceOrthoRayWhileIn(ex, wallEndY, x+stickDX, y, x+stickDX, floorY+1, (GridTagWall or GridTagDoor or GridTagStep)); + end; + _stuckagain: // floor transition? if (wallEndY <= floorY) and (y >= floorY) then begin @@ -488,8 +514,15 @@ begin case floorType of TFloorType.Wall: // hit the ground begin - sleep(); - goto _done; // nothing to do anymore + // check if our ground wasn't moved since the last scan + findFloor(true); // force trace + if (y = floorY) then + begin + sleep(); + goto _done; // nothing to do anymore + end; + // otherwise, do it again + goto _stuckagain; end; TFloorType.LiquidIn: // entering the liquid begin @@ -524,17 +557,28 @@ begin dX := round(velX); dY := round(velY); + if (state = TPartState.Normal) then checkAirStreams(); + // gravity, if not stuck if (state <> TPartState.Stuck) and (abs(velX) < 0.1) and (abs(velY) < 0.1) then begin - if (floorY = Unknown) then findFloor(); + floorJustTraced := (floorY = Unknown); + if floorJustTraced then findFloor(); + _gravityagain: // floor transition? if (y = floorY) then begin case floorType of TFloorType.Wall: // hit the ground begin - // nothing to do + // check if our ground wasn't moved since the last scan + if not floorJustTraced then + begin + findFloor(true); // force trace + if (floorType = TFloorType.LiquidOut) then env := TEnvType.ELiquid else env := TEnvType.EAir; + if (y <> floorY) then goto _gravityagain; + end; + // otherwise, nothing to do end; TFloorType.LiquidIn: // entering the liquid begin @@ -562,15 +606,21 @@ begin begin // has some horizontal velocity pan := g_Map_traceToNearest(x, y, x+dX, y+dY, GridTagObstacle, @ex, @ey); - if (x <> ex) then begin floorY := Unknown; ceilingY := Unknown; end; // dunno yet + checkEnv := (x <> ex); x := ex; y := ey; + if checkEnv then + begin + // dunno yet + floorY := Unknown; + ceilingY := Unknown; + // check environment (air/liquid) + if (g_Map_PanelAtPoint(x, y, GridTagLiquid) <> nil) then env := TEnvType.ELiquid else env := TEnvType.EAir; + end; if (pan <> nil) then begin // we stuck // the only case when we can have both ceiling and wall is corner; stick to wall in this case - // check environment (air/liquid) - if (g_Map_PanelAtPoint(x, y, GridTagLiquid) <> nil) then env := TEnvType.ELiquid else env := TEnvType.EAir; // check if we stuck to a wall if (dX < 0) then dX := -1 else dX := 1; if (g_Map_PanelAtPoint(x+dX, y, GridTagObstacle) <> nil) then @@ -601,7 +651,9 @@ begin while (dY > 0) do begin // falling down - if (floorY = Unknown) then findFloor(); // need to do this anyway + floorJustTraced := (floorY = Unknown); + if floorJustTraced then findFloor(); + if (floorType = TFloorType.LiquidOut) then env := TEnvType.ELiquid else env := TEnvType.EAir; y += dY; //e_LogWritefln('floorY=%s; newy=%s; dY=%s; floorType=%s', [floorY, y, dY, floorType]); if (y >= floorY) then @@ -613,6 +665,15 @@ begin case floorType of TFloorType.Wall: // hit the ground begin + // check if our ground wasn't moved since the last scan + if not floorJustTraced then + begin + e_LogWritefln('force rescanning vpart at (%d,%d); floorY=%d', [x, y, floorY]); + findFloor(true); // force trace + e_LogWritefln(' rescanned vpart at (%d,%d); floorY=%d', [x, y, floorY]); + if (floorType = TFloorType.LiquidOut) then env := TEnvType.ELiquid else env := TEnvType.EAir; + if (y <> floorY) then continue; + end; // environment didn't changed hitAFloor(); break; // done with vertical movement @@ -670,16 +731,22 @@ _done: time += 1; if (liveTime <= 0) then begin die(); exit; end; ex := 255-trunc(255.0*time/liveTime); - if (ex >= 250) then begin die(); exit; end; - if (ex < 0) then ex := 0; + if (ex <= 10) then begin die(); exit; end; + if (ex > 250) then ex := 255; alpha := Byte(ex); end; end else begin - // water will disappear in water (?) - if (env = TEnvType.ELiquid) then die(); + // water will disappear in any liquid + if (env = TEnvType.ELiquid) then begin die(); exit; end; time += 1; + // dry water + if (liveTime <= 0) then begin die(); exit; end; + ex := 255-trunc(255.0*time/liveTime); + if (ex <= 10) then begin die(); exit; end; + if (ex > 250) then ex := 255; + alpha := Byte(ex); end; end; @@ -835,19 +902,19 @@ begin // check for level bounds if (x < g_Map_MinX) or (y < g_Map_MinY) or (x > g_Map_MaxX) or (y > g_Map_MaxY) then continue; - // in what environment we are starting in? - pan := g_Map_PanelAtPoint(x, y, (GridTagObstacle or GridTagLiquid)); - if (pan <> nil) then + // this hack will allow water spawned in water to fly out + // it can happen when player fell from a huge height (see "DOOM2D.WAD:\MAP03", for example) + if (fVelY >= 0) then begin - // either in a wall, or in a liquid - //if ((pan.tag and GridTagObstacle) <> 0) then continue; // don't spawn in walls - //env := TEnvType.ELiquid; - continue; + // in what environment we are starting in? + pan := g_Map_PanelAtPoint(x, y, (GridTagObstacle or GridTagLiquid)); end else begin - env := TEnvType.EAir; + pan := g_Map_PanelAtPoint(x, y, GridTagObstacle); end; + if (pan <> nil) then continue; + env := TEnvType.EAir; // color case color of @@ -1045,12 +1112,13 @@ begin if (dX <> 0) then begin // has some horizontal velocity - pan := g_Map_traceToNearest(x, y, x+dX, y+dY, GridTagObstacle, @ex, @ey); + pan := g_Map_traceToNearest(x, y, x+dX, y+dY, (GridTagObstacle or GridTagLiquid), @ex, @ey); if (x <> ex) then begin floorY := Unknown; ceilingY := Unknown; end; // dunno yet x := ex; y := ey; if (pan <> nil) then begin + if ((pan.tag and GridTagLiquid) <> 0) then begin die(); exit; end; // die in liquid // hit the wall; falling down vertically velX := 0; accelX := 0; @@ -1445,6 +1513,7 @@ end; procedure g_GFX_Draw (); var a, len: Integer; + scaled: Boolean; begin if not gpart_dbg_enabled then exit; @@ -1458,15 +1527,18 @@ begin glBegin(GL_POINTS); + scaled := (g_dbg_scale <> 1.0); + len := High(Particles); for a := 0 to len do begin with Particles[a] do begin - if alive and (x >= sX) and (y >= sY) and (x <= sX+sWidth) and (sY <= sY+sHeight) then + if not alive then continue; + if scaled or ((x >= sX) and (y >= sY) and (x <= sX+sWidth) and (sY <= sY+sHeight)) then begin glColor4ub(red, green, blue, alpha); - glVertex2i(x, y); + glVertex2f(x+0.37, y+0.37); end; end; end;