diff --git a/material_cache/prop_material_cache.cpp b/material_cache/prop_material_cache.cpp index d4087f3..a428d20 100644 --- a/material_cache/prop_material_cache.cpp +++ b/material_cache/prop_material_cache.cpp @@ -24,7 +24,9 @@ SOFTWARE. #include "../../props/props/prop_data.h" #include "../../props/props/prop_data_prop.h" +#include "../../props/props/prop_data_tiled_wall.h" #include "../singleton/prop_cache.h" +#include "../tiled_wall/tiled_wall_data.h" #if MESH_DATA_RESOURCE_PRESENT #define PROPS_PRESENT 1 @@ -196,9 +198,24 @@ void PropMaterialCache::prop_add_textures(const Ref &prop) { continue; texture_add(tex); + + continue; } #endif + Ref pdtw = prop->get_prop(i); + + if (pdtw.is_valid()) { + Ref twd = pdtw->get_data(); + + if (!twd.is_valid()) + continue; + + twd->setup_cache(Ref(this)); + + continue; + } + Ref pdp = prop->get_prop(i); if (pdp.is_valid()) { @@ -225,6 +242,33 @@ void PropMaterialCache::prop_remove_textures(const Ref &prop) { } #endif + Ref pdtw = prop->get_prop(i); + + if (pdtw.is_valid()) { + Ref twd = pdtw->get_data(); + + if (!twd.is_valid()) + continue; + + for (int j = 0; j < twd->get_texture_count(); ++j) { + const Ref &tex = twd->get_texture(j); + + if (tex.is_valid()) { + texture_remove(tex); + } + } + + for (int j = 0; j < twd->get_flavour_texture_count(); ++j) { + const Ref &tex = twd->get_flavour_texture(j); + + if (tex.is_valid()) { + texture_remove(tex); + } + } + + continue; + } + Ref pdp = prop->get_prop(i); if (pdp.is_valid()) { @@ -238,7 +282,7 @@ void PropMaterialCache::refresh_rects() { } void PropMaterialCache::initial_setup_default() { - PropCache* pc = PropCache::get_singleton(); + PropCache *pc = PropCache::get_singleton(); pc->ensure_materials_loaded(); diff --git a/prop_instance.cpp b/prop_instance.cpp index 4957f83..ea84215 100644 --- a/prop_instance.cpp +++ b/prop_instance.cpp @@ -23,6 +23,10 @@ #include "./props/prop_data_light.h" #include "./props/prop_data_prop.h" #include "./props/prop_data_scene.h" +#include "./props/prop_data_tiled_wall.h" + +#include "tiled_wall/tiled_wall.h" +#include "tiled_wall/tiled_wall_data.h" Ref PropInstance::get_prop_data() { return _prop_data; @@ -127,6 +131,23 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref &pr continue; } + Ref tiled_wall_data = e; + + if (tiled_wall_data.is_valid()) { + TiledWall *twn = memnew(TiledWall); + + twn->set_width(tiled_wall_data->get_width()); + twn->set_heigth(tiled_wall_data->get_heigth()); + twn->set_data(tiled_wall_data->get_data()); + twn->set_collision(tiled_wall_data->get_collision()); + + twn->set_transform(t); + + add_child(twn); + + continue; + } + Ref scene_data = e; if (scene_data.is_valid()) { @@ -185,7 +206,6 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref &pr if (spmat.is_valid()) { spmat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture); } else { - Ref shmat = mat; if (shmat.is_valid()) { diff --git a/prop_instance_merger.cpp b/prop_instance_merger.cpp index 5357335..655463e 100644 --- a/prop_instance_merger.cpp +++ b/prop_instance_merger.cpp @@ -61,6 +61,10 @@ typedef class RenderingServer VS; #include "../thread_pool/thread_pool.h" #endif +#include "./props/prop_data_tiled_wall.h" + +#include "tiled_wall/tiled_wall_data.h" + const float PropInstanceMerger::LOD_CHECK_INTERVAL = 2; bool PropInstanceMerger::get_building() { @@ -522,6 +526,7 @@ void PropInstanceMerger::_build() { Ref cache = PropCache::get_singleton()->material_cache_get(_prop_data); + //note: this should be moved to the job if (!cache->get_initialized()) { cache->mutex_lock(); @@ -590,6 +595,15 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Ref tiled_wall_data = e; + + if (tiled_wall_data.is_valid()) { + + _job->add_tiled_wall(tiled_wall_data, t); + + continue; + } + Ref scene_data = e; if (scene_data.is_valid()) { diff --git a/prop_instance_prop_job.cpp b/prop_instance_prop_job.cpp index 419e57a..f04050c 100644 --- a/prop_instance_prop_job.cpp +++ b/prop_instance_prop_job.cpp @@ -59,6 +59,9 @@ SOFTWARE. #undef PROPS_PRESENT #endif +#include "tiled_wall/tiled_wall_data.h" +#include "props/prop_data_tiled_wall.h" + Ref PropInstancePropJob::get_material_cache() { return _material_cache; } @@ -132,6 +135,18 @@ void PropInstancePropJob::clear_meshes() { } #endif +void PropInstancePropJob::add_tiled_wall(const Ref &data, const Transform &base_transform) { + PTWEntry e; + e.data = data; + e.base_transform = base_transform; + + _prop_tiled_wall_datas.push_back(e); +} + +void PropInstancePropJob::clear_tiled_walls() { + _prop_tiled_wall_datas.clear(); +} + void PropInstancePropJob::add_light(const Ref &light) { _prop_mesher->add_light(light); } @@ -209,7 +224,6 @@ void PropInstancePropJob::phase_prop() { Ref mesh = pmd->get_mesh(); Ref tex = pmd->get_texture(); Transform t = pmd->get_transform(); - t *= e.base_transform; Rect2 uvr = _material_cache->texture_get_uv_rect(tex); @@ -217,6 +231,15 @@ void PropInstancePropJob::phase_prop() { } #endif + for (int i = 0; i < _prop_tiled_wall_datas.size(); ++i) { + PTWEntry &e = _prop_tiled_wall_datas.write[i]; + + Ref pdtw = e.data; + Transform t = pdtw->get_transform(); + + _prop_mesher->add_tiled_wall_simple(pdtw->get_width(), pdtw->get_heigth(), t, pdtw->get_data(), _material_cache); + } + if (_prop_mesher->get_vertex_count() == 0) { //reset_meshes(); @@ -293,6 +316,8 @@ void PropInstancePropJob::_reset() { _prop_mesher->reset(); } + _prop_tiled_wall_datas.clear(); + _prop_mesh_datas.clear(); clear_collision_shapes(); diff --git a/prop_instance_prop_job.h b/prop_instance_prop_job.h index d0a8103..ccf593c 100644 --- a/prop_instance_prop_job.h +++ b/prop_instance_prop_job.h @@ -32,6 +32,7 @@ class PropMesherJobStep; class PropMaterialCache; class Shape; class PropLight; +class PropDataTiledWall; #if MESH_DATA_RESOURCE_PRESENT class PropDataMeshData; @@ -65,6 +66,9 @@ public: void clear_meshes(); #endif + void add_tiled_wall(const Ref &data, const Transform &base_transform); + void clear_tiled_walls(); + void add_light(const Ref &light); void clear_lights(); @@ -103,6 +107,11 @@ protected: }; #endif + struct PTWEntry { + Ref data; + Transform base_transform; + }; + struct CollisionShapeEntry { Ref shape; Transform transform; @@ -123,6 +132,8 @@ protected: Vector _collision_shapes; + Vector _prop_tiled_wall_datas; + Array temp_mesh_arr; };