author | Grigory Ustinov <grenka@altlinux.org> |
Mon, 19 Nov 2018 19:02:48 +0300 | |
changeset 14262 | a6332977f396 |
parent 13800 | f26c9e931f5a |
child 15897 | d7b53d08ad9c |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10105
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uGame; |
22 |
interface |
|
23 |
||
371 | 24 |
procedure DoGameTick(Lag: LongInt); |
4 | 25 |
|
26 |
//////////////////// |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
27 |
implementation |
4 | 28 |
//////////////////// |
10116
dd27562b6f21
rolling back my PChar stuff, because unC0Rr improves string handling pas2c instead <3
sheepluva
parents:
10108
diff
changeset
|
29 |
uses uInputHandler, uTeams, uIO, uAI, uGears, uSound, uLocale, uCaptions, |
10128 | 30 |
uTypes, uVariables, uCommands, uConsts, uVisualGearsList, uUtils |
11532 | 31 |
{$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF}, uDebug; |
4 | 32 |
|
371 | 33 |
procedure DoGameTick(Lag: LongInt); |
11605 | 34 |
const maxCheckedGameDuration = 3*60*60*1000; |
8471
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
35 |
var i,j : LongInt; |
10127 | 36 |
s: ansistring; |
4 | 37 |
begin |
13800
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
38 |
|
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
39 |
inc(SoundTimerTicks, Lag); |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
40 |
if SoundTimerTicks >= 50 then |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
41 |
begin |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
42 |
SoundTimerTicks:= 0; |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
43 |
if cVolumeDelta <> 0 then |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
44 |
begin |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
45 |
j:= Volume; |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
46 |
i:= ChangeVolume(cVolumeDelta); |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
47 |
if (not cIsSoundEnabled) or (isAudioMuted and (j<>i)) then |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
48 |
AddCaption(trmsg[sidMute], capcolSetting, capgrpVolume) |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
49 |
else if not isAudioMuted then |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
50 |
begin |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
51 |
s:= ansistring(inttostr(i)); |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
52 |
AddCaption(FormatA(trmsg[sidVolume], s), capcolSetting, capgrpVolume) |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
53 |
end |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
54 |
end |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
55 |
else if cMuteToggle then |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
56 |
begin |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
57 |
MuteAudio; |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
58 |
if isAudioMuted then |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
59 |
AddCaption(trmsg[sidMute], capcolSetting, capgrpVolume) |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
60 |
else |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
61 |
begin |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
62 |
s:= ansistring(inttostr(GetVolumePercent())); |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
63 |
AddCaption(FormatA(trmsg[sidVolume], s), capcolSetting, capgrpVolume); |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
64 |
end; |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
65 |
cMuteToggle:= false; |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
66 |
end; |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
67 |
end; |
f26c9e931f5a
Allow to change volume during pause
Wuzzy <Wuzzy2@mail.ru>
parents:
13642
diff
changeset
|
68 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
69 |
if isPaused then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
70 |
exit; |
8472
da6b569ac930
- Collect synced packets to send within 1 second (cSendEmptyPacketTime) into buffer which is flushed each second.
unc0rr
parents:
8471
diff
changeset
|
71 |
|
1611 | 72 |
if (not CurrentTeam^.ExtDriven) then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2814
diff
changeset
|
73 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2814
diff
changeset
|
74 |
NetGetNextCmd; // its for the case of receiving "/say" message |
11532 | 75 |
if not allOK then exit; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2814
diff
changeset
|
76 |
isInLag:= false; |
8472
da6b569ac930
- Collect synced packets to send within 1 second (cSendEmptyPacketTime) into buffer which is flushed each second.
unc0rr
parents:
8471
diff
changeset
|
77 |
FlushMessages(Lag) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2814
diff
changeset
|
78 |
end; |
8472
da6b569ac930
- Collect synced packets to send within 1 second (cSendEmptyPacketTime) into buffer which is flushed each second.
unc0rr
parents:
8471
diff
changeset
|
79 |
|
7180 | 80 |
if GameType <> gmtRecord then |
81 |
begin |
|
82 |
if Lag > 100 then |
|
83 |
Lag:= 100 |
|
84 |
else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then |
|
85 |
Lag:= 2500; |
|
5130
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
4976
diff
changeset
|
86 |
|
9317
a04c30940d2d
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents:
9309
diff
changeset
|
87 |
if (GameType = gmtDemo) then |
7180 | 88 |
if isSpeed then |
8027
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7837
diff
changeset
|
89 |
begin |
7418 | 90 |
i:= RealTicks-SpeedStart; |
91 |
if i < 2000 then Lag:= Lag*5 |
|
92 |
else if i < 4000 then Lag:= Lag*10 |
|
93 |
else if i < 6000 then Lag:= Lag*20 |
|
94 |
else if i < 8000 then Lag:= Lag*40 |
|
95 |
else Lag:= Lag*80; |
|
8027
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7837
diff
changeset
|
96 |
end |
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7837
diff
changeset
|
97 |
else if cOnlyStats then |
11605 | 98 |
begin |
99 |
if GameTicks >= maxCheckedGameDuration then |
|
100 |
begin |
|
101 |
gameState:= gsExit; |
|
102 |
exit; |
|
103 |
end; |
|
104 |
||
105 |
Lag:= maxCheckedGameDuration + 60000; |
|
106 |
end; |
|
7180 | 107 |
end; |
10316 | 108 |
|
109 |
if cTestLua then |
|
110 |
Lag:= High(LongInt); |
|
111 |
||
5638
e35ba2a400d8
Try to avoid overlapping voices for major statements (not things like byebye or oof)
nemo
parents:
5357
diff
changeset
|
112 |
PlayNextVoice; |
89 | 113 |
i:= 1; |
11539 | 114 |
while (GameState <> gsExit) and (i <= Lag) and allOK do |
89 | 115 |
begin |
351 | 116 |
if not CurrentTeam^.ExtDriven then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
117 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
118 |
if CurrentHedgehog^.BotLevel <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
119 |
ProcessBot; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
120 |
ProcessGears; |
9651 | 121 |
{$IFDEF USE_TOUCH_INTERFACE}ProcessTouch;{$ENDIF} |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
122 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
123 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
124 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
125 |
NetGetNextCmd; |
11532 | 126 |
if not allOK then exit; |
127 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
128 |
if isInLag then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
129 |
case GameType of |
4075 | 130 |
gmtNet: begin |
10861
d84c725fe332
Also update wind indicator on lag when joining midgame
unc0rr
parents:
10316
diff
changeset
|
131 |
// update health bars and the wind indicator |
4075 | 132 |
AddVisualGear(0, 0, vgtTeamHealthSorter); |
10861
d84c725fe332
Also update wind indicator on lag when joining midgame
unc0rr
parents:
10316
diff
changeset
|
133 |
AddVisualGear(0, 0, vgtSmoothWindBar); |
4075 | 134 |
break; |
135 |
end; |
|
7386
e82a076df09b
Fix bug with isInLag picture displayed at end of some videos.
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
136 |
gmtDemo, gmtRecord: begin |
11026
b8022f4bea14
Put diagnostic message into log when quitting due to end of input in demo replay mode
unc0rr
parents:
10861
diff
changeset
|
137 |
AddFileLog('End of input, halting now'); |
4 | 138 |
GameState:= gsExit; |
139 |
exit |
|
72 | 140 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
141 |
gmtSave: begin |
72 | 142 |
RestoreTeamsFromSave; |
519 | 143 |
SetBinds(CurrentTeam^.Binds); |
7670
9485b88f6a44
Stop messages without possible desync on load from save
unc0rr
parents:
7447
diff
changeset
|
144 |
StopMessages(gmLeft or gmRight or gmUp or gmDown); |
7061 | 145 |
ResetSound; // restore previous sound state |
5809 | 146 |
PlayMusic; |
3902
3aac7ca07b0e
have Saves restart net when loaded, also resumes music
koda
parents:
3663
diff
changeset
|
147 |
GameType:= gmtLocal; |
4049
fe799b5d601b
fix issue 63 and draw health bars right away for savefiles
koda
parents:
4048
diff
changeset
|
148 |
AddVisualGear(0, 0, vgtTeamHealthSorter); |
5357
ec36f3d53f3c
Tiny optimization: convert smooth wind indicator change gear into visual gear
unc0rr
parents:
5174
diff
changeset
|
149 |
AddVisualGear(0, 0, vgtSmoothWindBar); |
4048 | 150 |
{$IFDEF IPHONEOS}InitIPC;{$ENDIF} |
10015 | 151 |
{$IFNDEF PAS2C} |
8204 | 152 |
with mobileRecord do |
153 |
if SaveLoadingEnded <> nil then |
|
154 |
SaveLoadingEnded(); |
|
8446
c18ba8726f5a
Fix sources so pas2c written in haskell could render them again
unc0rr
parents:
8330
diff
changeset
|
155 |
{$ENDIF} |
72 | 156 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
157 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
158 |
else ProcessGears |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
159 |
end; |
89 | 160 |
inc(i) |
162 | 161 |
end |
4 | 162 |
end; |
163 |
||
164 |
end. |