00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_ENGINE2_OBJECTLAYER_HPP_)
00012 #define _XRB_ENGINE2_OBJECTLAYER_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include <string>
00017
00018 #include "xrb_engine2_object.hpp"
00019 #include "xrb_engine2_types.hpp"
00020 #include "xrb_matrix2.hpp"
00021 #include "xrb_transform2.hpp"
00022 #include "xrb_vector.hpp"
00023
00024 namespace Xrb
00025 {
00026
00027 class RenderContext;
00028 class Serializer;
00029
00030 namespace Engine2
00031 {
00032
00033 class VisibilityQuadTree;
00034 class Entity;
00035 class World;
00036
00037 class ObjectLayer
00038 {
00039 public:
00040
00041 virtual ~ObjectLayer ();
00042
00043 static ObjectLayer *Create (
00044 World *owner_world,
00045 bool is_wrapped,
00046 Float side_length,
00047 Uint32 tree_depth,
00048 Float z_depth);
00049 static ObjectLayer *Create (
00050 Serializer &serializer,
00051 World *owner_world);
00052
00053 inline std::string const &Name () const { return m_name; }
00054 inline World *OwnerWorld () const { return m_owner_world; }
00055 inline bool IsWrapped () const { return m_is_wrapped; }
00056 inline Float SideLength () const { return m_side_length; }
00057 inline Float ZDepth () const { return m_z_depth; }
00058 Object *SmallestObjectTouchingPoint (FloatVector2 const &point) const;
00059 bool DoesAreaOverlapAnyObject (
00060 FloatVector2 const &area_center,
00061 Float area_radius) const;
00062 FloatVector2 NormalizedCoordinates (FloatVector2 const &coordinates) const;
00063 FloatVector2 AdjustedCoordinates (
00064 FloatVector2 const &coordinates,
00065 FloatVector2 const &reference_coordinates) const;
00066
00067 inline void SetName (std::string const &name) { m_name = name; }
00068 inline void SetIsWrapped (bool is_wrapped) { m_is_wrapped = is_wrapped; }
00069 inline void SetZDepth (Float z_depth) { m_z_depth = z_depth; }
00070
00071 void Write (Serializer &serializer) const;
00072 Uint32 Draw (
00073 RenderContext const &render_context,
00074 FloatMatrix2 const &world_to_screen,
00075 Float pixels_in_view_radius,
00076 FloatVector2 const &view_center,
00077 Float const &view_radius,
00078 TransparentObjectVector *transparent_object_vector);
00079 void AddObject (Object *object);
00080 void RemoveObject (Object *object);
00081
00082
00083
00084 void HandleContainmentOrWrapping (Object *object);
00085
00086 void ContainVector2 (FloatVector2 *vector) const;
00087
00088 void ContainTransform2 (FloatTransform2 *transform) const;
00089
00090
00091 void ContainEntity (Entity *entity) const;
00092 void WrapVector2 (FloatVector2 *vector) const;
00093 void WrapTransform2 (FloatTransform2 *transform) const;
00094 void WrapEntity (Entity *entity) const;
00095
00096 protected:
00097
00098
00099 ObjectLayer (
00100 World *owner_world,
00101 bool is_wrapped,
00102 Float side_length,
00103 Float z_depth);
00104
00105 inline VisibilityQuadTree *GetQuadTree () const
00106 {
00107 return m_quad_tree;
00108 }
00109
00110
00111
00112
00113
00114 std::string m_name;
00115
00116 VisibilityQuadTree *m_quad_tree;
00117
00118 private:
00119
00120
00121 World *m_owner_world;
00122
00123 Float m_side_length;
00124
00125 Float m_half_side_length;
00126
00127 Float m_z_depth;
00128
00129 bool m_is_wrapped;
00130 };
00131
00132 }
00133
00134 }
00135
00136 #endif // !defined(_XRB_ENGINE2_OBJECTLAYER_HPP_)