[Scummvm-git-logs] scummvm master -> bbc4af50dbe4be11c3b251e5c83b6a917ea80de4
mduggan
mgithub at guarana.org
Sun Apr 5 06:44:23 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
bbc4af50db ULTIMA8: Remove dead and duplicate code from ItemSorter
Commit: bbc4af50dbe4be11c3b251e5c83b6a917ea80de4
https://github.com/scummvm/scummvm/commit/bbc4af50dbe4be11c3b251e5c83b6a917ea80de4
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2020-04-05T15:44:06+09:00
Commit Message:
ULTIMA8: Remove dead and duplicate code from ItemSorter
Changed paths:
engines/ultima/ultima8/world/item_sorter.cpp
engines/ultima/ultima8/world/item_sorter.h
diff --git a/engines/ultima/ultima8/world/item_sorter.cpp b/engines/ultima/ultima8/world/item_sorter.cpp
index d208a4b494..4de379a3d0 100644
--- a/engines/ultima/ultima8/world/item_sorter.cpp
+++ b/engines/ultima/ultima8/world/item_sorter.cpp
@@ -645,11 +645,10 @@ void ItemSorter::BeginDisplayList(RenderSurface *rs,
}
void ItemSorter::AddItem(int32 x, int32 y, int32 z, uint32 shapeNum, uint32 frame_num, uint32 flags, uint32 ext_flags, uint16 itemNum) {
- //if (z > skip_lift) return;
- //if (Application::tgwds && _shape == 538) return;
// First thing, get a SortItem to use (first of unused)
- if (!_itemsUnused) _itemsUnused = new SortItem(0);
+ if (!_itemsUnused)
+ _itemsUnused = new SortItem(0);
SortItem *si = _itemsUnused;
si->_itemNum = itemNum;
@@ -663,26 +662,13 @@ void ItemSorter::AddItem(int32 x, int32 y, int32 z, uint32 shapeNum, uint32 fram
return;
}
- ShapeInfo *info = _shapes->getShapeInfo(shapeNum);
-
- //if (info->is_editor && !show_editor_items) return;
- //if (info->z > shape_max_height) return;
-
- // Dimensions
- int32 xd, yd, zd;
si->_flags = flags;
si->_extFlags = ext_flags;
- // X and Y are flipped
- if (si->_flags & Item::FLG_FLIPPED) {
- xd = info->_y * 32; // Multiply by 32 to get actual world size
- yd = info->_x * 32; // Multiply by 32 to get actual world size
- } else {
- xd = info->_x * 32; // Multiply by 32 to get actual world size
- yd = info->_y * 32; // Multiply by 32 to get actual world size
- }
-
- zd = info->_z * 8; // Multiply by 8 to get actual world size
+ const ShapeInfo *info = _shapes->getShapeInfo(shapeNum);
+ // Dimensions
+ int32 xd, yd, zd;
+ info->getFootpadWorld(xd, yd, zd, flags & Item::FLG_FLIPPED);
// Worldspace bounding box
si->_x = x;
@@ -707,14 +693,6 @@ void ItemSorter::AddItem(int32 x, int32 y, int32 z, uint32 shapeNum, uint32 fram
// Screenspace bounding box bottom extent (RNB y coord)
si->_syBot = si->_x / 8 + si->_y / 8 - si->_z - _camSy;
-// si->_sxLeft += swo2;
-// si->_sxRight += swo2;
-// si->_sxBot += swo2;
-// si->_sxTop += swo2;
-
-// si->_syTop += sho2;
-// si->_syBot += sho2;
-
// Real Screenspace coords
si->_sx = si->_sxBot - _frame->_xoff; // Left
si->_sy = si->_syBot - _frame->_yoff; // Top
@@ -723,36 +701,23 @@ void ItemSorter::AddItem(int32 x, int32 y, int32 z, uint32 shapeNum, uint32 fram
// Do Clipping here
si->_clipped = _surf->CheckClipped(Rect(si->_sx, si->_sy, _frame->_width, _frame->_height));
- if (si->_clipped < 0) return;
+ if (si->_clipped < 0)
+ return;
// These help out with sorting. We calc them now, so it will be faster
si->_f32x32 = xd == 128 && yd == 128;
si->_flat = zd == 0;
- /*
- if (Application::tgwds) {
- si->_draw = false;
- si->_solid = false;
- si->_occl = false;
- si->roof = false;
- si->noisy = false;
- si->_anim = false;
- si->_trans = false;
- }
- else
- */
- {
- si->_draw = info->is_draw();
- si->_solid = info->is_solid();
- si->_occl = info->is_occl() && !(si->_flags & Item::FLG_INVISIBLE) &&
- !(si->_extFlags & Item::EXT_TRANSPARENT);
- si->_roof = info->is_roof();
- si->_noisy = info->is_noisy();
- si->_anim = info->_animType != 0;
- si->_trans = info->is_translucent();
- si->_fixed = info->is_fixed();
- si->_land = info->is_land();
- }
+ si->_draw = info->is_draw();
+ si->_solid = info->is_solid();
+ si->_occl = info->is_occl() && !(si->_flags & Item::FLG_INVISIBLE) &&
+ !(si->_extFlags & Item::EXT_TRANSPARENT);
+ si->_roof = info->is_roof();
+ si->_noisy = info->is_noisy();
+ si->_anim = info->_animType != 0;
+ si->_trans = info->is_translucent();
+ si->_fixed = info->is_fixed();
+ si->_land = info->is_land();
si->_occluded = false;
si->_order = -1;
@@ -761,7 +726,6 @@ void ItemSorter::AddItem(int32 x, int32 y, int32 z, uint32 shapeNum, uint32 fram
// Stictly speaking the vector will sort of leak memory, since they
// are never deleted
si->_depends.clear();
- //si->_depends.erase(si->_depends.begin(), si->_depends.end()); // MSVC.Netism
// Iterate the list and compare _shapes
@@ -769,10 +733,12 @@ void ItemSorter::AddItem(int32 x, int32 y, int32 z, uint32 shapeNum, uint32 fram
SortItem *addpoint = nullptr;
for (SortItem *si2 = _items; si2 != nullptr; si2 = si2->_next) {
// Get the insert point... which is before the first item that has higher z than us
- if (!addpoint && si->ListLessThan(si2)) addpoint = si2;
+ if (!addpoint && si->ListLessThan(si2))
+ addpoint = si2;
// Doesn't overlap
- if (si2->_occluded || !si->overlap(*si2)) continue;
+ if (si2->_occluded || !si->overlap(*si2))
+ continue;
// Attempt to find which is infront
if (*si < *si2) {
@@ -787,9 +753,11 @@ void ItemSorter::AddItem(int32 x, int32 y, int32 z, uint32 shapeNum, uint32 fram
si2->_depends.insert_sorted(si);
} else {
// ss occludes si2. Sadly, we can't remove it from the list.
- if (si->_occl && si->occludes(*si2)) si2->_occluded = true;
+ if (si->_occl && si->occludes(*si2))
+ si2->_occluded = true;
// si2 is behind si1, so add it to si1's dependency list
- else si->_depends.push_back(si2);
+ else
+ si->_depends.push_back(si2);
}
}
@@ -802,195 +770,28 @@ void ItemSorter::AddItem(int32 x, int32 y, int32 z, uint32 shapeNum, uint32 fram
si->_next = addpoint;
si->_prev = addpoint->_prev;
addpoint->_prev = si;
- if (si->_prev) si->_prev->_next = si;
- else _items = si;
+ if (si->_prev)
+ si->_prev->_next = si;
+ else
+ _items = si;
}
// Add it to the end of the list
else {
- if (_itemsTail) _itemsTail->_next = si;
- if (!_items) _items = si;
+ if (_itemsTail)
+ _itemsTail->_next = si;
+ if (!_items)
+ _items = si;
si->_next = nullptr;
si->_prev = _itemsTail;
_itemsTail = si;
}
}
-void ItemSorter::AddItem(Item *add) {
-#if 0
-
+void ItemSorter::AddItem(const Item *add) {
int32 x, y, z;
add->getLerped(x, y, z);
- AddItem(x, y, z, add->getShape(), add->getFrame(), add->getFlags(), add->getObjId());
-
-#else
-
- //if (add->iz > skip_lift) return;
- //if (Application::tgwds && _shape == 538) return;
-
- // First thing, get a SortItem to use
- if (!_itemsUnused) _itemsUnused = new SortItem(0);
- SortItem *si = _itemsUnused;
-
- si->_itemNum = add->getObjId();
- si->_shape = add->getShapeObject();
- si->_shapeNum = add->getShape();
- si->_frame = add->getFrame();
- const ShapeFrame *_frame = si->_shape->getFrame(si->_frame);
- if (!_frame) {
- perr << "Invalid _shape: " << si->_shapeNum << "," << si->_frame
- << Std::endl;
- return;
- }
-
- ShapeInfo *info = add->getShapeInfo();
-
- //if (info->is_editor && !show_editor_items) return;
- //if (info->z > shape_max_height) return;
-
- // Dimensions
- int32 xd, yd, zd;
- si->_flags = add->getFlags();
- si->_extFlags = add->getExtFlags();
-
- // X and Y are flipped
- if (si->_flags & Item::FLG_FLIPPED) {
- xd = info->_y * 32; // Multiply by 32 to get actual world size
- yd = info->_x * 32; // Multiply by 32 to get actual world size
- } else {
- xd = info->_x * 32; // Multiply by 32 to get actual world size
- yd = info->_y * 32; // Multiply by 32 to get actual world size
- }
-
- zd = info->_z * 8; // Multiply by 8 to get actual world size
-
- // Worldspace bounding box
- add->getLerped(si->_x, si->_y, si->_z);
- si->_xLeft = si->_x - xd;
- si->_yFar = si->_y - yd;
- si->_zTop = si->_z + zd;
-
- // Screenspace bounding box left extent (LNT x coord)
- si->_sxLeft = si->_xLeft / 4 - si->_y / 4 - _camSx;
- // Screenspace bounding box right extent (RFT x coord)
- si->_sxRight = si->_x / 4 - si->_yFar / 4 - _camSx;
-
- // Screenspace bounding box top x coord (LFT x coord)
- si->_sxTop = si->_xLeft / 4 - si->_yFar / 4 - _camSx;
- // Screenspace bounding box top extent (LFT y coord)
- si->_syTop = si->_xLeft / 8 + si->_yFar / 8 - si->_zTop - _camSy;
-
- // Screenspace bounding box bottom x coord (RNB x coord)
- si->_sxBot = si->_x / 4 - si->_y / 4 - _camSx;
- // Screenspace bounding box bottom extent (RNB y coord)
- si->_syBot = si->_x / 8 + si->_y / 8 - si->_z - _camSy;
-
-// si->_sxLeft += swo2;
-// si->_sxRight += swo2;
-// si->_sxBot += swo2;
-// si->_sxTop += swo2;
-
-// si->_syTop += sho2;
-// si->_syBot += sho2;
-
- // Real Screenspace coords
- si->_sx = si->_sxBot - _frame->_xoff; // Left
- si->_sy = si->_syBot - _frame->_yoff; // Top
- si->_sx2 = si->_sx + _frame->_width; // Right
- si->_sy2 = si->_sy + _frame->_height; // Bottom
-
- // Do Clipping here
- si->_clipped = _surf->CheckClipped(Rect(si->_sx, si->_sy, _frame->_width, _frame->_height));
- if (si->_clipped < 0) return;
-
- // These help out with sorting. We calc them now, so it will be faster
- si->_f32x32 = xd == 128 && yd == 128;
- si->_flat = zd == 0;
-
- /*
- if (Application::tgwds) {
- si->_draw = false;
- si->_solid = false;
- si->_occl = false;
- si->roof = false;
- si->noisy = false;
- si->_anim = false;
- si->_trans = false;
- }
- else
- */
- {
- si->_draw = info->is_draw();
- si->_solid = info->is_solid();
- si->_occl = info->is_occl() && !(si->_flags & Item::FLG_INVISIBLE) &&
- !(si->_extFlags & Item::EXT_TRANSPARENT);
- si->_roof = info->is_roof();
- si->_noisy = info->is_noisy();
- si->_anim = info->_animType != 0;
- si->_trans = info->is_translucent();
- si->_fixed = info->is_fixed();
- si->_land = info->is_land();
- }
-
- si->_occluded = false;
- si->_order = -1;
-
- // We will clear all the vector memory
- // Stictly speaking the vector will sort of leak memory, since they
- // are never deleted
- si->_depends.clear();
- //si->_depends.erase(si->_depends.begin(), si->_depends.end()); // MSVC.Netism
-
- // Iterate the list and compare _shapes
-
- // Ok,
- SortItem *addpoint = nullptr;
- for (SortItem *si2 = _items; si2 != nullptr; si2 = si2->_next) {
- // Get the insert point... which is before the first item that has higher z than us
- if (!addpoint && si->ListLessThan(si2)) addpoint = si2;
-
- // Doesn't overlap
- if (si2->_occluded || !si->overlap(*si2)) continue;
-
- // Attempt to find which is infront
- if (*si < *si2) {
- // si2 occludes si
- if (si2->_occl && si2->occludes(*si)) {
- // No need to do any more checks, this isn't visible
- si->_occluded = true;
- break;
- }
-
- // si is behind si2, so add it to si2's dependency list
- si2->_depends.insert_sorted(si);
- } else {
- // si occludes si2. Sadly, we can't remove it from the list.
- if (si->_occl && si->occludes(*si2)) si2->_occluded = true;
- // si2 is behind si, so add it to si's dependency list
- else si->_depends.push_back(si2);
- }
- }
-
- // Add it to the list
- _itemsUnused = _itemsUnused->_next;
-
- // have a position
- //addpoint = 0;
- if (addpoint) {
- si->_next = addpoint;
- si->_prev = addpoint->_prev;
- addpoint->_prev = si;
- if (si->_prev) si->_prev->_next = si;
- else _items = si;
- }
- // Add it to the end of the list
- else {
- if (_itemsTail) _itemsTail->_next = si;
- if (!_items) _items = si;
- si->_next = nullptr;
- si->_prev = _itemsTail;
- _itemsTail = si;
- }
-#endif
+ AddItem(x, y, z, add->getShape(), add->getFrame(),
+ add->getFlags(), add->getExtFlags(), add->getObjId());
}
SortItem *_prev = 0;
diff --git a/engines/ultima/ultima8/world/item_sorter.h b/engines/ultima/ultima8/world/item_sorter.h
index fdb6a704a6..9eb873f935 100644
--- a/engines/ultima/ultima8/world/item_sorter.h
+++ b/engines/ultima/ultima8/world/item_sorter.h
@@ -57,7 +57,7 @@ public:
int32 camx, int32 camy, int32 camz);
void AddItem(int32 x, int32 y, int32 z, uint32 shape_num, uint32 frame_num, uint32 item_flags, uint32 ext_flags, uint16 item_num = 0);
- void AddItem(Item *); // Add an Item. SetupLerp() MUST have been called
+ void AddItem(const Item *); // Add an Item. SetupLerp() MUST have been called
void PaintDisplayList(bool item_highlight = false); // Finishes the display list and Paints
More information about the Scummvm-git-logs
mailing list