int print_u_option(unsigned long long n, t_flags flags) { int length; int tmp; int i; length = 1; i = 1; if (flags.precision == -1 && n < 1) length = 0; tmp = flags.field_width; while (n > 9) { n /= 10; length++; i++; } if (flags.precision > length) tmp -= flags.precision; else tmp -= length; length = split(tmp, length, flags); length = split2(i, length, flags); return (length); }
void FDSMesh::ReadMatrix(std::string line, std::ifstream &pFile) { int m = 0; int n; std::vector<std::string> strVec; while (std::getline(pFile, line)) { n = 0; strVec = split2(line, ',', strVec); for (auto &elem : strVec) { //std::cout << elem << " col " << n << " line " << m << std::endl; if (elem=="nan" || elem=="NAN" || elem=="NaN" || elem=="-inf" || elem=="inf") { _matrix[m][n].SetValue(1.0); //Log->Write("ERROR: Mesh values consist of nan!"); //exit(EXIT_FAILURE); } else _matrix[m][n].SetValue(std::stod(elem)); ++n; } strVec.clear(); ++m; } pFile.close(); _statMesh=true; }
LPTSTR PlayerFileDialogServiceWin::parseExtensions(const std::string &extensions) const { static WCHAR *defaultExtensions = L"All Files (*.*)\0*.*\0"; if (extensions.length() == 0) { WCHAR *buff = new WCHAR[wcslen(defaultExtensions) + 1]; wcscpy(buff, defaultExtensions); return buff; } // 1. // "Lua Script File|*.lua;JSON File|*.json" // to // "Lua Script File (*.lua)\0*.lua\0JSON File (*.json)\0*.json\0"; // // 2. // "Lua Script File|*.lua;Cocos Studio File|*.csd,*.csb" // to // "Lua Script File (*.lua)\0*.lua\0Cocos Studio File (*.csd;*.csb")\0*.csd;*.csb"\0"; std::u16string u16extensions; std::u16string split1((char16_t*)L";"); std::u16string split2((char16_t*)L"|"); std::u16string split3((char16_t*)L","); std::string extensionsArg(extensions); cocos2d::StringUtils::UTF8ToUTF16(extensions, u16extensions); vector<std::u16string> pairs = splitString(u16extensions, split1); size_t buffsize = extensions.length() * 6; WCHAR *buff = new WCHAR[buffsize]; memset(buff, 0, sizeof(WCHAR) * buffsize); size_t offset = 0; for (auto it = pairs.begin(); it != pairs.end(); ++it) { vector<std::u16string> p = splitString(*it, split2); std::u16string descr, ext; if (p.size() < 2) { descr = ext = *it; } else { descr = p.at(0); ext = p.at(1); } // *.csd,*.csb -> *.csd;*.csb std::replace(ext.begin(), ext.end(), ',', ';'); wcscat(buff + offset, (WCHAR*)descr.c_str()); wcscat(buff + offset, L" ("); wcscat(buff + offset, (WCHAR*)ext.c_str()); wcscat(buff + offset, L")"); offset += descr.length() + ext.length() + 4; wcscat(buff + offset, (WCHAR*)ext.c_str()); offset += ext.length() + 1; } return buff; }
void test_split() { printf("Testing split ...\n"); List_Pointer a = init(10); print(a); List_Pointer b = split2(a); print(b); print(a); printf("\n"); }
int main(int argc,char *argv[]){ int size = 0; char **result = split2(" new and delete cannot resize, because they allocate just enough memory to hold an object of the given type. The size of a given type will never change. There are new[] and delete[] but there's hardly ever a reason to use them. ",' ',size); printf("%d\n",size); int i = 0; for(i=0; i<size;++i){ printf("%s\n",result[i]); } }
void FrameInfo::split3() { int idx, len; split2(); if (!_description.isEmpty()) { idx = _description.find(Options::fieldDelimiter, 0); if (idx != -1) { len = idx++; if (_description.length() - idx == 3) _language = _description.substr(idx, 3).data(DEF_TSTR_ENC); _description = _description.substr(0, len); } } }
void game :: show_keys(string mod){ confload f; f.init("keys.txt"); //auto s = f.getstring("keys_" + mod); auto s = f.getstring("keys_" + mod.substr(5)); //msg(s); //auto s = f.getstring(mod); //msg(s); msg("[CONTROLS]"); auto v = split2(s,";"); for (auto&a : v) { msg(a); } }
TEST(TestTransaction, shouldAddSplitIntoAccount) { //given AccountPtr account(new Account()); SplitPtr split1(new Split()); SplitPtr split2(new Split()); //when account->addSplit(split1); account->addSplit(split2); //then const Splits& splits = account->getSplits(); ASSERT_EQ(2, splits.size()); ASSERT_EQ(split1, splits[0]); ASSERT_EQ(split2, splits[1]); }
int main(){ int test = 123; int numDigits = 3; int result[numDigits]; //test method 1 split(test,numDigits,result); for(int i=0;i<numDigits;i++){ printf("%d",result[i]); } //test method 2 char result2[numDigits]; split2(test,numDigits,result2); for(int i=0;i<numDigits;i++){ printf("%c",result2[i]); } }
void FDSMesh::SetKnotValuesFromFile(const std::string &filename) { ///open File (reading) std::ifstream pFile(filename); if (pFile) { std::vector<std::string> strVec; std::string line; ///skip two lines std::getline(pFile, line); std::getline(pFile, line); std::getline(pFile, line); //std::cout << line << std::endl; /// to avoid multiple reading of the header and mesh setting //if (statHeaderRead==false) //{ /// read header strVec = split2(line,',', strVec); double cellsize = std::stod(strVec[0]); double xmin = std::stod(strVec[2]); double xmax = std::stod(strVec[3]); double ymin = std::stod(strVec[4]); double ymax = std::stod(strVec[5]); strVec.clear(); //std::cout << "xmin=" << xmin << " , xmax=" << xmax << " , ymin=" << ymin << ", ymax=" << ymax << " , dx=" << cellsize << std::endl; SetUpMesh(xmin,ymin,xmax,ymax,cellsize); //statHeaderRead=true; //} //Read matrix ReadMatrix(line, pFile); } else { Log->Write("ERROR:\tCould not open FDS slicefile: %s",filename.c_str()); //return false; exit(EXIT_FAILURE); } }
void Shape::drawAvailable(vector<Line> available, vector<Point> demand, ShadowBuffer& sb, Color c) { for (int j=0; j<demand.size()-1; j+=2) { vector<Line> newAvailable; for (int i= 0; i < available.size(); i++ ) { if (available[i].getPoint2().x<=available[i].getPoint1().x) { //sudah tidak ada slot } else if ((available[i].getPoint1().x <= demand[j].x) && (demand[j+1].x <= available[i].getPoint2().x)) { //demand berada di tengah Line split1(available[i].getPoint1(), Point(demand[j].x-1, available[i].getPoint1().y,0)); Line split2(Point(demand[j+1].x+1,available[i].getPoint2().y,0), available[i].getPoint2()); newAvailable.push_back(split1); newAvailable.push_back(split2); Line line(demand[j], demand[j+1]); line.color = c; line.draw(sb, line.getPoint1(), line.getPoint1().getDistance(line.getPoint2()), line.color, Color(line.color.r - 50, line.color.g - 50, line.color.b - 50)); } else if (available[i].getPoint1().x <= demand[j].x) { //demand lebih banyak kebelakang Line split(available[i].getPoint1(), Point(demand[j].x-1, available[i].getPoint1().y,0)); newAvailable.push_back(split); Line line(demand[j], Point(available[i].getPoint2().x,demand[j].y,0)); line.color = c; line.draw(sb, line.getPoint1(), line.getPoint1().getDistance(line.getPoint2()), line.color, Color(line.color.r - 50, line.color.g - 50, line.color.b - 50)); } else if (demand[j+1].x <= available[i].getPoint2().x) { //demand lebih banyak di depan Line split(Point(demand[j+1].x+1,available[i].getPoint2().y,0), available[i].getPoint2()); Line line(Point(available[i].getPoint1().x,demand[j+1].y,0),demand[j+1]); line.color = c; line.draw(sb, line.getPoint1(), line.getPoint1().getDistance(line.getPoint2()), line.color, Color(line.color.r - 50, line.color.g - 50, line.color.b - 50)); newAvailable.push_back(split); } else { newAvailable.push_back(available[i]); } } //available.clear(); available = newAvailable; //update info available //Available.push_back(newAvailable); } }
//Splits the address and the TAC void split1(char* line) { char *tokens,*lineNo; int n=0; printf("%s",line); tokens=strtok(line,":"); while(tokens!=NULL) { if(n==0) lineNo=tokens; else line=tokens; n++; tokens=strtok(NULL,":"); } //printf("No: %s\t",lineNo); //printf("Line: %s",line); split2(lineNo,line); }
FrameInfo::FrameInfo(const char *id, ID3v2FrameID fid, const char *text) : _id(id), _fid(fid), _text(text, DEF_TSTR_ENC), _description(), _language("XXX"), _data() { switch (_fid) { case FID3_APIC: { IFile file(text); const char *mimetype; if (!file.isOpen()) break; mimetype = FileIO::mimetype(text); if (strstr(mimetype, "image") == NULL) { warn("%s: Wrong mime-type: %s. Not an image, not attached.", text, mimetype); break; } file.read(_data); if (file.error()) _data.clear(); else _description = mimetype; break; } case FID3_COMM: case FID3_USLT: split3(); break; case FID3_TXXX: case FID3_WXXX: split2(); break; default: break; } }
/** Split a string into substrings based a splitting character. The splitting characters are discarded as are empty strings otherwise produced by \ref split(). \param s String to split. \param p Character indicating split positions. \return Substrings. */ inline PDAL_DLL std::vector<std::string> split2(const std::string& s, char tChar) { auto pred = [tChar](char c){ return(c == tChar); }; return split2(s, pred); }
int main(int argc, char **argv) { intmax_t bytecnti; long scale; int ch; char *ep, *p; setlocale(LC_ALL, ""); while ((ch = getopt(argc, argv, "0123456789a:b:l:n:p:")) != -1) switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* * Undocumented kludge: split was originally designed * to take a number after a dash. */ if (numlines == 0) { p = argv[optind - 1]; if (p[0] == '-' && p[1] == ch && !p[2]) numlines = strtol(++p, &ep, 10); else numlines = strtol(argv[optind] + 1, &ep, 10); if (numlines <= 0 || *ep) errx(EX_USAGE, "%s: illegal line count", optarg); } break; case 'a': /* Suffix length */ if ((sufflen = strtol(optarg, &ep, 10)) <= 0 || *ep) errx(EX_USAGE, "%s: illegal suffix length", optarg); break; case 'b': /* Byte count. */ errno = 0; if ((bytecnti = strtoimax(optarg, &ep, 10)) <= 0 || strchr("kKmMgG", *ep) == NULL || errno != 0) errx(EX_USAGE, "%s: illegal byte count", optarg); if (*ep == 'k' || *ep == 'K') scale = 1024; else if (*ep == 'm' || *ep == 'M') scale = 1024 * 1024; else if (*ep == 'g' || *ep == 'G') scale = 1024 * 1024 * 1024; else scale = 1; if (bytecnti > OFF_MAX / scale) errx(EX_USAGE, "%s: offset too large", optarg); bytecnt = (off_t)(bytecnti * scale); break; case 'l': /* Line count. */ if (numlines != 0) usage(); if ((numlines = strtol(optarg, &ep, 10)) <= 0 || *ep) errx(EX_USAGE, "%s: illegal line count", optarg); break; case 'n': /* Chunks. */ if (!isdigit((unsigned char)optarg[0]) || (chunks = (size_t)strtoul(optarg, &ep, 10)) == 0 || *ep != '\0') { errx(EX_USAGE, "%s: illegal number of chunks", optarg); } break; case 'p': /* pattern matching. */ if (regcomp(&rgx, optarg, REG_EXTENDED|REG_NOSUB) != 0) errx(EX_USAGE, "%s: illegal regexp", optarg); pflag = 1; break; default: usage(); } argv += optind; argc -= optind; if (*argv != NULL) { /* Input file. */ if (strcmp(*argv, "-") == 0) ifd = STDIN_FILENO; else if ((ifd = open(*argv, O_RDONLY, 0)) < 0) err(EX_NOINPUT, "%s", *argv); ++argv; } if (*argv != NULL) /* File name prefix. */ if (strlcpy(fname, *argv++, sizeof(fname)) >= sizeof(fname)) errx(EX_USAGE, "file name prefix is too long"); if (*argv != NULL) usage(); if (strlen(fname) + (unsigned long)sufflen >= sizeof(fname)) errx(EX_USAGE, "suffix is too long"); if (pflag && (numlines != 0 || bytecnt != 0 || chunks != 0)) usage(); if (numlines == 0) numlines = DEFLINE; else if (bytecnt != 0 || chunks != 0) usage(); if (bytecnt && chunks) usage(); if (ifd == -1) /* Stdin by default. */ ifd = 0; if (bytecnt) { split1(); exit (0); } else if (chunks) { split3(); exit (0); } split2(); if (pflag) regfree(&rgx); exit(0); }
int main(int argc, char*argv[]) { // ████████ INITS 1 ████████ #ifndef COMMON_INITS1 cfg.init("bedlab.cfg"); ui2::init_ui(); Vec2i windowsize; Vec2i screen_resolution = { int(VideoMode::getDesktopMode().width), int(VideoMode::getDesktopMode().height) }; if (cfg.getvar<int>("auto_winsize")) { auto window_scale = cfg.getvar<Vec2>("window_scale"); windowsize = Vec2i(scal(Vec2(screen_resolution), window_scale)); } else { windowsize = cfg.getvar<Vec2i>("windowsize"); } winsize = Vec2(windowsize); //UI.init_console(); // ALWAYS AFTER SO IT CAN GET WINDOW SIZE ui2::init_console(); // ALWAYS AFTER SO IT CAN GET WINDOW SIZE wincenter = 0.5f*Vec2(windowsize); Vec2i windowpos; VideoMode::getDesktopMode().height; if (cfg.getvar<int>("stick_left")) { windowpos = Vec2i( screen_resolution.x - windowsize.x - 10, screen_resolution.y - windowsize.y - 40 ); } else windowpos = (Vec2i(5, 25)); sf::RenderWindow window(sf::VideoMode(windowsize.x, windowsize.y), "bedlab!", 7 //,sf::ContextSettings(0, 0, 1) ); window.setFramerateLimit(cfg.getvar<int>("fps_max")); frame_duration = 1.0f / cfg.getvar<int>("fps_max"); window.setPosition(windowpos); vector<string> keys; auto choice = cfg.getstr("app"); // show_keys(cfg.getstr("app"), keys); #endif // ████████ INITS2 ████████ #ifndef COMMON_INITS2 // we don't have a class/interface/struct with data, everything is local to this function, like a classic stack that all programs are anyway. // Texture cursor_tx; // if (!cursor_tx.loadFromFile(cfg.getstr("cursor"))) // cout << "did not load cursor" << endl; // Sprite cursor; // cursor.setTexture(cursor_tx); // cursor.setOrigin(3, 3); CircleShape cursor = mkcircle({ 0,0 }, Color::Transparent, 3, 1); Color background = cfg.getvar<Color>("background"); window.setMouseCursorVisible(false); Vec2 mpos; bool leftclicked = false, rightclicked = false; // view and zoom View view, ui_view; ui_view = view = window.getDefaultView(); float zoomlevel = 1; Vec2 mpos_abs; float frame_duration = 1.0f / cfg.getvar<int>("fps_max"); #endif // COMMON_INITS2 // ████████ APP ACTUAL ████████ float smaller_size = min(windowsize.y, windowsize.x); string descriptor; Transform transf; transf.translate(10, 10); transf.scale(Vec2(smaller_size, smaller_size)); transf_glob = transf; auto addvt_col = [&](Vec2 v, Color col) { glob_vert_single.append(Vertex(transf.transformPoint(v), col)); }; auto va_to_va_col = [&](mesh2d&idxd_v, Color col) { for (unsigned int i = 0; i < idxd_v.size(); ++i) { // if (i<) addvt_col(idxd_v[i].first, col); addvt_col(idxd_v[i].second, col); //addpt(idxd_v[i].first, Orange, 5); //addpt(idxd_v[i].second, Cyan, 5); } for (auto&a : idxd_v.verts) { addpt_col(a, col, 2); } }; auto stripify = [&](vector<Vec2> strip, Color col) { glob_vert_single = VertexArray(LineStrip); for (auto&a : strip) { glob_vert_single.append(Vertex(transf.transformPoint(a), col)); addpt_col(a, col, 2); } }; size_t edit_mode = 1; // ████████████████████████████████████████ sf::Sound sound; auto make_segment = [](int size, int amplitude) { vector<Int16> sample; for (int i = 0; i < size; ++i) { sample.push_back(amplitude*sin(float(i)*PI*2.0f)); } return sample; }; /* <Jonny> duration will be sample count * sample rate <Jonny> so at 44khz you'll have 44k samples per second <Jonny> if you have 88k samples that will last 2 second */ plot_bare pl; float sample_rate = 22050; auto make_tone = [&](float duration, float frequency, int amplitude_exp) { float sample_quantity = sample_rate * duration; vector<Int16> sample; int amplitude = 1 << amplitude_exp; float increment = frequency / sample_rate; float x = 0; for (int i = 0; i < sample_quantity; ++i){ sample.push_back(amplitude*sin(float(x)*PI*2.0f)); x += increment; } return sample; }; // http://sol.gfxile.net/interpolation/ auto make_tone_progressive_2 = [&](float duration, float frequency, int amplitude_exp) { float sample_quantity = sample_rate * duration; vector<Int16> sample; int amplitude = 1 << amplitude_exp; float increment = frequency / sample_rate; float x = 0; for (int i = 0; i < sample_quantity; ++i) { float soft = float(i) / sample_quantity; //soft = 1 - (1 - 2 * soft)*(1 - 2 * soft)*(1 - 2 * soft)*(1 - 2 * soft); soft = 1 - (1 - 2 * soft)*(1 - 2 * soft); soft *= amplitude; sample.push_back(soft*sin(float(x)*PI*2.0f)); x += increment; } return sample; }; auto make_tone_progressive_4 = [&](float duration, float frequency, int amplitude_exp) { float sample_quantity = sample_rate * duration; vector<Int16> sample; int amplitude = 1 << amplitude_exp; float increment = frequency / sample_rate; float x = 0; for (int i = 0; i < sample_quantity; ++i) { float soft = float(i) / sample_quantity; soft = 1 - (1 - 2 * soft)*(1 - 2 * soft)*(1 - 2 * soft)*(1 - 2 * soft); soft *= amplitude; sample.push_back(soft*sin(float(x)*PI*2.0f)); x += increment; } return sample; }; auto make_tone_progressive_6 = [&](float duration, float frequency, int amplitude_exp) { float sample_quantity = sample_rate * duration; vector<Int16> sample; int amplitude = 1 << amplitude_exp; float increment = frequency / sample_rate; float x = 0; for (int i = 0; i < sample_quantity; ++i) { float soft = float(i) / sample_quantity; soft = 1 - (1 - 2 * soft)*(1 - 2 * soft)*(1 - 2 * soft)*(1 - 2 * soft)*(1 - 2 * soft)*(1 - 2 * soft); soft *= amplitude; sample.push_back(soft*sin(float(x)*PI*2.0f)); x += increment; } return sample; }; auto sample_string2 = cfg.getstr("sound1"); auto spl1 = splitdelim(sample_string2, ','); auto params2 = splitdelim(spl1[0]); //float freq = parse<float>(params[1]); //float duration = parse<float>(params[2]); //float amplitude_exp = parse<float>(params[3]); float freq, duration, amplitude_exp, pause; int times, smoothstep_exp; dip_bars dbars(FONT, FONTSIZE, {400,20}); //dbars.add("sampling", &sampling,5, 10000); dbars.add("sample_rate", &sample_rate, 1000, 45000); dbars.add("freq", &freq,50,5000); dbars.add("duration", &duration, 0.5, 5); dbars.add("amplitude_exp", &litude_exp, 1, 14); SoundBuffer buffer; // always lived! auto load_sample2 = [&](){ auto delaystr = splitdelim(spl1[1]); vector<float> segment_sizes; float total = 0; for (auto&a : delaystr) { total += parse<float>(a); segment_sizes.push_back(parse<float>(a)); } int i = 0; vector<Int16> sample; vector<vector<Int16>> samples; for (auto&a : segment_sizes) a /= total; //for (auto&a : segment_sizes) msg(a*total); for (auto&a : segment_sizes){ auto scaled_back = duration * freq * a; int amplitude = i % 2 ? 0 : 1 << int(amplitude_exp); msg(scaled_back); samples.push_back(make_segment(scaled_back, amplitude)); ++i; } for (auto&a : samples){ concatenate(sample, a); } SoundBuffer buffer; // \param sampleRate Sample rate (number of samples to play per second) buffer.loadFromSamples(&sample[0], sample.size(), 1, sample.size()/duration); { // plut josting just plotting vector<Vec2> plot_this; int i = 0; for (auto&a : sample) { //plot_this.push_back({ float(i), 200 * float(a) / (1 << 12) }); plot_this.push_back({ float(i), float(a) }); i++; } pl.clear(); pl.from_data_normalized(plot_this); } return buffer; }; auto load_sample = [&]() { auto delaystr = splitdelim(spl1[1]); vector<float> segment_sizes; float total = 0; for (auto&a : delaystr) { total += parse<float>(a); segment_sizes.push_back(parse<float>(a)); } int i = 0; vector<Int16> sample; vector<vector<Int16>> samples; for (auto&a : segment_sizes) a /= total; //for (auto&a : segment_sizes) msg(a*total); if (smoothstep_exp == 2) { for (auto&a : segment_sizes) { samples.push_back(make_tone_progressive_2(duration*a, freq, i % 2 ? 0 : int(amplitude_exp))); ++i; } } else if (smoothstep_exp == 4){ for (auto&a : segment_sizes) { samples.push_back(make_tone_progressive_4(duration*a, freq, i % 2 ? 0 : int(amplitude_exp))); ++i; } } for (auto&a : samples) { concatenate(sample, a); } SoundBuffer buffer; // \param sampleRate Sample rate (number of samples to play per second) //sample = make_tone(2, 400, 8); //buffer.loadFromSamples(&sample[0], sample.size(), 1, sample.size() / duration); buffer.loadFromSamples(&sample[0], sample.size(), 1, sample.size() / duration); if (true) { // plut josting just plotting vector<Vec2> plot_this; int i = 0; for (auto&a : sample) { //plot_this.push_back({ float(i), 200 * float(a) / (1 << 12) }); plot_this.push_back({ float(i), float(a) }); i++; } pl.clear(); pl.from_data_normalized(plot_this); } return buffer; }; auto load_from_cfg = [ &freq, &duration, &litude_exp, &pause, ×, &descriptor, &smoothstep_exp]() { auto temp_cfg = configfile(); temp_cfg.init("bedlab.cfg"); auto sample_string = temp_cfg.getstr("sound2"); auto things = split2(sample_string, ","); auto params = split2(things[0], " "); auto segments = split2(things[1], " "); string segments_dashed = things[1]; if (segments_dashed[0] == ' ') segments_dashed = segments_dashed.substr(1); if (things[1][0] == ' ') things[1] = things[1].substr(1); if (things[2][0] == ' ') things[2] = things[2].substr(1); if (things[3][0] == ' ') things[3] = things[3].substr(1); if (things[4][0] == ' ') things[4] = things[4].substr(1); for (auto&c : segments_dashed) { if (c == ' ') c = '-'; } freq = parse<float>(params[0]); duration = parse<float>(params[1]); amplitude_exp = parse<float>(params[2]); pause = parse<float>(things[2]); times = parse<int>(things[3]); smoothstep_exp = parse<int>(things[4]); msgs(smoothstep_exp); descriptor = params[0] // freq + "_" + params[1] // duration + "_" + params[2] // amplitude_exp + "_" + segments_dashed + "_" + things[2] // pause + "_" + things[3] // times + "_" + things[4] // smoothstep_exp ; msgs(descriptor); return segments; }; auto segments = load_from_cfg(); auto flexible_expanse = [&]() { vector<float> segment_sizes, segment_concat; for (auto&a : segments) { segment_sizes.push_back(parse<float>(a)); } segment_sizes.push_back(pause); for (int i = 0; i < times; ++i) { concatenate(segment_concat, segment_sizes); } float total = 0; for (auto&a : segment_concat) total+=a; for (auto&a : segment_concat) a /= total; vector<vector<Int16>> samples; int i = 0; if (smoothstep_exp == 2) { for (auto&a : segment_concat) { samples.push_back(make_tone_progressive_2(duration*a, freq, i % 2 ? 0 : int(amplitude_exp))); ++i; } } else if (smoothstep_exp == 4) { for (auto&a : segment_concat) { samples.push_back(make_tone_progressive_4(duration*a, freq, i % 2 ? 0 : int(amplitude_exp))); ++i; } } else if (smoothstep_exp == 6) { for (auto&a : segment_concat) { samples.push_back(make_tone_progressive_6(duration*a, freq, i % 2 ? 0 : int(amplitude_exp))); ++i; } } vector<Int16> sample; for (auto&a : samples) { concatenate(sample, a); } SoundBuffer buffer; //buffer.loadFromSamples(&sample[0], sample.size(), 1, sample.size() / duration); buffer.loadFromSamples(&sample[0], sample.size(), 1, sample_rate); if (true) { // plut josting just plotting vector<Vec2> plot_this; int i = 0; for (auto&a : sample) { //plot_this.push_back({ float(i), 200 * float(a) / (1 << 12) }); plot_this.push_back({ float(i), float(a) }); i++; } pl.clear(); pl.from_data_normalized(plot_this); } return buffer; }; //buffer = load_sample(sample_string); auto make_sound = [&]() { //buffer = load_sample(); segments = load_from_cfg(); buffer = flexible_expanse(); sound.setBuffer(buffer); string filename = "rngtn_" + descriptor+".wav"; //buffer.saveToFile("file.wav"); buffer.saveToFile(filename); sound.play(); }; make_sound(); dbars.read_from_pointers(); // ████████ callbacks ████████ #ifndef LOOP_LAMBDAS draw = [&]() { window.setView(view); //////////////// OBJECTS THAT CAN ZOOMED //////////////// window.draw(glob_vert_single); for (auto&a : glob_pts)window.draw(a); for (auto&a : glob_rects)window.draw(a); for (auto&a : glob_vert)window.draw(a); for (auto&a : glob_texts)window.draw(a); // UI draw, AFTER ui view and BEFORE other draw window.setView(ui_view); //////////////// OBJECTS THAT CANNOT ZOOMED, MEANING UI //////////////// pl.draw(window); dbars.draw(window); //br.drawwithtext(window); UI.draw(window); window.draw(cursor); }; update = [&]() { }; treatkeyevent = [&](Keyboard::Key k) { switch (k) { case Keyboard::E: break; case Keyboard::I: break; case Keyboard::Q: break; case Keyboard::BackSpace: glob_pts.clear(); glob_texts.clear(); glob_rects.clear(); glob_vert.clear(); break; case Keyboard::Space: make_sound(); sound.play(); sound.setLoop(false); break; case Keyboard::S: screenshot(window); break; case Keyboard::Num1: case Keyboard::Num2: case Keyboard::Num3: case Keyboard::Num4: case Keyboard::Num5: break; } }; mousemoved = [&](Vec2 pos) { cursor.setPosition(pos); if (leftclicked); dbars.mouse_moved(pos); }; mouseclick = [&](sf::Mouse::Button button) { if (button == Mouse::Button::Left) leftclicked = true; if (button == Mouse::Button::Right) rightclicked = true; if (button == Mouse::Button::Left) dbars.mouse_click(mpos); }; mouserelease = [&](sf::Mouse::Button button) { if (button == Mouse::Button::Left) leftclicked = false; if (button == Mouse::Button::Right) rightclicked = false; if (button == Mouse::Button::Left) { dbars.mouse_release(); make_sound(); } }; loop = [&]() { while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { switch (event.type) { case sf::Event::KeyPressed: if (event.key.code == sf::Keyboard::Escape) window.close(); treatkeyevent(event.key.code); break; case sf::Event::Closed: window.close(); break; case sf::Event::MouseButtonPressed: mouseclick(event.mouseButton.button); break; case sf::Event::MouseButtonReleased: mouserelease(event.mouseButton.button); break; case sf::Event::MouseMoved: mpos = Vec2(event.mouseMove.x, event.mouseMove.y); mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view); mousemoved(mpos); break; default: treatotherevent(event); break; } } window.clear(background); update(); draw(); window.display(); } }; treatotherevent = [&](Event&e) { if (e.type == Event::MouseWheelMoved && e.mouseWheel.delta) { mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view); //view = window.getView(); if (e.mouseWheel.delta < 0) { zoomlevel *= 2.f; view.setSize(view.getSize()*2.f); view.setCenter(interp(mpos_abs, view.getCenter(), 2.f)); //view.setCenter(interp(mpos_abs, view.getCenter(), 2.f)); } if (e.mouseWheel.delta > 0) { zoomlevel *= 0.5; view.setSize(view.getSize()*.5f); view.setCenter(.5f*(view.getCenter() + mpos_abs)); //view.setCenter(.5f*(view.getCenter() + mpos_abs)); } window.setView(view); } }; #endif // LOOP_LAMBDAS loop(); }
void Tokenize(const string& str, vector<string>& tokens, const char& delimiter, const char& delimiter2) { split2(tokens, str, delimiter, delimiter2); }
/* analyze triangles and split if needed */ static int anaelt(pMesh mesh,pSol met,char typchk) { pTria pt; pPoint ppt,p1,p2; Hash hash; Bezier pb; pGeom go; double s,o[3],no[3],to[3],dd,len; int vx[3],i,j,ip,ip1,ip2,ier,k,ns,nc,nt; char i1,i2; static double uv[3][2] = { {0.5,0.5}, {0.,0.5}, {0.5,0.} }; hashNew(&hash,mesh->np); ns = 0; s = 0.5; for (k=1; k<=mesh->nt; k++) { pt = &mesh->tria[k]; if ( !MS_EOK(pt) || pt->ref < 0 ) continue; if ( MS_SIN(pt->tag[0]) || MS_SIN(pt->tag[1]) || MS_SIN(pt->tag[2]) ) continue; /* check element cut */ pt->flag = 0; if ( typchk == 1 ) { if ( !chkedg(mesh,k) ) continue; } else if ( typchk == 2 ) { for (i=0; i<3; i++) { i1 = inxt[i]; i2 = iprv[i]; len = lenedg(mesh,met,pt->v[i1],pt->v[i2],0); if ( len > LLONG ) MS_SET(pt->flag,i); } if ( !pt->flag ) continue; } ns++; /* geometric support */ ier = bezierCP(mesh,k,&pb); assert(ier); /* scan edges to split */ for (i=0; i<3; i++) { if ( !MS_GET(pt->flag,i) ) continue; i1 = inxt[i]; i2 = iprv[i]; ip1 = pt->v[i1]; ip2 = pt->v[i2]; ip = hashGet(&hash,ip1,ip2); if ( !MS_EDG(pt->tag[i]) && ip > 0 ) continue; /* new point along edge */ ier = bezierInt(&pb,uv[i],o,no,to); if ( !ip ) { ip = newPt(mesh,o,MS_EDG(pt->tag[i]) ? to : no); assert(ip); hashEdge(&hash,ip1,ip2,ip); p1 = &mesh->point[ip1]; p2 = &mesh->point[ip2]; ppt = &mesh->point[ip]; if ( MS_EDG(pt->tag[i]) ) { ++mesh->ng; assert(mesh->ng < mesh->ngmax); ppt->tag = pt->tag[i]; if ( p1->ref == pt->edg[i] || p2->ref == pt->edg[i] ) ppt->ref = pt->edg[i]; ppt->ig = mesh->ng; go = &mesh->geom[mesh->ng]; memcpy(go->n1,no,3*sizeof(double)); dd = go->n1[0]*ppt->n[0] + go->n1[1]*ppt->n[1] + go->n1[2]*ppt->n[2]; ppt->n[0] -= dd*go->n1[0]; ppt->n[1] -= dd*go->n1[1]; ppt->n[2] -= dd*go->n1[2]; dd = ppt->n[0]*ppt->n[0] + ppt->n[1]*ppt->n[1] + ppt->n[2]*ppt->n[2]; if ( dd > EPSD2 ) { dd = 1.0 / sqrt(dd); ppt->n[0] *= dd; ppt->n[1] *= dd; ppt->n[2] *= dd; } } if ( met->m ) { if ( typchk == 1 ) intmet33(mesh,met,ip1,ip2,ip,s); else intmet(mesh,met,k,i,ip,s); } } else if ( pt->tag[i] & MS_GEO ) { ppt = &mesh->point[ip]; go = &mesh->geom[ppt->ig]; memcpy(go->n2,no,3*sizeof(double)); /* a computation of the tangent with respect to these two normals is possible */ ppt->n[0] = go->n1[1]*go->n2[2] - go->n1[2]*go->n2[1]; ppt->n[1] = go->n1[2]*go->n2[0] - go->n1[0]*go->n2[2]; ppt->n[2] = go->n1[0]*go->n2[1] - go->n1[1]*go->n2[0]; dd = ppt->n[0]*ppt->n[0] + ppt->n[1]*ppt->n[1] + ppt->n[2]*ppt->n[2]; if ( dd > EPSD2 ) { dd = 1.0 / sqrt(dd); ppt->n[0] *= dd; ppt->n[1] *= dd; ppt->n[2] *= dd; } } } } if ( !ns ) { free(hash.item); return(ns); } /* step 2. checking if split by adjacent */ for (k=1; k<=mesh->nt; k++) { pt = &mesh->tria[k]; if ( !MS_EOK(pt) || pt->ref < 0 ) continue; else if ( pt->flag == 7 ) continue; /* geometric support */ ier = bezierCP(mesh,k,&pb); assert(ier); nc = 0; for (i=0; i<3; i++) { i1 = inxt[i]; i2 = inxt[i1]; if ( !MS_GET(pt->flag,i) && !MS_SIN(pt->tag[i]) ) { ip = hashGet(&hash,pt->v[i1],pt->v[i2]); if ( ip > 0 ) { MS_SET(pt->flag,i); nc++; if ( pt->tag[i] & MS_GEO ) { /* new point along edge */ ier = bezierInt(&pb,uv[i],o,no,to); assert(ier); ppt = &mesh->point[ip]; go = &mesh->geom[ppt->ig]; memcpy(go->n2,no,3*sizeof(double)); /* a computation of the tangent with respect to these two normals is possible */ ppt->n[0] = go->n1[1]*go->n2[2] - go->n1[2]*go->n2[1]; ppt->n[1] = go->n1[2]*go->n2[0] - go->n1[0]*go->n2[2]; ppt->n[2] = go->n1[0]*go->n2[1] - go->n1[1]*go->n2[0]; dd = ppt->n[0]*ppt->n[0] + ppt->n[1]*ppt->n[1] + ppt->n[2]*ppt->n[2]; if ( dd > EPSD2 ) { dd = 1.0 / sqrt(dd); ppt->n[0] *= dd; ppt->n[1] *= dd; ppt->n[2] *= dd; } } } } } if ( nc > 0 ) ++ns; } if ( info.ddebug && ns ) { fprintf(stdout," %d analyzed %d proposed\n",mesh->nt,ns); fflush(stdout); } /* step 3. splitting */ ns = 0; nt = mesh->nt; for (k=1; k<=nt; k++) { pt = &mesh->tria[k]; if ( !MS_EOK(pt) || pt->ref < 0 ) continue; else if ( pt->flag == 0 ) continue; j = -1; vx[0] = vx[1] = vx[2] = 0; for (i=0; i<3; i++) { i1 = inxt[i]; i2 = inxt[i1]; if ( MS_GET(pt->flag,i) ) { vx[i] = hashGet(&hash,pt->v[i1],pt->v[i2]); assert(vx[i]); j = i; } } if ( pt->flag == 1 || pt->flag == 2 || pt->flag == 4 ) { ier = split1(mesh,met,k,j,vx); assert(ier); ns++; } else if ( pt->flag == 7 ) { ier = split3(mesh,met,k,vx); assert(ier); ns++; } else { ier = split2(mesh,met,k,vx); assert(ier); ns++; } } if ( (info.ddebug || abs(info.imprim) > 5) && ns > 0 ) fprintf(stdout," %7d splitted\n",ns); free(hash.item); return(ns); }
void BuildingType::loadRules(INIFile* rules) { INISection* rulesSection = rules->getSection(ID); if (!rulesSection) return; TechnoType::loadRules(rules); rulesSection->readStringValue("ToTile", ToTile, ToTile); rulesSection->readBoolValue("HasSpotlight", HasSpotlight, HasSpotlight); rulesSection->readStringValue("HalfDamageSmokeLocation1", HalfDamageSmokeLocation1_str, HalfDamageSmokeLocation1_str); LineSplitter split(HalfDamageSmokeLocation1_str); HalfDamageSmokeLocation1.x = split.pop_int(); HalfDamageSmokeLocation1.y = split.pop_int(); HalfDamageSmokeLocation1.z = split.pop_int(); rulesSection->readStringValue("HalfDamageSmokeLocation2", HalfDamageSmokeLocation2_str, HalfDamageSmokeLocation2_str); LineSplitter split2(HalfDamageSmokeLocation2_str); HalfDamageSmokeLocation2.x = split2.pop_int(); HalfDamageSmokeLocation2.y = split2.pop_int(); HalfDamageSmokeLocation2.z = split2.pop_int(); rulesSection->readBoolValue("WaterBound", WaterBound, WaterBound); rulesSection->readBoolValue("Powered", Powered, Powered); rulesSection->readIntValue("RefinerySmokeFrames", RefinerySmokeFrames, RefinerySmokeFrames); rulesSection->readBoolValue("Wall", Wall, Wall); VehicleType::Array.findOrAllocate(FreeUnit); rulesSection->readBoolValue("IsPlug", IsPlug); InfantryType::Array.findOrAllocate(SecretInfantry); VehicleType::Array.findOrAllocate(SecretUnit); BuildingType::Array.findOrAllocate(SecretBuilding); rulesSection->readBoolValue("Gate", Gate); rulesSection->readBoolValue("LaserFencePost", LaserFencePost); rulesSection->readBoolValue("LaserFence", LaserFence); rulesSection->readBoolValue("FirestormWall", FirestormWall); rulesSection->readStringValue("PowersUpBuilding", PowersUpBuilding); rulesSection->readIntValue("PowersUpToLevel", PowersUpToLevel); rulesSection->readIntValue("Power", Power); rulesSection->readIntValue("ExtraPower", ExtraPower); rulesSection->readStringValue("TurretAnim", TurretAnim); rulesSection->readStringValue("TurretAnimDamaged", TurretAnimDamaged); rulesSection->readStringValue("TurretAnimGarrisoned", TurretAnimGarrisoned); rulesSection->readIntValue("TurretAnimX", TurretAnimX); rulesSection->readIntValue("TurretAnimY", TurretAnimY); rulesSection->readIntValue("TurretAnimZAdjust", TurretAnimZAdjust); rulesSection->readIntValue("TurretAnimYSort", TurretAnimYSort); rulesSection->readBoolValue("TurretAnimPowered", TurretAnimPowered); rulesSection->readBoolValue("TurretAnimPoweredLight", TurretAnimPoweredLight); rulesSection->readBoolValue("TurretAnimPoweredEffect", TurretAnimPoweredEffect); rulesSection->readBoolValue("TurretAnimPoweredSpecial", TurretAnimPoweredSpecial); rulesSection->readBoolValue("TurretAnimIsVoxel", TurretAnimIsVoxel); rulesSection->readStringValue("VoxelBarrelFile", VoxelBarrelFile); rulesSection->readStringValue("VoxelBarrelOffsetToRotatePivotPoint", VoxelBarrelOffsetToRotatePivotPoint_str); LineSplitter split3(VoxelBarrelOffsetToRotatePivotPoint_str); VoxelBarrelOffsetToRotatePivotPoint.x = split3.pop_int(); VoxelBarrelOffsetToRotatePivotPoint.y = split3.pop_int(); VoxelBarrelOffsetToRotatePivotPoint.z = split3.pop_int(); rulesSection->readStringValue("VoxelBarrelOffsetToBuildingPivotPoint", VoxelBarrelOffsetToBuildingPivotPoint_str); LineSplitter split4(VoxelBarrelOffsetToBuildingPivotPoint_str); VoxelBarrelOffsetToBuildingPivotPoint.x = split4.pop_int(); VoxelBarrelOffsetToBuildingPivotPoint.y = split4.pop_int(); VoxelBarrelOffsetToBuildingPivotPoint.z = split4.pop_int(); rulesSection->readStringValue("VoxelBarrelOffsetToPitchPivotPoint", VoxelBarrelOffsetToPitchPivotPoint_str); LineSplitter split5(VoxelBarrelOffsetToPitchPivotPoint_str); VoxelBarrelOffsetToPitchPivotPoint.x = split5.pop_int(); VoxelBarrelOffsetToPitchPivotPoint.y = split5.pop_int(); VoxelBarrelOffsetToPitchPivotPoint.z = split5.pop_int(); rulesSection->readStringValue("VoxelBarrelOffsetToBarrelEnd", VoxelBarrelOffsetToBarrelEnd_str); LineSplitter split6(VoxelBarrelOffsetToBarrelEnd_str); VoxelBarrelOffsetToBarrelEnd.x = split6.pop_int(); VoxelBarrelOffsetToBarrelEnd.y = split6.pop_int(); VoxelBarrelOffsetToBarrelEnd.z = split6.pop_int(); rulesSection->readIntValue("Upgrades", Upgrades, Upgrades); }
int main(int argc, char *argv[]) { int ch, scale; char *ep, *p; const char *errstr; while ((ch = getopt(argc, argv, "0123456789a:b:l:p:-")) != -1) switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* * Undocumented kludge: split was originally designed * to take a number after a dash. */ if (numlines == 0) { p = argv[optind - 1]; if (p[0] == '-' && p[1] == ch && !p[2]) numlines = strtol(++p, &ep, 10); else numlines = strtol(argv[optind] + 1, &ep, 10); if (numlines <= 0 || *ep) errx(EX_USAGE, "%s: illegal line count", optarg); } break; case '-': /* Undocumented: historic stdin flag. */ if (ifd != -1) usage(); ifd = 0; break; case 'a': /* suffix length. */ sufflen = strtonum(optarg, 1, NAME_MAX, &errstr); if (errstr) errx(EX_USAGE, "%s: %s", optarg, errstr); break; case 'b': /* Byte count. */ if ((bytecnt = strtol(optarg, &ep, 10)) <= 0 || (*ep != '\0' && *ep != 'k' && *ep != 'm')) errx(EX_USAGE, "%s: illegal byte count", optarg); if (*ep == 'k') scale = 1024; else if (*ep == 'm') scale = 1048576; else scale = 1; if (bytecnt > SSIZE_MAX / scale) errx(EX_USAGE, "%s: byte count too large", optarg); bytecnt *= scale; break; case 'p' : /* pattern matching. */ if (regcomp(&rgx, optarg, REG_EXTENDED|REG_NOSUB) != 0) errx(EX_USAGE, "%s: illegal regexp", optarg); pflag = 1; break; case 'l': /* Line count. */ if (numlines != 0) usage(); if ((numlines = strtol(optarg, &ep, 10)) <= 0 || *ep) errx(EX_USAGE, "%s: illegal line count", optarg); break; default: usage(); } argv += optind; argc -= optind; if (*argv != NULL) if (ifd == -1) { /* Input file. */ if ((ifd = open(*argv, O_RDONLY, 0)) < 0) err(EX_NOINPUT, "%s", *argv); ++argv; } if (*argv != NULL) /* File name prefix. */ (void)strlcpy(fname, *argv++, sizeof(fname)); if (*argv != NULL) usage(); if (strlen(fname) + sufflen >= sizeof(fname)) errx(EX_USAGE, "suffix is too long"); if (pflag && (numlines != 0 || bytecnt != 0)) usage(); if (numlines == 0) numlines = DEFLINE; else if (bytecnt != 0) usage(); if (ifd == -1) /* Stdin by default. */ ifd = 0; if (bytecnt) { split1(); exit (0); } split2(); if (pflag) regfree(&rgx); exit(0); }