Declare loop variables inside for loop in C++ files.
PiperOrigin-RevId: 518852339 Change-Id: I0174d873d89e48f11b816d337728f213c2798248
This commit is contained in:
committed by
Copybara-Service
parent
145fe7f354
commit
0e7e299bf6
+37
-49
@@ -139,8 +139,6 @@ const char help_title[] =
|
||||
|
||||
// init profiler figures
|
||||
void profilerinit(mj::Simulate* sim) {
|
||||
int i, n;
|
||||
|
||||
// set figures to default
|
||||
mjv_defaultFigure(&sim->figconstraint);
|
||||
mjv_defaultFigure(&sim->figcost);
|
||||
@@ -225,8 +223,8 @@ void profilerinit(mj::Simulate* sim) {
|
||||
sim->figtimer.range[1][1] = 0.4f;
|
||||
|
||||
// init x axis on history figures (do not show yet)
|
||||
for (n=0; n<6; n++)
|
||||
for (i=0; i<mjMAXLINEPNT; i++) {
|
||||
for (int n=0; n<6; n++)
|
||||
for (int i=0; i<mjMAXLINEPNT; i++) {
|
||||
sim->figtimer.linedata[n][2*i] = -i;
|
||||
sim->figsize.linedata[n][2*i] = -i;
|
||||
}
|
||||
@@ -234,11 +232,9 @@ void profilerinit(mj::Simulate* sim) {
|
||||
|
||||
// update profiler figures
|
||||
void profilerupdate(mj::Simulate* sim) {
|
||||
int i, n;
|
||||
|
||||
// update constraint figure
|
||||
sim->figconstraint.linepnt[0] = mjMIN(mjMIN(sim->d->solver_iter, mjNSOLVER), mjMAXLINEPNT);
|
||||
for (i=1; i<5; i++) {
|
||||
for (int i=1; i<5; i++) {
|
||||
sim->figconstraint.linepnt[i] = sim->figconstraint.linepnt[0];
|
||||
}
|
||||
if (sim->m->opt.solver==mjSOL_PGS) {
|
||||
@@ -248,7 +244,7 @@ void profilerupdate(mj::Simulate* sim) {
|
||||
if (sim->m->opt.solver==mjSOL_CG) {
|
||||
sim->figconstraint.linepnt[4] = 0;
|
||||
}
|
||||
for (i=0; i<sim->figconstraint.linepnt[0]; i++) {
|
||||
for (int i=0; i<sim->figconstraint.linepnt[0]; i++) {
|
||||
// x
|
||||
sim->figconstraint.linedata[0][2*i] = i;
|
||||
sim->figconstraint.linedata[1][2*i] = i;
|
||||
@@ -266,7 +262,7 @@ void profilerupdate(mj::Simulate* sim) {
|
||||
|
||||
// update cost figure
|
||||
sim->figcost.linepnt[0] = mjMIN(mjMIN(sim->d->solver_iter, mjNSOLVER), mjMAXLINEPNT);
|
||||
for (i=1; i<3; i++) {
|
||||
for (int i=1; i<3; i++) {
|
||||
sim->figcost.linepnt[i] = sim->figcost.linepnt[0];
|
||||
}
|
||||
if (sim->m->opt.solver==mjSOL_PGS) {
|
||||
@@ -274,7 +270,7 @@ void profilerupdate(mj::Simulate* sim) {
|
||||
sim->figcost.linepnt[2] = 0;
|
||||
}
|
||||
|
||||
for (i=0; i<sim->figcost.linepnt[0]; i++) {
|
||||
for (int i=0; i<sim->figcost.linepnt[0]; i++) {
|
||||
// x
|
||||
sim->figcost.linedata[0][2*i] = i;
|
||||
sim->figcost.linedata[1][2*i] = i;
|
||||
@@ -306,9 +302,9 @@ void profilerupdate(mj::Simulate* sim) {
|
||||
|
||||
// update figtimer
|
||||
int pnt = mjMIN(201, sim->figtimer.linepnt[0]+1);
|
||||
for (n=0; n<5; n++) {
|
||||
for (int n=0; n<5; n++) {
|
||||
// shift data
|
||||
for (i=pnt-1; i>0; i--) {
|
||||
for (int i=pnt-1; i>0; i--) {
|
||||
sim->figtimer.linedata[n][2*i+1] = sim->figtimer.linedata[n][2*i-1];
|
||||
}
|
||||
|
||||
@@ -329,9 +325,9 @@ void profilerupdate(mj::Simulate* sim) {
|
||||
|
||||
// update figsize
|
||||
pnt = mjMIN(201, sim->figsize.linepnt[0]+1);
|
||||
for (n=0; n<6; n++) {
|
||||
for (int n=0; n<6; n++) {
|
||||
// shift data
|
||||
for (i=pnt-1; i>0; i--) {
|
||||
for (int i=pnt-1; i>0; i--) {
|
||||
sim->figsize.linedata[n][2*i+1] = sim->figsize.linedata[n][2*i-1];
|
||||
}
|
||||
|
||||
@@ -542,7 +538,6 @@ void watch(mj::Simulate* sim) {
|
||||
|
||||
// make physics section of UI
|
||||
void makephysics(mj::Simulate* sim, int oldstate) {
|
||||
int i;
|
||||
mjOption& opt = sim->m->opt;
|
||||
|
||||
mjuiDef defPhysics[] = {
|
||||
@@ -591,13 +586,13 @@ void makephysics(mj::Simulate* sim, int oldstate) {
|
||||
{mjITEM_CHECKINT, "", 2, nullptr, ""},
|
||||
{mjITEM_END}
|
||||
};
|
||||
for (i=0; i<mjNDISABLE; i++) {
|
||||
for (int i=0; i<mjNDISABLE; i++) {
|
||||
mju::strcpy_arr(defFlag[0].name, mjDISABLESTRING[i]);
|
||||
defFlag[0].pdata = sim->disable + i;
|
||||
mjui_add(&sim->ui0, defFlag);
|
||||
}
|
||||
mjui_add(&sim->ui0, defEnableFlags);
|
||||
for (i=0; i<mjNENABLE; i++) {
|
||||
for (int i=0; i<mjNENABLE; i++) {
|
||||
mju::strcpy_arr(defFlag[0].name, mjENABLESTRING[i]);
|
||||
defFlag[0].pdata = sim->enable + i;
|
||||
mjui_add(&sim->ui0, defFlag);
|
||||
@@ -611,8 +606,6 @@ void makephysics(mj::Simulate* sim, int oldstate) {
|
||||
|
||||
// make rendering section of UI
|
||||
void makerendering(mj::Simulate* sim, int oldstate) {
|
||||
int i, j;
|
||||
|
||||
mjuiDef defRendering[] = {
|
||||
{
|
||||
mjITEM_SECTION,
|
||||
@@ -665,7 +658,7 @@ void makerendering(mj::Simulate* sim, int oldstate) {
|
||||
};
|
||||
|
||||
// add model cameras, up to UI limit
|
||||
for (i=0; i<mjMIN(sim->m->ncam, mjMAXUIMULTI-2); i++) {
|
||||
for (int i=0; i<mjMIN(sim->m->ncam, mjMAXUIMULTI-2); i++) {
|
||||
// prepare name
|
||||
char camname[mjMAXUITEXT] = "\n";
|
||||
if (sim->m->names[sim->m->name_camadr[i]]) {
|
||||
@@ -691,10 +684,10 @@ void makerendering(mj::Simulate* sim, int oldstate) {
|
||||
{mjITEM_CHECKBYTE, "", 2, nullptr, ""},
|
||||
{mjITEM_END}
|
||||
};
|
||||
for (i=0; i<mjNVISFLAG; i++) {
|
||||
for (int i=0; i<mjNVISFLAG; i++) {
|
||||
// set name, remove "&"
|
||||
mju::strcpy_arr(defFlag[0].name, mjVISSTRING[i][0]);
|
||||
for (j=0; j<strlen(mjVISSTRING[i][0]); j++)
|
||||
for (int j=0; j<strlen(mjVISSTRING[i][0]); j++)
|
||||
if (mjVISSTRING[i][0][j]=='&') {
|
||||
mju_strncpy(
|
||||
defFlag[0].name+j, mjVISSTRING[i][0]+j+1, mju::sizeof_arr(defFlag[0].name)-j);
|
||||
@@ -718,7 +711,7 @@ void makerendering(mj::Simulate* sim, int oldstate) {
|
||||
mjui_add(&sim->ui0, defTree);
|
||||
|
||||
mjui_add(&sim->ui0, defOpenGL);
|
||||
for (i=0; i<mjNRNDFLAG; i++) {
|
||||
for (int i=0; i<mjNRNDFLAG; i++) {
|
||||
mju::strcpy_arr(defFlag[0].name, mjRNDSTRING[i][0]);
|
||||
if (mjRNDSTRING[i][2][0]) {
|
||||
mju::sprintf_arr(defFlag[0].other, " %s", mjRNDSTRING[i][2]);
|
||||
@@ -788,7 +781,6 @@ void makegroup(mj::Simulate* sim, int oldstate) {
|
||||
|
||||
// make joint section of UI
|
||||
void makejoint(mj::Simulate* sim, int oldstate) {
|
||||
int i;
|
||||
|
||||
mjuiDef defJoint[] = {
|
||||
{mjITEM_SECTION, "Joint", oldstate, nullptr, "AJ"},
|
||||
@@ -805,7 +797,7 @@ void makejoint(mj::Simulate* sim, int oldstate) {
|
||||
|
||||
// add scalar joints, exit if UI limit reached
|
||||
int itemcnt = 0;
|
||||
for (i=0; i<sim->m->njnt && itemcnt<mjMAXUIITEM; i++)
|
||||
for (int i=0; i<sim->m->njnt && itemcnt<mjMAXUIITEM; i++)
|
||||
if ((sim->m->jnt_type[i]==mjJNT_HINGE || sim->m->jnt_type[i]==mjJNT_SLIDE)) {
|
||||
// skip if joint group is disabled
|
||||
if (!sim->vopt.jointgroup[mjMAX(0, mjMIN(mjNGROUP-1, sim->m->jnt_group[i]))]) {
|
||||
@@ -838,8 +830,6 @@ void makejoint(mj::Simulate* sim, int oldstate) {
|
||||
|
||||
// make control section of UI
|
||||
void makecontrol(mj::Simulate* sim, int oldstate) {
|
||||
int i;
|
||||
|
||||
mjuiDef defControl[] = {
|
||||
{mjITEM_SECTION, "Control", oldstate, nullptr, "AC"},
|
||||
{mjITEM_BUTTON, "Clear all", 2},
|
||||
@@ -856,7 +846,7 @@ void makecontrol(mj::Simulate* sim, int oldstate) {
|
||||
|
||||
// add controls, exit if UI limit reached (Clear button already added)
|
||||
int itemcnt = 1;
|
||||
for (i=0; i<sim->m->nu && itemcnt<mjMAXUIITEM; i++) {
|
||||
for (int i=0; i<sim->m->nu && itemcnt<mjMAXUIITEM; i++) {
|
||||
// skip if actuator group is disabled
|
||||
if (!sim->vopt.actuatorgroup[mjMAX(0, mjMIN(mjNGROUP-1, sim->m->actuator_group[i]))]) {
|
||||
continue;
|
||||
@@ -886,11 +876,9 @@ void makecontrol(mj::Simulate* sim, int oldstate) {
|
||||
|
||||
// make model-dependent UI sections
|
||||
void makesections(mj::Simulate* sim) {
|
||||
int i;
|
||||
|
||||
// get section open-close state, UI 0
|
||||
int oldstate0[NSECT0];
|
||||
for (i=0; i<NSECT0; i++) {
|
||||
for (int i=0; i<NSECT0; i++) {
|
||||
oldstate0[i] = 0;
|
||||
if (sim->ui0.nsect>i) {
|
||||
oldstate0[i] = sim->ui0.sect[i].state;
|
||||
@@ -899,7 +887,7 @@ void makesections(mj::Simulate* sim) {
|
||||
|
||||
// get section open-close state, UI 1
|
||||
int oldstate1[NSECT1];
|
||||
for (i=0; i<NSECT1; i++) {
|
||||
for (int i=0; i<NSECT1; i++) {
|
||||
oldstate1[i] = 0;
|
||||
if (sim->ui1.nsect>i) {
|
||||
oldstate1[i] = sim->ui1.sect[i].state;
|
||||
@@ -985,13 +973,11 @@ void copycamera(mj::Simulate* sim) {
|
||||
|
||||
// update UI 0 when MuJoCo structures change (except for joint sliders)
|
||||
void updatesettings(mj::Simulate* sim) {
|
||||
int i;
|
||||
|
||||
// physics flags
|
||||
for (i=0; i<mjNDISABLE; i++) {
|
||||
for (int i=0; i<mjNDISABLE; i++) {
|
||||
sim->disable[i] = ((sim->m->opt.disableflags & (1<<i)) !=0);
|
||||
}
|
||||
for (i=0; i<mjNENABLE; i++) {
|
||||
for (int i=0; i<mjNENABLE; i++) {
|
||||
sim->enable[i] = ((sim->m->opt.enableflags & (1<<i)) !=0);
|
||||
}
|
||||
|
||||
@@ -1094,7 +1080,6 @@ void uiEvent(mjuiState* state) {
|
||||
mj::Simulate* sim = static_cast<mj::Simulate*>(state->userdata);
|
||||
mjModel* m = sim->m;
|
||||
mjData* d = sim->d;
|
||||
int i;
|
||||
char err[200];
|
||||
|
||||
// call UI 0 if event is directed to it
|
||||
@@ -1202,22 +1187,25 @@ void uiEvent(mjuiState* state) {
|
||||
|
||||
case 5: // Adjust key
|
||||
case 6: // Load key
|
||||
i = sim->key;
|
||||
{
|
||||
int i = sim->key;
|
||||
d->time = m->key_time[i];
|
||||
mju_copy(d->qpos, m->key_qpos+i*m->nq, m->nq);
|
||||
mju_copy(d->qvel, m->key_qvel+i*m->nv, m->nv);
|
||||
mju_copy(d->act, m->key_act+i*m->na, m->na);
|
||||
mju_copy(d->mocap_pos, m->key_mpos+i*3*m->nmocap, 3*m->nmocap);
|
||||
mju_copy(d->mocap_quat, m->key_mquat+i*4*m->nmocap, 4*m->nmocap);
|
||||
mju_copy(d->ctrl, m->key_ctrl+i*m->nu, m->nu);
|
||||
mju_copy(d->qpos, m->key_qpos + i * m->nq, m->nq);
|
||||
mju_copy(d->qvel, m->key_qvel + i * m->nv, m->nv);
|
||||
mju_copy(d->act, m->key_act + i * m->na, m->na);
|
||||
mju_copy(d->mocap_pos, m->key_mpos + i * 3 * m->nmocap, 3 * m->nmocap);
|
||||
mju_copy(d->mocap_quat, m->key_mquat + i * 4 * m->nmocap,
|
||||
4 * m->nmocap);
|
||||
mju_copy(d->ctrl, m->key_ctrl + i * m->nu, m->nu);
|
||||
mj_forward(m, d);
|
||||
profilerupdate(sim);
|
||||
sensorupdate(sim);
|
||||
updatesettings(sim);
|
||||
break;
|
||||
} break;
|
||||
|
||||
case 7: // Save key
|
||||
i = sim->key;
|
||||
{
|
||||
int i = sim->key;
|
||||
m->key_time[i] = d->time;
|
||||
mju_copy(m->key_qpos+i*m->nq, d->qpos, m->nq);
|
||||
mju_copy(m->key_qvel+i*m->nv, d->qvel, m->nv);
|
||||
@@ -1225,7 +1213,7 @@ void uiEvent(mjuiState* state) {
|
||||
mju_copy(m->key_mpos+i*3*m->nmocap, d->mocap_pos, 3*m->nmocap);
|
||||
mju_copy(m->key_mquat+i*4*m->nmocap, d->mocap_quat, 4*m->nmocap);
|
||||
mju_copy(m->key_ctrl+i*m->nu, d->ctrl, m->nu);
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1233,14 +1221,14 @@ void uiEvent(mjuiState* state) {
|
||||
else if (it && it->sectionid==SECT_PHYSICS) {
|
||||
// update disable flags in mjOption
|
||||
m->opt.disableflags = 0;
|
||||
for (i=0; i<mjNDISABLE; i++)
|
||||
for (int i=0; i<mjNDISABLE; i++)
|
||||
if (sim->disable[i]) {
|
||||
m->opt.disableflags |= (1<<i);
|
||||
}
|
||||
|
||||
// update enable flags in mjOption
|
||||
m->opt.enableflags = 0;
|
||||
for (i=0; i<mjNENABLE; i++)
|
||||
for (int i=0; i<mjNENABLE; i++)
|
||||
if (sim->enable[i]) {
|
||||
m->opt.enableflags |= (1<<i);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user