Planeshift
modehandler.h
Go to the documentation of this file.
1 /*
2  * modehandler.h Keith Fulton <keith@paqrat.com>
3  *
4  * Copyright (C) 2001-2002 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 #ifndef MODEHANDLER_H
20 #define MODEHANDLER_H
21 //=============================================================================
22 // Crystal Space Includes
23 //=============================================================================
24 #include <csutil/parray.h>
25 #include <csutil/ref.h>
26 #include <csutil/cscolor.h>
27 #include <csutil/weakref.h>
28 #include <iengine/portal.h>
29 
30 //=============================================================================
31 // Project Includes
32 //=============================================================================
33 #include "net/cmdbase.h"
34 
35 //=============================================================================
36 // Local Includes
37 //=============================================================================
38 
39 struct iEngine;
40 struct iBase;
41 struct iSoundManager;
42 struct iLoaderContext;
43 struct LightingList;
44 struct LightingSetting;
45 struct WeatherInfo;
46 
47 class pawsChatWindow;
48 class GEMClientActor;
49 class psCelClient;
50 class MsgHandler;
51 class WeatherObject;
52 
53 /* Defines for the various times of day. Some things may need to trigger on a
54  'general' time of day. */
56 {
62 };
63 
64 
66 
67 /* This class is used as callback when a portal is shown.
68  This is needed to have correct weather */
69 class psPortalCallback : public scfImplementation1<psPortalCallback,iPortalCallback>
70 {
71 public:
73  virtual ~psPortalCallback();
74 
80  virtual bool Traverse (iPortal* portal,iBase* context);
81 
82  const char* GetSector() { return sector; }
83 
84 private:
85  csString sector;
86  csRef<iLoaderContext> loaderContext;
87 };
88 
91 {
94 
95  iPortal* portal;
96  csBox3 bbox;
97  csVector3 pos;
98 };
99 
108 {
109 public:
110  ModeHandler(psCelClient *cc,MsgHandler* mh,iObjectRegistry* object_reg);
111  virtual ~ModeHandler();
112  virtual void HandleMessage(MsgEntry* me);
113 
114  bool Initialize();
115 
116  void ClearLightFadeSettings();
117  void FinishLightFade();
118 
119  void PreProcess();
120 
121  void SetEntity(GEMClientActor *ent);
122 
123  // Get the general time of day it is ( from enum )
124  TimeOfDay GetGeneralTime() { return timeOfDay; }
125 
126  // Get the hour of the day.
127  size_t GetTime() { return clockHour; }
128 
129  void DoneLoading(const char* sectorname); // Called when every connected sector is loaded
130 
132  void CreatePortalWeather(iSector* sector, csTicks delta);
133  bool CreatePortalWeather(iPortal* portal, csTicks delta);
135  void RemovePortalWeather();
137  void RemoveWeather();
138 
139  void AddDownfallObject(WeatherObject* weatherobject);
140  void RemoveDownfallObject(WeatherObject* weatherobject);
141 
142  void SetModeSounds(uint8_t mode);
143  void UpdateLights();
144 
145 protected:
147 
150 
152  uint clockHour;
153 
154  iObjectRegistry* object_reg;
155  csRef<psCelClient> celclient;
156  csRef<MsgHandler> msghandler;
157  csRef<iEngine> engine;
158  csRef<iVFS> vfs;
159 
160  // Each element represents an hour of the day.
161  csPDelArray<LightingList> lights;
162  // Track the stage of the current step.
163  uint stepStage;
168  csRandomGen *randomgen;
170  csString sound_name;
171  csTicks sound_when;
172 
173  // Lighting variable.
174  csRef<iSharedVariable> lightningreset;
175  CS::ShaderVarStringID ambientId;
176  CS::ShaderVarStringID combinedAmbientId;
177 
178  // Weather intepolation stuff
181 
182  csHash<WeatherInfo*, csString> weatherlist;
183 
184  // Weather gfx object for current sector
185  WeatherObject* downfall; // Weather object following the player around
186  WeatherObject* fog; // Weather object that is always in effect
187  csPDelArray<WeatherPortal> portals; // Weather for portals out of the sector.
188  bool processWeather; // determine whether to show weather effects or not
189 
190  void HandleModeMessage(MsgEntry* me);
191  void HandleWeatherMessage(MsgEntry* me);
192  void HandleNewSectorMessage(MsgEntry* me);
193  void HandleCombatEvent(MsgEntry* me);
194  void HandleSpecialCombatEvent(MsgEntry* me);
195  void HandleCachedFile(MsgEntry* me);
196 
197  bool ProcessLighting(LightingSetting *color, float pct);
198  LightingSetting *FindLight(LightingSetting *light,int which);
199 
200  bool CheckCurrentSector(GEMClientObject *entity,
201  const char *sectorname,
202  csVector3& pos,
203  iSector*& sector);
204 
205  void SetSectorMusic(const char *sectorname);
206  void PublishTime( int newTime );
207 
208  void UpdateLights(csTicks when, bool force = false);
209 
210  /* WEATHER FUNCTIONS */
211  // Controls the weather.
212  void ProcessLighting(const psWeatherMessage::NetWeatherInfo& info);
213  void ProcessDownfall(const psWeatherMessage::NetWeatherInfo& info);
214  public:
215  void ProcessFog(const psWeatherMessage::NetWeatherInfo& info);
216 protected:
217  bool CreateWeather(WeatherInfo* ri, csTicks delta);
218 
219  void StartFollowWeather();
220  void StopFollowWeather();
221 
222  WeatherObject* CreateDownfallWeatherObject(WeatherInfo* ri);
223  WeatherObject* CreateStaticWeatherObject(WeatherInfo* ri);
224 
225  WeatherPortal* GetPortal(iPortal* portal);
226  WeatherInfo* GetWeatherInfo(const char* sector);
227  WeatherInfo* CreateWeatherInfo(const char* sector);
228  float GetDensity(WeatherInfo* wi);
229 
230  void UpdateWeather(csTicks when);
231  void UpdateWeatherSounds();
232 
233  /* END OF WEATHER FUNCTIONS */
234 
235  bool LoadLightingLevels(); // Called from Initialize
236 
237 
238 private:
239  pawsChatWindow* chatWindow;
240 
241  csString MungeName(GEMClientActor* obj, bool startOfPhrase = false);
242 
243  void SetCombatAnim( GEMClientActor* atObject, csStringID anim );
244 
245  void Other( int type, float damage, GEMClientActor* atObject, GEMClientActor* tarObject, csString& location );
246  void OtherOutOfRange( GEMClientActor* atObject, GEMClientActor* tarObject );
247  void OtherMiss( GEMClientActor* atObject, GEMClientActor* tarObject );
248  void OtherDodge( GEMClientActor* atObject, GEMClientActor* tarObject );
249  void OtherDeath( GEMClientActor* atObject, GEMClientActor* tarObject );
250  void OtherDamage( float damage, GEMClientActor* atObject, GEMClientActor* tarObject );
251  void OtherBlock( GEMClientActor* atObject, GEMClientActor* tarObject );
252  void OtherNearlyDead(GEMClientActor *tarObject);
253 
254  void Defend( int type, float damage, GEMClientActor* atObject, GEMClientActor* tarObject, csString& location );
255  void DefendOutOfRange( GEMClientActor* atObject, GEMClientActor* tarObject );
256  void DefendMiss( GEMClientActor* atObject, GEMClientActor* tarObject );
257  void DefendDodge( GEMClientActor* atObject, GEMClientActor* tarObject );
258  void DefendDeath( GEMClientActor* atObject );
259  void DefendDamage( float damage, GEMClientActor* atObject, GEMClientActor* tarObject, csString& location );
260  void DefendBlock( GEMClientActor* atObject, GEMClientActor* tarObject, csString& location );
261  void DefendNearlyDead();
262 
263  void Attack( int type, float damage, GEMClientActor* atObject, GEMClientActor* tarObject, csString& location );
264  void AttackOutOfRange( GEMClientActor* atObject, GEMClientActor* tarObject );
265  void AttackMiss(GEMClientActor* atObject, GEMClientActor* tarObject, csString& location );
266  void AttackDodge( GEMClientActor* atObject, GEMClientActor* tarObject );
267  void AttackDeath( GEMClientActor* atObject, GEMClientActor* tarObject );
268  void AttackDamage(float damage, GEMClientActor* atObject, GEMClientActor* tarObject, csString& location );
269  void AttackBlock( GEMClientActor* atObject, GEMClientActor* tarObject, csString& location );
270 
271 };
272 
279 {
280  csPDelArray<LightingSetting> colors;
281 };
282 
283 
285 {
286  bool error;
287  size_t value;
288  double density;
289  csString type;
290  csString object;
291  csColor color;
292  csColor raincolor;
293  csColor start_color;
294  csColor base_color;
295  csColor diff;
296  csString sector;
297  // The two cache values below use csWeakRef to make sure that the cache is cleared automatically
298  // as soon as the light or sector is removed (this can happen in case the region is unloaded).
299  csWeakRef<iLight> light_cache; // Optimization: pointer to light so we don't have to search it again.
300  csWeakRef<iSector> sector_cache; // Optimization: pointer to sector so we don't have to search it again.
301  csRef<csShaderVariable> ambient_cache; // Optimization: pointer to ambient so we don't have to search it again.
302  csRef<csShaderVariable> combined_ambient_cache; // Optimization: pointer to combined ambient so we don't have to search it again.
303 };
304 
305 #endif
virtual bool Traverse(iPortal *portal, iBase *context)
This function is called when a portal is shown for the first time and is missing and therefore it&#39;s h...
size_t GetTime()
Definition: modehandler.h:127
csPDelArray< LightingList > lights
Definition: modehandler.h:161
csColor raincolor
color when it is clear skies
Definition: modehandler.h:292
This is a player or another &#39;alive&#39; entity on the client.
Definition: pscelclient.h:554
csString type
What is the density level of the fog, if any.
Definition: modehandler.h:289
GEMClientObject * actorEntity
Definition: modehandler.h:146
csHash< WeatherInfo *, csString > weatherlist
Definition: modehandler.h:182
csRef< psCelClient > celclient
Definition: modehandler.h:155
csRef< csShaderVariable > ambient_cache
Definition: modehandler.h:301
csColor diff
base ambient light
Definition: modehandler.h:295
bool sound_queued
Definition: modehandler.h:169
csTicks sound_when
Definition: modehandler.h:171
size_t value
Has this lighting value had an error yet.
Definition: modehandler.h:287
WeatherObject * downfall
Definition: modehandler.h:93
Begin of classes.
Definition: modehandler.h:69
Main Chat window for PlaneShift.
Definition: chatwindow.h:133
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
csTicks last_interpolation_reset
Definition: modehandler.h:166
Holds the weather meshes and connected portal.
Definition: modehandler.h:90
CS::ShaderVarStringID ambientId
Definition: modehandler.h:175
Client version of the Cel Manager Requests world loading.
Definition: pscelclient.h:108
bool interpolation_complete
Definition: modehandler.h:167
CS::ShaderVarStringID combinedAmbientId
Definition: modehandler.h:176
TimeOfDay
Definition: modehandler.h:55
csString object
Fog, Light or Ambient.
Definition: modehandler.h:290
csWeakRef< iSector > sector_cache
Definition: modehandler.h:300
csVector3 pos
Definition: modehandler.h:97
double density
What time of day is this lighting for?
Definition: modehandler.h:288
uint clockHour
Stores the time of day in hours.
Definition: modehandler.h:152
iObjectRegistry * object_reg
Definition: modehandler.h:154
virtual ~psPortalCallback()
const char * GetSector()
Definition: modehandler.h:82
TimeOfDay GetGeneralTime()
Definition: modehandler.h:124
WeatherObject * downfall
Definition: modehandler.h:185
csWeakRef< iLight > light_cache
sector of light is stored to make searching for rain faster
Definition: modehandler.h:299
csRandomGen * randomgen
Definition: modehandler.h:168
csString sound_name
Definition: modehandler.h:170
bool processWeather
Definition: modehandler.h:188
WeatherObject * fog
Definition: modehandler.h:186
csTicks interpolation_time
Definition: modehandler.h:164
csTicks last_weather_update
Definition: modehandler.h:179
void void Initialize(iObjectRegistry *object_reg)
Holds the weather object, need this because some things have been created but do not have an object p...
Definition: weather.h:64
An object that the client knows about.
Definition: pscelclient.h:373
This class is the client&#39;s and server&#39;s main interface for either sending network messages out or get...
Definition: msghandler.h:106
csTicks weather_update_time
Definition: modehandler.h:180
csColor base_color
last color at start of interpolation
Definition: modehandler.h:294
uint interpolation_step
Definition: modehandler.h:165
csPDelArray< WeatherPortal > portals
Definition: modehandler.h:187
csRef< csShaderVariable > combined_ambient_cache
Definition: modehandler.h:302
csString sector
diff between last color and target color in interpolation
Definition: modehandler.h:296
csColor start_color
color when it is 100% downpour
Definition: modehandler.h:293
iPortal * portal
Definition: modehandler.h:95
TimeOfDay timeOfDay
Stores the &#39;general&#39; time of day it is. One of the TimeOfDay enums.
Definition: modehandler.h:149
csPDelArray< LightingSetting > colors
Definition: modehandler.h:280
csRef< iSharedVariable > lightningreset
Definition: modehandler.h:174
csRef< iEngine > engine
Definition: modehandler.h:157
csRef< MsgHandler > msghandler
Definition: modehandler.h:156
WeatherInfo * wi
Definition: modehandler.h:92
This class handles mode messages from the server, specifying "normal", or "combat" or "death"...
Definition: modehandler.h:107
Struct for information about current weather.
Definition: weather.h:44
uint stepStage
Definition: modehandler.h:163
csColor color
Name of light, or name of sector.
Definition: modehandler.h:291
csRef< iVFS > vfs
Definition: modehandler.h:158