DEADSOFTWARE

buffer network messages (broke a lot of shit)
[d2df-sdl.git] / src / game / g_window.pas
index 9d27d57e974d056eb6910c4e71abea088d66d9d5..a8c6b6a7b3c3bf8302e95d712e2a2b875750359a 100644 (file)
@@ -13,7 +13,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *)
-{$MODE DELPHI}
+{$INCLUDE g_amodes.inc}
 unit g_window;
 
 interface
@@ -38,6 +38,8 @@ function  g_Window_SetSize(W, H: Word; FScreen: Boolean): Boolean;
 
 var
   gwin_dump_extensions: Boolean = false;
+  gwin_has_stencil: Boolean = false;
+  gwin_k8_enable_light_experiments: Boolean = false;
 
 implementation
 
@@ -543,10 +545,17 @@ begin
   e_SoundUpdate();
 
   if NetMode = NET_SERVER then
-    g_Net_Host_Update
-  else
-    if (NetMode = NET_CLIENT) and (NetState <> NET_STATE_AUTH) then
-      g_Net_Client_UpdateWhileLoading;
+  begin
+    g_Net_Host_Update();
+    g_Net_Flush();
+  end
+  else if NetMode = NET_CLIENT then
+    if (NetState <> NET_STATE_AUTH) then
+    begin
+      g_Net_Client_UpdateWhileLoading();
+      g_Net_Flush();
+    end;
+
   wLoadingProgress := False;
 end;
 
@@ -584,12 +593,14 @@ begin
       if NetMode = NET_SERVER then g_Net_Host_Update()
       else if NetMode = NET_CLIENT then g_Net_Client_Update();
       Update();
+      if NetMode <> NET_NONE then g_Net_Flush();
     end;
   end
-  else
+  else if NetMode <> NET_NONE then
   begin
     if NetMode = NET_SERVER then g_Net_Host_Update()
     else if NetMode = NET_CLIENT then g_Net_Client_Update();
+    g_Net_Flush();
   end;
 
   if wLoadingQuit then
@@ -640,6 +651,10 @@ begin
   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+  if gwin_k8_enable_light_experiments then
+  begin
+    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); // lights; it is enough to have 1-bit stencil buffer for lighting
+  end;
   SDL_GL_SetSwapInterval(v);
 end;
 
@@ -687,11 +702,18 @@ end;
 function SDLMain(): Integer;
 var
   idx: Integer;
+  ltmp: Integer;
 begin
 {$IFDEF HEADLESS}
   e_NoGraphics := True;
 {$ENDIF}
 
+  for idx := 1 to ParamCount do
+  begin
+    if ParamStr(idx) = '--opengl-dump-exts' then gwin_dump_extensions := true;
+    if ParamStr(idx) = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
+  end;
+
   e_WriteLog('Initializing OpenGL', MSG_NOTIFY);
   InitOpenGL(gVSync);
 
@@ -704,9 +726,15 @@ begin
 
   {EnumDisplayModes();}
 
-  for idx := 1 to ParamCount do
+  if gwin_k8_enable_light_experiments then
   begin
-    if ParamStr(idx) = '--opengl-dump-exts' then gwin_dump_extensions := true;
+    SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, @ltmp);
+    e_WriteLog(Format('stencil buffer size: %d', [ltmp]), MSG_WARNING);
+    gwin_has_stencil := (ltmp > 0);
+  end
+  else
+  begin
+    gwin_has_stencil := false;
   end;
 
   if not glHasExtension('GL_ARB_texture_non_power_of_two') then