map-dynamics.h

Go to the documentation of this file.
00001 /*
00002  * map-dynamics.h
00003  *
00004  * Copyright (C) 2008,2009  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 
00032 #ifndef AESOP_MAP_DYNAMICS_H__
00033 #define AESOP_MAP_DYNAMICS_H__
00034 
00035 
00036 // includes --------------------------------------------------------------------
00037 #include "aesop-map/map.h"
00038 #include "aesop-physics/aesop-physics.h"
00039 
00040 
00041 // forward decl
00042 class Datahash;
00043 
00044 
00045 namespace aesop {
00046 
00047 
00048 ////////////////////////////////////////////////////////////////////////////////
00049 ///
00050 /// \ingroup aesop_map_mgmt
00051 /// \defgroup map_dynamics Map Dynamics Library
00052 ///
00053 /// These objects know how to dynamically manipulate (tick) loaded maps.
00054 /// This library is what binds the \ref aesop_physics library with Maps.
00055 ///
00056 /// Map objects themselves don't understand physics or dynamics, they just
00057 /// provide raw data about object placement and space (zone) partitioning.
00058 ///
00059 /// The purpose of this library is to allow people to implement their own
00060 /// Map / Zone objects as necessary (different space partitioning schemes,
00061 /// different map formats, etc.) but be able to re-use all of the handling for
00062 /// dynamic objects.  The goal is that people can override map/zone objects
00063 /// without worrying about dynamics at all.
00064 ///
00065 /// <b>This library must know nothing about rendering.</b>  MapDynamics
00066 /// objects are used on both the server (as the authoritative state) and on the
00067 /// client (in a predictive, non-authoritative way to accommodate network lag).
00068 ///
00069 ////////////////////////////////////////////////////////////////////////////////
00070 /*@{*/
00071 
00072 
00073 /// zone iteration callback
00074 typedef void (*zone_obj_iteration_fn)(
00075                                 IN smart_ptr<Instance>& instance,
00076                                 IN smart_ptr<PhysicsObject>& obj,
00077                                 IN void * context);
00078 
00079 
00080 /// this is a base class for caller-specified context attached to PhysicsObjects
00081 class ObjectContext {
00082 public:
00083         // virtual destructor --------------------------------------------------
00084         virtual ~ObjectContext(void) throw();
00085 };
00086 
00087 
00088 
00089 /// create one of these to handle dynamics (physics etc.) for a given Map
00090 class MapDynamics {
00091 public:
00092         // virtual destructor --------------------------------------------------
00093         virtual ~MapDynamics(void) throw();
00094 
00095         // aesop::MapDynamics class interface methods -------------------------
00096         virtual smart_ptr<Map> getMap(void) = 0;
00097         virtual smart_ptr<PhysicsWorld> getPhysics(void) = 0;
00098         virtual smart_ptr<PhysicsObject> addInstance(
00099                                 IN smart_ptr<Instance>& instance) = 0;
00100         virtual void removeObject(IN smart_ptr<PhysicsObject>& obj) = 0;
00101         virtual void tickMap(IN float seconds) = 0;
00102 
00103         /// iterates over all instances within the given zone (static and
00104         ///   dynamic objects).
00105         virtual void iterateInstancesInZone(IN Zone * zone,
00106                                 IN zone_obj_iteration_fn fn,
00107                                 IN void * context) = 0;
00108 
00109         // static factory methods ----------------------------------------------
00110         static smart_ptr<MapDynamics> create(IN smart_ptr<Map>& map,
00111                                 IN const Datahash * params);
00112 };
00113 
00114 
00115 
00116 /// can return null!
00117 smart_ptr<Instance> getInstanceFromPhysicsObject(IN smart_ptr<PhysicsObject>& obj);
00118 
00119 
00120 /// can return null!
00121 MapDynamics * getMapDynamicsFromPhysicsObject(IN smart_ptr<PhysicsObject>& obj);
00122 
00123 
00124 };      // aesop namespace
00125 
00126 #endif  // AESOP_MAP_DYNAMICS_H__
00127