static void _AndroidGetTxtFileArgs(int &argc, char** argv, int maxargc) { argc = 0; const U32 kMaxTextLen = 2048; U32 textLen; char* text = new char[kMaxTextLen]; // Open the file, kick out if we can't File cmdfile; File::Status err = cmdfile.open("AndroidCmdLine.txt", cmdfile.Read); // Re-organise function to handle memory deletion better if (err == File::Ok) { // read in the first kMaxTextLen bytes, kick out if we get errors or no data err = cmdfile.read(kMaxTextLen-1, text, &textLen); if (((err == File::Ok || err == File::EOS) || textLen > 0)) { // Null terminate text[textLen++] = '\0'; // Truncate to the 1st line of the file for(int i = 0; i < textLen; i++) { if( text[i] == '\n' || text[i] == '\r' ) { text[i] = '\0'; textLen = i+1; break; } } // Tokenize the args with nulls, save them in argv, count them in argc char* tok; for(tok = dStrtok(text, " "); tok && argc < maxargc; tok = dStrtok(NULL, " ")) argv[argc++] = tok; } } // Close file and delete memory before returning cmdfile.close(); delete[] text; text = NULL; }
void setVariable(const char *name, const char *value) { // get the field info from the object.. if(name[0] != '$' && dStrchr(name, '.') && !isFunction(name)) { S32 len = dStrlen(name); AssertFatal(len < sizeof(scratchBuffer)-1, "Sim::getVariable - name too long"); dMemcpy(scratchBuffer, name, len+1); char * token = dStrtok(scratchBuffer, "."); SimObject * obj = Sim::findObject(token); if(!obj) return; token = dStrtok(0, ".\0"); if(!token) return; while(token != NULL) { const char * val = obj->getDataField(StringTable->insert(token), 0); if(!val) return; char *fieldToken = token; token = dStrtok(0, ".\0"); if(token) { obj = Sim::findObject(token); if(!obj) return; } else { obj->setDataField(StringTable->insert(fieldToken), 0, value); } } } name = prependDollar(name); gEvalState.globalVars.setVariable(StringTable->insert(name), value); }
void ProjectWindow::refreshAssetList() { // Clear list. mAssetsTab->assetList->DeleteAllItems(); mAssetListRoot = mAssetsTab->assetList->AddRoot("ROOT"); Vector<ModuleInfo>* modules = mEditorManager->getModuleList(); const char* currentModuleID = ""; wxTreeItemId currentModuleTreeID = mAssetListRoot; for (Vector<ModuleInfo>::iterator modulesItr = modules->begin(); modulesItr != modules->end(); ++modulesItr) { if (dStrcmp(modulesItr->moduleID, currentModuleID) != 0) { currentModuleID = modulesItr->moduleID; currentModuleTreeID = mAssetsTab->assetList->AppendItem(mAssetListRoot, modulesItr->moduleID, 0, -1, new ModuleTreeItemData(*modulesItr)); } for (Vector<AssetCategoryInfo>::iterator assetCatItr = modulesItr->assets.begin(); assetCatItr != modulesItr->assets.end(); ++assetCatItr) { wxTreeItemId categoryTreeID = mAssetsTab->assetList->AppendItem(currentModuleTreeID, assetCatItr->categoryName, 1, -1, new AssetCategoryTreeItemData(*assetCatItr)); for (Vector<const AssetDefinition*>::iterator assetItr = assetCatItr->assets.begin(); assetItr != assetCatItr->assets.end(); ++assetItr) { // Fetch asset definition. const AssetDefinition* pAssetDefinition = *assetItr; char buf[256]; dStrcpy(buf, pAssetDefinition->mAssetId); const char* moduleName = dStrtok(buf, ":"); const char* assetName = dStrtok(NULL, ":"); mAssetsTab->assetList->AppendItem(categoryTreeID, assetName, 2, -1, new AssetTreeItemData(pAssetDefinition)); } } } // Sort Modules by Name mAssetsTab->assetList->SortChildren(mAssetListRoot); }
bool FindMatch::isMatchMultipleExprs( const char *exps, const char *str, bool caseSensitive ) { char *tok = 0; S32 len = dStrlen(exps); char *e = new char[len+1]; dStrcpy(e,exps); // [tom, 12/18/2006] This no longer supports space separated expressions as // they don't work when the paths have spaces in. // search for each expression. return true soon as we see one. for( tok = dStrtok(e,"\t"); tok != NULL; tok = dStrtok(NULL,"\t")) { if( isMatch( tok, str, caseSensitive) ) { delete []e; return true; } } delete []e; return false; }
void GFXGLCardProfiler::init() { mChipSet = reinterpret_cast<const char*>(glGetString(GL_VENDOR)); // get the major and minor parts of the GL version. These are defined to be // in the order "[major].[minor] [other]|[major].[minor].[release] [other] in the spec const char *versionStart = reinterpret_cast<const char*>(glGetString(GL_VERSION)); const char *versionEnd = versionStart; // get the text for the version "x.x.xxxx " for( S32 tok = 0; tok < 2; ++tok ) { char *text = dStrdup( versionEnd ); dStrtok(text, ". "); versionEnd += dStrlen( text ) + 1; dFree( text ); } mRendererString = "GL"; mRendererString += String::SpanToString(versionStart, versionEnd - 1); mCardDescription = reinterpret_cast<const char*>(glGetString(GL_RENDERER)); mVersionString = reinterpret_cast<const char*>(glGetString(GL_VERSION)); mVideoMemory = static_cast<GFXGLDevice*>(GFX)->getTotalVideoMemory(); Parent::init(); // Set new enums here so if our profile script forces this to be false we keep the GL_ZEROs. if(queryProfile("GL::suppFloatTexture")) { GFXGLTextureInternalFormat[GFXFormatR16G16F] = GL_RGBA_FLOAT16_ATI; GFXGLTextureFormat[GFXFormatR16G16F] = GL_RGBA; GFXGLTextureInternalFormat[GFXFormatR16G16B16A16F] = GL_RGBA_FLOAT16_ATI; GFXGLTextureInternalFormat[GFXFormatR32G32B32A32F] = GL_RGBA_FLOAT32_ATI; GFXGLTextureInternalFormat[GFXFormatR32F] = GL_RGBA_FLOAT32_ATI; } if(queryProfile("GL::suppMipLodBias")) { GFXGLSamplerState[GFXSAMPMipMapLODBias] = GL_TEXTURE_LOD_BIAS_EXT; } }
//----------------------------------------------------------------------------- // preload //----------------------------------------------------------------------------- bool ParticleData::preload(bool server, String &errorStr) { if (Parent::preload(server, errorStr) == false) return false; bool error = false; if(!server) { // Here we attempt to load the particle's texture if specified. An undefined // texture is *not* an error since the emitter may provide one. if (textureName && textureName[0]) { textureHandle = GFXTexHandle(textureName, &GFXDefaultStaticDiffuseProfile, avar("%s() - textureHandle (line %d)", __FUNCTION__, __LINE__)); if (!textureHandle) { errorStr = String::ToString("Missing particle texture: %s", textureName); error = true; } } if (animateTexture) { // Here we parse animTexFramesString into byte-size frame numbers in animTexFrames. // Each frame token must be separated by whitespace. // A frame token must be a positive integer frame number or a range of frame numbers // separated with a '-'. // The range separator, '-', cannot have any whitspace around it. // Ranges can be specified to move through the frames in reverse as well as forward. // Frame numbers exceeding the number of tiles will wrap. // example: // "0-16 20 19 18 17 31-21" S32 n_tiles = animTexTiling.x * animTexTiling.y; AssertFatal(n_tiles > 0 && n_tiles <= 256, "Error, bad animTexTiling setting." ); animTexFrames.clear(); char* tokCopy = new char[dStrlen(animTexFramesString) + 1]; dStrcpy(tokCopy, animTexFramesString); char* currTok = dStrtok(tokCopy, " \t"); while (currTok != NULL) { char* minus = dStrchr(currTok, '-'); if (minus) { // add a range of frames *minus = '\0'; S32 range_a = dAtoi(currTok); S32 range_b = dAtoi(minus+1); if (range_b < range_a) { // reverse frame range for (S32 i = range_a; i >= range_b; i--) animTexFrames.push_back((U8)(i % n_tiles)); } else { // forward frame range for (S32 i = range_a; i <= range_b; i++) animTexFrames.push_back((U8)(i % n_tiles)); } } else { // add one frame animTexFrames.push_back((U8)(dAtoi(currTok) % n_tiles)); } currTok = dStrtok(NULL, " \t"); } // Here we pre-calculate the UVs for each frame tile, which are // tiled inside the UV region specified by texCoords. Since the // UVs are calculated using bilinear interpolation, the texCoords // region does *not* have to be an axis-aligned rectangle. if (animTexUVs) delete [] animTexUVs; animTexUVs = new Point2F[(animTexTiling.x+1)*(animTexTiling.y+1)]; // interpolate points on the left and right edge of the uv quadrangle Point2F lf_pt = texCoords[0]; Point2F rt_pt = texCoords[3]; // per-row delta for left and right interpolated points Point2F lf_d = (texCoords[1] - texCoords[0])/(F32)animTexTiling.y; Point2F rt_d = (texCoords[2] - texCoords[3])/(F32)animTexTiling.y; S32 idx = 0; for (S32 yy = 0; yy <= animTexTiling.y; yy++) { Point2F p = lf_pt; Point2F dp = (rt_pt - lf_pt)/(F32)animTexTiling.x; for (S32 xx = 0; xx <= animTexTiling.x; xx++) { animTexUVs[idx++] = p; p += dp; } lf_pt += lf_d; rt_pt += rt_d; } // cleanup delete [] tokCopy; numFrames = animTexFrames.size(); } } return !error; }
void ProjectManager::refreshModuleList() { mModuleList.clear(); Vector<const AssetDefinition*> assetDefinitions = Torque::AssetDatabaseLink.getDeclaredAssets(); // Fetch all loaded module definitions. ModuleManager::typeConstModuleDefinitionVector loadedModules; Torque::ModuleDatabaseLink->findModules(true, loadedModules); // Iterate found loaded module definitions. for (ModuleManager::typeConstModuleDefinitionVector::const_iterator loadedModuleItr = loadedModules.begin(); loadedModuleItr != loadedModules.end(); ++loadedModuleItr) { // Fetch module definition. const ModuleDefinition* module = *loadedModuleItr; // Add to module list. ModuleInfo newModule; newModule.moduleID = module->getModuleId(); newModule.moduleVersion = module->getVersionId(); mModuleList.push_back(newModule); } // Iterate asset definitions. for (Vector<const AssetDefinition*>::iterator assetItr = assetDefinitions.begin(); assetItr != assetDefinitions.end(); ++assetItr) { // Fetch asset definition. const AssetDefinition* pAssetDefinition = *assetItr; char buf[256]; dStrcpy(buf, pAssetDefinition->mAssetId); const char* moduleName = dStrtok(buf, ":"); const char* assetName = dStrtok(NULL, ":"); // Try to find module bool foundModule = false; for (Vector<ModuleInfo>::iterator modulesItr = mModuleList.begin(); modulesItr != mModuleList.end(); ++modulesItr) { const char* moduleID = pAssetDefinition->mpModuleDefinition->getModuleId(); if (dStrcmp(modulesItr->moduleID, moduleID) == 0) { // Try to find category bool foundCategory = false; for (Vector<AssetCategoryInfo>::iterator categoriesItr = modulesItr->assets.begin(); categoriesItr != modulesItr->assets.end(); ++categoriesItr) { const char* moduleID = pAssetDefinition->mpModuleDefinition->getModuleId(); if (dStrcmp(categoriesItr->categoryName, pAssetDefinition->mAssetType) == 0) { categoriesItr->assets.push_back(pAssetDefinition); foundCategory = true; break; } } // Can't find module? Create one. if (!foundCategory) { AssetCategoryInfo newCategory; newCategory.categoryName = pAssetDefinition->mAssetType; newCategory.assets.push_back(pAssetDefinition); modulesItr->assets.push_back(newCategory); } foundModule = true; break; } } // Can't find module? Create one. if (!foundModule) { ModuleInfo newModule; newModule.moduleID = pAssetDefinition->mpModuleDefinition->getModuleId(); newModule.moduleVersion = pAssetDefinition->mpModuleDefinition->getVersionId(); AssetCategoryInfo newCategory; newCategory.categoryName = pAssetDefinition->mAssetType; newCategory.assets.push_back(pAssetDefinition); newModule.assets.push_back(newCategory); mModuleList.push_back(newModule); } } }