This commit is contained in:
1 parent
da66a6c9d7
commit
2444723bd3
7 files changed
+3707
-348
No files matched your search
@@ -18,7 +18,11 @@
|
||||
"src/res/KM_ResPalettes.pas",
|
||||
"src/res/KM_ResMapElements.pas",
|
||||
"src/res/KM_ResLocales.pas",
|
||||
"src/render/KM_Render.pas"
|
||||
"src/render/KM_Render.pas",
|
||||
"src/KM_GameApp.pas",
|
||||
"src/res/KM_Resource.pas",
|
||||
"src/common/KM_Defaults.pas",
|
||||
"src/res/KM_ResTypes.pas"
|
||||
],
|
||||
"source_paths": [
|
||||
"code/resource"
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,332 @@
|
||||
unit KM_ResTypes;
|
||||
{$I KaM_Remake.inc}
|
||||
interface
|
||||
uses
|
||||
KM_ResTilesetTypes;
|
||||
|
||||
type
|
||||
TKMChopableAge = (caAge1, caAge2, caAge3, caAgeFull, caAgeFall, caAgeStump);
|
||||
TKMChopableAgeSet = set of TKMChopableAge;
|
||||
|
||||
//* Ware type
|
||||
TKMWareType = (
|
||||
wtNone,
|
||||
wtTrunk, wtStone, wtTimber, wtIronOre, wtGoldOre,
|
||||
wtCoal, wtIron, wtGold, wtWine, wtCorn,
|
||||
wtBread, wtFlour, wtLeather, wtSausage, wtPig,
|
||||
wtSkin, wtWoodenShield, wtIronShield, wtLeatherArmor, wtIronArmor,
|
||||
wtAxe, wtSword, wtLance, wtPike, wtBow,
|
||||
wtCrossbow, wtHorse, wtFish,
|
||||
|
||||
// Special ware types
|
||||
wtAll, wtWarfare, wtFood
|
||||
);
|
||||
|
||||
//* Ware type set
|
||||
TKMWareTypeSet = set of TKMWareType;
|
||||
|
||||
const
|
||||
WARE_MIN = wtTrunk;
|
||||
WARE_MAX = wtFish;
|
||||
WARE_MAX_ALL = wtFood;
|
||||
WARFARE_MIN = wtWoodenShield;
|
||||
WEAPON_MIN = wtWoodenShield;
|
||||
WEAPON_MAX = wtCrossbow;
|
||||
WARFARE_MAX = wtHorse;
|
||||
|
||||
WARES_VALID = [WARE_MIN..WARE_MAX];
|
||||
WARES_WARFARE = [WARFARE_MIN..WARFARE_MAX];
|
||||
WARES_FOOD = [wtWine, wtBread, wtSausage, wtFish];
|
||||
|
||||
WARE_CNT = Integer(WARE_MAX) - Integer(WARE_MIN) + 1;
|
||||
WARFARE_CNT = Integer(WARFARE_MAX) - Integer(WEAPON_MIN) + 1;
|
||||
|
||||
WARFARE_IRON = [wtIronShield, wtIronArmor, wtSword, wtPike, wtCrossbow];
|
||||
|
||||
|
||||
type
|
||||
//* House type
|
||||
TKMHouseType = (
|
||||
htNone, htAny,
|
||||
htArmorSmithy, htArmorWorkshop, htBakery, htBarracks, htButchers,
|
||||
htCoalMine, htFarm, htFishermans, htGoldMine, htInn,
|
||||
htIronMine, htIronSmithy, htMarket, htMetallurgists, htMill,
|
||||
htQuarry, htSawmill, htSchool, htSiegeWorkshop, htStables,
|
||||
htStore, htSwine, htTannery, htTownHall, htWatchTower,
|
||||
htWeaponSmithy, htWeaponWorkshop, htVineyard, htWoodcutters
|
||||
);
|
||||
|
||||
//* House type set
|
||||
TKMHouseTypeSet = set of TKMHouseType;
|
||||
TKMHouseTypeArray = array of TKMHouseType;
|
||||
|
||||
|
||||
TKMKeyFunction = (
|
||||
kfNone,
|
||||
|
||||
// faCommon
|
||||
kfScrollLeft, // Scroll Left
|
||||
kfScrollRight, // Scroll Right
|
||||
kfScrollUp, // Scroll Up
|
||||
kfScrollDown, // Scroll Down
|
||||
|
||||
kfMapDragScroll, // Map drag scroll
|
||||
|
||||
kfZoomIn, // Zoom In
|
||||
kfZoomOut, // Zoom Out
|
||||
kfZoomReset, // Reset Zoom
|
||||
|
||||
kfCloseMenu, // Close opened menu
|
||||
|
||||
kfMusicPrevTrack, // Music previous track
|
||||
kfMusicNextTrack, // Music next track
|
||||
kfMusicDisable, // Music disable
|
||||
kfMusicShuffle, // Music shuffle
|
||||
kfMusicVolumeUp, // Music volume up
|
||||
kfMusicVolumeDown, // Music volume down
|
||||
kfMusicMute, // Music mute
|
||||
|
||||
kfSoundVolumeUp, // Sound volume up
|
||||
kfSoundVolumeDown, // Sound volume down
|
||||
kfSoundMute, // Sound mute
|
||||
|
||||
kfMuteAll, // Mute music and sound
|
||||
|
||||
kfDebugWindow, // Debug window
|
||||
kfDebugRevealmap, // Debug Menu Reveal Map
|
||||
kfDebugVictory, // Debug Menu Victory
|
||||
kfDebugDefeat, // Debug Menu Defeat
|
||||
kfDebugAddscout, // Debug Menu Add Scout
|
||||
|
||||
// faGame
|
||||
kfMenuBuild, // Build Menu
|
||||
kfMenuRatio, // Ratio Menu
|
||||
kfMenuStats, // Stats Menu
|
||||
kfMenuMenu, // Main Menu
|
||||
|
||||
kfSpeedup1, // Speed up 1
|
||||
kfSpeedup2, // Speed up 2
|
||||
kfSpeedup3, // Speed up 3
|
||||
kfSpeedup4, // Speed up 4
|
||||
|
||||
kfBeacon, // Beacon
|
||||
kfPause, // Pause
|
||||
kfShowTeams, // Show teams in MP
|
||||
|
||||
kfCenterAlert, // Center to alert
|
||||
kfDeleteMsg, // Delete message
|
||||
kfChat, // Show the chat
|
||||
|
||||
kfNextEntitySameType, // Select next building/unit with same type
|
||||
kfPlayerColorMode, // Switch player color mode
|
||||
|
||||
kfPlanRoad, // Plan road
|
||||
kfPlanField, // Plan field
|
||||
kfPlanWine, // Plan wine
|
||||
kfErasePlan, // Erase plan
|
||||
|
||||
kfSelect1, // Select 1
|
||||
kfSelect2, // Select 2
|
||||
kfSelect3, // Select 3
|
||||
kfSelect4, // Select 4
|
||||
kfSelect5, // Select 5
|
||||
kfSelect6, // Select 6
|
||||
kfSelect7, // Select 7
|
||||
kfSelect8, // Select 8
|
||||
kfSelect9, // Select 9
|
||||
kfSelect10, // Select 10
|
||||
kfSelect11, // Select 11
|
||||
kfSelect12, // Select 12
|
||||
kfSelect13, // Select 13
|
||||
kfSelect14, // Select 14
|
||||
kfSelect15, // Select 15
|
||||
kfSelect16, // Select 16
|
||||
kfSelect17, // Select 17
|
||||
kfSelect18, // Select 18
|
||||
kfSelect19, // Select 19
|
||||
kfSelect20, // Select 20
|
||||
|
||||
// faUnit
|
||||
kfArmyHalt, // Halt Command
|
||||
kfArmySplit, // Split up Command
|
||||
kfArmyLink, // Linkup Command
|
||||
kfArmyFood, // Food Command
|
||||
kfArmyStorm, // Storm Command
|
||||
kfArmyAddLine, // Formation Increase Line Command
|
||||
kfArmyDelLine, // Formation Shrink Line Command
|
||||
kfArmyRotateCw, // Turn Right Command
|
||||
kfArmyRotateCcw, // Turn Left Command
|
||||
|
||||
// faHouse
|
||||
kfTrainGotoPrev, // Goto previuos unit
|
||||
kfTrainEquipUnit, // Train or Equip unit
|
||||
kfTrainGotoNext, // Goto next unit
|
||||
|
||||
// faSpecReplay
|
||||
kfSpecpanelSelectDropbox, // Select dropbox on spectator panel
|
||||
kfReplayPlayNextTick, // Play next tick in replay
|
||||
kfSpectatePlayer1, // Spectate player 1
|
||||
kfSpectatePlayer2, // Spectate player 2
|
||||
kfSpectatePlayer3, // Spectate player 3
|
||||
kfSpectatePlayer4, // Spectate player 4
|
||||
kfSpectatePlayer5, // Spectate player 5
|
||||
kfSpectatePlayer6, // Spectate player 6
|
||||
kfSpectatePlayer7, // Spectate player 7
|
||||
kfSpectatePlayer8, // Spectate player 8
|
||||
kfSpectatePlayer9, // Spectate player 9
|
||||
kfSpectatePlayer10, // Spectate player 10
|
||||
kfSpectatePlayer11, // Spectate player 11
|
||||
kfSpectatePlayer12, // Spectate player 12
|
||||
|
||||
// faMapEdit
|
||||
kfMapedExtra, // Maped Extra's menu
|
||||
kfMapedSaveMap, // Maped Save map
|
||||
kfMapedTerrain, // Maped Terrain Editing
|
||||
kfMapedVillage, // Maped Village Planning
|
||||
kfMapedVisual, // Maped Visual Scripts
|
||||
kfMapedGlobal, // Maped Global Scripting
|
||||
kfMapedMainMenu, // Maped Main Menu
|
||||
kfMapedSubMenu1, // Maped Sub-menu 1
|
||||
kfMapedSubMenu2, // Maped Sub-menu 2
|
||||
kfMapedSubMenu3, // Maped Sub-menu 3
|
||||
kfMapedSubMenu4, // Maped Sub-menu 4
|
||||
kfMapedSubMenu5, // Maped Sub-menu 5
|
||||
kfMapedSubMenu6, // Maped Sub-menu 6
|
||||
kfMapedSubMenuAction1, // Maped Sub-menu Action 1
|
||||
kfMapedSubMenuAction2, // Maped Sub-menu Action 2
|
||||
kfMapedSubMenuAction3, // Maped Sub-menu Action 3
|
||||
kfMapedSubMenuAction4, // Maped Sub-menu Action 4
|
||||
kfMapedSubMenuAction5, // Maped Sub-menu Action 5
|
||||
kfMapedSubMenuAction6, // Maped Sub-menu Action 6
|
||||
kfMapedSubMenuAction7, // Maped Sub-menu Action 6
|
||||
kfMapedObjPalette, // Maped Objects palette
|
||||
kfMapedTilesPalette, // Maped Tiles palette
|
||||
kfMapedUnivErasor, // Maped Universal erasor
|
||||
kfMapedPaintBucket, // Maped Paint bucket
|
||||
kfMapedHistory, // Maped History
|
||||
kfMapedFlatTerrain, // Maped Flat terrain
|
||||
kfMapedTilesGrid // Maped Tiles grid
|
||||
);
|
||||
|
||||
TKMKeyFunctionSet = set of TKMKeyFunction;
|
||||
|
||||
TKMKeyFuncArea = (faCommon,
|
||||
faGame,
|
||||
faUnit,
|
||||
faHouse,
|
||||
faSpecReplay,
|
||||
faMapEdit);
|
||||
|
||||
TKMKeyFuncAreaSet = set of TKMKeyFuncArea;
|
||||
|
||||
const
|
||||
KEY_FUNC_LOW = Succ(kfNone); // 1st key function
|
||||
|
||||
KEY_FUNCS_ALL = [KEY_FUNC_LOW..High(TKMKeyFunction)];
|
||||
|
||||
type
|
||||
// Cursors
|
||||
TKMCursorImageType = (
|
||||
kmcDefault, kmcInfo, kmcAttack, kmcJoinYes, kmcJoinNo, kmcEdit, kmcDragUp,
|
||||
kmcDir0, kmcDir1, kmcDir2, kmcDir3, kmcDir4, kmcDir5, kmcDir6, kmcDir7, kmcDirNA,
|
||||
kmcScroll0, kmcScroll1, kmcScroll2, kmcScroll3, kmcScroll4, kmcScroll5, kmcScroll6, kmcScroll7,
|
||||
kmcBeacon, kmcDrag,
|
||||
kmcInvisible, // for some reason kmcInvisible should be at its current position in enum. Otherwise 1px dot will appear while TroopSelection is on
|
||||
kmcPaintBucket,
|
||||
kmcAnimatedDirSelector
|
||||
);
|
||||
|
||||
const
|
||||
// Indexes of cursor images in GUI.RX
|
||||
CURSOR_SPRITE_INDEX: array [TKMCursorImageType] of Word = (
|
||||
1, 452, 457, 460, 450, 453, 449,
|
||||
511, 512, 513, 514, 515, 516, 517, 518, 519,
|
||||
4, 7, 3, 9, 5, 8, 2, 6,
|
||||
456, 451, 999, 661, 0);
|
||||
|
||||
type
|
||||
TRXUsage = (ruMenu, ruGame, ruCustom); //Where sprites are used
|
||||
|
||||
TKMSpriteAtlasType = (saBase, saMask);
|
||||
|
||||
TRXInfo = record
|
||||
FileName: string; //Used for logging and filenames
|
||||
TeamColors: Boolean; //sprites should be generated with color masks
|
||||
Usage: TRXUsage; //Menu and Game sprites are loaded separately
|
||||
LoadingTextID: Word;
|
||||
end;
|
||||
|
||||
TKMGenTerrainInfo = record
|
||||
TerKind: TKMTerrainKind;
|
||||
Mask: TKMMaskFullType;
|
||||
end;
|
||||
|
||||
// ResSprites Types
|
||||
type
|
||||
TRXType = (
|
||||
rxTrees,
|
||||
rxHouses,
|
||||
rxUnits,
|
||||
rxGui,
|
||||
rxGuiMain,
|
||||
rxCustom, //Used for loading stuff like campaign maps (there is no main RXX file)
|
||||
rxTiles //Tiles
|
||||
);
|
||||
//Colors to paint beneath player color areas (flags)
|
||||
//The blacker/whiter - the more contrast player color will be
|
||||
FLAG_COLOR_DARK = $FF101010; //Dark-grey (Black)
|
||||
FLAG_COLOR_LITE = $FFFFFFFF; //White
|
||||
|
||||
type
|
||||
// Original KaM format for RX files
|
||||
{
|
||||
TRXData = record
|
||||
Count: Integer;
|
||||
Flag: array of Byte; // Sprite is valid
|
||||
Size: array of record X,Y: Word; end;
|
||||
Pivot: array of record X,Y: Integer; end;
|
||||
Data: array of array of Byte;
|
||||
end;}
|
||||
|
||||
// RXX and RXX1 file format, with Pivot type changed and SizeNoShadow added
|
||||
TRXData = record
|
||||
Count: Integer;
|
||||
Flag: array of Byte; //Sprite is valid
|
||||
Size: array of record X,Y: Word; end;
|
||||
Pivot: array of record X,Y: SmallInt; end;
|
||||
SizeNoShadow: array of record Left, Top, Right, Bottom: SmallInt; end; //Image object (without shadow) rect in the image sizes
|
||||
{unused in RXX} Data: array of array of Byte; //Used for RXX utils (Packer / Editor)
|
||||
RGBA: array {Index} of array {YX} of Cardinal; //Expanded image
|
||||
Mask: array of array of Byte; //Mask for team colors
|
||||
HasMask: array of Boolean; //Flag if Mask for team colors is used
|
||||
end;
|
||||
PRXData = ^TRXData;
|
||||
|
||||
const
|
||||
{$I KM_TextIDs.inc}
|
||||
|
||||
RX_INFO: array [TRXType] of TRXInfo = (
|
||||
(FileName: 'Trees'; TeamColors: False; Usage: ruGame; LoadingTextID: TX_MENU_LOADING_TREES;),
|
||||
(FileName: 'Houses'; TeamColors: True; Usage: ruGame; LoadingTextID: TX_MENU_LOADING_HOUSES;),
|
||||
(FileName: 'Units'; TeamColors: True; Usage: ruGame; LoadingTextID: TX_MENU_LOADING_UNITS;),
|
||||
(FileName: 'GUI'; TeamColors: True; Usage: ruMenu; LoadingTextID: 0;),
|
||||
(FileName: 'GUIMain'; TeamColors: False; Usage: ruMenu; LoadingTextID: 0;),
|
||||
(FileName: 'Custom'; TeamColors: False; Usage: ruCustom; LoadingTextID: 0;),
|
||||
(FileName: 'Tileset'; TeamColors: False; Usage: ruMenu; LoadingTextID: TX_MENU_LOADING_TILESET;));
|
||||
|
||||
function GetKeyFunctionStr(aKeyFun: TKMKeyFunction): string;
|
||||
|
||||
|
||||
implementation
|
||||
uses
|
||||
TypInfo;
|
||||
|
||||
|
||||
function GetKeyFunctionStr(aKeyFun: TKMKeyFunction): string;
|
||||
begin
|
||||
// Result := TRttiEnumerationType.GetName(aKeyFun);
|
||||
Result := GetEnumName(TypeInfo(TKMKeyFunction), Integer(aKeyFun));
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
@@ -0,0 +1,335 @@
|
||||
unit KM_Resource;
|
||||
{$I KaM_Remake.inc}
|
||||
interface
|
||||
uses
|
||||
{$IFDEF Unix} LCLIntf, LCLType, {$ENDIF}
|
||||
Classes, SysUtils,
|
||||
KM_CommonTypes, KM_Defaults,
|
||||
KM_ResTypes,
|
||||
KM_ResCursors,
|
||||
KM_ResFonts,
|
||||
KM_ResHouses,
|
||||
KM_ResLocales,
|
||||
KM_ResMapElements,
|
||||
KM_ResPalettes,
|
||||
KM_ResSound,
|
||||
KM_ResSprites,
|
||||
KM_ResTileset,
|
||||
KM_ResUnits,
|
||||
KM_ResWares,
|
||||
KM_ResInterpolation;
|
||||
|
||||
|
||||
type
|
||||
TResourceLoadState = (rlsNone, rlsMenu, rlsAll); //Resources are loaded in 2 steps, for menu and the rest
|
||||
|
||||
TKMResource = class
|
||||
private
|
||||
fDataState: TResourceLoadState;
|
||||
|
||||
fCursors: TKMResCursors;
|
||||
fFonts: TKMResFonts;
|
||||
fHouses: TKMResHouses;
|
||||
fPalettes: TKMResPalettes;
|
||||
fUnits: TKMResUnits;
|
||||
fWares: TKMResWares;
|
||||
fSounds: TKMResSounds;
|
||||
fSprites: TKMResSprites;
|
||||
fTileset: TKMResTileset;
|
||||
fMapElements: TKMResMapElements;
|
||||
fInterpolation: TKMResInterpolation;
|
||||
|
||||
function GetGameResourcesReady: Boolean;
|
||||
procedure EnsureGameResourceInterpolation;
|
||||
procedure StepRefresh;
|
||||
procedure StepCaption(const aCaption: UnicodeString);
|
||||
public
|
||||
OnLoadingStep: TKMEvent;
|
||||
OnLoadingText: TUnicodeStringEvent;
|
||||
|
||||
constructor Create(aOnLoadingStep: TKMEvent; aOnLoadingText: TUnicodeStringEvent);
|
||||
destructor Destroy; override;
|
||||
|
||||
function GetDATCRC: Cardinal;
|
||||
|
||||
procedure LoadMainResources(const aLocale: AnsiString = ''; aLoadFullFonts: Boolean = True);
|
||||
procedure LoadLocaleAndFonts(const aLocale: AnsiString = ''; aLoadFullFonts: Boolean = True);
|
||||
procedure LoadLocaleResources(const aLocale: AnsiString = '');
|
||||
procedure PreloadGameResources(aAlphaShadows: Boolean);
|
||||
procedure LoadGameResources(aAlphaShadows: Boolean; aForceReload: Boolean = False);
|
||||
procedure StartGameSpriteRecovery;
|
||||
procedure LoadLocaleFonts(const aLocale: AnsiString; aLoadFullFonts: Boolean);
|
||||
|
||||
property DataState: TResourceLoadState read fDataState;
|
||||
property GameResourcesReady: Boolean read GetGameResourcesReady;
|
||||
property Palettes: TKMResPalettes read fPalettes;
|
||||
property Cursors: TKMResCursors read fCursors;
|
||||
property MapElements: TKMResMapElements read fMapElements;
|
||||
property Fonts: TKMResFonts read fFonts;
|
||||
property Sounds: TKMResSounds read fSounds;
|
||||
property Sprites: TKMResSprites read fSprites;
|
||||
property Tileset: TKMResTileset read fTileset;
|
||||
property Houses: TKMResHouses read fHouses;
|
||||
property Units: TKMResUnits read fUnits;
|
||||
property Wares: TKMResWares read fWares;
|
||||
property Interpolation: TKMResInterpolation read fInterpolation;
|
||||
|
||||
procedure UpdateStateIdle;
|
||||
|
||||
function IsMsgHouseUnnocupied(aMsgId: Word): Boolean;
|
||||
end;
|
||||
|
||||
|
||||
var
|
||||
gRes: TKMResource;
|
||||
|
||||
|
||||
implementation
|
||||
uses
|
||||
TypInfo,
|
||||
{$IFNDEF NO_OGL}
|
||||
KM_System,
|
||||
{$ENDIF}
|
||||
KromUtils, KM_Log, KM_Points,
|
||||
KM_ResTexts, KM_ResKeyFuncs, KM_ResTilesetTypes;
|
||||
|
||||
|
||||
{ TKMResource }
|
||||
constructor TKMResource.Create(aOnLoadingStep: TKMEvent; aOnLoadingText: TUnicodeStringEvent);
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
fDataState := rlsNone;
|
||||
gLog.AddTime('Resource loading state - None');
|
||||
|
||||
OnLoadingStep := aOnLoadingStep;
|
||||
OnLoadingText := aOnLoadingText;
|
||||
end;
|
||||
|
||||
|
||||
destructor TKMResource.Destroy;
|
||||
begin
|
||||
FreeAndNil(fCursors);
|
||||
FreeAndNil(fHouses);
|
||||
FreeAndNil(gResLocales);
|
||||
FreeAndNil(fMapElements);
|
||||
FreeAndNil(fPalettes);
|
||||
FreeAndNil(fFonts);
|
||||
FreeAndNil(fWares);
|
||||
FreeAndNil(fSprites);
|
||||
FreeAndNil(fSounds);
|
||||
FreeAndNil(gResTexts);
|
||||
FreeAndNil(fTileset);
|
||||
FreeAndNil(fUnits);
|
||||
FreeAndNil(gResKeyFuncs);
|
||||
FreeAndNil(fInterpolation);
|
||||
|
||||
inherited;
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.UpdateStateIdle;
|
||||
begin
|
||||
try
|
||||
fSprites.UpdateStateIdle;
|
||||
except
|
||||
if fDataState = rlsAll then
|
||||
fDataState := rlsMenu;
|
||||
raise;
|
||||
end;
|
||||
|
||||
if (fDataState <> rlsNone) and (fInterpolation <> nil) and fSprites.GameResourcesReady then
|
||||
fDataState := rlsAll
|
||||
else if fDataState = rlsAll then
|
||||
fDataState := rlsMenu;
|
||||
end;
|
||||
|
||||
|
||||
function TKMResource.GetGameResourcesReady: Boolean;
|
||||
begin
|
||||
Result := fDataState = rlsAll;
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.EnsureGameResourceInterpolation;
|
||||
begin
|
||||
if fInterpolation = nil then
|
||||
begin
|
||||
gLog.AddTime('LoadGameResources ... Interpolations from interp.dat');
|
||||
fInterpolation := TKMResInterpolation.Create;
|
||||
fInterpolation.LoadFromFile(ExeDir + 'data' + PathDelim + 'defines' + PathDelim + 'interp.dat');
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.StepRefresh;
|
||||
begin
|
||||
if Assigned(OnLoadingStep) then OnLoadingStep;
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.StepCaption(const aCaption: UnicodeString);
|
||||
begin
|
||||
if Assigned(OnLoadingText) then OnLoadingText(aCaption);
|
||||
end;
|
||||
|
||||
|
||||
//CRC of data files that can cause inconsitencies
|
||||
function TKMResource.GetDATCRC: Cardinal;
|
||||
begin
|
||||
Result := gRes.Houses.CRC xor
|
||||
fUnits.CRC xor
|
||||
fMapElements.CRC xor
|
||||
fTileset.CRC;
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.LoadMainResources(const aLocale: AnsiString = ''; aLoadFullFonts: Boolean = True);
|
||||
var
|
||||
tileColors: TKMColor3bArray;
|
||||
begin
|
||||
StepCaption('Reading palettes ...');
|
||||
fPalettes := TKMResPalettes.Create;
|
||||
//We are using only default palette in the game for now, so no need to load all palettes
|
||||
fPalettes.LoadDefaultPalette(ExeDir + 'data' + PathDelim + 'gfx' + PathDelim);
|
||||
gLog.AddTime('Reading palettes done');
|
||||
|
||||
fSprites := TKMResSprites.Create(StepRefresh, StepCaption);
|
||||
|
||||
fCursors := TKMResCursors.Create;
|
||||
|
||||
fUnits := TKMResUnits.Create; // Load units prior to Sprites, as we could use it on SoftenShadows override for png in Sprites folder
|
||||
fSprites.LoadMenuResources;
|
||||
|
||||
{$IFNDEF NO_OGL}
|
||||
gSystem.MakeCursors(fSprites[rxGui]);
|
||||
gSystem.Cursor := kmcDefault;
|
||||
{$ENDIF}
|
||||
fCursors.SetRXDataPointer(@fSprites[rxGui].RXData);
|
||||
|
||||
gResKeyFuncs := TKMResKeyFuncs.Create;
|
||||
|
||||
LoadLocaleAndFonts(aLocale, aLoadFullFonts);
|
||||
|
||||
fTileset := TKMResTileset.Create;
|
||||
if not SKIP_RENDER then
|
||||
begin
|
||||
if fSprites.Sprites[rxTiles].RXData.Count <> TILES_CNT then
|
||||
gLog.AddTime('fSprites.Sprites[rxTiles].RXData.Count = ' + IntToStr(fSprites.Sprites[rxTiles].RXData.Count));
|
||||
|
||||
tileColors := fSprites.Sprites[rxTiles].GetAverageSpriteColors(TILES_CNT);
|
||||
fTileset.SetTileColors(tileColors);
|
||||
end;
|
||||
|
||||
fMapElements := TKMResMapElements.Create;
|
||||
fMapElements.LoadFromFile(ExeDir + 'data' + PathDelim + 'defines' + PathDelim + 'mapelem.dat');
|
||||
|
||||
fSprites.ClearTemp;
|
||||
|
||||
fWares := TKMResWares.Create;
|
||||
fHouses := TKMResHouses.Create;
|
||||
|
||||
StepRefresh;
|
||||
gLog.AddTime('ReadGFX is done');
|
||||
fDataState := rlsMenu;
|
||||
gLog.AddTime('Resource loading state - Menu');
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.LoadLocaleResources(const aLocale: AnsiString = '');
|
||||
begin
|
||||
FreeAndNil(gResLocales);
|
||||
FreeAndNil(gResTexts);
|
||||
FreeAndNil(fSounds);
|
||||
|
||||
gResLocales := TKMResLocales.Create(ExeDir + 'data' + PathDelim + 'locales.txt', aLocale);
|
||||
|
||||
gResTexts := TKMTextLibraryMulti.Create;
|
||||
gResTexts.LoadLocale(ExeDir + 'data' + PathDelim + 'text' + PathDelim + 'text.%s.libx', False);
|
||||
|
||||
fSounds := TKMResSounds.Create(gResLocales.UserLocale, gResLocales.FallbackLocale, gResLocales.DefaultLocale);
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.LoadLocaleAndFonts(const aLocale: AnsiString = ''; aLoadFullFonts: Boolean = True);
|
||||
begin
|
||||
// Locale info is needed for DAT export and font loading
|
||||
LoadLocaleResources(aLocale);
|
||||
|
||||
StepCaption('Reading fonts ...');
|
||||
fFonts := TKMResFonts.Create;
|
||||
if aLoadFullFonts or gResLocales.LocaleByCode(aLocale).NeedsFullFonts then
|
||||
fFonts.LoadFonts(fllFull)
|
||||
else
|
||||
fFonts.LoadFonts(fllMinimal);
|
||||
gLog.AddTime('Read fonts is done');
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.LoadLocaleFonts(const aLocale: AnsiString; aLoadFullFonts: Boolean);
|
||||
begin
|
||||
if (Fonts.LoadLevel <> fllFull)
|
||||
and (aLoadFullFonts or gResLocales.LocaleByCode(aLocale).NeedsFullFonts) then
|
||||
Fonts.LoadFonts(fllFull);
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.PreloadGameResources(aAlphaShadows: Boolean);
|
||||
begin
|
||||
try
|
||||
EnsureGameResourceInterpolation;
|
||||
fSprites.PreloadGameResources(aAlphaShadows);
|
||||
if fSprites.GameResourcesReady then
|
||||
fDataState := rlsAll
|
||||
else
|
||||
fDataState := rlsMenu;
|
||||
except
|
||||
fDataState := rlsMenu;
|
||||
raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.LoadGameResources(aAlphaShadows: Boolean; aForceReload: Boolean = False);
|
||||
begin
|
||||
try
|
||||
EnsureGameResourceInterpolation;
|
||||
|
||||
gLog.AddTime('LoadGameResources ... AlphaShadows: ' + BoolToStr(aAlphaShadows, True) + '. Forced: ' + BoolToStr(aForceReload, True));
|
||||
fSprites.LoadGameResources(aAlphaShadows, aForceReload);
|
||||
if not fSprites.GameResourcesReady then
|
||||
raise Exception.Create('Game resources failed to become ready');
|
||||
|
||||
fDataState := rlsAll;
|
||||
except
|
||||
fDataState := rlsMenu;
|
||||
raise;
|
||||
end;
|
||||
|
||||
gLog.AddTime('Resource loading state - Game');
|
||||
end;
|
||||
|
||||
|
||||
procedure TKMResource.StartGameSpriteRecovery;
|
||||
begin
|
||||
if fDataState <> rlsNone then
|
||||
fDataState := rlsMenu;
|
||||
try
|
||||
fSprites.StartGameSpriteRecovery;
|
||||
if fSprites.GameResourcesReady then
|
||||
fDataState := rlsAll;
|
||||
except
|
||||
if fDataState <> rlsNone then
|
||||
fDataState := rlsMenu;
|
||||
raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function TKMResource.IsMsgHouseUnnocupied(aMsgId: Word): Boolean;
|
||||
begin
|
||||
Result := (aMsgId >= TX_MSG_HOUSE_UNOCCUPIED__22) and (aMsgId <= TX_MSG_HOUSE_UNOCCUPIED__22 + 22);
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
@@ -111,9 +111,6 @@ type
|
||||
fLastPassword: string;
|
||||
fFlashOnMessage: Boolean;
|
||||
|
||||
//Misc
|
||||
fAsyncGameResLoader: Boolean;
|
||||
|
||||
//Menu
|
||||
fMenu_FavouriteMapsStr: UnicodeString;
|
||||
fMenu_MapSPType: Byte;
|
||||
@@ -161,7 +158,6 @@ type
|
||||
|
||||
procedure SetSpeedPace(const aValue: Word);
|
||||
function GetFavouriteMaps: TKMMapsCRCList;
|
||||
function GetAsyncGameResLoader: Boolean;
|
||||
public
|
||||
GFX: TKMSettingsGFX;
|
||||
SFX: TKMSettingsSFX;
|
||||
@@ -229,9 +225,6 @@ type
|
||||
property LastRoom: string read fLastRoom write fLastRoom;
|
||||
property LastPassword: string read fLastPassword write fLastPassword;
|
||||
|
||||
//Misc
|
||||
property AsyncGameResLoader: Boolean read GetAsyncGameResLoader;
|
||||
|
||||
// Menu
|
||||
property MenuMapSPType: Byte read fMenu_MapSPType write fMenu_MapSPType;
|
||||
property MenuReplaysType: Byte read fMenu_ReplaysType write fMenu_ReplaysType;
|
||||
@@ -265,6 +258,7 @@ var
|
||||
|
||||
implementation
|
||||
uses
|
||||
DOM,
|
||||
SysUtils, INIfiles, Math,
|
||||
KM_TerrainTypes;
|
||||
|
||||
@@ -323,14 +317,6 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function TKMGameSettings.GetAsyncGameResLoader: Boolean;
|
||||
begin
|
||||
if Self = nil then Exit(False);
|
||||
|
||||
Result := fAsyncGameResLoader;
|
||||
end;
|
||||
|
||||
|
||||
function TKMGameSettings.GetFavouriteMaps: TKMMapsCRCList;
|
||||
begin
|
||||
if Self = nil then Exit(nil);
|
||||
@@ -391,7 +377,6 @@ var
|
||||
nMenuSP,
|
||||
nMenuReplay,
|
||||
nMenuMapEd,
|
||||
nMisc,
|
||||
nDebug: TKMXmlNode;
|
||||
tempCard: Int64;
|
||||
begin
|
||||
@@ -517,10 +502,6 @@ begin
|
||||
fLastPassword := nMultiplayer.Attributes['LastPassword'].AsString('');
|
||||
fFlashOnMessage := nMultiplayer.Attributes['FlashOnMessage'].AsBoolean(True);
|
||||
|
||||
// Misc
|
||||
nMisc := nGameSettings.AddOrFindChild('Misc');
|
||||
fAsyncGameResLoader := nMisc.Attributes['AsyncGameResLoader'].AsBoolean(True);
|
||||
|
||||
// Menu
|
||||
nMenu := nGameSettings.AddOrFindChild('Menu');
|
||||
fMenu_FavouriteMapsStr := nMenu.Attributes['FavouriteMaps'].AsString('');
|
||||
@@ -590,8 +571,8 @@ var
|
||||
nMenuSP,
|
||||
nMenuReplay,
|
||||
nMenuMapEd,
|
||||
nMisc,
|
||||
nDebug: TKMXmlNode;
|
||||
nMisc: TDOMElement;
|
||||
begin
|
||||
if Self = nil then Exit;
|
||||
if BLOCK_FILE_WRITE then Exit;
|
||||
@@ -708,9 +689,9 @@ begin
|
||||
nMultiplayer.Attributes['LastPassword'] := fLastPassword;
|
||||
nMultiplayer.Attributes['FlashOnMessage'] := fFlashOnMessage;
|
||||
|
||||
// Misc
|
||||
nMisc := nGameSettings.AddOrFindChild('Misc');
|
||||
nMisc.Attributes['AsyncGameResLoader'] := fAsyncGameResLoader;
|
||||
nMisc := TDOMElement(TDOMNode(nGameSettings).FindNode('Misc'));
|
||||
if nMisc <> nil then
|
||||
nMisc.RemoveAttribute('AsyncGameResLoader');
|
||||
|
||||
// Menu
|
||||
nMenu := nGameSettings.AddOrFindChild('Menu');
|
||||
|
||||
Reference in new issue
Block a user