Пример #1
0
Файл: buf.c Проект: taysom/tau
Buf_s *buf_new (Inode_s *inode, Blknum_t blknum)
{
	Buf_s		*b;

	b = victim();
	b->inode = inode;
	b->blknum = blknum;
	if (blknum) add(b);
	return b;
}
Пример #2
0
Файл: cache.c Проект: taysom/tau
static inline buf_s *alloc_buf (tree_s *tree, u64 blkno)
{
	buf_s	*buf;

	buf = victim();
	buf->b_tree = tree;
	buf->b_blkno = blkno;
	add(buf);

	return buf;
}
Пример #3
0
bool spell_corrosion(int sn, int level, CHAR_DATA * ch, void * vo, int target)
{
    // Check for dodging
    CHAR_DATA * victim(static_cast<CHAR_DATA*>(vo));
    act("You spray a slurry of corroding minerals at $N!", ch, NULL, victim, TO_CHAR);
    act("$n sprays a slurry of corroding minerals at you!", ch, NULL, victim, TO_VICT);
    act("$n sprays a slurry of corroding minerals at $N!", ch, NULL, victim, TO_NOTVICT);
    if (check_dodge(ch, victim, NULL))
        return true;

    // Failed to dodge; build a list of candidate objects
    std::vector<OBJ_DATA*> wornObjects;
    for (OBJ_DATA * obj(victim->carrying); obj != NULL; obj = obj->next_content)
    {
        // Candidate objects must be worn, metal, and not already corroding
        if (obj->worn_on && !obj_is_affected(obj, sn) && material_table[obj->material].metal && !IS_SET(obj->extra_flags[0], ITEM_NODESTROY))
            wornObjects.push_back(obj);
    }

    if (wornObjects.empty())
    {
        act("The corrosive magics strike you, but can find no purchase on your equipment!", victim, NULL, NULL, TO_CHAR);
        act("The corrosive magics strike $n, but can find no purchase on $s equipment!", victim, NULL, NULL, TO_ROOM);
        return true;
    }

    // Prepare the effect
    AFFECT_DATA af = {0};
    af.where    = TO_OBJECT;
    af.type     = sn;
    af.level    = level;
    af.duration = (level / 8);

    // Hit some of the objects
    unsigned int count(number_range(2, 5));
    for (unsigned int i(0); i < count && !wornObjects.empty(); ++i)
    {
        // Apply the effect
        size_t index(number_range(0, wornObjects.empty() - 1));
        act("$p is struck by the corrosive magics!", ch, wornObjects[index], NULL, TO_ALL);
        affect_to_obj(wornObjects[index], &af);

        // Remove this object from the candidate set
        wornObjects[index] = wornObjects[wornObjects.size() - 1];
        wornObjects.pop_back();
    }
    
    return true;
}
Пример #4
0
Файл: blk.c Проект: taysom/tau
buf_s *bnew (dev_s *dev, u64 blkno)
{
	buf_s	*buf;

	if (!blkno) return NULL;

	buf = lookup(dev, blkno);
	if (!buf) {
		buf = victim();
		buf->b_dev = dev;
		buf->b_blkno = blkno;
		add(buf);
	}
	memset(buf->b_data, 0, BLK_SIZE);
	buf->b_dirty = FALSE;
	return buf;
}
Пример #5
0
Bool16 StringParser::Test()
{
    static char* string1 = "RTSP 200 OK\r\nContent-Type: MeowMix\r\n\t   \n3450";
    
    StrPtrLen theString(string1, strlen(string1));
    
    StringParser victim(&theString);
    
    StrPtrLen rtsp;
    SInt32 theInt = victim.ConsumeInteger();
    if (theInt != 0)
        return false;
    victim.ConsumeWord(&rtsp);
    if ((rtsp.len != 4) && (strncmp(rtsp.Ptr, "RTSP", 4) != 0))
        return false;
        
    victim.ConsumeWhiteSpace();
    theInt = victim.ConsumeInteger();
    if (theInt != 200)
        return false;
        
    return true;
}
Пример #6
0
Файл: blk.c Проект: taysom/tau
buf_s *bget (dev_s *dev, u64 blkno)
{
	buf_s	*buf;
	int	rc;

	if (!blkno) return NULL;

	buf = lookup(dev, blkno);
	if (buf) {
		return buf;
	}
	buf = victim();
	buf->b_dev = dev;
	buf->b_blkno = blkno;
	add(buf);

	rc = pread(dev->d_fd, buf->b_data, BLK_SIZE, blkno * BLK_SIZE);
	if (rc == -1) {
		eprintf("bget pread of %s at %lld failed:", dev->d_name, blkno);
		return NULL;
	}
	buf->b_dirty = FALSE;
	return buf;
}
Пример #7
0
/* message handling routine */
void p_handle(int b) {
  int i,k,len,tid,tag;
  jobinfo *j;
  jobinfo tj; 
  pvm_bufinfo(b,&len,&tag,&tid);

  switch (tag) {
    case TAG_HELLO:
      if (master) {
        wtid = realloc(wtid,sizeof(int) * ++nw);
        wtid[nw-1] = tid;
        for (i=1;i<nw;i++) {
          pvm_initsend(0);
          k = i << BASE_SHIFT;
          pvm_pkint(&k,1,1);
          pvm_pkint(&nw,1,1);
          pvm_pkint(wtid,nw,1);
          pvm_send(wtid[i],TAG_WORKERS);
          }
        }
      break;

    case TAG_WORKERS: 
      pvm_upkint(&nextjid,1,1);      
      nextjid <<= BASE_SHIFT;
      pvm_upkint(&nw,1,1);
      free(wtid);
      wtid = malloc(sizeof(int) * nw);
      pvm_upkint(wtid,nw,1);
      break;

    case TAG_KILL:
      die("Received TAG_KILL.  Too lazy to do anything useful.\n");

    case TAG_REQUEST:
      if (j = freejob()) {
        pvm_initsend(0);
        pkjobinfo_active(j);
        pvm_send(tid,TAG_JOB);
        add_stolen(tid,j->jid);
        free(j);
        }
      else if (!victim(tid)) {
        pvm_initsend(0);
        pvm_send(tid,TAG_NO_JOB);
        }
      break; 

    case TAG_DONE:
      upkjobinfo_done(&tj);
      if (cj && cj->jid == tj.pjid)
        slow_absorb(cj,&tj.s);
      else if (!tj.jid && master) {
        j = malloc(sizeof(jobinfo)); 
        *j = tj;
        add_jobarray(j);
        }
      else if ((i = find_jobarray(tj.pjid)) >= 0) { 
        slow_absorb(ja[i],&tj.s);
        if (ja[i]->status == JOB_DONE && !(!ja[i]->jid && master)) {
          send_done(ja[i]);
          free(ja[i]); 
          del_jobarray(i);
          }
        }
      else if (tj.tid = find_stolen(tj.pjid))  // if 0, job was cancelled
        send_done(&tj);
      break; 
    
    case TAG_CANCEL:
      pvm_upkint(&k,1,1); 
      if (cj && cj->jid == k) {
        cj->status = JOB_CANCELLED;
        if (p_head > 0) 
          cancel_children(cj);
        p_head = 1000;
        add_stolen(0,cj->jid);
        }
      else if ((i = find_jobarray(k)) >= 0) { 
        cancel_children(ja[i]);
        add_stolen(0,ja[i]->jid); 
        free(ja[i]);
        del_jobarray(i);
        }
      else if (tid = find_stolen(k)) 
        send_cancel(tid,k); 
      break;

    case TAG_STAT:
    default:
      die("Warning: ignoring invalid message\n");
    }
  }
void TestExceptions() {
    typedef local_counting_allocator<tbb::tbb_allocator<MyData2> > allocator_t;
    typedef tbb::concurrent_hash_map<MyKey,MyData2,MyHashCompare,allocator_t> ThrowingTable;
    enum methods {
        zero_method = 0,
        ctor_copy, op_assign, op_insert,
        all_methods
    };
    REMARK("testing exception-safety guarantees\n");
    ThrowingTable src;
    FillTable( src, 1000 );
    ASSERT( MyDataCount==1000, NULL );

    try {
        for(int t = 0; t < 2; t++) // exception type
        for(int m = zero_method+1; m < all_methods; m++)
        {
            allocator_t a;
            if(t) MyDataCountLimit = 101;
            else a.set_limits(101);
            ThrowingTable victim(a);
            MyDataCount = 0;

            try {
                switch(m) {
                case ctor_copy: {
                        ThrowingTable acopy(src, a);
                    } break;
                case op_assign: {
                        victim = src;
                    } break;
                case op_insert: {
                        FillTable( victim, 1000 );
                    } break;
                default:;
                }
                ASSERT(false, "should throw an exception");
            } catch(std::bad_alloc &e) {
                MyDataCountLimit = 0;
                size_t size = victim.size();
                switch(m) {
                case op_assign:
                    ASSERT( MyDataCount==100, "data leak?" );
                    ASSERT( size>=100, NULL );
                    CheckAllocator(victim, 100+t, t);
                case ctor_copy:
                    CheckTable(src, 1000);
                    break;
                case op_insert:
                    ASSERT( size==size_t(100-t), NULL );
                    ASSERT( MyDataCount==100-t, "data leak?" );
                    CheckTable(victim, 100-t);
                    CheckAllocator(victim, 100, t);
                    break;

                default:; // nothing to check here
                }
                REMARK("Exception %d: %s\t- ok ()\n", m, e.what());
            }
            catch ( ... ) {
                ASSERT ( __TBB_EXCEPTION_TYPE_INFO_BROKEN, "Unrecognized exception" );
            }
        }
    } catch(...) {
        ASSERT(false, "unexpected exception");
    }
    src.clear(); MyDataCount = 0;
}
void DefenderWeaponBehaviour::CheckBoost(ComponentWrapper cWeapon, WeaponInfo& wi)
{
    // Only check ammo client side
    if (!IsClient) {
        return;
    }

    // Only handle ammo check for the local player
    if (wi.Player != LocalPlayer) {
        return;
    }

    // Make sure the player isn't checking from the grave
    if (!wi.Player.Valid()) {
        return;
    }

    // 3D-pick middle of screen
    Rectangle viewport = m_Renderer->GetViewportSize();
    glm::vec2 centerScreen(viewport.Width / 2, viewport.Height / 2);
    // TODO: Some horizontal spread
    PickData pickData = m_Renderer->Pick(centerScreen);
    EntityWrapper victim(m_World, pickData.Entity);
    if (!victim.Valid()) {
        return;
    }

    // Don't let us somehow shoot ourselves in the foot
    if (victim == LocalPlayer) {
        return;
    }

    // Only care about players being hit
    if (!victim.HasComponent("Player")) {
        victim = victim.FirstParentWithComponent("Player");
    }
    if (!victim.Valid()) {
        return;
    }


    // If friendly fire, reduce damage to 0 (needed to make Boosts, Ammosharing work)
    if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {

        EntityWrapper friendlyBoostHudSpawner = wi.FirstPersonPlayerModel.FirstChildByName("FriendlyBoostAttachment");
        if (friendlyBoostHudSpawner.Valid()) {

            EntityWrapper assaultBoost = victim.FirstChildByName("BoostAssault");
            EntityWrapper defenderBoost = victim.FirstChildByName("BoostDefender");
            EntityWrapper sniperBoost = victim.FirstChildByName("BoostSniper");

            auto children = m_World->GetDirectChildren(friendlyBoostHudSpawner.ID);

            if (children.first == children.second) {
                if (friendlyBoostHudSpawner.HasComponent("Spawner")) {

                    EntityWrapper friendlyBoostHud = SpawnerSystem::Spawn(friendlyBoostHudSpawner, friendlyBoostHudSpawner);
                    if (friendlyBoostHud.Valid()) {
                        EntityWrapper assaultBoostEntity = friendlyBoostHud.FirstChildByName("AssaultBoost");
                        if (assaultBoostEntity.Valid()) {
                            EntityWrapper active = assaultBoostEntity.FirstChildByName("Active");
                            if (active.HasComponent("Text")) {
                                if (assaultBoost.Valid()) {
                                    (Field<bool>)active["Text"]["Visible"] = true;
                                } else {
                                    (Field<bool>)active["Text"]["Visible"] = false;
                                }
                            }
                        }

                        EntityWrapper defenderBoostEntity = friendlyBoostHud.FirstChildByName("DefenderBoost");
                        if (defenderBoostEntity.Valid()) {
                            EntityWrapper active = defenderBoostEntity.FirstChildByName("Active");
                            if (active.HasComponent("Text")) {
                                if (defenderBoost.Valid()) {
                                    (Field<bool>)active["Text"]["Visible"] = true;
                                } else {
                                    (Field<bool>)active["Text"]["Visible"] = false;
                                }
                            }
                        }

                        EntityWrapper sniperBoostEntity = friendlyBoostHud.FirstChildByName("SniperBoost");
                        if (sniperBoostEntity.Valid()) {
                            EntityWrapper active = sniperBoostEntity.FirstChildByName("Active");
                            if (active.HasComponent("Text")) {
                                if (sniperBoost.Valid()) {
                                    (Field<bool>)active["Text"]["Visible"] = true;
                                } else {
                                    (Field<bool>)active["Text"]["Visible"] = false;
                                }
                            }
                        }
                    }
                }
            } else {
                EntityWrapper friendlyBoostHud = friendlyBoostHudSpawner.FirstChildByName("FriendlyBoostHUD");
                if (friendlyBoostHud.Valid()) {
                    if (friendlyBoostHud.HasComponent("Lifetime")) {
                        (Field<double>)friendlyBoostHud["Lifetime"]["Lifetime"] = 0.5;
                    }



                    EntityWrapper assaultBoostEntity = friendlyBoostHud.FirstChildByName("AssaultBoost");
                    if (assaultBoostEntity.Valid()) {
                        EntityWrapper active = assaultBoostEntity.FirstChildByName("Active");
                        if (active.HasComponent("Text")) {
                            if (assaultBoost.Valid()) {
                                (Field<bool>)active["Text"]["Visible"] = true;
                            } else {
                                (Field<bool>)active["Text"]["Visible"] = false;
                            }
                        }
                    }

                    EntityWrapper defenderBoostEntity = friendlyBoostHud.FirstChildByName("DefenderBoost");
                    if (defenderBoostEntity.Valid()) {
                        EntityWrapper active = defenderBoostEntity.FirstChildByName("Active");
                        if (active.HasComponent("Text")) {
                            if (defenderBoost.Valid()) {
                                (Field<bool>)active["Text"]["Visible"] = true;
                            } else {
                                (Field<bool>)active["Text"]["Visible"] = false;
                            }
                        }
                    }

                    EntityWrapper sniperBoostEntity = friendlyBoostHud.FirstChildByName("SniperBoost");
                    if (sniperBoostEntity.Valid()) {
                        EntityWrapper active = sniperBoostEntity.FirstChildByName("Active");
                        if (active.HasComponent("Text")) {
                            if (sniperBoost.Valid()) {
                                (Field<bool>)active["Text"]["Visible"] = true;
                            } else {
                                (Field<bool>)active["Text"]["Visible"] = false;
                            }
                        }
                    }
                }
            }
        }
    }
}
void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, const std::vector<glm::vec2>& pattern)
{
    // Only deal damage client side
    if (!IsClient) {
        return;
    }

    // Only handle shooting for the local player
    if (wi.Player != LocalPlayer) {
        return;
    }

    // Make sure the player isn't shooting from the grave
    if (!wi.Player.Valid()) {
        return;
    }

    // Convert the spread angle to screen coordinates, taking FOV into account
    Rectangle res = m_Renderer->GetViewportSize();
    float spreadAngle = glm::radians((float)cWeapon["SpreadAngle"]);
    float nearClip = (double)m_CurrentCamera["Camera"]["NearClip"];
    float farClip = (double)m_CurrentCamera["Camera"]["FarClip"];
    float yFOV = glm::radians((double)m_CurrentCamera["Camera"]["FOV"]);
    //float yRefFOV = glm::radians(59.f);
    //float yRef = glm::tan(yRefFOV) * nearClip;
    //float yRatio = yRef / (glm::tan(yFOV) * nearClip);
    //float yMax = (yRatio / 2.f) * spreadAngle * (res.Height / 2.f);
    float yRefFOV = glm::radians(59.f);
    float yRef = glm::tan(yRefFOV) * nearClip;
    float yRatio = yRef / (glm::tan(yFOV) * nearClip);
    float yMax = yRatio * (glm::tan(spreadAngle) * (farClip - nearClip)) * glm::pi<float>(); // ????? Good enough????

    LOG_DEBUG("Ratio: %f", yRatio);
    LOG_DEBUG("fatClip: %f", farClip);
    LOG_DEBUG("yMax: %f", yMax);
    double pelletDamage = (double)cWeapon["BaseDamage"] / pattern.size();

    // Pick!
    std::unordered_map<EntityWrapper, double> damageSum;
    glm::vec2 screenCenter(res.Width / 2.f, res.Height / 2.f);
    for (auto& pellet : pattern) {
        glm::vec2 pickCoord = screenCenter + (pellet * glm::vec2(yMax, yMax));
        PickData pick = m_Renderer->Pick(pickCoord);        

        EntityWrapper victim(m_World, pick.Entity);
        if (!victim.Valid()) {
            continue;
        }

        // Temp hit decal
//         EntityWrapper hit = ResourceManager::Load<EntityFile>("Schema/Entities/HitTest.xml")->MergeInto(m_World);
//         (Field<glm::vec3>)hit["Transform"]["Position"] = pick.Position;

        // Don't let us shoot ourselves in the foot somehow
        if (victim == LocalPlayer) {
            continue;
        }

        // Only care about players being hit
        if (!victim.HasComponent("Player")) {
            victim = victim.FirstParentWithComponent("Player");
            if (!victim.Valid()) {
                continue;
            }
        }

        // Check for friendly fire
        if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {
            // Give boost
            Events::PlayerDamage ePlayerDamage;
            ePlayerDamage.Inflictor = wi.Player;
            ePlayerDamage.Victim = victim;
            ePlayerDamage.Damage = 0;
            m_EventBroker->Publish(ePlayerDamage);
            continue;
        }

        damageSum[victim] += pelletDamage;
       // ((Field<glm::vec4>)hit["Model"]["Color"]).z(1.f);
    }

    // Deal damage!
    for (auto& kv : damageSum) {
        // Deal damage! 
        Events::PlayerDamage ePlayerDamage;
        ePlayerDamage.Inflictor = wi.Player;
        ePlayerDamage.Victim = kv.first;
        ePlayerDamage.Damage = kv.second;
        m_EventBroker->Publish(ePlayerDamage);
    }
}