// the body of the main loop void tick() { doTiming("outside of tick()"); frameCount += 1; // printf("frame %d\n", frameCount); // for (int i=0; i<5; ++i) { Atomos::getInstance().tick(); // where the magic happens // } doTiming("repeated atomos::tick()"); // interpret the volumes as a pixel grid for (int y=0; y<simulation_ht; ++y){ for (int x=0; x<simulation_wd; ++x) { int index = y * simulation_wd + x; std::vector<Molecule_ptr> &mols = getMolecules(x, y); unsigned molCount = 0; for (const Molecule_ptr &mol : mols) { if (mol) { molCount += 1; } } // red if completely full // black if completely empty pixelData[4 * index] = ( 1.0 * (molCount * 255) / mols.size() + 0.0 * pixelData[4 * index] ); } } doTiming("pixelData filling"); // do a debug print of the one volume // printVolume(simulation_wd*0.5, simulation_ht*0.5); // draw the pixel data // we are using old openGL but this is quick, simple and dirty glClearColor(0.1, 0.1, 0.1, 1.0); // have a dark grey background glClear(GL_COLOR_BUFFER_BIT); glDrawPixels(simulation_wd, simulation_ht, GL_RGBA, GL_UNSIGNED_BYTE, pixelData); glutSwapBuffers(); glutPostRedisplay(); // active rendering doTiming("draw"); if (enableTimingPrintouts) { printf("\n"); } }
Soup Soup::operator+(Soup &other) { Soup res; // add names if (name != "") res.name = name+" + "+other.name; else res.name = other.name; // add protein chains vector<ProteinChain *> these_protein_chains = getProteinChains(); for(unsigned int i=0; i<these_protein_chains.size(); i++) res.add_protein_chain(*these_protein_chains[i]); vector<ProteinChain *> other_protein_chains = other.getProteinChains(); for(unsigned int i=0; i<other_protein_chains.size(); i++) res.add_protein_chain(*other_protein_chains[i]); // add molecules vector<Molecule *> these_molecules = getMolecules(); for(unsigned int i=0; i<these_molecules.size(); i++) res.add_molecule(*these_molecules[i]); vector<Molecule *> other_molecules = other.getMolecules(); for(unsigned int i=0; i<other_molecules.size(); i++) res.add_molecule(*other_molecules[i]); // add waters vector<Water *> these_waters = getWaters(); for(unsigned int i=0; i<these_waters.size(); i++) res.add_water(*these_waters[i]); vector<Water *> other_waters = other.getWaters(); for(unsigned int i=0; i<other_waters.size(); i++) res.add_water(*other_waters[i]); return res; }
void printVolume(unsigned x, unsigned y) { for (const Molecule_ptr &mol : getMolecules(x,y)) { printf((mol)? "1" : "0"); } printf("\n"); }
int main(int argc, char** argv) { printf("hello world\n"); time_init(); // create the atmos grid for (int y=0; y<simulation_ht; ++y) { for (int x=0; x<simulation_wd; ++x) { Environment *newEnv = new Environment(8); volumes.push_back(newEnv); // add connections to existing volumes in a grid if (x > 0) { // horizontal Pipe* p = new Pipe(); newEnv->takeControlOf(&p->A), volumes.at(y*simulation_wd + x-1)->takeControlOf(&p->B), p->checkConnections(); pipes.push_back(p); } if (y > 0) { // vertical Pipe* p = new Pipe(); newEnv->takeControlOf(&p->A); volumes.at((y-1)*simulation_wd + x)->takeControlOf(&p->B); p->checkConnections(); pipes.push_back(p); } } } doTiming("graph creation"); // fill a region of the grid to its capacity for (unsigned y=simulation_ht*0.25; y<=simulation_ht*0.5; ++y) { for (unsigned x=simulation_wd*0.25; x<=simulation_wd*0.5; ++x) { std::vector<Molecule_ptr> &mols = getMolecules(x, y); for (unsigned i=0; i < mols.size(); ++i) { mols.at(i).reset(new Molecule(1337)); } } } doTiming("molecule creation"); // set up the window glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(window_wd, window_ht); window = glutCreateWindow("atomos"); glutDisplayFunc(tick); glutReshapeFunc(reshapeHandler); // glutIdleFunc(AnimateScene); glutKeyboardFunc(keyHandler); // glutMouseFunc(mouseHandler); doTiming("window setup"); printf("\n"); glutMainLoop(); return 0; }