void Player::drawHud(sf::RenderWindow& rw) const { static bool firstRun = true; static sf::Font font; if(firstRun) { firstRun = false; font.LoadFromFile("silesiana.otf", 50, L"A�BC�DE�FGHIJKL�MN�O�PRS�TUWYZ��a�bc�de�fghijkl�mn�o�prs�tuwyz��XxVvQq0123456789~!@#$%^&*()_-[]\\;',./{}:\"<>?=-+ "); } sf::Sprite hud(hudimg, sf::Vector2f(0, 350)); rw.Draw(hud); int hbarheight= health * hbarimg.GetHeight(); sf::Sprite hbar(hbarimg, sf::Vector2f(42, 376 + hbarimg.GetHeight() - hbarheight)); hbar.SetSubRect(sf::IntRect(0, hbarimg.GetHeight() - hbarheight, hbarimg.GetWidth(), hbarimg.GetHeight())); rw.Draw(hbar); std::wstring str; for(int i=0;i<4;i++) { if(i<msgList.size()) str += msgList[i] + L"\n"; } sf::String msgs(str, font, 30); msgs.SetColor(sf::Color(120, 10, 10)); msgs.SetPosition(200, 450); rw.Draw(msgs); }
void exec( ) throw( general_error ) { iec61853_module_t solver; msg_handler msgs( *this ); solver._imsg = &msgs; util::matrix_t<double> input = as_matrix("input"), par; if ( input.ncols() != iec61853_module_t::COL_MAX ) throw exec_error( "iec61853", "six data columns required for input matrix: IRR,TC,PMP,VMP,VOC,ISC"); if (!solver.calculate( input, as_integer("nser"), as_integer("type"), par, as_boolean("verbose") )) throw exec_error( "iec61853", "failed to solve for parameters"); assign("n", var_data((ssc_number_t)solver.n)); assign("alphaIsc", var_data((ssc_number_t)solver.alphaIsc)); assign("betaVoc", var_data((ssc_number_t)solver.betaVoc)); assign( "gammaPmp", var_data((ssc_number_t)solver.gammaPmp) ); assign( "Il", var_data((ssc_number_t)solver.Il) ); assign( "Io", var_data((ssc_number_t)solver.Io) ); assign( "C1", var_data((ssc_number_t)solver.C1) ); assign( "C2", var_data((ssc_number_t)solver.C2) ); assign( "C3", var_data((ssc_number_t)solver.C3) ); assign( "D1", var_data((ssc_number_t)solver.D1) ); assign( "D2", var_data((ssc_number_t)solver.D2) ); assign( "D3", var_data((ssc_number_t)solver.D3) ); assign( "Egref", var_data((ssc_number_t)solver.Egref) ); ssc_number_t *output = allocate( "output", par.nrows(), par.ncols() ); size_t c = 0; for( size_t i=0;i<par.nrows();i++ ) for( size_t j=0;j<par.ncols();j++ ) output[c++] = (ssc_number_t)par(i, j); }
int main() { auto loggy = to_vector2("fds2", 3, 14.43f); //auto loggy = to_str("2",3,14.f); for (auto&a : loggy) msgs(a); //vector<string> a = {strfy(args)...}; system("PAUSE"); return 0; }
int Executor::submit(mltools::Message *msg) { CHECK(msg); CHECK(msg->recver_.size()); Lock l(nodeMu_); int ts = msg->task_.has_time() ? msg->task_.time() : (time_ + 1); msg->task_.set_time(ts); msg->task_.set_request(true); msg->task_.set_customer_id(obj_.id()); time_ = ts; auto &reqInfo = sentReqs_[ts]; reqInfo.recver_ = msg->recver_; if (msg->callback) { reqInfo.callback_ = msg->callback; } // slice *msg* RemoteNode *rnode = getRNode(msg->recver_); std::vector<Message *> msgs(rnode->keys_.size()); for (auto &m : msgs) { m = new Message(msg->task_); } obj_.slice(*msg, rnode->keys_, &msgs); CHECK_EQ(msgs.size(), rnode->group_.size()); // sent out message one by one for (int i = 0; i < msgs.size(); ++i) { RemoteNode *r = CHECK_NOTNULL(rnode->group_[i]); Message *m = msgs[i]; if (!m->valid_) { r->sentReqTracker_.finish(ts); continue; } r->encodeMessage(m); m->recver_ = r->node_.id(); sys_.Queue(m); } return ts; }
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(); }
int SrsForwarder::forward() { int ret = ERROR_SUCCESS; client->set_recv_timeout(SRS_PULSE_TIMEOUT_US); SrsPithyPrint pithy_print(SRS_STAGE_FORWARDER); SrsSharedPtrMessageArray msgs(SYS_MAX_FORWARD_SEND_MSGS); while (pthread->can_loop()) { // switch to other st-threads. st_usleep(0); pithy_print.elapse(); // read from client. if (true) { SrsMessage* msg = NULL; ret = client->recv_message(&msg); srs_verbose("play loop recv message. ret=%d", ret); if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) { srs_error("recv server control message failed. ret=%d", ret); return ret; } srs_freep(msg); } // forward all messages. int count = 0; if ((ret = queue->dump_packets(msgs.size, msgs.msgs, count)) != ERROR_SUCCESS) { srs_error("get message to forward failed. ret=%d", ret); return ret; } // pithy print if (pithy_print.can_print()) { kbps->sample(); srs_trace("-> "SRS_LOG_ID_FOWARDER " time=%"PRId64", msgs=%d, okbps=%d,%d,%d, ikbps=%d,%d,%d", pithy_print.age(), count, kbps->get_send_kbps(), kbps->get_send_kbps_30s(), kbps->get_send_kbps_5m(), kbps->get_recv_kbps(), kbps->get_recv_kbps_30s(), kbps->get_recv_kbps_5m()); } // ignore when no messages. if (count <= 0) { srs_verbose("no packets to forward."); continue; } // all msgs to forward. // @remark, becareful, all msgs must be free explicitly, // free by send_and_free_message or srs_freep. for (int i = 0; i < count; i++) { SrsSharedPtrMessage* msg = msgs.msgs[i]; srs_assert(msg); msgs.msgs[i] = NULL; if ((ret = client->send_and_free_message(msg, stream_id)) != ERROR_SUCCESS) { srs_error("forwarder send message to server failed. ret=%d", ret); return ret; } } } return ret; }
std::vector<typename Machine::State> simulatePortNumberedDDA( const Network& network, const Machine& machine, const std::vector<typename Machine::Input>& inputs, Listener& listener = EmptyListener<Machine>::instance ) { typedef typename Machine::State State; typedef typename Machine::Message Message; std::size_t n = network.size(); if(n != inputs.size()) { throw std::runtime_error( "simulatePortNumberedDDA: Wrong number of inputs given." ); } std::vector<State> states; // Initialize all states from init function. for(std::size_t i = 0; i < n; ++i) { states.emplace_back(machine.init(network[i].size(), inputs[i])); } std::vector<std::vector<Message>> msgs(n); std::size_t round = 0; while(true) { listener.start(round, (const std::vector<State>&)states); // If all states are stopped, we are done. bool done = true; for(const State& state : states) { if(!machine.stopped(state)) { done = false; break; } } if(done) break; // Send all messages. for(std::size_t i = 0; i < n; ++i) { msgs[i].clear(); machine.send(states[i], msgs[i]); if(msgs[i].size() != network[i].size()) { throw std::runtime_error( "simulatePortNumberedDDA: " "'send' function wrote wrong number of messages." ); } } listener.send( round, (const std::vector<State>&)states, (const std::vector<std::vector<Message>>&)msgs ); // Swap messages for each port. for(std::size_t i = 0; i < n; ++i) { for(std::size_t ei = 0; ei < network[i].size(); ++ei) { Edge edge = network[i][ei]; // Swap only once. if(std::make_pair(i, ei) < std::make_pair(edge.dest, edge.back_index)) { continue; } std::swap(msgs[i][ei], msgs[edge.dest][edge.back_index]); } } listener.receive( round, (const std::vector<State>&)states, (const std::vector<std::vector<Message>>&)msgs ); // Receive all messages and update states. for(std::size_t i = 0; i < n; ++i) { states[i] = machine.receive(states[i], msgs[i]); } ++round; } return states; }
// all configurations - > linker -> subsystem = windows //int WinMain() int main(int argc, char*argv[]) { //OutputDebugStringA("f*****g test in main2"); //cout << "f*****g test in main" << endl; //main(); configfile cfg; cfg.init("bedlab.cfg"); 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 wincenter = 0.5f*Vec2(windowsize); //msg(windowsize); Vec2i windowpos; //msg(screen_resolution); VideoMode::getDesktopMode().height; //SET(screen_resolution); if (cfg.getvar<int>("stick_left")) { windowpos = Vec2i(screen_resolution.x - windowsize.x - 10, 25); //msg(screen_resolution); //msg(windowpos); } 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); // add all the app { ADDAPP(smoothmouse); ADDAPP(mokio); ADDAPP(osm); ADDAPP(mousetest); ADDAPP(guns_axes); ADDAPP(nestedgrid); ADDAPP(recoil_test); ADDAPP(splosions); ADDAPP(industrio); ADDAPP(mason); ADDAPP(geomtest); ADDAPP(astar); ADDAPP(quadtree_test2); ADDAPP(springrecoil_test); ADDAPP(mine_solver); ADDAPP(sound_test); ADDAPP(clock_system_test); ADDAPP(populio); ADDAPP(simpleplot); ADDAPP(citynet); ADDAPP(bag); ADDAPP(delaun_distr); ADDAPP(spellmech); ADDAPP(short_tests); ADDAPP(geomtests); ADDAPP(tests_path); ADDAPP(test_perlin); ADDAPP(checkers_box); ADDAPP(swarming); ADDAPP(citynet2); ADDAPP(testbed); ADDAPP(geomtest_orient); ADDAPP(holosight); ADDAPP(recoil_simul); ADDAPP(recoil_spring); ADDAPP(bar_bump); ADDAPP(masonette); ADDAPP(mild_tests); ADDAPP(perlin_plain); /* ADDAPP(phone_pattern); ADDAPP(guns_test); ADDAPP(triangul); // just re add triangul.cpp to the project! ADDAPP(quadtree_test); ADDAPP(balldemo); apps["smoothmouse"] = smoothmouse(window,UI); ADDAPP(guns_test); ADDAPP(kdtree); */ } //{ // configfile descr_file; // descr_file.init("demo_descr.txt"); // set<string> avail; // for (auto&a : descr_file.dict) avail.insert(a.first); // for(auto&app :apps) // { // if (descr_file.dict.count(app.first)) // { // avail.erase(app.first); // } // } // for (auto&a : avail) // { // msgs("not loaded " + a); // } //} auto dont_load = cfg.getlist("dont_load"); for (auto&a : dont_load) { apps.erase(a); } //for (auto&a : dont_load) dont_load_these.insert(a); //auto dont_load_these = split2(dont_load," "); // read the string s = cfg.getstr("app"); if (cfg.getvar<int>("use_menu") == 1) { while (1) { string choice = appchooser(window, UI)(); //int i = 432; msgs("chosen " + choice); if (choice != "none") apps[choice](); else { break; } } } else { if (s == "") { msgs("######## error in config, app was not found! ########"); return -2; } if (!apps.count(s)) { msgs("######## app " + s + " not found! ######## "); throw runtime_error(string("app " + s + " not found!")); return -2; } vector<string> keys; auto choice = cfg.getstr("app"); show_keys(cfg.getstr("app"), keys); msgs(choice); for (auto&a : keys) msgs(a); apps[cfg.getstr("app")](); } return 0; }
void mrbig(void) { char *p; time_t t, lastrun; int sleeptime, i; char hostname[256]; DWORD hostsize; /* * install exception logging/stacktrace handler. * We need to resolve the symbol at run time because windows 2000 * does not have it. */ do { HMODULE dll; PVOID (*ptr) (ULONG First,PVECTORED_EXCEPTION_HANDLER Handler) = NULL; dll = LoadLibraryEx("kernel32.dll", NULL, 0); if (dll == NULL) break; ptr = (typeof(ptr))GetProcAddress(dll, "AddVectoredExceptionHandler"); if (ptr == NULL) break; ptr(1, VectoredExceptionHandler); mrlog("VectoredExceptionHandler handler has been installed"); } while(0); if (debug) { mrlog("mrbig()"); } for (i = 0; _environ[i]; i++) { startup_log("%s", _environ[i]); } for (;;) { if (debug) mrlog("main loop"); read_cfg("mrbig", cfgfile); readcfg(); t = time(NULL); strlcpy(now, ctime(&t), sizeof now); p = strchr(now, '\n'); if (p) *p = '\0'; hostsize = sizeof hostname; if (GetComputerName(hostname, &hostsize)) { for (i = 0; hostname[i]; i++) hostname[i] = tolower(hostname[i]); snprcat(now, sizeof now, " [%s]", hostname); } cpu(); check_chunks("after cpu test"); disk(); check_chunks("after disk test"); memory(); check_chunks("after memory test"); msgs(); check_chunks("after msgs test"); procs(); check_chunks("after procs test"); svcs(); check_chunks("after svcs test"); wmi(); check_chunks("after wmi test"); if (pickupdir[0]) ext_tests(); lastrun = t; t = time(NULL); if (t < lastrun) { mrlog("mainloop: timewarp detected, sleep for %d", mrloop); sleeptime = mrloop; } else { sleeptime = mrloop-(t-lastrun); } if (sleeptime < SLEEP_MIN) sleeptime = SLEEP_MIN; if (debug) mrlog("started at %d, finished at %d, sleep for %d", (int)lastrun, (int)t, sleeptime); clear_cfg(); if (debug) { dump_chunks(); check_chunks("after main loop"); } Sleep(sleeptime*1000); } }