X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=02358aa292a3803890ca42b4526f679af0884cce;hb=b08a9452f891ea0132aca72b79abead3f7784d1c;hp=9885217c4706ae77366cff4ddc47f50d646ae9a4;hpb=9f9e4ca920d37c88d3c6e15d645e18e8b56e662a;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 9885217c..02358aa2 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1682,6 +1682,31 @@ void swap_number_pairs(int *x1, int *y1, int *x2, int *y2) *y2 = help_y; } +int get_number_of_bits(int bits) +{ + /* + Counting bits set, Brian Kernighan's way + + Brian Kernighan's method goes through as many iterations as there are set + bits. So if we have a 32-bit word with only the high bit set, then it will + only go once through the loop. + + Published in 1988, the C Programming Language 2nd Ed. (by Brian W. Kernighan + and Dennis M. Ritchie) mentions this in exercise 2-9. + First published by Peter Wegner in CACM 3 (1960), 322. + */ + + int num_bits = 0; + + while (bits) + { + bits &= bits - 1; // clear the least significant bit set + num_bits++; + } + + return num_bits; +} + /* the "put" variants of the following file access functions check for the file pointer being != NULL and return the number of bytes they have or would have written; this allows for chunk writing functions to first determine the size @@ -4179,6 +4204,11 @@ void FreeCustomArtworkLists(struct ArtworkListInfo *artwork_info) // (now also added for Windows, to create files in user data directory) // ---------------------------------------------------------------------------- +char *getLogBasename(char *basename) +{ + return getStringCat2(basename, ".log"); +} + char *getLogFilename(char *basename) { return getPath2(getMainUserGameDataDir(), basename);