mirror of
https://github.com/Relintai/terraman_2d.git
synced 2024-11-12 10:15:18 +01:00
Now chunks use canvas items. This makes positions work on both rendering backends.
This commit is contained in:
parent
4b3e7accd4
commit
91ffd8d1c3
@ -686,6 +686,8 @@ void Terrain2DChunkDefault::_draw() {
|
||||
return;
|
||||
}
|
||||
|
||||
VisualServer::get_singleton()->canvas_item_clear(get_canvas_item());
|
||||
|
||||
Terrain2DWorld *world = get_voxel_world();
|
||||
|
||||
ERR_FAIL_COND(!world);
|
||||
@ -696,7 +698,7 @@ void Terrain2DChunkDefault::_draw() {
|
||||
RID terrain_texture_rid = mesh_rid_get(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_TEXTURE_RID);
|
||||
|
||||
//Note: the transform parameter is not implemented in gles2
|
||||
VisualServer::get_singleton()->canvas_item_add_mesh(world->get_canvas_item(), terrain_mesh_rid, Transform2D(), Color(1, 1, 1, 1), terrain_texture_rid, RID());
|
||||
VisualServer::get_singleton()->canvas_item_add_mesh(get_canvas_item(), terrain_mesh_rid, Transform2D(), Color(1, 1, 1, 1), terrain_texture_rid, RID());
|
||||
}
|
||||
|
||||
RID liquid_mesh_rid = mesh_rid_get(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH);
|
||||
@ -705,7 +707,7 @@ void Terrain2DChunkDefault::_draw() {
|
||||
RID liquid_texture_rid = mesh_rid_get(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_TEXTURE_RID);
|
||||
|
||||
//Note: the transform parameter is not implemented in gles2
|
||||
VisualServer::get_singleton()->canvas_item_add_mesh(world->get_canvas_item(), liquid_mesh_rid, Transform2D(), Color(1, 1, 1, 1), liquid_texture_rid, RID());
|
||||
VisualServer::get_singleton()->canvas_item_add_mesh(get_canvas_item(), liquid_mesh_rid, Transform2D(), Color(1, 1, 1, 1), liquid_texture_rid, RID());
|
||||
}
|
||||
|
||||
RID prop_mesh_rid = mesh_rid_get(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH);
|
||||
@ -714,7 +716,7 @@ void Terrain2DChunkDefault::_draw() {
|
||||
RID prop_texture_rid = mesh_rid_get(MESH_INDEX_PROP, MESH_TYPE_INDEX_TEXTURE_RID);
|
||||
|
||||
//Note: the transform parameter is not implemented in gles2
|
||||
VisualServer::get_singleton()->canvas_item_add_mesh(world->get_canvas_item(), prop_mesh_rid, Transform2D(), Color(1, 1, 1, 1), prop_texture_rid, RID());
|
||||
VisualServer::get_singleton()->canvas_item_add_mesh(get_canvas_item(), prop_mesh_rid, Transform2D(), Color(1, 1, 1, 1), prop_texture_rid, RID());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,12 +239,7 @@ void Terrain2DChunk::set_voxel_world(Terrain2DWorld *world) {
|
||||
_voxel_world = world;
|
||||
}
|
||||
void Terrain2DChunk::set_voxel_world_bind(Node *world) {
|
||||
if (world == NULL) {
|
||||
_voxel_world = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
_voxel_world = Object::cast_to<Terrain2DWorld>(world);
|
||||
set_voxel_world(Object::cast_to<Terrain2DWorld>(world));
|
||||
}
|
||||
|
||||
Ref<Terrain2DJob> Terrain2DChunk::job_get(int index) const {
|
||||
@ -1123,9 +1118,13 @@ Terrain2DChunk::Terrain2DChunk() {
|
||||
_world_height = 256;
|
||||
|
||||
_queued_generation = false;
|
||||
|
||||
_canvas_item = VisualServer::get_singleton()->canvas_item_create();
|
||||
}
|
||||
|
||||
Terrain2DChunk::~Terrain2DChunk() {
|
||||
VisualServer::get_singleton()->free(_canvas_item);
|
||||
|
||||
if (_library.is_valid()) {
|
||||
_library.unref();
|
||||
}
|
||||
@ -1156,6 +1155,10 @@ Terrain2DChunk::~Terrain2DChunk() {
|
||||
}
|
||||
|
||||
void Terrain2DChunk::_enter_tree() {
|
||||
if (_voxel_world) {
|
||||
VisualServer::get_singleton()->canvas_item_set_parent(get_canvas_item(), get_voxel_world()->get_canvas_item());
|
||||
}
|
||||
|
||||
for (int i = 0; i < _jobs.size(); ++i) {
|
||||
Ref<Terrain2DJob> j = _jobs[i];
|
||||
|
||||
@ -1249,6 +1252,8 @@ void Terrain2DChunk::_world_transform_changed() {
|
||||
t.set_origin( Vector2(_position_x * static_cast<int>(_size_x) * _voxel_scale, _position_z * static_cast<int>(_size_z) * _voxel_scale));
|
||||
|
||||
set_transform(t);
|
||||
|
||||
VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), t);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -66,8 +66,8 @@ include_pool_vector
|
||||
|
||||
#include "scene/resources/shape_2d.h"
|
||||
|
||||
#include "../library/terrain_2d_surface.h"
|
||||
#include "../library/terrain_2d_library.h"
|
||||
#include "../library/terrain_2d_surface.h"
|
||||
; //hackfix for a clang format issue
|
||||
|
||||
class Terrain2DJob;
|
||||
@ -312,6 +312,10 @@ public:
|
||||
|
||||
bool is_safe_to_delete();
|
||||
|
||||
_FORCE_INLINE_ RID get_canvas_item() const {
|
||||
return _canvas_item;
|
||||
}
|
||||
|
||||
Terrain2DChunk();
|
||||
~Terrain2DChunk();
|
||||
|
||||
@ -418,6 +422,8 @@ protected:
|
||||
|
||||
bool _abort_build;
|
||||
bool _queued_generation;
|
||||
|
||||
RID _canvas_item;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user