Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Rugby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruce Cowan
Rugby
Commits
7ba452b4
Commit
7ba452b4
authored
7 years ago
by
Bruce Cowan
Browse files
Options
Downloads
Patches
Plain Diff
Replace GVariant with GPtrArray
Not the intended purpose for variants
parent
4fd81442
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/rugby-score-store.c
+33
-45
33 additions, 45 deletions
src/rugby-score-store.c
src/rugby-scoring.c
+35
-38
35 additions, 38 deletions
src/rugby-scoring.c
src/rugby-scoring.h
+13
-6
13 additions, 6 deletions
src/rugby-scoring.h
with
81 additions
and
89 deletions
src/rugby-score-store.c
+
33
−
45
View file @
7ba452b4
...
@@ -95,58 +95,46 @@ rugby_score_store_class_init (RugbyScoreStoreClass *klass)
...
@@ -95,58 +95,46 @@ rugby_score_store_class_init (RugbyScoreStoreClass *klass)
}
}
static
void
static
void
populate_store
(
RugbyScoreStore
*
store
)
populate_store_foreach
(
gpointer
data
,
gpointer
user_data
)
{
{
GtkListStore
*
lstore
=
GTK_LIST_STORE
(
store
);
RugbyPossibility
*
possiblity
=
(
RugbyPossibility
*
)
data
;
GVariant
*
possibilities
;
GtkListStore
*
store
=
GTK_LIST_STORE
(
user_data
);
GVariant
*
possibility
;
GVariantIter
iter
;
GtkTreeIter
iter
;
gsize
total
;
gint
tries
=
possiblity
->
tries
;
gint
utries
=
possiblity
->
utries
;
gint
kicks
=
possiblity
->
kicks
;
g_autofree
gchar
*
tooltip
=
g_strdup_printf
(
"%d tries, %d converted, %d kicks"
,
tries
,
utries
,
kicks
);
gtk_list_store_append
(
store
,
&
iter
);
gtk_list_store_set
(
store
,
&
iter
,
RUGBY_SCORE_STORE_TRIES
,
tries
,
RUGBY_SCORE_STORE_UTRIES
,
utries
,
RUGBY_SCORE_STORE_KICKS
,
kicks
,
RUGBY_SCORE_STORE_TOOLTIP
,
tooltip
,
-
1
);
}
static
void
populate_store
(
RugbyScoreStore
*
self
)
{
GtkListStore
*
store
=
GTK_LIST_STORE
(
self
);
g_autoptr
(
GPtrArray
)
possibilities
=
NULL
;
/* Clear the store */
/* Clear the store */
gtk_list_store_clear
(
l
store
);
gtk_list_store_clear
(
store
);
possibilities
=
rugby_scoring_get_possibilities
(
s
tore
->
score
);
possibilities
=
rugby_scoring_get_possibilities
(
s
elf
->
score
);
if
(
possibilities
==
NULL
)
if
(
possibilities
->
len
==
0
)
return
;
return
;
total
=
g_variant_iter_init
(
&
iter
,
possibilities
);
g_ptr_array_foreach
(
possibilities
,
populate_store_foreach
,
store
);
while
((
possibility
=
g_variant_iter_next_value
(
&
iter
)))
{
gint
tries
,
utries
,
kicks
;
GString
*
tooltip
;
GtkTreeIter
iter
;
g_variant_get
(
possibility
,
"(iii)"
,
&
tries
,
&
utries
,
&
kicks
);
g_variant_unref
(
possibility
);
tooltip
=
g_string_new_len
(
NULL
,
20
);
if
(
utries
>
0
||
tries
>
0
)
{
g_string_append_printf
(
tooltip
,
"%d tries, %d converted"
,
tries
+
utries
,
tries
);
if
(
kicks
>
0
)
g_string_append_printf
(
tooltip
,
", %d kicks"
,
kicks
);
}
else
if
(
utries
==
0
&&
tries
==
0
)
g_string_append_printf
(
tooltip
,
"%d kicks"
,
kicks
);
/* Put result in list store */
gtk_list_store_append
(
lstore
,
&
iter
);
gtk_list_store_set
(
lstore
,
&
iter
,
RUGBY_SCORE_STORE_TRIES
,
tries
,
RUGBY_SCORE_STORE_UTRIES
,
utries
,
RUGBY_SCORE_STORE_KICKS
,
kicks
,
RUGBY_SCORE_STORE_TOOLTIP
,
tooltip
->
str
,
-
1
);
g_string_free
(
tooltip
,
TRUE
);
}
g_signal_emit
(
s
tore
,
signals
[
FINISHED
],
0
,
(
gint
)
total
);
g_signal_emit
(
s
elf
,
signals
[
FINISHED
],
0
,
(
gint
)
possibilities
->
len
);
}
}
static
void
static
void
...
...
This diff is collapsed.
Click to expand it.
src/rugby-scoring.c
+
35
−
38
View file @
7ba452b4
#include
"rugby-scoring.h"
#include
"rugby-scoring.h"
static
inline
void
possibility_free
(
gpointer
possibility
)
{
g_slice_free
(
RugbyPossibility
,
possibility
);
}
/**
/**
* rugby_scoring_get_possibilities:
* rugby_scoring_get_possibilities:
* @score: the score of a team
* @score: the score of a team
*
*
* Gets the possible ways of scoring @score points, as a %GVariant of the
* Gets the possible ways of scoring @score points.
* type "a(iii)", in the order "tries, utries, pens".
*
*
* Returns: (transfer-none): the possibilities, or %NULL in the case there are
* Returns: (transfer-full): the possibilities
* none
*/
*/
G
Variant
*
G
PtrArray
*
rugby_scoring_get_possibilities
(
gint
score
)
rugby_scoring_get_possibilities
(
gint
score
)
{
{
GVariantBuilder
builder
;
GPtrArray
*
array
;
gint
possibilities
=
0
;
gint
max_tries
,
max_utries
;
gint
tries
,
utries
;
g_return_val_if_fail
(
score
>=
0
,
NULL
);
g_variant_builder_init
(
&
builder
,
G_VARIANT_TYPE_ARRAY
);
g_return_val_if_fail
(
score
>=
0
,
NULL
);
max_tries
=
(
gint
)
(
score
/
TRY_POINTS
);
array
=
g_ptr_array_new_with_free_func
(
possibility_free
);
max_utries
=
(
gint
)
(
score
/
UTRY_POINTS
);
for
(
tries
=
0
;
tries
<=
max_tries
;
tries
++
)
gint
possibilities
=
0
;
{
gint
max_tries
=
score
/
TRY_POINTS
;
for
(
utries
=
0
;
utries
<=
max_utries
;
utries
++
)
gint
max_utries
=
score
/
UTRY_POINTS
;
{
gint
left
;
/* Calculate left over score for penalties */
for
(
gint
tries
=
0
;
tries
<=
max_tries
;
tries
++
)
left
=
score
-
(
tries
*
TRY_POINTS
)
-
(
utries
*
UTRY_POINTS
);
{
for
(
gint
utries
=
0
;
utries
<=
max_utries
;
utries
++
)
{
gint
left
=
score
-
(
tries
*
TRY_POINTS
)
-
(
utries
*
UTRY_POINTS
);
if
(
left
<
0
)
if
(
left
<
0
)
continue
;
continue
;
/* If the score after pens is 0, it's a possibility */
if
(
left
%
KICK_POINTS
==
0
)
if
(
left
%
KICK_POINTS
==
0
)
{
{
gint
kicks
=
left
/
KICK_POINTS
;
gint
pens
;
pens
=
left
/
KICK_POINTS
;
RugbyPossibility
*
possibility
=
g_slice_new
(
RugbyPossibility
);
possibility
->
tries
=
tries
;
possibility
->
utries
=
utries
;
possibility
->
kicks
=
kicks
;
/* Add result to variant */
g_ptr_array_add
(
array
,
possibility
);
g_variant_builder_add
(
&
builder
,
"(iii)"
,
tries
,
utries
,
pens
);
possibilities
++
;
possibilities
++
;
}
}
}
}
}
}
if
(
possibilities
==
0
)
return
array
;
return
NULL
;
else
return
g_variant_builder_end
(
&
builder
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
src/rugby-scoring.h
+
13
−
6
View file @
7ba452b4
...
@@ -11,14 +11,21 @@ G_BEGIN_DECLS
...
@@ -11,14 +11,21 @@ G_BEGIN_DECLS
typedef
enum
typedef
enum
{
{
RUGBY_SCORE_TYPE_TRY
,
RUGBY_SCORE_TYPE_TRY
,
RUGBY_SCORE_TYPE_UTRY
,
RUGBY_SCORE_TYPE_UTRY
,
RUGBY_SCORE_TYPE_KICK
RUGBY_SCORE_TYPE_KICK
}
RugbyScoreType
;
}
RugbyScoreType
;
GVariant
*
rugby_scoring_get_possibilities
(
gint
score
);
typedef
struct
gint
rugby_scoring_get_max_tries
(
gint
score
);
{
gint
rugby_scoring_get_max_kicks
(
gint
score
);
gint
tries
;
gint
utries
;
gint
kicks
;
}
RugbyPossibility
;
GPtrArray
*
rugby_scoring_get_possibilities
(
gint
score
);
gint
rugby_scoring_get_max_tries
(
gint
score
);
gint
rugby_scoring_get_max_kicks
(
gint
score
);
G_END_DECLS
G_END_DECLS
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment