ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Helper/LevelDB.pas
(Generate patch)

Comparing oup/current/Helper/LevelDB.pas (file contents):
Revision 130 by alloc, Wed Mar 28 01:17:24 2007 UTC vs.
Revision 136 by alloc, Thu Mar 29 14:20:25 2007 UTC

# Line 65 | Line 65 | var
65    Stream_Body, Stream_Names:          TMemoryStream;
66    Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
67  
68 //  Data, rawdata: Tdata;
68    BeginTime, FileTime: Double;
69    Step:     Integer;
71 //  rawlist:  TRawDataList;
72 //  datlinks: TDatLinks;
70    OniImage:   TOniImage;
71    LevelID:    Integer;
72    TimeFormat: TFormatSettings;
# Line 90 | Line 87 | var
87    RawLinks:   TRawDataList;
88  
89    DatFileStream, RawFileStream: TMemoryStream;
90 +
91 + // ###########################
92 +  datsum, linksum, rawsum: Int64;
93 +  freq: Int64;
94 +  tempticks1, tempticks2: Int64;
95 + // ###########################
96   const
97    Steps: Byte = 3;
98  
# Line 151 | Line 154 | begin
154        begin
155          ShowMessage('Couldn''t delete file. Aborting');
156          Exit;
157 <      end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
158 <      begin
159 <        ShowMessage('Couldn''t delete file. Aborting');
157 <        Exit;
158 <      end else if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
159 <      begin
160 <        if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
157 >      end;
158 >      if FileExists(AnsiReplaceStr(Target, '.dat', '.raw')) then
159 >        if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
160          begin
161            ShowMessage('Couldn''t delete file. Aborting');
162            Exit;
163          end;
164 <      end;
164 >      if FileExists(AnsiReplaceStr(Target, '.dat', '.sep')) then
165 >        if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
166 >          if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
167 >          begin
168 >            ShowMessage('Couldn''t delete file. Aborting');
169 >            Exit;
170 >          end;
171      end else begin
172        ShowMessage('Aborting');
173        Exit;
# Line 278 | Line 283 | begin
283    lbl_estimation.Caption := 'Estimated finishing time: unknown';
284    Application.ProcessMessages;
285  
286 +  QueryPerformanceFrequency(freq);
287 +  datsum := 0;
288 +  linksum := 0;
289 +  rawsum := 0;
290 +
291    FileTime := Time;
292    for FileID := 0 to DatHeader.Files - 1 do
293    begin
# Line 286 | Line 296 | begin
296        FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
297      if FileInfo.Size > 0 then
298      begin
299 +      QueryPerformanceCounter(tempticks1);
300 +
301        FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
302        DatFileStream := TMemoryStream.Create;
303        Connection.LoadDatFile(FileID, TStream(DatFileStream));
304 <      DatFileStream.Seek(4, soFromBeginning);
304 >      DatFileStream.Seek(0, soFromBeginning);
305 >      DatFileStream.Write(FileID, 4);
306        DatFileStream.Write(LevelID, 4);
307  
308 +      QueryPerformanceCounter(tempticks2);
309 +      datsum := datsum + (tempticks2 - tempticks1);
310 +
311        DatLinks := Connection.GetDatLinks(FileID);
312        if Length(DatLinks) > 0 then
313        begin
# Line 306 | Line 322 | begin
322          end;
323        end;
324  
325 +      QueryPerformanceCounter(tempticks1);
326 +      linksum := linksum + (tempticks1 - tempticks2);
327 +
328        RawLinks := Connection.GetRawList(FileID);
329        if Length(RawLinks) > 0 then
330        begin
# Line 332 | Line 351 | begin
351        end;
352        DatFileStream.Seek(0, soFromBeginning);
353        Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
354 +
355 +      QueryPerformanceCounter(tempticks2);
356 +      rawsum := rawsum + (tempticks2 - tempticks1);
357      end
358      else
359 <      FilesHeader[i].DataAddr := 0;
359 >      FilesHeader[FileID].DataAddr := 0;
360      if Length(fileinfo.Name) > 0 then
361      begin
362 <      FilesHeader[i].NameAddr := Stream_Names.Size;
362 >      FilesHeader[FileID].NameAddr := Stream_Names.Size;
363        temps := fileinfo.Extension + fileinfo.Name + Chr(0);
364        Stream_Names.Write(temps[1], Length(temps));
365      end
366      else
367 <      FilesHeader[i].NameAddr := 0;
368 <    FilesHeader[i].FileSize := fileinfo.Size;
369 <    FilesHeader[i].FileType := fileinfo.FileType;
367 >      FilesHeader[FileID].NameAddr := 0;
368 >    FilesHeader[FileID].FileSize := fileinfo.Size;
369 >    FilesHeader[FileID].FileType := fileinfo.FileType;
370  
371      if ((FileID mod 10) = 0) and (FileID >= 100) then
372        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
# Line 354 | Line 376 | begin
376      Application.ProcessMessages;
377    end;
378  
379 +  ShowMessage('AvgDats: ' + FloatToStr((datsum / progress.Max) / freq) + #13#10 +
380 +      'AvgLinks: ' + FloatToStr((linksum / progress.Max) / freq) + #13#10 +
381 +      'AvgRaws: ' + FloatToStr((rawsum / progress.Max) / freq)
382 +   );
383 +
384    Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
385    for i := 0 to High(FilesHeader) do
386      Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
# Line 365 | Line 392 | begin
392    DatHeader.DataSize  := Stream_Body.Size;
393    DatHeader.NamesSize := Stream_Names.Size;
394    DatHeader.DataAddr  := Stream_Dat.Size;
395 +
396    Stream_Body.Seek(0, soFromBeginning);
397    Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
398    DatHeader.NamesAddr := Stream_Dat.Size;
# Line 420 | Line 448 | begin
448  
449  
450   procedure TForm_LevelDB.CreateDatabase(Source, target: String);
451 + var
452 +  DataBase:  TABSDatabase;
453   {
454   var
455    DataBase:    TABSDatabase;
# Line 481 | Line 511 | begin
511    absolutebegintime := Time;
512  
513    DataBase := TABSDatabase.Create(Self);
514 + }
515 +  DataBase.MaxConnections := 1;
516 +  DataBase.PageSize := 8112;
517 +  DataBase.PageCountInExtent := 8;
518 + {
519    DataBase.DatabaseName := 'OLDB';
520    DataBase.DatabaseFileName := target;
521    DataBase.CreateDatabase;
# Line 494 | Line 529 | begin
529    Query := TABSQuery.Create(Self);
530    Query.DatabaseName := 'OLDB';
531    Query.SQL.Text :=
532 <    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), value STRING(128) );';
532 >    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), ' +
533 >    'value STRING(128) );';
534    Query.ExecSQL;
535    Query.SQL.Text :=
536 <    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, target_id INTEGER );';
536 >    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
537 >    'src_link_offset INTEGER, target_id INTEGER,  INDEX idsrcid src_id, ' +
538 >    'INDEX iddestid target_id);';
539    Query.ExecSQL;
540    Query.SQL.Text :=
541 <    'CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, sep BOOLEAN, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
541 >    'CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
542 >    'src_link_offset INTEGER, sep BOOLEAN, size INTEGER, ' +
543 >    'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib, ' +
544 >    'INDEX idsrcid src_id);';
545    //    Query.SQL.Text:='CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
546    Query.ExecSQL;
547    Query.SQL.Text :=
548 <    'CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
548 >    'CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), ' +
549 >    'name STRING(128), contenttype INTEGER, size INTEGER, ' +
550 >    'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
551    //    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
552    Query.ExecSQL;
553 <  Query.SQL.Text :=
554 <    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
555 <  Query.ExecSQL;
553 > //  Query.SQL.Text :=
554 > //    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
555 > //  Query.ExecSQL;
556  
557    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
558      dbversion + '");';
# Line 518 | Line 561 | begin
561    for i := 0 to High(OniDataConnection.LevelInfo.Ident) do
562      Data[i] := OniDataConnection.LevelInfo.Ident[i];
563    temps := CreateHexString(Data, True);
564 <  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("ident","' + temps + '");';
565 <  Query.ExecSQL;
564 > //  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("ident","' + temps + '");';
565 > //  Query.ExecSQL;
566    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
567      IntToStr(OniDataConnection.LevelInfo.LevelNumber) + '");';
568    Query.ExecSQL;

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)