176 end; |
176 end; |
177 |
177 |
178 /////////////////// |
178 /////////////////// |
179 procedure MainLoop; |
179 procedure MainLoop; |
180 var PrevTime, CurrTime: Longword; |
180 var PrevTime, CurrTime: Longword; |
181 {$IFNDEF IPHONEOS}event: TSDL_Event;{$ENDIF} |
181 event: TSDL_Event; |
182 begin |
182 begin |
183 PrevTime:= SDL_GetTicks; |
183 PrevTime:= SDL_GetTicks; |
184 while isTerminated = false do |
184 while isTerminated = false do |
185 begin |
185 begin |
186 {$IFNDEF IPHONEOS} |
|
187 // have to remove this cycle because otherwise it segfaults at exit |
186 // have to remove this cycle because otherwise it segfaults at exit |
188 while SDL_PollEvent(@event) <> 0 do |
187 while SDL_PollEvent(@event) <> 0 do |
189 begin |
188 begin |
190 case event.type_ of |
189 case event.type_ of |
191 SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); |
190 SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); |
192 {$IFDEF SDL13} |
191 {$IFDEF SDL13} |
193 SDL_WINDOWEVENT: |
192 SDL_WINDOWEVENT: |
|
193 if event.wevent.event = SDL_WINDOWEVENT_SHOWN then |
|
194 cHasFocus:= true; |
194 {$ELSE} |
195 {$ELSE} |
195 SDL_ACTIVEEVENT: |
196 SDL_ACTIVEEVENT: |
196 {$ENDIF} |
|
197 if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
197 if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then |
198 cHasFocus:= event.active.gain = 1; |
198 cHasFocus:= event.active.gain = 1; |
|
199 {$ENDIF} |
|
200 {$IFNDEF IPHONEOS} |
199 //SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450)); |
201 //SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450)); |
200 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true; |
202 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true; |
201 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true; |
203 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true; |
|
204 {$ENDIF} |
202 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
205 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); |
203 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
206 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); |
204 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
207 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); |
205 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
208 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); |
206 SDL_QUITEV: isTerminated:= true |
209 SDL_QUITEV: isTerminated:= true |
207 end; // end case event.type_ of |
210 end; // end case event.type_ |
208 end; // end while SDL_PollEvent(@event) <> 0 do |
211 end; // end while SDL_PollEvent(@event) <> 0 |
209 {$ENDIF} |
212 |
210 if isTerminated = false then |
213 if isTerminated = false then |
211 begin |
214 begin |
212 CurrTime:= SDL_GetTicks; |
215 CurrTime:= SDL_GetTicks; |
213 if PrevTime + cTimerInterval <= CurrTime then |
216 if PrevTime + cTimerInterval <= CurrTime then |
214 begin |
217 begin |