Tree @HEAD (Download .tar.gz)
- ..
- achievements.cpp
- achievements.hpp
- animation_creator.cpp
- animation_creator.hpp
- animation_preview_widget.cpp
- animation_preview_widget.hpp
- animation_widget.cpp
- animation_widget.hpp
- Appirater.h
- Appirater.m
- array_callable.hpp
- asserts.cpp
- asserts.hpp
- background.cpp
- background.hpp
- background_task_pool.cpp
- background_task_pool.hpp
- base64.cpp
- base64.hpp
- blur.cpp
- blur.hpp
- border_widget.cpp
- border_widget.hpp
- button.cpp
- button.hpp
- character_editor_dialog.cpp
- character_editor_dialog.hpp
- checkbox.cpp
- checkbox.hpp
- checksum.cpp
- checksum.hpp
- clipboard.cpp
- clipboard.hpp
- CMakeLists.txt
- code_editor_dialog.cpp
- code_editor_dialog.hpp
- code_editor_widget.cpp
- code_editor_widget.hpp
- collision_utils.cpp
- collision_utils.hpp
- color_chart.cpp
- color_chart.hpp
- color_utils.cpp
- color_utils.hpp
- colorshift_hash_table.cpp
- colorshift_hash_table.hpp
- compat.hpp
- compress.cpp
- compress.hpp
- concurrent_cache.hpp
- controls.cpp
- controls.hpp
- controls_dialog.cpp
- controls_dialog.hpp
- current_generator.cpp
- current_generator.hpp
- custom_object.cpp
- custom_object.hpp
- custom_object_callable.cpp
- custom_object_callable.hpp
- custom_object_dialog.cpp
- custom_object_dialog.hpp
- custom_object_functions.cpp
- custom_object_functions.hpp
- custom_object_type.cpp
- custom_object_type.hpp
- debug_console.cpp
- debug_console.hpp
- decimal.cpp
- decimal.hpp
- dialog.cpp
- dialog.hpp
- difficulty.cpp
- difficulty.hpp
- drag_widget.cpp
- drag_widget.hpp
- draw_number.cpp
- draw_number.hpp
- draw_scene.cpp
- draw_scene.hpp
- draw_tile.cpp
- draw_tile.hpp
- dropdown_widget.cpp
- dropdown_widget.hpp
- editor.cpp
- editor.hpp
- editor_dialogs.cpp
- editor_dialogs.hpp
- editor_formula_functions.cpp
- editor_formula_functions.hpp
- editor_layers_dialog.cpp
- editor_layers_dialog.hpp
- editor_level_properties_dialog.cpp
- editor_level_properties_dialog.hpp
- editor_module_properties_dialog.cpp
- editor_module_properties_dialog.hpp
- editor_stats_dialog.cpp
- editor_stats_dialog.hpp
- editor_variable_info.cpp
- editor_variable_info.hpp
- eglport-tegra.c
- eglport.c
- eglport.h
- entity.cpp
- entity.hpp
- entity_fwd.hpp
- external_text_editor.cpp
- external_text_editor.hpp
- file_chooser_dialog.cpp
- file_chooser_dialog.hpp
- filesystem-android.cpp
- filesystem.cpp
- filesystem.hpp
- font.cpp
- font.hpp
- foreach.hpp
- formatter.hpp
- formula.cpp
- formula.hpp
- formula_callable.hpp
- formula_callable_definition.cpp
- formula_callable_definition.hpp
- formula_callable_definition_fwd.hpp
- formula_callable_utils.hpp
- formula_constants.cpp
- formula_constants.hpp
- formula_function.cpp
- formula_function.hpp
- formula_function_registry.cpp
- formula_function_registry.hpp
- formula_fwd.hpp
- formula_profiler.cpp
- formula_profiler.hpp
- formula_test.cpp
- formula_tokenizer.cpp
- formula_tokenizer.hpp
- formula_variable_storage.cpp
- formula_variable_storage.hpp
- frame.cpp
- frame.hpp
- framed_gui_element.cpp
- framed_gui_element.hpp
- frogatto-resouces.rc
- functional.hpp
- game_registry.cpp
- game_registry.hpp
- geometry.cpp
- geometry.hpp
- gles2.cpp
- gles2.hpp
- globals.cpp
- globals.h
- graphical_font.cpp
- graphical_font.hpp
- graphical_font_label.cpp
- graphical_font_label.hpp
- graphics.hpp
- grid_widget.cpp
- grid_widget.hpp
- grid_widget_fwd.hpp
- group_property_editor_dialog.cpp
- group_property_editor_dialog.hpp
- gui_formula_functions.cpp
- gui_formula_functions.hpp
- gui_section.cpp
- gui_section.hpp
- hex_map.cpp
- hex_map.hpp
- hex_object.cpp
- hex_object.hpp
- hex_object_fwd.hpp
- hex_tile.cpp
- hex_tile.hpp
- hex_tileset_editor_dialog.cpp
- hex_tileset_editor_dialog.hpp
- hi_res_timer.hpp
- http_client.cpp
- http_client.hpp
- http_server.cpp
- http_server.hpp
- i18n.cpp
- i18n.hpp
- image_widget.cpp
- image_widget.hpp
- image_widget_fwd.hpp
- IMG_savepng.cpp
- IMG_savepng.h
- input.cpp
- input.hpp
- iphone_controls.cpp
- iphone_controls.hpp
- iphone_device_info.h
- iphone_device_info.m
- iphone_sound.h
- iphone_sound.m
- joystick.cpp
- joystick.hpp
- json_parser.cpp
- json_parser.hpp
- json_tokenizer.cpp
- json_tokenizer.hpp
- key.cpp
- key.hpp
- key_button.cpp
- key_button.hpp
- label.cpp
- label.hpp
- level.cpp
- level.hpp
- level_logic.cpp
- level_logic.hpp
- level_object.cpp
- level_object.hpp
- level_runner.cpp
- level_runner.hpp
- level_solid_map.cpp
- level_solid_map.hpp
- LICENSE
- light.cpp
- light.hpp
- load_level.cpp
- load_level.hpp
- load_level_nothread.cpp
- loading_screen.cpp
- loading_screen.hpp
- main.cpp
- map_utils.hpp
- md5.cpp
- md5.hpp
- message_dialog.cpp
- message_dialog.hpp
- module.cpp
- module.hpp
- module_web_server.cpp
- module_web_server.hpp
- movement_script.cpp
- movement_script.hpp
- multi_tile_pattern.cpp
- multi_tile_pattern.hpp
- multiplayer.cpp
- multiplayer.hpp
- object_events.cpp
- object_events.hpp
- of_bridge.h
- of_bridge.mm
- options_dialog.cpp
- options_dialog.hpp
- particle_system.cpp
- particle_system.hpp
- pathfinding.cpp
- pathfinding.hpp
- pause_game_dialog.cpp
- pause_game_dialog.hpp
- playable_custom_object.cpp
- playable_custom_object.hpp
- player_info.cpp
- player_info.hpp
- point_map.hpp
- poly_line_widget.hpp
- preferences.cpp
- preferences.hpp
- preprocessor.cpp
- preprocessor.hpp
- preview_tileset_widget.cpp
- preview_tileset_widget.hpp
- progress_bar.cpp
- progress_bar.hpp
- property_editor_dialog.cpp
- property_editor_dialog.hpp
- random.cpp
- random.hpp
- raster.cpp
- raster.hpp
- raster_distortion.cpp
- raster_distortion.hpp
- rectangle_rotator.cpp
- rectangle_rotator.hpp
- reference_counted_object.hpp
- regex_utils.hpp
- SampleOFDelegate.h
- SampleOFDelegate.mm
- SConscript
- scoped_resource.hpp
- scrollable_widget.cpp
- scrollable_widget.hpp
- scrollbar_widget.cpp
- scrollbar_widget.hpp
- SDLMain.h
- SDLMain.m
- segment_editor_dialog.cpp
- segment_editor_dialog.hpp
- server.cpp
- settings_dialog.cpp
- settings_dialog.hpp
- shaders.cpp
- shaders.hpp
- simple_wml.cpp
- simple_wml.hpp
- slider.cpp
- slider.hpp
- solid_map.cpp
- solid_map.hpp
- solid_map_fwd.hpp
- sound.cpp
- sound.hpp
- speech_dialog.cpp
- speech_dialog.hpp
- stats.cpp
- stats.hpp
- stats_server.cpp
- stats_server.hpp
- stats_server_main.cpp
- stats_web_server.cpp
- stats_web_server.hpp
- string_utils.cpp
- string_utils.hpp
- surface.cpp
- surface.hpp
- surface_cache.cpp
- surface_cache.hpp
- surface_formula.cpp
- surface_formula.hpp
- surface_palette.cpp
- surface_palette.hpp
- surface_scaling.cpp
- surface_scaling_generated.hpp
- sys.cpp
- sys.hpp
- tbs_ai_player.cpp
- tbs_ai_player.hpp
- tbs_bot.cpp
- tbs_bot.hpp
- tbs_client.cpp
- tbs_client.hpp
- tbs_functions.cpp
- tbs_functions.hpp
- tbs_game.cpp
- tbs_game.hpp
- tbs_server.cpp
- tbs_server.hpp
- tbs_web_server.cpp
- tbs_web_server.hpp
- text_editor_widget.cpp
- text_editor_widget.hpp
- texture.cpp
- texture.hpp
- texture_frame_buffer.cpp
- texture_frame_buffer.hpp
- thread.cpp
- thread.hpp
- tile_map.cpp
- tile_map.hpp
- tileset_editor_dialog.cpp
- tileset_editor_dialog.hpp
- tooltip.cpp
- tooltip.hpp
- translate.cpp
- translate.hpp
- tree_view_widget.cpp
- tree_view_widget.hpp
- unit_test.cpp
- unit_test.hpp
- uri.hpp
- userevents.h
- utility_object_compiler.cpp
- utility_query.cpp
- utility_query.hpp
- utility_render_level.cpp
- utils.cpp
- utils.hpp
- variant.cpp
- variant.hpp
- variant_callable.cpp
- variant_callable.hpp
- variant_utils.cpp
- variant_utils.hpp
- vecmath.hpp
- vector_text.cpp
- vector_text.hpp
- water.cpp
- water.hpp
- water_particle_system.cpp
- water_particle_system.hpp
- weather_particle_system.cpp
- weather_particle_system.hpp
- widget.cpp
- widget.hpp
- widget_factory.cpp
- widget_factory.hpp
- win_profile_timer.hpp
- wm.cpp
- wm.hpp
- wml_formula_callable.cpp
- wml_formula_callable.hpp
weather_particle_system.cpp @HEAD — raw · history · blame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #include <cstdio> #include <math.h> #include <vector> #include "weather_particle_system.hpp" #include "variant_utils.hpp" weather_particle_system_factory::weather_particle_system_factory (variant node) : info(node) { } particle_system_ptr weather_particle_system_factory::create(const entity& e) const { return particle_system_ptr(new weather_particle_system(e, *this)); } weather_particle_system::weather_particle_system(const entity& e, const weather_particle_system_factory& factory) : factory_(factory), info_(factory.info), cycle_(0) { base_velocity = sqrtf(info_.velocity_x*info_.velocity_x + info_.velocity_y*info_.velocity_y); direction[0] = info_.velocity_x / base_velocity; direction[1] = info_.velocity_y / base_velocity; particles_.reserve(info_.number_of_particles); for (int i = 0; i < info_.number_of_particles; i++) { particle new_p; new_p.pos[0] = rand()%info_.repeat_period; new_p.pos[1] = rand()%info_.repeat_period; new_p.velocity = base_velocity + (info_.velocity_rand ? (rand() % info_.velocity_rand) : 0); particles_.push_back(new_p); } } void weather_particle_system::process(const entity& e) { ++cycle_; foreach(particle& p, particles_) { p.pos[0] = static_cast<int>(p.pos[0]+direction[0] * p.velocity) % info_.repeat_period; p.pos[1] = static_cast<int>(p.pos[1]+direction[1] * p.velocity) % info_.repeat_period; } //while (particles_.size() > 1500) particles_.pop_front(); } void weather_particle_system::draw(const rect& area, const entity& e) const { #if !defined(USE_GLES2) glDisable(GL_TEXTURE_2D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); #endif glLineWidth(info_.line_width); glColor4f(info_.rgba[0]/255.0, info_.rgba[1]/255.0, info_.rgba[2]/255.0, info_.rgba[3]/255.0); int offset_x = area.x() - area.x()%info_.repeat_period; if (area.x() < 0) offset_x -= info_.repeat_period; int offset_y = area.y() - area.y()%info_.repeat_period; if (area.y() < 0) offset_y -= info_.repeat_period; static std::vector<GLfloat> vertices; vertices.clear(); foreach(const particle& p, particles_) { float my_y = p.pos[1]+offset_y; do { float my_x = p.pos[0]+offset_x; do { vertices.push_back(my_x); vertices.push_back(my_y); vertices.push_back(my_x+direction[0]*info_.line_length); vertices.push_back(my_y+direction[1]*info_.line_length); my_x += info_.repeat_period; //printf("my_x: %f, area.x: %i, area.w: %i\n", my_x, area.x(), area.w()); } while (my_x < area.x()+area.w()); my_y += info_.repeat_period; } while (my_y < area.y()+area.h()); } #if defined(USE_GLES2) gles2::manager gles2_manager(gles2::get_simple_shader()); gles2::active_shader()->shader()->vertex_array(2, GL_FLOAT, 0, 0, &vertices.front()); #else glVertexPointer(2, GL_FLOAT, 0, &vertices.front()); #endif glDrawArrays(GL_LINES, 0, vertices.size()/2); #if !defined(USE_GLES2) //glDisable(GL_SMOOTH); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_2D); #endif glColor4f(1.0, 1.0, 1.0, 1.0); } variant weather_particle_system::get_value(const std::string& key) const { if(key == "velocity_x") { return variant(decimal(direction[0])); } else if(key == "velocity_y") { return variant(decimal(direction[1])); } else { return variant(); } } void weather_particle_system::set_value(const std::string& key, const variant& value) { if(key == "velocity_x") { direction[0] = value.as_decimal().as_float(); } else if(key == "velocity_y") { direction[1] = value.as_decimal().as_float(); } } |