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

📄 gl_model.pas

📁 雷神之锤2(Quake2)Delphi源码
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  if (count < 1) OR (count >= MAX_MAP_SURFEDGES) then
    ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: bad surfedges count in %s: %i',
                            [loadmodel.name, count]);

(*Y  _out := Hunk_Alloc ( count*sizeof(*out));

  loadmodel.surfedges := _out;*)
  loadmodel.numsurfedges := count;

  for i:=0 to count-1 do
(*Y    _out[i] := LittleLong (in[i])*);
end;

{*
=================
Mod_LoadPlanes
=================
*}
procedure Mod_LoadPlanes (l : lump_p);
var
  i, j  : integer;
  _out  : cplane_p;
  _in   : dplane_p;
  count,
  bits  : integer;
begin
//Y  in = (void * )(mod_base + l->fileofs);
  if (l.filelen MOD sizeof(_in^)) <> 0 then
    ri.Sys_Error (ERR_DROP, 'MOD_LoadBmodel: funny lump size in %s', [loadmodel.name]);
  count := l.filelen DIV sizeof(_in^);
//Y  _out = Hunk_Alloc ( count*2*sizeof(*out));

  loadmodel.planes := _out;
  loadmodel.numplanes := count;

//Y  for ( i=0 ; i<count ; i++, in++, out++)
  begin
    bits := 0;
    for j:=0 to 2 do
    begin
      _out.normal[j] := LittleFloat (_in.normal[j]);
      if (_out.normal[j] < 0) then
//              bits |= 1<<j;
        bits := bits OR (1 SHL j);
    end;

    _out.dist := LittleFloat (_in.dist);
    _out._type := LittleLong (_in._type);
    _out.signbits := bits;
  end;
end;

{*
=================
Mod_LoadBrushModel
=================
*}
procedure Mod_LoadBrushModel (_mod : model_p; buffer : pointer);
var
  i       : integer;
  header  : dheader_p;
  bm      : mmodel_p;
  starmod : model_p;
begin
  loadmodel._type := mod_brush;
//Y  if (loadmodel <> mod_known) then
          ri.Sys_Error (ERR_DROP, 'Loaded a brush model after the world', []);

  header := {(dheader_t * )}buffer;

//Y  i := LittleLong (header->version);
  if (i <> BSPVERSION) then
    ri.Sys_Error (ERR_DROP, 'Mod_LoadBrushModel: %s has wrong version number (%i should be %i)', [_mod.name, i, BSPVERSION]);

// swap all the lumps
(*Y  mod_base := {(byte * )}header;

  for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
          ((int * )header)[i] = LittleLong ( ((int * )header)[i]);*)

// load into heap
  Mod_LoadVertexes (@header.lumps[LUMP_VERTEXES]);
  Mod_LoadEdges (@header.lumps[LUMP_EDGES]);
  Mod_LoadSurfedges (@header.lumps[LUMP_SURFEDGES]);
  Mod_LoadLighting (@header.lumps[LUMP_LIGHTING]);
  Mod_LoadPlanes (@header.lumps[LUMP_PLANES]);
  Mod_LoadTexinfo (@header.lumps[LUMP_TEXINFO]);
  Mod_LoadFaces (@header.lumps[LUMP_FACES]);
  Mod_LoadMarksurfaces (@header.lumps[LUMP_LEAFFACES]);
  Mod_LoadVisibility (@header.lumps[LUMP_VISIBILITY]);
  Mod_LoadLeafs (@header.lumps[LUMP_LEAFS]);
  Mod_LoadNodes (@header.lumps[LUMP_NODES]);
  Mod_LoadSubmodels (@header.lumps[LUMP_MODELS]);
  _mod.numframes := 2;	// regular and alternate animation
	
//
// set up the submodels
//
  for i:=0 to _mod.numsubmodels-1 do
  begin
//Y    bm := _mod.submodels[i];
    starmod := @mod_inline[i];

//Y    *starmod = *loadmodel;

    starmod.firstmodelsurface := bm.firstface;
    starmod.nummodelsurfaces := bm.numfaces;
    starmod.firstnode := bm.headnode;
    if (starmod.firstnode >= loadmodel.numnodes) then
      ri.Sys_Error (ERR_DROP, 'Inline model %i has bad firstnode', [i]);

    VectorCopy (bm.maxs, starmod.maxs);
    VectorCopy (bm.mins, starmod.mins);
    starmod.radius := bm.radius;

(*Y    if (i = 0) then
            *loadmodel = *starmod;*)

    starmod.numleafs := bm.visleafs;
  end;
end;


{*
==============================================================================

ALIAS MODELS

==============================================================================
*}

{*
=================
Mod_LoadAliasModel
=================
*}
procedure Mod_LoadAliasModel (_mod : model_p; buffer : pointer);
var
  i, j      : integer;
  pinmodel,
  pheader   : dmdl_p;
  pinst,
  poutst    : dstvert_p;
  pintri,
  pouttri   : dtriangle_p;
(*	daliasframe_t		*pinframe, *poutframe;
	int					*pincmd, *poutcmd;*)
  version : integer;
begin
  pinmodel := {(dmdl_t * )}buffer;

  version := LittleLong (pinmodel.version);
  if (version <> ALIAS_VERSION) then
    ri.Sys_Error (ERR_DROP, '%s has wrong version number (%i should be %i)',
                            [_mod.name, version, ALIAS_VERSION]);

(*Y  pheader := Hunk_Alloc (LittleLong(pinmodel->ofs_end));

  // byte swap the header fields and sanity check
  for (i=0 ; i<sizeof(dmdl_t)/4 ; i++)
          ((int * )pheader)[i] = LittleLong (((int * )buffer)[i]);*)

  if (pheader.skinheight > MAX_LBM_HEIGHT) then
    ri.Sys_Error (ERR_DROP, 'model %s has a skin taller than %d',
                            [_mod.name, MAX_LBM_HEIGHT]);

  if (pheader.num_xyz <= 0) then
    ri.Sys_Error (ERR_DROP, 'model %s has no vertices', [_mod.name]);

  if (pheader.num_xyz > MAX_VERTS) then
    ri.Sys_Error (ERR_DROP, 'model %s has too many vertices', [_mod.name]);

  if (pheader.num_st <= 0) then
    ri.Sys_Error (ERR_DROP, 'model %s has no st vertices', [_mod.name]);

  if (pheader.num_tris <= 0) then
    ri.Sys_Error (ERR_DROP, 'model %s has no triangles', [_mod.name]);

  if (pheader.num_frames <= 0) then
    ri.Sys_Error (ERR_DROP, 'model %s has no frames', [_mod.name]);

//
// load base s and t vertices (not used in gl version)
//
(*Y  pinst  := (dstvert_t * ) ((byte * )pinmodel + pheader->ofs_st);
  poutst := (dstvert_t * ) ((byte * )pheader + pheader->ofs_st);*)

  for i:=0 to pheader.num_st-1 do
  begin
(*Y    poutst[i].s = LittleShort (pinst[i].s);
    poutst[i].t = LittleShort (pinst[i].t);*)
  end;

//
// load triangle lists
//
(*  pintri = (dtriangle_t * ) ((byte * )pinmodel + pheader->ofs_tris);
  pouttri = (dtriangle_t * ) ((byte * )pheader + pheader->ofs_tris);*)

  for i:=0 to pheader.num_tris-1 do
    for j:=0 to 2 do
      begin
(*Y        pouttri[i].index_xyz[j] := LittleShort (pintri[i].index_xyz[j]);
        pouttri[i].index_st[j]  := LittleShort (pintri[i].index_st[j]);*)
      end;

//
// load the frames
//
  for i:=0 to pheader.num_frames-1 do
  begin
(*Y    pinframe = (daliasframe_t * ) ((byte * )pinmodel
            + pheader->ofs_frames + i * pheader->framesize);
    poutframe = (daliasframe_t * ) ((byte * )pheader
            + pheader->ofs_frames + i * pheader->framesize);

    memcpy (poutframe->name, pinframe->name, sizeof(poutframe->name));
    for (j=0 ; j<3 ; j++)
    {
            poutframe->scale[j] = LittleFloat (pinframe->scale[j]);
            poutframe->translate[j] = LittleFloat (pinframe->translate[j]);
    }
    // verts are all 8 bit, so no swapping needed
    memcpy (poutframe->verts, pinframe->verts,
            pheader->num_xyz*sizeof(dtrivertx_t));*)
  end;

  _mod._type := mod_alias;

(*Y  //
  // load the glcmds
  //
  pincmd = (int * ) ((byte * )pinmodel + pheader->ofs_glcmds);
  poutcmd = (int * ) ((byte * )pheader + pheader->ofs_glcmds);
  for (i=0 ; i<pheader->num_glcmds ; i++)
          poutcmd[i] = LittleLong (pincmd[i]);


  // register all skins
  memcpy ((char * )pheader + pheader->ofs_skins, (char * )pinmodel + pheader->ofs_skins,
          pheader->num_skins*MAX_SKINNAME);
  for i:=0 to pheader.num_skins-1 do
    _mod.skins[i] := GL_FindImage ((char * )pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);*)

  _mod.mins[0] := -32;
  _mod.mins[1] := -32;
  _mod.mins[2] := -32;
  _mod.maxs[0] := 32;
  _mod.maxs[1] := 32;
  _mod.maxs[2] := 32;
end;


{*
==============================================================================

SPRITE MODELS

==============================================================================
*}

{*
=================
Mod_LoadSpriteModel
=================
*}
procedure Mod_LoadSpriteModel (_mod : model_p; buffer : pointer);
var
  sprin,
  sprout : dsprite_p;
  i      : integer;
begin
(*	sprin = (dsprite_t * )buffer;
	sprout = Hunk_Alloc (modfilelen);*)

  sprout.ident     := LittleLong (sprin.ident);
  sprout.version   := LittleLong (sprin.version);
  sprout.numframes := LittleLong (sprin.numframes);

  if (sprout.version <> SPRITE_VERSION) then
    ri.Sys_Error (ERR_DROP, '%s has wrong version number (%i should be %i)',
                            [_mod.name, sprout.version, SPRITE_VERSION]);

  if (sprout.numframes > MAX_MD2SKINS) then
    ri.Sys_Error (ERR_DROP, '%s has too many frames (%i > %i)',
                            [_mod.name, sprout.numframes, MAX_MD2SKINS]);

  // byte swap everything
  for i:=0 to sprout.numframes-1 do
  begin
    sprout.frames[i].width    := LittleLong (sprin.frames[i].width);
    sprout.frames[i].height   := LittleLong (sprin.frames[i].height);
    sprout.frames[i].origin_x := LittleLong (sprin.frames[i].origin_x);
    sprout.frames[i].origin_y := LittleLong (sprin.frames[i].origin_y);
(*Y    memcpy (sprout->frames[i].name, sprin->frames[i].name, MAX_SKINNAME);
    _mod.skins[i] :=*) GL_FindImage (sprout.frames[i].name, it_sprite);
  end;

  _mod._type := mod_sprite;
end;


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

{*
@@@@@@@@@@@@@@@@@@@@@
R_BeginRegistration

Specifies the model that will be used as the world
@@@@@@@@@@@@@@@@@@@@@
*}
procedure R_BeginRegistration (model : PChar); cdecl; //for gl_rmain
var
//  char	fullname[MAX_QPATH];
  fullname : array [0..MAX_QPATH-1] of char;
  flushmap : cvar_p;
begin
//Y  registration_sequence++;
  r_oldviewcluster := -1;  // force markleafs

  Com_sprintf (fullname, sizeof(fullname), 'maps/%s.bsp', [model]);

  // explicitly free the old map if different
  // this guarantees that mod_known[0] is the world map
  flushmap := ri.Cvar_Get ('flushmap', '0', 0);
//Y  if ( strcmp(mod_known[0].name, fullname) || flushmap->value) then
    Mod_Free (@mod_known[0]);
  r_worldmodel := Mod_ForName (fullname, true);

  r_viewcluster := -1;
end;

{*
@@@@@@@@@@@@@@@@@@@@@
R_RegisterModel

@@@@@@@@@@@@@@@@@@@@@
*}
//struct model_s *R_RegisterModel (char *name)
function R_RegisterModel (name : PChar) : model_p; cdecl; //for gl_rmain
var
  _mod    : model_p;
  i       : integer;
  sprout  : dsprite_p;
  pheader : dmdl_p;
begin
  _mod := Mod_ForName (name, false);
  if Assigned(_mod) then
  begin
//Y    _mod.registration_sequence := registration_sequence;

    // register any images used by the models
    if (_mod._type = mod_sprite)
    then begin
      sprout := {(dsprite_t * )} _mod.extradata;
      for i:=0 to sprout.numframes-1 do
(*Y        _mod.skins[i] :=*) GL_FindImage (sprout.frames[i].name, it_sprite);
    end
    else
      if (_mod._type = mod_alias)
      then begin
        pheader := {(dmdl_t * )}_mod.extradata;
        for i:=0 to pheader.num_skins-1 do
(*Y          _mod.skins[i] := GL_FindImage ((char * )pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin)*);
//PGM
        _mod.numframes := pheader.num_frames;
//PGM
      end
      else
        if (_mod._type = mod_brush) then
          for i:=0 to _mod.numtexinfo-1 do
(*Y            _mod.texinfo[i].image.registration_sequence := registration_sequence*);
  end;
  Result := _mod;
end;

{*
@@@@@@@@@@@@@@@@@@@@@
R_EndRegistration

@@@@@@@@@@@@@@@@@@@@@
*}
procedure R_EndRegistration; cdecl; //gl_rmain
var
  i    : integer;
  _mod : model_p;
begin
//Y  for (i=0, mod=mod_known ; i<mod_numknown ; i++, mod++)
  begin
(*Y          if (!mod->name[0])
                  continue;
    if (_mod.registration_sequence <> registration_sequence) then*)
      // don't need this model
      Mod_Free (_mod);
  end;

  GL_FreeUnusedImages ();
end;

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

{*
================
Mod_Free
================
*}
procedure Mod_Free (_mod : model_p);
begin
(*Y  Hunk_Free (_mod.extradata);
  memset (mod, 0, sizeof(*mod));*)
end;

{*
================
Mod_FreeAll
================
*}
procedure Mod_FreeAll; //for gl_rmain
var
  i : integer;
begin
  for i:=0 to mod_numknown-1 do
    if (mod_known[i].extradatasize <> 0) then
      Mod_Free (@mod_known[i]);
end;

end.

⌨️ 快捷键说明

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