Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
c4efa8f1
Commit
c4efa8f1
authored
Mar 09, 2011
by
Max-Wilhelm Bruker
Browse files
performance improvement
parent
349a60fb
Changes
5
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/handcounter.h
View file @
c4efa8f1
...
@@ -23,4 +23,3 @@ public:
...
@@ -23,4 +23,3 @@ public:
};
};
#endif
#endif
cockatrice/src/player.cpp
View file @
c4efa8f1
...
@@ -22,36 +22,65 @@
...
@@ -22,36 +22,65 @@
#include
<QMenu>
#include
<QMenu>
#include
<QDebug>
#include
<QDebug>
Player
::
Player
(
ServerInfo_User
*
info
,
int
_id
,
bool
_local
,
TabGame
*
_
parent
)
Player
Area
::
Player
Area
(
QGraphicsItem
*
parent
Item
)
:
QObject
(
_parent
),
shortcutsActive
(
false
),
defaultNumberTopCards
(
3
),
lastTokenDestroy
(
true
),
userInfo
(
new
ServerInfo_User
(
info
)),
id
(
_id
),
active
(
false
),
local
(
_local
),
mirrored
(
false
),
handVisible
(
false
),
conceded
(
false
),
dialogSemaphore
(
false
)
:
QObject
(
),
QGraphicsItem
(
parentItem
)
{
{
setCacheMode
(
DeviceCoordinateCache
);
setCacheMode
(
DeviceCoordinateCache
);
connect
(
settingsCache
,
SIGNAL
(
horizontalHandChanged
()),
this
,
SLOT
(
rearrangeZones
()));
connect
(
settingsCache
,
SIGNAL
(
playerBgPathChanged
()),
this
,
SLOT
(
updateBgPixmap
()));
connect
(
settingsCache
,
SIGNAL
(
playerBgPathChanged
()),
this
,
SLOT
(
updateBgPixmap
()));
updateBgPixmap
();
updateBgPixmap
();
}
void
PlayerArea
::
updateBgPixmap
()
{
QString
bgPath
=
settingsCache
->
getPlayerBgPath
();
if
(
bgPath
.
isEmpty
())
bgPixmapBrush
=
QBrush
(
QColor
(
200
,
200
,
200
));
else
{
qDebug
()
<<
"loading"
<<
bgPath
;
bgPixmapBrush
=
QBrush
(
QPixmap
(
bgPath
));
}
update
();
}
void
PlayerArea
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*/
*
option
*/
,
QWidget
*/
*
widget
*/
)
{
painter
->
fillRect
(
bRect
,
bgPixmapBrush
);
}
void
PlayerArea
::
setSize
(
qreal
width
,
qreal
height
)
{
prepareGeometryChange
();
bRect
=
QRectF
(
0
,
0
,
width
,
height
);
}
Player
::
Player
(
ServerInfo_User
*
info
,
int
_id
,
bool
_local
,
TabGame
*
_parent
)
:
QObject
(
_parent
),
shortcutsActive
(
false
),
defaultNumberTopCards
(
3
),
lastTokenDestroy
(
true
),
userInfo
(
new
ServerInfo_User
(
info
)),
id
(
_id
),
active
(
false
),
local
(
_local
),
mirrored
(
false
),
handVisible
(
false
),
conceded
(
false
),
dialogSemaphore
(
false
)
{
connect
(
settingsCache
,
SIGNAL
(
horizontalHandChanged
()),
this
,
SLOT
(
rearrangeZones
()));
playerTarget
=
new
PlayerTarget
(
this
);
playerArea
=
new
PlayerArea
(
this
);
playerTarget
=
new
PlayerTarget
(
this
,
playerArea
);
qreal
avatarMargin
=
(
counterAreaWidth
+
CARD_HEIGHT
+
15
-
playerTarget
->
boundingRect
().
width
())
/
2.0
;
qreal
avatarMargin
=
(
counterAreaWidth
+
CARD_HEIGHT
+
15
-
playerTarget
->
boundingRect
().
width
())
/
2.0
;
playerTarget
->
setPos
(
QPointF
(
avatarMargin
,
avatarMargin
));
playerTarget
->
setPos
(
QPointF
(
avatarMargin
,
avatarMargin
));
PileZone
*
deck
=
new
PileZone
(
this
,
"deck"
,
true
,
false
,
this
);
PileZone
*
deck
=
new
PileZone
(
this
,
"deck"
,
true
,
false
,
playerArea
);
QPointF
base
=
QPointF
(
counterAreaWidth
+
(
CARD_HEIGHT
-
CARD_WIDTH
+
15
)
/
2.0
,
10
+
playerTarget
->
boundingRect
().
height
()
+
5
-
(
CARD_HEIGHT
-
CARD_WIDTH
)
/
2.0
);
QPointF
base
=
QPointF
(
counterAreaWidth
+
(
CARD_HEIGHT
-
CARD_WIDTH
+
15
)
/
2.0
,
10
+
playerTarget
->
boundingRect
().
height
()
+
5
-
(
CARD_HEIGHT
-
CARD_WIDTH
)
/
2.0
);
deck
->
setPos
(
base
);
deck
->
setPos
(
base
);
qreal
h
=
deck
->
boundingRect
().
width
()
+
5
;
qreal
h
=
deck
->
boundingRect
().
width
()
+
5
;
HandCounter
*
handCounter
=
new
HandCounter
(
this
);
HandCounter
*
handCounter
=
new
HandCounter
(
playerArea
);
handCounter
->
setPos
(
base
+
QPointF
(
0
,
h
+
10
));
handCounter
->
setPos
(
base
+
QPointF
(
0
,
h
+
10
));
qreal
h2
=
handCounter
->
boundingRect
().
height
();
qreal
h2
=
handCounter
->
boundingRect
().
height
();
PileZone
*
grave
=
new
PileZone
(
this
,
"grave"
,
false
,
true
,
this
);
PileZone
*
grave
=
new
PileZone
(
this
,
"grave"
,
false
,
true
,
playerArea
);
grave
->
setPos
(
base
+
QPointF
(
0
,
h
+
h2
+
10
));
grave
->
setPos
(
base
+
QPointF
(
0
,
h
+
h2
+
10
));
PileZone
*
rfg
=
new
PileZone
(
this
,
"rfg"
,
false
,
true
,
this
);
PileZone
*
rfg
=
new
PileZone
(
this
,
"rfg"
,
false
,
true
,
playerArea
);
rfg
->
setPos
(
base
+
QPointF
(
0
,
2
*
h
+
h2
+
10
));
rfg
->
setPos
(
base
+
QPointF
(
0
,
2
*
h
+
h2
+
10
));
PileZone
*
sb
=
new
PileZone
(
this
,
"sb"
,
false
,
false
,
this
);
PileZone
*
sb
=
new
PileZone
(
this
,
"sb"
,
false
,
false
,
playerArea
);
sb
->
setVisible
(
false
);
sb
->
setVisible
(
false
);
table
=
new
TableZone
(
this
,
this
);
table
=
new
TableZone
(
this
,
this
);
...
@@ -377,16 +406,6 @@ void Player::updateZones()
...
@@ -377,16 +406,6 @@ void Player::updateZones()
table
->
reorganizeCards
();
table
->
reorganizeCards
();
}
}
void
Player
::
updateBgPixmap
()
{
QString
bgPath
=
settingsCache
->
getPlayerBgPath
();
if
(
!
bgPath
.
isEmpty
())
{
qDebug
()
<<
"loading"
<<
bgPath
;
bgPixmap
.
load
(
bgPath
);
}
update
();
}
void
Player
::
updateBoundingRect
()
void
Player
::
updateBoundingRect
()
{
{
prepareGeometryChange
();
prepareGeometryChange
();
...
@@ -396,6 +415,8 @@ void Player::updateBoundingRect()
...
@@ -396,6 +415,8 @@ void Player::updateBoundingRect()
bRect
=
QRectF
(
0
,
0
,
width
+
table
->
boundingRect
().
width
(),
table
->
boundingRect
().
height
()
+
handHeight
);
bRect
=
QRectF
(
0
,
0
,
width
+
table
->
boundingRect
().
width
(),
table
->
boundingRect
().
height
()
+
handHeight
);
}
else
}
else
bRect
=
QRectF
(
0
,
0
,
width
+
hand
->
boundingRect
().
width
()
+
table
->
boundingRect
().
width
(),
table
->
boundingRect
().
height
());
bRect
=
QRectF
(
0
,
0
,
width
+
hand
->
boundingRect
().
width
()
+
table
->
boundingRect
().
width
(),
table
->
boundingRect
().
height
());
playerArea
->
setSize
(
CARD_HEIGHT
+
counterAreaWidth
+
15
,
bRect
.
height
());
emit
sizeChanged
();
emit
sizeChanged
();
}
}
...
@@ -1054,13 +1075,8 @@ QRectF Player::boundingRect() const
...
@@ -1054,13 +1075,8 @@ QRectF Player::boundingRect() const
return
bRect
;
return
bRect
;
}
}
void
Player
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*/
*
option
*/
,
QWidget
*/
*
widget
*/
)
void
Player
::
paint
(
QPainter
*
/*
painter
*/
,
const
QStyleOptionGraphicsItem
*/
*
option
*/
,
QWidget
*/
*
widget
*/
)
{
{
int
totalWidth
=
CARD_HEIGHT
+
counterAreaWidth
+
15
;
if
(
bgPixmap
.
isNull
())
painter
->
fillRect
(
QRectF
(
0
,
0
,
totalWidth
,
boundingRect
().
height
()),
QColor
(
200
,
200
,
200
));
else
painter
->
fillRect
(
QRectF
(
0
,
0
,
totalWidth
,
boundingRect
().
height
()),
QBrush
(
bgPixmap
));
}
}
void
Player
::
processPlayerInfo
(
ServerInfo_Player
*
info
)
void
Player
::
processPlayerInfo
(
ServerInfo_Player
*
info
)
...
...
cockatrice/src/player.h
View file @
c4efa8f1
...
@@ -46,6 +46,24 @@ class Event_AttachCard;
...
@@ -46,6 +46,24 @@ class Event_AttachCard;
class
Event_DrawCards
;
class
Event_DrawCards
;
class
Event_RevealCards
;
class
Event_RevealCards
;
class
PlayerArea
:
public
QObject
,
public
QGraphicsItem
{
Q_OBJECT
private:
QBrush
bgPixmapBrush
;
QRectF
bRect
;
private
slots
:
void
updateBgPixmap
();
public:
enum
{
Type
=
typeOther
};
int
type
()
const
{
return
Type
;
}
PlayerArea
(
QGraphicsItem
*
parent
=
0
);
QRectF
boundingRect
()
const
{
return
bRect
;
}
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
void
setSize
(
qreal
width
,
qreal
height
);
};
class
Player
:
public
QObject
,
public
QGraphicsItem
{
class
Player
:
public
QObject
,
public
QGraphicsItem
{
Q_OBJECT
Q_OBJECT
signals:
signals:
...
@@ -109,7 +127,6 @@ private slots:
...
@@ -109,7 +127,6 @@ private slots:
void
removePlayer
(
Player
*
player
);
void
removePlayer
(
Player
*
player
);
void
playerListActionTriggered
();
void
playerListActionTriggered
();
void
updateBgPixmap
();
void
updateBoundingRect
();
void
updateBoundingRect
();
void
rearrangeZones
();
void
rearrangeZones
();
private:
private:
...
@@ -142,6 +159,7 @@ private:
...
@@ -142,6 +159,7 @@ private:
bool
clearCardsToDelete
();
bool
clearCardsToDelete
();
QList
<
CardItem
*>
cardsToDelete
;
QList
<
CardItem
*>
cardsToDelete
;
PlayerArea
*
playerArea
;
QMap
<
QString
,
CardZone
*>
zones
;
QMap
<
QString
,
CardZone
*>
zones
;
StackZone
*
stack
;
StackZone
*
stack
;
TableZone
*
table
;
TableZone
*
table
;
...
@@ -150,7 +168,6 @@ private:
...
@@ -150,7 +168,6 @@ private:
void
setCardAttrHelper
(
GameEventContext
*
context
,
CardItem
*
card
,
const
QString
&
aname
,
const
QString
&
avalue
,
bool
allCards
);
void
setCardAttrHelper
(
GameEventContext
*
context
,
CardItem
*
card
,
const
QString
&
aname
,
const
QString
&
avalue
,
bool
allCards
);
QPixmap
bgPixmap
;
QRectF
bRect
;
QRectF
bRect
;
QMap
<
int
,
AbstractCounter
*>
counters
;
QMap
<
int
,
AbstractCounter
*>
counters
;
...
...
cockatrice/src/playertarget.cpp
View file @
c4efa8f1
...
@@ -46,8 +46,8 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
...
@@ -46,8 +46,8 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
painter
->
drawText
(
translatedRect
,
Qt
::
AlignCenter
,
QString
::
number
(
value
));
painter
->
drawText
(
translatedRect
,
Qt
::
AlignCenter
,
QString
::
number
(
value
));
}
}
PlayerTarget
::
PlayerTarget
(
Player
*
_owner
)
PlayerTarget
::
PlayerTarget
(
Player
*
_owner
,
QGraphicsItem
*
parentItem
)
:
ArrowTarget
(
_owner
,
_owner
),
playerCounter
(
0
)
:
ArrowTarget
(
_owner
,
parentItem
),
playerCounter
(
0
)
{
{
setCacheMode
(
DeviceCoordinateCache
);
setCacheMode
(
DeviceCoordinateCache
);
...
...
cockatrice/src/playertarget.h
View file @
c4efa8f1
...
@@ -27,7 +27,7 @@ public:
...
@@ -27,7 +27,7 @@ public:
enum
{
Type
=
typePlayerTarget
};
enum
{
Type
=
typePlayerTarget
};
int
type
()
const
{
return
Type
;
}
int
type
()
const
{
return
Type
;
}
PlayerTarget
(
Player
*
parent
=
0
);
PlayerTarget
(
Player
*
_player
=
0
,
QGraphicsItem
*
parent
Item
=
0
);
QRectF
boundingRect
()
const
;
QRectF
boundingRect
()
const
;
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment