Adding support for Achievements in RetroPlayer#1
Conversation
9a4a4a8 to
693d4aa
Compare
| const char* richPresence) | ||
| { | ||
| m_username = username; | ||
| m_token = token; |
There was a problem hiding this comment.
same here, you are keeping a reference to a kodi pointer, also I believe it's better to add a new method SetRetroAchievementsCredentials(const char* username, const char* token) and call it once and then use the instance variables instead of passing username and token each time a post is happening and setting the value again
There was a problem hiding this comment.
How can we limit the function call to take place only once, I am not sure of it.
I can check if m_username and m_token is NULL, if yes then I will call this function, will it be fine?
There was a problem hiding this comment.
you will call the new function once when you activate achievements for example here. you wont limit the calls to this function, you will remove 2 arguments an 2 assignments
There was a problem hiding this comment.
Okay so I have done it now through a little different way which I will show you in a day or two
|
|
||
| void CCheevos::ActivateAchievement(unsigned cheevo_id, const char* memaddr) //1 | ||
| { | ||
| int res = rc_runtime_activate_achievement(&m_runtime, cheevo_id, memaddr, NULL, 0); |
There was a problem hiding this comment.
you could make this method to return bool and do something like the other methods
| int res = rc_runtime_activate_achievement(&m_runtime, cheevo_id, memaddr, NULL, 0); | |
| return rc_runtime_activate_achievement(&m_runtime, cheevo_id, memaddr, NULL, 0) == 0; |
| const char* username, | ||
| const char* token, |
There was a problem hiding this comment.
again here you can use the instance variables instead of getting them as parameters
| bool CCheevos::GetCheevo_ID(void (*Callback)(char* achievement_url, unsigned cheevo_id)) | ||
| { | ||
| //kodi::Log(ADDON_LOG_ERROR, "Fine till nowwwww in Callback"); | ||
| Callback(url, m_cheevo_id); | ||
| return true; | ||
| } |
There was a problem hiding this comment.
this method isn't used anywhere and the callback here isn't needed you could just return the m_cheevo_id the point of the callback was to be called when the cheevo id is set and not call a function each frame from kodi. Here you just pass a callback as an argument and you immediately call it which doesn't help anywhere you could just return the url
|
|
||
| m_client.retro_run(); | ||
|
|
||
| CCheevos::Get().TestAchievementPerFrame(); |
There was a problem hiding this comment.
minor: add an empty line before and after
| CCheevos::Get().ActivateAchievement(cheevo_id, memaddr); | ||
| return GAME_ERROR_NO_ERROR; |
There was a problem hiding this comment.
you should change ActivateAchievement to return a boolean value and return GAME_ERROR_FAILED if it returns false like the other methods
| { | ||
| return GAME_ERROR_FAILED; | ||
| } | ||
| return GAME_ERROR_NO_ERROR(); |
There was a problem hiding this comment.
GAME_ERROR_NO_ERROR is not a function, you should remove the ()
| CCheevos::Get().DeactivateTriggeredAchievement(cheevo_id); | ||
| return GAME_ERROR_NO_ERROR; |
There was a problem hiding this comment.
same here, return GAME_ERROR_FAILED if DeactivateTriggeredAchievement returns false
There was a problem hiding this comment.
I think there is no need of this function in client.cpp so I will remove it, as it is called from cheevos.cpp and used there only
| return true; | ||
| } | ||
|
|
||
| void CCheevos::DeactivateTriggeredAchievement(unsigned cheevo_id) |
There was a problem hiding this comment.
you could make this method to return bool and do something like the other methods
There was a problem hiding this comment.
lgtm 👍
Btw, please rewrite the commit history in a meaningful way.
You can use interactive rebase. You can also do git reset 693d4aa22386e594bf39404573d155af6498392f && git reset HEAD~ which will delete all the commits (it will not delete the changes you made) and then you can add all the files and do git commit -m "RetroPlayer achievements support", for example
| void CCheevos::ActivateAchievement(unsigned cheevo_id, const char* memaddr) | ||
| { | ||
| rc_runtime_activate_achievement(&m_runtime, cheevo_id, memaddr, NULL, 0); | ||
| // it will return integer value 0 in case achivement is activated successfully. |
There was a problem hiding this comment.
rc_runtime_activate_achievement will return 0 if the achievement is activated successfully but the method ActivateAchievement returns void?
There was a problem hiding this comment.
Yes, I will make these changes after rebasing and adding new commits
| { | ||
| CCheevos::Get().ActivateAchievement(cheevo_id, memaddr); | ||
|
|
||
| return GAME_ERROR_NO_ERROR; |
There was a problem hiding this comment.
Is this supposed to return GAME_ERROR_NO_ERROR at all times? What if something happens and CCheevos::Get().ActivateAchievement (which returns void) fails? If we don't want to handle the errors at all for now, that's fine.
| GAME_ERROR CGameLibRetro::GetCheevo_URL_ID(void (*Callback)(const char* achievement_url, | ||
| unsigned cheevo_id)) | ||
| { | ||
| CCheevos::Get().GetCheevo_URL_ID(Callback); |
There was a problem hiding this comment.
Same here, if GetCheevo_URL_ID fails, we never know it because it returns void. Again, if it's not essential to handle errors around this for now, it's fine.
45fb977 to
5e2f992
Compare
2554122 to
40ada13
Compare
d54d5a6 to
19efb51
Compare
0a3df37 to
5b8d4c9
Compare
2fd03e8 to
262c7b3
Compare
I have changed client.cpp, client.h, cheevos.cpp, cheevo.h for the Achievement feature till now, recent commit have a log debug command for testing whether activate achievement function will be called successfully from xbmc code or not.