Skip to content

Commit

Permalink
Replace stack code with IMaterial (#72)
Browse files Browse the repository at this point in the history
* AccelStruct now takes information from Source

Before this commit, the AccelStruct would take material information from Lua. Now, it takes information directly from source.

Theoretically this should make it faster (I feel it's faster), but I've done no benchmarks yet.

* Fix issues relating to IMaterial

* Remove additional newline

* Remove extra newline
  • Loading branch information
yogwoggf authored Sep 17, 2022
1 parent 38caeaa commit 38b9bf9
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 218 deletions.
29 changes: 20 additions & 9 deletions source/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,28 @@ Vector MakeVector(const float x, const float y, const float z)
return v;
}

std::string GetMaterialString(ILuaBase* LUA, const std::string& key)
IMaterialVar* GetMaterialVar(IMaterial* mat, const std::string& key) {
IMaterialVar* result = nullptr;
bool found = false;

result = mat->FindVar(key.c_str(), &found, false);

if (found) {
return result;
} else {
return nullptr;
}
}

std::string GetMaterialString(IMaterial* mat, const std::string& key)
{
std::string val = "";
LUA->GetField(-1, "GetString");
LUA->Push(-2);
LUA->PushString(key.c_str());
LUA->Call(2, 1);
if (LUA->IsType(-1, Type::String)) val = LUA->GetString();
LUA->Pop();
// Check if the variable is even present
IMaterialVar* var = GetMaterialVar(mat, key);
if (var) {
return var->GetStringValue();
}

return val;
return "";
}

bool ValidVector(const glm::vec3& v)
Expand Down
16 changes: 13 additions & 3 deletions source/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "glm/glm.hpp"

#include "vistrace/IVTFTexture.h"
#include "SourceTypes.h"

#include <string>
#include <vector>
Expand Down Expand Up @@ -31,12 +32,21 @@ Vector MakeVector(const float n);
Vector MakeVector(const float x, const float y, const float z);

/// <summary>
/// Gets a string from the material at the top of the stack
/// Gets a string from the material
/// </summary>
/// <param name="LUA">ILuaBase pointer</param>
/// <param name="mat">Material pointer</param>
/// <param name="key">String key</param>
/// <returns>Value at the key or an empty string</returns>
std::string GetMaterialString(GarrysMod::Lua::ILuaBase* LUA, const std::string& key);
std::string GetMaterialString(IMaterial* mat, const std::string& key);

/// <summary>
/// Gets a material variable from the given IMaterial
/// The reason for this function existing is to handle the extra "found" variable in ->FindVar and to support std::string
/// </summary>
/// <param name="mat">Material pointer</param>
/// <param name="key">String key</param>
/// <returns>Pointer to the IMaterialVar or a nullptr</returns>
IMaterialVar* GetMaterialVar(IMaterial* mat, const std::string& key);

/// <summary>
/// VMT flags
Expand Down
1 change: 1 addition & 0 deletions source/VisTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Sampler.h"
#include "RenderTarget.h"
#include "VTFTexture.h"
#include "SourceTypes.h"

#include "TraceResult.h"
#include "AccelStruct.h"
Expand Down
Loading

0 comments on commit 38b9bf9

Please sign in to comment.