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, bool force = false);
81 virtual void Move(Real X, Real Y, Real Z, Real speed = 1.0, bool force = false);
82 virtual void SetPosition(const Vector3 &position, bool relative = false, bool force = false);
83 virtual void SetPosition(Real X, Real Y, Real Z, bool relative = false, bool force = false);
84 virtual void SetPositionY(Real value, bool force = false);
85 virtual Vector3 GetPosition(bool relative = false);
86 virtual void Rotate(const Vector3 &vector, Real speed = 1.0);
87 virtual void Rotate(Real X, Real Y, Real Z, Real speed = 1.0);
88 virtual void SetRotation(const Vector3 &rotation);
89 virtual void SetRotation(Real X, Real Y, Real Z);
90 virtual Vector3 GetRotation();
91 Quaternion GetOrientation(bool relative = false);
92 void SetOrientation(const Quaternion &q, bool relative = false);
93 virtual void OnMove(bool parent) {} //called when object is moved
94 virtual void OnRotate(bool parent) {} //called when object is rotated
95 virtual void OnClick(Vector3 &position, bool shift, bool ctrl, bool alt, bool right) {} //called when object is clicked on
96 virtual void OnUnclick(bool right) {} //called when mouse is held and released on object
97 virtual void OnHit() {} //called when user hits/collides with object
98 void NotifyMove(bool parent = false);
99 void NotifyRotate(bool parent = false);
100 virtual void ResetState() {} //resets the internal state of an object
101 void ChangeParent(Object *new_parent);
102 bool IsGlobal();
103 void Init(bool children = true); //pre-runloop (first-run) object initialization
104 virtual void OnInit() {} //called when object is initialized
105 virtual void Loop() {} //object runloop
106 void RegisterLoop(Object *object);
107 void UnregisterLoop(Object *object);
108 virtual void Enabled(bool value) {}
109 virtual bool IsEnabled() { return true; }
110 std::string GetNameBase();
111
112 template <typename T> bool IsType()
113 {
114 //check if an object is of the given type
115 return (dynamic_cast<T*>(this) > 0);
116 }
117
118 template <typename T> T* ConvertTo()
119 {
120 //convert object to the given type, if possible. Returns 0 on failure
121 return dynamic_cast<T*>(this);
122 }
123
124protected:
125 void EnableLoop(bool value);
126 void LoopChildren();
127 bool SelfDestruct();
128
129private:
130 void NotifyChildren(bool move, bool rotate);
131 void InitChildren();
132
133 bool Permanent; //is object permanent?
134 std::string Type; //object type
135 int Number; //object identifier
136 std::vector<Object*> children; //object's children
137 SceneNode *node; //node in scene graph
140 std::vector<Object*> runloops; //child object active runloops
142};
143
144}
145
146#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:138
virtual void OnRotate(bool parent)
Definition object.h:94
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:133
std::vector< Object * > runloops
Definition object.h:140
bool initialized
Definition object.h:139
bool IsType()
Definition object.h:112
virtual void OnInit()
Definition object.h:104
virtual void OnMove(bool parent)
Definition object.h:93
virtual void ResetState()
Definition object.h:100
int Number
Definition object.h:135
virtual void Enabled(bool value)
Definition object.h:108
std::string command_processed
Definition object.h:60
std::vector< Object * > children
Definition object.h:136
virtual void OnHit()
Definition object.h:97
virtual void Loop()
Definition object.h:105
bool loop_enabled
Definition object.h:141
virtual void OnClick(Vector3 &position, bool shift, bool ctrl, bool alt, bool right)
Definition object.h:95
T * ConvertTo()
Definition object.h:118
std::string Type
Definition object.h:134
virtual bool IsEnabled()
Definition object.h:109
virtual void OnUnclick(bool right)
Definition object.h:96
std::string includefile
Definition object.h:63
SceneNode * node
Definition object.h:137
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