Removed the texture packer from PropInstancePropJob. The code now uses the material cache instead.

This commit is contained in:
Relintai 2021-08-10 09:39:18 +02:00
parent 35cf1962d0
commit 64e6447d9c
3 changed files with 18 additions and 58 deletions

View File

@ -417,8 +417,8 @@ void PropInstanceMerger::_build() {
//job -> if !has cache query -> buildings can use this to only have one material per building
//move this to job
#if TEXTURE_PACKER_PRESENT
Ref<TexturePacker> packer; // = PropCache::get_singleton()->get_or_create_texture_threaded(_prop_data);
//#if TEXTURE_PACKER_PRESENT
//Ref<TexturePacker> packer; // = PropCache::get_singleton()->get_or_create_texture_threaded(_prop_data);
/*
if (packer->get_generated_texture_count() == 0) {
_building = false;
@ -426,8 +426,8 @@ void PropInstanceMerger::_build() {
return;
}
*/
_job->set_texture_packer(packer);
#endif
// _job->set_texture_packer(packer);
//#endif
for (int i = 0; i < get_child_count(); ++i) {
Node *n = get_child(i);

View File

@ -31,10 +31,11 @@ SOFTWARE.
#endif
#include "jobs/prop_mesher_job_step.h"
#include "material_cache/prop_material_cache.h"
#include "prop_instance.h"
#include "prop_instance_merger.h"
#include "prop_mesher.h"
#include "material_cache/prop_material_cache.h"
#include "singleton/prop_cache.h"
#ifdef MESH_DATA_RESOURCE_PRESENT
#include "../mesh_data_resource/mesh_data_resource.h"
@ -56,15 +57,6 @@ SOFTWARE.
#undef PROPS_PRESENT
#endif
#if TEXTURE_PACKER_PRESENT
Ref<TexturePacker> PropInstancePropJob::get_texture_packer() {
return _texture_packer;
}
void PropInstancePropJob::set_texture_packer(const Ref<TexturePacker> &packer) {
_texture_packer = packer;
}
#endif
Ref<PropMaterialCache> PropInstancePropJob::get_material_cache() {
return _material_cache;
}
@ -216,15 +208,7 @@ void PropInstancePropJob::phase_prop() {
Transform t = pmd->get_transform();
t *= e.base_transform;
Rect2 uvr = Rect2(0, 0, 1, 1);
if (_texture_packer.is_valid() && tex.is_valid()) {
Ref<AtlasTexture> at = _texture_packer->get_texture(tex);
if (at.is_valid()) {
uvr = at->get_region();
}
}
Rect2 uvr = _material_cache->texture_get_uv_rect(tex);
get_prop_mesher()->add_mesh_data_resource_transform(mesh, t, uvr);
}
@ -449,35 +433,30 @@ void PropInstancePropJob::_physics_process(float delta) {
}
void PropInstancePropJob::_execute_phase() {
/*
ERR_FAIL_COND(!_chunk.is_valid());
if (!_material_cache.is_valid()) {
ERR_PRINT("!PropInstancePropJob::_execute_phase(): _material_cache.is_valid()");
set_complete(true); //So threadpool knows it's done
finished();
}
Ref<TerramanLibrary> library = _chunk->get_library();
ERR_FAIL_COND(!library.is_valid());
Ref<TerraChunkDefault> chunk = _chunk;
if (!chunk.is_valid()
#ifdef MESH_DATA_RESOURCE_PRESENT
|| chunk->mesh_data_resource_get_count() == 0
#endif
) {
if (_prop_mesh_datas.size() == 0) {
set_complete(true);
finished();
return;
}
*/
#endif
if (_phase == 1) {
//phase_prop();
phase_prop();
} else if (_phase > 1) {
set_complete(true); //So threadpool knows it's done
finished();
ERR_FAIL_MSG("PropInstancePropJob: _phase is too high!");
}
set_complete(true); //So threadpool knows it's done
finished();
//set_complete(true); //So threadpool knows it's done
//finished();
}
void PropInstancePropJob::_reset() {
@ -880,12 +859,6 @@ PropInstancePropJob::~PropInstancePropJob() {
}
void PropInstancePropJob::_bind_methods() {
#if TEXTURE_PACKER_PRESENT
ClassDB::bind_method(D_METHOD("get_texture_packer"), &PropInstancePropJob::get_texture_packer);
ClassDB::bind_method(D_METHOD("set_texture_packer", "packer"), &PropInstancePropJob::set_texture_packer);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_packer", PROPERTY_HINT_RESOURCE_TYPE, "TexturePacker", 0), "set_texture_packer", "get_texture_packer");
#endif
ClassDB::bind_method(D_METHOD("get_material_cache"), &PropInstancePropJob::get_material_cache);
ClassDB::bind_method(D_METHOD("set_material_cache", "packer"), &PropInstancePropJob::set_material_cache);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_cache", PROPERTY_HINT_RESOURCE_TYPE, "PropMaterialCache", 0), "set_material_cache", "get_material_cache");

View File

@ -25,10 +25,6 @@ SOFTWARE.
#include "prop_instance_job.h"
#if TEXTURE_PACKER_PRESENT
class TexturePacker;
#endif
class PropMesher;
class PropInstance;
class PropInstanceMerger;
@ -43,11 +39,6 @@ class PropInstancePropJob : public PropInstanceJob {
GDCLASS(PropInstancePropJob, PropInstanceJob);
public:
#if TEXTURE_PACKER_PRESENT
Ref<TexturePacker> get_texture_packer();
void set_texture_packer(const Ref<TexturePacker> &packer);
#endif
Ref<PropMaterialCache> get_material_cache();
void set_material_cache(const Ref<PropMaterialCache> &cache);
@ -102,10 +93,6 @@ protected:
};
#endif
#if TEXTURE_PACKER_PRESENT
Ref<TexturePacker> _texture_packer;
#endif
Ref<PropMaterialCache> _material_cache;
Vector<Ref<PropMesherJobStep>> _job_steps;