mirror of
https://github.com/Relintai/terraman_2d.git
synced 2024-11-14 10:17:23 +01:00
Now the world inherits from Navigation2D.
This commit is contained in:
parent
208d21cd40
commit
467e862b08
@ -113,7 +113,6 @@ typedef class RenderingServer VS;
|
||||
#define INSTANCE_VALIDATE(var) var
|
||||
#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 GET_WORLD get_world_3d
|
||||
#define INSTANCE instantiate
|
||||
#define VREMOVE remove_at
|
||||
|
||||
@ -164,7 +163,6 @@ typedef class RenderingServer VS;
|
||||
#define INSTANCE_VALIDATE(var) ObjectDB::instance_validate(var)
|
||||
#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 GET_WORLD get_world
|
||||
#define INSTANCE instance
|
||||
#define VREMOVE remove
|
||||
|
||||
|
@ -310,14 +310,14 @@ void Terrain2DChunkDefault::meshes_create(const int mesh_index, const int mesh_c
|
||||
for (int i = 0; i < mesh_count; ++i) {
|
||||
RID mesh_instance_rid = VS::get_singleton()->instance_create();
|
||||
|
||||
if (get_voxel_world()->GET_WORLD().is_valid())
|
||||
VS::get_singleton()->instance_set_scenario(mesh_instance_rid, get_voxel_world()->GET_WORLD()->get_scenario());
|
||||
//if (get_voxel_world()->get_world_2d().is_valid())
|
||||
// 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();
|
||||
|
||||
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)
|
||||
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() {
|
||||
RID empty_rid;
|
||||
Transform t = get_transform();
|
||||
//Transform t = get_transform();
|
||||
|
||||
List<Variant> keys;
|
||||
|
||||
@ -500,8 +500,8 @@ void Terrain2DChunkDefault::update_transforms() {
|
||||
for (int i = 0; i < arr.size(); ++i) {
|
||||
RID rid = arr[i];
|
||||
|
||||
if (rid != empty_rid)
|
||||
VS::get_singleton()->instance_set_transform(rid, get_transform());
|
||||
// if (rid != empty_rid)
|
||||
// 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));
|
||||
}
|
||||
|
||||
if (_debug_mesh_instance != RID()) {
|
||||
VS::get_singleton()->instance_set_transform(_debug_mesh_instance, get_transform());
|
||||
}
|
||||
//if (_debug_mesh_instance != RID()) {
|
||||
// VS::get_singleton()->instance_set_transform(_debug_mesh_instance, get_transform());
|
||||
//}
|
||||
}
|
||||
|
||||
//Lights
|
||||
@ -549,11 +549,11 @@ void Terrain2DChunkDefault::debug_mesh_allocate() {
|
||||
if (_debug_mesh_instance == RID()) {
|
||||
_debug_mesh_instance = VisualServer::get_singleton()->instance_create();
|
||||
|
||||
if (get_voxel_world()->GET_WORLD().is_valid())
|
||||
VS::get_singleton()->instance_set_scenario(_debug_mesh_instance, get_voxel_world()->GET_WORLD()->get_scenario());
|
||||
//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_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);
|
||||
}
|
||||
}
|
||||
|
@ -142,6 +142,7 @@ PoolColorArray Terrain2DWorldDefault::get_vertex_colors(const Transform &transfo
|
||||
}
|
||||
|
||||
void Terrain2DWorldDefault::_update_lods() {
|
||||
/*
|
||||
if (!get_player() || !INSTANCE_VALIDATE(get_player())) {
|
||||
return;
|
||||
}
|
||||
@ -149,7 +150,7 @@ void Terrain2DWorldDefault::_update_lods() {
|
||||
if (_num_lods <= 1)
|
||||
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 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)
|
||||
c->set_current_lod_level(mr);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Ref<Terrain2DChunk> Terrain2DWorldDefault::_create_chunk(int x, int z, Ref<Terrain2DChunk> chunk) {
|
||||
|
@ -85,7 +85,7 @@ void Terrain2DProp2DJob::phase_physics_process() {
|
||||
PhysicsServer::get_singleton()->body_set_collision_mask(body, 1);
|
||||
|
||||
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()) {
|
||||
PhysicsServer::get_singleton()->body_set_space(body, world->get_space());
|
||||
|
@ -1039,24 +1039,24 @@ void Terrain2DChunk::generation_physics_process(const float delta) {
|
||||
call("_generation_physics_process", delta);
|
||||
}
|
||||
|
||||
Transform Terrain2DChunk::get_transform() const {
|
||||
Transform2D Terrain2DChunk::get_transform() const {
|
||||
return _transform;
|
||||
}
|
||||
void Terrain2DChunk::set_transform(const Transform &transform) {
|
||||
void Terrain2DChunk::set_transform(const Transform2D &transform) {
|
||||
_transform = transform;
|
||||
}
|
||||
|
||||
Transform Terrain2DChunk::get_global_transform() const {
|
||||
ERR_FAIL_COND_V(!get_voxel_world(), Transform());
|
||||
Transform2D Terrain2DChunk::get_global_transform() const {
|
||||
ERR_FAIL_COND_V(!get_voxel_world(), Transform2D());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Vector3 Terrain2DChunk::to_global(Vector3 p_local) const {
|
||||
Vector2 Terrain2DChunk::to_global(Vector2 p_local) const {
|
||||
return get_global_transform().xform(p_local);
|
||||
}
|
||||
|
||||
@ -1241,13 +1241,14 @@ void Terrain2DChunk::_generation_physics_process(const float delta) {
|
||||
}
|
||||
|
||||
void Terrain2DChunk::_world_transform_changed() {
|
||||
Transform wt;
|
||||
Transform2D wt;
|
||||
|
||||
if (_voxel_world != NULL) {
|
||||
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)));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -302,12 +302,12 @@ public:
|
||||
void generation_process(const float delta);
|
||||
void generation_physics_process(const float delta);
|
||||
|
||||
Transform get_transform() const;
|
||||
void set_transform(const Transform &transform);
|
||||
Transform2D get_transform() const;
|
||||
void set_transform(const Transform2D &transform);
|
||||
|
||||
Transform get_global_transform() const;
|
||||
Vector3 to_local(Vector3 p_global) const;
|
||||
Vector3 to_global(Vector3 p_local) const;
|
||||
Transform2D get_global_transform() const;
|
||||
Vector2 to_local(Vector2 p_global) const;
|
||||
Vector2 to_global(Vector2 p_local) const;
|
||||
|
||||
bool is_safe_to_delete();
|
||||
|
||||
@ -413,7 +413,7 @@ protected:
|
||||
|
||||
Vector<ColliderBody> _colliders;
|
||||
|
||||
Transform _transform;
|
||||
Transform2D _transform;
|
||||
|
||||
bool _abort_build;
|
||||
bool _queued_generation;
|
||||
|
@ -168,14 +168,14 @@ void Terrain2DWorld::set_player_path(const NodePath &player_path) {
|
||||
_player_path = player_path;
|
||||
}
|
||||
|
||||
Spatial *Terrain2DWorld::get_player() const {
|
||||
Node2D *Terrain2DWorld::get_player() const {
|
||||
return _player;
|
||||
}
|
||||
void Terrain2DWorld::set_player(Spatial *player) {
|
||||
void Terrain2DWorld::set_player(Node2D *player) {
|
||||
_player = 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 {
|
||||
@ -866,27 +866,6 @@ int Terrain2DWorld::get_channel_index_info(const Terrain2DWorld::ChannelTypeInfo
|
||||
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() {
|
||||
_active = true;
|
||||
_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_editor_camera"), &Terrain2DWorld::get_editor_camera);
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
BIND_VMETHOD(MethodInfo("_set_voxel_with_tool",
|
||||
PropertyInfo(Variant::BOOL, "mode_add"),
|
||||
|
@ -35,7 +35,7 @@ SOFTWARE.
|
||||
|
||||
#include "../defines.h"
|
||||
|
||||
#include navigation_h
|
||||
#include "scene/2d/navigation_2d.h"
|
||||
|
||||
#include "../areas/terrain_2d_world_area.h"
|
||||
#include "../level_generator/terrain_2d_level_generator.h"
|
||||
@ -51,8 +51,8 @@ class Terrain2DStructure;
|
||||
class Terrain2DChunk;
|
||||
class Prop2DData;
|
||||
|
||||
class Terrain2DWorld : public Navigation {
|
||||
GDCLASS(Terrain2DWorld, Navigation);
|
||||
class Terrain2DWorld : public Navigation2D {
|
||||
GDCLASS(Terrain2DWorld, Navigation2D);
|
||||
|
||||
public:
|
||||
enum ChannelTypeInfo {
|
||||
@ -110,8 +110,8 @@ public:
|
||||
NodePath get_player_path() const;
|
||||
void set_player_path(const NodePath &player_path);
|
||||
|
||||
Spatial *get_player() const;
|
||||
void set_player(Spatial *player);
|
||||
Node2D *get_player() const;
|
||||
void set_player(Node2D *player);
|
||||
void set_player_bind(Node *player);
|
||||
|
||||
//World Areas
|
||||
@ -192,8 +192,6 @@ public:
|
||||
|
||||
int get_channel_index_info(const ChannelTypeInfo channel_type);
|
||||
|
||||
Spatial *get_editor_camera();
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
GDVIRTUAL1(_chunk_added, Ref<Terrain2DChunk>);
|
||||
|
||||
@ -276,7 +274,7 @@ private:
|
||||
Vector<Ref<Terrain2DStructure>> _voxel_structures;
|
||||
|
||||
NodePath _player_path;
|
||||
Spatial *_player;
|
||||
Node2D *_player;
|
||||
|
||||
int _max_concurrent_generations;
|
||||
Vector<Ref<Terrain2DChunk>> _generation_queue;
|
||||
|
@ -104,6 +104,7 @@ EditorPlugin::AfterGUIInput Terrain2DWorldEditor::forward_spatial_input_event(Ca
|
||||
#endif
|
||||
|
||||
bool Terrain2DWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) {
|
||||
/*
|
||||
if (!spatial_editor || !_world || !_world->is_inside_world())
|
||||
return false;
|
||||
|
||||
@ -115,7 +116,7 @@ bool Terrain2DWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_poi
|
||||
from = local_xform.xform(from);
|
||||
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;
|
||||
|
||||
@ -144,7 +145,7 @@ bool Terrain2DWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_poi
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user