home *** CD-ROM | disk | FTP | other *** search
- File: GAME.TXT
- Path: ...\REHACK\TEXT\GAME.TXT
- Version: 0.01
- Author: Pat Reilly
- CIS Id: 71333,2764
- Created On: 6/25/93
- Modified On: 6/27/93
- Description: Documentation on classes in GAME.HPP
- Tabs: 4
-
- Typedef VisMaker
- ================
-
- This typedef just makes referring to a "function which takes a Rect
- argument and returns a pointer to a Visible" easier to do. For a function
- pointer to be a VisMaker, it has to be in the form:
- Visible* foo(Rect);
-
- Class GameInit
- ==============
-
- The sole purpose in life of GameInit is to allow classes derived from
- Game to initialize some of the default members when Game::Game() ctor is
- called. See the description for the Game class for more information.
-
- Methods
- -------
-
- GameInit(VisMaker A, VisMaker B, VisMaker C, VisMaker D, VisMaker E)
- A, B, C, D and E are all of the VisMaker typedef; that is, they are
- all pointers to functions which are passed a Rect and return a
- pointer to a Visible object. All GameInit() does is to store these
- function pointers in closeUpMaker, autoMapMaker, buttonsMaker,
- characterMaker, and messageMaker. Game::Game() will use these
- to build the appropriate sub-windows of Game.
-
- Members
- -------
-
- closeUpMaker
- VisMaker which makes the close-up object.
-
- autoMapMaker
- VisMaker which makes the automap object.
-
- buttonsMaker
- VisMaker which makes the buttons object.
-
- characterMaker
- VisMaker which makes the character object.
-
- messageMaker
- VisMaker which makes the message object.
-
-
- Class Game - derived from Window and virtually from GameInit
- ==========
-
- Game encapsulates the basic framework for the REHACK game. It inherits
- most of the functionality from Window, and has GameInit as a virtual base
- class.
- Virtual base classes which have non-default constructors MUST be
- explicitly initialized by the most-derived class. This means that if you
- derive a new class from Game, it's ctor initialization list must explicitly
- call GameInit::GameInit(...). For example:
-
- class MyGame : public Game
- {
- public:
- MyGame(const Rect& aBounds) :
- Game(aBounds),
- GameInit(fnA, fnB, fnC, fnD, fnE)
- {}
- };
-
- GameInit's purpose is to store VisMaker function pointers which can be used
- by Game's constructor. We cannot use virtual functions for this because
- when Game's constructor is called, MyGame (above) hasn't been built yet; if
- we called a virtual function foo, Game::foo() would get called instead of
- MyGame::foo().
- We work around that limitation by having the GameInit virtual base class.
- Because GameInit is a virtual base, and it has a non-default constructor,
- then MyGame (as shown) HAS to initialize GameInit explicitly; also, this
- initialization will occur BEFORE Game::Game()'s body is executed. So the
- five function pointers that we pass to GameInit in MyGame::MyGame() will be
- stored in the inherited GameInit members BEFORE Game::Game() is executed.
- Now Game's ctor can call those functions to initialize the standard sub-
- windows of game (automap, character, etc)
- Game also overrides the get(Event&) member so that (since Game has no
- owner) the local eventQueue is called upon to retrieve events.
- Never try to just use a Game and run() it - it will enter an endless
- loop since the eventQueue's won't be receiving input, and the Game has no
- sub-windows to force it to quit (by default, all the function pointers passed
- to GameInit are null). Once we have some working Keyboard, Mouse, etc classes
- Game can be modified to instantiate them.
- For a sub-object, or a derived Game::handle() to quit the game, Game's
- modal state has to be ended. Game::handle() handles Message events which
- have an id of IdQuit to end the modal state. For more on modal, see
- WINDOW.TXT.
-
- Methods
- -------
-
- Game(const Rect&) constructor
- Passes the rect to the Window ctor. Next it calls getLocalBounds() to
- get the bounding rectangle for the Game (topLeft at (0,0)) and
- calls each function stored by the virtual base GameInit to initialize
- the five static members. If the function was null, then the
- associated static Visible* member is set to null.
-
- void get(Event& event) virtual
- Overridden from Visible::get() so that events are retrieved from the
- eventQueue member. If the retrieved event is null, the virtual
- member idle() is called so that required background operations can
- be performed.
-
- void handle(Event& event) virtual
- Overridden from Window::handle(). First it checks to see if the event
- is a Message/IdQuit event; if so, stopRunning is called so that the
- modal state ends; also then clears the event. If the event is not
- this, it is passed on to the base Window::handle(event) to handle
- the event.
-
- void idle() virtual
- This is called whenever get() retrieves an event from the queue and
- the event is null (indicating no pending events). This function just
- returns; if background operations need to be performed during idle
- time, override this function.
-
- bool sendMessage(Visible* dest, word type, word id, void* info) static
- This member allows you to more easily send a message directly to a
- Visible. It build an Event with event.type == type, event.msg.id == id,
- and event.msg.pointerValue == info; then it calls dest->handle(event)
- to process the event. If the event is null afterward (dest handled it)
- returns true; if dest is null or the event is *not* null afterward,
- returns false.
-
- Members
- -------
-
- EventQueue eventQueue static
- This is the event queue, which hold Event class objects. See
- EVENTQ.TXT for more information. Since this member is public and
- static, any module can access the system queue by including GAME.HPP
- and accessing it through:
- #include "WINDOW\GAME.HPP"
-
- ...
- Game::eventQueue.put(event);
- ...
-
- Mouse mouse static
- This is the default mouse class.
-
- Game* game static
- Points to the (only) instance of game. Using this, you can call
- virtual functions in a derived Game class.
-
- Visible* closeUp static
- Pointer to the close up window.
-
- Visible* autoMap static
- Pointer to the automap window.
-
- Visible* buttons static
- Pointer to the buttons window.
-
- Visible* character static
- Pointer to the character window.
-
- Visible* message
- Pointer to the message window.
-
- Note: the above pointers are provided so that modules can pass events
- directly to the windows if necessary.
-
-