summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b171ccb)
raw | patch | inline | side by side (parent: b171ccb)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Fri, 11 Oct 2019 22:27:25 +0000 (01:27 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sat, 12 Oct 2019 15:54:12 +0000 (18:54 +0300) |
src/game/g_map.pas | patch | blob | history | |
src/game/g_net.pas | patch | blob | history | |
src/game/g_res_downloader.pas | patch | blob | history |
diff --git a/src/game/g_map.pas b/src/game/g_map.pas
index bf1f9159d096fdfe54d7f42b268b4e07aba425ec..08ebadeb2929d4b429c62c9a7794173bfb0995cc 100644 (file)
--- a/src/game/g_map.pas
+++ b/src/game/g_map.pas
Math, g_monsters, g_saveload, g_language, g_netmsg,
sfs, xstreams, hashtable, wadreader,
ImagingTypes, Imaging, ImagingUtility,
- ImagingGif, ImagingNetworkGraphics;
+ ImagingGif, ImagingNetworkGraphics,
+ g_res_downloader;
const
FLAGRECT: TRectWH = (X:15; Y:12; Width:33; Height:52);
end;
+function GetReplacementWad (WadName: AnsiString): AnsiString;
+begin
+ if (length(WadName) = 0) then
+ begin
+ result := '';
+ end
+ else
+ begin
+ result := g_Res_FindReplacementWad(WadName);
+ if (result <> WadName) then
+ begin
+ //e_LogWritefln('GetReplacementWad: old=%s; new=%s', [WadName, result]);
+ end
+ else
+ begin
+ result := GameDir+'/wads/'+result;
+ end;
+ end;
+end;
+
function CreateTexture(RecName: AnsiString; Map: string; log: Boolean): Integer;
var
WAD: TWADFile;
end;
// Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
- WADName := g_ExtractWadName(RecName);
+ WADName := GetReplacementWad(g_ExtractWadName(RecName));
+ if WADName = '' then WADName := Map; //WADName := GameDir+'/wads/'+WADName else
WAD := TWADFile.Create();
-
- if WADName <> '' then WADName := GameDir+'/wads/'+WADName else WADName := Map;
-
WAD.ReadFile(WADName);
//txname := RecName;
end;
// ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü:
- WADName := g_ExtractWadName(RecName);
+ WADName := GetReplacementWad(g_ExtractWadName(RecName));
+ if WADName = '' then WADName := Map; //WADName := GameDir+'/wads/'+WADName else
WAD := TWADFile.Create();
try
- if WADName <> '' then WADName := GameDir+'/wads/'+WADName else WADName := Map;
+ //if WADName <> '' then WADName := GameDir+'/wads/'+WADName else WADName := Map;
WAD.ReadFile(WADName);
//e_LogWritefln('DBG: ***trying external resource %s', [res]);
res := toLowerCase1251(extractWadName(res));
// ignore "standart.wad"
- if (res <> '') and (res <> 'standart.wad') and (gExternalResources.IndexOf(res) = -1) then
+ if (res <> '') {and (res <> 'standart.wad')} and (gExternalResources.IndexOf(res) = -1) then
begin
//e_LogWritefln('DBG: added external resource %s', [res]);
gExternalResources.Add(res);
diff --git a/src/game/g_net.pas b/src/game/g_net.pas
index 82f4632a28c22fefd344cdca1e406d3f547534e0..ac845852fa1c26f5d3e4e41339842b11f93bedba 100644 (file)
--- a/src/game/g_net.pas
+++ b/src/game/g_net.pas
rd := tf.size-(tf.lastSentChunk*tf.chunkSize);
if (rd > tf.chunkSize) then rd := tf.chunkSize;
omsg.Write(LongInt(rd));
- e_LogWritefln('download: client #%d, sending chunk #%d/#%d (%d bytes)', [nc.ID, tf.lastSentChunk, chunks, rd]);
+ //e_LogWritefln('download: client #%d, sending chunk #%d/#%d (%d bytes)', [nc.ID, tf.lastSentChunk, chunks, rd]);
//FIXME: check for errors here
try
tf.stream.Seek(tf.lastSentChunk*tf.chunkSize, soFromBeginning);
for f := Low(NetClients) to High(NetClients) do
begin
if (not NetClients[f].Used) then continue;
- //if (NetClients[f].Transfer.stream = nil) then continue;
if (NetClients[f].Peer = NetEvent.peer) then
begin
nid := f;
break;
end;
end;
- e_LogWritefln('RECEIVE: dlpacket; client=%d (datalen=%u)', [nid, NetEvent.packet^.dataLength]);
+ //e_LogWritefln('RECEIVE: dlpacket; client=%d (datalen=%u)', [nid, NetEvent.packet^.dataLength]);
if (nid < 0) then exit; // wtf?!
nc := @NetClients[nid];
tf.lastAckTime := GetTimerMS();
cmd := Byte(NetEvent.packet^.data^);
- e_LogWritefln('RECEIVE: nid=%d; cmd=%u', [nid, cmd]);
+ //e_LogWritefln('RECEIVE: nid=%d; cmd=%u', [nid, cmd]);
case cmd of
NTF_CLIENT_FILE_REQUEST: // file request
begin
KillClientByFT(nc^);
exit;
end;
- if (ridx < 0) then fname := MapsDir+gGameSettings.WAD else fname := gExternalResources[ridx];
+ if (ridx < 0) then fname := MapsDir+gGameSettings.WAD else fname := GameDir+'/wads/'+gExternalResources[ridx];
if (length(fname) = 0) then
begin
e_WriteLog('Invalid filename: '+fname, TMsgType.Warning);
exit;
end;
tf.diskName := findDiskWad(fname);
- if (length(tf.diskName) = 0) then tf.diskName := findDiskWad(GameDir+'/wads/'+fname);
+ //if (length(tf.diskName) = 0) then tf.diskName := findDiskWad(GameDir+'/wads/'+fname);
if (length(tf.diskName) = 0) then
begin
e_LogWritefln('NETWORK: file "%s" not found!', [fname], TMsgType.Fatal);
// do it this way, so client may seek, or request retransfers for some reason
tf.lastAckChunk := chunk;
tf.lastSentChunk := chunk;
- e_LogWritefln('client #%d acked file transfer chunk %d', [nc.ID, chunk]);
+ //e_LogWritefln('client #%d acked file transfer chunk %d', [nc.ID, chunk]);
end;
NTF_CLIENT_MAP_REQUEST:
begin
TC: pTNetClient;
TP: TPlayer;
f: Integer;
+ //ctt: Int64;
begin
IP := '';
Result := 0;
if NetUseMaster then g_Net_Slist_Check;
g_Net_Host_CheckPings;
+ //ctt := -GetTimerMS();
// process file transfers
for f := Low(NetClients) to High(NetClients) do
begin
if (NetClients[f].Transfer.stream = nil) then continue;
ProcessHostFileTransfers(NetClients[f]);
end;
+ {
+ ctt := ctt+GetTimerMS();
+ if (ctt > 1) then e_LogWritefln('all transfers: [%d]', [Integer(ctt)]);
+ }
while (enet_host_service(NetHost, @NetEvent, 0) > 0) do
begin
ct, ett: Int64;
status: cint;
nextChunk: Integer = 0;
+ chunkTotal: Integer;
chunk: Integer;
csize: Integer;
buf: PChar = nil;
pkt: PENetPacket;
+ //stx: Int64;
begin
// send request
msg.Alloc(NET_BUFSIZE);
msg.Free();
end;
+ chunkTotal := (tf.size+tf.chunkSize-1) div tf.chunkSize;
+ e_LogWritefln('receiving file `%s` (%d chunks)', [tf.diskName, chunkTotal], TMsgType.Notify);
+ g_Game_SetLoadingText('downloading "'+ExtractFileName(tf.diskName)+'"', chunkTotal, False);
+
// wait for reply data
FillChar(ev, SizeOf(ev), 0);
Result := -1;
try
ett := getNewTimeoutEnd();
repeat
+ //stx := -GetTimerMS();
status := enet_host_service(NetHost, @ev, 300);
if (status < 0) then
begin
end
else
begin
+ //stx := stx+GetTimerMS();
+ //e_LogWritefln('g_Net_ReceiveResourceFile: stx=%d', [Integer(stx)]);
+ //stx := -GetTimerMS();
ett := getNewTimeoutEnd();
if (ev.packet.dataLength < 1) then
begin
Result := -1;
exit;
end;
- e_LogWritefln('got chunk #%d of #%d (csize=%d)', [chunk, (tf.size+tf.chunkSize-1) div tf.chunkSize, csize]);
+ //e_LogWritefln('got chunk #%d of #%d (csize=%d)', [chunk, (tf.size+tf.chunkSize-1) div tf.chunkSize, csize]);
msg.ReadData(buf, csize);
strm.WriteBuffer(buf^, csize);
nextChunk := chunk+1;
+ g_Game_StepLoading();
// send ack
omsg.Alloc(NET_BUFSIZE);
try
Result := -1;
exit;
end;
+ //stx := stx+GetTimerMS();
+ //e_LogWritefln('g_Net_ReceiveResourceFile: process stx=%d', [Integer(stx)]);
end;
end;
ENET_EVENT_TYPE_DISCONNECT:
index ed1ea3bdf3feb7c77de12529d99b0b146c67d94b..72717573b0b9b39303a0d8f4d707891ac350c5b1 100644 (file)
uses sysutils, Classes, md5, g_net, g_netmsg, g_console, g_main, e_log;
function g_Res_SearchSameWAD(const path, filename: AnsiString; const resMd5: TMD5Digest): AnsiString;
-function g_Res_SearchResWad (asMap: Boolean; const resMd5: TMD5Digest): AnsiString;
// download map wad from server (if necessary)
// download all required map resource wads too
procedure g_Res_PutReplacementWad (oldname: AnsiString; newDiskName: AnsiString);
begin
e_LogWritefln('adding replacement wad: oldname=%s; newname=%s', [oldname, newDiskName]);
+ if not assigned(replacements) then replacements := THashStrStr.Create();
replacements.put(toLowerCase1251(oldname), newDiskName);
end;
end;
-function g_Res_SearchResWad (asMap: Boolean; const resMd5: TMD5Digest): AnsiString;
+function g_Res_SearchResWad (asMap: Boolean; fname: AnsiString; const resMd5: TMD5Digest): AnsiString;
var
f: Integer;
begin
//if not assigned(scannedDirs) then scannedDirs := THashStrInt.Create();
if (asMap) then
begin
+ if CheckFileHash(GameDir+'/maps', fname, resMd5) then
+ begin
+ result := findDiskWad(GameDir+'/maps/'+fname);
+ if (length(result) <> 0) then exit;
+ end;
scanDir(GameDir+'/maps/downloads', true);
end
else
begin
+ if CheckFileHash(GameDir+'/wads', fname, resMd5) then
+ begin
+ result := findDiskWad(GameDir+'/wads/'+fname);
+ if (length(result) <> 0) then exit;
+ end;
scanDir(GameDir+'/wads/downloads', true);
end;
for f := Low(knownFiles) to High(knownFiles) do
wadname: AnsiString;
begin
//SetLength(mapData.ExternalResources, 0);
- //result := g_Res_SearchResWad(true{asMap}, mapHash);
result := '';
g_Res_ClearReplacementWads();
g_Res_received_map_start := false;
if (res <> 0) then exit;
// find or download a map
- result := g_Res_SearchResWad(true{asMap}, mapHash);
+ result := g_Res_SearchResWad(true{asMap}, tf.diskName, mapHash);
if (length(result) = 0) then
begin
// download map
result := '';
exit;
end;
+ tf.diskName := fname;
try
res := g_Net_ReceiveResourceFile(-1{map}, tf, strm);
except
begin
res := g_Net_RequestResFileInfo(f, tf);
if (res <> 0) then begin result := ''; exit; end;
- wadname := g_Res_SearchResWad(false{asMap}, tf.hash);
+ wadname := g_Res_SearchResWad(false{asMap}, tf.diskName, tf.hash);
if (length(wadname) <> 0) then
begin
// already here