GroupWidget::GroupWidget(QList <Group*> *group, QWidget *parent) : QWidget(parent), groupList(group) { QHBoxLayout *h1 = new QHBoxLayout(); { QLabel *l = new QLabel(tr("Group: ")); addGroupEdit = new QLineEdit(this); connect(addGroupEdit, SIGNAL(editingFinished()), SLOT(createGroup())); addButton = new QPushButton(tr("Create"), this); connect(addGroupEdit, SIGNAL(textChanged(QString)), SLOT(changeAddGroup(QString))); connect(addButton, SIGNAL(clicked()), SLOT(createGroup())); addButton->setEnabled(false); h1->addWidget(l); h1->addWidget(addGroupEdit); h1->addWidget(addButton); } QHBoxLayout *h2 = new QHBoxLayout(); { h2->setMargin(0); upButton = new QPushButton(this); upButton->setIcon(QIcon(":images/uparrow.png")); downButton = new QPushButton(this); downButton->setIcon(QIcon(":images/downarrow.png")); h2->addStretch(); h2->addWidget(upButton); h2->addWidget(downButton); editButton = new QPushButton(this); editButton->setIcon(QIcon(":images/edit.png")); h2->addWidget(editButton); delButton = new QPushButton(this); delButton->setIcon(QIcon(":images/delete.png")); h2->addWidget(delButton); } groupListWidget = new QListWidget(this); QVBoxLayout *v = new QVBoxLayout; v->setMargin(0); v->setSpacing(0); v->addLayout(h1); v->addWidget(groupListWidget); v->addLayout(h2); setLayout(v); //qDebug() << "BookWidget 3"; connect(upButton, SIGNAL(clicked()), SLOT(upItem())); connect(downButton, SIGNAL(clicked()), SLOT(downItem())); connect(editButton, SIGNAL(clicked()), SLOT(editItem())); connect(delButton, SIGNAL(clicked()), SLOT(delItem())); connect(groupListWidget, SIGNAL(currentRowChanged(int)), SLOT(changeRow(int))); connect(groupListWidget, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(changeName(QListWidgetItem*))); connect(groupListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(editItem(QListWidgetItem*))); connect(groupListWidget, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem*)), SLOT(changeSelect(QListWidgetItem *, QListWidgetItem*))); initGroup(); resetButtons(); }
// // Allocate a chunk of blocks that is at least min and at most max // blocks in size. This API is used by the nursery allocator that // wants contiguous memory preferably, but doesn't require it. When // memory is fragmented we might have lots of chunks that are // less than a full megablock, so allowing the nursery allocator to // use these reduces fragmentation considerably. e.g. on a GHC build // with +RTS -H, I saw fragmentation go from 17MB down to 3MB on a // single compile. // // Further to this: in #7257 there is a program that creates serious // fragmentation such that the heap is full of tiny <4 block chains. // The nursery allocator therefore has to use single blocks to avoid // fragmentation, but we make sure that we allocate large blocks // preferably if there are any. // bdescr * allocLargeChunk (W_ min, W_ max) { bdescr *bd; StgWord ln, lnmax; if (min >= BLOCKS_PER_MBLOCK) { return allocGroup(max); } ln = log_2_ceil(min); lnmax = log_2_ceil(max); // tops out at MAX_FREE_LIST while (ln < lnmax && free_list[ln] == NULL) { ln++; } if (ln == lnmax) { return allocGroup(max); } bd = free_list[ln]; if (bd->blocks <= max) // exactly the right size! { dbl_link_remove(bd, &free_list[ln]); initGroup(bd); } else // block too big... { bd = split_free_block(bd, max, ln); ASSERT(bd->blocks == max); initGroup(bd); } n_alloc_blocks += bd->blocks; if (n_alloc_blocks > hw_alloc_blocks) hw_alloc_blocks = n_alloc_blocks; IF_DEBUG(sanity, memset(bd->start, 0xaa, bd->blocks * BLOCK_SIZE)); IF_DEBUG(sanity, checkFreeListSanity()); return bd; }
void initData() { R_START = initGroup(R_COUNT, 1, 40, 1, 1000); S_START = initGroup(S_COUNT, 20, 60, 1, 1000); }
void ObjLoader::load() { string line; GLfloat x, y, z; Group *current = &(Group()); current->vertexCount = 0; current->texCoordCount = 0; current->facesCount = 0; int i = 0; // OPEN FILE ifstream input("../Resources/AridSimple.obj"); if (!input.is_open()) { cout << "Unable to open file\n"; return; } /******* INITIALICE ARRAYS *******/ // create first group createGroup(); // count vertex and create all groups and group-arrays while (getline(input, line)) { switch (line[0]) { case 'v': switch (line[1]) { case ' ': groups.back().vertexCount++; break; case 't': groups.back().texCoordCount++; break; } break; case 'f': current->facesCount++; break; case 'g': if (current->vertexCount != 0) initGroup(current); createGroup(); current = &(groups[groups.size() - 2]); break; default:; } } // finish initializations initGroup(current); groups.pop_back(); input.clear(); input.seekg(0); cout << "Populating vertex" << endl; /******* POPULATING ARRAYS *******/ int currentVertex = 0; int accumulatedVertex = 1; int lastVertexCount = 0; int currentTextCoord = 0; int currentFace = 0; int currentGroup = 0; int xFace, yFace, zFace; char auxCString[100]; while (getline(input, line)) { switch (line[0]) { case 'v': // Vertices & textures sscanf(line.c_str(), "%s %f %f %f", &auxCString, &x, &y, &z); switch (line[1]) { case ' ': groups[currentGroup].vertex[currentVertex][0] = x; groups[currentGroup].vertex[currentVertex][1] = y; groups[currentGroup].vertex[currentVertex][2] = z; currentVertex++; break; case 't': groups[currentGroup].texCoord[currentTextCoord][0] = x; groups[currentGroup].texCoord[currentTextCoord][1] = y; //groups[currentGroup].textCoord[currentTextCoord][2] = z; currentTextCoord++; break; default:; } break; case 'f': // Faces (Triangles) sscanf(line.c_str(), "f %f/%d %f/%d %f/%d", &x, &xFace, &y, &yFace, &z, &zFace); groups[currentGroup - 1].faces[currentFace][0] = xFace - accumulatedVertex; groups[currentGroup - 1].faces[currentFace][1] = yFace - accumulatedVertex; groups[currentGroup - 1].faces[currentFace][2] = zFace - accumulatedVertex; currentFace++; break; case 'g': // Group sscanf(line.c_str(), "g %s", &auxCString); current->name = string(auxCString); cout << current->name << endl; //Mesh_Arid_{A,B, ... , J}_XX de aqui se puede sacar la textura // Next group, reset other counters currentGroup++; accumulatedVertex += lastVertexCount; lastVertexCount = currentVertex; currentVertex = 0; currentTextCoord = 0; currentFace = 0; break; default:; } } // Close file input.close(); }
bdescr * allocGroup (W_ n) { bdescr *bd, *rem; StgWord ln; if (n == 0) barf("allocGroup: requested zero blocks"); if (n >= BLOCKS_PER_MBLOCK) { StgWord mblocks; mblocks = BLOCKS_TO_MBLOCKS(n); // n_alloc_blocks doesn't count the extra blocks we get in a // megablock group. n_alloc_blocks += mblocks * BLOCKS_PER_MBLOCK; if (n_alloc_blocks > hw_alloc_blocks) hw_alloc_blocks = n_alloc_blocks; bd = alloc_mega_group(mblocks); // only the bdescrs of the first MB are required to be initialised initGroup(bd); goto finish; } n_alloc_blocks += n; if (n_alloc_blocks > hw_alloc_blocks) hw_alloc_blocks = n_alloc_blocks; ln = log_2_ceil(n); while (ln < MAX_FREE_LIST && free_list[ln] == NULL) { ln++; } if (ln == MAX_FREE_LIST) { #if 0 /* useful for debugging fragmentation */ if ((W_)mblocks_allocated * BLOCKS_PER_MBLOCK * BLOCK_SIZE_W - (W_)((n_alloc_blocks - n) * BLOCK_SIZE_W) > (2*1024*1024)/sizeof(W_)) { debugBelch("Fragmentation, wanted %d blocks, %ld MB free\n", n, ((mblocks_allocated * BLOCKS_PER_MBLOCK) - n_alloc_blocks) / BLOCKS_PER_MBLOCK); RtsFlags.DebugFlags.block_alloc = 1; checkFreeListSanity(); } #endif bd = alloc_mega_group(1); bd->blocks = n; initGroup(bd); // we know the group will fit rem = bd + n; rem->blocks = BLOCKS_PER_MBLOCK-n; initGroup(rem); // init the slop n_alloc_blocks += rem->blocks; freeGroup(rem); // add the slop on to the free list goto finish; } bd = free_list[ln]; if (bd->blocks == n) // exactly the right size! { dbl_link_remove(bd, &free_list[ln]); initGroup(bd); } else if (bd->blocks > n) // block too big... { bd = split_free_block(bd, n, ln); ASSERT(bd->blocks == n); initGroup(bd); } else { barf("allocGroup: free list corrupted"); } finish: IF_DEBUG(sanity, memset(bd->start, 0xaa, bd->blocks * BLOCK_SIZE)); IF_DEBUG(sanity, checkFreeListSanity()); return bd; }