void scene::set_location(const char *name) { nya_render::texture::set_default_aniso(2); if (!m_curve.is_valid()) { m_curve.create(); load("postprocess.txt"); set_texture("color_curve", m_curve); set_shader_param("screen_radius", nya_math::vec4(1.185185, 0.5 * 4.0 / 3.0, 0.0, 0.0)); set_shader_param("damage_frame", nya_math::vec4(0.35, 0.5, 1.0, 0.1)); m_flare.init(get_texture("main_color"), get_texture("main_depth")); m_cockpit_black.load("shaders/cockpit_black.nsh"); m_cockpit_black_quad.init(); m_missile_trails_renderer.init(); m_particles_render.init(); } if (is_native_location(name)) { auto &zip = get_native_location_provider(name); auto tex = load_texture(zip, "tonecurve.tga"); if (tex.get_width() > 0) { auto rtex = tex.internal().get_shared_data()->tex; rtex.set_wrap(nya_render::texture::wrap_clamp, nya_render::texture::wrap_clamp); m_curve.set(tex); } else m_curve.set(load_tonecurve("Map/tonecurve_default.tcb")); } else { if (m_location_name == "def" || m_location_name.empty()) m_curve.set(load_tonecurve("Map/tonecurve_default.tcb")); else m_curve.set(load_tonecurve(("Map/tonecurve_" + m_location_name + ".tcb").c_str())); } world::set_location(name); for (auto &a: m_aircrafts) a->apply_location(m_location_name.c_str(), m_location.get_params()); m_flare.apply_location(m_location.get_params()); auto &p = m_location.get_params(); set_shader_param("bloom_param", nya_math::vec4(p.hdr.bloom_threshold, p.hdr.bloom_offset, p.hdr.bloom_scale, 1.0)); set_shader_param("saturation", nya_math::vec4(p.tone_saturation * 0.01, 0.0, 0.0, 0.0)); m_luminance_speed = p.hdr.luminance_speed; m_fade_time = m_fade_max_time = 2000; }
int main (int argc, char *argv[]) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "SDL died.\n"); exit(1); } init_screen(); init_data(); status("Waves running..."); int x, y, down = 0; int pause = 0; int brushsize = 32; int fps = 0, frames = 0; int prev_ticks = SDL_GetTicks(); int accel = 1; while (1) { SDL_Event e; if (!pause) { for (int iter = 0 ; iter < accel ; iter++) update(); } draw(); if (fps) { int ticks = SDL_GetTicks(); frames++; if (ticks - prev_ticks >= 1000) { status("Waves: %d FPS", (int)(frames * 1000 / (ticks - prev_ticks))); prev_ticks = ticks; frames = 0; } } while (SDL_PollEvent(&e)) { switch(e.type) { case SDL_VIDEORESIZE: scr_width = e.resize.w; scr_height = e.resize.h; init_screen(); break; case SDL_MOUSEMOTION: x = e.motion.x * WIDTH / scr_width; y = HEIGHT - e.motion.y * HEIGHT / scr_height; break; case SDL_MOUSEBUTTONDOWN: down = e.button.button; break; case SDL_MOUSEBUTTONUP: down = 0; break; case SDL_KEYDOWN: switch(e.key.keysym.sym) { /* case SDLK_MINUS: TRANSFER -= 1; status("Viscosity: %d", TRANSFER); break; */ /* case SDLK_EQUALS: TRANSFER += 1; status("Viscosity: %d", TRANSFER); break; */ /* case SDLK_z: TRANSFER *= -1; status("Viscosity: %d", TRANSFER); break; */ case SDLK_t: BRUSHTYPE = !BRUSHTYPE ; status("Brushtype: %d", BRUSHTYPE); break; case SDLK_s: BRUSHSOFT = !BRUSHSOFT ; status("Brushsoft: %d", BRUSHSOFT); break; case SDLK_a: BRUSHADD = !BRUSHADD ; status("BrushAdd: %d", BRUSHADD); break; case SDLK_f: fps = 1 - fps; status("FPS: %s", fps?"on":"off") break; case SDLK_SEMICOLON: VEL_LIMIT = 4 * VEL_LIMIT / 5; status("VLimit: %d", VEL_LIMIT); break; case SDLK_QUOTE: VEL_LIMIT = 5 * VEL_LIMIT / 4 ; status("VLimit: %d", VEL_LIMIT); break; case SDLK_w: WRAP = 1 - WRAP; if (WRAP) { set_wrap(); } else { set_nowrap(); } status("Wrap: %d", WRAP); break; case SDLK_i: invert(); break; case SDLK_v: invert_vel(); break; case SDLK_r: randomize(); break; case SDLK_n: NONLINEAR = (NONLINEAR + 1) % 2; status("Nonlinear mode: %d", NONLINEAR) break; case SDLK_p: pause = 1 - pause; if(pause) status("Waves Paused") else status("Waves Running") break; case SDLK_SLASH: clear(); clear_vel(); break; case SDLK_PERIOD: clear(); break; case SDLK_COMMA: clear_vel(); break; case SDLK_q: case SDLK_ESCAPE: fullscreen = 0; init_screen(); return(0); break; case SDLK_LEFTBRACKET: brushsize--; status("Brush size: %d", brushsize); break; case SDLK_RIGHTBRACKET: brushsize++; status("Brush size: %d", brushsize); break; case SDLK_F11: DRAG--; status("Drag: %d/1024", DRAG); break; case SDLK_F12: DRAG++; status("Drag: %d/1024", DRAG); break; case SDLK_F1: RAIN--; if (RAIN<0) RAIN=0; status("Rain: %d", RAIN); break; case SDLK_F2: RAIN++; status("Rain: %d", RAIN); break; case SDLK_F3: COLOROFFSET -=8 ; if (COLOROFFSET<0) COLOROFFSET=0; status("ColorOffset: %d", COLOROFFSET); set_palette(); break; case SDLK_F4: COLOROFFSET += 8; if (COLOROFFSET > num_colors - 256) COLOROFFSET = num_colors - 256; status("ColorOffset: %d", COLOROFFSET); set_palette(); break; case SDLK_F9: fullscreen = 1 - fullscreen; init_screen(); break; case SDLK_PAGEUP: accel--; if (accel < 1) accel = 1; status("Accel: %d", accel); break; case SDLK_PAGEDOWN: accel++; status("Accel: %d", accel); break; } break; case SDL_QUIT: fullscreen = 0; init_screen(); return(0); break; } } if (down) { for (int j = y - brushsize ; j < y + brushsize ; j++) { if (j < 0 || j >= HEIGHT) continue; for (int k = x - brushsize ; k < x + brushsize ; k++) { if (k < 0 || k >= WIDTH) continue; float disty = sqrt( ((k-x)*(k-x)) + ((j-y)*(j-y)) ) ; float ity = 1 ; if (BRUSHTYPE == 1) { if (disty>(brushsize) ) continue ; } if (BRUSHSOFT ==1) { ity = 1-(disty/brushsize); } if (down == 1) { if (BRUSHADD==1) { data[WIDTH * j + k] += (256 * 256 *ity) ;} else {data[WIDTH * j + k] = (256 * 256 *ity) ;} if (data[WIDTH * j + k] <0 ||data[WIDTH * j + k] > (256*256) ) { data[WIDTH * j + k] = (256*256);} } else { data[WIDTH * j + k] = 0; v_x[WIDTH * j + k] = 0; v_y[WIDTH * j + k] = 0; } } } } if (RAIN && ((rand() % 100) < RAIN)) { int x = 1 + rand() % (WIDTH - 2); int y = 1 + rand() % (HEIGHT - 2); for (int j = y - brushsize ; j < y + brushsize ; j++) { if (j < 0 || j >= HEIGHT) continue; for (int k = x - brushsize ; k < x + brushsize ; k++) { if (k < 0 || k >= WIDTH) continue; float disty = sqrt( ((k-x)*(k-x)) + ((j-y)*(j-y)) ) ; float ity = 1 ; if (BRUSHTYPE == 1) { if (disty>(brushsize) ) continue ; } if (BRUSHSOFT ==1) { ity = 1-(disty/brushsize); } if (BRUSHADD==1) { data[WIDTH * j + k] += (256 * 256 *ity) ;} else {data[WIDTH * j + k] = (256 * 256 *ity) ;} if (data[WIDTH * j + k] <0 ||data[WIDTH * j + k] > (256*256) ) { data[WIDTH * j + k] = (256*256);} } } } } return 0; }
/* preferred_format: 0=from config, 1=text, 2=html */ void message_view::display_body(const struct display_prefs& prefs, int preferred_format) { if (!m_pmsg) return; if (preferred_format==0) { preferred_format = get_config().get_string("display/body/preferred_format").toLower()=="text" ? 1: 2; } reset_state(); /* First we try to fetch html contents from body.bodyhtml If it's empty, we look for an HTML part (even if we won't load it later) */ attachment* html_attachment; QString body_html = m_pmsg->get_body_html(); // from the body table if (body_html.isEmpty()) html_attachment = m_pmsg->body_html_attached_part(); // from the attachments QString body_text = m_pmsg->get_body_text(true); attachments_list& attchs = m_pmsg->attachments(); if (m_pmsg->has_attachments() > 0) { // Note: don't try to optimize here by removing the fetch: we need // it later for a lot of reasons, and the result is cached. attchs.fetch(); } if (preferred_format==1) { if (body_text.isEmpty()) { if (attchs.size() > 0) { attachments_list::iterator iter; for (iter=attchs.begin(); iter!=attchs.end(); iter++) { if (iter->filename().isEmpty() && iter->mime_type()=="text/plain") { iter->append_decoded_contents(body_text); } } } } } else { // preferred display format=html if (html_attachment && body_html.isEmpty()) { html_attachment->append_decoded_contents(body_html); } } // Format headers mail_displayer disp(this); QString h = disp.sprint_headers(prefs.m_show_headers_level, m_pmsg); QString hmore = disp.sprint_additional_headers(prefs, m_pmsg); h.append(hmore); set_wrap(prefs.m_wrap_lines); m_has_text_part = !body_text.isEmpty(); m_has_html_part = (html_attachment!=NULL || !body_html.isEmpty()); if (preferred_format==1 || body_html.isEmpty()) { QString b2 = disp.text_body_to_html(body_text, prefs); b2.prepend("<html>"); b2.append("</html>"); set_html_contents(h, b2, 1); // partial load? if (m_pmsg->body_length()>0 && m_pmsg->body_fetched_length() < m_pmsg->body_length()) { if (m_parent) { m_headersv->enable_command("complete_load", true); QString msg = QString(tr("Partial load (%1%)")).arg(m_pmsg->body_fetched_length()*100/ m_pmsg->body_length()); m_parent->blip_status_message(msg); } } } else { set_html_contents(h, body_html, 2); } }