⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rw_imp.pas

📁 delphi编的不错的贪吃蛇
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    GetClientRect(sww_state.h_Wnd, R);
    OffsetRect(R, p.x, p.y);
    SetRect(RS, 0, 0, vid.width, vid.height);
    rval := sww_state.lpddsFrontBuffer.Blt(@R, sww_state.lpddsOffScreenBuffer, @RS, DDBLT_WAIT, nil);
    if rval = DDERR_SURFACELOST then
    begin
      sww_state.lpddsFrontBuffer._Restore;
      sww_state.lpddsFrontBuffer.Blt(@R, sww_state.lpddsOffScreenBuffer, @RS, DDBLT_WAIT, nil);
    end;

{$ELSE}
    if sww_State.Modex then
    Begin
      Rval := sww_state.lpddsBackBuffer.BltFast(0, 0,
						                                    sww_state.lpddsOffScreenBuffer,
						                                    @r,DDBLTFAST_WAIT);
      if RVal = DDERR_SURFACELOST then
      Begin
        sww_state.lpddsBackBuffer._Restore;
        sww_state.lpddsBackBuffer.BltFast(0, 0, sww_state.lpddsOffScreenBuffer,
					                                @r, DDBLTFAST_WAIT );
      end;
      Rval := sww_state.lpddsFrontBuffer.Flip(Nil, DDFLIP_WAIT);
      if Rval = DDERR_SURFACELOST then
      Begin
        sww_state.lpddsFrontBuffer._Restore;
        sww_state.lpddsFrontBuffer.Flip(Nil, DDFLIP_WAIT);
      end;
    end
    Else
    Begin
      rval := sww_state.lpddsBackBuffer.BltFast(0, 0, sww_state.lpddsOffScreenBuffer,
                                                @r,DDBLTFAST_WAIT);
      if rval = DDERR_SURFACELOST then
      Begin
        sww_state.lpddsBackBuffer._Restore;
        sww_state.lpddsBackBuffer.BltFast(0, 0, sww_state.lpddsOffScreenBuffer,
                                          @r, DDBLTFAST_WAIT);
      end;
    end;
{$ENDIF}

    FillChar(ddsd,SizeOf(ddsd),0);
    ddsd.dwSize := sizeOf(ddsd);

    sww_state.lpddsOffScreenBuffer.Lock(nil, ddsd, DDLOCK_WAIT, 0);

    vid.Buffer   := ddsd.lpSurface;
    vid.RowBytes := ddsd.lPitch;
  end;
end;

(*
** SWimp_SetMode
*)

function SWimp_SetMode(pWidth,pHeight : PInteger; Mode : Integer; FullScreen : QBoolean): rserr_t;
const
  win_fs : array[0..1] of Pchar = ('W','FS');
var
  retVal : rserr_t;
Begin
  retval := rserr_ok;
  ri.Con_Printf(PRINT_ALL, PChar('setting mode '+IntToStr(mode)+':'));
  if not Ri.Vid_GetModeInfo(pwidth, pheight, mode) then
  Begin
    ri.Con_Printf(PRINT_ALL, ' invalid mode'+#13#10);
    Result := rserr_invalid_mode;
    Exit;
  end;

  ri.Con_Printf(PRINT_ALL, PChar(' '+IntToStr(pwidth^)+' '+IntToStr(pheight^)+' '+win_fs[Integer(fullscreen) and 1]+#13#10));
  sww_state.Initializing := true;
  if FullScreen  then
  Begin
    if not SWimp_InitGraphics(True) then
    Begin
      if SWimp_InitGraphics(False)  then
      Begin
        // mode is legal but not as fullscreen
        fullscreen := False;
        retval := rserr_invalid_fullscreen;
      end
      else
      Begin
        // failed to set a valid mode in windowed mode
       	retval := rserr_unknown;
      end;
    end;
  end
  else
  Begin
    // failure to set a valid mode in windowed mode
    if not SWimp_InitGraphics(fullscreen) then
    Begin
      sww_state.initializing := true;
      result := rserr_unknown;
      exit;
    end;
  end;
  sw_state.fullscreen := fullscreen;

  R_GammaCorrectAndSetPalette(PByte(@d_8to24table));
  sww_state.initializing := true;

  Result := RetVal;

end;

(*
** SWimp_SetPalette
**
** System specific palette setting routine.  A NULL palette means
** to use the existing palette.  The palette is expected to be in
** a padded 4-byte xRGB format.
*)

procedure SWimp_SetPalette(Palette : PByteArray);
Begin
// MGL - what the fuck was kendall doing here?!
// clear screen to black and change palette
//	for (i=0 ; i<vid.height ; i++)
//		memset (vid.buffer + i*vid.rowbytes, 0, vid.width);

  if not Assigned(Palette) then
    Palette := (@sw_state.currentpalette);
  if not sw_state.FullScreen then
    DIB_SetPalette(Palette)
  else
    DDraw_SetPalette(Palette);
end;

(*
** SWimp_Shutdown
**
** System specific graphics subsystem shutdown routine.  Destroys
** DIBs or DDRAW surfaces as appropriate.
*)

procedure SWimp_ShutDown;
Begin
  ri.Con_Printf(PRINT_ALL, 'Shutting down SW imp'+#13#10);
  DIB_Shutdown;
  DDRAW_Shutdown;

  if sww_state.h_wnd <> 0 then
  Begin
    ri.Con_Printf(PRINT_ALL, '...destroying window'+#13#10);
    ShowWindow( sww_state.h_Wnd, SW_SHOWNORMAL);	// prevents leaving empty slots in the taskbar
    DestroyWindow(sww_state.h_Wnd);
    sww_state.h_Wnd := 0;
    UnregisterClass(WINDOW_CLASS_NAME, sww_state.h_Inst);
  end;
end;

(*
** SWimp_AppActivate
*)

procedure SWimp_AppActivate(Active : qBoolean);
Begin
  if Active then
  begin
    if sww_state.h_wnd <> 0 then
    begin
      SetForegroundWindow(sww_state.h_Wnd);
      ShowWindow(sww_state.h_Wnd, SW_RESTORE);
    end;
  end
  else
  begin
    if sww_state.h_wnd <> 0 then
    begin
      if sww_state.Initializing then
        Exit;
      if vid_fullscreen.Value <> 0 then
        ShowWindow(sww_state.h_wnd, SW_MINIMIZE);
    end;
  end;
end;

//===============================================================================


(*
================
Sys_MakeCodeWriteable
================
*)

procedure Sys_MakeCodeWriteable(StartAddr, Length : Double);
//var
//  flOldProtect : DWORD;
Begin
// This has been removed because we do not use any code that is self-
// modificating. The asm routine that do so has been changed.

//  if not(VirtualProtect(startaddr, length, PAGE_READWRITE, @flOldProtect)) then
//  ri.sys_Error(ERR_FATAL, 'Protection change failed\n');
//
end;

(*
** Sys_SetFPCW
**
** For reference:
**
** 1
** 5               0
** xxxxRRPP.xxxxxxxx
**
** PP = 00 = 24-bit single precision
** PP = 01 = reserved
** PP = 10 = 53-bit double precision
** PP = 11 = 64-bit extended precision
**
** RR = 00 = round to nearest
** RR = 01 = round down (towards -inf, floor)
** RR = 10 = round up (towards +inf, ceil)
** RR = 11 = round to zero (truncate/towards 0)
**
*)
{$IFNDEF id386}
procedure Sys_SetFPCW;
begin
end;
{$ELSE}
var
  fpu_ceil_cwfpu_chop_cw,
  fpu_full_cw,
  fpu_cw,
  fpu_pushed_cw : Cardinal;
  fpu_sp24_cw,
  fpu_sp24_ceil_cw : Cardinal;

procedure Sys_SetFPCW;
begin
  asm
  xor eax, eax
  fnstcw  word ptr fpu_cw
  mov ax, word ptr fpu_cw

  and ah, 0f0h
  or  ah, 003h          // round to nearest mode, extended precision
  mov fpu_full_cw, eax

  and ah, 0f0h
  or  ah, 00fh          // RTZ/truncate/chop mode, extended precision
  mov fpu_chop_cw, eax

  and ah, 0f0h
  or  ah, 00bh          // ceil mode, extended precision
  mov fpu_ceil_cw, eax

  and ah, 0f0h          // round to nearest, 24-bit single precision
  mov fpu_sp24_cw, eax

  and ah, 0f0h          // ceil mode, 24-bit single precision
  or  ah, 008h          //
  mov fpu_sp24_ceil_cw, eax
end;
{$ENDIF}




end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -