Example #1
0
ostream& operator<<(ostream& o, const lvid_t& lvid)
{
    const u_char* p = (const u_char*) &lvid.high;
    //(char*)inet_ntoa(lvid.net_addr)

        // WARNING: byte-order-dependent
    return o << u_int(p[0]) << '.' << u_int(p[1]) << '.'
             << u_int(p[2]) << '.' << u_int(p[3]) << ':'
             <<        lvid.low;
}
Example #2
0
File: lm.cpp Project: caomw/r4r
void CSplitBregman<Matrix,T>::Shrink() {

    u_int dim = u_int(m_dim_grad);

    assert(m_d.NRows()%dim==0);

    size_t npts = m_d.NRows()/dim;

    T li = 1/m_lambda;

    for(size_t j=0; j<m_d.NCols(); j++) {

        for(size_t i=0; i<npts; i++) {

            T norm = 0;

            for(u_int k=0; k<dim; k++)
                norm += m_d.Get(i+k*npts,j)*m_d.Get(i+k*npts,j);

            norm = sqrt(norm);

            T factor;
            if(norm<=li)
                factor = 0;
            else
                factor = (norm - li)/norm;

            for(u_int k=0; k<dim; k++)
                m_d(i+k*npts,j) *= factor;

        }

    }

}
Example #3
0
void DirectShowGrabber::fps(int f) {
   if (f <= 0)
      f = 1;
   else if (u_int(f) > max_fps_)
      f = max_fps_;

   Grabber::fps(f);
}
Example #4
0
void _BOS_INFO::setData(char* aData,u_int aDataSize)   // dataSize given in bytes
{
        bos->length=u_int((aDataSize+3)/4);  // now in units of words

        delete data;
        data=new char[bos->length*4];

        memcpy(data,aData,aDataSize);
}
Example #5
0
bool _BOS_HIVO::readFromFile(_BOS *aBos,f_i *file)
{
        *bos=*(aBos->bos);
        file->read((char*)(&colCount),4);
        file->read((char*)(&rowCount),4);
        file->read((char*)(&dataSize),4);
        if (dataSize>100000) return false;
        delete [] data;
        data=new char[dataSize];
        return (file->read(data,dataSize)==u_int(dataSize));
}
Example #6
0
void init::randomSeed() {
  data::rand.setSeed(u_int(time(nullptr)));
}
Example #7
0
static void *
worker (void *c)
{
  int count = *(static_cast<int*> (c));

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) worker, iterations = %d\n"), count));

  ACE_thread_key_t key = ACE_OS::NULL_key;
  int *ip = 0;

  // Make one key that will be available when the thread exits so that
  // we'll have something to cleanup!

  if (ACE_Thread::keycreate (&key, cleanup) == -1)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p (no keys available)\n"),
                  ACE_TEXT ("ACE_Thread::keycreate")));
      return (void *) -1;
    }

  ACE_NEW_RETURN (ip, int, 0);

  if (ACE_Thread::setspecific (key, (void *) ip) == -1)
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                ACE_TEXT ("ACE_Thread::setspecific")));

  for (int i = 0; i < count; i++)
    {
      if (ACE_Thread::keycreate (&key, cleanup) == -1)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p (no more keys)\n"),
                      ACE_TEXT ("ACE_Thread::keycreate")));
          break;
        }

      ACE_NEW_RETURN (ip, int, 0);

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) in worker at location 1, ")
                            ACE_TEXT ("key = %d, ip = %x\n"),
                  key, ip));

      // Needed to work around (possibly broken?) strict aliasing warning in GCC.
      void *v_ip (reinterpret_cast <void *> (ip));

      if (ACE_Thread::setspecific (key, v_ip) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::setspecific")));

      if (ACE_Thread::getspecific (key, &v_ip) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::getspecific")));

      if (ACE_Thread::setspecific (key, (void *) 0) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::setspecific")));

      // See comment in cleanup () above.
      delete ip;

#if defined (ACE_HAS_TSS_EMULATION)
      if (ACE_Thread::keyfree (key) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::keyfree")));
#endif /* ACE_HAS_TSS_EMULATION */

      // Cause an error.
      ACE_OS::read (ACE_INVALID_HANDLE, 0, 0);

      // The following two lines set the thread-specific state.
      (*tss_error)->error (errno);
      (*tss_error)->line (__LINE__);

      // This sets the static state (note how C++ makes it easy to do
      // both).
      (*tss_error)->flags (count);

      {
        // Use the guard to serialize access
        ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, output_lock, 0));
        ACE_ASSERT ((*tss_error)->flags () == ITERATIONS);
      }

      // Demonstrate use of ACE_TSS_Type_Adapter to wrap built-in
      // types when used with ACE_TSS.  See DESCRIPTION of template
      // class ACE_TSS_Type_Adapter in ace/Synch_T.h for what this
      // should look like.  Unfortunately, some compilers have trouble
      // with the implicit type conversions.  Others have problems with
      // the *explicit* type conversions.
#if !defined (ACE_HAS_BROKEN_EXPLICIT_TYPECAST_OPERATOR_INVOCATION)
      (*u)->operator u_int & () = 37;
      if ((*u)->operator u_int () != 37)
        {
          // Use the guard to serialize access to errors.
          ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, output_lock,
                                    0));
          ACE_DEBUG ((LM_ERROR,
                      ACE_TEXT ("use of ACE_TSS_Type_Adapter failed, value ")
                      ACE_TEXT ("is %u, it should be 37!\n"),
                      (*u)->operator u_int ()));
          ++errors;
        }
#endif /* !defined (ACE_HAS_BROKEN_EXPLICIT_TYPECAST_OPERATOR_INVOCATION) */

#if defined (ACE_HAS_TSS_EMULATION)
      key = ACE_OS::NULL_key;

      if (ACE_Thread::keycreate (&key, cleanup) == -1)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p (no more keys)\n"),
                      ACE_TEXT ("ACE_Thread::keycreate")));
          break;
        }

      ACE_NEW_RETURN (ip, int, 0);

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) in worker at location 2, ")
                            ACE_TEXT ("key = %d, ip = %x\n"),
                  key, ip));

      // Needed to work around (possibly broken?) strict aliasing warning in GCC.
      void *v_ip2 (reinterpret_cast <void *> (ip));

      if (ACE_Thread::setspecific (key, v_ip2) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::setspecific")));

      if (ACE_Thread::getspecific (key, &v_ip2) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::getspecific")));

      if (ACE_Thread::setspecific (key, (void *) 0) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::setspecific")));

      // See comment in cleanup () above.
      delete ip;

      // ACE_HAS_TSS_EMULATION is turned on, then it should work.
#  if defined (ACE_HAS_TSS_EMULATION)
      if (ACE_Thread::keyfree (key) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::keyfree")));
#  endif /* defined (ACE_HAS_TSS_EMULATION) */
#endif /* ACE_HAS_TSS_EMULATION */
    }
  return 0;
}
Example #8
0
Entity* EntityManager::createEntity(WorldPacket& packet)
{
	Entity* entity = createEntity();
	if (!entity)
		return 0;
	
	PropertySetComp* propSet = entity->getComponent<PropertySetComp>(ComponentBase::PropertySet);
	UnitInterfComp* unitInterf = entity->getComponent<UnitInterfComp>(ComponentBase::UnitInterf);

	// 设置基本属性
	propSet->initialize(PLAYER_END);
	propSet->setUintValue(OBJECT_FIELD_GUID, m_hiCharGuid++);
	propSet->setUintValue(OBJECT_FIELD_GUID + 1, HIGHGUID_PLAYER);
	propSet->setUintValue(OBJECT_FIELD_TYPE, Entity::Type_Object | Entity::Type_Unit | Entity::Type_Player);

	packet >> entity->m_entityName;

	// ***TODO*** 出生地需要根据种族和职业来查表
	unitInterf->map(0);
	unitInterf->posX(-8921.41f);
	unitInterf->posY(-118.494f);
	unitInterf->posZ(82.273f);
	unitInterf->orientation(0);

	propSet->setFloatValue(UNIT_FIELD_BOUNDINGRADIUS, 0.388999998569489f);
	propSet->setFloatValue(UNIT_FIELD_COMBATREACH, 1.5f);

	// 种族和职业
	u_char race, cls, gender;
	packet >> race >> cls >> gender;

	// ***TODO*** 模型ID, 暂时先固定一个, 人类男性
	propSet->setUintValue(UNIT_FIELD_DISPLAYID, 49);
	propSet->setUintValue(UNIT_FIELD_NATIVEDISPLAYID, 49);

	propSet->setUintValue(UNIT_FIELD_FACTIONTEMPLATE, 1);

	// ***TODO*** 需要查表
	u_char powerType = 1;
	u_int unitfield = 0x00110000;
	propSet->setUintValue(UNIT_FIELD_BYTES_0, (race | (cls << 8) | (gender << 16) | (powerType << 24)));
	propSet->setUintValue(UNIT_FIELD_BYTES_1, unitfield);
	propSet->setUintValue(UNIT_FIELD_BYTES_2, (0x28 << 8));		// players - 0x2800, 0x2801, units - 0x1001
	propSet->setUintValue(UNIT_FIELD_FLAGS, UNIT_FLAG_UNKNOWN1);
	propSet->setFloatValue(UNIT_MOD_CAST_SPEED, 1.0f);
	propSet->setFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);

	// 5项基本属性
	for (int i = STAT_STRENGTH; i < STATS_MAX; ++i)
	{
		propSet->setUintValue(UNIT_FIELD_STAT0 + i, 20);
		propSet->setFloatValue(UNIT_FIELD_POSSTAT0 + i, 0.0f);
		propSet->setFloatValue(UNIT_FIELD_NEGSTAT0 + i, 0.0f);
	}

	// ***TODO*** 生命值, 查表或配置
	propSet->setUintValue(UNIT_FIELD_BASE_HEALTH, 100);
	propSet->setUintValue(UNIT_FIELD_BASE_MANA, 0);
	propSet->setUintValue(UNIT_FIELD_MAXHEALTH, 100);
	propSet->setUintValue(UNIT_FIELD_MAXPOWER1, 0);
	propSet->setUintValue(UNIT_FIELD_MAXPOWER2, 1000);
	propSet->setUintValue(UNIT_FIELD_MAXPOWER3, 0);
	propSet->setUintValue(UNIT_FIELD_MAXPOWER4, 100);
	propSet->setUintValue(UNIT_FIELD_MAXPOWER5, 0);

	u_char skin,face,hairStyle,hairColor,facialHair,outfitId;
	packet >> skin >> face;
	packet >> hairStyle >> hairColor >> facialHair >> outfitId;

	propSet->setUintValue(PLAYER_FIELD_WATCHED_FACTION_INDEX, u_int(-1));
	propSet->setUintValue(PLAYER_BYTES, (skin | (face << 8) | (hairStyle << 16) | (hairColor << 24)));
	propSet->setUintValue(PLAYER_BYTES_2, (facialHair | (0x00 << 8) | (0x00 << 16) | (0x02 << 24)));
	propSet->setUintValue(PLAYER_BYTES_3, gender);

	// ***TODO*** 新建的角色都为1级, 改为可配置的
	propSet->setUintValue(UNIT_FIELD_LEVEL, 1);
	propSet->setUintValue(PLAYER_FIELD_MAX_LEVEL, 70);
	propSet->setUintValue(PLAYER_NEXT_LEVEL_XP, 100);

	propSet->setUintValue(UNIT_FIELD_RESISTANCES, 40);

	propSet->setUintValue(PLAYER_FIELD_MOD_HEALING_DONE_POS, 0);
	for (int i = 0; i < 7; ++i)
	{
		propSet->setUintValue(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG + i, 0);
		propSet->setUintValue(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + i, 0);
		propSet->setFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT + i, 1.0f);
	}

	propSet->setFloatValue(UNIT_FIELD_BASEATTACKTIME, 2000.0f);
	propSet->setFloatValue(UNIT_FIELD_OFFHANDATTACKTIME, 2000.0f);
	propSet->setFloatValue(UNIT_FIELD_RANGEDATTACKTIME, 2000.0f);

	propSet->setUintValue(PLAYER_CHARACTER_POINTS2, 2);

	return entity;
}
void cScreenGangs::check_events()
{
	if (g_InterfaceEvents.GetNumEvents() == 0) return;	// no events means we can go home
	if (g_InterfaceEvents.CheckButton(back_id))			// if it's the back button, pop the window off the stack and we're done
	{
		g_InitWin = true;
		g_WinManager.Pop();
		return;
	}
	if (g_InterfaceEvents.CheckButton(ganghire_id))
	{
		hire_recruitable();
		return;
	}
	if (g_InterfaceEvents.CheckButton(weaponup_id))
	{
		int cost = 0;
		int *wlev = g_Gangs.GetWeaponLevel();
		cost = tariff.goon_weapon_upgrade(*wlev);
		if (g_Gold.item_cost(cost) == true)
		{
			*wlev += 1;
			g_InitWin = true;
		}
		wlev = 0;
		return;
	}

	int buynets = 0;
	if (g_InterfaceEvents.CheckButton(netbuy_id))	buynets = 1;
	if (g_InterfaceEvents.CheckButton(netbuy10_id))	buynets = 10;
	if (g_InterfaceEvents.CheckButton(netbuy20_id))	buynets = 20;
	if (buynets > 0)
	{
		int cost = 0;
		int amount = buynets;
		int *nets = g_Gangs.GetNets();
		if (((*nets) + buynets) > 60) amount = 60 - (*nets);
		cost = tariff.nets_price(amount);
		if (g_Gold.item_cost(cost) == true)
		{
			*nets += amount;
			if (IsCheckboxOn(netautobuy_id)) g_Gangs.KeepNetStocked(*nets);
			g_InitWin = true;
		}
		nets = 0;
		buynets = 0;
		return;
	}

	int buypots = 0;
	if (g_InterfaceEvents.CheckButton(healbuy_id))		buypots = 1;
	if (g_InterfaceEvents.CheckButton(healbuy10_id))	buypots = 10;
	if (g_InterfaceEvents.CheckButton(healbuy20_id))	buypots = 20;
	if (buypots > 0)
	{
		int cost = 0;
		int amount = buypots;
		int *potions = g_Gangs.GetHealingPotions();
		if (((*potions) + buypots) > 200)	amount = 200 - (*potions);
		cost = tariff.healing_price(amount);
		if (g_Gold.item_cost(cost) == true)
		{
			*potions += amount;
			if (IsCheckboxOn(healautobuy_id)) g_Gangs.KeepHealStocked(*potions);
			g_InitWin = true;
		}
		potions = 0;
		buypots = 0;
		return;
	}
	if (g_InterfaceEvents.CheckCheckbox(netautobuy_id))
	{
		int *nets = g_Gangs.GetNets();
		g_Gangs.KeepNetStocked(IsCheckboxOn(netautobuy_id) ? *nets : 0);
	}
	if (g_InterfaceEvents.CheckCheckbox(healautobuy_id))
	{
		int *potions = g_Gangs.GetHealingPotions();
		g_Gangs.KeepHealStocked(IsCheckboxOn(healautobuy_id) ? *potions : 0);
	}
	if (g_InterfaceEvents.CheckButton(gangfire_id))
	{
		selection = GetLastSelectedItemFromList(ganglist_id);
		if (selection != -1)
		{
			g_Gangs.FireGang(selection);
			g_InitWin = true;
		}
		return;
	}
	if (g_InterfaceEvents.CheckListbox(recruitlist_id))
	{
		string ClickedHeader = HeaderClicked(recruitlist_id);
		if (ClickedHeader != "")
		{
			g_LogFile.ss() << "User clicked \"" << ClickedHeader << "\" column header on Recruit listbox" << endl; g_LogFile.ssend();
			return;
		}

		g_LogFile.ss() << "selected recruitable gang changed" << endl; g_LogFile.ssend();
		sel_recruit = GetLastSelectedItemFromList(recruitlist_id);

		if (ListDoubleClicked(recruitlist_id))
		{
			g_LogFile.ss() << "User double-clicked recruitable gang! Hiring if possible." << endl; g_LogFile.ssend();
			hire_recruitable();
			return;
		}
		//		g_InitWin = true;
	}

	// this is what gets called it you change the selected gang
	if (g_InterfaceEvents.CheckListbox(ganglist_id))
	{
		string ClickedHeader = HeaderClicked(ganglist_id);
		if (ClickedHeader != "")
		{
			g_LogFile.ss() << "User clicked \"" << ClickedHeader << "\" column header on Gangs listbox" << endl; g_LogFile.ssend();
			return;
		}

		g_LogFile.write("selected gang changed");
		selection = GetLastSelectedItemFromList(ganglist_id);
		if (selection != -1)
		{
			sGang* gang = g_Gangs.GetGang(selection);
			ss.str(""); ss << "Name: " << gang->m_Name << "\n" << "Number: " << gang->m_Num << "\n" << "Combat: " << gang->m_Skills[SKILL_COMBAT] << "%\n" << "Magic: " << gang->m_Skills[SKILL_MAGIC] << "%\n" << "Intelligence: " << gang->m_Stats[STAT_INTELLIGENCE] << "%\n";
			EditTextItem(ss.str(), gangdesc_id);
			SetSelectedItemInList(missionlist_id, gang->m_MissionID, false);
			set_mission_desc(gang->m_MissionID);		// set the long description for the mission
		}
	}
	if (g_InterfaceEvents.CheckListbox(missionlist_id))
	{
		// get the index into the missions list
		int mission_id = GetLastSelectedItemFromList(missionlist_id);
		g_LogFile.ss() << "selchange: mid = " << mission_id << endl; g_LogFile.ssend();
		set_mission_desc(mission_id);		// set the textfield with the long description and price for this mission
		g_LogFile.ss() << "selection change: rebuilding gang list box" << endl; g_LogFile.ssend();
		for (int selection = multi_first(); selection != -1; selection = multi_next())
		{
			sGang* gang = g_Gangs.GetGang(selection);
			/*
			*				make sure we found the gang - pretty catastrophic
			*				if not, so log it if we do
			*/
			if (gang == 0)
			{
				g_LogFile.ss() << "Error: No gang for index " << selection; g_LogFile.ssend();
				continue;
			}
			/*
			*				if the mission id is -1, nothing else to do
			*				(moving this to before the recruitment check
			*				since -1 most likely means nothing selected in
			*				the missions list)
			*/
			if (mission_id == -1) { continue; }
			/*
			*				if the gang is already doing <whatever>
			*				then let them get on with it
			*/
			if (gang->m_MissionID == u_int(mission_id)) { continue; }
			/*
			*				if they were recruiting, turn off the
			*				auto-recruit flag
			*/
			if (gang->m_MissionID == MISS_RECRUIT && gang->m_AutoRecruit)
			{
				gang->m_AutoRecruit = false;
				gang->m_LastMissID = -1;
			}
			gang->m_MissionID = mission_id;
			/*
			*				format the display line
			*/
			g_InitWin = true;
		}

		int cost = 0;
		if (g_Gangs.GetNumGangs() > 0)
		{
			for (int i = 0; i < g_Gangs.GetNumGangs(); i++)
			{
				sGang* g = g_Gangs.GetGang(i);
				cost += tariff.goon_mission_cost(g->m_MissionID);
			}
		}
		ss.str(""); ss << "Weekly Cost: " << cost;
		EditTextItem(ss.str(), totalcost_id);
		if (gold_id >= 0)
		{
			ss.str(""); ss << "Gold: " << g_Gold.ival();
			EditTextItem(ss.str(), gold_id);
		}

	}

	if (g_InterfaceEvents.CheckCheckbox(controlcatacombs_id))
	{
		g_Gangs.Control_Gangs(IsCheckboxOn(controlcatacombs_id));
	}
	bool dosliders = false;
	if (g_InterfaceEvents.CheckSlider(girlspercslider_id))
	{
		int s1 = SliderValue(girlspercslider_id);
		int s2 = SliderValue(itemspercslider_id);
		if (s2 < s1)
		{
			s2 = s1;
			SliderRange(itemspercslider_id, 0, 100, s2, 1);
		}
		dosliders = true;
	}
	if (g_InterfaceEvents.CheckSlider(itemspercslider_id))
	{
		int s1 = SliderValue(itemspercslider_id);
		int s2 = SliderValue(girlspercslider_id);
		if (s1 < s2)
		{
			s2 = s1;
			SliderRange(girlspercslider_id, 0, 100, s2, 1);
		}
		dosliders = true;
	}
	if (dosliders)
	{
		int s1 = SliderValue(girlspercslider_id);
		int s2 = SliderValue(itemspercslider_id);
		g_Gangs.Gang_Gets_Girls(s1);
		g_Gangs.Gang_Gets_Items(s2 - s1);
		g_Gangs.Gang_Gets_Beast(100 - s2);
		ss.str("");	ss << "Girls : " << g_Gangs.Gang_Gets_Girls() << "%";	EditTextItem(ss.str(), ganggetsgirls_id);
		ss.str("");	ss << "Items : " << g_Gangs.Gang_Gets_Items() << "%";	EditTextItem(ss.str(), ganggetsitems_id);
		ss.str("");	ss << "Beasts : " << g_Gangs.Gang_Gets_Beast() << "%";	EditTextItem(ss.str(), ganggetsbeast_id);
		return;
	}
}
Example #10
0
Spectrum IGIIntegrator::Li(const Scene *scene,
		const RayDifferential &ray, const Sample *sample,
		   float *alpha) const {
	Spectrum L(0.);
	Intersection isect;
	if (scene->Intersect(ray, &isect)) {
		if (alpha) *alpha = 1.;
		Vector wo = -ray.d;
		// Compute emitted light if ray hit an area light source
		L += isect.Le(wo);
		// Evaluate BSDF at hit point
		BSDF *bsdf = isect.GetBSDF(ray);
		const Point &p = bsdf->dgShading.p;
		const Normal &n = bsdf->dgShading.nn;
		L += UniformSampleAllLights(scene, p, n,
					    wo, bsdf, sample,
					    lightSampleOffset, bsdfSampleOffset,
					    bsdfComponentOffset);
		// Compute indirect illumination with virtual lights
		u_int lSet = min(u_int(sample->oneD[vlSetOffset][0] * nLightSets),
		                 nLightSets-1);
		for (u_int i = 0; i < virtualLights[lSet].size(); ++i) {
			const VirtualLight &vl = virtualLights[lSet][i];
			// Add contribution from _VirtualLight_ _vl_
			// Ignore light if it's too close to current point
			float d2 = DistanceSquared(p, vl.p);
			//if (d2 < .8 * minDist2) continue;
			float distScale = SmoothStep(.8 * minDist2, 1.2 * minDist2, d2);
			// Compute virtual light's tentative contribution _Llight_
			Vector wi = Normalize(vl.p - p);
			Spectrum f = distScale * bsdf->f(wo, wi);
			if (f.Black()) continue;
			float G = AbsDot(wi, n) * AbsDot(wi, vl.n) / d2;
			Spectrum Llight = indirectScale * f * G * vl.Le /
				virtualLights[lSet].size();
			Llight *= scene->Transmittance(Ray(p, vl.p - p));
			// Possibly skip shadow ray with Russian roulette
			if (Llight.y() < rrThreshold) {
				float continueProbability = .1f;
				if (RandomFloat() > continueProbability)
					continue;
				Llight /= continueProbability;
			}
			static StatsCounter vlsr("IGI Integrator", "Shadow Rays to Virtual Lights"); //NOBOOK
			++vlsr; //NOBOOK
			if (!scene->IntersectP(Ray(p, vl.p - p, RAY_EPSILON,
					1.f - RAY_EPSILON)))
				L += Llight;
		}
		// Trace rays for specular reflection and refraction
		if (specularDepth++ < maxSpecularDepth) {
			Vector wi;
			// Trace rays for specular reflection and refraction
			Spectrum f = bsdf->Sample_f(wo, &wi,
						BxDFType(BSDF_REFLECTION | BSDF_SPECULAR));
			if (!f.Black()) {
				// Compute ray differential _rd_ for specular reflection
				RayDifferential rd(p, wi);
				rd.hasDifferentials = true;
				rd.rx.o = p + isect.dg.dpdx;
				rd.ry.o = p + isect.dg.dpdy;
				// Compute differential reflected directions
				Normal dndx = bsdf->dgShading.dndu * bsdf->dgShading.dudx +
					bsdf->dgShading.dndv * bsdf->dgShading.dvdx;
				Normal dndy = bsdf->dgShading.dndu * bsdf->dgShading.dudy +
					bsdf->dgShading.dndv * bsdf->dgShading.dvdy;
				Vector dwodx = -ray.rx.d - wo, dwody = -ray.ry.d - wo;
				float dDNdx = Dot(dwodx, n) + Dot(wo, dndx);
				float dDNdy = Dot(dwody, n) + Dot(wo, dndy);
				rd.rx.d = wi -
					dwodx + 2 * Vector(Dot(wo, n) * dndx +
						 dDNdx * n);
				rd.ry.d = wi -
					dwody + 2 * Vector(Dot(wo, n) * dndy +
						 dDNdy * n);
				L += scene->Li(rd, sample) * f * AbsDot(wi, n);
			}
			f = bsdf->Sample_f(wo, &wi,
					   BxDFType(BSDF_TRANSMISSION | BSDF_SPECULAR));
			if (!f.Black()) {
				// Compute ray differential _rd_ for specular transmission
				RayDifferential rd(p, wi);
				rd.hasDifferentials = true;
				rd.rx.o = p + isect.dg.dpdx;
				rd.ry.o = p + isect.dg.dpdy;

				float eta = bsdf->eta;
				Vector w = -wo;
				if (Dot(wo, n) < 0) eta = 1.f / eta;

				Normal dndx = bsdf->dgShading.dndu * bsdf->dgShading.dudx + bsdf->dgShading.dndv * bsdf->dgShading.dvdx;
				Normal dndy = bsdf->dgShading.dndu * bsdf->dgShading.dudy + bsdf->dgShading.dndv * bsdf->dgShading.dvdy;

				Vector dwodx = -ray.rx.d - wo, dwody = -ray.ry.d - wo;
				float dDNdx = Dot(dwodx, n) + Dot(wo, dndx);
				float dDNdy = Dot(dwody, n) + Dot(wo, dndy);

				float mu = eta * Dot(w, n) - Dot(wi, n);
				float dmudx = (eta - (eta*eta*Dot(w,n))/Dot(wi, n)) * dDNdx;
				float dmudy = (eta - (eta*eta*Dot(w,n))/Dot(wi, n)) * dDNdy;

				rd.rx.d = wi + eta * dwodx - Vector(mu * dndx + dmudx * n);
				rd.ry.d = wi + eta * dwody - Vector(mu * dndy + dmudy * n);
				L += scene->Li(rd, sample) * f * AbsDot(wi, n);
			}
		}
		--specularDepth;
	}
	else {
		// Handle ray with no intersection
		if (alpha) *alpha = 0.;
		for (u_int i = 0; i < scene->lights.size(); ++i)
			L += scene->lights[i]->Le(ray);
		if (alpha && !L.Black()) *alpha = 1.;
		return L;
	}
	return L;
}
Example #11
0
int 
main (int argc, char *argv[])
{
  setprogname (argv[0]);
  if (argc != 2)
    usage ();
  str s = file2str (argv[1]);

  if (!s)
    fatal << "cannot open file: " << argv[1];

  u_int niter = 10;
  u_int osz = 0;
  u_int32_t tot = 0;
  mstr *outbuf = NULL;

  u_int slen = s.len ();
  u_int out_avail = u_int ((slen / 1000) * 1001) + 16;

  for (u_int i = 0; i < niter; i++) {

    if (outbuf)
      delete outbuf;
    outbuf = New mstr (out_avail);

    warn << "+ starting compression\n";
    startt ();
    osz = go (s, outbuf, out_avail); 
    u_int t = stopt ();
    warn << "- ending compression (time=" << t << ")\n";
    tot += t;
    
  }

  outbuf->setlen (osz);

  //
  // write out the buffer once, just to make sure we were getting reasonable
  // data output (and not some bullshit)
  //
  u_int i = 0;
  do {
    int rc = write (1, outbuf->cstr () + i, min<u_int> (2048, osz - i));
    if (rc < 0)
      panic ("write error!\n");
    i += rc;
  } while (i < osz);

  u_int64_t bw = osz / 1024;
  bw *= 1000000;
  bw /= tot;
  bw *= niter;


  warn ("Input: %d bytes\n"
	"Output: %d bytes\n"
	"Iterations: %d\n"
	"Usecs Total: %d\n"
	"Compression ratio * 1000: %d\n"
	"Throughput (kB/sec): %d\n",
	slen, osz, niter, tot, osz * 1000 / slen, u_int32_t (bw));

}
Example #12
0
// メインプログラム
int main() {


	// アプリウインドウの準備
	AppEnv env(WIDTH, HEIGHT);

	//ランダムパターンが同じにならないように
	random.setSeed(u_int(time(nullptr)));

	//Object型のobjを作成
	enum {
		//enum で obj の最大値を設定
		//配列で作る場合:数を変えたいならこの数字を変えるだけ
		OBJ_MAX = 5
	};
	Object obj[OBJ_MAX];

	//初期化
	for (int i = 0; i < OBJ_MAX; ++i){
		obj[i] = {
			Vec2f(0, 0), Vec2f(50, 50),
			Vec2f(random.fromFirstToLast(-5, 5), random.fromFirstToLast(-5, 5)),
			random.fromZeroToOne(), random.fromZeroToOne(), random.fromZeroToOne()
		};
	}


	while (env.isOpen()){


		for (int i = 0; i < OBJ_MAX; ++i){
			//objに速度を加える
			//Vec2f + Vec2f が可能( (pos.x + speed.x), (pos.y + speed.y) )
			obj[i].pos += obj[i].speed;

			//壁とobjの当たり判定(当たったら反射)
			if (obj[i].pos.x() < -WIDTH / 2){						//左の壁
				obj[i].speed.x() = random.fromFirstToLast(2, 5);
				colorChange(obj[i].red, obj[i].green, obj[i].blue);
			}
			if (obj[i].pos.x() + obj[i].size.x() > WIDTH / 2){		//右の壁
				obj[i].speed.x() = random.fromFirstToLast(-5, -2);
				colorChange(obj[i].red, obj[i].green, obj[i].blue);
			}
			if (obj[i].pos.y() < -HEIGHT / 2){						//下の壁
				obj[i].speed.y() = random.fromFirstToLast(2, 5);
				colorChange(obj[i].red, obj[i].green, obj[i].blue);
			}
			if (obj[i].pos.y() + obj[i].size.y() > HEIGHT / 2){		//上の壁
				obj[i].speed.y() = random.fromFirstToLast(-5, -2);
				colorChange(obj[i].red, obj[i].green, obj[i].blue);
			}

		}


		// 描画準備
		env.setupDraw();



		//描画
		for (int i = 0; i < OBJ_MAX; ++i){
			drawFillBox(obj[i].pos.x(), obj[i].pos.y(),
				obj[i].size.x(), obj[i].size.y(), Color(obj[i].red, obj[i].green, obj[i].blue));
		}


		// 画面更新
		env.update();

	}

}
void cScreenGangs::check_events()
{
	// no events means we can go home
	if(g_InterfaceEvents.GetNumEvents() == 0)
		return;

	// if it's the back button, pop the window off the stack and we're done
	if(g_InterfaceEvents.CheckButton(back_id))
	{
		g_InitWin = true;
		g_WinManager.Pop();
		return;
	}
	if(g_InterfaceEvents.CheckButton(ganghire_id))
	{
		hire_recruitable();
		return;
	}
	if(g_InterfaceEvents.CheckButton(weaponup_id))
	{
		int cost = 0;
		int *wlev = g_Gangs.GetWeaponLevel();
		cost = tariff.goon_weapon_upgrade(*wlev);
		if(g_Gold.item_cost(cost) == true)
		{
			*wlev += 1;
			g_InitWin = true;
		}
		wlev = nullptr;
		return;
	}
	if(g_InterfaceEvents.CheckButton(netbuy_id))
	{
		int cost = 0;
		int amount = 20;
		int *nets = g_Gangs.GetNets();
		if(((*nets) + 20) > 60)
			amount = 60 - (*nets);
		cost = tariff.nets_price(amount);
		if(g_Gold.item_cost(cost) == true)
		{
			*nets += amount;
			if(IsCheckboxOn(netautobuy_id))
				g_Gangs.KeepNetStocked(*nets);
			g_InitWin = true;
		}
		nets = nullptr;
		return;
	}
	if(g_InterfaceEvents.CheckButton(healbuy_id))
	{
		int cost = 0;
		int amount = 20;
		int *potions = g_Gangs.GetHealingPotions();
		if(((*potions) + 20) > 200)
			amount = 200 - (*potions);
		cost = tariff.healing_price(amount);
		if(g_Gold.item_cost(cost) == true)
		{
			*potions += amount;
			g_InitWin = true;
		}
		potions = nullptr;
		return;
	}
	if(g_InterfaceEvents.CheckCheckbox(netautobuy_id))
	{
		int *nets = g_Gangs.GetNets();
		if(IsCheckboxOn(netautobuy_id))
			g_Gangs.KeepNetStocked(*nets);
		else
			g_Gangs.KeepNetStocked(0);
	}
	if(g_InterfaceEvents.CheckCheckbox(healautobuy_id))
	{
		int *potions = g_Gangs.GetHealingPotions();
		if(IsCheckboxOn(healautobuy_id))
			g_Gangs.KeepHealStocked(*potions);
		else
			g_Gangs.KeepHealStocked(0);
	}
	if(g_InterfaceEvents.CheckButton(gangfire_id))
	{
		selection = GetLastSelectedItemFromList(ganglist_id);
		if(selection != -1)
		{
			g_Gangs.FireGang(selection);
			g_InitWin = true;
		}
		return;
	}
	if(g_InterfaceEvents.CheckListbox(recruitlist_id))
	{
	    std::string ClickedHeader = HeaderClicked(recruitlist_id);
		if(ClickedHeader != "")
		{
			g_LogFile.ss() << "User clicked \"" << ClickedHeader << "\" column header on Recruit listbox" << std::endl;
            g_LogFile.ssend();
			return;
		}

		g_LogFile.ss() << "selected recruitable gang changed" << std::endl;
		g_LogFile.ssend();
		sel_recruit = GetLastSelectedItemFromList(recruitlist_id);

		if(ListDoubleClicked(recruitlist_id))
		{
			g_LogFile.ss() << "User double-clicked recruitable gang! Hiring if possible." << std::endl;
			g_LogFile.ssend();
			hire_recruitable();
			return;
		}
//		g_InitWin = true;
	}
/*
 *		this is what gets called it you change the selected gang
 */
	if(g_InterfaceEvents.CheckListbox(ganglist_id))
	{
	    std::string ClickedHeader = HeaderClicked(ganglist_id);
		if(ClickedHeader != "")
		{
			g_LogFile.ss() << "User clicked \"" << ClickedHeader << "\" column header on Gangs listbox" << std::endl;
			g_LogFile.ssend();
			return;
		}

		g_LogFile.ss() << "selected gang changed" << std::endl;
		g_LogFile.ssend();
		selection = GetLastSelectedItemFromList(ganglist_id);
		if(selection != -1)
		{
			sGang* gang = g_Gangs.GetGang(selection);

		    std::string text = "Name: ";
			text += gang->m_Name;
			text += "\n";
			text += "Number: ";
			text += toString((int)gang->m_Num);
			text += "\n";
			text += "Combat: ";
			text += toString(gang->m_Skills[SKILL_COMBAT]);
			text += "%\n";
			text += "Magic: ";
			text += toString(gang->m_Skills[SKILL_MAGIC]);
			text += "%\n";
			text += "Intelligence: ";
			text += toString(gang->m_Stats[STAT_INTELLIGENCE]);
			text += "%\n";
			EditTextItem(text, gangdesc_id);

			SetSelectedItemInList(missionlist_id, gang->m_MissionID, false);
/*
 *				set the long description for the mission
 */
			set_mission_desc(gang->m_MissionID);
		}
	}
	if(g_InterfaceEvents.CheckListbox(missionlist_id))
	{
/*
 *			get the index into the missions list
 */
		int mission_id =  GetLastSelectedItemFromList(missionlist_id);
		g_LogFile.ss() << "selchange: mid = " << mission_id << std::endl;
		g_LogFile.ssend();
/*
 *			set the textfield with the long description and price
 *			for this mission
 */
		set_mission_desc(mission_id);

		g_LogFile.ss() << "selection change: rebuilding gang list box" << std::endl;
		g_LogFile.ssend();

		for(int	selection = multi_first();
			selection != -1;
			selection = multi_next()
		) {
			sGang* gang = g_Gangs.GetGang(selection);
/*
 *				make sure we found the gang - pretty catastrophic
 *				if not, so log it if we do
 */
			if(gang == nullptr) {
				g_LogFile.ss()	<< "Error: No gang for index "
				  		<< selection
				;
				g_LogFile.ssend();
				continue;
			}
/*
 *				if the mission id is -1, nothing else to do
 *				(moving this to before the recruitment check
 *				since -1 most likely means nothing selected in
 *				the missions list)
 */
			if(mission_id == -1) {
				continue;
			}
/*
 *				if the gang is already doing <whatever>
 *				then let them get on with it
 */
			if(gang->m_MissionID == u_int(mission_id)) {
				continue;
			}
/*
 *				if they were recruiting, turn off the
 *				auto-recruit flag
 */
			if(gang->m_MissionID == MISS_RECRUIT && gang->m_AutoRecruit)
			{
				gang->m_AutoRecruit = false;
				gang->m_LastMissID = -1;
			}
			gang->m_MissionID = mission_id;
/*
 *				format the display line
 */
		    std::string Data[6];
			ss.str("");
			ss << gang->m_Name;
			Data[0] = ss.str();
			ss.str("");
			ss << gang->m_Num;
			Data[1] = ss.str();
			ss.str("");
			ss << short_mission_desc(mission_id);
			Data[2] = ss.str();
			ss.str("");
			ss << (int)gang->m_Skills[SKILL_COMBAT] << "%";
			Data[3] = ss.str();
			ss.str("");
			ss << (int)gang->m_Skills[SKILL_MAGIC] << "%";
			Data[4] = ss.str();
			ss.str("");
			ss << (int)gang->m_Stats[STAT_INTELLIGENCE] << "%";
			Data[5] = ss.str();

//		    g_LogFile.ss() << "Gang:\t" << Data[0] << "\t" << Data[1] << "\t" << Data[2]
//			    << "\t" << Data[3] << "\t" << Data[4] << "\t" << Data[5] << "\t" << Data[6] << std::endl
//              << "        index " << mission_id << ": " << ss.str() << std::endl;
//          g_LogFile.ssend();
/*
 *				and add it to the list
 */
			SetSelectedItemText( ganglist_id, selection, Data, 6 );
		}

	    std::string message = "";
		if(g_Gangs.GetNumGangs() > 0)
		{
			int cost = 0;
			for(int i=0; i < g_Gangs.GetNumGangs(); i++)
			{
				sGang* g = g_Gangs.GetGang(i);
				cost += tariff.goon_mission_cost(
					g->m_MissionID
				);
			}
			message = "Daily Cost: ";
			message += toString(cost);
		}
		else
			message = "Daily Cost: 0";

		EditTextItem(message, totalcost_id);
	}

}
Example #14
0
Spectrum IGIIntegrator::Li(const Scene *scene, const Renderer *renderer,
        const RayDifferential &ray, const Intersection &isect,
        const Sample *sample, MemoryArena &arena) const {
    Spectrum L(0.);
    Vector wo = -ray.d;
    // Compute emitted light if ray hit an area light source
    L += isect.Le(wo);

    // Evaluate BSDF at hit point
    BSDF *bsdf = isect.GetBSDF(ray, arena);
    const Point &p = bsdf->dgShading.p;
    const Normal &n = bsdf->dgShading.nn;
    L += UniformSampleAllLights(scene, renderer, arena, p, n,
                    wo, isect.rayEpsilon, bsdf, sample,
                    lightSampleOffsets, bsdfSampleOffsets);
    // Compute indirect illumination with virtual lights
    u_int lSet = min(u_int(sample->oneD[vlSetOffset][0] * nLightSets),
                     nLightSets-1);
    for (u_int i = 0; i < virtualLights[lSet].size(); ++i) {
        const VirtualLight &vl = virtualLights[lSet][i];
        // Compute virtual light's tentative contribution _Llight_
        float d2 = DistanceSquared(p, vl.p);
        Vector wi = Normalize(vl.p - p);
        float G = AbsDot(wi, n) * AbsDot(wi, vl.n) / d2;
        Spectrum f = bsdf->f(wo, wi);
        G = min(G, gLimit);
        if (G == 0.f || f.IsBlack()) continue;
        Spectrum Llight = f * G * vl.pathContrib / virtualLights[lSet].size();
        RayDifferential connectRay(p, wi, ray, isect.rayEpsilon,
            sqrtf(d2) * (1.f - vl.rayEpsilon));
        Llight *= renderer->Transmittance(scene, connectRay, NULL, arena,
                                          sample->rng);

        // Possibly skip virtual light shadow ray with Russian roulette
        if (Llight.y() < rrThreshold) {
            float continueProbability = .1f;
            if (sample->rng->RandomFloat() > continueProbability)
                continue;
            Llight /= continueProbability;
        }

        // Add contribution from _VirtualLight_ _vl_
        if (!scene->IntersectP(connectRay))
            L += Llight;
    }
    if (ray.depth < maxSpecularDepth) {
        // Do bias compensation for bounding geoemtry term
        int nSamples = (ray.depth == 0) ? nGatherSamples : 1;
        for (int i = 0; i < nSamples; ++i) {
            Vector wi;
            float pdf;
            BSDFSample bsdfSample = (ray.depth == 0) ?
                                    BSDFSample(sample, gatherSampleOffset, i) :
                                    BSDFSample(*sample->rng);
            Spectrum f = bsdf->Sample_f(wo, &wi, bsdfSample,
                                        &pdf, BxDFType(BSDF_ALL & ~BSDF_SPECULAR));
            if (!f.IsBlack() && pdf > 0.f) {
                // Trace ray for bias compensation gather sample
                float maxDist = sqrtf(AbsDot(wi, n) / gLimit);
                RayDifferential gatherRay(p, wi, ray, isect.rayEpsilon, maxDist);
                Intersection gatherIsect;
                Spectrum Li = renderer->Li(scene, gatherRay, sample, arena, &gatherIsect);
                if (Li.IsBlack()) continue;
                float Ggather = AbsDot(wi, n) * AbsDot(-wi, gatherIsect.dg.nn) /
                    DistanceSquared(p, gatherIsect.dg.p);
                if (Ggather - gLimit > 0.f && !isinf(Ggather))
                    L += f * Li * ((Ggather - gLimit) / Ggather * AbsDot(wi, n) /
                        (nSamples * pdf));
            }
        }
    }
    if (ray.depth + 1 < maxSpecularDepth) {
        Vector wi;
        // Trace rays for specular reflection and refraction
        L += SpecularReflect(ray, bsdf, *sample->rng, isect, renderer,
                             scene, sample, arena);
        L += SpecularTransmit(ray, bsdf, *sample->rng, isect, renderer,
                              scene, sample, arena);
    }
    return L;
}