Now the world inherits from Navigation2D.

This commit is contained in:
Relintai 2022-02-23 20:01:38 +01:00
parent 208d21cd40
commit 467e862b08
9 changed files with 43 additions and 66 deletions

View File

@ -113,7 +113,6 @@ typedef class RenderingServer VS;
#define INSTANCE_VALIDATE(var) var #define INSTANCE_VALIDATE(var) var
#define CONNECT(sig, obj, target_method_class, method) connect(sig, callable_mp(obj, &target_method_class::method)) #define CONNECT(sig, obj, target_method_class, method) connect(sig, callable_mp(obj, &target_method_class::method))
#define DISCONNECT(sig, obj, target_method_class, method) disconnect(sig, callable_mp(obj, &target_method_class::method)) #define DISCONNECT(sig, obj, target_method_class, method) disconnect(sig, callable_mp(obj, &target_method_class::method))
#define GET_WORLD get_world_3d
#define INSTANCE instantiate #define INSTANCE instantiate
#define VREMOVE remove_at #define VREMOVE remove_at
@ -164,7 +163,6 @@ typedef class RenderingServer VS;
#define INSTANCE_VALIDATE(var) ObjectDB::instance_validate(var) #define INSTANCE_VALIDATE(var) ObjectDB::instance_validate(var)
#define CONNECT(sig, obj, target_method_class, method) connect(sig, obj, #method) #define CONNECT(sig, obj, target_method_class, method) connect(sig, obj, #method)
#define DISCONNECT(sig, obj, target_method_class, method) disconnect(sig, obj, #method) #define DISCONNECT(sig, obj, target_method_class, method) disconnect(sig, obj, #method)
#define GET_WORLD get_world
#define INSTANCE instance #define INSTANCE instance
#define VREMOVE remove #define VREMOVE remove

View File

@ -310,14 +310,14 @@ void Terrain2DChunkDefault::meshes_create(const int mesh_index, const int mesh_c
for (int i = 0; i < mesh_count; ++i) { for (int i = 0; i < mesh_count; ++i) {
RID mesh_instance_rid = VS::get_singleton()->instance_create(); RID mesh_instance_rid = VS::get_singleton()->instance_create();
if (get_voxel_world()->GET_WORLD().is_valid()) //if (get_voxel_world()->get_world_2d().is_valid())
VS::get_singleton()->instance_set_scenario(mesh_instance_rid, get_voxel_world()->GET_WORLD()->get_scenario()); // VS::get_singleton()->instance_set_scenario(mesh_instance_rid, get_voxel_world()->get_world_2d()->get_scenario());
RID mesh_rid = VS::get_singleton()->mesh_create(); RID mesh_rid = VS::get_singleton()->mesh_create();
VS::get_singleton()->instance_set_base(mesh_instance_rid, mesh_rid); VS::get_singleton()->instance_set_base(mesh_instance_rid, mesh_rid);
VS::get_singleton()->instance_set_transform(mesh_instance_rid, get_transform()); //VS::get_singleton()->instance_set_transform(mesh_instance_rid, get_transform());
if (i != 0) if (i != 0)
VS::get_singleton()->instance_set_visible(mesh_instance_rid, false); VS::get_singleton()->instance_set_visible(mesh_instance_rid, false);
@ -480,7 +480,7 @@ void Terrain2DChunkDefault::free_index(const int mesh_index) {
void Terrain2DChunkDefault::update_transforms() { void Terrain2DChunkDefault::update_transforms() {
RID empty_rid; RID empty_rid;
Transform t = get_transform(); //Transform t = get_transform();
List<Variant> keys; List<Variant> keys;
@ -500,8 +500,8 @@ void Terrain2DChunkDefault::update_transforms() {
for (int i = 0; i < arr.size(); ++i) { for (int i = 0; i < arr.size(); ++i) {
RID rid = arr[i]; RID rid = arr[i];
if (rid != empty_rid) // if (rid != empty_rid)
VS::get_singleton()->instance_set_transform(rid, get_transform()); // VS::get_singleton()->instance_set_transform(rid, get_transform());
} }
} }
@ -526,9 +526,9 @@ void Terrain2DChunkDefault::update_transforms() {
//PhysicsServer::get_singleton()->body_set_state(collider_get_body(i), PhysicsServer::BODY_STATE_TRANSFORM, get_transform() * collider_get_transform(i)); //PhysicsServer::get_singleton()->body_set_state(collider_get_body(i), PhysicsServer::BODY_STATE_TRANSFORM, get_transform() * collider_get_transform(i));
} }
if (_debug_mesh_instance != RID()) { //if (_debug_mesh_instance != RID()) {
VS::get_singleton()->instance_set_transform(_debug_mesh_instance, get_transform()); // VS::get_singleton()->instance_set_transform(_debug_mesh_instance, get_transform());
} //}
} }
//Lights //Lights
@ -549,11 +549,11 @@ void Terrain2DChunkDefault::debug_mesh_allocate() {
if (_debug_mesh_instance == RID()) { if (_debug_mesh_instance == RID()) {
_debug_mesh_instance = VisualServer::get_singleton()->instance_create(); _debug_mesh_instance = VisualServer::get_singleton()->instance_create();
if (get_voxel_world()->GET_WORLD().is_valid()) //if (get_voxel_world()->GET_WORLD().is_valid())
VS::get_singleton()->instance_set_scenario(_debug_mesh_instance, get_voxel_world()->GET_WORLD()->get_scenario()); // VS::get_singleton()->instance_set_scenario(_debug_mesh_instance, get_voxel_world()->GET_WORLD()->get_scenario());
VS::get_singleton()->instance_set_base(_debug_mesh_instance, _debug_mesh_rid); VS::get_singleton()->instance_set_base(_debug_mesh_instance, _debug_mesh_rid);
VS::get_singleton()->instance_set_transform(_debug_mesh_instance, get_transform()); //VS::get_singleton()->instance_set_transform(_debug_mesh_instance, get_transform());
VS::get_singleton()->instance_set_visible(_debug_mesh_instance, true); VS::get_singleton()->instance_set_visible(_debug_mesh_instance, true);
} }
} }

View File

@ -142,6 +142,7 @@ PoolColorArray Terrain2DWorldDefault::get_vertex_colors(const Transform &transfo
} }
void Terrain2DWorldDefault::_update_lods() { void Terrain2DWorldDefault::_update_lods() {
/*
if (!get_player() || !INSTANCE_VALIDATE(get_player())) { if (!get_player() || !INSTANCE_VALIDATE(get_player())) {
return; return;
} }
@ -149,7 +150,7 @@ void Terrain2DWorldDefault::_update_lods() {
if (_num_lods <= 1) if (_num_lods <= 1)
return; return;
Vector3 ppos = get_player()->get_transform().origin; Vector2 ppos = get_player()->get_transform().get_origin();
int ppx = int(ppos.x / get_chunk_size_x() / get_voxel_scale()); int ppx = int(ppos.x / get_chunk_size_x() / get_voxel_scale());
int ppz = int(ppos.z / get_chunk_size_z() / get_voxel_scale()); int ppz = int(ppos.z / get_chunk_size_z() / get_voxel_scale());
@ -173,6 +174,7 @@ void Terrain2DWorldDefault::_update_lods() {
if (c->get_current_lod_level() != mr) if (c->get_current_lod_level() != mr)
c->set_current_lod_level(mr); c->set_current_lod_level(mr);
} }
*/
} }
Ref<Terrain2DChunk> Terrain2DWorldDefault::_create_chunk(int x, int z, Ref<Terrain2DChunk> chunk) { Ref<Terrain2DChunk> Terrain2DWorldDefault::_create_chunk(int x, int z, Ref<Terrain2DChunk> chunk) {

View File

@ -85,7 +85,7 @@ void Terrain2DProp2DJob::phase_physics_process() {
PhysicsServer::get_singleton()->body_set_collision_mask(body, 1); PhysicsServer::get_singleton()->body_set_collision_mask(body, 1);
if (chunk->get_voxel_world()->is_inside_tree() && chunk->get_voxel_world()->is_inside_world()) { if (chunk->get_voxel_world()->is_inside_tree() && chunk->get_voxel_world()->is_inside_world()) {
Ref<World> world = chunk->get_voxel_world()->GET_WORLD(); Ref<World> world = chunk->get_voxel_world()->get_world_2d();
if (world.is_valid() && world->get_space() != RID()) { if (world.is_valid() && world->get_space() != RID()) {
PhysicsServer::get_singleton()->body_set_space(body, world->get_space()); PhysicsServer::get_singleton()->body_set_space(body, world->get_space());

View File

@ -1039,24 +1039,24 @@ void Terrain2DChunk::generation_physics_process(const float delta) {
call("_generation_physics_process", delta); call("_generation_physics_process", delta);
} }
Transform Terrain2DChunk::get_transform() const { Transform2D Terrain2DChunk::get_transform() const {
return _transform; return _transform;
} }
void Terrain2DChunk::set_transform(const Transform &transform) { void Terrain2DChunk::set_transform(const Transform2D &transform) {
_transform = transform; _transform = transform;
} }
Transform Terrain2DChunk::get_global_transform() const { Transform2D Terrain2DChunk::get_global_transform() const {
ERR_FAIL_COND_V(!get_voxel_world(), Transform()); ERR_FAIL_COND_V(!get_voxel_world(), Transform2D());
return get_voxel_world()->get_global_transform() * _transform; return get_voxel_world()->get_global_transform() * _transform;
} }
Vector3 Terrain2DChunk::to_local(Vector3 p_global) const { Vector2 Terrain2DChunk::to_local(Vector2 p_global) const {
return get_global_transform().affine_inverse().xform(p_global); return get_global_transform().affine_inverse().xform(p_global);
} }
Vector3 Terrain2DChunk::to_global(Vector3 p_local) const { Vector2 Terrain2DChunk::to_global(Vector2 p_local) const {
return get_global_transform().xform(p_local); return get_global_transform().xform(p_local);
} }
@ -1241,13 +1241,14 @@ void Terrain2DChunk::_generation_physics_process(const float delta) {
} }
void Terrain2DChunk::_world_transform_changed() { void Terrain2DChunk::_world_transform_changed() {
Transform wt; Transform2D wt;
if (_voxel_world != NULL) { if (_voxel_world != NULL) {
wt = _voxel_world->get_transform(); wt = _voxel_world->get_transform();
} }
set_transform(wt * Transform(Basis(), Vector3(_position_x * static_cast<int>(_size_x) * _voxel_scale, 0, _position_z * static_cast<int>(_size_z) * _voxel_scale))); //TODO
//set_transform(wt * Transform(Basis(), Vector3(_position_x * static_cast<int>(_size_x) * _voxel_scale, 0, _position_z * static_cast<int>(_size_z) * _voxel_scale)));
} }
/* /*

View File

@ -302,12 +302,12 @@ public:
void generation_process(const float delta); void generation_process(const float delta);
void generation_physics_process(const float delta); void generation_physics_process(const float delta);
Transform get_transform() const; Transform2D get_transform() const;
void set_transform(const Transform &transform); void set_transform(const Transform2D &transform);
Transform get_global_transform() const; Transform2D get_global_transform() const;
Vector3 to_local(Vector3 p_global) const; Vector2 to_local(Vector2 p_global) const;
Vector3 to_global(Vector3 p_local) const; Vector2 to_global(Vector2 p_local) const;
bool is_safe_to_delete(); bool is_safe_to_delete();
@ -413,7 +413,7 @@ protected:
Vector<ColliderBody> _colliders; Vector<ColliderBody> _colliders;
Transform _transform; Transform2D _transform;
bool _abort_build; bool _abort_build;
bool _queued_generation; bool _queued_generation;

View File

@ -168,14 +168,14 @@ void Terrain2DWorld::set_player_path(const NodePath &player_path) {
_player_path = player_path; _player_path = player_path;
} }
Spatial *Terrain2DWorld::get_player() const { Node2D *Terrain2DWorld::get_player() const {
return _player; return _player;
} }
void Terrain2DWorld::set_player(Spatial *player) { void Terrain2DWorld::set_player(Node2D *player) {
_player = player; _player = player;
} }
void Terrain2DWorld::set_player_bind(Node *player) { void Terrain2DWorld::set_player_bind(Node *player) {
set_player(Object::cast_to<Spatial>(player)); set_player(Object::cast_to<Node2D>(player));
} }
Ref<Terrain2DWorldArea> Terrain2DWorld::world_area_get(const int index) const { Ref<Terrain2DWorldArea> Terrain2DWorld::world_area_get(const int index) const {
@ -866,27 +866,6 @@ int Terrain2DWorld::get_channel_index_info(const Terrain2DWorld::ChannelTypeInfo
RETURN_CALLP(int, _get_channel_index_info, channel_type); RETURN_CALLP(int, _get_channel_index_info, channel_type);
} }
Spatial *Terrain2DWorld::get_editor_camera() {
#if TOOLS_ENABLED
SpatialEditor *se = SpatialEditor::get_singleton();
if (!se) {
return nullptr;
}
SpatialEditorViewport *wp = se->get_editor_viewport(0);
if (!wp) {
return nullptr;
}
return wp->get_camera();
#else
return nullptr;
#endif
}
Terrain2DWorld::Terrain2DWorld() { Terrain2DWorld::Terrain2DWorld() {
_active = true; _active = true;
_editable = false; _editable = false;
@ -1251,8 +1230,6 @@ void Terrain2DWorld::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_channel_index_info", "channel_type"), &Terrain2DWorld::get_channel_index_info); ClassDB::bind_method(D_METHOD("get_channel_index_info", "channel_type"), &Terrain2DWorld::get_channel_index_info);
ClassDB::bind_method(D_METHOD("_get_channel_index_info", "channel_type"), &Terrain2DWorld::_get_channel_index_info); ClassDB::bind_method(D_METHOD("_get_channel_index_info", "channel_type"), &Terrain2DWorld::_get_channel_index_info);
ClassDB::bind_method(D_METHOD("get_editor_camera"), &Terrain2DWorld::get_editor_camera);
#if VERSION_MAJOR < 4 #if VERSION_MAJOR < 4
BIND_VMETHOD(MethodInfo("_set_voxel_with_tool", BIND_VMETHOD(MethodInfo("_set_voxel_with_tool",
PropertyInfo(Variant::BOOL, "mode_add"), PropertyInfo(Variant::BOOL, "mode_add"),

View File

@ -35,7 +35,7 @@ SOFTWARE.
#include "../defines.h" #include "../defines.h"
#include navigation_h #include "scene/2d/navigation_2d.h"
#include "../areas/terrain_2d_world_area.h" #include "../areas/terrain_2d_world_area.h"
#include "../level_generator/terrain_2d_level_generator.h" #include "../level_generator/terrain_2d_level_generator.h"
@ -51,8 +51,8 @@ class Terrain2DStructure;
class Terrain2DChunk; class Terrain2DChunk;
class Prop2DData; class Prop2DData;
class Terrain2DWorld : public Navigation { class Terrain2DWorld : public Navigation2D {
GDCLASS(Terrain2DWorld, Navigation); GDCLASS(Terrain2DWorld, Navigation2D);
public: public:
enum ChannelTypeInfo { enum ChannelTypeInfo {
@ -110,8 +110,8 @@ public:
NodePath get_player_path() const; NodePath get_player_path() const;
void set_player_path(const NodePath &player_path); void set_player_path(const NodePath &player_path);
Spatial *get_player() const; Node2D *get_player() const;
void set_player(Spatial *player); void set_player(Node2D *player);
void set_player_bind(Node *player); void set_player_bind(Node *player);
//World Areas //World Areas
@ -192,8 +192,6 @@ public:
int get_channel_index_info(const ChannelTypeInfo channel_type); int get_channel_index_info(const ChannelTypeInfo channel_type);
Spatial *get_editor_camera();
#if VERSION_MAJOR >= 4 #if VERSION_MAJOR >= 4
GDVIRTUAL1(_chunk_added, Ref<Terrain2DChunk>); GDVIRTUAL1(_chunk_added, Ref<Terrain2DChunk>);
@ -276,7 +274,7 @@ private:
Vector<Ref<Terrain2DStructure>> _voxel_structures; Vector<Ref<Terrain2DStructure>> _voxel_structures;
NodePath _player_path; NodePath _player_path;
Spatial *_player; Node2D *_player;
int _max_concurrent_generations; int _max_concurrent_generations;
Vector<Ref<Terrain2DChunk>> _generation_queue; Vector<Ref<Terrain2DChunk>> _generation_queue;

View File

@ -104,6 +104,7 @@ EditorPlugin::AfterGUIInput Terrain2DWorldEditor::forward_spatial_input_event(Ca
#endif #endif
bool Terrain2DWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) { bool Terrain2DWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) {
/*
if (!spatial_editor || !_world || !_world->is_inside_world()) if (!spatial_editor || !_world || !_world->is_inside_world())
return false; return false;
@ -115,7 +116,7 @@ bool Terrain2DWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_poi
from = local_xform.xform(from); from = local_xform.xform(from);
to = local_xform.xform(to); to = local_xform.xform(to);
PhysicsDirectSpaceState *ss = _world->GET_WORLD()->get_direct_space_state(); PhysicsDirectSpaceState *ss = _world->get_world_2d()->get_direct_space_state();
PhysicsDirectSpaceState::RayResult res; PhysicsDirectSpaceState::RayResult res;
@ -144,7 +145,7 @@ bool Terrain2DWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_poi
return true; return true;
} }
*/
return false; return false;
} }