153 ControllerClose(); |
151 ControllerClose(); |
154 SendKB(); |
152 SendKB(); |
155 CloseIPC(); |
153 CloseIPC(); |
156 TTF_Quit(); |
154 TTF_Quit(); |
157 SDL_Quit(); |
155 SDL_Quit(); |
158 {$IFDEF IPHONEOS} |
156 exit(); |
159 IPH_returnFrontend(); |
|
160 {$ELSE} |
|
161 halt(); |
|
162 {$ENDIF} |
|
163 end; |
157 end; |
164 |
158 |
165 /////////////////// |
159 /////////////////// |
166 procedure MainLoop; |
160 procedure MainLoop; |
167 var PrevTime, |
161 var PrevTime, |
168 CurrTime: Longword; |
162 CurrTime: Longword; |
169 event: TSDL_Event; |
163 event: TSDL_Event; |
170 {$IFDEF TOUCHINPUT} |
164 begin |
171 //var tiltValue: LongInt; |
165 |
172 {$ENDIF} |
166 PrevTime:= SDL_GetTicks; |
173 begin |
167 repeat |
174 PrevTime:= SDL_GetTicks; |
168 {$IFNDEF IPHONEOS} |
175 repeat |
169 // have to remove this cycle because otherwise it segfaults at exit |
176 while SDL_PollEvent(@event) <> 0 do |
170 while SDL_PollEvent(@event) <> 0 do |
177 case event.type_ of |
171 begin |
|
172 case event.type_ of |
|
173 SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); |
178 {$IFDEF SDL13} |
174 {$IFDEF SDL13} |
179 SDL_WINDOWEVENT: |
175 SDL_WINDOWEVENT: |
180 {$ELSE} |
176 {$ELSE} |
181 SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); |
177 SDL_ACTIVEEVENT: |
182 SDL_ACTIVEEVENT: |
178 {$ENDIF} |
183 {$ENDIF} |
179 if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
184 if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
180 cHasFocus:= event.active.gain = 1; |
185 cHasFocus:= event.active.gain = 1; |
181 //SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450)); |
186 //SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450)); |
182 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true; |
|
183 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true; |
|
184 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
|
185 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
|
186 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
|
187 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
|
188 SDL_QUITEV: isTerminated:= true |
|
189 end; // end case event.type_ of |
|
190 end; // end while SDL_PollEvent(@event) <> 0 do |
|
191 {$ENDIF} |
|
192 CurrTime:= SDL_GetTicks; |
|
193 if PrevTime + cTimerInterval <= CurrTime then |
|
194 begin |
|
195 DoTimer(CurrTime - PrevTime); |
|
196 PrevTime:= CurrTime |
|
197 end else SDL_Delay(1); |
|
198 if isTerminated = false then IPCCheckSock(); |
|
199 until isTerminated; |
|
200 |
|
201 exit(); |
|
202 end; |
|
203 |
|
204 ///////////////////////// |
|
205 procedure ShowMainWindow; |
|
206 begin |
|
207 if cFullScreen then ParseCommand('fullscr 1', true) |
|
208 else ParseCommand('fullscr 0', true); |
|
209 SDL_ShowCursor(0) |
|
210 end; |
|
211 |
|
212 /////////////// |
|
213 procedure Game;{$IFDEF IPHONEOS}cdecl; export;{$ENDIF} |
|
214 var p: TPathType; |
|
215 s: shortstring; |
|
216 begin |
187 {$IFDEF IPHONEOS} |
217 {$IFDEF IPHONEOS} |
188 (* SDL_JOYAXISMOTION: begin |
218 Randomize; |
189 {* axis 0 = left and right; |
219 |
190 axis 1 = up and down; |
220 val('320', cScreenWidth); |
191 axis 2 = back and forth; *} |
221 val('480', cScreenHeight); |
192 |
222 cInitWidth:= cScreenWidth; |
193 WriteLnToConsole('********************************************* accelerometer'); |
223 cInitHeight:= cScreenHeight; |
194 |
224 cBitsStr:= '16'; |
195 tiltValue:= SDL_JoystickGetAxis(uKeys.theJoystick, 0); |
225 val(cBitsStr, cBits); |
196 |
226 val('51432', ipcPort); |
197 if (CurrentTeam <> nil) then |
227 cFullScreen:= true; |
198 begin |
228 isSoundEnabled:= false; |
199 {$IFDEF DEBUGFILE} |
229 cVSyncInUse:= true; |
200 AddFileLog('Joystick: 0; Axis: 0; Value: ' + inttostr(tiltValue)); |
230 cLocaleFName:= 'en.txt'; |
201 {$ENDIF} |
231 val('100', cInitVolume); |
202 if tiltValue > 1500 then |
232 val('8', cTimerInterval); |
203 begin |
233 PathPrefix:= 'Data'; |
204 uKeys.rightKey:= true; |
234 cShowFPS:= true; |
205 uKeys.isWalking:= true; |
235 cAltDamage:= false; |
206 end |
236 UserNick:= 'Koda'; //DecodeBase64(ParamStr(15)); |
207 else |
237 isMusicEnabled:= false; |
208 if tiltValue <= -1500 then |
238 cReducedQuality:= false; |
209 begin |
239 {$ENDIF} |
210 uKeys.leftKey:= true; |
240 |
211 uKeys.isWalking:= true; |
241 for p:= Succ(Low(TPathType)) to High(TPathType) do |
212 end |
242 if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]; |
213 else |
243 |
214 if (tiltValue > -1500) and (tiltValue <= 1500) and (movedbybuttons = false) then uKeys.isWalking:= false; |
244 WriteToConsole('Init SDL... '); |
215 end; |
245 SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); |
216 end;*) |
246 WriteLnToConsole(msgOK); |
217 {$ELSE} |
247 |
218 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true; |
248 SDL_EnableUNICODE(1); |
219 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true; |
249 |
220 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
250 WriteToConsole('Init SDL_ttf... '); |
221 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
251 SDLTry(TTF_Init <> -1, true); |
222 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
252 WriteLnToConsole(msgOK); |
223 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
253 |
224 {$ENDIF} |
254 ShowMainWindow; |
225 SDL_QUITEV: isTerminated:= true |
255 |
226 end; |
256 AddProgress; |
227 |
257 |
228 CurrTime:= SDL_GetTicks; |
258 ControllerInit; // has to happen before InitKbdKeyTable to map keys |
229 if PrevTime + cTimerInterval <= CurrTime then |
259 InitKbdKeyTable; |
230 begin |
260 |
231 DoTimer(CurrTime - PrevTime); |
261 if recordFileName = '' then |
232 PrevTime:= CurrTime |
262 InitIPC; |
233 end else SDL_Delay(1); |
263 WriteLnToConsole(msgGettingConfig); |
234 IPCCheckSock |
264 |
235 until isTerminated |
265 if cLocaleFName <> 'en.txt' then |
236 |
266 LoadLocale(Pathz[ptLocale] + '/en.txt'); |
|
267 LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
|
268 |
|
269 if recordFileName = '' then |
|
270 SendIPCAndWaitReply('C') // ask for game config |
|
271 else |
|
272 LoadRecordFromFile(recordFileName); |
|
273 |
|
274 s:= 'eproto ' + inttostr(cNetProtoVersion); |
|
275 SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
|
276 |
|
277 InitTeams; |
|
278 AssignStores; |
|
279 |
|
280 if isSoundEnabled then |
|
281 InitSound; |
|
282 |
|
283 isDeveloperMode:= false; |
|
284 |
|
285 TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
|
286 |
|
287 MainLoop(); |
|
288 OnDestroy(); |
|
289 exit(); |
|
290 end; |
|
291 |
|
292 {$IFNDEF IPHONEOS} |
|
293 ///////////////////////// |
|
294 procedure GenLandPreview; |
|
295 var Preview: TPreview; |
|
296 h: byte; |
|
297 begin |
|
298 InitIPC; |
|
299 IPCWaitPongEvent; |
|
300 TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
|
301 |
|
302 Preview:= GenPreview; |
|
303 WriteLnToConsole('Sending preview...'); |
|
304 SendIPCRaw(@Preview, sizeof(Preview)); |
|
305 h:= MaxHedgehogs; |
|
306 SendIPCRaw(@h, sizeof(h)); |
|
307 WriteLnToConsole('Preview sent, disconnect'); |
|
308 CloseIPC(); |
|
309 end; |
|
310 |
|
311 //////////////////////////////// |
|
312 procedure Resize(w, h: LongInt); |
|
313 begin |
|
314 cScreenWidth:= w; |
|
315 cScreenHeight:= h; |
|
316 if cFullScreen then |
|
317 ParseCommand('/fullscr 1', true) |
|
318 else |
|
319 ParseCommand('/fullscr 0', true); |
237 end; |
320 end; |
238 |
321 |
239 ///////////////////// |
322 ///////////////////// |
240 procedure DisplayUsage; |
323 procedure DisplayUsage; |
241 var i: LongInt; |
324 var i: LongInt; |
265 i: LongInt; |
349 i: LongInt; |
266 {$ENDIF} |
350 {$ENDIF} |
267 p: TPathType; |
351 p: TPathType; |
268 begin |
352 begin |
269 |
353 |
270 case ParamCount of |
354 case ParamCount of |
271 17: begin |
355 17: begin |
272 val(ParamStr(2), cScreenWidth); |
356 val(ParamStr(2), cScreenWidth); |
273 val(ParamStr(3), cScreenHeight); |
357 val(ParamStr(3), cScreenHeight); |
274 cInitWidth:= cScreenWidth; |
|
275 cInitHeight:= cScreenHeight; |
|
276 cBitsStr:= ParamStr(4); |
|
277 val(cBitsStr, cBits); |
|
278 val(ParamStr(5), ipcPort); |
|
279 cFullScreen:= ParamStr(6) = '1'; |
|
280 isSoundEnabled:= ParamStr(7) = '1'; |
|
281 cVSyncInUse:= ParamStr(8) = '1'; |
|
282 cLocaleFName:= ParamStr(9); |
|
283 val(ParamStr(10), cInitVolume); |
|
284 val(ParamStr(11), cTimerInterval); |
|
285 PathPrefix:= ParamStr(12); |
|
286 cShowFPS:= ParamStr(13) = '1'; |
|
287 cAltDamage:= ParamStr(14) = '1'; |
|
288 UserNick:= DecodeBase64(ParamStr(15)); |
|
289 isMusicEnabled:= ParamStr(16) = '1'; |
|
290 cReducedQuality:= ParamStr(17) = '1'; |
|
291 for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
292 if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
293 end; |
|
294 {$IFDEF IPHONEOS} |
|
295 0: begin |
|
296 PathPrefix:= 'Data'; |
|
297 recordFileName:= 'save.hws'; |
|
298 val('320', cScreenWidth); |
|
299 val('480', cScreenHeight); |
|
300 cInitWidth:= cScreenWidth; |
|
301 cInitHeight:= cScreenHeight; |
|
302 cBitsStr:= '32'; |
|
303 val(cBitsStr, cBits); |
|
304 val('100', cInitVolume); |
|
305 isMusicEnabled:= false; |
|
306 isSoundEnabled:= false; |
|
307 cLocaleFName:= 'en.txt'; |
|
308 cFullScreen:= true; //T or F is is the same here |
|
309 cAltDamage:= false; |
|
310 cShowFPS:= true; |
|
311 val('8', cTimerInterval); |
|
312 cReducedQuality:= false; |
|
313 |
|
314 for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
315 if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
316 end; |
|
317 {$ENDIF} |
|
318 3: begin |
|
319 val(ParamStr(2), ipcPort); |
|
320 GameType:= gmtLandPreview; |
|
321 if ParamStr(3) <> 'landpreview' then OutError(errmsgShouldntRun, true); |
|
322 end; |
|
323 2: begin |
|
324 PathPrefix:= ParamStr(1); |
|
325 recordFileName:= ParamStr(2); |
|
326 |
|
327 for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
328 if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
329 end; |
|
330 6: begin |
|
331 PathPrefix:= ParamStr(1); |
|
332 recordFileName:= ParamStr(2); |
|
333 |
|
334 if ParamStr(3) = '--set-video' then |
|
335 begin |
|
336 val(ParamStr(4), cScreenWidth); |
|
337 val(ParamStr(5), cScreenHeight); |
|
338 cInitWidth:= cScreenWidth; |
358 cInitWidth:= cScreenWidth; |
339 cInitHeight:= cScreenHeight; |
359 cInitHeight:= cScreenHeight; |
340 cBitsStr:= ParamStr(6); |
360 cBitsStr:= ParamStr(4); |
341 val(cBitsStr, cBits); |
361 val(cBitsStr, cBits); |
342 end |
362 val(ParamStr(5), ipcPort); |
343 else |
363 cFullScreen:= ParamStr(6) = '1'; |
344 begin |
364 isSoundEnabled:= ParamStr(7) = '1'; |
345 if ParamStr(3) = '--set-audio' then |
365 cVSyncInUse:= ParamStr(8) = '1'; |
|
366 cLocaleFName:= ParamStr(9); |
|
367 val(ParamStr(10), cInitVolume); |
|
368 val(ParamStr(11), cTimerInterval); |
|
369 PathPrefix:= ParamStr(12); |
|
370 cShowFPS:= ParamStr(13) = '1'; |
|
371 cAltDamage:= ParamStr(14) = '1'; |
|
372 UserNick:= DecodeBase64(ParamStr(15)); |
|
373 isMusicEnabled:= ParamStr(16) = '1'; |
|
374 cReducedQuality:= ParamStr(17) = '1'; |
|
375 end; |
|
376 3: begin |
|
377 val(ParamStr(2), ipcPort); |
|
378 GameType:= gmtLandPreview; |
|
379 if ParamStr(3) <> 'landpreview' then |
|
380 OutError(errmsgShouldntRun, true); |
|
381 end; |
|
382 2: begin |
|
383 PathPrefix:= ParamStr(1); |
|
384 recordFileName:= ParamStr(2); |
|
385 end; |
|
386 6: begin |
|
387 PathPrefix:= ParamStr(1); |
|
388 recordFileName:= ParamStr(2); |
|
389 |
|
390 if ParamStr(3) = '--set-video' then |
346 begin |
391 begin |
347 val(ParamStr(4), cInitVolume); |
392 val(ParamStr(4), cScreenWidth); |
348 isMusicEnabled:= ParamStr(5) = '1'; |
393 val(ParamStr(5), cScreenHeight); |
349 isSoundEnabled:= ParamStr(6) = '1'; |
394 cInitWidth:= cScreenWidth; |
|
395 cInitHeight:= cScreenHeight; |
|
396 cBitsStr:= ParamStr(6); |
|
397 val(cBitsStr, cBits); |
350 end |
398 end |
351 else |
399 else |
352 begin |
400 begin |
353 if ParamStr(3) = '--set-other' then |
401 if ParamStr(3) = '--set-audio' then |
354 begin |
402 begin |
355 cLocaleFName:= ParamStr(4); |
403 val(ParamStr(4), cInitVolume); |
356 cFullScreen:= ParamStr(5) = '1'; |
404 isMusicEnabled:= ParamStr(5) = '1'; |
357 cShowFPS:= ParamStr(6) = '1'; |
405 isSoundEnabled:= ParamStr(6) = '1'; |
358 end |
406 end |
359 else DisplayUsage; |
407 else |
|
408 begin |
|
409 if ParamStr(3) = '--set-other' then |
|
410 begin |
|
411 cLocaleFName:= ParamStr(4); |
|
412 cFullScreen:= ParamStr(5) = '1'; |
|
413 cShowFPS:= ParamStr(6) = '1'; |
|
414 end |
|
415 else DisplayUsage; |
|
416 end |
|
417 end; |
|
418 end; |
|
419 11: begin |
|
420 PathPrefix:= ParamStr(1); |
|
421 recordFileName:= ParamStr(2); |
|
422 |
|
423 if ParamStr(3) = '--set-multimedia' then |
|
424 begin |
|
425 val(ParamStr(4), cScreenWidth); |
|
426 val(ParamStr(5), cScreenHeight); |
|
427 cInitWidth:= cScreenWidth; |
|
428 cInitHeight:= cScreenHeight; |
|
429 cBitsStr:= ParamStr(6); |
|
430 val(cBitsStr, cBits); |
|
431 val(ParamStr(7), cInitVolume); |
|
432 isMusicEnabled:= ParamStr(8) = '1'; |
|
433 isSoundEnabled:= ParamStr(9) = '1'; |
|
434 cLocaleFName:= ParamStr(10); |
|
435 cFullScreen:= ParamStr(11) = '1'; |
360 end |
436 end |
361 end; |
437 else DisplayUsage; |
362 |
438 end; |
363 for p:= Succ(Low(TPathType)) to High(TPathType) do |
439 15: begin |
364 if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
440 PathPrefix:= ParamStr(1); |
|
441 recordFileName:= ParamStr(2); |
|
442 if ParamStr(3) = '--set-everything' then |
|
443 begin |
|
444 val(ParamStr(4), cScreenWidth); |
|
445 val(ParamStr(5), cScreenHeight); |
|
446 cInitWidth:= cScreenWidth; |
|
447 cInitHeight:= cScreenHeight; |
|
448 cBitsStr:= ParamStr(6); |
|
449 val(cBitsStr, cBits); |
|
450 val(ParamStr(7), cInitVolume); |
|
451 isMusicEnabled:= ParamStr(8) = '1'; |
|
452 isSoundEnabled:= ParamStr(9) = '1'; |
|
453 cLocaleFName:= ParamStr(10); |
|
454 cFullScreen:= ParamStr(11) = '1'; |
|
455 cAltDamage:= ParamStr(12) = '1'; |
|
456 cShowFPS:= ParamStr(13) = '1'; |
|
457 val(ParamStr(14), cTimerInterval); |
|
458 cReducedQuality:= ParamStr(15) = '1'; |
|
459 end |
|
460 else DisplayUsage; |
|
461 end; |
|
462 else DisplayUsage; |
365 end; |
463 end; |
366 11: begin |
|
367 PathPrefix:= ParamStr(1); |
|
368 recordFileName:= ParamStr(2); |
|
369 |
|
370 if ParamStr(3) = '--set-multimedia' then |
|
371 begin |
|
372 val(ParamStr(4), cScreenWidth); |
|
373 val(ParamStr(5), cScreenHeight); |
|
374 cInitWidth:= cScreenWidth; |
|
375 cInitHeight:= cScreenHeight; |
|
376 cBitsStr:= ParamStr(6); |
|
377 val(cBitsStr, cBits); |
|
378 val(ParamStr(7), cInitVolume); |
|
379 isMusicEnabled:= ParamStr(8) = '1'; |
|
380 isSoundEnabled:= ParamStr(9) = '1'; |
|
381 cLocaleFName:= ParamStr(10); |
|
382 cFullScreen:= ParamStr(11) = '1'; |
|
383 end |
|
384 else DisplayUsage; |
|
385 |
|
386 for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
387 if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
388 end; |
|
389 15: begin |
|
390 PathPrefix:= ParamStr(1); |
|
391 recordFileName:= ParamStr(2); |
|
392 if ParamStr(3) = '--set-everything' then |
|
393 begin |
|
394 val(ParamStr(4), cScreenWidth); |
|
395 val(ParamStr(5), cScreenHeight); |
|
396 cInitWidth:= cScreenWidth; |
|
397 cInitHeight:= cScreenHeight; |
|
398 cBitsStr:= ParamStr(6); |
|
399 val(cBitsStr, cBits); |
|
400 val(ParamStr(7), cInitVolume); |
|
401 isMusicEnabled:= ParamStr(8) = '1'; |
|
402 isSoundEnabled:= ParamStr(9) = '1'; |
|
403 cLocaleFName:= ParamStr(10); |
|
404 cFullScreen:= ParamStr(11) = '1'; |
|
405 cAltDamage:= ParamStr(12) = '1'; |
|
406 cShowFPS:= ParamStr(13) = '1'; |
|
407 val(ParamStr(14), cTimerInterval); |
|
408 cReducedQuality:= ParamStr(15) = '1'; |
|
409 end |
|
410 else DisplayUsage; |
|
411 |
|
412 for p:= Succ(Low(TPathType)) to High(TPathType) do |
|
413 if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p] |
|
414 end; |
|
415 else DisplayUsage; |
|
416 end; |
|
417 |
464 |
418 {$IFDEF DEBUGFILE} |
465 {$IFDEF DEBUGFILE} |
419 AddFileLog('Prefix: "' + PathPrefix +'"'); |
466 AddFileLog('Prefix: "' + PathPrefix +'"'); |
420 for i:= 0 to ParamCount do |
467 for i:= 0 to ParamCount do |
421 AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
468 AddFileLog(inttostr(i) + ': ' + ParamStr(i)); |
422 {$IFDEF IPHONEOS} |
469 {$IFDEF IPHONEOS} |
423 WriteLnToConsole('Saving debug file at: ' + IPH_getDocumentsPath()); |
470 WriteLnToConsole('Saving debug file at: ' + IPH_getDocumentsPath()); |
424 {$ENDIF} |
471 {$ENDIF} |
425 {$ENDIF} |
472 {$ENDIF} |
426 end; |
473 end; |
427 |
|
428 ///////////////////////// |
|
429 procedure ShowMainWindow; |
|
430 begin |
|
431 if cFullScreen then ParseCommand('fullscr 1', true) |
|
432 else ParseCommand('fullscr 0', true); |
|
433 SDL_ShowCursor(0) |
|
434 end; |
|
435 |
|
436 /////////////// |
|
437 procedure Game; |
|
438 var s: shortstring; |
|
439 begin |
|
440 WriteToConsole('Init SDL... '); |
|
441 SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); |
|
442 WriteLnToConsole(msgOK); |
|
443 |
|
444 SDL_EnableUNICODE(1); |
|
445 |
|
446 WriteToConsole('Init SDL_ttf... '); |
|
447 SDLTry(TTF_Init <> -1, true); |
|
448 WriteLnToConsole(msgOK); |
|
449 |
|
450 ShowMainWindow; |
|
451 |
|
452 AddProgress; |
|
453 |
|
454 ControllerInit; // has to happen before InitKbdKeyTable to map keys |
|
455 InitKbdKeyTable; |
|
456 |
|
457 if recordFileName = '' then InitIPC; |
|
458 WriteLnToConsole(msgGettingConfig); |
|
459 |
|
460 if cLocaleFName <> 'en.txt' then |
|
461 LoadLocale(Pathz[ptLocale] + '/en.txt'); |
|
462 LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); |
|
463 |
|
464 if recordFileName = '' then |
|
465 SendIPCAndWaitReply('C') // ask for game config |
|
466 else |
|
467 LoadRecordFromFile(recordFileName); |
|
468 |
|
469 s:= 'eproto ' + inttostr(cNetProtoVersion); |
|
470 SendIPCRaw(@s[0], Length(s) + 1); // send proto version |
|
471 |
|
472 InitTeams; |
|
473 AssignStores; |
|
474 |
|
475 if isSoundEnabled then |
|
476 InitSound; |
|
477 |
|
478 isDeveloperMode:= false; |
|
479 |
|
480 TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
|
481 |
|
482 MainLoop; |
|
483 end; |
|
484 |
|
485 ///////////////////////// |
|
486 procedure GenLandPreview; |
|
487 var Preview: TPreview; |
|
488 h: byte; |
|
489 begin |
|
490 InitIPC; |
|
491 IPCWaitPongEvent; |
|
492 TryDo(InitStepsFlags = cifRandomize, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true); |
|
493 |
|
494 Preview:= GenPreview; |
|
495 WriteLnToConsole('Sending preview...'); |
|
496 SendIPCRaw(@Preview, sizeof(Preview)); |
|
497 h:= MaxHedgehogs; |
|
498 SendIPCRaw(@h, sizeof(h)); |
|
499 WriteLnToConsole('Preview sent, disconnect'); |
|
500 CloseIPC(); |
|
501 end; |
|
502 |
|
503 //////////////////////////////////////////////////////////////////////////////// |
474 //////////////////////////////////////////////////////////////////////////////// |
504 /////////////////////////////// m a i n //////////////////////////////////////// |
475 /////////////////////////////// m a i n //////////////////////////////////////// |
505 //////////////////////////////////////////////////////////////////////////////// |
476 //////////////////////////////////////////////////////////////////////////////// |
506 |
477 |
507 begin |
478 begin |
508 WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
479 WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); |
509 GetParams; |
480 GetParams; |
510 |
481 |
511 Randomize; |
482 Randomize; |
512 |
483 |
513 if GameType = gmtLandPreview then GenLandPreview |
484 if GameType = gmtLandPreview then GenLandPreview |
514 else Game; |
485 else Game; |
515 // ExitCode := 100; |
486 // ExitCode := 100; |
|
487 {$ENDIF} |
|
488 |
516 end. |
489 end. |
517 |
490 |