00001 /* 00002 Copyright (C) 2005 The Pentagram team 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public License 00006 as published by the Free Software Foundation; either version 2 00007 of the License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include "pent_include.h" 00020 00021 #include "SchedulerProcess.h" 00022 #include "Actor.h" 00023 #include "GUIApp.h" 00024 #include "getObject.h" 00025 00026 #include "IDataSource.h" 00027 #include "ODataSource.h" 00028 00029 // p_dynamic_cast stuff 00030 DEFINE_RUNTIME_CLASSTYPE_CODE(SchedulerProcess,Process); 00031 00032 SchedulerProcess::SchedulerProcess() : Process() 00033 { 00034 lastRun = 0; 00035 nextActor = 0; 00036 type = 0x245; // CONSTANT! 00037 } 00038 00039 bool SchedulerProcess::run(const uint32 framenum) 00040 { 00041 if (nextActor != 0) { 00042 // doing a scheduling run at the moment 00043 00044 Actor* a = getActor(nextActor); 00045 if (a) { 00046 // CHECKME: is this the right time to pass? CONSTANT 00047 uint32 stime = GUIApp::get_instance()->getGameTimeInSeconds()/60; 00048 ProcId schedpid = a->callUsecodeEvent_schedule(stime); 00049 if (schedpid) waitFor(schedpid); 00050 } 00051 00052 nextActor++; 00053 if (nextActor == 256) { // CONSTANT 00054 nextActor = 0; // done 00055 #if 0 00056 pout << "Scheduler: finished run at " << framenum << std::endl; 00057 #endif 00058 } 00059 00060 return false; 00061 } 00062 00063 // CONSTANT! 00064 uint32 currenthour = GUIApp::get_instance()->getGameTimeInSeconds()/900; 00065 00066 if (currenthour > lastRun) { 00067 // schedule a new scheduling run 00068 lastRun = currenthour; 00069 nextActor = 1; 00070 #if 0 00071 pout << "Scheduler: " << framenum << std::endl; 00072 #endif 00073 } 00074 00075 return false; 00076 } 00077 00078 void SchedulerProcess::saveData(ODataSource* ods) 00079 { 00080 Process::saveData(ods); 00081 00082 ods->write4(lastRun); 00083 ods->write2(nextActor); 00084 } 00085 00086 bool SchedulerProcess::loadData(IDataSource* ids, uint32 version) 00087 { 00088 if (!Process::loadData(ids, version)) return false; 00089 00090 lastRun = ids->read4(); 00091 nextActor = ids->read2(); 00092 00093 return true; 00094 }