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

📄 cl_view.pas

📁 delphi编的不错的贪吃蛇
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{$ALIGN ON}{$MINENUMSIZE 4}
{----------------------------------------------------------------------------}
{                                                                            }
{ File(s): client\cl_view.c                                                  }
{                                                                            }
{ Initial conversion by : Ter Roshak                                         }
{ Initial conversion on : ?                                                  }
{                                                                            }
{ This File contains part of convertion of Quake2 source to ObjectPascal.    }
{ More information about this project can be found at:                       }
{ http://www.sulaco.co.za/quake2/                                            }
{                                                                            }
{ Copyright (C) 1997-2001 Id Software, Inc.                                  }
{                                                                            }
{ This program is free software; you can redistribute it and/or              }
{ modify it under the terms of the GNU General Public License                }
{ as published by the Free Software Foundation; either version 2             }
{ of the License, or (at your option) any later version.                     }
{                                                                            }
{ This program is distributed in the hope that it will be useful,            }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of             }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                       }
{                                                                            }
{ See the GNU General Public License for more details.                       }
{                                                                            }
{----------------------------------------------------------------------------}
// cl_view.c -- player rendering positioning

unit cl_view;

interface

uses
  q_shared,
  Client,
  ref;

procedure V_ClearScene;
procedure V_AddLightStyle(style: integer; r, g, b: single);
procedure V_AddEntity(ent: entity_p);
procedure V_AddParticle(const org: vec3_t; color: integer; alpha: single);
procedure V_AddLight(const org: vec3_t; intensity: Single; r, g, b: Single);
procedure V_TestParticles;
procedure V_RenderView(stereo_separation: single);
procedure V_Init;

procedure CL_PrepRefresh;
function CalcFov(fov_x, width, height: Single): Single;

//=============
//
// development tools for weapons
//
var
  gun_frame: integer;
  gun_model: model_p;

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

  crosshair: cvar_p;
  cl_testparticles: cvar_p;
  cl_testentities: cvar_p;
  cl_testlights: cvar_p;
  cl_testblend: cvar_p;

  cl_stats: cvar_p;

  r_numdlights: integer;
  r_dlights: array[0..MAX_DLIGHTS - 1] of dlight_t;

  r_numentities: integer;
  r_entities: array[0..MAX_ENTITIES - 1] of entity_t;

  r_numparticles: integer;
  r_particles: array[0..MAX_PARTICLES - 1] of particle_t;

  r_lightstyles: array[0..MAX_LIGHTSTYLES - 1] of lightstyle_t;

  cl_weaponmodels: array[0..MAX_CLIENTWEAPONMODELS - 1] of array[0..MAX_QPATH - 1] of char;
  num_cl_weaponmodels: integer;

implementation

uses
  cl_scrn,
  cl_main,
  {$IFDEF WIN32}
  sys_win,
  q_shwin,
  cd_win,
  vid_dll,
  {$ELSE}
  sys_linux,
  q_shlinux,
  cd_sdl,
  vid_so,
  {$ENDIF}
  CModel,
  CPas,
  Cmd,
  Common,
  cl_tent,
  cl_parse,
  cl_ents,
  CVar,
  Console,
  sysutils,
  math;

{
====================
V_ClearScene

Specifies the model that will be used as the world
====================
}

procedure V_ClearScene;
begin

  r_numdlights := 0;
  r_numentities := 0;
  r_numparticles := 0;

end;

{
=====================
V_AddEntity

=====================
}

procedure V_AddEntity(ent: entity_p);
begin

  if (r_numentities >= MAX_ENTITIES) then
    exit;
  r_entities[r_numentities] := ent^;
  inc(r_numentities);

end;

{
=====================
V_AddParticle

=====================
}

procedure V_AddParticle(const org: vec3_t; color: integer; alpha: single);
var
  p: particle_p;
begin
  if (r_numparticles >= MAX_PARTICLES) then
    exit;
  p := @r_particles[r_numparticles];
  inc(r_numparticles);
  VectorCopy(org, p^.origin);
  p^.color := color;
  p^.alpha := alpha;
end;

{
=====================
V_AddLight

=====================
}

procedure V_AddLight(const org: vec3_t; intensity: Single; r, g, b: Single);
var
  dl: dlight_p;
begin
  if (r_numdlights >= MAX_DLIGHTS) then
    exit;
  dl := @r_dlights[r_numdlights];
  inc(r_numdlights);
  VectorCopy(org, dl^.origin);
  dl^.intensity := intensity;
  dl^.color[0] := r;
  dl^.color[1] := g;
  dl^.color[2] := b;
end;

{
=====================
V_AddLightStyle

=====================
}

procedure V_AddLightStyle(style: integer; r, g, b: single);
var
  ls: lightstyle_p;
begin

  if ((style < 0) or (style > MAX_LIGHTSTYLES)) then
    Com_Error(ERR_DROP, 'Bad light style %d', [style]);
  ls := @r_lightstyles[style];

  ls^.white := r + b + g;
  ls^.rgb[0] := r;
  ls^.rgb[1] := g;
  ls^.rgb[2] := b;

end;

{
================
V_TestParticles

If cl_testparticles is set, create 4096 particles in the view
================
}

procedure V_TestParticles;
var
  p: particle_p;
  i, j: integer;
  d, r, u: Single;
begin

  r_numparticles := MAX_PARTICLES;
  for i := 0 to r_numparticles - 1 do
  begin
    d := i * 0.25;
    r := 4 * ((i and 7) - 3.5);
    u := 4 * (((i shr 3) and 7) - 3.5);
    p := @r_particles[i];

    for j := 0 to 2 do
      p^.origin[j] := cl.refdef.vieworg[j] + cl.v_forward[j] * d +
        cl.v_right[j] * r + cl.v_up[j] * u;

    p^.color := 8;
    p^.alpha := cl_testparticles^.value;
  end;

end;

{
================
V_TestEntities

If cl_testentities is set, create 32 player models
================
}

procedure V_TestEntities;
var
  i, j: integer;
  f, r: Single;
  ent: entity_p;
begin

  r_numentities := 32;
  FillChar(r_entities, sizeof(r_entities), 0);

  for i := 0 to r_numentities - 1 do
  begin
    ent := @r_entities[i];

    r := 64 * ((i mod 4) - 1.5);
    f := 64 * (i / 4) + 128;

    for j := 0 to 2 do
      ent^.origin[j] := cl.refdef.vieworg[j] + cl.v_forward[j] * f +
        cl.v_right[j] * r;
    ent^.model := cl.baseclientinfo.model;
    ent^.skin := cl.baseclientinfo.skin;
  end;

end;

{
================
V_TestLights

If cl_testlights is set, create 32 lights models
================
}

procedure V_TestLights;
var
  i, j: integer;
  f, r: Single;
  dl: dlight_p;
begin

  r_numdlights := 32;
  FillChar(r_dlights, sizeof(r_dlights), 0);

  for i := 0 to r_numdlights - 1 do
  begin
    dl := @r_dlights[i];

    r := 64 * ((i mod 4) - 1.5);
    f := 64 * (i / 4) + 128;

    for j := 0 to 2 do
      dl^.origin[j] := cl.refdef.vieworg[j] + cl.v_forward[j] * f + cl.v_right[j] * r;

    dl^.color[0] := ((i mod 6) + 1) and 1;
    dl^.color[1] := (((i mod 6) + 1) and 2) shr 1;
    dl^.color[2] := (((i mod 6) + 1) and 4) shr 2;
    dl^.intensity := 200;
  end;

end;

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

{
=================
CL_PrepRefresh

Call before entering a new level, or after changing dlls
=================
}

procedure CL_PrepRefresh;
var
  mapname: array[0..31] of char;
  i: integer;
  name: array[0..MAX_QPATH - 1] of char;
  rotate: Single;
  axis: vec3_t;
begin
  if (cl.configstrings[CS_MODELS + 1][0] = #0) then
    exit;                               // no map loaded

  SCR_AddDirtyPoint(0, 0);
  SCR_AddDirtyPoint(viddef.width - 1, viddef.height - 1);

  // let the render dll load the map
  strcpy(mapname, cl.configstrings[CS_MODELS + 1] + 5); // skip "maps/"
  mapname[strlen(mapname) - 4] := #0;   // cut off ".bsp"

  // register models, pics, and skins
  Com_Printf('Map: %s'#13, [mapname]);

⌨️ 快捷键说明

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