void CCameraThread::AdjustMotor(double parm_scale) { bool forward = true; unsigned int step = 0, idx; double scale = parm_scale; idx = m_cLineAdj->m_iAdjPhase - 1; switch (m_cLineAdj->m_iAdjPhase) { case 2: if (!m_cLineAdj->GetPhase2Data(idx, parm_scale, &scale)) break; case 1: case 3: if (scale < 0) { forward = false; scale = -1 * scale; } if (scale < 1) m_cLineAdj->NextPhase(); else step = GetStep(idx, scale); break; default: m_cLineAdj->m_iAdjPhase = 1; return; } m_cLineAdj->MotorRun(idx, step, forward); }
int main(int argc, char *argv[]) { int row,column,step=0; FILE *in; if(argc>=2) if((in = fopen(argv[argc-1],"r+"))==NULL) { printf("%s %s Open file error, please make sure you have inputed right file name and location!",argv[0],argv[1]); system("pause"); return 0; } step=GetStep(argc,argv); if(step==0) { printf("Wrong Parameter!"); system("pause"); return 0; } //printf("%d",fscanf(in,"%d,%d,",&row,&column)); if(fscanf(in,"%d,%d",&row,&column)!=2) { printf("%d %d",row,column); printf("Row Column number illegal!"); system("pause"); return 0; } fgetc(in); if(row>Max_R||column>Max_C) { printf("Come on! Don't break rules of our deal!"); system("pause"); return 0; } printf("%d %d",row,column); if(step==1) { if(row==1) MaxStep1(in,row,column); else MaxStep2(in,row,column); } else if(step==2) { MaxStep3(in,row,column); } else if(step==3) MaxStep4H(in,row,column); else if(step==4) MaxStep4V(in,row,column); else MaxStep5(in,row,column); system("pause"); return 0; }
void pedometer(void* data) { INT16U oldsteps = 0; INT16U steps; INT8U count = 0; INT8U rest = FALSE; INT16U energyVal = 0; INT8U i; /* store data*/ StoreData((INT8S *)data); count++; /* when there is no count for a long time, it consider to be rest.*/ /* can ignore wrap around as rest is set.*/ if (count > REST_CNT) { rest = TRUE; } CntStep(); steps = GetStep(); if (oldsteps != steps) { /* display steps:.*/ /*print_str("steps: %d\n", steps);.*/ if (rest) rest = FALSE; else { /* Add energy according to table*/ for (i=0; i<TABLE_LEN; i++) { if (count > STEP_INT[i]) { energyVal += (count*ENERGY_INT[i])/4; break; } } } count = 0; /* show energy*/ /*print_str("energy: %d\n", energyVal/1000);*/ } oldsteps = steps; }
void ChsBullet::Update(irr::f32 fTick) { irr::scene::ISceneManager *pSmgr = CSAApp::GetPtr()->m_pSmgr; switch(GetStatus()) { case ChsBullet::FSM_READY: { SetStatus(ChsBullet::FSM_MOVE); } break; case ChsBullet::FSM_MOVE: { if(m_pAnim->getRigidBody()->getHitFraction() < 1.0f) { Signal("hit",NULL); } } break; case ChsBullet::FSM_HIT: if(GetStep() == 0) { m_pAnim->RemoveFromWorld(); irr::scene::ISceneNodeAnimator *pAniDel = pSmgr->createDeleteAnimator(0); m_pNode->addAnimator(pAniDel); pAniDel->drop(); IncStep(); } else { SetStatus(ChsBullet::FSM_DIE); } break; case ChsBullet::FSM_DIE: break; } }
main() { while (!feof(stdin)) { //пока файл не закончится char *s = GetString(); //находим строку if (!s) continue; if (TestWhile(s)) { //проверяем, на то, что это цикл int num = 0; char **strs = GetStrings(&num); //находим строчки учавствующие в цикле if (strs) { LoopStrings(strs, num, GetStart(s), GetLimit(s), GetStep(s)); while (num--) free(strs[num]); free(strs); } } else PrintString(s); free(s); } return 0; }
void MipsEnv::StepExec (void) { if (IsStopSim() == true) { return; } SetJumped (false); Word_t inst_hex; int32_t fetch_res; Addr_t fetch_pc = GetPC(); fetch_res = FetchMemory (fetch_pc, &inst_hex); if (fetch_res == -1) { DebugPrint ("<Error: Instructino is Misaligned>\n"); return; } std::string func_symbol; if ((IsDebugFunc () == true) && (FindSymbol (fetch_pc, &func_symbol) == true)) { DebugPrint ("<Func: %s>\n", func_symbol.c_str()); } GetTrace()->SetInstHex (inst_hex); GetTrace()->SetTracePC (GetPC()); GetTrace()->SetStep(GetStep()); AdvanceStep (); // Update Step Information uint32_t inst_idx = MIPS_DEC (inst_hex); GetTrace()->SetInstIdx (inst_idx); if (inst_idx == static_cast<uint32_t>(-1)) { DebugPrint ("<Error: instruction is not decoded. [%08x]=%08x\n", GetPC (), inst_hex); exit (EXIT_FAILURE); } else { m_inst_env->MIPS_Inst_Exec (inst_idx, inst_hex); if (IsDebugTrace() == true) { if (GetTrace()->IsDelayedSlot() == false) { DebugPrint ("%10d : ", GetTrace()->GetStep ()); DebugPrint ("[%08x] %08x : ", GetTrace()->GetTracePC (), GetTrace()->GetInstHex ()); char inst_string[31]; PrintInst (GetTrace()->GetInstHex(), GetTrace()->GetInstIdx(), inst_string, 30); DebugPrint ("%-30s ", inst_string); std::stringstream operand_str; PrintOperand (&operand_str); DebugPrint ("%s\n", operand_str.str().c_str()); if (GetTrace()->IsDelayedSlotExecuted () != 0) { GetTrace()->SetDelayedSlot (); DebugPrint ("%10d : ", GetTrace()->GetStep ()); DebugPrint ("[%08x] %08x : ", GetTrace()->GetTracePC (), GetTrace()->GetInstHex()); char inst_string[31]; PrintInst (GetTrace()->GetInstHex(), GetTrace()->GetInstIdx(), inst_string, 30); DebugPrint ("%-30s ", inst_string); std::stringstream operand_str; PrintOperand (&operand_str); DebugPrint ("%s\n", operand_str.str().c_str()); GetTrace()->ClearDelayedSlot (); } } } } if ((GetTrace()->IsDelayedSlot() == false) && (GetJumped () == false)) { ProceedPC (); // Update PC } }
void CAIPlayer::Update(irr::f32 fDelta) { irr::scene::ISceneManager *pSmgr = CSAApp::GetPtr()->m_pSmgr; irr::IrrlichtDevice *pDevice = CSAApp::GetPtr()->m_pDevice; irr::scene::CBulletAnimatorManager* pBulletPhysicsFactory = CSAApp::GetPtr()->m_pBulletPhysicsFactory; irr::scene::CBulletWorldAnimator* pWorldAnimator = CSAApp::GetPtr()->m_pWorldAnimator; switch(GetStatus()) { case FSM_READY: { //시작위치 지정 m_pNode->setVisible(true); irr::core::vector3df pos_Spwan = pSmgr->getSceneNodeFromName("genpos/zombie",m_pTrigerNode)->getAbsolutePosition(); m_pChracterAnimator->setPosition(pos_Spwan); m_pChracterAnimator->zeroForces(); //캐릭터 중심점을 보정해준다. SetStatus(FSM_STAND); } break; case FSM_STAND: if(GetStep() == 0) { m_pNode->changeAction("stand"); IncStep(); m_accTick = 0; //누적시간 리셋 } else if(GetStep() == 1) { if(m_accTick >= 2.0f) //2초경과 { SetStatus(FSM_WALK); m_vTargetDir.X = (rand() % 1000) / 1000.f - 0.5f; m_vTargetDir.Z = (rand() % 1000) / 1000.f - 0.5f; m_vTargetDir.Y = 0; m_vTargetDir.normalize(); } } break; case FSM_WALK: if(GetStep() == 0) { m_pNode->changeAction("walk"); IncStep(); m_accTick = 0; //누적시간 리셋 } else if(GetStep() == 1) { if(m_accTick >= 3.0f) //3초경과 { SetStatus(FSM_STAND); } else { btVector3 WalkVelocity(0,0,0); btScalar speed = 0; speed = btScalar(1.1) * 180.0f * fDelta; btVector3 btDir; Irrlicht2Bullet(m_vTargetDir,btDir); WalkVelocity = btDir * speed; m_pChracterAnimator->controlStep_Walker(WalkVelocity); } } break; case FSM_KICK: break; case FSM_ATTACKED: if(GetStep() == 0) { m_pNode->changeAction("damage",false); IncStep(); } else if(GetStep() == 1) { if(m_pNode->IsActionFinished()) { SetStatus(FSM_STAND); } } break; } //누적 타이머 m_accTick += fDelta; }
// Main function =============================================================== void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *X, *Y, Nd, *Space, UnitSpace = 1.0; mwSize nX, nDX, ndimX, N, Step, nSpace; const mwSize *dimX; int Order2 = 0; // Check number and type of inputs and outputs: ------------------------------ if (nrhs == 0 || nrhs > 4) { mexErrMsgIdAndTxt(ERR_ID "BadNInput", ERR_HEAD "1 or 4 inputs required."); } if (nlhs > 1) { mexErrMsgIdAndTxt(ERR_ID "BadNOutput", ERR_HEAD "1 output allowed."); } if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || mxIsSparse(prhs[0])) { mexErrMsgIdAndTxt(ERR_ID "BadTypeInput1", ERR_HEAD "Input must be a full real double array."); } // Pointers and dimension to input array: ------------------------------------ X = mxGetPr(prhs[0]); nX = mxGetNumberOfElements(prhs[0]); ndimX = mxGetNumberOfDimensions(prhs[0]); dimX = mxGetDimensions(prhs[0]); // Return fast on empty input matrix: if (nX == 0) { plhs[0] = COPY_ARRAY(prhs[0]); return; } // Get spacing, if defined: -------------------------------------------------- if (nrhs < 2) { // No 2nd input defined - scalar unit spacing: nSpace = 1; Space = &UnitSpace; } else { // Get pointer to spacing vector: if (!mxIsDouble(prhs[1])) { mexErrMsgIdAndTxt(ERR_ID "BadTypeInput2", ERR_HEAD "2nd input [Spacing] must be a DOUBLE."); } Space = mxGetPr(prhs[1]); nSpace = mxGetNumberOfElements(prhs[1]); if (nSpace == 0) { nSpace = 1; Space = &UnitSpace; } } // Determine dimension to operate on: ---------------------------------------- if (nrhs < 3) { N = FirstNonSingeltonDim(ndimX, dimX); // Zero based Step = 1; nDX = dimX[N]; } else if (mxIsNumeric(prhs[2])) { // 3rd input used: switch (mxGetNumberOfElements(prhs[2])) { case 0: // Use 1st non-singelton dim if 3rd input is []: N = FirstNonSingeltonDim(ndimX, dimX); Step = 1; nDX = dimX[N]; break; case 1: // Numerical scalar: Nd = mxGetScalar(prhs[2]); N = (mwSize) Nd - 1; if (Nd < 1.0 || Nd != floor(Nd)) { mexErrMsgIdAndTxt(ERR_ID "BadValueInput3", ERR_HEAD "Dimension must be a positive integer scalar."); } if (N < ndimX) { Step = GetStep(dimX, N); nDX = dimX[N]; } else { // Treat imaginated trailing dimensions as singelton, as usual in // Matlab: Step = nX; nDX = 1; } break; default: mexErrMsgIdAndTxt(ERR_ID "BadSizeInput3", ERR_HEAD "3rd input [Dim] must be scalar index."); } } else { // 2nd input is not numeric: mexErrMsgIdAndTxt(ERR_ID "BadTypeInput3", ERR_HEAD "3rd input must be scalar index."); } // Check matching sizes of X and Spacing: if (nSpace != 1 && nSpace != nDX) { mexErrMsgIdAndTxt(ERR_ID "BadSizeInput2", ERR_HEAD "2nd input [Spacing] does not match the dimensions."); } // Check 4th input: ---------------------------------------------------------- if (nrhs >= 4) { // "2ndOrder", but accept everything starting with "2": if (mxIsChar(prhs[3]) && !mxIsEmpty(prhs[3])) { Order2 = (*(mxChar *) mxGetData(prhs[3]) == L'2'); } else { mexErrMsgIdAndTxt(ERR_ID "BadTypeInput4", ERR_HEAD "4th input must be a string."); } } // Create output matrix: ----------------------------------------------------- plhs[0] = mxCreateNumericArray(ndimX, dimX, mxDOUBLE_CLASS, mxREAL); Y = mxGetPr(plhs[0]); // Reply ZEROS, if the length of the processed dimension is 1: if (nDX == 1) { return; } // Calculate the gradient: --------------------------------------------------- if (nSpace == 1) { // Scalar spacing if (Step == 1) { // Operate on 1st dimension CoreDim1Space1(X, nX, nDX, *Space, Y); } else { // Step >= 1, operate on any dimension CoreDimNSpace1(X, Step, nX, nDX, *Space, Y); } } else if (Order2) { // Spacing defined as vector, 2nd order method: if (nX == nDX) { // Single vector only - dynamic spacing factors: CoreDim1SpaceNOrder2(X, nX, nDX, Space, Y); } else { WrapSpaceNOrder2(X, Step, nX, nDX, Space, Y); } } else { // Spacing defined as vector, 1st order method: if (nX == nDX) { // Single vector only - dynamic spacing factors: CoreDim1SpaceN(X, nX, nDX, Space, Y); } else { WrapSpaceN(X, Step, nX, nDX, Space, Y); } } return; }