28 {$ELSE} |
28 {$ELSE} |
29 program hwengine; |
29 program hwengine; |
30 {$ENDIF} |
30 {$ENDIF} |
31 |
31 |
32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound, |
32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound, |
33 uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, uMobile, sysutils; |
33 uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, uMobile, |
34 |
34 sysutils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted; |
35 var isTerminated: boolean = false; |
|
36 alsoShutdownFrontend: boolean = false; |
|
37 |
35 |
38 {$IFDEF HWLIBRARY} |
36 {$IFDEF HWLIBRARY} |
39 procedure initEverything(complete:boolean); |
37 procedure initEverything(complete:boolean); |
40 procedure freeEverything(complete:boolean); |
38 procedure freeEverything(complete:boolean); |
41 |
39 |
96 end; |
97 end; |
97 end; |
98 end; |
98 gsExit: begin |
99 gsExit: begin |
99 isTerminated:= true; |
100 isTerminated:= true; |
100 end; |
101 end; |
|
102 gsSuspend: exit; |
101 end; |
103 end; |
102 |
104 |
103 {$IFDEF SDL13} |
105 {$IFDEF SDL13} |
104 SDL_RenderPresent(); |
106 SDL_RenderPresent(); |
105 {$ELSE} |
107 {$ELSE} |
106 SDL_GL_SwapBuffers(); |
108 SDL_GL_SwapBuffers(); |
107 {$ENDIF} |
109 {$ENDIF} |
108 // not going to make captures on the iPhone |
110 |
109 if flagMakeCapture then |
111 if flagMakeCapture then |
110 begin |
112 begin |
111 flagMakeCapture:= false; |
113 flagMakeCapture:= false; |
112 s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks); |
114 s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks); |
113 WriteLnToConsole('Saving ' + s + '...'); |
115 WriteLnToConsole('Saving ' + s + '...'); |
|
116 playSound(sndShutter); |
114 MakeScreenshot(s); |
117 MakeScreenshot(s); |
115 //SDL_SaveBMP_RW(SDLPrimSurface, SDL_RWFromFile(Str2PChar(s), 'wb'), 1) |
118 //SDL_SaveBMP_RW(SDLPrimSurface, SDL_RWFromFile(Str2PChar(s), 'wb'), 1) |
116 end; |
119 end; |
117 end; |
120 end; |
118 |
121 |
145 |
147 |
146 while SDL_PollEvent(@event) <> 0 do |
148 while SDL_PollEvent(@event) <> 0 do |
147 begin |
149 begin |
148 case event.type_ of |
150 case event.type_ of |
149 SDL_KEYDOWN: if GameState = gsChat then |
151 SDL_KEYDOWN: if GameState = gsChat then |
150 {$IFDEF IPHONEOS} |
152 {$IFDEF SDL13} |
151 // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3 |
153 // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3 |
152 KeyPressChat(event.key.keysym.sym); |
154 KeyPressChat(event.key.keysym.sym); |
|
155 SDL_WINDOWEVENT: |
|
156 if event.wevent.event = SDL_WINDOWEVENT_SHOWN then |
|
157 cHasFocus:= true; |
153 {$ELSE} |
158 {$ELSE} |
154 KeyPressChat(event.key.keysym.unicode); |
159 KeyPressChat(event.key.keysym.unicode); |
155 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true; |
160 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true; |
156 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true; |
161 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true; |
157 {$ENDIF} |
|
158 {$IFDEF SDL13} |
|
159 SDL_WINDOWEVENT: |
|
160 if event.wevent.event = SDL_WINDOWEVENT_SHOWN then |
|
161 cHasFocus:= true; |
|
162 {$ELSE} |
|
163 SDL_ACTIVEEVENT: |
162 SDL_ACTIVEEVENT: |
164 if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
163 if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
165 cHasFocus:= event.active.gain = 1; |
164 cHasFocus:= event.active.gain = 1; |
166 {$ENDIF} |
165 {$ENDIF} |
167 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
166 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
168 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
167 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
169 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
168 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
170 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
169 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
171 SDL_QUITEV: isTerminated:= true |
170 SDL_QUITEV: isTerminated:= true |
172 end; // end case event.type_ |
171 end; //end case event.type_ of |
173 end; // end while SDL_PollEvent(@event) <> 0 |
172 end; //end while SDL_PollEvent(@event) <> 0 do |
174 |
173 |
175 if isTerminated = false then |
174 if isTerminated = false then |
176 begin |
175 begin |
177 CurrTime:= SDL_GetTicks; |
176 CurrTime:= SDL_GetTicks; |
178 if PrevTime + longword(cTimerInterval) <= CurrTime then |
177 if PrevTime + longword(cTimerInterval) <= CurrTime then |
349 uStats.initModule; |
354 uStats.initModule; |
350 uStore.initModule; |
355 uStore.initModule; |
351 uTeams.initModule; |
356 uTeams.initModule; |
352 uVisualGears.initModule; |
357 uVisualGears.initModule; |
353 uWorld.initModule; |
358 uWorld.initModule; |
|
359 uCaptions.initModule; |
354 end; |
360 end; |
355 end; |
361 end; |
356 |
362 |
357 procedure freeEverything (complete:boolean); |
363 procedure freeEverything (complete:boolean); |
358 begin |
364 begin |
359 if complete then |
365 if complete then |
360 begin |
366 begin |
|
367 uCaptions.freeModule; |
361 uWorld.freeModule; |
368 uWorld.freeModule; |
362 uVisualGears.freeModule; |
369 uVisualGears.freeModule; |
363 uTeams.freeModule; |
370 uTeams.freeModule; |
364 uStore.freeModule; //stub |
371 uStore.freeModule; //stub |
365 uStats.freeModule; //stub |
372 uStats.freeModule; //stub |
385 end; |
392 end; |
386 |
393 |
387 uIO.freeModule; //stub |
394 uIO.freeModule; //stub |
388 uLand.freeModule; |
395 uLand.freeModule; |
389 |
396 |
|
397 uCommandHandlers.freeModule; |
|
398 uCommands.freeModule; |
390 uConsole.freeModule; |
399 uConsole.freeModule; |
|
400 uVariables.freeModule; |
|
401 uUtils.freeModule; |
391 uMisc.freeModule; // uMisc closes the debug log. |
402 uMisc.freeModule; // uMisc closes the debug log. |
392 end; |
403 end; |
393 |
404 |
394 ///////////////////////// |
405 ///////////////////////// |
395 procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF}; |
406 procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF}; |