DEADSOFTWARE

gl: optimize grid drawing
[d2df-editor.git] / src / editor / f_main.pas
index 4d62e2ef6a0c04dfe7d373b0ac7b515dc997f174..bf92c229531d27eacc2a0bb83561c9ed3bcb9dd4 100644 (file)
@@ -2756,6 +2756,8 @@ begin
 
   config := TConfig.CreateFile(CfgFileName);
 
+  gWADEditorLogLevel := config.ReadInt('WADEditor', 'LogLevel', DFWAD_LOG_DEFAULT);
+
   if config.ReadInt('Editor', 'XPos', -1) = -1 then
     Position := poDesktopCenter
   else begin
@@ -2862,6 +2864,23 @@ begin
   e_TextureFontPrintEx(X, Y, Text, FontID, 0, 0, 0, 1.0);
 end;
 
+procedure InitGraphics;
+begin
+  // FIXME: this is a shitty hack
+  if not gDataLoaded then
+  begin
+    e_WriteLog('Init OpenGL', MSG_NOTIFY);
+    e_InitGL();
+    e_WriteLog('Loading data', MSG_NOTIFY);
+    LoadStdFont('STDTXT', 'STDFONT', gEditorFont);
+    e_WriteLog('Loading more data', MSG_NOTIFY);
+    LoadData();
+    e_WriteLog('Loading even more data', MSG_NOTIFY);
+    gDataLoaded := True;
+    MainForm.FormResize(nil);
+  end;
+end;
+
 procedure TMainForm.Draw();
 var
   x, y: Integer;
@@ -2877,6 +2896,8 @@ begin
   Width := 0;
   Height := 0;
 
+  InitGraphics();
+
   e_BeginRender();
 
   e_Clear(GL_COLOR_BUFFER_BIT,
@@ -2928,22 +2949,23 @@ begin
     else
       a := 0;
 
+    glDisable(GL_TEXTURE_2D);
+    glColor3ub(GetRValue(DotColor), GetGValue(DotColor), GetBValue(DotColor));
+    glPointSize(DotSize);
+    glBegin(GL_POINTS);
     x := MapOffset.X mod DotStep;
-    y := MapOffset.Y mod DotStep;
-
     while x < RenderPanel.Width do
     begin
+      y := MapOffset.Y mod DotStep;
       while y < RenderPanel.Height do
       begin
-        e_DrawPoint(DotSize, x + a, y + a,
-                    GetRValue(DotColor),
-                    GetGValue(DotColor),
-                    GetBValue(DotColor));
+        glVertex2i(x + a, y + a);
         y += DotStep;
       end;
       x += DotStep;
-      y := MapOffset.Y mod DotStep;
     end;
+    glEnd();
+    glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255);
   end;
 
 // Превью текстуры:
@@ -3759,7 +3781,12 @@ begin
   if Button = mbMiddle then
     MouseMDown := False;
 
-  DrawRect := nil;
+  if DrawRect <> nil then
+  begin
+    Dispose(DrawRect);
+    DrawRect := nil;
+  end;
+
   ResizeType := RESIZETYPE_NONE;
   TextureID := 0;
 
@@ -4324,8 +4351,11 @@ begin
   end;
 
 // Клавиши мыши не зажаты:
-  if (not MouseRDown) and (not MouseLDown) then
+  if (not MouseRDown) and (not MouseLDown) and (DrawRect <> nil) then
+  begin
+    Dispose(DrawRect);
     DrawRect := nil;
+  end;
 
 // Строка состояния - координаты мыши:
   StatusBar.Panels[1].Text := Format('(%d:%d)',
@@ -4355,6 +4385,8 @@ var
 begin
   config := TConfig.CreateFile(CfgFileName);
 
+  config.WriteInt('WADEditor', 'LogLevel', gWADEditorLogLevel);
+
   if WindowState <> wsMaximized then
   begin
     config.WriteInt('Editor', 'XPos', Left);
@@ -6689,20 +6721,6 @@ end;
 procedure TMainForm.OnIdle(Sender: TObject; var Done: Boolean);
   var f: AnsiString;
 begin
-  // FIXME: this is a shitty hack
-  if not gDataLoaded then
-  begin
-    e_WriteLog('Init OpenGL', MSG_NOTIFY);
-    e_InitGL();
-    e_WriteLog('Loading data', MSG_NOTIFY);
-    LoadStdFont('STDTXT', 'STDFONT', gEditorFont);
-    e_WriteLog('Loading more data', MSG_NOTIFY);
-    LoadData();
-    e_WriteLog('Loading even more data', MSG_NOTIFY);
-    gDataLoaded := True;
-    MainForm.FormResize(nil);
-  end;
-  Draw();
   if StartMap <> '' then
   begin
     f := StartMap;