53 begin |
53 begin |
54 if isPaused = false then |
54 if isPaused = false then |
55 inc(RealTicks, Lag); |
55 inc(RealTicks, Lag); |
56 |
56 |
57 case GameState of |
57 case GameState of |
58 gsLandGen: begin |
58 gsLandGen: |
59 GenMap; |
59 begin |
60 ParseCommand('sendlanddigest', true); |
60 GenMap; |
61 GameState:= gsStart; |
61 ParseCommand('sendlanddigest', true); |
|
62 GameState:= gsStart; |
|
63 end; |
|
64 gsStart: |
|
65 begin |
|
66 if HasBorder then |
|
67 DisableSomeWeapons; |
|
68 AddClouds; |
|
69 AddFlakes; |
|
70 AssignHHCoords; |
|
71 AddMiscGears; |
|
72 StoreLoad; |
|
73 InitWorld; |
|
74 ResetKbd; |
|
75 SoundLoad; |
|
76 if GameType = gmtSave then |
|
77 begin |
|
78 isSEBackup:= isSoundEnabled; |
|
79 isSoundEnabled:= false |
62 end; |
80 end; |
63 gsStart: begin |
81 FinishProgress; |
64 if HasBorder then DisableSomeWeapons; |
82 PlayMusic; |
65 AddClouds; |
83 SetScale(zoom); |
66 AddFlakes; |
84 ScriptCall('onGameStart'); |
67 AssignHHCoords; |
85 GameState:= gsGame; |
68 AddMiscGears; |
86 end; |
69 StoreLoad; |
87 gsConfirm, gsGame: |
70 InitWorld; |
88 begin |
71 ResetKbd; |
89 DrawWorld(Lag); // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible |
72 SoundLoad; |
90 ProcessKbd; |
73 if GameType = gmtSave then |
91 if not isPaused then |
74 begin |
92 begin |
75 isSEBackup:= isSoundEnabled; |
93 DoGameTick(Lag); |
76 isSoundEnabled:= false |
94 ProcessVisualGears(Lag); |
77 end; |
|
78 FinishProgress; |
|
79 PlayMusic; |
|
80 SetScale(zoom); |
|
81 ScriptCall('onGameStart'); |
|
82 GameState:= gsGame; |
|
83 end; |
95 end; |
84 gsConfirm, |
96 end; |
85 gsGame: begin |
97 gsChat: |
86 DrawWorld(Lag); // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible |
98 begin |
87 ProcessKbd; |
99 DrawWorld(Lag); |
88 if not isPaused then |
100 if not isPaused then |
89 begin |
101 begin |
90 DoGameTick(Lag); |
102 DoGameTick(Lag); |
91 ProcessVisualGears(Lag); |
103 ProcessVisualGears(Lag); |
92 end; |
|
93 end; |
104 end; |
94 gsChat: begin |
105 end; |
95 DrawWorld(Lag); |
106 gsExit: |
96 if not isPaused then |
107 begin |
97 begin |
108 isTerminated:= true; |
98 DoGameTick(Lag); |
109 end; |
99 ProcessVisualGears(Lag); |
110 gsSuspend: |
100 end; |
111 exit; |
101 end; |
112 end; |
102 gsExit: begin |
|
103 isTerminated:= true; |
|
104 end; |
|
105 gsSuspend: exit; |
|
106 end; |
|
107 |
113 |
108 {$IFDEF SDL13} |
114 {$IFDEF SDL13} |
109 SDL_GL_SwapWindow(SDLwindow); |
115 SDL_GL_SwapWindow(SDLwindow); |
110 {$ELSE} |
116 {$ELSE} |
111 SDL_GL_SwapBuffers(); |
117 SDL_GL_SwapBuffers(); |
112 {$ENDIF} |
118 {$ENDIF} |
113 |
119 |
114 if flagMakeCapture then |
120 if flagMakeCapture then |
115 begin |
121 begin |
116 flagMakeCapture:= false; |
122 flagMakeCapture:= false; |
117 s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks); |
123 s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks); |
118 |
124 |
119 playSound(sndShutter); |
125 playSound(sndShutter); |
120 if MakeScreenshot(s) then WriteLnToConsole('Screenshot saved: ' + s) |
126 |
121 else begin |
127 if MakeScreenshot(s) then |
|
128 WriteLnToConsole('Screenshot saved: ' + s) |
|
129 else |
|
130 begin |
122 WriteLnToConsole('Screenshot failed.'); |
131 WriteLnToConsole('Screenshot failed.'); |
123 AddChatString(#5 + 'screen capture failed (lack of memory or write permissions)'); |
132 AddChatString(#5 + 'screen capture failed (lack of memory or write permissions)'); |
124 end |
133 end |
125 end; |
134 end; |
126 end; |
135 end; |
127 |
136 |
128 //////////////////// |
137 //////////////////// |
129 procedure OnDestroy; |
138 procedure OnDestroy; |
130 begin |
139 begin |
187 cNewScreenWidth:= max(2 * (event.window.data1 div 2), cMinScreenWidth); |
198 cNewScreenWidth:= max(2 * (event.window.data1 div 2), cMinScreenWidth); |
188 cNewScreenHeight:= max(2 * (event.window.data2 div 2), cMinScreenHeight); |
199 cNewScreenHeight:= max(2 * (event.window.data2 div 2), cMinScreenHeight); |
189 cScreenResizeDelay:= RealTicks+500; |
200 cScreenResizeDelay:= RealTicks+500; |
190 *) |
201 *) |
191 end; |
202 end; |
192 SDL_FINGERMOTION: onTouchMotion(event.tfinger.x, event.tfinger.y,event.tfinger.dx, event.tfinger.dy, event.tfinger.fingerId); |
203 |
193 SDL_FINGERDOWN: onTouchDown(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId); |
204 SDL_FINGERMOTION: |
194 SDL_FINGERUP: onTouchUp(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId); |
205 onTouchMotion(event.tfinger.x, event.tfinger.y,event.tfinger.dx, event.tfinger.dy, event.tfinger.fingerId); |
|
206 |
|
207 SDL_FINGERDOWN: |
|
208 onTouchDown(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId); |
|
209 |
|
210 SDL_FINGERUP: |
|
211 onTouchUp(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId); |
195 {$ELSE} |
212 {$ELSE} |
196 SDL_KEYDOWN: if GameState = gsChat then |
213 SDL_KEYDOWN: |
197 KeyPressChat(event.key.keysym.unicode); |
214 if GameState = gsChat then |
198 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then wheelDown:= true; |
215 KeyPressChat(event.key.keysym.unicode); |
199 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then wheelUp:= true; |
216 |
|
217 SDL_MOUSEBUTTONDOWN: |
|
218 if event.button.button = SDL_BUTTON_WHEELDOWN then |
|
219 wheelDown:= true; |
|
220 |
|
221 SDL_MOUSEBUTTONUP: |
|
222 if event.button.button = SDL_BUTTON_WHEELUP then |
|
223 wheelUp:= true; |
|
224 |
200 SDL_ACTIVEEVENT: |
225 SDL_ACTIVEEVENT: |
201 if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
226 if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
202 begin |
227 begin |
203 prevFocusState:= cHasFocus; |
228 prevFocusState:= cHasFocus; |
204 cHasFocus:= event.active.gain = 1; |
229 cHasFocus:= event.active.gain = 1; |
205 if prevFocusState xor cHasFocus then |
230 if prevFocusState xor cHasFocus then |
206 onFocusStateChanged() |
231 onFocusStateChanged() |
207 end; |
232 end; |
208 SDL_VIDEORESIZE: begin |
233 |
|
234 SDL_VIDEORESIZE: |
|
235 begin |
209 // using lower values than cMinScreenWidth or cMinScreenHeight causes widget overlap and off-screen widget parts |
236 // using lower values than cMinScreenWidth or cMinScreenHeight causes widget overlap and off-screen widget parts |
210 // Change by sheepluva: |
237 // Change by sheepluva: |
211 // Let's only use even numbers for custom width/height since I ran into scaling issues with odd width values. |
238 // Let's only use even numbers for custom width/height since I ran into scaling issues with odd width values. |
212 // Maybe just fixes the symptom not the actual cause(?), I'm too tired to find out :P |
239 // Maybe just fixes the symptom not the actual cause(?), I'm too tired to find out :P |
213 cNewScreenWidth:= max(2 * (event.resize.w div 2), cMinScreenWidth); |
240 cNewScreenWidth:= max(2 * (event.resize.w div 2), cMinScreenWidth); |
214 cNewScreenHeight:= max(2 * (event.resize.h div 2), cMinScreenHeight); |
241 cNewScreenHeight:= max(2 * (event.resize.h div 2), cMinScreenHeight); |
215 cScreenResizeDelay:= RealTicks+500; |
242 cScreenResizeDelay:= RealTicks+500; |
216 end; |
243 end; |
217 {$ENDIF} |
244 {$ENDIF} |
218 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
245 SDL_JOYAXISMOTION: |
219 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
246 ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
220 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
247 SDL_JOYHATMOTION: |
221 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
248 ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
222 SDL_QUITEV: isTerminated:= true |
249 SDL_JOYBUTTONDOWN: |
223 end; //end case event.type_ of |
250 ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
224 end; //end while SDL_PollEvent(@event) <> 0 do |
251 SDL_JOYBUTTONUP: |
225 |
252 ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
226 if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) and ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then |
253 SDL_QUITEV: |
|
254 isTerminated:= true |
|
255 end; //end case event.type_ of |
|
256 end; //end while SDL_PollEvent(@event) <> 0 do |
|
257 |
|
258 if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) |
|
259 and ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then |
227 begin |
260 begin |
228 cScreenResizeDelay:= 0; |
261 cScreenResizeDelay:= 0; |
229 cScreenWidth:= cNewScreenWidth; |
262 cScreenWidth:= cNewScreenWidth; |
230 cScreenHeight:= cNewScreenHeight; |
263 cScreenHeight:= cNewScreenHeight; |
231 |
264 |
263 val(gameArgs[0], ipcPort); |
297 val(gameArgs[0], ipcPort); |
264 val(gameArgs[1], cScreenWidth); |
298 val(gameArgs[1], cScreenWidth); |
265 val(gameArgs[2], cScreenHeight); |
299 val(gameArgs[2], cScreenHeight); |
266 val(gameArgs[3], cReducedQuality); |
300 val(gameArgs[3], cReducedQuality); |
267 cLocaleFName:= gameArgs[4]; |
301 cLocaleFName:= gameArgs[4]; |
268 if (Length(cLocaleFName) > 6) then cLocale := Copy(cLocaleFName,1,5) |
302 |
269 else cLocale := Copy(cLocaleFName,1,2); |
303 if (Length(cLocaleFName) > 6) then |
|
304 cLocale := Copy(cLocaleFName,1,5) |
|
305 else |
|
306 cLocale := Copy(cLocaleFName,1,2); |
|
307 |
270 UserNick:= gameArgs[5]; |
308 UserNick:= gameArgs[5]; |
271 isSoundEnabled:= gameArgs[6] = '1'; |
309 isSoundEnabled:= gameArgs[6] = '1'; |
272 isMusicEnabled:= gameArgs[7] = '1'; |
310 isMusicEnabled:= gameArgs[7] = '1'; |
273 cAltDamage:= gameArgs[8] = '1'; |
311 cAltDamage:= gameArgs[8] = '1'; |
274 PathPrefix:= gameArgs[9]; |
312 PathPrefix:= gameArgs[9]; |
283 |
321 |
284 initEverything(true); |
322 initEverything(true); |
285 WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
323 WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
286 AddFileLog('Prefix: "' + PathPrefix +'"'); |
324 AddFileLog('Prefix: "' + PathPrefix +'"'); |
287 AddFileLog('UserPrefix: "' + UserPathPrefix +'"'); |
325 AddFileLog('UserPrefix: "' + UserPathPrefix +'"'); |
|
326 |
288 for i:= 0 to ParamCount do |
327 for i:= 0 to ParamCount do |
289 AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
328 AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
290 |
329 |
291 for p:= Succ(Low(TPathType)) to High(TPathType) do |
330 for p:= Succ(Low(TPathType)) to High(TPathType) do |
292 if (p <> ptMapCurrent) and (p <> ptData) then UserPathz[p]:= UserPathPrefix + '/Data/' + Pathz[p]; |
331 if (p <> ptMapCurrent) and (p <> ptData) then |
|
332 UserPathz[p]:= UserPathPrefix + '/Data/' + Pathz[p]; |
293 |
333 |
294 UserPathz[ptData]:= UserPathPrefix + '/Data'; |
334 UserPathz[ptData]:= UserPathPrefix + '/Data'; |
295 |
335 |
296 for p:= Succ(Low(TPathType)) to High(TPathType) do |
336 for p:= Succ(Low(TPathType)) to High(TPathType) do |
297 if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]; |
337 if p <> ptMapCurrent then |
|
338 Pathz[p]:= PathPrefix + '/' + Pathz[p]; |
298 |
339 |
299 WriteToConsole('Init SDL... '); |
340 WriteToConsole('Init SDL... '); |
300 SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, true); |
341 SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, true); |
301 WriteLnToConsole(msgOK); |
342 WriteLnToConsole(msgOK); |
302 |
343 |
527 //////////////////////////////////////////////////////////////////////////////// |
576 //////////////////////////////////////////////////////////////////////////////// |
528 /////////////////////////////// m a i n //////////////////////////////////////// |
577 /////////////////////////////// m a i n //////////////////////////////////////// |
529 //////////////////////////////////////////////////////////////////////////////// |
578 //////////////////////////////////////////////////////////////////////////////// |
530 begin |
579 begin |
531 GetParams(); |
580 GetParams(); |
532 if (Length(cLocaleFName) > 6) then cLocale := Copy(cLocaleFName,1,5) |
581 if (Length(cLocaleFName) > 6) then |
533 else cLocale := Copy(cLocaleFName,1,2); |
582 cLocale := Copy(cLocaleFName,1,5) |
534 |
583 else |
535 if GameType = gmtLandPreview then GenLandPreview() |
584 cLocale := Copy(cLocaleFName,1,2); |
536 else if GameType = gmtSyntax then DisplayUsage() |
585 |
|
586 if GameType = gmtLandPreview then |
|
587 GenLandPreview() |
|
588 else if GameType = gmtSyntax then |
|
589 DisplayUsage() |
537 else Game(); |
590 else Game(); |
538 |
591 |
539 // return 1 when engine is not called correctly |
592 // return 1 when engine is not called correctly |
540 ExitCode:= LongInt(GameType = gmtSyntax); |
593 ExitCode:= LongInt(GameType = gmtSyntax); |
541 {$ENDIF} |
594 {$ENDIF} |