# HG changeset patch # User koda # Date 1263792968 0 # Node ID 249adefa9c1c7da760a0ac74e5638b8a5b3b004a # Parent 90585aba87addd86460b87e2f5b5272f2bb4cede replace initialization/finalization statements with custom init functions diff -r 90585aba87ad -r 249adefa9c1c cocoaTouch/GameSetup.m --- a/cocoaTouch/GameSetup.m Sat Jan 16 17:30:37 2010 +0000 +++ b/cocoaTouch/GameSetup.m Mon Jan 18 05:36:08 2010 +0000 @@ -146,7 +146,7 @@ [self sendToEngine:@"egrave star"]; // team 1 fort info - [self sendToEngine:@"efort Earth"]; + [self sendToEngine:@"efort Earth"]; // team 1 voicepack info [self sendToEngine:@"evoicepack Classic"]; @@ -236,7 +236,7 @@ } NSLog(@"Client Exited"); // wait a little to let the client close cleanly - sleep(5); + sleep(2); // Close the client socket SDLNet_TCP_Close(csd); } @@ -257,7 +257,8 @@ if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:filePath]; - [self setValue:dict forKey:objName]; + systemSettings = dict; + //[self setValue:dict forKey:objName]; [dict release]; } else { //TODO create it @@ -267,7 +268,7 @@ } -(void) unloadSettings { - [systemSettings release]; + systemSettings = nil; } diff -r 90585aba87ad -r 249adefa9c1c cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m --- a/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m Sat Jan 16 17:30:37 2010 +0000 +++ b/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m Mon Jan 18 05:36:08 2010 +0000 @@ -91,7 +91,7 @@ [UIView beginAnimations:@"inserting main controller" context:NULL]; [UIView setAnimationDuration:1]; controller.view.alpha = 1; - [UIView commitAnimations]; + [UIView commitAnimations]; } // override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) diff -r 90585aba87ad -r 249adefa9c1c hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/SDLh.pas Mon Jan 18 05:36:08 2010 +0000 @@ -634,6 +634,7 @@ function SDL_RenderClear: LongInt; cdecl; external SDLLibName; procedure SDL_RenderPresent; cdecl; external SDLLibName; function SDL_RenderCopy(textureID: TSDL_TextureID; srcrect, dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName; +procedure SDL_VideoQuit; cdecl; external SDLLibName; function SDL_CreateTextureFromSurface(format: LongInt; surface: PSDL_Surface): TSDL_TextureID; cdecl; external SDLLibName; procedure SDL_DestroyTexture(textureID: TSDL_TextureID); cdecl; external SDLLibName; diff -r 90585aba87ad -r 249adefa9c1c hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/hwengine.pas Mon Jan 18 05:36:08 2010 +0000 @@ -53,6 +53,7 @@ uFloat in 'uFloat.pas', uStats in 'uStats.pas', uChat in 'uChat.pas', + uTriggers in 'uTriggers.pas', uLandTexture in 'uLandTexture.pas' {$IFDEF IPHONEOS} , PascalExports in 'PascalExports.pas' @@ -71,11 +72,14 @@ procedure MainLoop; procedure ShowMainWindow; procedure Game; cdecl; export; +procedure initEverything; +procedure freeEverything; implementation {$ELSE} procedure OnDestroy; forward; +procedure freeEverything; forward; {$ENDIF} //////////////////////////////// @@ -151,7 +155,9 @@ ControllerClose(); SendKB(); CloseIPC(); + freeEverything(); TTF_Quit(); + {$IFDEF SDL13}SDL_VideoQuit();{$ENDIF} SDL_Quit(); exit(); end; @@ -215,7 +221,8 @@ s: shortstring; begin {$IFDEF IPHONEOS} - Randomize; + initEverything(); + Randomize(); val('320', cScreenWidth); val('480', cScreenHeight); @@ -289,11 +296,40 @@ exit(); end; +procedure initEverything; +begin + init_uConsts(); + init_uMisc(); + init_uConsole(); // MUST happen after uMisc + init_uStore(); + init_uTeams(); + init_uGears(); + init_uVisualGears(); + init_uLand(); + init_uIO(); + init_uWorld(); + init_uRandom; + init_uTriggers; + +end; + +procedure freeEverything; +begin + //free_uConts(); not necessary + free_uConsole(); + free_uMisc(); + free_uTeams(); + free_uGears(); + //free_uVisualGears(); not necessary + free_uLand(); + //free_uWorld(); not necessary + +end; {$IFNDEF IPHONEOS} ///////////////////////// procedure GenLandPreview; var Preview: TPreview; - h: byte; + h: byte; begin InitIPC; IPCWaitPongEvent; @@ -344,11 +380,9 @@ //////////////////// procedure GetParams; -var {$IFDEF DEBUGFILE} - i: LongInt; +var i: LongInt; {$ENDIF} - p: TPathType; begin case ParamCount of @@ -476,15 +510,14 @@ //////////////////////////////////////////////////////////////////////////////// begin + initEverything(); WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); - GetParams; - - Randomize; + + GetParams(); + Randomize(); - if GameType = gmtLandPreview then GenLandPreview - else Game; -// ExitCode := 100; + if GameType = gmtLandPreview then GenLandPreview() + else Game(); + ExitCode := 0; {$ENDIF} - end. - diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uChat.pas --- a/hedgewars/uChat.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uChat.pas Mon Jan 18 05:36:08 2010 +0000 @@ -27,7 +27,7 @@ procedure KeyPressChat(Key: Longword); var UserNick: shortstring = ''; - showAll: boolean = false; + showAll: boolean = false; implementation uses uMisc, uStore, uConsts, SDLh, uConsole, uKeys, uTeams; diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uConsole.pas --- a/hedgewars/uConsole.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uConsole.pas Mon Jan 18 05:36:08 2010 +0000 @@ -22,10 +22,12 @@ interface uses uFloat; -const isDeveloperMode: boolean = true; +var isDeveloperMode: boolean; type TVariableType = (vtCommand, vtLongInt, vthwFloat, vtBoolean); TCommandHandler = procedure (var params: shortstring); +procedure init_uConsole; +procedure free_uConsole; procedure WriteToConsole(s: shortstring); procedure WriteLnToConsole(s: shortstring); procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); @@ -55,8 +57,8 @@ end; var ConsoleLines: array[byte] of TTextLine; - CurrLine: LongInt = 0; - Variables: PVariable = nil; + CurrLine: LongInt; + Variables: PVariable; procedure SetLine(var tl: TTextLine; str: shortstring); begin @@ -112,37 +114,35 @@ procedure WriteToConsole(s: shortstring); var Len: LongInt; + done: boolean; begin -{$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF} -Write(s); -repeat -Len:= cLineWidth - Length(ConsoleLines[CurrLine].s); -SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len)); -Delete(s, 1, Len); -if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then - begin - inc(CurrLine); - if CurrLine = cLinesCount then CurrLine:= 0; - PByte(@ConsoleLines[CurrLine].s)^:= 0 - end; -until Length(s) = 0 + {$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF} + Write(s); + done:= false; + + while not done do + begin + Len:= cLineWidth - Length(ConsoleLines[CurrLine].s); + SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len)); + Delete(s, 1, Len); + if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then + begin + inc(CurrLine); + if CurrLine = cLinesCount then CurrLine:= 0; + PByte(@ConsoleLines[CurrLine].s)^:= 0 + end; + done:= (Length(s) = 0); + end; end; procedure WriteLnToConsole(s: shortstring); begin -WriteToConsole(s); -WriteLn; -inc(CurrLine); -if CurrLine = cLinesCount then CurrLine:= 0; -PByte(@ConsoleLines[CurrLine].s)^:= 0 -end; - -procedure InitConsole; -var i: LongInt; -begin -cLineWidth:= cScreenWidth div 10; -if cLineWidth > 255 then cLineWidth:= 255; -for i:= 0 to Pred(cLinesCount) do PByte(@ConsoleLines[i])^:= 0 + WriteToConsole(s); + WriteLn; + inc(CurrLine); + if CurrLine = cLinesCount then + CurrLine:= 0; + PByte(@ConsoleLines[CurrLine].s)^:= 0 end; procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); @@ -225,90 +225,104 @@ end; {$INCLUDE "CCHandlers.inc"} +procedure init_uConsole; +var i: LongInt; +begin + CurrLine:= 0; + Variables:= nil; + isDeveloperMode:= true; + + // initConsole + cLineWidth:= cScreenWidth div 10; + if cLineWidth > 255 then + cLineWidth:= 255; + for i:= 0 to Pred(cLinesCount) do + PByte(@ConsoleLines[i])^:= 0; + + RegisterVariable('proto' , vtCommand, @chCheckProto , true ); + RegisterVariable('spectate', vtBoolean, @fastUntilLag , false); + RegisterVariable('capture' , vtCommand, @chCapture , true ); + RegisterVariable('rotmask' , vtCommand, @chRotateMask , true ); + RegisterVariable('addteam' , vtCommand, @chAddTeam , false); + RegisterVariable('addtrig' , vtCommand, @chAddTrigger , false); + RegisterVariable('rdriven' , vtCommand, @chTeamLocal , false); + RegisterVariable('map' , vtCommand, @chSetMap , false); + RegisterVariable('theme' , vtCommand, @chSetTheme , false); + RegisterVariable('seed' , vtCommand, @chSetSeed , false); + RegisterVariable('template_filter', vtLongInt, @cTemplateFilter, false); + RegisterVariable('delay' , vtLongInt, @cInactDelay , false); + RegisterVariable('casefreq', vtLongInt, @cCaseFactor , false); + RegisterVariable('sd_turns', vtLongInt, @cSuddenDTurns , false); + RegisterVariable('damagepct',vtLongInt, @cDamagePercent , false); + RegisterVariable('landadds', vtLongInt, @cLandAdditions , false); + RegisterVariable('gmflags' , vtLongInt, @GameFlags , false); + RegisterVariable('trflags' , vtLongInt, @TrainingFlags , false); + RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false); + RegisterVariable('minestime',vtLongInt, @cMinesTime , false); + RegisterVariable('fort' , vtCommand, @chFort , false); + RegisterVariable('voicepack',vtCommand, @chVoicepack , false); + RegisterVariable('grave' , vtCommand, @chGrave , false); + RegisterVariable('bind' , vtCommand, @chBind , true ); + RegisterVariable('addhh' , vtCommand, @chAddHH , false); + RegisterVariable('hat' , vtCommand, @chSetHat , false); + RegisterVariable('hhcoords', vtCommand, @chSetHHCoords , false); + RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false); + RegisterVariable('quit' , vtCommand, @chQuit , true ); + RegisterVariable('confirm' , vtCommand, @chConfirm , true ); + RegisterVariable('+speedup', vtCommand, @chSpeedup_p , true ); + RegisterVariable('-speedup', vtCommand, @chSpeedup_m , true ); + RegisterVariable('zoomin' , vtCommand, @chZoomIn , true ); + RegisterVariable('zoomout' , vtCommand, @chZoomOut , true ); + RegisterVariable('zoomreset',vtCommand, @chZoomReset , true ); + RegisterVariable('skip' , vtCommand, @chSkip , false); + RegisterVariable('history' , vtCommand, @chHistory , true ); + RegisterVariable('chat' , vtCommand, @chChat , true ); + RegisterVariable('newgrave', vtCommand, @chNewGrave , false); + RegisterVariable('say' , vtCommand, @chSay , true ); + RegisterVariable('hogsay' , vtCommand, @chHogSay , true ); + RegisterVariable('team' , vtCommand, @chTeamSay , true ); + RegisterVariable('ammomenu', vtCommand, @chAmmoMenu , false); + RegisterVariable('+precise', vtCommand, @chPrecise_p , false); + RegisterVariable('-precise', vtCommand, @chPrecise_m , false); + RegisterVariable('+left' , vtCommand, @chLeft_p , false); + RegisterVariable('-left' , vtCommand, @chLeft_m , false); + RegisterVariable('+right' , vtCommand, @chRight_p , false); + RegisterVariable('-right' , vtCommand, @chRight_m , false); + RegisterVariable('+up' , vtCommand, @chUp_p , false); + RegisterVariable('-up' , vtCommand, @chUp_m , false); + RegisterVariable('+down' , vtCommand, @chDown_p , false); + RegisterVariable('-down' , vtCommand, @chDown_m , false); + RegisterVariable('+attack' , vtCommand, @chAttack_p , false); + RegisterVariable('-attack' , vtCommand, @chAttack_m , false); + RegisterVariable('switch' , vtCommand, @chSwitch , false); + RegisterVariable('nextturn', vtCommand, @chNextTurn , false); + RegisterVariable('timer' , vtCommand, @chTimer , false); + RegisterVariable('taunt' , vtCommand, @chTaunt , false); + RegisterVariable('setweap' , vtCommand, @chSetWeapon , false); + RegisterVariable('slot' , vtCommand, @chSlot , false); + RegisterVariable('put' , vtCommand, @chPut , false); + RegisterVariable('ljump' , vtCommand, @chLJump , false); + RegisterVariable('hjump' , vtCommand, @chHJump , false); + RegisterVariable('fullscr' , vtCommand, @chFullScr , true ); + RegisterVariable('+volup' , vtCommand, @chVol_p , true ); + RegisterVariable('-volup' , vtCommand, @chVol_m , true ); + RegisterVariable('+voldown', vtCommand, @chVol_m , true ); + RegisterVariable('-voldown', vtCommand, @chVol_p , true ); + RegisterVariable('findhh' , vtCommand, @chFindhh , true ); + RegisterVariable('pause' , vtCommand, @chPause , true ); + RegisterVariable('+cur_u' , vtCommand, @chCurU_p , true ); + RegisterVariable('-cur_u' , vtCommand, @chCurU_m , true ); + RegisterVariable('+cur_d' , vtCommand, @chCurD_p , true ); + RegisterVariable('-cur_d' , vtCommand, @chCurD_m , true ); + RegisterVariable('+cur_l' , vtCommand, @chCurL_p , true ); + RegisterVariable('-cur_l' , vtCommand, @chCurL_m , true ); + RegisterVariable('+cur_r' , vtCommand, @chCurR_p , true ); + RegisterVariable('-cur_r' , vtCommand, @chCurR_m , true ); +end; -initialization -InitConsole; -RegisterVariable('proto' , vtCommand, @chCheckProto , true ); -RegisterVariable('spectate', vtBoolean, @fastUntilLag , false); -RegisterVariable('capture' , vtCommand, @chCapture , true ); -RegisterVariable('rotmask' , vtCommand, @chRotateMask , true ); -RegisterVariable('addteam' , vtCommand, @chAddTeam , false); -RegisterVariable('addtrig' , vtCommand, @chAddTrigger , false); -RegisterVariable('rdriven' , vtCommand, @chTeamLocal , false); -RegisterVariable('map' , vtCommand, @chSetMap , false); -RegisterVariable('theme' , vtCommand, @chSetTheme , false); -RegisterVariable('seed' , vtCommand, @chSetSeed , false); -RegisterVariable('template_filter', vtLongInt, @cTemplateFilter, false); -RegisterVariable('delay' , vtLongInt, @cInactDelay , false); -RegisterVariable('casefreq', vtLongInt, @cCaseFactor , false); -RegisterVariable('sd_turns', vtLongInt, @cSuddenDTurns , false); -RegisterVariable('damagepct',vtLongInt, @cDamagePercent , false); -RegisterVariable('landadds', vtLongInt, @cLandAdditions , false); -RegisterVariable('gmflags' , vtLongInt, @GameFlags , false); -RegisterVariable('trflags' , vtLongInt, @TrainingFlags , false); -RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false); -RegisterVariable('minestime',vtLongInt, @cMinesTime , false); -RegisterVariable('fort' , vtCommand, @chFort , false); -RegisterVariable('voicepack',vtCommand, @chVoicepack , false); -RegisterVariable('grave' , vtCommand, @chGrave , false); -RegisterVariable('bind' , vtCommand, @chBind , true ); -RegisterVariable('addhh' , vtCommand, @chAddHH , false); -RegisterVariable('hat' , vtCommand, @chSetHat , false); -RegisterVariable('hhcoords', vtCommand, @chSetHHCoords , false); -RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false); -RegisterVariable('quit' , vtCommand, @chQuit , true ); -RegisterVariable('confirm' , vtCommand, @chConfirm , true ); -RegisterVariable('+speedup', vtCommand, @chSpeedup_p , true ); -RegisterVariable('-speedup', vtCommand, @chSpeedup_m , true ); -RegisterVariable('zoomin' , vtCommand, @chZoomIn , true ); -RegisterVariable('zoomout' , vtCommand, @chZoomOut , true ); -RegisterVariable('zoomreset',vtCommand, @chZoomReset , true ); -RegisterVariable('skip' , vtCommand, @chSkip , false); -RegisterVariable('history' , vtCommand, @chHistory , true ); -RegisterVariable('chat' , vtCommand, @chChat , true ); -RegisterVariable('newgrave', vtCommand, @chNewGrave , false); -RegisterVariable('say' , vtCommand, @chSay , true ); -RegisterVariable('hogsay' , vtCommand, @chHogSay , true ); -RegisterVariable('team' , vtCommand, @chTeamSay , true ); -RegisterVariable('ammomenu', vtCommand, @chAmmoMenu , false); -RegisterVariable('+precise', vtCommand, @chPrecise_p , false); -RegisterVariable('-precise', vtCommand, @chPrecise_m , false); -RegisterVariable('+left' , vtCommand, @chLeft_p , false); -RegisterVariable('-left' , vtCommand, @chLeft_m , false); -RegisterVariable('+right' , vtCommand, @chRight_p , false); -RegisterVariable('-right' , vtCommand, @chRight_m , false); -RegisterVariable('+up' , vtCommand, @chUp_p , false); -RegisterVariable('-up' , vtCommand, @chUp_m , false); -RegisterVariable('+down' , vtCommand, @chDown_p , false); -RegisterVariable('-down' , vtCommand, @chDown_m , false); -RegisterVariable('+attack' , vtCommand, @chAttack_p , false); -RegisterVariable('-attack' , vtCommand, @chAttack_m , false); -RegisterVariable('switch' , vtCommand, @chSwitch , false); -RegisterVariable('nextturn', vtCommand, @chNextTurn , false); -RegisterVariable('timer' , vtCommand, @chTimer , false); -RegisterVariable('taunt' , vtCommand, @chTaunt , false); -RegisterVariable('setweap' , vtCommand, @chSetWeapon , false); -RegisterVariable('slot' , vtCommand, @chSlot , false); -RegisterVariable('put' , vtCommand, @chPut , false); -RegisterVariable('ljump' , vtCommand, @chLJump , false); -RegisterVariable('hjump' , vtCommand, @chHJump , false); -RegisterVariable('fullscr' , vtCommand, @chFullScr , true ); -RegisterVariable('+volup' , vtCommand, @chVol_p , true ); -RegisterVariable('-volup' , vtCommand, @chVol_m , true ); -RegisterVariable('+voldown', vtCommand, @chVol_m , true ); -RegisterVariable('-voldown', vtCommand, @chVol_p , true ); -RegisterVariable('findhh' , vtCommand, @chFindhh , true ); -RegisterVariable('pause' , vtCommand, @chPause , true ); -RegisterVariable('+cur_u' , vtCommand, @chCurU_p , true ); -RegisterVariable('-cur_u' , vtCommand, @chCurU_m , true ); -RegisterVariable('+cur_d' , vtCommand, @chCurD_p , true ); -RegisterVariable('-cur_d' , vtCommand, @chCurD_m , true ); -RegisterVariable('+cur_l' , vtCommand, @chCurL_p , true ); -RegisterVariable('-cur_l' , vtCommand, @chCurL_m , true ); -RegisterVariable('+cur_r' , vtCommand, @chCurR_p , true ); -RegisterVariable('-cur_r' , vtCommand, @chCurR_m , true ); - -finalization -FreeVariablesList +procedure free_uConsole; +begin + FreeVariablesList(); +end; end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uConsts.pas Mon Jan 18 05:36:08 2010 +0000 @@ -21,14 +21,13 @@ unit uConsts; interface -uses - SDLh, +uses SDLh, uFloat, uLocale, {$IFDEF GLES11} - gles11, + gles11; {$ELSE} - GL, + GL; {$ENDIF} - uLocale; + {$INCLUDE "proto.inc"} @@ -36,7 +35,10 @@ // in freepascal you may actually use var for the same purpose type - + HwColor4f = record + r, g, b, a: byte + end; + TGameState = (gsLandGen, gsStart, gsGame, gsChat, gsConfirm, gsExit); TGameType = (gmtLocal, gmtDemo, gmtNet, gmtSave, gmtLandPreview); @@ -158,6 +160,7 @@ PTexture = ^TTexture; const + // message constants errmsgCreateSurface = 'Error creating SDL surface'; errmsgTransparentSet = 'Error setting transparent color'; errmsgUnknownCommand = 'Unknown command'; @@ -173,20 +176,26 @@ msgFailedSize = 'failed due to size'; msgGettingConfig = 'Getting game config...'; -const // image flags (for LoadImage()) - ifNone = $00000000; // nothing special - ifAlpha = $00000001; // use alpha channel (unused right now?) - ifCritical = $00000002; // image is critical for gameplay (exit game if unable to load) - ifTransparent = $00000004; // image uses transparent pixels (color keying) - ifIgnoreCaps = $00000008; // ignore hardware capabilities when loading (i.e. image will not be drawn using OpenGL) - ifLowRes = $00000010; // try loading a low resolution image when it is critical + // color constants + cWhiteColorChannels : TSDL_Color = (r:$FF; g:$FF; b:$FF; unused:$FF); + cNearBlackColorChannels : TSDL_Color = (r:$00; g:$00; b:$10; unused:$FF); + + cWhiteColor : Longword = $FFFFFFFF; + cYellowColor : Longword = $FFFFFF00; + cExplosionBorderColor : LongWord = $FF808080; -const - cMaxPower = 1500; - cMaxAngle = 2048; - cPowerDivisor = 1500; +{$WARNINGS OFF} + cAirPlaneSpeed: hwFloat = (isNegative: false; QWordValue: 3006477107); // 1.4 + cBombsSpeed : hwFloat = (isNegative: false; QWordValue: 429496729); +{$WARNINGS ON} - MAXNAMELEN = 192; + // image flags (for LoadImage()) + ifNone = $00000000; // nothing special + ifAlpha = $00000001; // use alpha channel (unused right now?) + ifCritical = $00000002; // image is critical for gameplay (exit game if unable to load) + ifTransparent = $00000004; // image uses transparent pixels (color keying) + ifIgnoreCaps = $00000008; // ignore hardware capabilities when loading (i.e. image will not be drawn using OpenGL) + ifLowRes = $00000010; // try loading a low resolution image when it is critical {* REFERENCE 4096 -> $FFFFF000 @@ -211,18 +220,29 @@ COLOR_INDESTRUCTIBLE = $88FF; // red COLOR_OBJECT = $44FF; // no idea + cMaxPower = 1500; + cMaxAngle = 2048; + cPowerDivisor = 1500; + + MAXNAMELEN = 192; + // some opengl headers do not have these macros - GL_BGR = $80E0; - GL_BGRA = $80E1; + GL_BGR = $80E0; + GL_BGRA = $80E1; GL_CLAMP_TO_EDGE = $812F; + cSendCursorPosTime : LongWord = 50; + cVisibleWater : LongInt = 128; + cCursorEdgesDist : LongInt = 100; + cTeamHealthWidth : LongInt = 128; + cWaterOpacity : byte = $80; cifRandomize = $00000001; cifTheme = $00000002; cifMap = $00000002; // either theme or map (or map+theme) cifAllInited = cifRandomize or cifTheme or cifMap; - cTransparentColor: Longword = $000000; + cTransparentColor: Longword = $00000000; cMaxTeams = 6; cMaxHHIndex = 7; @@ -338,6 +358,7 @@ posCaseUtility = $00000004; NoPointX = Low(LongInt); + cTargetPointRef : TPoint = (X: NoPointX; Y: 0); // hog tag mask htNone = $00; @@ -346,7 +367,14 @@ htHealth = $04; htTransparent = $80; - cTagsMasks : array[0..7] of byte = ( + cHHFileName = 'Hedgehog'; + cCHFileName = 'Crosshair'; + cThemeCFGFilename = 'theme.cfg'; + + FontBorder = 2; +var PathPrefix: string; + +const cTagsMasks : array[0..7] of byte = ( htTeamName or htName or htHealth, htName or htHealth, htHealth, @@ -357,10 +385,6 @@ htNone ); - cHHFileName = 'Hedgehog'; - cCHFileName = 'Crosshair'; - cThemeCFGFilename = 'theme.cfg'; - Fontz: array[THWFont] of THHFont = ( (Handle: nil; Height: 12; @@ -388,52 +412,9 @@ Name: 'DroidSansFallback.ttf') ); - FontBorder = 2; - - PathPrefix: string = './'; - Pathz: array[TPathType] of String = ( - '', // ptNone - '', // ptData - 'Graphics', // ptGraphics - 'Themes', // ptThemes - 'Themes/avematan', // ptCurrTheme - 'Teams', // ptTeams - 'Maps', // ptMaps - '', // ptMapCurrent - 'Demos', // ptDemos - 'Sounds', // ptSounds - 'Graphics/Graves', // ptGraves - 'Fonts', // ptFonts - 'Forts', // ptForts - 'Locale', // ptLocale - 'Graphics/AmmoMenu', // ptAmmoMenu - 'Graphics/Hedgehog', // ptHedgehog - 'Sounds/voices', // ptVoices - 'Graphics/Hats' // ptHats - ); - (* - PathzBackup: array[TPathType] of String = ( - '', // ptNone - '', // ptData - 'Graphics', // ptGraphics - 'Themes', // ptThemes - 'Themes/avematan', // ptCurrTheme - 'Teams', // ptTeams - 'Maps', // ptMaps - '', // ptMapCurrent - 'Demos', // ptDemos - 'Sounds', // ptSounds - 'Graphics/Graves', // ptGraves - 'Fonts', // ptFonts - 'Forts', // ptForts - 'Locale', // ptLocale - 'Graphics/AmmoMenu', // ptAmmoMenu - 'Graphics/Hedgehog', // ptHedgehog - 'Sounds/voices', // ptVoices - 'Graphics/Hats' // ptHats - ); - *) - SpritesData: array[TSprite] of record +var Pathz: array[TPathType] of String; + +const SpritesData: array[TSprite] of record FileName: String[14]; Path, AltPath: TPathType; Texture: PTexture; @@ -1634,36 +1615,64 @@ ); -const conversionFormat: TSDL_PixelFormat = ( - palette: nil; - BitsPerPixel : 32; - BytesPerPixel: 4; - Rloss : 0; - Gloss : 0; - Bloss : 0; - Aloss : 0; + conversionFormat: TSDL_PixelFormat = ( + palette: nil; + BitsPerPixel : 32; + BytesPerPixel: 4; + Rloss : 0; + Gloss : 0; + Bloss : 0; + Aloss : 0; {$IFDEF ENDIAN_LITTLE} - Rshift: 0; - Gshift: 8; - Bshift: 16; - Ashift: 24; + Rshift: 0; + Gshift: 8; + Bshift: 16; + Ashift: 24; {$ELSE} - Rshift: 24; - Gshift: 16; - Bshift: 8; - Ashift: 0; + Rshift: 24; + Gshift: 16; + Bshift: 8; + Ashift: 0; {$ENDIF} - RMask : RMask; - GMask : GMask; - BMask : BMask; - AMask : AMask; - colorkey: 0; - alpha : 255 -); + RMask : RMask; + GMask : GMask; + BMask : BMask; + AMask : AMask; + colorkey: 0; + alpha : 255 + ); var CountTexz: array[1..Pred(AMMO_INFINITE)] of PTexture; +procedure init_uConsts; + implementation +procedure init_uConsts; +var cPathz: array[TPathType] of String = ( + '', // ptNone + '', // ptData + 'Graphics', // ptGraphics + 'Themes', // ptThemes + 'Themes/avematan', // ptCurrTheme + 'Teams', // ptTeams + 'Maps', // ptMaps + '', // ptMapCurrent + 'Demos', // ptDemos + 'Sounds', // ptSounds + 'Graphics/Graves', // ptGraves + 'Fonts', // ptFonts + 'Forts', // ptForts + 'Locale', // ptLocale + 'Graphics/AmmoMenu', // ptAmmoMenu + 'Graphics/Hedgehog', // ptHedgehog + 'Sounds/voices', // ptVoices + 'Graphics/Hats' // ptHats + ); +begin + PathPrefix := './'; + Pathz:= cPathz; +end; + end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uGears.pas --- a/hedgewars/uGears.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uGears.pas Mon Jan 18 05:36:08 2010 +0000 @@ -59,6 +59,8 @@ uid: Longword end; +procedure init_uGears; +procedure free_uGears; function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear; procedure ProcessGears; procedure ResetUtilities; @@ -72,24 +74,23 @@ procedure InsertGearToList(Gear: PGear); procedure RemoveGearFromList(Gear: PGear); -var CurAmmoGear: PGear = nil; - GearsList: PGear = nil; - KilledHHs: Longword = 0; - SuddenDeathDmg: Boolean = false; - SpeechType: Longword = 1; +var CurAmmoGear: PGear; + GearsList: PGear; + KilledHHs: Longword; + SuddenDeathDmg: Boolean; + SpeechType: Longword; SpeechText: shortstring; - TrainingTargetGear: PGear = nil; - skipFlag: boolean = false; + TrainingTargetGear: PGear; + skipFlag: boolean; implementation -uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, - uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos, uTriggers, +uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, uLand, uIO, uLandGraphics, + uAIMisc, uLocale, uAI, uAmmos, uTriggers, uStats, uVisualGears, {$IFDEF GLES11} - gles11, + gles11; {$ELSE} - GL, + GL; {$ENDIF} - uStats, uVisualGears; const MAXROPEPOINTS = 384; var RopePoints: record @@ -2041,9 +2042,20 @@ end end; -initialization +procedure init_uGears; +begin + CurAmmoGear:= nil; + GearsList:= nil; + KilledHHs:= 0; + SuddenDeathDmg:= false; + SpeechType:= 1; + TrainingTargetGear:= nil; + skipFlag:= false; +end; -finalization -FreeGearsList; +procedure free_uGears; +begin + FreeGearsList(); +end; end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uIO.pas --- a/hedgewars/uIO.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uIO.pas Mon Jan 18 05:36:08 2010 +0000 @@ -23,7 +23,9 @@ uses SDLh; const ipcPort: Word = 0; +var hiTicks: Word; +procedure init_uIO; procedure SendIPC(s: shortstring); procedure SendIPCXY(cmd: char; X, Y: SmallInt); procedure SendIPCRaw(p: pointer; len: Longword); @@ -37,11 +39,8 @@ procedure CloseIPC; procedure NetGetNextCmd; -var hiTicks: Word = 0; - implementation uses uConsole, uConsts, uWorld, uMisc, uLand, uChat, uTeams; -const isPonged: boolean = false; type PCmd = ^TCmd; TCmd = packed record @@ -54,14 +53,14 @@ 2: (str: shortstring); end; -var - IPCSock: PTCPSocket = nil; +var IPCSock: PTCPSocket; fds: PSDLNet_SocketSet; + isPonged: boolean; - headcmd: PCmd = nil; - lastcmd: PCmd = nil; + headcmd: PCmd; + lastcmd: PCmd; - SendEmptyPacketTicks: LongWord = 0; + SendEmptyPacketTicks: LongWord; function AddCmd(Time: Word; str: shortstring): PCmd; @@ -111,9 +110,9 @@ procedure CloseIPC; begin -SDLNet_FreeSocketSet(fds); -SDLNet_TCP_Close(IPCSock); -SDLNet_Quit + SDLNet_FreeSocketSet(fds); + SDLNet_TCP_Close(IPCSock); + SDLNet_Quit(); end; procedure ParseIPCCommand(s: shortstring); @@ -343,4 +342,16 @@ if isInLag then fastUntilLag:= false end; +procedure init_uIO; +begin + IPCSock:= nil; + + headcmd:= nil; + lastcmd:= nil; + isPonged:= false; // was const + + hiTicks:= 0; + SendEmptyPacketTicks:= 0; +end; + end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uKeys.pas --- a/hedgewars/uKeys.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uKeys.pas Mon Jan 18 05:36:08 2010 +0000 @@ -483,6 +483,5 @@ if pressed then ControllerButtons[joy][button]:= 1 else ControllerButtons[joy][button]:= 0; end; -initialization end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uLand.pas --- a/hedgewars/uLand.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uLand.pas Mon Jan 18 05:36:08 2010 +0000 @@ -20,26 +20,28 @@ unit uLand; interface -uses SDLh, uLandTemplates, uFloat, +uses SDLh, uLandTemplates, uFloat, uConsts, {$IFDEF GLES11} - gles11, + gles11; {$ELSE} - GL, + GL; {$ENDIF} - uConsts; + type TLandArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of LongWord; TCollisionArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of Word; TPreview = packed array[0..127, 0..31] of byte; TDirtyTag = packed array[0 .. LAND_HEIGHT div 32 - 1, 0 .. LAND_WIDTH div 32 - 1] of byte; -var Land: TCollisionArray; - LandPixels: TLandArray; - LandDirty: TDirtyTag; - hasBorder: boolean; - hasGirders: boolean; - playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword; // idea is that a template can specify height/width. Or, a map, a height/width by the dimensions of the image. If the map has pixels near top of image, it triggers border. - LandBackSurface: PSDL_Surface = nil; +var Land: TCollisionArray; + LandPixels: TLandArray; + LandDirty: TDirtyTag; + hasBorder: boolean; + hasGirders: boolean; + playHeight, playWidth, leftX, rightX, topY, MaxHedgehogs: Longword; // idea is that a template can specify height/width. Or, a map, a height/width by the dimensions of the image. If the map has pixels near top of image, it triggers border. + LandBackSurface: PSDL_Surface; +procedure init_uLand; +procedure free_uLand; procedure GenMap; function GenPreview: TPreview; procedure CheckLandDigest(s: shortstring); @@ -315,10 +317,10 @@ if LandBackSurface = nil then LandBackPixel:= 0 else - begin + begin p:= LandBackSurface^.pixels; LandBackPixel:= p^[LandBackSurface^.w * (y mod LandBackSurface^.h) + (x mod LandBackSurface^.w)];// or $FF000000; - end + end end; procedure ColorizeLand(Surface: PSDL_Surface); @@ -849,9 +851,15 @@ GenPreview:= Preview end; -initialization +procedure init_uLand; +begin + LandBackSurface:= nil; +end; -finalization -if LandBackSurface <> nil then - SDL_FreeSurface(LandBackSurface); +procedure free_uLand; +begin + if LandBackSurface <> nil then + SDL_FreeSurface(LandBackSurface); +end; + end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uLandObjects.pas --- a/hedgewars/uLandObjects.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uLandObjects.pas Mon Jan 18 05:36:08 2010 +0000 @@ -28,13 +28,13 @@ procedure AddOnLandObjects(Surface: PSDL_Surface); implementation -uses uLand, uStore, uConsts, uMisc, uConsole, uRandom, uVisualGears, uFloat, +uses uLand, uStore, uConsts, uMisc, uConsole, uRandom, uVisualGears, uFloat, uSound, uWorld, {$IFDEF GLES11} - gles11, + gles11; {$ELSE} - GL, + GL; {$ENDIF} - uSound, uWorld; + const MaxRects = 512; MAXOBJECTRECTS = 16; MAXTHEMEOBJECTS = 32; diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uLandTexture.pas --- a/hedgewars/uLandTexture.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uLandTexture.pas Mon Jan 18 05:36:08 2010 +0000 @@ -27,13 +27,13 @@ procedure FreeLand; implementation -uses uMisc, uLand, uStore, +uses uMisc, uLand, uStore, uConsts, {$IFDEF GLES11} - gles11, + gles11; {$ELSE} - GL, + GL; {$ENDIF} - uConsts; + const TEXSIZE = 256; LANDTEXARW = LAND_WIDTH div TEXSIZE; diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uMisc.pas Mon Jan 18 05:36:08 2010 +0000 @@ -21,175 +21,148 @@ unit uMisc; interface -uses uConsts, SDLh, +uses SDLh, uConsts, uFloat, {$IFDEF GLES11} - gles11, + gles11; {$ELSE} - GL, + GL; {$ENDIF} - uFloat -{$IFDEF IPHONEOS} - , PascalExports -{$ENDIF} - ; - -type HwColor4f = record - r, g, b, a: byte - end; var - isCursorVisible : boolean = false; - isTerminated : boolean = false; - isInLag : boolean = false; - isPaused : boolean = false; - isSoundEnabled : boolean = true; - isMusicEnabled : boolean = false; - isSEBackup : boolean = true; - isInMultiShoot : boolean = false; - isSpeed : boolean = false; - - fastUntilLag : boolean = false; + isCursorVisible : boolean; + isTerminated : boolean; + isInLag : boolean; + isPaused : boolean; + isSoundEnabled : boolean; + isMusicEnabled : boolean; + isSEBackup : boolean; + isInMultiShoot : boolean; + isSpeed : boolean; - GameState : TGameState = Low(TGameState); - GameType : TGameType = gmtLocal; - GameFlags : Longword = 0; - TrainingFlags : Longword = 0; - TurnTimeLeft : Longword = 0; - cSuddenDTurns : LongInt = 15; - cDamagePercent : LongInt = 100; - cTemplateFilter : LongInt = 0; + fastUntilLag : boolean; - cHedgehogTurnTime: Longword = 45000; - cMinesTime : LongInt = 3000; - cMaxAIThinkTime : Longword = 9000; + GameState : TGameState; + GameType : TGameType; + GameFlags : Longword; + TrainingFlags : Longword; + TurnTimeLeft : Longword; + cSuddenDTurns : LongInt; + cDamagePercent : LongInt; + cTemplateFilter : LongInt; - cCloudsNumber : LongInt = 9; - cScreenWidth : LongInt = 1024; - cScreenHeight : LongInt = 768; - cInitWidth : LongInt = 1024; - cInitHeight : LongInt = 768; - cVSyncInUse : boolean = true; - cBits : LongInt = 32; - cBitsStr : string[2] = '32'; - cTagsMaskIndex : byte = Low(cTagsMasks); - zoom : GLfloat = 2.0; - ZoomValue : GLfloat = 2.0; + cHedgehogTurnTime: Longword; + cMinesTime : LongInt; + cMaxAIThinkTime : Longword; - cWaterLine : LongInt = LAND_HEIGHT; - cVisibleWater : LongInt = 128; - cGearScrEdgesDist: LongInt = 240; - cCursorEdgesDist : LongInt = 100; - cTeamHealthWidth : LongInt = 128; - cAltDamage : boolean = true; + cCloudsNumber : LongInt; + cScreenWidth : LongInt; + cScreenHeight : LongInt; + cInitWidth : LongInt; + cInitHeight : LongInt; + cVSyncInUse : boolean; + cBits : LongInt; + cBitsStr : string[2]; + cTagsMaskIndex : byte; + zoom : GLfloat; + ZoomValue : GLfloat; - GameTicks : LongWord = 0; - TrainingTimeInc: Longword = 10000; - TrainingTimeInD: Longword = 500; - TrainingTimeInM: Longword = 5000; - TrainingTimeMax: Longword = 60000; + cWaterLine : LongInt; + cGearScrEdgesDist: LongInt; + cAltDamage : boolean; - TimeTrialStartTime: Longword = 0; - TimeTrialStopTime : Longword = 0; - - cWhiteColorChannels : TSDL_Color = (r:$FF; g:$FF; b:$FF; unused:$FF); - cNearBlackColorChannels : TSDL_Color = (r:$00; g:$00; b:$10; unused:$FF); + GameTicks : LongWord; + TrainingTimeInc : Longword; + TrainingTimeInD : Longword; + TrainingTimeInM : Longword; + TrainingTimeMax : Longword; - cWhiteColor : Longword = $FFFFFFFF; - cYellowColor : Longword = $FFFFFF00; - cExplosionBorderColor : LongWord = $FF808080; + TimeTrialStartTime: Longword; + TimeTrialStopTime : Longword; + + recordFileName : shortstring; + cShowFPS : boolean; + cCaseFactor : Longword; + cLandAdditions : Longword; + cFullScreen : boolean; + cReducedQuality : boolean; + cLocaleFName : shortstring; + cSeed : shortstring; + cInitVolume : LongInt; + cVolumeDelta : LongInt; + cTimerInterval : Longword; + cHasFocus : boolean; + cInactDelay : Longword; -var recordFileName : shortstring = ''; - cShowFPS : boolean = false; - cCaseFactor : Longword = 5; {0..9} - cLandAdditions: Longword = 4; - cFullScreen : boolean = false; - cReducedQuality : boolean = false; - cLocaleFName : shortstring = 'en.txt'; - cSeed : shortstring = ''; - cInitVolume : LongInt = 50; - cVolumeDelta : LongInt = 0; - cTimerInterval: Longword = 8; - cHasFocus : boolean = true; - cInactDelay : Longword = 1250; - - bBetweenTurns: boolean = false; - cHealthDecrease: LongWord = 0; - bWaterRising : Boolean = false; - -{$WARNINGS OFF} - cAirPlaneSpeed: hwFloat = (isNegative: false; QWordValue: 3006477107); // 1.4 - cBombsSpeed : hwFloat = (isNegative: false; QWordValue: 429496729); -{$WARNINGS ON} + bBetweenTurns : boolean; + cHealthDecrease : LongWord; + bWaterRising : Boolean; - cSendCursorPosTime : LongWord = 50; - ShowCrosshair : boolean; - CursorMovementX : Integer = 0; - CursorMovementY : Integer = 0; - cDrownSpeed, - cMaxWindSpeed, - cWindSpeed, - cGravity: hwFloat; - cDamageModifier: hwFloat; - cLaserSighting: boolean; - cVampiric: boolean; - cArtillery: boolean; + ShowCrosshair : boolean; + CursorMovementX : Integer; + CursorMovementY : Integer; + cDrownSpeed : hwFloat; + cMaxWindSpeed : hwFloat; + cWindSpeed : hwFloat; + cGravity : hwFloat; + cDamageModifier : hwFloat; + cLaserSighting : boolean; + cVampiric : boolean; + cArtillery : boolean; - flagMakeCapture: boolean = false; - - InitStepsFlags: Longword = 0; + flagMakeCapture : boolean; - RealTicks: Longword = 0; + InitStepsFlags : Longword; + RealTicks : Longword; + AttackBar : LongInt; - AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP + WaterColorArray : array[0..3] of HwColor4f; - i: LongInt; - - cWaterOpacity: byte = $80; - WaterColorArray: array[0..3] of HwColor4f; + CursorPoint : TPoint; + TargetPoint : TPoint; + - CursorPoint: TPoint; - TargetPoint: TPoint = (X: NoPointX; Y: 0); - +procedure init_uMisc; +procedure free_uMisc; procedure movecursor(dx, dy: Integer); -function hwSign(r: hwFloat): LongInt; -function Min(a, b: LongInt): LongInt; -function Max(a, b: LongInt): LongInt; +function hwSign(r: hwFloat): LongInt; +function Min(a, b: LongInt): LongInt; +function Max(a, b: LongInt): LongInt; procedure OutError(Msg: String; isFatalError: boolean); procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); procedure SDLTry(Assert: boolean; isFatal: boolean); -function IntToStr(n: LongInt): shortstring; -function FloatToStr(n: hwFloat): shortstring; -function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; -function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; -function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; +function IntToStr(n: LongInt): shortstring; +function FloatToStr(n: hwFloat): shortstring; +function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; +function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; +function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; procedure AdjustColor(var Color: Longword); -{$IFDEF DEBUGFILE} -procedure AddFileLog(s: shortstring); -function RectToStr(Rect: TSDL_Rect): shortstring; -{$ENDIF} procedure SetKB(n: Longword); procedure SendKB; procedure SetLittle(var r: hwFloat); procedure SendStat(sit: TStatInfoType; s: shortstring); function Str2PChar(const s: shortstring): PChar; -function NewTexture(width, height: Longword; buf: Pointer): PTexture; +function NewTexture(width, height: Longword; buf: Pointer): PTexture; function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; procedure FreeTexture(tex: PTexture); function toPowerOf2(i: Longword): Longword; function DecodeBase64(s: shortstring): shortstring; function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; function endian(independent: LongWord): LongWord; +function modifyDamage(dmg: Longword): Longword; +{$IFDEF DEBUGFILE} +procedure AddFileLog(s: shortstring); +function RectToStr(Rect: TSDL_Rect): shortstring; +{$ENDIF} {$IFNDEF IPHONEOS} procedure MakeScreenshot(s: shortstring); {$ENDIF} -function modifyDamage(dmg: Longword): Longword; - implementation -uses uConsole, uStore, uIO, Math, uRandom, uSound; -var KBnum: Longword = 0; +uses Math, uConsole, uStore, uIO, uRandom, uSound; + +var KBnum: Longword; {$IFDEF DEBUGFILE} -var f: textfile; + f: textfile; {$ENDIF} procedure movecursor(dx, dy: Integer); @@ -574,50 +547,130 @@ {$ENDIF} end; -initialization -cDrownSpeed.QWordValue:= 257698038;// 0.06 -cMaxWindSpeed.QWordValue:= 2147484;// 0.0005 -cWindSpeed.QWordValue:= 429496;// 0.0001 -cGravity:= cMaxWindSpeed; -cDamageModifier:= _1; -cLaserSighting:= false; -cVampiric:= false; -cArtillery:= false; + +procedure init_uMisc; +var i: LongInt; +begin + cDrownSpeed.QWordValue := 257698038; // 0.06 + cMaxWindSpeed.QWordValue:= 2147484; // 0.0005 + cWindSpeed.QWordValue := 429496; // 0.0001 + cGravity := cMaxWindSpeed; + cDamageModifier := _1; + TargetPoint := cTargetPointRef; + + // int, longint longword and byte + CursorMovementX := 0; + CursorMovementY := 0; + GameTicks := 0; + TrainingTimeInc := 10000; + TrainingTimeInD := 500; + TrainingTimeInM := 5000; + TrainingTimeMax := 60000; + TimeTrialStartTime := 0; + TimeTrialStopTime := 0; + cWaterLine := LAND_HEIGHT; + cGearScrEdgesDist := 240; + cHealthDecrease := 0; + + GameFlags := 0; + TrainingFlags := 0; + TurnTimeLeft := 0; + cSuddenDTurns := 15; + cDamagePercent := 100; + cTemplateFilter := 0; + + cHedgehogTurnTime := 45000; + cMinesTime := 3000; + cMaxAIThinkTime := 9000; + + cCloudsNumber := 9; + cScreenWidth := 1024; + cScreenHeight := 768; + cInitWidth := cScreenWidth; + cInitHeight := cScreenHeight; + cBits := 32; + cTagsMaskIndex := Low(cTagsMasks); + KBnum := 0; + InitStepsFlags := 0; + RealTicks := 0; + AttackBar := 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP + + // tgametype and glfloat and string + GameState := Low(TGameState); + GameType := gmtLocal; + zoom := 2.0; + ZoomValue := 2.0; + cBitsStr := '32'; + + // booleans + cLaserSighting := false; + cVampiric := false; + cArtillery := false; + flagMakeCapture := false; + bBetweenTurns := false; + bWaterRising := false; + isCursorVisible := false; + isTerminated := false; + isInLag := false; + isPaused := false; + isMusicEnabled := false; + isInMultiShoot := false; + isSpeed := false; + fastUntilLag := false; + cVSyncInUse := true; + isSoundEnabled := true; + isSEBackup := true; + + // init flags + recordFileName := ''; + cShowFPS := false; + cCaseFactor := 5; {0..9} + cLandAdditions := 4; + cFullScreen := false; + cReducedQuality := false; + cLocaleFName := 'en.txt'; + cSeed := ''; + cInitVolume := 50; + cVolumeDelta := 0; + cTimerInterval := 8; + cHasFocus := true; + cInactDelay := 1250; + cAltDamage := true; {$IFDEF DEBUGFILE} {$I-} -for i:= 0 to 7 do -begin -{$IFDEF IPHONEDBG} +{$IFDEF IPHONEOS} f:= stderr; {$ELSE} - assign(f, - {$IFDEF IPHONEOS} - string(IPH_getDocumentsPath()) - {$ELSE} - ParamStr(1) - {$ENDIF} - + '/debug' + inttostr(i) + '.txt'); -{$ENDIF} - rewrite(f); - if IOResult = 5 then + for i:= 0 to 7 do begin - // prevent writing on a directory you do not have permissions on - // should be safe to assume the current directory is writable - assign(f, './debug' + inttostr(i) + '.txt'); + assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); rewrite(f); + if IOResult = 5 then + begin + // prevent writing on a directory you do not have permissions on + // should be safe to assume the current directory is writable + assign(f, './debug' + inttostr(i) + '.txt'); + rewrite(f); + end; + if IOResult = 0 then break; end; - if IOResult = 0 then break -end; +{$ENDIF} + {$I+} +{$ENDIF} -finalization +end; + +procedure free_uMisc; +begin //uRandom.DumpBuffer; +{$IFDEF DEBUGFILE} writeln(f, 'halt at ', GameTicks, ' ticks. TurnTimeLeft = ', TurnTimeLeft); flush(f); -close(f) - +close(f); {$ENDIF} +end; end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uRandom.pas --- a/hedgewars/uRandom.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uRandom.pas Mon Jan 18 05:36:08 2010 +0000 @@ -23,6 +23,7 @@ uses uFloat; {$INCLUDE "proto.inc"} +procedure init_uRandom; procedure SetRandomSeed(Seed: shortstring); function GetRandom: hwFloat; overload; function GetRandom(m: LongWord): LongWord; overload; @@ -36,7 +37,7 @@ uses uMisc; {$ENDIF} var cirbuf: array[0..63] of Longword; - n: byte = 54; + n: byte; function GetNext: Longword; begin @@ -93,4 +94,9 @@ end; {$ENDIF} +procedure init_uRandom; +begin + n:= 54; +end; + end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uStore.pas --- a/hedgewars/uStore.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uStore.pas Mon Jan 18 05:36:08 2010 +0000 @@ -20,14 +20,31 @@ unit uStore; interface -uses sysutils, uConsts, uTeams, SDLh, +uses sysutils, uConsts, uTeams, SDLh, uFloat, {$IFDEF GLES11} - gles11, + gles11; {$ELSE} - GL, GLext, + GL, GLext; {$ENDIF} -uFloat; + +var PixelFormat: PSDL_PixelFormat; + SDLPrimSurface: PSDL_Surface; + PauseTexture, + SyncTexture, + ConfirmTexture: PTexture; + cScaleFactor: GLfloat; + SupportNPOTT: Boolean; + Step: LongInt; + squaresize : LongInt; + numsquares : LongInt; +{$IFDEF SDL13notworking} + ProgrTex: TSDL_TextureID; +{$ELSE} + ProgrTex: PTexture; +{$ENDIF} + +procedure init_uStore; procedure StoreLoad; procedure StoreRelease; procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); @@ -60,26 +77,14 @@ procedure SetScale(f: GLfloat); -var PixelFormat: PSDL_PixelFormat = nil; - SDLPrimSurface: PSDL_Surface = nil; - PauseTexture, - SyncTexture, - ConfirmTexture: PTexture; - cScaleFactor: GLfloat = 2.0; - SupportNPOTT: Boolean = false; - implementation -uses uMisc, uConsole, uLand, uLocale, uWorld - {$IFDEF IPHONEOS} - , PascalExports - {$ENDIF} - ; +uses uMisc, uConsole, uLand, uLocale, uWorld{$IFDEF IPHONEOS}, PascalExports{$ENDIF}; type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel); -var HHTexture: PTexture; - MaxTextureSize: Integer; - {$IFNDEF IPHONEOS}cGPUVendor: TGPUVendor = gvUnknown;{$ENDIF} +var HHTexture: PTexture; + MaxTextureSize: Integer; + {$IFNDEF IPHONEOS}cGPUVendor: TGPUVendor;{$ENDIF} procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); var r: TSDL_Rect; @@ -1165,15 +1170,6 @@ end; //////////////////////////////////////////////////////////////////////////////// -var Step: LongInt = 0; - squaresize : LongInt; - numsquares : LongInt; -{$IFDEF SDL13notworking} - ProgrTex: TSDL_TextureID = 0; -{$ELSE} - ProgrTex: PTexture = nil; -{$ENDIF} - procedure AddProgress; var r: TSDL_Rect; texsurf: PSDL_Surface; @@ -1306,4 +1302,20 @@ end; end; +procedure init_uStore; +begin + PixelFormat:= nil; + SDLPrimSurface:= nil; + {$IFNDEF IPHONEOS}cGPUVendor:= gvUnknown;{$ENDIF} + + cScaleFactor:= 2.0; + SupportNPOTT:= false; + Step:= 0; +{$IFDEF SDL13notworking} + ProgrTex:= 0; +{$ELSE} + ProgrTex:= nil; +{$ENDIF} +end; + end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uTeams.pas Mon Jan 18 05:36:08 2010 +0000 @@ -87,16 +87,18 @@ TurnNumber: LongWord; end; -var CurrentTeam: PTeam = nil; - PreviousTeam: PTeam = nil; - CurrentHedgehog: PHedgehog = nil; - TeamsArray: array[0..Pred(cMaxTeams)] of PTeam; - TeamsCount: Longword = 0; - ClansArray: array[0..Pred(cMaxTeams)] of PClan; - ClansCount: Longword = 0; - LocalClan: Longword = 0; // first non-bot, non-extdriven clan - CurMinAngle, CurMaxAngle: Longword; +var CurrentTeam: PTeam; + PreviousTeam: PTeam; + CurrentHedgehog: PHedgehog; + TeamsArray: array[0..Pred(cMaxTeams)] of PTeam; + TeamsCount: Longword; + ClansArray: array[0..Pred(cMaxTeams)] of PClan; + ClansCount: Longword; + LocalClan: Longword; // first non-bot, non-extdriven clan + CurMinAngle, CurMaxAngle: Longword; +procedure init_uTeams; +procedure free_uTeams; function AddTeam(TeamColor: Longword): PTeam; procedure SwitchHedgehog; procedure AfterSwitchHedgehog; @@ -402,10 +404,19 @@ Gear^.Damage:= Gear^.Health end; -initialization +procedure init_uTeams; +begin + CurrentTeam:= nil; + PreviousTeam:= nil; + CurrentHedgehog:= nil; + TeamsCount:= 0; + ClansCount:= 0; + LocalClan:= 0; // first non-bot, non-extdriven clan +end; -finalization - -FreeTeamsList +procedure free_uTeams; +begin + FreeTeamsList() +end; end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uTriggers.pas --- a/hedgewars/uTriggers.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uTriggers.pas Mon Jan 18 05:36:08 2010 +0000 @@ -25,6 +25,7 @@ type TTrigAction = (taSpawnGear, taSuccessFinish, taFailFinish); +procedure init_uTriggers; procedure AddTriggerSpawner(id, Ticks, Lives: Longword; GearType: TGearType; X, Y: LongInt; GearTriggerId: Longword); procedure AddTriggerSuccess(id, Ticks, Lives: Longword); procedure AddTriggerFail(id, Ticks, Lives: Longword); @@ -44,7 +45,7 @@ SpawnGearTriggerId: Longword; Next: PTrigger; end; -var TriggerList: PTrigger = nil; +var TriggerList: PTrigger; function AddTrigger(id, Ticks, Lives: Longword): PTrigger; var tmp: PTrigger; @@ -143,4 +144,9 @@ end end; +procedure init_uTriggers; +begin + TriggerList:= nil; +end; + end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uVisualGears.pas --- a/hedgewars/uVisualGears.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uVisualGears.pas Mon Jan 18 05:36:08 2010 +0000 @@ -20,13 +20,12 @@ unit uVisualGears; interface -uses SDLh, uConsts, +uses SDLh, uConsts, uFloat, {$IFDEF GLES11} - gles11, + gles11; {$ELSE} - GL, + GL; {$ENDIF} - uFloat; type PVisualGear = ^TVisualGear; TVGearStepProcedure = procedure (Gear: PVisualGear; Steps: Longword); @@ -48,6 +47,7 @@ Text: shortstring end; +procedure init_uVisualGears; function AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear; procedure ProcessVisualGears(Steps: Longword); procedure DrawVisualGears(Layer: LongWord); @@ -55,9 +55,9 @@ procedure AddClouds; procedure AddDamageTag(X, Y, Damage, Color: LongWord); -var VisualGearsList: PVisualGear = nil; - vobFrameTicks, vobFramesCount: Longword; - vobVelocity, vobFallSpeed: LongInt; +var VisualGearsList: PVisualGear; + vobFrameTicks, vobFramesCount: Longword; + vobVelocity, vobFallSpeed: LongInt; implementation uses uWorld, uMisc, uStore, uTeams, uSound; @@ -518,8 +518,10 @@ AddVisualGear( - cScreenWidth + i * ((cScreenWidth * 2 + (LAND_WIDTH+256)) div (cCloudsNumber + 1)), LAND_HEIGHT-1184, vgtCloud) end; -initialization +procedure init_uVisualGears; +begin + VisualGearsList:= nil; +end; -finalization end. diff -r 90585aba87ad -r 249adefa9c1c hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Sat Jan 16 17:30:37 2010 +0000 +++ b/hedgewars/uWorld.pas Mon Jan 18 05:36:08 2010 +0000 @@ -25,6 +25,7 @@ const WorldDx: LongInt = -512; WorldDy: LongInt = -256; +procedure init_uWorld; procedure InitWorld; procedure DrawWorld(Lag: LongInt); procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); @@ -32,22 +33,21 @@ {$IFDEF COUNTTICKS} var cntTicks: LongWord; {$ENDIF} -var FollowGear: PGear = nil; - WindBarWidth: LongInt = 0; - bShowAmmoMenu: boolean = false; - bSelected: boolean = false; - bShowFinger: boolean = false; - Frames: Longword = 0; - WaterColor, DeepWaterColor: TSDL_Color; +var FollowGear: PGear; + WindBarWidth: LongInt; + bShowAmmoMenu: boolean; + bSelected: boolean; + bShowFinger: boolean; + Frames: Longword; + WaterColor, DeepWaterColor: TSDL_Color; implementation -uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, +uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, uAmmos, uVisualGears, uChat, uLandTexture, uLand, {$IFDEF GLES11} - gles11, + gles11; {$ELSE} - GL, + GL; {$ENDIF} - uAmmos, uVisualGears, uChat, uLandTexture, uLand; const FPS: Longword = 0; CountTicks: Longword = 0; @@ -60,10 +60,10 @@ end; var cWaveWidth, cWaveHeight: LongInt; - Captions: array[TCapGroup] of TCaptionStr; - AMxShift, SlotsNum: LongInt; - tmpSurface: PSDL_Surface; - fpsTexture: PTexture = nil; + Captions: array[TCapGroup] of TCaptionStr; + AMxShift, SlotsNum: LongInt; + tmpSurface: PSDL_Surface; + fpsTexture: PTexture; procedure InitWorld; begin @@ -723,7 +723,17 @@ if WorldDx > 1024 then WorldDx:= 1024; end; -initialization -FillChar(Captions, sizeof(Captions), 0) +procedure init_uWorld; +begin + fpsTexture:= nil; + FollowGear:= nil; + WindBarWidth:= 0; + bShowAmmoMenu:= false; + bSelected:= false; + bShowFinger:= false; + Frames:= 0; + + FillChar(Captions, sizeof(Captions), 0) +end; end.