Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Dynamics/Entities/Units/Unit.cpp

Diff revisions: vs.
  @@ -20,69 +20,55 @@
20 20 _currentPosition = _node->getTransform()->getPosition();
21 21 _currentTargetPosition = targetPosition;
22 22
23 - if(_prevTime <= 0) _prevTime = GETMSTIME();
24 - /// Get current time in ms
23 + if(_prevTime <= 0)
24 + _prevTime = GETMSTIME();
25 + // Get current time in ms
25 26 U32 currentTime = GETMSTIME();
26 - /// figure out how many milliseconds have elapsed since last move time
27 + // figure out how many milliseconds have elapsed since last move time
27 28 U32 timeDif = currentTime - _prevTime;
28 - /// 'moveSpeed' m/s = '0.001 * moveSpeed' m / ms
29 - /// distance = timeDif * 0.001 * moveSpeed
29 + CLAMP<U32>(timeDif, 0, timeDif);
30 + // 'moveSpeed' m/s = '0.001 * moveSpeed' m / ms
31 + // distance = timeDif * 0.001 * moveSpeed
30 32 F32 moveDistance = _moveSpeed * (getMsToSec(timeDif));
31 - /// apply framerate varyance
32 - F32 speedFactor = FRAME_SPEED_FACTOR;
33 - moveDistance *= speedFactor;
34 - /// update previous time
35 - _prevTime = currentTime;
36 -
33 + CLAMP<F32>(moveDistance, EPSILON, _moveSpeed);
34 + // apply framerate varyance
35 + moveDistance *= FRAME_SPEED_FACTOR;
36 +
37 37 F32 xDelta = _currentTargetPosition.x - _currentPosition.x;
38 38 F32 yDelta = _currentTargetPosition.y - _currentPosition.y;
39 39 F32 zDelta = _currentTargetPosition.z - _currentPosition.z;
40 40
41 - /*if(_prevTime <= 0) _prevTime = 0;
42 - // Get current time in ms
43 - U32 currentTime = GETMSTIME();
44 - // figure out how many milliseconds have elapsed since last move time
45 - assert(currentTime >= _prevTime);
46 - U32 timeDiff = currentTime - _prevTime;
47 - MsToSec(timeDiff);
48 - // 'moveSpeed' m/s = '0.001 * moveSpeed' m / ms
49 - // distance = timeDif * 0.001 * moveSpeed
50 - // apply framerate varyance
51 - F32 moveDistance = _moveSpeed * timeDiff * FRAME_SPEED_FACTOR;
52 - assert(moveDistance >= 0);
53 - */
54 - /// Compute the destination point for current frame step
55 - vec3<F32> interpPosition;
56 - bool returnValue = false;
57 - if(!IS_TOLERANCE(yDelta,_moveTolerance) && !IS_ZERO(_moveSpeed)){
58 - if( !IS_ZERO( yDelta ) ){
41 + bool returnValue = IS_ZERO(_moveSpeed);
42 + if(!returnValue){
43 + // Compute the destination point for current frame step
44 + vec3<F32> interpPosition;
45 + if(!IS_TOLERANCE(yDelta,_moveTolerance) && !IS_ZERO( yDelta ) )
59 46 interpPosition.y = ( _currentPosition.y > _currentTargetPosition.y ? -moveDistance : moveDistance );
47 +
48 + if((!IS_TOLERANCE(xDelta,_moveTolerance) || !IS_TOLERANCE(zDelta,_moveTolerance))) {
49 + // Update target
50 + if( IS_ZERO( xDelta ) ){
51 + interpPosition.z = ( _currentPosition.z > _currentTargetPosition.z ? -moveDistance : moveDistance );
52 + }else if( IS_ZERO( zDelta ) ){
53 + interpPosition.x = ( _currentPosition.x > _currentTargetPosition.x ? -moveDistance : moveDistance );
54 + }else if( fabs( xDelta ) > fabs( zDelta ) ) {
55 + F32 value = fabs( zDelta / xDelta ) * moveDistance;
56 + interpPosition.z = ( _currentPosition.z > _currentTargetPosition.z ? -value : value );
57 + interpPosition.x = ( _currentPosition.x > _currentTargetPosition.x ? -moveDistance : moveDistance );
58 + }else {
59 + F32 value = fabs( xDelta / zDelta ) * moveDistance;
60 + interpPosition.x = ( _currentPosition.x > _currentTargetPosition.x ? -value : value );
61 + interpPosition.z = ( _currentPosition.z > _currentTargetPosition.z ? -moveDistance : moveDistance );
62 + }
63 + // commit transformations
64 + _node->getTransform()->translate(interpPosition);
65 + // Update current position
66 + _currentPosition = _node->getTransform()->getPosition();
60 67 }
61 - }
62 - if((!IS_TOLERANCE(xDelta,_moveTolerance) || !IS_TOLERANCE(zDelta,_moveTolerance)) && !IS_ZERO(_moveSpeed)) {
63 - /// Update target
64 - if( IS_ZERO( xDelta ) ){
65 - interpPosition.z = ( _currentPosition.z > _currentTargetPosition.z ? -moveDistance : moveDistance );
66 - }else if( IS_ZERO( zDelta ) ){
67 - interpPosition.x = ( _currentPosition.x > _currentTargetPosition.x ? -moveDistance : moveDistance );
68 - }else if( fabs( xDelta ) > fabs( zDelta ) ) {
69 - F32 value = fabs( zDelta / xDelta ) * moveDistance;
70 - interpPosition.z = ( _currentPosition.z > _currentTargetPosition.z ? -value : value );
71 - interpPosition.x = ( _currentPosition.x > _currentTargetPosition.x ? -moveDistance : moveDistance );
72 - }else {
73 - F32 value = fabs( xDelta / zDelta ) * moveDistance;
74 - interpPosition.x = ( _currentPosition.x > _currentTargetPosition.x ? -value : value );
75 - interpPosition.z = ( _currentPosition.z > _currentTargetPosition.z ? -moveDistance : moveDistance );
76 - }
77 - /// commit transformations
78 - _node->getTransform()->translate(interpPosition);
79 - /// Update current position
80 - _currentPosition = _node->getTransform()->getPosition();
81 - }else{
82 - returnValue = true; //< yes
83 - }
68 + }
84 69 // update previous time
85 70 _prevTime = currentTime;
71 +
86 72 return returnValue;
87 73 }
88 74