<commit_before>/*
    Copyright (C) 2003 by <NAME>
              (C) 2004 by <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "cssysdef.h"
#include "csqsqrt.h"
#include "csgeom/sphere.h"
#include "csgeom/poly3d.h"
#include "csgeom/poly2d.h"
#include "csgeom/transfrm.h"
#include "igeom/clip2d.h"
#include "imesh/objmodel.h"
#include "iengine/movable.h"
#include "iengine/rview.h"
#include "iengine/camera.h"
#include "iutil/objreg.h"
#include "plugins/engine/3d/portalcontainer.h"
#include "plugins/engine/3d/meshobj.h"
#include "plugins/engine/3d/engine.h"
#include "cstool/rviewclipper.h"

CS_PLUGIN_NAMESPACE_BEGIN(Engine)
{

// ---------------------------------------------------------------------------
// csPortalContainerTriMeshHelper
// ---------------------------------------------------------------------------

void csPortalContainerTriMeshHelper::SetPortalContainer (csPortalContainer* pc)
{
  parent = pc;
  data_nr = pc->GetDataNumber ()-1;
}

void csPortalContainerTriMeshHelper::Setup ()
{
  parent->Prepare ();
  if (data_nr != parent->GetDataNumber () || !vertices)
  {
    data_nr = parent->GetDataNumber ();
    Cleanup ();

    vertices = parent->GetVertices ();
    // Count number of needed triangles.
    num_tri = 0;

    size_t i;
    const csRefArray<csPortal>& portals = parent->GetPortals ();
    for (i = 0 ; i < portals.GetSize () ; i++)
    {
      csPortal *p = portals[i];
      if (p->flags.CheckAll (poly_flag))
        num_tri += p->GetVertexIndicesCount ()-2;
    }

    if (num_tri)
    {
      triangles = new csTriangle[num_tri];
      num_tri = 0;
      for (i = 0 ; i < portals.GetSize () ; i++)
      {
        csPortal *p = portals[i];
        if (p->flags.CheckAll (poly_flag))
        {
          csDirtyAccessArray<int>& vi = p->GetVertexIndices ();
          size_t j;
          for (j = 1 ; j < (size_t)p->GetVertexIndicesCount ()-1 ; j++)
          {
	    triangles[num_tri].a = vi[0];
	    triangles[num_tri].b = vi[j];
	    triangles[num_tri].c = vi[j+1];
            num_tri++;
          }
        }
      }
    }
  }
}

void csPortalContainerTriMeshHelper::Cleanup ()
{
  vertices = 0;
  delete[] triangles;
  triangles = 0;
}

// ---------------------------------------------------------------------------
// csPortalContainer
// ---------------------------------------------------------------------------


csPortalContainer::csPortalContainer (iEngine* engine,
	iObjectRegistry *object_reg) :
	scfImplementationType (this, engine)
{
  csRef<csPortalContainerTriMeshHelper> trimesh;
  trimesh.AttachNew (new csPortalContainerTriMeshHelper (0));
  trimesh->SetPortalContainer (this);
  csEngine* e = static_cast<csEngine*> (engine);
  SetTriangleData (e->base_id, trimesh);
  trimesh.AttachNew (new csPortalContainerTriMeshHelper (CS_PORTAL_COLLDET));
  trimesh->SetPortalContainer (this);
  SetTriangleData (e->colldet_id, trimesh);
  trimesh.AttachNew (new csPortalContainerTriMeshHelper (CS_PORTAL_VISCULL));
  trimesh->SetPortalContainer (this);
  SetTriangleData (e->viscull_id, trimesh);

  prepared = false;
  data_nr = 0;
  movable_nr = -1;
  movable_identity = false;

  meshwrapper = 0;

  shader_man = csQueryRegistry<iShaderManager> (object_reg);
  fog_shader = shader_man->GetShader ("std_lighting_portal");

  fogplane_name = e->svNameStringSet->Request ("fogplane");
  fogdensity_name = e->svNameStringSet->Request ("fog density");
  fogcolor_name = e->svNameStringSet->Request ("fog color");
}

csPortalContainer::~csPortalContainer ()<commit_msg>- Patch from <NAME> to fix uninitialised var usage reported by valgrind.<commit_after>/*
    Copyright (C) 2003 by <NAME>
              (C) 2004 by <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "cssysdef.h"
#include "csqsqrt.h"
#include "csgeom/sphere.h"
#include "csgeom/poly3d.h"
#include "csgeom/poly2d.h"
#include "csgeom/transfrm.h"
#include "igeom/clip2d.h"
#include "imesh/objmodel.h"
#include "iengine/movable.h"
#include "iengine/rview.h"
#include "iengine/camera.h"
#include "iutil/objreg.h"
#include "plugins/engine/3d/portalcontainer.h"
#include "plugins/engine/3d/meshobj.h"
#include "plugins/engine/3d/engine.h"
#include "cstool/rviewclipper.h"

CS_PLUGIN_NAMESPACE_BEGIN(Engine)
{

// ---------------------------------------------------------------------------
// csPortalContainerTriMeshHelper
// ---------------------------------------------------------------------------

void csPortalContainerTriMeshHelper::SetPortalContainer (csPortalContainer* pc)
{
  parent = pc;
  data_nr = pc->GetDataNumber ()-1;
}

void csPortalContainerTriMeshHelper::Setup ()
{
  parent->Prepare ();
  if (data_nr != parent->GetDataNumber () || !vertices)
  {
    data_nr = parent->GetDataNumber ();
    Cleanup ();

    vertices = parent->GetVertices ();
    // Count number of needed triangles.
    num_tri = 0;

    size_t i;
    const csRefArray<csPortal>& portals = parent->GetPortals ();
    for (i = 0 ; i < portals.GetSize () ; i++)
    {
      csPortal *p = portals[i];
      if (p->flags.CheckAll (poly_flag))
        num_tri += p->GetVertexIndicesCount ()-2;
    }

    if (num_tri)
    {
      triangles = new csTriangle[num_tri];
      num_tri = 0;
      for (i = 0 ; i < portals.GetSize () ; i++)
      {
        csPortal *p = portals[i];
        if (p->flags.CheckAll (poly_flag))
        {
          csDirtyAccessArray<int>& vi = p->GetVertexIndices ();
          size_t j;
          for (j = 1 ; j < (size_t)p->GetVertexIndicesCount ()-1 ; j++)
          {
	    triangles[num_tri].a = vi[0];
	    triangles[num_tri].b = vi[j];
	    triangles[num_tri].c = vi[j+1];
            num_tri++;
          }
        }
      }
    }
  }
}

void csPortalContainerTriMeshHelper::Cleanup ()
{
  vertices = 0;
  delete[] triangles;
  triangles = 0;
}

// ---------------------------------------------------------------------------
// csPortalContainer
// ---------------------------------------------------------------------------


csPortalContainer::csPortalContainer (iEngine* engine,
	iObjectRegistry *object_reg) :
	scfImplementationType (this, engine)
{
  prepared = false;
  data_nr = 0;
  movable_nr = -1;
  movable_identity = false;

  meshwrapper = 0;

  csRef<csPortalContainerTriMeshHelper> trimesh;
  trimesh.AttachNew (new csPortalContainerTriMeshHelper (0));
  trimesh->SetPortalContainer (this);
  csEngine* e = static_cast<csEngine*> (engine);
  SetTriangleData (e->base_id, trimesh);
  trimesh.AttachNew (new csPortalContainerTriMeshHelper (CS_PORTAL_COLLDET));
  trimesh->SetPortalContainer (this);
  SetTriangleData (e->colldet_id, trimesh);
  trimesh.AttachNew (new csPortalContainerTriMeshHelper (CS_PORTAL_VISCULL));
  trimesh->SetPortalContainer (this);
  SetTriangleData (e->viscull_id, trimesh);

  shader_man = csQueryRegistry<iShaderManager> (object_reg);
  fog_shader = shader_man->GetShader ("std_lighting_portal");

  fogplane_name = e->svNameStringSet->Request ("fogplane");
  fogdensity_name = e->svNameStringSet->Request ("fog density");
  fogcolor_name = e->svNameStringSet->Request ("fog color");
}

csPortalContainer::~csPortalContainer ()
{'fraction_non_alphanumeric': 0.18269570335491467, 'fraction_numerical': 0.009181871689228958, 'mean_word_length': 2.633875106928999, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2961815', 'n_tokens_mistral': 2761, 'n_tokens_neox': 2700, 'n_words': 657}