void TriangleStripVBO::initVBO(const MAUtil::Vector<TriangleStrip>& strips) { /**/ // VBO code glGenBuffers(1, &mVBO); glBindBuffer(GL_ARRAY_BUFFER, mVBO); int totalDataSize = 0; int vertexCoordOffset = 0; int textureCoordOffset = 0; mTriangleStrips.clear(); for(int i = 0; i < strips.size(); i++) { textureCoordOffset = vertexCoordOffset + strips[i].vertices.size()*sizeof(vec3); mTriangleStrips.add(TriangleStripInfo(vertexCoordOffset, textureCoordOffset, strips[i].vertices.size())); vertexCoordOffset = textureCoordOffset + strips[i].textureCoordinates.size()*sizeof(vec2); } totalDataSize = vertexCoordOffset; glBufferData(GL_ARRAY_BUFFER, totalDataSize, NULL, GL_STATIC_DRAW); for(int i = 0; i < strips.size(); i++) { glBufferSubData(GL_ARRAY_BUFFER, mTriangleStrips[i].vertexCoordOffset, mTriangleStrips[i].numVertices*sizeof(vec3), &strips[i].vertices[0]); glBufferSubData(GL_ARRAY_BUFFER, mTriangleStrips[i].textureCoordOffset, mTriangleStrips[i].numVertices*sizeof(vec2), &strips[i].textureCoordinates[0]); } glBindBuffer(GL_ARRAY_BUFFER, 0); }
void testConnectOverload(const char* url, bool acceptSuccess) { int connects = 0, events = 0; int result = 0; int conn; bool hasConn = false; MAUtil::Vector<Handle> conns; do { EVENT event; while(maGetEvent(&event)) { if(event.type == EVENT_TYPE_CLOSE || (event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0)) { maExit(0); } else if(event.type == EVENT_TYPE_CONN) { printf("Op %i conn %i result %i\n", event.conn.opType, event.conn.handle, event.conn.result); MAASSERT(event.conn.opType == CONNOP_CONNECT); conn = event.conn.handle; if(acceptSuccess) { if(event.conn.result < 0) { result = event.conn.result; } } else { result = event.conn.result; } MAASSERT(event.conn.result != 0); hasConn = true; events++; printf("Event %i\n", events); break; } } if(result == 0) { conn = maConnect(url); conns.add(conn); if(conn < 0) { printf("maConnect error %i\n", conn); result = conn; hasConn = false; } else { connects++; printf("Connect %i\n", connects); } } else if(events != connects) maWait(0); } while(events != connects);// && connects < 3); if(hasConn) { printf("Result %i on handle %i after %i connects\n", result, conn, connects); } else { printf("Result %i after %i connects\n", result, connects); } printf("Closing %i handles\n", conns.size()); for(int i=0; i<conns.size(); i++) { maConnClose(conns[i]); } printf("Done.\n"); }
/** * Post an HTTP request. * * The HTTP header parameters must be a vector (possibly empty) * of strings, ordered as key/value pairs. * * @param url The url of the POST request. * @param httpParams HTTP header parameters. * @param requestBody Data written to the request body. * @param requestLength Length of the request body. * * @return WORMHOLE_HTTP_SUCCESS if successful, WORMHOLE_HTTP_ERROR on error. */ int HighLevelHttpConnection::postRequest( const char* url, MAUtil::Vector<MAUtil::String>& httpParams, const void* requestBody, int requestLength) { // Create request. int result = create(url, HTTP_POST); if (result < 0) { return WORMHOLE_HTTP_ERROR; } // Write headers. for (int i = 0; i < httpParams.size(); i = i + 2) { setRequestHeader( httpParams[i].c_str(), httpParams[i + 1].c_str()); } // Write request data. write(requestBody, requestLength); // Next that happens is that connWriteFinished is called. return WORMHOLE_HTTP_SUCCESS; }
/** * Reads the CountryTable file. * Data will be written into mCountryFileNames. */ void DatabaseManager::readCountryTableFile() { // Reset array. mCountryFileNames.clear(); // Open CountryTable file. MAUtil::String filePath = mFileUtil->getLocalPath() + COUNTRY_TABLE_FILE_NAME; MAUtil::String fileContent; if (!mFileUtil->readTextFromFile(filePath, fileContent)) { printf("Cannot read text from CountryTable"); return; } //Read file content. MAUtil::YAJLDom::Value* root = MAUtil::YAJLDom::parse( (const unsigned char*)fileContent.c_str(), fileContent.size()); MAUtil::YAJLDom::Value* countries = root->getValueForKey(sCountriesKey); MAUtil::YAJLDom::ArrayValue* countriesArray = (MAUtil::YAJLDom::ArrayValue*) countries; MAUtil::Vector<MAUtil::YAJLDom::Value*> allCountries = countriesArray->getValues(); // Get all country files that we should read next. for (int index = 0; index < allCountries.size(); index++) { MAUtil::YAJLDom::Value* countryValue = allCountries[index]; MAUtil::String countryFileName = countryValue->toString(); mCountryFileNames.add(countryFileName); } delete root; }
void Video::setComments(const MAUtil::Vector<Comment> &comments) { mComments.clear(); for(int i=0; i<comments.size(); i++) { mComments.add(comments[i]); } }
void Video::setTags(MAUtil::Vector<IdNamePair> &tags) { mTags.clear(); for(int i=0; i<tags.size(); i++) { mTags.add(tags[i]); } }
// Helper function for removing an entry from the expected list. void eraseExpected( MAUtil::Vector<MAUtil::String>& v, const MAUtil::String& s) { for (int i = 0; i < v.size(); ++i) { if (v[i] == s) { v.remove(i); return; } } }
/** * Delete the entries on selected indexes. * @param indexList The list with the indexes of the records that * need to be deleted. */ void MediaWiki::filterData(MAUtil::Vector<int> indexList) { int shift = 0; // The vector is shifted to the left. for (int i=0; i < indexList.size(); i++) { if ( indexList[i]-shift >= 0) { if ( indexList[i]-shift < mWiki->titleResults.size() ){ mWiki->titleResults.remove(indexList[i]-shift); } if ( indexList[i]-shift < mWiki->snippetResults.size() ){ mWiki->snippetResults.remove(indexList[i]-shift); } } shift++; } }