hedgewars/hwengine.pas
changeset 2590 e7e87e3c67db
parent 2587 0dfa56a8513c
child 2591 c6597b65caea
equal deleted inserted replaced
2589:4329597c85c8 2590:e7e87e3c67db
   164     CurrTime: Longword;
   164     CurrTime: Longword;
   165     event: TSDL_Event;
   165     event: TSDL_Event;
   166 {$IFDEF IPHONEOS}
   166 {$IFDEF IPHONEOS}
   167 type TDirection = (nodir, left, right);
   167 type TDirection = (nodir, left, right);
   168 var x, y: LongInt;
   168 var x, y: LongInt;
   169     oldy_zoom: LongInt = -1;
   169         dx, dy, mouseState: LongInt;
   170     oldy_aim: LongInt = -1;
   170     direction: TDirection = nodir;
       
   171     havetrace: boolean = false;
   171 {$ENDIF}
   172 {$ENDIF}
   172 begin
   173 begin
   173 PrevTime:= SDL_GetTicks;
   174 PrevTime:= SDL_GetTicks;
   174 repeat
   175 repeat
   175 while SDL_PollEvent(@event) <> 0 do
   176 while SDL_PollEvent(@event) <> 0 do
       
   177 {$IFDEF TOUCHINPUT}
       
   178 if direction <> nodir then
       
   179 begin
       
   180         uKeys.isWalking:= true;
       
   181         if direction = left then uKeys.leftKey:= true
       
   182         else if direction = right then uKeys.rightKey:= true;
       
   183 end
       
   184 else uKeys.isWalking:= false;
       
   185 {$ENDIF}
   176 	case event.type_ of
   186 	case event.type_ of
   177 {$IFDEF SDL13}
   187 {$IFDEF SDL13}
   178                 SDL_WINDOWEVENT:
   188                 SDL_WINDOWEVENT:
   179 {$ELSE}
   189 {$ELSE}
   180 		SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode);
   190 		SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode);
   182 {$ENDIF}
   192 {$ENDIF}
   183                         if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   193                         if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   184 				cHasFocus:= event.active.gain = 1;
   194 				cHasFocus:= event.active.gain = 1;
   185 		//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450));
   195 		//SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450));
   186 {$IFDEF TOUCHINPUT}
   196 {$IFDEF TOUCHINPUT}
       
   197                 SDL_MOUSEMOTION: begin
       
   198                         AddFileLog('*********************************************       motion');
       
   199                         mouseState:= SDL_GetMouseState(0, @x, @y);
       
   200                         SDL_GetRelativeMouseState(0, @dx, @dy);
       
   201                         
       
   202                         direction:= nodir;
       
   203 
       
   204                         if boolean(mouseState) then
       
   205                         begin
       
   206                                 AddFileLog('x: ' + inttostr(x) + ' y: ' + inttostr(y) + ' dx: ' + inttostr(dx) + ' dy: ' + inttostr(dy));
       
   207 
       
   208                                 {* zoom slider *}
       
   209                                 if (x <= 50) and (y <= 430) and (y > 50) then 
       
   210                                 begin
       
   211                                         if (dy > 0) then uKeys.wheelDown:= true
       
   212                                         else if (dy < 0) then uKeys.wheelUp:= true;
       
   213                                 end;
       
   214 
       
   215                                 {* aim slider *}
       
   216                                 if (x > 270) and (y > 50) and (y <= 430) then
       
   217                                 begin
       
   218                                         if (dy > 0) then uKeys.downKey:= true
       
   219                                         else if (dy < 0) then uKeys.upKey:= true;
       
   220                                 end;
       
   221 
       
   222                                 {* switch *}
       
   223                                 if (x > 50) and (x <= 270) and (y > 400) then
       
   224                                 begin
       
   225                                         if (dy <> 0) then uKeys.tabKey:= true
       
   226                                 end;
       
   227                         end;
       
   228                 end;
   187         {*MoveCamera is in uWord.pas -- conflicts with other commands*}
   229         {*MoveCamera is in uWord.pas -- conflicts with other commands*}
   188         {*Keys are in uKeys.pas*}
       
   189                 SDL_MOUSEBUTTONDOWN: begin
   230                 SDL_MOUSEBUTTONDOWN: begin
   190                         AddFileLog('*********************************************       touch down');
   231                         AddFileLog('*********************************************       touch down');
   191 
   232 
   192                         SDL_GetMouseState(0, @x, @y);
   233                         mouseState:= SDL_GetMouseState(0, @x, @y);                       
   193  uKeys.leftClick:= true;
   234 
   194 
       
   195                         {* zoom slider *}
       
   196                         if (x <= 50) and (y <= 430) then 
       
   197                         begin
       
   198 {$IFDEF DEBUGFILE}
       
   199                                 AddFileLog('Wheel -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   200 {$ENDIF}
       
   201                                 if oldy_zoom = -1 then oldy_zoom:= y
       
   202                                 else
       
   203                                 begin
       
   204                                         if oldy_zoom - y > 10 then uKeys.wheelUp:= true
       
   205                                         else if oldy_zoom -y < -10 then uKeys.wheelDown:= true;
       
   206                                         {* update value only if movement is consistent *}
       
   207                                         if (y > oldy_zoom + 20 ) or (y < oldy_zoom - 20 ) then oldy_zoom:= y
       
   208                                 end;
       
   209                         end;
       
   210                         {* reset zoom *}
       
   211                         if (x <= 50) and (y > 430) then
       
   212                         begin
       
   213 {$IFDEF DEBUGFILE}
       
   214                                 AddFileLog('Middle Click -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   215 {$ENDIF}
       
   216                                 uKeys.middleClick:= true;
       
   217                         end;
       
   218                         {* aim slider *}
       
   219                         if (x > 230) and (y <= 430) then 
       
   220                         begin
       
   221 {$IFDEF DEBUGFILE}
       
   222                                 AddFileLog('Up&Down -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   223 {$ENDIF}
       
   224                                 if oldy_aim = -1 then oldy_aim:= y
       
   225                                 else
       
   226                                 begin
       
   227                                         if oldy_aim - y > 10 then uKeys.upKey:= true
       
   228                                         else if oldy_aim -y < -10 then uKeys.downKey:= true;
       
   229                                         {* update value only if movement is consistent *}
       
   230                                         if (y > oldy_aim + 20 ) or (y < oldy_aim - 20 ) then oldy_aim:= y
       
   231                                 end;
       
   232                         end;
       
   233                         {* reset zoom *}
       
   234                         if (x <= 50) and (y > 430) then
       
   235                         begin
       
   236 {$IFDEF DEBUGFILE}
       
   237                                 AddFileLog('Middle Click -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   238 {$ENDIF}
       
   239                                 uKeys.middleClick:= true;
       
   240                         end;
       
   241                         {* long jump *}                        
       
   242                         if (y > 430) and (x > 50) and (x <= 135) then
       
   243                         begin
       
   244 {$IFDEF DEBUGFILE}
       
   245                                 AddFileLog('Enter -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   246 {$ENDIF}
       
   247                                 uKeys.enterKey:= true;
       
   248                         end;
       
   249                         {* high jump *}                        
       
   250                         if (y > 430) and (x > 185) and (x <= 270) then
       
   251                         begin
       
   252 {$IFDEF DEBUGFILE}
       
   253                                 AddFileLog('Backspace -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   254 {$ENDIF}
       
   255                                 uKeys.backspaceKey:= true;
       
   256 
       
   257                         end;
       
   258                         {* attack *}
   235                         {* attack *}
   259                         if (y <= 50) and (x > 50) and (x <= 270) then
   236                         if (x > 50) and (x <= 270) and (y <= 50) then
   260                         begin
   237                         begin
   261 {$IFDEF DEBUGFILE}
       
   262                                 AddFileLog('Space DOWN -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
   238                                 AddFileLog('Space DOWN -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
   263 {$ENDIF}
       
   264                                 uKeys.spaceKey:= true;
   239                                 uKeys.spaceKey:= true;
   265                                 uKeys.isAttacking:= true;
   240                                 uKeys.isAttacking:= true;
   266                         end
   241                         end;
   267                         else
   242 
   268                         begin
   243                         if (x <= 50) and (y <= 50) then
   269                                 AddFileLog('Space UP -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
   244                         begin
   270                                 uKeys.isAttacking:= false;
   245                                 AddFileLog('Left Arrow Key DOWN -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   246                             //    uKeys.leftKey:= true;
       
   247                             //    uKeys.isWalking:= true;
       
   248                                 direction:= left;
       
   249                         end;
       
   250                         
       
   251                         if (x > 270) and (y <= 50) then
       
   252                         begin
       
   253                                 AddFileLog('Right Arrow Key DOWN -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   254                             //    uKeys.rightKey:= true;
       
   255                             //    uKeys.isWalking:= true;
       
   256                                 direction:= right;
       
   257                         end;
       
   258 
       
   259                         {* high jump *}                        
       
   260                         if (x > 160) and (x <= 270) and (y > 400) then
       
   261                         begin
       
   262 {$IFDEF DEBUGFILE}
       
   263                                 AddFileLog('Backspace -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   264 {$ENDIF}
       
   265                                 uKeys.backspaceKey:= true;
   271                         end;
   266                         end;
   272                 end;
   267                 end;
   273                 SDL_MOUSEBUTTONUP: begin
   268                 SDL_MOUSEBUTTONUP: begin
   274                         AddFileLog('*********************************************       touch up');
   269                         AddFileLog('*********************************************       touch up');
   275 
   270 
   276                         SDL_GetMouseState(0, @x, @y);
   271                         mouseState:= SDL_GetMouseState(0, @x, @y);
       
   272                         uKeys.leftClick:= true;
       
   273 
   277                         {* open ammo menu *}
   274                         {* open ammo menu *}
   278                         if (y > 430) and (x > 270) then
   275                         if (y > 430) and (x > 270) then
   279                         begin
   276                         begin
   280 {$IFDEF DEBUGFILE}
   277 {$IFDEF DEBUGFILE}
   281                                 AddFileLog('Right Click -- x: ' + inttostr(x) + ' y: ' + inttostr(y) );
   278                                 AddFileLog('Right Click -- x: ' + inttostr(x) + ' y: ' + inttostr(y) );
   282 {$ENDIF}
   279 {$ENDIF}
   283                                 uKeys.rightClick:= true;
   280                                 uKeys.rightClick:= true;
   284                         end;
   281                         end;
       
   282 
       
   283                         {* long jump *}                        
       
   284                         if (x > 50) and (x <= 160) and (y > 400) then
       
   285                         begin
       
   286 {$IFDEF DEBUGFILE}
       
   287                                 AddFileLog('Enter -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   288 {$ENDIF}
       
   289                                 uKeys.enterKey:= true;
       
   290                         end;
       
   291 
       
   292                         {* reset zoom *}
       
   293                         if (x <= 50) and (y > 430) then
       
   294                         begin
       
   295 {$IFDEF DEBUGFILE}
       
   296                                 AddFileLog('Middle Click -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
       
   297 {$ENDIF}
       
   298                                 uKeys.middleClick:= true;
       
   299                         end;
       
   300 
       
   301                         {* end movement and attack *}
       
   302 {$IFDEF DEBUGFILE}
       
   303                         AddFileLog('Arrow Keys UP | Space UP -- x: ' + inttostr(x) + ' y: ' + inttostr(y) );
       
   304 {$ENDIF}
       
   305                         direction:= nodir;
       
   306                         uKeys.isAttacking:= false;
   285                 end;
   307                 end;
   286 {$ENDIF}
   308 {$ENDIF}
   287 {$IFDEF IPHONEOS}
   309 {$IFDEF IPHONEOS}
       
   310 {* might be masked by above events
   288 		SDL_JOYAXIS: begin
   311 		SDL_JOYAXIS: begin
   289                 {* axis 0 = left and right;
   312                 {* axis 0 = left and right;
   290                    axis 1 = up and down;
   313                    axis 1 = up and down;
   291                    axis 2 = back and forth; *}
   314                    axis 2 = back and forth; *}
   292                         if (event.jaxis.axis = 0) and (CurrentTeam <> nil) then
   315                         if (event.jaxis.axis = 0) and (CurrentTeam <> nil) then
   293                         begin
   316                         begin
   294                                 if event.jaxis.value > 1500 then
   317                                 if event.jaxis.value > 1500 then
   295                                 begin
   318                                 begin
   296                                         uKeys.rightKey:= true;
   319                                         direction:= right;
   297                                         uKeys.isWalking:= true;
       
   298                                 end
   320                                 end
   299                                 else
   321                                 else
   300                                         if event.jaxis.value <= -1500 then
   322                                         if event.jaxis.value <= -1500 then
   301                                         begin 
   323                                         begin 
   302                                                 uKeys.leftKey:= true;
   324                                                 direction:= left
   303                                                 uKeys.isWalking:= true;
       
   304                                         end
   325                                         end
   305                                         else
   326                                         else
   306                                                 if (event.jaxis.value  > -1500) and (event.jaxis.value <= 1500) then uKeys.isWalking:= false;
   327                                                 if (event.jaxis.value  > -1500) and (event.jaxis.value <= 1500) then direction:= nodir;
   307 {$IFDEF DEBUGFILE}
   328 {$IFDEF DEBUGFILE}
   308                                 AddFileLog('Joystick value: ' + inttostr(event.jaxis.value));
   329                                 AddFileLog('Joystick value: ' + inttostr(event.jaxis.value));
   309 {$ENDIF}
   330 {$ENDIF}
   310                         end;
   331                         end;
   311                 
   332                 
   312                 end;
   333                 end;
   313 
   334 *}
   314 {$ELSE}
   335 {$ELSE}
   315 		SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
   336 		SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
   316 		SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELDUP then uKeys.wheelUp:= true;
   337 		SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELDUP then uKeys.wheelUp:= true;
   317 		SDL_JOYAXIS: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
   338 		SDL_JOYAXIS: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
   318 		SDL_JOYHAT: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
   339 		SDL_JOYHAT: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
   319 		SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
   340 		SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
   320 		SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
   341 		SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
   321 {$ENDIF}
   342 {$ENDIF}
   322 		SDL_QUITEV: isTerminated:= true
   343 		SDL_QUITEV: isTerminated:= true
   323 		end;
   344         end;
       
   345 
   324 CurrTime:= SDL_GetTicks;
   346 CurrTime:= SDL_GetTicks;
   325 if PrevTime + cTimerInterval <= CurrTime then
   347 if PrevTime + cTimerInterval <= CurrTime then
   326    begin
   348    begin
   327    DoTimer(CurrTime - PrevTime);
   349    DoTimer(CurrTime - PrevTime);
   328    PrevTime:= CurrTime
   350    PrevTime:= CurrTime
   329    end else SDL_Delay(1);
   351    end else SDL_Delay(1);
   330 IPCCheckSock
   352 IPCCheckSock
   331 until isTerminated
   353 until isTerminated
       
   354 
   332 end;
   355 end;
   333 
   356 
   334 /////////////////////
   357 /////////////////////
   335 procedure DisplayUsage;
   358 procedure DisplayUsage;
   336 begin
   359 begin