Batch #17237 by ragnarok-clanker: no function's compiled code changes; checked with 105 compiled unit(s), including every includer of Source/Linkage/Source/Client/Mode/LoginMode.cpp.h, Source/Linkage/Source/Client/Session/SessionAchievements.cpp.h, Source/Linkage/Source/Client/Session/SessionPredicates.cpp.h, Source/Linkage/Source/Client/Session/SessionState.cpp.h, Source/Linkage/Source/Contents/Achievement/AchievementMgr.cpp.h, Source/Linkage/Source/Contents/Actors/ActorPickNode.cpp.h, Source/Linkage/Source/Contents/Actors/MercenaryAI.cpp.h, Source/Linkage/Source/Contents/Actors/Resources/RobeResources.cpp.h, Source/Linkage/Source/Contents/CashEmotion/CashEmotionMgr.cpp.h, Source/Linkage/Source/Contents/Effects/EffectResourceSwitcher.cpp.h, Source/Linkage/Source/Contents/Effects/Particles/AnimatedEmitterEffect.cpp.h, Source/Linkage/Source/Contents/Effects/Particles/Particle.cpp.h, Source/Linkage/Source/Contents/Effects/Skills/MonsterSkillEffects.cpp.h, Source/Linkage/Source/Contents/Emblems/EmblemCache.cpp.h, Source/Linkage/Source/Contents/Emblems/EmblemDataDownloadAsyncWork.cpp.h, Source/Linkage/Source/Contents/Emblems/EmblemDataMgr.cpp.h, Source/Linkage/Source/Contents/Emblems/EmblemDataUploadAsyncWork.cpp.h, Source/Linkage/Source/Contents/Emblems/GuildEmblemLookup.cpp.h, Source/Linkage/Source/Contents/Hotkeys/EmotionHotkeys.cpp.h, Source/Linkage/Source/Contents/Items/ItemInfo.cpp.h, Source/Linkage/Source/Contents/Items/ItemNaming.cpp.h, Source/Linkage/Source/Contents/Map/PrivateAirplaneMgr.cpp.h, Source/Linkage/Source/Contents/Map/TownInfoMgr.cpp.h, Source/Linkage/Source/Contents/Messenger/MessengerMember.cpp.h, Source/Linkage/Source/Contents/Messenger/WhisperBlockMgr.cpp.h, Source/Linkage/Source/Contents/Models/ModelLighting.cpp.h, Source/Linkage/Source/Contents/Movies/BinkMovies.cpp.h, Source/Linkage/Source/Contents/Navigation/NavigationDestinations.cpp.h, Source/Linkage/Source/Contents/Navigation/NavigationRequest.cpp.h, Source/Linkage/Source/Contents/Navigation/NavigationRoute.cpp.h, Source/Linkage/Source/Contents/Party/AgencyRequests.cpp.h, Source/Linkage/Source/Contents/Party/LoadPartyInfoAsyncWork.cpp.h, Source/Linkage/Source/Contents/Party/LoadPartyListAsyncWork.cpp.h, Source/Linkage/Source/Contents/Party/RegisterPartyAsyncWork.cpp.h, Source/Linkage/Source/Contents/Repute/ReputeMgr.cpp.h, Source/Linkage/Source/Contents/Sound/SoundMgr.cpp.h, Source/Linkage/Source/Contents/Store/MCStoreInfoBackup.cpp.h, Source/Linkage/Source/Contents/Store/MCStoreInfoBackupAsyncWork.cpp.h, Source/Linkage/Source/Contents/Time/ClientTiming.cpp.h, Source/Linkage/Source/Contents/UserData/AccountLinkedUserDataLoadAsyncWork.cpp.h, Source/Linkage/Source/Contents/UserData/AccountLinkedUserDataMgr.cpp.h, Source/Linkage/Source/Contents/UserData/AccountLinkedUserDataSaveAsyncWork.cpp.h, Source/Linkage/Source/Contents/UserData/CharacterConfigSave.cpp.h, Source/Linkage/Source/Contents/UserData/CharacterLinkedUserDataLoadAsyncWork.cpp.h, Source/Linkage/Source/Contents/UserData/CharacterLinkedUserDataSaveAsyncWork.cpp.h, Source/Linkage/Source/File/DirectoryRemoval.cpp.h, Source/Linkage/Source/Network/NIPAddr.cpp.h, Source/Linkage/Source/Network/Packets/ActorNamePacket.cpp.h, Source/Linkage/Source/Render/Device/RenderBackends.cpp.h, Source/Linkage/Source/Render/Primitives/ScreenLine.cpp.h, Source/Linkage/Source/Render/Text/EmbedFont.cpp.h, Source/Linkage/Source/Resource/Models/RmaResource.cpp.h, Source/Linkage/Source/Resource/ResourceFailures.cpp.h, Source/Linkage/Source/Script/LuaScript.cpp.h, Source/Linkage/Source/Security/NProtectGameGuardMgr.cpp.h, Source/Linkage/Source/UI/Acceptance/UIExchangeAcceptWnd.cpp.h, Source/Linkage/Source/UI/Achievement/UIAchWnd.cpp.h, Source/Linkage/Source/UI/Buttons/UINaviLinkButton.cpp.h, Source/Linkage/Source/UI/CashShop/UICashShopWnd.cpp.h, Source/Linkage/Source/UI/Chat/UIChatRoomTitle.cpp.h, Source/Linkage/Source/UI/Dialogs/UIMessageBox.cpp.h, Source/Linkage/Source/UI/Dialogs/UINoteWnd.cpp.h, Source/Linkage/Source/UI/Edit/UIEditCtrl3.cpp.h, Source/Linkage/Source/UI/Enchant/UIEnchantUI.cpp.h, Source/Linkage/Source/UI/EntryQueue/UIEntryQueueWnd.cpp.h, Source/Linkage/Source/UI/Events/UICheckAttendanceWnd.cpp.h, Source/Linkage/Source/UI/GameSettings/GameSettingsUI.cpp.h, Source/Linkage/Source/UI/GameSettings/UIHotkeyGuideWnd.cpp.h, Source/Linkage/Source/UI/Gauges/UIBarGraph.cpp.h, Source/Linkage/Source/UI/Guild/UIGuildHelperWnd.cpp.h, Source/Linkage/Source/UI/Items/UIEquipmentPropertiesWnd.cpp.h, Source/Linkage/Source/UI/Items/UIItemReformWnd.cpp.h, Source/Linkage/Source/UI/Items/UIItemStoreComboBox.cpp.h, Source/Linkage/Source/UI/Items/UILapineBoxWnd.cpp.h, Source/Linkage/Source/UI/Items/UIMakeTargetProcessWnd.cpp.h, Source/Linkage/Source/UI/Items/UIMerchantItemLogWnd.cpp.h, Source/Linkage/Source/UI/Items/UISwapEquipmentWnd.cpp.h, Source/Linkage/Source/UI/Lists/UIChatHisBox.cpp.h, Source/Linkage/Source/UI/Lists/UIComboBoxDefWnd.cpp.h, Source/Linkage/Source/UI/Login/UIPasswordWnd.cpp.h, Source/Linkage/Source/UI/Macro/UIMacroDetectorWnd.cpp.h, Source/Linkage/Source/UI/Navigation/NavigationLink.cpp.h, Source/Linkage/Source/UI/Party/UIApplyForPartyWnd.cpp.h, Source/Linkage/Source/UI/Party/UIRegisterPartyWnd.cpp.h, Source/Linkage/Source/UI/Party/UISeekPartyMBWnd.cpp.h, Source/Linkage/Source/UI/Quest/UIRecommendedQuestInfo.cpp.h, Source/Linkage/Source/UI/Repute/UIReputeWnd.cpp.h, Source/Linkage/Source/UI/Rodex/UIRodexComposeWnd.cpp.h, Source/Linkage/Source/UI/RuneSystem/UIRuneSystemWnd.cpp.h, Source/Linkage/Source/UI/Shop/UIMerchantShopTitle.cpp.h, Source/Linkage/Source/UI/Shortcuts/UIShortCutWnd.cpp.h, Source/Linkage/Source/UI/Skill/UIGraffiStrboxWnd.cpp.h, Source/Linkage/Source/UI/SkillDelayInfo/UISkillDelayInfo.cpp.h, Source/Linkage/Source/UI/Status/UIBasicInfoWnd.cpp.h, Source/Linkage/Source/UI/Text/ColoredText.cpp.h, Source/Linkage/Source/UI/Text/ItemLinkDisplay.cpp.h, Source/Linkage/Source/UI/Text/TextMarkup.cpp.h, Source/Linkage/Source/UI/Text/UITagTextViewer.cpp.h, Source/Linkage/Source/UI/Text/UITextViewer.cpp.h, Source/Linkage/Source/UI/Window/UIFrameWnd.cpp.h, Source/Linkage/Source/UI/Window/UIWindow.cpp.h, Source/Linkage/Source/UI/Window/UIWindowFactory.cpp.h, Source/Linkage/Source/UI/Window/WindowRegistration.cpp.h, Source/Linkage/Source/UI/Window/WindowRetirement.cpp.h, Source/Linkage/Source/Utility/Threading/NThread.cpp.h.
233 lines
8.8 KiB
C++
233 lines
8.8 KiB
C++
#include "Client/Mode/CGameMode.h"
|
|
#include "Client/Mode/ModeMgr.h"
|
|
#include "Contents/Ground/GroundGeometry.h"
|
|
#include "Contents/Models/ModelActor.h"
|
|
#include "Contents/Models/ModelNode.h"
|
|
#include "Contents/World/World.h"
|
|
#include "Render/Renderer.h"
|
|
#include "Render/Textures/Texture.h"
|
|
|
|
#include "Utility/Math/ScalarConversion.h"
|
|
#include <cmath>
|
|
#include <cstring>
|
|
|
|
union ModelColor {
|
|
std::uint32_t value;
|
|
struct {
|
|
unsigned char b;
|
|
unsigned char g;
|
|
unsigned char r;
|
|
unsigned char a;
|
|
};
|
|
};
|
|
|
|
// GLOBAL: gl_25474
|
|
static ModelColor g_modelFaceColors[90000];
|
|
|
|
namespace {
|
|
// INLINED
|
|
float InverseLength(float squared) {
|
|
return 1.0f / SquareRoot(squared);
|
|
}
|
|
|
|
// INLINED
|
|
__forceinline void Light(const float* normal, const float* values, const float* direction, const float* diffuse, const float* ambient, float* output) {
|
|
const float x = ((normal[0] * values[0] + normal[1] * values[3]) + normal[2] * values[6]) + 0.0f;
|
|
const float y = ((normal[0] * values[1] + normal[1] * values[4]) + normal[2] * values[7]) + 0.0f;
|
|
const float z = ((normal[0] * values[2] + normal[1] * values[5]) + normal[2] * values[8]) + 0.0f;
|
|
const float inverse = InverseLength((y * y + x * x) + z * z);
|
|
const float dot = ((y * inverse) * direction[1] + (x * inverse) * direction[0]) + (z * inverse) * direction[2];
|
|
const float amount = dot > 0.0f ? dot : 0.0f;
|
|
|
|
for (unsigned component = 0; component < 3; ++component) {
|
|
const float color = amount * diffuse[component] + ambient[component];
|
|
output[component] = color < 1.0f ? color : 1.0f;
|
|
}
|
|
}
|
|
|
|
// INLINED
|
|
unsigned char Scale(float factor, float light, unsigned char channel) {
|
|
const float value = (factor * light) * static_cast<float>(channel);
|
|
return static_cast<unsigned char>(255.0f < value ? 255.0f : value);
|
|
}
|
|
|
|
// INLINED
|
|
ModelColor LitColor(std::uint32_t source, float alpha, bool shaded, const float* light) {
|
|
const float factor = shaded ? 0.5f : 1.0f;
|
|
ModelColor color;
|
|
color.value = source;
|
|
color.a = static_cast<unsigned char>(alpha * 255.0f);
|
|
color.r = Scale(factor, light[0], color.r);
|
|
color.g = Scale(factor, light[1], color.g);
|
|
color.b = Scale(factor, light[2], color.b);
|
|
return color;
|
|
}
|
|
|
|
// INLINED
|
|
__forceinline void GroundColor(const C3dNode* node, const GroundGeometry& ground, const float* matrix, const std::array<float, 3>& vertex, std::uint32_t* output) {
|
|
const float x = (((vertex[0] * matrix[0] + vertex[1] * matrix[3]) + vertex[2] * matrix[6]) + matrix[9]) + node->model->position[0];
|
|
const float y = (((vertex[0] * matrix[1] + vertex[1] * matrix[4]) + vertex[2] * matrix[7]) + matrix[10]) + node->model->position[1];
|
|
const float z = (((vertex[0] * matrix[2] + vertex[1] * matrix[5]) + vertex[2] * matrix[8]) + matrix[11]) + node->model->position[2];
|
|
ground.WorldColor(x, y, z, output);
|
|
}
|
|
|
|
// INLINED
|
|
int AddChannel(std::uint32_t sampled, std::uint32_t channel) {
|
|
const int value = static_cast<int>(sampled) + channel;
|
|
return value > 255 ? 255 : value;
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00AB78B0
|
|
// FUNCTION: fn_17491
|
|
C3dNode* C3dNode::Find(const char* selected) {
|
|
if (this->name.compare(selected) == 0) {
|
|
return this;
|
|
}
|
|
|
|
for (std::list<C3dNode*>::iterator it = this->children.begin(); it != this->children.end(); ++it) {
|
|
if (C3dNode* found = (*it)->Find(selected)) {
|
|
return found;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
// OFFSET: 0x00AB94A0
|
|
// FUNCTION: fn_17509
|
|
void C3dNode::OverrideColors() {
|
|
this->overrideColors = 1;
|
|
|
|
for (std::list<C3dNode*>::iterator it = this->children.begin(); it != this->children.end(); ++it) {
|
|
(*it)->OverrideColors();
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00ABB450
|
|
// FUNCTION: fn_17515
|
|
void C3dNode::SampleGroundColors(const CRenderer*, const float* matrix, const GroundGeometry& ground) {
|
|
const std::array<float, 3>* vertices = this->mesh->vertices;
|
|
const ModelFace* faces = this->mesh->faces;
|
|
|
|
std::uint32_t sampled[3];
|
|
|
|
for (int index = 0; index < this->mesh->faceCount; ++index) {
|
|
const ModelFace& face = faces[index];
|
|
const ModelFaceState& state = this->faceState[index];
|
|
|
|
GroundColor(this, ground, matrix, vertices[face.vertices[0]], sampled);
|
|
this->faceValues[index * 9] = AddChannel(sampled[0], (state.colors[0] >> 16) & 255u);
|
|
this->faceValues[index * 9 + 1] = AddChannel(sampled[1], (state.colors[0] >> 8) & 255u);
|
|
this->faceValues[index * 9 + 2] = AddChannel(sampled[2], state.colors[0] & 255u);
|
|
|
|
GroundColor(this, ground, matrix, vertices[face.vertices[1]], sampled);
|
|
this->faceValues[index * 9 + 3] = AddChannel(sampled[0], (state.colors[1] >> 16) & 255u);
|
|
this->faceValues[index * 9 + 4] = AddChannel(sampled[1], (state.colors[1] >> 8) & 255u);
|
|
this->faceValues[index * 9 + 5] = AddChannel(sampled[2], state.colors[1] & 255u);
|
|
|
|
GroundColor(this, ground, matrix, vertices[face.vertices[2]], sampled);
|
|
this->faceValues[index * 9 + 6] = AddChannel(sampled[0], (state.colors[2] >> 16) & 255u);
|
|
this->faceValues[index * 9 + 7] = AddChannel(sampled[1], (state.colors[2] >> 8) & 255u);
|
|
this->faceValues[index * 9 + 8] = AddChannel(sampled[2], state.colors[2] & 255u);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00ABBB00
|
|
// FUNCTION: fn_17521
|
|
void C3dNode::Prepare(const float* matrix, const float* direction, const float* diffuse, const float* ambient, int shade) {
|
|
struct matrix combined;
|
|
combined.Compose(this->transform, *reinterpret_cast<const struct matrix*>(matrix));
|
|
const struct matrix rotation = combined;
|
|
|
|
switch (shade) {
|
|
case 2: {
|
|
const ModelFace* faces = this->mesh->faces;
|
|
const ModelTextureVertex* textureVertices = this->mesh->textureVertices;
|
|
const std::array<float, 3>* normals = this->mesh->vertexNormals;
|
|
ModelColor* color = g_modelFaceColors;
|
|
|
|
for (int index = 0; index < this->mesh->faceCount; ++index) {
|
|
for (unsigned corner = 0; corner < 3; ++corner) {
|
|
float light[3];
|
|
Light(normals[index * 3 + corner].data(), rotation.values, direction, diffuse, ambient, light);
|
|
const bool shaded = textureVertices[faces[index].textureVertices[corner]].shaded > 0u;
|
|
*color++ = LitColor(this->model->color, this->alpha, shaded, light);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case 1: {
|
|
const ModelFace* faces = this->mesh->faces;
|
|
const ModelTextureVertex* textureVertices = this->mesh->textureVertices;
|
|
const std::array<float, 3>* normals = this->mesh->faceNormals;
|
|
ModelColor* color = g_modelFaceColors;
|
|
|
|
for (int index = 0; index < this->mesh->faceCount; ++index) {
|
|
float light[3];
|
|
Light(normals[index].data(), rotation.values, direction, diffuse, ambient, light);
|
|
|
|
for (unsigned corner = 0; corner < 3; ++corner) {
|
|
const bool shaded = textureVertices[faces[index].textureVertices[corner]].shaded > 0u;
|
|
*color++ = LitColor(this->model->color, this->alpha, shaded, light);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case 0: {
|
|
ModelColor* color = g_modelFaceColors;
|
|
|
|
for (int index = 0; index < this->mesh->faceCount; ++index) {
|
|
for (unsigned corner = 0; corner < 3; ++corner) {
|
|
color->value = this->model->color;
|
|
color->a = static_cast<unsigned char>(this->alpha * 255.0f);
|
|
++color;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
const ModelFace* face = this->mesh->faces;
|
|
const ModelFace* const end = face + this->mesh->faceCount;
|
|
const ModelTextureVertex* textureVertices = this->mesh->textureVertices;
|
|
ModelFaceState* state = this->faceState.data();
|
|
const ModelColor* colors = g_modelFaceColors;
|
|
|
|
while (face != end) {
|
|
const std::uint16_t texture = face->texture;
|
|
CTexture* image = this->textures[texture % this->textures.size()];
|
|
|
|
const float u = static_cast<float>(static_cast<double>(image->ImageWidth())) / static_cast<float>(static_cast<double>(image->TextureWidth()));
|
|
const float v = static_cast<float>(static_cast<double>(image->ImageHeight())) / static_cast<float>(static_cast<double>(image->TextureHeight()));
|
|
|
|
while (face != end && face->texture == texture) {
|
|
for (unsigned corner = 0; corner < 3; ++corner) {
|
|
state->colors[corner] = colors[corner].value;
|
|
}
|
|
|
|
if (this->mesh->textureVertexCount == 0) {
|
|
for (unsigned corner = 0; corner < 3; ++corner) {
|
|
state->uv[corner][0] = u;
|
|
state->uv[corner][1] = v;
|
|
}
|
|
} else {
|
|
for (unsigned corner = 0; corner < 3; ++corner) {
|
|
const ModelTextureVertex& uv = textureVertices[face->textureVertices[corner]];
|
|
state->uv[corner][1] = v * uv.v;
|
|
state->uv[corner][0] = u * uv.u;
|
|
}
|
|
}
|
|
|
|
++face;
|
|
++state;
|
|
colors += 3;
|
|
}
|
|
}
|
|
|
|
this->SampleGroundColors(g_renderer, combined.values, *static_cast<CGameMode*>(g_modeMgr.GetGameMode())->scene->ground);
|
|
|
|
for (std::list<C3dNode*>::iterator it = this->children.begin(); it != this->children.end(); ++it) {
|
|
(*it)->Prepare(combined.values, direction, diffuse, ambient, shade);
|
|
}
|
|
}
|