REPLAY AWARDS

11 views
Skip to first unread message

james cardona

unread,
Jan 1, 2013, 5:54:09 PM1/1/13
to fre...@googlegroups.com
Hi all,
the replay award feature is not working for me as originally written.  I think I found the offending code (which I don't quite understand)
and below are my uncommited changes.  I don't really understand what this "unlikely" does or know exactly how the replay score offset works either, but my changes do work as far as I have tested - only for the first replay level.

in replay.c we have:

void replay_check_current (void)
{
    replay_score_t *curr;

    if (unlikely (system_config.replay_award == FREE_AWARD_OFF)) {
        return;
    }

    if (unlikely (replay_total_this_player >= NUM_REPLAY_LEVELS)){
        return;
    }

    // OLD METHOD
//    curr = (replay_score_t *)(current_score + REPLAY_SCORE_OFFSET);
//    if (unlikely (*curr >= next_replay_score)) {
//        replay_award ();

//MY METHOD
    if (score_compare (current_score, next_replay_score) ) {
        replay_award ();
    }
}

Ewan Meadows

unread,
Jan 1, 2013, 6:07:58 PM1/1/13
to fre...@googlegroups.com
ooh, I dunno. To be honest I haven't looked at your code yet but I
remember looking at Brians, discussing it with people and seeing it as
the best way. I may be wrong however ;-)
ooh I dunno

Dominic Clifton

unread,
Jan 1, 2013, 6:30:27 PM1/1/13
to fre...@googlegroups.com

The ‘unlikely()’ macro is to help the compiler generate better output for the usual-case scenario IIRC.

 

Dominic

Brian Dominy

unread,
Jan 1, 2013, 7:07:36 PM1/1/13
to fre...@googlegroups.com
On Tue, Jan 1, 2013 at 5:54 PM, james cardona <JAMES....@pseg.com> wrote:
    // OLD METHOD
//    curr = (replay_score_t *)(current_score + REPLAY_SCORE_OFFSET);
//    if (unlikely (*curr >= next_replay_score)) {
//        replay_award ();

//MY METHOD
    if (score_compare (current_score, next_replay_score) ) {
        replay_award ();


Yes, this is a bug - and your fix is correct.  The way that replay scores are tracked changed significantly in 2011, and this code should have been changed but it was not.  Good find.
 
And yes, unlikely() is just a hint to the compiler - it generates no code on its own.  Usually the effect is that "more likely" code will run slightly faster.

- Brian

Ewan Meadows

unread,
Jan 1, 2013, 7:11:24 PM1/1/13
to fre...@googlegroups.com
Ah I remember now, I had an IRC discussion about how you assigned
replays to more than one player with several people and we all agreed
that it was the best method, it wasn't that code at all.

Ewan Meadows

unread,
Jan 1, 2013, 7:12:25 PM1/1/13
to fre...@googlegroups.com
Duh, match not replay.

Brian Dominy

unread,
Jan 2, 2013, 1:32:10 PM1/2/13
to fre...@googlegroups.com
On Tue, Jan 1, 2013 at 5:54 PM, james cardona <JAMES....@pseg.com> wrote:
//MY METHOD
    if (score_compare (current_score, next_replay_score) ) {
        replay_award ();
    }
}

One small adjustment: change this to:

if (score_compare (current_score, next_replay_score) >= 0)

compare will return 0 if they are equal, and in the (bizarre) case where you match the replay score exactly, it should be credited.

Brian

Reply all
Reply to author
Forward
0 new messages