void Halftone_TX::enable_lod_only_correction(int layer_num) { halftone_layer_t* layer = get_layer(layer_num); assert(layer); if (layer->_use_lod_only) { disable_lod_only_correction(layer_num); } enable_tone_correction(layer_num); //need this first if (layer->_mode !=1 && layer->_mode !=2) { cerr << "Unknown layer mode, can't setup tone correction " << endl; return; } // look if the r function map has been already creaed for // this layer's texture stage somewhere else bool used = false; for (vector<layer_base_t*>::size_type i=0; i<_layers.size(); i++) { halftone_layer_t* layer_i = get_layer(layer_num); if (layer_i->_use_lod_only && layer_i->_pattern_tex_stage == layer->_pattern_tex_stage) { used = true; layer->_r_function_tex_stage = layer_i->_r_function_tex_stage; layer->_use_lod_only = true; if (debug) cerr << "Layer " << i << " already has this texture so we will share " << endl; break; } } if (!used) { //create r function map for this stage GLint tex_stage = get_free_tex_stage(); r_function_maps[tex_stage] = make_shared<TEXTUREgl>( "", GL_TEXTURE_2D, GL_TEXTURE0 + tex_stage ); r_function_maps[tex_stage]->set_save_img(); r_function_maps[tex_stage]->set_wrap_r(GL_CLAMP_TO_EDGE); r_function_maps[tex_stage]->set_wrap_s(GL_CLAMP_TO_EDGE); // it's a 1D texture really: r_function_maps[tex_stage]->image().resize(CORR_RES,1,4); if (layer->_mode == 1) build_r_function_tex(r_function_maps[tex_stage], _patterns[layer->_pattern_tex_stage]); if (layer->_mode == 2) build_r_function_tex(r_function_maps[tex_stage],nullptr); layer->_r_function_tex_stage = tex_stage; layer->_use_lod_only = true; } }
int LayerIcon::get_zpos() const { if(!is_valid()) { return std::numeric_limits<int>::min(); } if (is_tilemap) { //When the layer is a tilemap, the class is obvious. return (static_cast<TileMap*>(layer))->get_layer(); } auto bkgrd = dynamic_cast<Background*>(layer); if (bkgrd) { return bkgrd->get_layer(); } auto grd = dynamic_cast<Gradient*>(layer); if (grd) { return grd->get_layer(); } auto ps = dynamic_cast<ParticleSystem*>(layer); if (ps) { return ps->get_layer(); } auto psi = dynamic_cast<ParticleSystem_Interactive*>(layer); if (psi) { return psi->get_layer(); } return std::numeric_limits<int>::min(); }
void Halftone_TX::disable_tone_correction(int layer_num) { halftone_layer_t* layer = get_layer(layer_num); assert(layer); //disable tone correction if(!layer->_use_tone_correction) return; layer->_use_tone_correction=false; GLint tex_stage = layer->_tone_correction_tex_stage; bool used = false; for (vector<layer_base_t*>::size_type i=0; i<_layers.size(); i++) { halftone_layer_t* layer_i = get_layer(i); if (layer_i->_use_tone_correction && layer_i->_tone_correction_tex_stage == tex_stage) used = true; } if (!used) { if (debug) cerr << "Recycling texture stage " << tex_stage << " back to unused and mopping up the details.. " << endl; free_tex_stage(tex_stage); tone_correction_maps.erase(tex_stage); layer->_tone_correction_tex_stage = 0; } else { layer->_tone_correction_tex_stage = 0; } }
/** * \brief Do one iteration in the progression of the item. */ void bear::reflecting_decoration::progress( universe::time_type elapsed_time ) { super::progress(elapsed_time); m_items_list.clear(); std::list<universe::physical_item*> items; if ( get_layer().has_world() ) { bear::universe::item_picking_filter filter; filter.set_fixed_value(false); get_layer().get_world().pick_items_in_rectangle ( items, get_bounding_box(), filter); std::list<universe::physical_item*>::iterator it; for ( it = items.begin(); it != items.end(); ++it ) { engine::base_item* item = dynamic_cast<engine::base_item*>(*it); if ( (item != NULL) && (item != this) ) m_items_list.push_back(item_handle(*it)); } } } // reflecting_decoration::progress()
void initialize() override { set_layers(sf::Vector2f(15,-5), sf::Vector2f(90,-30), sf::Vector2f(15, -5)); get_layer(0).shadow_color = sf::Color(100, 100, 0); get_layer(1).shadow_color = sf::Color(100, 100, 0); get_layer(0).background = sf::Color(200, 100, 50); //get_layer(0).background = sf::Color::White; }
void initialize() override { set_layers(sf::Vector2f(5,-5), sf::Vector2f(30,-30), sf::Vector2f(5, -5)); get_layer(0).shadow_color = sf::Color(128, 128, 128); get_layer(1).shadow_color = sf::Color(128, 128, 218); get_layer(0).background = sf::Color(200, 200, 255); //get_layer(0).background = sf::Color::White; }
/** * \brief Makes the hero leave this raised crystal block if possible. * \param hero the hero * \param collision_box destination wanted for the jump * \param jump_direction direction of the jump * \param jump_length length of the jump * \return true if the jump was done, i.e. if the collision box was overlapping * no obstacle and no raised crystal block. */ bool CrystalBlock::try_jump(Hero& hero, const Rectangle& collision_box, int jump_direction, int jump_length) { // jump if there is no collision and no other raised crystal blocks if (!get_map().test_collision_with_obstacles(get_layer(), collision_box, hero) && !get_entities().overlaps_raised_blocks(get_layer(), collision_box)) { hero.start_jumping(jump_direction, jump_length, true, false); Sound::play("hero_lands"); return true; } return false; }
/** * \brief Create the margins on the top the level. * \param screen_size The size of the screen. */ void ptb::layer_border::create_top_margin ( const claw::math::coordinate_2d<unsigned int>& screen_size ) { const bear::universe::size_type max_x = get_layer().get_size().x; const bear::universe::size_type width = screen_size.x; const bear::universe::size_type y = get_layer().get_size().y - m_block_width; bear::universe::coordinate_type x = 0; for ( ; x < max_x - width; x += width ) new_align_block( x, y, width, m_block_width, "bottom" ); if ( max_x != x ) new_align_block( x, y, max_x - x, m_block_width, "bottom" ); } // layer_border::create_top_margin()
/** * \brief Scan if there is a player in a given direction. * \param origin The position from which we start watching. * \param dir The direction in which the gorilla looks. * \param distance The distance of scan. */ bool ptb::gorilla::scan_no_wall_in_direction ( const bear::universe::position_type& origin, const bear::universe::vector_type& dir, bear::universe::coordinate_type distance ) const { bear::universe::item_picking_filter filter; filter.set_can_move_items_value(true); if ( ( dir.length() <= distance ) && get_layer().has_world() ) return get_layer().get_world().pick_item_in_direction (origin, dir, filter) == NULL; else return false; } // gorilla::scan_no_wall_in_direction()
/** * \brief Destroys the item while it is being thrown. */ void CarriedItem::break_item() { if (is_throwing && throwing_direction != 3) { // destroy the item where it is actually drawn set_y(get_y() - item_height); } get_movement()->stop(); if (!can_explode()) { if (!destruction_sound_id.empty()) { Sound::play(destruction_sound_id); } if (get_sprite().has_animation("destroy")) { get_sprite().set_current_animation("destroy"); } else { remove_from_map(); } } else { get_entities().add_entity(std::make_shared<Explosion>( "", get_layer(), get_xy(), true )); Sound::play("explosion"); if (is_throwing) { remove_from_map(); // because if the item was still carried by the hero, then the hero class will destroy it } } is_throwing = false; is_breaking = true; }
void Halftone_TX::activate_layer_textures() { GLSLShader_Layer_Base::activate_layer_textures(); for (vector<layer_base_t*>::size_type i=0; i<_layers.size(); i++) { //main tone correction map halftone_layer_t* layer = get_layer(i); if (layer->_use_tone_correction) { if (!activate_texture( tone_correction_maps[layer->_tone_correction_tex_stage]) ) cerr << class_name() << ": can't activate tone correction texture at stage: " << layer->_tone_correction_tex_stage << endl; } // forward R function if (layer->_use_lod_only) { if (!activate_texture(r_function_maps[layer->_r_function_tex_stage])) cerr << class_name() << ": can't activate R function texture at stage: " << layer->_r_function_tex_loc << endl; } } }
void QcMapView::set_opacity(const QcWmtsPluginLayer * plugin_layer, float opacity) { QcMapViewLayer * layer = get_layer(plugin_layer); if (layer) layer->set_opacity(opacity); }
void Instrument::unload_samples() { for ( int i=0; i<MAX_LAYERS; i++ ) { InstrumentLayer* layer = get_layer( i ); if( layer ) layer->unload_sample(); } }
void step_detach_widget() { MyGUI::Widget* widget = get_random(all_widgets); if (!widget) return; widget->detachFromWidget(get_layer()); test_widgets(); }
void Instrument::save_to( XMLNode* node ) { XMLNode instrument_node = node->ownerDocument().createElement( "instrument" ); instrument_node.write_int( "id", __id ); instrument_node.write_string( "name", __name ); instrument_node.write_float( "volume", __volume ); instrument_node.write_bool( "isMuted", __muted ); instrument_node.write_float( "pan_L", __pan_l ); instrument_node.write_float( "pan_R", __pan_r ); instrument_node.write_float( "randomPitchFactor", __random_pitch_factor ); instrument_node.write_float( "gain", __gain ); instrument_node.write_bool( "filterActive", __filter_active ); instrument_node.write_float( "filterCutoff", __filter_cutoff ); instrument_node.write_float( "filterResonance", __filter_resonance ); instrument_node.write_float( "Attack", __adsr->get_attack() ); instrument_node.write_float( "Decay", __adsr->get_decay() ); instrument_node.write_float( "Sustain", __adsr->get_sustain() ); instrument_node.write_float( "Release", __adsr->get_release() ); instrument_node.write_int( "muteGroup", __mute_group ); instrument_node.write_int( "midiOutChannel", __midi_out_channel ); instrument_node.write_int( "midiOutNote", __midi_out_note ); instrument_node.write_bool( "isStopNote", __stop_notes ); for ( int i=0; i<MAX_FX; i++ ) { instrument_node.write_float( QString( "FX%1Level" ).arg( i+1 ), __fx_level[i] ); } for ( int n = 0; n < MAX_LAYERS; n++ ) { InstrumentLayer* layer = get_layer( n ); if( layer ) { layer->save_to( &instrument_node ); } } node->appendChild( instrument_node ); }
/** * \brief Initialize a slope. * \param slope A reference to the pointer of the slope. * \param s The steepness. * \param z The z position of the slope. */ void rp::switching::init_slope( bear::slope*& slope, double s, int z ) { if ( slope == NULL ) { slope = new bear::slope; if ( s < 0 ) slope->set_size( get_width(), get_height() / 2 ); else slope->set_size( get_size() ); const double effective_steepness = get_rendering_attributes().is_mirrored() ? -s : s; slope->set_bottom_left( get_bottom_left() ); slope->set_steepness( effective_steepness ); slope->set_top_friction( 0.95 ); slope->set_max_z_for_collision( z + 100 ); slope->set_z_position(z); slope->set_z_shift(100); slope->set_force_z_position(true); new_item(*slope); } else get_layer().add_item(*slope); } // rp::switching::init_slope()
/* functie care roteste un strat al cubului rubik in orice directie */ void Rubik::rotate_layer (int layer, float speed) { Point3d center; std::vector<int> to_move = get_layer(layer); for (int i = 0; i < to_move.size(); i++) { if (layer == LEFT || layer == RIGHT) { rotateX(to_move[i], cs->axiscenter, speed); } if (layer == TOP || layer == BOTTOM) { rotateY(to_move[i], cs->axiscenter, speed); } if (layer == BACK || layer == FRONT) { rotateZ(to_move[i], cs->axiscenter, speed); } if (layer == CENTER_X) { rotateY(to_move[i], cs->axiscenter, speed); } if (layer == CENTER_Y) { rotateX(to_move[i], cs->axiscenter, speed); } if (layer == CENTER_Z) { rotateZ(to_move[i], cs->axiscenter, speed); } } }
/** * @brief This function is called when some stairs detect a collision with this entity. * @param stairs the stairs entity * @param collision_mode the collision mode that detected the event */ void CarriedItem::notify_collision_with_stairs(Stairs &stairs, CollisionMode collision_mode) { if (is_throwing && !is_breaking && stairs.is_inside_floor() && get_layer() == LAYER_LOW) { break_on_intermediate_layer = true; // show the destruction animation above the stairs } }
decltype(auto) dropout_wrapper_test() { //std::random_device rd; //std::mt19937 rand(rd()); std::mt19937 rand(0); // fixed initial vector auto input_dim = 2u; auto output_dim = 1u; auto batch_size = 4u; std::vector<neu::cpu_vector> cpu_input = { {0.f, 0.f}, {1.f, 0.f}, {0.f, 1.f}, {1.f, 1.f} }; std::vector<neu::cpu_vector> cpu_teach = { {0.f}, {1.f}, {1.f}, {0.f} }; neu::gpu_vector input; for(auto const& cpui : cpu_input) { input.insert(input.end(), cpui.begin(), cpui.end()); } neu::gpu_vector teach; for(auto const& cput : cpu_teach) { teach.insert(teach.end(), cput.begin(), cput.end()); } auto fc = neu::make_full_connected_layer( input_dim, output_dim, batch_size, neu::rectifier()); fc.init_weight_randomly( [&rand, bin=std::uniform_real_distribution<>(0.f, 1.f)]() mutable { return bin(rand); }); std::cout << "weight "; neu::print(fc.get_weight()); std::cout << std::endl; auto dfc = neu::make_dropout_wrapper(fc, 0.9f, rand); std::cout << "weight "; neu::print(dfc.get_layer().get_weight()); std::cout << std::endl; neu::layer_calc_u_and_y(dfc, input); auto y = neu::layer_get_y(dfc); std::cout << "y "; neu::print(y); neu::gpu_vector errors(y.size()); boost::compute::transform(y.begin(), y.end(), teach.begin(), errors.begin(), boost::compute::minus<neu::scalar>()); neu::layer_calc_delta(dfc, errors); neu::layer_update_delta_weight(dfc, input); neu::layer_update_weight(dfc); auto weight = neu::layer_get_weight(dfc.get_layer()); std::cout << "updated weight"; neu::print(weight); }
/** * \brief Makes the bomb explode. */ void Bomb::explode() { get_entities().add_entity(std::make_shared<Explosion>( "", get_layer(), get_center_point(), true )); Sound::play("explosion"); remove_from_map(); }
/** * \brief Get the default thumb of the mini-game. */ bear::visual::sprite ptb::frame_play_story::get_default_thumb() const { bear::engine::level_globals& glob = get_layer().get_level().get_globals(); const bear::visual::image& img = glob.get_image( "gfx/thumb/none.png" ); return bear::visual::sprite( img ); } // frame_play_story::get_default_thumb()
/** * \brief Creates an explosion on this object. */ void Destructible::explode() { get_entities().add_entity(std::make_shared<Explosion>( "", get_layer(), get_xy(), true )); Sound::play("explosion"); get_lua_context().destructible_on_exploded(*this); }
/** * @brief This function is called when the layer of this entity has just changed. * * Redefine it if you need to be notified. */ void CustomEnemy::notify_layer_changed() { Enemy::notify_layer_changed(); if (!is_being_hurt()) { script->event_layer_changed(get_layer()); } }
float QcMapView::opacity(const QcWmtsPluginLayer * plugin_layer) { QcMapViewLayer * layer = get_layer(plugin_layer); if (layer) return layer->opacity(); else return .0; }
/** * \brief This function is called when some stairs detect a collision with this entity. * \param stairs the stairs entity * \param collision_mode the collision mode that detected the event */ void CarriedItem::notify_collision_with_stairs(Stairs& stairs, CollisionMode /* collision_mode */) { if (is_throwing && !is_breaking && stairs.is_inside_floor() && get_layer() == stairs.get_layer()) { break_one_layer_above = true; // show the destruction animation above the stairs } }
/** * \brief Create the static text components. */ void ptb::frame_play_story::create_controls() { m_thumb = new bear::gui::picture( get_default_thumb() ); m_name_text = new bear::gui::scene_element(); m_status_picture = new bear::gui::picture( get_status_picture() ); get_content().insert( m_thumb ); get_content().insert( m_name_text ); get_content().insert( m_status_picture ); m_second_player_status.energy = new horizontal_gauge ( get_layer().get_level().get_globals(), 100, "bar (light blue)", "bar (red)", "heart", true ); m_first_player_status.energy = new horizontal_gauge ( get_layer().get_level().get_globals(), 100, "bar (green)", "bar (red)", "heart", true ); create_player_component(m_first_player_status); create_player_component(m_second_player_status); create_bonus_component(); bear::gui::visual_component* ok = create_ok_button(); bear::gui::visual_component* back = create_back_button(); bear::gui::visual_component* previous = create_previous_button(); bear::gui::visual_component* next = create_next_button(); position_controls( ok->top() + get_margin() ); bear::gui::size_type sum_w ( 3 * get_margin() + ok->width() + back->width() + previous->width() + next->width() ); const bear::gui::size_type w ( (m_bonus->width() + m_thumb->width() + 2*get_margin() - sum_w) / 3); back->set_left( ok->right() + w ); previous->set_left( back->right() + w ); next->set_right( m_status_picture->right() ); ok->set_focus(); fit( get_margin() ); } // frame_play_story::create_controls()
/** * \brief Come back to the title screen. */ void ptb::frame_pause::on_title_screen() { m_msg_result = message_box::s_ok | message_box::s_cancel; message_box* msg = new message_box ( &get_layer(), gettext("Are you sure you want to leave this level?"), &m_msg_result ); show_window(msg); } // frame_pause::on_title_screen()
/** * \brief Get the status picture of the mini-game. */ bear::visual::sprite ptb::frame_play_story::get_status_picture() const { std::string medal("none"); if ( !m_levels.empty() ) medal = m_levels[m_index].get_medal_name(); return get_layer().get_level().get_globals().auto_sprite ( "gfx/mini-game/medal.png", medal ); } // frame_play_story::get_thumb()
bool Shader::add(OSL::ShadingSystem& shading_system) { for (each<ShaderParamContainer> i = impl->m_params; i; ++i) { if (!i->add(shading_system)) return false; } // For some reason, OSL only supports the surface shader usage. // So, we ignore the user shader type specified in the XML file, // and hardcode "surface" here. TODO: research this... //if (!shading_system.Shader(get_type(), get_shader(), get_layer())) if (!shading_system.Shader("surface", get_shader(), get_layer())) { RENDERER_LOG_ERROR("error adding shader %s, %s.", get_shader(), get_layer()); return false; } return true; }
/** * \brief Set position of controls for player's informations. * \param p The object containing all player's information controls. */ void ptb::frame_play_story::player_status_position_controls ( player_status& p ) { bear::engine::level_globals& glob = get_layer().get_level().get_globals(); p.energy->set_size (p.component->get_size().x - 2 * get_margin(), (p.component->get_size().y - 4*get_margin()) / 3); p.energy->set_bottom_left( get_margin(), get_margin()); bear::visual::sprite s0(glob.auto_sprite("gfx/ui/status/status.png", "plee")); p.lives_picture->set_size(s0.get_size()); p.lives_picture->set_bottom_left ( get_margin(), p.energy->top() + get_margin()); p.lives_text->set_size (p.component->get_size().x / 2 - p.lives_picture->width() - get_margin(), (p.component->get_size().y - 4*get_margin()) / 3); p.lives_text->set_top_left (p.lives_picture->right() + get_margin(), p.lives_picture->top()); p.score_text->set_size (p.component->get_size().x / 2, (p.component->get_size().y - 4*get_margin()) / 3); p.score_text->set_bottom_left ( get_margin(), p.lives_picture->top()+get_margin()); bear::visual::sprite s1(glob.get_image("gfx/ui/air-power.png")); p.air_power->set_size(s1.get_size()); p.air_power->set_top_left (p.score_text->right() + get_margin(), p.score_text->top()); p.fire_power->set_size(s1.get_size()); p.fire_power->set_top_left (p.air_power->right() + get_margin(), p.score_text->top()); p.water_power->set_size(s1.get_size()); p.water_power->set_top_left (p.fire_power->right() + get_margin(), p.score_text->top()); bear::visual::sprite s2 (glob.auto_sprite("gfx/stone/stone.png", "default stone")); p.stone_picture->set_size(s2.get_size()); p.stone_picture->set_bottom_left (p.lives_text->right() + get_margin(), p.lives_text->bottom()); p.stone_text->set_size (p.component->get_size().x / 2, (p.component->get_size().y - 4*get_margin()) / 3); p.stone_text->set_top_left ( p.stone_picture->right() + get_margin(), p.stone_picture->top()); } // frame_play_story::player_status_position_controls