Beispiel #1
0
//------------------------------------------------------------------------
bool CWeapon::CAnimationFiringLocator::GetProbableHit(EntityId weaponId, const IFireMode* pFireMode, Vec3& hit)
{
	CRY_ASSERT(m_pOwnerWeapon);

	// [*DavidR | 14/Oct/2010] Note: Basically a Copy & Paste of CSingle::GetProbableHit but without getting info
	// from the movement controller
	static Vec3 pos(ZERO), dir(FORWARD_DIRECTION);

	CActor *pActor = m_pOwnerWeapon->GetOwnerActor();
	IEntity *pWeaponEntity = m_pOwnerWeapon->GetEntity();

	static PhysSkipList skipList;
	skipList.clear();
	CSingle::GetSkipEntities(m_pOwnerWeapon, skipList);

	float rayLength = 250.0f;
	IEntityClass* pAmmoClass = pFireMode->GetAmmoType();
	const SAmmoParams *pAmmoParams = pAmmoClass ? g_pGame->GetWeaponSystem()->GetAmmoParams(pAmmoClass) : NULL;
	if (pAmmoParams)
	{
		//Benito - It could happen that the lifetime/speed are zero, so ensure at least some minimum distance check
		rayLength = clamp_tpl(min(pAmmoParams->speed * pAmmoParams->lifetime, rayLength), 5.0f, rayLength);
	}

	// Change this so it calls this firing locator's GetFiringPos if it gets implemented (no need atm)
	pos = pFireMode->GetFiringPos(Vec3Constants<float>::fVec3_Zero);
	IF_UNLIKELY(!GetFiringDir(weaponId, pFireMode, dir, Vec3Constants<float>::fVec3_Zero, Vec3Constants<float>::fVec3_Zero))
		dir = pFireMode->GetFiringDir(Vec3Constants<float>::fVec3_Zero, pos);
	dir *= rayLength;

	static ray_hit rayHit;	

	// use the ammo's pierceability
	uint32 flags=(geom_colltype_ray|geom_colltype13)<<rwi_colltype_bit|rwi_colltype_any|rwi_force_pierceable_noncoll|rwi_ignore_solid_back_faces;
	uint8 pierceability = 8;
	if (pAmmoParams && pAmmoParams->pParticleParams && !is_unused(pAmmoParams->pParticleParams->iPierceability))
	{
		pierceability=pAmmoParams->pParticleParams->iPierceability;
	}
	flags |= pierceability;

	if (gEnv->pPhysicalWorld->RayWorldIntersection(pos, dir, ent_all, flags, &rayHit, 1, !skipList.empty() ? &skipList[0] : NULL, skipList.size()))
	{
		hit = rayHit.pt;
	}
	else
	{
		hit = pos + dir;
	}

	return true;
}
//------------------------------------------------------------------------
void CVehicleMovementStdBoat::DrawImpulse(const pe_action_impulse& action, const Vec3& offset, float scale, const ColorB& col)
{
  if (!is_unused(action.impulse) && action.impulse.len2()>0)
  {
    IRenderAuxGeom* pGeom = gEnv->pRenderer->GetIRenderAuxGeom();
    Vec3 start = action.point + offset;
    Vec3 end = start - (action.impulse*scale/m_pVehicle->GetMass());
    Vec3 dir = (start-end).GetNormalizedSafe();
    pGeom->DrawCone(start-1.f*dir, dir, 0.5f, 1.f, col);
    pGeom->DrawLine(start, col, end, col);
    pGeom->DrawSphere(end, 0.25f, col);
  }  
}
Beispiel #3
0
void jumpTableEntry::verify() {
  if (is_unused()) {
    // Nothing to check in an unused entry
    return;
  }

  if (is_nmethod_stub()) {
    // Check nmethod
    char* addr = destination();
    if (!Universe::code->contains(addr)) report_verify_error("nmethod not in zone");
    if (method()->entryPoint() != addr)  report_verify_error("destination doesn't point to beginning of nmethod");
    return;
  }

  if (is_link()) {
    // Verify the elements in the list {nmethod} {block_closure}+
    jumpTableEntry* head = jumpTable::jump_entry_for_at(link(), 0);
    if (!head->is_nmethod_stub()) report_verify_error("must be nmethod stub");
    head->verify();
    nmethod* nm = method();
    if (!nm->has_noninlined_blocks()) report_verify_error("nmethod must have noninlined blocks");
    for (int index = 1; index <= nm->number_of_noninlined_blocks(); index++) {
       jumpTableEntry* son = jumpTable::jump_entry_for_at(link(), index);
       if (!son->is_block_closure_stub()) report_verify_error("must be block closure stub");
       son->verify();
    }
    return;
  }

  if (is_block_closure_stub()) {
    char* addr = destination();
    if (!Universe::code->contains(addr)) {
      if (addr != StubRoutines::compile_block_entry())
        report_verify_error("destination points neither into zone nor to compile stub");
    } else {
      nmethod* nm = block_nmethod();
      if (nm->entryPoint() != addr) 
        report_verify_error("destination doesn't point to beginning of nmethod");
    }
    return;
  }

  report_verify_error("invalid state");
}
Beispiel #4
0
void jumpTableEntry::print() {
  if (is_unused()) { 
    std->print_cr("Unused {next = %d}", (int) destination());
    return;
  }
  if (is_nmethod_stub()) {
    std->print("Nmethod stub ");
    Disassembler::decode(jump_inst_addr(), state_addr());
    nmethod* nm = method();
    if (nm) {
      nm->key.print();
    } else {
      std->print_cr("{not pointing to nmethod}");
    }
    return;
  }

  if (is_block_closure_stub()) {
    std->print("Block closure stub");
    Disassembler::decode(jump_inst_addr(), state_addr());
    nmethod* nm = block_nmethod();
    if (nm) {
      nm->key.print();
    } else {
      std->print_cr("{not compiled yet}");
    }
    return;
  }

  if (is_link()) {
    std->print_cr("Link for:");
    jumpTable::jump_entry_for_at(link(), 0)->print();
    return;
  }

  fatal("unknown jump table entry");
}
Beispiel #5
0
//------------------------------------------------------------------------
bool CProjectile::SetAspectProfile( EEntityAspects aspect, uint8 profile )
{
	//if (m_pAmmoParams->physicalizationType == ePT_None)
		//return true;

	if (aspect == eEA_Physics)
	{
		Vec3 spin(m_pAmmoParams->spin);
		Vec3 spinRandom(BiRandom(m_pAmmoParams->spinRandom.x), BiRandom(m_pAmmoParams->spinRandom.y), BiRandom(m_pAmmoParams->spinRandom.z));
		spin += spinRandom;
		spin = DEG2RAD(spin);

		switch (profile)
		{
		case ePT_Particle:
			{
				if (m_pAmmoParams->pParticleParams)
				{
					m_pAmmoParams->pParticleParams->wspin = spin;
					if (!m_initial_dir.IsZero() && !gEnv->bServer)
						m_pAmmoParams->pParticleParams->heading=m_initial_dir;
				}

				SEntityPhysicalizeParams params;
				params.type = PE_PARTICLE;
				params.mass = m_pAmmoParams->mass;
				if (m_pAmmoParams->pParticleParams)
					params.pParticle = m_pAmmoParams->pParticleParams;

				GetEntity()->Physicalize(params);
			}
			break;
		case ePT_Rigid:
			{
				SEntityPhysicalizeParams params;
				params.type = PE_RIGID;
				params.mass = m_pAmmoParams->mass;
				params.nSlot = 0;

				GetEntity()->Physicalize(params);

				pe_action_set_velocity velocity;
				m_pPhysicalEntity = GetEntity()->GetPhysics();
				velocity.w = spin;
				m_pPhysicalEntity->Action(&velocity);

				if (m_pAmmoParams->pSurfaceType)
				{
					int sfid = m_pAmmoParams->pSurfaceType->GetId();

					pe_params_part part;
					part.ipart = 0;

					GetEntity()->GetPhysics()->GetParams(&part);
					for (int i=0; i<part.nMats; i++)
						part.pMatMapping[i] = sfid;
				}
			}
			break;

		case ePT_Static:
			{
				SEntityPhysicalizeParams params;
				params.type = PE_STATIC;
				params.nSlot = 0;

				GetEntity()->Physicalize(params);

				if (m_pAmmoParams->pSurfaceType)
				{
					int sfid = m_pAmmoParams->pSurfaceType->GetId();

					pe_params_part part;
					part.ipart = 0;

					if (GetEntity()->GetPhysics()->GetParams(&part))
						if (!is_unused(part.pMatMapping))
							for (int i=0; i<part.nMats; i++)
								part.pMatMapping[i] = sfid;
				}
			}
			break;
		case ePT_None:
		case ePT_StuckToEntity:
			{
				SEntityPhysicalizeParams params;
				params.type = PE_NONE;
				params.nSlot = 0;

				GetEntity()->Physicalize(params);
			}
			break;
		}

		m_pPhysicalEntity = GetEntity()->GetPhysics();

		if (m_pPhysicalEntity)
		{
			pe_simulation_params simulation;
			simulation.maxLoggedCollisions = m_pAmmoParams->maxLoggedCollisions;

			pe_params_flags flags;
			flags.flagsOR = pef_log_collisions|(m_pAmmoParams->traceable?pef_traceable:0);

			pe_params_part colltype;
			colltype.flagsAND=~geom_colltype_explosion;

			m_pPhysicalEntity->SetParams(&simulation);
			m_pPhysicalEntity->SetParams(&flags);
			m_pPhysicalEntity->SetParams(&colltype);
		}
	}

	return true;
}
Beispiel #6
0
static VALUE protected_tidy_bytes(VALUE arg) {
  struct protected_tidy_bytes_arg* args = (struct protected_tidy_bytes_arg *)arg;
  VALUE string = args->string;
  uint8_t *arr = args->arr;

  int conts_expected = 0;
  int i, j;
  uint8_t byte;

  uint8_t *curr = arr;
  uint8_t *last_lead = curr;

  int did_write = 0;

  for (i = 0; i < RSTRING_LEN(string) ; i++) {
    byte = RSTRING_PTR(string)[i];
    curr[0] = byte;
    did_write = 0;

    if (is_unused(byte) || is_restricted(byte)) {
      curr = tidy_byte2(byte, curr);
      did_write = 1;
    } else if (is_cont(byte)) {
      if (conts_expected == 0) {
        curr = tidy_byte2(byte, curr);
        did_write = 1;
      } else {
        conts_expected--;
      }
    } else {
      if (conts_expected > 0) {
        int start_index = last_lead-arr;
        int end_index = curr-arr;
        int len = end_index - start_index;

        uint8_t temp[len];
        for (j = 0; j < len; j++) {
          temp[j] = arr[start_index + j];
        }

        curr = arr + start_index;
        for (j = 0; j < len; j++) {
          curr = tidy_byte2(temp[j], curr);
        }

        conts_expected = 0;
      }
      if (is_lead(byte)) {
        if (i == RSTRING_LEN(string) - 1) {
          curr = tidy_byte2(byte, curr);
          did_write = 1;
        } else {
          if (byte < 224) {
            conts_expected = 1;
          } else if (byte < 240) {
            conts_expected = 2;
          } else {
            conts_expected = 3;
          }
          last_lead = curr;
        }
      }
    }
    if (!did_write) {
      *curr++ = byte;
    }
  }
  VALUE str = rb_str_new((const char *)arr, curr-arr);
  return rb_funcall(str, idForceEncoding, 1, rb_str_new2("UTF-8"));
}
Beispiel #7
0
int jumpTableEntry::next_free() const {
  assert(is_unused(), "must be a unused entry");
  return (int) *destination_addr();
}