From 30a69f6d588ea92238f3b758799fed56c12e8628 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Fri, 20 Nov 2009 02:54:23 +0000 Subject: [PATCH] Split particlesystem_interactive.?pp into separate files SVN-Revision: 6062 --- src/object/comet_particle_system.cpp | 88 ++++++++++++++++++ src/object/comet_particle_system.hpp | 56 ++++++++++++ src/object/particlesystem_interactive.cpp | 143 ------------------------------ src/object/particlesystem_interactive.hpp | 63 ------------- src/object/rain_particle_system.cpp | 98 ++++++++++++++++++++ src/object/rain_particle_system.hpp | 55 ++++++++++++ src/supertux/sector.cpp | 25 +++--- src/supertux/title_screen.hpp | 2 +- 8 files changed, 311 insertions(+), 219 deletions(-) create mode 100644 src/object/comet_particle_system.cpp create mode 100644 src/object/comet_particle_system.hpp create mode 100644 src/object/rain_particle_system.cpp create mode 100644 src/object/rain_particle_system.hpp diff --git a/src/object/comet_particle_system.cpp b/src/object/comet_particle_system.cpp new file mode 100644 index 000000000..eb2e37725 --- /dev/null +++ b/src/object/comet_particle_system.cpp @@ -0,0 +1,88 @@ +// SuperTux +// Copyright (C) 2009 Ingo Ruhnke +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "object/comet_particle_system.hpp" + +#include "math/random_generator.hpp" +#include "supertux/globals.hpp" +#include "video/surface.hpp" +#include "util/reader.hpp" + +CometParticleSystem::CometParticleSystem() +{ + cometimages[0] = new Surface("images/creatures/mr_bomb/exploding-left-0.png"); + cometimages[1] = new Surface("images/creatures/mr_bomb/exploding-left-0.png"); + + virtual_width = SCREEN_WIDTH * 2; + + // create some random comets + size_t cometcount = 2; + for(size_t i=0; ipos.x = systemRandom.rand(int(virtual_width)); + particle->pos.y = systemRandom.rand(int(virtual_height)); + int cometsize = systemRandom.rand(2); + particle->texture = cometimages[cometsize]; + do { + particle->speed = (cometsize+1)*30 + systemRandom.randf(3.6); + } while(particle->speed < 1); + particle->speed *= 10; // gravity + + particles.push_back(particle); + } +} + +void +CometParticleSystem::parse(const Reader& reader) +{ + reader.get("z-pos", z_pos); +} + +CometParticleSystem::~CometParticleSystem() +{ + for(int i=0;i<2;++i) + delete cometimages[i]; +} + +void CometParticleSystem::update(float elapsed_time) +{ + (void) elapsed_time; +#if 0 + std::vector::iterator i; + for( + i = particles.begin(); i != particles.end(); ++i) { + CometParticle* particle = (CometParticle*) *i; + float movement = particle->speed * elapsed_time; + float abs_x = Sector::current()->camera->get_translation().x; + float abs_y = Sector::current()->camera->get_translation().y; + particle->pos.y += movement; + particle->pos.x -= movement; + int col = collision(particle, Vector(-movement, movement)); + if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) { + if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)) { + Sector::current()->add_object(new Bomb(particle->pos, LEFT)); + } + int new_x = systemRandom.rand(int(virtual_width)) + int(abs_x); + int new_y = 0; + //FIXME: Don't move particles over solid tiles + particle->pos.x = new_x; + particle->pos.y = new_y; + } + } +#endif +} + +/* EOF */ diff --git a/src/object/comet_particle_system.hpp b/src/object/comet_particle_system.hpp new file mode 100644 index 000000000..7eb7e9c1f --- /dev/null +++ b/src/object/comet_particle_system.hpp @@ -0,0 +1,56 @@ +// SuperTux +// Copyright (C) 2009 Ingo Ruhnke +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_OBJECT_COMET_PARTICLE_SYSTEM_HPP +#define HEADER_SUPERTUX_OBJECT_COMET_PARTICLE_SYSTEM_HPP + +#include "object/particlesystem_interactive.hpp" + +class CometParticleSystem : public ParticleSystem_Interactive +{ +public: + CometParticleSystem(); + virtual ~CometParticleSystem(); + + void parse(const Reader& lisp); + void write(Writer& writer); + + virtual void update(float elapsed_time); + + std::string type() const + { return "CometParticleSystem"; } + +private: + class CometParticle : public Particle + { + public: + float speed; + + CometParticle() : + speed() + {} + }; + + Surface* cometimages[2]; + +private: + CometParticleSystem(const CometParticleSystem&); + CometParticleSystem& operator=(const CometParticleSystem&); +}; + +#endif + +/* EOF */ diff --git a/src/object/particlesystem_interactive.cpp b/src/object/particlesystem_interactive.cpp index e9a28bec7..b31707172 100644 --- a/src/object/particlesystem_interactive.cpp +++ b/src/object/particlesystem_interactive.cpp @@ -17,14 +17,9 @@ #include "object/particlesystem_interactive.hpp" #include "math/aatriangle.hpp" -#include "math/random_generator.hpp" -#include "object/camera.hpp" -#include "object/rainsplash.hpp" #include "object/tilemap.hpp" #include "supertux/collision.hpp" -#include "supertux/globals.hpp" #include "supertux/tile.hpp" -#include "util/reader.hpp" //TODO: Find a way to make rain collide with objects like bonus blocks // Add an option to set rain strength @@ -138,142 +133,4 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement) return 0; } -RainParticleSystem::RainParticleSystem() -{ - rainimages[0] = new Surface("images/objects/particles/rain0.png"); - rainimages[1] = new Surface("images/objects/particles/rain1.png"); - - virtual_width = SCREEN_WIDTH * 2; - - // create some random raindrops - size_t raindropcount = size_t(virtual_width/6.0); - for(size_t i=0; ipos.x = systemRandom.rand(int(virtual_width)); - particle->pos.y = systemRandom.rand(int(virtual_height)); - int rainsize = systemRandom.rand(2); - particle->texture = rainimages[rainsize]; - do { - particle->speed = (rainsize+1)*45 + systemRandom.randf(3.6); - } while(particle->speed < 1); - particle->speed *= 10; // gravity - - particles.push_back(particle); - } -} - -void -RainParticleSystem::parse(const Reader& reader) -{ - reader.get("z-pos", z_pos); -} - -RainParticleSystem::~RainParticleSystem() -{ - for(int i=0;i<2;++i) - delete rainimages[i]; -} - -void RainParticleSystem::update(float elapsed_time) -{ - std::vector::iterator i; - for( - i = particles.begin(); i != particles.end(); ++i) { - RainParticle* particle = (RainParticle*) *i; - float movement = particle->speed * elapsed_time; - float abs_x = Sector::current()->camera->get_translation().x; - float abs_y = Sector::current()->camera->get_translation().y; - particle->pos.y += movement; - particle->pos.x -= movement; - int col = collision(particle, Vector(-movement, movement)); - if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) { - //Create rainsplash - if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)){ - bool vertical = (col == 2); - int splash_x, splash_y; - if (!vertical) { //check if collision happened from above - splash_x = int(particle->pos.x); - splash_y = int(particle->pos.y) - (int(particle->pos.y) % 32) + 32; - Sector::current()->add_object(new RainSplash(Vector(splash_x, splash_y),vertical)); - } - // Uncomment the following to display vertical splashes, too - /* else { - splash_x = int(particle->pos.x) - (int(particle->pos.x) % 32) + 32; - splash_y = int(particle->pos.y); - Sector::current()->add_object(new RainSplash(Vector(splash_x, splash_y),vertical)); - } */ - } - int new_x = systemRandom.rand(int(virtual_width)) + int(abs_x); - int new_y = 0; - //FIXME: Don't move particles over solid tiles - particle->pos.x = new_x; - particle->pos.y = new_y; - } - } -} - -CometParticleSystem::CometParticleSystem() -{ - cometimages[0] = new Surface("images/creatures/mr_bomb/exploding-left-0.png"); - cometimages[1] = new Surface("images/creatures/mr_bomb/exploding-left-0.png"); - - virtual_width = SCREEN_WIDTH * 2; - - // create some random comets - size_t cometcount = 2; - for(size_t i=0; ipos.x = systemRandom.rand(int(virtual_width)); - particle->pos.y = systemRandom.rand(int(virtual_height)); - int cometsize = systemRandom.rand(2); - particle->texture = cometimages[cometsize]; - do { - particle->speed = (cometsize+1)*30 + systemRandom.randf(3.6); - } while(particle->speed < 1); - particle->speed *= 10; // gravity - - particles.push_back(particle); - } -} - -void -CometParticleSystem::parse(const Reader& reader) -{ - reader.get("z-pos", z_pos); -} - -CometParticleSystem::~CometParticleSystem() -{ - for(int i=0;i<2;++i) - delete cometimages[i]; -} - -void CometParticleSystem::update(float elapsed_time) -{ - (void) elapsed_time; -#if 0 - std::vector::iterator i; - for( - i = particles.begin(); i != particles.end(); ++i) { - CometParticle* particle = (CometParticle*) *i; - float movement = particle->speed * elapsed_time; - float abs_x = Sector::current()->camera->get_translation().x; - float abs_y = Sector::current()->camera->get_translation().y; - particle->pos.y += movement; - particle->pos.x -= movement; - int col = collision(particle, Vector(-movement, movement)); - if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) { - if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)) { - Sector::current()->add_object(new Bomb(particle->pos, LEFT)); - } - int new_x = systemRandom.rand(int(virtual_width)) + int(abs_x); - int new_y = 0; - //FIXME: Don't move particles over solid tiles - particle->pos.x = new_x; - particle->pos.y = new_y; - } - } -#endif -} - /* EOF */ diff --git a/src/object/particlesystem_interactive.hpp b/src/object/particlesystem_interactive.hpp index b7d841176..1a7796db7 100644 --- a/src/object/particlesystem_interactive.hpp +++ b/src/object/particlesystem_interactive.hpp @@ -71,69 +71,6 @@ protected: float virtual_height; }; -class RainParticleSystem : public ParticleSystem_Interactive -{ -public: - RainParticleSystem(); - virtual ~RainParticleSystem(); - - void parse(const Reader& lisp); - - virtual void update(float elapsed_time); - - std::string type() const - { return "RainParticleSystem"; } - -private: - class RainParticle : public Particle - { - public: - float speed; - - RainParticle() : - speed() - {} - }; - - Surface* rainimages[2]; - -private: - RainParticleSystem(const RainParticleSystem&); - RainParticleSystem& operator=(const RainParticleSystem&); -}; - -class CometParticleSystem : public ParticleSystem_Interactive -{ -public: - CometParticleSystem(); - virtual ~CometParticleSystem(); - - void parse(const Reader& lisp); - void write(Writer& writer); - - virtual void update(float elapsed_time); - - std::string type() const - { return "CometParticleSystem"; } - -private: - class CometParticle : public Particle - { - public: - float speed; - - CometParticle() : - speed() - {} - }; - - Surface* cometimages[2]; - -private: - CometParticleSystem(const CometParticleSystem&); - CometParticleSystem& operator=(const CometParticleSystem&); -}; - #endif /* EOF */ diff --git a/src/object/rain_particle_system.cpp b/src/object/rain_particle_system.cpp new file mode 100644 index 000000000..3f4a1252f --- /dev/null +++ b/src/object/rain_particle_system.cpp @@ -0,0 +1,98 @@ +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "object/rain_particle_system.hpp" + +#include "math/random_generator.hpp" +#include "object/camera.hpp" +#include "object/rainsplash.hpp" +#include "util/reader.hpp" + +RainParticleSystem::RainParticleSystem() +{ + rainimages[0] = new Surface("images/objects/particles/rain0.png"); + rainimages[1] = new Surface("images/objects/particles/rain1.png"); + + virtual_width = SCREEN_WIDTH * 2; + + // create some random raindrops + size_t raindropcount = size_t(virtual_width/6.0); + for(size_t i=0; ipos.x = systemRandom.rand(int(virtual_width)); + particle->pos.y = systemRandom.rand(int(virtual_height)); + int rainsize = systemRandom.rand(2); + particle->texture = rainimages[rainsize]; + do { + particle->speed = (rainsize+1)*45 + systemRandom.randf(3.6); + } while(particle->speed < 1); + particle->speed *= 10; // gravity + + particles.push_back(particle); + } +} + +void +RainParticleSystem::parse(const Reader& reader) +{ + reader.get("z-pos", z_pos); +} + +RainParticleSystem::~RainParticleSystem() +{ + for(int i=0;i<2;++i) + delete rainimages[i]; +} + +void RainParticleSystem::update(float elapsed_time) +{ + std::vector::iterator i; + for( + i = particles.begin(); i != particles.end(); ++i) { + RainParticle* particle = (RainParticle*) *i; + float movement = particle->speed * elapsed_time; + float abs_x = Sector::current()->camera->get_translation().x; + float abs_y = Sector::current()->camera->get_translation().y; + particle->pos.y += movement; + particle->pos.x -= movement; + int col = collision(particle, Vector(-movement, movement)); + if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) { + //Create rainsplash + if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)){ + bool vertical = (col == 2); + int splash_x, splash_y; + if (!vertical) { //check if collision happened from above + splash_x = int(particle->pos.x); + splash_y = int(particle->pos.y) - (int(particle->pos.y) % 32) + 32; + Sector::current()->add_object(new RainSplash(Vector(splash_x, splash_y),vertical)); + } + // Uncomment the following to display vertical splashes, too + /* else { + splash_x = int(particle->pos.x) - (int(particle->pos.x) % 32) + 32; + splash_y = int(particle->pos.y); + Sector::current()->add_object(new RainSplash(Vector(splash_x, splash_y),vertical)); + } */ + } + int new_x = systemRandom.rand(int(virtual_width)) + int(abs_x); + int new_y = 0; + //FIXME: Don't move particles over solid tiles + particle->pos.x = new_x; + particle->pos.y = new_y; + } + } +} + +/* EOF */ diff --git a/src/object/rain_particle_system.hpp b/src/object/rain_particle_system.hpp new file mode 100644 index 000000000..25715ea32 --- /dev/null +++ b/src/object/rain_particle_system.hpp @@ -0,0 +1,55 @@ +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_OBJECT_RAIN_PARTICLE_SYSTEM_HPP +#define HEADER_SUPERTUX_OBJECT_RAIN_PARTICLE_SYSTEM_HPP + +#include "object/particlesystem_interactive.hpp" + +class RainParticleSystem : public ParticleSystem_Interactive +{ +public: + RainParticleSystem(); + virtual ~RainParticleSystem(); + + void parse(const Reader& lisp); + + virtual void update(float elapsed_time); + + std::string type() const + { return "RainParticleSystem"; } + +private: + class RainParticle : public Particle + { + public: + float speed; + + RainParticle() : + speed() + {} + }; + + Surface* rainimages[2]; + +private: + RainParticleSystem(const RainParticleSystem&); + RainParticleSystem& operator=(const RainParticleSystem&); +}; + +#endif + +/* EOF */ diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 62fb618f3..24c43ab75 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -28,27 +28,29 @@ #include "object/brick.hpp" #include "object/bullet.hpp" #include "object/camera.hpp" +#include "object/cloud_particle_system.hpp" #include "object/coin.hpp" +#include "object/comet_particle_system.hpp" #include "object/display_effect.hpp" +#include "object/ghost_particle_system.hpp" #include "object/gradient.hpp" #include "object/invisible_block.hpp" #include "object/particlesystem.hpp" -#include "object/cloud_particle_system.hpp" -#include "object/ghost_particle_system.hpp" -#include "object/snow_particle_system.hpp" #include "object/particlesystem_interactive.hpp" #include "object/player.hpp" #include "object/portable.hpp" #include "object/pulsing_light.hpp" +#include "object/rain_particle_system.hpp" #include "object/smoke_cloud.hpp" +#include "object/snow_particle_system.hpp" #include "object/text_object.hpp" #include "object/tilemap.hpp" #include "physfs/ifile_stream.hpp" #include "scripting/squirrel_util.hpp" #include "supertux/collision.hpp" #include "supertux/constants.hpp" -#include "supertux/level.hpp" #include "supertux/globals.hpp" +#include "supertux/level.hpp" #include "supertux/object_factory.hpp" #include "supertux/spawn_point.hpp" #include "supertux/tile.hpp" @@ -168,15 +170,14 @@ Sector::parse_object(const std::string& name, const Reader& reader) return partsys; } else if(name == "money") { // for compatibility with old maps return new Jumpy(reader); + } else { + try { + return create_object(name, reader); + } catch(std::exception& e) { + log_warning << e.what() << "" << std::endl; + return 0; + } } - - try { - return create_object(name, reader); - } catch(std::exception& e) { - log_warning << e.what() << "" << std::endl; - } - - return 0; } void diff --git a/src/supertux/title_screen.hpp b/src/supertux/title_screen.hpp index 8156f3ec6..33964fa14 100644 --- a/src/supertux/title_screen.hpp +++ b/src/supertux/title_screen.hpp @@ -55,7 +55,7 @@ private: void generate_main_menu(); private: - std::auto_ptr main_menu; + std::auto_ptr main_menu; std::auto_ptr frame; std::auto_ptr controller; std::auto_ptr titlesession; -- 2.11.0