-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for Achievements in RetroPlayer #1
base: rcheevos
Are you sure you want to change the base?
Conversation
9a4a4a8
to
693d4aa
Compare
src/cheevos/Cheevos.cpp
Outdated
@@ -72,6 +77,8 @@ bool CCheevos::PostRichPresenceUrl(char* url, | |||
unsigned gameID, | |||
const char* richPresence) | |||
{ | |||
m_username = username; | |||
m_token = token; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so I have done it now through a little different way which I will show you in a day or two
src/cheevos/Cheevos.cpp
Outdated
@@ -91,6 +98,102 @@ void CCheevos::EvaluateRichPresence(char* evaluation, size_t size) | |||
rc_evaluate_richpresence(m_richPresence, evaluation, size, PeekInternal, this, NULL); | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
src/cheevos/Cheevos.cpp
Outdated
const char* username, | ||
const char* token, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again here you can use the instance variables instead of getting them as parameters
src/cheevos/Cheevos.cpp
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
src/client.cpp
Outdated
@@ -278,7 +278,7 @@ GAME_ERROR CGameLibRetro::RunFrame() | |||
m_clientBridge.FrameTime(delta); | |||
|
|||
m_client.retro_run(); | |||
|
|||
CCheevos::Get().TestAchievementPerFrame(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: add an empty line before and after
src/client.cpp
Outdated
CCheevos::Get().ActivateAchievement(cheevo_id, memaddr); | ||
return GAME_ERROR_NO_ERROR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should change ActivateAchievement
to return a boolean value and return GAME_ERROR_FAILED
if it returns false
like the other methods
src/client.cpp
Outdated
{ | ||
return GAME_ERROR_FAILED; | ||
} | ||
return GAME_ERROR_NO_ERROR(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GAME_ERROR_NO_ERROR
is not a function, you should remove the ()
src/client.cpp
Outdated
CCheevos::Get().DeactivateTriggeredAchievement(cheevo_id); | ||
return GAME_ERROR_NO_ERROR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, return GAME_ERROR_FAILED
if DeactivateTriggeredAchievement
returns false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could make this method to return bool and do something like the other methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.