mirror of
https://github.com/Relintai/terraman_2d.git
synced 2025-02-20 17:24:45 +01:00
Initial drawing setup.
This commit is contained in:
parent
9e4e2becf8
commit
2a778660c9
@ -333,7 +333,7 @@ void Terrain2DChunkDefault::colliders_create(const int mesh_index, const int lay
|
|||||||
_rids[mesh_index] = m;
|
_rids[mesh_index] = m;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//todo
|
//todo
|
||||||
}
|
}
|
||||||
void Terrain2DChunkDefault::colliders_create_area(const int mesh_index, const int layer_mask) {
|
void Terrain2DChunkDefault::colliders_create_area(const int mesh_index, const int layer_mask) {
|
||||||
/*
|
/*
|
||||||
@ -646,6 +646,40 @@ void Terrain2DChunkDefault::_world_transform_changed() {
|
|||||||
update_transforms();
|
update_transforms();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Terrain2DChunkDefault::_draw() {
|
||||||
|
if (_is_generating) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Terrain2DWorld *world = get_voxel_world();
|
||||||
|
|
||||||
|
ERR_FAIL_COND(!world);
|
||||||
|
|
||||||
|
RID terrain_mesh_rid = mesh_rid_get(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_MESH);
|
||||||
|
|
||||||
|
if (terrain_mesh_rid != RID()) {
|
||||||
|
RID terrain_texture_rid = mesh_rid_get(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_TEXTURE_RID);
|
||||||
|
|
||||||
|
VisualServer::get_singleton()->canvas_item_add_mesh(world->get_canvas_item(), terrain_mesh_rid, get_transform(), Color(1, 1, 1, 1), terrain_texture_rid, RID());
|
||||||
|
}
|
||||||
|
|
||||||
|
RID liquid_mesh_rid = mesh_rid_get(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH);
|
||||||
|
|
||||||
|
if (liquid_mesh_rid != RID()) {
|
||||||
|
RID liquid_texture_rid = mesh_rid_get(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_TEXTURE_RID);
|
||||||
|
|
||||||
|
VisualServer::get_singleton()->canvas_item_add_mesh(world->get_canvas_item(), liquid_mesh_rid, get_transform(), Color(1, 1, 1, 1), liquid_texture_rid, RID());
|
||||||
|
}
|
||||||
|
|
||||||
|
RID prop_mesh_rid = mesh_rid_get(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH);
|
||||||
|
|
||||||
|
if (prop_mesh_rid != RID()) {
|
||||||
|
RID prop_texture_rid = mesh_rid_get(MESH_INDEX_PROP, MESH_TYPE_INDEX_TEXTURE_RID);
|
||||||
|
|
||||||
|
VisualServer::get_singleton()->canvas_item_add_mesh(world->get_canvas_item(), prop_mesh_rid, get_transform(), Color(1, 1, 1, 1), prop_texture_rid, RID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Lights
|
//Lights
|
||||||
void Terrain2DChunkDefault::_bake_lights() {
|
void Terrain2DChunkDefault::_bake_lights() {
|
||||||
clear_baked_lights();
|
clear_baked_lights();
|
||||||
@ -841,7 +875,8 @@ void Terrain2DChunkDefault::_bind_methods() {
|
|||||||
|
|
||||||
//virtuals
|
//virtuals
|
||||||
ClassDB::bind_method(D_METHOD("_channel_setup"), &Terrain2DChunkDefault::_channel_setup);
|
ClassDB::bind_method(D_METHOD("_channel_setup"), &Terrain2DChunkDefault::_channel_setup);
|
||||||
|
ClassDB::bind_method(D_METHOD("_draw"), &Terrain2DChunkDefault::_draw);
|
||||||
|
|
||||||
//lights
|
//lights
|
||||||
ClassDB::bind_method(D_METHOD("_bake_lights"), &Terrain2DChunkDefault::_bake_lights);
|
ClassDB::bind_method(D_METHOD("_bake_lights"), &Terrain2DChunkDefault::_bake_lights);
|
||||||
ClassDB::bind_method(D_METHOD("_bake_light", "light"), &Terrain2DChunkDefault::_bake_light);
|
ClassDB::bind_method(D_METHOD("_bake_light", "light"), &Terrain2DChunkDefault::_bake_light);
|
||||||
@ -869,6 +904,8 @@ void Terrain2DChunkDefault::_bind_methods() {
|
|||||||
BIND_CONSTANT(MESH_TYPE_INDEX_MESH);
|
BIND_CONSTANT(MESH_TYPE_INDEX_MESH);
|
||||||
BIND_CONSTANT(MESH_TYPE_INDEX_SHAPE);
|
BIND_CONSTANT(MESH_TYPE_INDEX_SHAPE);
|
||||||
BIND_CONSTANT(MESH_TYPE_INDEX_BODY);
|
BIND_CONSTANT(MESH_TYPE_INDEX_BODY);
|
||||||
|
BIND_CONSTANT(MESH_TYPE_INDEX_AREA);
|
||||||
|
BIND_CONSTANT(MESH_TYPE_INDEX_TEXTURE_RID);
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(BUILD_FLAG_USE_ISOLEVEL);
|
BIND_ENUM_CONSTANT(BUILD_FLAG_USE_ISOLEVEL);
|
||||||
BIND_ENUM_CONSTANT(BUILD_FLAG_USE_LIGHTING);
|
BIND_ENUM_CONSTANT(BUILD_FLAG_USE_LIGHTING);
|
||||||
|
@ -26,16 +26,15 @@ SOFTWARE.
|
|||||||
#include "core/version.h"
|
#include "core/version.h"
|
||||||
|
|
||||||
#if VERSION_MAJOR > 3
|
#if VERSION_MAJOR > 3
|
||||||
#include "core/string/ustring.h"
|
|
||||||
#include "core/config/engine.h"
|
#include "core/config/engine.h"
|
||||||
|
#include "core/string/ustring.h"
|
||||||
#include "core/variant/array.h"
|
#include "core/variant/array.h"
|
||||||
#else
|
#else
|
||||||
#include "core/ustring.h"
|
|
||||||
#include "core/engine.h"
|
|
||||||
#include "core/array.h"
|
#include "core/array.h"
|
||||||
|
#include "core/engine.h"
|
||||||
|
#include "core/ustring.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "../terrain_2d_chunk.h"
|
#include "../terrain_2d_chunk.h"
|
||||||
|
|
||||||
#include "../../defines.h"
|
#include "../../defines.h"
|
||||||
@ -44,12 +43,12 @@ SOFTWARE.
|
|||||||
#include "core/os/thread.h"
|
#include "core/os/thread.h"
|
||||||
#include "core/os/thread_safe.h"
|
#include "core/os/thread_safe.h"
|
||||||
|
|
||||||
#include "scene/resources/packed_scene.h"
|
|
||||||
#include "../terrain_2d_world.h"
|
|
||||||
#include "../../data/terrain_2d_light.h"
|
#include "../../data/terrain_2d_light.h"
|
||||||
#include "../../meshers/terrain_2d_mesher.h"
|
|
||||||
#include "../../library/terrain_2d_surface.h"
|
|
||||||
#include "../../library/terrain_2d_library.h"
|
#include "../../library/terrain_2d_library.h"
|
||||||
|
#include "../../library/terrain_2d_surface.h"
|
||||||
|
#include "../../meshers/terrain_2d_mesher.h"
|
||||||
|
#include "../terrain_2d_world.h"
|
||||||
|
#include "scene/resources/packed_scene.h"
|
||||||
|
|
||||||
class Terrain2DWorld;
|
class Terrain2DWorld;
|
||||||
class Terrain2DJob;
|
class Terrain2DJob;
|
||||||
@ -85,6 +84,7 @@ public:
|
|||||||
MESH_TYPE_INDEX_SHAPE,
|
MESH_TYPE_INDEX_SHAPE,
|
||||||
MESH_TYPE_INDEX_BODY,
|
MESH_TYPE_INDEX_BODY,
|
||||||
MESH_TYPE_INDEX_AREA,
|
MESH_TYPE_INDEX_AREA,
|
||||||
|
MESH_TYPE_INDEX_TEXTURE_RID,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BuildFlags {
|
enum BuildFlags {
|
||||||
@ -181,6 +181,7 @@ protected:
|
|||||||
|
|
||||||
virtual void _exit_tree();
|
virtual void _exit_tree();
|
||||||
virtual void _world_transform_changed();
|
virtual void _world_transform_changed();
|
||||||
|
virtual void _draw();
|
||||||
|
|
||||||
//lights
|
//lights
|
||||||
virtual void _bake_lights();
|
virtual void _bake_lights();
|
||||||
@ -209,7 +210,7 @@ protected:
|
|||||||
RID _debug_mesh_instance;
|
RID _debug_mesh_instance;
|
||||||
PoolVector3Array _debug_mesh_array;
|
PoolVector3Array _debug_mesh_array;
|
||||||
|
|
||||||
Vector<Ref<Terrain2DLight> > _lights;
|
Vector<Ref<Terrain2DLight>> _lights;
|
||||||
};
|
};
|
||||||
|
|
||||||
VARIANT_ENUM_CAST(Terrain2DChunkDefault::DefaultChannels);
|
VARIANT_ENUM_CAST(Terrain2DChunkDefault::DefaultChannels);
|
||||||
|
@ -1039,6 +1039,10 @@ void Terrain2DChunk::generation_physics_process(const float delta) {
|
|||||||
call("_generation_physics_process", delta);
|
call("_generation_physics_process", delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Terrain2DChunk::draw() {
|
||||||
|
call("_draw");
|
||||||
|
}
|
||||||
|
|
||||||
Transform2D Terrain2DChunk::get_transform() const {
|
Transform2D Terrain2DChunk::get_transform() const {
|
||||||
return _transform;
|
return _transform;
|
||||||
}
|
}
|
||||||
@ -1319,6 +1323,7 @@ void Terrain2DChunk::_bind_methods() {
|
|||||||
BIND_VMETHOD(MethodInfo("_visibility_changed", PropertyInfo(Variant::BOOL, "visible")));
|
BIND_VMETHOD(MethodInfo("_visibility_changed", PropertyInfo(Variant::BOOL, "visible")));
|
||||||
BIND_VMETHOD(MethodInfo("_world_light_added", PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DLight")));
|
BIND_VMETHOD(MethodInfo("_world_light_added", PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DLight")));
|
||||||
BIND_VMETHOD(MethodInfo("_world_light_removed", PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DLight")));
|
BIND_VMETHOD(MethodInfo("_world_light_removed", PropertyInfo(Variant::OBJECT, "light", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DLight")));
|
||||||
|
BIND_VMETHOD(MethodInfo("_draw"));
|
||||||
|
|
||||||
BIND_VMETHOD(MethodInfo("_generation_process", PropertyInfo(Variant::REAL, "delta")));
|
BIND_VMETHOD(MethodInfo("_generation_process", PropertyInfo(Variant::REAL, "delta")));
|
||||||
BIND_VMETHOD(MethodInfo("_generation_physics_process", PropertyInfo(Variant::REAL, "delta")));
|
BIND_VMETHOD(MethodInfo("_generation_physics_process", PropertyInfo(Variant::REAL, "delta")));
|
||||||
|
@ -301,6 +301,7 @@ public:
|
|||||||
void world_light_removed(const Ref<Terrain2DLight> &light);
|
void world_light_removed(const Ref<Terrain2DLight> &light);
|
||||||
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);
|
||||||
|
void draw();
|
||||||
|
|
||||||
Transform2D get_transform() const;
|
Transform2D get_transform() const;
|
||||||
void set_transform(const Transform2D &transform);
|
void set_transform(const Transform2D &transform);
|
||||||
|
@ -905,6 +905,18 @@ Terrain2DWorld ::~Terrain2DWorld() {
|
|||||||
_lights.clear();
|
_lights.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Terrain2DWorld::_draw() {
|
||||||
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||||
|
Ref<Terrain2DChunk> chunk = _chunks_vector[i];
|
||||||
|
|
||||||
|
ERR_CONTINUE(!chunk.is_valid());
|
||||||
|
|
||||||
|
if (chunk->get_visible()) {
|
||||||
|
chunk->draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Terrain2DWorld::_generate_chunk(Ref<Terrain2DChunk> chunk) {
|
void Terrain2DWorld::_generate_chunk(Ref<Terrain2DChunk> chunk) {
|
||||||
ERR_FAIL_COND(!chunk.is_valid());
|
ERR_FAIL_COND(!chunk.is_valid());
|
||||||
|
|
||||||
@ -976,10 +988,12 @@ void Terrain2DWorld::_notification(int p_what) {
|
|||||||
CALL(_generation_finished);
|
CALL(_generation_finished);
|
||||||
|
|
||||||
emit_signal("generation_finished");
|
emit_signal("generation_finished");
|
||||||
|
update();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool needs_update = false;
|
||||||
for (int i = 0; i < _generating.size(); ++i) {
|
for (int i = 0; i < _generating.size(); ++i) {
|
||||||
Ref<Terrain2DChunk> chunk = _generating.get(i);
|
Ref<Terrain2DChunk> chunk = _generating.get(i);
|
||||||
|
|
||||||
@ -992,6 +1006,7 @@ void Terrain2DWorld::_notification(int p_what) {
|
|||||||
if (!chunk->get_is_generating()) {
|
if (!chunk->get_is_generating()) {
|
||||||
_generating.VREMOVE(i);
|
_generating.VREMOVE(i);
|
||||||
--i;
|
--i;
|
||||||
|
needs_update = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1002,6 +1017,10 @@ void Terrain2DWorld::_notification(int p_what) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needs_update) {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
if (_generating.size() >= _max_concurrent_generations)
|
if (_generating.size() >= _max_concurrent_generations)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1059,6 +1078,9 @@ void Terrain2DWorld::_notification(int p_what) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case NOTIFICATION_DRAW: {
|
||||||
|
call("_draw");
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1244,6 +1266,9 @@ void Terrain2DWorld::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("set_voxel_with_tool", "mode_add", "hit_position", "hit_normal", "selected_voxel", "isolevel"), &Terrain2DWorld::set_voxel_with_tool);
|
ClassDB::bind_method(D_METHOD("set_voxel_with_tool", "mode_add", "hit_position", "hit_normal", "selected_voxel", "isolevel"), &Terrain2DWorld::set_voxel_with_tool);
|
||||||
ClassDB::bind_method(D_METHOD("_set_voxel_with_tool", "mode_add", "hit_position", "hit_normal", "selected_voxel", "isolevel"), &Terrain2DWorld::_set_voxel_with_tool);
|
ClassDB::bind_method(D_METHOD("_set_voxel_with_tool", "mode_add", "hit_position", "hit_normal", "selected_voxel", "isolevel"), &Terrain2DWorld::_set_voxel_with_tool);
|
||||||
|
|
||||||
|
BIND_VMETHOD(MethodInfo("_draw"));
|
||||||
|
ClassDB::bind_method(D_METHOD("_draw"), &Terrain2DWorld::_draw);
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_TYPE);
|
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_TYPE);
|
||||||
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_ISOLEVEL);
|
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_ISOLEVEL);
|
||||||
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_LIQUID_FLOW);
|
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_LIQUID_FLOW);
|
||||||
|
@ -210,6 +210,7 @@ public:
|
|||||||
~Terrain2DWorld();
|
~Terrain2DWorld();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void _draw();
|
||||||
virtual void _generate_chunk(Ref<Terrain2DChunk> chunk);
|
virtual void _generate_chunk(Ref<Terrain2DChunk> chunk);
|
||||||
virtual Ref<Terrain2DChunk> _create_chunk(int x, int z, Ref<Terrain2DChunk> p_chunk);
|
virtual Ref<Terrain2DChunk> _create_chunk(int x, int z, Ref<Terrain2DChunk> p_chunk);
|
||||||
virtual int _get_channel_index_info(const ChannelTypeInfo channel_type);
|
virtual int _get_channel_index_info(const ChannelTypeInfo channel_type);
|
||||||
|
Loading…
Reference in New Issue
Block a user