Page 1 of 1

RenderManager.cpp split into smaller classes

PostPosted: 24 Jun 2014, 19:44
by paul424
Each of this enum's :
Allows to create the RenderRequest object of the fileds type with the value below :
{l Code}: {l Select All Code}
    enum RequestType
    {
        createTile,
        refreshTile,
        destroyTile,
        deleteTile,
        colorTile,
        temporalMarkTile,
        attachTile,
        detachTile,
        attachCreature,
        detachCreature,
        toggleCreatureVisibility,
        showSquareSelector,
        createCreature,
        destroyCreature,
        deleteCreature,
        setObjectAnimationState,
        createCreatureVisualDebug,
        destroyCreatureVisualDebug,
        createWeapon,
        destroyWeapon,
        deleteWeapon,
        pickUpCreature,
        dropCreature,
        rotateCreaturesInHand,
        createRoom,
        destroyRoom,
        deleteRoom,
        createRoomObject,
        destroyRoomObject,
        deleteRoomObject,
        createTrap,
        destroyTrap,
        deleteTrap,
        createTreasuryIndicator,
        destroyTreasuryIndicator,
        createMapLight,
        updateMapLight,
        destroyMapLight,
        destroyMapLightVisualIndicator,
        deleteMapLight,
        createField,
        refreshField,
        destroyField,
        moveSceneNode,
        orientSceneNodeToward,
        reorientSceneNode,
        scaleSceneNode,
        createMissileObject,
        destroyMissileObject,
        deleteMissileObject, //setMissileObjectAnimationState,
        noRequest
    };

The goal is to have separate class for each of them ... Than we are protected by C++ type system , and each of it has it's own constructor and it's safer from crashes ... Should I start splitting that , shouldn't be too though with some bash tools magic ...
( BTW: the same regards the subfunctions for each user command in bool Console::executePromptCommand(const std::string& command, std::string arguments) as it grows too large ! Don;'t know whether that is equally simple as dividing to separate classes or functions ... ) .
Bertram say something :) !

Re: RenderManager.cpp split into smaller classes

PostPosted: 24 Jun 2014, 21:59
by Bertram
Well, nice and all, but you have neither finished the image2map feature nor the culling algorithm.
Wanna give up on one or another?

Re: RenderManager.cpp split into smaller classes

PostPosted: 24 Jun 2014, 22:57
by MCMic
I’m really not sure what you intend to do…
What would you put in these classes?

Which problems are you trying to fix? There is no problem of construction/destruction with an enum, it’s a simple integer.

Re: RenderManager.cpp split into smaller classes

PostPosted: 11 Jul 2014, 02:10
by paul424
{l Code}: {l Select All Code}
class AttachCreature:RenderRequest
{
public:
    AttachCreature(){}

    virtual int exectute()
    {
   GameEntity* curEntity = static_cast<GameEntity*>(renderRequest.p);
   Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curEntity->getName() + "_node");

   curEntity->pSN->addChild(creatureNode);
    }
};
class AttachTile:RenderRequest
{
public:
    AttachTile(){}

    virtual int exectute()
    {
   GameEntity* curEntity = static_cast<GameEntity*>(renderRequest.p);
   Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curEntity->getName() + "_node");

   Ogre::SceneNode* parentNode = creatureNode->getParentSceneNode();
   if (parentNode == nullptr)
   {
       curEntity->pSN->addChild(creatureNode);
   }
   else
   {
       curEntity->pSN = parentNode;
   }
    }
};
class CreateCreature:RenderRequest
{
public:
    CreateCreature(){}

    virtual int exectute()
    {
   Creature* curCreature = static_cast<Creature*>(renderRequest.p);
   std::string meshName = renderRequest.str;
   Ogre::Vector3 scale = renderRequest.vec;

   assert(curCreature != 0);
   //assert(curCreature->getDefinition() != 0);

   // Load the mesh for the creature
   // TODO the prefix Creature_ should be static field in some class then changing won't broke program
   Ogre::Entity* ent = mSceneManager->createEntity("Creature_" + curCreature->getName(), meshName);
   Ogre::MeshPtr meshPtr = ent->getMesh();

   unsigned short src, dest;
   if (!meshPtr->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
   {
       meshPtr->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
   }

   //Disabled temporarily for normal-mapping
   //colourizeEntity(ent, curCreature->color);
   Ogre::SceneNode* node = mCreatureSceneNode->createChildSceneNode(
       curCreature->getName() + "_node");
   curCreature->mSceneNode = node;
   node->setPosition(curCreature->getPosition());
   node->setScale(scale);
   node->attachObject(ent);
   curCreature->pSN = (node->getParentSceneNode());
   // curCreature->pSN->removeChild(node);
    }
};
class CreateCreatureVisualDebug:RenderRequest
{
public:
    CreateCreatureVisualDebug(){}

    virtual int exectute()
    {
   Tile* curTile = static_cast<Tile*>(renderRequest.p);
   Creature* curCreature = static_cast<Creature*>( renderRequest.p2);

   if (curTile != NULL && curCreature != NULL)
   {
       std::stringstream tempSS;
       tempSS << "Vision_indicator_" << curCreature->getName() << "_"
         << curTile->x << "_" << curTile->y;

       Ogre::Entity* visIndicatorEntity = mSceneManager->createEntity(tempSS.str(),
                              "Cre_vision_indicator.mesh");
       Ogre::SceneNode* visIndicatorNode = mCreatureSceneNode->createChildSceneNode(tempSS.str()
                                  + "_node");
       visIndicatorNode->attachObject(visIndicatorEntity);
       visIndicatorNode->setPosition(Ogre::Vector3((Ogre::Real)curTile->x, (Ogre::Real)curTile->y, (Ogre::Real)0));
       visIndicatorNode->setScale(Ogre::Vector3(BLENDER_UNITS_PER_OGRE_UNIT,
                       BLENDER_UNITS_PER_OGRE_UNIT,
                       BLENDER_UNITS_PER_OGRE_UNIT));
   }
    }
};
class CreateField:RenderRequest
{
public:
    CreateField(){}

    virtual int exectute()
    {
   BattleField* curField = static_cast<BattleField*>(renderRequest.p);
   double* tempDoublePtr = static_cast<double*>(renderRequest.p2);
   Ogre::Real securityLevel = static_cast<Ogre::Real>(*tempDoublePtr);
   delete tempDoublePtr;

   FieldType::iterator fieldItr = curField->begin();
   while (fieldItr != curField->end())
   {
       int x = fieldItr->getPosX();
       int y = fieldItr->getPosY();
       Ogre::Real securityLevel2 = static_cast<Ogre::Real>(fieldItr->getSecurityLevel());
       //cout << "\ncreating field tile:  " << tempX << "
       //"\t" << tempY << "\t" << securityLevel;
       std::stringstream tempSS;
       tempSS << "Field_" << curField->getName() << "_" << x << "_" << y;
       Ogre::Entity* fieldIndicatorEntity = mSceneManager->createEntity(tempSS.str(),
                                "Field_indicator.mesh");
       Ogre::SceneNode* fieldIndicatorNode = mFieldSceneNode->createChildSceneNode(tempSS.str()
                                 + "_node");
       fieldIndicatorNode->setPosition(static_cast<Ogre::Real>(x),
                   static_cast<Ogre::Real>(y),
                   securityLevel + securityLevel2);
       fieldIndicatorNode->attachObject(fieldIndicatorEntity);

       ++fieldItr;
   }
    }
};
class CreateMapLight:RenderRequest
{
public:
    CreateMapLight(){}

    virtual int exectute()
    {
   MapLight* curMapLight = static_cast<MapLight*> (renderRequest.p);

   // Create the light and attach it to the lightSceneNode.
   std::string mapLightName = "MapLight_" + curMapLight->getName();
   Ogre::Light* light = mSceneManager->createLight(mapLightName);
   light->setDiffuseColour(curMapLight->getDiffuseColor());
   light->setSpecularColour(curMapLight->getSpecularColor());
   light->setAttenuation(curMapLight->getAttenuationRange(),
               curMapLight->getAttenuationConstant(),
               curMapLight->getAttenuationLinear(),
               curMapLight->getAttenuationQuadratic());

   // Create the base node that the "flicker_node" and the mesh attach to.
   Ogre::SceneNode* mapLightNode = mLightSceneNode->createChildSceneNode(mapLightName + "_node");
   mapLightNode->setPosition(curMapLight->getPosition());

   //TODO - put this in request so we don't have to include the globals here.
   if (renderRequest.b)
   {
       // Create the MapLightIndicator mesh so the light can be drug around in the map editor.
       Ogre::Entity* lightEntity = mSceneManager->createEntity("MapLightIndicator_"
                            + curMapLight->getName(), "Light.mesh");
       mapLightNode->attachObject(lightEntity);
   }

   // Create the "flicker_node" which moves around randomly relative to
   // the base node.  This node carries the light itself.
   Ogre::SceneNode* flickerNode = mapLightNode->createChildSceneNode(mapLightName + "_flicker_node");
   flickerNode->attachObject(light);
    }
};
class CreateMissileObject:RenderRequest
{
public:
    CreateMissileObject(){}

    virtual int exectute()
    {
   MissileObject* curMissileObject = static_cast<MissileObject*>(renderRequest.p);
   Ogre::Entity* ent = mSceneManager->createEntity(curMissileObject->getName(),
                     curMissileObject->getMeshName() + ".mesh");
   //TODO:  Make a new subroot scene node for these so lookups are faster
   // since only a few missile objects should be onscreen at once.
   Ogre::SceneNode* node = mCreatureSceneNode->createChildSceneNode(
       curMissileObject->getName() + "_node");
   node->setPosition(curMissileObject->getPosition());
   node->attachObject(ent);
    }
};
class CreateRoom:RenderRequest
{
public:
    CreateRoom(){}

    virtual int exectute()
    {
   Room* curRoom = static_cast<Room*>(renderRequest.p);
   Tile* curTile = static_cast<Tile*>(renderRequest.p2);

   std::stringstream tempSS;
   tempSS << curRoom->getName() << "_" << curTile->x << "_" << curTile->y;
   // Create the room ground tile
   Ogre::Entity* ent = mSceneManager->createEntity(tempSS.str(), curRoom->getMeshName() + ".mesh");
   Ogre::SceneNode* node = mRoomSceneNode->createChildSceneNode(tempSS.str() + "_node");

   node->setPosition(static_cast<Ogre::Real>(curTile->x),
           static_cast<Ogre::Real>(curTile->y),
           static_cast<Ogre::Real>(0.02f));
   node->setScale(Ogre::Vector3(BLENDER_UNITS_PER_OGRE_UNIT,
                 BLENDER_UNITS_PER_OGRE_UNIT,
                 BLENDER_UNITS_PER_OGRE_UNIT));
   node->attachObject(ent);
    }
};
class CreateRoomObject:RenderRequest
{
public:
    CreateRoomObject(){}

    virtual int exectute()
    {
   RoomObject* curRoomObject = static_cast<RoomObject*> (renderRequest.p);
   std::string name = renderRequest.str;
   boost::scoped_ptr<std::string> meshName(static_cast<std::string*>(renderRequest.p3));
   std::string tempString = curRoomObject->getOgreNamePrefix() + name;

   Ogre::Entity* ent = mSceneManager->createEntity(tempString, *meshName.get() + ".mesh");
   Ogre::SceneNode* node = mRoomSceneNode->createChildSceneNode(tempString + "_node");

   node->setPosition(Ogre::Vector3(curRoomObject->mX, curRoomObject->mY, 0.0));
   node->setScale(Ogre::Vector3(0.7, 0.7, 0.7));
   node->roll(Ogre::Degree(curRoomObject->mRotationAngle));
   node->attachObject(ent);
    }
};
class CreateTile:RenderRequest
{
public:
    CreateTile(){}

    virtual int exectute()
    {
   int rt = 0;
   Tile* curTile = static_cast<Tile*> (renderRequest.p);

   std::string meshName = Tile::meshNameFromNeighbors(curTile->getType(),
                        curTile->getFullnessMeshNumber(),
                        mGameMap->getNeighborsTypes(curTile),
                        mGameMap->getNeighborsFullness(curTile),
                        rt);

   Ogre::Entity* ent = mSceneManager->createEntity(curTile->getName(), meshName);


   if(curTile->getType() == Tile::gold)
   {
       for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
       {
      ent->getSubEntity(ii)->setMaterialName("Gold");
       }
   }
   else if(curTile->getType() == Tile::rock)
   {
       for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
       {
      ent->getSubEntity(ii)->setMaterialName("Rock");
       }
   }
   else if(curTile->getType() == Tile::lava)
   {
       for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
       {
      Ogre::SubEntity* subEnt = ent->getSubEntity(ii);
      if (subEnt->getMaterialName() == "Water")
          subEnt->setMaterialName("Lava");
       }
   }

   if (curTile->getType() == Tile::claimed)
   {
       colourizeEntity(ent, curTile->getColor(), curTile->getMarkedForDigging(mGameMap->getLocalPlayer()));
   }

   Ogre::SceneNode* node = mSceneManager->getRootSceneNode()->createChildSceneNode(curTile->getName() + "_node");

   Ogre::MeshPtr meshPtr = ent->getMesh();
   unsigned short src, dest;
   if (!meshPtr->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
   {
       meshPtr->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
   }

   node->setPosition(static_cast<Ogre::Real>(curTile->x), static_cast<Ogre::Real>(curTile->y), 0);

   node->attachObject(ent);

   node->setScale(Ogre::Vector3((Ogre::Real)(4.0 / BLENDER_UNITS_PER_OGRE_UNIT),
                 (Ogre::Real)(4.0 / BLENDER_UNITS_PER_OGRE_UNIT),
                 (Ogre::Real)(5.0 / BLENDER_UNITS_PER_OGRE_UNIT)));
   node->resetOrientation();
   node->roll(Ogre::Degree((Ogre::Real)(-1 * rt * 90)));
    }
};
class CreateTrap:RenderRequest
{
public:
    CreateTrap(){}

    virtual int exectute()
    {
   Trap* curTrap = static_cast<Trap*>(renderRequest.p);
   Tile* curTile = static_cast<Tile*>(renderRequest.p2);

   std::stringstream tempSS;
   tempSS << "Trap_" << curTrap->getName() + "_tile_"
          << curTile->x << "_" << curTile->y;
   std::string tempString = tempSS.str();
   Ogre::Entity* ent = mSceneManager->createEntity(tempString, curTrap->getMeshName() + ".mesh");
   Ogre::SceneNode* node = mRoomSceneNode->createChildSceneNode(tempString + "_node");
   node->setPosition(static_cast<Ogre::Real>(curTile->x),
           static_cast<Ogre::Real>(curTile->y),
           0.0f);
   node->attachObject(ent);
    }
};
class CreateTreasuryIndicator:RenderRequest
{
public:
    CreateTreasuryIndicator(){}

    virtual int exectute()
    {
   Tile* curTile = static_cast<Tile*>(renderRequest.p);
   Room* curRoom = static_cast<Room*>(renderRequest.p2);
   std::stringstream tempSS;

   tempSS << curRoom->getName() << "_" << curTile->x << "_"
          << curTile->y;
   Ogre::Entity* ent = mSceneManager->createEntity(tempSS.str()
                     + "_treasury_indicator", renderRequest.str + ".mesh");
   Ogre::SceneNode* node = mSceneManager->getSceneNode(tempSS.str() + "_node");

   //FIXME: This second scene node is purely to cancel out the effects of BLENDER_UNITS_PER_OGRE_UNIT,
   // it can be gotten rid of when that hack is fixed.
   node = node->createChildSceneNode(node->getName()
                 + "_hack_node");
   node->setScale(Ogre::Vector3((Ogre::Real)(1.0 / BLENDER_UNITS_PER_OGRE_UNIT),
                 (Ogre::Real)(1.0 / BLENDER_UNITS_PER_OGRE_UNIT),
                 (Ogre::Real)(1.0 / BLENDER_UNITS_PER_OGRE_UNIT)));
   node->attachObject(ent);
    }
};
class CreateWeapon:RenderRequest
{
public:
    CreateWeapon(){}

    virtual int exectute()
    {
   Weapon* curWeapon = static_cast<Weapon*>( renderRequest.p);
   Creature* curCreature = static_cast<Creature*>(renderRequest.p2);

   Ogre::Entity* ent = mSceneManager->getEntity("Creature_" + curCreature->getName());
   //colourizeEntity(ent, curCreature->color);
   Ogre::Entity* weaponEntity = mSceneManager->createEntity("Weapon_"
                         + curWeapon->getHandString() + "_" + curCreature->getName(),
                         curWeapon->getMeshName());
   Ogre::Bone* weaponBone = ent->getSkeleton()->getBone(
       "Weapon_" + curWeapon->getHandString());

   // Rotate by -90 degrees around the x-axis from the bone's rotation.
   Ogre::Quaternion rotationQuaternion;
   rotationQuaternion.FromAngleAxis(Ogre::Degree(-90.0), Ogre::Vector3(1.0,
                               0.0, 0.0));

   ent->attachObjectToBone(weaponBone->getName(), weaponEntity,
            rotationQuaternion);
    }
};
class DestroyCreature:RenderRequest
{
public:
    DestroyCreature(){}

    virtual int exectute()
    {
   Creature* curCreature = static_cast<Creature*>(renderRequest.p);
   if (mSceneManager->hasEntity("Creature_" + curCreature->getName()))
   {
       Ogre::Entity* ent = mSceneManager->getEntity("Creature_" + curCreature->getName());
       Ogre::SceneNode* node = mSceneManager->getSceneNode(curCreature->getName() + "_node");
       node->detachObject(ent);
       mCreatureSceneNode->removeChild(node);
       mSceneManager->destroyEntity(ent);
       mSceneManager->destroySceneNode(curCreature->getName() + "_node");
   }
   curCreature->mSceneNode = NULL;
    }
};
class DestroyCreatureVisualDebug:RenderRequest
{
public:
    DestroyCreatureVisualDebug(){}

    virtual int exectute()
    {
   Tile* curTile = static_cast<Tile*>(renderRequest.p);
   Creature* curCreature = static_cast<Creature*>(renderRequest.p2);

   std::stringstream tempSS;
   tempSS << "Vision_indicator_" << curCreature->getName() << "_"
          << curTile->x << "_" << curTile->y;
   if (mSceneManager->hasEntity(tempSS.str()))
   {
       Ogre::Entity* visIndicatorEntity = mSceneManager->getEntity(tempSS.str());
       Ogre::SceneNode* visIndicatorNode = mSceneManager->getSceneNode(tempSS.str() + "_node");

       visIndicatorNode->detachAllObjects();
       mSceneManager->destroyEntity(visIndicatorEntity);
       mSceneManager->destroySceneNode(visIndicatorNode);
   }
    }
};
class DestroyMapLight:RenderRequest
{
public:
    DestroyMapLight(){}

    virtual int exectute()
    {
   MapLight* curMapLight = static_cast<MapLight*> (renderRequest.p);
   std::string mapLightName = "MapLight_" + curMapLight->getName();
   if (mSceneManager->hasLight(mapLightName))
   {
       Ogre::Light* light = mSceneManager->getLight(mapLightName);
       Ogre::SceneNode* lightNode = mSceneManager->getSceneNode(mapLightName + "_node");
       Ogre::SceneNode* lightFlickerNode = mSceneManager->getSceneNode(mapLightName
                               + "_flicker_node");
       lightFlickerNode->detachObject(light);
       mLightSceneNode->removeChild(lightNode);
       mSceneManager->destroyLight(light);

       if (mSceneManager->hasEntity(mapLightName))
       {
      Ogre::Entity* mapLightIndicatorEntity = mSceneManager->getEntity("MapLightIndicator_"
                               + curMapLight->getName());
      lightNode->detachObject(mapLightIndicatorEntity);
       }
       mSceneManager->destroySceneNode(lightFlickerNode->getName());
       mSceneManager->destroySceneNode(lightNode->getName());
   }
    }
};
class DestroyMapLightVisualIndicator:RenderRequest
{
public:
    DestroyMapLightVisualIndicator(){}

    virtual int exectute()
    {
   MapLight* curMapLight = static_cast<MapLight*>(renderRequest.p);
   std::string mapLightName = "MapLight_" + curMapLight->getName();
   if (mSceneManager->hasLight(mapLightName))
   {
       Ogre::SceneNode* mapLightNode = mSceneManager->getSceneNode(mapLightName + "_node");
       std::string mapLightIndicatorName = "MapLightIndicator_"
      + curMapLight->getName();
       if (mSceneManager->hasEntity(mapLightIndicatorName))
       {
      Ogre::Entity* mapLightIndicatorEntity = mSceneManager->getEntity(mapLightIndicatorName);
      mapLightNode->detachObject(mapLightIndicatorEntity);
      mSceneManager->destroyEntity(mapLightIndicatorEntity);
      //NOTE: This line throws an error complaining 'scene node not found' that should not be happening.
      //mSceneManager->destroySceneNode(node->getName());
       }
   }
    }
};
class DestroyMissileObject:RenderRequest
{
public:
    DestroyMissileObject(){}

    virtual int exectute()
    {
   MissileObject* curMissileObject = static_cast<MissileObject*>(renderRequest.p);
   if (mSceneManager->hasEntity(curMissileObject->getName()))
   {
       Ogre::Entity* ent = mSceneManager->getEntity(curMissileObject->getName());
       Ogre::SceneNode* node = mSceneManager->getSceneNode(curMissileObject->getName()  + "_node");
       node->detachObject(ent);
       mCreatureSceneNode->removeChild(node);
       mSceneManager->destroyEntity(ent);
       mSceneManager->destroySceneNode(curMissileObject->getName() + "_node");
   }
    }
};
class DestroyRoom:RenderRequest
{
public:
    DestroyRoom(){}

    virtual int exectute()
    {
   Room* curRoom = static_cast<Room*>(renderRequest.p);
   Tile* curTile = static_cast<Tile*>(renderRequest.p2);
   std::stringstream tempSS;
   tempSS << curRoom->getName() << "_" << curTile->x << "_" << curTile->y;

   if (mSceneManager->hasEntity(tempSS.str()))
   {
       Ogre::Entity* ent = mSceneManager->getEntity(tempSS.str());
       Ogre::SceneNode* node = mSceneManager->getSceneNode(tempSS.str() + "_node");
       node->detachObject(ent);
       mRoomSceneNode->removeChild(node);
       mSceneManager->destroyEntity(ent);
       mSceneManager->destroySceneNode(tempSS.str() + "_node");
   }
    }
};
class DestroyRoomObject:RenderRequest
{
public:
    DestroyRoomObject(){}

    virtual int exectute()
    {
   RoomObject* curRoomObject = static_cast<RoomObject*> (renderRequest.p);

   std::string tempString = curRoomObject->getOgreNamePrefix()
       + curRoomObject->getName();
   Ogre::Entity* ent = mSceneManager->getEntity(tempString);
   Ogre::SceneNode* node = mSceneManager->getSceneNode(tempString + "_node");
   node->detachObject(ent);
   mSceneManager->destroySceneNode(node->getName());
   mSceneManager->destroyEntity(ent);
    }
};
class DestroyTile:RenderRequest
{
public:
    DestroyTile(){}

    virtual int exectute()
    {
   Tile* curTile = static_cast<Tile*>(renderRequest.p);

   if (mSceneManager->hasEntity(curTile->getName()))
   {
       Ogre::Entity* ent = mSceneManager->getEntity(curTile->getName());
       Ogre::SceneNode* node = mSceneManager->getSceneNode(curTile->getName() + "_node");
       node->detachAllObjects();
       mSceneManager->destroySceneNode(curTile->getName() + "_node");
       mSceneManager->destroyEntity(ent);
   }
    }
};
class DestroyTrap:RenderRequest
{
public:
    DestroyTrap(){}

    virtual int exectute()
    {
   Trap* curTrap = static_cast<Trap*>(renderRequest.p);
   Tile* curTile = static_cast<Tile*>(renderRequest.p2);

   std::stringstream tempSS;
   tempSS << "Trap_" << curTrap->getName() + "_tile_" << curTile->x << "_"
          << curTile->y;
   std::string tempString = tempSS.str();
   Ogre::Entity* ent = mSceneManager->getEntity(tempString);
   Ogre::SceneNode* node = mSceneManager->getSceneNode(tempString + "_node");
   node->detachObject(ent);
   mSceneManager->destroySceneNode(node->getName());
   mSceneManager->destroyEntity(ent);
    }
};
class DestroyTreasuryIndicator:RenderRequest
{
public:
    DestroyTreasuryIndicator(){}

    virtual int exectute()
    {
   Tile* curTile = static_cast<Tile*>(renderRequest.p);
   Room* curRoom = static_cast<Room*>(renderRequest.p2);

   std::stringstream tempSS;
   tempSS << curRoom->getName() << "_" << curTile->x << "_"
          << curTile->y;
   if (mSceneManager->hasEntity(tempSS.str() + "_treasury_indicator"))
   {
       Ogre::Entity* ent = mSceneManager->getEntity(tempSS.str()
                      + "_treasury_indicator");

       //FIXME: This second scene node is purely to cancel out the effects of BLENDER_UNITS_PER_OGRE_UNIT,
       // it can be gotten rid of when that hack is fixed.
       Ogre::SceneNode* node = mSceneManager->getSceneNode(tempSS.str() + "_node" + "_hack_node");

       /*  The proper code once the above hack is fixed.
      node = sceneManager->getSceneNode(tempSS.str() + "_node");
       */
       node->detachObject(ent);

       //FIXME: This line is not needed once the above hack is fixed.
       mSceneManager->destroySceneNode(node->getName());

       mSceneManager->destroyEntity(ent);
   }
    }
};
class DestroyWeapon:RenderRequest
{
public:
    DestroyWeapon(){}

    virtual int exectute()
    {
   Weapon* curWeapon = static_cast<Weapon*>(renderRequest.p);
   Creature* curCreature = static_cast<Creature*>(renderRequest.p2);

   if (curWeapon->getName().compare("none") != 0)
   {
       Ogre::Entity* ent = mSceneManager->getEntity("Weapon_"
                      + curWeapon->getHandString() + "_" + curCreature->getName());
       mSceneManager->destroyEntity(ent);
   }
    }
};
class DetachCreature:RenderRequest
{
public:
    DetachCreature(){}

    virtual int exectute()
    {
   GameEntity* curEntity = static_cast<GameEntity*>(renderRequest.p);
   Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curEntity->getName() + "_node");

   curEntity->pSN->removeChild(creatureNode);
    }
};
class DetachTile:RenderRequest
{
public:
    DetachTile(){}

    virtual int exectute()
    {
   GameEntity* curEntity = static_cast<GameEntity*>(renderRequest.p);
   Ogre::SceneNode* tileNode = mSceneManager->getSceneNode(curEntity->getName() + "_node");

   curEntity->pSN=(tileNode->getParentSceneNode());
   curEntity->pSN->removeChild(tileNode);
    }
};
class DropCreature:RenderRequest
{
public:
    DropCreature(){}

    virtual int exectute()
    {
   Creature* curCreature = static_cast<Creature*>(renderRequest.p);
   Player* curPlayer = static_cast<Player*> (renderRequest.p2);
   // Detach the creature from the "hand" scene node
   Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curCreature->getName() + "_node");
   mSceneManager->getSceneNode("Hand_node")->removeChild(creatureNode);

   // Attach the creature from the creature scene node
   mCreatureSceneNode->addChild(creatureNode);
   creatureNode->setPosition(curCreature->getPosition());
   creatureNode->scale(3.0, 3.0, 3.0);

   // Move the other creatures in the player's hand to replace the dropped one
   for (unsigned int i = 0; i < curPlayer->numCreaturesInHand(); ++i)
   {
       curCreature = curPlayer->getCreatureInHand(i);
       creatureNode = mSceneManager->getSceneNode(curCreature->getName() + "_node");
       creatureNode->setPosition((Ogre::Real)(i % 6 + 1), (Ogre::Real)(i / (int)6), (Ogre::Real)0.0);
   }
    }
};
class MoveSceneNode:RenderRequest
{
public:
    MoveSceneNode(){}

    virtual int exectute()
    {
   if (mSceneManager->hasSceneNode(renderRequest.str))
   {
       Ogre::SceneNode* node = mSceneManager->getSceneNode(renderRequest.str);
       node->setPosition(renderRequest.vec);
   }
    }};
class OrientSceneNodeToward:RenderRequest
{
public:
    OrientSceneNodeToward(){}

    virtual int exectute()
    {
   Ogre::SceneNode* node = mSceneManager->getSceneNode(renderRequest.str);
   Ogre::Vector3 tempVector = node->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Y;

   // Work around 180 degree quaternion rotation quirk
   if ((1.0f + tempVector.dotProduct(renderRequest.vec)) < 0.0001f)
   {
       node->roll(Ogre::Degree(180));
   }
   else
   {
       node->rotate(tempVector.getRotationTo(renderRequest.vec));
   }
    }
};
class PickUpCreature:RenderRequest
{
public:
    PickUpCreature(){}

    virtual int exectute()
    {
   Creature* curCreature = static_cast<Creature*>(renderRequest.p);
   // Detach the creature from the creature scene node
   Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curCreature->getName() + "_node");
   //FIXME this variable name is a bit misleading
   mCreatureSceneNode->removeChild(creatureNode);

   // Attach the creature to the hand scene node
   mSceneManager->getSceneNode("Hand_node")->addChild(creatureNode);
   //FIXME we should probably use setscale for this, because of rounding.
   creatureNode->scale(0.333, 0.333, 0.333);

   // Move the other creatures in the player's hand to make room for the one just picked up.
   for (unsigned int i = 0; i < mGameMap->getLocalPlayer()->numCreaturesInHand(); ++i)
   {
       curCreature = mGameMap->getLocalPlayer()->getCreatureInHand(i);
       creatureNode = mSceneManager->getSceneNode(curCreature->getName() + "_node");
       creatureNode->setPosition((Ogre::Real)(i % 6 + 1), (Ogre::Real)(i / (int)6), (Ogre::Real)0.0);
   }
    }
};
class RefreshField:RenderRequest
{
public:
    RefreshField(){}

    virtual int exectute()
    {
   BattleField* curField = static_cast<BattleField*> (renderRequest.p);
   double* tempDoublePtr = static_cast<double*>(renderRequest.p2);
   double securityLevel = *tempDoublePtr;
   delete tempDoublePtr;

   // Update existing meshes and create any new ones needed.
   FieldType::iterator fieldItr = curField->begin();
   while (fieldItr != curField->end())
   {
       int x = fieldItr->getPosX();
       int y = fieldItr->getPosY();
       double securityLevel2 = fieldItr->getSecurityLevel();

       std::stringstream tempSS;
       tempSS << "Field_" << curField->getName() << "_" << x << "_" << y;

       Ogre::SceneNode* fieldIndicatorNode = NULL;

       if (mSceneManager->hasEntity(tempSS.str()))
       {
      // The mesh alread exists, just get the existing one
      fieldIndicatorNode = mSceneManager->getSceneNode(tempSS.str() + "_node");
       }
       else
       {
      // The mesh does not exist, create a new one
      Ogre::Entity* fieldIndicatorEntity = mSceneManager->createEntity(tempSS.str(),
                               "Field_indicator.mesh");
      fieldIndicatorNode = mFieldSceneNode->createChildSceneNode(tempSS.str() + "_node");
      fieldIndicatorNode->attachObject(fieldIndicatorEntity);
       }

       fieldIndicatorNode->setPosition((Ogre::Real)x, (Ogre::Real)y,
                   (Ogre::Real)(securityLevel + securityLevel2));
       ++fieldItr;
   }

   //TODO: Deleting is not done yet.
   // Delete any meshes not in the field currently
    }
};
class RefreshTile:RenderRequest
{
public:
    RefreshTile(){}

    virtual int exectute()
    {
   int rt = 0;
   Tile* curTile = static_cast<Tile*>(renderRequest.p);

   if (!mSceneManager->hasSceneNode(curTile->getName() + "_node"))
       return;

   // Unlink and delete the old mesh
   mSceneManager->getSceneNode(curTile->getName() + "_node")->detachObject(curTile->getName());
   mSceneManager->destroyEntity(curTile->getName());

   std::string meshName = Tile::meshNameFromNeighbors(curTile->getType(),
                        curTile->getFullnessMeshNumber(),
                        mGameMap->getNeighborsTypes(curTile),
                        mGameMap->getNeighborsFullness(curTile),
                        rt);

   Ogre::Entity* ent = mSceneManager->createEntity(curTile->getName(), meshName);

   if(curTile->getType() == Tile::gold)
   {
       for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
       {
      ent->getSubEntity(ii)->setMaterialName("Gold");
       }
   }
   else if(curTile->getType() == Tile::rock)
   {
       for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
       {
      ent->getSubEntity(ii)->setMaterialName("Rock");
       }

   }
   else if(curTile->getType() == Tile::lava)
   {
       for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
       {
      Ogre::SubEntity* subEnt = ent->getSubEntity(ii);
      if (subEnt->getMaterialName() == "Water")
          subEnt->setMaterialName("Lava");
       }
   }

   colourizeEntity(ent, curTile->getColor(), curTile->getMarkedForDigging(mGameMap->getLocalPlayer()));

   // Link the tile mesh back to the relevant scene node so OGRE will render it
   Ogre::SceneNode* node = mSceneManager->getSceneNode(curTile->getName() + "_node");
   node->attachObject(ent);
   node->resetOrientation();
   node->roll(Ogre::Degree((Ogre::Real)(-1 * rt * 90)));
    }

};
void RenderManager::rrRefreshTile(const RenderRequest& renderRequest)
{
    int rt = 0;
    Tile* curTile = static_cast<Tile*>(renderRequest.p);

    if (!mSceneManager->hasSceneNode(curTile->getName() + "_node"))
        return;

    // Unlink and delete the old mesh
    mSceneManager->getSceneNode(curTile->getName() + "_node")->detachObject(curTile->getName());
    mSceneManager->destroyEntity(curTile->getName());

    std::string meshName = Tile::meshNameFromNeighbors(curTile->getType(),
                                                       curTile->getFullnessMeshNumber(),
                                                       mGameMap->getNeighborsTypes(curTile),
                                                       mGameMap->getNeighborsFullness(curTile),
                                                       rt);

    Ogre::Entity* ent = mSceneManager->createEntity(curTile->getName(), meshName);

    if(curTile->getType() == Tile::gold)
    {
        for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
        {
            ent->getSubEntity(ii)->setMaterialName("Gold");
        }
    }
    else if(curTile->getType() == Tile::rock)
    {
        for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
        {
            ent->getSubEntity(ii)->setMaterialName("Rock");
        }

    }
    else if(curTile->getType() == Tile::lava)
    {
        for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
        {
            Ogre::SubEntity* subEnt = ent->getSubEntity(ii);
            if (subEnt->getMaterialName() == "Water")
                subEnt->setMaterialName("Lava");
        }
    }

    colourizeEntity(ent, curTile->getColor(), curTile->getMarkedForDigging(mGameMap->getLocalPlayer()));

    // Link the tile mesh back to the relevant scene node so OGRE will render it
    Ogre::SceneNode* node = mSceneManager->getSceneNode(curTile->getName() + "_node");
    node->attachObject(ent);
    node->resetOrientation();
    node->roll(Ogre::Degree((Ogre::Real)(-1 * rt * 90)));
}


void RenderManager::rrCreateTile(const RenderRequest& renderRequest)
{
    int rt = 0;
    Tile* curTile = static_cast<Tile*> (renderRequest.p);

    std::string meshName = Tile::meshNameFromNeighbors(curTile->getType(),
                                                       curTile->getFullnessMeshNumber(),
                                                       mGameMap->getNeighborsTypes(curTile),
                                                       mGameMap->getNeighborsFullness(curTile),
                                                       rt);

    Ogre::Entity* ent = mSceneManager->createEntity(curTile->getName(), meshName);


    if(curTile->getType() == Tile::gold)
    {
        for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
        {
            ent->getSubEntity(ii)->setMaterialName("Gold");
        }
    }
    else if(curTile->getType() == Tile::rock)
    {
        for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
        {
            ent->getSubEntity(ii)->setMaterialName("Rock");
        }
    }
    else if(curTile->getType() == Tile::lava)
    {
        for(unsigned int ii = 0; ii < ent->getNumSubEntities(); ++ii)
        {
            Ogre::SubEntity* subEnt = ent->getSubEntity(ii);
            if (subEnt->getMaterialName() == "Water")
                subEnt->setMaterialName("Lava");
        }
    }

    if (curTile->getType() == Tile::claimed)
    {
        colourizeEntity(ent, curTile->getColor(), curTile->getMarkedForDigging(mGameMap->getLocalPlayer()));
    }

    Ogre::SceneNode* node = mSceneManager->getRootSceneNode()->createChildSceneNode(curTile->getName() + "_node");

    Ogre::MeshPtr meshPtr = ent->getMesh();
    unsigned short src, dest;
    if (!meshPtr->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
    {
        meshPtr->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
    }

    node->setPosition(static_cast<Ogre::Real>(curTile->x), static_cast<Ogre::Real>(curTile->y), 0);

    node->attachObject(ent);

    node->setScale(Ogre::Vector3((Ogre::Real)(4.0 / BLENDER_UNITS_PER_OGRE_UNIT),
                                 (Ogre::Real)(4.0 / BLENDER_UNITS_PER_OGRE_UNIT),
                                 (Ogre::Real)(5.0 / BLENDER_UNITS_PER_OGRE_UNIT)));
    node->resetOrientation();
    node->roll(Ogre::Degree((Ogre::Real)(-1 * rt * 90)));
}

void RenderManager::rrDestroyTile (const RenderRequest& renderRequest)
{
    Tile* curTile = static_cast<Tile*>(renderRequest.p);

    if (mSceneManager->hasEntity(curTile->getName()))
    {
        Ogre::Entity* ent = mSceneManager->getEntity(curTile->getName());
        Ogre::SceneNode* node = mSceneManager->getSceneNode(curTile->getName() + "_node");
        node->detachAllObjects();
        mSceneManager->destroySceneNode(curTile->getName() + "_node");
        mSceneManager->destroyEntity(ent);
    }
}

void RenderManager::rrTemporalMarkTile(const RenderRequest& renderRequest)
{
    Ogre::SceneManager* mSceneMgr = RenderManager::getSingletonPtr()->getSceneManager();
    Ogre::Entity* ent;
    std::stringstream ss;
    std::stringstream ss2;
    Tile* curTile = static_cast<Tile*>(renderRequest.p);

    bool bb = curTile->getSelected();

    ss.str(std::string());
    ss << "Level";
    ss << "_";
    ss <<  curTile->x;
    ss << "_";
    ss <<  curTile->y;
    ss << "_selection_indicator";

    if (mSceneMgr->hasEntity(ss.str()))
    {
        ent = mSceneMgr->getEntity(ss.str());
    }
    else
    {
        ss2.str(std::string());
        ss2 << "Level";
        ss2 << "_";
        ss2 << curTile->x;
        ss2 << "_";
        ss2 << curTile->y;
        ss2 << "_node";
        ent = mSceneMgr->createEntity(ss.str(), "SquareSelector.mesh");
        Ogre::SceneNode* node = mSceneManager->getSceneNode(ss2.str())->createChildSceneNode(ss.str()+"Node");
        node->setInheritScale(false);
        node->scale(Ogre::Vector3(BLENDER_UNITS_PER_OGRE_UNIT,
                                  BLENDER_UNITS_PER_OGRE_UNIT, 0.45 * BLENDER_UNITS_PER_OGRE_UNIT));
        node->attachObject(ent);
    }

    ent->setVisible(bb);
}

void RenderManager::rrDetachTile(const RenderRequest& renderRequest)
{
    GameEntity* curEntity = static_cast<GameEntity*>(renderRequest.p);
    Ogre::SceneNode* tileNode = mSceneManager->getSceneNode(curEntity->getName() + "_node");

    curEntity->pSN=(tileNode->getParentSceneNode());
    curEntity->pSN->removeChild(tileNode);
}

void RenderManager::rrAttachTile(const RenderRequest& renderRequest)
{
    GameEntity* curEntity = static_cast<GameEntity*>(renderRequest.p);
    Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curEntity->getName() + "_node");

    Ogre::SceneNode* parentNode = creatureNode->getParentSceneNode();
    if (parentNode == nullptr)
    {
        curEntity->pSN->addChild(creatureNode);
    }
    else
    {
        curEntity->pSN = parentNode;
    }
}



Re: RenderManager.cpp split into smaller classes

PostPosted: 11 Jul 2014, 02:15
by paul424
{l Code}: {l Select All Code}
void RenderManager::rrDetachCreature(const RenderRequest& renderRequest)
{
    GameEntity* curEntity = static_cast<GameEntity*>(renderRequest.p);
    Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curEntity->getName() + "_node");

    curEntity->pSN->removeChild(creatureNode);
}

void RenderManager::rrAttachCreature(const RenderRequest& renderRequest)
{
    GameEntity* curEntity = static_cast<GameEntity*>(renderRequest.p);
    Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curEntity->getName() + "_node");

    curEntity->pSN->addChild(creatureNode);
}

void RenderManager::rrToggleCreaturesVisibility()
{
    mVisibleCreatures = !mVisibleCreatures;

    if(mVisibleCreatures)
    {
        for(std::vector<Creature*>::iterator it = mGameMap->creatures.begin(); it != mGameMap->creatures.end(); ++it)
        {
            if((*it)->isMeshExisting() && (*it)->mSceneNode != NULL)

      // (*it)->pSN=((*it)->sceneNode->getParentSceneNode());
      //pSN->removeChild((*it)->
                (*it)->pSN->addChild((*it)->mSceneNode);
            //  addAnimatedObject(*it);
            // (*it)->createMesh();
        }
    }
    else
    {
        for(std::vector<Creature*>::iterator it = mGameMap->creatures.begin(); it != mGameMap->creatures.end(); ++it)
        {
            if((*it)->isMeshExisting() && (*it)->mSceneNode!=NULL)
            {
                (*it)->pSN=((*it)->mSceneNode->getParentSceneNode());
                (*it)->pSN->removeChild((*it)->mSceneNode);
            }

            // removeAnimatedObject(*it);
            // (*it)->destroyMesh();
        }
    }
}

void RenderManager::rrShowSquareSelector(const RenderRequest& renderRequest)
{
    int* xPos = static_cast<int*>(renderRequest.p);
    int* yPos = static_cast<int*>(renderRequest.p2);

    mSceneManager->getEntity("SquareSelector")->setVisible(true);
    mSceneManager->getSceneNode("SquareSelectorNode")->setPosition((Ogre::Real)*xPos,
                           (Ogre::Real)*yPos,
                           (Ogre::Real)0);
}

void RenderManager::rrCreateRoom(const RenderRequest& renderRequest)
{
    Room* curRoom = static_cast<Room*>(renderRequest.p);
    Tile* curTile = static_cast<Tile*>(renderRequest.p2);

    std::stringstream tempSS;
    tempSS << curRoom->getName() << "_" << curTile->x << "_" << curTile->y;
    // Create the room ground tile
    Ogre::Entity* ent = mSceneManager->createEntity(tempSS.str(), curRoom->getMeshName() + ".mesh");
    Ogre::SceneNode* node = mRoomSceneNode->createChildSceneNode(tempSS.str() + "_node");

    node->setPosition(static_cast<Ogre::Real>(curTile->x),
            static_cast<Ogre::Real>(curTile->y),
            static_cast<Ogre::Real>(0.02f));
    node->setScale(Ogre::Vector3(BLENDER_UNITS_PER_OGRE_UNIT,
                                 BLENDER_UNITS_PER_OGRE_UNIT,
                                 BLENDER_UNITS_PER_OGRE_UNIT));
    node->attachObject(ent);
}

void RenderManager::rrDestroyRoom(const RenderRequest& renderRequest)
{
    Room* curRoom = static_cast<Room*>(renderRequest.p);
    Tile* curTile = static_cast<Tile*>(renderRequest.p2);
    std::stringstream tempSS;
    tempSS << curRoom->getName() << "_" << curTile->x << "_" << curTile->y;

    if (mSceneManager->hasEntity(tempSS.str()))
    {
        Ogre::Entity* ent = mSceneManager->getEntity(tempSS.str());
        Ogre::SceneNode* node = mSceneManager->getSceneNode(tempSS.str() + "_node");
        node->detachObject(ent);
        mRoomSceneNode->removeChild(node);
        mSceneManager->destroyEntity(ent);
        mSceneManager->destroySceneNode(tempSS.str() + "_node");
    }
}

void RenderManager::rrCreateRoomObject(const RenderRequest& renderRequest)
{
    RoomObject* curRoomObject = static_cast<RoomObject*> (renderRequest.p);
    std::string name = renderRequest.str;
    boost::scoped_ptr<std::string> meshName(static_cast<std::string*>(renderRequest.p3));
    std::string tempString = curRoomObject->getOgreNamePrefix() + name;

    Ogre::Entity* ent = mSceneManager->createEntity(tempString, *meshName.get() + ".mesh");
    Ogre::SceneNode* node = mRoomSceneNode->createChildSceneNode(tempString + "_node");

    node->setPosition(Ogre::Vector3(curRoomObject->mX, curRoomObject->mY, 0.0));
    node->setScale(Ogre::Vector3(0.7, 0.7, 0.7));
    node->roll(Ogre::Degree(curRoomObject->mRotationAngle));
    node->attachObject(ent);
}

void RenderManager::rrDestroyRoomObject(const RenderRequest& renderRequest)
{
    RoomObject* curRoomObject = static_cast<RoomObject*> (renderRequest.p);

    std::string tempString = curRoomObject->getOgreNamePrefix()
   + curRoomObject->getName();
    Ogre::Entity* ent = mSceneManager->getEntity(tempString);
    Ogre::SceneNode* node = mSceneManager->getSceneNode(tempString + "_node");
    node->detachObject(ent);
    mSceneManager->destroySceneNode(node->getName());
    mSceneManager->destroyEntity(ent);
}

void RenderManager::rrCreateTrap(const RenderRequest& renderRequest)
{
    Trap* curTrap = static_cast<Trap*>(renderRequest.p);
    Tile* curTile = static_cast<Tile*>(renderRequest.p2);

    std::stringstream tempSS;
    tempSS << "Trap_" << curTrap->getName() + "_tile_"
      << curTile->x << "_" << curTile->y;
    std::string tempString = tempSS.str();
    Ogre::Entity* ent = mSceneManager->createEntity(tempString, curTrap->getMeshName() + ".mesh");
    Ogre::SceneNode* node = mRoomSceneNode->createChildSceneNode(tempString + "_node");
    node->setPosition(static_cast<Ogre::Real>(curTile->x),
                      static_cast<Ogre::Real>(curTile->y),
                      0.0f);
    node->attachObject(ent);
}

void RenderManager::rrDestroyTrap(const RenderRequest& renderRequest)
{
    Trap* curTrap = static_cast<Trap*>(renderRequest.p);
    Tile* curTile = static_cast<Tile*>(renderRequest.p2);

    std::stringstream tempSS;
    tempSS << "Trap_" << curTrap->getName() + "_tile_" << curTile->x << "_"
      << curTile->y;
    std::string tempString = tempSS.str();
    Ogre::Entity* ent = mSceneManager->getEntity(tempString);
    Ogre::SceneNode* node = mSceneManager->getSceneNode(tempString + "_node");
    node->detachObject(ent);
    mSceneManager->destroySceneNode(node->getName());
    mSceneManager->destroyEntity(ent);
}

void RenderManager::rrCreateTreasuryIndicator(const RenderRequest& renderRequest)
{
    Tile* curTile = static_cast<Tile*>(renderRequest.p);
    Room* curRoom = static_cast<Room*>(renderRequest.p2);
    std::stringstream tempSS;

    tempSS << curRoom->getName() << "_" << curTile->x << "_"
      << curTile->y;
    Ogre::Entity* ent = mSceneManager->createEntity(tempSS.str()
                      + "_treasury_indicator", renderRequest.str + ".mesh");
    Ogre::SceneNode* node = mSceneManager->getSceneNode(tempSS.str() + "_node");

    //FIXME: This second scene node is purely to cancel out the effects of BLENDER_UNITS_PER_OGRE_UNIT,
    // it can be gotten rid of when that hack is fixed.
    node = node->createChildSceneNode(node->getName()
                                      + "_hack_node");
    node->setScale(Ogre::Vector3((Ogre::Real)(1.0 / BLENDER_UNITS_PER_OGRE_UNIT),
                                 (Ogre::Real)(1.0 / BLENDER_UNITS_PER_OGRE_UNIT),
                                 (Ogre::Real)(1.0 / BLENDER_UNITS_PER_OGRE_UNIT)));
    node->attachObject(ent);
}

void RenderManager::rrDestroyTreasuryIndicator(const RenderRequest& renderRequest)
{
    Tile* curTile = static_cast<Tile*>(renderRequest.p);
    Room* curRoom = static_cast<Room*>(renderRequest.p2);

    std::stringstream tempSS;
    tempSS << curRoom->getName() << "_" << curTile->x << "_"
      << curTile->y;
    if (mSceneManager->hasEntity(tempSS.str() + "_treasury_indicator"))
    {
        Ogre::Entity* ent = mSceneManager->getEntity(tempSS.str()
                       + "_treasury_indicator");

        //FIXME: This second scene node is purely to cancel out the effects of BLENDER_UNITS_PER_OGRE_UNIT,
        // it can be gotten rid of when that hack is fixed.
        Ogre::SceneNode* node = mSceneManager->getSceneNode(tempSS.str() + "_node" + "_hack_node");

        /*  The proper code once the above hack is fixed.
       node = sceneManager->getSceneNode(tempSS.str() + "_node");
        */
        node->detachObject(ent);

        //FIXME: This line is not needed once the above hack is fixed.
        mSceneManager->destroySceneNode(node->getName());

        mSceneManager->destroyEntity(ent);
    }
}

void RenderManager::rrCreateCreature(const RenderRequest& renderRequest)
{
    Creature* curCreature = static_cast<Creature*>(renderRequest.p);
    std::string meshName = renderRequest.str;
    Ogre::Vector3 scale = renderRequest.vec;

    assert(curCreature != 0);
    //assert(curCreature->getDefinition() != 0);

    // Load the mesh for the creature
    // TODO the prefix Creature_ should be static field in some class then changing won't broke program
    Ogre::Entity* ent = mSceneManager->createEntity("Creature_" + curCreature->getName(), meshName);
    Ogre::MeshPtr meshPtr = ent->getMesh();

    unsigned short src, dest;
    if (!meshPtr->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
    {
        meshPtr->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
    }

    //Disabled temporarily for normal-mapping
    //colourizeEntity(ent, curCreature->color);
    Ogre::SceneNode* node = mCreatureSceneNode->createChildSceneNode(
   curCreature->getName() + "_node");
    curCreature->mSceneNode = node;
    node->setPosition(curCreature->getPosition());
    node->setScale(scale);
    node->attachObject(ent);
    curCreature->pSN = (node->getParentSceneNode());
    // curCreature->pSN->removeChild(node);
}

void RenderManager::rrDestroyCreature(const RenderRequest& renderRequest)
{
    Creature* curCreature = static_cast<Creature*>(renderRequest.p);
    if (mSceneManager->hasEntity("Creature_" + curCreature->getName()))
    {
        Ogre::Entity* ent = mSceneManager->getEntity("Creature_" + curCreature->getName());
        Ogre::SceneNode* node = mSceneManager->getSceneNode(curCreature->getName() + "_node");
        node->detachObject(ent);
        mCreatureSceneNode->removeChild(node);
        mSceneManager->destroyEntity(ent);
        mSceneManager->destroySceneNode(curCreature->getName() + "_node");
    }
    curCreature->mSceneNode = NULL;
}

void RenderManager::rrOrientSceneNodeToward(const RenderRequest& renderRequest)
{
    Ogre::SceneNode* node = mSceneManager->getSceneNode(renderRequest.str);
    Ogre::Vector3 tempVector = node->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Y;

    // Work around 180 degree quaternion rotation quirk
    if ((1.0f + tempVector.dotProduct(renderRequest.vec)) < 0.0001f)
    {
        node->roll(Ogre::Degree(180));
    }
    else
    {
        node->rotate(tempVector.getRotationTo(renderRequest.vec));
    }
}

void RenderManager::rrReorientSceneNode(const RenderRequest& renderRequest)
{
    Ogre::SceneNode* node = static_cast<Ogre::SceneNode*>(renderRequest.p);

    if (node != NULL)
    {
        node->rotate(renderRequest.quaternion);
    }
}

void RenderManager::rrScaleSceneNode(const RenderRequest& renderRequest)
{
    Ogre::SceneNode* node = static_cast<Ogre::SceneNode*>(renderRequest.p);

    if (node != NULL)
    {
        node->scale(renderRequest.vec);
    }
}

void RenderManager::rrCreateWeapon(const RenderRequest& renderRequest)
{
    Weapon* curWeapon = static_cast<Weapon*>( renderRequest.p);
    Creature* curCreature = static_cast<Creature*>(renderRequest.p2);

    Ogre::Entity* ent = mSceneManager->getEntity("Creature_" + curCreature->getName());
    //colourizeEntity(ent, curCreature->color);
    Ogre::Entity* weaponEntity = mSceneManager->createEntity("Weapon_"
                          + curWeapon->getHandString() + "_" + curCreature->getName(),
                          curWeapon->getMeshName());
    Ogre::Bone* weaponBone = ent->getSkeleton()->getBone(
   "Weapon_" + curWeapon->getHandString());

    // Rotate by -90 degrees around the x-axis from the bone's rotation.
    Ogre::Quaternion rotationQuaternion;
    rotationQuaternion.FromAngleAxis(Ogre::Degree(-90.0), Ogre::Vector3(1.0,
                           0.0, 0.0));

    ent->attachObjectToBone(weaponBone->getName(), weaponEntity,
                            rotationQuaternion);
}

void RenderManager::rrDestroyWeapon(const RenderRequest& renderRequest)
{
    Weapon* curWeapon = static_cast<Weapon*>(renderRequest.p);
    Creature* curCreature = static_cast<Creature*>(renderRequest.p2);

    if (curWeapon->getName().compare("none") != 0)
    {
        Ogre::Entity* ent = mSceneManager->getEntity("Weapon_"
                       + curWeapon->getHandString() + "_" + curCreature->getName());
        mSceneManager->destroyEntity(ent);
    }
}

void RenderManager::rrCreateMissileObject(const RenderRequest& renderRequest)
{
    MissileObject* curMissileObject = static_cast<MissileObject*>(renderRequest.p);
    Ogre::Entity* ent = mSceneManager->createEntity(curMissileObject->getName(),
                      curMissileObject->getMeshName() + ".mesh");
    //TODO:  Make a new subroot scene node for these so lookups are faster
    // since only a few missile objects should be onscreen at once.
    Ogre::SceneNode* node = mCreatureSceneNode->createChildSceneNode(
   curMissileObject->getName() + "_node");
    node->setPosition(curMissileObject->getPosition());
    node->attachObject(ent);
}

void RenderManager::rrDestroyMissileObject(const RenderRequest& renderRequest)
{
    MissileObject* curMissileObject = static_cast<MissileObject*>(renderRequest.p);
    if (mSceneManager->hasEntity(curMissileObject->getName()))
    {
        Ogre::Entity* ent = mSceneManager->getEntity(curMissileObject->getName());
        Ogre::SceneNode* node = mSceneManager->getSceneNode(curMissileObject->getName()  + "_node");
        node->detachObject(ent);
        mCreatureSceneNode->removeChild(node);
        mSceneManager->destroyEntity(ent);
        mSceneManager->destroySceneNode(curMissileObject->getName() + "_node");
    }
}

void RenderManager::rrCreateMapLight(const RenderRequest& renderRequest)
{
    MapLight* curMapLight = static_cast<MapLight*> (renderRequest.p);

    // Create the light and attach it to the lightSceneNode.
    std::string mapLightName = "MapLight_" + curMapLight->getName();
    Ogre::Light* light = mSceneManager->createLight(mapLightName);
    light->setDiffuseColour(curMapLight->getDiffuseColor());
    light->setSpecularColour(curMapLight->getSpecularColor());
    light->setAttenuation(curMapLight->getAttenuationRange(),
                          curMapLight->getAttenuationConstant(),
                          curMapLight->getAttenuationLinear(),
                          curMapLight->getAttenuationQuadratic());

    // Create the base node that the "flicker_node" and the mesh attach to.
    Ogre::SceneNode* mapLightNode = mLightSceneNode->createChildSceneNode(mapLightName + "_node");
    mapLightNode->setPosition(curMapLight->getPosition());

    //TODO - put this in request so we don't have to include the globals here.
    if (renderRequest.b)
    {
        // Create the MapLightIndicator mesh so the light can be drug around in the map editor.
        Ogre::Entity* lightEntity = mSceneManager->createEntity("MapLightIndicator_"
                        + curMapLight->getName(), "Light.mesh");
        mapLightNode->attachObject(lightEntity);
    }

    // Create the "flicker_node" which moves around randomly relative to
    // the base node.  This node carries the light itself.
    Ogre::SceneNode* flickerNode = mapLightNode->createChildSceneNode(mapLightName + "_flicker_node");
    flickerNode->attachObject(light);
}

void RenderManager::rrDestroyMapLight(const RenderRequest& renderRequest)
{
    MapLight* curMapLight = static_cast<MapLight*> (renderRequest.p);
    std::string mapLightName = "MapLight_" + curMapLight->getName();
    if (mSceneManager->hasLight(mapLightName))
    {
        Ogre::Light* light = mSceneManager->getLight(mapLightName);
        Ogre::SceneNode* lightNode = mSceneManager->getSceneNode(mapLightName + "_node");
        Ogre::SceneNode* lightFlickerNode = mSceneManager->getSceneNode(mapLightName
                           + "_flicker_node");
        lightFlickerNode->detachObject(light);
        mLightSceneNode->removeChild(lightNode);
        mSceneManager->destroyLight(light);

        if (mSceneManager->hasEntity(mapLightName))
        {
            Ogre::Entity* mapLightIndicatorEntity = mSceneManager->getEntity("MapLightIndicator_"
                                + curMapLight->getName());
            lightNode->detachObject(mapLightIndicatorEntity);
        }
        mSceneManager->destroySceneNode(lightFlickerNode->getName());
        mSceneManager->destroySceneNode(lightNode->getName());
    }
}

void RenderManager::rrDestroyMapLightVisualIndicator(const RenderRequest& renderRequest)
{
    MapLight* curMapLight = static_cast<MapLight*>(renderRequest.p);
    std::string mapLightName = "MapLight_" + curMapLight->getName();
    if (mSceneManager->hasLight(mapLightName))
    {
        Ogre::SceneNode* mapLightNode = mSceneManager->getSceneNode(mapLightName + "_node");
        std::string mapLightIndicatorName = "MapLightIndicator_"
       + curMapLight->getName();
        if (mSceneManager->hasEntity(mapLightIndicatorName))
        {
            Ogre::Entity* mapLightIndicatorEntity = mSceneManager->getEntity(mapLightIndicatorName);
            mapLightNode->detachObject(mapLightIndicatorEntity);
            mSceneManager->destroyEntity(mapLightIndicatorEntity);
            //NOTE: This line throws an error complaining 'scene node not found' that should not be happening.
            //mSceneManager->destroySceneNode(node->getName());
        }
    }
}

void RenderManager::rrCreateField(const RenderRequest& renderRequest)
{
    BattleField* curField = static_cast<BattleField*>(renderRequest.p);
    double* tempDoublePtr = static_cast<double*>(renderRequest.p2);
    Ogre::Real securityLevel = static_cast<Ogre::Real>(*tempDoublePtr);
    delete tempDoublePtr;

    FieldType::iterator fieldItr = curField->begin();
    while (fieldItr != curField->end())
    {
        int x = fieldItr->getPosX();
        int y = fieldItr->getPosY();
        Ogre::Real securityLevel2 = static_cast<Ogre::Real>(fieldItr->getSecurityLevel());
        //cout << "\ncreating field tile:  " << tempX << "
        //"\t" << tempY << "\t" << securityLevel;
        std::stringstream tempSS;
        tempSS << "Field_" << curField->getName() << "_" << x << "_" << y;
        Ogre::Entity* fieldIndicatorEntity = mSceneManager->createEntity(tempSS.str(),
                            "Field_indicator.mesh");
        Ogre::SceneNode* fieldIndicatorNode = mFieldSceneNode->createChildSceneNode(tempSS.str()
                                  + "_node");
        fieldIndicatorNode->setPosition(static_cast<Ogre::Real>(x),
                                        static_cast<Ogre::Real>(y),
                                        securityLevel + securityLevel2);
        fieldIndicatorNode->attachObject(fieldIndicatorEntity);

        ++fieldItr;
    }
}

void RenderManager::rrRefreshField(const RenderRequest& renderRequest)
{
    BattleField* curField = static_cast<BattleField*> (renderRequest.p);
    double* tempDoublePtr = static_cast<double*>(renderRequest.p2);
    double securityLevel = *tempDoublePtr;
    delete tempDoublePtr;

    // Update existing meshes and create any new ones needed.
    FieldType::iterator fieldItr = curField->begin();
    while (fieldItr != curField->end())
    {
        int x = fieldItr->getPosX();
        int y = fieldItr->getPosY();
        double securityLevel2 = fieldItr->getSecurityLevel();

        std::stringstream tempSS;
        tempSS << "Field_" << curField->getName() << "_" << x << "_" << y;

        Ogre::SceneNode* fieldIndicatorNode = NULL;

        if (mSceneManager->hasEntity(tempSS.str()))
        {
            // The mesh alread exists, just get the existing one
            fieldIndicatorNode = mSceneManager->getSceneNode(tempSS.str() + "_node");
        }
        else
        {
            // The mesh does not exist, create a new one
            Ogre::Entity* fieldIndicatorEntity = mSceneManager->createEntity(tempSS.str(),
                                "Field_indicator.mesh");
            fieldIndicatorNode = mFieldSceneNode->createChildSceneNode(tempSS.str() + "_node");
            fieldIndicatorNode->attachObject(fieldIndicatorEntity);
        }

        fieldIndicatorNode->setPosition((Ogre::Real)x, (Ogre::Real)y,
                                        (Ogre::Real)(securityLevel + securityLevel2));
        ++fieldItr;
    }

    //TODO: Deleting is not done yet.
    // Delete any meshes not in the field currently
}

void RenderManager::rrPickUpCreature(const RenderRequest& renderRequest)
{
    Creature* curCreature = static_cast<Creature*>(renderRequest.p);
    // Detach the creature from the creature scene node
    Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curCreature->getName() + "_node");
    //FIXME this variable name is a bit misleading
    mCreatureSceneNode->removeChild(creatureNode);

    // Attach the creature to the hand scene node
    mSceneManager->getSceneNode("Hand_node")->addChild(creatureNode);
    //FIXME we should probably use setscale for this, because of rounding.
    creatureNode->scale(0.333, 0.333, 0.333);

    // Move the other creatures in the player's hand to make room for the one just picked up.
    for (unsigned int i = 0; i < mGameMap->getLocalPlayer()->numCreaturesInHand(); ++i)
    {
        curCreature = mGameMap->getLocalPlayer()->getCreatureInHand(i);
        creatureNode = mSceneManager->getSceneNode(curCreature->getName() + "_node");
        creatureNode->setPosition((Ogre::Real)(i % 6 + 1), (Ogre::Real)(i / (int)6), (Ogre::Real)0.0);
    }
}

void RenderManager::rrDropCreature(const RenderRequest& renderRequest)
{
    Creature* curCreature = static_cast<Creature*>(renderRequest.p);
    Player* curPlayer = static_cast<Player*> (renderRequest.p2);
    // Detach the creature from the "hand" scene node
    Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curCreature->getName() + "_node");
    mSceneManager->getSceneNode("Hand_node")->removeChild(creatureNode);

    // Attach the creature from the creature scene node
    mCreatureSceneNode->addChild(creatureNode);
    creatureNode->setPosition(curCreature->getPosition());
    creatureNode->scale(3.0, 3.0, 3.0);

    // Move the other creatures in the player's hand to replace the dropped one
    for (unsigned int i = 0; i < curPlayer->numCreaturesInHand(); ++i)
    {
        curCreature = curPlayer->getCreatureInHand(i);
        creatureNode = mSceneManager->getSceneNode(curCreature->getName() + "_node");
        creatureNode->setPosition((Ogre::Real)(i % 6 + 1), (Ogre::Real)(i / (int)6), (Ogre::Real)0.0);
    }
}

void RenderManager::rrRotateCreaturesInHand(const RenderRequest&)
{
    // Loop over the creatures in our hand and redraw each of them in their new location.
    for (unsigned int i = 0; i < mGameMap->getLocalPlayer()->numCreaturesInHand(); ++i)
    {
        Creature* curCreature = mGameMap->getLocalPlayer()->getCreatureInHand(i);
        Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curCreature->getName() + "_node");
        creatureNode->setPosition((Ogre::Real)(i % 6 + 1), (Ogre::Real)(i / (int)6), (Ogre::Real)0.0);
    }
}

void RenderManager::rrCreateCreatureVisualDebug(const RenderRequest& renderRequest)
{
    Tile* curTile = static_cast<Tile*>(renderRequest.p);
    Creature* curCreature = static_cast<Creature*>( renderRequest.p2);

    if (curTile != NULL && curCreature != NULL)
    {
        std::stringstream tempSS;
        tempSS << "Vision_indicator_" << curCreature->getName() << "_"
          << curTile->x << "_" << curTile->y;

        Ogre::Entity* visIndicatorEntity = mSceneManager->createEntity(tempSS.str(),
                               "Cre_vision_indicator.mesh");
        Ogre::SceneNode* visIndicatorNode = mCreatureSceneNode->createChildSceneNode(tempSS.str()
                                   + "_node");
        visIndicatorNode->attachObject(visIndicatorEntity);
        visIndicatorNode->setPosition(Ogre::Vector3((Ogre::Real)curTile->x, (Ogre::Real)curTile->y, (Ogre::Real)0));
        visIndicatorNode->setScale(Ogre::Vector3(BLENDER_UNITS_PER_OGRE_UNIT,
                   BLENDER_UNITS_PER_OGRE_UNIT,
                   BLENDER_UNITS_PER_OGRE_UNIT));
    }
}

void RenderManager::rrDestroyCreatureVisualDebug(const RenderRequest& renderRequest)
{
    Tile* curTile = static_cast<Tile*>(renderRequest.p);
    Creature* curCreature = static_cast<Creature*>(renderRequest.p2);

    std::stringstream tempSS;
    tempSS << "Vision_indicator_" << curCreature->getName() << "_"
      << curTile->x << "_" << curTile->y;
    if (mSceneManager->hasEntity(tempSS.str()))
    {
        Ogre::Entity* visIndicatorEntity = mSceneManager->getEntity(tempSS.str());
        Ogre::SceneNode* visIndicatorNode = mSceneManager->getSceneNode(tempSS.str() + "_node");

        visIndicatorNode->detachAllObjects();
        mSceneManager->destroyEntity(visIndicatorEntity);
        mSceneManager->destroySceneNode(visIndicatorNode);
    }
}

void RenderManager::rrSetObjectAnimationState(const RenderRequest& renderRequest)
{
    MovableGameEntity* curAnimatedObject = static_cast<MovableGameEntity*>(renderRequest.p);
    Ogre::Entity* objectEntity = mSceneManager->getEntity(
   curAnimatedObject->getOgreNamePrefix()
   + curAnimatedObject->getName());

    if (objectEntity->hasSkeleton()
   && objectEntity->getSkeleton()->hasAnimation(renderRequest.str))
    {
        // Disable the animation for all of the animations on this entity.
        Ogre::AnimationStateIterator animationStateIterator(
            objectEntity->getAllAnimationStates()->getAnimationStateIterator());
        while (animationStateIterator.hasMoreElements())
        {
            animationStateIterator.getNext()->setEnabled(false);
        }

        // Enable the animation specified in the RenderRequest object.
        // FIXME:, make a function rather than using a public var
        curAnimatedObject->mAnimationState = objectEntity->getAnimationState(
       renderRequest.str);
        curAnimatedObject->mAnimationState->setLoop(renderRequest.b);
        curAnimatedObject->mAnimationState->setEnabled(true);
    }
    //TODO:  Handle the case where this entity does not have the requested animation.
}
void RenderManager::rrMoveSceneNode(const RenderRequest& renderRequest)
{
    if (mSceneManager->hasSceneNode(renderRequest.str))
    {
        Ogre::SceneNode* node = mSceneManager->getSceneNode(renderRequest.str);
        node->setPosition(renderRequest.vec);
    }
}class ReorientSceneNode:RenderRequest
 {
 public:
     ReorientSceneNode(){}

     virtual int exectute()
     {
    Ogre::SceneNode* node = static_cast<Ogre::SceneNode*>(renderRequest.p);

    if (node != NULL)
    {
        node->rotate(renderRequest.quaternion);
    }
     }
};
class RotateCreaturesInHand:RenderRequest
{
public:
    RotateCreaturesInHand(){}

    virtual int exectute()
    {
   // Loop over the creatures in our hand and redraw each of them in their new location.
   for (unsigned int i = 0; i < mGameMap->getLocalPlayer()->numCreaturesInHand(); ++i)
   {
       Creature* curCreature = mGameMap->getLocalPlayer()->getCreatureInHand(i);
       Ogre::SceneNode* creatureNode = mSceneManager->getSceneNode(curCreature->getName() + "_node");
       creatureNode->setPosition((Ogre::Real)(i % 6 + 1), (Ogre::Real)(i / (int)6), (Ogre::Real)0.0);
   }
    }
};
class ScaleSceneNode:RenderRequest
{
public:
    ScaleSceneNode(){}

    virtual int exectute()
    {
   Ogre::SceneNode* node = static_cast<Ogre::SceneNode*>(renderRequest.p);

   if (node != NULL)
   {
       node->scale(renderRequest.vec);
   }
    }
};
class SetObjectAnimationState:RenderRequest
{
public:
    SetObjectAnimationState(){}

    virtual int exectute()
    {
   MovableGameEntity* curAnimatedObject = static_cast<MovableGameEntity*>(renderRequest.p);
   Ogre::Entity* objectEntity = mSceneManager->getEntity(
       curAnimatedObject->getOgreNamePrefix()
       + curAnimatedObject->getName());

   if (objectEntity->hasSkeleton()
            && objectEntity->getSkeleton()->hasAnimation(renderRequest.str))
   {
       // Disable the animation for all of the animations on this entity.
       Ogre::AnimationStateIterator animationStateIterator(
      objectEntity->getAllAnimationStates()->getAnimationStateIterator());
       while (animationStateIterator.hasMoreElements())
       {
      animationStateIterator.getNext()->setEnabled(false);
       }

       // Enable the animation specified in the RenderRequest object.
       // FIXME:, make a function rather than using a public var
       curAnimatedObject->mAnimationState = objectEntity->getAnimationState(
      renderRequest.str);
       curAnimatedObject->mAnimationState->setLoop(renderRequest.b);
       curAnimatedObject->mAnimationState->setEnabled(true);
   }
   //TODO:  Handle the case where this entity does not have the requested animation.
    }};
class ShowSquareSelector:RenderRequest
{
public:
    ShowSquareSelector(){}

    virtual int exectute()
    {
   int* xPos = static_cast<int*>(renderRequest.p);
   int* yPos = static_cast<int*>(renderRequest.p2);

   mSceneManager->getEntity("SquareSelector")->setVisible(true);
   mSceneManager->getSceneNode("SquareSelectorNode")->setPosition((Ogre::Real)*xPos,
                               (Ogre::Real)*yPos,
                               (Ogre::Real)0);
    }
};
class TemporalMarkTile:RenderRequest
{
public:
    TemporalMarkTile(){}

    virtual int exectute()
    {
   Ogre::SceneManager* mSceneMgr = RenderManager::getSingletonPtr()->getSceneManager();
   Ogre::Entity* ent;
   std::stringstream ss;
   std::stringstream ss2;
   Tile* curTile = static_cast<Tile*>(renderRequest.p);

   bool bb = curTile->getSelected();

   ss.str(std::string());
   ss << "Level";
   ss << "_";
   ss <<  curTile->x;
   ss << "_";
   ss <<  curTile->y;
   ss << "_selection_indicator";

   if (mSceneMgr->hasEntity(ss.str()))
   {
       ent = mSceneMgr->getEntity(ss.str());
   }
   else
   {
       ss2.str(std::string());
       ss2 << "Level";
       ss2 << "_";
       ss2 << curTile->x;
       ss2 << "_";
       ss2 << curTile->y;
       ss2 << "_node";
       ent = mSceneMgr->createEntity(ss.str(), "SquareSelector.mesh");
       Ogre::SceneNode* node = mSceneManager->getSceneNode(ss2.str())->createChildSceneNode(ss.str()+"Node");
       node->setInheritScale(false);
       node->scale(Ogre::Vector3(BLENDER_UNITS_PER_OGRE_UNIT,
                  BLENDER_UNITS_PER_OGRE_UNIT, 0.45 * BLENDER_UNITS_PER_OGRE_UNIT));
       node->attachObject(ent);
   }

   ent->setVisible(bb);
    }
};
class ToggleCreaturesVisibility:RenderRequest
{
public:
    ToggleCreaturesVisibility(){}

    virtual int exectute()
    {
   mVisibleCreatures = !mVisibleCreatures;

   if(mVisibleCreatures)
   {
       for(std::vector<Creature*>::iterator it = mGameMap->creatures.begin(); it != mGameMap->creatures.end(); ++it)
       {
      if((*it)->isMeshExisting() && (*it)->mSceneNode != NULL)

          // (*it)->pSN=((*it)->sceneNode->getParentSceneNode());
          //pSN->removeChild((*it)->
          (*it)->pSN->addChild((*it)->mSceneNode);
      //  addAnimatedObject(*it);
      // (*it)->createMesh();
       }
   }
   else
   {
       for(std::vector<Creature*>::iterator it = mGameMap->creatures.begin(); it != mGameMap->creatures.end(); ++it)
       {
      if((*it)->isMeshExisting() && (*it)->mSceneNode!=NULL)
      {
          (*it)->pSN=((*it)->mSceneNode->getParentSceneNode());
          (*it)->pSN->removeChild((*it)->mSceneNode);
      }

      // removeAnimatedObject(*it);
      // (*it)->destroyMesh();
       }
   }
    }
};


That's half done , I am showing what I was able to transform to ... :)

Re: RenderManager.cpp split into smaller classes

PostPosted: 13 Jul 2014, 20:24
by paul424
I’m really not sure what you intend to do…
What would you put in these classes?

Which problems are you trying to fix? There is no problem of construction/destruction with an enum, it’s a simple integer

Well the problem of casting from (void*) to proper pointer (which could be any pointer ) here and there ......

Re: RenderManager.cpp split into smaller classes

PostPosted: 14 Jul 2014, 22:56
by hwoarangmy
paul424 {l Wrote}:Well the problem of casting from (void*) to proper pointer (which could be any pointer ) here and there ......
To be honest, I didn't understand what you really intended to do until now. In fact, you don't want to split the class but to use inheritance instead of old c void*. In general, I would say it is a good thing. But in this particular case, I have to say that I am not really sure that there is a point in using a message queue for rendering. As everything is already done in the ODFrameListener thread context, I don't see why there is a rendering step. But I have to say I have not played much with this part of the code and I might have missed something.
To me, it seems like a rest of the old threaded code Bertram was talking about. IMHO, we should check if it is needed to keep this class or if we can remove it (and that would also get ride of the void* pointers that were bothering you).

Re: RenderManager.cpp split into smaller classes

PostPosted: 15 Jul 2014, 12:45
by paul424
<strike>What I understood Ogre3d is optimizing those calls , having such message pump. Notice that the dequing does not take part in ordinary thread, it's part of Ogre3d mechanism .... Hmm ha ! maybe it's kind of optimalization : when it comes to rendering part ( frame started event ) maybe it can watch over how much Vertex Lists, Textures to raster there is , if too few it can dequeue sevaral requests more etc, so the GPU batch is not wasted ..... </strike>
HTML5 is such a crap ....

Well it can't be obviously true , cause the rendering perf . depends in size of the visible scene in camera frustrum , in general, but anyway maybe it has something to do with optimalization ....

Re: RenderManager.cpp split into smaller classes

PostPosted: 15 Jul 2014, 14:06
by oln
The message queue was there because there used to be a rendering thread. (Which made the game crash on exit due to rendering on something else than the main thread was not really supported, by either ogre or OpenGL, not sure which.) It does make sense to do use message passing if threading is used (granted the rendering is done in the main thread), but it isn't at the moment, and it wasn't really being done in a good way before anyhow.

Re: RenderManager.cpp split into smaller classes

PostPosted: 15 Jul 2014, 20:25
by paul424
Aha, Bertram ( or someone else ) removed the separate thread for rendering , that would explain why it is so lagging on my weaker machine .

Re: RenderManager.cpp split into smaller classes

PostPosted: 17 Jul 2014, 23:03
by hwoarangmy
Almost all the graphics API (3D or not) I've tried do not support changing the objects to render outside the rendering thread (in OD, ODFrameListener).
That is because on rendering functions, called many times per second, synchronisation costs needed to allow objects modifications from other threads are too expensive. And as far as I've seen, it is the same with ogre.

The problem with doing everything on the rendering thread is that it can freeze the UI and that really feels laggy when it happens. But the best is to have a thread that updates the game mechanics (most of what is done in the GameMap) and use the dedicated one for rendering (from this point of view, using a render class like the actual one makes sense if the message queue is used within the frame listener context).
Anyway, when we will have implemented the server paradigm, that will more or less be done as the GameMap will be updated in the server thread :)

But it is a good practice to avoid using threads when not needed. The work Bertram did on removing the (many) threads used in OD will likely solve much problems and help the code being more understandable...

Re: RenderManager.cpp split into smaller classes

PostPosted: 18 Jul 2014, 13:19
by paul424
Almost all the graphics API (3D or not) I've tried do not support changing the objects to render outside the rendering thread (in OD, ODFrameListener).

Could you rettranslate that to a more simple English ( I hardly understand what is being said here ) .
The problem with doing everything on the rendering thread is that it can freeze the UI and that really feels laggy when it happens.

You mean, I get UI freezes on my second machine right ?

Re: RenderManager.cpp split into smaller classes

PostPosted: 21 Jul 2014, 21:52
by hwoarangmy
paul424 {l Wrote}:Could you rettranslate that to a more simple English ( I hardly understand what is being said here ) .
To say things simply, as every framework, Ogre keeps track of the objects (meshes, ...) you add and renders them many times per second. The problem is that if you use another thread to change the rendered objects state (removing, changing the position, changing the text, ...), you may change them while they are being rendered. So, there are only 2 solutions :
1 - allow the rendered objets to be updated only is the render thread (in OD, the thread that calls ODFrameListener::frameStarted
2 - Use synchronisation everywhere to make sure everything is thread safe

Every framework (3D or 2D) I've used until then chose solution 1 because as they render frames several times per second, synchronisation costs are just too heavy.

paul424 {l Wrote}:You mean, I get UI freezes on my second machine right ?
I don't know what you've got on your second machine, I've not seen it ;)
But that's what I was talking about. When there is only one thread like it is the case actually, if something a little bit time consuming happens (updating game map or whatever), the UI will freeze and that makes the game feel laggy. If there is a background task that does the work, the game is not faster but because the UI do not freeze, it do not feel as laggy...