Beispiel #1
0
void
dmz::ObjectModuleGridBasic::_init (Config &local) {

   _xCoordMax = config_to_int32 ("grid.cell.x", local, _xCoordMax);
   _yCoordMax = config_to_int32 ("grid.cell.y", local, _yCoordMax);
   _minGrid = config_to_vector ("grid.min", local, _minGrid);
   _maxGrid = config_to_vector ("grid.max", local, _maxGrid);

   _log.info << "grid: " << _xCoordMax << "x" << _yCoordMax << endl;
   _log.info << "extents:" << endl
      << "\t" << _minGrid << endl
      << "\t" << _maxGrid << endl;

   Vector vec (_maxGrid - _minGrid);
   _xCellSize = vec.get (_primaryAxis) / (Float64)(_xCoordMax);
   _yCellSize = vec.get (_secondaryAxis) / (Float64)(_yCoordMax);

   _log.info << "cell count: " << _xCoordMax * _yCoordMax << endl;

   if (is_zero64 (_xCellSize)) { _xCellSize = 1.0; }
   if (is_zero64 (_yCellSize)) { _yCellSize = 1.0; }

   _grid = new GridStruct[_xCoordMax * _yCoordMax];

   activate_default_object_attribute (
      ObjectCreateMask | ObjectDestroyMask | ObjectPositionMask);
}
Beispiel #2
0
/*!

\brief Decomposes the Matrix into three Euler angles.
\param[out] hy Heading in radians.
\param[out] px Pitch in radians.
\param[out] rz Roll in radians.

*/
void
dmz::Matrix::to_euler_angles (Float64 &hy, Float64 &px, Float64 &rz)  const {

   Vector hvec (Forward), pvec (Forward), rvec (Up);
   transform_vector(hvec);
   Matrix cmat (*this), hmat, pmat, rmat;

   hvec.set_y (0.0);

   if (hvec.is_zero ()) { hy = 0.0; }
   else {

      hvec.normalize_in_place ();
      hy = Forward.get_signed_angle (hvec);
      hmat.from_axis_and_angle (Up, hy);
      hmat.transpose_in_place ();
      cmat = hmat * cmat;
   }

   cmat.transform_vector (pvec);

   if (is_zero64 (pvec.get_y ())) { px = 0.0; }
   else {

      px = Forward.get_signed_angle (pvec);
      pmat.from_axis_and_angle (Right, px);
      pmat.transpose_in_place ();
      cmat = pmat * cmat;
   }

   cmat.transform_vector (rvec);

   if (is_zero64 (rvec.get_x ())) { rz = 0.0; }
   else { rz = Up.get_signed_angle (rvec); }
}
Beispiel #3
0
/*===========================================================================*
 *				switch_to_user				     * 
 *===========================================================================*/
PUBLIC void switch_to_user(void)
{
	/* This function is called an instant before proc_ptr is
	 * to be scheduled again.
	 */

	/*
	 * if the current process is still runnable check the misc flags and let
	 * it run unless it becomes not runnable in the meantime
	 */
	if (proc_is_runnable(proc_ptr))
		goto check_misc_flags;
	/*
	 * if a process becomes not runnable while handling the misc flags, we
	 * need to pick a new one here and start from scratch. Also if the
	 * current process wasn' runnable, we pick a new one here
	 */
not_runnable_pick_new:
	if (proc_is_preempted(proc_ptr)) {
		proc_ptr->p_rts_flags &= ~RTS_PREEMPTED;
		if (proc_is_runnable(proc_ptr)) {
			if (!is_zero64(proc_ptr->p_cpu_time_left))
				enqueue_head(proc_ptr);
			else
				enqueue(proc_ptr);
		}
	}

	/*
	 * if we have no process to run, set IDLE as the current process for
	 * time accounting and put the cpu in and idle state. After the next
	 * timer interrupt the execution resumes here and we can pick another
	 * process. If there is still nothing runnable we "schedule" IDLE again
	 */
	while (!(proc_ptr = pick_proc())) {
		proc_ptr = proc_addr(IDLE);
		if (priv(proc_ptr)->s_flags & BILLABLE)
			bill_ptr = proc_ptr;
		idle();
	}

	switch_address_space(proc_ptr);

check_misc_flags:

	assert(proc_ptr);
	assert(proc_is_runnable(proc_ptr));
	while (proc_ptr->p_misc_flags &
		(MF_KCALL_RESUME | MF_DELIVERMSG |
		 MF_SC_DEFER | MF_SC_TRACE | MF_SC_ACTIVE)) {

		assert(proc_is_runnable(proc_ptr));
		if (proc_ptr->p_misc_flags & MF_KCALL_RESUME) {
			kernel_call_resume(proc_ptr);
		}
		else if (proc_ptr->p_misc_flags & MF_DELIVERMSG) {
			TRACE(VF_SCHEDULING, printf("delivering to %s / %d\n",
				proc_ptr->p_name, proc_ptr->p_endpoint););
			delivermsg(proc_ptr);
		}
Beispiel #4
0
//! Stops Plugins.
dmz::Boolean
dmz::Application::stop () {

   _state.rt.update_time_slice ();
   _state.container.stop_plugins ();

   const Float64 StopTime (get_time ());

   const Float64 TimeDelta (StopTime - _state.startTime);

   if (!is_zero64 (_state.frameCount) && !is_zero64 (TimeDelta) && !_state.quiet) {

      _state.log.out << "Average Frame Rate: " <<  _state.frameCount / TimeDelta
         << "Hz" << endl;
   }

   return True;
}
void
dmz::EntityPluginFreeFly::receive_axis_event (
      const Handle Channel,
      const InputEventAxis &Value) {

   const Float64 AxisValue = Value.get_axis_value ();

   Float64 rvalue = 0.0;

   if (!is_zero64 (AxisValue, 0.1)) { rvalue = AxisValue  * fabs (AxisValue); }

   switch (Value.get_axis_id ()) {

      case 2: { _move.speedAxis = rvalue * _move.moveSpeed; break; }
      case 1: { _move.turnAxis = rvalue * _move.turnRate; break; }
      case 6: { _move.strafeAxis = rvalue * _move.moveSpeed; break; }
      case 7: { _move.pitchAxis = rvalue * _move.turnRate; break; }
      case 8: { _move.ymoveAxis = rvalue * _move.moveSpeed; break; }
   }
}
Beispiel #6
0
/*!

\brief Creates a Matrix from a single Vector.
\details The Matrix will look in the direction of the given vector. The Matrix will
only update heading a pitch and will not contain a roll component.
\param[in] Direction Vector pointing in the direction to look.

*/
void
dmz::Matrix::from_vector (const Vector &Direction) {

   Vector hvec (Direction), pvec (Direction);
   Matrix hmat, pmat;

   hvec.set_y (0.0);

   if (!hvec.is_zero ()) {

      hvec.normalize_in_place ();
      hmat.from_axis_and_angle (Up, Forward.get_signed_angle (hvec));
   }

   hmat.transpose ().transform_vector (pvec);

   if (!is_zero64 (pvec.get_y ())) {

      pmat.from_axis_and_angle (Right, Forward.get_signed_angle (pvec));
   }

   *this = hmat * pmat;
}
Beispiel #7
0
PUBLIC short cpu_load(void)
{
	u64_t current_tsc, *current_idle;
	u64_t tsc_delta, idle_delta, busy;
	struct proc *idle;
	short load;
#ifdef CONFIG_SMP
	unsigned cpu = cpuid;
#endif

	u64_t *last_tsc, *last_idle;

	last_tsc = get_cpu_var_ptr(cpu, cpu_last_tsc);
	last_idle = get_cpu_var_ptr(cpu, cpu_last_idle);

	idle = get_cpu_var_ptr(cpu, idle_proc);;
	read_tsc_64(&current_tsc);
	current_idle = &idle->p_cycles; /* ptr to idle proc */

	/* calculate load since last cpu_load invocation */
	if (!is_zero64(*last_tsc)) {
		tsc_delta = sub64(current_tsc, *last_tsc);
		idle_delta = sub64(*current_idle, *last_idle);

		busy = sub64(tsc_delta, idle_delta);
		busy = mul64(busy, make64(100, 0));
		load = ex64lo(div64(busy, tsc_delta));

		if (load > 100)
			load = 100;
	} else
		load = 0;
	
	*last_tsc = current_tsc;
	*last_idle = *current_idle;
	return load;
}
void
dmz::MBRAPluginArchiveSupport::post_process_archive (
    const Handle ArchiveHandle,
    const Int32 Version) {

    ObjectModule *objMod = get_object_module ();

    if (objMod && _storeObjects) {

        if (_objects.get_count () > 0) {

            Float64 minx = 1.0e32, miny = 1.0e32, maxx = -1.0e32, maxy = -1.0e32;
            HandleContainerIterator it;
            Handle object (0);

            while (_objects.get_next (it, object)) {

                Vector pos;

                if (objMod->lookup_position (object, _defaultAttrHandle, pos)) {

                    const Float64 XX = pos.get_x ();
                    const Float64 YY = pos.get_z ();

                    if (XX < minx) {
                        minx = XX;
                    }
                    if (XX > maxx) {
                        maxx = XX;
                    }

                    if (YY < miny) {
                        miny = YY;
                    }
                    if (YY > maxy) {
                        maxy = YY;
                    }
                }
            }

            const Float64 OffsetX = minx + ((maxx - minx) * 0.5);
            const Float64 OffsetY = miny + ((maxy - miny) * 0.5);
            const Float64 Scale = is_zero64 (maxx - minx) ? 1.0 : 0.6 / (maxx - minx);

            it.reset ();

            while (_objects.get_next (it, object)) {

                Vector pos;

                if (objMod->lookup_position (object, _defaultAttrHandle, pos)) {

                    pos.set_x ((pos.get_x () - OffsetX) * Scale);
                    pos.set_z ((pos.get_z () - OffsetY) * Scale);
                    objMod->store_position (object, _defaultAttrHandle, pos);
                }
            }

            if (_map) {

                _map->center_on (0.0, 0.0);
                _map->set_zoom (10);

                Data out;
                out.store_boolean (_toggleHandle, 0, False);
                _toggleMapMessage.send (_toggleTargetHandle, &out);
            }

            _undo.reset ();
        }
    }

    if (objMod) {

        HandleContainerIterator it;
        Handle object (0);

        while (_ecObjects.get_next (it, object)) {

            Float64 value (0.0);

            if (!objMod->lookup_scalar (object, _threatAttrHandle, value)) {

                objMod->store_scalar (object, _threatAttrHandle, 1.0);
            }

            if (!objMod->lookup_scalar (object, _vulAttrHandle, value)) {

                objMod->store_scalar (object, _vulAttrHandle, 1.0);
            }
        }
    }

    _storeObjects = False;
}
void
dmz::EntityPluginGroundSimple::_move_entity (
      const Float64 TimeDelta,
      const Boolean Airborn,
      Vector &pos,
      Matrix &ori,
      Vector &vel,
      Float64 &heading) {

   const Vector Up (0.0, 1.0, 0.0);
   const Vector Forward (0.0, 0.0, -1.0);

   Vector vup (Up), vforward (Forward);

   ori.transform_vector (vup);
   ori.transform_vector (vforward);

   Matrix mat (vup, Up);

   mat.transform_vector (vforward);

   heading = Forward.get_signed_angle ( vforward);

   if (Airborn) {

      vel.set_y (vel.get_y () - (EarthGravity64 * TimeDelta));

      pos += vel * TimeDelta;
   }
   else if (_isDead) { pos += vel * TimeDelta; }
   else {

      const Float64 ForwardFactor ((vforward.get_angle (vel) > HalfPi64) ? -1.0 : 1.0);

      mat.transpose_in_place ();

      heading -= _move.turn * _move.turnRate * TimeDelta;

      Matrix hm (Up, heading);

      ori = mat * hm;

      vforward = Forward;

      ori.transform_vector (vforward);

      Float64 speed (vel.magnitude () - (_move.brake * _move.brakeRate * TimeDelta));

      if (!is_zero64 (_move.brake) && (speed < 0.0)) { speed = 0.0; }

      if (!is_zero64 (_move.throttle)) {

         const Float64 TargetSpeed (
            (_move.maxSpeed + _move.turboModifier) * _move.throttle);

         if ((speed * ForwardFactor) < TargetSpeed) {

            speed += (_move.throttle * _move.maxAccel * TimeDelta);

            if (speed > TargetSpeed) { speed = TargetSpeed; }
         }
         else if ((speed * ForwardFactor) > TargetSpeed) {

            speed -= (_move.maxDecel * TimeDelta);

            if (speed < 0) { speed = 0; }
         }
      }

      if (is_zero64 (_move.throttle) && is_zero64 (_move.brake))  {

         if (is_zero64 (vforward.get_y (), 0.05)) {

            speed -= _move.maxDecel * TimeDelta;

            if (speed < 0.0) { speed = 0.0; }
         }
         else {

            speed -= EarthGravity64 * vforward.get_y () * TimeDelta * ForwardFactor;
         }

         speed = speed * ForwardFactor;
      }

      vel = vforward * speed;

      pos += vel * TimeDelta;
   }
}
// TimeSlice Interface
void
dmz::EntityPluginFreeFly::update_time_slice (const Float64 TimeDelta) {

   ObjectModule *objMod (get_object_module ());

   if (objMod && _handle && _defaultHandle) {

      Vector pos, vel;
      Matrix ori;

      objMod->lookup_position (_handle, _defaultHandle, pos);
      objMod->lookup_velocity (_handle, _defaultHandle, vel);
      objMod->lookup_orientation (_handle, _defaultHandle, ori);

      const Vector Right (1.0, 0.0, 0.0);
      const Vector Up (0.0, 1.0, 0.0);
      const Vector Forward (0.0, 0.0, -1.0);
      Vector dir (Forward);

      ori.transform_vector (dir);

      Vector headingVec (dir);
      headingVec.set_y (0.0);
      headingVec.normalize_in_place ();

      Float64 heading (Forward.get_angle (headingVec));
      const Float64 HCross (Forward.cross (headingVec).normalize_in_place ().get_y ());

      if (HCross < 0.0) {

         heading += _move.turnAxis * TimeDelta;
         heading = TwoPi64 - heading;
      }
      else { heading -= _move.turnAxis * TimeDelta; }

      if (heading > Pi64) { heading -= TwoPi64; }
      else if (heading < -Pi64) { heading += TwoPi64; }

      Float64 pitch (dir.get_angle (headingVec));

      if (dir.get_y () < 0.0) {

         pitch += _move.pitchAxis * TimeDelta;
         pitch = TwoPi64 - pitch;
      }
      else {

         pitch -= _move.pitchAxis * TimeDelta;
      }

      if ((pitch > HalfPi64) && (pitch <= (Pi64))) { pitch = HalfPi64 - 0.001; }
      else if ((pitch < (Pi64 + HalfPi64)) && (pitch > Pi64)) {

         pitch = HalfPi64 + Pi64 + 0.001;
      }

      Matrix pm (Right, pitch);
      Matrix hm (Up, heading);

      ori = hm * pm;

      dir = Forward;
      Vector slide (Right);
      Vector ymove (Up);

      ori.transform_vector (dir);
      ori.transform_vector (slide);
      ori.transform_vector (ymove);

      const Vector OldPos (pos);

      pos -= (dir * (_move.speedAxis * TimeDelta));
      pos += (slide * (_move.strafeAxis * TimeDelta));
      pos += (ymove * (_move.ymoveAxis * TimeDelta));

      if (!is_zero64 (TimeDelta)) { vel = (pos - OldPos) * (1 /  TimeDelta); }

      objMod->store_position (_handle, _defaultHandle, pos);
      objMod->store_velocity (_handle, _defaultHandle, vel);
      objMod->store_orientation (_handle, _defaultHandle, ori);
   }
}
// Time Slice Interface
void
dmz::CyclesPluginWallOSG::update_time_slice (const Float64 DeltaTime) {

   static const Vector Scale (1.0, 1.0, 1.0);

   HashTableHandleIterator it;

   ObjectStruct *os (_objectTable.get_first (it));

   while (os) {
      
      if (!os->dir.is_zero () && !os->dirPrev.is_zero ()) {

         if (os->triCount <= 0) {

            os->verts->push_back (osg::Vec3 (os->pos.get_x (), 0.0, os->pos.get_z ()));
            os->verts->push_back (
               osg::Vec3 (os->pos.get_x (), os->WallInfo.Height, os->pos.get_z ()));

            os->verts->push_back (osg::Vec3 (os->pos.get_x (), 0.0, os->pos.get_z ()));
            os->verts->push_back (
               osg::Vec3 (os->pos.get_x (), os->WallInfo.Height, os->pos.get_z ()));

            os->triCount = 2;

            os->draw->setCount (os->triCount + 2);
            osg::Vec3 normal (os->dir.get_z (), 0.0, os->dir.get_x ());
            os->normals->push_back (normal);
            os->normals->push_back (normal);
            os->lastCorner = os->pos;
         }
         else {

            const Float64 Dot (os->dir.dot (os->dirPrev));

            if (!is_zero64 (Dot - 1.0)) {

               const Vector Previous (os->dirPrev * os->dirPrev);
               const Vector Current (os->dir * os->dir);

               osg::Vec3 pos (
                  (os->pos.get_x () * Previous.get_x ()) +
                     (os->posPrev.get_x () * Current.get_x ()),
                  0.0f,
                  (os->pos.get_z () * Previous.get_z ()) +
                     (os->posPrev.get_z () * Current.get_z ()));

               (*(os->verts))[os->triCount] = pos;
               os->verts->push_back (pos);

               pos.y () = os->WallInfo.Height;

               (*(os->verts))[os->triCount + 1] = pos;
               os->verts->push_back (pos);

               os->triCount += 2;

               os->draw->setCount (os->triCount + 2);
               osg::Vec3 normal (os->dir.get_z (), 0.0, os->dir.get_x ());
               os->normals->push_back (normal);
               os->normals->push_back (normal);
               os->lastCorner.set_xyz (pos.x (), 0.0, pos.z ());
            }
         }

         if ((os->pos - os->lastCorner).magnitude () > os->WallInfo.Offset) {

            Vector pos (os->pos - (os->dir * os->WallInfo.Offset));
            (*(os->verts))[os->triCount] =
               osg::Vec3 (pos.get_x (), 0.0f, pos.get_z ());
            (*(os->verts))[os->triCount + 1] =
               osg::Vec3 (pos.get_x (), os->WallInfo.Height, pos.get_z ());

            os->wall->dirtyDisplayList ();
            os->wall->dirtyBound ();
         }

         os->posPrev = os->pos;
         os->dirPrev = os->dir;
      }

      os  = _objectTable.get_next (it);
   }

   os = _deadTable.get_first (it);

   while (os) {

      if (os->wallYOffset < (-os->WallInfo.Height)) {

         ObjectStruct *tmp = _deadTable.remove (it.get_hash_key ());
         if (tmp) { _remove_wall (*tmp); delete tmp; tmp = 0; }
      }
      else {

         os->wallYOffset -= 2.0 * DeltaTime;
         os->xform->setMatrix (
            to_osg_matrix (Matrix (), Vector (0.0, os->wallYOffset, 0.0), Scale));
      }

      os  = _deadTable.get_next (it);
   }
}