[*] Optimize button popup drawing by caching its width and height
[*] More correct grayscale formula [-] Fixed crash wheh program can't read file in debug mode [-] Fixed crash with spawn-missile when target unit is dead [-] Fixed crash then CUnit::TTL killing dead unit
This commit is contained in:
parent
24fe5a7fab
commit
0f41a9e3b3
9 changed files with 46 additions and 16 deletions
src
action
animation
include
missile
stratagus
ui
|
@ -287,7 +287,7 @@ static inline void IncreaseVariable(CUnit &unit, int index)
|
|||
static void HandleBuffsEachCycle(CUnit &unit)
|
||||
{
|
||||
// Look if the time to live is over.
|
||||
if (unit.TTL && unit.TTL < GameCycle) {
|
||||
if (unit.TTL && unit.IsAlive() && unit.TTL < GameCycle) {
|
||||
DebugPrint("Unit must die %lu %lu!\n" _C_ unit.TTL _C_ GameCycle);
|
||||
|
||||
// Hit unit does some funky stuff...
|
||||
|
|
|
@ -184,8 +184,9 @@ static int ParseAnimFlags(CUnit &unit, const char *parseflag)
|
|||
if (flags & ANIM_SM_DAMAGE) {
|
||||
missile->SourceUnit = &unit;
|
||||
}
|
||||
if (flags & ANIM_SM_TOTARGET) {
|
||||
missile->TargetUnit = goal->CurrentOrder()->GetGoal();
|
||||
CUnit *target = goal->CurrentOrder()->GetGoal();
|
||||
if (flags & ANIM_SM_TOTARGET && target && target->IsAlive()) {
|
||||
missile->TargetUnit = target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -238,6 +238,8 @@ extern enum _cursor_on_ CursorOn;
|
|||
|
||||
/// vladi: used for unit buttons sub-menus etc
|
||||
extern int CurrentButtonLevel;
|
||||
/// Last drawn popup : used to speed up drawing
|
||||
extern ButtonAction *LastDrawnButtonPopup;
|
||||
|
||||
/// Time to detect double clicks
|
||||
extern int DoubleClickDelay;
|
||||
|
|
|
@ -893,14 +893,18 @@ void Missile::MissileHit(CUnit *unit)
|
|||
}
|
||||
|
||||
if (mtype.CorrectSphashDamage == true) {
|
||||
bool isPositionSpell = false;
|
||||
if (this->TargetUnit == NULL && this->SourceUnit->CurrentAction() == UnitActionSpellCast) {
|
||||
const COrder_SpellCast &order = *static_cast<COrder_SpellCast *>(this->SourceUnit->CurrentOrder());
|
||||
if (order.GetSpell().Target == TargetPosition) {
|
||||
isPositionSpell = true;
|
||||
bool isPosition = false;
|
||||
if (this->TargetUnit == NULL) {
|
||||
if (this->SourceUnit->CurrentAction() == UnitActionSpellCast) {
|
||||
const COrder_SpellCast &order = *static_cast<COrder_SpellCast *>(this->SourceUnit->CurrentOrder());
|
||||
if (order.GetSpell().Target == TargetPosition) {
|
||||
isPosition = true;
|
||||
}
|
||||
} else {
|
||||
isPosition = true;
|
||||
}
|
||||
}
|
||||
if (isPositionSpell || this->SourceUnit->CurrentAction() == UnitActionAttackGround) {
|
||||
if (isPosition || this->SourceUnit->CurrentAction() == UnitActionAttackGround) {
|
||||
if (goal.Type->UnitType != this->SourceUnit->Type->UnitType) {
|
||||
shouldHit = false;
|
||||
}
|
||||
|
|
|
@ -190,8 +190,8 @@ void UpdateDisplay()
|
|||
UI.Minimap.DrawViewportArea(*UI.SelectedViewport);
|
||||
|
||||
UI.InfoPanel.Draw();
|
||||
UI.ButtonPanel.Draw();
|
||||
DrawResources();
|
||||
UI.ButtonPanel.Draw();
|
||||
UI.StatusLine.Draw();
|
||||
}
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ static bool GetFileContent(const std::string &file, std::string &content)
|
|||
|
||||
content.clear();
|
||||
if (fp.open(file.c_str(), CL_OPEN_READ) == -1) {
|
||||
DebugPrint("Can't open file '%s': %s\n" _C_ file.c_str());
|
||||
DebugPrint("Can't open file '%s\n" _C_ file.c_str());
|
||||
fprintf(stderr, "Can't open file '%s': %s\n", file.c_str(), strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -69,6 +69,8 @@
|
|||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/// Last drawn popup : used to speed up drawing
|
||||
ButtonAction *LastDrawnButtonPopup;
|
||||
/// for unit buttons sub-menus etc.
|
||||
int CurrentButtonLevel;
|
||||
/// All buttons for units
|
||||
|
@ -198,6 +200,7 @@ void CleanButtons()
|
|||
UnitButtonTable.clear();
|
||||
|
||||
CurrentButtonLevel = 0;
|
||||
LastDrawnButtonPopup = NULL;
|
||||
CurrentButtons.clear();
|
||||
}
|
||||
|
||||
|
@ -535,15 +538,25 @@ void DrawPopupUnitInfo(const CUnitType *type,
|
|||
}
|
||||
#endif
|
||||
|
||||
static struct PopupDrawCache {
|
||||
int popupWidth;
|
||||
int popupHeight;
|
||||
} popupCache;
|
||||
|
||||
/**
|
||||
** Draw popup
|
||||
*/
|
||||
void DrawPopup(const ButtonAction &button, const CUIButton &uibutton)
|
||||
{
|
||||
CPopup *popup = PopupByIdent(button.Popup);
|
||||
bool useCache = false;
|
||||
|
||||
if (!popup) {
|
||||
return;
|
||||
} else if (&button == LastDrawnButtonPopup) {
|
||||
useCache = true;
|
||||
} else {
|
||||
LastDrawnButtonPopup = const_cast<ButtonAction *>(&button);
|
||||
}
|
||||
|
||||
int popupWidth, popupHeight;
|
||||
|
@ -568,9 +581,17 @@ void DrawPopup(const ButtonAction &button, const CUIButton &uibutton)
|
|||
break;
|
||||
}
|
||||
|
||||
GetPopupSize(*popup, button, popupWidth, popupHeight, Costs);
|
||||
popupWidth = std::max(popupWidth, popup->MinWidth);
|
||||
popupHeight = std::max(popupHeight, popup->MinHeight);
|
||||
if (useCache) {
|
||||
popupWidth = popupCache.popupWidth;
|
||||
popupHeight = popupCache.popupHeight;
|
||||
} else {
|
||||
GetPopupSize(*popup, button, popupWidth, popupHeight, Costs);
|
||||
popupWidth = std::max(popupWidth, popup->MinWidth);
|
||||
popupHeight = std::max(popupHeight, popup->MinHeight);
|
||||
popupCache.popupWidth = popupWidth;
|
||||
popupCache.popupHeight = popupHeight;
|
||||
}
|
||||
|
||||
int x = std::min<int>(uibutton.X, Video.Width - 1 - popupWidth);
|
||||
int y = uibutton.Y - popupHeight - 10;
|
||||
|
||||
|
@ -1185,6 +1206,7 @@ void CButtonPanel::DoClicked_StandGround()
|
|||
void CButtonPanel::DoClicked_Button(int button)
|
||||
{
|
||||
CurrentButtonLevel = CurrentButtons[button].Value;
|
||||
LastDrawnButtonPopup = NULL;
|
||||
UI.ButtonPanel.Update();
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,6 @@ void CIcon::DrawIcon(const CPlayer &player, const PixelPos &pos) const
|
|||
/**
|
||||
** Draw icon at pos.
|
||||
**
|
||||
** @param player Player pointer used for icon colors
|
||||
** @param pos display pixel position
|
||||
*/
|
||||
void CIcon::DrawGrayscaleIcon(const PixelPos &pos) const
|
||||
|
@ -146,7 +145,7 @@ void CIcon::DrawGrayscaleIcon(const PixelPos &pos) const
|
|||
SDL_Palette &pal = *this->G->Surface->format->palette;
|
||||
memcpy(backup, pal.colors, sizeof(SDL_Color) * 256);
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
int gray = 0.2 * pal.colors[i].r + 0.4 * pal.colors[i].g + 0.12 * pal.colors[i].b;
|
||||
int gray = 0.21 * pal.colors[i].r + 0.72 * pal.colors[i].g + 0.07 * pal.colors[i].b;
|
||||
colors[i].r = colors[i].g = colors[i].b = gray;
|
||||
}
|
||||
SDL_SetColors(this->G->Surface, &colors[0], 0, 256);
|
||||
|
|
|
@ -1045,6 +1045,8 @@ void SelectionChanged()
|
|||
UI.StatusLine.Clear();
|
||||
ClearCosts();
|
||||
CurrentButtonLevel = 0;
|
||||
LastDrawnButtonPopup = NULL;
|
||||
|
||||
UI.ButtonPanel.Update();
|
||||
GameCursor = UI.Point.Cursor;
|
||||
CursorBuilding = NULL;
|
||||
|
|
Loading…
Add table
Reference in a new issue