home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 11 / Engine / Scripting.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  2.1 KB  |  62 lines

  1. //-----------------------------------------------------------------------------
  2. // A simple scripting system. The scripts are nothing more than a collection of
  3. // variables stored in a text file.
  4. //
  5. // Programming a Multiplayer First Person Shooter in DirectX
  6. // Copyright (c) 2004 Vaughan Young
  7. //-----------------------------------------------------------------------------
  8. #ifndef SCRIPTING_H
  9. #define SCRIPTING_H
  10.  
  11. //-----------------------------------------------------------------------------
  12. // Variable Type Enumeration
  13. //-----------------------------------------------------------------------------
  14. enum{ VARIABLE_BOOL, VARIABLE_COLOUR, VARIABLE_FLOAT, VARIABLE_NUMBER, VARIABLE_STRING, VARIABLE_VECTOR, VARIABLE_UNKNOWN };
  15.  
  16. //-----------------------------------------------------------------------------
  17. // Variable Class
  18. //-----------------------------------------------------------------------------
  19. class Variable
  20. {
  21. public:
  22.     Variable( char *name, FILE *file );
  23.     Variable( char *name, char type, void *value );
  24.     virtual ~Variable();
  25.  
  26.     char GetType();
  27.     char *GetName();
  28.     void *GetData();
  29.  
  30. private:
  31.     char m_type; // Type of data stored in the variable.
  32.     char *m_name; // Name of the variable.
  33.     void *m_data; // Data stored in the variable.
  34. };
  35.  
  36. //-----------------------------------------------------------------------------
  37. // Script Class
  38. //-----------------------------------------------------------------------------
  39. class Script : public Resource< Script >
  40. {
  41. public:
  42.     Script( char *name, char *path = "./" );
  43.     virtual ~Script();
  44.  
  45.     void AddVariable( char *name, char type, void *value );
  46.     void SetVariable( char *name, void *value );
  47.  
  48.     void SaveScript( char *filename = NULL );
  49.  
  50.     bool *GetBoolData( char *variable );
  51.     D3DCOLORVALUE *GetColourData( char *variable );
  52.     float *GetFloatData( char *variable );
  53.     long *GetNumberData( char *variable );
  54.     char *GetStringData( char *variable );
  55.     D3DXVECTOR3 *GetVectorData( char *variable );
  56.     void *GetUnknownData( char *variable );
  57.  
  58. private:
  59.     LinkedList< Variable > *m_variables; // Linked list of variables in the script.
  60. };
  61.  
  62. #endif