Update of /cvsroot/pure-data/externals/nusmuk/msd2D In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7919/nusmuk/msd2D
Modified Files: main.cpp Log Message: some small changes for Windows compilation
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/nusmuk/msd2D/main.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** main.cpp 22 Apr 2005 09:33:31 -0000 1.5 --- main.cpp 26 Apr 2005 11:39:48 -0000 1.6 *************** *** 40,45 **** // define constants #define MSD2D_VERSION 0.03 ! #define nb_max_link 4000 ! #define nb_max_mass 4000 #define Id_length 20
--- 40,45 ---- // define constants #define MSD2D_VERSION 0.03 ! #define nb_max_link 4000 ! #define nb_max_mass 4000 #define Id_length 20
*************** *** 49,77 **** #endif
! #define max(a,b) ( ((a) > (b)) ? (a) : (b) ) #define min(a,b) ( ((a) < (b)) ? (a) : (b) )
! typedef struct _mass { t_symbol *Id; t_int nbr; ! t_int mobile; ! t_float invM; ! t_float speedX; t_float posX; ! t_float posX2; t_float forceX; t_float out_forceX; ! t_float speedY; t_float posY; ! t_float posY2; t_float forceY; t_float out_forceY; ! } t_mass; ! ! typedef struct _link { t_symbol *Id; ! t_int nbr; ! t_mass *mass1; ! t_mass *mass2; t_float K1, D1, D2; t_float longx, longy, longueur, long_min, long_max; --- 49,86 ---- #endif
! #define max(a,b) ( ((a) > (b)) ? (a) : (b) ) #define min(a,b) ( ((a) < (b)) ? (a) : (b) )
! #ifdef _MSC_VER ! #define NEWARR(type,var,size) type *var = new type[size] ! #define DELARR(var) delete[] var ! #else ! #define NEWARR(type,var,size) type var[size] ! #define DELARR(var) ((void)0) ! #endif ! ! ! typedef struct _mass { t_symbol *Id; t_int nbr; ! t_int mobile; ! t_float invM; ! t_float speedX; t_float posX; ! t_float posX2; t_float forceX; t_float out_forceX; ! t_float speedY; t_float posY; ! t_float posY2; t_float forceY; t_float out_forceY; ! } t_mass; ! ! typedef struct _link { t_symbol *Id; ! t_int nbr; ! t_mass *mass1; ! t_mass *mass2; t_float K1, D1, D2; t_float longx, longy, longueur, long_min, long_max; *************** *** 107,111 **** { t_int i; ! t_atom sortie[0];
for (i=0; i<nb_mass; i++) { --- 116,120 ---- { t_int i; ! // t_atom sortie;
for (i=0; i<nb_mass; i++) { *************** *** 115,120 **** delete link[i]; } ! ToOutAnything(1,S_Reset,0,sortie); ! nb_link = 0; nb_mass = 0; id_mass = 0; --- 124,129 ---- delete link[i]; } ! ToOutAnything(1,S_Reset,0,NULL); ! nb_link = 0; nb_mass = 0; id_mass = 0; *************** *** 127,135 **** void m_bang() { ! t_float F=0,Fx=0,Fy=0,distance,vitesse, X_new, Y_new; t_int i; ! struct _mass mass_1, mass_2; ! for (i=0; i<nb_link; i++) { // compute link forces distance = sqrt(pow(link[i]->mass1->posX-link[i]->mass2->posX,2) + --- 136,144 ---- void m_bang() { ! t_float F=0,Fx=0,Fy=0,distance,vitesse, X_new, Y_new; t_int i; ! struct _mass mass_1, mass_2; ! for (i=0; i<nb_link; i++) { // compute link forces distance = sqrt(pow(link[i]->mass1->posX-link[i]->mass2->posX,2) + *************** *** 146,164 **** Fy = F * (link[i]->mass1->posY - link[i]->mass2->posY)/distance; // Fy = F * Ly[n]/L[n] } ! } link[i]->mass1->forceX -= Fx; // Fx1[n] = -Fx ! link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1] link[i]->mass2->forceX += Fx; // Fx2[n] = Fx link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1] link[i]->mass1->forceY -= Fy; // Fy1[n] = -Fy ! link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1] link[i]->mass2->forceY += Fy; // Fy2[n] = Fy link[i]->mass2->forceY -= link[i]->D2*link[i]->mass2->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1] link[i]->distance_old = distance; // L[n-1] = L[n] } ! ! for (i=0; i<nb_mass; i++) ! // compute new masses position only if mobile = 1 ! if (mass[i]->mobile == 1) { X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1] mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1] --- 155,173 ---- Fy = F * (link[i]->mass1->posY - link[i]->mass2->posY)/distance; // Fy = F * Ly[n]/L[n] } ! } link[i]->mass1->forceX -= Fx; // Fx1[n] = -Fx ! link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1] link[i]->mass2->forceX += Fx; // Fx2[n] = Fx link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1] link[i]->mass1->forceY -= Fy; // Fy1[n] = -Fy ! link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1] link[i]->mass2->forceY += Fy; // Fy2[n] = Fy link[i]->mass2->forceY -= link[i]->D2*link[i]->mass2->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1] link[i]->distance_old = distance; // L[n-1] = L[n] } ! ! for (i=0; i<nb_mass; i++) ! // compute new masses position only if mobile = 1 ! if (mass[i]->mobile == 1) { X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1] mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1] *************** *** 171,181 **** }
! for (i=0; i<nb_mass; i++) { // clear forces ! mass[i]->out_forceX = mass[i]->forceX; mass[i]->forceX = 0; // Fx[n] = 0 ! mass[i]->out_forceY = mass[i]->forceY; mass[i]->forceY = 0; // Fy[n] = 0 ! } }
--- 180,190 ---- }
! for (i=0; i<nb_mass; i++) { // clear forces ! mass[i]->out_forceX = mass[i]->forceX; mass[i]->forceX = 0; // Fx[n] = 0 ! mass[i]->out_forceY = mass[i]->forceY; mass[i]->forceY = 0; // Fy[n] = 0 ! } }
*************** *** 183,189 **** // ----------------------------------------------------------------------
! void m_mass(int argc,t_atom *argv) ! // add a mass ! // Id, nbr, mobile, invM, speedX Y, posX Y, forceX Y { t_atom sortie[6], aux[2]; --- 192,198 ---- // ----------------------------------------------------------------------
! void m_mass(int argc,t_atom *argv) ! // add a mass ! // Id, nbr, mobile, invM, speedX Y, posX Y, forceX Y { t_atom sortie[6], aux[2]; *************** *** 193,197 **** error("mass : Id mobile mass X Y");
! mass[nb_mass] = new t_mass; // new mass mass[nb_mass]->Id = GetSymbol(argv[0]); // ID mass[nb_mass]->mobile = GetInt(argv[1]); // mobile --- 202,206 ---- error("mass : Id mobile mass X Y");
! mass[nb_mass] = new t_mass; // new mass mass[nb_mass]->Id = GetSymbol(argv[0]); // ID mass[nb_mass]->mobile = GetInt(argv[1]); // mobile *************** *** 200,214 **** else M = GetFloat(argv[2]); mass[nb_mass]->invM = 1/(M); // invM ! mass[nb_mass]->speedX = 0; // vx[n] mass[nb_mass]->posX = GetFloat(argv[3]); // x[n] ! mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1] mass[nb_mass]->forceX = 0; // Fx[n] ! mass[nb_mass]->speedY = 0; // vy[n] mass[nb_mass]->posY = GetFloat(argv[4]); // y[n] ! mass[nb_mass]->posY2 = GetFloat(argv[4]); // y[n-1] mass[nb_mass]->forceY = 0; // Fy[n] mass[nb_mass]->nbr = id_mass; // id number nb_mass++ ; ! id_mass++; nb_mass = min ( nb_max_mass -1, nb_mass ); SetFloat((sortie[0]),id_mass-1); --- 209,223 ---- else M = GetFloat(argv[2]); mass[nb_mass]->invM = 1/(M); // invM ! mass[nb_mass]->speedX = 0; // vx[n] mass[nb_mass]->posX = GetFloat(argv[3]); // x[n] ! mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1] mass[nb_mass]->forceX = 0; // Fx[n] ! mass[nb_mass]->speedY = 0; // vy[n] mass[nb_mass]->posY = GetFloat(argv[4]); // y[n] ! mass[nb_mass]->posY2 = GetFloat(argv[4]); // y[n-1] mass[nb_mass]->forceY = 0; // Fy[n] mass[nb_mass]->nbr = id_mass; // id number nb_mass++ ; ! id_mass++; nb_mass = min ( nb_max_mass -1, nb_mass ); SetFloat((sortie[0]),id_mass-1); *************** *** 221,226 **** }
! void m_forceX(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; --- 230,235 ---- }
! void m_forceX(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; *************** *** 237,242 **** }
! void m_forceY(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; --- 246,251 ---- }
! void m_forceY(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; *************** *** 254,259 ****
void m_posX(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetSymbol(argv[0]); --- 263,268 ----
void m_posX(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetSymbol(argv[0]); *************** *** 271,276 ****
void m_posY(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetSymbol(argv[0]); --- 280,285 ----
void m_posY(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetSymbol(argv[0]); *************** *** 289,294 ****
void m_set_mobile(int argc,t_atom *argv) ! { ! // set mass No to mobile t_int i,aux; --- 298,303 ----
void m_set_mobile(int argc,t_atom *argv) ! { ! // set mass No to mobile t_int i,aux; *************** *** 306,311 ****
void m_set_fixe(int argc,t_atom *argv) ! { ! // set mass No to fixed t_int i,aux; --- 315,320 ----
void m_set_fixe(int argc,t_atom *argv) ! { ! // set mass No to fixed t_int i,aux; *************** *** 326,330 **** // Delete mass t_int i,nb_link_delete=0; ! t_atom sortie[6], aux[nb_link];
if (argc != 1) --- 335,340 ---- // Delete mass t_int i,nb_link_delete=0; ! t_atom sortie[6]; ! NEWARR(t_atom,aux,nb_link);
if (argc != 1) *************** *** 357,365 **** break; } }
void m_Xmax(int argc,t_atom *argv) ! { // set X max if (argc != 1) --- 367,376 ---- break; } + DELARR(aux); }
void m_Xmax(int argc,t_atom *argv) ! { // set X max if (argc != 1) *************** *** 369,373 ****
void m_Xmin(int argc,t_atom *argv) ! { // set X min if (argc != 1) --- 380,384 ----
void m_Xmin(int argc,t_atom *argv) ! { // set X min if (argc != 1) *************** *** 376,380 **** } void m_Ymax(int argc,t_atom *argv) ! { // set Y max if (argc != 1) --- 387,391 ---- } void m_Ymax(int argc,t_atom *argv) ! { // set Y max if (argc != 1) *************** *** 384,388 ****
void m_Ymin(int argc,t_atom *argv) ! { // set Y min if (argc != 1) --- 395,399 ----
void m_Ymin(int argc,t_atom *argv) ! { // set Y min if (argc != 1) *************** *** 395,401 ****
void m_link(int argc,t_atom *argv) ! // add a link ! // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax) ! { t_atom sortie[7], aux[2]; t_int i; --- 406,412 ----
void m_link(int argc,t_atom *argv) ! // add a link ! // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax) ! { t_atom sortie[7], aux[2]; t_int i; *************** *** 410,414 **** else if(mass[i]->nbr==GetAInt(argv[2])) // pointer to mass2 link[nb_link]->mass2 = mass[i]; ! link[nb_link]->K1 = GetFloat(argv[3]); // K1 link[nb_link]->D1 = GetFloat(argv[4]); // D1 link[nb_link]->D2 = GetFloat(argv[5]); // D2 --- 421,425 ---- else if(mass[i]->nbr==GetAInt(argv[2])) // pointer to mass2 link[nb_link]->mass2 = mass[i]; ! link[nb_link]->K1 = GetFloat(argv[3]); // K1 link[nb_link]->D1 = GetFloat(argv[4]); // D1 link[nb_link]->D2 = GetFloat(argv[5]); // D2 *************** *** 433,437 **** } nb_link++; ! id_link++; nb_link = min ( nb_max_link -1, nb_link ); SetFloat((sortie[0]),id_link-1); --- 444,448 ---- } nb_link++; ! id_link++; nb_link = min ( nb_max_link -1, nb_link ); SetFloat((sortie[0]),id_link-1); *************** *** 442,454 **** SetFloat((sortie[5]),link[nb_link-1]->D1); SetFloat((sortie[6]),link[nb_link-1]->D2); ! ToOutAnything(1,S_Link,7,sortie); }
void m_ilink(int argc,t_atom *argv) ! // add interactor link ! // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax) ! { t_atom aux[2], arglist[8]; ! t_int i,j, imass1[nb_mass], nbmass1=0, imass2[nb_mass], nbmass2=0; t_symbol *Id1, *Id2;
--- 453,467 ---- SetFloat((sortie[5]),link[nb_link-1]->D1); SetFloat((sortie[6]),link[nb_link-1]->D2); ! ToOutAnything(1,S_Link,7,sortie); }
void m_ilink(int argc,t_atom *argv) ! // add interactor link ! // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax) ! { t_atom aux[2], arglist[8]; ! t_int i,j, nbmass1=0, nbmass2=0; ! NEWARR(t_int,imass1,nb_mass); ! NEWARR(t_int,imass2,nb_mass); t_symbol *Id1, *Id2;
*************** *** 491,498 **** m_link(argc,arglist); } }
void m_setK(int argc,t_atom *argv) ! { // set rigidity of link(s) named Id t_int i; --- 504,513 ---- m_link(argc,arglist); } + DELARR(imass1); + DELARR(imass2); }
void m_setK(int argc,t_atom *argv) ! { // set rigidity of link(s) named Id t_int i; *************** *** 510,514 ****
void m_setD(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; --- 525,529 ----
void m_setD(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; *************** *** 526,530 ****
void m_setD2(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; --- 541,545 ----
void m_setD2(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; *************** *** 743,747 **** // List of masses positions on first outlet { ! t_atom sortie[2*nb_mass]; t_int i; --- 758,762 ---- // List of masses positions on first outlet { ! NEWARR(t_atom,sortie,2*nb_mass); t_int i; *************** *** 751,754 **** --- 766,770 ---- } ToOutAnything(0, S_massesPosL, 2*nb_mass, sortie); + DELARR(sortie); }
*************** *** 756,760 **** // List of masses forces on first outlet { ! t_atom sortie[2*nb_mass]; t_int i; --- 772,776 ---- // List of masses forces on first outlet { ! NEWARR(t_atom,sortie,2*nb_mass); t_int i; *************** *** 764,767 **** --- 780,784 ---- } ToOutAnything(0, S_massesForcesL, 2*nb_mass, sortie); + DELARR(sortie); }
*************** *** 798,802 **** // --------------------------------------------------------------------------------
! t_link * link[nb_max_link]; t_mass * mass[nb_max_mass]; t_float Xmin, Xmax, Ymin, Ymax; --- 815,819 ---- // --------------------------------------------------------------------------------
! t_link * link[nb_max_link]; t_mass * mass[nb_max_mass]; t_float Xmin, Xmax, Ymin, Ymax;