<commit_before>/*
    Copyright (C) 1998-2001 by <NAME>
    Copyright (C) 2001 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 "cssys/system.h"
#include "apps/bumptest/bumptest.h"
#include "csengine/sector.h"
#include "csengine/engine.h"
#include "csengine/csview.h"
#include "csengine/camera.h"
#include "csengine/light.h"
#include "csengine/polygon.h"
#include "csengine/meshobj.h"
#include "csengine/texture.h"
#include "csengine/thing.h"
#include "csengine/halo.h"
#include "csfx/proctex.h"
#include "csfx/prdots.h"
#include "csfx/prplasma.h"
#include "csfx/prfire.h"
#include "csfx/prwater.h"
#include "ivideo/graph3d.h"
#include "ivideo/txtmgr.h"
#include "ivaria/conout.h"
#include "imesh/object.h"
#include "iengine/mesh.h"
#include "imesh/cube.h"
#include "imesh/ball.h"
#include "imesh/sprite3d.h"
#include "imap/parser.h"
#include "prbump.h"
#include "iengine/ptextype.h"
#include "igraphic/loader.h"

//------------------------------------------------- We need the 3D engine -----

REGISTER_STATIC_LIBRARY (engine)
REGISTER_STATIC_LIBRARY (lvlload)

//-----------------------------------------------------------------------------

BumpTest::BumpTest ()
{
  view = NULL;
  engine = NULL;
  dynlight = NULL;
  prBump = NULL;
  matBump = NULL;
  LevelLoader = NULL;
  bumplight = NULL;
  animli = 0.0;
  going_right = true;
}

BumpTest::~BumpTest ()
{
  delete view;
  delete prBump;
  if (LevelLoader) LevelLoader->DecRef();
}

void cleanup ()
{
  System->console_out ("Cleaning up...\n");
  delete System;
}

bool BumpTest::InitProcDemo ()
{
  iTextureManager* txtmgr = G3D->GetTextureManager ();
  csMaterialWrapper* tm = engine->GetMaterials ()->FindByName ("wood");
  iMaterialWrapper* itm = QUERY_INTERFACE (tm, iMaterialWrapper);

  //char *vfsfilename = "/lib/std/mystone2.gif";
  char *vfsfilename = "/lib/std/stone4.gif";
  iTextureWrapper *bptex = engine->CreateTexture("bumptex", vfsfilename, 0,
    CS_TEXTURE_2D| CS_TEXTURE_3D);
  iMaterialWrapper* ibp = engine->CreateMaterial("bumptexture", bptex);
  engine->Prepare ();
  //iImageIO *imgloader = QUERY_PLUGIN(System, iImageIO);
  //iVFS *VFS = QUERY_PLUGIN(System, iVFS);
  //iDataBuffer *buf = VFS->ReadFile (vfsfilename);
  //iImage *map = imgloader->Load(buf->GetUint8 (), buf->GetSize (),
      //txtmgr->GetTextureFormat ());
  //map->IncRef();
  //buf->DecRef();
  //VFS->DecRef();
  //imgloader->DecRef();
  iImage *map = bptex->GetPrivateObject()->GetImageFile();
  prBump = new csProcBump (map);
  //prBump->SetBumpMap(map);
  matBump = prBump->Initialize (this, engine, txtmgr, "bumps");
  iMeshObjectType* thing_type = engine->GetThingType ();
  iMeshObjectFactory* thing_fact = thing_type->NewFactory ();
  iMeshObject* thing_obj = QUERY_INTERFACE (thing_fact, iMeshObject);
  thing_fact->DecRef ();


  iMaterialWrapper* imatBump = QUERY_INTERFACE (matBump, iMaterialWrapper);
  iThingState* thing_state = QUERY_INTERFACE (thing_obj, iThingState);
  float dx = 1, dy = 1, dz = 1;
  iPolygon3D* p;

  /// the stone
  p = thing_state->CreatePolygon ();
  p->SetMaterial (itm);
  p->CreateVertex (csVector3 (-dx, +dy, -dz));
  p->CreateVertex (csVector3 (+dx, +dy, -dz));
  p->CreateVertex (csVector3 (+dx, -dy, -dz));
  p->CreateVertex (csVector3 (-dx, -dy, -dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1.0);

  // to seee unbumpmapped
  p = thing_state->CreatePolygon ();
  p->SetMaterial (itm);
  p->CreateVertex (csVector3 (-dx, +dy, -dz) + csVector3(-2.5,0,0));
  p->CreateVertex (csVector3 (+dx, +dy, -dz) + csVector3(-2.5,0,0));
  p->CreateVertex (csVector3 (+dx, -dy, -dz) + csVector3(-2.5,0,0));
  p->CreateVertex (csVector3 (-dx, -dy, -dz) + csVector3(-2.5,0,0));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1.0);
  csVector3 overdist(0,0,-0.01); // to move slightly in front
  /// the bumpoverlay
  /*
  // this does not work - the texture is flat shaded too.
  p = thing_state->CreatePolygon ();
  p->SetTextureType(POLYTXT_FLAT);
  //p->SetLightingMode(false);
  p->GetFlags().Set(CS_POLY_LIGHTING, 0); // the overlay is not lit
  p->SetMaterial (imatBump);
  p->CreateVertex (csVector3 (-dx, +dy, -dz)+overdist);
  p->CreateVertex (csVector3 (+dx, +dy, -dz)+overdist);
  p->CreateVertex (csVector3 (+dx, -dy, -dz)+overdist);
  p->CreateVertex (csVector3 (-dx, -dy, -dz)+overdist);
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), .5);
  const char *conv[] = {"POLYTXT_NONE", "POLYTXT_FLAT", "POLYTXT_GOURAUD",
    "POLYTXT_LIGHTMAP"};
  printf("PolyTexType = %s\n", conv[p->GetTextureType()]);
  printf("MaterialWrap = %x  Handle %x\n", (int)imatBump, (int)imatBump->GetMaterialHandle());
  iPolyTexType *ipn = p->GetPolyTexType();
  if(!ipn) printf("No PolyTexNone info!\n");
  else ipn->SetMixMode(CS_FX_MULTIPLY2);
  if(ipn) ipn->SetMixMode(CS_FX_COPY);
  */

  ////// copy of bumps for debug
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->GetFlags().Set(CS_POLY_LIGHTING, 0); // not lit
  p->CreateVertex (csVector3 (-dx, +0, -dz) + csVector3(2.5,0,0));
  p->CreateVertex (csVector3 (+0, +0, -dz) + csVector3(2.5,0,0));
  p->CreateVertex (csVector3 (+0, -dy, -dz) + csVector3(2.5,0,0));
  p->CreateVertex (csVector3 (-dx, -dy, -dz) + csVector3(2.5,0,0));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1.0);

  //ibp->GetMaterialHandle()->Prepare();
  p = thing_state->CreatePolygon ();
  p->SetMaterial (ibp);
  p->CreateVertex (csVector3 (-dx, +0, -dz) + csVector3(2.5,1,0));
  p->CreateVertex (csVector3 (+0, +0, -dz) + csVector3(2.5,1,0));
  p->CreateVertex (csVector3 (+0, -dy, -dz) + csVector3(2.5,1,0));
  p->CreateVertex (csVector3 (-dx, -dy, -dz) + csVector3(2.5,1,0));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1.0);
  //engine->Prepare();

  /*
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->CreateVertex (csVector3 (+dx, +dy, -dz));
  p->CreateVertex (csVector3 (-dx, +dy, -dz));
  p->CreateVertex (csVector3 (-dx, +dy, +dz));
  p->CreateVertex (csVector3 (+dx, +dy, +dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), .5);
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->CreateVertex (csVector3 (+dx, -dy, +dz));
  p->CreateVertex (csVector3 (-dx, -dy, +dz));
  p->CreateVertex (csVector3 (-dx, -dy, -dz));
  p->CreateVertex (csVector3 (+dx, -dy, -dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1);
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->GetFlags().Set (CS_POLY_LIGHTING, 0);
  p->CreateVertex (csVector3 (-dx, +dy, -dz));
  p->CreateVertex (csVector3 (+dx, +dy, -dz));
  p->CreateVertex (csVector3 (+dx, -dy, -dz));
  p->CreateVertex (csVector3 (-dx, -dy, -dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 2);
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->GetFlags().Set (CS_POLY_LIGHTING, 0);
  p->CreateVertex (csVector3 (-dx, -dy, -dz));
  p->CreateVertex (csVector3 (-dx, -dy, +dz));
  p->CreateVertex (csVector3 (-dx, +dy, +dz));
  p->CreateVertex (csVector3 (-dx, +dy, -dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1);
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->CreateVertex (csVector3 (+dx, -dy, +dz));
  p->CreateVertex (csVector3 (+dx, -dy, -dz));
  p->CreateVertex (csVector3 (+dx, +dy, -dz));
  p->CreateVertex (csVector3 (+dx, +dy, +dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), .5);
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->CreateVertex (csVector3 (-dx, -dy, +dz));
  p->CreateVertex (csVector3 (+dx, -dy, +dz));
  p->CreateVertex (csVector3 (+dx, +dy, +dz));
  p->CreateVertex (csVector3 (-dx, +dy, +dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), .5);
  */

  csMeshWrapper* thing_wrap = new csMeshWrapper (engine, thing_obj);
  thing_obj->DecRef ();
  thing_wrap->SetName ("Bumpy");
  engine->meshes.Push (thing_wrap);
  thing_wrap->HardTransform (csTransform (csMatrix3 (), csVector3 (0, 5, 1)));
  thing_wrap->GetMovable ().SetSector (room);
  thing_wrap->GetMovable ().UpdateMove ();

  thing_state->InitLightMaps (false);
  iMeshWrapper* ithing_wrap = QUERY_INTERFACE (thing_wrap, iMeshWrapper);
  room->ShineLights (ithing_wrap);
  ithing_wrap->DecRef ();
  thing_state->CreateLightMaps (G3D);

  iSector* iroom = QUERY_INTERFACE (room, iSector);
  iMeshFactoryWrapper* sprfact = engine->CreateMeshFactory (
    "crystalspace.mesh.object.sprite.3d", "sprite3d");
  iSprite3DFactoryState* sprfactstate = QUERY_INTERFACE(
    sprfact->GetMeshObjectFactory(), iSprite3DFactoryState);
  sprfactstate->SetMaterialWrapper(imatBump);
  iSpriteAction *a0 = sprfactstate->AddAction();
  a0->SetName("Action0");
  iSpriteFrame *f0 = sprfactstate->AddFrame();
  a0->AddFrame(f0, 100);
  sprfactstate->AddVertices(4);
  sprfactstate->GetVertex(0,0).Set (csVector3 (-dx, +dy, -dz)+overdist);
  sprfactstate->GetVertex(0,1).Set (csVector3 (+dx, +dy, -dz)+overdist);
  sprfactstate->GetVertex(0,2).Set (csVector3 (+dx, -dy, -dz)+overdist);
  sprfactstate->GetVertex(0,3).Set (csVector3 (-dx, -dy, -dz)+overdist);
  sprfactstate->GetTexel(0,0).Set(0,0);
  sprfactstate->GetTexel(0,1).Set(2,0);
  sprfactstate->GetTexel(0,2).Set(2,2);
  sprfactstate->GetTexel(0,3).Set(0,2);
  sprfactstate->AddTriangle(0,1,2);
  sprfactstate->AddTriangle(0,2,3);
  sprfactstate->DecRef();
  iMeshWrapper* sprite = engine->CreateMeshObject(sprfact, "bumpspr",
    iroom, csVector3(0, 5, 1) );
  sprite->GetMovable ()->UpdateMove ();
  iSprite3DState* spstate = QUERY_INTERFACE (sprite->GetMeshObject (), 
    iSprite3DState);

  //sprite->GetFlags().Set(CS_ENTITY_NOLIGHTING, CS_ENTITY_NOLIGHTING);
  //sprite->GetFlags().Set(CS_ENTITY_NOSHADOWS, CS_ENTITY_NOSHADOWS);
  spstate->SetLighting(false);
  spstate->SetBaseColor(csColor(1.,1.,1.));
  spstate->SetMaterialWrapper(imatBump);
  //spstate->SetMixMode(CS_FX_COPY);
  spstate->SetMixMode(CS_FX_MULTIPLY2);
  spstate->DecRef ();


  iroom->DecRef();
  //sprfact->DecRef(); // mem leak

  thing_state->DecRef ();
  imatBump->DecRef ();
  itm->DecRef();


  return true;
}

bool BumpTest::Initialize (int argc, const char* const argv[],
  const char *iConfigName)
{
  if (!superclass::Initialize (argc, argv, iConfigName))
    return false;

  // Find the pointer to engine plugin
  iEngine *Engine = QUERY_PLUGIN (this, iEngine);
  if (!Engine)<commit_msg>Added CS_FX_TILING to the bumptest bump layer. It works perfectly nice in software now!<commit_after>/*
    Copyright (C) 1998-2001 by <NAME>
    Copyright (C) 2001 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 "cssys/system.h"
#include "apps/bumptest/bumptest.h"
#include "csengine/sector.h"
#include "csengine/engine.h"
#include "csengine/csview.h"
#include "csengine/camera.h"
#include "csengine/light.h"
#include "csengine/polygon.h"
#include "csengine/meshobj.h"
#include "csengine/texture.h"
#include "csengine/thing.h"
#include "csengine/halo.h"
#include "csfx/proctex.h"
#include "csfx/prdots.h"
#include "csfx/prplasma.h"
#include "csfx/prfire.h"
#include "csfx/prwater.h"
#include "ivideo/graph3d.h"
#include "ivideo/txtmgr.h"
#include "ivaria/conout.h"
#include "imesh/object.h"
#include "iengine/mesh.h"
#include "imesh/cube.h"
#include "imesh/ball.h"
#include "imesh/sprite3d.h"
#include "imap/parser.h"
#include "prbump.h"
#include "iengine/ptextype.h"
#include "igraphic/loader.h"

//------------------------------------------------- We need the 3D engine -----

REGISTER_STATIC_LIBRARY (engine)
REGISTER_STATIC_LIBRARY (lvlload)

//-----------------------------------------------------------------------------

BumpTest::BumpTest ()
{
  view = NULL;
  engine = NULL;
  dynlight = NULL;
  prBump = NULL;
  matBump = NULL;
  LevelLoader = NULL;
  bumplight = NULL;
  animli = 0.0;
  going_right = true;
}

BumpTest::~BumpTest ()
{
  delete view;
  delete prBump;
  if (LevelLoader) LevelLoader->DecRef();
}

void cleanup ()
{
  System->console_out ("Cleaning up...\n");
  delete System;
}

bool BumpTest::InitProcDemo ()
{
  iTextureManager* txtmgr = G3D->GetTextureManager ();
  csMaterialWrapper* tm = engine->GetMaterials ()->FindByName ("wood");
  iMaterialWrapper* itm = QUERY_INTERFACE (tm, iMaterialWrapper);

  //char *vfsfilename = "/lib/std/mystone2.gif";
  char *vfsfilename = "/lib/std/stone4.gif";
  iTextureWrapper *bptex = engine->CreateTexture("bumptex", vfsfilename, 0,
    CS_TEXTURE_2D| CS_TEXTURE_3D);
  iMaterialWrapper* ibp = engine->CreateMaterial("bumptexture", bptex);
  engine->Prepare ();
  //iImageIO *imgloader = QUERY_PLUGIN(System, iImageIO);
  //iVFS *VFS = QUERY_PLUGIN(System, iVFS);
  //iDataBuffer *buf = VFS->ReadFile (vfsfilename);
  //iImage *map = imgloader->Load(buf->GetUint8 (), buf->GetSize (),
      //txtmgr->GetTextureFormat ());
  //map->IncRef();
  //buf->DecRef();
  //VFS->DecRef();
  //imgloader->DecRef();
  iImage *map = bptex->GetPrivateObject()->GetImageFile();
  prBump = new csProcBump (map);
  //prBump->SetBumpMap(map);
  matBump = prBump->Initialize (this, engine, txtmgr, "bumps");
  iMeshObjectType* thing_type = engine->GetThingType ();
  iMeshObjectFactory* thing_fact = thing_type->NewFactory ();
  iMeshObject* thing_obj = QUERY_INTERFACE (thing_fact, iMeshObject);
  thing_fact->DecRef ();


  iMaterialWrapper* imatBump = QUERY_INTERFACE (matBump, iMaterialWrapper);
  iThingState* thing_state = QUERY_INTERFACE (thing_obj, iThingState);
  float dx = 1, dy = 1, dz = 1;
  iPolygon3D* p;

  /// the stone
  p = thing_state->CreatePolygon ();
  p->SetMaterial (itm);
  p->CreateVertex (csVector3 (-dx, +dy, -dz));
  p->CreateVertex (csVector3 (+dx, +dy, -dz));
  p->CreateVertex (csVector3 (+dx, -dy, -dz));
  p->CreateVertex (csVector3 (-dx, -dy, -dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1.0);

  // to seee unbumpmapped
  p = thing_state->CreatePolygon ();
  p->SetMaterial (itm);
  p->CreateVertex (csVector3 (-dx, +dy, -dz) + csVector3(-2.5,0,0));
  p->CreateVertex (csVector3 (+dx, +dy, -dz) + csVector3(-2.5,0,0));
  p->CreateVertex (csVector3 (+dx, -dy, -dz) + csVector3(-2.5,0,0));
  p->CreateVertex (csVector3 (-dx, -dy, -dz) + csVector3(-2.5,0,0));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1.0);
  csVector3 overdist(0,0,-0.01); // to move slightly in front
  /// the bumpoverlay
  /*
  // this does not work - the texture is flat shaded too.
  p = thing_state->CreatePolygon ();
  p->SetTextureType(POLYTXT_FLAT);
  //p->SetLightingMode(false);
  p->GetFlags().Set(CS_POLY_LIGHTING, 0); // the overlay is not lit
  p->SetMaterial (imatBump);
  p->CreateVertex (csVector3 (-dx, +dy, -dz)+overdist);
  p->CreateVertex (csVector3 (+dx, +dy, -dz)+overdist);
  p->CreateVertex (csVector3 (+dx, -dy, -dz)+overdist);
  p->CreateVertex (csVector3 (-dx, -dy, -dz)+overdist);
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), .5);
  const char *conv[] = {"POLYTXT_NONE", "POLYTXT_FLAT", "POLYTXT_GOURAUD",
    "POLYTXT_LIGHTMAP"};
  printf("PolyTexType = %s\n", conv[p->GetTextureType()]);
  printf("MaterialWrap = %x  Handle %x\n", (int)imatBump, (int)imatBump->GetMaterialHandle());
  iPolyTexType *ipn = p->GetPolyTexType();
  if(!ipn) printf("No PolyTexNone info!\n");
  else ipn->SetMixMode(CS_FX_MULTIPLY2);
  if(ipn) ipn->SetMixMode(CS_FX_COPY);
  */

  ////// copy of bumps for debug
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->GetFlags().Set(CS_POLY_LIGHTING, 0); // not lit
  p->CreateVertex (csVector3 (-dx, +0, -dz) + csVector3(2.5,0,0));
  p->CreateVertex (csVector3 (+0, +0, -dz) + csVector3(2.5,0,0));
  p->CreateVertex (csVector3 (+0, -dy, -dz) + csVector3(2.5,0,0));
  p->CreateVertex (csVector3 (-dx, -dy, -dz) + csVector3(2.5,0,0));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1.0);

  //ibp->GetMaterialHandle()->Prepare();
  p = thing_state->CreatePolygon ();
  p->SetMaterial (ibp);
  p->CreateVertex (csVector3 (-dx, +0, -dz) + csVector3(2.5,1,0));
  p->CreateVertex (csVector3 (+0, +0, -dz) + csVector3(2.5,1,0));
  p->CreateVertex (csVector3 (+0, -dy, -dz) + csVector3(2.5,1,0));
  p->CreateVertex (csVector3 (-dx, -dy, -dz) + csVector3(2.5,1,0));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1.0);
  //engine->Prepare();

  /*
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->CreateVertex (csVector3 (+dx, +dy, -dz));
  p->CreateVertex (csVector3 (-dx, +dy, -dz));
  p->CreateVertex (csVector3 (-dx, +dy, +dz));
  p->CreateVertex (csVector3 (+dx, +dy, +dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), .5);
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->CreateVertex (csVector3 (+dx, -dy, +dz));
  p->CreateVertex (csVector3 (-dx, -dy, +dz));
  p->CreateVertex (csVector3 (-dx, -dy, -dz));
  p->CreateVertex (csVector3 (+dx, -dy, -dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1);
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->GetFlags().Set (CS_POLY_LIGHTING, 0);
  p->CreateVertex (csVector3 (-dx, +dy, -dz));
  p->CreateVertex (csVector3 (+dx, +dy, -dz));
  p->CreateVertex (csVector3 (+dx, -dy, -dz));
  p->CreateVertex (csVector3 (-dx, -dy, -dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 2);
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->GetFlags().Set (CS_POLY_LIGHTING, 0);
  p->CreateVertex (csVector3 (-dx, -dy, -dz));
  p->CreateVertex (csVector3 (-dx, -dy, +dz));
  p->CreateVertex (csVector3 (-dx, +dy, +dz));
  p->CreateVertex (csVector3 (-dx, +dy, -dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), 1);
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->CreateVertex (csVector3 (+dx, -dy, +dz));
  p->CreateVertex (csVector3 (+dx, -dy, -dz));
  p->CreateVertex (csVector3 (+dx, +dy, -dz));
  p->CreateVertex (csVector3 (+dx, +dy, +dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), .5);
  p = thing_state->CreatePolygon ();
  p->SetMaterial (imatBump);
  p->CreateVertex (csVector3 (-dx, -dy, +dz));
  p->CreateVertex (csVector3 (+dx, -dy, +dz));
  p->CreateVertex (csVector3 (+dx, +dy, +dz));
  p->CreateVertex (csVector3 (-dx, +dy, +dz));
  p->SetTextureSpace (p->GetVertex (0), p->GetVertex (1), .5);
  */

  csMeshWrapper* thing_wrap = new csMeshWrapper (engine, thing_obj);
  thing_obj->DecRef ();
  thing_wrap->SetName ("Bumpy");
  engine->meshes.Push (thing_wrap);
  thing_wrap->HardTransform (csTransform (csMatrix3 (), csVector3 (0, 5, 1)));
  thing_wrap->GetMovable ().SetSector (room);
  thing_wrap->GetMovable ().UpdateMove ();

  thing_state->InitLightMaps (false);
  iMeshWrapper* ithing_wrap = QUERY_INTERFACE (thing_wrap, iMeshWrapper);
  room->ShineLights (ithing_wrap);
  ithing_wrap->DecRef ();
  thing_state->CreateLightMaps (G3D);

  iSector* iroom = QUERY_INTERFACE (room, iSector);
  iMeshFactoryWrapper* sprfact = engine->CreateMeshFactory (
    "crystalspace.mesh.object.sprite.3d", "sprite3d");
  iSprite3DFactoryState* sprfactstate = QUERY_INTERFACE(
    sprfact->GetMeshObjectFactory(), iSprite3DFactoryState);
  sprfactstate->SetMaterialWrapper(imatBump);
  iSpriteAction *a0 = sprfactstate->AddAction();
  a0->SetName("Action0");
  iSpriteFrame *f0 = sprfactstate->AddFrame();
  a0->AddFrame(f0, 100);
  sprfactstate->AddVertices(4);
  sprfactstate->GetVertex(0,0).Set (csVector3 (-dx, +dy, -dz)+overdist);
  sprfactstate->GetVertex(0,1).Set (csVector3 (+dx, +dy, -dz)+overdist);
  sprfactstate->GetVertex(0,2).Set (csVector3 (+dx, -dy, -dz)+overdist);
  sprfactstate->GetVertex(0,3).Set (csVector3 (-dx, -dy, -dz)+overdist);
  sprfactstate->GetTexel(0,0).Set(0,0);
  sprfactstate->GetTexel(0,1).Set(2,0);
  sprfactstate->GetTexel(0,2).Set(2,2);
  sprfactstate->GetTexel(0,3).Set(0,2);
  sprfactstate->AddTriangle(0,1,2);
  sprfactstate->AddTriangle(0,2,3);
  sprfactstate->DecRef();
  iMeshWrapper* sprite = engine->CreateMeshObject(sprfact, "bumpspr",
    iroom, csVector3(0, 5, 1) );
  sprite->GetMovable ()->UpdateMove ();
  iSprite3DState* spstate = QUERY_INTERFACE (sprite->GetMeshObject (), 
    iSprite3DState);

  //sprite->GetFlags().Set(CS_ENTITY_NOLIGHTING, CS_ENTITY_NOLIGHTING);
  //sprite->GetFlags().Set(CS_ENTITY_NOSHADOWS, CS_ENTITY_NOSHADOWS);
  spstate->SetLighting(false);
  spstate->SetBaseColor(csColor(1.,1.,1.));
  spstate->SetMaterialWrapper(imatBump);
  //spstate->SetMixMode(CS_FX_COPY);
  spstate->SetMixMode(CS_FX_MULTIPLY2 | CS_FX_TILING);
  spstate->DecRef ();


  iroom->DecRef();
  //sprfact->DecRef(); // mem leak

  thing_state->DecRef ();
  imatBump->DecRef ();
  itm->DecRef();


  return true;
}

bool BumpTest::Initialize (int argc, const char* const argv[],
  const char *iConfigName)
{
  if (!superclass::Initialize (argc, argv, iConfigName))
    return false;

  // Find the pointer to engine plugin
  iEngine *Engine = QUERY_PLUGIN (this, iEngine);
  if (!Engine)
{'fraction_non_alphanumeric': 0.19215404641141884, 'fraction_numerical': 0.023430136002513577, 'mean_word_length': 4.1681744374855025, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 373, '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': '4196236', 'n_tokens_mistral': 8587, 'n_tokens_neox': 8432, 'n_words': 1811}