void ZoneListWidget::_createImages(ImageMap& retlist)
{
    retlist.clear();

    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "EntityTex",
                   Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
                   256, 256, 0, Ogre::PF_A8R8G8B8 , Ogre::TU_RENDERTARGET );

    Ogre::RenderTexture *rttTex = texture->getBuffer()->getRenderTarget();
    Ogre::SceneManager *mSceneMgr = Ogre::Root::getSingletonPtr()->createSceneManager("OctreeSceneManager", "EntityTexMgr");

    Ogre::Light *dirl = mSceneMgr->createLight("DisplayLight");
    dirl->setDirection(-1,-1,-1);
    dirl->setDiffuseColour(1,1,1);
    dirl->setType(Ogre::Light::LT_DIRECTIONAL);

    Ogre::Camera* RTTCam = mSceneMgr->createCamera("EntityCam");
    RTTCam->setNearClipDistance(0.01F);
    RTTCam->setFarClipDistance(0);
    RTTCam->setAspectRatio(1);
    RTTCam->setFOVy(Ogre::Degree(90));
    RTTCam->setPosition(0,0,1);
    RTTCam->lookAt(0,0,0);

    Ogre::Viewport *v = rttTex->addViewport( RTTCam );
    v->setClearEveryFrame( true );
    v->setBackgroundColour(Ogre::ColourValue(0,0,0,0));

    ModularZoneFactory* factory = dynamic_cast<ModularZoneFactory*>(OgitorsRoot::getSingletonPtr()->GetEditorObjectFactory("Modular Zone Object"));
    if(!factory)return;
    factory->loadZoneTemplates();
    ZoneInfoMap zoneTemplates = factory->getZoneTemplateMap();

    Ogre::Entity *mEntity;

    unsigned char dataptr[300 * 300 * 6];
    unsigned char *dataptr2;
    Ogre::PixelBox pb(256,256,1,Ogre::PF_A8R8G8B8, dataptr);

    EntityMap entities;
    ZoneInfoMap::iterator zi;
    for(zi=zoneTemplates.begin();zi!=zoneTemplates.end();++zi)
    {
        Ogre::String addstr = (*zi).second.mMesh;
        if(entities.find((*zi).first) == entities.end())
            entities.insert(EntityMap::value_type((*zi).first,addstr));
    }

    EntityMap::const_iterator ite = entities.begin();

    while(ite != entities.end())
    {
        Ogre::String addstr = ite->second;

        mEntity = mSceneMgr->createEntity("MZP_Preview", addstr);

        mSceneMgr->getRootSceneNode()->attachObject(mEntity);

        //TODO: It would be nice to retrieve a Preview Camera Position from
        //the .zone file
        //TODO: also render portal outlines clearly so that the user can see
        //how the zone is laid out
        Ogre::Vector3 vSize = mEntity->getBoundingBox().getCorner(Ogre::AxisAlignedBox::NEAR_RIGHT_TOP);//.getHalfSize();//============
        Ogre::Vector3 vCenter = mEntity->getBoundingBox().getCenter();

//FIXME ------ NICE PREVIEWS NEEDED - bigger

        vSize += Ogre::Vector3(vSize.z, vSize.z, vSize.z);

        float maxsize = std::max(std::max(vSize.x,vSize.y),vSize.z);

        //vSize = Ogre::Vector3(0, 0, maxsize * 1.1f) + vCenter;
        vSize = Ogre::Vector3(maxsize * 0.5f, vSize.y, maxsize * 0.5f) + vCenter;
        //vSize.x +=vSize.x/2;//Maybe test to see which is larger x/2 or z/2 and use that?
        //vSize.z +=vSize.x/2;
        //RTTCam->setProjectionType(Ogre::PT_ORTHOGRAPHIC);

        RTTCam->setPosition(vSize.x,vSize.y,vSize.z);
        RTTCam->lookAt(vCenter.x,vCenter.y,vCenter.z);

        rttTex->update();
        rttTex->copyContentsToMemory(pb, Ogre::RenderTarget::FB_FRONT);


        dataptr2 = new unsigned char[96 * 96 * 4];
        Ogre::PixelBox pb2(96,96,1,Ogre::PF_A8R8G8B8, dataptr2);
        Ogre::Image::scale(pb,pb2);

        addstr.erase(addstr.length() - 5, 5);
        retlist.insert(ImageMap::value_type((*ite).first, dataptr2));

        mEntity->detachFromParent();
        mSceneMgr->destroyEntity(mEntity);

        ite++;
    }

    rttTex->removeAllViewports();
    Ogre::Root::getSingletonPtr()->destroySceneManager(mSceneMgr);
    Ogre::TextureManager::getSingletonPtr()->unload(texture->getName());
    Ogre::TextureManager::getSingletonPtr()->remove(texture->getName());
}
Example #2
0
AdZone2Creatives AdMatchManagerI::GetAdsByZoneInfo(const string& userProfile, const string& append_para, int rotate_index, const ZoneInfoMap &zone_info_map, const ::Ice::Current& current){
  timeval start;
  gettimeofday(&start, NULL);
  AdResultMap ans;
  AdZone2Creatives res;
  UserProfile profile;
  UserProfileClient::instance().Deserialize(userProfile, &profile);
  if(!init_ok_){
    MCE_INFO("AdMatchNManagerI::GetAds() --> initing.......");
    return res;
  }
  CookieEmptyCheck(profile);

  if(profile.id() == 287726637 || profile.id() == 287726711) {
    unsigned int ip = ntohl(inet_addr("14.201.79.46"));
    profile.set_ip(ip);
    profile.set_ip_area("0001000000000000");
    MCE_DEBUG("Modify user ip" << ip << ",userid:" << profile.id());
  }

  MatchHandlerParamter para(profile, append_para);
  //AdZoneDict zone_dict = AdZonePool::instance().GetAdZoneOrdered(para.referer_, profile, false);
  AdZoneDict zone_dict = AdZonePool::instance().GetAdZoneOrdered(zone_info_map, profile);
  if(zone_dict.empty()){
    MCE_INFO("AdMatchNManagerI::GetAdsByZoneInfo GetAdZoneOrdered() empty. referer=" << para.referer_);
    return res;
  }
  MCE_INFO("[MAIN_PROCESS] AdMatchNManagerI::GetAdsByZoneInfo --> AdZoneDict->size = " << zone_dict.size()<<",uid = " << para.userProfile_.id());

  FilterBindUser(zone_dict, ans, profile.id());

  /*string tag;
  Ice::Context::const_iterator i = current.ctx.find("tag");
  if (i != current.ctx.end() && !i->second.empty()) {
    tag = i->second;
  }

  if(!tag.empty()) {
    para.tag_ = tag;
  }*/

  Ice::Context::const_iterator i = current.ctx.find("photo");
  if (i != current.ctx.end() && i->second == "true") {
    para.photo_ = true;
  }
  i = current.ctx.find("count");
  if (i != current.ctx.end() && !i->second.empty()) {
    try{
      para.count_ = boost::lexical_cast<int>(i->second);
    }catch(std::exception e) {
      MCE_WARN("AdMatchManagerI::GetAdsByZoneInfo--err:" << e.what());
    }catch(...) {
      MCE_WARN("AdMatchManagerI::GetAdsByZoneInfo--unknow err:" );
    } 
  }
  MCE_DEBUG("AdMatchManagerI::GetAdsByZoneInfo --> para.count_ = " << para.count_);

  bool hide_flag = false;
  for(AdZoneDict::iterator it = zone_dict.begin(); it != zone_dict.end(); ++it){
    para.adzone_ = it->second;
    para.style_ = AdStyleDispatcher::instance().Dispatch(para.adzone_->id(),para.userProfile_);
    MCE_DEBUG("after dispatch: user_id = " << para.userProfile_.id() << ", adzone_id = " <<para.adzone_->id() << ", style_id = " << para.style_);
    if(100000000073 == para.adzone_->id() && hide_flag) {
      continue;
    }
    int rotate_size = it->second->GetRotateSize();
    if (rotate_size) {
      para.rotate_index_ = rotate_index % rotate_size;
    }
    para.zone_selected_groups_.clear();


    ZoneInfoMap::const_iterator itz = zone_info_map.find(para.adzone_->id());
    if(itz != zone_info_map.end()) {
      para.tag_ = itz->second.tag;
    } else {
      para.tag_ = "";
    }

    for(size_t i = 0; i < ad_match_handler_list_.size(); ++i) {

      if (!ad_match_handler_list_[i]->handle(para, ans)) {
        //如果是相册页wb1(72)展示自助广告,则不展示wb2广告位(73)
        if((100000000072 == para.adzone_->id()) && (!ans[100000000072].empty())) {
          MCE_DEBUG("hide_flag = true");
          hide_flag = true;
        }
        break;
      }
    }
    AdInfoSeq ad_seq = ans[para.adzone_->id()];
    AdCreativeSeq ac_seq;
    int abs_pos =0 ;
    for(AdInfoSeq::const_iterator ad_it = ad_seq.begin() ; ad_it != ad_seq.end() ; ++ ad_it){
      AdCreativeInfo ac ;
      ac.creativeid = ad_it->creativeid;
      ac.groupid = ad_it->groupid;
      string atts = ad_it->text;
      vector<string> para_strs;
      boost::algorithm::split_regex( para_strs, atts,regex( "\\^C" ) ) ;
      ac.widgetid = boost::lexical_cast<Ice::Long>(para_strs[1]);
      ac.text = atts;
      if(ad_it->updateTime == -1) {
        ac.extra = "style_test";
      } else {
        ac.extra = "";
      }
      ac.position = ++abs_pos;
      ac_seq.push_back(ac);
    }
    res[para.adzone_->id()] = ac_seq;
  }

  for(AdZone2Creatives::const_iterator it = res.begin(); it != res.end(); ++it) {
    MCE_DEBUG("Ads : " << it->first << '/' << it->second.size());
    if( it->second.size() > 0 ) {
      for( int vi = 0 ; vi < it->second.size() ; vi ++ ) {
        MCE_DEBUG("widgetid = " << it->second[vi].widgetid);
      }
    }
  }
  timeval end;
  gettimeofday(&end, NULL);
  AdMatchManagerI::instance().ping_sender_.Send("GetAds", 1000*(end.tv_sec-start.tv_sec)+(end.tv_usec-start.tv_usec)/1000);
  return res;
}