void SoundSystem::setSoundEffectVolume(float volume) { ASSERT(volume >= 0.0f, "Volume is negative: " + ftos(volume)); ASSERT(volume <= 1.0f, "Volume is greater than 100%: " + ftos(volume)); soundVolume = volume; FSOUND_SetSFXMasterVolume((int)(soundVolume * 255.0f)); }
void ComponentMovement::walk(const vec2 &direction, float speed) { ASSERT(speed >= -1.0f, "Speed is too negative: " + ftos(speed)); ASSERT(speed <= +1.0f, "Speed is too positive: " + ftos(speed)); const float modifiedSpeed = speed * topSpeed; vec3 dv = vec3(-direction, 0.0f).getNormal() * modifiedSpeed; velocity = velocity + dv; }
void XonoticCheckBox_saveCvars(entity me) { if not(me.cvarName) return; if(me.checked) cvar_set(me.cvarName, ftos(me.yesValue)); else cvar_set(me.cvarName, ftos(me.noValue)); }
std::string RealWorldMappingMetaData::toString(const std::string& component) const { if (component == "offset") return ftos(getValue().getOffset()); else if (component == "scale") return ftos(getValue().getScale()); else if (component == "unit") return getValue().getUnit(); else return toString(); }
void SoundSystem::setMusicVolume(float volume) { ASSERT(volume >= 0.0f, "Volume is negative: " + ftos(volume)); ASSERT(volume <= 1.0f, "Volume is greater than 100%: " + ftos(volume)); musicVolume = volume; if(musicChannel>=0) { FSOUND_SetVolume(musicChannel, (int)(musicVolume * 255.0f)); } }
void GUISettingsMenu::save() { // controls int m = VLKC_MAX; for (int i=0; i<m; i++) { saveKeySetting(keys[i],(KeyCode)i); } // graphics g_settings->set("new_style_leaves", itos(m_data.fancy_trees)); g_settings->set("smooth_lighting", itos(m_data.smooth_lighting)); g_settings->set("enable_3d_clouds", itos(m_data.clouds_3d)); g_settings->set("opaque_water", itos(m_data.opaque_water)); g_settings->set("old_hotbar", itos(m_data.hotbar)); g_settings->set("enable_wieldindex", itos(m_data.wield_index)); // video g_settings->set("mip_map", itos(m_data.mip_map)); g_settings->set("anisotropic_filter", itos(m_data.anisotropic_filter)); g_settings->set("bilinear_filter", itos(m_data.bilinear_filter)); g_settings->set("trilinear_filter", itos(m_data.trilinear_filter)); g_settings->set("fullscreen", itos(m_data.fullscreen)); g_settings->set("enable_particles", itos(m_data.particles)); Environment->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, m_data.mip_map); // sound g_settings->set("sound_volume",ftos(m_data.volume)); }
const vector<Mesh*>& AnimationSequence::getFrame(size_t lowerFrame, size_t upperFrame, float bias) const { ASSERT(!keyFrames.empty(), "no keyframes in the animation sequence"); if(keyFrames.size()==1) return keyFrames[0].getMeshes(); ASSERT(lowerFrame < keyFrames.size(), "lower keyframe out of range:" + sizet_to_string(lowerFrame)); ASSERT(upperFrame < keyFrames.size(), "upper keyframe out of range: "+ sizet_to_string(upperFrame)); ASSERT(bias >= 0.0f && bias <= 1.0f, "bias is out of range: " + ftos(bias)); if(lowerFrame == upperFrame) return(keyFrames[lowerFrame].getMeshes()); const vector<Mesh*> &meshesA = keyFrames[lowerFrame].getMeshes(); const vector<Mesh*> &meshesB = keyFrames[upperFrame].getMeshes(); for(size_t i=0; i<meshes.size(); ++i) { Mesh*const mesh = meshes[i]; const Mesh*const a = meshesA[i]; const Mesh*const b = meshesB[i]; interpolate(bias, *mesh, *a, *b); } return meshes; }
void saveCvarsNexuizSlider(entity me) { if not(me.cvarName) return; cvar_set(me.cvarName, ftos(me.value)); }
void drawListBoxItemNexuizMapList(entity me, float i, vector absSize, float isSelected) { // layout: Ping, Map name, Map name, NP, TP, MP string s; float p; float theAlpha; float included; if(!MapInfo_Get_ByID(i)) return; included = me.g_maplistCacheQuery(me, i); if(included || isSelected) theAlpha = SKINALPHA_MAPLIST_INCLUDEDFG; else theAlpha = SKINALPHA_MAPLIST_NOTINCLUDEDFG; if(isSelected) draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); else if(included) draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG); s = ftos(p); draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); if(included) draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1); s = draw_TextShortenToWidth(strcat(MapInfo_Map_bspname, ": ", MapInfo_Map_title), me.columnNameSize / me.realFontSize_x, 0); draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_TITLE, theAlpha, 0); s = draw_TextShortenToWidth(MapInfo_Map_author, me.columnNameSize / me.realFontSize_x, 0); draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 1.00 * (me.columnNameSize - draw_TextWidth(s, 0) * me.realFontSize_x)) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_AUTHOR, theAlpha, 0); MapInfo_ClearTemps(); }
void saveCvarsNexuizGametypeButton(entity me) { if not(me.cvarName) return; cvar_set(me.cvarName, ftos(me.checked)); }
void image_write_float(const char *name, int w, int h, int c, int b, float *q) { void *p; int i; int n = w * h * c; /* If the caller requests a float file (b = 4) then write immediately. */ if (b == 4) image_write(name, w, h, c, b, q); /* Otherwise, convert the file to float before writing. */ else if ((p = malloc(n * b))) { if (b == 1) for (i = 0; i < n; ++i) ((unsigned char *) p)[i] = ftob(clamp(q[i])); if (b == 2) for (i = 0; i < n; ++i) ((unsigned short *) p)[i] = ftos(clamp(q[i])); image_write(name, w, h, c, b, p); free(p); } }
//--------------------------PlotStats------------------------------------- // // Given a surface to draw on this function displays some simple stats //------------------------------------------------------------------------ void CController::PlotStats(HDC surface)const { string s = "Generation: " + itos(m_iGenerations); TextOut(surface, 5, 25, s.c_str(), s.size()); s = "Num Species: " + itos(m_pPop->NumSpecies()); TextOut(surface, 5, 65, s.c_str(), s.size()); s = "Trial: " + itos(m_iTrials + 1) + "/" + itos(CParams::iNumTrials); TextOut(surface, 5, 45, s.c_str(), s.size()); s = "Best Fitness so far: " + ftos(m_pPop->BestEverFitness()); TextOut(surface, 5, 5, s.c_str(), s.size()); s = "Generation time: " + itos(elapsed); TextOut(surface, 5, 85, s.c_str(), s.size()); s = "Balance: " + itos(joeSum) + "(Left: " + itos(joeLeft) + ", right: " + itos(joeRight) + ")"; TextOut(surface, 5, 105, s.c_str(), s.size()); s = "Did it change?: " + (joeChanged ? (string("OMG YESSS!") + " change: " + itos(joeBalanceChanged)) : string("No...")); TextOut(surface, 5, 125, s.c_str(), s.size()); s = "Did it ever change?: " + (joeEverChanged ? (string("OMG YESSS!") + " times: " + itos(joeEverChangedTimes)) : string("No...")); TextOut(surface, 5, 145, s.c_str(), s.size()); }
void Player_SkeletonDisplayNumBones() { local float numbones,i; numbones = skel_get_numbones(self.skeletonindex); for (i = 1;i< numbones;i++){ print(ftos(i) ," - ", skel_get_bonename(self.skeletonindex,i)," \n"); } }
//--------------------------PlotStats------------------------------------- // // Given a surface to draw on this function displays stats and a crude // graph showing best and average MinesGathered //------------------------------------------------------------------------ void CController::PlotStats(HDC surface) { string s = "Most MinesGathered last round: " + ftos((m_vecMostMinesGathered.size() > 0) ? m_vecMostMinesGathered[m_vecMostMinesGathered.size()-1] : 0.0); TextOut(surface, 5, 20, s.c_str(), s.size()); s = "Average MinesGathered last round: " + ftos((m_vecAvMinesGathered.size() > 0) ? m_vecAvMinesGathered[m_vecAvMinesGathered.size()-1] : 0.0); TextOut(surface, 5, 40, s.c_str(), s.size()); s = "Number of deaths last round: " + ftos((m_vecDeaths.size() > 0) ? m_vecDeaths[m_vecDeaths.size()-1] : 0.0); TextOut(surface, 5, 60, s.c_str(), s.size()); //render the graph float HSlice = (float)cxClient/(m_iIterations+1); float VSlice = (float)cyClient/((1)*2); //plot the graph for the best MinesGathered float x = 0; m_OldPen = (HPEN)SelectObject(surface, m_RedPen); MoveToEx(surface, 0, cyClient, NULL); for (int i=0; i<m_vecMostMinesGathered.size(); ++i) { LineTo(surface, x, cyClient - VSlice*m_vecMostMinesGathered[i]); x += HSlice; } //plot the graph for the average MinesGathered x = 0; SelectObject(surface, m_BluePen); MoveToEx(surface, 0, cyClient, NULL); for (int i=0; i<m_vecAvMinesGathered.size(); ++i) { LineTo(surface, (int)x, (int)(cyClient - VSlice*m_vecAvMinesGathered[i])); x += HSlice; } //replace the old pen SelectObject(surface, m_OldPen); }
void XonoticCrosshairButton_saveCvars(entity me) { if not(me.cvarName) return; if(me.checked) cvar_set(me.cvarName, ftos(me.cvarValueFloat)); // TODO on an apply button, read _cl_color and execute the color command for it }
std::string QuicktuneValue::getString() { switch(type){ case QVT_NONE: return "(none)"; case QVT_FLOAT: return ftos(value_QVT_FLOAT.current); } return "<invalid type>"; }
void XonoticCrosshairButton_configureXonoticCrosshairButton(entity me, float theGroup, float theCrosshair) { me.cvarName = "crosshair"; me.cvarValueFloat = theCrosshair; me.loadCvars(me); me.configureRadioButton(me, string_null, me.fontSize, me.image, theGroup, 0); me.srcMulti = 1; me.src3 = strzone(strcat("/gfx/crosshair", ftos(me.cvarValueFloat))); me.src4 = "/gfx/crosshairdot"; }
void XonoticDecibelsSlider_saveCvars(entity me) { if not(me.cvarName) return; if(me.value >= -0.1) cvar_set(me.cvarName, "1"); if(me.value < -33) cvar_set(me.cvarName, "0"); else cvar_set(me.cvarName, ftos(pow(10, me.value / 10))); }
void Gecko_configureBrowser( entity me, string URI ) { me.focusable = 1; //create a new gecko object if needed if( !me.texturePath ) { me.texturePath = strzone( strcat( "_dynamic/gecko/menu/", ftos( _gecko_instanceNumber ) ) ); _gecko_instanceNumber+=1; // TODO: add error checks gecko_create( me.texturePath ); } gecko_navigate( me.texturePath, URI ); }
void saveCvarsNexuizCheckBox(entity me) { if(me.inverted == 0) cvar_set(me.cvarName, me.checked ? "1" : "0"); else if(me.inverted == 1) cvar_set(me.cvarName, me.checked ? "0" : "1"); else if(me.inverted > 1) { if(me.checked) cvar_set(me.cvarName, ftos(-(me.inverted - 1))); else cvar_set(me.cvarName, ftos(+(me.inverted - 1))); } else if(me.inverted < -1) { if(me.checked) cvar_set(me.cvarName, ftos(-(me.inverted + 1))); else cvar_set(me.cvarName, ftos(+(me.inverted + 1))); } }
// set_float(self, name, var) int NodeMetaRef::l_set_float(lua_State *L) { NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); float a = lua_tonumber(L, 3); std::string str = ftos(a); NodeMetadata *meta = getmeta(ref, true); if(meta == NULL || str == meta->getString(name)) return 0; meta->setString(name, str); reportMetadataChange(ref); return 0; }
Writer &BasicWriter::writeDouble(double val) { #if 1 gchar *buf = g_strdup_printf("%8.3f", val); if (buf) { writeString(buf); g_free(buf); } #else std::string tmp = ftos(val, 'g', 8, 3, 0); writeStdString(tmp); #endif return *this; }
void TFT_ScaleFonts::printNumF(double num, byte dec, int x, int y, char divider, int length, byte S, char filler) { if (S < 1) S = 1; if (S == 1) { _Disp->printNumF(num, dec, x, y, divider, length, filler); return; } char st[27]; boolean neg = false; if (dec < 1) dec = 1; else if (dec > 5) dec = 5; if (num < 0) neg = true; ftos(num, length, dec, st); if (divider != '.') { for (int i = 0; i < sizeof(st); i++) if (st[i] == '.') st[i] = divider; } if (filler != ' ') { if (neg) { st[0] = '-'; for (int i = 1; i < sizeof(st); i++) if ((st[i] == ' ') || (st[i] == '-')) st[i] = filler; } else { for (int i = 0; i < sizeof(st); i++) if (st[i] == ' ') st[i] = filler; } } print(st, x, y, S); }
void XonoticPlayerModelSelector_configureXonoticPlayerModelSelector(entity me) { float sortbuf, glob, i; string fn; glob = search_begin(language_filename(get_model_datafilename(string_null, -1, "txt")), TRUE, TRUE); if (glob < 0) return; me.configureXonoticImage(me, string_null, -1); sortbuf = buf_create(); for(i = 0; i < search_getsize(glob); ++i) { // select model #i! fn = search_getfilename(glob, i); if(!get_model_parameters(fn, -1)) continue; bufstr_add(sortbuf, sprintf("%-128s%s", get_model_parameters_name, fn), 1); } search_end(glob); buf_sort(sortbuf, 128, 0); me.numModels = buf_getsize(sortbuf); me.bufModels = buf_create(); for(i = 0; i < me.numModels; ++i) { fn = substring(bufstr_get(sortbuf, i), 128, -1); if(!get_model_parameters(fn, -1)) error("But it JUST worked!"); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_TITLE, get_model_parameters_name); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_IMAGE, strcat("/", substring(get_model_datafilename(get_model_parameters_modelname, get_model_parameters_modelskin, "tga"), 0, -5))); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_MODEL, get_model_parameters_modelname); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_SKIN, ftos(get_model_parameters_modelskin)); get_model_parameters_desc = strcat(get_model_parameters_desc, "\n"); if(get_model_parameters_sex) get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nSex: %s", get_model_parameters_sex)); if(get_model_parameters_weight) get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nWeight: %g kg", get_model_parameters_weight)); if(get_model_parameters_age) get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nAge: %g", get_model_parameters_age)); while(substring(get_model_parameters_desc, -1, 1) == "\n") get_model_parameters_desc = substring(get_model_parameters_desc, 0, -2); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_DESC, get_model_parameters_desc); } buf_del(sortbuf); get_model_parameters(string_null, 0); me.loadCvars(me); // this will select the initial model, depending on the current cvars me.go(me, 0); // this will set the vars for the selected model }
//------------------------------ Render ---------------------------------- void CGun::Render(HDC &surface) { WorldTransform(); MoveToEx(surface, m_vecGunVBTrans[0].x, m_vecGunVBTrans[0].y, NULL); for (int vtx=0; vtx<m_vecGunVBTrans.size(); ++vtx) { LineTo(surface, m_vecGunVBTrans[vtx].x, m_vecGunVBTrans[vtx].y); } LineTo(surface, m_vecGunVBTrans[0].x, m_vecGunVBTrans[0].y); //now render object info string s = "Position(" + ftos(m_dPosX) + ", " + ftos(m_dPosY) + ")"; TextOut(surface, 5, 0, s.c_str(), s.size()); s = "Rotation: " + ftos(m_dRotation); TextOut(surface, 5, 20, s.c_str(), s.size()); s = "Scale: " + ftos(m_dScale); TextOut(surface, 5, 40, s.c_str(), s.size()); }
// set_float(self, name, var) int MetaDataRef::l_set_float(lua_State *L) { MAP_LOCK_REQUIRED; MetaDataRef *ref = checkobject(L, 1); std::string name = luaL_checkstring(L, 2); float a = readParam<float>(L, 3); std::string str = ftos(a); Metadata *meta = ref->getmeta(true); if (meta == NULL || str == meta->getString(name)) return 0; meta->setString(name, str); ref->reportMetadataChange(); return 0; }
void updateConwidths() { vector r, c; float minfactor, maxfactor; float sz, f; r_x = cvar("menu_vid_width"); r_y = cvar("menu_vid_height"); r_z = cvar("menu_vid_pixelheight"); sz = cvar("menu_vid_scale"); // calculate the base resolution c_z = 0; c_x = 800; c_y = c_x * r_y * r_z / r_x; if(c_y < 600) { c_y = 600; c_x = c_y * r_x / (r_y * r_z); } f = min(r_x / c_x, r_y / c_y); if(f < 1) c = c * f; // ensures that c_x <= r_x and c_y <= r_y minfactor = min(1, 640 / c_x); // can be > 1 only if c_x is <640 maxfactor = max3(1, r_x / c_x, r_y / c_y); // can be < 1 only if r_x < c_x and r_y < c_y dprint("min factor: ", ftos(minfactor), "\n"); dprint("max factor: ", ftos(maxfactor), "\n"); if(sz < 0) f = 1 - (maxfactor - 1) * sz; else if(sz > 0) f = 1 + (minfactor - 1) * sz; else f = 1; c = c * f; // fteqcc fail cvar_set("vid_width", ftos(rint(r_x))); cvar_set("vid_height", ftos(rint(r_y))); cvar_set("vid_pixelheight", ftos(rint(r_z))); cvar_set("vid_conwidth", ftos(rint(c_x))); cvar_set("vid_conheight", ftos(rint(c_y))); }
static long rdstat(int port, void *buf, long n, ulong offset) { int fd = eia[port].fd; struct termios ts; char str[Maxctl]; char sbuf[20]; char *s; if(tcgetattr(fd, &ts) < 0) oserror(); s = str; s += sprint(s, "opens %d ferr %d oerr %d baud %s", eia[port].r.ref-1, eia[port].frame, eia[port].overrun, ftos(sbuf, bps, (tcflag_t)cfgetospeed(&ts))); s = rdxtra(port, &ts, s); sprint(s, "\n"); return readstr(offset, buf, n, str); }
void drawListBoxItemListBox(entity me, float i, vector absSize, float selected) { draw_Text('0 0 0', strcat("Item ", ftos(i)), eX * (8 / absSize_x) + eY * (8 / absSize_y), (selected ? '0 1 0' : '1 1 1'), 1, 0); }
/** Converts a float into an const char* * * \param f The float to convert * * \return A string that contains the float * */ const char* RainbruRPG::Core::StringConv::ftoc(float f){ std::string s=ftos( f ); return s.c_str(); }