Skip to content
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

Open
wants to merge 13 commits into
base: rcheevos
Choose a base branch
from

Conversation

Shardul555
Copy link

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.

src/cheevos/Cheevos.cpp Show resolved Hide resolved
@@ -72,6 +77,8 @@ bool CCheevos::PostRichPresenceUrl(char* url,
unsigned gameID,
const char* richPresence)
{
m_username = username;
m_token = token;
Copy link
Owner

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

Copy link
Author

@Shardul555 Shardul555 Aug 8, 2021

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?

Copy link
Owner

@NikosSiak NikosSiak Aug 8, 2021

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

Copy link
Author

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

@@ -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);
Copy link
Owner

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

Suggested change
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;

Comment on lines 115 to 116
const char* username,
const char* token,
Copy link
Owner

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

Comment on lines 125 to 122
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;
}
Copy link
Owner

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();
Copy link
Owner

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
Comment on lines 528 to 529
CCheevos::Get().ActivateAchievement(cheevo_id, memaddr);
return GAME_ERROR_NO_ERROR;
Copy link
Owner

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();
Copy link
Owner

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
Comment on lines 571 to 572
CCheevos::Get().DeactivateTriggeredAchievement(cheevo_id);
return GAME_ERROR_NO_ERROR;
Copy link
Owner

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

Copy link
Author

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)
Copy link
Owner

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

@Shardul555 Shardul555 changed the title PR for debugging the changes done for Achievements portion Adding support for Achievements in RetroPlayer Aug 17, 2021
Copy link

@gusandrianos gusandrianos left a 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.

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?

Copy link
Author

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;

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);

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.

@NikosSiak NikosSiak force-pushed the rcheevos branch 2 times, most recently from 2554122 to 40ada13 Compare November 8, 2021 16:41
@NikosSiak NikosSiak force-pushed the rcheevos branch 3 times, most recently from d54d5a6 to 19efb51 Compare January 27, 2022 18:20
@NikosSiak NikosSiak force-pushed the rcheevos branch 4 times, most recently from 0a3df37 to 5b8d4c9 Compare February 20, 2022 14:15
@NikosSiak NikosSiak force-pushed the rcheevos branch 2 times, most recently from 2fd03e8 to 262c7b3 Compare March 20, 2022 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants