Skip to content

Commit

Permalink
Allow ptLayer.setTexture() for unloaded images.
Browse files Browse the repository at this point in the history
This is useful for setting textures that are in global PRPs.
  • Loading branch information
Hoikas committed Nov 19, 2024
1 parent ac7ecff commit 83c6af8
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 11 deletions.
7 changes: 0 additions & 7 deletions Sources/Plasma/FeatureLib/pfPython/pyImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "pyImage.h"

#include <algorithm>
#include <vector>

#include <string_theory/format>
Expand Down Expand Up @@ -209,12 +208,6 @@ PyObject* pyImage::Find(const ST::string& name)
{
std::vector<plKey> foundKeys;
plKeyFinder::Instance().ReallyStupidSubstringSearch(name, plMipmap::Index(), foundKeys);
// Remove anything that isn't loaded - they aren't useful in Python code
std::remove_if(
foundKeys.begin(),
foundKeys.end(),
[](const plKey& key) { return key->ObjectIsLoaded() == nullptr; }
);

PyObject* tup = PyTuple_New(foundKeys.size());
for (size_t i = 0; i < foundKeys.size(); ++i)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfPython/pyLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ plLayer* pyLayer::GetLayer() const
return plLayer::ConvertNoRef(fLayerKey->ObjectIsLoaded());
}

void pyLayer::SetTexture(plBitmap* image)
void pyLayer::SetTexture(const plKey& image)
{
plLayer* layer = GetLayer();

if (image) {
plLayRefMsg* refMsg = new plLayRefMsg(fLayerKey, plRefMsg::kOnReplace, 0, plLayRefMsg::kTexture);
hsgResMgr::ResMgr()->AddViaNotify(image->GetKey(), refMsg, plRefFlags::kActiveRef);
hsgResMgr::ResMgr()->AddViaNotify(image, refMsg, plRefFlags::kActiveRef);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/FeatureLib/pfPython/pyLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class pyLayer
plLayer* GetLayer() const;

// For Python access
void SetTexture(plBitmap* image);
void SetTexture(const plKey& image);
PyObject* GetTexture() const;

static PyObject* Find(const ST::string& name, const ST::string& age, const ST::string& page);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/FeatureLib/pfPython/pyLayerGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ PYTHON_METHOD_DEFINITION(ptLayer, setTexture, args)
PYTHON_RETURN_ERROR;
}

self->fThis->SetTexture(pyImage::ConvertFrom(imageObj)->GetImage());
self->fThis->SetTexture(pyImage::ConvertFrom(imageObj)->GetKey());
PYTHON_RETURN_NONE;
}

Expand Down

0 comments on commit 83c6af8

Please sign in to comment.