Connection *ConnectionClone (Connection *conn, UWORD type DEBUGPARAM) { Connection *child; child = ConnectionC (type DEBUGFOR); if (!child) return NULL; child->parent = conn; child->cont = conn->cont; child->flags = 0; Debug (DEB_CONNECT, "<=*= %p (%s) clone from %p (%s)", child, ConnectionType (child), conn, ConnectionType (conn)); return child; }
int CALMAPI::CALMReadSpecs( char* filename ) { ifstream infile; char dummy[32]; char mdlname[32]; int mdltype, mdlsize, mdlidx, mdlconn, link, delay; int i, j; // open the file infile.open( filename ); if ( infile.fail() ) { FileOpenError( filename ); return kCALMFileError; } // read in number of CALM modules SkipComments( &infile ); // ignore any strings starting with # infile >> mNumModules; // read in number of input modules SkipComments( &infile ); infile >> mNumInputs; // set up the module array mNetwork->SetNumModules( mNumModules, mNumInputs ); // read in each module. Pattern modules should be specified first, // before all other module types. for ( i = 0; i < mNumModules+mNumInputs; i++ ) { // read name of module SkipComments( &infile ); infile >> mdlname; // read module type SkipComments( &infile ); infile >> dummy; mdltype = ModuleType( dummy ); // read number of nodes SkipComments( &infile ); infile >> mdlsize; // initialize the module mNetwork->InitializeModule( i, mdltype, mdlsize, mdlname ); } // read in connections for ( int i = 0; i < mNumModules; i++ ) { // read name of to-module SkipComments( &infile ); infile >> mdlname; // get idx for to-module mdlidx = mNetwork->GetModuleIndex( mdlname ); // read number of connections SkipComments( &infile ); infile >> mdlconn; // set connections array for module mNetwork->SetNumConnections( mdlidx, mdlconn ); // set up each single connection for ( j = 0; j < mdlconn; j++ ) { // read from-module SkipComments( &infile ); infile >> mdlname; // get connection type SkipComments( &infile ); infile >> dummy; link = ConnectionType( dummy ); // with time delay connections, the time constant should be provided if ( link == kDelayLink ) { SkipComments( &infile ); infile >> delay; } else delay = 0; // connect the modules mNetwork->ConnectModules( j, mdlidx, mNetwork->GetModuleIndex( mdlname ), link, delay ); }
Simulation::Simulation(int argc, char* argv[], int width, int height) : BaseGfxApp(argc, argv, width, height, 50, 50, GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH, true, 851, 50) { setCaption("Robot Simulation"); //creates a basic UI panel with quit button GLUI_Panel *toolPanel = new GLUI_Panel(m_glui, "Control Panel"); new GLUI_Button(m_glui, "Start", UI_START, (GLUI_Update_CB)s_gluicallback); new GLUI_Button(m_glui, "Pause", UI_PAUSE, (GLUI_Update_CB)s_gluicallback); new GLUI_Button(m_glui, "Resume", UI_RESUME, (GLUI_Update_CB)s_gluicallback); new GLUI_Button(m_glui, "Quit", UI_QUIT, (GLUI_Update_CB)quick_exit); float scale = 1.0; //add_spinner_to_panel( GLUI_Panel *panel, const char *name, int data_type=GLUI_SPINNER_INT, void *live_var=NULL, int id=-1, GLUI_CB callback=GLUI_CB() ); spinner = m_glui->add_spinner_to_panel(toolPanel, "Light ActionRange(1-3):", GLUI_SPINNER_FLOAT, &scale, UI_SPIN, (GLUI_Update_CB)s_gluicallback); spinner->set_float_limits(1.0, 3.0, GLUI_LIMIT_CLAMP); spinner->set_speed(10.0f); // Initialize OpenGL glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluOrtho2D(0, m_width, 0, m_height); glViewport(0, 0, m_width, m_height); controlflag = true; // environment constructer //env.EnvironmentClass(area, boundary[0], boundary[1], robots, lights); env = new EnvironmentClass((glutGet(GLUT_WINDOW_WIDTH)*glutGet(GLUT_WINDOW_HEIGHT)), glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), &robots, &lights); oldTimeSinceStart = 0; count = 0; // initial setting : 10 robots, 5 lights srand(time(NULL)); int i = 0, j = 0, k = 0, l = 0; numRobot = 10; numLight = 4; for (i = 0; i < numRobot; i++) { float c[3] = {1.0f, 0.0f, 0.0f}; // red //RobotClass(pos_x, , pos_y, width, length, speed, orientation, shapeType, color, ConnectionType, id) RobotClass robot(rand()%760+20, rand()%760+20, 20 + rand() % 10, 0.0, 0, 2*M_PI*(double)rand()/RAND_MAX, Circle, c, ConnectionType(rand()%4), i); env->registerRobotClass(robot); /* cout << "Robot "<< i << endl; cout << "X: " << robots[i].getXPosition() << " Y: " << robots[i].getYPosition() << endl; cout << "Ori: " << robots[i].getOrientation() << endl; cout << "Radius: " << robots[i].getWidth()/2.0 << endl; cout << "l Wheel X:" << robots[i].getLeftWheelX() << " l Wheel Y: " << robots[i].getLeftWheelY() << endl << endl; cout << "r Wheel X:" << robots[i].getRightWheelX() << " r Wheel Y: " << robots[i].getRightWheelY() << endl << endl; */ } for (i = 0; i < numLight; i++) { float c[3] = {1.0f, 0.0f, 1.0f}; // yellow //Light(pos_x, , pos_y, width, length, speed, orientation, shapeType, color, actionRange) Light light(rand() % 760 +20, rand() % 760 + 20, 20 + rand() % 20, 0.0, 0.0, 0.0, Circle, c); env->registerLight(light); } //############################################################################################################# cout << "---------------Avoid initial overlap start:-------------"<<endl; // avoid initial overlap int num = numRobot + numLight; cout << "The number of Lights and Robots: " << num <<endl; //-----------------------------checks if overlap occurs robot/robot --------------------------------------- for(j = 0; j < robots.size(); j++){ for(k = 0; k < robots.size(); k++){ if ( ((j != k) && (DetectRobot_Robot (robots[j], robots[k]))) || robots[j].detectWall(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT)) != None){ double r = robots[j].getWidth()/2.0; double x = fmod(rand(),(800.0-2*r)) + r; double y = fmod(rand(),(800.0-2*r)) + r; robots[j].setNewPosition(x, y); k = 0; } } } //-----------------------------checks if overlap occurs light/robot --------------------------------------- for(j = 0; j < lights.size(); j++){ for(k = 0; k < lights.size(); k++){ for( l = 0; l < robots.size(); l++){ double r = lights[j].getWidth()/2.0; if ( (j != k) && DetectLights_Lights (lights[j], lights[k])){ // light overlap with other light lights[j].setPosition(fmod(rand(),(800.0-2*r)) + r, fmod(rand(),(800.0-2*r))+r); k = 0; l = 0; }else if(lights[j].detectWall(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT)) != None){ // light overlap with wall lights[j].setPosition(fmod(rand(),(800.0-2*r)) + r, fmod(rand(),(800.0-2*r))+r); k = 0; l = 0; }else if(DetectLights_Robot (lights[j], robots[l])) // light overlap with other light { lights[j].setPosition(fmod(rand(),(800.0-2*r)) + r, fmod(rand(),(800.0-2*r))+r); k = 0; l = 0; } } } } }