-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Jsonize species footsteps sound #31493
Jsonize species footsteps sound #31493
Conversation
src/mtype.cpp
Outdated
for( const species_id &s : species ) { | ||
return s.obj().get_footsteps(); | ||
} | ||
return "footstepz."; |
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.
Typo? (footstepz instead of footsteps)
@@ -790,6 +790,8 @@ void MonsterGenerator::load_species( JsonObject &jo, const std::string &src ) | |||
|
|||
void species_type::load( JsonObject &jo, const std::string & ) | |||
{ | |||
optional( jo, was_loaded, "footsteps", footsteps, "footsteps." ); | |||
footsteps = _( footsteps ); |
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.
Translation should occur in get_footsteps
. Changing the language midway through a game will not change the stored (and already translated) string, so the footsteps will still be in the language that was selected upon loading the game.
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.
That is intentional - translation calls inside of footsteps function are very expensive.
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.
It's possible to detect language changes and swap out this value, we can look into doing that in a future PR.
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 was thinking whether it is possible not to make rather costly translation calls in a runtime, but instead do translation on json data loading (possibly with data/translation reloading when language is changed or simply requiring game restart on language change).
I don't think that changing language during running game is a frequent use-case. It is really cheaper to select language and reload game then doing thousands of calls to get the same footstep string.
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 don't think translation calls are expensive. After a simple benchmark, 10 samples without I18N and another 10 samples with I18N, it seems a single gettext call only costs extra 0.32us on a pretty old Core Duo laptop.
#include <iostream>
#include <libintl.h>
using namespace std;
const int cnt = 1000*1000;
int main()
{
setlocale(LC_ALL, "zh_CN");
bindtextdomain( "cataclysm-dda", "lang/mo" );
bind_textdomain_codeset( "cataclysm-dda", "UTF-8" );
textdomain( "cataclysm-dda" );
for(int i = 0; i < cnt; i++)
#ifdef I18N
cout << gettext("battery") << endl;
#else
cout << "battery" << endl;
#endif
return 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.
We are doing various optimizations now and libgettext calls started to appear on top in various scenarios after other things were optimized.
@@ -68,15 +69,18 @@ | |||
{ | |||
"type": "SPECIES", | |||
"id": "WORM", | |||
"footsteps": "rustle.", |
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.
Translatable strings in JSON require separate code in "lang/extract_json_strings.py" to extract them for translation.
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've updated Python script - hope everything was correct.
CC: @BrettDong
208b653
to
c7e7322
Compare
Summary
SUMMARY: Features "Jsonize species footsteps sound"
Purpose of change
Allow definition of monster species footsteps sound via json.