Planeshift
psengine.h
Go to the documentation of this file.
1 /*
2  * psengine.h
3  *
4  * Copyright (C) 2001 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 __ENGINE_H__
20 #define __ENGINE_H__
21 
22 #include <csutil/csstring.h>
23 #include <csutil/strhashr.h>
24 #include <csutil/randomgen.h>
25 #include <csutil/refarr.h>
26 #include <csutil/sysfunc.h>
27 #include <csutil/leakguard.h>
28 #include <csutil/eventhandlers.h>
29 #include <csutil/weakrefarr.h>
30 #include <csutil/weakreferenced.h>
31 #include <ivaria/profile.h>
32 #include <ivideo/graph3d.h>
33 #include <iutil/eventh.h>
34 
35 #include "psnetmanager.h"
36 #include "isoundmngr.h"
37 
38 #include "util/slots.h"
39 
40 class psCelClient;
41 class ClientMsgHandler;
43 struct iBgLoader;
44 struct iConfigManager;
45 struct iDialogManager;
46 struct iDocumentSystem;
47 struct iEngine;
48 struct iEvent;
49 struct iEventQueue;
50 struct iFont;
51 struct iGraphics2D;
52 struct iGraphics3D;
53 struct iSceneManipulate;
54 struct iTextureManager;
55 struct iThreadReturn;
56 struct iVFS;
57 struct iVirtualClock;
58 class ModeHandler;
59 class ActionHandler;
60 class ZoneHandler;
61 class psCharController;
62 class psCamera;
63 class psEffectManager;
64 class psChatBubbles;
66 class psMainWidget;
67 class psQuestionClient;
68 class psOptions;
69 class psCSSetup;
70 class psMouseBinds;
71 class psInventoryCache;
72 class PawsManager;
73 class Autoexec;
74 
75 // Networking classes
76 class ClientMsgHandler;
77 class psNetManager;
78 class psSlotManager;
79 class ClientSongManager;
80 
81 class GUIHandler;
82 
83 struct DelayedLoader : public CS::Utility::WeakReferenced
84 {
85  virtual bool CheckLoadStatus() = 0;
86  virtual ~DelayedLoader() { };
87 };
88 
94 class psEngine
95 {
96 public:
97  enum LoadState
98  {
106  LS_ERROR
107  };
108 
110  psEngine(iObjectRegistry* object_reg, psCSSetup* CSSetup);
111 
113  virtual ~psEngine();
114 
135  bool Initialize(int level);
136 
142  void Cleanup();
143 
147  void ResetEngine();
148 
150  void UpdatePerFrame();
151 
153  void FinishFrame()
154  {
155  g3d->FinishDraw();
156  g3d->Print(NULL);
157  }
158 
164  bool ProcessLogic(iEvent &Event);
165  bool Process2D(iEvent &Event);
166  bool Process3D(iEvent &Event);
167  bool ProcessFrame(iEvent &Event);
168 
170  void LoadGame();
171 
174  {
175  return gameLoaded;
176  };
177 
178  // References to plugins
179  iObjectRegistry* GetObjectRegistry()
180  {
181  return object_reg;
182  }
183  iEventNameRegistry* GetEventNameRegistry()
184  {
185  return nameRegistry;
186  }
187  iEngine* GetEngine()
188  {
189  return engine;
190  }
191  iGraphics3D* GetG3D()
192  {
193  return g3d;
194  }
195  iGraphics2D* GetG2D()
196  {
197  return g2d;
198  }
199  iTextureManager* GetTextureManager()
200  {
201  return txtmgr;
202  }
203  iVFS* GetVFS()
204  {
205  return vfs;
206  }
207  iVirtualClock* GetVirtualClock()
208  {
209  return vc;
210  }
211  iDocumentSystem* GetXMLParser()
212  {
213  return xmlparser;
214  }
215  iConfigManager* GetConfig()
216  {
217  return cfgmgr;
218  }
219  iBgLoader* GetLoader()
220  {
221  return loader;
222  }
223  iSceneManipulate* GetSceneManipulator()
224  {
225  return scenemanipulator;
226  }
227  iSoundManager* GetSoundManager()
228  {
229  return SoundManager;
230  }
231 
232  csRandomGen &GetRandomGen()
233  {
234  return random;
235  }
236  float GetRandom()
237  {
238  return random.Get();
239  }
240 
242  {
243  return netmanager->GetMsgHandler();
244  }
246  {
247  return netmanager->GetCmdHandler();
248  }
250  {
251  return slotManager;
252  }
254  {
255  return songManager;
256  }
258  {
259  return charmanager;
260  }
262  {
263  return celclient;
264  };
266  {
267  return mainWidget;
268  }
270  {
271  return effectManager;
272  }
274  {
275  return chatBubbles;
276  }
278  {
279  return options;
280  }
282  {
283  return modehandler;
284  }
286  {
287  return actionhandler;
288  }
290  {
291  return charController;
292  }
293  psMouseBinds* GetMouseBinds();
295  {
296  return camera;
297  }
299  {
300  return netmanager;
301  }
303  {
304  return CS_Setup;
305  }
307  {
308  return zonehandler;
309  }
311  {
312  return autoexec;
313  }
314 
318  void SetTargetPetitioner(const char* pet)
319  {
320  targetPetitioner = pet;
321  }
322 
323  const char* GetTargetPetitioner()
324  {
325  return targetPetitioner;
326  }
327 
331  void QuitClient();
332 
336  void Disconnect();
337 
341  void StartLoad()
342  {
343  loadstate = LS_LOAD_SCREEN;
344  }
346 
347  size_t GetTime();
348 
353  {
354  return BrightnessCorrection;
355  }
356 
360  void SetBrightnessCorrection(float B);
361 
365  void AdjustBrightnessCorrectionUp();
366 
370  void AdjustBrightnessCorrectionDown();
371 
375  void ResetBrightnessCorrection();
376 
377  void UpdateLights();
378 
379  float GetKFactor()
380  {
381  return KFactor;
382  }
383  void SetKFactor(float K)
384  {
385  KFactor = K;
386  }
387 
388  iEvent* GetLastEvent()
389  {
390  return lastEvent;
391  }
392 
393  // Functions to set and get frameLimit converted into a value of FPS for users
394  void setLimitFPS(int);
396  {
397  return maxFPS;
398  }
399  float getFPS()
400  {
401  return currFPS;
402  }
403 
404  bool toggleFPS()
405  {
406  showFPS = !showFPS;
407  return showFPS;
408  }
409 
416  inline void SetDuelConfirm(int confirmType)
417  {
418  duelConfirmation = confirmType;
419  WriteConfirmationSettings();
420  }
425  inline int GetDuelConfirm() const
426  {
427  return duelConfirmation;
428  }
434  inline void SetMarriageProposal(bool ignore)
435  {
436  marriageProposal = ignore;
437  WriteConfirmationSettings();
438  }
443  inline bool GetMarriageProposal() const
444  {
445  return marriageProposal;
446  }
447 
452  void WriteConfirmationSettings();
453 
459  bool LoadConfirmationSettings();
460 
467  bool LoadSoundSettings(bool forceDef);
468 
470  inline bool HasLoadedMap() const
471  {
472  return loadedMap;
473  }
474 
476  void SetLoadedMap(bool value)
477  {
478  loadedMap = value;
479  }
480 
483  {
484  return loadError;
485  }
486 
488  void LoadError(bool value)
489  {
490  loadError = value;
491  }
492 
500  bool LoadPawsWidget(const char* title, const char* filename);
501 
507  bool LoadCustomPawsWidgets(const char* filename);
508 
510 
511  void AddLoadingWindowMsg(const csString &msg);
512 
518  void FatalError(const char* msg);
519 
521  bool IsLoggedIn()
522  {
523  return loggedIn;
524  }
525  void SetLoggedIn(bool v)
526  {
527  loggedIn = v;
528  }
529 
535  void SetNumChars(int chars)
536  {
537  numOfChars = chars;
538  }
539 
542  {
543  return numOfChars;
544  }
545 
547  const char* GetMainPlayerName();
548 
550  bool UpdateWindowTitleInformations();
551 
554  {
555  elapsed = 0;
556  }
557 
559  void SetGuildName(const char* name)
560  {
561  guildname = name;
562  }
563 
565  const char* GetGuildName()
566  {
567  return guildname;
568  }
569 
573  bool GetMuteSoundsOnFocusLoss(void) const
574  {
575  return muteSoundsOnFocusLoss;
576  }
580  void SetMuteSoundsOnFocusLoss(bool value)
581  {
582  muteSoundsOnFocusLoss = value;
583  }
584 
586  void MuteAllSounds(void);
588  void UnmuteAllSounds(void);
589 
593  const char* FindCommonString(unsigned int cstr_id);
594 
600  csStringID FindCommonStringId(const char* str);
601 
603  csStringHashReversible* GetMsgStrings();
604 
607  {
608  return soundOn;
609  }
610 
613  {
614  return inventoryCache;
615  }
616 
619  {
620  return backgroundWorldLoading;
621  }
622 
624  {
625  delayedLoaders.PushSmart(obj);
626  }
628  {
629  delayedLoaders.Delete(obj);
630  }
631 
632  static csString hwRenderer;
633  static csString hwVersion;
634  static csString playerName;
635 #ifdef WIN32
636  static HWND hwnd;
637 #endif
638 
639 private:
641  void LoadLogSettings();
642 
644  bool QueryPlugins();
645 
647  void DeclareExtraFactories();
648 
649  void HideWindow(const csString &widgetName);
650 
652  void FrameLimit();
653 
654  /* plugins we're using... */
655  iObjectRegistry* object_reg;
656  csRef<iEventNameRegistry> nameRegistry;
657  csRef<iEngine> engine;
658  csRef<iConfigManager> cfgmgr;
659  csRef<iTextureManager> txtmgr;
660  csRef<iVFS> vfs;
661  csRef<iGraphics2D> g2d;
662  csRef<iGraphics3D> g3d;
663  csRef<iEventQueue> queue;
664  csRef<iVirtualClock> vc;
665  csRef<iDocumentSystem> xmlparser;
666  csRef<iSoundManager> SoundManager;
667  csRef<iStringSet> stringset;
668  csRandomGen random;
669 
670  csRef<psNetManager> netmanager;
671  csRef<psCelClient> celclient;
672  csRef<ModeHandler> modehandler;
673  csRef<ActionHandler> actionhandler;
674  csRef<ZoneHandler> zonehandler;
675  csRef<psCal3DCallbackLoader> cal3DCallbackLoader;
676  psClientCharManager* charmanager;
677  GUIHandler* guiHandler;
678  psCharController* charController;
679  psMouseBinds* mouseBinds;
680  psCamera* camera;
681  csRef<psEffectManager> effectManager;
682  psChatBubbles* chatBubbles;
683  psOptions* options;
684  psSlotManager* slotManager;
685  ClientSongManager* songManager;
686  psQuestionClient* questionclient;
687  PawsManager* paws;
688  psMainWidget* mainWidget;
689  psInventoryCache* inventoryCache;
690  psCSSetup* CS_Setup;
691  csRef<iBgLoader> loader;
692  csRef<iSceneManipulate> scenemanipulator;
693  Autoexec* autoexec;
694 
695  /* status, misc. vars */
696  bool gameLoaded;
697  bool modalMenu;
698  bool loggedIn;
699 
700  csTicks loadtimeout;
701 
702  csString lasterror;
703 
704  csString guildname;
705 
707  bool drawScreen;
708 
709  // For splash progress.
710  csRefArray<iThreadReturn> precaches;
711  csRef<iStringArray> meshes;
712  csRef<iStringArray> maps;
713  size_t lastLoadingCount;
714 
715  // True if we've requested the main actor.
716  bool actorRequested;
717 
718 private:
719 
720  csString targetPetitioner;
721 
722  float BrightnessCorrection;
723 
724  float KFactor;
725 
726  iEvent* lastEvent;
727 
734  int duelConfirmation;
735  bool marriageProposal;
736 
737  bool loadedMap;
738  bool loadError;
739  csArray<csString> wdgProblems;
740 
742  int numOfChars;
743 
745  csTicks elapsed;
746 
748  csTicks frameLimit;
749 
751  int maxFPS;
752 
753  float currFPS;
754  unsigned int countFPS;
755  unsigned int timeFPS;
756 
757  bool showFPS;
758 
759  csRef<iFont> font;
760 
762  bool muteSoundsOnFocusLoss;
763 
765  bool soundOn;
766 
767  bool backgroundWorldLoading;
768 
769  // Event ID cache
770  csEventID event_frame;
771  csEventID event_canvashidden;
772  csEventID event_canvasexposed;
773  csEventID event_focusgained;
774  csEventID event_focuslost;
775  csEventID event_mouse;
776  csEventID event_keyboard;
777  csEventID event_joystick;
778  csEventID event_quit;
779 
780 #if defined(CS_PLATFORM_UNIX) && defined(INCLUDE_CLIPBOARD)
781  csEventID event_selectionnotify;
782 #endif
783 
788  class LogicEventHandler : public scfImplementation1<LogicEventHandler, iEventHandler>
789  {
790  public:
791  LogicEventHandler(psEngine* parent) : scfImplementationType(this), parent(parent)
792  {
793  }
794 
795  virtual ~LogicEventHandler()
796  {
797  }
798 
799  virtual bool HandleEvent(iEvent &ev)
800  {
801  return parent->ProcessLogic(ev);
802  }
803 
804  virtual const csHandlerID* GenericPrec(csRef<iEventHandlerRegistry> &,
805  csRef<iEventNameRegistry> &, csEventID) const;
806  virtual const csHandlerID* GenericSucc(csRef<iEventHandlerRegistry> &,
807  csRef<iEventNameRegistry> &, csEventID) const;
808 
809  CS_EVENTHANDLER_NAMES("planeshift.client.frame.logic")
810  CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS
811 
812  private:
813  psEngine* parent;
814  };
815 
820  class EventHandler3D : public scfImplementation1<EventHandler3D, iEventHandler>
821  {
822  public:
823  EventHandler3D(psEngine* parent) : scfImplementationType(this), parent(parent)
824  {
825  }
826 
827  virtual ~EventHandler3D()
828  {
829  }
830 
831  virtual bool HandleEvent(iEvent &ev)
832  {
833  return parent->Process3D(ev);
834  }
835 
836  CS_EVENTHANDLER_PHASE_3D("planeshift.client.frame.3d");
837 
838  private:
839  psEngine* parent;
840  };
841 
846  class EventHandler2D : public scfImplementation1<EventHandler2D, iEventHandler>
847  {
848  public:
849  EventHandler2D(psEngine* parent) : scfImplementationType(this), parent(parent)
850  {
851  }
852 
853  virtual ~EventHandler2D()
854  {
855  }
856 
857  virtual bool HandleEvent(iEvent &ev)
858  {
859  return parent->Process2D(ev);
860  }
861 
862  CS_EVENTHANDLER_PHASE_2D("planeshift.client.frame.2d");
863 
864  private:
865  psEngine* parent;
866  };
867 
872  class FrameEventHandler : public scfImplementation1<FrameEventHandler, iEventHandler>
873  {
874  public:
875  FrameEventHandler(psEngine* parent) : scfImplementationType(this), parent(parent)
876  {
877  }
878 
879  virtual ~FrameEventHandler()
880  {
881  }
882 
883  virtual bool HandleEvent(iEvent &ev)
884  {
885  return parent->ProcessFrame(ev);
886  }
887 
888  CS_EVENTHANDLER_PHASE_FRAME("planeshift.client.frame");
889 
890  private:
891  psEngine* parent;
892  };
893 
894  csRef<LogicEventHandler> eventHandlerLogic;
895  csRef<EventHandler3D> eventHandler3D;
896  csRef<EventHandler2D> eventHandler2D;
897  csRef<FrameEventHandler> eventHandlerFrame;
898 
899  csWeakRefArray<DelayedLoader> delayedLoaders;
900 };
901 
902 #endif
Manages character details for the client.
Definition: psclientchar.h:83
psChatBubbles * GetChatBubbles()
Definition: psengine.h:273
void SetKFactor(float K)
Definition: psengine.h:383
iVirtualClock * GetVirtualClock()
Definition: psengine.h:207
bool HasLoadedMap() const
Checks if the client has loaded its map.
Definition: psengine.h:470
Ensures all regions that need to be loaded are.
Definition: zonehandler.h:105
ZoneHandler * GetZoneHandler()
Definition: psengine.h:306
bool ProcessFrame(iEvent &Event)
psOptions * GetOptions()
Definition: psengine.h:277
A helper class to setup Crystal Space and mount some dirs.
Definition: pscssetup.h:52
static csString playerName
Definition: psengine.h:634
float GetBrightnessCorrection()
Get the current brightness correlation value.
Definition: psengine.h:352
ModeHandler * GetModeHandler()
Definition: psengine.h:281
float getFPS()
Definition: psengine.h:399
iEventNameRegistry * GetEventNameRegistry()
Definition: psengine.h:183
LoadState loadstate
Definition: psengine.h:345
bool BackgroundWorldLoading()
Whether or not we&#39;re background loading.
Definition: psengine.h:618
Creates the effect of a chat bubble on top of character heads taking data from text chat...
Definition: chatbubbles.h:54
void UnregisterDelayedLoader(DelayedLoader *obj)
Definition: psengine.h:627
void SetLoadedMap(bool value)
Sets the HasLoadedMap value.
Definition: psengine.h:476
bool GetMuteSoundsOnFocusLoss(void) const
Gets whether sounds should be muted when the application loses focus.
Definition: psengine.h:573
bool GetMarriageProposal() const
Simply returns if marriage proposals should be read or automatically ignored.
Definition: psengine.h:443
void SetGuildName(const char *name)
Set Guild Name here for use with Entity labels.
Definition: psengine.h:559
Main PlaneShift Window manager.
Definition: pawsmanager.h:82
iGraphics3D * GetG3D()
Definition: psengine.h:191
virtual bool CheckLoadStatus()=0
ClientMsgHandler * GetMsgHandler()
Definition: psengine.h:241
bool IsGameLoaded()
check if the game has been loaded or not
Definition: psengine.h:173
psCSSetup * GetCSSetup()
Definition: psengine.h:302
psCelClient * GetCelClient()
Definition: psengine.h:261
psMainWidget * GetMainWidget()
Definition: psengine.h:265
ClientSongManager * GetSongManager()
Definition: psengine.h:253
Autoexec * GetAutoexec()
Definition: psengine.h:310
class handling autoexecution of commands at the startup.
Definition: autoexec.h:36
bool GetSoundStatus()
Get the status of the sound plugin, if available or not.
Definition: psengine.h:606
float GetKFactor()
Definition: psengine.h:379
SlotNameHash slotName
Definition: psengine.h:509
void RegisterDelayedLoader(DelayedLoader *obj)
Definition: psengine.h:623
iDocumentSystem * GetXMLParser()
Definition: psengine.h:211
iSceneManipulate * GetSceneManipulator()
Definition: psengine.h:223
Handles messages to be sent out, connects to server and send those.
void SetDuelConfirm(int confirmType)
Sets the duel confirm type and updates the confirmation settings XML.
Definition: psengine.h:416
iConfigManager * GetConfig()
Definition: psengine.h:215
void SetTargetPetitioner(const char *pet)
Access the player&#39;s petitioner target.
Definition: psengine.h:318
static csString hwRenderer
Definition: psengine.h:632
iSoundManager * GetSoundManager()
Definition: psengine.h:227
Client version of the Cel Manager Requests world loading.
Definition: pscelclient.h:108
iObjectRegistry * GetObjectRegistry()
Definition: psengine.h:179
static csString hwVersion
Definition: psengine.h:633
Implement iSoundManager.
Definition: soundmanager.h:53
void SetMuteSoundsOnFocusLoss(bool value)
Sets whether sounds should be muted when the application loses focus.
Definition: psengine.h:580
void SetLoggedIn(bool v)
Definition: psengine.h:525
void StartLoad()
Tell the engine to start the load proceedure.
Definition: psengine.h:341
bool Process2D(iEvent &Event)
A stripped version of the cal3d callback loader used only for eedit.
This class holds references to different network classes and provides some conveniance functions to a...
Definition: psnetmanager.h:40
psCharController * GetCharControl()
Definition: psengine.h:289
This class receives all network messages from the server which affect the GUI or are displayable by t...
Definition: guihandler.h:49
void LoadError(bool value)
Sets the LoadError value.
Definition: psengine.h:488
psMouseBinds holds set of psMouseAction
Definition: psmousebinds.h:64
int GetDuelConfirm() const
Simply returns the duel confirmation setting.
Definition: psengine.h:425
Handles camera modes like first person, thrid person, speak to npc manages collision of camera with m...
Definition: pscamera.h:55
CmdHandler * GetCmdHandler()
Definition: psengine.h:245
void ForceRefresh()
Force the next frame to get drawn. Used when updating LoadWindow.
Definition: psengine.h:553
iEvent * GetLastEvent()
Definition: psengine.h:388
bool Process3D(iEvent &Event)
const char * GetGuildName()
Get GuildName.
Definition: psengine.h:565
This class connect the GUI and the server side of the instruments system to the sound plugin...
The psQuestionClient class manages answering to various questions sent from server to user...
Manages dragging items from one inventory slot to another and dropping them into the world...
Definition: psslotmgr.h:43
void void Initialize(iObjectRegistry *object_reg)
psCamera * GetPSCamera()
Definition: psengine.h:294
psinventorycache.h
iBgLoader * GetLoader()
Definition: psengine.h:219
Manages all control and movement related activities.
bool toggleFPS()
Definition: psengine.h:404
A hash map class that stores a name->ID of sockets.
Definition: slots.h:91
ActionHandler * GetActionHandler()
Definition: psengine.h:285
psClientCharManager * GetCharManager()
Definition: psengine.h:257
iEngine * GetEngine()
Definition: psengine.h:187
iGraphics2D * GetG2D()
Definition: psengine.h:195
const char * GetTargetPetitioner()
Definition: psengine.h:323
This class handles mode messages from the server, specifying actions for a clicked location...
Definition: actionhandler.h:50
psNetManager * GetNetManager()
Definition: psengine.h:298
float GetRandom()
Definition: psengine.h:236
bool LoadingError()
Checks if the client had any errors during the loading state.
Definition: psengine.h:482
bool ProcessLogic(iEvent &Event)
Everything is event base for csApp based system.
int getLimitFPS()
Definition: psengine.h:395
virtual ~DelayedLoader()
Definition: psengine.h:86
psEngine This is the main class that contains all the object.
Definition: psengine.h:94
bool IsLoggedIn()
Logged in?
Definition: psengine.h:521
csRandomGen & GetRandomGen()
Definition: psengine.h:232
int GetNumChars()
Get the number of characters this player should have.
Definition: psengine.h:541
This class handles mode messages from the server, specifying "normal", or "combat" or "death"...
Definition: modehandler.h:107
psSlotManager * GetSlotManager()
Definition: psengine.h:249
iTextureManager * GetTextureManager()
Definition: psengine.h:199
void SetMarriageProposal(bool ignore)
Sets if marriage proposals should be ignored and updates the confirmation settings XML...
Definition: psengine.h:434
iVFS * GetVFS()
Definition: psengine.h:203
psInventoryCache * GetInventoryCache(void)
get the inventory cache
Definition: psengine.h:612
void FinishFrame()
Wait to finish drawing the current frame.
Definition: psengine.h:153
void SetNumChars(int chars)
Set the number of characters this player has.
Definition: psengine.h:535
The main or desktop widget.
Definition: psmainwidget.h:79
psEffectManager * GetEffectManager()
Definition: psengine.h:269