Show GameSettings.pas syntax highlighted
//*******************************//
// //
// Strange Game Profile Settings //
// //
//******************//*******************************//*********************//
// //
// This unit is the part of a real time 3d space strategy engine //
// (www.federation.netfirms.com) //
// //
//**************************************************************************//
{
Author : Alexander Federyakov aka Da Stranger
Version : 0.001 ;-]
Date : 22 November '2005
License : You can use this unit ONLY for educational purposes. You cannot use
more than 10% of its code in your own personal projects. It cannot
be used for any commercial products.
Comments: This is the core of a 3d realtime space strategy game engine.
Much is still to be done...
Requirements: GLScene
Known Bugs and limitations: none
Contacts:
Web: http://www.sector-37.com
E-mail: datarget@mail.ru
ICQ: 293-963-070
Odigo: 8077227
}
unit GameSettings;
interface
uses iniFiles,SysUtils,
VectorTypes,
GLKeyboard,
StrangeMouseEmulator,
GameConstants,
StrangeIniFiles;
type
TProfile = class;
TVideoSettings = class (TPrimitiveErrorHandlerClass)
UseCurrentResolution : Boolean;
ScreenWidth : integer;
ScreenHeight : integer;
MultiProxyNearDistance : single;
MultiProxyMediumDistance : single;
MultiProxyFarDistance : single;
EveryTextureScale: byte;
MediumTextureScale: byte;
FarTextureScale: byte;
MeshQuality: byte; //MQ_XXX constants
BlowUpModelQuality: byte; //BUMQ_XXX constants
ExplosionsQuality: byte; //EQ_XXX constants
procedure LoadFromIni(ini : TStrangeIniFile; Section : String);
end;
TAudioSettings = class
EnableMusic : Boolean;
//more to come...
procedure LoadFromIni(ini : TStrangeIniFile; Section : String);
end;
TGeneralSettings = class //will hold all game options
SplitScreenMode : Boolean;
FullScreenMode : Boolean;
QuickSavePeriod : byte; //in minutes;
QuickSaveFile : string; //there will be 2-4 files, each next one will replace previous one
AddLastDotOnKeyPress : Boolean; //conserns unit commands OP_MOVE, OP_PATROL,
//OP_MOVE_AND_ATTACK, OP_MOVE_BY_WAYPOINTS
SectorSize : TVector3f;
procedure LoadFromIni(ini : TStrangeIniFile; Section : String);
end;
TPlayerControls = class(TPrimitiveErrorHandlerClass)
public
Profile: TProfile;
NavigateForward,
NavigateBackward,
NavigateStrafeLeft,
NavigateStrafeRight,
NavigateUp,
NavigateDown : byte;
NavigateAccelerateMultiplier,
NavigateSpeed : single;
UIInvertMouse : Boolean;
UIMouseSpeed : single;
TurnInertia: single;
MovementInertia: single;
MaxTurnAngle: single;
MoveAroundTargetMult: single;
MoveAroundTargetInertia: single;
MaxMoveAroundTargetAngle: single;
ShowTacticMap,
ShowConsole,
Cancel,
Pause,
UnitAgressiveMode,
UnitDefensiveMode,
UnitBlowUp,
UnitStop,
UnitMove,
UnitPatrol,
UnitWaypointMove,
UnitFollowAndDefend,
MovementManagerDebugMode,
CollisionManagerDebugMode: byte;
procedure LoadFromIni(ini : TStrangeIniFile; Section : String);
constructor Create(WhatProfile: TProfile);
Destructor Destroy; override;
end;
TProfile = class(TGameErrorHandlerClass)
public
FileName : string;
RealName : string;
GeneralSettings : TGeneralSettings;
VideoSettings : TVideoSettings;
AudioSettings : TAudioSettings;
MouseEmulatorControls : TStrangeMouseControls;
KeyboardPlayerControls : TPlayerControls;
MousePlayerControls : TPlayerControls;
JoystickPlayerControls : TPlayerControls;
procedure LoadFromFile(FilePath : string);
constructor Create;
Destructor Destroy; override;
end;
implementation
function LoadFromQualityString(Str: string): byte;
begin
if Str = 'high' then
Result := 0
else if Str = 'medium' then
Result := 1
else if Str = 'low' then
Result := 2
else
Result := 255;
end;
{ TProfile }
constructor TProfile.Create;
begin
MouseEmulatorControls := TStrangeMouseControls.Create(nil);
KeyboardPlayerControls := TPlayerControls.Create(self);
MousePlayerControls := TPlayerControls.Create(self);
JoystickPlayerControls := TPlayerControls.Create(self);
GeneralSettings := TGeneralSettings.Create;
VideoSettings := TVideoSettings.Create;
AudioSettings := TAudioSettings.Create;
end;
destructor TProfile.Destroy;
begin
GeneralSettings.Destroy;
VideoSettings.Destroy;
AudioSettings.Destroy;
MouseEmulatorControls.Destroy;
KeyboardPlayerControls.Destroy;
MousePlayerControls.Destroy;
JoystickPlayerControls.Destroy;
inherited;
end;
procedure TProfile.LoadFromFile(FilePath:string);
var
ProfileIni: TStrangeIniFile;
begin
ProfileIni := TStrangeIniFile.Create(FilePath);
//set its RealName and FileName
RealName := ProfileIni.ReadString(str_GENERAL,str_REAL_NAME,RealName);
FileName := ExtractFilePath(FilePath);
setLength(FileName,Length(FileName)-1);
FileName := ExtractFileName(FileName);
//general settings
if not ProfileIni.SectionExists(str_GENERAL_SETTINGS) then
MakeError(str_ERROR_READING_SECTION + str_GENERAL_SETTINGS + str_FROM_FILE + ProfileIni.FileName + str_IT_DOES_NOT_EXIST,ERR_BAD_INI);
GeneralSettings.LoadFromIni(ProfileIni, str_GENERAL_SETTINGS);
//video settings
if not ProfileIni.SectionExists(str_VIDEO_SETTINGS) then
MakeError(str_ERROR_READING_SECTION + str_VIDEO_SETTINGS + str_FROM_FILE + ProfileIni.FileName + str_IT_DOES_NOT_EXIST,ERR_BAD_INI);
VideoSettings.LoadFromIni(ProfileIni, str_VIDEO_SETTINGS);
//audio settings
if not ProfileIni.SectionExists(str_AUDIO_SETTINGS) then
MakeError(str_ERROR_READING_SECTION + str_AUDIO_SETTINGS + str_FROM_FILE + ProfileIni.FileName + str_IT_DOES_NOT_EXIST,ERR_BAD_INI);
AudioSettings.LoadFromIni(ProfileIni, str_AUDIO_SETTINGS);
//Keyboard Player Settings
if not ProfileIni.SectionExists(str_KEYBOARD_PLAYER_CONTROLS) then
MakeError(str_ERROR_READING_SECTION + str_KEYBOARD_PLAYER_CONTROLS + str_FROM_FILE + ProfileIni.FileName + str_IT_DOES_NOT_EXIST,ERR_BAD_INI);
KeyboardPlayerControls.LoadFromIni(ProfileIni,str_KEYBOARD_PLAYER_CONTROLS);
MouseEmulatorControls.LoadFromMemIni(TStrangeMemIniFile(ProfileIni),str_KEYBOARD_PLAYER_CONTROLS);
//Mouse Player Settings
if not ProfileIni.SectionExists(str_MOUSE_PLAYER_CONTROLS) then
MakeError(str_ERROR_READING_SECTION + str_MOUSE_PLAYER_CONTROLS + str_FROM_FILE + ProfileIni.FileName + str_IT_DOES_NOT_EXIST,ERR_BAD_INI);
MousePlayerControls.LoadFromIni(ProfileIni,str_MOUSE_PLAYER_CONTROLS);
//Joystick Player Settings
//if not ProfileIni.SectionExists(str_JOYSTICK_PLAYER_CONTROLS) then
// MakeError(str_ERROR_READING_SECTION + str_JOYSTICK_PLAYER_CONTROLS + str_FROM_FILE + ProfileIni.FileName + str_IT_DOES_NOT_EXIST,ERR_BAD_INI);
//JoystickPlayerControls.LoadFromIni(ProfileIni,str_JOYSTICK_PLAYER_CONTROLS);
{ TODO -oDa Stranger -cJoystick : Joystick }
ProfileIni.Free;
end;
{ TPlayerControls }
constructor TPlayerControls.Create(WhatProfile: TProfile);
begin
Profile := WhatProfile;
end;
destructor TPlayerControls.Destroy;
begin
//
inherited;
end;
procedure TPlayerControls.LoadFromIni(ini: TStrangeIniFile; Section: String);
begin
try
NavigateForward := ini.ReadKeyboardKey(Section,'NavigateForward', 0);
NavigateBackward := ini.ReadKeyboardKey(Section,'NavigateBackward', 0);
NavigateStrafeLeft := ini.ReadKeyboardKey(Section,'NavigateStrafeLeft', 0);
NavigateStrafeRight := ini.ReadKeyboardKey(Section,'NavigateStrafeRight', 0);
NavigateUp := ini.ReadKeyboardKey(Section,'NavigateUp', 0);
NavigateDown := ini.ReadKeyboardKey(Section,'NavigateDown', 0);
except
on Exception do
MakeError('Invalid Buttonz',ERR_EXTERNAL_MODULE);
end;
NavigateAccelerateMultiplier := ini.ReadFloat(Section,'NavigateAccelerateMultiplier ',0);
NavigateSpeed := ini.ReadFloat(Section,'NavigateSpeed',0);
UIMouseSpeed := ini.ReadFloat(Section,'UIMouseSpeed',UIMouseSpeed);
UIInvertMouse := ini.ReadBool(Section,'UIInvertMouse',UIInvertMouse);
TurnInertia := ini.ReadFloat(Section,'TurnInertia',TurnInertia);
MovementInertia := ini.ReadFloat(Section,'MovementInertia',MovementInertia);
MaxTurnAngle := ini.ReadFloat(Section,'MaxTurnAngle',MaxTurnAngle);
MoveAroundTargetMult := ini.ReadFloat(Section,'MoveAroundTargetMult',MoveAroundTargetMult);
MoveAroundTargetInertia := ini.ReadFloat(Section,'MoveAroundTargetInertia',MoveAroundTargetInertia);
MaxMoveAroundTargetAngle := ini.ReadFloat(Section,'MaxMoveAroundTargetAngle',MaxMoveAroundTargetAngle);
ShowTacticMap := ini.ReadKeyboardKey(Section,'ShowTacticMap', 0);
ShowConsole := ini.ReadKeyboardKey(Section,'ShowConsole', 0);
Cancel := ini.ReadKeyboardKey(Section,'Cancel', 0);
Pause := ini.ReadKeyboardKey(Section,'Pause', 0);
UnitAgressiveMode := ini.ReadKeyboardKey(Section,'UnitAgressiveMode', 0);
UnitDefensiveMode := ini.ReadKeyboardKey(Section,'UnitDefensiveMode', 0);
UnitBlowUp := ini.ReadKeyboardKey(Section,'UnitBlowUp', 0);
UnitMove := ini.ReadKeyboardKey(Section,'UnitMove', 0);
UnitStop := ini.ReadKeyboardKey(Section,'UnitStop', 0);
UnitPatrol := ini.ReadKeyboardKey(Section,'UnitPatrol', 0);
UnitWaypointMove := ini.ReadKeyboardKey(Section,'UnitWaypointMove', 0);
UnitFollowAndDefend := ini.ReadKeyboardKey(Section,'UnitFollowAndDefend', 0);
MovementManagerDebugMode := ini.ReadKeyboardKey(Section,'MovementManagerDebugMode', 0);
CollisionManagerDebugMode := ini.ReadKeyboardKey(Section,'CollisionManagerDebugMode', 0);
end;
{ TVideoSettings }
procedure TVideoSettings.LoadFromIni(ini: TStrangeIniFile; Section: String);
begin
ScreenWidth := ini.ReadInteger(Section, 'ScreenWidth',0);
ScreenHeight := ini.ReadInteger(Section, 'ScreenHeight',0);
UseCurrentResolution := ini.ReadBool(Section, 'UseCurrentResolution',False);
MultiProxyNearDistance := ini.ReadFloat(Section, 'MultiProxyNearDistance',0);
MultiProxyMediumDistance := ini.ReadFloat(Section, 'MultiProxyMediumDistance',0);
MultiProxyFarDistance := ini.ReadFloat(Section, 'MultiProxyFarDistance',0);
EveryTextureScale := ini.ReadInteger(Section, 'EveryTextureScale',0);
MediumTextureScale := ini.ReadInteger(Section, 'MediumTextureScale',0);
FarTextureScale := ini.ReadInteger(Section, 'FarTextureScale',0);
BlowUpModelQuality := LoadFromQualityString(LowerCase(ini.ReadString(Section, 'BlowUpModelQuality','')));
if BlowUpModelQuality = 255 then
MakeError(str_ERROR_READING + 'BlowUpModelQuality' + str_IN_SECTION + Section + str_FROM_FILE + ini.FileName + str_INVALID_VALUE, ERR_BAD_INI);
MeshQuality := LoadFromQualityString(LowerCase(ini.ReadString(Section, 'MeshQuality','')));
if MeshQuality = 255 then
MakeError(str_ERROR_READING + 'MeshQuality' + str_IN_SECTION + Section + str_FROM_FILE + ini.FileName + str_INVALID_VALUE, ERR_BAD_INI);
ExplosionsQuality := LoadFromQualityString(LowerCase(ini.ReadString(Section, 'ExplosionsQuality','')));
if ExplosionsQuality = 255 then
MakeError(str_ERROR_READING + 'ExplosionsQuality' + str_IN_SECTION + Section + str_FROM_FILE + ini.FileName + str_INVALID_VALUE, ERR_BAD_INI);
end;
{ TGeneralSettings }
procedure TGeneralSettings.LoadFromIni(ini: TStrangeIniFile; Section: String);
begin
QuickSaveFile := ini.ReadString(Section, 'QuickSaveFile', '');
QuickSavePeriod := ini.ReadInteger(Section, 'QuickSavePeriod', 0);
SplitScreenMode := ini.ReadBool(Section, 'SplitScreenMode', False);
FullScreenMode := ini.ReadBool(Section, 'FullScreenMode', False);
AddLastDotOnKeyPress := ini.ReadBool(Section, 'AddLastDotOnKeyPress', True);
SectorSize[0] := ini.ReadFloat(Section, str_SECTOR_SIZE + 'X', 0);
SectorSize[1] := ini.ReadFloat(Section, str_SECTOR_SIZE + 'Y', 0);
SectorSize[2] := ini.ReadFloat(Section, str_SECTOR_SIZE + 'Z', 0);
end;
{ TAudioSettings }
procedure TAudioSettings.LoadFromIni(ini: TStrangeIniFile; Section: String);
begin
EnableMusic := ini.ReadBool(Section, 'EnableMusic', True);
end;
end.
See more files for this project here