Skyscraper 2.0
object.h
Go to the documentation of this file.
1/*
2 Scalable Building Simulator - Generic Object Class
3 The Skyscraper Project - Version 2.0
4 Copyright (C)2004-2024 Ryan Thoryk
5 https://www.skyscrapersim.net
6 https://sourceforge.net/projects/skyscraper/
7 Contact - ryan@skyscrapersim.net
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22*/
23
24#ifndef _SBS_OBJECT_H
25#define _SBS_OBJECT_H
26
27namespace SBS {
28
29class Object;
30
31//ObjectBase is used for lightweight objects, and core of Object
33{
34 friend class Object;
35
36public:
37 ObjectBase(Object *parent);
38 virtual ~ObjectBase() {};
39 Object* GetParent();
40 SBS* GetRoot();
41 void SetName(const std::string &name);
42 const std::string& GetName();
43 std::string GetNameBase();
44 virtual void Report(const std::string &message);
45 virtual bool ReportError(const std::string &message);
46
47protected:
48 SBS *sbs; //engine root
49
50private:
51 Object *Parent; //parent object
52 std::string Name; //object name
53};
54
56{
57public:
58
59 std::string command; //command line used to create object, if applicable
60 std::string command_processed; //processed command used to create object
61 std::string context; //script context object was created in
62 int linenum; //script line number where object was created
63 std::string includefile; //include file name
64 bool parent_deleting; //true if object's parent is deleting object
65
66 //functions
67 Object(Object *parent);
68 virtual ~Object();
69 void SetValues(const std::string &type, const std::string &name, bool is_permanent, bool is_movable = true);
70 bool IsPermanent();
71 bool IsMovable();
72 const std::string& GetType();
73 int GetNumber();
74 void AddChild(Object *object);
75 Object* GetChild(int index);
76 int GetChildrenCount();
77 void RemoveChild(Object *object);
78 SceneNode* GetSceneNode();
79 void ShowBoundingBox(bool value);
80 virtual void Move(const Vector3 &vector, Real speed = 1.0);
81 virtual void Move(Real X, Real Y, Real Z, Real speed = 1.0);
82 virtual void SetPosition(const Vector3 &position);
83 void SetPositionRelative(const Vector3 &position);
84 virtual void SetPosition(Real X, Real Y, Real Z);
85 void SetPositionRelative(Real X, Real Y, Real Z);
86 virtual void SetPositionY(Real value);
87 virtual Vector3 GetPosition(bool relative = false);
88 virtual void Rotate(const Vector3 &vector, Real speed = 1.0);
89 virtual void Rotate(Real X, Real Y, Real Z, Real speed = 1.0);
90 virtual void SetRotation(const Vector3 &rotation);
91 virtual void SetRotation(Real X, Real Y, Real Z);
92 virtual Vector3 GetRotation();
93 Quaternion GetOrientation(bool relative = false);
94 void SetOrientation(const Quaternion &q, bool relative = false);
95 virtual void OnMove(bool parent) {} //called when object is moved
96 virtual void OnRotate(bool parent) {} //called when object is rotated
97 virtual void OnClick(Vector3 &position, bool shift, bool ctrl, bool alt, bool right) {} //called when object is clicked on
98 virtual void OnUnclick(bool right) {} //called when mouse is held and released on object
99 virtual void OnHit() {} //called when user hits/collides with object
100 void NotifyMove(bool parent = false);
101 void NotifyRotate(bool parent = false);
102 virtual void ResetState() {} //resets the internal state of an object
103 void ChangeParent(Object *new_parent);
104 bool IsGlobal();
105 void Init(bool children = true); //pre-runloop (first-run) object initialization
106 virtual void OnInit() {} //called when object is initialized
107 virtual void Loop() {} //object runloop
108 void RegisterLoop(Object *object);
109 void UnregisterLoop(Object *object);
110 virtual void Enabled(bool value) {}
111 std::string GetNameBase();
112
113 template <typename T> bool IsType()
114 {
115 //check if an object is of the given type
116 return (dynamic_cast<T*>(this) > 0);
117 }
118
119 template <typename T> T* ConvertTo()
120 {
121 //convert object to the given type, if possible. Returns 0 on failure
122 return dynamic_cast<T*>(this);
123 }
124
125protected:
126 void EnableLoop(bool value);
127 void LoopChildren();
128 bool SelfDestruct();
129
130private:
131 void NotifyChildren(bool move, bool rotate);
132 void InitChildren();
133
134 bool Permanent; //is object permanent?
135 std::string Type; //object type
136 int Number; //object identifier
137 std::vector<Object*> children; //object's children
138 SceneNode *node; //node in scene graph
141 std::vector<Object*> runloops; //child object active runloops
143};
144
145}
146
147#endif
std::string Name
Definition object.h:52
Object * Parent
Definition object.h:51
virtual ~ObjectBase()
Definition object.h:38
bool values_set
Definition object.h:139
virtual void OnRotate(bool parent)
Definition object.h:96
bool parent_deleting
Definition object.h:64
std::string command
Definition object.h:59
std::string context
Definition object.h:61
int linenum
Definition object.h:62
bool Permanent
Definition object.h:134
std::vector< Object * > runloops
Definition object.h:141
bool initialized
Definition object.h:140
bool IsType()
Definition object.h:113
virtual void OnInit()
Definition object.h:106
virtual void OnMove(bool parent)
Definition object.h:95
virtual void ResetState()
Definition object.h:102
int Number
Definition object.h:136
virtual void Enabled(bool value)
Definition object.h:110
std::string command_processed
Definition object.h:60
std::vector< Object * > children
Definition object.h:137
virtual void OnHit()
Definition object.h:99
virtual void Loop()
Definition object.h:107
bool loop_enabled
Definition object.h:142
virtual void OnClick(Vector3 &position, bool shift, bool ctrl, bool alt, bool right)
Definition object.h:97
T * ConvertTo()
Definition object.h:119
std::string Type
Definition object.h:135
virtual void OnUnclick(bool right)
Definition object.h:98
std::string includefile
Definition object.h:63
SceneNode * node
Definition object.h:138
Ogre::Vector3 Vector3
Definition globals.h:58
Ogre::Real Real
Definition globals.h:57
#define SBSIMPEXP
Definition globals.h:53
Ogre::Quaternion Quaternion
Definition globals.h:60