HealthListeners.cpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #include "HealthListeners.hpp"
00023 #include "HealthListener.hpp"
00024 #include "../thing/Actor.hpp"
00025 
00026 namespace se_core {
00027     HealthListeners
00028     ::HealthListeners()
00029             : listenerCount_(0), actorIds_(new Composite::id_type[ MAX_LISTENERS ]), listeners_(new HealthListener*[ MAX_LISTENERS ]) {
00030         for(int i = 0; i < MAX_LISTENERS; ++i) {
00031             actorIds_[ i ] = 0;
00032             listeners_[ i ] = 0;
00033         }
00034     }
00035 
00036     HealthListeners
00037     ::~HealthListeners() {
00038         delete[] actorIds_;
00039         delete[] listeners_;
00040     }
00041 
00042 
00043     void HealthListeners
00044     ::add(StatComponent& actor, HealthListener& l) {
00045         listeners_[ listenerCount_ ] = &l;
00046         actorIds_[ listenerCount_ ] = actor.owner()->id();
00047         ++listenerCount_;
00048     }
00049 
00050 
00051     void HealthListeners
00052     ::add(HealthListener& l) {
00053         listeners_[ listenerCount_ ] = &l;
00054         actorIds_[ listenerCount_ ] = 0;
00055         ++listenerCount_;
00056     }
00057 
00058 
00059     void HealthListeners
00060     ::remove(HealthListener& l) {
00061         for(int i = 0; i < listenerCount_; ++i) {
00062             if(listeners_[ i ] == &l) {
00063                 --listenerCount_;
00064                 listeners_[ i ] = listeners_[ listenerCount_ ];
00065                 break;
00066             }
00067         }
00068     }
00069 
00070 
00071     void HealthListeners
00072     ::castHealthChangedEvent(StatComponent& actor, short change) {
00073         for(int i = 0; i < listenerCount_; ++i) {
00074             if(actorIds_[ i ] != 0 || actor.owner()->id() == actorIds_[ i ]) {
00075                 listeners_[ i ]->healthChangedEvent(actor, change);
00076             }
00077         }
00078     }
00079 
00080 }

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo