Batch #14681 by ragnarok-clanker: forced by an admin (6 lower score(s), 70 changed function(s)); checked with 555 compiled unit(s), including every includer of Source/Client/Mode/CLoginMode.h, Source/Client/Session.h, Source/Contents/Actors/GameActor.h, Source/Contents/Actors/GrannyGameActor.h, Source/Contents/Actors/Pc.h, Source/Contents/Actors/RenderObject.h, Source/Contents/EffectResourceSwitcher.h, Source/Contents/Effects/CartCannon.h, Source/Contents/Effects/EZ2STREffectEx.h, Source/Contents/Effects/EffectActor.h, Source/Contents/Effects/MonsterSkillEffects.h, Source/Contents/Effects/RagEffect.h, Source/Contents/Effects/RectUpEffect.h, Source/Contents/Ground/GroundGeometry.h, Source/Network/Connection/Connection.h, Source/Resource/Audio/WaveResource.h, Source/Resource/Bitmap/BitmapResource.h, Source/Resource/EZeffectResource.h, Source/Resource/EmblemResource.h, Source/Resource/GifResource.h, Source/Resource/ImfResource.h, Source/Resource/Models/AnimatedModelResource.h, Source/Resource/Models/GrannyModelResource.h, Source/Resource/Models/ModelResource.h, Source/Resource/PaletteResource.h, Source/Resource/RmaResource.h, Source/Resource/Sprites/ActionResource.h, Source/Resource/Sprites/SpriteResource.h, Source/Resource/World/GroundResource.h, Source/Resource/World/TerrainResource.h, Source/Resource/World/WorldResource.h, Source/UI/Buttons/UIBmpRadioBtn.h, Source/UI/Buttons/UITextButton.h, Source/UI/Item/UIItemPurchaseWnd.h, Source/UI/Item/UIItemSellWnd.h, Source/UI/Item/UIItemSellWnd2.h, Source/UI/Item/UIItemStoreWnd.h, Source/UI/Item/UIItemWnd.h, Source/UI/Item/UIParaItemShopWnd.h, Source/UI/Items/UIItemRepairWnd.h, Source/UI/Items/UIMakeTargetListWnd.h, Source/UI/Items/UIMakeTargetProcessWnd.h, Source/UI/Items/UIWeaponRefineWnd.h, Source/UI/Rodex/UIRodexInboxWnd.h, Source/UI/Shop/UIMerchantItemShopWnd.h, Source/UI/Shop/UIMerchantMirrorItemWnd.h, Source/UI/Shop/UIMerchantShopMakeWnd.h, Source/UI/StylingShop/UIStylingShopWnd.h, Source/UI/UIChangeMaterialWnd.h, Source/UI/UIIngredientInfoWnd.h, Source/UI/UIItemReformWnd.h, Source/UI/UILapineScrollBar.h, Source/UI/Window/UIHotKeyWnd.h, Source/UI/Window/UINewSelectCharWnd.h.
280 lines
8.4 KiB
C++
280 lines
8.4 KiB
C++
#include "Client/Session.h"
|
|
#include "Contents/Actors/GroundScope.h"
|
|
#include "Contents/Camera/Camera.h"
|
|
#include "Contents/Effects/EffectLists.h"
|
|
#include "Contents/Ground/GroundGeometry.h"
|
|
#include "Contents/Ground/GroundRendering.h"
|
|
#include "Contents/Models/ModelActor.h"
|
|
#include "Contents/NavigationManager.h"
|
|
#include "Contents/Sound/SoundMaker.h"
|
|
#include "Contents/World/World.h"
|
|
#include "Contents/World/WorldModelView.h"
|
|
#include "Contents/World/WorldSpatialTree.h"
|
|
#include "Render/Renderer.h"
|
|
#include "Utility/Math/AffineMatrix.h"
|
|
|
|
#include <cmath>
|
|
|
|
// GLOBAL: gl_24780
|
|
int g_groundOverlayA;
|
|
|
|
// GLOBAL: gl_24781
|
|
int g_groundOverlayB;
|
|
|
|
// GLOBAL: gl_24782
|
|
int g_groundOverlaySkip;
|
|
|
|
// GLOBAL: gl_24783
|
|
int g_groundOverlayC;
|
|
|
|
namespace {
|
|
// INLINED
|
|
float Absolute(float value) {
|
|
return std::fabs(value);
|
|
}
|
|
|
|
// INLINED
|
|
void IncludeRectangle(const int* rectangle, int* output) {
|
|
if (output[0] > rectangle[0]) {
|
|
output[0] = rectangle[0];
|
|
}
|
|
|
|
if (output[2] < rectangle[2]) {
|
|
output[2] = rectangle[2];
|
|
}
|
|
|
|
if (output[1] > rectangle[1]) {
|
|
output[1] = rectangle[1];
|
|
}
|
|
|
|
if (output[3] < rectangle[3]) {
|
|
output[3] = rectangle[3];
|
|
}
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00ADB7F0
|
|
// FUNCTION: fn_17922
|
|
int WorldViewSpatial::ClassifyOriented(const OrientedBounds& bounds) const {
|
|
bool clipped = false;
|
|
|
|
for (int plane = 0; plane < 6; ++plane) {
|
|
const float* normal = this->planes.normals[plane];
|
|
const float second = Absolute(((normal[0] * bounds.axes[1][0] + normal[1] * bounds.axes[1][1]) + normal[2] * bounds.axes[1][2]) * bounds.halfSize[1]);
|
|
const float first = Absolute(((normal[0] * bounds.axes[0][0] + normal[1] * bounds.axes[0][1]) + normal[2] * bounds.axes[0][2]) * bounds.halfSize[0]);
|
|
const float third = Absolute(((normal[0] * bounds.axes[2][0] + normal[1] * bounds.axes[2][1]) + normal[2] * bounds.axes[2][2]) * bounds.halfSize[2]);
|
|
const float radius = (second + first) + third;
|
|
const float distance = ((normal[0] * bounds.center[0] + normal[1] * bounds.center[1]) + normal[2] * bounds.center[2]) + this->planes.planes[plane][3];
|
|
|
|
if (!(distance > radius)) {
|
|
const float negative = -radius;
|
|
|
|
if (!(distance > negative)) {
|
|
return 0;
|
|
}
|
|
|
|
clipped = true;
|
|
}
|
|
}
|
|
|
|
return clipped ? 2 : 1;
|
|
}
|
|
|
|
// INLINED
|
|
int ClassifyModelView(const OrientedBounds& bounds, const ModelViewPlanes& planes) {
|
|
bool clipped = false;
|
|
|
|
for (unsigned plane = 0; plane < 6; ++plane) {
|
|
const float* normal = planes.normals[plane];
|
|
const float second = Absolute(((bounds.axes[1][0] * normal[0] + bounds.axes[1][1] * normal[1]) + bounds.axes[1][2] * normal[2]) * bounds.halfSize[1]);
|
|
const float first = Absolute(((bounds.axes[0][0] * normal[0] + bounds.axes[0][1] * normal[1]) + bounds.axes[0][2] * normal[2]) * bounds.halfSize[0]);
|
|
const float third = Absolute(((bounds.axes[2][0] * normal[0] + bounds.axes[2][1] * normal[1]) + bounds.axes[2][2] * normal[2]) * bounds.halfSize[2]);
|
|
const float radius = (second + first) + third;
|
|
const float distance =
|
|
((bounds.center[0] * normal[0] + bounds.center[1] * normal[1]) + bounds.center[2] * normal[2]) + planes.planes[plane][3];
|
|
|
|
if (!(distance > radius)) {
|
|
const float negative = -radius;
|
|
|
|
if (!(distance > negative)) {
|
|
return 0;
|
|
}
|
|
|
|
clipped = true;
|
|
}
|
|
}
|
|
|
|
return clipped ? 2 : 1;
|
|
}
|
|
|
|
// INLINED
|
|
void DrawWorldModelLeaves(
|
|
std::list<WorldSpatialTree*>& clipped, std::list<WorldSpatialTree*>& inside, const ModelViewPlanes& planes, const float* matrix, unsigned frame, int updates,
|
|
GroundGeometry& ground, int* visibleRectangle
|
|
) {
|
|
visibleRectangle[0] = visibleRectangle[1] = 999;
|
|
visibleRectangle[2] = visibleRectangle[3] = 0;
|
|
|
|
for (WorldSpatialTree* node : clipped) {
|
|
for (C3dActor* model : node->objects) {
|
|
if (model->renderFrame == frame) {
|
|
continue;
|
|
}
|
|
|
|
const int visibility = ClassifyModelView(model->oriented, planes);
|
|
|
|
if (updates > 0) {
|
|
model->Update();
|
|
}
|
|
|
|
if (visibility == 1 || visibility == 2) {
|
|
model->Draw(matrix, visibility == 2);
|
|
}
|
|
|
|
model->renderFrame = frame;
|
|
}
|
|
|
|
ground.DrawLit(matrix, node->groundCells, true);
|
|
IncludeRectangle(node->groundCells, visibleRectangle);
|
|
}
|
|
|
|
for (WorldSpatialTree* node : inside) {
|
|
for (C3dActor* model : node->objects) {
|
|
if (updates > 0) {
|
|
model->Update();
|
|
}
|
|
|
|
if (model->renderFrame != frame) {
|
|
model->Draw(matrix, false);
|
|
model->renderFrame = frame;
|
|
}
|
|
}
|
|
|
|
ground.DrawLit(matrix, node->groundCells, false);
|
|
IncludeRectangle(node->groundCells, visibleRectangle);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00ADC1E0
|
|
// FUNCTION: fn_17930
|
|
void CView::Render() {
|
|
g_worldViewDrawn = 1;
|
|
|
|
const float* matrix = this->frame.view.values;
|
|
this->spatial.Collect(g_renderer->viewport.horizontal, g_renderer->viewport.vertical, matrix, this->scene->spatial);
|
|
|
|
g_visibleMinY = 999;
|
|
g_visibleMinX = 999;
|
|
g_visibleMaxY = 0;
|
|
g_visibleMaxX = 0;
|
|
|
|
for (auto node = this->spatial.clipped.begin(); node != this->spatial.clipped.end(); ++node) {
|
|
std::vector<C3dActor*>& objects = (*node)->objects;
|
|
for (auto it = objects.begin(); it != objects.end(); ++it) {
|
|
C3dActor* model = *it;
|
|
if (model->renderFrame == g_renderer->frame) {
|
|
continue;
|
|
}
|
|
|
|
const int visibility = this->spatial.ClassifyOriented(model->oriented);
|
|
|
|
if (g_updateTick > 0) {
|
|
model->Update();
|
|
}
|
|
|
|
switch (visibility) {
|
|
case 1:
|
|
model->Draw(matrix, false);
|
|
break;
|
|
case 2:
|
|
model->Draw(matrix, true);
|
|
break;
|
|
}
|
|
|
|
model->renderFrame = g_renderer->frame;
|
|
}
|
|
|
|
(*node)->ground->DrawLit(matrix, (*node)->groundCells, true);
|
|
|
|
if (g_visibleMinX > (*node)->groundCells[0]) {
|
|
g_visibleMinX = (*node)->groundCells[0];
|
|
}
|
|
|
|
if (g_visibleMaxX < (*node)->groundCells[2]) {
|
|
g_visibleMaxX = (*node)->groundCells[2];
|
|
}
|
|
|
|
if (g_visibleMinY > (*node)->groundCells[1]) {
|
|
g_visibleMinY = (*node)->groundCells[1];
|
|
}
|
|
|
|
if (g_visibleMaxY < (*node)->groundCells[3]) {
|
|
g_visibleMaxY = (*node)->groundCells[3];
|
|
}
|
|
}
|
|
|
|
for (auto node = this->spatial.inside.begin(); node != this->spatial.inside.end(); ++node) {
|
|
std::vector<C3dActor*>& objects = (*node)->objects;
|
|
for (auto it = objects.begin(); it != objects.end(); ++it) {
|
|
C3dActor* model = *it;
|
|
if (g_updateTick > 0) {
|
|
model->Update();
|
|
}
|
|
|
|
if (model->renderFrame != g_renderer->frame) {
|
|
model->Draw(matrix, false);
|
|
model->renderFrame = g_renderer->frame;
|
|
}
|
|
}
|
|
|
|
(*node)->ground->DrawLit(matrix, (*node)->groundCells, false);
|
|
|
|
if (g_visibleMinY > (*node)->groundCells[1]) {
|
|
g_visibleMinY = (*node)->groundCells[1];
|
|
}
|
|
|
|
if (g_visibleMaxY < (*node)->groundCells[3]) {
|
|
g_visibleMaxY = (*node)->groundCells[3];
|
|
}
|
|
|
|
if (g_visibleMinX > (*node)->groundCells[0]) {
|
|
g_visibleMinX = (*node)->groundCells[0];
|
|
}
|
|
|
|
if (g_visibleMaxX < (*node)->groundCells[2]) {
|
|
g_visibleMaxX = (*node)->groundCells[2];
|
|
}
|
|
}
|
|
|
|
g_navigationManager.DrawRoute(matrix);
|
|
|
|
if (g_groundOverlaySkip == 0) {
|
|
this->scene->ground->DrawGrid(*this->scene->terrain, matrix, g_groundOverlayA, g_groundOverlayB, g_groundOverlayC);
|
|
}
|
|
|
|
if (g_session.unknown_5614 != 0 && g_session.unknown_5600 != 0 && g_session.unknown_5604 != 0) {
|
|
this->scene->ground->DrawGrid(*this->scene->terrain, matrix, g_session.unknown_5600, g_session.unknown_5604, 0xfeff0000);
|
|
}
|
|
|
|
for (auto it = this->scene->objects.begin(); it != this->scene->objects.end(); ++it) {
|
|
(*it)->Render(reinterpret_cast<std::intptr_t>(matrix));
|
|
}
|
|
|
|
g_effectMgr->Render();
|
|
|
|
const float x = this->camera.target[0] - this->frame.eye[0];
|
|
const float y = this->camera.target[1] - this->frame.eye[1];
|
|
const float z = this->camera.target[2] - this->frame.eye[2];
|
|
*reinterpret_cast<float*>(&g_renderer->unknown_003C) = x;
|
|
*reinterpret_cast<float*>(&g_renderer->unknown_0040) = y;
|
|
*reinterpret_cast<float*>(&g_renderer->unknown_0044) = z;
|
|
const float inverseLength = 1.0f / SquareRoot(x * x + y * y + z * z);
|
|
*reinterpret_cast<float*>(&g_renderer->unknown_003C) *= inverseLength;
|
|
*reinterpret_cast<float*>(&g_renderer->unknown_0040) *= inverseLength;
|
|
*reinterpret_cast<float*>(&g_renderer->unknown_0044) *= inverseLength;
|
|
|
|
this->spatial.inside.clear();
|
|
this->spatial.clipped.clear();
|
|
|
|
this->scene->ground->Ground15Slot04(reinterpret_cast<int>(matrix));
|
|
}
|