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 131 by alloc, Wed Mar 28 01:20:26 2007 UTC vs.
Revision 137 by alloc, Fri Mar 30 00:00:10 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 280 | 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 288 | 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 >      tempi := FileID * 256 + 1;
306 >      DatFileStream.Write(tempi, 4);
307        DatFileStream.Write(LevelID, 4);
308  
309 +      QueryPerformanceCounter(tempticks2);
310 +      datsum := datsum + (tempticks2 - tempticks1);
311 +
312        DatLinks := Connection.GetDatLinks(FileID);
313        if Length(DatLinks) > 0 then
314        begin
# Line 308 | Line 323 | begin
323          end;
324        end;
325  
326 +      QueryPerformanceCounter(tempticks1);
327 +      linksum := linksum + (tempticks1 - tempticks2);
328 +
329        RawLinks := Connection.GetRawList(FileID);
330        if Length(RawLinks) > 0 then
331        begin
# Line 334 | Line 352 | begin
352        end;
353        DatFileStream.Seek(0, soFromBeginning);
354        Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
355 +
356 +      QueryPerformanceCounter(tempticks2);
357 +      rawsum := rawsum + (tempticks2 - tempticks1);
358      end
359      else
360 <      FilesHeader[i].DataAddr := 0;
360 >      FilesHeader[FileID].DataAddr := 0;
361      if Length(fileinfo.Name) > 0 then
362      begin
363 <      FilesHeader[i].NameAddr := Stream_Names.Size;
363 >      FilesHeader[FileID].NameAddr := Stream_Names.Size;
364        temps := fileinfo.Extension + fileinfo.Name + Chr(0);
365        Stream_Names.Write(temps[1], Length(temps));
366      end
367      else
368 <      FilesHeader[i].NameAddr := 0;
369 <    FilesHeader[i].FileSize := fileinfo.Size;
370 <    FilesHeader[i].FileType := fileinfo.FileType;
368 >      FilesHeader[FileID].NameAddr := 0;
369 >    FilesHeader[FileID].FileSize := fileinfo.Size;
370 >    FilesHeader[FileID].FileType := fileinfo.FileType;
371  
372      if ((FileID mod 10) = 0) and (FileID >= 100) then
373        lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
# Line 356 | Line 377 | begin
377      Application.ProcessMessages;
378    end;
379  
380 +  ShowMessage('AvgDats: ' + FloatToStr((datsum / progress.Max) / freq) + #13#10 +
381 +      'AvgLinks: ' + FloatToStr((linksum / progress.Max) / freq) + #13#10 +
382 +      'AvgRaws: ' + FloatToStr((rawsum / progress.Max) / freq)
383 +   );
384 +
385    Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
386    for i := 0 to High(FilesHeader) do
387      Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
# Line 367 | Line 393 | begin
393    DatHeader.DataSize  := Stream_Body.Size;
394    DatHeader.NamesSize := Stream_Names.Size;
395    DatHeader.DataAddr  := Stream_Dat.Size;
396 +
397    Stream_Body.Seek(0, soFromBeginning);
398    Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
399    DatHeader.NamesAddr := Stream_Dat.Size;
# Line 422 | Line 449 | begin
449  
450  
451   procedure TForm_LevelDB.CreateDatabase(Source, target: String);
452 + var
453 +  DataBase:  TABSDatabase;
454   {
455   var
456    DataBase:    TABSDatabase;
# Line 483 | Line 512 | begin
512    absolutebegintime := Time;
513  
514    DataBase := TABSDatabase.Create(Self);
515 + }
516 +  DataBase.MaxConnections := 1;
517 +  DataBase.PageSize := 8112;
518 +  DataBase.PageCountInExtent := 8;
519 + {
520    DataBase.DatabaseName := 'OLDB';
521    DataBase.DatabaseFileName := target;
522    DataBase.CreateDatabase;
# Line 496 | Line 530 | begin
530    Query := TABSQuery.Create(Self);
531    Query.DatabaseName := 'OLDB';
532    Query.SQL.Text :=
533 <    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), value STRING(128) );';
533 >    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), ' +
534 >    'value STRING(128) );';
535    Query.ExecSQL;
536    Query.SQL.Text :=
537 <    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, target_id INTEGER );';
537 >    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
538 >    'src_link_offset INTEGER, target_id INTEGER,  INDEX idsrcid src_id, ' +
539 >    'INDEX iddestid target_id);';
540    Query.ExecSQL;
541    Query.SQL.Text :=
542 <    '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 );';
542 >    'CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
543 >    'src_link_offset INTEGER, sep BOOLEAN, size INTEGER, ' +
544 >    'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib, ' +
545 >    'INDEX idsrcid src_id);';
546    //    Query.SQL.Text:='CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
547    Query.ExecSQL;
548    Query.SQL.Text :=
549 <    '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 );';
549 >    'CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), ' +
550 >    'name STRING(128), contenttype INTEGER, size INTEGER, ' +
551 >    'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
552    //    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
553    Query.ExecSQL;
554 <  Query.SQL.Text :=
555 <    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
556 <  Query.ExecSQL;
554 > //  Query.SQL.Text :=
555 > //    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
556 > //  Query.ExecSQL;
557  
558    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
559      dbversion + '");';
# Line 520 | Line 562 | begin
562    for i := 0 to High(OniDataConnection.LevelInfo.Ident) do
563      Data[i] := OniDataConnection.LevelInfo.Ident[i];
564    temps := CreateHexString(Data, True);
565 <  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("ident","' + temps + '");';
566 <  Query.ExecSQL;
565 > //  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("ident","' + temps + '");';
566 > //  Query.ExecSQL;
567    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
568      IntToStr(OniDataConnection.LevelInfo.LevelNumber) + '");';
569    Query.ExecSQL;

Diff Legend

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