2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* room_instance.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:11:42 +02:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "room_instance.h"
|
|
|
|
|
|
|
|
#include "servers/visual_server.h"
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-08-27 21:07:15 +02:00
|
|
|
// FIXME: Will be removed, kept as reference for new implementation
|
2017-08-26 05:40:45 +02:00
|
|
|
#if 0
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "geometry.h"
|
2017-07-19 22:00:46 +02:00
|
|
|
#include "project_settings.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/resources/surface_tool.h"
|
|
|
|
|
|
|
|
void Room::_notification(int p_what) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_what) {
|
2014-02-10 02:10:30 +01:00
|
|
|
case NOTIFICATION_ENTER_WORLD: {
|
|
|
|
// go find parent level
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *parent_room = get_parent();
|
|
|
|
level = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (parent_room) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
Room *r = Object::cast_to<Room>(parent_room);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (r) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
level = r->level + 1;
|
2014-02-10 02:10:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
parent_room = parent_room->get_parent();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_EXIT_WORLD: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
Rect3 Room::get_aabb() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (room.is_null())
|
2017-01-11 04:52:51 +01:00
|
|
|
return Rect3();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
return Rect3();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<Face3> Room::get_faces(uint32_t p_usage_flags) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
return PoolVector<Face3>();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void Room::set_room(const Ref<RoomBounds> &p_room) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
room = p_room;
|
2014-02-10 02:10:30 +01:00
|
|
|
update_gizmo();
|
|
|
|
|
|
|
|
if (room.is_valid()) {
|
|
|
|
|
|
|
|
set_base(room->get_rid());
|
|
|
|
} else {
|
|
|
|
set_base(RID());
|
|
|
|
}
|
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
if (!is_inside_tree())
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
propagate_notification(NOTIFICATION_AREA_CHANGED);
|
|
|
|
update_gizmo();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<RoomBounds> Room::get_room() const {
|
|
|
|
|
|
|
|
return room;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void Room::_parse_node_faces(PoolVector<Face3> &all_faces, const Node *p_node) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
const VisualInstance *vi = Object::cast_to<VisualInstance>(p_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (vi) {
|
2017-03-05 16:44:50 +01:00
|
|
|
PoolVector<Face3> faces = vi->get_faces(FACES_ENCLOSING);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (faces.size()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
int old_len = all_faces.size();
|
|
|
|
all_faces.resize(all_faces.size() + faces.size());
|
|
|
|
int new_len = all_faces.size();
|
|
|
|
PoolVector<Face3>::Write all_facesw = all_faces.write();
|
|
|
|
Face3 *all_facesptr = all_facesw.ptr();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PoolVector<Face3>::Read facesr = faces.read();
|
|
|
|
const Face3 *facesptr = facesr.ptr();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform tr = vi->get_relative_transform(this);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = old_len; i < new_len; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Face3 f = facesptr[i - old_len];
|
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
f.vertex[j] = tr.xform(f.vertex[j]);
|
|
|
|
all_facesptr[i] = f;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_node->get_child_count(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_parse_node_faces(all_faces, p_node->get_child(i));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::_bounds_changed() {
|
|
|
|
|
|
|
|
update_gizmo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::_bind_methods() {
|
|
|
|
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_room", "room"), &Room::set_room);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_room"), &Room::get_room);
|
2017-01-15 20:06:14 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "room/room", PROPERTY_HINT_RESOURCE_TYPE, "Area"), "set_room", "get_room");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Room::Room() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
// sound_enabled=false;
|
2017-01-13 00:35:46 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
level = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Room::~Room() {
|
|
|
|
}
|
2017-08-26 05:40:45 +02:00
|
|
|
#endif
|