terminal.h

Go to the documentation of this file.
00001 /*
00002  * terminal.h
00003  *
00004  * Copyright (C) 2008-2010  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * A "terminal" object here acts like a computer terminal: it manages display
00032  * and input for a single player.
00033  */
00034 
00035 #ifndef AESOP_CLIENT_TERMINAL_H__
00036 #define AESOP_CLIENT_TERMINAL_H__
00037 
00038 // includes --------------------------------------------------------------------
00039 #include "common/common.h"
00040 
00041 #include "events.h"
00042 
00043 #include "dialog/dialog.h"
00044 #include "geometry/geometry_3d.h"
00045 #include "gamepad/manager.h"
00046 #include "map-kdtree/map-kdtree.h"
00047 #include "viewport/viewport.h"
00048 
00049 
00050 // forward declarations
00051 namespace aesop {
00052         class MapDynamics;
00053 }
00054 
00055 
00056 
00057 namespace aesop {
00058 
00059 /// \ingroup glut_app
00060 /*@{*/
00061 
00062 
00063 /// anyone that wants events from a terminal needs to implement this interface
00064 class TerminalHost {
00065 public:
00066         // aesop::TerminalHost class interface methods ------------------------
00067 
00068         /// terminal is requesting to move player by the specified amount
00069         /// (\var delta ).  \var newPosition will return the actual position
00070         /// of the player at the moment.
00071         virtual void requestMove(IN int playerId,
00072                                 IN const point3d_t& delta,
00073                                 IN const point3d_t& euler,
00074                                 OUT point3d_t& newPosition) = 0;
00075 
00076         /// terminal is notifying host that player input has been received
00077         virtual void notifyInput(IN int playerId,
00078                                 IN const event_t& event) = 0;
00079 
00080 protected:
00081         // cannot delete through this interface! -------------------------------
00082         virtual ~TerminalHost(void) throw();
00083 };
00084 
00085 
00086 /// Class that manages input + display for a particular player.
00087 class Terminal : public view::Host {
00088 public:
00089         virtual ~Terminal(void) throw();
00090 
00091         // aesop::Terminal class interface methods ------------------------------
00092         virtual void setKeys(IN smart_ptr<crypto::DESKey>& desKey,
00093                                 IN smart_ptr<gamepad::Manager>& mgr) = 0;
00094         virtual void input(IN gamepad::Gamepad * gp,
00095                                 IN float dt) = 0;
00096         virtual void mouseMove(IN int x, IN int y) = 0;
00097         virtual void mouseButton(IN int button, IN int state,
00098                                 IN int x, IN int y) = 0;
00099         virtual void keyboard(IN int key, IN int mods) = 0;
00100         virtual void showDialog(IN const char * id,
00101                                 IN const Datahash * dialog,
00102                                 IN dialog::Host * host) = 0;
00103         virtual void destroyDialog(IN const char * id) = 0;
00104         virtual void notifyMap(IN MapKdTree * mapKdTree) = 0;  ///< can be null!
00105         virtual void notifyInstance(IN smart_ptr<Instance>& instance) = 0;
00106 
00107         // static factory methods ----------------------------------------------
00108         static smart_ptr<Terminal> create(IN TerminalHost * host,
00109                                 IN int playerId,
00110                                 IN smart_ptr<glut::RenderQueue>& rq);
00111 };
00112 
00113 
00114 
00115 };      // aesop namespace
00116 
00117 #endif  // AESOP_CLIENT_TERMINAL_H__
00118