Only update world and sky materials when changes are made.

Signed-off-by: aixxe <me@aixxe.net>
This commit is contained in:
aixxe 2016-12-23 21:31:54 +00:00
parent 468fbe5d07
commit f09c083a43
1 changed files with 44 additions and 13 deletions

View File

@ -1,3 +1,5 @@
#include <unordered_map>
#include "Hooks.h"
typedef void (*FrameStageNotify_t) (IBaseClientDLL*, ClientFrameStage_t);
@ -8,34 +10,63 @@ float GUI::NoSky::Color[3] = {0, 0, 0.275};
bool GUI::ASUS::Enabled = true;
float GUI::ASUS::Color[4] = {1, 1, 1, 0.75};
std::unordered_map<MaterialHandle_t, ImColor> material_colors;
void Hooks::FrameStageNotify(IBaseClientDLL* thisptr, ClientFrameStage_t stage) {
// Get the original function and store it statically.
static FrameStageNotify_t oFrameStageNotify = clientdll_hook->GetOriginalFunction<FrameStageNotify_t>(35);
// Really should move this somewhere else. Doesn't need to be called this often.
// Restore skybox & world materials to original state when disconnected.
if (!engine->IsConnected() && material_colors.size() > 0) {
for (const auto& it: material_colors) {
IMaterial* material = matsystem->GetMaterial(it.first);
material->ColorModulate(1, 1, 1);
material->AlphaModulate(1);
}
material_colors.clear();
}
if (stage == ClientFrameStage_t::FRAME_NET_UPDATE_POSTDATAUPDATE_END) {
for (MaterialHandle_t i = matsystem->FirstMaterial(); i != matsystem->InvalidMaterial(); i = matsystem->NextMaterial(i)) {
// Get the material from the current handle.
IMaterial* material = matsystem->GetMaterial(i);
// No Sky
// Check for 'SkyBox textures' group.
if (!strcmp(material->GetTextureGroupName(), TEXTURE_GROUP_SKYBOX)) {
if (GUI::NoSky::Enabled) {
material->ColorModulate(GUI::NoSky::Color[0], GUI::NoSky::Color[1], GUI::NoSky::Color[2]);
} else {
material->ColorModulate(1, 1, 1);
if (material_colors.find(i) == material_colors.end())
material_colors.emplace(i, ImColor());
ImColor color = ImColor(1.0f, 1.0f, 1.0f);
if (GUI::NoSky::Enabled)
color = ImColor(GUI::NoSky::Color[0], GUI::NoSky::Color[1], GUI::NoSky::Color[2]);
if (material_colors.at(i) != color) {
material->ColorModulate(color.Value.x, color.Value.y, color.Value.z);
material_colors.at(i) = color;
}
continue;
}
// Check for 'World textures' group.
if (!strcmp(material->GetTextureGroupName(), TEXTURE_GROUP_WORLD)) {
// ASUS walls.
if (GUI::ASUS::Enabled) {
material->ColorModulate(GUI::ASUS::Color[0], GUI::ASUS::Color[1], GUI::ASUS::Color[2]);
material->AlphaModulate(GUI::ASUS::Color[3]);
} else {
material->ColorModulate(1, 1, 1);
material->AlphaModulate(1);
if (material_colors.find(i) == material_colors.end())
material_colors.emplace(i, ImColor());
ImColor color = ImColor(1.0f, 1.0f, 1.0f);
if (GUI::ASUS::Enabled)
color = ImColor(GUI::ASUS::Color[0], GUI::ASUS::Color[1], GUI::ASUS::Color[2], GUI::ASUS::Color[3]);
if (material_colors.at(i) != color) {
material->ColorModulate(color.Value.x, color.Value.y, color.Value.z);
material->AlphaModulate(color.Value.w);
material_colors.at(i) = color;
}
}
}