EventContainer.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <engine/EventContainer.h>
00022 #include <engine/ScorchedContext.h>
00023 #include <landscapedef/LandscapeDefn.h>
00024 #include <landscapedef/LandscapeTex.h>
00025 #include <landscapedef/LandscapeEvents.h>
00026 #include <landscapemap/LandscapeMaps.h>
00027 
00028 EventContainer::EventContainer()
00029 {
00030 }
00031 
00032 EventContainer::~EventContainer()
00033 {
00034 }
00035 
00036 void EventContainer::clear()
00037 {
00038         events_.clear();
00039 }
00040 
00041 void EventContainer::initialize(ScorchedContext &context)
00042 {
00043         clear();
00044 
00045         LandscapeTex &tex = 
00046                 *context.getLandscapeMaps().getDefinitions().getTex();
00047         LandscapeDefn &defn = 
00048                 *context.getLandscapeMaps().getDefinitions().getDefn();
00049 
00050         addEvents(context, tex.texDefn.includes);
00051         addEvents(context, defn.texDefn.includes);
00052 }
00053 
00054 void EventContainer::addEvents(ScorchedContext &context, 
00055         std::vector<LandscapeInclude *> &events)
00056 {
00057         std::vector<LandscapeInclude *>::iterator itor;
00058         for (itor = events.begin();
00059                 itor != events.end();
00060                 itor++)
00061         {
00062                 LandscapeInclude *event = (*itor);
00063                 addEvent(context, event->events);
00064         }
00065 }
00066 
00067 void EventContainer::addEvent(ScorchedContext &context, 
00068         std::vector<LandscapeEvent *> &events)
00069 {
00070         std::vector<LandscapeEvent *>::iterator itor;
00071         for (itor = events.begin();
00072                 itor != events.end();
00073                 itor++)
00074         {
00075                 LandscapeEvent *event = (*itor);
00076 
00077                 EventEntry entry;
00078                 entry.eventNumber = 0;
00079                 entry.eventTime = 
00080                         event->condition->getNextEventTime(context, ++entry.eventNumber);
00081                 entry.event = event;
00082                 events_.push_back(entry);
00083         }
00084 }
00085 
00086 void EventContainer::simulate(fixed frameTime, ScorchedContext &context)
00087 {
00088         std::vector<EventEntry>::iterator itor;
00089         for (itor = events_.begin();
00090                 itor != events_.end();
00091                 itor++)
00092         {
00093                 EventEntry &entry = (*itor);
00094                 
00095                 LandscapeEvent *event = entry.event;
00096                 entry.eventTime -= frameTime;
00097                 if (event->condition->fireEvent(context, 
00098                         entry.eventTime, entry.eventNumber))
00099                 {
00100                         event->action->fireAction(context);
00101                         entry.eventTime = 
00102                                 event->condition->getNextEventTime(
00103                                         context, ++entry.eventNumber);
00104                 }
00105         }       
00106 }

Generated on Mon Feb 16 15:14:49 2009 for Scorched3D by  doxygen 1.5.3