Skyscraper 2.0
floorindicator.cpp
Go to the documentation of this file.
1/*
2 Scalable Building Simulator - Floor Indicator Object
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#include "globals.h"
25#include "sbs.h"
26#include "mesh.h"
27#include "elevator.h"
28#include "elevatorcar.h"
29#include "profiler.h"
30#include "floor.h"
31#include "timer.h"
32#include "texture.h"
33#include "floorindicator.h"
34
35namespace SBS {
36
38{
39public:
41 bool on;
42 Timer(const std::string &name, FloorIndicator *parent) : TimerObject(parent, name)
43 {
44 indicator = parent;
45 on = false;
46 }
47 virtual void Notify();
48};
49
50FloorIndicator::FloorIndicator(Object *parent, int index, int elevator, int car, const std::string &texture_prefix, const std::string &blank_texture, const std::string &direction, Real CenterX, Real CenterZ, Real width, Real height, Real voffset) : Object(parent)
51{
52 //creates a new floor indicator at the specified position
53
54 //set up SBS object
55 SetValues("FloorIndicator", "", false);
56
57 is_enabled = true;
58 elev = elevator;
59 this->car = car;
60 Prefix = texture_prefix;
61 Blank = blank_texture;
62 off = false;
63
64 //move object
65 Move(CenterX, voffset, CenterZ);
66
67 std::string ext;
68 if (index > 0)
69 ext = ":" + ToString(index + 1);
70 std::string name = "Floor Indicator " + ToString(elevator) + ext;
71 SetName(name);
72
73 FloorIndicatorMesh = new MeshObject(this, name, 0, "", "", sbs->GetConfigFloat("Skyscraper.SBS.MaxSmallRenderDistance", 100));
74
75 //exit if elevator is invalid
76 if (!sbs->GetElevator(elev))
77 return;
78
79 //exit if the elevator car is invalid
81 if (!Car)
82 return;
83
84 //exit if the car starting floor is invalid
85 if (!sbs->GetFloor(Car->StartingFloor))
86 return;
87
88 std::string texture = Prefix + sbs->GetFloor(Car->StartingFloor)->ID;
89 sbs->GetTextureManager()->EnableLighting(texture, false);
90 std::string tmpdirection = direction;
91 SetCase(tmpdirection, false);
92
93 Wall *wall = FloorIndicatorMesh->CreateWallObject("Floor Indicator");
94 if (tmpdirection == "front" || tmpdirection == "back")
95 {
96 if (tmpdirection == "front")
97 sbs->DrawWalls(true, false, false, false, false, false);
98 else
99 sbs->DrawWalls(false, true, false, false, false, false);
100
101 sbs->AddWallMain(wall, "Floor Indicator", texture, 0, -width / 2, 0, width / 2, 0, height, height, 0, 0, 1, 1, false);
102 }
103 else if (tmpdirection == "left" || tmpdirection == "right")
104 {
105 if (tmpdirection == "left")
106 sbs->DrawWalls(true, false, false, false, false, false);
107 else
108 sbs->DrawWalls(false, true, false, false, false, false);
109
110 sbs->AddWallMain(wall, "Floor Indicator", texture, 0, 0, width / 2, 0, -width / 2, height, height, 0, 0, 1, 1, false);
111 }
112 sbs->ResetWalls();
113
114 flash_timer = new Timer("Flash Timer", this);
115
116 EnableLoop(true);
117}
118
120{
121 //delete timer
122 if (flash_timer)
123 delete flash_timer;
124 flash_timer = 0;
125
127 {
129 delete FloorIndicatorMesh;
130 }
132
133 //unregister from parent
134 if (sbs->FastDelete == false && parent_deleting == false)
135 {
136 std::string type = GetParent()->GetType();
137
138 if (type == "ElevatorCar")
139 static_cast<ElevatorCar*>(GetParent())->RemoveFloorIndicator(this);
140 else if (type == "Floor")
141 static_cast<Floor*>(GetParent())->RemoveFloorIndicator(this);
142 }
143}
144
146{
147 //turns indicator on/off
148
149 if (is_enabled == value)
150 return;
151
153 is_enabled = value;
154}
155
157{
158 //update indicator display with elevator's current floor identifier
159
160 SBS_PROFILE("FloorIndicator::Update");
161
162 if (blank == true && Blank != "")
163 {
165 return;
166 }
167
168 Elevator *elevator = sbs->GetElevator(elev);
169
170 if (!elevator)
171 return;
172
173 ElevatorCar *car = elevator->GetCar(this->car);
174
175 if (!car)
176 return;
177
178 std::string texture = car->GetFloorDisplay();
179
180 //don't update texture if no value
181 if (texture == "")
182 return;
183
184 texture.insert(0, Prefix);
185
187 sbs->GetTextureManager()->EnableLighting(texture, false);
188}
189
190void FloorIndicator::Flash(bool enabled)
191{
192 if (enabled == true)
193 flash_timer->Start(500, false);
194 else
195 {
196 flash_timer->Stop();
197 Update(false); //refresh indicator
198 }
199}
200
202{
203 if (on == false)
204 {
205 indicator->Update(false);
206 on = true;
207 }
208 else
209 {
210 indicator->Update(true);
211 on = false;
212 }
213
214}
215
217{
218 //turn off indicator
219
220 if (off == true)
221 return;
222
223 off = true;
224 Update(true);
225}
226
228{
229 //turn on indicator
230
231 if (off == false)
232 return;
233
234 off = false;
235 Update();
236}
237
239{
240 if (sbs->GetPower() == false)
241 Off();
242 else
243 On();
244}
245
246}
std::string GetFloorDisplay()
ElevatorCar * GetCar(int number)
Timer(const std::string &name, FloorIndicator *parent)
void Enabled(bool value)
MeshObject * FloorIndicatorMesh
FloorIndicator(Object *parent, int index, int elevator, int car, const std::string &texture_prefix, const std::string &blank_texture, const std::string &direction, Real CenterX, Real CenterZ, Real width, Real height, Real altitude)
void Update(bool blank=false)
void Flash(bool enabled)
std::string ID
Definition floor.h:38
void Enabled(bool value)
Definition mesh.cpp:154
bool ChangeTexture(const std::string &texture, bool matcheck=true)
Definition mesh.cpp:709
Wall * CreateWallObject(const std::string &name)
Definition mesh.cpp:208
Object * GetParent()
Definition object.cpp:42
void SetName(const std::string &name)
Definition object.cpp:72
bool parent_deleting
Definition object.h:64
virtual void Move(const Vector3 &vector, Real speed=1.0)
Definition object.cpp:253
void SetValues(const std::string &type, const std::string &name, bool is_permanent, bool is_movable=true)
Definition object.cpp:144
void EnableLoop(bool value)
Definition object.cpp:521
const std::string & GetType()
Definition object.cpp:177
Elevator * GetElevator(int number)
Definition sbs.cpp:1746
bool GetPower()
Definition sbs.cpp:4701
Real GetConfigFloat(const std::string &key, Real default_value)
Definition sbs.cpp:3249
bool AddWallMain(Wall *wallobject, const std::string &name, const std::string &texture, Real thickness, Real x1, Real z1, Real x2, Real z2, Real height_in1, Real height_in2, Real altitude1, Real altitude2, Real tw, Real th, bool autosize)
Definition sbs.cpp:690
void ResetWalls(bool ToDefaults=false)
Definition sbs.cpp:1854
Floor * GetFloor(int number)
Definition sbs.cpp:1739
bool FastDelete
Definition sbs.h:188
TextureManager * GetTextureManager()
Definition sbs.cpp:4558
void DrawWalls(bool MainN, bool MainP, bool SideN, bool SideP, bool Top, bool Bottom)
Definition sbs.cpp:1833
void EnableLighting(const std::string &material_name, bool value)
Definition texture.cpp:2207
void Start(int milliseconds=-1, bool oneshot=false)
Definition timer.cpp:49
Ogre::Real Real
Definition globals.h:57
void SetCase(std::string &string, bool uppercase)
Definition globals.cpp:172
std::string ToString(int number)
Definition globals.cpp:279
#define SBS_PROFILE(name)
Definition profiler.h:131