diff --git a/astyle.ini b/astyle.ini index 4544c17..0d60479 100644 --- a/astyle.ini +++ b/astyle.ini @@ -4,4 +4,5 @@ --indent=tab --indent-switches --pad-header +--unpad-paren --keep-one-line-blocks \ No newline at end of file diff --git a/data/translations/Makefile.am b/data/translations/Makefile.am index 444287e..e029fb2 100644 --- a/data/translations/Makefile.am +++ b/data/translations/Makefile.am @@ -3,20 +3,9 @@ pkgdatadir = $(datadir)/$(PACKAGE)/translations pkgdata_DATA = \ languages.lst \ - eu_ES.lst \ de_DE.lst \ es_ES.lst \ fr_FR.lst \ - it_IT.lst \ - nl_NL.lst \ - nb_NO.lst \ - nn_NO.lst \ - pl_PL.lst \ - pt_PT.lst \ - ru_RU.lst \ - ro_RO.lst \ - sk_SK.lst \ - fi_FI.lst \ - sv_SE.lst + pl_PL.lst EXTRA_DIST = $(pkgdata_DATA) diff --git a/data/translations/de_DE.lst b/data/translations/de_DE.lst index 547503b..3fbb830 100644 --- a/data/translations/de_DE.lst +++ b/data/translations/de_DE.lst @@ -103,4 +103,12 @@ *[idx] 83 [engl] Randomize settings [trans] Zufällige Einstellungen *[idx] 84 [engl] Fullscreen setting has changed, [trans] Damit die Vollbild-Einstellung geändert wird, -*[idx] 85 [engl] You need to restart the game [trans] muss das Spiel neugestartet werden. \ No newline at end of file +*[idx] 85 [engl] You need to restart the game [trans] muss das Spiel neugestartet werden. + +*[idx] 86 [engl] Score [trans] Punkte +*[idx] 87 [engl] Herring [trans] Herringe +*[idx] 88 [engl] Time [trans] Zeit +*[idx] 89 [engl] Path length [trans] Streckenlänge +*[idx] 90 [engl] Average speed [trans] Durchschnittsgeschwindigkeit +*[idx] 91 [engl] Position [trans] Platz +*[idx] 92 [engl] in highscore list [trans] in der Punktelilste. \ No newline at end of file diff --git a/data/translations/eu_ES.lst b/data/translations/eu_ES.lst deleted file mode 100644 index 3f3dd2e..0000000 --- a/data/translations/eu_ES.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] diff --git a/data/translations/fi_FI.lst b/data/translations/fi_FI.lst deleted file mode 100644 index 209a732..0000000 --- a/data/translations/fi_FI.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] \ No newline at end of file diff --git a/data/translations/it_IT.lst b/data/translations/it_IT.lst deleted file mode 100644 index 209a732..0000000 --- a/data/translations/it_IT.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] \ No newline at end of file diff --git a/data/translations/languages.lst b/data/translations/languages.lst index d3b99eb..44d8cdc 100644 --- a/data/translations/languages.lst +++ b/data/translations/languages.lst @@ -1,15 +1,4 @@ -*[lang] eu_ES [language] Basque *[lang] de_DE [language] Deutsch *[lang] es_ES [language] Español *[lang] fr_FR [language] français -*[lang] it_IT [language] Italian -*[lang] nl_NL [language] Nederlands -*[lang] nb_NO [language] Norsk (bokmål) -*[lang] nn_NO [language] Norsk (nynorsk) -*[lang] pl_PL [language] polski -*[lang] pt_PT [language] Português -*[lang] ru_RU [language] Русский -*[lang] ro_RO [language] românã -*[lang] sk_SK [language] Slovenčina -*[lang] fi_FI [language] Suomi -*[lang] sv_SE [language] Svenska \ No newline at end of file +*[lang] pl_PL [language] polski \ No newline at end of file diff --git a/data/translations/nb_NO.lst b/data/translations/nb_NO.lst deleted file mode 100644 index 209a732..0000000 --- a/data/translations/nb_NO.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] \ No newline at end of file diff --git a/data/translations/nl_NL.lst b/data/translations/nl_NL.lst deleted file mode 100644 index 209a732..0000000 --- a/data/translations/nl_NL.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] \ No newline at end of file diff --git a/data/translations/nn_NO.lst b/data/translations/nn_NO.lst deleted file mode 100644 index 209a732..0000000 --- a/data/translations/nn_NO.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] \ No newline at end of file diff --git a/data/translations/pt_PT.lst b/data/translations/pt_PT.lst deleted file mode 100644 index 209a732..0000000 --- a/data/translations/pt_PT.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] \ No newline at end of file diff --git a/data/translations/ro_RO.lst b/data/translations/ro_RO.lst deleted file mode 100644 index 209a732..0000000 --- a/data/translations/ro_RO.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] \ No newline at end of file diff --git a/data/translations/ru_RU.lst b/data/translations/ru_RU.lst deleted file mode 100644 index 209a732..0000000 --- a/data/translations/ru_RU.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] \ No newline at end of file diff --git a/data/translations/sk_SK.lst b/data/translations/sk_SK.lst deleted file mode 100644 index 209a732..0000000 --- a/data/translations/sk_SK.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] \ No newline at end of file diff --git a/data/translations/sv_SE.lst b/data/translations/sv_SE.lst deleted file mode 100644 index 209a732..0000000 --- a/data/translations/sv_SE.lst +++ /dev/null @@ -1,54 +0,0 @@ -# Please, don't change the idx - -*[idx] 0 [engl] PRESS ANY KEY TO START [trans] -*[idx] 1 [engl] Enter an event [trans] -*[idx] 2 [engl] Practice [trans] -*[idx] 3 [engl] Configuration [trans] -*[idx] 4 [engl] Credits [trans] -*[idx] 5 [engl] Quit [trans] -*[idx] 6 [engl] Select an event [trans] -*[idx] 7 [engl] Select a cup [trans] -*[idx] 8 [engl] Back [trans] -*[idx] 9 [engl] Continue [trans] -*[idx] 10 [engl] You cannot enter this cup yet - [trans] - -*[idx] 11 [engl] Herring: [trans] -*[idx] 12 [engl] Time: [trans] -*[idx] 13 [engl] Race! [trans] -*[idx] 14 [engl] seconds [trans] -*[idx] 15 [engl] Ok [trans] -*[idx] 16 [engl] Congratulations! You won the cup! - [trans] -*[idx] 17 [engl] You have reached level [trans] -*[idx] 18 [engl] Sorry, you didn't advance [trans] -*[idx] 19 [engl] You don't have any lives left [trans] -*[idx] 20 [engl] Select a race [trans] - -*[idx] 21 [engl] Failed, -1 Tuxlive [trans] -*[idx] 22 [engl] Success, +/- 0 Tuxlive [trans] -*[idx] 23 [engl] Success, +1 Tuxlive [trans] -*[idx] 24 [engl] Success, +2 Tuxlive [trans] -*[idx] 25 [engl] Race aborted [trans] -*[idx] 26 [engl] Score: [trans] -*[idx] 27 [engl] points [trans] - -*[idx] 28 [engl] Cancel [trans] -*[idx] 29 [engl] Loading [trans] -*[idx] 30 [engl] Please wait... [trans] - -*[idx] 31 [engl] Fullscreen: [trans] -*[idx] 32 [engl] Resolution: [trans] -*[idx] 33 [engl] Music volume: [trans] -*[idx] 34 [engl] Sound volume: [trans] -*[idx] 35 [engl] Language: [trans] -*[idx] 36 [engl] Level of detail: [trans] -*[idx] 37 [engl] Contributed by: [trans] -*[idx] 38 [engl] Event: [trans] -*[idx] 39 [engl] Cup: [trans] -*[idx] 40 [engl] Race Over [trans] - -*[idx] 41 [engl] For more configuration options, please edit the - [trans] -*[idx] 42 [engl] file 'options.lst' and read the documentation. - [trans] \ No newline at end of file diff --git a/data/translations/xx_XX.lst b/data/translations/xx_XX.lst index 4d7c73e..3d9bdeb 100644 --- a/data/translations/xx_XX.lst +++ b/data/translations/xx_XX.lst @@ -1,5 +1,4 @@ # Please, don't change the idx -# but you may change the order of the entries *[idx] 0 [engl] PRESS ANY KEY TO START [trans] *[idx] 1 [engl] Enter an event [trans] @@ -35,6 +34,7 @@ *[idx] 28 [engl] Cancel [trans] *[idx] 29 [engl] Loading [trans] *[idx] 30 [engl] Please wait... [trans] + *[idx] 31 [engl] Fullscreen: [trans] *[idx] 32 [engl] Resolution: [trans] *[idx] 33 [engl] Music volume: [trans] @@ -48,7 +48,6 @@ *[idx] 41 [engl] For more configuration options, please edit the [trans] *[idx] 42 [engl] file 'options.lst' and read the documentation. [trans] - *[idx] 43 [engl] Help [trans] *[idx] 44 [engl] 1, 2, 3 - change view mode [trans] *[idx] 45 [engl] F - hide/show fps display [trans] @@ -63,4 +62,47 @@ *[idx] 54 [engl] CRSR Right - turn right [trans] *[idx] 55 [engl] CRSR Up - accelerate [trans] *[idx] 56 [engl] CRSR down - brake [trans] -*[idx] 57 [engl] Keyboard Functions [trans] \ No newline at end of file +*[idx] 57 [engl] Keyboard Functions [trans] +*[idx] 65 [engl] Press any key to return to the main menu [trans] + +*[idx] 58 [engl] Select your player name: [trans] +*[idx] 59 [engl] Select a character: [trans] +*[idx] 60 [engl] Enter [trans] +*[idx] 61 [engl] Register a new player [trans] + +*[idx] 62 [engl] Highscore list [trans] +*[idx] 63 [engl] No entries for this race [trans] +*[idx] 64 [engl] Back [trans] + +*[idx] 66 [engl] Enter a name for the new player and select an avatar: [trans] + +*[idx] 67 [engl] Loading resources, [trans] +*[idx] 68 [engl] please wait [trans] + +*[idx] 69 [engl] Mirror track: Off [trans] +*[idx] 70 [engl] Mirror track: On [trans] + +*[idx] 71 [engl] Light: Sunny [trans] +*[idx] 72 [engl] Light: Cloudy [trans] +*[idx] 73 [engl] Light: Evening [trans] +*[idx] 74 [engl] Light: Night [trans] + +*[idx] 75 [engl] Snow: No [trans] +*[idx] 76 [engl] Snow: A little [trans] +*[idx] 77 [engl] Snow: Some [trans] +*[idx] 78 [engl] Snow: A lot [trans] + +*[idx] 79 [engl] Wind: No [trans] +*[idx] 80 [engl] Wind: Breeze [trans] +*[idx] 81 [engl] Wind: Strong [trans] +*[idx] 82 [engl] Wind: Blustery [trans] + +*[idx] 83 [engl] Randomize settings [trans] + +*[idx] 84 [engl] Score [trans] +*[idx] 85 [engl] Herring [trans] +*[idx] 86 [engl] Time [trans] +*[idx] 87 [engl] Path length [trans] +*[idx] 88 [engl] Average speed [trans] +*[idx] 89 [engl] Position [trans] +*[idx] 90 [engl] in highscore list [trans] \ No newline at end of file diff --git a/src/audio.cpp b/src/audio.cpp index fbedcce..90c4365 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -31,28 +31,28 @@ CSound Sound; // class CAudio // -------------------------------------------------------------------- -CAudio::CAudio () { +CAudio::CAudio() { IsOpen = false; } -void CAudio::Open () { +void CAudio::Open() { // first initialize audio (SDL, not SDL_Mixer). - if (SDL_Init (SDL_INIT_AUDIO) < 0) { - Message ("Couldn't initialize SDL Audio", SDL_GetError()); + if (SDL_Init(SDL_INIT_AUDIO) < 0) { + Message("Couldn't initialize SDL Audio", SDL_GetError()); return; } Uint16 format = AUDIO_S16SYS; int channels = 2; - if (Mix_OpenAudio (param.audio_freq, format, channels, param.audio_buffer_size) < 0) - Message ("Couldn't open SDL_mixer", Mix_GetError()); - IsOpen = CheckOpen (); - Mix_AllocateChannels (8); + if (Mix_OpenAudio(param.audio_freq, format, channels, param.audio_buffer_size) < 0) + Message("Couldn't open SDL_mixer", Mix_GetError()); + IsOpen = CheckOpen(); + Mix_AllocateChannels(8); } -void CAudio::Close () { +void CAudio::Close() { if (IsOpen) { - Music.FreeMusics (); - Sound.FreeSounds (); + Music.FreeMusics(); + Sound.FreeSounds(); Mix_CloseAudio(); IsOpen = false; } @@ -62,7 +62,7 @@ bool CAudio::CheckOpen() { int freq; Uint16 format; int channels; - int ret = Mix_QuerySpec (&freq, &format, &channels); + int ret = Mix_QuerySpec(&freq, &format, &channels); return (ret > 0); } @@ -70,47 +70,47 @@ bool CAudio::CheckOpen() { // class CSound // -------------------------------------------------------------------- -bool CSound::LoadChunk (const std::string& name, const char *filename) { +bool CSound::LoadChunk(const std::string& name, const char *filename) { if (Audio.IsOpen == false) return false; sounds.push_back(TSound()); - sounds.back().chunk = Mix_LoadWAV (filename); + sounds.back().chunk = Mix_LoadWAV(filename); if (sounds.back().chunk == NULL) return false; sounds.back().channel = -1; // default: no channel sounds.back().loop_count = 0; // default: playing once - Mix_VolumeChunk (sounds.back().chunk, param.sound_volume); + Mix_VolumeChunk(sounds.back().chunk, param.sound_volume); SoundIndex[name] = sounds.size()-1; return true; } // Load all soundfiles listed in "/sounds/sounds.lst" -void CSound::LoadSoundList () { +void CSound::LoadSoundList() { if (!Audio.IsOpen) { - Message ("cannot load music, first open Audio"); + Message("cannot load music, first open Audio"); return; } CSPList list(200); - if (list.Load (param.sounds_dir, "sounds.lst")) { + if (list.Load(param.sounds_dir, "sounds.lst")) { for (size_t i=0; i= sounds.size()) return; volume = clamp(0, volume, MIX_MAX_VOLUME); if (sounds[soundid].chunk == NULL) return; - Mix_VolumeChunk (sounds[soundid].chunk, volume); + Mix_VolumeChunk(sounds[soundid].chunk, volume); } -void CSound::SetVolume (const string& name, int volume) { - SetVolume (GetSoundIdx (name), volume); +void CSound::SetVolume(const string& name, int volume) { + SetVolume(GetSoundIdx(name), volume); } // ------------------- play ------------------------------------------- @@ -138,56 +138,56 @@ void TSound::Play(int loop) { if (active == true) return; if (chunk == NULL) return; - channel = Mix_PlayChannel (-1, chunk, loop); + channel = Mix_PlayChannel(-1, chunk, loop); loop_count = loop; if (loop < 0) active = true; } -void CSound::Play (size_t soundid, int loop) { +void CSound::Play(size_t soundid, int loop) { if (!Audio.IsOpen) return; if (soundid >= sounds.size()) return; sounds[soundid].Play(loop); } -void CSound::Play (const string& name, int loop) { - Play (GetSoundIdx (name), loop); +void CSound::Play(const string& name, int loop) { + Play(GetSoundIdx(name), loop); } -void CSound::Play (size_t soundid, int loop, int volume) { +void CSound::Play(size_t soundid, int loop, int volume) { if (!Audio.IsOpen) return; if (soundid >= sounds.size()) return; volume = clamp(0, volume, MIX_MAX_VOLUME); - Mix_VolumeChunk (sounds[soundid].chunk, volume); + Mix_VolumeChunk(sounds[soundid].chunk, volume); sounds[soundid].Play(loop); } -void CSound::Play (const string& name, int loop, int volume) { - Play (GetSoundIdx (name), loop, volume); +void CSound::Play(const string& name, int loop, int volume) { + Play(GetSoundIdx(name), loop, volume); } -void CSound::Halt (size_t soundid) { +void CSound::Halt(size_t soundid) { if (!Audio.IsOpen) return; if (soundid >= sounds.size()) return; if (sounds[soundid].chunk == NULL) return; // loop_count must be -1 (endless loop) for halt if (sounds[soundid].loop_count < 0) { - Mix_HaltChannel (sounds[soundid].channel); + Mix_HaltChannel(sounds[soundid].channel); sounds[soundid].loop_count = 0; sounds[soundid].channel = -1; sounds[soundid].active = false; } } -void CSound::Halt (const string& name) { - Halt (GetSoundIdx (name)); +void CSound::Halt(const string& name) { + Halt(GetSoundIdx(name)); } -void CSound::HaltAll () { +void CSound::HaltAll() { if (!Audio.IsOpen) return; - Mix_HaltChannel (-1); + Mix_HaltChannel(-1); for (size_t i=0; i= musics.size()) return false; Mix_Music *music = musics[musid]; return Play(music, loop, curr_volume); } -bool CMusic::Play (const string& name, int loop) { - return Play (GetMusicIdx(name), loop); +bool CMusic::Play(const string& name, int loop) { + return Play(GetMusicIdx(name), loop); } -bool CMusic::Play (size_t musid, int loop, int volume) { +bool CMusic::Play(size_t musid, int loop, int volume) { if (!Audio.IsOpen) return false; if (musid >= musics.size()) return false; Mix_Music *music = musics[musid]; return Play(music, loop, volume); } -bool CMusic::Play (const string& name, int loop, int volume) { - return Play (GetMusicIdx (name), loop, volume); +bool CMusic::Play(const string& name, int loop, int volume) { + return Play(GetMusicIdx(name), loop, volume); } -bool CMusic::PlayTheme (size_t theme, ESituation situation) { +bool CMusic::PlayTheme(size_t theme, ESituation situation) { if (theme >= themes.size()) return false; if (situation >= SITUATION_COUNT) return false; Mix_Music *music = themes [theme].situation[situation]; - return Play (music, -1, curr_volume); + return Play(music, -1, curr_volume); } -void CMusic::Halt () { - if (Mix_PlayingMusic ()) Mix_HaltMusic(); +void CMusic::Halt() { + if (Mix_PlayingMusic()) Mix_HaltMusic(); loop_count = -1; curr_music = 0; } diff --git a/src/audio.h b/src/audio.h index 88fbcb2..244f1f5 100644 --- a/src/audio.h +++ b/src/audio.h @@ -29,11 +29,11 @@ GNU General Public License for more details. class CAudio { private: public: - CAudio (); + CAudio(); - void Open (); - void Close (); - static bool CheckOpen (); + void Open(); + void Close(); + static bool CheckOpen(); bool IsOpen; }; @@ -47,7 +47,7 @@ struct TSound { int loop_count; bool active; - void Play (int loop); + void Play(int loop); }; class CSound { @@ -55,23 +55,23 @@ private: vector sounds; map SoundIndex; public: - bool LoadChunk (const std::string& name, const char *filename); - void LoadSoundList (); - size_t GetSoundIdx (const string& name) const; + bool LoadChunk(const std::string& name, const char *filename); + void LoadSoundList(); + size_t GetSoundIdx(const string& name) const; - void SetVolume (size_t soundid, int volume); - void SetVolume (const string& name, int volume); + void SetVolume(size_t soundid, int volume); + void SetVolume(const string& name, int volume); - void Play (size_t soundid, int loop); - void Play (const string& name, int loop); // -1 infinite, 0 once, 1 twice ... - void Play (size_t soundid, int loop, int volume); - void Play (const string& name, int loop, int volume); + void Play(size_t soundid, int loop); + void Play(const string& name, int loop); // -1 infinite, 0 once, 1 twice ... + void Play(size_t soundid, int loop, int volume); + void Play(const string& name, int loop, int volume); - void Halt (size_t soundid); - void Halt (const string& name); - void HaltAll (); + void Halt(size_t soundid); + void Halt(const string& name); + void HaltAll(); - void FreeSounds (); + void FreeSounds(); }; // -------------------------------------------------------------------- @@ -98,24 +98,24 @@ private: Mix_Music* curr_music; // current music piece int curr_volume; - bool Play (Mix_Music* music, int loop, int volume); + bool Play(Mix_Music* music, int loop, int volume); public: - CMusic (); + CMusic(); - bool LoadPiece (const string& name, const char *filename); - void LoadMusicList (); - size_t GetMusicIdx (const string& name) const; - size_t GetThemeIdx (const string& theme) const; + bool LoadPiece(const string& name, const char *filename); + void LoadMusicList(); + size_t GetMusicIdx(const string& name) const; + size_t GetThemeIdx(const string& theme) const; - void SetVolume (int volume); - void Update (); - bool Play (size_t musid, int loop); - bool Play (const string& name, int loop); - bool Play (size_t musid, int loop, int volume); - bool Play (const string& name, int loop, int volume); - bool PlayTheme (size_t theme, ESituation situation); - void Halt (); - void FreeMusics (); + void SetVolume(int volume); + void Update(); + bool Play(size_t musid, int loop); + bool Play(const string& name, int loop); + bool Play(size_t musid, int loop, int volume); + bool Play(const string& name, int loop, int volume); + bool PlayTheme(size_t theme, ESituation situation); + void Halt(); + void FreeMusics(); }; // -------------------------------------------------------------------- diff --git a/src/common.cpp b/src/common.cpp index b306b30..b569e64 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -30,77 +30,77 @@ GNU General Public License for more details. // color utils // -------------------------------------------------------------------- -const TColor colWhite (1.0, 1.0, 1.0, 1.0); -const TColor colDYell (1.0, 0.8, 0.0, 1.0); -const TColor colDDYell (0.8, 0.6, 0.0, 1.0); -const TColor colYellow (1.0, 1.0, 0.0, 1.0); -const TColor colLYell (1.0, 1.0, 0.4, 1.0); -const TColor colOrange (1.0, 0.5, 0.0, 1.0); -const TColor colLRed (1.0, 0.3, 0.3, 1.0); -const TColor colRed (1.0, 0.0, 0.0, 1.0); -const TColor colDRed (0.8, 0.0, 0.0, 1.0); -const TColor colGrey (0.5, 0.5, 0.5, 1.0); -const TColor colLGrey (0.7, 0.7, 0.7, 1.0); -const TColor colDGrey (0.3, 0.3, 0.3, 1.0); -const TColor colBlack (0.0, 0.0, 0.0, 1.0); -const TColor colBlue (0.0, 0.0, 1.0, 1.0); -const TColor colLBlue (0.5, 0.7, 1.0, 1.0); -const TColor colDBlue (0.0, 0.0, 0.6, 1.0); -const TColor colLBackgr (0.5, 0.7, 0.9, 1.0); -const TColor colBackgr (0.4, 0.6, 0.8, 1.0); -const TColor colMBackgr (0.35, 0.5, 0.7, 1.0); -const TColor colDBackgr (0.2, 0.3, 0.6, 1.0); -const TColor colDDBackgr (0.13, 0.2, 0.4, 1.0); -const TColor colMess (0.3, 0.3, 0.7, 1.0); -const TColor colSky (0.82, 0.86, 0.88, 1.0); +const TColor colWhite(1.0, 1.0, 1.0, 1.0); +const TColor colDYell(1.0, 0.8, 0.0, 1.0); +const TColor colDDYell(0.8, 0.6, 0.0, 1.0); +const TColor colYellow(1.0, 1.0, 0.0, 1.0); +const TColor colLYell(1.0, 1.0, 0.4, 1.0); +const TColor colOrange(1.0, 0.5, 0.0, 1.0); +const TColor colLRed(1.0, 0.3, 0.3, 1.0); +const TColor colRed(1.0, 0.0, 0.0, 1.0); +const TColor colDRed(0.8, 0.0, 0.0, 1.0); +const TColor colGrey(0.5, 0.5, 0.5, 1.0); +const TColor colLGrey(0.7, 0.7, 0.7, 1.0); +const TColor colDGrey(0.3, 0.3, 0.3, 1.0); +const TColor colBlack(0.0, 0.0, 0.0, 1.0); +const TColor colBlue(0.0, 0.0, 1.0, 1.0); +const TColor colLBlue(0.5, 0.7, 1.0, 1.0); +const TColor colDBlue(0.0, 0.0, 0.6, 1.0); +const TColor colLBackgr(0.5, 0.7, 0.9, 1.0); +const TColor colBackgr(0.4, 0.6, 0.8, 1.0); +const TColor colMBackgr(0.35, 0.5, 0.7, 1.0); +const TColor colDBackgr(0.2, 0.3, 0.6, 1.0); +const TColor colDDBackgr(0.13, 0.2, 0.4, 1.0); +const TColor colMess(0.3, 0.3, 0.7, 1.0); +const TColor colSky(0.82, 0.86, 0.88, 1.0); // -------------------------------------------------------------------- // print utils // -------------------------------------------------------------------- -void PrintInt (const int val) { +void PrintInt(const int val) { cout << "Integer: " << val << '\n'; } -void PrintInt (const string& s, const int val) { +void PrintInt(const string& s, const int val) { cout << s << val << endl; } -void PrintStr (const char *val) { +void PrintStr(const char *val) { cout << val << '\n'; } -void PrintString (const string& s) { +void PrintString(const string& s) { cout << s << endl; } -void PrintDouble (const double val) { +void PrintDouble(const double val) { cout.precision(4); cout << val << '\n'; } -void PrintVector4 (const TVector4d& v) { +void PrintVector4(const TVector4d& v) { cout.precision(3); cout << v.x << " " << v.y << " " << v.z << " " << v.w << '\n'; } -void PrintColor (const TColor& v) { +void PrintColor(const TColor& v) { cout.precision(3); cout << v.r << " " << v.g << " " << v.b << '\n'; } -void PrintVector2 (const TVector2d& v) { +void PrintVector2(const TVector2d& v) { cout.precision(3); cout << v.x << " " << v.y << '\n'; } -void PrintVector (const TVector3d& v) { +void PrintVector(const TVector3d& v) { cout.precision(5); cout << v.x << " " << v.y << " " << v.z << '\n'; } template -void PrintMatrix (const TMatrix& mat) { +void PrintMatrix(const TMatrix& mat) { cout << '\n'; cout.precision(3); for (int i=0; i& mat) { template void PrintMatrix<4, 4>(const TMatrix<4, 4>& mat); template void PrintMatrix<3, 3>(const TMatrix<3, 3>& mat); -void PrintQuaternion (const TQuaternion& q) { +void PrintQuaternion(const TQuaternion& q) { cout.precision(5); cout << "Quaternion: " << q.x << " " << q.y << " " << q.z << " " << q.w << '\n'; } @@ -124,13 +124,13 @@ void PrintQuaternion (const TQuaternion& q) { // message utils // -------------------------------------------------------------------- -static CSPList msg_list (100); +static CSPList msg_list(100); -void SaveMessages () { - msg_list.Save (param.config_dir, "messages"); +void SaveMessages() { + msg_list.Save(param.config_dir, "messages"); } -void Message (const char *msg, const char *desc) { +void Message(const char *msg, const char *desc) { if (*msg == 0 && *desc == 0) { cout << '\n'; return; @@ -139,55 +139,51 @@ void Message (const char *msg, const char *desc) { string aa = msg; string bb = desc; cout << aa << " " << bb << '\n'; - msg_list.Add (aa + bb); + msg_list.Add(aa + bb); } -void Message (const char *msg) { +void Message(const char *msg) { cout << msg << '\n'; if (*msg != 0) - msg_list.Add (msg); + msg_list.Add(msg); } -void Message (const string& a, const string& b) { +void Message(const string& a, const string& b) { cout << a << ' ' << b << endl; - msg_list.Add (a + b); + msg_list.Add(a + b); } -void Message (const string& msg) { +void Message(const string& msg) { cout << msg << endl; - msg_list.Add (msg); + msg_list.Add(msg); } // -------------------------------------------------------------------- // file utils // -------------------------------------------------------------------- -bool FileExists (const char *filename) { +bool FileExists(const string& filename) { struct stat stat_info; - if (stat (filename, &stat_info) != 0) { - if (errno != ENOENT) Message ("couldn't stat ", filename); + if (stat(filename.c_str(), &stat_info) != 0) { + if (errno != ENOENT) Message("couldn't stat ", filename); return false; } else return true; } -bool FileExists (const string& filename) { - return FileExists (filename.c_str()); -} - -bool FileExists (const string& dir, const string& filename) { - return FileExists (dir + SEP + filename); +bool FileExists(const string& dir, const string& filename) { + return FileExists(dir + SEP + filename); } #ifndef OS_WIN32_MSC -bool DirExists (const char *dirname) { +bool DirExists(const char *dirname) { DIR *xdir; - if ((xdir = opendir (dirname)) == 0) + if ((xdir = opendir(dirname)) == 0) return ((errno != ENOENT) && (errno != ENOTDIR)); - if (closedir (xdir) != 0) Message ("Couldn't close directory", dirname); + if (closedir(xdir) != 0) Message("Couldn't close directory", dirname); return true; } #else -bool DirExists (const char *dirname) { +bool DirExists(const char *dirname) { DWORD typ = GetFileAttributesA(dirname); if (typ == INVALID_FILE_ATTRIBUTES) return false; // Doesn't exist @@ -200,23 +196,23 @@ bool DirExists (const char *dirname) { // date and time // -------------------------------------------------------------------- -void GetTimeComponents (double time, int *min, int *sec, int *hundr) { - *min = (int) (time / 60); +void GetTimeComponents(double time, int *min, int *sec, int *hundr) { + *min = (int)(time / 60); *sec = ((int) time) % 60; - *hundr = ((int) (time * 100 + 0.5) ) % 100; + *hundr = ((int)(time * 100 + 0.5)) % 100; } -string GetTimeString () { +string GetTimeString() { time_t rawtime; struct tm * timeinfo; - time (&rawtime); - timeinfo = localtime (&rawtime); + time(&rawtime); + timeinfo = localtime(&rawtime); // line = Int_StrN (timeinfo->tm_year-100); - string line = Int_StrN (timeinfo->tm_mon + 1); - line += "_" + Int_StrN (timeinfo->tm_mday); - line += "_" + Int_StrN (timeinfo->tm_hour); - line += Int_StrN (timeinfo->tm_min); - line += Int_StrN (timeinfo->tm_sec); + string line = Int_StrN(timeinfo->tm_mon + 1); + line += "_" + Int_StrN(timeinfo->tm_mday); + line += "_" + Int_StrN(timeinfo->tm_hour); + line += Int_StrN(timeinfo->tm_min); + line += Int_StrN(timeinfo->tm_sec); return line; } diff --git a/src/common.h b/src/common.h index aea1b36..2f3e9df 100644 --- a/src/common.h +++ b/src/common.h @@ -77,45 +77,44 @@ extern const TColor colSky; // -------------------------------------------------------------------- // some simple functions to print out values on the // terminal. Only used for development. -void PrintInt (const int val); -void PrintInt (const string& s, const int val); -void PrintStr (const char *val); -void PrintString (const string& s); -void PrintDouble (const double val); -void PrintVector (const TVector3d& v); -void PrintVector4 (const TVector4d& v); -void PrintColor (const TColor& c); -void PrintVector2 (const TVector2d& v); +void PrintInt(const int val); +void PrintInt(const string& s, const int val); +void PrintStr(const char *val); +void PrintString(const string& s); +void PrintDouble(const double val); +void PrintVector(const TVector3d& v); +void PrintVector4(const TVector4d& v); +void PrintColor(const TColor& c); +void PrintVector2(const TVector2d& v); template -void PrintMatrix (const TMatrix& mat); -void PrintQuaternion (const TQuaternion& q); +void PrintMatrix(const TMatrix& mat); +void PrintQuaternion(const TQuaternion& q); // -------------------------------------------------------------------- // file utils // -------------------------------------------------------------------- -bool FileExists (const char *filename); -bool FileExists (const string& filename); -bool FileExists (const string& dir, const string& filename); -bool DirExists (const char *dirname); +bool FileExists(const string& filename); +bool FileExists(const string& dir, const string& filename); +bool DirExists(const char *dirname); // -------------------------------------------------------------------- // message utils // -------------------------------------------------------------------- -void Message (const char *msg, const char *desc); -void Message (const char *msg); -void Message (const string& a, const string& b); -void Message (const string& a); -void SaveMessages (); +void Message(const char *msg, const char *desc); +void Message(const char *msg); +void Message(const string& a, const string& b); +void Message(const string& a); +void SaveMessages(); // -------------------------------------------------------------------- // date and time // -------------------------------------------------------------------- -void GetTimeComponents (double time, int *min, int *sec, int *hundr); -string GetTimeString (); +void GetTimeComponents(double time, int *min, int *sec, int *hundr); +string GetTimeString(); #endif diff --git a/src/config_screen.cpp b/src/config_screen.cpp index f0b0f36..613a30f 100644 --- a/src/config_screen.cpp +++ b/src/config_screen.cpp @@ -48,9 +48,6 @@ Then edit the below functions: #include "gui.h" #include "textures.h" #include "font.h" -#include "translation.h" -#include "course.h" -#include "game_ctrl.h" #include "winsys.h" CGameConfig GameConfig; @@ -64,8 +61,7 @@ static TUpDown* sound_vol; static TUpDown* detail_level; static TWidget* textbuttons[2]; - -void SetConfig () { +void SetConfig() { if (mus_vol->GetValue() != param.music_volume || sound_vol->GetValue() != param.sound_volume || language->GetValue() != param.language || @@ -89,20 +85,20 @@ void SetConfig () { // the followind config params don't require a new VideoMode // they only must stored in the param structure (and saved) param.music_volume = mus_vol->GetValue(); - Music.SetVolume (param.music_volume); + Music.SetVolume(param.music_volume); param.sound_volume = sound_vol->GetValue(); param.perf_level = detail_level->GetValue(); - Winsys.SetFonttype (); + FT.SetFontFromSettings(); if (param.language != language->GetValue()) { param.language = language->GetValue(); - Trans.LoadTranslations (param.language); + Trans.LoadTranslations(param.language); } - SaveConfigFile (); + SaveConfigFile(); } State::manager.RequestEnterState(*State::manager.PreviousState()); } -void CGameConfig::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CGameConfig::Keyb(unsigned int key, bool special, bool release, int x, int y) { if (release) return; if (key != SDLK_UP && key != SDLK_DOWN) @@ -112,13 +108,13 @@ void CGameConfig::Keyb (unsigned int key, bool special, bool release, int x, int State::manager.RequestQuit(); break; case SDLK_ESCAPE: - State::manager.RequestEnterState (*State::manager.PreviousState()); + State::manager.RequestEnterState(*State::manager.PreviousState()); break; case SDLK_RETURN: if (textbuttons[0]->focussed()) - State::manager.RequestEnterState (*State::manager.PreviousState()); + State::manager.RequestEnterState(*State::manager.PreviousState()); else if (textbuttons[1]->focussed()) - SetConfig (); + SetConfig(); break; case SDLK_UP: DecreaseFocus(); @@ -129,21 +125,21 @@ void CGameConfig::Keyb (unsigned int key, bool special, bool release, int x, int } } -void CGameConfig::Mouse (int button, int state, int x, int y) { +void CGameConfig::Mouse(int button, int state, int x, int y) { if (state == 1) { TWidget* focussed = ClickGUI(x, y); if (focussed == textbuttons[0]) - State::manager.RequestEnterState (*State::manager.PreviousState()); + State::manager.RequestEnterState(*State::manager.PreviousState()); else if (focussed == textbuttons[1]) - SetConfig (); + SetConfig(); } } -void CGameConfig::Motion (int x, int y) { +void CGameConfig::Motion(int x, int y) { MouseMoveGUI(x, y); - if (param.ui_snow) push_ui_snow (cursor_pos); + if (param.ui_snow) push_ui_snow(cursor_pos); } // ------------------ Init -------------------------------------------- @@ -152,20 +148,20 @@ static TArea area; static int dd; void CGameConfig::Enter() { - Winsys.ShowCursor (!param.ice_cursor); - Winsys.KeyRepeat (true); + Winsys.ShowCursor(!param.ice_cursor); + Winsys.KeyRepeat(true); - for (int i=0; ichecked = param.fullscreen; resolution = AddUpDown(rightpos, area.top+dd*1, 0, NUM_RESOLUTIONS-1, (int)param.res_type); @@ -174,90 +170,88 @@ void CGameConfig::Enter() { detail_level = AddUpDown(rightpos, area.top+dd*4, 1, 4, param.perf_level); language = AddUpDown(rightpos, area.top+dd*5, 0, (int)Trans.languages.size() - 1, (int)param.language); - int siz = FT.AutoSizeN (5); - textbuttons[0] = AddTextButton (Trans.Text(28), area.left+50, AutoYPosN (80), siz); - double len = FT.GetTextWidth (Trans.Text(8)); - textbuttons[1] = AddTextButton (Trans.Text(15), area.right-len-50, AutoYPosN (80), siz); + int siz = FT.AutoSizeN(5); + textbuttons[0] = AddTextButton(Trans.Text(28), area.left+50, AutoYPosN(80), siz); + double len = FT.GetTextWidth(Trans.Text(8)); + textbuttons[1] = AddTextButton(Trans.Text(15), area.right-len-50, AutoYPosN(80), siz); - Music.Play (param.config_music, -1); + Music.Play(param.config_music, -1); } -void CGameConfig::Loop (double time_step) { +void CGameConfig::Loop(double time_step) { int ww = Winsys.resolution.width; int hh = Winsys.resolution.height; - Music.Update (); + Music.Update(); - check_gl_error(); - Music.Update (); ScopedRenderMode rm(GUI); - ClearRenderContext (); - SetupGuiDisplay (); + ClearRenderContext(); + SetupGuiDisplay(); if (param.ui_snow) { - update_ui_snow (time_step); + update_ui_snow(time_step); draw_ui_snow(); } - Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), 1.0); - Tex.Draw (BOTTOM_LEFT, 0, hh-256, 1); - Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); - Tex.Draw (TOP_LEFT, 0, 0, 1); - Tex.Draw (TOP_RIGHT, ww-256, 0, 1); + Tex.Draw(T_TITLE_SMALL, CENTER, AutoYPosN(5), 1.0); + Tex.Draw(BOTTOM_LEFT, 0, hh-256, 1); + Tex.Draw(BOTTOM_RIGHT, ww-256, hh-256, 1); + Tex.Draw(TOP_LEFT, 0, 0, 1); + Tex.Draw(TOP_RIGHT, ww-256, 0, 1); // DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top, // 0, colMBackgr, colBlack, 0.2); - FT.AutoSizeN (4); + FT.AutoSizeN(4); - if (resolution->focussed()) FT.SetColor (colDYell); - else FT.SetColor (colWhite); - FT.DrawString (area.left, area.top + dd, Trans.Text(32)); - if (mus_vol->focussed()) FT.SetColor (colDYell); - else FT.SetColor (colWhite); - FT.DrawString (area.left, area.top + dd*2, Trans.Text(33)); - if (sound_vol->focussed()) FT.SetColor (colDYell); - else FT.SetColor (colWhite); - FT.DrawString (area.left, area.top + dd*3, Trans.Text(34)); - if (detail_level->focussed()) FT.SetColor (colDYell); - else FT.SetColor (colWhite); - FT.DrawString (area.left, area.top + dd*4, Trans.Text(36)); - if (language->focussed()) FT.SetColor (colDYell); - else FT.SetColor (colWhite); - FT.DrawString (area.left, area.top + dd*5, Trans.Text(35)); + if (resolution->focussed()) FT.SetColor(colDYell); + else FT.SetColor(colWhite); + FT.DrawString(area.left, area.top + dd, Trans.Text(32)); + if (mus_vol->focussed()) FT.SetColor(colDYell); + else FT.SetColor(colWhite); + FT.DrawString(area.left, area.top + dd*2, Trans.Text(33)); + if (sound_vol->focussed()) FT.SetColor(colDYell); + else FT.SetColor(colWhite); + FT.DrawString(area.left, area.top + dd*3, Trans.Text(34)); + if (detail_level->focussed()) FT.SetColor(colDYell); + else FT.SetColor(colWhite); + FT.DrawString(area.left, area.top + dd*4, Trans.Text(36)); + if (language->focussed()) FT.SetColor(colDYell); + else FT.SetColor(colWhite); + FT.DrawString(area.left, area.top + dd*5, Trans.Text(35)); - FT.SetColor (colWhite); - FT.DrawString (area.left+240, area.top + dd, res_names[resolution->GetValue()]); - FT.DrawString (area.left+240, area.top + dd*2, Int_StrN (mus_vol->GetValue())); - FT.DrawString (area.left+240, area.top + dd*3, Int_StrN (sound_vol->GetValue())); - FT.DrawString (area.left+240, area.top + dd*4, Int_StrN (detail_level->GetValue())); - FT.DrawString (area.left+240, area.top + dd*5, Trans.languages[language->GetValue()].language); + FT.SetColor(colWhite); + FT.DrawString(area.left+240, area.top + dd, res_names[resolution->GetValue()]); + FT.DrawString(area.left+240, area.top + dd*2, Int_StrN(mus_vol->GetValue())); + FT.DrawString(area.left+240, area.top + dd*3, Int_StrN(sound_vol->GetValue())); + FT.DrawString(area.left+240, area.top + dd*4, Int_StrN(detail_level->GetValue())); + FT.DrawString(area.left+240, area.top + dd*5, Trans.languages[language->GetValue()].language); #if defined (_WIN32) if (fullscreen->checked != param.fullscreen) { - FT.SetColor (colDYell); - FT.AutoSizeN (4); - FT.DrawString (CENTER, AutoYPosN (68), Trans.Text(84)); - FT.DrawString (CENTER, AutoYPosN (72), Trans.Text(85)); + FT.SetColor(colDYell); + FT.AutoSizeN(4); + FT.DrawString(CENTER, AutoYPosN(68), Trans.Text(84)); + FT.DrawString(CENTER, AutoYPosN(72), Trans.Text(85)); } else { - FT.SetColor (colLGrey); - FT.AutoSizeN (3); - FT.DrawString (CENTER, AutoYPosN (68), Trans.Text(41)); - FT.DrawString (CENTER, AutoYPosN (72), Trans.Text(42)); + FT.SetColor(colLGrey); + FT.AutoSizeN(3); + FT.DrawString(CENTER, AutoYPosN(68), Trans.Text(41)); + FT.DrawString(CENTER, AutoYPosN(72), Trans.Text(42)); } #else - FT.SetColor (colWhite); - FT.AutoSizeN (3); - FT.DrawString (CENTER, AutoYPosN (68), Trans.Text(41)); - FT.DrawString (CENTER, AutoYPosN (72), Trans.Text(42)); + FT.SetColor(colWhite); + FT.AutoSizeN(3); + FT.DrawString(CENTER, AutoYPosN(68), Trans.Text(41)); + FT.DrawString(CENTER, AutoYPosN(72), Trans.Text(42)); #endif DrawGUI(); - Reshape (ww, hh); - Winsys.SwapBuffers (); + Reshape(ww, hh); + Winsys.SwapBuffers(); } void CGameConfig::Exit() { - Winsys.KeyRepeat (false); + Winsys.KeyRepeat(false); } diff --git a/src/course.cpp b/src/course.cpp index e9384b9..9483e77 100644 --- a/src/course.cpp +++ b/src/course.cpp @@ -37,7 +37,7 @@ GNU General Public License for more details. CCourse Course; -CCourse::CCourse () { +CCourse::CCourse() { terrain = NULL; elevation = NULL; nmls = NULL; @@ -48,12 +48,12 @@ CCourse::CCourse () { } CCourse::~CCourse() { - FreeCourseList (); - ResetCourse (); + FreeCourseList(); + ResetCourse(); } -double CCourse::GetBaseHeight (double distance) const { - double slope = tan (ANGLES_TO_RADIANS (curr_course->angle)); +double CCourse::GetBaseHeight(double distance) const { + double slope = tan(ANGLES_TO_RADIANS(curr_course->angle)); double base_height; base_height = -slope * distance - @@ -61,16 +61,16 @@ double CCourse::GetBaseHeight (double distance) const { return base_height; } -double CCourse::GetMaxHeight (double distance) const { - return GetBaseHeight (distance) + curr_course->scale; +double CCourse::GetMaxHeight(double distance) const { + return GetBaseHeight(distance) + curr_course->scale; } -void CCourse::GetDivisions (int *x, int *y) const { +void CCourse::GetDivisions(int *x, int *y) const { *x = nx; *y = ny; } -const TPolyhedron& CCourse::GetPoly (size_t type) const { +const TPolyhedron& CCourse::GetPoly(size_t type) const { return PolyArr[ObjTypes[type].poly]; } @@ -79,17 +79,17 @@ TCourse* CCourse::GetCourse(const string& dir) { } size_t CCourse::GetCourseIdx(const TCourse* course) const { - size_t idx = (course - &CourseList[0]) / sizeof(TCourse); + size_t idx = (course - &CourseList[0]); if (idx >= CourseList.size()) return -1; return idx; } -void CCourse::CalcNormals () { +void CCourse::CalcNormals() { for (int y=0; y 0 && y > 0) { @@ -97,16 +97,16 @@ void CCourse::CalcNormals () { TVector3d p2 = NMLPOINT(x-1,y-1); TVector3d v1 = p1 - p0; TVector3d v2 = p2 - p0; - TVector3d n = CrossProduct (v2, v1); + TVector3d n = CrossProduct(v2, v1); n.Norm(); nml += n; - p1 = NMLPOINT (x-1, y-1); - p2 = NMLPOINT (x-1, y); + p1 = NMLPOINT(x-1, y-1); + p2 = NMLPOINT(x-1, y); v1 = p1 - p0; v2 = p2 - p0; - n = CrossProduct (v2, v1); + n = CrossProduct(v2, v1); n.Norm(); nml += n; @@ -116,7 +116,7 @@ void CCourse::CalcNormals () { TVector3d p2 = NMLPOINT(x-1,y+1); TVector3d v1 = p1 - p0; TVector3d v2 = p2 - p0; - TVector3d n = CrossProduct (v2, v1); + TVector3d n = CrossProduct(v2, v1); n.Norm(); nml += n; @@ -125,7 +125,7 @@ void CCourse::CalcNormals () { p2 = NMLPOINT(x ,y+1); v1 = p1 - p0; v2 = p2 - p0; - n = CrossProduct (v2, v1); + n = CrossProduct(v2, v1); n.Norm(); nml += n; @@ -135,7 +135,7 @@ void CCourse::CalcNormals () { TVector3d p2 = NMLPOINT(x+1,y-1); TVector3d v1 = p1 - p0; TVector3d v2 = p2 - p0; - TVector3d n = CrossProduct (v2, v1); + TVector3d n = CrossProduct(v2, v1); n.Norm(); nml += n; @@ -144,7 +144,7 @@ void CCourse::CalcNormals () { p2 = NMLPOINT(x ,y-1); v1 = p1 - p0; v2 = p2 - p0; - n = CrossProduct (v2, v1); + n = CrossProduct(v2, v1); n.Norm(); nml += n; @@ -154,7 +154,7 @@ void CCourse::CalcNormals () { TVector3d p2 = NMLPOINT(x+1,y+1); TVector3d v1 = p1 - p0; TVector3d v2 = p2 - p0; - TVector3d n = CrossProduct (v1, v2); + TVector3d n = CrossProduct(v1, v2); n.Norm(); nml += n; @@ -163,7 +163,7 @@ void CCourse::CalcNormals () { p2 = NMLPOINT(x ,y+1); v1 = p1 - p0; v2 = p2 - p0; - n = CrossProduct (v1, v2); + n = CrossProduct(v1, v2); n.Norm(); nml += n; @@ -174,7 +174,7 @@ void CCourse::CalcNormals () { TVector3d p2 = NMLPOINT(x-1,y); TVector3d v1 = p1 - p0; TVector3d v2 = p2 - p0; - TVector3d n = CrossProduct (v2, v1); + TVector3d n = CrossProduct(v2, v1); n.Norm(); nml += n; @@ -184,7 +184,7 @@ void CCourse::CalcNormals () { TVector3d p2 = NMLPOINT(x ,y+1); TVector3d v1 = p1 - p0; TVector3d v2 = p2 - p0; - TVector3d n = CrossProduct (v2, v1); + TVector3d n = CrossProduct(v2, v1); n.Norm(); nml += n; @@ -194,7 +194,7 @@ void CCourse::CalcNormals () { TVector3d p2 = NMLPOINT(x ,y-1); TVector3d v1 = p1 - p0; TVector3d v2 = p2 - p0; - TVector3d n = CrossProduct (v2, v1); + TVector3d n = CrossProduct(v2, v1); n.Norm(); nml += n; @@ -204,7 +204,7 @@ void CCourse::CalcNormals () { TVector3d p2 = NMLPOINT(x ,y+1); TVector3d v1 = p1 - p0; TVector3d v2 = p2 - p0; - TVector3d n = CrossProduct (v1, v2); + TVector3d n = CrossProduct(v1, v2); n.Norm(); nml += n; @@ -218,15 +218,15 @@ void CCourse::CalcNormals () { } } -void CCourse::MakeCourseNormals () { +void CCourse::MakeCourseNormals() { if (nmls != NULL) delete[] nmls; try { nmls = new TVector3d[nx * ny]; } catch (...) { nmls = NULL; - Message ("Allocation failed in MakeCourseNormals"); + Message("Allocation failed in MakeCourseNormals"); } - CalcNormals (); + CalcNormals(); } // -------------------------------------------------------------------- @@ -261,7 +261,7 @@ void CCourse::FillGlArrays() { } } -void CCourse::MakeStandardPolyhedrons () { +void CCourse::MakeStandardPolyhedrons() { PolyArr.resize(2); // polyhedron "none" @@ -312,14 +312,14 @@ void CCourse::MakeStandardPolyhedrons () { PolyArr[1].polygons[7].vertices[2] = 3; } -void CCourse::FreeTerrainTextures () { +void CCourse::FreeTerrainTextures() { for (size_t i=0; iangle)); + double slope = tan(ANGLES_TO_RADIANS(curr_course->angle)); int pad = 0; for (int y=0; ysize.x; double zz = -(ny - z) / (double)(ny - 1.0) * curr_course->size.y; - string name = SPStrN (line, "name"); + string name = SPStrN(line, "name"); size_t type = ObjectIndex[name]; if (ObjTypes[type].texture == NULL && ObjTypes[type].drawable) { string terrpath = param.obj_dir + SEP + ObjTypes[type].textureFile; @@ -401,7 +402,7 @@ void CCourse::LoadItemList () { // -------------------- LoadObjectMap --------------------------------- -static int GetObject (unsigned char pixel[]) { +static int GetObject(unsigned char pixel[]) { int r = pixel[0]; int g = pixel[1]; int b = pixel[2]; @@ -428,32 +429,33 @@ const double sizefact[6] = {0.5, 0.5, 0.7, 1.0, 1.4, 2.0}; const double varfact[6] = {1.0, 1.0, 1.22, 1.41, 1.73, 2.0}; const double diamfact = 1.4; -static void CalcRandomTrees (double baseheight, double basediam, double &height, double &diam) { +static void CalcRandomTrees(double baseheight, double basediam, double &height, double &diam) { double hhh = baseheight * sizefact[g_game.treesize]; double minsiz = hhh / varfact[g_game.treevar]; double maxsiz = hhh * varfact[g_game.treevar]; - height = XRandom (minsiz, maxsiz); - diam = XRandom (height/diamfact, height); + height = XRandom(minsiz, maxsiz); + diam = XRandom(height/diamfact, height); } -bool CCourse::LoadAndConvertObjectMap () { +bool CCourse::LoadAndConvertObjectMap() { CImage treeImg; - if (!treeImg.LoadPng (CourseDir.c_str(), "trees.png", true)) { Message ("unable to open trees.png"); + if (!treeImg.LoadPng(CourseDir.c_str(), "trees.png", true)) { + Message("unable to open trees.png"); return false; } int pad = 0; int cnt = 0; double height, diam; - CSPList savelist (10000); + CSPList savelist(10000); CollArr.clear(); NocollArr.clear(); for (int y=0; y= 0) { cnt++; double xx = (nx - x) / (double)(nx - 1.0) * curr_course->size.x; @@ -467,13 +469,13 @@ bool CCourse::LoadAndConvertObjectMap () { // set random height and diam - see constants above switch (type) { case 5: - CalcRandomTrees (2.5, 2.5, height, diam); + CalcRandomTrees(2.5, 2.5, height, diam); break; case 6: - CalcRandomTrees (3, 3, height, diam); + CalcRandomTrees(3, 3, height, diam); break; case 7: - CalcRandomTrees (1.2, 1.2, height, diam); + CalcRandomTrees(1.2, 1.2, height, diam); break; case 2: @@ -495,17 +497,17 @@ bool CCourse::LoadAndConvertObjectMap () { string line = "*[name]"; line += ObjTypes[type].name; - SPSetIntN (line, "x", x); - SPSetIntN (line, "z", y); - SPSetFloatN (line, "height", height, 1); - SPSetFloatN (line, "diam", diam, 1); - savelist.Add (line); + SPSetIntN(line, "x", x); + SPSetIntN(line, "z", y); + SPSetFloatN(line, "height", height, 1); + SPSetFloatN(line, "diam", diam, 1); + savelist.Add(line); } } pad += (nx * treeImg.depth) % 4; } string itemfile = CourseDir + SEP "items.lst"; - savelist.Save (itemfile); // Convert trees.png to items.lst + savelist.Save(itemfile); // Convert trees.png to items.lst return true; } @@ -513,11 +515,11 @@ bool CCourse::LoadAndConvertObjectMap () { // LoadObjectTypes // -------------------------------------------------------------------- -bool CCourse::LoadObjectTypes () { - CSPList list (MAX_OBJECT_TYPES+10); +bool CCourse::LoadObjectTypes() { + CSPList list(MAX_OBJECT_TYPES+10); - if (!list.Load (param.obj_dir, "object_types.lst")) { - Message ("could not load object types"); + if (!list.Load(param.obj_dir, "object_types.lst")) { + Message("could not load object types"); return false; } @@ -525,22 +527,22 @@ bool CCourse::LoadObjectTypes () { for (size_t i=0; i desclist = FT.MakeLineList (desc.c_str(), 335 * Winsys.scale - 16.0); + string desc = SPStrN(line1, "desc"); + FT.AutoSizeN(2); + vector desclist = FT.MakeLineList(desc.c_str(), 335 * Winsys.scale - 16.0); size_t cnt = min(desclist.size(), MAX_DESCRIPTION_LINES); CourseList[i].num_lines = cnt; for (size_t ll=0; llLoadMipmap(previewfile, false)) { - Message ("couldn't load previewfile"); + Message("couldn't load previewfile"); // texid = Tex.TexID (NO_PREVIEW); } // params string paramfile = coursepath + SEP "course.dim"; - if (!paramlist.Load (paramfile)) { - Message ("could not load course.dim"); + if (!paramlist.Load(paramfile)) { + Message("could not load course.dim"); } - const string& line2 = paramlist.Line (0); - CourseList[i].author = SPStrN (line2, "author", "unknown"); - CourseList[i].size.x = SPFloatN (line2, "width", 100); - CourseList[i].size.y = SPFloatN (line2, "length", 1000); - CourseList[i].play_size.x = SPFloatN (line2, "play_width", 90); - CourseList[i].play_size.y = SPFloatN (line2, "play_length", 900); - CourseList[i].angle = SPFloatN (line2, "angle", 10); - CourseList[i].scale = SPFloatN (line2, "scale", 10); - CourseList[i].start.x = SPFloatN (line2, "startx", 50); - CourseList[i].start.y = SPFloatN (line2, "starty", 5); - CourseList[i].env = Env.GetEnvIdx (SPStrN (line2, "env", "etr")); - CourseList[i].music_theme = Music.GetThemeIdx (SPStrN (line2, "theme", "normal")); - CourseList[i].use_keyframe = SPBoolN (line2, "use_keyframe", false); - CourseList[i].finish_brake = SPFloatN (line2, "finish_brake", 20); - paramlist.Clear (); // the list is used several times + const string& line2 = paramlist.Line(0); + CourseList[i].author = SPStrN(line2, "author", "unknown"); + CourseList[i].size.x = SPFloatN(line2, "width", 100); + CourseList[i].size.y = SPFloatN(line2, "length", 1000); + CourseList[i].play_size.x = SPFloatN(line2, "play_width", 90); + CourseList[i].play_size.y = SPFloatN(line2, "play_length", 900); + CourseList[i].angle = SPFloatN(line2, "angle", 10); + CourseList[i].scale = SPFloatN(line2, "scale", 10); + CourseList[i].start.x = SPFloatN(line2, "startx", 50); + CourseList[i].start.y = SPFloatN(line2, "starty", 5); + CourseList[i].env = Env.GetEnvIdx(SPStrN(line2, "env", "etr")); + CourseList[i].music_theme = Music.GetThemeIdx(SPStrN(line2, "theme", "normal")); + CourseList[i].use_keyframe = SPBoolN(line2, "use_keyframe", false); + CourseList[i].finish_brake = SPFloatN(line2, "finish_brake", 20); + paramlist.Clear(); // the list is used several times } } - list.MakeIndex (CourseIndex, "dir"); + list.MakeIndex(CourseIndex, "dir"); return true; } -void CCourse::FreeCourseList () { +void CCourse::FreeCourseList() { for (size_t i=0; idir; @@ -738,33 +741,33 @@ bool CCourse::LoadCourse (TCourse* course) { g_game.use_keyframe = course->use_keyframe; g_game.finish_brake = course->finish_brake; - if (!LoadElevMap ()) { - Message ("could not load course elev map"); + if (!LoadElevMap()) { + Message("could not load course elev map"); return false; } - MakeCourseNormals (); - FillGlArrays (); + MakeCourseNormals(); + FillGlArrays(); - if (!LoadTerrainMap ()) { - Message ("could not load course terrain map"); + if (!LoadTerrainMap()) { + Message("could not load course terrain map"); return false; } // ................................................................ string itemfile = CourseDir + SEP "items.lst"; - bool itemsexists = FileExists (itemfile); + bool itemsexists = FileExists(itemfile); const CControl *ctrl = g_game.player->ctrl; if (itemsexists && !g_game.force_treemap) - LoadItemList (); + LoadItemList(); else - LoadAndConvertObjectMap (); + LoadAndConvertObjectMap(); g_game.force_treemap = false; // ................................................................ - init_track_marks (); - InitQuadtree ( + init_track_marks(); + InitQuadtree( elevation, nx, ny, curr_course->size.x / (nx - 1.0), -curr_course->size.y / (ny - 1.0), @@ -773,13 +776,13 @@ bool CCourse::LoadCourse (TCourse* course) { } if (g_game.mirrorred != mirrored) { - MirrorCourse (); + MirrorCourse(); mirrored = g_game.mirrorred; } return true; } -size_t CCourse::GetEnv () const { +size_t CCourse::GetEnv() const { return curr_course->env; } @@ -787,7 +790,7 @@ size_t CCourse::GetEnv () const { // mirror course // -------------------------------------------------------------------- -void CCourse::MirrorCourseData () { +void CCourse::MirrorCourseData() { for (int y=0; ysize.x - CollArr[i].pt.x; - CollArr[i].pt.y = FindYCoord (CollArr[i].pt.x, CollArr[i].pt.z); + CollArr[i].pt.y = FindYCoord(CollArr[i].pt.x, CollArr[i].pt.z); } for (size_t i=0; isize.x - NocollArr[i].pt.x; - NocollArr[i].pt.y = FindYCoord (NocollArr[i].pt.x, NocollArr[i].pt.z); + NocollArr[i].pt.y = FindYCoord(NocollArr[i].pt.x, NocollArr[i].pt.z); } FillGlArrays(); - ResetQuadtree (); + ResetQuadtree(); if (nx > 0 && ny > 0) { const CControl *ctrl = g_game.player->ctrl; - InitQuadtree (elevation, nx, ny, curr_course->size.x/(nx-1), - - curr_course->size.y/(ny-1), ctrl->viewpos, param.course_detail_level); + InitQuadtree(elevation, nx, ny, curr_course->size.x/(nx-1), + - curr_course->size.y/(ny-1), ctrl->viewpos, param.course_detail_level); } start_pt.x = curr_course->size.x - start_pt.x; } -void CCourse::MirrorCourse () { - MirrorCourseData (); - init_track_marks (); +void CCourse::MirrorCourse() { + MirrorCourseData(); + init_track_marks(); } // ******************************************************************** @@ -840,7 +843,7 @@ void CCourse::MirrorCourse () { void CCourse::GetIndicesForPoint(double x, double z, int *x0, int *y0, int *x1, int *y1) const { double xidx = x / curr_course->size.x * ((double) nx - 1.); - double yidx = -z / curr_course->size.y * ((double) ny - 1.); + double yidx = -z / curr_course->size.y * ((double) ny - 1.); if (xidx < 0) xidx = 0; else if (xidx > nx-1) xidx = nx-1; @@ -854,12 +857,12 @@ void CCourse::GetIndicesForPoint(double x, double z, int *x0, int *y0, int *x1, *y1 = (int)(yidx + 0.9999); // ceil(yidx) if (*x0 == *x1) { - if (*x1 < nx - 1) (*x1)++; + if (*x1 < nx - 1)(*x1)++; else (*x0)--; } if (*y0 == *y1) { - if (*y1 < ny - 1) (*y1)++; + if (*y1 < ny - 1)(*y1)++; else (*y0)--; } } @@ -870,7 +873,7 @@ void CCourse::FindBarycentricCoords(double x, double z, TVector2i *idx0, int x0, x1, y0, y1; double dx, ex, dz, ez, qx, qz, invdet; - GetIndicesForPoint (x, z, &x0, &y0, &x1, &y1); + GetIndicesForPoint(x, z, &x0, &y0, &x1, &y1); xidx = x / curr_course->size.x * ((double) nx - 1.); yidx = -z / curr_course->size.y * ((double) ny - 1.); @@ -911,23 +914,23 @@ void CCourse::FindBarycentricCoords(double x, double z, TVector2i *idx0, #define COURSE_VERTX(_x, _y) TVector3d ( (double)(_x)/(nx-1.)*curr_course->size.x, \ ELEV((_x),(_y)), -(double)(_y)/(ny-1.)*curr_course->size.y ) -TVector3d CCourse::FindCourseNormal (double x, double z) const { +TVector3d CCourse::FindCourseNormal(double x, double z) const { double *elevation = Course.elevation; int x0, x1, y0, y1; - GetIndicesForPoint (x, z, &x0, &y0, &x1, &y1); + GetIndicesForPoint(x, z, &x0, &y0, &x1, &y1); TVector2i idx0, idx1, idx2; double u, v; - FindBarycentricCoords (x, z, &idx0, &idx1, &idx2, &u, &v); + FindBarycentricCoords(x, z, &idx0, &idx1, &idx2, &u, &v); const TVector3d& n0 = Course.nmls[ idx0.x + nx * idx0.y ]; const TVector3d& n1 = Course.nmls[ idx1.x + nx * idx1.y ]; const TVector3d& n2 = Course.nmls[ idx2.x + nx * idx2.y ]; - TVector3d p0 = COURSE_VERTX (idx0.x, idx0.y); - TVector3d p1 = COURSE_VERTX (idx1.x, idx1.y); - TVector3d p2 = COURSE_VERTX (idx2.x, idx2.y); + TVector3d p0 = COURSE_VERTX(idx0.x, idx0.y); + TVector3d p1 = COURSE_VERTX(idx1.x, idx1.y); + TVector3d p2 = COURSE_VERTX(idx2.x, idx2.y); TVector3d smooth_nml = u * n0 + v * n1 + @@ -936,8 +939,8 @@ TVector3d CCourse::FindCourseNormal (double x, double z) const { TVector3d tri_nml = CrossProduct(p1 - p0, p2 - p0); tri_nml.Norm(); - double min_bary = min (u, min (v, 1. - u - v)); - double interp_factor = min (min_bary / NORM_INTERPOL, 1.0); + double min_bary = min(u, min(v, 1. - u - v)); + double interp_factor = min(min_bary / NORM_INTERPOL, 1.0); TVector3d interp_nml = interp_factor * tri_nml + (1.-interp_factor) * smooth_nml; interp_nml.Norm(); @@ -945,7 +948,7 @@ TVector3d CCourse::FindCourseNormal (double x, double z) const { return interp_nml; } -double CCourse::FindYCoord (double x, double z) const { +double CCourse::FindYCoord(double x, double z) const { static double last_x, last_z, last_y; static bool cache_full = false; @@ -954,13 +957,13 @@ double CCourse::FindYCoord (double x, double z) const { TVector2i idx0, idx1, idx2; double u, v; - FindBarycentricCoords (x, z, &idx0, &idx1, &idx2, &u, &v); + FindBarycentricCoords(x, z, &idx0, &idx1, &idx2, &u, &v); - TVector3d p0 = COURSE_VERTX (idx0.x, idx0.y); - TVector3d p1 = COURSE_VERTX (idx1.x, idx1.y); - TVector3d p2 = COURSE_VERTX (idx2.x, idx2.y); + TVector3d p0 = COURSE_VERTX(idx0.x, idx0.y); + TVector3d p1 = COURSE_VERTX(idx1.x, idx1.y); + TVector3d p2 = COURSE_VERTX(idx2.x, idx2.y); - double ycoord = u * p0.y + v * p1.y + (1. - u - v) * p2.y; + double ycoord = u * p0.y + v * p1.y + (1. - u - v) * p2.y; last_x = x; last_z = z; @@ -970,10 +973,10 @@ double CCourse::FindYCoord (double x, double z) const { return ycoord; } -void CCourse::GetSurfaceType (double x, double z, double weights[]) const { +void CCourse::GetSurfaceType(double x, double z, double weights[]) const { TVector2i idx0, idx1, idx2; double u, v; - FindBarycentricCoords (x, z, &idx0, &idx1, &idx2, &u, &v); + FindBarycentricCoords(x, z, &idx0, &idx1, &idx2, &u, &v); char *terrain = Course.terrain; for (size_t i=0; i CourseList; @@ -152,37 +155,37 @@ public: TVector3d *nmls; GLubyte *vnc_array; - void ResetCourse (); - TCourse* GetCourse (const string& dir); + void ResetCourse(); + TCourse* GetCourse(const string& dir); size_t GetCourseIdx(const TCourse* course) const; - bool LoadCourseList (); - void FreeCourseList (); + bool LoadCourseList(); + void FreeCourseList(); bool LoadCourse(TCourse* course); - bool LoadTerrainTypes (); - bool LoadObjectTypes (); - void MakeStandardPolyhedrons (); + bool LoadTerrainTypes(); + bool LoadObjectTypes(); + void MakeStandardPolyhedrons(); GLubyte* GetGLArrays() const { return vnc_array; } void FillGlArrays(); const TVector2d& GetDimensions() const { return curr_course->size; } const TVector2d& GetPlayDimensions() const { return curr_course->play_size; } - void GetDivisions (int *nx, int *ny) const; - double GetCourseAngle () const { return curr_course->angle; } - double GetBaseHeight (double distance) const; - double GetMaxHeight (double distance) const; - size_t GetEnv () const; - const TVector2d& GetStartPoint () const { return start_pt; } - const TPolyhedron& GetPoly (size_t type) const; - void MirrorCourse (); + void GetDivisions(int *nx, int *ny) const; + double GetCourseAngle() const { return curr_course->angle; } + double GetBaseHeight(double distance) const; + double GetMaxHeight(double distance) const; + size_t GetEnv() const; + const TVector2d& GetStartPoint() const { return start_pt; } + const TPolyhedron& GetPoly(size_t type) const; + void MirrorCourse(); - void GetIndicesForPoint (double x, double z, int *x0, int *y0, int *x1, int *y1) const; - void FindBarycentricCoords (double x, double z, - TVector2i *idx0, TVector2i *idx1, TVector2i *idx2, double *u, double *v) const; - TVector3d FindCourseNormal (double x, double z) const; - double FindYCoord (double x, double z) const; - void GetSurfaceType (double x, double z, double weights[]) const; - int GetTerrainIdx (double x, double z, double level) const; - TPlane GetLocalCoursePlane (TVector3d pt) const; + void GetIndicesForPoint(double x, double z, int *x0, int *y0, int *x1, int *y1) const; + void FindBarycentricCoords(double x, double z, + TVector2i *idx0, TVector2i *idx1, TVector2i *idx2, double *u, double *v) const; + TVector3d FindCourseNormal(double x, double z) const; + double FindYCoord(double x, double z) const; + void GetSurfaceType(double x, double z, double weights[]) const; + int GetTerrainIdx(double x, double z, double level) const; + TPlane GetLocalCoursePlane(TVector3d pt) const; }; extern CCourse Course; diff --git a/src/course_render.cpp b/src/course_render.cpp index 286d525..75a9b82 100644 --- a/src/course_render.cpp +++ b/src/course_render.cpp @@ -32,24 +32,24 @@ GNU General Public License for more details. #define TEX_SCALE 6 static const bool clip_course = true; -void setup_course_tex_gen () { +void setup_course_tex_gen() { static const GLfloat xplane[4] = {1.0 / TEX_SCALE, 0.0, 0.0, 0.0 }; static const GLfloat zplane[4] = {0.0, 0.0, 1.0 / TEX_SCALE, 0.0 }; - glTexGenfv (GL_S, GL_OBJECT_PLANE, xplane); - glTexGenfv (GL_T, GL_OBJECT_PLANE, zplane); + glTexGenfv(GL_S, GL_OBJECT_PLANE, xplane); + glTexGenfv(GL_T, GL_OBJECT_PLANE, zplane); } // -------------------------------------------------------------------- // render course // -------------------------------------------------------------------- -void RenderCourse () { +void RenderCourse() { ScopedRenderMode rm(COURSE); - setup_course_tex_gen (); - glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - set_material (colWhite, colBlack, 1.0); + setup_course_tex_gen(); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + set_material(colWhite, colBlack, 1.0); const CControl *ctrl = g_game.player->ctrl; - UpdateQuadtree (ctrl->viewpos, param.course_detail_level); - RenderQuadtree (); + UpdateQuadtree(ctrl->viewpos, param.course_detail_level); + RenderQuadtree(); } // -------------------------------------------------------------------- @@ -64,31 +64,28 @@ void DrawTrees() { double fwd_clip_limit = param.forward_clip_distance; double bwd_clip_limit = param.backward_clip_distance; - glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - set_material (colWhite, colBlack, 1.0); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + set_material(colWhite, colBlack, 1.0); // -------------- trees ------------------------ - TCollidable* treeLocs = &Course.CollArr[0]; - size_t numTrees = Course.CollArr.size(); - - for (size_t i = 0; i< numTrees; i++) { + for (size_t i = 0; i< Course.CollArr.size(); i++) { if (clip_course) { - if (ctrl->viewpos.z - treeLocs[i].pt.z > fwd_clip_limit) continue; - if (treeLocs[i].pt.z - ctrl->viewpos.z > bwd_clip_limit) continue; + if (ctrl->viewpos.z - Course.CollArr[i].pt.z > fwd_clip_limit) continue; + if (Course.CollArr[i].pt.z - ctrl->viewpos.z > bwd_clip_limit) continue; } - if (treeLocs[i].tree_type != tree_type) { - tree_type = treeLocs[i].tree_type; + if (Course.CollArr[i].tree_type != tree_type) { + tree_type = Course.CollArr[i].tree_type; object_types[tree_type].texture->Bind(); } glPushMatrix(); - glTranslate(treeLocs[i].pt); - if (param.perf_level > 1) glRotatef (1, 0, 1, 0); + glTranslate(Course.CollArr[i].pt); + if (param.perf_level > 1) glRotatef(1, 0, 1, 0); - float treeRadius = treeLocs[i].diam / 2.0; - float treeHeight = treeLocs[i].height; + float treeRadius = Course.CollArr[i].diam / 2.0; + float treeHeight = Course.CollArr[i].height; glNormal3i(0, 0, 1); static const GLshort tex[] = { @@ -127,32 +124,30 @@ void DrawTrees() { } // items ----------------------------- - TItem* itemLocs = &Course.NocollArr[0]; - size_t numItems = Course.NocollArr.size(); const TObjectType* item_type = NULL; - for (size_t i = 0; i< numItems; i++) { - if (itemLocs[i].collectable == 0 || itemLocs[i].type.drawable == false) continue; + for (size_t i = 0; i< Course.NocollArr.size(); i++) { + if (Course.NocollArr[i].collectable == 0 || Course.NocollArr[i].type.drawable == false) continue; if (clip_course) { - if (ctrl->viewpos.z - itemLocs[i].pt.z > fwd_clip_limit) continue; - if (itemLocs[i].pt.z - ctrl->viewpos.z > bwd_clip_limit) continue; + if (ctrl->viewpos.z - Course.NocollArr[i].pt.z > fwd_clip_limit) continue; + if (Course.NocollArr[i].pt.z - ctrl->viewpos.z > bwd_clip_limit) continue; } - if (&itemLocs[i].type != item_type) { - item_type = &itemLocs[i].type; + if (&Course.NocollArr[i].type != item_type) { + item_type = &Course.NocollArr[i].type; item_type->texture->Bind(); } glPushMatrix(); - glTranslate(itemLocs[i].pt); - double itemRadius = itemLocs[i].diam / 2; - double itemHeight = itemLocs[i].height; + glTranslate(Course.NocollArr[i].pt); + double itemRadius = Course.NocollArr[i].diam / 2; + double itemHeight = Course.NocollArr[i].height; TVector3d normal; if (item_type->use_normal) { normal = item_type->normal; } else { - normal = ctrl->viewpos - itemLocs[i].pt; + normal = ctrl->viewpos - Course.NocollArr[i].pt; normal.Norm(); } glNormal3(normal); diff --git a/src/course_render.h b/src/course_render.h index 0fb3257..ecc1489 100644 --- a/src/course_render.h +++ b/src/course_render.h @@ -20,9 +20,9 @@ GNU General Public License for more details. #include "bh.h" -void setup_course_tex_gen (); +void setup_course_tex_gen(); -void RenderCourse (); -void DrawTrees (); +void RenderCourse(); +void DrawTrees(); #endif diff --git a/src/credits.cpp b/src/credits.cpp index fed9445..a1d5f6c 100644 --- a/src/credits.cpp +++ b/src/credits.cpp @@ -39,30 +39,30 @@ CCredits Credits; static double y_offset = 0; static bool moving = true; -void CCredits::LoadCreditList () { +void CCredits::LoadCreditList() { CSPList list(MAX_CREDITS); - if (!list.Load (param.data_dir, "credits.lst")) { - Message ("could not load credits list"); + if (!list.Load(param.data_dir, "credits.lst")) { + Message("could not load credits list"); return; } for (size_t i=0; i0) credit.offs = CreditList.back().offs + (int)offset; else credit.offs = offset; - credit.col = SPIntN (line, "col", 0); - credit.size = SPFloatN (line, "size", 1.0); + credit.col = SPIntN(line, "col", 0); + credit.size = SPFloatN(line, "size", 1.0); CreditList.push_back(credit); } } -void CCredits::DrawCreditsText (double time_step) { +void CCredits::DrawCreditsText(double time_step) { int w = Winsys.resolution.width; int h = Winsys.resolution.height; double offs = 0.0; @@ -75,19 +75,19 @@ void CCredits::DrawCreditsText (double time_step) { continue; if (i->col == 0) - FT.SetColor (colWhite); + FT.SetColor(colWhite); else - FT.SetColor (colDYell); - FT.AutoSizeN (i->size); - FT.DrawString (-1, (int)offs, i->text); + FT.SetColor(colDYell); + FT.AutoSizeN(i->size); + FT.DrawString(-1, (int)offs, i->text); } - glDisable (GL_TEXTURE_2D); + glDisable(GL_TEXTURE_2D); glColor(colBackgr); - glRecti (0, 0, w, BOTT_Y); + glRecti(0, 0, w, BOTT_Y); - glBegin( GL_QUADS ); + glBegin(GL_QUADS); glVertex2i(0, BOTT_Y); glVertex2i(w, BOTT_Y); glColor(colBackgr, 0); @@ -96,21 +96,21 @@ void CCredits::DrawCreditsText (double time_step) { glEnd(); glColor(colBackgr); - glRecti (0, h - TOP_Y, w, h); + glRecti(0, h - TOP_Y, w, h); - glBegin( GL_QUADS ); + glBegin(GL_QUADS); glVertex2i(w, h - TOP_Y); glVertex2i(0, h - TOP_Y); glColor(colBackgr, 0); glVertex2i(0, h - TOP_Y - 30); - glVertex2i (w, h - TOP_Y - 30); + glVertex2i(w, h - TOP_Y - 30); glEnd(); - glEnable (GL_TEXTURE_2D); + glEnable(GL_TEXTURE_2D); if (offs < TOP_Y) y_offset = 0; } -void CCredits::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CCredits::Keyb(unsigned int key, bool special, bool release, int x, int y) { if (release) return; switch (key) { case SDLK_m: @@ -120,46 +120,52 @@ void CCredits::Keyb (unsigned int key, bool special, bool release, int x, int y) param.ui_snow = !param.ui_snow; break; default: - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); } } -void CCredits::Mouse (int button, int state, int x, int y) { - if (state == 1) State::manager.RequestEnterState (GameTypeSelect); +void CCredits::Mouse(int button, int state, int x, int y) { + if (state == 1) State::manager.RequestEnterState(GameTypeSelect); } void CCredits::Motion(int x, int y) { - if (param.ui_snow) push_ui_snow (cursor_pos); + if (param.ui_snow) push_ui_snow(cursor_pos); } void CCredits::Enter() { - Music.Play (param.credits_music, -1); + LoadCreditList(); + + Music.Play(param.credits_music, -1); y_offset = 0; moving = true; } +void CCredits::Exit() { + CreditList.clear(); +} + void CCredits::Loop(double time_step) { int ww = Winsys.resolution.width; int hh = Winsys.resolution.height; - Music.Update (); + Music.Update(); check_gl_error(); - ClearRenderContext (); + ClearRenderContext(); ScopedRenderMode rm(GUI); - SetupGuiDisplay (); + SetupGuiDisplay(); - DrawCreditsText (time_step); + DrawCreditsText(time_step); if (param.ui_snow) { - update_ui_snow (time_step); + update_ui_snow(time_step); draw_ui_snow(); } - Tex.Draw (BOTTOM_LEFT, 0, hh-256, 1); - Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); - Tex.Draw (TOP_LEFT, 0, 0, 1); - Tex.Draw (TOP_RIGHT, ww-256, 0, 1); - Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), Winsys.scale); + Tex.Draw(BOTTOM_LEFT, 0, hh-256, 1); + Tex.Draw(BOTTOM_RIGHT, ww-256, hh-256, 1); + Tex.Draw(TOP_LEFT, 0, 0, 1); + Tex.Draw(TOP_RIGHT, ww-256, 0, 1); + Tex.Draw(T_TITLE_SMALL, CENTER, AutoYPosN(5), Winsys.scale); - Reshape (ww, hh); + Reshape(ww, hh); Winsys.SwapBuffers(); } diff --git a/src/credits.h b/src/credits.h index d76b471..d21906f 100644 --- a/src/credits.h +++ b/src/credits.h @@ -36,6 +36,7 @@ class CCredits : public State { void DrawCreditsText(double time_step); void Enter(); + void Exit(); void Loop(double time_step); void Keyb(unsigned int key, bool special, bool release, int x, int y); void Mouse(int button, int state, int x, int y); diff --git a/src/env.cpp b/src/env.cpp index 01a8d73..d21f246 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -35,7 +35,7 @@ static const float def_diff[] = {1.0, 0.9, 1.0, 1.0}; static const float def_spec[] = {0.6, 0.6, 0.6, 1.0}; static const float def_pos[] = {1, 2, 2, 0.0}; static const float def_fogcol[] = {0.9, 0.9, 1.0, 0.0}; -static const TColor def_partcol (0.8, 0.8, 0.9, 0.0); +static const TColor def_partcol(0.8, 0.8, 0.9, 0.0); void TLight::Enable(GLenum num) const { glLightfv(num, GL_POSITION, position); @@ -47,7 +47,7 @@ void TLight::Enable(GLenum num) const { CEnvironment Env; -CEnvironment::CEnvironment () { +CEnvironment::CEnvironment() { EnvID = -1; lightcond[0] = "sunny"; lightcond[1] = "cloudy"; @@ -75,12 +75,12 @@ CEnvironment::CEnvironment () { default_fog.part_color = def_partcol; } -void CEnvironment::ResetSkybox () { +void CEnvironment::ResetSkybox() { delete[] Skybox; Skybox = NULL; } -void CEnvironment::SetupLight () { +void CEnvironment::SetupLight() { lights[0].Enable(GL_LIGHT0); if (lights[1].is_on) lights[1].Enable(GL_LIGHT1); @@ -92,43 +92,43 @@ void CEnvironment::SetupLight () { glEnable(GL_LIGHTING); } -void CEnvironment::SetupFog () { - glEnable (GL_FOG); - glFogi (GL_FOG_MODE, fog.mode); - glFogf (GL_FOG_START, fog.start); - glFogf (GL_FOG_END, fog.end); - glFogfv (GL_FOG_COLOR, fog.color); +void CEnvironment::SetupFog() { + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, fog.mode); + glFogf(GL_FOG_START, fog.start); + glFogf(GL_FOG_END, fog.end); + glFogfv(GL_FOG_COLOR, fog.color); if (param.perf_level > 1) { - glHint (GL_FOG_HINT, GL_NICEST); + glHint(GL_FOG_HINT, GL_NICEST); } else { - glHint (GL_FOG_HINT, GL_FASTEST); + glHint(GL_FOG_HINT, GL_FASTEST); } } -void CEnvironment::ResetLight () { +void CEnvironment::ResetLight() { lights[0] = default_light; for (int i=1; i<4; i++) lights[i].is_on = false; - glDisable (GL_LIGHT1); - glDisable (GL_LIGHT2); - glDisable (GL_LIGHT3); + glDisable(GL_LIGHT1); + glDisable(GL_LIGHT2); + glDisable(GL_LIGHT3); } -void CEnvironment::ResetFog () { +void CEnvironment::ResetFog() { fog = default_fog; } -void CEnvironment::Reset () { +void CEnvironment::Reset() { EnvID = -1; - ResetSkybox (); - ResetLight (); - ResetFog (); + ResetSkybox(); + ResetLight(); + ResetFog(); } -bool CEnvironment::LoadEnvironmentList () { - CSPList list (32, true); - if (!list.Load (param.env_dir2, "environment.lst")) { - Message ("could not load environment.lst"); +bool CEnvironment::LoadEnvironmentList() { + CSPList list(32, true); + if (!list.Load(param.env_dir2, "environment.lst")) { + Message("could not load environment.lst"); return false; } @@ -138,11 +138,11 @@ bool CEnvironment::LoadEnvironmentList () { locs[i].name = SPStrN(line, "location"); locs[i].high_res = SPBoolN(line, "high_res", false); } - list.MakeIndex (EnvIndex, "location"); + list.MakeIndex(EnvIndex, "location"); return true; } -string CEnvironment::GetDir (size_t location, size_t light) const { +string CEnvironment::GetDir(size_t location, size_t light) const { if (location >= locs.size()) return ""; if (light >= 4) return ""; string res = @@ -160,7 +160,7 @@ void CEnvironment::LoadSkyboxSide(size_t index, const string& EnvDir, const stri Skybox[index].Load(EnvDir, name + ".png"); } -void CEnvironment::LoadSkybox (const string& EnvDir, bool high_res) { +void CEnvironment::LoadSkybox(const string& EnvDir, bool high_res) { Skybox = new TTexture[param.full_skybox ? 6 : 3]; LoadSkyboxSide(0, EnvDir, "front", high_res); LoadSkyboxSide(1, EnvDir, "left", high_res); @@ -172,37 +172,37 @@ void CEnvironment::LoadSkybox (const string& EnvDir, bool high_res) { } } -void CEnvironment::LoadLight (const string& EnvDir) { +void CEnvironment::LoadLight(const string& EnvDir) { static const string idxstr = "[fog]-1[0]0[1]1[2]2[3]3[4]4[5]5[6]6"; CSPList list(24); - if (!list.Load (EnvDir, "light.lst")) { - Message ("could not load light file"); + if (!list.Load(EnvDir, "light.lst")) { + Message("could not load light file"); return; } for (size_t i=0; i= locs.size()) loc = 0; if (light >= 4) light = 0; // remember: with (example) 3 locations and 4 lights there @@ -397,24 +397,24 @@ void CEnvironment::LoadEnvironment (size_t loc, size_t light) { EnvID = env_id; // Set directory. The dir is used several times. - string EnvDir = GetDir (loc, light); + string EnvDir = GetDir(loc, light); // Load skybox. If the sky can't be loaded for any reason, the // texture id's are set to 0 and the sky will not be drawn. // There is no error handling, you see the result on the screen. - ResetSkybox (); + ResetSkybox(); LoadSkybox(EnvDir, locs[loc].high_res); // Load light conditions. - ResetFog (); - ResetLight (); - LoadLight (EnvDir); + ResetFog(); + ResetLight(); + LoadLight(EnvDir); } -size_t CEnvironment::GetEnvIdx (const string& tag) const { +size_t CEnvironment::GetEnvIdx(const string& tag) const { return EnvIndex.at(tag); } -size_t CEnvironment::GetLightIdx (const string& tag) const { +size_t CEnvironment::GetLightIdx(const string& tag) const { return LightIndex.at(tag); } diff --git a/src/env.h b/src/env.h index 05c8393..dec7ff4 100644 --- a/src/env.h +++ b/src/env.h @@ -64,25 +64,25 @@ private: map EnvIndex; map LightIndex; - void ResetSkybox (); + void ResetSkybox(); void LoadSkybox(const string& EnvDir, bool high_res); void LoadSkyboxSide(size_t index, const string& EnvDir, const string& name, bool high_res); - void ResetLight (); - void LoadLight (const string& EnvDir); - void ResetFog (); - void Reset (); - string GetDir (size_t location, size_t light) const; + void ResetLight(); + void LoadLight(const string& EnvDir); + void ResetFog(); + void Reset(); + string GetDir(size_t location, size_t light) const; public: - CEnvironment (); - bool LoadEnvironmentList (); - void LoadEnvironment (size_t loc, size_t light); - void DrawSkybox (const TVector3d& pos); - void SetupLight (); - void SetupFog (); - void DrawFog (); - const TColor& ParticleColor () const { return fog.part_color; } - size_t GetEnvIdx (const string& tag) const; - size_t GetLightIdx (const string& tag) const; + CEnvironment(); + bool LoadEnvironmentList(); + void LoadEnvironment(size_t loc, size_t light); + void DrawSkybox(const TVector3d& pos); + void SetupLight(); + void SetupFog(); + void DrawFog(); + const TColor& ParticleColor() const { return fog.part_color; } + size_t GetEnvIdx(const string& tag) const; + size_t GetLightIdx(const string& tag) const; }; extern CEnvironment Env; diff --git a/src/etr_types.h b/src/etr_types.h index 188ac7d..fde2ff7 100644 --- a/src/etr_types.h +++ b/src/etr_types.h @@ -78,17 +78,17 @@ struct TGameData { // course and race params TPlayer* player; + TCharacter* character; size_t start_player; TCup* cup; - bool mirrorred; - TCharacter* character; + TRace* race; // Only valid if not in practice mode TCourse* course; + bool mirrorred; size_t location_id; size_t light_id; int snow_id; int wind_id; size_t theme_id; - TRace* race; // Only valid if not in practice mode // race results (better in player.ctrl ?) double time; // reached time diff --git a/src/event.cpp b/src/event.cpp index 575a5a0..56564ce 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -46,9 +46,9 @@ static size_t curr_race = 0; static size_t curr_bonus = 0; static TWidget* textbuttons[3]; -void StartRace () { +void StartRace() { if (ready > 0) { - State::manager.RequestEnterState (EventSelect); + State::manager.RequestEnterState(EventSelect); return; } g_game.mirrorred = false; @@ -59,18 +59,18 @@ void StartRace () { g_game.wind_id = ecup->races[curr_race]->wind; g_game.race = ecup->races[curr_race]; g_game.game_type = CUPRACING; - State::manager.RequestEnterState (Loading); + State::manager.RequestEnterState(Loading); } -void CEvent::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CEvent::Keyb(unsigned int key, bool special, bool release, int x, int y) { if (release) return; switch (key) { case SDLK_RETURN: - if (curr_focus == textbuttons[0] && ready < 1) StartRace (); - else State::manager.RequestEnterState (EventSelect); + if (curr_focus == textbuttons[0] && ready < 1) StartRace(); + else State::manager.RequestEnterState(EventSelect); break; case SDLK_ESCAPE: - State::manager.RequestEnterState (EventSelect); + State::manager.RequestEnterState(EventSelect); break; case SDLK_TAB: if (ready > 0) { @@ -92,25 +92,25 @@ void CEvent::Keyb (unsigned int key, bool special, bool release, int x, int y) { } } -void CEvent::Mouse (int button, int state, int x, int y) { +void CEvent::Mouse(int button, int state, int x, int y) { if (state != 1) return; TWidget* clicked = ClickGUI(x, y); if (clicked == textbuttons[0]) { if (ready < 1) - StartRace (); + StartRace(); } else if (clicked == textbuttons[1] || clicked == textbuttons[2]) - State::manager.RequestEnterState (EventSelect); + State::manager.RequestEnterState(EventSelect); } -void CEvent::Motion (int x, int y) { +void CEvent::Motion(int x, int y) { TWidget* foc = MouseMoveGUI(x, y); if (foc != 0) curr_focus = foc; - if (param.ui_snow) push_ui_snow (cursor_pos); + if (param.ui_snow) push_ui_snow(cursor_pos); } -void InitCupRacing () { +void InitCupRacing() { ecup = g_game.cup; curr_race = 0; curr_bonus = ecup->races.size(); @@ -118,7 +118,7 @@ void InitCupRacing () { curr_focus = 0; } -void UpdateCupRacing () { +void UpdateCupRacing() { size_t lastrace = ecup->races.size() - 1; curr_bonus += g_game.race_result; if (g_game.race_result >= 0) { @@ -128,8 +128,8 @@ void UpdateCupRacing () { if (curr_bonus == 0) ready = 2; } if (ready == 1) { - Players.AddPassedCup (ecup->cup); - Players.SavePlayers (); + Players.AddPassedCup(ecup->cup); + Players.SavePlayers(); } } @@ -140,122 +140,121 @@ static int messtop, messtop2; static int bonustop, framewidth, frametop, framebottom; static int dist, texsize; -void CEvent::Enter () { - Winsys.ShowCursor (!param.ice_cursor); +void CEvent::Enter() { + Winsys.ShowCursor(!param.ice_cursor); - if (State::manager.PreviousState() == &GameOver) UpdateCupRacing (); - else InitCupRacing (); + if (State::manager.PreviousState() == &GameOver) UpdateCupRacing(); + else InitCupRacing(); framewidth = 500; - frametop = AutoYPosN (45); - area = AutoAreaN (30, 80, framewidth); - messtop = AutoYPosN (50); - messtop2 = AutoYPosN (60); - bonustop = AutoYPosN (35); + frametop = AutoYPosN(45); + area = AutoAreaN(30, 80, framewidth); + messtop = AutoYPosN(50); + messtop2 = AutoYPosN(60); + bonustop = AutoYPosN(35); texsize = 32 * Winsys.scale; if (texsize < 32) texsize = 32; dist = texsize + 2 * 4; framebottom = frametop + (int)ecup->races.size() * dist + 10; - ResetGUI (); - int siz = FT.AutoSizeN (5); - textbuttons[1] = AddTextButton (Trans.Text(8), area.left + 100, AutoYPosN (80), siz); - double len = FT.GetTextWidth (Trans.Text(13)); - textbuttons[0] = AddTextButton (Trans.Text(13), area.right -len - 100, AutoYPosN (80), siz); - textbuttons[2] = AddTextButton (Trans.Text(15), CENTER, AutoYPosN (80), siz); + ResetGUI(); + int siz = FT.AutoSizeN(5); + textbuttons[1] = AddTextButton(Trans.Text(8), area.left + 100, AutoYPosN(80), siz); + double len = FT.GetTextWidth(Trans.Text(13)); + textbuttons[0] = AddTextButton(Trans.Text(13), area.right -len - 100, AutoYPosN(80), siz); + textbuttons[2] = AddTextButton(Trans.Text(15), CENTER, AutoYPosN(80), siz); - Music.Play (param.menu_music, -1); + Music.Play(param.menu_music, -1); if (ready < 1) curr_focus = textbuttons[0]; else curr_focus = textbuttons[2]; } -int resultlevel (size_t num, size_t numraces) { +int resultlevel(size_t num, size_t numraces) { if (num < 1) return 0; int q = (int)((num - 0.01) / numraces); return q + 1; } -void CEvent::Loop (double timestep) { +void CEvent::Loop(double timestep) { int ww = Winsys.resolution.width; int hh = Winsys.resolution.height; - check_gl_error(); ScopedRenderMode rm(GUI); - Music.Update (); - ClearRenderContext (); - SetupGuiDisplay (); + Music.Update(); + ClearRenderContext(); + SetupGuiDisplay(); if (param.ui_snow) { - update_ui_snow (timestep); - draw_ui_snow (); + update_ui_snow(timestep); + draw_ui_snow(); } - Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), Winsys.scale); - Tex.Draw (BOTTOM_LEFT, 0, hh-256, 1); - Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); - Tex.Draw (TOP_LEFT, 0, 0, 1); - Tex.Draw (TOP_RIGHT, ww-256, 0, 1); + Tex.Draw(T_TITLE_SMALL, CENTER, AutoYPosN(5), Winsys.scale); + Tex.Draw(BOTTOM_LEFT, 0, hh-256, 1); + Tex.Draw(BOTTOM_RIGHT, ww-256, hh-256, 1); + Tex.Draw(TOP_LEFT, 0, 0, 1); + Tex.Draw(TOP_RIGHT, ww-256, 0, 1); // DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top, // 0, colMBackgr, colBlack, 0.2); if (ready == 0) { // cup not finished - FT.AutoSizeN (6); - FT.SetColor (colWhite); - FT.DrawString (CENTER, AutoYPosN (25), ecup->name); + FT.AutoSizeN(6); + FT.SetColor(colWhite); + FT.DrawString(CENTER, AutoYPosN(25), ecup->name); - DrawBonusExt (bonustop, (int)ecup->races.size(), curr_bonus); + DrawBonusExt(bonustop, (int)ecup->races.size(), curr_bonus); - DrawFrameX (area.left, frametop, framewidth, - (int)ecup->races.size() * dist + 20, 3, colBackgr, colWhite, 1); + DrawFrameX(area.left, frametop, framewidth, + (int)ecup->races.size() * dist + 20, 3, colBackgr, colWhite, 1); for (size_t i=0; iraces.size(); i++) { - FT.AutoSizeN (3); + FT.AutoSizeN(3); int y = frametop + 10 + (int)i * dist; if (i == curr_race) - FT.SetColor (colDYell); + FT.SetColor(colDYell); else - FT.SetColor (colWhite); - FT.DrawString (area.left + 29, y, ecup->races[i]->course->name); - Tex.Draw (CHECKBOX, area.right -54, y, texsize, texsize); - if (curr_race > i) Tex.Draw (CHECKMARK_SMALL, area.right-50, y + 4, 0.8); + FT.SetColor(colWhite); + FT.DrawString(area.left + 29, y, ecup->races[i]->course->name); + Tex.Draw(CHECKBOX, area.right -54, y, texsize, texsize); + if (curr_race > i) Tex.Draw(CHECKMARK_SMALL, area.right-50, y + 4, 0.8); } - FT.AutoSizeN (3); - int ddd = FT.AutoDistanceN (1); - FT.SetColor (colDBlue); + FT.AutoSizeN(3); + int ddd = FT.AutoDistanceN(1); + FT.SetColor(colDBlue); string info = Trans.Text(11); - info += " " + Int_StrN (ecup->races[curr_race]->herrings.x); - info += " " + Int_StrN (ecup->races[curr_race]->herrings.y); - info += " " + Int_StrN (ecup->races[curr_race]->herrings.z); - FT.DrawString (CENTER, framebottom+15, info); + info += " " + Int_StrN(ecup->races[curr_race]->herrings.x); + info += " " + Int_StrN(ecup->races[curr_race]->herrings.y); + info += " " + Int_StrN(ecup->races[curr_race]->herrings.z); + FT.DrawString(CENTER, framebottom+15, info); info = Trans.Text(12); - info += " " + Float_StrN (ecup->races[curr_race]->time.x, 0); - info += " " + Float_StrN (ecup->races[curr_race]->time.y, 0); - info += " " + Float_StrN (ecup->races[curr_race]->time.z, 0); + info += " " + Float_StrN(ecup->races[curr_race]->time.x, 0); + info += " " + Float_StrN(ecup->races[curr_race]->time.y, 0); + info += " " + Float_StrN(ecup->races[curr_race]->time.z, 0); info += " " + Trans.Text(14); - FT.DrawString (CENTER, framebottom+15+ddd, info); + FT.DrawString(CENTER, framebottom+15+ddd, info); } else if (ready == 1) { // cup successfully finished - FT.AutoSizeN (5); - FT.SetColor (colWhite); - FT.DrawString (CENTER, messtop, Trans.Text(16)); - DrawBonusExt (bonustop, (int)ecup->races.size(), curr_bonus); + FT.AutoSizeN(5); + FT.SetColor(colWhite); + FT.DrawString(CENTER, messtop, Trans.Text(16)); + DrawBonusExt(bonustop, (int)ecup->races.size(), curr_bonus); int res = resultlevel(curr_bonus, ecup->races.size()); - FT.DrawString (CENTER, messtop2, Trans.Text(17) + " " + Int_StrN (res)); + FT.DrawString(CENTER, messtop2, Trans.Text(17) + " " + Int_StrN(res)); } else if (ready == 2) { // cup finished but failed - FT.AutoSizeN (5); - FT.SetColor (colLRed); - FT.DrawString (CENTER, messtop, Trans.Text(18)); - DrawBonusExt (bonustop, ecup->races.size(), curr_bonus); - FT.DrawString (CENTER, messtop2, Trans.Text(19)); + FT.AutoSizeN(5); + FT.SetColor(colLRed); + FT.DrawString(CENTER, messtop, Trans.Text(18)); + DrawBonusExt(bonustop, ecup->races.size(), curr_bonus); + FT.DrawString(CENTER, messtop2, Trans.Text(19)); } textbuttons[0]->SetVisible(ready < 1); textbuttons[1]->SetVisible(ready < 1); textbuttons[2]->SetVisible(!(ready < 1)); - DrawGUI (); + DrawGUI(); Winsys.SwapBuffers(); } diff --git a/src/event_select.cpp b/src/event_select.cpp index 27dd9f0..a4c38bb 100644 --- a/src/event_select.cpp +++ b/src/event_select.cpp @@ -39,24 +39,24 @@ static TUpDown* event; static TUpDown* cup; static TWidget* textbuttons[2]; -void EnterEvent () { +void EnterEvent() { g_game.game_type = CUPRACING; g_game.cup = EventList[event->GetValue()].cups[cup->GetValue()]; State::manager.RequestEnterState(Event); } -void CEventSelect::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CEventSelect::Keyb(unsigned int key, bool special, bool release, int x, int y) { if (release) return; switch (key) { case SDLK_ESCAPE: - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); break; case SDLK_q: State::manager.RequestQuit(); break; case SDLK_RETURN: - if (textbuttons[1]->focussed()) State::manager.RequestEnterState (GameTypeSelect); - else if (Events.IsUnlocked (event->GetValue(), cup->GetValue())) EnterEvent(); + if (textbuttons[1]->focussed()) State::manager.RequestEnterState(GameTypeSelect); + else if (Events.IsUnlocked(event->GetValue(), cup->GetValue())) EnterEvent(); break; case SDLK_u: param.ui_snow = !param.ui_snow; @@ -66,104 +66,103 @@ void CEventSelect::Keyb (unsigned int key, bool special, bool release, int x, in } } -void CEventSelect::Mouse (int button, int state, int x, int y) { +void CEventSelect::Mouse(int button, int state, int x, int y) { if (state == 1) { TWidget* clicked = ClickGUI(x, y); if (textbuttons[0] == clicked) { - if (Events.IsUnlocked (event->GetValue(), cup->GetValue())) + if (Events.IsUnlocked(event->GetValue(), cup->GetValue())) EnterEvent(); } else if (textbuttons[1] == clicked) - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); } } -void CEventSelect::Motion (int x, int y) { +void CEventSelect::Motion(int x, int y) { MouseMoveGUI(x, y); - if (param.ui_snow) push_ui_snow (cursor_pos); + if (param.ui_snow) push_ui_snow(cursor_pos); } // -------------------------------------------------------------------- static TArea area; static int framewidth, frameheight, frametop1, frametop2; -void CEventSelect::Enter () { - Winsys.ShowCursor (!param.ice_cursor); +void CEventSelect::Enter() { + Winsys.ShowCursor(!param.ice_cursor); EventList = &Events.EventList[0]; framewidth = 500 * Winsys.scale; frameheight = 50 * Winsys.scale; - area = AutoAreaN (30, 80, framewidth); - frametop1 = AutoYPosN (35); - frametop2 = AutoYPosN (50); + area = AutoAreaN(30, 80, framewidth); + frametop1 = AutoYPosN(35); + frametop2 = AutoYPosN(50); ResetGUI(); event = AddUpDown(area.right+8, frametop1, 0, (int)Events.EventList.size() - 1, 0); cup = AddUpDown(area.right + 8, frametop2, 0, (int)Events.EventList[0].cups.size() - 1, 0); - int siz = FT.AutoSizeN (5); + int siz = FT.AutoSizeN(5); - double len = FT.GetTextWidth (Trans.Text(9)); - textbuttons[0] = AddTextButton (Trans.Text(9), area.right-len-50, AutoYPosN (70), siz); - textbuttons[1] = AddTextButton (Trans.Text(8), area.left+50, AutoYPosN (70), siz); + double len = FT.GetTextWidth(Trans.Text(9)); + textbuttons[0] = AddTextButton(Trans.Text(9), area.right-len-50, AutoYPosN(70), siz); + textbuttons[1] = AddTextButton(Trans.Text(8), area.left+50, AutoYPosN(70), siz); SetFocus(textbuttons[1]); - Events.MakeUnlockList (g_game.player->funlocked); - Music.Play (param.menu_music, -1); + Events.MakeUnlockList(g_game.player->funlocked); + Music.Play(param.menu_music, -1); } -void CEventSelect::Loop (double timestep) { +void CEventSelect::Loop(double timestep) { int ww = Winsys.resolution.width; int hh = Winsys.resolution.height; TColor col; - check_gl_error(); ScopedRenderMode rm(GUI); - Music.Update (); - ClearRenderContext (); - SetupGuiDisplay (); + Music.Update(); + ClearRenderContext(); + SetupGuiDisplay(); if (param.ui_snow) { - update_ui_snow (timestep); - draw_ui_snow (); + update_ui_snow(timestep); + draw_ui_snow(); } - Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), Winsys.scale); - Tex.Draw (BOTTOM_LEFT, 0, hh-256, 1); - Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); - Tex.Draw (TOP_LEFT, 0, 0, 1); - Tex.Draw (TOP_RIGHT, ww-256, 0, 1); + Tex.Draw(T_TITLE_SMALL, CENTER, AutoYPosN(5), Winsys.scale); + Tex.Draw(BOTTOM_LEFT, 0, hh-256, 1); + Tex.Draw(BOTTOM_RIGHT, ww-256, hh-256, 1); + Tex.Draw(TOP_LEFT, 0, 0, 1); + Tex.Draw(TOP_RIGHT, ww-256, 0, 1); // DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top, // 0, colMBackgr, colBlack, 0.2); - FT.AutoSizeN (3); - FT.SetColor (colWhite); - FT.DrawString (area.left, AutoYPosN (30), Trans.Text (6)); - FT.DrawString (area.left,AutoYPosN (45), Trans.Text (7)); - if (Events.IsUnlocked (event->GetValue(), cup->GetValue()) == false) { - FT.SetColor (colLGrey); - FT.DrawString (CENTER, AutoYPosN (58), Trans.Text (10)); + FT.AutoSizeN(3); + FT.SetColor(colWhite); + FT.DrawString(area.left, AutoYPosN(30), Trans.Text(6)); + FT.DrawString(area.left,AutoYPosN(45), Trans.Text(7)); + if (Events.IsUnlocked(event->GetValue(), cup->GetValue()) == false) { + FT.SetColor(colLGrey); + FT.DrawString(CENTER, AutoYPosN(58), Trans.Text(10)); } - FT.AutoSizeN (4); + FT.AutoSizeN(4); if (event->focussed()) col = colDYell; else col = colWhite; - DrawFrameX (area.left, frametop1, framewidth, frameheight, 3, colMBackgr, col, 1.0); - FT.SetColor (colDYell); - FT.DrawString (area.left + 20, frametop1, EventList[event->GetValue()].name); + DrawFrameX(area.left, frametop1, framewidth, frameheight, 3, colMBackgr, col, 1.0); + FT.SetColor(colDYell); + FT.DrawString(area.left + 20, frametop1, EventList[event->GetValue()].name); if (cup->focussed()) col = colDYell; else col = colWhite; - DrawFrameX (area.left, frametop2, framewidth, frameheight, 3, colMBackgr, col, 1.0); - if (Events.IsUnlocked (event->GetValue(), cup->GetValue())) - FT.SetColor (colDYell); + DrawFrameX(area.left, frametop2, framewidth, frameheight, 3, colMBackgr, col, 1.0); + if (Events.IsUnlocked(event->GetValue(), cup->GetValue())) + FT.SetColor(colDYell); else - FT.SetColor (colLGrey); - FT.DrawString (area.left + 20, frametop2, Events.GetCupTrivialName (event->GetValue(), cup->GetValue())); + FT.SetColor(colLGrey); + FT.DrawString(area.left + 20, frametop2, Events.GetCupTrivialName(event->GetValue(), cup->GetValue())); - textbuttons[0]->SetActive(Events.IsUnlocked (event->GetValue(), cup->GetValue())); + textbuttons[0]->SetActive(Events.IsUnlocked(event->GetValue(), cup->GetValue())); DrawGUI(); Winsys.SwapBuffers(); diff --git a/src/font.cpp b/src/font.cpp index da2b15d..01ced8c 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -33,7 +33,7 @@ GNU General Public License for more details. // CFont::MakeLineList. This bundle of functions generates // a vector from a textstring and adapts the lines to the textbox -static void MakeWordList (vector& wordlist, const char *s) { +static void MakeWordList(vector& wordlist, const char *s) { size_t start = 0; for (size_t i = 0; s[i] != '\0'; i++) { if (s[i] == ' ') { @@ -48,7 +48,7 @@ static void MakeWordList (vector& wordlist, const char *s) { wordlist.push_back(string(s+start)); } -static size_t MakeLine (size_t first, const vector& wordlist, vector& linelist, float width) { +static size_t MakeLine(size_t first, const vector& wordlist, vector& linelist, float width) { if (first >= wordlist.size()) return wordlist.size()-1; size_t last = first; @@ -82,7 +82,7 @@ static size_t MakeLine (size_t first, const vector& wordlist, vector= 0xF0) { - ch = (wchar_t) (s[i] & 0x07) << 18; - ch |= (wchar_t) (s[++i] & 0x3F) << 12; - ch |= (wchar_t) (s[++i] & 0x3F) << 6; - ch |= (wchar_t) (s[++i] & 0x3F); + ch = (wchar_t)(s[i] & 0x07) << 18; + ch |= (wchar_t)(s[++i] & 0x3F) << 12; + ch |= (wchar_t)(s[++i] & 0x3F) << 6; + ch |= (wchar_t)(s[++i] & 0x3F); } else if (ch >= 0xE0) { - ch = (wchar_t) (s[i] & 0x0F) << 12; - ch |= (wchar_t) (s[++i] & 0x3F) << 6; - ch |= (wchar_t) (s[++i] & 0x3F); + ch = (wchar_t)(s[i] & 0x0F) << 12; + ch |= (wchar_t)(s[++i] & 0x3F) << 6; + ch |= (wchar_t)(s[++i] & 0x3F); } else if (ch >= 0xC0) { - ch = (wchar_t) (s[i] & 0x1F) << 6; - ch |= (wchar_t) (s[++i] & 0x3F); + ch = (wchar_t)(s[i] & 0x1F) << 6; + ch |= (wchar_t)(s[++i] & 0x3F); } res[j] = ch; } @@ -139,14 +139,14 @@ wstring CFont::UnicodeStr (const char *s) { // public // -------------------------------------------------------------------- -int CFont::LoadFont (const string& name, const char *path) { - fonts.push_back(new FTGLPixmapFont (path)); +int CFont::LoadFont(const string& name, const char *path) { + fonts.push_back(new FTGLPixmapFont(path)); if (fonts.back()->Error()) { - Message ("Failed to open font"); + Message("Failed to open font"); return -1; } - fonts.back()->FaceSize (18); - fonts.back()->CharMap (ft_encoding_unicode); + fonts.back()->FaceSize(18); + fonts.back()->CharMap(ft_encoding_unicode); fontindex[name] = fonts.size()-1; return (int)fonts.size()-1; @@ -156,40 +156,40 @@ int CFont::LoadFont(const string& name, const string& dir, const string& filenam string path = dir; path += SEP; path += filename; - return LoadFont (name, path.c_str()); + return LoadFont(name, path.c_str()); } -bool CFont::LoadFontlist () { +bool CFont::LoadFontlist() { CSPList list(MAX_FONTS); - if (!list.Load ( param.font_dir, "fonts.lst")) return false; + if (!list.Load(param.font_dir, "fonts.lst")) return false; for (size_t i=0; i 0) + SetFont("pc20"); + else + SetFont("bold"); +} + // -------------------- auto ------------------------------------------ -int CFont::AutoSizeN (int rel_val) { +int CFont::AutoSizeN(int rel_val) { float size = (rel_val + 2) * 4; size *= curr_fact; size *= Winsys.scale; - SetSize (size); + SetSize(size); return (int)size; } -int CFont::AutoDistanceN (int rel_val) { +int CFont::AutoDistanceN(int rel_val) { float fact = (rel_val + 5) * 0.2; float dist = curr_size * fact; return (int) dist; @@ -232,9 +239,9 @@ void CFont::DrawText(float x, float y, const T* text, size_t font, float size) c if (left < 0) left = 0; if (forientation == OR_TOP) { - glRasterPos2i ((int)left, (int)(Winsys.resolution.height - curr_size - y)); + glRasterPos2i((int)left, (int)(Winsys.resolution.height - curr_size - y)); } else { - glRasterPos2i ((int)left, (int)y); + glRasterPos2i((int)left, (int)y); } fonts[font]->Render(text); @@ -243,7 +250,7 @@ void CFont::DrawText(float x, float y, const T* text, size_t font, float size) c template void CFont::DrawText(float x, float y, const char* text, size_t font, float size) const; // instanciate template void CFont::DrawText(float x, float y, const wchar_t* text, size_t font, float size) const; // instanciate -void CFont::DrawText (float x, float y, const char *text) const { +void CFont::DrawText(float x, float y, const char *text) const { #if USE_UNICODE DrawString(x, y, UnicodeStr(text)); #else @@ -251,20 +258,20 @@ void CFont::DrawText (float x, float y, const char *text) const { #endif } -void CFont::DrawText (float x, float y, const wchar_t *text) const { +void CFont::DrawText(float x, float y, const wchar_t *text) const { DrawText(x, y, text, curr_font, curr_size); } -void CFont::DrawString (float x, float y, const string &s) const { - DrawText (x, y, s.c_str()); +void CFont::DrawString(float x, float y, const string &s) const { + DrawText(x, y, s.c_str()); } -void CFont::DrawString (float x, float y, const wstring &s) const { - DrawText (x, y, s.c_str()); +void CFont::DrawString(float x, float y, const wstring &s) const { + DrawText(x, y, s.c_str()); } void CFont::DrawText(float x, float y, const char *text, const string &fontname, float size) const { - size_t temp_font = GetFontIdx (fontname); + size_t temp_font = GetFontIdx(fontname); #if USE_UNICODE DrawText(x, y, UnicodeStr(text).c_str(), temp_font, size); #else @@ -274,90 +281,90 @@ void CFont::DrawText(float x, float y, const char *text, const string &fontname, void CFont::DrawText (float x, float y, const wchar_t *text, const string &fontname, float size) const { - size_t temp_font = GetFontIdx (fontname); + size_t temp_font = GetFontIdx(fontname); DrawText(x, y, text, temp_font, size); } -void CFont::DrawString ( +void CFont::DrawString( float x, float y, const string &s, const string &fontname, float size) const { - DrawText (x, y, s.c_str(), fontname, size); + DrawText(x, y, s.c_str(), fontname, size); } -void CFont::DrawString ( +void CFont::DrawString( float x, float y, const wstring &s, const string &fontname, float size) const { - DrawText (x, y, s.c_str(), fontname, size); + DrawText(x, y, s.c_str(), fontname, size); } // --------------------- metrics -------------------------------------- -void CFont::GetTextSize (const wchar_t *text, float &x, float &y, size_t font, float size) const { +void CFont::GetTextSize(const wchar_t *text, float &x, float &y, size_t font, float size) const { if (font >= fonts.size()) { x = 0; y = 0; return; } float llx, lly, llz, urx, ury, urz; - fonts[font]->FaceSize ((int)size); - fonts[font]->BBox (text, llx, lly, llz, urx, ury, urz); + fonts[font]->FaceSize((int)size); + fonts[font]->BBox(text, llx, lly, llz, urx, ury, urz); x = urx - llx; y = ury - lly; } -void CFont::GetTextSize (const char *text, float &x, float &y, size_t font, float size) const { +void CFont::GetTextSize(const char *text, float &x, float &y, size_t font, float size) const { #if USE_UNICODE GetTextSize(UnicodeStr(text).c_str(), x, y, font, size); #else if (font >= fonts.size()) { x = 0; y = 0; return; } float llx, lly, llz, urx, ury, urz; - fonts[font]->FaceSize ((int)size); - fonts[font]->BBox (text, llx, lly, llz, urx, ury, urz); + fonts[font]->FaceSize((int)size); + fonts[font]->BBox(text, llx, lly, llz, urx, ury, urz); x = urx - llx; y = ury - lly; #endif } -void CFont::GetTextSize (const char *text, float &x, float &y) const { +void CFont::GetTextSize(const char *text, float &x, float &y) const { GetTextSize(text, x, y, curr_font, curr_size); } -void CFont::GetTextSize (const char *text, float &x, float &y, const string &fontname, float size) const { - size_t temp_font = GetFontIdx (fontname); +void CFont::GetTextSize(const char *text, float &x, float &y, const string &fontname, float size) const { + size_t temp_font = GetFontIdx(fontname); GetTextSize(text, x, y, temp_font, size); } -float CFont::GetTextWidth (const char *text) const { +float CFont::GetTextWidth(const char *text) const { float x, y; GetTextSize(text, x, y, curr_font, curr_size); return x; } -float CFont::GetTextWidth (const string& text) const { - return GetTextWidth (text.c_str()); +float CFont::GetTextWidth(const string& text) const { + return GetTextWidth(text.c_str()); } -float CFont::GetTextWidth (const wchar_t *text) const { +float CFont::GetTextWidth(const wchar_t *text) const { float x, y; GetTextSize(text, x, y, curr_font, curr_size); return x; } -float CFont::GetTextWidth (const char *text, const string &fontname, float size) const { - size_t temp_font = GetFontIdx (fontname); +float CFont::GetTextWidth(const char *text, const string &fontname, float size) const { + size_t temp_font = GetFontIdx(fontname); float x, y; GetTextSize(text, x, y, temp_font, size); return x; } -float CFont::GetTextWidth (const wchar_t *text, const string &fontname, float size) const { - size_t temp_font = GetFontIdx (fontname); +float CFont::GetTextWidth(const wchar_t *text, const string &fontname, float size) const { + size_t temp_font = GetFontIdx(fontname); float x, y; GetTextSize(text, x, y, temp_font, size); return x; } -float CFont::CenterX (const char *text) const { - return (Winsys.resolution.width - GetTextWidth (text)) / 2.0; +float CFont::CenterX(const char *text) const { + return (Winsys.resolution.width - GetTextWidth(text)) / 2.0; } -vector CFont::MakeLineList (const char *source, float width) { +vector CFont::MakeLineList(const char *source, float width) { vector wordlist; MakeWordList(wordlist, source); vector linelist; diff --git a/src/font.h b/src/font.h index 52fa87f..2cd39ac 100644 --- a/src/font.h +++ b/src/font.h @@ -50,51 +50,52 @@ private: void GetTextSize(const wchar_t *text, float &x, float &y, size_t font, float size) const; public: - CFont (); - ~CFont (); + CFont(); + ~CFont(); - void Clear (); + void Clear(); int LoadFont(const string& name, const string& dir, const string& filename); int LoadFont(const string& name, const char *path); - bool LoadFontlist (); - size_t GetFontIdx (const string &name) const; + bool LoadFontlist(); + size_t GetFontIdx(const string &name) const; // properties - void SetProps (const string &fontname, float size, const TColor& col); - void SetProps (const string &fontname, float size); - void SetColor (const TColor& col) { curr_col = col; } - void SetSize (float size) { curr_size = size; } - void SetFont (const string& fontname); + void SetProps(const string &fontname, float size, const TColor& col); + void SetProps(const string &fontname, float size); + void SetColor(const TColor& col) { curr_col = col; } + void SetSize(float size) { curr_size = size; } + void SetFont(const string& fontname); + void SetFontFromSettings(); // auto - int AutoSizeN (int rel_val); // rel_val = relative size, return: autosize - int AutoDistanceN (int rel_val); // rel_val = relative dist + int AutoSizeN(int rel_val); // rel_val = relative size, return: autosize + int AutoDistanceN(int rel_val); // rel_val = relative dist // draw - void DrawText (float x, float y, const char *text) const; // normal char* - void DrawText (float x, float y, const wchar_t *text) const; // wide char* - void DrawString (float x, float y, const string &s) const; // string class - void DrawString (float x, float y, const wstring &s) const; // wstring class + void DrawText(float x, float y, const char *text) const; // normal char* + void DrawText(float x, float y, const wchar_t *text) const; // wide char* + void DrawString(float x, float y, const string &s) const; // string class + void DrawString(float x, float y, const wstring &s) const; // wstring class - void DrawText (float x, float y, const char *text, const string &fontname, float size) const; - void DrawText (float x, float y, const wchar_t *text, const string &fontname, float size) const; - void DrawString (float x, float y, const string &s, const string &fontname, float size) const; - void DrawString (float x, float y, const wstring &s, const string &fontname, float size) const; + void DrawText(float x, float y, const char *text, const string &fontname, float size) const; + void DrawText(float x, float y, const wchar_t *text, const string &fontname, float size) const; + void DrawString(float x, float y, const string &s, const string &fontname, float size) const; + void DrawString(float x, float y, const wstring &s, const string &fontname, float size) const; // metrics - void GetTextSize (const char *text, float &x, float &y) const; - void GetTextSize (const char *text, float &x, float &y, const string &fontname, float size) const; - float GetTextWidth (const char *text) const; - float GetTextWidth (const string& text) const; - float GetTextWidth (const wchar_t *text) const; - float GetTextWidth (const char *text, const string &fontname, float size) const; - float GetTextWidth (const wchar_t *text, const string &fontname, float size) const; + void GetTextSize(const char *text, float &x, float &y) const; + void GetTextSize(const char *text, float &x, float &y, const string &fontname, float size) const; + float GetTextWidth(const char *text) const; + float GetTextWidth(const string& text) const; + float GetTextWidth(const wchar_t *text) const; + float GetTextWidth(const char *text, const string &fontname, float size) const; + float GetTextWidth(const wchar_t *text, const string &fontname, float size) const; - float CenterX (const char *text) const; - void SetOrientation (Orientation orientation) { forientation = orientation; } + float CenterX(const char *text) const; + void SetOrientation(Orientation orientation) { forientation = orientation; } - vector MakeLineList (const char *source, float width); + vector MakeLineList(const char *source, float width); }; extern CFont FT; diff --git a/src/ft_font.cpp b/src/ft_font.cpp index 52c1eda..0acfe53 100644 --- a/src/ft_font.cpp +++ b/src/ft_font.cpp @@ -26,22 +26,22 @@ module. // FTFont // -------------------------------------------------------------------- -FTFont::FTFont (const char* fontFilePath) - : face (fontFilePath), glyphList(0) { +FTFont::FTFont(const char* fontFilePath) + : face(fontFilePath), glyphList(0) { err = face.Error(); - if (err == 0) glyphList = new FTGlyphContainer (&face); + if (err == 0) glyphList = new FTGlyphContainer(&face); } -FTFont::FTFont (const unsigned char *pBufferBytes, size_t bufferSizeInBytes) - : face (pBufferBytes, bufferSizeInBytes), glyphList(0) { +FTFont::FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes) + : face(pBufferBytes, bufferSizeInBytes), glyphList(0) { err = face.Error(); - if (err == 0) glyphList = new FTGlyphContainer (&face); + if (err == 0) glyphList = new FTGlyphContainer(&face); } FTFont::~FTFont() {delete glyphList;} -bool FTFont::Attach (const char* fontFilePath) { - if (face.Attach (fontFilePath)) { +bool FTFont::Attach(const char* fontFilePath) { + if (face.Attach(fontFilePath)) { err = 0; return true; } else { @@ -50,8 +50,8 @@ bool FTFont::Attach (const char* fontFilePath) { } } -bool FTFont::Attach (const unsigned char *pBufferBytes, size_t bufferSizeInBytes) { - if (face.Attach (pBufferBytes, bufferSizeInBytes)) { +bool FTFont::Attach(const unsigned char *pBufferBytes, size_t bufferSizeInBytes) { + if (face.Attach(pBufferBytes, bufferSizeInBytes)) { err = 0; return true; } else { @@ -60,20 +60,20 @@ bool FTFont::Attach (const unsigned char *pBufferBytes, size_t bufferSizeInBytes } } -bool FTFont::FaceSize (const unsigned int size, const unsigned int res) { - charSize = face.Size (size, res); +bool FTFont::FaceSize(const unsigned int size, const unsigned int res) { + charSize = face.Size(size, res); err = face.Error(); if (err != 0) return false; if (glyphList != NULL) delete glyphList; - glyphList = new FTGlyphContainer (&face); + glyphList = new FTGlyphContainer(&face); return true; } unsigned int FTFont::FaceSize() const {return charSize.CharSize();} -bool FTFont::CharMap (FT_Encoding encoding) { - bool result = glyphList->CharMap (encoding); +bool FTFont::CharMap(FT_Encoding encoding) { + bool result = glyphList->CharMap(encoding); err = glyphList->Error(); return result; } @@ -84,25 +84,25 @@ float FTFont::Ascender() const {return charSize.Ascender();} float FTFont::Descender() const {return charSize.Descender();} float FTFont::LineHeight() const {return charSize.Height();} -void FTFont::BBox (const char* string, float& llx, float& lly, float& llz, - float& urx, float& ury, float& urz) { +void FTFont::BBox(const char* string, float& llx, float& lly, float& llz, + float& urx, float& ury, float& urz) { FTBBox totalBBox; if ((NULL != string) && ('\0' != *string)) { const unsigned char* c = (unsigned char*)string; float advance = 0; - if (CheckGlyph (*c)) { - totalBBox = glyphList->BBox (*c); - advance = glyphList->Advance (*c, *(c + 1)); + if (CheckGlyph(*c)) { + totalBBox = glyphList->BBox(*c); + advance = glyphList->Advance(*c, *(c + 1)); } while (*++c) { - if (CheckGlyph (*c)) { - FTBBox tempBBox = glyphList->BBox (*c); - tempBBox.Move (FTPoint (advance, 0.0f, 0.0f)); + if (CheckGlyph(*c)) { + FTBBox tempBBox = glyphList->BBox(*c); + tempBBox.Move(FTPoint(advance, 0.0f, 0.0f)); totalBBox += tempBBox; - advance += glyphList->Advance (*c, *(c + 1)); + advance += glyphList->Advance(*c, *(c + 1)); } } } @@ -115,25 +115,25 @@ void FTFont::BBox (const char* string, float& llx, float& lly, float& llz, urz = totalBBox.upperZ; } -void FTFont::BBox (const wchar_t* string, float& llx, float& lly, float& llz, - float& urx, float& ury, float& urz) { +void FTFont::BBox(const wchar_t* string, float& llx, float& lly, float& llz, + float& urx, float& ury, float& urz) { FTBBox totalBBox; if ((NULL != string) && ('\0' != *string)) { const wchar_t* c = string; float advance = 0; - if (CheckGlyph (*c)) { - totalBBox = glyphList->BBox (*c); - advance = glyphList->Advance (*c, *(c + 1)); + if (CheckGlyph(*c)) { + totalBBox = glyphList->BBox(*c); + advance = glyphList->Advance(*c, *(c + 1)); } while (*++c) { - if (CheckGlyph (*c)) { - FTBBox tempBBox = glyphList->BBox (*c); - tempBBox.Move (FTPoint (advance, 0.0f, 0.0f)); + if (CheckGlyph(*c)) { + FTBBox tempBBox = glyphList->BBox(*c); + tempBBox.Move(FTPoint(advance, 0.0f, 0.0f)); totalBBox += tempBBox; - advance += glyphList->Advance (*c, *(c + 1)); + advance += glyphList->Advance(*c, *(c + 1)); } } } @@ -146,59 +146,59 @@ void FTFont::BBox (const wchar_t* string, float& llx, float& lly, float& llz, } -float FTFont::Advance (const wchar_t* string) { +float FTFont::Advance(const wchar_t* string) { const wchar_t* c = string; float width = 0.0f; while (*c) { - if (CheckGlyph (*c)) width += glyphList->Advance (*c, *(c + 1)); + if (CheckGlyph(*c)) width += glyphList->Advance(*c, *(c + 1)); ++c; } return width; } -float FTFont::Advance (const char* string) { +float FTFont::Advance(const char* string) { const unsigned char* c = (unsigned char*)string; float width = 0.0f; while (*c) { - if (CheckGlyph (*c)) width += glyphList->Advance (*c, *(c + 1)); + if (CheckGlyph(*c)) width += glyphList->Advance(*c, *(c + 1)); ++c; } return width; } -void FTFont::Render (const char* string) { +void FTFont::Render(const char* string) { const unsigned char* c = (unsigned char*)string; pen.X(0); pen.Y(0); while (*c) { - if (CheckGlyph (*c)) pen = glyphList->Render (*c, *(c + 1), pen); + if (CheckGlyph(*c)) pen = glyphList->Render(*c, *(c + 1), pen); ++c; } } -void FTFont::Render (const wchar_t* string) { +void FTFont::Render(const wchar_t* string) { const wchar_t* c = string; pen.X(0); pen.Y(0); while (*c) { - if (CheckGlyph (*c)) pen = glyphList->Render (*c, *(c + 1), pen); + if (CheckGlyph(*c)) pen = glyphList->Render(*c, *(c + 1), pen); ++c; } } -bool FTFont::CheckGlyph (const unsigned int characterCode) { - if (NULL == glyphList->Glyph (characterCode)) { - unsigned int glyphIndex = glyphList->FontIndex (characterCode); - FTGlyph* tempGlyph = MakeGlyph (glyphIndex); +bool FTFont::CheckGlyph(const unsigned int characterCode) { + if (NULL == glyphList->Glyph(characterCode)) { + unsigned int glyphIndex = glyphList->FontIndex(characterCode); + FTGlyph* tempGlyph = MakeGlyph(glyphIndex); if (NULL == tempGlyph) { if (0 == err) err = 0x13; return false; } - glyphList->Add (tempGlyph, characterCode); + glyphList->Add(tempGlyph, characterCode); } return true; } @@ -207,26 +207,26 @@ bool FTFont::CheckGlyph (const unsigned int characterCode) { // FTLibrary // -------------------------------------------------------------------- -const FTLibrary &FTLibrary::Instance () { +const FTLibrary &FTLibrary::Instance() { static FTLibrary ftlib; return ftlib; } -FTLibrary::~FTLibrary () { +FTLibrary::~FTLibrary() { // PrintStr ("desctructor FTLibrary"); if (library != 0) { - FT_Done_FreeType (*library); + FT_Done_FreeType(*library); delete library; library= 0; } } -FTLibrary::FTLibrary () : library(0), err(0) {Initialise();} +FTLibrary::FTLibrary() : library(0), err(0) {Initialise();} -bool FTLibrary::Initialise () { +bool FTLibrary::Initialise() { if (library != 0) return true; library = new FT_Library; - err = FT_Init_FreeType (library); + err = FT_Init_FreeType(library); if (err) { delete library; library = 0; @@ -239,14 +239,14 @@ bool FTLibrary::Initialise () { // FTFace // -------------------------------------------------------------------- -FTFace::FTFace (const char* fontFilePath) +FTFace::FTFace(const char* fontFilePath) : numGlyphs(0), fontEncodingList(0), err(0) { const FT_Long DEFAULT_FACE_INDEX = 0; ftFace = new FT_Face; - err = FT_New_Face (*FTLibrary::Instance().GetLibrary(), fontFilePath, DEFAULT_FACE_INDEX, ftFace); + err = FT_New_Face(*FTLibrary::Instance().GetLibrary(), fontFilePath, DEFAULT_FACE_INDEX, ftFace); if (err) { - Message ("error FT_New_Face"); + Message("error FT_New_Face"); delete ftFace; ftFace = 0; } else { @@ -255,12 +255,12 @@ FTFace::FTFace (const char* fontFilePath) } } -FTFace::FTFace (const unsigned char *pBufferBytes, size_t bufferSizeInBytes) +FTFace::FTFace(const unsigned char *pBufferBytes, size_t bufferSizeInBytes) : numGlyphs(0), err(0) { const FT_Long DEFAULT_FACE_INDEX = 0; ftFace = new FT_Face; - err = FT_New_Memory_Face ( + err = FT_New_Memory_Face( *FTLibrary::Instance().GetLibrary(), (FT_Byte *)pBufferBytes, (FT_Long)bufferSizeInBytes, DEFAULT_FACE_INDEX, ftFace); @@ -273,30 +273,30 @@ FTFace::FTFace (const unsigned char *pBufferBytes, size_t bufferSizeInBytes) FTFace::~FTFace() { if (ftFace) { - FT_Done_Face (*ftFace); + FT_Done_Face(*ftFace); delete ftFace; ftFace = 0; } } -bool FTFace::Attach (const char* fontFilePath) { - err = FT_Attach_File (*ftFace, fontFilePath); +bool FTFace::Attach(const char* fontFilePath) { + err = FT_Attach_File(*ftFace, fontFilePath); return !err; } -bool FTFace::Attach (const unsigned char *pBufferBytes, size_t bufferSizeInBytes) { +bool FTFace::Attach(const unsigned char *pBufferBytes, size_t bufferSizeInBytes) { FT_Open_Args open; open.flags = FT_OPEN_MEMORY; open.memory_base = (FT_Byte *)pBufferBytes; open.memory_size = (FT_Long)bufferSizeInBytes; - err = FT_Attach_Stream (*ftFace, &open); + err = FT_Attach_Stream(*ftFace, &open); return !err; } -const FTSize& FTFace::Size (const unsigned int size, const unsigned int res) { - charSize.CharSize (ftFace, size, res, res); +const FTSize& FTFace::Size(const unsigned int size, const unsigned int res) { + charSize.CharSize(ftFace, size, res, res); err = charSize.Error(); return charSize; } @@ -315,7 +315,7 @@ FT_Encoding* FTFace::CharMapList() { return fontEncodingList; } -FTPoint FTFace::KernAdvance (unsigned int index1, unsigned int index2) { +FTPoint FTFace::KernAdvance(unsigned int index1, unsigned int index2) { float x, y; x = y = 0.0f; @@ -323,17 +323,17 @@ FTPoint FTFace::KernAdvance (unsigned int index1, unsigned int index2) { FT_Vector kernAdvance; kernAdvance.x = kernAdvance.y = 0; - err = FT_Get_Kerning (*ftFace, index1, index2, ft_kerning_unfitted, &kernAdvance); + err = FT_Get_Kerning(*ftFace, index1, index2, ft_kerning_unfitted, &kernAdvance); if (!err) { - x = static_cast (kernAdvance.x) / 64.0f; - y = static_cast (kernAdvance.y) / 64.0f; + x = static_cast(kernAdvance.x) / 64.0f; + y = static_cast(kernAdvance.y) / 64.0f; } } - return FTPoint (x, y, 0.0); + return FTPoint(x, y, 0.0); } -FT_GlyphSlot FTFace::Glyph (unsigned int index, FT_Int load_flags) { - err = FT_Load_Glyph (*ftFace, index, load_flags); +FT_GlyphSlot FTFace::Glyph(unsigned int index, FT_Int load_flags) { + err = FT_Load_Glyph(*ftFace, index, load_flags); if (err) return NULL; return (*ftFace)->glyph; } @@ -347,7 +347,7 @@ bool operator == (const FTPoint &a, const FTPoint &b) { b.values[1]) && (a.values[2] == b.values[2])); } -bool operator != (const FTPoint &a, const FTPoint &b) { +bool operator != (const FTPoint &a, const FTPoint &b) { return ((a.values[0] != b.values[0]) || (a.values[1] != b.values[1]) || (a.values[2] != b.values[2])); } @@ -371,10 +371,10 @@ FTSize::FTSize() FTSize::~FTSize() {} -bool FTSize::CharSize (FT_Face* face, unsigned int pointSize, - unsigned int xRes, unsigned int yRes) { +bool FTSize::CharSize(FT_Face* face, unsigned int pointSize, + unsigned int xRes, unsigned int yRes) { if (size != pointSize || xResolution != xRes || yResolution != yRes) { - err = FT_Set_Char_Size (*face, 0L, pointSize * 64, xResolution, yResolution); + err = FT_Set_Char_Size(*face, 0L, pointSize * 64, xResolution, yResolution); if (!err) { ftFace = face; @@ -398,29 +398,29 @@ unsigned int FTSize::CharSize() const { } float FTSize::Ascender() const { - return ftSize == 0 ? 0.0f : static_cast (ftSize->metrics.ascender) / 64.0f; + return ftSize == 0 ? 0.0f : static_cast(ftSize->metrics.ascender) / 64.0f; } float FTSize::Descender() const { - return ftSize == 0 ? 0.0f : static_cast (ftSize->metrics.descender) / 64.0f; + return ftSize == 0 ? 0.0f : static_cast(ftSize->metrics.descender) / 64.0f; } float FTSize::Height() const { if (0 == ftSize) return 0.0f; if (FT_IS_SCALABLE((*ftFace))) { - return ((*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin) * - ((float)ftSize->metrics.y_ppem / (float)(*ftFace)->units_per_EM); - } else return static_cast (ftSize->metrics.height) / 64.0f; + return ((*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin) * + ((float)ftSize->metrics.y_ppem / (float)(*ftFace)->units_per_EM); + } else return static_cast(ftSize->metrics.height) / 64.0f; } float FTSize::Width() const { if (0 == ftSize) return 0.0f; if (FT_IS_SCALABLE((*ftFace))) { - return ((*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin) * - (static_cast(ftSize->metrics.x_ppem) / - static_cast((*ftFace)->units_per_EM)); - } else return static_cast (ftSize->metrics.max_advance) / 64.0f; + return ((*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin) * + (static_cast(ftSize->metrics.x_ppem) / + static_cast((*ftFace)->units_per_EM)); + } else return static_cast(ftSize->metrics.max_advance) / 64.0f; } float FTSize::Underline() const {return 0.0f;} @@ -429,20 +429,20 @@ float FTSize::Underline() const {return 0.0f;} // FTGlyph // -------------------------------------------------------------------- -FTGlyph::FTGlyph (FT_GlyphSlot glyph) +FTGlyph::FTGlyph(FT_GlyphSlot glyph) : err(0) { if (glyph) { - bBox = FTBBox (glyph); - advance = FTPoint (glyph->advance.x / 64.0f, glyph->advance.y / 64.0f, 0.0f); + bBox = FTBBox(glyph); + advance = FTPoint(glyph->advance.x / 64.0f, glyph->advance.y / 64.0f, 0.0f); } } FTGlyph::~FTGlyph() {} -FTGlyphContainer::FTGlyphContainer (FTFace* f) +FTGlyphContainer::FTGlyphContainer(FTFace* f) : face(f), err(0) { - glyphs.push_back (NULL); - charMap = new FTCharmap (face); + glyphs.push_back(NULL); + charMap = new FTCharmap(face); } // -------------------------------------------------------------------- @@ -458,51 +458,51 @@ FTGlyphContainer::~FTGlyphContainer() { delete charMap; } -bool FTGlyphContainer::CharMap (FT_Encoding encoding) { - bool result = charMap->CharMap (encoding); +bool FTGlyphContainer::CharMap(FT_Encoding encoding) { + bool result = charMap->CharMap(encoding); err = charMap->Error(); return result; } -unsigned int FTGlyphContainer::FontIndex (const unsigned int characterCode) const { - return charMap->FontIndex (characterCode); +unsigned int FTGlyphContainer::FontIndex(const unsigned int characterCode) const { + return charMap->FontIndex(characterCode); } -void FTGlyphContainer::Add (FTGlyph* tempGlyph, const unsigned int characterCode) { - charMap->InsertIndex (characterCode, (unsigned int)glyphs.size()); - glyphs.push_back (tempGlyph); +void FTGlyphContainer::Add(FTGlyph* tempGlyph, const unsigned int characterCode) { + charMap->InsertIndex(characterCode, (unsigned int)glyphs.size()); + glyphs.push_back(tempGlyph); } -const FTGlyph* const FTGlyphContainer::Glyph (const unsigned int characterCode) const { - signed int index = charMap->GlyphListIndex (characterCode); +const FTGlyph* const FTGlyphContainer::Glyph(const unsigned int characterCode) const { + signed int index = charMap->GlyphListIndex(characterCode); return glyphs[index]; } -FTBBox FTGlyphContainer::BBox (const unsigned int characterCode) const { - return glyphs[charMap->GlyphListIndex (characterCode)]->BBox(); +FTBBox FTGlyphContainer::BBox(const unsigned int characterCode) const { + return glyphs[charMap->GlyphListIndex(characterCode)]->BBox(); } -float FTGlyphContainer::Advance (const unsigned int characterCode, - const unsigned int nextCharacterCode) { - unsigned int left = charMap->FontIndex (characterCode); - unsigned int right = charMap->FontIndex (nextCharacterCode); +float FTGlyphContainer::Advance(const unsigned int characterCode, + const unsigned int nextCharacterCode) { + unsigned int left = charMap->FontIndex(characterCode); + unsigned int right = charMap->FontIndex(nextCharacterCode); - float width = face->KernAdvance (left, right).X(); - width += glyphs[charMap->GlyphListIndex (characterCode)]->Advance().X(); + float width = face->KernAdvance(left, right).X(); + width += glyphs[charMap->GlyphListIndex(characterCode)]->Advance().X(); return width; } -FTPoint FTGlyphContainer::Render (const unsigned int characterCode, - const unsigned int nextCharacterCode, FTPoint penPosition) { +FTPoint FTGlyphContainer::Render(const unsigned int characterCode, + const unsigned int nextCharacterCode, FTPoint penPosition) { FTPoint kernAdvance, advance; - unsigned int left = charMap->FontIndex (characterCode); - unsigned int right = charMap->FontIndex (nextCharacterCode); + unsigned int left = charMap->FontIndex(characterCode); + unsigned int right = charMap->FontIndex(nextCharacterCode); - kernAdvance = face->KernAdvance (left, right); + kernAdvance = face->KernAdvance(left, right); if (!face->Error()) { - advance = glyphs[charMap->GlyphListIndex (characterCode)]->Render (penPosition); + advance = glyphs[charMap->GlyphListIndex(characterCode)]->Render(penPosition); } kernAdvance += advance; @@ -515,10 +515,10 @@ FTPoint FTGlyphContainer::Render (const unsigned int characterCode, GLint FTTextureGlyph::activeTextureID = 0; -FTTextureGlyph::FTTextureGlyph (FT_GlyphSlot glyph, int id, int xOffset, - int yOffset, GLsizei width, GLsizei height) - : FTGlyph (glyph), destWidth(0), destHeight(0), glTextureID(id) { - err = FT_Render_Glyph (glyph, FT_RENDER_MODE_NORMAL); +FTTextureGlyph::FTTextureGlyph(FT_GlyphSlot glyph, int id, int xOffset, + int yOffset, GLsizei width, GLsizei height) + : FTGlyph(glyph), destWidth(0), destHeight(0), glTextureID(id) { + err = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL); if (err || glyph->format != ft_glyph_format_bitmap) return; FT_Bitmap bitmap = glyph->bitmap; @@ -526,36 +526,36 @@ FTTextureGlyph::FTTextureGlyph (FT_GlyphSlot glyph, int id, int xOffset, destHeight = bitmap.rows; if (destWidth && destHeight) { - glPushClientAttrib (GL_CLIENT_PIXEL_STORE_BIT); - glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); - glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei (GL_UNPACK_ALIGNMENT, 1); + glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glBindTexture (GL_TEXTURE_2D, glTextureID); - glTexSubImage2D (GL_TEXTURE_2D, 0, xOffset, yOffset, - destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer); + glBindTexture(GL_TEXTURE_2D, glTextureID); + glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, + destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer); glPopClientAttrib(); } - uv[0].X (static_cast(xOffset) / static_cast(width)); - uv[0].Y (static_cast(yOffset) / static_cast(height)); - uv[1].X (static_cast (xOffset + destWidth) / static_cast(width)); - uv[1].Y (static_cast (yOffset + destHeight) / static_cast(height)); + uv[0].X(static_cast(xOffset) / static_cast(width)); + uv[0].Y(static_cast(yOffset) / static_cast(height)); + uv[1].X(static_cast(xOffset + destWidth) / static_cast(width)); + uv[1].Y(static_cast(yOffset + destHeight) / static_cast(height)); - pos.X (glyph->bitmap_left); - pos.Y (glyph->bitmap_top); + pos.X(glyph->bitmap_left); + pos.Y(glyph->bitmap_top); } FTTextureGlyph::~FTTextureGlyph() {} -const FTPoint& FTTextureGlyph::Render (const FTPoint& pen) { +const FTPoint& FTTextureGlyph::Render(const FTPoint& pen) { if (activeTextureID != glTextureID) { - glBindTexture (GL_TEXTURE_2D, (GLuint)glTextureID); + glBindTexture(GL_TEXTURE_2D, (GLuint)glTextureID); activeTextureID = glTextureID; } - glTranslatef (pen.X(), pen.Y(), 0.0f); + glTranslatef(pen.X(), pen.Y(), 0.0f); const GLfloat tex[] = { uv[0].X(), uv[0].Y(), @@ -581,7 +581,7 @@ const FTPoint& FTTextureGlyph::Render (const FTPoint& pen) { return advance; } -inline GLuint NextPowerOf2 (GLuint in) { +inline GLuint NextPowerOf2(GLuint in) { in -= 1; in |= in >> 16; @@ -596,8 +596,8 @@ inline GLuint NextPowerOf2 (GLuint in) { // FTGLTextureFont // -------------------------------------------------------------------- -FTGLTextureFont::FTGLTextureFont (const char* fontFilePath) - : FTFont (fontFilePath), +FTGLTextureFont::FTGLTextureFont(const char* fontFilePath) + : FTFont(fontFilePath), maximumGLTextureSize(0), textureWidth(0), textureHeight(0), @@ -609,8 +609,8 @@ FTGLTextureFont::FTGLTextureFont (const char* fontFilePath) remGlyphs = numGlyphs = face.GlyphCount(); } -FTGLTextureFont::FTGLTextureFont (const unsigned char *pBufferBytes, size_t bufferSizeInBytes) - : FTFont (pBufferBytes, bufferSizeInBytes), +FTGLTextureFont::FTGLTextureFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes) + : FTFont(pBufferBytes, bufferSizeInBytes), maximumGLTextureSize(0), textureWidth(0), textureHeight(0), @@ -623,34 +623,34 @@ FTGLTextureFont::FTGLTextureFont (const unsigned char *pBufferBytes, size_t buff } FTGLTextureFont::~FTGLTextureFont() { - glDeleteTextures ((GLsizei)textureIDList.size(), (const GLuint*)&textureIDList[0]); + glDeleteTextures((GLsizei)textureIDList.size(), (const GLuint*)&textureIDList[0]); } -FTGlyph* FTGLTextureFont::MakeGlyph (unsigned int glyphIndex) { - FT_GlyphSlot ftGlyph = face.Glyph (glyphIndex, FT_LOAD_NO_HINTING); +FTGlyph* FTGLTextureFont::MakeGlyph(unsigned int glyphIndex) { + FT_GlyphSlot ftGlyph = face.Glyph(glyphIndex, FT_LOAD_NO_HINTING); if (ftGlyph) { - glyphHeight = static_cast (charSize.Height()); - glyphWidth = static_cast (charSize.Width()); + glyphHeight = static_cast(charSize.Height()); + glyphWidth = static_cast(charSize.Width()); if (textureIDList.empty()) { - textureIDList.push_back (CreateTexture()); + textureIDList.push_back(CreateTexture()); xOffset = yOffset = padding; } - if (xOffset > (textureWidth - glyphWidth)) { + if (xOffset > (textureWidth - glyphWidth)) { xOffset = padding; yOffset += glyphHeight; - if (yOffset > (textureHeight - glyphHeight)) { - textureIDList.push_back (CreateTexture()); + if (yOffset > (textureHeight - glyphHeight)) { + textureIDList.push_back(CreateTexture()); yOffset = padding; } } FTTextureGlyph* tempGlyph = - new FTTextureGlyph (ftGlyph, textureIDList[textureIDList.size() - 1], - xOffset, yOffset, textureWidth, textureHeight); - xOffset += static_cast (tempGlyph->BBox().upperX - tempGlyph->BBox().lowerX + padding); + new FTTextureGlyph(ftGlyph, textureIDList[textureIDList.size() - 1], + xOffset, yOffset, textureWidth, textureHeight); + xOffset += static_cast(tempGlyph->BBox().upperX - tempGlyph->BBox().lowerX + padding); --remGlyphs; return tempGlyph; @@ -661,13 +661,13 @@ FTGlyph* FTGLTextureFont::MakeGlyph (unsigned int glyphIndex) { void FTGLTextureFont::CalculateTextureSize() { if (!maximumGLTextureSize) { - glGetIntegerv (GL_MAX_TEXTURE_SIZE, (GLint*)&maximumGLTextureSize); + glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&maximumGLTextureSize); } - textureWidth = NextPowerOf2 ((remGlyphs * glyphWidth) + (padding * 2)); + textureWidth = NextPowerOf2((remGlyphs * glyphWidth) + (padding * 2)); textureWidth = textureWidth > maximumGLTextureSize ? maximumGLTextureSize : textureWidth; - int h = static_cast ((textureWidth - (padding * 2)) / glyphWidth); - textureHeight = NextPowerOf2 (( (numGlyphs / h) + 1) * glyphHeight); + int h = static_cast((textureWidth - (padding * 2)) / glyphWidth); + textureHeight = NextPowerOf2(((numGlyphs / h) + 1) * glyphHeight); textureHeight = textureHeight > maximumGLTextureSize ? maximumGLTextureSize : textureHeight; } @@ -676,48 +676,48 @@ GLuint FTGLTextureFont::CreateTexture() { int totalMemory = textureWidth * textureHeight; unsigned char* textureMemory = new unsigned char[totalMemory]; - memset (textureMemory, 0, totalMemory); + memset(textureMemory, 0, totalMemory); GLuint textID; - glGenTextures (1, (GLuint*)&textID); + glGenTextures(1, (GLuint*)&textID); - glBindTexture (GL_TEXTURE_2D, textID); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, textID); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, textureWidth, textureHeight, 0, - GL_ALPHA, GL_UNSIGNED_BYTE, textureMemory); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, textureWidth, textureHeight, 0, + GL_ALPHA, GL_UNSIGNED_BYTE, textureMemory); delete [] textureMemory; return textID; } -bool FTGLTextureFont::FaceSize (const unsigned int size, const unsigned int res) { +bool FTGLTextureFont::FaceSize(const unsigned int size, const unsigned int res) { if (!textureIDList.empty()) { - glDeleteTextures ((GLsizei)textureIDList.size(), (const GLuint*)&textureIDList[0]); + glDeleteTextures((GLsizei)textureIDList.size(), (const GLuint*)&textureIDList[0]); textureIDList.clear(); remGlyphs = numGlyphs = face.GlyphCount(); } - return FTFont::FaceSize (size, res); + return FTFont::FaceSize(size, res); } -void FTGLTextureFont::Render (const char* string) { - glPushAttrib (GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT); +void FTGLTextureFont::Render(const char* string) { + glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE FTTextureGlyph::ResetActiveTexture(); - FTFont::Render (string); + FTFont::Render(string); glPopAttrib(); } -void FTGLTextureFont::Render (const wchar_t* string) { - glPushAttrib (GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT); +void FTGLTextureFont::Render(const wchar_t* string) { + glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE FTTextureGlyph::ResetActiveTexture(); - FTFont::Render (string); + FTFont::Render(string); glPopAttrib(); } @@ -725,33 +725,33 @@ void FTGLTextureFont::Render (const wchar_t* string) { // FTCharmap (character map) // -------------------------------------------------------------------- -FTCharmap::FTCharmap (FTFace* face) - : ftFace (*(face->Face())), err(0) { - if (!ftFace->charmap) err = FT_Set_Charmap (ftFace, ftFace->charmaps[0]); +FTCharmap::FTCharmap(FTFace* face) + : ftFace(*(face->Face())), err(0) { + if (!ftFace->charmap) err = FT_Set_Charmap(ftFace, ftFace->charmaps[0]); ftEncoding = ftFace->charmap->encoding; } FTCharmap::~FTCharmap() {charMap.clear();} -bool FTCharmap::CharMap (FT_Encoding encoding) { +bool FTCharmap::CharMap(FT_Encoding encoding) { if (ftEncoding == encoding) return true; - err = FT_Select_Charmap (ftFace, encoding); + err = FT_Select_Charmap(ftFace, encoding); if (!err) ftEncoding = encoding; else ftEncoding = ft_encoding_none; charMap.clear(); return !err; } -unsigned int FTCharmap::GlyphListIndex (unsigned int characterCode) { - return charMap.find (characterCode); +unsigned int FTCharmap::GlyphListIndex(unsigned int characterCode) { + return charMap.find(characterCode); } -unsigned int FTCharmap::FontIndex (unsigned int characterCode) { - return FT_Get_Char_Index (ftFace, characterCode); +unsigned int FTCharmap::FontIndex(unsigned int characterCode) { + return FT_Get_Char_Index(ftFace, characterCode); } -void FTCharmap::InsertIndex (const unsigned int characterCode, const unsigned int containerIndex) { - charMap.insert (characterCode, containerIndex); +void FTCharmap::InsertIndex(const unsigned int characterCode, const unsigned int containerIndex) { + charMap.insert(characterCode, containerIndex); } @@ -759,13 +759,13 @@ void FTCharmap::InsertIndex (const unsigned int characterCode, const unsigned in // FTPixmapGlyph // -------------------------------------------------------------------- -FTPixmapGlyph::FTPixmapGlyph( FT_GlyphSlot glyph) - : FTGlyph( glyph), +FTPixmapGlyph::FTPixmapGlyph(FT_GlyphSlot glyph) + : FTGlyph(glyph), destWidth(0), destHeight(0), data(0) { - err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL); - if ( err || ft_glyph_format_bitmap != glyph->format) return; + err = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL); + if (err || ft_glyph_format_bitmap != glyph->format) return; FT_Bitmap bitmap = glyph->bitmap; int srcWidth = bitmap.width; @@ -781,8 +781,8 @@ FTPixmapGlyph::FTPixmapGlyph( FT_GlyphSlot glyph) unsigned char* dest = data + ((destHeight - 1) * destWidth * 2); size_t destStep = destWidth * 2 * 2; - for ( int y = 0; y < srcHeight; ++y) { - for ( int x = 0; x < srcWidth; ++x) { + for (int y = 0; y < srcHeight; ++y) { + for (int x = 0; x < srcWidth; ++x) { *dest++ = static_cast(255); *dest++ = *src++; } @@ -797,16 +797,16 @@ FTPixmapGlyph::FTPixmapGlyph( FT_GlyphSlot glyph) FTPixmapGlyph::~FTPixmapGlyph() {delete [] data;} -const FTPoint& FTPixmapGlyph::Render( const FTPoint& pen) { - glBitmap( 0, 0, 0.0f, 0.0f, pen.X() + pos.X(), pen.Y() - pos.Y(), (const GLubyte*)0); +const FTPoint& FTPixmapGlyph::Render(const FTPoint& pen) { + glBitmap(0, 0, 0.0f, 0.0f, pen.X() + pos.X(), pen.Y() - pos.Y(), (const GLubyte*)0); - if ( data) { - glPixelStorei( GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei( GL_UNPACK_ALIGNMENT, 2); + if (data) { + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, 2); - glDrawPixels( destWidth, destHeight, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (const GLvoid*)data); + glDrawPixels(destWidth, destHeight, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (const GLvoid*)data); } - glBitmap( 0, 0, 0.0f, 0.0f, -pos.X(), pos.Y(), (const GLubyte*)0); + glBitmap(0, 0, 0.0f, 0.0f, -pos.X(), pos.Y(), (const GLubyte*)0); return advance; } @@ -815,13 +815,13 @@ const FTPoint& FTPixmapGlyph::Render( const FTPoint& pen) { // FTPixmapFont // -------------------------------------------------------------------- -FTGLPixmapFont::FTGLPixmapFont( const char* fontFilePath) - : FTFont( fontFilePath) +FTGLPixmapFont::FTGLPixmapFont(const char* fontFilePath) + : FTFont(fontFilePath) {} -FTGLPixmapFont::FTGLPixmapFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes) - : FTFont( pBufferBytes, bufferSizeInBytes) +FTGLPixmapFont::FTGLPixmapFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes) + : FTFont(pBufferBytes, bufferSizeInBytes) {} @@ -829,11 +829,11 @@ FTGLPixmapFont::~FTGLPixmapFont() {} -FTGlyph* FTGLPixmapFont::MakeGlyph( unsigned int g) { - FT_GlyphSlot ftGlyph = face.Glyph( g, FT_LOAD_NO_HINTING); +FTGlyph* FTGLPixmapFont::MakeGlyph(unsigned int g) { + FT_GlyphSlot ftGlyph = face.Glyph(g, FT_LOAD_NO_HINTING); - if ( ftGlyph) { - FTPixmapGlyph* tempGlyph = new FTPixmapGlyph( ftGlyph); + if (ftGlyph) { + FTPixmapGlyph* tempGlyph = new FTPixmapGlyph(ftGlyph); return tempGlyph; } @@ -842,48 +842,48 @@ FTGlyph* FTGLPixmapFont::MakeGlyph( unsigned int g) { } -void FTGLPixmapFont::Render( const char* string) { - glPushAttrib( GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); - glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT); +void FTGLPixmapFont::Render(const char* string) { + glPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); + glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); glEnable(GL_BLEND); - glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable( GL_TEXTURE_2D); + glDisable(GL_TEXTURE_2D); GLfloat ftglColour[4]; - glGetFloatv( GL_CURRENT_RASTER_COLOR, ftglColour); + glGetFloatv(GL_CURRENT_RASTER_COLOR, ftglColour); glPixelTransferf(GL_RED_SCALE, ftglColour[0]); glPixelTransferf(GL_GREEN_SCALE, ftglColour[1]); glPixelTransferf(GL_BLUE_SCALE, ftglColour[2]); glPixelTransferf(GL_ALPHA_SCALE, ftglColour[3]); - FTFont::Render( string); + FTFont::Render(string); glPopClientAttrib(); glPopAttrib(); } -void FTGLPixmapFont::Render( const wchar_t* string) { - glPushAttrib( GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); - glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT); +void FTGLPixmapFont::Render(const wchar_t* string) { + glPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT); + glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); glEnable(GL_BLEND); - glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable( GL_TEXTURE_2D); + glDisable(GL_TEXTURE_2D); GLfloat ftglColour[4]; - glGetFloatv( GL_CURRENT_RASTER_COLOR, ftglColour); + glGetFloatv(GL_CURRENT_RASTER_COLOR, ftglColour); glPixelTransferf(GL_RED_SCALE, ftglColour[0]); glPixelTransferf(GL_GREEN_SCALE, ftglColour[1]); glPixelTransferf(GL_BLUE_SCALE, ftglColour[2]); glPixelTransferf(GL_ALPHA_SCALE, ftglColour[3]); - FTFont::Render( string); + FTFont::Render(string); glPopClientAttrib(); glPopAttrib(); diff --git a/src/ft_font.h b/src/ft_font.h index ad6fa1f..55eb3d4 100644 --- a/src/ft_font.h +++ b/src/ft_font.h @@ -211,9 +211,9 @@ public: typedef signed long GlyphIndex; enum { - NumberOfBuckets = 256, - BucketSize = 256, - IndexNotFound = -1 + NumberOfBuckets = 256, + BucketSize = 256, + IndexNotFound = -1 }; FTCharToGlyphIndexMap() {this->Indices = 0;} virtual ~FTCharToGlyphIndexMap() { @@ -444,7 +444,7 @@ public: upperY = static_cast(bbox.yMax) / 64.0f; upperZ = 0.0f; } - FTBBox &Move (FTPoint distance) { + FTBBox &Move(FTPoint distance) { lowerX += distance.X(); lowerY += distance.Y(); lowerZ += distance.Z(); @@ -521,7 +521,7 @@ private: class FTGL_EXPORT FTGlyphContainer { typedef FTVector GlyphVector; public: - FTGlyphContainer (FTFace* face); + FTGlyphContainer(FTFace* face); ~FTGlyphContainer(); bool CharMap(FT_Encoding encoding); unsigned int FontIndex(const unsigned int characterCode) const; @@ -566,13 +566,13 @@ private: class FTGL_EXPORT FTFont { public: - FTFont (const char* fontFilePath); - FTFont (const unsigned char *pBufferBytes, size_t bufferSizeInBytes); + FTFont(const char* fontFilePath); + FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes); virtual ~FTFont(); - bool Attach (const char* fontFilePath); - bool Attach (const unsigned char *pBufferBytes, size_t bufferSizeInBytes); - bool CharMap (FT_Encoding encoding); + bool Attach(const char* fontFilePath); + bool Attach(const unsigned char *pBufferBytes, size_t bufferSizeInBytes); + bool CharMap(FT_Encoding encoding); unsigned int CharMapCount(); FT_Encoding* CharMapList(); virtual bool FaceSize(const unsigned int size, const unsigned int res = 72); @@ -583,12 +583,12 @@ public: float LineHeight() const; void BBox(const char* string, float& llx, float& lly, float& llz, float& urx, float& ury, float& urz); - void BBox (const wchar_t* string, float& llx, float& lly, - float& llz, float& urx, float& ury, float& urz); - float Advance (const wchar_t* string); - float Advance (const char* string); - virtual void Render (const char* string); - virtual void Render (const wchar_t* string); + void BBox(const wchar_t* string, float& llx, float& lly, + float& llz, float& urx, float& ury, float& urz); + float Advance(const wchar_t* string); + float Advance(const char* string); + virtual void Render(const char* string); + virtual void Render(const wchar_t* string); FT_Error Error() const { return err;} protected: @@ -633,22 +633,22 @@ private: class FTGL_EXPORT FTGLPixmapFont : public FTFont { public: - FTGLPixmapFont( const char* fontFilePath); - FTGLPixmapFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes); + FTGLPixmapFont(const char* fontFilePath); + FTGLPixmapFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes); ~FTGLPixmapFont(); - void Render( const char* string); - void Render( const wchar_t* string); + void Render(const char* string); + void Render(const wchar_t* string); private: - inline virtual FTGlyph* MakeGlyph( unsigned int g); + inline virtual FTGlyph* MakeGlyph(unsigned int g); }; class FTGL_EXPORT FTPixmapGlyph : public FTGlyph { public: - FTPixmapGlyph( FT_GlyphSlot glyph); + FTPixmapGlyph(FT_GlyphSlot glyph); virtual ~FTPixmapGlyph(); - virtual const FTPoint& Render( const FTPoint& pen); + virtual const FTPoint& Render(const FTPoint& pen); private: int destWidth; int destHeight; diff --git a/src/game_config.cpp b/src/game_config.cpp index d0e2aed..f3b2e1a 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -50,47 +50,47 @@ Then edit the below functions: TParam param; -void LoadConfigFile () { +void LoadConfigFile() { CSPList list(4); - if (!list.Load (param.configfile)) { - Message ("Could not load 'options'"); + if (!list.Load(param.configfile)) { + Message("Could not load 'options'"); return; } for (size_t i=0; i 5) { + strcpy(buff, arg0); + if (strlen(buff) > 5) { buff[strlen(buff)-3] = 0; } } @@ -306,13 +306,13 @@ void InitConfig (const char *arg0) { param.prog_dir = buff; #endif /* 0 */ - struct passwd *pwent = getpwuid (getuid ()); + struct passwd *pwent = getpwuid(getuid()); param.config_dir = pwent->pw_dir; param.config_dir += SEP; - param.config_dir += CONFIG_DIR; + param.config_dir += ".etr"; // or: param.config_dir = param.prog_dir + SEP "config"; - if (!DirExists (param.config_dir.c_str())) - mkdir (param.config_dir.c_str(), 0775); + if (!DirExists(param.config_dir.c_str())) + mkdir(param.config_dir.c_str(), 0775); param.data_dir = ETR_DATA_DIR; param.data_dir += SEP; param.data_dir += "etr"; @@ -338,10 +338,12 @@ void InitConfig (const char *arg0) { param.display_fps = false; param.show_hud = true; - if (FileExists (param.configfile)) { - LoadConfigFile (); + Trans.LoadLanguages(); + + if (FileExists(param.configfile)) { + LoadConfigFile(); } else { - SetConfigDefaults (); - SaveConfigFile (); + SetConfigDefaults(); + SaveConfigFile(); } } diff --git a/src/game_config.h b/src/game_config.h index e78f33c..68b5b22 100644 --- a/src/game_config.h +++ b/src/game_config.h @@ -19,9 +19,6 @@ GNU General Public License for more details. #include "bh.h" -#define CONFIG_DIR ".etr" -#define PLAYER_FILE "players" - struct TParam { // defined at runtime: // string prog_dir; @@ -78,8 +75,8 @@ struct TParam { TViewMode view_mode; }; -void InitConfig (const char *arg0); -void SaveConfigFile (); +void InitConfig(); +void SaveConfigFile(); extern TParam param; diff --git a/src/game_ctrl.cpp b/src/game_ctrl.cpp index 7dd5c35..903fc60 100644 --- a/src/game_ctrl.cpp +++ b/src/game_ctrl.cpp @@ -33,18 +33,18 @@ GNU General Public License for more details. CEvents Events; -bool CEvents::LoadEventList () { +bool CEvents::LoadEventList() { CSPList list(256); - if (!list.Load (param.common_course_dir, "events.lst")) { - Message ("could not load events.lst"); + if (!list.Load(param.common_course_dir, "events.lst")) { + Message("could not load events.lst"); return false; } // pass 1: races for (size_t i=0; i= EventList.size()) return errorString; if (cup >= EventList[event].cups.size()) return errorString; return EventList[event].cups[cup]->cup; } -const string& CEvents::GetCupTrivialName (size_t event, size_t cup) const { +const string& CEvents::GetCupTrivialName(size_t event, size_t cup) const { if (event >= EventList.size()) return errorString; if (cup >= EventList[event].cups.size()) return errorString; return EventList[event].cups[cup]->name; } -void CEvents::MakeUnlockList (const string& unlockstr) { +void CEvents::MakeUnlockList(const string& unlockstr) { for (size_t event=0; eventUnlocked = false; @@ -128,8 +128,8 @@ void CEvents::MakeUnlockList (const string& unlockstr) { } for (size_t event=0; eventUnlocked = true; if (passed) { EventList[event].cups[cup]->Unlocked = true; @@ -140,7 +140,7 @@ void CEvents::MakeUnlockList (const string& unlockstr) { } } -bool CEvents::IsUnlocked (size_t event, size_t cup) const { +bool CEvents::IsUnlocked(size_t event, size_t cup) const { if (event >= EventList.size()) return false; if (cup >= EventList[event].cups.size()) return false; return EventList[event].cups[cup]->Unlocked; @@ -158,26 +158,26 @@ CPlayers::~CPlayers() { delete avatars[i].texture; } -void CPlayers::AddPlayer (const string& name, const string& avatar) { +void CPlayers::AddPlayer(const string& name, const string& avatar) { plyr.push_back(TPlayer(name, FindAvatar(avatar))); } -void CPlayers::SetDefaultPlayers () { +void CPlayers::SetDefaultPlayers() { plyr.push_back(TPlayer("Racer", FindAvatar("avatar01.png"))); plyr.push_back(TPlayer("Bunny", FindAvatar("avatar02.png"))); } -bool CPlayers::LoadPlayers () { - if (FileExists (param.config_dir, "players") == false) { - SetDefaultPlayers (); - Message ("file 'players' does not exist, set default players"); +bool CPlayers::LoadPlayers() { + if (FileExists(param.config_dir, "players") == false) { + SetDefaultPlayers(); + Message("file 'players' does not exist, set default players"); return false; } CSPList list(MAX_PLAYERS); - if (list.Load (param.config_dir, "players") == false) { - SetDefaultPlayers (); - Message ("could not load players list, set default players"); + if (list.Load(param.config_dir, "players") == false) { + SetDefaultPlayers(); + Message("could not load players list, set default players"); return false; } @@ -185,22 +185,22 @@ bool CPlayers::LoadPlayers () { plyr.resize(list.Count()); for (size_t i=0; i 0) g_game.start_player = plyr.size()-1; } if (plyr.empty()) { - SetDefaultPlayers (); - Message ("player file doesn't contain a player, set default players"); + SetDefaultPlayers(); + Message("player file doesn't contain a player, set default players"); return false; } return true; } -void CPlayers::SavePlayers () const { +void CPlayers::SavePlayers() const { string playerfile = param.config_dir + SEP "players"; CSPList list(plyr.size()); for (size_t i=0; ifunlocked, cup, -1) > 0) return; +void CPlayers::AddPassedCup(const string& cup) { + if (SPIntN(g_game.player->funlocked, cup, -1) > 0) return; g_game.player->funlocked += " "; g_game.player->funlocked += cup; } -void CPlayers::ResetControls () { +void CPlayers::ResetControls() { for (size_t i=0; i= plyr.size()) return; if (plyr[player].ctrl != NULL) return; plyr[player].ctrl = new CControl; @@ -243,17 +243,17 @@ void CPlayers::AllocControl (size_t player) { // ----------------------- avatars ------------------------------------ -void CPlayers::LoadAvatars () { - CSPList list (MAX_AVATARS); +void CPlayers::LoadAvatars() { + CSPList list(MAX_AVATARS); - if (!list.Load (param.player_dir, "avatars.lst")) { - Message ("could not load avators.lst"); + if (!list.Load(param.player_dir, "avatars.lst")) { + Message("could not load avators.lst"); return; } for (size_t i=0; iLoad(param.player_dir, filename)) { avatars.push_back(TAvatar(filename, texture)); @@ -262,12 +262,12 @@ void CPlayers::LoadAvatars () { } } -TTexture* CPlayers::GetAvatarTexture (size_t avatar) const { +TTexture* CPlayers::GetAvatarTexture(size_t avatar) const { if (avatar >= avatars.size()) return 0; return avatars[avatar].texture; } -const string& CPlayers::GetDirectAvatarName (size_t avatar) const { +const string& CPlayers::GetDirectAvatarName(size_t avatar) const { if (avatar >= avatars.size()) return emptyString; return avatars[avatar].filename; } @@ -293,48 +293,48 @@ CCharacter::~CCharacter() { } } -void CCharacter::LoadCharacterList () { - CSPList list (MAX_CHARACTERS); +void CCharacter::LoadCharacterList() { + CSPList list(MAX_CHARACTERS); - if (!list.Load (param.char_dir, "characters.lst")) { - Message ("could not load characters.lst"); + if (!list.Load(param.char_dir, "characters.lst")) { + Message("could not load characters.lst"); return; } CharList.resize(list.Count()); for (size_t i=0; ipreview = new TTexture(); if (!ch->preview->LoadMipmap(previewfile, false)) { - Message ("could not load previewfile of character"); + Message("could not load previewfile of character"); // texid = Tex.TexID (NO_PREVIEW); } ch->shape = new CCharShape; - if (ch->shape->Load (charpath, "shape.lst", false) == false) { + if (ch->shape->Load(charpath, "shape.lst", false) == false) { delete ch->shape; ch->shape = NULL; - Message ("could not load character shape"); + Message("could not load character shape"); } - ch->frames[0].Load (charpath, "start.lst"); + ch->frames[0].Load(charpath, "start.lst"); ch->finishframesok = true; - ch->frames[1].Load (charpath, "finish.lst"); + ch->frames[1].Load(charpath, "finish.lst"); if (ch->frames[1].loaded == false) ch->finishframesok = false; - ch->frames[2].Load (charpath, "wonrace.lst"); + ch->frames[2].Load(charpath, "wonrace.lst"); if (ch->frames[2].loaded == false) ch->finishframesok = false; - ch->frames[3].Load (charpath, "lostrace.lst"); + ch->frames[3].Load(charpath, "lostrace.lst"); if (ch->frames[3].loaded == false) ch->finishframesok = false; } } diff --git a/src/game_ctrl.h b/src/game_ctrl.h index bf72751..11ba4b1 100644 --- a/src/game_ctrl.h +++ b/src/game_ctrl.h @@ -78,15 +78,15 @@ public: vector RaceList; vector CupList; vector EventList; - bool LoadEventList (); - size_t GetRaceIdx (const string& race) const; - size_t GetCupIdx (const string& cup) const; - size_t GetEventIdx (const string& event) const; - const string& GetCup (size_t event, size_t cup) const; - const string& GetCupTrivialName (size_t event, size_t cup) const; + bool LoadEventList(); + size_t GetRaceIdx(const string& race) const; + size_t GetCupIdx(const string& cup) const; + size_t GetEventIdx(const string& event) const; + const string& GetCup(size_t event, size_t cup) const; + const string& GetCupTrivialName(size_t event, size_t cup) const; - void MakeUnlockList (const string& unlockstr); - bool IsUnlocked (size_t event, size_t cup) const; + void MakeUnlockList(const string& unlockstr); + bool IsUnlocked(size_t event, size_t cup) const; }; extern CEvents Events; @@ -121,7 +121,7 @@ struct TPlayer { class CPlayers { private: vector plyr; - void SetDefaultPlayers (); + void SetDefaultPlayers(); vector avatars; const TAvatar* FindAvatar(const string& name); @@ -129,17 +129,17 @@ public: ~CPlayers(); TPlayer* GetPlayer(size_t index) { return &plyr[index]; } - void AddPassedCup (const string& cup); - void AddPlayer (const string& name, const string& avatar); - bool LoadPlayers (); - void SavePlayers () const; - void ResetControls (); - void AllocControl (size_t player); - void LoadAvatars (); + void AddPassedCup(const string& cup); + void AddPlayer(const string& name, const string& avatar); + bool LoadPlayers(); + void SavePlayers() const; + void ResetControls(); + void AllocControl(size_t player); + void LoadAvatars(); size_t numAvatars() const { return avatars.size(); } size_t numPlayers() const { return plyr.size(); } - TTexture* GetAvatarTexture (size_t avatar) const; + TTexture* GetAvatarTexture(size_t avatar) const; const string& GetDirectAvatarName(size_t avatar) const; }; @@ -166,8 +166,8 @@ public: ~CCharacter(); - void LoadCharacterList (); - void FreeCharacterPreviews (); + void LoadCharacterList(); + void FreeCharacterPreviews(); }; extern CCharacter Char; diff --git a/src/game_over.cpp b/src/game_over.cpp index 9468a4d..cbbed6c 100644 --- a/src/game_over.cpp +++ b/src/game_over.cpp @@ -43,27 +43,27 @@ GNU General Public License for more details. CGameOver GameOver; static CKeyframe *final_frame; -static int highscore_pos = 999; +static int highscore_pos = MAX_SCORES; -void QuitGameOver () { +void QuitGameOver() { if (g_game.game_type == PRACTICING) { - State::manager.RequestEnterState (RaceSelect); + State::manager.RequestEnterState(RaceSelect); } else { - State::manager.RequestEnterState (Event); + State::manager.RequestEnterState(Event); } } -void CGameOver::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CGameOver::Keyb(unsigned int key, bool special, bool release, int x, int y) { if (release) return; - if (key == 13 || key == SDLK_ESCAPE) QuitGameOver (); + if (key == 13 || key == SDLK_ESCAPE) QuitGameOver(); } -void CGameOver::Mouse (int button, int state, int x, int y) { - QuitGameOver (); +void CGameOver::Mouse(int button, int state, int x, int y) { + QuitGameOver(); } -void GameOverMessage (const CControl *ctrl) { +void GameOverMessage(const CControl *ctrl) { int fwidth = 500; int leftframe = (Winsys.resolution.width - fwidth) / 2; @@ -72,82 +72,84 @@ void GameOverMessage (const CControl *ctrl) { const TColor& backcol = colWhite; static const TColor framecol(0.7, 0.7, 1, 1); - if (param.use_papercut_font > 0) FT.SetSize (28); - else FT.SetSize (22); + if (param.use_papercut_font > 0) FT.SetSize(28); + else FT.SetSize(22); if (g_game.raceaborted) { - DrawFrameX (leftframe, topframe, fwidth, 100, 4, backcol, framecol, 0.5); - FT.SetColor (colDBlue); - FT.DrawString (CENTER, topframe+30, Trans.Text(25)); + DrawFrameX(leftframe, topframe, fwidth, 100, 4, backcol, framecol, 0.5); + FT.SetColor(colDBlue); + FT.DrawString(CENTER, topframe+30, Trans.Text(25)); } else { + int firstMarker = leftframe + 60; + int secondMarker = leftframe + 310; DrawFrameX(leftframe, topframe, fwidth, 210, 4, backcol, framecol, 0.5); - if (param.use_papercut_font > 0) FT.SetSize (20); - else FT.SetSize (14); - if (g_game.race_result >= 0 || g_game.game_type != CUPRACING) FT.SetColor (colDBlue); - else FT.SetColor (colDRed); + if (param.use_papercut_font > 0) FT.SetSize(20); + else FT.SetSize(14); + if (g_game.race_result >= 0 || g_game.game_type != CUPRACING) FT.SetColor(colDBlue); + else FT.SetColor(colDRed); - string line = "Score: "; - FT.DrawString (leftframe+80, topframe+15, line); - line = Int_StrN (g_game.score); + string line = Trans.Text(86) + ": "; + FT.DrawString(firstMarker, topframe + 15, line); + line = Int_StrN(g_game.score); line += " pts"; - FT.DrawString (leftframe+240, topframe+15, line); + FT.DrawString(secondMarker, topframe + 15, line); - line = "Herring: "; - FT.DrawString (leftframe+80, topframe+40, line); - line = Int_StrN (g_game.herring); + line = Trans.Text(87) + ": "; + FT.DrawString(firstMarker, topframe + 40, line); + line = Int_StrN(g_game.herring); if (g_game.game_type == CUPRACING) { line += " ("; - line += Int_StrN (g_game.race->herrings.x); + line += Int_StrN(g_game.race->herrings.x); line += ")"; } - FT.DrawString (leftframe+240, topframe+40, line); + FT.DrawString(secondMarker, topframe + 40, line); - line = "Time: "; - FT.DrawString (leftframe+80, topframe+65, line); - line = Float_StrN (g_game.time, 2); + line = Trans.Text(88) + ": "; + FT.DrawString(firstMarker, topframe + 65, line); + line = Float_StrN(g_game.time, 2); line += " s"; if (g_game.game_type == CUPRACING) { line += " ("; - line += Float_StrN (g_game.race->time.x, 2); + line += Float_StrN(g_game.race->time.x, 2); line += ")"; } - FT.DrawString (leftframe+240, topframe+65, line); + FT.DrawString(secondMarker, topframe + 65, line); - line = "Path length: "; - FT.DrawString (leftframe+80, topframe+90, line); - line = Float_StrN (ctrl->way, 2); + line = Trans.Text(89) + ": "; + FT.DrawString(firstMarker, topframe + 90, line); + line = Float_StrN(ctrl->way, 2); line += " m"; - FT.DrawString (leftframe+240, topframe+90, line); + FT.DrawString(secondMarker, topframe + 90, line); - line = "Average speed: "; - FT.DrawString (leftframe+80, topframe+115, line); - line = Float_StrN (ctrl->way / g_game.time * 3.6, 2); + line = Trans.Text(90) + ": "; + FT.DrawString(firstMarker, topframe + 115, line); + line = Float_StrN(ctrl->way / g_game.time * 3.6, 2); line += " km/h"; - FT.DrawString (leftframe+240, topframe+115, line); + FT.DrawString(secondMarker, topframe + 115, line); - if (param.use_papercut_font > 0) FT.SetSize (28); - else FT.SetSize (22); + if (param.use_papercut_font > 0) FT.SetSize(28); + else FT.SetSize(22); if (g_game.game_type == CUPRACING) { switch (g_game.race_result) { case -1: - FT.DrawString (CENTER, topframe+150, Trans.Text(21)); + FT.DrawString(CENTER, topframe+150, Trans.Text(21)); break; case 0: - FT.DrawString (CENTER, topframe+150, Trans.Text(22)); + FT.DrawString(CENTER, topframe+150, Trans.Text(22)); break; case 1: - FT.DrawString (CENTER, topframe+150, Trans.Text(23)); + FT.DrawString(CENTER, topframe+150, Trans.Text(23)); break; case 2: - FT.DrawString (CENTER, topframe+150, Trans.Text(24)); + FT.DrawString(CENTER, topframe+150, Trans.Text(24)); break; } } else { - if (highscore_pos < 5) { - line = "Position "; - line += Int_StrN (highscore_pos + 1); - line += " in highscore list"; - FT.DrawString (CENTER, topframe+150, line); + if (highscore_pos < MAX_SCORES) { + line = Trans.Text(91) + ' '; + line += Int_StrN(highscore_pos + 1); + line += ' ' + Trans.Text(92); + FT.DrawString(CENTER, topframe+150, line); } } } @@ -155,21 +157,19 @@ void GameOverMessage (const CControl *ctrl) { // ========================================================================= void CGameOver::Enter() { - Sound.HaltAll (); - - if (!g_game.raceaborted) highscore_pos = Score.CalcRaceResult (); + if (!g_game.raceaborted) highscore_pos = Score.CalcRaceResult(); if (g_game.game_type == CUPRACING) { if (g_game.race_result >= 0) { - Music.PlayTheme (g_game.theme_id, MUS_WONRACE); + Music.PlayTheme(g_game.theme_id, MUS_WONRACE); } else { - Music.PlayTheme (g_game.theme_id, MUS_LOSTRACE); + Music.PlayTheme(g_game.theme_id, MUS_LOSTRACE); } } else { if (g_game.raceaborted) { - Music.PlayTheme (g_game.theme_id, MUS_LOSTRACE); + Music.PlayTheme(g_game.theme_id, MUS_LOSTRACE); } else { - Music.PlayTheme (g_game.theme_id, MUS_WONRACE); + Music.PlayTheme(g_game.theme_id, MUS_WONRACE); } } @@ -181,14 +181,14 @@ void CGameOver::Enter() { if (g_game.race_result < 0) final_frame = g_game.character->GetKeyframe(LOSTRACE); else final_frame = g_game.character->GetKeyframe(WONRACE); - } else final_frame = g_game.character->GetKeyframe( FINISH); + } else final_frame = g_game.character->GetKeyframe(FINISH); if (!g_game.raceaborted) { const CControl *ctrl = g_game.player->ctrl; - final_frame->Init (ctrl->cpos, -0.18); + final_frame->Init(ctrl->cpos, -0.18); } } - SetStationaryCamera (true); + SetStationaryCamera(true); } @@ -196,38 +196,37 @@ void CGameOver::Loop(double time_step) { CControl *ctrl = g_game.player->ctrl; int width = Winsys.resolution.width; int height = Winsys.resolution.height; - check_gl_error(); - Music.Update (); + Music.Update(); - ClearRenderContext (); - Env.SetupFog (); + ClearRenderContext(); + Env.SetupFog(); - update_view (ctrl, 0); + update_view(ctrl, 0); - if (final_frame != NULL) final_frame->Update (time_step); + if (final_frame != NULL) final_frame->Update(time_step); - SetupViewFrustum (ctrl); - Env.DrawSkybox (ctrl->viewpos); - Env.DrawFog (); - Env.SetupLight (); + SetupViewFrustum(ctrl); + Env.DrawSkybox(ctrl->viewpos); + Env.DrawFog(); + Env.SetupLight(); - RenderCourse (); - DrawTrackmarks (); - DrawTrees (); + RenderCourse(); + DrawTrackmarks(); + DrawTrees(); - UpdateWind (time_step); - UpdateSnow (time_step, ctrl); - DrawSnow (ctrl); + UpdateWind(time_step); + UpdateSnow(time_step, ctrl); + DrawSnow(ctrl); g_game.character->shape->Draw(); ScopedRenderMode rm(GUI); - SetupGuiDisplay (); + SetupGuiDisplay(); if (final_frame != NULL) { - if (!final_frame->active) GameOverMessage (ctrl); - } else GameOverMessage (ctrl); - DrawHud (ctrl); - Reshape (width, height); - Winsys.SwapBuffers (); + if (!final_frame->active) GameOverMessage(ctrl); + } else GameOverMessage(ctrl); + DrawHud(ctrl); + Reshape(width, height); + Winsys.SwapBuffers(); } diff --git a/src/game_type_select.cpp b/src/game_type_select.cpp index b7c6cdf..58c8ed8 100644 --- a/src/game_type_select.cpp +++ b/src/game_type_select.cpp @@ -39,36 +39,36 @@ CGameTypeSelect GameTypeSelect; static TTextButton* textbuttons[7]; -void EnterPractice () { +void EnterPractice() { g_game.game_type = PRACTICING; - State::manager.RequestEnterState (RaceSelect); + State::manager.RequestEnterState(RaceSelect); } -void QuitGameType () { +void QuitGameType() { if (textbuttons[0]->focussed()) - State::manager.RequestEnterState (EventSelect); + State::manager.RequestEnterState(EventSelect); if (textbuttons[1]->focussed()) - EnterPractice (); + EnterPractice(); if (textbuttons[2]->focussed()) - State::manager.RequestEnterState (GameConfig); + State::manager.RequestEnterState(GameConfig); if (textbuttons[3]->focussed()) - State::manager.RequestEnterState (Score); + State::manager.RequestEnterState(Score); if (textbuttons[4]->focussed()) - State::manager.RequestEnterState (Help); + State::manager.RequestEnterState(Help); if (textbuttons[5]->focussed()) - State::manager.RequestEnterState (Credits); + State::manager.RequestEnterState(Credits); if (textbuttons[6]->focussed()) State::manager.RequestQuit(); } -void CGameTypeSelect::Mouse (int button, int state, int x, int y) { +void CGameTypeSelect::Mouse(int button, int state, int x, int y) { if (state == 1) { ClickGUI(x, y); QuitGameType(); } } -void CGameTypeSelect::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CGameTypeSelect::Keyb(unsigned int key, bool special, bool release, int x, int y) { if (release) return; KeyGUI(key, 0, release); @@ -94,55 +94,54 @@ void CGameTypeSelect::Keyb (unsigned int key, bool special, bool release, int x, } } -void CGameTypeSelect::Motion (int x, int y) { +void CGameTypeSelect::Motion(int x, int y) { MouseMoveGUI(x, y); - if (param.ui_snow) push_ui_snow (cursor_pos); + if (param.ui_snow) push_ui_snow(cursor_pos); } // ==================================================================== -void CGameTypeSelect::Enter () { - Winsys.ShowCursor (!param.ice_cursor); +void CGameTypeSelect::Enter() { + Winsys.ShowCursor(!param.ice_cursor); - ResetGUI (); - int top = AutoYPosN (40); - int siz = FT.AutoSizeN (6); - int dist = FT.AutoDistanceN (2); - textbuttons[0] = AddTextButton (Trans.Text(1), CENTER, top, siz); - textbuttons[1] = AddTextButton (Trans.Text(2), CENTER, top + dist, siz); - textbuttons[2] = AddTextButton (Trans.Text(3), CENTER, top + dist * 2, siz); - textbuttons[3] = AddTextButton (Trans.Text(62), CENTER, top + dist * 3, siz); - textbuttons[4] = AddTextButton (Trans.Text(43), CENTER, top + dist * 4, siz); - textbuttons[5] = AddTextButton (Trans.Text(4), CENTER, top + dist * 5, siz); - textbuttons[6] = AddTextButton (Trans.Text(5), CENTER, top + dist * 6, siz); + ResetGUI(); + int top = AutoYPosN(40); + int siz = FT.AutoSizeN(6); + int dist = FT.AutoDistanceN(2); + textbuttons[0] = AddTextButton(Trans.Text(1), CENTER, top, siz); + textbuttons[1] = AddTextButton(Trans.Text(2), CENTER, top + dist, siz); + textbuttons[2] = AddTextButton(Trans.Text(3), CENTER, top + dist * 2, siz); + textbuttons[3] = AddTextButton(Trans.Text(62), CENTER, top + dist * 3, siz); + textbuttons[4] = AddTextButton(Trans.Text(43), CENTER, top + dist * 4, siz); + textbuttons[5] = AddTextButton(Trans.Text(4), CENTER, top + dist * 5, siz); + textbuttons[6] = AddTextButton(Trans.Text(5), CENTER, top + dist * 6, siz); - Music.Play (param.menu_music, -1); + Music.Play(param.menu_music, -1); } -void CGameTypeSelect::Loop (double time_step) { +void CGameTypeSelect::Loop(double time_step) { int ww = Winsys.resolution.width; int hh = Winsys.resolution.height; - check_gl_error(); - Music.Update (); + Music.Update(); ScopedRenderMode rm(GUI); - ClearRenderContext (); - SetupGuiDisplay (); + ClearRenderContext(); + SetupGuiDisplay(); if (param.ui_snow) { - update_ui_snow (time_step); + update_ui_snow(time_step); draw_ui_snow(); } - Tex.Draw (T_TITLE, CENTER, AutoYPosN (5), Winsys.scale); - Tex.Draw (BOTTOM_LEFT, 0, hh-256, 1); - Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); - Tex.Draw (TOP_LEFT, 0, 0, 1); - Tex.Draw (TOP_RIGHT, ww-256, 0, 1); + Tex.Draw(T_TITLE, CENTER, AutoYPosN(5), Winsys.scale); + Tex.Draw(BOTTOM_LEFT, 0, hh-256, 1); + Tex.Draw(BOTTOM_RIGHT, ww-256, hh-256, 1); + Tex.Draw(TOP_LEFT, 0, 0, 1); + Tex.Draw(TOP_RIGHT, ww-256, 0, 1); DrawGUI(); - Reshape (ww, hh); - Winsys.SwapBuffers (); + Reshape(ww, hh); + Winsys.SwapBuffers(); } diff --git a/src/gui.cpp b/src/gui.cpp index deeb0f8..9410827 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -32,7 +32,7 @@ GNU General Public License for more details. static vector Widgets; -static bool Inside (int x, int y, const TRect& Rect) { +static bool Inside(int x, int y, const TRect& Rect) { return (x >= Rect.left && x <= Rect.left + Rect.width && y >= Rect.top @@ -63,9 +63,9 @@ TTextButton::TTextButton(int x, int y, const string& text_, double ftsize_) : TWidget(x, y, 0, 0) , text(text_) , ftsize(ftsize_) { - if (ftsize < 0) ftsize = FT.AutoSizeN (4); + if (ftsize < 0) ftsize = FT.AutoSizeN(4); - double len = FT.GetTextWidth (text); + double len = FT.GetTextWidth(text); if (x == CENTER) position.x = (int)((Winsys.resolution.width - len) / 2); int offs = (int)(ftsize / 5); mouseRect.left = position.x-20; @@ -76,21 +76,21 @@ TTextButton::TTextButton(int x, int y, const string& text_, double ftsize_) void TTextButton::Draw() const { if (focus) - FT.SetColor (colDYell); + FT.SetColor(colDYell); else - FT.SetColor (colWhite); - FT.SetSize (ftsize); - FT.DrawString (position.x, position.y, text); + FT.SetColor(colWhite); + FT.SetSize(ftsize); + FT.DrawString(position.x, position.y, text); } -TTextButton* AddTextButton (const string& text, int x, int y, double ftsize) { +TTextButton* AddTextButton(const string& text, int x, int y, double ftsize) { Widgets.push_back(new TTextButton(x, y, text, ftsize)); return static_cast(Widgets.back()); } -TTextButton* AddTextButtonN (const string& text, int x, int y, int rel_ftsize) { - double siz = FT.AutoSizeN (rel_ftsize); - return AddTextButton (text, x, y, siz); +TTextButton* AddTextButtonN(const string& text, int x, int y, int rel_ftsize) { + double siz = FT.AutoSizeN(rel_ftsize); + return AddTextButton(text, x, y, siz); } @@ -105,22 +105,22 @@ TTextField::TTextField(int x, int y, int width, int height, const string& text_) void TTextField::Draw() const { const TColor& col = focus?colDYell:colWhite; - FT.SetColor (col); - DrawFrameX (mouseRect.left, mouseRect.top, mouseRect.width, mouseRect.height, 3, colMBackgr, col, 1.0); - FT.AutoSizeN (5); - FT.DrawString (mouseRect.left+20, mouseRect.top, text); + FT.SetColor(col); + DrawFrameX(mouseRect.left, mouseRect.top, mouseRect.width, mouseRect.height, 3, colMBackgr, col, 1.0); + FT.AutoSizeN(5); + FT.DrawString(mouseRect.left+20, mouseRect.top, text); if (cursor && focus) { int x = mouseRect.left + 20 + 1; if (cursorPos != 0) { - string temp = text.substr (0, cursorPos); - x += FT.GetTextWidth (temp); + string temp = text.substr(0, cursorPos); + x += FT.GetTextWidth(temp); } int w = 3; int h = 26 * Winsys.scale; int scrheight = Winsys.resolution.height; - glDisable (GL_TEXTURE_2D); + glDisable(GL_TEXTURE_2D); glColor(colYellow); const GLshort vtx[] = { x, scrheight - mouseRect.top - h - 9, @@ -132,18 +132,18 @@ void TTextField::Draw() const { glVertexPointer(2, GL_SHORT, 0, vtx); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); - glEnable (GL_TEXTURE_2D); + glEnable(GL_TEXTURE_2D); } } void TTextField::Key(unsigned int key, unsigned int mod, bool released) { - if (islower (key)) { + if (islower(key)) { if (text.size() < maxLng) { if (mod & KMOD_SHIFT) text.insert(cursorPos, 1, toupper(key)); else text.insert(cursorPos, 1, key); cursorPos++; } - } else if (isdigit (key)) { + } else if (isdigit(key)) { if (text.size() < maxLng) { text.insert(cursorPos, 1, key); cursorPos++; @@ -151,10 +151,10 @@ void TTextField::Key(unsigned int key, unsigned int mod, bool released) { } else { switch (key) { case SDLK_DELETE: - if (cursorPos < text.size()) text.erase (cursorPos, 1); + if (cursorPos < text.size()) text.erase(cursorPos, 1); break; case SDLK_BACKSPACE: - if (cursorPos > 0) { text.erase (cursorPos-1, 1); cursorPos--; } + if (cursorPos > 0) { text.erase(cursorPos-1, 1); cursorPos--; } break; case SDLK_RIGHT: if (cursorPos < text.size()) cursorPos++; @@ -189,15 +189,15 @@ TTextField* AddTextField(const string& text, int x, int y, int width, int height return static_cast(Widgets.back()); } -void TCheckbox::Draw () const { - Tex.Draw (CHECKBOX, position.x + width - 32, position.y, 1.0); +void TCheckbox::Draw() const { + Tex.Draw(CHECKBOX, position.x + width - 32, position.y, 1.0); if (checked) - Tex.Draw (CHECKMARK_SMALL, position.x + width - 32, position.y, 1.0); + Tex.Draw(CHECKMARK_SMALL, position.x + width - 32, position.y, 1.0); if (focus) - FT.SetColor (colDYell); + FT.SetColor(colDYell); else - FT.SetColor (colWhite); - FT.DrawString (position.x, position.y, tag); + FT.SetColor(colWhite); + FT.DrawString(position.x, position.y, tag); } bool TCheckbox::Click(int x, int y) { @@ -216,18 +216,18 @@ void TCheckbox::Key(unsigned int key, unsigned int mod, bool released) { } } -TCheckbox* AddCheckbox (int x, int y, int width, const string& tag) { +TCheckbox* AddCheckbox(int x, int y, int width, const string& tag) { Widgets.push_back(new TCheckbox(x, y, width, tag)); return static_cast(Widgets.back()); } -void TIconButton::SetValue (int _value) { +void TIconButton::SetValue(int _value) { value = _value; if (value > maximum) value = maximum; } -void TIconButton::Draw () const { +void TIconButton::Draw() const { TColor framecol = colWhite; if (focus) framecol = colDYell; @@ -238,13 +238,13 @@ void TIconButton::Draw () const { int x = position.x; int r = x + size; - DrawFrameX (position.x-line, position.y-line, - framesize, framesize, line, colBlack, framecol, 1.0); + DrawFrameX(position.x-line, position.y-line, + framesize, framesize, line, colBlack, framecol, 1.0); - glEnable (GL_TEXTURE_2D); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); texture->Bind(); - glColor4f (1.0, 1.0, 1.0, 1.0); + glColor4f(1.0, 1.0, 1.0, 1.0); const GLshort vtx[] = { x, y, @@ -329,10 +329,10 @@ void TArrow::Draw() const { if (down) type += 3; - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable (GL_TEXTURE_2D); - Tex.BindTex (LB_ARROWS); - glColor4f (1.0, 1.0, 1.0, 1.0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_TEXTURE_2D); + Tex.BindTex(LB_ARROWS); + glColor4f(1.0, 1.0, 1.0, 1.0); const GLfloat tex[] = { textl[type], texbl[type], @@ -448,7 +448,7 @@ TUpDown* AddUpDown(int x, int y, int minimum, int maximum, int value, int distan // ------------------ Elementary drawing --------------------------------------------- -void DrawFrameX (int x, int y, int w, int h, int line, const TColor& backcol, const TColor& framecol, double transp) { +void DrawFrameX(int x, int y, int w, int h, int line, const TColor& backcol, const TColor& framecol, double transp) { float yy = Winsys.resolution.height - y - h; if (x < 0) x = (Winsys.resolution.width -w) / 2; @@ -478,11 +478,11 @@ void DrawFrameX (int x, int y, int w, int h, int line, const TColor& backcol, co glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); - glEnable (GL_TEXTURE_2D); + glEnable(GL_TEXTURE_2D); glPopMatrix(); } -void DrawBonusExt (int y, size_t numraces, size_t num) { +void DrawBonusExt(int y, size_t numraces, size_t num) { size_t maxtux = numraces * 3; if (num > maxtux) return; @@ -502,18 +502,18 @@ void DrawBonusExt (int y, size_t numraces, size_t num) { lleft[1] = xleft + framewidth + 4; lleft[2] = xleft + framewidth + framewidth + 8; - DrawFrameX (lleft[0], y, framewidth, 40, 1, col2, colBlack, 1); - DrawFrameX (lleft[1], y, framewidth, 40, 1, col2, colBlack, 1); - DrawFrameX (lleft[2], y, framewidth, 40, 1, col2, colBlack, 1); - if (param.use_papercut_font > 0) FT.SetSize (20); - else FT.SetSize (15); + DrawFrameX(lleft[0], y, framewidth, 40, 1, col2, colBlack, 1); + DrawFrameX(lleft[1], y, framewidth, 40, 1, col2, colBlack, 1); + DrawFrameX(lleft[2], y, framewidth, 40, 1, col2, colBlack, 1); + if (param.use_papercut_font > 0) FT.SetSize(20); + else FT.SetSize(15); bl.y = Winsys.resolution.height - y - 32 -4; tr.y = Winsys.resolution.height - y - 0 -4; - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable (GL_TEXTURE_2D); - Tex.BindTex (TUXBONUS); - glColor4f (1.0, 1.0, 1.0, 1.0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_TEXTURE_2D); + Tex.BindTex(TUXBONUS); + glColor4f(1.0, 1.0, 1.0, 1.0); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); @@ -552,9 +552,9 @@ void DrawBonusExt (int y, size_t numraces, size_t num) { glDisableClientState(GL_VERTEX_ARRAY); } -void DrawCursor () { - Tex.Draw (MOUSECURSOR, cursor_pos.x, cursor_pos.y, - CURSOR_SIZE * (double)Winsys.resolution.width / 14000); +void DrawCursor() { + Tex.Draw(MOUSECURSOR, cursor_pos.x, cursor_pos.y, + CURSOR_SIZE * (double)Winsys.resolution.width / 14000); } @@ -565,7 +565,7 @@ void DrawGUI() { if (Widgets[i]->GetVisible()) Widgets[i]->Draw(); if (param.ice_cursor) - DrawCursor (); + DrawCursor(); } TWidget* ClickGUI(int x, int y) { @@ -664,7 +664,7 @@ void DecreaseFocus() { Widgets[focussed]->focus = true; } -void ResetGUI () { +void ResetGUI() { for (size_t i = 0; i < Widgets.size(); i++) delete Widgets[i]; Widgets.clear(); @@ -673,16 +673,16 @@ void ResetGUI () { // ------------------ new --------------------------------------------- -int AutoYPosN (double percent) { +int AutoYPosN(double percent) { double hh = (double)Winsys.resolution.height; double po = hh * percent / 100; return (int)(po); } -TArea AutoAreaN (double top_perc, double bott_perc, int w) { +TArea AutoAreaN(double top_perc, double bott_perc, int w) { TArea res; - res.top = AutoYPosN (top_perc); - res.bottom = AutoYPosN (bott_perc); + res.top = AutoYPosN(top_perc); + res.bottom = AutoYPosN(bott_perc); if (w > Winsys.resolution.width) w = Winsys.resolution.width; res.left = (Winsys.resolution.width - w) / 2; res.right = Winsys.resolution.width - res.left; diff --git a/src/gui.h b/src/gui.h index 19c4338..b707ebc 100644 --- a/src/gui.h +++ b/src/gui.h @@ -70,8 +70,8 @@ public: TTextButton(int x, int y, const string& text_, double ftsize_); void Draw() const; }; -TTextButton* AddTextButton (const string& text, int x, int y, double ftsize); -TTextButton* AddTextButtonN (const string& text, int x, int y, int rel_ftsize); +TTextButton* AddTextButton(const string& text, int x, int y, double ftsize); +TTextButton* AddTextButtonN(const string& text, int x, int y, int rel_ftsize); class TTextField : public TWidget { string text; @@ -105,7 +105,7 @@ public: bool Click(int x, int y); void Key(unsigned int key, unsigned int mod, bool released); }; -TCheckbox* AddCheckbox (int x, int y, int width, const string& tag); +TCheckbox* AddCheckbox(int x, int y, int width, const string& tag); class TIconButton : public TWidget { double size; @@ -126,7 +126,7 @@ public: bool Click(int x, int y); void Key(unsigned int key, unsigned int mod, bool released); }; -TIconButton* AddIconButton (int x, int y, TTexture* texture, double size, int maximum, int value); +TIconButton* AddIconButton(int x, int y, TTexture* texture, double size, int maximum, int value); class TArrow : public TWidget { public: @@ -171,14 +171,14 @@ void ResetGUI(); // -------------------------------------------------------------------- -void DrawFrameX (int x, int y, int w, int h, int line, - const TColor& backcol, const TColor& framecol, double transp); -void DrawBonusExt (int y, size_t numraces, size_t num); -void DrawCursor (); +void DrawFrameX(int x, int y, int w, int h, int line, + const TColor& backcol, const TColor& framecol, double transp); +void DrawBonusExt(int y, size_t numraces, size_t num); +void DrawCursor(); // -------------------------------------------------------------------- -int AutoYPosN (double percent); -TArea AutoAreaN (double top_perc, double bott_perc, int w); +int AutoYPosN(double percent); +TArea AutoAreaN(double top_perc, double bott_perc, int w); #endif diff --git a/src/help.cpp b/src/help.cpp index ebe9fe8..5c75ef5 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -34,58 +34,57 @@ CHelp Help; static int ytop; void CHelp::Keyb(unsigned int key, bool special, bool release, int x, int y) { - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); } void CHelp::Mouse(int button, int state, int x, int y) { - if (state == 1) State::manager.RequestEnterState (GameTypeSelect); + if (state == 1) State::manager.RequestEnterState(GameTypeSelect); } void CHelp::Motion(int x, int y) { - if (param.ui_snow) push_ui_snow (cursor_pos); + if (param.ui_snow) push_ui_snow(cursor_pos); } void CHelp::Enter() { - Winsys.ShowCursor (false); - Music.Play (param.credits_music, -1); + Winsys.ShowCursor(false); + Music.Play(param.credits_music, -1); - ytop = AutoYPosN (15); + ytop = AutoYPosN(15); } void CHelp::Loop(double timestep) { - Music.Update (); - check_gl_error(); - ClearRenderContext (); + Music.Update(); + ClearRenderContext(); ScopedRenderMode rm(GUI); - SetupGuiDisplay (); + SetupGuiDisplay(); if (param.ui_snow) { - update_ui_snow (timestep); + update_ui_snow(timestep); draw_ui_snow(); } - FT.AutoSizeN (4); + FT.AutoSizeN(4); FT.SetColor(colWhite); const int xleft1 = 40; - FT.DrawString (xleft1, AutoYPosN (5), Trans.Text (57)); + FT.DrawString(xleft1, AutoYPosN(5), Trans.Text(57)); - FT.AutoSizeN (3); - int offs = FT.AutoDistanceN (2); - FT.DrawString (xleft1, ytop, Trans.Text(44)); - FT.DrawString (xleft1, ytop + offs, Trans.Text(45)); - FT.DrawString (xleft1, ytop + offs * 2, Trans.Text(46)); - FT.DrawString (xleft1, ytop + offs * 3, Trans.Text(47)); - FT.DrawString (xleft1, ytop + offs * 4, Trans.Text(48)); - FT.DrawString (xleft1, ytop + offs * 5, Trans.Text(49)); - FT.DrawString (xleft1, ytop + offs * 6, Trans.Text(50)); - FT.DrawString (xleft1, ytop + offs * 7, Trans.Text(51)); - FT.DrawString (xleft1, ytop + offs * 8,Trans.Text(52)); - FT.DrawString (xleft1, ytop + offs * 9, Trans.Text(53)); - FT.DrawString (xleft1, ytop + offs * 10, Trans.Text(54)); - FT.DrawString (xleft1, ytop + offs * 11, Trans.Text(55)); - FT.DrawString (xleft1, ytop + offs * 12, Trans.Text(56)); + FT.AutoSizeN(3); + int offs = FT.AutoDistanceN(2); + FT.DrawString(xleft1, ytop, Trans.Text(44)); + FT.DrawString(xleft1, ytop + offs, Trans.Text(45)); + FT.DrawString(xleft1, ytop + offs * 2, Trans.Text(46)); + FT.DrawString(xleft1, ytop + offs * 3, Trans.Text(47)); + FT.DrawString(xleft1, ytop + offs * 4, Trans.Text(48)); + FT.DrawString(xleft1, ytop + offs * 5, Trans.Text(49)); + FT.DrawString(xleft1, ytop + offs * 6, Trans.Text(50)); + FT.DrawString(xleft1, ytop + offs * 7, Trans.Text(51)); + FT.DrawString(xleft1, ytop + offs * 8,Trans.Text(52)); + FT.DrawString(xleft1, ytop + offs * 9, Trans.Text(53)); + FT.DrawString(xleft1, ytop + offs * 10, Trans.Text(54)); + FT.DrawString(xleft1, ytop + offs * 11, Trans.Text(55)); + FT.DrawString(xleft1, ytop + offs * 12, Trans.Text(56)); - FT.DrawString (CENTER, AutoYPosN (90), Trans.Text(65)); + FT.DrawString(CENTER, AutoYPosN(90), Trans.Text(65)); Winsys.SwapBuffers(); } diff --git a/src/hud.cpp b/src/hud.cpp index edc1a36..e21cc4e 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -56,17 +56,17 @@ static const TColor text_colour(0, 0, 0, 1); static void draw_time() { int min, sec, hundr; - GetTimeComponents (g_game.time, &min, &sec, &hundr); - string timestr = Int_StrN (min, 2); - string secstr = Int_StrN (sec, 2); - string hundrstr = Int_StrN (hundr, 2); + GetTimeComponents(g_game.time, &min, &sec, &hundr); + string timestr = Int_StrN(min, 2); + string secstr = Int_StrN(sec, 2); + string hundrstr = Int_StrN(hundr, 2); timestr += ":"; timestr += secstr; if (param.use_papercut_font < 2) { - Tex.DrawNumStr (timestr, 20, 10, 1, colWhite); - Tex.DrawNumStr (hundrstr, 136, 10, 0.7, colWhite); + Tex.DrawNumStr(timestr, 50, 12, 1, colWhite); + Tex.DrawNumStr(hundrstr, 170, 12, 0.7, colWhite); } else { /* @@ -76,45 +76,45 @@ static void draw_time() { glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE); glLineWidth (1.5); */ - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - Tex.Draw (T_TIME, 16, 20, 1); - FT.SetColor (colDYell); - FT.SetSize (32); - FT.DrawString (160, 6, hundrstr); - FT.SetSize (42); - FT.DrawString (70, 10, timestr); + Tex.Draw(T_TIME, 16, 20, 1); + FT.SetColor(colDYell); + FT.SetSize(32); + FT.DrawString(160, 6, hundrstr); + FT.SetSize(42); + FT.DrawString(70, 10, timestr); } } -static void draw_herring_count (int herring_count) { - string hcountstr = Int_StrN (herring_count, 3); +static void draw_herring_count(int herring_count) { + string hcountstr = Int_StrN(herring_count, 3); if (param.use_papercut_font < 2) { - Tex.DrawNumStr (hcountstr, Winsys.resolution.width - 90, 10, 1, colWhite); - Tex.Draw (HERRING_ICON, Winsys.resolution.width-160, -20, 1); + Tex.DrawNumStr(hcountstr, Winsys.resolution.width - 90, 10, 1, colWhite); + Tex.Draw(HERRING_ICON, Winsys.resolution.width-160, -20, 1); } else { - FT.SetColor (colDYell); - FT.DrawString ( Winsys.resolution.width - 90, 10, hcountstr); - Tex.Draw (T_YELLHERRING, Winsys.resolution.width-160, 12, 1); + FT.SetColor(colDYell); + FT.DrawString(Winsys.resolution.width - 90, 10, hcountstr); + Tex.Draw(T_YELLHERRING, Winsys.resolution.width-160, 12, 1); } } -TVector2d calc_new_fan_pt (double angle) { +TVector2d calc_new_fan_pt(double angle) { TVector2d pt; - pt.x = ENERGY_GAUGE_CENTER_X + cos (ANGLES_TO_RADIANS (angle)) * SPEEDBAR_OUTER_RADIUS; - pt.y = ENERGY_GAUGE_CENTER_Y + sin (ANGLES_TO_RADIANS (angle)) * SPEEDBAR_OUTER_RADIUS; + pt.x = ENERGY_GAUGE_CENTER_X + cos(ANGLES_TO_RADIANS(angle)) * SPEEDBAR_OUTER_RADIUS; + pt.y = ENERGY_GAUGE_CENTER_Y + sin(ANGLES_TO_RADIANS(angle)) * SPEEDBAR_OUTER_RADIUS; return pt; } void start_tri_fan() { - glBegin (GL_TRIANGLE_FAN); - glVertex2f (ENERGY_GAUGE_CENTER_X, - ENERGY_GAUGE_CENTER_Y); - TVector2d pt = calc_new_fan_pt (SPEEDBAR_BASE_ANGLE); - glVertex2f (pt.x, pt.y); + glBegin(GL_TRIANGLE_FAN); + glVertex2f(ENERGY_GAUGE_CENTER_X, + ENERGY_GAUGE_CENTER_Y); + TVector2d pt = calc_new_fan_pt(SPEEDBAR_BASE_ANGLE); + glVertex2f(pt.x, pt.y); } -void draw_partial_tri_fan (double fraction) { +void draw_partial_tri_fan(double fraction) { bool trifan = false; double angle = SPEEDBAR_BASE_ANGLE + @@ -130,8 +130,8 @@ void draw_partial_tri_fan (double fraction) { trifan = true; } cur_angle -= angle_incr; - TVector2d pt = calc_new_fan_pt (cur_angle); - glVertex2f (pt.x, pt.y); + TVector2d pt = calc_new_fan_pt(cur_angle); + glVertex2f(pt.x, pt.y); } if (cur_angle > angle + EPS) { @@ -140,8 +140,8 @@ void draw_partial_tri_fan (double fraction) { start_tri_fan(); trifan = true; } - TVector2d pt = calc_new_fan_pt (cur_angle); - glVertex2f (pt.x, pt.y); + TVector2d pt = calc_new_fan_pt(cur_angle); + glVertex2f(pt.x, pt.y); } if (trifan) { @@ -149,23 +149,23 @@ void draw_partial_tri_fan (double fraction) { } } -void draw_gauge (double speed, double energy) { +void draw_gauge(double speed, double energy) { static const GLfloat xplane[4] = {1.0 / GAUGE_IMG_SIZE, 0.0, 0.0, 0.0 }; static const GLfloat yplane[4] = {0.0, 1.0 / GAUGE_IMG_SIZE, 0.0, 0.0 }; ScopedRenderMode rm(GAUGE_BARS); - if (Tex.GetTexture (GAUGE_ENERGY) == NULL) return; - if (Tex.GetTexture (GAUGE_SPEED) == NULL) return; - if (Tex.GetTexture (GAUGE_OUTLINE) == NULL) return; + if (Tex.GetTexture(GAUGE_ENERGY) == NULL) return; + if (Tex.GetTexture(GAUGE_SPEED) == NULL) return; + if (Tex.GetTexture(GAUGE_OUTLINE) == NULL) return; - Tex.BindTex (GAUGE_ENERGY); - glTexGenfv (GL_S, GL_OBJECT_PLANE, xplane); - glTexGenfv (GL_T, GL_OBJECT_PLANE, yplane); + Tex.BindTex(GAUGE_ENERGY); + glTexGenfv(GL_S, GL_OBJECT_PLANE, xplane); + glTexGenfv(GL_T, GL_OBJECT_PLANE, yplane); glPushMatrix(); - glTranslatef (Winsys.resolution.width - GAUGE_WIDTH, 0, 0); - Tex.BindTex (GAUGE_ENERGY); + glTranslatef(Winsys.resolution.width - GAUGE_WIDTH, 0, 0); + Tex.BindTex(GAUGE_ENERGY); double y = ENERGY_GAUGE_BOTTOM + energy * ENERGY_GAUGE_HEIGHT; const GLfloat vtx1 [] = { @@ -213,13 +213,13 @@ void draw_gauge (double speed, double energy) { speedbar_frac += speed/SPEEDBAR_GREEN_MAX_SPEED * SPEEDBAR_GREEN_FRACTION; } - glColor4fv (speedbar_background_color); - Tex.BindTex (GAUGE_SPEED); - draw_partial_tri_fan (1.0); - glColor4fv (hud_white); - draw_partial_tri_fan (min (1.0, speedbar_frac)); + glColor4fv(speedbar_background_color); + Tex.BindTex(GAUGE_SPEED); + draw_partial_tri_fan(1.0); + glColor4fv(hud_white); + draw_partial_tri_fan(min(1.0, speedbar_frac)); - glColor4fv (hud_white); + glColor4fv(hud_white); Tex.BindTex(GAUGE_OUTLINE); static const GLshort vtx3 [] = { 0, 0, @@ -236,22 +236,22 @@ void draw_gauge (double speed, double energy) { glPopMatrix(); } -void DrawSpeed (double speed) { - string speedstr = Int_StrN ((int)speed, 3); +void DrawSpeed(double speed) { + string speedstr = Int_StrN((int)speed, 3); if (param.use_papercut_font < 2) { - Tex.DrawNumStr (speedstr, - Winsys.resolution.width - 85, Winsys.resolution.height-74, 1, colWhite); + Tex.DrawNumStr(speedstr, + Winsys.resolution.width - 85, Winsys.resolution.height-74, 1, colWhite); } else { - FT.SetColor (colDDYell); - FT.DrawString (Winsys.resolution.width-82, Winsys.resolution.height-80, speedstr); + FT.SetColor(colDDYell); + FT.DrawString(Winsys.resolution.width-82, Winsys.resolution.height-80, speedstr); } } void DrawWind(float dir, float speed, const CControl *ctrl) { if (g_game.wind_id < 1) return; - Tex.Draw (SPEEDMETER, 0, Winsys.resolution.height-140, 1.0); - glDisable (GL_TEXTURE_2D); + Tex.Draw(SPEEDMETER, 0, Winsys.resolution.height-140, 1.0); + glDisable(GL_TEXTURE_2D); float alpha, red, blue; @@ -264,9 +264,9 @@ void DrawWind(float dir, float speed, const CControl *ctrl) { } blue = 1.0 - red; - glPushMatrix (); - glColor4f (red, 0, blue, alpha); - glTranslatef (72, 66, 0); + glPushMatrix(); + glColor4f(red, 0, blue, alpha); + glTranslatef(72, 66, 0); glRotatef(dir, 0, 0, 1); glEnableClientState(GL_VERTEX_ARRAY); static const int len = 45; @@ -282,8 +282,8 @@ void DrawWind(float dir, float speed, const CControl *ctrl) { // direction indicator float dir_angle = RADIANS_TO_ANGLES(atan2(ctrl->cvel.x, ctrl->cvel.z)); - glColor4f (0, 0.5, 0, 1.0); - glRotatef (dir_angle - dir, 0, 0, 1); + glColor4f(0, 0.5, 0, 1.0); + glRotatef(dir_angle - dir, 0, 0, 1); static const GLshort vtx2 [] = { -2, 0, 2, 0, @@ -293,17 +293,17 @@ void DrawWind(float dir, float speed, const CControl *ctrl) { glVertexPointer(2, GL_SHORT, 0, vtx2); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); - glPopMatrix (); + glPopMatrix(); - glEnable (GL_TEXTURE_2D); + glEnable(GL_TEXTURE_2D); - Tex.Draw (SPEED_KNOB, 64, Winsys.resolution.height - 74, 1.0); - string windstr = Int_StrN ((int)speed, 3); + Tex.Draw(SPEED_KNOB, 64, Winsys.resolution.height - 74, 1.0); + string windstr = Int_StrN((int)speed, 3); if (param.use_papercut_font < 2) { - Tex.DrawNumStr (windstr, 130, Winsys.resolution.height - 55, 1, colWhite); + Tex.DrawNumStr(windstr, 130, Winsys.resolution.height - 55, 1, colWhite); } else { - FT.SetColor (colBlue); - FT.DrawString (130, Winsys.resolution.height - 55, windstr); + FT.SetColor(colBlue); + FT.DrawString(130, Winsys.resolution.height - 55, windstr); } } @@ -328,19 +328,19 @@ void DrawFps() { string fpsstr = Int_StrN((int)averagefps); if (param.use_papercut_font < 2) { - Tex.DrawNumStr (fpsstr, (Winsys.resolution.width - 60) / 2, 10, 1, colWhite); + Tex.DrawNumStr(fpsstr, (Winsys.resolution.width - 60) / 2, 10, 1, colWhite); } else { if (averagefps >= 35) - FT.SetColor (colWhite); + FT.SetColor(colWhite); else - FT.SetColor (colRed); - FT.DrawString ((Winsys.resolution.width - 60) / 2, 10, fpsstr); + FT.SetColor(colRed); + FT.DrawString((Winsys.resolution.width - 60) / 2, 10, fpsstr); } } -void DrawPercentBar (float fact, float x, float y) { - Tex.BindTex (T_ENERGY_MASK); - glColor4f (1.0, 1.0, 1.0, 1.0); +void DrawPercentBar(float fact, float x, float y) { + Tex.BindTex(T_ENERGY_MASK); + glColor4f(1.0, 1.0, 1.0, 1.0); const GLfloat tex[] = { 0, 0, @@ -366,28 +366,28 @@ void DrawPercentBar (float fact, float x, float y) { glDisableClientState(GL_VERTEX_ARRAY); } -void DrawCoursePosition (const CControl *ctrl) { +void DrawCoursePosition(const CControl *ctrl) { double fact = ctrl->cpos.z / Course.GetPlayDimensions().y; if (fact > 1.0) fact = 1.0; - glEnable (GL_TEXTURE_2D); - DrawPercentBar (-fact, Winsys.resolution.width - 48, 280-128); - Tex.Draw (T_MASK_OUTLINE, Winsys.resolution.width - 48, Winsys.resolution.height - 280, 1.0); + glEnable(GL_TEXTURE_2D); + DrawPercentBar(-fact, Winsys.resolution.width - 48, 280-128); + Tex.Draw(T_MASK_OUTLINE, Winsys.resolution.width - 48, Winsys.resolution.height - 280, 1.0); } // ------------------------------------------------------- -void DrawHud (const CControl *ctrl) { +void DrawHud(const CControl *ctrl) { if (!param.show_hud) return; double speed = ctrl->cvel.Length(); - SetupGuiDisplay (); + SetupGuiDisplay(); - draw_gauge (speed * 3.6, ctrl->jump_amt); + draw_gauge(speed * 3.6, ctrl->jump_amt); ScopedRenderMode rm(TEXFONT); draw_time(); - draw_herring_count (g_game.herring); - DrawSpeed (speed * 3.6); - DrawFps (); - DrawCoursePosition (ctrl); - DrawWind (Wind.Angle (), Wind.Speed (), ctrl); + draw_herring_count(g_game.herring); + DrawSpeed(speed * 3.6); + DrawFps(); + DrawCoursePosition(ctrl); + DrawWind(Wind.Angle(), Wind.Speed(), ctrl); } diff --git a/src/hud.h b/src/hud.h index a4e5000..bcee77c 100644 --- a/src/hud.h +++ b/src/hud.h @@ -20,6 +20,6 @@ GNU General Public License for more details. #include "bh.h" -void DrawHud (const CControl *ctrl); +void DrawHud(const CControl *ctrl); #endif diff --git a/src/intro.cpp b/src/intro.cpp index a34dff2..4b66323 100644 --- a/src/intro.cpp +++ b/src/intro.cpp @@ -38,9 +38,9 @@ GNU General Public License for more details. CIntro Intro; static CKeyframe *startframe; -void abort_intro (CControl *ctrl) { - TVector2d start_pt = Course.GetStartPoint (); - State::manager.RequestEnterState (Racing); +void abort_intro(CControl *ctrl) { + TVector2d start_pt = Course.GetStartPoint(); + State::manager.RequestEnterState(Racing); ctrl->orientation_initialized = false; ctrl->view_init = false; ctrl->cpos.x = start_pt.x; @@ -50,7 +50,7 @@ void abort_intro (CControl *ctrl) { // ================================================================= void CIntro::Enter() { CControl *ctrl = g_game.player->ctrl; - TVector2d start_pt = Course.GetStartPoint (); + TVector2d start_pt = Course.GetStartPoint(); ctrl->orientation_initialized = false; ctrl->view_init = false; ctrl->cpos.x = start_pt.x; @@ -68,14 +68,14 @@ void CIntro::Enter() { g_game.race_result = -1; g_game.raceaborted = false; - ctrl->Init (); + ctrl->Init(); ctrl->cvel = TVector3d(0, 0, 0); clear_particles(); - set_view_mode (ctrl, ABOVE); - SetCameraDistance (4.0); - SetStationaryCamera (false); - update_view (ctrl, EPS); + set_view_mode(ctrl, ABOVE); + SetCameraDistance(4.0); + SetStationaryCamera(false); + update_view(ctrl, EPS); size_t num_items = Course.NocollArr.size(); TItem* item_locs = &Course.NocollArr[0]; for (size_t i = 0; i < num_items; i++) { @@ -84,53 +84,52 @@ void CIntro::Enter() { } } - InitSnow (ctrl); - InitWind (); + InitSnow(ctrl); + InitWind(); - Music.PlayTheme (g_game.theme_id, MUS_RACING); + Music.PlayTheme(g_game.theme_id, MUS_RACING); param.show_hud = true; } -void CIntro::Loop (double time_step) { +void CIntro::Loop(double time_step) { CControl *ctrl = g_game.player->ctrl; int width = Winsys.resolution.width; int height = Winsys.resolution.height; - check_gl_error(); if (startframe->active) { - startframe->Update (time_step); - } else State::manager.RequestEnterState (Racing); + startframe->Update(time_step); + } else State::manager.RequestEnterState(Racing); - ClearRenderContext (); - Env.SetupFog (); + ClearRenderContext(); + Env.SetupFog(); - update_view (ctrl, time_step); - SetupViewFrustum (ctrl); + update_view(ctrl, time_step); + SetupViewFrustum(ctrl); - Music.Update (); - Env.DrawSkybox (ctrl->viewpos); + Music.Update(); + Env.DrawSkybox(ctrl->viewpos); - Env.DrawFog (); - Env.SetupLight (); - RenderCourse (); - DrawTrackmarks (); - DrawTrees (); + Env.DrawFog(); + Env.SetupLight(); + RenderCourse(); + DrawTrackmarks(); + DrawTrees(); - UpdateWind (time_step); - UpdateSnow (time_step, ctrl); - DrawSnow (ctrl); + UpdateWind(time_step); + UpdateSnow(time_step, ctrl); + DrawSnow(ctrl); g_game.character->shape->Draw(); - DrawHud (ctrl); + DrawHud(ctrl); - Reshape (width, height); - Winsys.SwapBuffers (); + Reshape(width, height); + Winsys.SwapBuffers(); } // ----------------------------------------------------------------------- -void CIntro::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CIntro::Keyb(unsigned int key, bool special, bool release, int x, int y) { CControl *ctrl = g_game.player->ctrl; if (release) return; - abort_intro (ctrl); + abort_intro(ctrl); } diff --git a/src/keyframe.cpp b/src/keyframe.cpp index 9064b11..3c1537d 100644 --- a/src/keyframe.cpp +++ b/src/keyframe.cpp @@ -52,7 +52,7 @@ static const string highlightnames[numJoints] = { CKeyframe TestFrame; -CKeyframe::CKeyframe () { +CKeyframe::CKeyframe() { keytime = 0; active = false; loaded = false; @@ -60,11 +60,11 @@ CKeyframe::CKeyframe () { keyidx = 0; } -double CKeyframe::interp (double frac, double v1, double v2) { +double CKeyframe::interp(double frac, double v1, double v2) { return frac * v1 + (1.0 - frac) * v2; } -void CKeyframe::Init (const TVector3d& ref_position, double height_correction) { +void CKeyframe::Init(const TVector3d& ref_position, double height_correction) { if (!loaded) return; g_game.character->shape->ResetNode("head"); g_game.character->shape->ResetNode("neck"); @@ -75,10 +75,10 @@ void CKeyframe::Init (const TVector3d& ref_position, double height_correction) { keytime = 0; } -void CKeyframe::Init (const TVector3d& ref_position, double height_correction, CCharShape *shape) { +void CKeyframe::Init(const TVector3d& ref_position, double height_correction, CCharShape *shape) { if (!loaded) return; - shape->ResetNode ("head"); - shape->ResetNode ("neck"); + shape->ResetNode("head"); + shape->ResetNode("neck"); refpos = ref_position; heightcorr = height_correction; active = true; @@ -87,10 +87,10 @@ void CKeyframe::Init (const TVector3d& ref_position, double height_correction, C } -void CKeyframe::InitTest (const TVector3d& ref_position, CCharShape *shape) { +void CKeyframe::InitTest(const TVector3d& ref_position, CCharShape *shape) { if (!loaded) return; - shape->ResetNode ("head"); - shape->ResetNode ("neck"); + shape->ResetNode("head"); + shape->ResetNode("neck"); refpos = ref_position; heightcorr = 0.0; active = true; @@ -98,7 +98,7 @@ void CKeyframe::InitTest (const TVector3d& ref_position, CCharShape *shape) { keytime = 0; } -void CKeyframe::Reset () { +void CKeyframe::Reset() { loaded = false; active = false; loadedfile = ""; @@ -106,24 +106,24 @@ void CKeyframe::Reset () { frames.clear(); } -bool CKeyframe::Load (const string& dir, const string& filename) { +bool CKeyframe::Load(const string& dir, const string& filename) { if (loaded && loadedfile == filename) return true; - CSPList list (1000); + CSPList list(1000); - if (list.Load (dir, filename)) { + if (list.Load(dir, filename)) { frames.resize(list.Count()); for (size_t i=0; iRotateNode ("root", 2, vv); + vv = interp(frac, frames[idx].val[4], frames[idx+1].val[4]); + shape->RotateNode("root", 2, vv); - vv = interp (frac, frames[idx].val[5], frames[idx+1].val[5]); - shape->RotateNode ("root", 1, vv); + vv = interp(frac, frames[idx].val[5], frames[idx+1].val[5]); + shape->RotateNode("root", 1, vv); - vv = interp (frac, frames[idx].val[6], frames[idx+1].val[6]); - shape->RotateNode ("root", 3, vv); + vv = interp(frac, frames[idx].val[6], frames[idx+1].val[6]); + shape->RotateNode("root", 3, vv); - vv = interp (frac, frames[idx].val[7], frames[idx+1].val[7]); - shape->RotateNode ("neck", 3, vv); + vv = interp(frac, frames[idx].val[7], frames[idx+1].val[7]); + shape->RotateNode("neck", 3, vv); - vv = interp (frac, frames[idx].val[8], frames[idx+1].val[8]); - shape->RotateNode ("head", 2, vv); + vv = interp(frac, frames[idx].val[8], frames[idx+1].val[8]); + shape->RotateNode("head", 2, vv); - vv = interp (frac, frames[idx].val[9], frames[idx+1].val[9]); - shape->RotateNode ("left_shldr", 3, vv); + vv = interp(frac, frames[idx].val[9], frames[idx+1].val[9]); + shape->RotateNode("left_shldr", 3, vv); - vv = interp (frac, frames[idx].val[10], frames[idx+1].val[10]); - shape->RotateNode ("right_shldr", 3, vv); + vv = interp(frac, frames[idx].val[10], frames[idx+1].val[10]); + shape->RotateNode("right_shldr", 3, vv); - vv = interp (frac, frames[idx].val[11], frames[idx+1].val[11]); - shape->RotateNode ("left_shldr", 2, vv); + vv = interp(frac, frames[idx].val[11], frames[idx+1].val[11]); + shape->RotateNode("left_shldr", 2, vv); - vv = interp (frac, frames[idx].val[12], frames[idx+1].val[12]); - shape->RotateNode ("right_shldr", 2, vv); + vv = interp(frac, frames[idx].val[12], frames[idx+1].val[12]); + shape->RotateNode("right_shldr", 2, vv); - vv = interp (frac, frames[idx].val[13], frames[idx+1].val[13]); - shape->RotateNode ("left_hip", 3, vv); + vv = interp(frac, frames[idx].val[13], frames[idx+1].val[13]); + shape->RotateNode("left_hip", 3, vv); - vv = interp (frac, frames[idx].val[14], frames[idx+1].val[14]); - shape->RotateNode ("right_hip", 3, vv); + vv = interp(frac, frames[idx].val[14], frames[idx+1].val[14]); + shape->RotateNode("right_hip", 3, vv); - vv = interp (frac, frames[idx].val[15], frames[idx+1].val[15]); - shape->RotateNode ("left_knee", 3, vv); + vv = interp(frac, frames[idx].val[15], frames[idx+1].val[15]); + shape->RotateNode("left_knee", 3, vv); - vv = interp (frac, frames[idx].val[16], frames[idx+1].val[16]); - shape->RotateNode ("right_knee", 3, vv); + vv = interp(frac, frames[idx].val[16], frames[idx+1].val[16]); + shape->RotateNode("right_knee", 3, vv); - vv = interp (frac, frames[idx].val[17], frames[idx+1].val[17]); - shape->RotateNode ("left_ankle", 3, vv); + vv = interp(frac, frames[idx].val[17], frames[idx+1].val[17]); + shape->RotateNode("left_ankle", 3, vv); - vv = interp (frac, frames[idx].val[18], frames[idx+1].val[18]); - shape->RotateNode ("right_ankle", 3, vv); + vv = interp(frac, frames[idx].val[18], frames[idx+1].val[18]); + shape->RotateNode("right_ankle", 3, vv); } -void CKeyframe::CalcKeyframe (size_t idx, CCharShape *shape, const TVector3d& refpos) { +void CKeyframe::CalcKeyframe(size_t idx, CCharShape *shape, const TVector3d& refpos) { double vv; TVector3d pos; @@ -209,57 +209,57 @@ void CKeyframe::CalcKeyframe (size_t idx, CCharShape *shape, const TVector3d& re pos.z = frames[idx].val[3] + refpos.z; pos.y = refpos.y; - shape->ResetRoot (); - shape->ResetJoints (); - shape->TranslateNode (0, pos); + shape->ResetRoot(); + shape->ResetJoints(); + shape->TranslateNode(0, pos); vv = frames[idx].val[4]; - shape->RotateNode ("root", 2, vv); + shape->RotateNode("root", 2, vv); vv = frames[idx].val[5]; - shape->RotateNode ("root", 1, vv); + shape->RotateNode("root", 1, vv); vv = frames[idx].val[6]; - shape->RotateNode ("root", 3, vv); + shape->RotateNode("root", 3, vv); vv = frames[idx].val[7]; - shape->RotateNode ("neck", 3, vv); + shape->RotateNode("neck", 3, vv); vv = frames[idx].val[8]; - shape->RotateNode ("head", 2, vv); + shape->RotateNode("head", 2, vv); vv = frames[idx].val[9]; - shape->RotateNode ("left_shldr", 3, vv); + shape->RotateNode("left_shldr", 3, vv); vv = frames[idx].val[10]; - shape->RotateNode ("right_shldr", 3, vv); + shape->RotateNode("right_shldr", 3, vv); vv = frames[idx].val[11]; - shape->RotateNode ("left_shldr", 2, vv); + shape->RotateNode("left_shldr", 2, vv); vv = frames[idx].val[12]; - shape->RotateNode ("right_shldr", 2, vv); + shape->RotateNode("right_shldr", 2, vv); vv = frames[idx].val[13]; - shape->RotateNode ("left_hip", 3, vv); + shape->RotateNode("left_hip", 3, vv); vv = frames[idx].val[14]; - shape->RotateNode ("right_hip", 3, vv); + shape->RotateNode("right_hip", 3, vv); vv = frames[idx].val[15]; - shape->RotateNode ("left_knee", 3, vv); + shape->RotateNode("left_knee", 3, vv); vv = frames[idx].val[16]; - shape->RotateNode ("right_knee", 3, vv); + shape->RotateNode("right_knee", 3, vv); vv = frames[idx].val[17]; - shape->RotateNode ("left_ankle", 3, vv); + shape->RotateNode("left_ankle", 3, vv); vv = frames[idx].val[18]; - shape->RotateNode ("right_ankle", 3, vv); + shape->RotateNode("right_ankle", 3, vv); } -void CKeyframe::Update (double timestep) { +void CKeyframe::Update(double timestep) { if (!loaded) return; if (!active) return; @@ -278,25 +278,25 @@ void CKeyframe::Update (double timestep) { TVector3d pos; CCharShape *shape = g_game.character->shape; - if (fabs (frames[keyidx].val[0]) < 0.0001) frac = 1.0; + if (fabs(frames[keyidx].val[0]) < 0.0001) frac = 1.0; else frac = (frames[keyidx].val[0] - keytime) / frames[keyidx].val[0]; - pos.x = interp (frac, frames[keyidx].val[1], frames[keyidx+1].val[1]) + refpos.x; - pos.z = interp (frac, frames[keyidx].val[3], frames[keyidx+1].val[3]) + refpos.z; - pos.y = interp (frac, frames[keyidx].val[2], frames[keyidx+1].val[2]); - pos.y += Course.FindYCoord (pos.x, pos.z); + pos.x = interp(frac, frames[keyidx].val[1], frames[keyidx+1].val[1]) + refpos.x; + pos.z = interp(frac, frames[keyidx].val[3], frames[keyidx+1].val[3]) + refpos.z; + pos.y = interp(frac, frames[keyidx].val[2], frames[keyidx+1].val[2]); + pos.y += Course.FindYCoord(pos.x, pos.z); - shape->ResetRoot (); - shape->ResetJoints (); + shape->ResetRoot(); + shape->ResetJoints(); g_game.player->ctrl->cpos = pos; double disp_y = pos.y + TUX_Y_CORR + heightcorr; - shape->ResetNode (0); - shape->TranslateNode (0, TVector3d(pos.x, disp_y, pos.z)); - InterpolateKeyframe (keyidx, frac, shape); + shape->ResetNode(0); + shape->TranslateNode(0, TVector3d(pos.x, disp_y, pos.z)); + InterpolateKeyframe(keyidx, frac, shape); } -void CKeyframe::UpdateTest (double timestep, CCharShape *shape) { +void CKeyframe::UpdateTest(double timestep, CCharShape *shape) { if (!active) return; keytime += timestep; @@ -313,52 +313,52 @@ void CKeyframe::UpdateTest (double timestep, CCharShape *shape) { double frac; TVector3d pos; - if (fabs (frames[keyidx].val[0]) < 0.0001) frac = 1.0; + if (fabs(frames[keyidx].val[0]) < 0.0001) frac = 1.0; else frac = (frames[keyidx].val[0] - keytime) / frames[keyidx].val[0]; - pos.x = interp (frac, frames[keyidx].val[1], frames[keyidx+1].val[1]) + refpos.x; - pos.z = interp (frac, frames[keyidx].val[3], frames[keyidx+1].val[3]) + refpos.z; - pos.y = interp (frac, frames[keyidx].val[2], frames[keyidx+1].val[2]); + pos.x = interp(frac, frames[keyidx].val[1], frames[keyidx+1].val[1]) + refpos.x; + pos.z = interp(frac, frames[keyidx].val[3], frames[keyidx+1].val[3]) + refpos.z; + pos.y = interp(frac, frames[keyidx].val[2], frames[keyidx+1].val[2]); - shape->ResetRoot (); - shape->ResetJoints (); - shape->TranslateNode (0, pos); - InterpolateKeyframe (keyidx, frac, shape); + shape->ResetRoot(); + shape->ResetJoints(); + shape->TranslateNode(0, pos); + InterpolateKeyframe(keyidx, frac, shape); } -void CKeyframe::ResetFrame2 (TKeyframe *frame) { +void CKeyframe::ResetFrame2(TKeyframe *frame) { for (int i=1; i<32; i++) frame->val[i] = 0.0; frame->val[0] = 0.5; // time } -TKeyframe *CKeyframe::GetFrame (size_t idx) { +TKeyframe *CKeyframe::GetFrame(size_t idx) { if (idx >= frames.size()) return NULL; return &frames[idx]; } -const string& CKeyframe::GetJointName (size_t idx) { +const string& CKeyframe::GetJointName(size_t idx) { if (idx >= numJoints) return emptyString; return jointnames[idx]; } -const string& CKeyframe::GetHighlightName (size_t idx) { +const string& CKeyframe::GetHighlightName(size_t idx) { if (idx >= numJoints) return emptyString; return highlightnames[idx]; } -int CKeyframe::GetNumJoints () { +int CKeyframe::GetNumJoints() { return numJoints; } -void CKeyframe::SaveTest (const string& dir, const string& filename) { - CSPList list (100); +void CKeyframe::SaveTest(const string& dir, const string& filename) { + CSPList list(100); for (size_t i=0; ival[0], 1); - line += " [pos] " + Float_StrN (frame->val[1], 2); - line += " " + Float_StrN (frame->val[2], 2); - line += " " + Float_StrN (frame->val[3], 2); + string line = "*[time] " + Float_StrN(frame->val[0], 1); + line += " [pos] " + Float_StrN(frame->val[1], 2); + line += " " + Float_StrN(frame->val[2], 2); + line += " " + Float_StrN(frame->val[3], 2); if (frame->val[4] != 0) line += " [yaw] " + Int_StrN((int)frame->val[4]); if (frame->val[5] != 0) line += " [pitch] " + Int_StrN((int)frame->val[5]); if (frame->val[6] != 0) line += " [roll] " + Int_StrN((int)frame->val[6]); @@ -390,23 +390,23 @@ void CKeyframe::SaveTest (const string& dir, const string& filename) { if (ll != 0 || rr != 0) line += " [ankle] " + Int_StrN((int)ll) + " " + Int_StrN((int)rr); - list.Add (line); + list.Add(line); } - list.Save (dir, filename); + list.Save(dir, filename); } -void CKeyframe::CopyFrame (size_t prim_idx, size_t sec_idx) { +void CKeyframe::CopyFrame(size_t prim_idx, size_t sec_idx) { TKeyframe *ppp = &frames[prim_idx]; TKeyframe *sss = &frames[sec_idx]; memcpy(sss->val, ppp->val, MAX_FRAME_VALUES*sizeof(*sss->val)); } -void CKeyframe::AddFrame () { +void CKeyframe::AddFrame() { frames.push_back(TKeyframe()); - ResetFrame2 (&frames.back()); + ResetFrame2(&frames.back()); } -size_t CKeyframe::DeleteFrame (size_t idx) { +size_t CKeyframe::DeleteFrame(size_t idx) { if (frames.size() < 2) return idx; size_t lastframe = frames.size()-1; if (idx > lastframe) return 0; @@ -416,33 +416,33 @@ size_t CKeyframe::DeleteFrame (size_t idx) { return frames.size()-1; } else { - for (size_t i=idx; i lastframe) return; frames.push_back(TKeyframe()); - for (size_t i=frames.size()-1; i>idx; i--) CopyFrame (i-1, i); - ResetFrame2 (&frames[idx]); + for (size_t i=frames.size()-1; i>idx; i--) CopyFrame(i-1, i); + ResetFrame2(&frames[idx]); } -void CKeyframe::CopyToClipboard (size_t idx) { +void CKeyframe::CopyToClipboard(size_t idx) { if (idx >= frames.size()) return; memcpy(clipboard.val, frames[idx].val, MAX_FRAME_VALUES*sizeof(*frames[idx].val)); } -void CKeyframe::PasteFromClipboard (size_t idx) { +void CKeyframe::PasteFromClipboard(size_t idx) { if (idx >= frames.size()) return; memcpy(frames[idx].val, clipboard.val, MAX_FRAME_VALUES*sizeof(*frames[idx].val)); } -void CKeyframe::ClearFrame (size_t idx) { +void CKeyframe::ClearFrame(size_t idx) { if (idx >= frames.size()) return; - ResetFrame2 (&frames[idx]); + ResetFrame2(&frames[idx]); } diff --git a/src/keyframe.h b/src/keyframe.h index b451824..1824401 100644 --- a/src/keyframe.h +++ b/src/keyframe.h @@ -39,38 +39,38 @@ private: double heightcorr; size_t keyidx; - double interp (double frac, double v1, double v2); - void InterpolateKeyframe (size_t idx, double frac, CCharShape *shape); + double interp(double frac, double v1, double v2); + void InterpolateKeyframe(size_t idx, double frac, CCharShape *shape); // test and editing - void ResetFrame2 (TKeyframe *frame); + void ResetFrame2(TKeyframe *frame); public: - CKeyframe (); + CKeyframe(); bool loaded; bool active; - void Init (const TVector3d& ref_position, double height_correction); - void Init (const TVector3d& ref_position, double height_correction, CCharShape *shape); - void InitTest (const TVector3d& ref_position, CCharShape *shape); - void Reset (); - void Update (double timestep); - void UpdateTest (double timestep, CCharShape *shape); - bool Load (const string& dir, const string& filename); - void CalcKeyframe (size_t idx, CCharShape *shape, const TVector3d& refpos); + void Init(const TVector3d& ref_position, double height_correction); + void Init(const TVector3d& ref_position, double height_correction, CCharShape *shape); + void InitTest(const TVector3d& ref_position, CCharShape *shape); + void Reset(); + void Update(double timestep); + void UpdateTest(double timestep, CCharShape *shape); + bool Load(const string& dir, const string& filename); + void CalcKeyframe(size_t idx, CCharShape *shape, const TVector3d& refpos); // test and editing - TKeyframe *GetFrame (size_t idx); - static const string& GetHighlightName (size_t idx); - static const string& GetJointName (size_t idx); - static int GetNumJoints (); - void SaveTest (const string& dir, const string& filename); - void CopyFrame (size_t prim_idx, size_t sec_idx); - void AddFrame (); - size_t DeleteFrame (size_t idx); - void InsertFrame (size_t idx); - void CopyToClipboard (size_t idx); - void PasteFromClipboard (size_t idx); - void ClearFrame (size_t idx); + TKeyframe *GetFrame(size_t idx); + static const string& GetHighlightName(size_t idx); + static const string& GetJointName(size_t idx); + static int GetNumJoints(); + void SaveTest(const string& dir, const string& filename); + void CopyFrame(size_t prim_idx, size_t sec_idx); + void AddFrame(); + size_t DeleteFrame(size_t idx); + void InsertFrame(size_t idx); + void CopyToClipboard(size_t idx); + void PasteFromClipboard(size_t idx); + void ClearFrame(size_t idx); size_t numFrames() const { return frames.size(); } }; diff --git a/src/loading.cpp b/src/loading.cpp index d90526d..255a8b6 100644 --- a/src/loading.cpp +++ b/src/loading.cpp @@ -36,8 +36,8 @@ CLoading Loading; // ==================================================================== void CLoading::Enter() { - Winsys.ShowCursor (false); - Music.Play ("loading", -1); + Winsys.ShowCursor(false); + Music.Play("loading", -1); } void CLoading::Loop(double time_step) { @@ -46,35 +46,34 @@ void CLoading::Loop(double time_step) { int ww = Winsys.resolution.width; int hh = Winsys.resolution.height; string msg = Trans.Text(29) + " " + g_game.course->name; - check_gl_error (); ScopedRenderMode rm(GUI); - ClearRenderContext (); - SetupGuiDisplay (); + ClearRenderContext(); + SetupGuiDisplay(); if (param.ui_snow) { - update_ui_snow (time_step); - draw_ui_snow (); + update_ui_snow(time_step); + draw_ui_snow(); } - Tex.Draw (TEXLOGO, CENTER, 40, 0.7); - Tex.Draw (BOTTOM_LEFT, 0, hh-256, 1); - Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); - Tex.Draw (TOP_LEFT, 0, 0, 1); - Tex.Draw (TOP_RIGHT, ww-256, 0, 1); + Tex.Draw(TEXLOGO, CENTER, 40, 0.6); + Tex.Draw(BOTTOM_LEFT, 0, hh-256, 1); + Tex.Draw(BOTTOM_RIGHT, ww-256, hh-256, 1); + Tex.Draw(TOP_LEFT, 0, 0, 1); + Tex.Draw(TOP_RIGHT, ww-256, 0, 1); - FT.SetColor (colDYell); - FT.AutoSizeN (5); - FT.DrawString (CENTER, AutoYPosN (60), msg); - FT.SetColor (colWhite); - FT.DrawString (CENTER, AutoYPosN (70), Trans.Text (30)); - Winsys.SwapBuffers (); + FT.SetColor(colDYell); + FT.AutoSizeN(5); + FT.DrawString(CENTER, AutoYPosN(60), msg); + FT.SetColor(colWhite); + FT.DrawString(CENTER, AutoYPosN(70), Trans.Text(30)); + Winsys.SwapBuffers(); - Course.LoadCourse (g_game.course); - g_game.location_id = Course.GetEnv (); - Env.LoadEnvironment (g_game.location_id, g_game.light_id); - State::manager.RequestEnterState (Intro); + Course.LoadCourse(g_game.course); + g_game.location_id = Course.GetEnv(); + Env.LoadEnvironment(g_game.location_id, g_game.light_id); + State::manager.RequestEnterState(Intro); } void CLoading::Exit() { - Music.Halt (); + Music.Halt(); } diff --git a/src/main.cpp b/src/main.cpp index 06562b6..caf1477 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,7 @@ GNU General Public License for more details. TGameData g_game; -void InitGame (int argc, char **argv) { +void InitGame(int argc, char **argv) { g_game.toolmode = NONE; g_game.argument = 0; if (argc == 4) { @@ -55,7 +55,7 @@ void InitGame (int argc, char **argv) { g_game.snow_id = 0; g_game.cup = 0; g_game.theme_id = 0; - g_game.force_treemap = 0; + g_game.force_treemap = false; g_game.treesize = 3; g_game.treevar = 3; } @@ -68,28 +68,28 @@ void InitGame (int argc, char **argv) { #undef main #endif -int main( int argc, char **argv ) { +int main(int argc, char **argv) { // **************************************************************** cout << "\n----------- Extreme Tux Racer " ETR_VERSION_STRING " ----------------"; cout << "\n----------- (C) 2010-2013 Extreme Tuxracer Team --------\n\n"; - srand (time (NULL)); - InitConfig (argv[0]); - InitGame (argc, argv); - Winsys.Init (); - InitOpenglExtensions (); + srand(time(NULL)); + InitConfig(); + InitGame(argc, argv); + Winsys.Init(); + InitOpenglExtensions(); // for checking the joystick and the OpgenGL version (the info is // written on the console): // Winsys.PrintJoystickInfo (); // PrintGLInfo (); // theses resources must or should be loaded before splashscreen starts - Tex.LoadTextureList (); - FT.LoadFontlist (); - Winsys.SetFonttype (); - Audio.Open (); - Music.LoadMusicList (); - Music.SetVolume (param.music_volume); + Tex.LoadTextureList(); + FT.LoadFontlist(); + FT.SetFontFromSettings(); + Audio.Open(); + Music.LoadMusicList(); + Music.SetVolume(param.music_volume); switch (g_game.argument) { case 0: diff --git a/src/mathlib.cpp b/src/mathlib.cpp index 24fa02b..1744782 100644 --- a/src/mathlib.cpp +++ b/src/mathlib.cpp @@ -25,8 +25,8 @@ GNU General Public License for more details. #include -TVector3d ProjectToPlane (const TVector3d& nml, const TVector3d& v) { - double dotProd = DotProduct (nml, v); +TVector3d ProjectToPlane(const TVector3d& nml, const TVector3d& v) { + double dotProd = DotProduct(nml, v); TVector3d nmlComp = dotProd * nml; return v - nmlComp; @@ -60,7 +60,7 @@ TVector3d TransformPoint(const TMatrix<4, 4>& mat, const TVector3d& p) { return r; } -bool IntersectPlanes (const TPlane& s1, const TPlane& s2, const TPlane& s3, TVector3d *p) { +bool IntersectPlanes(const TPlane& s1, const TPlane& s2, const TPlane& s3, TVector3d *p) { double A[3][4]; double x[3]; double retval; @@ -80,7 +80,7 @@ bool IntersectPlanes (const TPlane& s1, const TPlane& s2, const TPlane& s3, TVec A[2][2] = s3.nml.z; A[2][3] = -s3.d; - retval = Gauss ((double*) A, 3, x); + retval = Gauss((double*) A, 3, x); if (retval != 0) { return false; @@ -92,7 +92,7 @@ bool IntersectPlanes (const TPlane& s1, const TPlane& s2, const TPlane& s3, TVec } } -double DistanceToPlane (const TPlane& plane, const TVector3d& pt) { +double DistanceToPlane(const TPlane& plane, const TVector3d& pt) { return DotProduct(plane.nml, pt) + plane.d; @@ -107,7 +107,7 @@ TMatrix<4, 4> RotateAboutVectorMatrix(const TVector3d& u, double angle) { double b = u.y; double c = u.z; - double d = sqrt (b*b + c*c); + double d = sqrt(b*b + c*c); if (d < EPS) { if (a < 0) @@ -151,7 +151,7 @@ TMatrix<4, 4> RotateAboutVectorMatrix(const TVector3d& u, double angle) { return mat; } -TQuaternion MultiplyQuaternions (const TQuaternion& q, const TQuaternion& r) { +TQuaternion MultiplyQuaternions(const TQuaternion& q, const TQuaternion& r) { TQuaternion res; res.x = q.y * r.z - q.z * r.y + r.w * q.x + q.w * r.x; res.y = q.z * r.x - q.x * r.z + r.w * q.y + q.w * r.y; @@ -160,7 +160,7 @@ TQuaternion MultiplyQuaternions (const TQuaternion& q, const TQuaternion& r) { return res; } -TQuaternion ConjugateQuaternion (const TQuaternion& q) { +TQuaternion ConjugateQuaternion(const TQuaternion& q) { TQuaternion res( -1 * q.x, -1 * q.y, @@ -172,17 +172,17 @@ TQuaternion ConjugateQuaternion (const TQuaternion& q) { TMatrix<4, 4> MakeMatrixFromQuaternion(const TQuaternion& q) { TMatrix<4, 4> mat; - mat[0][0] = 1.0 - 2.0 * (q.y * q.y + q.z * q.z); - mat[1][0] = 2.0 * (q.x * q.y - q.w * q.z); - mat[2][0] = 2.0 * (q.x * q.z + q.w * q.y); + mat[0][0] = 1.0 - 2.0 * (q.y * q.y + q.z * q.z); + mat[1][0] = 2.0 * (q.x * q.y - q.w * q.z); + mat[2][0] = 2.0 * (q.x * q.z + q.w * q.y); - mat[0][1] = 2.0 * (q.x * q.y + q.w * q.z); - mat[1][1] = 1.0 - 2.0 * (q.x * q.x + q.z * q.z); - mat[2][1] = 2.0 * (q.y * q.z - q.w * q.x); + mat[0][1] = 2.0 * (q.x * q.y + q.w * q.z); + mat[1][1] = 1.0 - 2.0 * (q.x * q.x + q.z * q.z); + mat[2][1] = 2.0 * (q.y * q.z - q.w * q.x); - mat[0][2] = 2.0 * (q.x * q.z - q.w * q.y); - mat[1][2] = 2.0 * (q.y * q.z + q.w * q.x); - mat[2][2] = 1.0 - 2.0 * (q.x * q.x + q.y * q.y); + mat[0][2] = 2.0 * (q.x * q.z - q.w * q.y); + mat[1][2] = 2.0 * (q.y * q.z + q.w * q.x); + mat[2][2] = 1.0 - 2.0 * (q.x * q.x + q.y * q.y); mat[3][0] = mat[3][1] = mat[3][2] = 0.0; mat[0][3] = mat[1][3] = mat[2][3] = 0.0; @@ -199,7 +199,7 @@ TQuaternion MakeQuaternionFromMatrix(const TMatrix<4, 4>& m) { tr = m[0][0] + m[1][1] + m[2][2]; if (tr > 0.0) { - s = sqrt (tr + 1.0); + s = sqrt(tr + 1.0); res.w = 0.5 * s; s = 0.5 / s; res.x = (m[1][2] - m[2][1]) * s; @@ -212,7 +212,7 @@ TQuaternion MakeQuaternionFromMatrix(const TMatrix<4, 4>& m) { int j = nxt[i]; int k = nxt[j]; - s = sqrt (m[i][i] - m[j][j] - m[k][k] + 1.0); + s = sqrt(m[i][i] - m[j][j] - m[k][k] + 1.0); q[i] = s * 0.5; @@ -231,17 +231,17 @@ TQuaternion MakeQuaternionFromMatrix(const TMatrix<4, 4>& m) { return res; } -TQuaternion MakeRotationQuaternion (const TVector3d& s, const TVector3d& t) { - TVector3d u = CrossProduct (s, t); +TQuaternion MakeRotationQuaternion(const TVector3d& s, const TVector3d& t) { + TVector3d u = CrossProduct(s, t); double sin2phi = u.Norm(); if (sin2phi < EPS) { - return TQuaternion (0., 0., 0., 1.); + return TQuaternion(0., 0., 0., 1.); } else { - double cos2phi = DotProduct (s, t); + double cos2phi = DotProduct(s, t); - double sinphi = sqrt ( (1 - cos2phi) / 2.0); - double cosphi = sqrt ( (1 + cos2phi) / 2.0); + double sinphi = sqrt((1 - cos2phi) / 2.0); + double cosphi = sqrt((1 + cos2phi) / 2.0); return TQuaternion( sinphi * u.x, @@ -251,7 +251,7 @@ TQuaternion MakeRotationQuaternion (const TVector3d& s, const TVector3d& t) { } } -TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double t) { +TQuaternion InterpolateQuaternions(const TQuaternion& q, TQuaternion r, double t) { double cosphi = q.x * r.x + q.y * r.y + q.z * r.z + q.w * r.w; if (cosphi < 0.0) { @@ -264,10 +264,10 @@ TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double double scale0, scale1; if (1.0 - cosphi > EPS) { - double phi = acos (cosphi); - double sinphi = sin (phi); - scale0 = sin (phi * (1.0 - t)) / sinphi; - scale1 = sin (phi * t) / sinphi; + double phi = acos(cosphi); + double sinphi = sin(phi); + scale0 = sin(phi * (1.0 - t)) / sinphi; + scale1 = sin(phi * t) / sinphi; } else { scale0 = 1.0 - t; scale1 = t; @@ -276,12 +276,12 @@ TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double return scale0 * q + scale1 * r; } -TVector3d RotateVector (const TQuaternion& q, const TVector3d& v) { +TVector3d RotateVector(const TQuaternion& q, const TVector3d& v) { TQuaternion p(v.x, v.y, v.z, 1.0); TQuaternion qs(-q.x, -q.y, -q.z, q.w); - TQuaternion res_q = MultiplyQuaternions (q, MultiplyQuaternions (p, qs)); + TQuaternion res_q = MultiplyQuaternions(q, MultiplyQuaternions(p, qs)); return res_q; } @@ -290,9 +290,9 @@ TVector3d RotateVector (const TQuaternion& q, const TVector3d& v) { // Gauss // -------------------------------------------------------------------- -bool order (double *matrix, int n, int pivot); -void elim (double *matrix, int n, int pivot); -void backsb (double *matrix, int n, double *soln); +bool order(double *matrix, int n, int pivot); +void elim(double *matrix, int n, int pivot); +void backsb(double *matrix, int n, double *soln); int Gauss(double *matrix, int n, double *soln) { int pivot = 0; @@ -312,7 +312,7 @@ int Gauss(double *matrix, int n, double *soln) { return 0; } -bool order (double *matrix, int n, int pivot) { +bool order(double *matrix, int n, int pivot) { bool error = false; int rmax = pivot; @@ -334,7 +334,7 @@ bool order (double *matrix, int n, int pivot) { return error; } -void elim (double *matrix, int n, int pivot) { +void elim(double *matrix, int n, int pivot) { for (int row = pivot+1; row < n; row++) { double factor = (*(matrix+row*(n+1)+pivot))/(*(matrix+pivot*(n+1)+pivot)); *(matrix+row*(n+1)+pivot)=0.0; @@ -346,7 +346,7 @@ void elim (double *matrix, int n, int pivot) { } -void backsb (double *matrix, int n, double *soln) { +void backsb(double *matrix, int n, double *soln) { for (int row = n-1; row >=0; row--) { for (int col = n-1; col >= row+1; col--) { *(matrix+row*(n+1)+(n)) = *(matrix+row*(n+1)+n) - @@ -364,17 +364,17 @@ bool IntersectPolygon(const TPolygon& p, vector& v) { double d, s, nuDotProd; double distsq; - TVector3d nml = MakeNormal (p, &v[0]); + TVector3d nml = MakeNormal(p, &v[0]); ray.pt = TVector3d(0., 0., 0.); ray.vec = nml; - nuDotProd = DotProduct (nml, ray.vec); + nuDotProd = DotProduct(nml, ray.vec); if (fabs(nuDotProd) < EPS) return false; d = - DotProduct(nml, v[p.vertices[0]]); - if (fabs (d) > 1) return false; + if (fabs(d) > 1) return false; for (size_t i=0; i < p.vertices.size(); i++) { TVector3d *v0, *v1; @@ -385,28 +385,28 @@ bool IntersectPolygon(const TPolygon& p, vector& v) { TVector3d edge_vec = *v1 - *v0; double edge_len = edge_vec.Norm(); - double t = - DotProduct (*v0, edge_vec); + double t = - DotProduct(*v0, edge_vec); if (t < 0) { - distsq = MAG_SQD (*v0); + distsq = MAG_SQD(*v0); } else if (t > edge_len) { - distsq = MAG_SQD (*v1); + distsq = MAG_SQD(*v1); } else { *v0 += t * edge_vec; - distsq = MAG_SQD (*v0); + distsq = MAG_SQD(*v0); } if (distsq <= 1) return true; } - s = - (d + DotProduct (nml, ray.pt)) / nuDotProd; + s = - (d + DotProduct(nml, ray.pt)) / nuDotProd; TVector3d pt = ray.pt + s * ray.vec; for (size_t i = 0; i < p.vertices.size(); i++) { - TVector3d edge_nml = CrossProduct (nml, - v[p.vertices[(i + 1) % p.vertices.size()]] - v[p.vertices[i]]); + TVector3d edge_nml = CrossProduct(nml, + v[p.vertices[(i + 1) % p.vertices.size()]] - v[p.vertices[i]]); - double wec = DotProduct (pt - v[p.vertices[i]], edge_nml); + double wec = DotProduct(pt - v[p.vertices[i]], edge_nml); if (wec < 0) return false; } return true; @@ -415,25 +415,25 @@ bool IntersectPolygon(const TPolygon& p, vector& v) { bool IntersectPolyhedron(TPolyhedron& p) { bool hit = false; for (size_t i = 0; i < p.polygons.size(); i++) { - hit = IntersectPolygon (p.polygons[i], p.vertices); + hit = IntersectPolygon(p.polygons[i], p.vertices); if (hit == true) break; } return hit; } -TVector3d MakeNormal (const TPolygon& p, const TVector3d *v) { +TVector3d MakeNormal(const TPolygon& p, const TVector3d *v) { TVector3d v1 = v[p.vertices[1]] - v[p.vertices[0]]; TVector3d v2 = v[p.vertices[p.vertices.size() - 1]] - v[p.vertices[0]]; - TVector3d normal = CrossProduct (v1, v2); + TVector3d normal = CrossProduct(v1, v2); normal.Norm(); return normal; } -void TransPolyhedron (const TMatrix<4, 4>& mat, TPolyhedron& ph) { +void TransPolyhedron(const TMatrix<4, 4>& mat, TPolyhedron& ph) { for (size_t i = 0; i < ph.vertices.size(); i++) - ph.vertices[i] = TransformPoint (mat, ph.vertices[i]); + ph.vertices[i] = TransformPoint(mat, ph.vertices[i]); } // -------------------------------------------------------------------- @@ -453,7 +453,7 @@ const double ode23_time_step_exp = 1./3.; int ode23_NumEstimates() {return 4; } -void ode23_InitOdeData (TOdeData *data, double init_val, double h) { +void ode23_InitOdeData(TOdeData *data, double init_val, double h) { data->init_val = init_val; data->h = h; } @@ -462,7 +462,7 @@ double ode23_NextTime(TOdeData *data, int step) { return ode23_time_step_mat[step] * data->h; } -double ode23_NextValue (TOdeData *data, int step) { +double ode23_NextValue(TOdeData *data, int step) { double val = data->init_val; for (int i=0; i& mat, const TVector3d& v); TVector3d TransformNormal(const TVector3d& n, const TMatrix<4, 4>& mat); // not used ? TVector3d TransformPoint(const TMatrix<4, 4>& mat, const TVector3d& p); -bool IntersectPlanes (const TPlane& s1, const TPlane& s2, const TPlane& s3, TVector3d *p); -double DistanceToPlane (const TPlane& plane, const TVector3d& pt); +bool IntersectPlanes(const TPlane& s1, const TPlane& s2, const TPlane& s3, TVector3d *p); +double DistanceToPlane(const TPlane& plane, const TVector3d& pt); TMatrix<4, 4> RotateAboutVectorMatrix(const TVector3d& u, double angle); -TQuaternion MultiplyQuaternions (const TQuaternion& q, const TQuaternion& r); -TQuaternion ConjugateQuaternion (const TQuaternion& q); +TQuaternion MultiplyQuaternions(const TQuaternion& q, const TQuaternion& r); +TQuaternion ConjugateQuaternion(const TQuaternion& q); TMatrix<4, 4> MakeMatrixFromQuaternion(const TQuaternion& q); TQuaternion MakeQuaternionFromMatrix(const TMatrix<4, 4>& mat); -TQuaternion MakeRotationQuaternion (const TVector3d& s, const TVector3d& t); -TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double t); -TVector3d RotateVector (const TQuaternion& q, const TVector3d& v); +TQuaternion MakeRotationQuaternion(const TVector3d& s, const TVector3d& t); +TQuaternion InterpolateQuaternions(const TQuaternion& q, TQuaternion r, double t); +TVector3d RotateVector(const TQuaternion& q, const TVector3d& v); -bool IntersectPolygon (const TPolygon& p, vector& v); -bool IntersectPolyhedron (TPolyhedron& p); -TVector3d MakeNormal (const TPolygon& p, const TVector3d *v); +bool IntersectPolygon(const TPolygon& p, vector& v); +bool IntersectPolyhedron(TPolyhedron& p); +TVector3d MakeNormal(const TPolygon& p, const TVector3d *v); void TransPolyhedron(const TMatrix<4, 4>& mat, TPolyhedron& ph); // -------------------------------------------------------------------- @@ -78,14 +78,14 @@ struct TOdeData { double h; }; -typedef int (*PNumEstimates) (); -typedef void (*PInitOdeData) (TOdeData *, double init_val, double h); -typedef double (*PNextTime) (TOdeData *, int step); -typedef double (*PNextValue) (TOdeData *, int step); -typedef void (*PUpdateEstimate) (TOdeData *, int step, double val); -typedef double (*PFinalEstimate) (TOdeData *); -typedef double (*PEstimateError) (TOdeData *); -typedef double (*PTimestepExponent) (); +typedef int (*PNumEstimates)(); +typedef void (*PInitOdeData)(TOdeData *, double init_val, double h); +typedef double(*PNextTime)(TOdeData *, int step); +typedef double(*PNextValue)(TOdeData *, int step); +typedef void (*PUpdateEstimate)(TOdeData *, int step, double val); +typedef double(*PFinalEstimate)(TOdeData *); +typedef double(*PEstimateError)(TOdeData *); +typedef double(*PTimestepExponent)(); struct TOdeSolver { PNumEstimates NumEstimates; @@ -103,13 +103,13 @@ struct TOdeSolver { // special // -------------------------------------------------------------------- -int Gauss (double *matrix, int n, double *soln); -double LinearInterp (const double x[], const double y[], double val, int n); +int Gauss(double *matrix, int n, double *soln); +double LinearInterp(const double x[], const double y[], double val, int n); -double XRandom (float min, float max); -double FRandom (); -int IRandom (int min, int max); -int ITrunc (int val, int base); -int IFrac (int val, int base); +double XRandom(float min, float max); +double FRandom(); +int IRandom(int min, int max); +int ITrunc(int val, int base); +int IFrac(int val, int base); #endif diff --git a/src/newplayer.cpp b/src/newplayer.cpp index 9d0085c..3ccb431 100644 --- a/src/newplayer.cpp +++ b/src/newplayer.cpp @@ -39,69 +39,69 @@ static TUpDown* avatar; static TWidget* textbuttons[2]; static TTextField* textfield; -void QuitAndAddPlayer () { - if (textfield->Text().size () > 0) - Players.AddPlayer (textfield->Text(), Players.GetDirectAvatarName(avatar->GetValue())); - State::manager.RequestEnterState (Regist); +void QuitAndAddPlayer() { + if (textfield->Text().size() > 0) + Players.AddPlayer(textfield->Text(), Players.GetDirectAvatarName(avatar->GetValue())); + State::manager.RequestEnterState(Regist); } -void CNewPlayer::Keyb_spec (SDL_keysym sym, bool release) { +void CNewPlayer::Keyb_spec(SDL_keysym sym, bool release) { if (release) return; KeyGUI(sym.sym, sym.mod, release); switch (sym.sym) { case SDLK_ESCAPE: - State::manager.RequestEnterState (Regist); + State::manager.RequestEnterState(Regist); break; case SDLK_RETURN: - if (textbuttons[0]->focussed()) State::manager.RequestEnterState (Regist); - else QuitAndAddPlayer (); + if (textbuttons[0]->focussed()) State::manager.RequestEnterState(Regist); + else QuitAndAddPlayer(); break; default: break; } } -void CNewPlayer::Mouse (int button, int state, int x, int y) { +void CNewPlayer::Mouse(int button, int state, int x, int y) { if (state == 1) { TWidget* clicked = ClickGUI(x, y); if (clicked == textbuttons[0]) - State::manager.RequestEnterState (Regist); + State::manager.RequestEnterState(Regist); else if (clicked == textbuttons[1]) QuitAndAddPlayer(); } } -void CNewPlayer::Motion (int x, int y) { +void CNewPlayer::Motion(int x, int y) { MouseMoveGUI(x, y); - if (param.ui_snow) push_ui_snow (cursor_pos); + if (param.ui_snow) push_ui_snow(cursor_pos); } static int prevleft, prevtop, prevwidth; void CNewPlayer::Enter() { - Winsys.KeyRepeat (true); - Winsys.ShowCursor (!param.ice_cursor); - Music.Play (param.menu_music, -1); + Winsys.KeyRepeat(true); + Winsys.ShowCursor(!param.ice_cursor); + Music.Play(param.menu_music, -1); int framewidth = 400 * Winsys.scale; int frameheight = 50 * Winsys.scale; - int frametop = AutoYPosN (38); + int frametop = AutoYPosN(38); TArea area = AutoAreaN(30, 80, framewidth); int prevoffs = 80; prevleft = area.left + prevoffs; - prevtop = AutoYPosN (52); + prevtop = AutoYPosN(52); prevwidth = 75 * Winsys.scale; ResetGUI(); - avatar = AddUpDown (area.left + prevwidth + prevoffs + 8, prevtop, 0, (int)Players.numAvatars() - 1, 0, prevwidth - 34); - int siz = FT.AutoSizeN (5); - textbuttons[0] = AddTextButton (Trans.Text(8), area.left+50, AutoYPosN (70), siz); - double len = FT.GetTextWidth (Trans.Text(15)); - textbuttons[1] = AddTextButton (Trans.Text(15), area.right-len-50, AutoYPosN (70), siz); + avatar = AddUpDown(area.left + prevwidth + prevoffs + 8, prevtop, 0, (int)Players.numAvatars() - 1, 0, prevwidth - 34); + int siz = FT.AutoSizeN(5); + textbuttons[0] = AddTextButton(Trans.Text(8), area.left+50, AutoYPosN(70), siz); + double len = FT.GetTextWidth(Trans.Text(15)); + textbuttons[1] = AddTextButton(Trans.Text(15), area.right-len-50, AutoYPosN(70), siz); textfield = AddTextField(emptyString, area.left, frametop, framewidth, frameheight); } @@ -111,14 +111,13 @@ void CNewPlayer::Loop(double timestep) { int hh = Winsys.resolution.height; TColor col; - Music.Update (); - check_gl_error(); - ClearRenderContext (); + Music.Update(); + ClearRenderContext(); ScopedRenderMode rm(GUI); - SetupGuiDisplay (); + SetupGuiDisplay(); if (param.ui_snow) { - update_ui_snow (timestep); + update_ui_snow(timestep); draw_ui_snow(); } @@ -127,15 +126,15 @@ void CNewPlayer::Loop(double timestep) { // DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top, // 0, colMBackgr, col, 0.2); - Tex.Draw (BOTTOM_LEFT, 0, hh - 256, 1); - Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); - Tex.Draw (TOP_LEFT, 0, 0, 1); - Tex.Draw (TOP_RIGHT, ww-256, 0, 1); - Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), Winsys.scale); + Tex.Draw(BOTTOM_LEFT, 0, hh - 256, 1); + Tex.Draw(BOTTOM_RIGHT, ww-256, hh-256, 1); + Tex.Draw(TOP_LEFT, 0, 0, 1); + Tex.Draw(TOP_RIGHT, ww-256, 0, 1); + Tex.Draw(T_TITLE_SMALL, CENTER, AutoYPosN(5), Winsys.scale); - FT.SetColor (colWhite); - FT.AutoSizeN (4); - FT.DrawString (CENTER, AutoYPosN (30), Trans.Text(66)); + FT.SetColor(colWhite); + FT.AutoSizeN(4); + FT.DrawString(CENTER, AutoYPosN(30), Trans.Text(66)); if (avatar->focussed()) col = colDYell; else col = colWhite; diff --git a/src/ogl.cpp b/src/ogl.cpp index 23c7ae3..e1276b6 100644 --- a/src/ogl.cpp +++ b/src/ogl.cpp @@ -47,7 +47,7 @@ void check_gl_error() { GLenum error = glGetError(); if (error != GL_NO_ERROR) { const char* errstr = (const char*)gluErrorString(error); - Message ("OpenGL Error: ", errstr ? errstr : ""); + Message("OpenGL Error: ", errstr ? errstr : ""); } } @@ -55,7 +55,7 @@ PFNGLLOCKARRAYSEXTPROC glLockArraysEXT_p = NULL; PFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT_p = NULL; typedef void (*(*get_gl_proc_fptr_t)(const GLubyte *))(); -void InitOpenglExtensions () { +void InitOpenglExtensions() { get_gl_proc_fptr_t get_gl_proc; get_gl_proc = (get_gl_proc_fptr_t) SDL_GL_GetProcAddress; @@ -69,24 +69,24 @@ void InitOpenglExtensions () { if (glLockArraysEXT_p != NULL && glUnlockArraysEXT_p != NULL) { } else { - Message ("GL_EXT_compiled_vertex_array extension NOT supported"); + Message("GL_EXT_compiled_vertex_array extension NOT supported"); glLockArraysEXT_p = NULL; glUnlockArraysEXT_p = NULL; } } else { - Message ("No function available for obtaining GL proc addresses"); + Message("No function available for obtaining GL proc addresses"); } } -void PrintGLInfo () { - Message ("Gl vendor: ", (char*)glGetString (GL_VENDOR)); - Message ("Gl renderer: ", (char*)glGetString (GL_RENDERER)); - Message ("Gl version: ", (char*)glGetString (GL_VERSION)); - string extensions = (char*)glGetString (GL_EXTENSIONS); - Message (""); - Message ("Gl extensions:"); - Message (""); +void PrintGLInfo() { + Message("Gl vendor: ", (char*)glGetString(GL_VENDOR)); + Message("Gl renderer: ", (char*)glGetString(GL_RENDERER)); + Message("Gl version: ", (char*)glGetString(GL_VERSION)); + string extensions = (char*)glGetString(GL_EXTENSIONS); + Message(""); + Message("Gl extensions:"); + Message(""); size_t oldpos = 0; size_t pos; @@ -97,44 +97,44 @@ void PrintGLInfo () { } Message(extensions.substr(oldpos)); - Message (""); + Message(""); for (int i=0; i<(int)(sizeof(gl_values)/sizeof(gl_values[0])); i++) { switch (gl_values[i].type) { case GL_INT: { GLint int_val; - glGetIntegerv (gl_values[i].value, &int_val); - string ss = Int_StrN (int_val); - Message (gl_values[i].name, ss); + glGetIntegerv(gl_values[i].value, &int_val); + string ss = Int_StrN(int_val); + Message(gl_values[i].name, ss); break; } case GL_FLOAT: { GLfloat float_val; - glGetFloatv (gl_values[i].value, &float_val); - string ss = Float_StrN (float_val, 2); - Message (gl_values[i].name, ss); + glGetFloatv(gl_values[i].value, &float_val); + string ss = Float_StrN(float_val, 2); + Message(gl_values[i].name, ss); break; } case GL_UNSIGNED_BYTE: { GLboolean boolean_val; - glGetBooleanv (gl_values[i].value, &boolean_val); - string ss = Int_StrN (boolean_val); - Message (gl_values[i].name, ss); + glGetBooleanv(gl_values[i].value, &boolean_val); + string ss = Int_StrN(boolean_val); + Message(gl_values[i].name, ss); break; } default: - Message (""); + Message(""); } } } -void set_material (const TColor& diffuse_colour, const TColor& specular_colour, float specular_exp) { +void set_material(const TColor& diffuse_colour, const TColor& specular_colour, float specular_exp) { GLfloat mat_amb_diff[4] = { static_cast(diffuse_colour.r), static_cast(diffuse_colour.g), static_cast(diffuse_colour.b), static_cast(diffuse_colour.a) }; - glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff); GLfloat mat_specular[4] = { static_cast(specular_colour.r), @@ -142,261 +142,261 @@ void set_material (const TColor& diffuse_colour, const TColor& specular_colour, static_cast(specular_colour.b), static_cast(specular_colour.a) }; - glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); - glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, specular_exp); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, specular_exp); glColor(diffuse_colour); } -void ClearRenderContext () { - glDepthMask (GL_TRUE); - glClearColor (colBackgr.r, colBackgr.g, colBackgr.b, colBackgr.a); - glClearStencil (0); - glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); +void ClearRenderContext() { + glDepthMask(GL_TRUE); + glClearColor(colBackgr.r, colBackgr.g, colBackgr.b, colBackgr.a); + glClearStencil(0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } -void ClearRenderContext (const TColor& col) { - glDepthMask (GL_TRUE); - glClearColor (col.r, col.g, col.b, col.a); - glClearStencil (0); - glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); +void ClearRenderContext(const TColor& col) { + glDepthMask(GL_TRUE); + glClearColor(col.r, col.g, col.b, col.a); + glClearStencil(0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } -void SetupGuiDisplay () { +void SetupGuiDisplay() { static const float offset = 0.f; - glMatrixMode (GL_PROJECTION); - glLoadIdentity (); - glOrtho (0, Winsys.resolution.width, 0, Winsys.resolution.height, -1.0, 1.0); - glMatrixMode (GL_MODELVIEW); - glLoadIdentity (); - glTranslatef (offset, offset, -1.0); - glColor4f (1.0, 1.0, 1.0, 1.0); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, Winsys.resolution.width, 0, Winsys.resolution.height, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(offset, offset, -1.0); + glColor4f(1.0, 1.0, 1.0, 1.0); } -void Reshape (int w, int h) { - glViewport (0, 0, (GLint) w, (GLint) h ); - glMatrixMode (GL_PROJECTION); - glLoadIdentity (); +void Reshape(int w, int h) { + glViewport(0, 0, (GLint) w, (GLint) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); double far_clip_dist = param.forward_clip_distance + FAR_CLIP_FUDGE_AMOUNT; - gluPerspective (param.fov, (double)w/h, NEAR_CLIP_DIST, far_clip_dist ); - glMatrixMode (GL_MODELVIEW); + gluPerspective(param.fov, (double)w/h, NEAR_CLIP_DIST, far_clip_dist); + glMatrixMode(GL_MODELVIEW); } // ==================================================================== // GL options // ==================================================================== TRenderMode currentMode = RM_UNINITIALIZED; -void set_gl_options (TRenderMode mode) { +void set_gl_options(TRenderMode mode) { currentMode = mode; switch (mode) { case GUI: - glEnable (GL_TEXTURE_2D); - glDisable (GL_DEPTH_TEST); - glDisable (GL_CULL_FACE); - glDisable (GL_LIGHTING); - glDisable (GL_NORMALIZE); - glDisable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_STENCIL_TEST); - glDisable (GL_TEXTURE_GEN_S); - glDisable (GL_TEXTURE_GEN_T); - glDisable (GL_COLOR_MATERIAL); - glDepthMask (GL_TRUE); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LESS); - glDisable (GL_FOG); + glEnable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_STENCIL_TEST); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_COLOR_MATERIAL); + glDepthMask(GL_TRUE); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LESS); + glDisable(GL_FOG); break; case GAUGE_BARS: - glEnable (GL_TEXTURE_2D); - glDisable (GL_DEPTH_TEST); - glDisable (GL_CULL_FACE); - glDisable (GL_LIGHTING); - glDisable (GL_NORMALIZE); - glDisable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_STENCIL_TEST); - glEnable (GL_TEXTURE_GEN_S); - glEnable (GL_TEXTURE_GEN_T); - glDisable (GL_COLOR_MATERIAL); - glDepthMask (GL_TRUE); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LESS); + glEnable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_STENCIL_TEST); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glDisable(GL_COLOR_MATERIAL); + glDepthMask(GL_TRUE); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LESS); - glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); break; case TEXFONT: - glEnable (GL_TEXTURE_2D); - glDisable (GL_DEPTH_TEST); - glDisable (GL_CULL_FACE); - glDisable (GL_LIGHTING); - glDisable (GL_NORMALIZE); - glDisable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_STENCIL_TEST); - glDisable (GL_TEXTURE_GEN_S); - glDisable (GL_TEXTURE_GEN_T); - glDisable (GL_COLOR_MATERIAL); - glDepthMask (GL_TRUE); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LESS); + glEnable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_STENCIL_TEST); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_COLOR_MATERIAL); + glDepthMask(GL_TRUE); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LESS); break; case COURSE: - glEnable (GL_TEXTURE_2D); - glEnable (GL_DEPTH_TEST); - glEnable (GL_CULL_FACE); - glEnable (GL_LIGHTING); - glDisable (GL_NORMALIZE); - glDisable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_STENCIL_TEST); - glEnable (GL_TEXTURE_GEN_S); - glEnable (GL_TEXTURE_GEN_T); - glEnable (GL_COLOR_MATERIAL); - glDepthMask (GL_TRUE); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LEQUAL); + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_STENCIL_TEST); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glEnable(GL_COLOR_MATERIAL); + glDepthMask(GL_TRUE); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LEQUAL); - glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); break; case TREES: - glEnable (GL_TEXTURE_2D); - glEnable (GL_DEPTH_TEST); - glDisable (GL_CULL_FACE); - glEnable (GL_LIGHTING); - glDisable (GL_NORMALIZE); - glEnable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_STENCIL_TEST); - glDisable (GL_TEXTURE_GEN_S); - glDisable (GL_TEXTURE_GEN_T); - glDisable (GL_COLOR_MATERIAL); - glDepthMask (GL_TRUE); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LESS); + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glEnable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_STENCIL_TEST); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_COLOR_MATERIAL); + glDepthMask(GL_TRUE); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LESS); - glAlphaFunc (GL_GEQUAL, 0.5); + glAlphaFunc(GL_GEQUAL, 0.5); break; case PARTICLES: - glEnable (GL_TEXTURE_2D); - glEnable (GL_DEPTH_TEST); - glDisable (GL_CULL_FACE); - glDisable (GL_LIGHTING); - glDisable (GL_NORMALIZE); - glEnable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_STENCIL_TEST); - glDisable (GL_TEXTURE_GEN_S); - glDisable (GL_TEXTURE_GEN_T); - glDisable (GL_COLOR_MATERIAL); - glDepthMask (GL_TRUE); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LESS); + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glEnable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_STENCIL_TEST); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_COLOR_MATERIAL); + glDepthMask(GL_TRUE); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LESS); - glAlphaFunc (GL_GEQUAL, 0.5); + glAlphaFunc(GL_GEQUAL, 0.5); break; case SKY: - glEnable (GL_TEXTURE_2D); - glDisable (GL_DEPTH_TEST); - glDisable (GL_CULL_FACE); - glDisable (GL_LIGHTING); - glDisable (GL_NORMALIZE); - glDisable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_STENCIL_TEST); - glDisable (GL_TEXTURE_GEN_S); - glDisable (GL_TEXTURE_GEN_T); - glDisable (GL_COLOR_MATERIAL); - glDepthMask (GL_FALSE); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LESS); + glEnable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_STENCIL_TEST); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_COLOR_MATERIAL); + glDepthMask(GL_FALSE); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LESS); break; case FOG_PLANE: - glDisable (GL_TEXTURE_2D); - glEnable (GL_DEPTH_TEST); - glDisable (GL_CULL_FACE); - glDisable (GL_LIGHTING); - glDisable (GL_NORMALIZE); - glDisable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_STENCIL_TEST); - glDisable (GL_TEXTURE_GEN_S); - glDisable (GL_TEXTURE_GEN_T); - glDisable (GL_COLOR_MATERIAL); - glDepthMask (GL_TRUE); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LESS); + glDisable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_STENCIL_TEST); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_COLOR_MATERIAL); + glDepthMask(GL_TRUE); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LESS); break; case TUX: - glDisable (GL_TEXTURE_2D); - glEnable (GL_DEPTH_TEST); - glEnable (GL_CULL_FACE); - glEnable (GL_LIGHTING); - glEnable (GL_NORMALIZE); - glDisable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_STENCIL_TEST); - glDisable (GL_TEXTURE_GEN_S); - glDisable (GL_TEXTURE_GEN_T); - glDisable (GL_COLOR_MATERIAL); - glDepthMask (GL_TRUE); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LESS); + glDisable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_NORMALIZE); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_STENCIL_TEST); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_COLOR_MATERIAL); + glDepthMask(GL_TRUE); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LESS); break; case TUX_SHADOW: - glDisable (GL_TEXTURE_2D); - glEnable (GL_DEPTH_TEST); - glDisable (GL_LIGHTING); - glDisable (GL_NORMALIZE); - glDisable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_COLOR_MATERIAL); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LESS); + glDisable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_COLOR_MATERIAL); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LESS); #ifdef USE_STENCIL_BUFFER - glDisable (GL_CULL_FACE); - glEnable (GL_STENCIL_TEST); - glDepthMask (GL_FALSE); + glDisable(GL_CULL_FACE); + glEnable(GL_STENCIL_TEST); + glDepthMask(GL_FALSE); - glStencilFunc (GL_EQUAL, 0, ~0); - glStencilOp (GL_KEEP, GL_KEEP, GL_INCR); + glStencilFunc(GL_EQUAL, 0, ~0); + glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); #else - glEnable (GL_CULL_FACE); - glDisable (GL_STENCIL_TEST); - glDepthMask (GL_TRUE); + glEnable(GL_CULL_FACE); + glDisable(GL_STENCIL_TEST); + glDepthMask(GL_TRUE); #endif break; case TRACK_MARKS: - glEnable (GL_TEXTURE_2D); - glEnable (GL_DEPTH_TEST); - glDisable (GL_CULL_FACE); - glEnable (GL_LIGHTING); - glDisable (GL_NORMALIZE); - glDisable (GL_ALPHA_TEST); - glEnable (GL_BLEND); - glDisable (GL_STENCIL_TEST); - glDisable (GL_COLOR_MATERIAL); - glDisable (GL_TEXTURE_GEN_S); - glDisable (GL_TEXTURE_GEN_T); - glDepthMask (GL_FALSE); - glShadeModel (GL_SMOOTH); - glDepthFunc (GL_LEQUAL); + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glDisable(GL_STENCIL_TEST); + glDisable(GL_COLOR_MATERIAL); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDepthMask(GL_FALSE); + glShadeModel(GL_SMOOTH); + glDepthFunc(GL_LEQUAL); break; default: - Message ("not a valid render mode"); + Message("not a valid render mode"); } } /* defined but not used @@ -509,6 +509,10 @@ void glTexCoord2(const TVector2d& vec) { glTexCoord2d(vec.x, vec.y); } -void glMultMatrix(const TMatrix<4, 4>& mat) { - glMultMatrixd((const double*)mat.data()); +void glLoadMatrix(const TMatrix<4, 4>& mat) { + glLoadMatrixd((const double*) mat.data()); +} + +void glMultMatrix(const TMatrix<4, 4>& mat) { + glMultMatrixd((const double*) mat.data()); } diff --git a/src/ogl.h b/src/ogl.h index a45758f..334bf4e 100644 --- a/src/ogl.h +++ b/src/ogl.h @@ -48,9 +48,9 @@ void check_gl_error(); void InitOpenglExtensions(); void PrintGLInfo(); -void set_material (const TColor& diffuse_colour, - const TColor& specular_colour, - float specular_exp); +void set_material(const TColor& diffuse_colour, + const TColor& specular_colour, + float specular_exp); void PushRenderMode(TRenderMode mode); @@ -65,10 +65,10 @@ struct ScopedRenderMode { } }; -void ClearRenderContext (); -void ClearRenderContext (const TColor& col); -void SetupGuiDisplay (); -void Reshape (int w, int h); +void ClearRenderContext(); +void ClearRenderContext(const TColor& col); +void SetupGuiDisplay(); +void Reshape(int w, int h); void glColor(const TColor& col); void glColor(const TColor& col, double alpha); @@ -79,6 +79,7 @@ void glNormal3(const TVector3d& vec); void glVertex3(const TVector3d& vec); void glTexCoord2(const TVector2d& vec); +void glLoadMatrix(const TMatrix<4, 4>& mat); void glMultMatrix(const TMatrix<4, 4>& mat); diff --git a/src/ogl_test.cpp b/src/ogl_test.cpp index ef9bc85..e83907a 100644 --- a/src/ogl_test.cpp +++ b/src/ogl_test.cpp @@ -37,7 +37,7 @@ static const TLight light = { }; -void SetTestLight () { +void SetTestLight() { light.Enable(GL_LIGHT0); glEnable(GL_LIGHTING); } @@ -53,19 +53,17 @@ void COglTest::Keyb(unsigned int key, bool special, bool release, int x, int y) } void COglTest::Enter() { - Winsys.KeyRepeat (true); + Winsys.KeyRepeat(true); } void COglTest::Loop(double timestep) { - check_gl_error(); - // ------------- 3d scenery --------------------------------------- ScopedRenderMode rm(TUX); - ClearRenderContext (colDDBackgr); + ClearRenderContext(colDDBackgr); - glLoadIdentity (); - glPushMatrix (); - SetTestLight (); + glLoadIdentity(); + glPushMatrix(); + SetTestLight(); /* glTranslatef (xposition, yposition, zposition); @@ -73,13 +71,13 @@ void COglTest::Loop(double timestep) { glRotatef (yrotation, 0, 1, 0); glRotatef (zrotation, 0, 0, 1); */ - glPopMatrix (); + glPopMatrix(); // --------------- 2d screen -------------------------------------- - SetupGuiDisplay (); + SetupGuiDisplay(); ScopedRenderMode rm2(TEXFONT); FT.SetProps("bold", 24, colWhite); - FT.DrawString (CENTER, 10, "Test screen"); - Reshape (Winsys.resolution.width, Winsys.resolution.height); - Winsys.SwapBuffers (); + FT.DrawString(CENTER, 10, "Test screen"); + Reshape(Winsys.resolution.width, Winsys.resolution.height); + Winsys.SwapBuffers(); } diff --git a/src/particles.cpp b/src/particles.cpp index 5873698..49e4a65 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -37,7 +37,7 @@ GNU General Public License for more details. // ==================================================================== #define MAX_num_snowparticles 4000 -#define BASE_num_snowparticles 1000 +#define BASE_snowparticles 1000.0/1024 // This is intentionally not divided by height*width to make particle count increasing slower than screen size #define GRAVITY_FACTOR 0.015 #define BASE_VELOCITY 0.05 #define VELOCITY_RANGE 0.02 @@ -124,19 +124,19 @@ void TGuiParticle::Update(double time_step, double push_timestep, const TVector2 if (push_timestep > 0) { f.x = PUSH_FACTOR * push_vector.x / push_timestep; f.y = PUSH_FACTOR * push_vector.y / push_timestep; - f.x = clamp (-MAX_PUSH_FORCE, f.x, MAX_PUSH_FORCE); - f.y = clamp (-MAX_PUSH_FORCE, f.y, MAX_PUSH_FORCE); + f.x = clamp(-MAX_PUSH_FORCE, f.x, MAX_PUSH_FORCE); + f.y = clamp(-MAX_PUSH_FORCE, f.y, MAX_PUSH_FORCE); f.x *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) * size/PARTICLE_SIZE_RANGE; f.y *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) * size/PARTICLE_SIZE_RANGE; } - vel.x += (f.x - vel.x * AIR_DRAG) * time_step; - vel.y += (f.y - GRAVITY_FACTOR - vel.y * AIR_DRAG) * time_step; + vel.x += (f.x - vel.x * AIR_DRAG) * time_step; + vel.y += (f.y - GRAVITY_FACTOR - vel.y * AIR_DRAG) * time_step; - pt.x += vel.x * time_step * (size / PARTICLE_SIZE_RANGE); - pt.y += vel.y * time_step * (size / PARTICLE_SIZE_RANGE); + pt.x += vel.x * time_step * (size / PARTICLE_SIZE_RANGE); + pt.y += vel.y * time_step * (size / PARTICLE_SIZE_RANGE); if (pt.x < 0) { pt.x = 1; @@ -145,14 +145,15 @@ void TGuiParticle::Update(double time_step, double push_timestep, const TVector2 } } -void init_ui_snow () { - for (int i=0; i::iterator p = particles_2d.begin(); p != particles_2d.end();) { if (p->pt.y < -0.05) { - if (particles_2d.size() > BASE_num_snowparticles && FRandom() > 0.2) { + if (particles_2d.size() > BASE_snowparticles * Winsys.resolution.width && FRandom() > 0.2) { p = particles_2d.erase(p); } else { p->pt.x = FRandom(); @@ -198,12 +199,12 @@ void update_ui_snow(double time_step) { push_vector.y = 0.0; } } -void draw_ui_snow () { +void draw_ui_snow() { double xres = Winsys.resolution.width; double yres = Winsys.resolution.height; - glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - Tex.BindTex (SNOW_PART); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + Tex.BindTex(SNOW_PART); glColor4f(1.f, 1.f, 1.f, 0.3f); glEnableClientState(GL_VERTEX_ARRAY); @@ -215,7 +216,7 @@ void draw_ui_snow () { glDisableClientState(GL_VERTEX_ARRAY); } -void push_ui_snow (const TVector2i& pos) { +void push_ui_snow(const TVector2i& pos) { push_position = TVector2d(pos.x/(double)Winsys.resolution.width, 1.0 - pos.y/(double)Winsys.resolution.height); if (!push_position_initialized) last_push_position = push_position; push_position_initialized = true; @@ -288,13 +289,13 @@ void Particle::Draw(const CControl* ctrl) const { } }; - const TColor& particle_colour = Env.ParticleColor (); + const TColor& particle_colour = Env.ParticleColor(); glColor(particle_colour, particle_colour.a * alpha); draw_billboard(ctrl, cur_size, cur_size, false, tex_coords[type]); } -void Particle::draw_billboard (const CControl *ctrl, double width, double height, bool use_world_y_axis, const GLfloat* tex) const { +void Particle::draw_billboard(const CControl *ctrl, double width, double height, bool use_world_y_axis, const GLfloat* tex) const { TVector3d x_vec; TVector3d y_vec; TVector3d z_vec; @@ -305,9 +306,9 @@ void Particle::draw_billboard (const CControl *ctrl, double width, double height if (use_world_y_axis) { y_vec = TVector3d(0, 1, 0); - x_vec = ProjectToPlane (y_vec, x_vec); + x_vec = ProjectToPlane(y_vec, x_vec); x_vec.Norm(); - z_vec = CrossProduct (x_vec, y_vec); + z_vec = CrossProduct(x_vec, y_vec); } else { y_vec.x = ctrl->view_mat[1][0]; y_vec.y = ctrl->view_mat[1][1]; @@ -340,11 +341,11 @@ void Particle::draw_billboard (const CControl *ctrl, double width, double height glDisableClientState(GL_VERTEX_ARRAY); } -void create_new_particles (const TVector3d& loc, const TVector3d& vel, int num) { +void create_new_particles(const TVector3d& loc, const TVector3d& vel, int num) { double speed = vel.Length(); if (particles.size() + num > MAX_PARTICLES) { - Message ("maximum number of particles exceeded"); + Message("maximum number of particles exceeded"); } for (int i=0; i::iterator p = particles.begin(); p != particles.end();) { p->age += time_step; if (p->age < 0) { @@ -372,7 +373,7 @@ void update_particles (double time_step) { } p->pt += time_step * p->vel; - double ycoord = Course.FindYCoord (p->pt.x, p->pt.z); + double ycoord = Course.FindYCoord(p->pt.x, p->pt.z); if (p->pt.y < ycoord - 3) {p->age = p->death + 1;} if (p->age >= p->death) { p = particles.erase(p); @@ -385,10 +386,10 @@ void update_particles (double time_step) { ++p; } } -void draw_particles (const CControl *ctrl) { +void draw_particles(const CControl *ctrl) { ScopedRenderMode rm(PARTICLES); - Tex.BindTex (SNOW_PART); - glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + Tex.BindTex(SNOW_PART); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glColor4f(1.f, 1.f, 1.f, 0.8f); for (list::const_iterator p = particles.begin(); p != particles.end(); ++p) { @@ -400,21 +401,21 @@ void clear_particles() { particles.clear(); } -double adjust_particle_count (double particles) { +double adjust_particle_count(double particles) { if (particles < 1) { if (((double) rand()) / RAND_MAX < particles) return 1.0; else return 0.0; } else return particles; } -void generate_particles (const CControl *ctrl, double dtime, const TVector3d& pos, double speed) { +void generate_particles(const CControl *ctrl, double dtime, const TVector3d& pos, double speed) { TTerrType *TerrList = &Course.TerrList[0]; - double surf_y = Course.FindYCoord (pos.x, pos.z); + double surf_y = Course.FindYCoord(pos.x, pos.z); - int id = Course.GetTerrainIdx (pos.x, pos.z, 0.5); + int id = Course.GetTerrainIdx(pos.x, pos.z, 0.5); if (id >= 0 && TerrList[id].particles && pos.y < surf_y) { - TVector3d xvec = CrossProduct (ctrl->cdirection, ctrl->plane_nml); + TVector3d xvec = CrossProduct(ctrl->cdirection, ctrl->plane_nml); TVector3d right_part_pt = pos + TUX_WIDTH/2.0 * xvec; @@ -423,45 +424,45 @@ void generate_particles (const CControl *ctrl, double dtime, const TVector3d& po right_part_pt.y = left_part_pt.y = surf_y; double brake_particles = dtime * - BRAKE_PARTICLES * (ctrl->is_braking ? 1.0 : 0.0) - * min (speed / PARTICLE_SPEED_FACTOR, 1.0); + BRAKE_PARTICLES * (ctrl->is_braking ? 1.0 : 0.0) + * min(speed / PARTICLE_SPEED_FACTOR, 1.0); double turn_particles = dtime * MAX_TURN_PARTICLES - * min (speed / PARTICLE_SPEED_FACTOR, 1.0); + * min(speed / PARTICLE_SPEED_FACTOR, 1.0); double roll_particles = dtime * MAX_ROLL_PARTICLES - * min (speed / PARTICLE_SPEED_FACTOR, 1.0); + * min(speed / PARTICLE_SPEED_FACTOR, 1.0); double left_particles = turn_particles * - fabs (min(ctrl->turn_fact, 0.)) + + fabs(min(ctrl->turn_fact, 0.)) + brake_particles + - roll_particles * fabs (min(ctrl->turn_animation, 0.)); + roll_particles * fabs(min(ctrl->turn_animation, 0.)); double right_particles = turn_particles * - fabs (max(ctrl->turn_fact, 0.)) + + fabs(max(ctrl->turn_fact, 0.)) + brake_particles + - roll_particles * fabs (max(ctrl->turn_animation, 0.)); + roll_particles * fabs(max(ctrl->turn_animation, 0.)); - left_particles = adjust_particle_count (left_particles); - right_particles = adjust_particle_count (right_particles); + left_particles = adjust_particle_count(left_particles); + right_particles = adjust_particle_count(right_particles); TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix( ctrl->cdirection, - max (-MAX_PARTICLE_ANGLE, - -MAX_PARTICLE_ANGLE * speed / MAX_PARTICLE_ANGLE_SPEED)); - TVector3d left_part_vel = TransformVector (rot_mat, ctrl->plane_nml); + max(-MAX_PARTICLE_ANGLE, + -MAX_PARTICLE_ANGLE * speed / MAX_PARTICLE_ANGLE_SPEED)); + TVector3d left_part_vel = TransformVector(rot_mat, ctrl->plane_nml); left_part_vel = min(MAX_PARTICLE_SPEED, speed * PARTICLE_SPEED_MULTIPLIER); rot_mat = RotateAboutVectorMatrix( ctrl->cdirection, - min (MAX_PARTICLE_ANGLE, - MAX_PARTICLE_ANGLE * speed / MAX_PARTICLE_ANGLE_SPEED)); - TVector3d right_part_vel = TransformVector (rot_mat, ctrl->plane_nml); + min(MAX_PARTICLE_ANGLE, + MAX_PARTICLE_ANGLE * speed / MAX_PARTICLE_ANGLE_SPEED)); + TVector3d right_part_vel = TransformVector(rot_mat, ctrl->plane_nml); right_part_vel *= min(MAX_PARTICLE_SPEED, speed * PARTICLE_SPEED_MULTIPLIER); - create_new_particles (left_part_pt, left_part_vel, - (int)left_particles); - create_new_particles (right_part_pt, right_part_vel, - (int)right_particles); + create_new_particles(left_part_pt, left_part_vel, + (int)left_particles); + create_new_particles(right_part_pt, right_part_vel, + (int)right_particles); } } @@ -475,10 +476,10 @@ static CFlakes Flakes; void TFlake::Draw(const TPlane& lp, const TPlane& rp, bool rotate_flake, float dir_angle) const { - if ((DistanceToPlane (lp, pt) < 0) && (DistanceToPlane (rp, pt) < 0)) { + if ((DistanceToPlane(lp, pt) < 0) && (DistanceToPlane(rp, pt) < 0)) { glPushMatrix(); glTranslate(pt); - if (rotate_flake) glRotatef (dir_angle, 0, 1, 0); + if (rotate_flake) glRotatef(dir_angle, 0, 1, 0); const GLfloat vtx[] = { 0, 0, 0, @@ -495,7 +496,7 @@ void TFlake::Draw(const TPlane& lp, const TPlane& rp, bool rotate_flake, float d } -TFlakeArea::TFlakeArea ( +TFlakeArea::TFlakeArea( int num_flakes, float _xrange, float _ytop, @@ -519,17 +520,17 @@ TFlakeArea::TFlakeArea ( flakes.resize(num_flakes); } -void TFlakeArea::Draw (const CControl *ctrl) const { +void TFlakeArea::Draw(const CControl *ctrl) const { if (g_game.snow_id < 1) return; - const TPlane& lp = get_left_clip_plane (); - const TPlane& rp = get_right_clip_plane (); - float dir_angle (atan (ctrl->viewdir.x / ctrl->viewdir.z) * 180 / 3.14159); + const TPlane& lp = get_left_clip_plane(); + const TPlane& rp = get_right_clip_plane(); + float dir_angle(atan(ctrl->viewdir.x / ctrl->viewdir.z) * 180 / 3.14159); ScopedRenderMode rm(PARTICLES); - glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); Tex.BindTex(SNOW_PART); - const TColor& particle_colour = Env.ParticleColor (); + const TColor& particle_colour = Env.ParticleColor(); glColor(particle_colour); glEnableClientState(GL_VERTEX_ARRAY); @@ -563,16 +564,16 @@ void TFlakeArea::Update(float timestep, float xcoeff, float ycoeff, float zcoeff } } -void CFlakes::Reset () { +void CFlakes::Reset() { areas.clear(); } -void CFlakes::MakeSnowFlake (size_t ar, size_t i) { - areas[ar].flakes[i].pt.x = XRandom (areas[ar].left, areas[ar].right); - areas[ar].flakes[i].pt.y = -XRandom (areas[ar].top, areas[ar].bottom); - areas[ar].flakes[i].pt.z = areas[ar].back - FRandom () * (areas[ar].back - areas[ar].front); +void CFlakes::MakeSnowFlake(size_t ar, size_t i) { + areas[ar].flakes[i].pt.x = XRandom(areas[ar].left, areas[ar].right); + areas[ar].flakes[i].pt.y = -XRandom(areas[ar].top, areas[ar].bottom); + areas[ar].flakes[i].pt.z = areas[ar].back - FRandom() * (areas[ar].back - areas[ar].front); - areas[ar].flakes[i].size = XRandom (areas[ar].minSize, areas[ar].maxSize); + areas[ar].flakes[i].size = XRandom(areas[ar].minSize, areas[ar].maxSize); areas[ar].flakes[i].vel.x = 0; areas[ar].flakes[i].vel.z = 0; areas[ar].flakes[i].vel.y = -areas[ar].flakes[i].size * areas[ar].speed; @@ -606,15 +607,15 @@ void CFlakes::MakeSnowFlake (size_t ar, size_t i) { areas[ar].flakes[i].tex = tex_coords[type]; } -void CFlakes::GenerateSnowFlakes (const CControl *ctrl) { +void CFlakes::GenerateSnowFlakes(const CControl *ctrl) { if (g_game.snow_id < 1) return; snow_lastpos = ctrl->cpos; for (size_t ar=0; arcpos.x - areas[ar].xrange / 2; areas[ar].right = areas[ar].left + areas[ar].xrange; @@ -628,8 +629,8 @@ void CFlakes::UpdateAreas (const CControl *ctrl) { #define YDRIFT 0.8 #define ZDRIFT 0.6 -void CFlakes::Init (int grade, const CControl *ctrl) { - Reset (); +void CFlakes::Init(int grade, const CControl *ctrl) { + Reset(); switch (grade) { case 1: // areas.push_back(TFlakeArea(400, 5, 4, 4, -2, 4, 0.01, 0.02, 5, true)); @@ -668,15 +669,15 @@ void CFlakes::Init (int grade, const CControl *ctrl) { break; } - UpdateAreas (ctrl); - GenerateSnowFlakes (ctrl); + UpdateAreas(ctrl); + GenerateSnowFlakes(ctrl); } -void CFlakes::Update (double timestep, const CControl *ctrl) { +void CFlakes::Update(double timestep, const CControl *ctrl) { if (g_game.snow_id < 1) return; - UpdateAreas (ctrl); + UpdateAreas(ctrl); float zdiff = ctrl->cpos.z - snow_lastpos.z; float ydiff = 0.f; @@ -684,7 +685,7 @@ void CFlakes::Update (double timestep, const CControl *ctrl) { ydiff = ctrl->cpos.y - snow_lastpos.y; } - TVector3d winddrift = SNOW_WIND_DRIFT * Wind.WindDrift (); + TVector3d winddrift = SNOW_WIND_DRIFT * Wind.WindDrift(); float xcoeff = winddrift.x * timestep; float ycoeff = (ydiff * YDRIFT) + (winddrift.z * timestep); float zcoeff = (zdiff * ZDRIFT) + (winddrift.z * timestep); @@ -695,7 +696,7 @@ void CFlakes::Update (double timestep, const CControl *ctrl) { snow_lastpos = ctrl->cpos; } -void CFlakes::Draw (const CControl *ctrl) const { +void CFlakes::Draw(const CControl *ctrl) const { for (size_t ar=0; arforward) { @@ -742,8 +743,8 @@ void UpdateChanges (double timestep) { } } -TCurtain::TCurtain (int num_rows, float z_dist, float tex_size, - float base_speed, float start_angle, float min_height, int dense) { +TCurtain::TCurtain(int num_rows, float z_dist, float tex_size, + float base_speed, float start_angle, float min_height, int dense) { numRows = num_rows; zdist = z_dist; size = tex_size; @@ -762,13 +763,13 @@ TCurtain::TCurtain (int num_rows, float z_dist, float tex_size, break; } - angledist = atan (size / 2 / zdist) * 360 / 3.14159; + angledist = atan(size / 2 / zdist) * 360 / 3.14159; numCols = (unsigned int)(-2 * startangle / angledist) + 1; if (numCols > MAX_CURTAIN_COLS) numCols = MAX_CURTAIN_COLS; lastangle = startangle + (numCols-1) * angledist; for (unsigned int i=0; iheight = minheight + row * size; float x, z; curt->angle = co * angledist + startangle; - CurtainVec (curt->angle, zdist, x, z); + CurtainVec(curt->angle, zdist, x, z); curt->pt.x = ctrl->cpos.x + x; curt->pt.z = ctrl->cpos.z + z; curt->pt.y = ctrl->cpos.y + curt->height; @@ -787,7 +788,7 @@ void TCurtain::SetStartParams(const CControl* ctrl) { } void TCurtain::Draw() const { - Tex.BindTex (texture); + Tex.BindTex(texture); float halfsize = size / 2.f; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); @@ -796,7 +797,7 @@ void TCurtain::Draw() const { const TVector3d& pt = curtains[co][row].pt; glPushMatrix(); glTranslate(pt); - glRotatef (-curtains[co][row].angle, 0, 1, 0); + glRotatef(-curtains[co][row].angle, 0, 1, 0); static const GLshort tex[] = { 0, 0, @@ -832,7 +833,7 @@ void TCurtain::Update(float timestep, const TVector3d& drift, const CControl* ct if (curt->angle > lastangle + angledist) curt->angle = startangle; if (curt->angle < startangle - angledist) curt->angle = lastangle; float x, z; - CurtainVec (curt->angle, zdist, x, z); + CurtainVec(curt->angle, zdist, x, z); curt->pt.x = ctrl->cpos.x + x; curt->pt.z = ctrl->cpos.z + z; curt->pt.y = ctrl->cpos.y + curt->height; @@ -843,18 +844,18 @@ void TCurtain::Update(float timestep, const TVector3d& drift, const CControl* ct static CCurtain Curtain; -void TCurtain::CurtainVec (float angle, float zdist, float &x, float &z) { - x = zdist * sin (angle * 3.14159 / 180); - if (angle > 90 || angle < -90) z = sqrt (zdist * zdist - x * x); - else z = -sqrt (zdist * zdist - x * x); +void TCurtain::CurtainVec(float angle, float zdist, float &x, float &z) { + x = zdist * sin(angle * 3.14159 / 180); + if (angle > 90 || angle < -90) z = sqrt(zdist * zdist - x * x); + else z = -sqrt(zdist * zdist - x * x); } -void CCurtain::Draw () { +void CCurtain::Draw() { if (g_game.snow_id < 1) return; ScopedRenderMode rm(PARTICLES); - glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - const TColor& particle_colour = Env.ParticleColor (); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + const TColor& particle_colour = Env.ParticleColor(); glColor(particle_colour, 1.0); // glEnable (GL_NORMALIZE); @@ -863,30 +864,30 @@ void CCurtain::Draw () { } } -void CCurtain::Update (float timestep, const CControl *ctrl) { +void CCurtain::Update(float timestep, const CControl *ctrl) { if (g_game.snow_id < 1) return; - const TVector3d& drift = Wind.WindDrift (); + const TVector3d& drift = Wind.WindDrift(); - UpdateChanges (timestep); + UpdateChanges(timestep); for (size_t i=0; i 100) params.maxSpeed = 100; - angle = XRandom (min_base_angle, max_base_angle); - if (XRandom (0, 100) > 50) angle = angle + alt_angle; - var = XRandom (min_angle_var, max_angle_var) / 2; + angle = XRandom(min_base_angle, max_base_angle); + if (XRandom(0, 100) > 50) angle = angle + alt_angle; + var = XRandom(min_angle_var, max_angle_var) / 2; params.minAngle = angle - var; params.maxAngle = angle + var; } -void CWind::CalcDestSpeed () { - float rand = XRandom (0, 100); +void CWind::CalcDestSpeed() { + float rand = XRandom(0, 100); if (rand > (100 - params.topProbability)) { - DestSpeed = XRandom (params.maxSpeed, params.topSpeed); + DestSpeed = XRandom(params.maxSpeed, params.topSpeed); WindChange = params.maxChange; } else if (rand < params.nullProbability) { DestSpeed = 0.0; - WindChange = XRandom (params.minChange, params.maxChange); + WindChange = XRandom(params.minChange, params.maxChange); } else { - DestSpeed = XRandom (params.minSpeed, params.maxSpeed); - WindChange = XRandom (params.minChange, params.maxChange); + DestSpeed = XRandom(params.minSpeed, params.maxSpeed); + WindChange = XRandom(params.minChange, params.maxChange); } if (DestSpeed > WSpeed) SpeedMode = 1; else SpeedMode = 0; } -void CWind::CalcDestAngle () { - DestAngle = XRandom (params.minAngle, params.maxAngle); - AngleChange = XRandom (params.minAngleChange, params.maxAngleChange); +void CWind::CalcDestAngle() { + DestAngle = XRandom(params.minAngle, params.maxAngle); + AngleChange = XRandom(params.minAngleChange, params.maxAngleChange); if (DestAngle > WAngle) AngleMode = 1; else AngleMode = 0; } -void CWind::Update (float timestep) { +void CWind::Update(float timestep) { if (!windy) return; // the wind needn't be updated in each frame @@ -1072,11 +1073,11 @@ void CWind::Update (float timestep) { if (SpeedMode == 1) { // current speed lesser than destination speed if (WSpeed < DestSpeed) { WSpeed = WSpeed + WindChange; - } else CalcDestSpeed (); + } else CalcDestSpeed(); } else { if (WSpeed > DestSpeed) { WSpeed = WSpeed - WindChange; - } else CalcDestSpeed (); + } else CalcDestSpeed(); } if (WSpeed > params.topSpeed) WSpeed = params.topSpeed; if (WSpeed < 0) WSpeed = 0; @@ -1085,17 +1086,17 @@ void CWind::Update (float timestep) { if (AngleMode == 1) { if (WAngle < DestAngle) { WAngle = WAngle + AngleChange; - } else CalcDestAngle (); + } else CalcDestAngle(); } else { if (WAngle > DestAngle) { WAngle = WAngle - AngleChange; - } else CalcDestAngle (); + } else CalcDestAngle(); } if (WAngle > params.maxAngle) WAngle = params.maxAngle; if (WAngle < params.minAngle) WAngle = params.minAngle; - float xx = sin (WAngle * 3.14159 / 180); - float zz = sqrt (1 - xx * xx); + float xx = sin(WAngle * 3.14159 / 180); + float zz = sqrt(1 - xx * xx); if ((WAngle > 90 && WAngle < 270) || (WAngle > 450 && WAngle < 630)) { zz = -zz; } @@ -1105,48 +1106,48 @@ void CWind::Update (float timestep) { } } -void CWind::Init (int wind_id) { +void CWind::Init(int wind_id) { if (wind_id < 1 || wind_id > 3) { windy = false; - WVector = TVector3d (0, 0, 0); + WVector = TVector3d(0, 0, 0); WAngle = 0; WSpeed = 0; return; } windy = true;; - SetParams (wind_id -1); - WSpeed = XRandom (params.minSpeed, (params.minSpeed + params.maxSpeed) / 2); - WAngle = XRandom (params.minAngle, params.maxAngle); - CalcDestSpeed (); - CalcDestAngle (); + SetParams(wind_id -1); + WSpeed = XRandom(params.minSpeed, (params.minSpeed + params.maxSpeed) / 2); + WAngle = XRandom(params.minAngle, params.maxAngle); + CalcDestSpeed(); + CalcDestAngle(); } // ==================================================================== // access functions // ==================================================================== -void InitSnow (const CControl *ctrl) { +void InitSnow(const CControl *ctrl) { if (g_game.snow_id < 1 || g_game.snow_id > 3) return; - Flakes.Init (g_game.snow_id, ctrl); - Curtain.Init (ctrl); + Flakes.Init(g_game.snow_id, ctrl); + Curtain.Init(ctrl); } -void UpdateSnow (double timestep, const CControl *ctrl) { +void UpdateSnow(double timestep, const CControl *ctrl) { if (g_game.snow_id < 1 || g_game.snow_id > 3) return; - Flakes.Update (timestep, ctrl); - Curtain.Update (timestep, ctrl); + Flakes.Update(timestep, ctrl); + Curtain.Update(timestep, ctrl); } -void DrawSnow (const CControl *ctrl) { +void DrawSnow(const CControl *ctrl) { if (g_game.snow_id < 1 || g_game.snow_id > 3) return; - Flakes.Draw (ctrl); - Curtain.Draw (); + Flakes.Draw(ctrl); + Curtain.Draw(); } -void InitWind () { - Wind.Init (g_game.wind_id); +void InitWind() { + Wind.Init(g_game.wind_id); } -void UpdateWind (double timestep) { - Wind.Update (timestep); +void UpdateWind(double timestep) { + Wind.Update(timestep); } diff --git a/src/particles.h b/src/particles.h index 09b08b5..b19ed57 100644 --- a/src/particles.h +++ b/src/particles.h @@ -26,20 +26,20 @@ GNU General Public License for more details. // snow for menu screens // -------------------------------------------------------------------- -void init_ui_snow (); -void update_ui_snow (double time_step); -void push_ui_snow (const TVector2i& pos); -void draw_ui_snow (); +void init_ui_snow(); +void update_ui_snow(double time_step); +void push_ui_snow(const TVector2i& pos); +void draw_ui_snow(); // -------------------------------------------------------------------- // snow particles during race // -------------------------------------------------------------------- -void create_new_particles (const TVector3d& loc, const TVector3d& vel, int num); -void update_particles (double time_step); -void clear_particles (); -void draw_particles (const CControl *ctrl); -void generate_particles (const CControl *ctrl, double dtime, const TVector3d& pos, double speed); +void create_new_particles(const TVector3d& loc, const TVector3d& vel, int num); +void update_particles(double time_step); +void clear_particles(); +void draw_particles(const CControl *ctrl); +void generate_particles(const CControl *ctrl, double dtime, const TVector3d& pos, double speed); // -------------------------------------------------------------------- // snow flakes for short distances @@ -93,14 +93,14 @@ class CFlakes { private: TVector3d snow_lastpos; vector areas; - void MakeSnowFlake (size_t ar, size_t i); - void GenerateSnowFlakes (const CControl *ctrl); - void UpdateAreas (const CControl *ctrl); + void MakeSnowFlake(size_t ar, size_t i); + void GenerateSnowFlakes(const CControl *ctrl); + void UpdateAreas(const CControl *ctrl); public: - void Init (int grade, const CControl *ctrl); - void Reset (); - void Update (double timestep, const CControl *ctrl); - void Draw (const CControl *ctrl) const; + void Init(int grade, const CControl *ctrl); + void Reset(); + void Update(double timestep, const CControl *ctrl); + void Draw(const CControl *ctrl) const; }; // -------------------------------------------------------------------- @@ -150,19 +150,19 @@ struct TCurtain { void Update(float timestep, const TVector3d& drift, const CControl* ctrl); private: - static void CurtainVec (float angle, float zdist, float &x, float &z); + static void CurtainVec(float angle, float zdist, float &x, float &z); }; class CCurtain { private: vector curtains; - void SetStartParams (const CControl *ctrl); + void SetStartParams(const CControl *ctrl); public: - void Init (const CControl *ctrl); - void Update (float timestep, const CControl *ctrl); - void Draw (); - void Reset (); + void Init(const CControl *ctrl); + void Update(float timestep, const CControl *ctrl); + void Draw(); + void Reset(); }; // -------------------------------------------------------------------- @@ -203,18 +203,18 @@ private: float WindChange; float AngleChange; - void SetParams (int grade); - void CalcDestSpeed (); - void CalcDestAngle (); + void SetParams(int grade); + void CalcDestSpeed(); + void CalcDestAngle(); public: - CWind (); + CWind(); - void Update (float timestep); - void Init (int wind_id); - bool Windy () const { return windy; } - float Angle () const { return WAngle; } - float Speed () const { return WSpeed; } - const TVector3d& WindDrift () const { return WVector; } + void Update(float timestep); + void Init(int wind_id); + bool Windy() const { return windy; } + float Angle() const { return WAngle; } + float Speed() const { return WSpeed; } + const TVector3d& WindDrift() const { return WVector; } }; extern CWind Wind; @@ -223,10 +223,10 @@ extern CWind Wind; // Acess functions // -------------------------------------------------------------------- -void InitSnow (const CControl *ctrl); -void UpdateSnow (double timestep, const CControl *ctrl); -void DrawSnow (const CControl *ctrl); -void InitWind (); -void UpdateWind (double timestep); +void InitSnow(const CControl *ctrl); +void UpdateSnow(double timestep, const CControl *ctrl); +void DrawSnow(const CControl *ctrl); +void InitWind(); +void UpdateWind(double timestep); #endif diff --git a/src/paused.cpp b/src/paused.cpp index df02642..27c1064 100644 --- a/src/paused.cpp +++ b/src/paused.cpp @@ -42,11 +42,11 @@ static bool fog = true; static bool terr = true; static bool trees = true; -void CPaused::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CPaused::Keyb(unsigned int key, bool special, bool release, int x, int y) { if (release) return; switch (key) { case SDLK_s: - ScreenshotN (); + ScreenshotN(); break; case SDLK_F5: sky = !sky; @@ -61,41 +61,40 @@ void CPaused::Keyb (unsigned int key, bool special, bool release, int x, int y) trees = !trees; break; default: - State::manager.RequestEnterState (Racing); + State::manager.RequestEnterState(Racing); } } -void CPaused::Mouse (int button, int state, int x, int y) { - State::manager.RequestEnterState (Racing); +void CPaused::Mouse(int button, int state, int x, int y) { + State::manager.RequestEnterState(Racing); } // ==================================================================== -void CPaused::Loop (double time_step) { +void CPaused::Loop(double time_step) { CControl *ctrl = g_game.player->ctrl; int width = Winsys.resolution.width; int height = Winsys.resolution.height; - check_gl_error(); - Music.Update (); - ClearRenderContext (); - Env.SetupFog (); - update_view (ctrl, 0); - SetupViewFrustum (ctrl); + Music.Update(); + ClearRenderContext(); + Env.SetupFog(); + update_view(ctrl, 0); + SetupViewFrustum(ctrl); - if (sky) Env.DrawSkybox (ctrl->viewpos); - if (fog) Env.DrawFog (); - Env.SetupLight (); + if (sky) Env.DrawSkybox(ctrl->viewpos); + if (fog) Env.DrawFog(); + Env.SetupLight(); if (terr) RenderCourse(); - DrawTrackmarks (); + DrawTrackmarks(); if (trees) DrawTrees(); - DrawSnow (ctrl); + DrawSnow(ctrl); - if (param.perf_level > 2) draw_particles (ctrl); + if (param.perf_level > 2) draw_particles(ctrl); g_game.character->shape->Draw(); - DrawHud (ctrl); - Reshape (width, height); - Winsys.SwapBuffers (); + DrawHud(ctrl); + Reshape(width, height); + Winsys.SwapBuffers(); } diff --git a/src/physics.cpp b/src/physics.cpp index 73634b8..b66e956 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -28,7 +28,7 @@ GNU General Public License for more details. #include "game_over.h" #include -CControl::CControl () : +CControl::CControl() : cnet_force(0, 0, 0) { minSpeed = 0; minFrictspeed = 0; @@ -62,11 +62,11 @@ CControl::CControl () : // init // -------------------------------------------------------------------- -void CControl::Init () { - TVector3d nml = Course.FindCourseNormal (cpos.x, cpos.z); +void CControl::Init() { + TVector3d nml = Course.FindCourseNormal(cpos.x, cpos.z); TMatrix<4, 4> rotMat; rotMat.SetRotationMatrix(-90.0, 'x'); - TVector3d init_vel = TransformVector (rotMat, nml); + TVector3d init_vel = TransformVector(rotMat, nml); init_vel *= INIT_TUX_SPEED; turn_fact = 0; @@ -76,10 +76,10 @@ void CControl::Init () { is_paddling = false; jumping = false; jump_charging = false; - cpos.y = Course.FindYCoord (cpos.x, cpos.z); + cpos.y = Course.FindYCoord(cpos.x, cpos.z); cvel = init_vel; last_pos = cpos; - cnet_force = TVector3d (0, 0, 0); + cnet_force = TVector3d(0, 0, 0); orientation_initialized = false; plane_nml = nml; cdirection = init_vel; @@ -100,36 +100,28 @@ void CControl::Init () { // collision // -------------------------------------------------------------------- -bool CControl::CheckTreeCollisions (const TVector3d& pos, TVector3d *tree_loc, double *tree_diam) { +bool CControl::CheckTreeCollisions(const TVector3d& pos, TVector3d *tree_loc) { // These variables are used to cache collision detection results static bool last_collision = false; static TVector3d last_collision_tree_loc(-999, -999, -999); - static double last_collision_tree_diam = 0; static TVector3d last_collision_pos(-999, -999, -999); TVector3d dist_vec = pos - last_collision_pos; - if (MAG_SQD (dist_vec) < COLL_TOLERANCE) { + if (MAG_SQD(dist_vec) < COLL_TOLERANCE) { if (last_collision && !cairborne) { if (tree_loc != NULL) *tree_loc = last_collision_tree_loc; - if (tree_diam != NULL) *tree_diam = last_collision_tree_diam; return true; } else return false; } - double diam = 0.0; TVector3d loc(0, 0, 0); bool hit = false; TMatrix<4, 4> mat; - TCollidable *trees = &Course.CollArr[0]; - size_t num_trees = Course.CollArr.size(); - size_t tree_type = trees[0].tree_type; - const TPolyhedron* ph = &Course.GetPoly (tree_type); - - for (size_t i=0; i squared_dist) continue; - // have to look at polyhedron - switch to correct one if necessary - if (tree_type != trees[i].tree_type) { - tree_type = trees[i].tree_type; - ph = &Course.GetPoly (tree_type); - } - - TPolyhedron ph2 = *ph; + TPolyhedron ph2 = Course.GetPoly(Course.CollArr[i].tree_type); mat.SetScalingMatrix(diam, height, diam); - TransPolyhedron (mat, ph2); + TransPolyhedron(mat, ph2); mat.SetTranslationMatrix(loc.x, loc.y, loc.z); - TransPolyhedron (mat, ph2); -// hit = TuxCollision2 (pos, ph2); - hit = g_game.character->shape->Collision(pos, ph2); + TransPolyhedron(mat, ph2); + hit = g_game.character->shape->Collision(pos, ph2); if (hit == true) { if (tree_loc != NULL) *tree_loc = loc; - if (tree_diam != NULL) *tree_diam = diam; - Sound.Play ("tree_hit", 0); + Sound.Play("tree_hit", 0); break; } } last_collision_tree_loc = loc; - last_collision_tree_diam = diam; last_collision_pos = pos; + last_collision = hit; - if (hit) last_collision = true; - else last_collision = false; return hit; } -void CControl::AdjustTreeCollision (const TVector3d& pos, TVector3d *vel) { +void CControl::AdjustTreeCollision(const TVector3d& pos, TVector3d *vel) { TVector3d treeLoc; - double tree_diam; - if (CheckTreeCollisions (pos, &treeLoc, &tree_diam)) { + if (CheckTreeCollisions(pos, &treeLoc)) { TVector3d treeNml( pos.x - treeLoc.x, 0, @@ -182,7 +163,7 @@ void CControl::AdjustTreeCollision (const TVector3d& pos, TVector3d *vel) { double speed = vel->Norm(); speed *= 0.8; // original 0.7 - double costheta = DotProduct (*vel, treeNml); + double costheta = DotProduct(*vel, treeNml); if (costheta < 0) { double factor; if (cairborne) factor = 0.5; @@ -190,16 +171,12 @@ void CControl::AdjustTreeCollision (const TVector3d& pos, TVector3d *vel) { *vel += (-factor * costheta) * treeNml; vel->Norm(); } - speed = max (speed, minSpeed); + speed = max(speed, minSpeed); *vel *= speed; } } -void CControl::CheckItemCollection (const TVector3d& pos) { - static TVector3d last_collision_pos(-999, -999, -999); - TVector3d dist_vec = pos - last_collision_pos; - if (MAG_SQD (dist_vec) < COLL_TOLERANCE) return; - +void CControl::CheckItemCollection(const TVector3d& pos) { TItem *items = &Course.NocollArr[0]; size_t num_items = Course.NocollArr.size(); @@ -210,20 +187,15 @@ void CControl::CheckItemCollection (const TVector3d& pos) { double height = items[i].height; const TVector3d& loc = items[i].pt; - TVector3d distvec(loc.x - pos.x, 0.0, loc.z - pos.z); - double squared_dist = (diam / 2. + 0.6); + TVector3d distvec(loc.x - pos.x, loc.y - pos.y, loc.z - pos.z); + double squared_dist = (diam / 2. + 0.7); squared_dist *= squared_dist; - if (MAG_SQD (distvec) > squared_dist) continue; - - if ((pos.y - 0.6 >= loc.y && pos.y - 0.6 <= loc.y + height) || - (pos.y + 0.6 >= loc.y && pos.y + 0.6 <= loc.y + height) || - (pos.y - 0.6 <= loc.y && pos.y + 0.6 >= loc.y + height)) { + if (MAG_SQD(distvec) <= squared_dist) { // Check collision using a bounding sphere items[i].collectable = 0; g_game.herring += 1; - Sound.HaltAll (); - Sound.Play ("pickup1", 0); - Sound.Play ("pickup2", 0); - Sound.Play ("pickup3", 0); + Sound.Play("pickup1", 0); + Sound.Play("pickup2", 0); + Sound.Play("pickup3", 0); } } } @@ -231,26 +203,26 @@ void CControl::CheckItemCollection (const TVector3d& pos) { // position and velocity *** // -------------------------------------------------------------------- -void CControl::AdjustVelocity (const TPlane& surf_plane) { +void CControl::AdjustVelocity(const TPlane& surf_plane) { double speed = cvel.Norm(); - speed = max (minSpeed, speed); + speed = max(minSpeed, speed); cvel *= speed; if (g_game.finish == true) { /// --------------- finish ------------------------------------ - if (speed < 3) State::manager.RequestEnterState (GameOver); + if (speed < 3) State::manager.RequestEnterState(GameOver); /// ----------------------------------------------------------- } } -void CControl::AdjustPosition (const TPlane& surf_plane, double dist_from_surface) { +void CControl::AdjustPosition(const TPlane& surf_plane, double dist_from_surface) { if (dist_from_surface < -MAX_SURF_PEN) { double displace = -MAX_SURF_PEN - dist_from_surface; cpos += displace * surf_plane.nml; } } -void CControl::SetTuxPosition (double speed) { +void CControl::SetTuxPosition(double speed) { CCharShape *shape = g_game.character->shape; TVector2d playSize = Course.GetPlayDimensions(); @@ -267,69 +239,69 @@ void CControl::SetTuxPosition (double speed) { g_game.finish = true; finish_speed = speed; // SetStationaryCamera (true); - } else State::manager.RequestEnterState (GameOver); + } else State::manager.RequestEnterState(GameOver); } /// ----------------------------------------------------------- } double disp_y = cpos.y + TUX_Y_CORR; - shape->ResetNode (0); - shape->TranslateNode (0, TVector3d (cpos.x, disp_y, cpos.z)); + shape->ResetNode(0); + shape->TranslateNode(0, TVector3d(cpos.x, disp_y, cpos.z)); } // -------------------------------------------------------------------- // forces *** // -------------------------------------------------------------------- -TVector3d CControl::CalcRollNormal (double speed) { - TVector3d vel = ProjectToPlane (ff.surfnml, ff.vel); +TVector3d CControl::CalcRollNormal(double speed) { + TVector3d vel = ProjectToPlane(ff.surfnml, ff.vel); vel.Norm(); double roll_angle = MAX_ROLL_ANGLE; if (is_braking) roll_angle = BRAKING_ROLL_ANGLE; double angle = turn_fact * roll_angle * - min (1.0, max (0.0, ff.frict_coeff) / IDEAL_ROLL_FRIC) * - min (1.0, max (0.0, speed - minSpeed) / (IDEAL_ROLL_SPEED - minSpeed)); + min(1.0, max(0.0, ff.frict_coeff) / IDEAL_ROLL_FRIC) * + min(1.0, max(0.0, speed - minSpeed) / (IDEAL_ROLL_SPEED - minSpeed)); TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(vel, angle); - return TransformVector (rot_mat, ff.surfnml); + return TransformVector(rot_mat, ff.surfnml); } const double airlog[] = {-1, 0, 1, 2, 3, 4, 5, 6}; const double airdrag[] = {2.25, 1.35, 0.6, 0, -0.35, -0.45, -0.33, -0.9}; -TVector3d CControl::CalcAirForce () { +TVector3d CControl::CalcAirForce() { TVector3d windvec = -1.0 * ff.vel; if (g_game.wind_id > 0) windvec += WIND_FACTOR * Wind.WindDrift(); double windspeed = windvec.Length(); double re = 34600 * windspeed; - int tablesize = sizeof (airdrag) / sizeof (airdrag[0]); - double interpol = LinearInterp (airlog, airdrag, log10 (re), tablesize); - double dragcoeff = pow (10.0, interpol); + int tablesize = sizeof(airdrag) / sizeof(airdrag[0]); + double interpol = LinearInterp(airlog, airdrag, log10(re), tablesize); + double dragcoeff = pow(10.0, interpol); double airfact = 0.104 * dragcoeff * windspeed; return airfact * windvec; } -TVector3d CControl::CalcSpringForce () { - double springvel = DotProduct (ff.vel, ff.rollnml); - double springfact = min (ff.compression, 0.05) * 1500; - springfact += clamp (0.0, ff.compression - 0.05, 0.12) * 3000; - springfact += max (0.0, ff.compression - 0.12 - 0.05) * 10000; +TVector3d CControl::CalcSpringForce() { + double springvel = DotProduct(ff.vel, ff.rollnml); + double springfact = min(ff.compression, 0.05) * 1500; + springfact += clamp(0.0, ff.compression - 0.05, 0.12) * 3000; + springfact += max(0.0, ff.compression - 0.12 - 0.05) * 10000; springfact -= springvel * (ff.compression <= 0.05 ? 1500 : 500); - springfact = clamp (0.0, springfact, 3000.0); + springfact = clamp(0.0, springfact, 3000.0); return springfact * ff.rollnml; } -TVector3d CControl::CalcNormalForce () { +TVector3d CControl::CalcNormalForce() { if (ff.surfdistance <= -ff.comp_depth) { ff.compression = -ff.surfdistance - ff.comp_depth; - return CalcSpringForce (); + return CalcSpringForce(); } return TVector3d(0, 0, 0); } -TVector3d CControl::CalcJumpForce () { +TVector3d CControl::CalcJumpForce() { TVector3d jumpforce; if (begin_jump == true) { begin_jump = false; @@ -348,26 +320,26 @@ TVector3d CControl::CalcJumpForce () { return jumpforce; // normally scaled with 1.0 } -TVector3d CControl::CalcFrictionForce (double speed, const TVector3d& nmlforce) { +TVector3d CControl::CalcFrictionForce(double speed, const TVector3d& nmlforce) { if ((cairborne == false && speed > minFrictspeed) || g_game.finish) { double fric_f_mag = nmlforce.Length() * ff.frict_coeff; - fric_f_mag = min (MAX_FRICT_FORCE, fric_f_mag); + fric_f_mag = min(MAX_FRICT_FORCE, fric_f_mag); TVector3d frictforce = fric_f_mag * ff.frictdir; double steer_angle = turn_fact * MAX_TURN_ANGLE; - if (fabs (fric_f_mag * sin (steer_angle * M_PI / 180)) > MAX_TURN_PERP) { - steer_angle = RADIANS_TO_ANGLES (asin (MAX_TURN_PERP / fric_f_mag)) * - turn_fact / fabs (turn_fact); + if (fabs(fric_f_mag * sin(steer_angle * M_PI / 180)) > MAX_TURN_PERP) { + steer_angle = RADIANS_TO_ANGLES(asin(MAX_TURN_PERP / fric_f_mag)) * + turn_fact / fabs(turn_fact); } TMatrix<4, 4> fric_rot_mat = RotateAboutVectorMatrix(ff.surfnml, steer_angle); - frictforce = TransformVector (fric_rot_mat, frictforce); + frictforce = TransformVector(fric_rot_mat, frictforce); return (1.0 + MAX_TURN_PEN) * frictforce; } - return TVector3d (0, 0, 0); + return TVector3d(0, 0, 0); } -TVector3d CControl::CalcBrakeForce (double speed) { +TVector3d CControl::CalcBrakeForce(double speed) { if (g_game.finish == false) { if (cairborne == false && speed > minFrictspeed) { if (speed > minSpeed && is_braking) { @@ -388,7 +360,7 @@ TVector3d CControl::CalcBrakeForce (double speed) { return TVector3d(0, 0, 0); } -TVector3d CControl::CalcPaddleForce (double speed) { +TVector3d CControl::CalcPaddleForce(double speed) { TVector3d paddleforce(0, 0, 0); if (is_paddling) if (g_game.time - paddle_time >= PADDLING_DURATION) is_paddling = false; @@ -396,7 +368,7 @@ TVector3d CControl::CalcPaddleForce (double speed) { if (is_paddling) { if (cairborne) { paddleforce.z = -TUX_MASS * EARTH_GRAV / 4.0; - paddleforce = RotateVector (corientation, paddleforce); + paddleforce = RotateVector(corientation, paddleforce); } else { double factor = -1 * min(MAX_PADD_FORCE, MAX_PADD_FORCE * (MAX_PADDLING_SPEED - speed) / MAX_PADDLING_SPEED @@ -407,18 +379,18 @@ TVector3d CControl::CalcPaddleForce (double speed) { return PADDLE_FACT * paddleforce; } -TVector3d CControl::CalcGravitationForce () { +TVector3d CControl::CalcGravitationForce() { if (g_game.finish == false) { - return TVector3d (0, -EARTH_GRAV * TUX_MASS, 0); + return TVector3d(0, -EARTH_GRAV * TUX_MASS, 0); } else { /// ---------------- finish ----------------------------------- - if (cairborne) return TVector3d (0, -FIN_AIR_GRAV, 0); - else return TVector3d (0, -FIN_GRAV, 0); + if (cairborne) return TVector3d(0, -FIN_AIR_GRAV, 0); + else return TVector3d(0, -FIN_GRAV, 0); /// ----------------------------------------------------------- } } -TVector3d CControl::CalcNetForce (const TVector3d& pos, const TVector3d& vel) { +TVector3d CControl::CalcNetForce(const TVector3d& pos, const TVector3d& vel) { // pos and vel are temporary, see ODE solver ff.pos = pos; @@ -431,7 +403,7 @@ TVector3d CControl::CalcNetForce (const TVector3d& pos, const TVector3d& vel) { static vector surfweights; if (surfweights.size() != Course.TerrList.size()) surfweights.resize(Course.TerrList.size()); - Course.GetSurfaceType (ff.pos.x, ff.pos.z, &surfweights[0]); + Course.GetSurfaceType(ff.pos.x, ff.pos.z, &surfweights[0]); TTerrType *TerrList = &Course.TerrList[0]; ff.frict_coeff = ff.comp_depth = 0; for (size_t i=0; i 0); // don't change this order: - TVector3d gravforce = CalcGravitationForce (); - TVector3d nmlforce = CalcNormalForce (); - TVector3d jumpforce = CalcJumpForce (); - TVector3d frictforce = CalcFrictionForce (speed, nmlforce); - TVector3d brakeforce = CalcBrakeForce (speed); - TVector3d airforce = CalcAirForce (); - TVector3d paddleforce = CalcPaddleForce (speed); + TVector3d gravforce = CalcGravitationForce(); + TVector3d nmlforce = CalcNormalForce(); + TVector3d jumpforce = CalcJumpForce(); + TVector3d frictforce = CalcFrictionForce(speed, nmlforce); + TVector3d brakeforce = CalcBrakeForce(speed); + TVector3d airforce = CalcAirForce(); + TVector3d paddleforce = CalcPaddleForce(speed); return jumpforce + gravforce + nmlforce + frictforce + airforce + brakeforce + paddleforce; } @@ -461,21 +433,21 @@ TVector3d CControl::CalcNetForce (const TVector3d& pos, const TVector3d& vel) { // ODE solver // -------------------------------------------------------------------- -double CControl::AdjustTimeStep (double h, const TVector3d& vel) { +double CControl::AdjustTimeStep(double h, const TVector3d& vel) { double speed = vel.Length(); - h = clamp (MIN_TIME_STEP, h, MAX_STEP_DIST / speed); - h = min (h, MAX_TIME_STEP); + h = clamp(MIN_TIME_STEP, h, MAX_STEP_DIST / speed); + h = min(h, MAX_TIME_STEP); return h; } -void CControl::SolveOdeSystem (double timestep) { +void CControl::SolveOdeSystem(double timestep) { double pos_err[3], vel_err[3], tot_pos_err, tot_vel_err; double err=0, tol=0; static const TOdeSolver solver; double h = ode_time_step; if (h < 0 || solver.EstimateError == NULL) - h = AdjustTimeStep (timestep, cvel); + h = AdjustTimeStep(timestep, cvel); double t = 0; double tfinal = timestep; @@ -493,7 +465,7 @@ void CControl::SolveOdeSystem (double timestep) { bool done = false; while (!done) { if (t >= tfinal) { - Message ("t >= tfinal in ode_system()"); + Message("t >= tfinal in ode_system()"); break; } if (1.1 * h > tfinal - t) { @@ -506,55 +478,55 @@ void CControl::SolveOdeSystem (double timestep) { bool failed = false; for (;;) { - solver.InitOdeData (&x, new_pos.x, h); - solver.InitOdeData (&y, new_pos.y, h); - solver.InitOdeData (&z, new_pos.z, h); - solver.InitOdeData (&vx, new_vel.x, h); - solver.InitOdeData (&vy, new_vel.y, h); - solver.InitOdeData (&vz, new_vel.z, h); + solver.InitOdeData(&x, new_pos.x, h); + solver.InitOdeData(&y, new_pos.y, h); + solver.InitOdeData(&z, new_pos.z, h); + solver.InitOdeData(&vx, new_vel.x, h); + solver.InitOdeData(&vy, new_vel.y, h); + solver.InitOdeData(&vz, new_vel.z, h); - solver.UpdateEstimate (&x, 0, new_vel.x); - solver.UpdateEstimate (&y, 0, new_vel.y); - solver.UpdateEstimate (&z, 0, new_vel.z); - solver.UpdateEstimate (&vx, 0, new_f.x / TUX_MASS); - solver.UpdateEstimate (&vy, 0, new_f.y / TUX_MASS); - solver.UpdateEstimate (&vz, 0, new_f.z / TUX_MASS); + solver.UpdateEstimate(&x, 0, new_vel.x); + solver.UpdateEstimate(&y, 0, new_vel.y); + solver.UpdateEstimate(&z, 0, new_vel.z); + solver.UpdateEstimate(&vx, 0, new_f.x / TUX_MASS); + solver.UpdateEstimate(&vy, 0, new_f.y / TUX_MASS); + solver.UpdateEstimate(&vz, 0, new_f.z / TUX_MASS); for (int i=1; i < solver.NumEstimates(); i++) { - new_pos.x = solver.NextValue (&x, i); - new_pos.y = solver.NextValue (&y, i); - new_pos.z = solver.NextValue (&z, i); - new_vel.x = solver.NextValue (&vx, i); - new_vel.y = solver.NextValue (&vy, i); - new_vel.z = solver.NextValue (&vz, i); + new_pos.x = solver.NextValue(&x, i); + new_pos.y = solver.NextValue(&y, i); + new_pos.z = solver.NextValue(&z, i); + new_vel.x = solver.NextValue(&vx, i); + new_vel.y = solver.NextValue(&vy, i); + new_vel.z = solver.NextValue(&vz, i); - solver.UpdateEstimate (&x, i, new_vel.x); - solver.UpdateEstimate (&y, i, new_vel.y); - solver.UpdateEstimate (&z, i, new_vel.z); + solver.UpdateEstimate(&x, i, new_vel.x); + solver.UpdateEstimate(&y, i, new_vel.y); + solver.UpdateEstimate(&z, i, new_vel.z); - new_f = CalcNetForce (new_pos, new_vel); + new_f = CalcNetForce(new_pos, new_vel); - solver.UpdateEstimate (&vx, i, new_f.x / TUX_MASS); - solver.UpdateEstimate (&vy, i, new_f.y / TUX_MASS); - solver.UpdateEstimate (&vz, i, new_f.z / TUX_MASS); + solver.UpdateEstimate(&vx, i, new_f.x / TUX_MASS); + solver.UpdateEstimate(&vy, i, new_f.y / TUX_MASS); + solver.UpdateEstimate(&vz, i, new_f.z / TUX_MASS); } - new_pos.x = solver.FinalEstimate (&x); - new_pos.y = solver.FinalEstimate (&y); - new_pos.z = solver.FinalEstimate (&z); + new_pos.x = solver.FinalEstimate(&x); + new_pos.y = solver.FinalEstimate(&y); + new_pos.z = solver.FinalEstimate(&z); - new_vel.x = solver.FinalEstimate (&vx); - new_vel.y = solver.FinalEstimate (&vy); - new_vel.z = solver.FinalEstimate (&vz); + new_vel.x = solver.FinalEstimate(&vx); + new_vel.y = solver.FinalEstimate(&vy); + new_vel.z = solver.FinalEstimate(&vz); if (solver.EstimateError != NULL) { - pos_err[0] = solver.EstimateError (&x); - pos_err[1] = solver.EstimateError (&y); - pos_err[2] = solver.EstimateError (&z); + pos_err[0] = solver.EstimateError(&x); + pos_err[1] = solver.EstimateError(&y); + pos_err[2] = solver.EstimateError(&z); - vel_err[0] = solver.EstimateError (&vx); - vel_err[1] = solver.EstimateError (&vy); - vel_err[2] = solver.EstimateError (&vz); + vel_err[0] = solver.EstimateError(&vx); + vel_err[1] = solver.EstimateError(&vy); + vel_err[2] = solver.EstimateError(&vz); tot_pos_err = 0.; tot_vel_err = 0.; @@ -565,8 +537,8 @@ void CControl::SolveOdeSystem (double timestep) { vel_err[i] *= vel_err[i]; tot_vel_err += vel_err[i]; } - tot_pos_err = sqrt (tot_pos_err); - tot_vel_err = sqrt (tot_vel_err); + tot_pos_err = sqrt(tot_pos_err); + tot_vel_err = sqrt(tot_vel_err); if (tot_pos_err / MAX_POS_ERR > tot_vel_err / MAX_VEL_ERR) { err = tot_pos_err; tol = MAX_POS_ERR; @@ -579,10 +551,10 @@ void CControl::SolveOdeSystem (double timestep) { done = false; if (!failed) { failed = true; - h *= max (0.5, 0.8 * pow (tol/err, solver.TimestepExponent())); + h *= max(0.5, 0.8 * pow(tol/err, solver.TimestepExponent())); } else h *= 0.5; - h = AdjustTimeStep (h, saved_vel); + h = AdjustTimeStep(h, saved_vel); new_pos = saved_pos; new_vel = saved_vel; new_f = saved_f; @@ -592,19 +564,19 @@ void CControl::SolveOdeSystem (double timestep) { t = t + h; double speed = new_vel.Length(); - if (param.perf_level > 2) generate_particles (this, h, new_pos, speed); + if (param.perf_level > 2) generate_particles(this, h, new_pos, speed); - new_f = CalcNetForce (new_pos, new_vel); + new_f = CalcNetForce(new_pos, new_vel); if (!failed && solver.EstimateError != NULL) { - double temp = 1.25 * pow (err / tol, solver.TimestepExponent()); + double temp = 1.25 * pow(err / tol, solver.TimestepExponent()); if (temp > 0.2) h = h / temp; else h = 5.0 * h; } - h = AdjustTimeStep (h, new_vel); - AdjustTreeCollision (new_pos, &new_vel); + h = AdjustTimeStep(h, new_vel); + AdjustTreeCollision(new_pos, &new_vel); // if (g_game.finish) new_vel = ScaleVector (0.99,new_vel); - CheckItemCollection (new_pos); + CheckItemCollection(new_pos); } ode_time_step = h; cnet_force = new_f; @@ -621,7 +593,7 @@ void CControl::SolveOdeSystem (double timestep) { // update tux position // -------------------------------------------------------------------- -void CControl::UpdatePlayerPos (double timestep) { +void CControl::UpdatePlayerPos(double timestep) { CCharShape *shape = g_game.character->shape; double paddling_factor; double flap_factor; @@ -637,17 +609,17 @@ void CControl::UpdatePlayerPos (double timestep) { minFrictspeed = MIN_FRICT_SPEED; } - if (timestep > 2 * EPS) SolveOdeSystem (timestep); + if (timestep > 2 * EPS) SolveOdeSystem(timestep); - TPlane surf_plane = Course.GetLocalCoursePlane (cpos); + TPlane surf_plane = Course.GetLocalCoursePlane(cpos); TVector3d surf_nml = surf_plane.nml; // normal vector of terrain - dist_from_surface = DistanceToPlane (surf_plane, cpos); + dist_from_surface = DistanceToPlane(surf_plane, cpos); double speed = cvel.Length(); - AdjustVelocity (surf_plane); - AdjustPosition (surf_plane, dist_from_surface); - SetTuxPosition (speed); // speed only to set finish_speed - shape->AdjustOrientation (this, timestep, dist_from_surface, surf_nml); + AdjustVelocity(surf_plane); + AdjustPosition(surf_plane, dist_from_surface); + SetTuxPosition(speed); // speed only to set finish_speed + shape->AdjustOrientation(this, timestep, dist_from_surface, surf_nml); flap_factor = 0; if (is_paddling) { @@ -665,11 +637,11 @@ void CControl::UpdatePlayerPos (double timestep) { } TVector3d local_force = RotateVector - (ConjugateQuaternion (corientation), cnet_force); + (ConjugateQuaternion(corientation), cnet_force); if (jumping) flap_factor = (g_game.time - jump_start_time) / JUMP_FORCE_DURATION; - shape->AdjustJoints (turn_animation, is_braking, paddling_factor, speed, - local_force, flap_factor); + shape->AdjustJoints(turn_animation, is_braking, paddling_factor, speed, + local_force, flap_factor); } diff --git a/src/physics.h b/src/physics.h index 934c790..17e8524 100644 --- a/src/physics.h +++ b/src/physics.h @@ -81,29 +81,29 @@ private: double ode_time_step; double finish_speed; - bool CheckTreeCollisions (const TVector3d& pos, TVector3d *tree_loc, double *tree_diam); - void AdjustTreeCollision (const TVector3d& pos, TVector3d *vel); - void CheckItemCollection (const TVector3d& pos); + bool CheckTreeCollisions(const TVector3d& pos, TVector3d *tree_loc); + void AdjustTreeCollision(const TVector3d& pos, TVector3d *vel); + void CheckItemCollection(const TVector3d& pos); - TVector3d CalcRollNormal (double speed); - TVector3d CalcAirForce (); - TVector3d CalcSpringForce (); - TVector3d CalcNormalForce (); - TVector3d CalcJumpForce (); - TVector3d CalcFrictionForce (double speed, const TVector3d& nmlforce); - TVector3d CalcPaddleForce (double speed); - TVector3d CalcBrakeForce (double speed); - TVector3d CalcGravitationForce (); - TVector3d CalcNetForce (const TVector3d& pos, const TVector3d& vel); - TVector3d CalcFinishForce (const TVector3d& pos, const TVector3d& vel); + TVector3d CalcRollNormal(double speed); + TVector3d CalcAirForce(); + TVector3d CalcSpringForce(); + TVector3d CalcNormalForce(); + TVector3d CalcJumpForce(); + TVector3d CalcFrictionForce(double speed, const TVector3d& nmlforce); + TVector3d CalcPaddleForce(double speed); + TVector3d CalcBrakeForce(double speed); + TVector3d CalcGravitationForce(); + TVector3d CalcNetForce(const TVector3d& pos, const TVector3d& vel); + TVector3d CalcFinishForce(const TVector3d& pos, const TVector3d& vel); - void AdjustVelocity (const TPlane& surf_plane); - void AdjustPosition (const TPlane& surf_plane, double dist_from_surface); - void SetTuxPosition (double speed); - double AdjustTimeStep (double h, const TVector3d& vel); - void SolveOdeSystem (double timestep); + void AdjustVelocity(const TPlane& surf_plane); + void AdjustPosition(const TPlane& surf_plane, double dist_from_surface); + void SetTuxPosition(double speed); + double AdjustTimeStep(double h, const TVector3d& vel); + void SolveOdeSystem(double timestep); public: - CControl (); + CControl(); // view: TViewMode viewmode; @@ -147,8 +147,8 @@ public: double minSpeed; double minFrictspeed; - void Init (); - void UpdatePlayerPos (double timestep); + void Init(); + void UpdatePlayerPos(double timestep); }; #endif diff --git a/src/quadtree.cpp b/src/quadtree.cpp index babc977..bcc1d18 100644 --- a/src/quadtree.cpp +++ b/src/quadtree.cpp @@ -65,7 +65,7 @@ GLuint quadsquare::VertexArrayCounter; GLuint quadsquare::VertexArrayMinIdx; GLuint quadsquare::VertexArrayMaxIdx; -quadsquare::quadsquare (quadcornerdata* pcd) { +quadsquare::quadsquare(quadcornerdata* pcd) { pcd->Square = this; Static = false; ForceEastVert = false; @@ -107,7 +107,7 @@ quadsquare::~quadsquare() { } } -void quadsquare::SetStatic (const quadcornerdata &cd) { +void quadsquare::SetStatic(const quadcornerdata &cd) { if (Static == false) { Static = true; if (cd.Parent && cd.Parent->Square) { @@ -360,7 +360,7 @@ float quadsquare::RecomputeError(const quadcornerdata& cd) { if (total > 0) { terrain_error = (1.0 - max_count / total); if (numTerr > 1) { - terrain_error *= numTerr / (numTerr - 1.0); + terrain_error *= numTerr / (numTerr - 1.0); } } else terrain_error = 0; terrain_error *= whole * whole; @@ -571,10 +571,10 @@ static float DetailThreshold = 100; bool quadsquare::VertexTest(int x, float y, int z, float error, const float Viewer[3], int level, vertex_loc_t vertex_loc) { - float dx = fabs(x - Viewer[0]) * fabs (ScaleX); + float dx = fabs(x - Viewer[0]) * fabs(ScaleX); float dy = fabs(y - Viewer[1]); - float dz = fabs(z - Viewer[2]) * fabs (ScaleZ); - float d = max (dx, max (dy, dz) ); + float dz = fabs(z - Viewer[2]) * fabs(ScaleZ); + float d = max(dx, max(dy, dz)); if (vertex_loc == South && ForceSouthVert && d < VERTEX_FORCE_THRESHOLD) { return true; @@ -591,10 +591,10 @@ bool quadsquare::VertexTest(int x, float y, int z, float error, bool quadsquare::BoxTest(int x, int z, float size, float miny, float maxy, float error, const float Viewer[3]) { float half = size * 0.5; - float dx = (fabs(x + half - Viewer[0]) - half ) * fabs(ScaleX); + float dx = (fabs(x + half - Viewer[0]) - half) * fabs(ScaleX); float dy = fabs((miny + maxy) * 0.5 - Viewer[1]) - (maxy - miny) * 0.5; - float dz = (fabs(z + half - Viewer[2]) - half ) * fabs(ScaleZ); - float d = max (dx, max (dy , dz) ); + float dz = (fabs(z + half - Viewer[2]) - half) * fabs(ScaleZ); + float d = max(dx, max(dy , dz)); if (d < ERROR_MAGNIFICATION_THRESHOLD) { error *= ERROR_MAGNIFICATION_AMOUNT; @@ -603,15 +603,15 @@ bool quadsquare::BoxTest(int x, int z, float size, float miny, float maxy, float if (error * DetailThreshold > d) { return true; } - if ( (x < RowSize-1 && x+size >= RowSize) || - (z < NumRows-1 && z+size >= NumRows) ) { + if ((x < RowSize-1 && x+size >= RowSize) || + (z < NumRows-1 && z+size >= NumRows)) { return true; } return false; } -void quadsquare::Update (const quadcornerdata& cd, const TVector3d& ViewerLocation, float Detail) { +void quadsquare::Update(const quadcornerdata& cd, const TVector3d& ViewerLocation, float Detail) { float Viewer[3]; DetailThreshold = Detail; @@ -622,10 +622,10 @@ void quadsquare::Update (const quadcornerdata& cd, const TVector3d& ViewerLocati } -void quadsquare::UpdateAux (const quadcornerdata& cd, - const float ViewerLocation[3], float CenterError, clip_result_t vis) { +void quadsquare::UpdateAux(const quadcornerdata& cd, + const float ViewerLocation[3], float CenterError, clip_result_t vis) { if (vis != NoClip) { - vis = ClipSquare (cd); + vis = ClipSquare(cd); if (vis == NotVisible) { return; @@ -639,13 +639,13 @@ void quadsquare::UpdateAux (const quadcornerdata& cd, int whole = half << 1; if ((EnabledFlags & 1) == 0 && VertexTest(cd.xorg + whole, Vertex[1].Y, cd.zorg + half, - Error[0], ViewerLocation, cd.Level, East) == true ) { + Error[0], ViewerLocation, cd.Level, East) == true) { EnableEdgeVertex(0, false, cd); } if ((EnabledFlags & 8) == 0 && VertexTest(cd.xorg + half, Vertex[4].Y, cd.zorg + whole, - Error[1], ViewerLocation, cd.Level, South) == true ) { + Error[1], ViewerLocation, cd.Level, South) == true) { EnableEdgeVertex(3, false, cd); } @@ -732,11 +732,11 @@ void quadsquare::DrawTris() { if (glLockArraysEXT_p) { if (tmp_min_idx == 0) tmp_min_idx = 1; - glLockArraysEXT_p (tmp_min_idx, VertexArrayMaxIdx - tmp_min_idx + 1); + glLockArraysEXT_p(tmp_min_idx, VertexArrayMaxIdx - tmp_min_idx + 1); } - glDrawElements (GL_TRIANGLES, VertexArrayCounter, - GL_UNSIGNED_INT, VertexArrayIndices); + glDrawElements(GL_TRIANGLES, VertexArrayCounter, + GL_UNSIGNED_INT, VertexArrayIndices); if (glUnlockArraysEXT_p) glUnlockArraysEXT_p(); } @@ -746,11 +746,11 @@ void quadsquare::InitArrayCounters() { VertexArrayMaxIdx = 0; } -void quadsquare::Render (const quadcornerdata& cd, GLubyte *vnc_array) { +void quadsquare::Render(const quadcornerdata& cd, GLubyte *vnc_array) { VNCArray = vnc_array; bool fog_on; int nx, ny; - Course.GetDivisions (&nx, &ny); + Course.GetDivisions(&nx, &ny); const TTerrType *TerrList = &Course.TerrList[0]; size_t numTerrains = Course.TerrList.size(); @@ -759,34 +759,34 @@ void quadsquare::Render (const quadcornerdata& cd, GLubyte *vnc_array) { for (size_t j=0; jBind(); - DrawTris (); + DrawTris(); } } if (param.perf_level > 1) { InitArrayCounters(); - RenderAux (cd, SomeClip, -1); + RenderAux(cd, SomeClip, -1); if (VertexArrayCounter != 0) { - glDisable (GL_FOG); + glDisable(GL_FOG); for (GLuint i=0; iBind(); DrawTris(); - if (fog_on) glEnable (GL_FOG); - glBlendFunc (GL_SRC_ALPHA, GL_ONE); + if (fog_on) glEnable(GL_FOG); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); for (GLuint i=0; iBind(); for (GLuint i=0; i= RowSize-1) { return NotVisible; } @@ -851,52 +851,52 @@ clip_result_t quadsquare::ClipSquare (const quadcornerdata& cd) { } -inline void quadsquare::MakeTri (int a, int b, int c, int terrain) { - if ( (VertexTerrains[a] == terrain || +inline void quadsquare::MakeTri(int a, int b, int c, int terrain) { + if ((VertexTerrains[a] == terrain || VertexTerrains[b] == terrain || - VertexTerrains[c] == terrain) ) { + VertexTerrains[c] == terrain)) { VertexArrayIndices[VertexArrayCounter++] = VertexIndices[a]; setalphaval(a); - update_min_max (VertexIndices[a]); + update_min_max(VertexIndices[a]); VertexArrayIndices[VertexArrayCounter++] = VertexIndices[b]; setalphaval(b); - update_min_max (VertexIndices[b]); + update_min_max(VertexIndices[b]); VertexArrayIndices[VertexArrayCounter++] = VertexIndices[c]; setalphaval(c); - update_min_max (VertexIndices[c]); + update_min_max(VertexIndices[c]); } } -inline void quadsquare::MakeSpecialTri (int a, int b, int c, int terrain) { +inline void quadsquare::MakeSpecialTri(int a, int b, int c, int terrain) { if (VertexTerrains[a] != VertexTerrains[b] && VertexTerrains[a] != VertexTerrains[c] && VertexTerrains[b] != VertexTerrains[c]) { VertexArrayIndices[VertexArrayCounter++] = VertexIndices[a]; - update_min_max (VertexIndices[a]); + update_min_max(VertexIndices[a]); VertexArrayIndices[VertexArrayCounter++] = VertexIndices[b]; - update_min_max (VertexIndices[b]); + update_min_max(VertexIndices[b]); VertexArrayIndices[VertexArrayCounter++] = VertexIndices[c]; - update_min_max (VertexIndices[c]); + update_min_max(VertexIndices[c]); } } -inline void quadsquare::MakeNoBlendTri (int a, int b, int c, int terrain) { - if ( (VertexTerrains[a] == terrain || +inline void quadsquare::MakeNoBlendTri(int a, int b, int c, int terrain) { + if ((VertexTerrains[a] == terrain || VertexTerrains[b] == terrain || VertexTerrains[c] == terrain) && (VertexTerrains[a] >= terrain && VertexTerrains[b] >= terrain && - VertexTerrains[c] >= terrain) ) { + VertexTerrains[c] >= terrain)) { VertexArrayIndices[VertexArrayCounter++] = VertexIndices[a]; setalphaval(a); - update_min_max (VertexIndices[a]); + update_min_max(VertexIndices[a]); VertexArrayIndices[VertexArrayCounter++] = VertexIndices[b]; setalphaval(b); - update_min_max (VertexIndices[b]); + update_min_max(VertexIndices[b]); VertexArrayIndices[VertexArrayCounter++] = VertexIndices[c]; setalphaval(c); - update_min_max (VertexIndices[c]); + update_min_max(VertexIndices[c]); } } @@ -904,7 +904,7 @@ void quadsquare::RenderAux(const quadcornerdata& cd, clip_result_t vis, int terr int half = 1 << cd.Level; int whole = 2 << cd.Level; if (vis != NoClip) { - vis = ClipSquare (cd); + vis = ClipSquare(cd); if (vis == NotVisible) return; } @@ -1062,7 +1062,7 @@ void quadsquare::SetScale(double x, double z) { } char* quadsquare::Terrain; -void quadsquare::SetTerrain (char *t) { +void quadsquare::SetTerrain(char *t) { Terrain = t; } @@ -1092,16 +1092,16 @@ void ResetQuadtree() { } } -static int get_root_level (int nx, int nz) { - int xlev = (int) (log(static_cast(nx)) / log (2.0)); - int zlev = (int) (log(static_cast(nz)) / log (2.0)); +static int get_root_level(int nx, int nz) { + int xlev = (int)(log(static_cast(nx)) / log(2.0)); + int zlev = (int)(log(static_cast(nz)) / log(2.0)); - return max (xlev, zlev); + return max(xlev, zlev); } -void InitQuadtree (double *elevation, int nx, int nz, - double scalex, double scalez, const TVector3d& view_pos, double detail) { +void InitQuadtree(double *elevation, int nx, int nz, + double scalex, double scalez, const TVector3d& view_pos, double detail) { HeightMapInfo hm; hm.Data = elevation; @@ -1114,7 +1114,7 @@ void InitQuadtree (double *elevation, int nx, int nz, root_corner_data.Square = (quadsquare*)NULL; root_corner_data.ChildIndex = 0; - root_corner_data.Level = get_root_level (nx, nz); + root_corner_data.Level = get_root_level(nx, nz); root_corner_data.xorg = 0; root_corner_data.zorg = 0; @@ -1123,19 +1123,19 @@ void InitQuadtree (double *elevation, int nx, int nz, root_corner_data.Verts[i].Y = 0; } - root = new quadsquare (&root_corner_data); - root->AddHeightMap (root_corner_data, hm); - root->SetScale (scalex, scalez); - root->SetTerrain (Course.terrain); + root = new quadsquare(&root_corner_data); + root->AddHeightMap(root_corner_data, hm); + root->SetScale(scalex, scalez); + root->SetTerrain(Course.terrain); - root->StaticCullData (root_corner_data, CULL_DETAIL_FACTOR); + root->StaticCullData(root_corner_data, CULL_DETAIL_FACTOR); for (int i = 0; i < 10; i++) { root->Update(root_corner_data, view_pos, detail); } } -void UpdateQuadtree (const TVector3d& view_pos, float detail) { +void UpdateQuadtree(const TVector3d& view_pos, float detail) { root->Update(root_corner_data, view_pos, detail); } diff --git a/src/quadtree.h b/src/quadtree.h index 793a769..40792fd 100644 --- a/src/quadtree.h +++ b/src/quadtree.h @@ -77,14 +77,14 @@ struct quadsquare { static GLuint VertexArrayMinIdx; static GLuint VertexArrayMaxIdx; - static void MakeTri( int a, int b, int c, int terrain ); - static void MakeSpecialTri( int a, int b, int c, int terrain ); - static void MakeNoBlendTri( int a, int b, int c, int terrain ); + static void MakeTri(int a, int b, int c, int terrain); + static void MakeSpecialTri(int a, int b, int c, int terrain); + static void MakeNoBlendTri(int a, int b, int c, int terrain); static void DrawTris(); static void InitArrayCounters(); - quadsquare (quadcornerdata* pcd); + quadsquare(quadcornerdata* pcd); ~quadsquare(); void AddHeightMap(const quadcornerdata& cd, const HeightMapInfo& hm); @@ -95,29 +95,29 @@ struct quadsquare { void Render(const quadcornerdata& cd, GLubyte *vnc_array); float GetHeight(const quadcornerdata& cd, float x, float z); void SetScale(double x, double z); - void SetTerrain (char *terrain); + void SetTerrain(char *terrain); private: quadsquare* EnableDescendant(int count, int stack[], const quadcornerdata& cd); quadsquare* GetNeighbor(int dir, const quadcornerdata &cd); - clip_result_t ClipSquare( const quadcornerdata &cd ); + clip_result_t ClipSquare(const quadcornerdata &cd); void EnableEdgeVertex(int index, bool IncrementCount, const quadcornerdata &cd); void EnableChild(int index, const quadcornerdata &cd); void NotifyChildDisable(const quadcornerdata& cd, int index); void ResetTree(); - void StaticCullAux (const quadcornerdata &cd, float ThresholdDetail, - int TargetLevel); + void StaticCullAux(const quadcornerdata &cd, float ThresholdDetail, + int TargetLevel); void CreateChild(int index, const quadcornerdata &cd); - void SetupCornerData (quadcornerdata *q, const quadcornerdata &pd, - int ChildIndex); + void SetupCornerData(quadcornerdata *q, const quadcornerdata &pd, + int ChildIndex); void UpdateAux(const quadcornerdata &cd, const float ViewerLocation[3], float CenterError, clip_result_t vis); void RenderAux(const quadcornerdata &cd, clip_result_t vis, int terrain); - void SetStatic (const quadcornerdata &cd); + void SetStatic(const quadcornerdata &cd); void InitVert(int i, int x, int z); bool VertexTest(int x, float y, int z, float error, const float Viewer[3], int level, vertex_loc_t vertex_loc); @@ -130,11 +130,11 @@ private: // -------------------------------------------------------------------- void ResetQuadtree(); -void InitQuadtree (double *elevation, int nx, int nz, - double scalex, double scalez, - const TVector3d& view_pos, double detail); +void InitQuadtree(double *elevation, int nx, int nz, + double scalex, double scalez, + const TVector3d& view_pos, double detail); -void UpdateQuadtree (const TVector3d& view_pos, float detail); +void UpdateQuadtree(const TVector3d& view_pos, float detail); void RenderQuadtree(); diff --git a/src/race_select.cpp b/src/race_select.cpp index badb9bc..8a64b6a 100644 --- a/src/race_select.cpp +++ b/src/race_select.cpp @@ -71,34 +71,34 @@ void SetRaceConditions() { g_game.course = &Course.CourseList[course->GetValue()]; g_game.theme_id = CourseList[course->GetValue()].music_theme; g_game.game_type = PRACTICING; - State::manager.RequestEnterState (Loading); + State::manager.RequestEnterState(Loading); } -void CRaceSelect::Motion (int x, int y) { +void CRaceSelect::Motion(int x, int y) { MouseMoveGUI(x, y); - if (param.ui_snow) push_ui_snow (cursor_pos); + if (param.ui_snow) push_ui_snow(cursor_pos); - UpdateInfo (); + UpdateInfo(); } -void CRaceSelect::Mouse (int button, int state, int x, int y) { +void CRaceSelect::Mouse(int button, int state, int x, int y) { if (state == 1) { ClickGUI(x, y); if (textbuttons[0]->focussed()) - SetRaceConditions (); + SetRaceConditions(); else if (textbuttons[1]->focussed()) - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); if (random_btn->focussed()) { - mirror->SetValue(IRandom (0, 1)); - light->SetValue(IRandom (0, 3)); - snow->SetValue(IRandom (0, 3)); - wind->SetValue(IRandom (0, 3)); + mirror->SetValue(IRandom(0, 1)); + light->SetValue(IRandom(0, 3)); + snow->SetValue(IRandom(0, 3)); + wind->SetValue(IRandom(0, 3)); } - UpdateInfo (); + UpdateInfo(); } } @@ -107,7 +107,7 @@ void CRaceSelect::Keyb(unsigned int key, bool special, bool release, int x, int KeyGUI(key, 0, release); switch (key) { case SDLK_ESCAPE: - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); break; case SDLK_u: param.ui_snow = !param.ui_snow; @@ -125,9 +125,9 @@ void CRaceSelect::Keyb(unsigned int key, bool special, bool release, int x, int break; case SDLK_RETURN: if (textbuttons[1]->focussed()) - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); else - SetRaceConditions (); + SetRaceConditions(); break; } } @@ -139,40 +139,41 @@ static int prevtop, prevwidth, prevheight; static int boxleft, boxwidth; void CRaceSelect::Enter() { - Winsys.ShowCursor (!param.ice_cursor); - Music.Play (param.menu_music, -1); + Winsys.ShowCursor(!param.ice_cursor); + Music.Play(param.menu_music, -1); CourseList = &Course.CourseList[0]; framewidth = 550 * Winsys.scale; frameheight = 50 * Winsys.scale; - frametop = AutoYPosN (30); + frametop = AutoYPosN(30); - area = AutoAreaN (30, 80, framewidth); - prevtop = AutoYPosN (50); + area = AutoAreaN(30, 80, framewidth); + prevtop = AutoYPosN(50); prevheight = 144 * Winsys.scale; prevwidth = 192 * Winsys.scale; boxwidth = framewidth - prevwidth - 20; boxleft = area.right - boxwidth; int icontop = AutoYPosN(40); int iconsize = 32 * Winsys.scale; - int iconspace = (int) ((iconsize + 6) * 1.5); + int iconspace = (int)((iconsize + 6) * 1.5); int iconsumwidth = iconspace * 4 + iconsize; int iconleft = (Winsys.resolution.width - iconsumwidth) / 2; - ResetGUI (); + ResetGUI(); course = AddUpDown(area.left + framewidth + 8, frametop, 0, (int)Course.CourseList.size() - 1, g_game.course?(int)Course.GetCourseIdx(g_game.course):0); random_btn = AddIconButton(iconleft + iconspace * 4, icontop, Tex.GetTexture(RANDOM_BUTT), iconsize, 0, 0); - light = AddIconButton (iconleft, icontop, Tex.GetTexture (LIGHT_BUTT), iconsize, 3, (int)g_game.light_id); - snow = AddIconButton (iconleft + iconspace, icontop, Tex.GetTexture (SNOW_BUTT), iconsize, 3, g_game.snow_id); - wind = AddIconButton (iconleft + iconspace*2, icontop, Tex.GetTexture (WIND_BUTT), iconsize, 3, g_game.wind_id); - mirror = AddIconButton (iconleft + iconspace*3, icontop, Tex.GetTexture (MIRROR_BUTT), iconsize, 1, (int)g_game.mirrorred); - random_btn = AddIconButton (iconleft + iconspace*4, icontop, Tex.GetTexture (RANDOM_BUTT), iconsize, 0, 0); int siz = FT.AutoSizeN (5); - int len1 = FT.GetTextWidth (Trans.Text(13)); - textbuttons[0] = AddTextButton (Trans.Text(13), area.right-len1-50, AutoYPosN (80), siz); - textbuttons[1] = AddTextButton (Trans.Text(8), area.left + 50, AutoYPosN (80), siz); + light = AddIconButton(iconleft, icontop, Tex.GetTexture(LIGHT_BUTT), iconsize, 3, (int)g_game.light_id); + snow = AddIconButton(iconleft + iconspace, icontop, Tex.GetTexture(SNOW_BUTT), iconsize, 3, g_game.snow_id); + wind = AddIconButton(iconleft + iconspace*2, icontop, Tex.GetTexture(WIND_BUTT), iconsize, 3, g_game.wind_id); + mirror = AddIconButton(iconleft + iconspace*3, icontop, Tex.GetTexture(MIRROR_BUTT), iconsize, 1, (int)g_game.mirrorred); + random_btn = AddIconButton(iconleft + iconspace*4, icontop, Tex.GetTexture(RANDOM_BUTT), iconsize, 0, 0); + int siz = FT.AutoSizeN(5); + int len1 = FT.GetTextWidth(Trans.Text(13)); + textbuttons[0] = AddTextButton(Trans.Text(13), area.right-len1-50, AutoYPosN(80), siz); + textbuttons[1] = AddTextButton(Trans.Text(8), area.left + 50, AutoYPosN(80), siz); } void CRaceSelect::Loop(double timestep) { @@ -180,22 +181,21 @@ void CRaceSelect::Loop(double timestep) { int hh = Winsys.resolution.height; TColor col; - check_gl_error(); ScopedRenderMode rm(GUI); - ClearRenderContext (); - SetupGuiDisplay (); + ClearRenderContext(); + SetupGuiDisplay(); - Music.Update (); + Music.Update(); if (param.ui_snow) { - update_ui_snow (timestep); - draw_ui_snow (); + update_ui_snow(timestep); + draw_ui_snow(); } - Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), 1.0); - Tex.Draw (BOTTOM_LEFT, 0, hh-256, 1); - Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); - Tex.Draw (TOP_LEFT, 0, 0, 1); - Tex.Draw (TOP_RIGHT, ww-256, 0, 1); + Tex.Draw(T_TITLE_SMALL, CENTER, AutoYPosN(5), 1.0); + Tex.Draw(BOTTOM_LEFT, 0, hh-256, 1); + Tex.Draw(BOTTOM_RIGHT, ww-256, hh-256, 1); + Tex.Draw(TOP_LEFT, 0, 0, 1); + Tex.Draw(TOP_RIGHT, ww-256, 0, 1); // DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top, // 0, colMBackgr, colBlack, 0.2); @@ -203,36 +203,36 @@ void CRaceSelect::Loop(double timestep) { // course selection if (course->focussed()) col = colDYell; else col = colWhite; - DrawFrameX (area.left, frametop, framewidth, frameheight, 3, colMBackgr, col, 1.0); - FT.AutoSizeN (4); - FT.SetColor (colDYell); - FT.DrawString (area.left+20, frametop, CourseList[course->GetValue()].name); + DrawFrameX(area.left, frametop, framewidth, frameheight, 3, colMBackgr, col, 1.0); + FT.AutoSizeN(4); + FT.SetColor(colDYell); + FT.DrawString(area.left+20, frametop, CourseList[course->GetValue()].name); if (CourseList[course->GetValue()].preview) CourseList[course->GetValue()].preview->DrawFrame(area.left + 3, prevtop, prevwidth, prevheight, 3, colWhite); - DrawFrameX (area.right-boxwidth, prevtop-3, boxwidth, prevheight+6, 3, colBackgr, colWhite, 1.0); - FT.AutoSizeN (2); - FT.SetColor (colWhite); - int dist = FT.AutoDistanceN (0); + DrawFrameX(area.right-boxwidth, prevtop-3, boxwidth, prevheight+6, 3, colBackgr, colWhite, 1.0); + FT.AutoSizeN(2); + FT.SetColor(colWhite); + int dist = FT.AutoDistanceN(0); for (size_t i=0; iGetValue()].num_lines; i++) { - FT.DrawString (boxleft+8, prevtop+i*dist, CourseList[course->GetValue()].desc[i]); + FT.DrawString(boxleft+8, prevtop+i*dist, CourseList[course->GetValue()].desc[i]); } - FT.DrawString (CENTER, prevtop + prevheight + 10, "Author: " + CourseList[course->GetValue()].author); + FT.DrawString(CENTER, prevtop + prevheight + 10, "Author: " + CourseList[course->GetValue()].author); - FT.DrawString (CENTER, AutoYPosN (45), info); + FT.DrawString(CENTER, AutoYPosN(45), info); if (g_game.force_treemap) { - FT.AutoSizeN (4); + FT.AutoSizeN(4); static const string forcetrees = "Load trees.png"; string sizevar = "Size: "; - sizevar += Int_StrN (g_game.treesize); + sizevar += Int_StrN(g_game.treesize); sizevar += " Variation: "; - sizevar += Int_StrN (g_game.treevar); - FT.SetColor (colYellow); - FT.DrawString (CENTER, AutoYPosN (85), forcetrees); - FT.DrawString (CENTER, AutoYPosN (90), sizevar); + sizevar += Int_StrN(g_game.treevar); + FT.SetColor(colYellow); + FT.DrawString(CENTER, AutoYPosN(85), forcetrees); + FT.DrawString(CENTER, AutoYPosN(90), sizevar); } DrawGUI(); diff --git a/src/racing.cpp b/src/racing.cpp index 4846b9e..0a36a06 100644 --- a/src/racing.cpp +++ b/src/racing.cpp @@ -66,7 +66,7 @@ static bool trees = true; static int newsound = -1; static int lastsound = -1; -void CRacing::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CRacing::Keyb(unsigned int key, bool special, bool release, int x, int y) { switch (key) { // steering flipflops case SDLK_UP: @@ -92,35 +92,35 @@ void CRacing::Keyb (unsigned int key, bool special, bool release, int x, int y) if (!release) { g_game.raceaborted = true; g_game.race_result = -1; - State::manager.RequestEnterState (GameOver); + State::manager.RequestEnterState(GameOver); } break; case SDLK_p: - if (!release) State::manager.RequestEnterState (Paused); + if (!release) State::manager.RequestEnterState(Paused); break; case SDLK_r: - if (!release) State::manager.RequestEnterState (Reset); + if (!release) State::manager.RequestEnterState(Reset); break; case SDLK_s: - if (!release) ScreenshotN (); + if (!release) ScreenshotN(); break; // view changing case SDLK_1: if (!release) { - set_view_mode (g_game.player->ctrl, ABOVE); + set_view_mode(g_game.player->ctrl, ABOVE); param.view_mode = ABOVE; } break; case SDLK_2: if (!release) { - set_view_mode (g_game.player->ctrl, FOLLOW); + set_view_mode(g_game.player->ctrl, FOLLOW); param.view_mode = FOLLOW; } break; case SDLK_3: if (!release) { - set_view_mode (g_game.player->ctrl, BEHIND); + set_view_mode(g_game.player->ctrl, BEHIND); param.view_mode = BEHIND; } break; @@ -147,7 +147,7 @@ void CRacing::Keyb (unsigned int key, bool special, bool release, int x, int y) } } -void CRacing::Jaxis (int axis, float value) { +void CRacing::Jaxis(int axis, float value) { if (axis == 0) { // left and right stick_turn = ((value < -0.2) || (value > 0.2)); if (stick_turn) stick_turnfact = value; @@ -158,7 +158,7 @@ void CRacing::Jaxis (int axis, float value) { } } -void CRacing::Jbutt (int button, int state) { +void CRacing::Jbutt(int button, int state) { if (button == 0) { key_charging = state != 0; } else if (button == 1) { @@ -166,32 +166,32 @@ void CRacing::Jbutt (int button, int state) { } } -void CalcJumpEnergy (double time_step) { +void CalcJumpEnergy(double time_step) { CControl *ctrl = g_game.player->ctrl; if (ctrl->jump_charging) { - ctrl->jump_amt = min (MAX_JUMP_AMT, g_game.time - charge_start_time); + ctrl->jump_amt = min(MAX_JUMP_AMT, g_game.time - charge_start_time); } else if (ctrl->jumping) { - ctrl->jump_amt *= (1.0 - (g_game.time - ctrl->jump_start_time) / - JUMP_FORCE_DURATION); + ctrl->jump_amt *= (1.0 - (g_game.time - ctrl->jump_start_time) / + JUMP_FORCE_DURATION); } else { ctrl->jump_amt = 0; } } -int CalcSoundVol (float fact) { +int CalcSoundVol(float fact) { float vv = (float) param.sound_volume * fact; if (vv > 120) vv = 120; return (int) vv; } -void SetSoundVolumes () { - Sound.SetVolume ("pickup1", CalcSoundVol (1.0)); - Sound.SetVolume ("pickup2", CalcSoundVol (0.8)); - Sound.SetVolume ("pickup3", CalcSoundVol (0.8)); - Sound.SetVolume ("snow_sound", CalcSoundVol (1.5)); - Sound.SetVolume ("ice_sound", CalcSoundVol (0.6)); - Sound.SetVolume ("rock_sound", CalcSoundVol (1.1)); +void SetSoundVolumes() { + Sound.SetVolume("pickup1", CalcSoundVol(1.0)); + Sound.SetVolume("pickup2", CalcSoundVol(0.8)); + Sound.SetVolume("pickup3", CalcSoundVol(0.8)); + Sound.SetVolume("snow_sound", CalcSoundVol(1.5)); + Sound.SetVolume("ice_sound", CalcSoundVol(0.6)); + Sound.SetVolume("rock_sound", CalcSoundVol(1.1)); } // ---------------------------- init ---------------------------------- @@ -201,7 +201,7 @@ void CRacing::Enter() { if (param.view_mode < 0 || param.view_mode >= NUM_VIEW_MODES) { param.view_mode = ABOVE; } - set_view_mode (ctrl, (TViewMode)param.view_mode); + set_view_mode(ctrl, param.view_mode); left_turn = right_turn = trick_modifier = false; ctrl->turn_fact = 0.0; @@ -214,11 +214,11 @@ void CRacing::Enter() { lastsound = -1; newsound = -1; - if (State::manager.PreviousState() != &Paused) ctrl->Init (); + if (State::manager.PreviousState() != &Paused) ctrl->Init(); g_game.raceaborted = false; - SetSoundVolumes (); - Music.PlayTheme (g_game.theme_id, MUS_RACING); + SetSoundVolumes(); + Music.PlayTheme(g_game.theme_id, MUS_RACING); g_game.finish = false; } @@ -226,40 +226,40 @@ void CRacing::Enter() { // -------------------- sound ----------------------------------------- // this function is not used yet. -int SlideVolume (CControl *ctrl, double speed, int typ) { +int SlideVolume(CControl *ctrl, double speed, int typ) { if (typ == 1) { // only at paddling or braking - return (int)(min ((((pow(ctrl->turn_fact, 2) * 128)) + - (ctrl->is_braking ? 128:0) + - (ctrl->jumping ? 128:0) + 20) * (speed / 10), 128.0)); + return (int)(min((((pow(ctrl->turn_fact, 2) * 128)) + + (ctrl->is_braking ? 128:0) + + (ctrl->jumping ? 128:0) + 20) * (speed / 10), 128.0)); } else { // always return (int)(128 * pow((speed/2),2)); } } -void PlayTerrainSound (CControl *ctrl, bool airborne) { +void PlayTerrainSound(CControl *ctrl, bool airborne) { if (airborne == false) { - int terridx = Course.GetTerrainIdx (ctrl->cpos.x, ctrl->cpos.z, 0.5); + int terridx = Course.GetTerrainIdx(ctrl->cpos.x, ctrl->cpos.z, 0.5); if (terridx >= 0) { newsound = (int)Course.TerrList[terridx].sound; } else newsound = -1; } else newsound = -1; - if ((newsound != lastsound) && (lastsound >= 0)) Sound.Halt (lastsound); - if (newsound >= 0) Sound.Play (newsound, -1); + if ((newsound != lastsound) && (lastsound >= 0)) Sound.Halt(lastsound); + if (newsound >= 0) Sound.Play(newsound, -1); lastsound = newsound; } // ----------------------- controls ----------------------------------- -void CalcSteeringControls (CControl *ctrl, double time_step) { +void CalcSteeringControls(CControl *ctrl, double time_step) { if (stick_turn) { ctrl->turn_fact = stick_turnfact; ctrl->turn_animation += ctrl->turn_fact * 2 * time_step; - ctrl->turn_animation = clamp (-1.0, ctrl->turn_animation, 1.0); + ctrl->turn_animation = clamp(-1.0, ctrl->turn_animation, 1.0); } else if (left_turn ^ right_turn) { if (left_turn) ctrl->turn_fact = -1.0; else ctrl->turn_fact = 1.0; ctrl->turn_animation += ctrl->turn_fact * 2 * time_step; - ctrl->turn_animation = clamp (-1.0, ctrl->turn_animation, 1.0); + ctrl->turn_animation = clamp(-1.0, ctrl->turn_animation, 1.0); } else { ctrl->turn_fact = 0.0; if (time_step < ROLL_DECAY) { @@ -280,7 +280,7 @@ void CalcSteeringControls (CControl *ctrl, double time_step) { bool charge = key_charging || stick_charging; bool invcharge = !key_charging && !stick_charging; - CalcJumpEnergy (time_step); + CalcJumpEnergy(time_step); if ((charge) && !ctrl->jump_charging && !ctrl->jumping) { ctrl->jump_charging = true; charge_start_time = g_game.time; @@ -291,11 +291,11 @@ void CalcSteeringControls (CControl *ctrl, double time_step) { } } -void CalcFinishControls (CControl *ctrl, double timestep, bool airborne) { +void CalcFinishControls(CControl *ctrl, double timestep, bool airborne) { double speed = ctrl->cvel.Length(); double dir_angle = RADIANS_TO_ANGLES(atan(ctrl->cvel.x / ctrl->cvel.z)); - if (fabs (dir_angle) > 5 && speed > 5) { + if (fabs(dir_angle) > 5 && speed > 5) { ctrl->turn_fact = dir_angle / 20; if (ctrl->turn_fact < -1) ctrl->turn_fact = -1; if (ctrl->turn_fact > 1) ctrl->turn_fact = 1; @@ -310,7 +310,7 @@ void CalcFinishControls (CControl *ctrl, double timestep, bool airborne) { // ----------------------- trick -------------------------------------- -void CalcTrickControls (CControl *ctrl, double time_step, bool airborne) { +void CalcTrickControls(CControl *ctrl, double time_step, bool airborne) { if (airborne && trick_modifier) { if (left_turn) ctrl->roll_left = true; if (right_turn) ctrl->roll_right = true; @@ -338,52 +338,51 @@ void CalcTrickControls (CControl *ctrl, double time_step, bool airborne) { // loop // ==================================================================== -void CRacing::Loop (double time_step) { +void CRacing::Loop(double time_step) { CControl *ctrl = g_game.player->ctrl; - double ycoord = Course.FindYCoord (ctrl->cpos.x, ctrl->cpos.z); - bool airborne = (bool) (ctrl->cpos.y > (ycoord + JUMP_MAX_START_HEIGHT)); + double ycoord = Course.FindYCoord(ctrl->cpos.x, ctrl->cpos.z); + bool airborne = (bool)(ctrl->cpos.y > (ycoord + JUMP_MAX_START_HEIGHT)); - check_gl_error(); - ClearRenderContext (); - Env.SetupFog (); - Music.Update (); - CalcTrickControls (ctrl, time_step, airborne); + ClearRenderContext(); + Env.SetupFog(); + Music.Update(); + CalcTrickControls(ctrl, time_step, airborne); - if (!g_game.finish) CalcSteeringControls (ctrl, time_step); - else CalcFinishControls (ctrl, time_step, airborne); - PlayTerrainSound (ctrl, airborne); + if (!g_game.finish) CalcSteeringControls(ctrl, time_step); + else CalcFinishControls(ctrl, time_step, airborne); + PlayTerrainSound(ctrl, airborne); // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - ctrl->UpdatePlayerPos (time_step); + ctrl->UpdatePlayerPos(time_step); // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - if (g_game.finish) IncCameraDistance (time_step); - update_view (ctrl, time_step); - UpdateTrackmarks (ctrl); + if (g_game.finish) IncCameraDistance(time_step); + update_view(ctrl, time_step); + UpdateTrackmarks(ctrl); - SetupViewFrustum (ctrl); - if (sky) Env.DrawSkybox (ctrl->viewpos); - if (fog) Env.DrawFog (); - void SetupLight (); - if (terr) RenderCourse (); - DrawTrackmarks (); - if (trees) DrawTrees (); + SetupViewFrustum(ctrl); + if (sky) Env.DrawSkybox(ctrl->viewpos); + if (fog) Env.DrawFog(); + void SetupLight(); + if (terr) RenderCourse(); + DrawTrackmarks(); + if (trees) DrawTrees(); if (param.perf_level > 2) { - update_particles (time_step); - draw_particles (ctrl); + update_particles(time_step); + draw_particles(ctrl); } g_game.character->shape->Draw(); - UpdateWind (time_step); - UpdateSnow (time_step, ctrl); - DrawSnow (ctrl); - DrawHud (ctrl); + UpdateWind(time_step); + UpdateSnow(time_step, ctrl); + DrawSnow(ctrl); + DrawHud(ctrl); - Reshape (Winsys.resolution.width, Winsys.resolution.height); - Winsys.SwapBuffers (); + Reshape(Winsys.resolution.width, Winsys.resolution.height); + Winsys.SwapBuffers(); if (g_game.finish == false) g_game.time += time_step; } // ---------------------------------- term ------------------ void CRacing::Exit() { - Sound.HaltAll (); - break_track_marks (); + Sound.HaltAll(); + break_track_marks(); } diff --git a/src/regist.cpp b/src/regist.cpp index e6052d5..e4f377c 100644 --- a/src/regist.cpp +++ b/src/regist.cpp @@ -38,17 +38,17 @@ static TWidget* textbuttons[2]; static TUpDown* player; static TUpDown* character; -void QuitRegistration () { - Players.ResetControls (); - Players.AllocControl (player->GetValue()); +void QuitRegistration() { + Players.ResetControls(); + Players.AllocControl(player->GetValue()); g_game.player = Players.GetPlayer(player->GetValue()); g_game.character = &Char.CharList[character->GetValue()]; Char.FreeCharacterPreviews(); // From here on, character previews are no longer required - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); } -void CRegist::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CRegist::Keyb(unsigned int key, bool special, bool release, int x, int y) { TWidget* focussed = KeyGUI(key, 0, release); if (release) return; switch (key) { @@ -58,28 +58,28 @@ void CRegist::Keyb (unsigned int key, bool special, bool release, int x, int y) case SDLK_RETURN: if (focussed == textbuttons[1]) { g_game.player = Players.GetPlayer(player->GetValue()); - State::manager.RequestEnterState (NewPlayer); - } else QuitRegistration (); + State::manager.RequestEnterState(NewPlayer); + } else QuitRegistration(); break; } } -void CRegist::Mouse (int button, int state, int x, int y) { +void CRegist::Mouse(int button, int state, int x, int y) { if (state == 1) { TWidget* focussed = ClickGUI(x, y); if (focussed == textbuttons[0]) - QuitRegistration (); + QuitRegistration(); else if (focussed == textbuttons[1]) { g_game.player = Players.GetPlayer(player->GetValue()); - State::manager.RequestEnterState (NewPlayer); + State::manager.RequestEnterState(NewPlayer); } } } -void CRegist::Motion (int x, int y) { +void CRegist::Motion(int x, int y) { MouseMoveGUI(x, y); - if (param.ui_snow) push_ui_snow (cursor_pos); + if (param.ui_snow) push_ui_snow(cursor_pos); } static int framewidth, frameheight, arrowwidth; @@ -87,78 +87,77 @@ static TArea area; static double texsize; void CRegist::Enter() { - Winsys.ShowCursor (!param.ice_cursor); - Music.Play (param.menu_music, -1); + Winsys.ShowCursor(!param.ice_cursor); + Music.Play(param.menu_music, -1); - framewidth = (int) (Winsys.scale * 280); - frameheight = (int) (Winsys.scale * 50); + framewidth = (int)(Winsys.scale * 280); + frameheight = (int)(Winsys.scale * 50); arrowwidth = 50; int sumwidth = framewidth * 2 + arrowwidth * 2; - area = AutoAreaN (30, 80, sumwidth); + area = AutoAreaN(30, 80, sumwidth); texsize = 128 * Winsys.scale; - ResetGUI (); + ResetGUI(); player = AddUpDown(area.left + framewidth + 8, area.top, 0, (int)Players.numPlayers() - 1, (int)g_game.start_player); character = AddUpDown(area.left + framewidth * 2 + arrowwidth + 8, area.top, 0, (int)Char.CharList.size() - 1, 0); - int siz = FT.AutoSizeN (5); - textbuttons[0] = AddTextButton (Trans.Text(60), CENTER, AutoYPosN (62), siz); - textbuttons[1] = AddTextButton (Trans.Text(61), CENTER, AutoYPosN (70), siz); + int siz = FT.AutoSizeN(5); + textbuttons[0] = AddTextButton(Trans.Text(60), CENTER, AutoYPosN(62), siz); + textbuttons[1] = AddTextButton(Trans.Text(61), CENTER, AutoYPosN(70), siz); if (Char.CharList.empty()) Winsys.Terminate(); // Characters are necessary - ETR is unusable otherwise } -void CRegist::Loop (double timestep) { +void CRegist::Loop(double timestep) { int ww = Winsys.resolution.width; int hh = Winsys.resolution.height; - Music.Update (); - check_gl_error(); - ClearRenderContext (); + Music.Update(); + ClearRenderContext(); ScopedRenderMode rm(GUI); - SetupGuiDisplay (); + SetupGuiDisplay(); TColor col; if (param.ui_snow) { - update_ui_snow (timestep); + update_ui_snow(timestep); draw_ui_snow(); } - Tex.Draw (BOTTOM_LEFT, 0, hh - 256, 1); - Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); - Tex.Draw (TOP_LEFT, 0, 0, 1); - Tex.Draw (TOP_RIGHT, ww-256, 0, 1); + Tex.Draw(BOTTOM_LEFT, 0, hh - 256, 1); + Tex.Draw(BOTTOM_RIGHT, ww-256, hh-256, 1); + Tex.Draw(TOP_LEFT, 0, 0, 1); + Tex.Draw(TOP_RIGHT, ww-256, 0, 1); Tex.Draw(T_TITLE_SMALL, CENTER, AutoYPosN(5), Winsys.scale); - FT.AutoSizeN (3); - FT.SetColor (colWhite); - int top = AutoYPosN (24); - FT.DrawString (area.left, top, Trans.Text(58)); - FT.DrawString (area.left + framewidth + arrowwidth, top, Trans.Text(59)); + FT.AutoSizeN(3); + FT.SetColor(colWhite); + int top = AutoYPosN(24); + FT.DrawString(area.left, top, Trans.Text(58)); + FT.DrawString(area.left + framewidth + arrowwidth, top, Trans.Text(59)); - FT.AutoSizeN (4); + FT.AutoSizeN(4); if (player->focussed()) col = colDYell; else col = colWhite; - DrawFrameX (area.left, area.top, framewidth, frameheight, 3, colMBackgr, col, 1.0); - FT.SetColor (col); + DrawFrameX(area.left, area.top, framewidth, frameheight, 3, colMBackgr, col, 1.0); + FT.SetColor(col); FT.DrawString(area.left + 20, area.top, Players.GetPlayer(player->GetValue())->name); Players.GetAvatarTexture(player->GetValue())->DrawFrame( - area.left + 60, AutoYPosN (40), texsize, texsize, 3, colWhite); + area.left + 60, AutoYPosN(40), texsize, texsize, 3, colWhite); if (character->focussed()) col = colDYell; else col = colWhite; - DrawFrameX (area.left + framewidth + arrowwidth, area.top, - framewidth, frameheight, 3, colMBackgr, col, 1.0); - FT.SetColor (col); - FT.DrawString (area.left + framewidth + arrowwidth + 20, - area.top, Char.CharList[character->GetValue()].name); + DrawFrameX(area.left + framewidth + arrowwidth, area.top, + framewidth, frameheight, 3, colMBackgr, col, 1.0); + FT.SetColor(col); + FT.DrawString(area.left + framewidth + arrowwidth + 20, + area.top, Char.CharList[character->GetValue()].name); if (Char.CharList[character->GetValue()].preview != NULL) Char.CharList[character->GetValue()].preview->DrawFrame( area.right - texsize - 60 - arrowwidth, - AutoYPosN (40), texsize, texsize, 3, colWhite); + AutoYPosN(40), texsize, texsize, 3, colWhite); - FT.SetColor (colWhite); + FT.SetColor(colWhite); DrawGUI(); Winsys.SwapBuffers(); diff --git a/src/reset.cpp b/src/reset.cpp index 0a793f9..51ffc55 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -45,28 +45,27 @@ static bool position_reset; //===================================================================== void CReset::Enter() { - reset_start_time = Winsys.ClockTime (); + reset_start_time = Winsys.ClockTime(); position_reset = false; } void CReset::Loop(double time_step) { CControl *ctrl = g_game.player->ctrl; - double elapsed_time = Winsys.ClockTime () - reset_start_time; + double elapsed_time = Winsys.ClockTime() - reset_start_time; static bool tux_visible = true; static int tux_visible_count = 0; - check_gl_error(); - ClearRenderContext (); - Env.SetupFog (); - ctrl->UpdatePlayerPos (EPS); - update_view (ctrl, EPS); - SetupViewFrustum (ctrl); - Env.DrawSkybox (ctrl->viewpos); - Env.DrawFog (); - Env.SetupLight (); // and fog + ClearRenderContext(); + Env.SetupFog(); + ctrl->UpdatePlayerPos(EPS); + update_view(ctrl, EPS); + SetupViewFrustum(ctrl); + Env.DrawSkybox(ctrl->viewpos); + Env.DrawFog(); + Env.SetupLight(); // and fog RenderCourse(); - DrawTrackmarks (); - DrawTrees (); + DrawTrackmarks(); + DrawTrees(); if ((elapsed_time > BLINK_IN_PLACE_TIME) && (!position_reset)) { TObjectType* object_types = &Course.ObjTypes[0]; @@ -98,10 +97,10 @@ void CReset::Loop(double time_step) { if (best_loc == -1) { ctrl->cpos.x = Course.GetDimensions().x/2.0; - ctrl->cpos.z = min (ctrl->cpos.z + 10, -1.0); + ctrl->cpos.z = min(ctrl->cpos.z + 10, -1.0); } else if (item_locs[best_loc].pt.z <= ctrl->cpos.z) { ctrl->cpos.x = Course.GetDimensions().x/2.0; - ctrl->cpos.z = min (ctrl->cpos.z + 10, -1.0); + ctrl->cpos.z = min(ctrl->cpos.z + 10, -1.0); } else { ctrl->cpos.x = item_locs[best_loc].pt.x; ctrl->cpos.z = item_locs[best_loc].pt.z; @@ -109,7 +108,7 @@ void CReset::Loop(double time_step) { } ctrl->view_init = false; - ctrl->Init (); + ctrl->Init(); position_reset = true; } // if elapsed time @@ -120,12 +119,12 @@ void CReset::Loop(double time_step) { tux_visible_count = 0; } - DrawHud (ctrl); - Reshape (Winsys.resolution.width, Winsys.resolution.height); - Winsys.SwapBuffers (); + DrawHud(ctrl); + Reshape(Winsys.resolution.width, Winsys.resolution.height); + Winsys.SwapBuffers(); g_game.time += time_step; if (elapsed_time > TOTAL_RESET_TIME) { - State::manager.RequestEnterState (Racing); + State::manager.RequestEnterState(Racing); } } diff --git a/src/score.cpp b/src/score.cpp index 2f0ba42..65e566c 100644 --- a/src/score.cpp +++ b/src/score.cpp @@ -66,30 +66,30 @@ int CScore::AddScore(const TCourse* course, const TScore& score) { } // for testing: -void CScore::PrintScorelist (size_t list_idx) const { +void CScore::PrintScorelist(size_t list_idx) const { if (list_idx >= Scorelist.size()) return; const TScoreList *list = &Scorelist[list_idx]; if (list->numScores < 1) { - PrintStr ("no entries in this score list"); + PrintStr("no entries in this score list"); } else { for (int i=0; inumScores; i++) { string line = "player: " + list->scores[i].player; - line += " points: " + Int_StrN (list->scores[i].points); - line += " herrings: " + Int_StrN (list->scores[i].herrings); - line += " time: " + Float_StrN (list->scores[i].time, 2); - PrintString (line); + line += " points: " + Int_StrN(list->scores[i].points); + line += " herrings: " + Int_StrN(list->scores[i].herrings); + line += " time: " + Float_StrN(list->scores[i].time, 2); + PrintString(line); } } } -const TScoreList *CScore::GetScorelist (size_t list_idx) const { +const TScoreList *CScore::GetScorelist(size_t list_idx) const { if (list_idx >= Scorelist.size()) return NULL; return &Scorelist[list_idx]; } -bool CScore::SaveHighScore () const { - CSPList splist ((int)Scorelist.size()*MAX_SCORES); +bool CScore::SaveHighScore() const { + CSPList splist((int)Scorelist.size()*MAX_SCORES); for (size_t li=0; liscores[sc]; string line = "*[course] " + Course.CourseList[li].dir; line += " [plyr] " + score.player; - line += " [pts] " + Int_StrN (score.points); - line += " [herr] " + Int_StrN (score.herrings); - line += " [time] " + Float_StrN (score.time, 1); - splist.Add (line); + line += " [pts] " + Int_StrN(score.points); + line += " [herr] " + Int_StrN(score.herrings); + line += " [time] " + Float_StrN(score.time, 1); + splist.Add(line); } } } } - if (!splist.Save (param.config_dir, "highscore")) { - Message ("could not save highscore list"); + if (!splist.Save(param.config_dir, "highscore")) { + Message("could not save highscore list"); return false; } return true; } -bool CScore::LoadHighScore () { - CSPList list (520); +bool CScore::LoadHighScore() { + CSPList list(520); Scorelist.resize(Course.CourseList.size()); - if (!list.Load (param.config_dir, "highscore")) { - Message ("could not load highscore list"); + if (!list.Load(param.config_dir, "highscore")) { + Message("could not load highscore list"); return false; } for (size_t i=0; iname; - return AddScore (g_game.course, TempScore); + return AddScore(g_game.course, TempScore); } // -------------------------------------------------------------------- @@ -174,40 +174,40 @@ static TCourse *CourseList; static TUpDown* course; static TWidget* textbutton; -void CScore::Keyb (unsigned int key, bool special, bool release, int x, int y) { +void CScore::Keyb(unsigned int key, bool special, bool release, int x, int y) { KeyGUI(key, 0, release); if (release) return; switch (key) { case SDLK_ESCAPE: - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); break; case SDLK_q: State::manager.RequestQuit(); break; case SDLK_s: - Score.SaveHighScore (); + Score.SaveHighScore(); break; case SDLK_l: - Score.LoadHighScore (); + Score.LoadHighScore(); break; case SDLK_RETURN: - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); break; } } -void CScore::Mouse (int button, int state, int x, int y) { +void CScore::Mouse(int button, int state, int x, int y) { if (state == 1) { TWidget* clicked = ClickGUI(x, y); if (clicked == textbutton) - State::manager.RequestEnterState (GameTypeSelect); + State::manager.RequestEnterState(GameTypeSelect); } } -void CScore::Motion (int x, int y) { +void CScore::Motion(int x, int y) { MouseMoveGUI(x, y); - if (param.ui_snow) push_ui_snow (cursor_pos); + if (param.ui_snow) push_ui_snow(cursor_pos); } static TArea area; @@ -216,17 +216,17 @@ static int linedist, listtop; static int dd1, dd2, dd3, dd4; void CScore::Enter() { - Winsys.ShowCursor (!param.ice_cursor); - Winsys.KeyRepeat (true); - Music.Play (param.menu_music, -1); + Winsys.ShowCursor(!param.ice_cursor); + Winsys.KeyRepeat(true); + Music.Play(param.menu_music, -1); framewidth = 550 * Winsys.scale; frameheight = 50 * Winsys.scale; - frametop = AutoYPosN (32); - area = AutoAreaN (30, 80, framewidth); - FT.AutoSizeN (3); - linedist = FT.AutoDistanceN (1); - listtop = AutoYPosN (44); + frametop = AutoYPosN(32); + area = AutoAreaN(30, 80, framewidth); + FT.AutoSizeN(3); + linedist = FT.AutoDistanceN(1); + listtop = AutoYPosN(44); dd1 = 50 * Winsys.scale; dd2 = 115 * Winsys.scale; dd3 = 250 * Winsys.scale; @@ -234,68 +234,67 @@ void CScore::Enter() { CourseList = &Course.CourseList[0]; - ResetGUI (); + ResetGUI(); course = AddUpDown(area.right + 8, frametop, 0, (int)Course.CourseList.size()-1, 0); - int siz = FT.AutoSizeN (5); - textbutton = AddTextButton (Trans.Text(64), CENTER, AutoYPosN (80), siz); + int siz = FT.AutoSizeN(5); + textbutton = AddTextButton(Trans.Text(64), CENTER, AutoYPosN(80), siz); } const string ordinals[10] = {"1:st", "2:nd", "3:rd", "4:th", "5:th", "6:th", "7:th", "8:th", "9:th", "10:th"}; -void CScore::Loop (double timestep) { +void CScore::Loop(double timestep) { int ww = Winsys.resolution.width; int hh = Winsys.resolution.height; - Music.Update (); - check_gl_error(); - ClearRenderContext (); + Music.Update(); + ClearRenderContext(); ScopedRenderMode rm(GUI); - SetupGuiDisplay (); + SetupGuiDisplay(); if (param.ui_snow) { - update_ui_snow (timestep); + update_ui_snow(timestep); draw_ui_snow(); } - Tex.Draw (BOTTOM_LEFT, 0, hh - 256, 1); - Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1); - Tex.Draw (TOP_LEFT, 0, 0, 1); - Tex.Draw (TOP_RIGHT, ww-256, 0, 1); - Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), Winsys.scale); + Tex.Draw(BOTTOM_LEFT, 0, hh - 256, 1); + Tex.Draw(BOTTOM_RIGHT, ww-256, hh-256, 1); + Tex.Draw(TOP_LEFT, 0, 0, 1); + Tex.Draw(TOP_RIGHT, ww-256, 0, 1); + Tex.Draw(T_TITLE_SMALL, CENTER, AutoYPosN(5), Winsys.scale); // DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top, // 0, colMBackgr, colBlack, 0.2); - FT.AutoSizeN (7); - FT.SetColor (colWhite); - FT.DrawString (CENTER, AutoYPosN (22), Trans.Text(62)); + FT.AutoSizeN(7); + FT.SetColor(colWhite); + FT.DrawString(CENTER, AutoYPosN(22), Trans.Text(62)); - DrawFrameX (area.left, frametop, framewidth, frameheight, 3, colMBackgr, colDYell, 1.0); - FT.AutoSizeN (5); - FT.SetColor (colWhite); - FT.DrawString (area.left+20, frametop, CourseList[course->GetValue()].name); + DrawFrameX(area.left, frametop, framewidth, frameheight, 3, colMBackgr, colDYell, 1.0); + FT.AutoSizeN(5); + FT.SetColor(colWhite); + FT.DrawString(area.left+20, frametop, CourseList[course->GetValue()].name); - const TScoreList *list = Score.GetScorelist (course->GetValue()); + const TScoreList *list = Score.GetScorelist(course->GetValue()); - FT.SetColor (colWhite); + FT.SetColor(colWhite); if (list != NULL) { - FT.AutoSizeN (3); + FT.AutoSizeN(3); if (list->numScores < 1) { - FT.DrawString (CENTER, area.top + 140, Trans.Text(63)); + FT.DrawString(CENTER, area.top + 140, Trans.Text(63)); } else { for (int i=0; inumScores); i++) { int y = listtop + i*linedist; - FT.DrawString (area.left, y, ordinals[i]); - FT.DrawString (area.left + dd1, y, Int_StrN (list->scores[i].points)); - FT.DrawString (area.left + dd2, y, list->scores[i].player); - FT.DrawString (area.left + dd3, y, - Int_StrN (list->scores[i].herrings) + " herrings"); - FT.DrawString (area.left + dd4, y, - Float_StrN (list->scores[i].time, 1) + " sec"); + FT.DrawString(area.left, y, ordinals[i]); + FT.DrawString(area.left + dd1, y, Int_StrN(list->scores[i].points)); + FT.DrawString(area.left + dd2, y, list->scores[i].player); + FT.DrawString(area.left + dd3, y, + Int_StrN(list->scores[i].herrings) + " herrings"); + FT.DrawString(area.left + dd4, y, + Float_StrN(list->scores[i].time, 1) + " sec"); } } - } else Message ("score list out of range"); + } else Message("score list out of range"); DrawGUI(); diff --git a/src/score.h b/src/score.h index 8b3d82d..5c5504d 100644 --- a/src/score.h +++ b/src/score.h @@ -47,11 +47,11 @@ private: void Motion(int x, int y); public: int AddScore(const TCourse* course, const TScore& score); - const TScoreList *GetScorelist (size_t list_idx) const; - void PrintScorelist (size_t list_idx) const; - bool SaveHighScore () const; - bool LoadHighScore (); - int CalcRaceResult (); + const TScoreList *GetScorelist(size_t list_idx) const; + void PrintScorelist(size_t list_idx) const; + bool SaveHighScore() const; + bool LoadHighScore(); + int CalcRaceResult(); }; extern CScore Score; diff --git a/src/splash_screen.cpp b/src/splash_screen.cpp index 8689957..da23ef4 100644 --- a/src/splash_screen.cpp +++ b/src/splash_screen.cpp @@ -25,10 +25,8 @@ GNU General Public License for more details. #include "audio.h" #include "gui.h" #include "course.h" -#include "tux.h" #include "env.h" #include "particles.h" -#include "credits.h" #include "font.h" #include "game_ctrl.h" #include "translation.h" @@ -45,48 +43,47 @@ void CSplashScreen::Keyb(unsigned int key, bool special, bool release, int x, in State::manager.RequestQuit(); break; case SDLK_RETURN: - State::manager.RequestEnterState (Regist); + State::manager.RequestEnterState(Regist); break; } } void CSplashScreen::Enter() { - Winsys.ShowCursor (!param.ice_cursor); - init_ui_snow (); - Music.Play (param.menu_music, -1); + Winsys.ShowCursor(!param.ice_cursor); + Music.Play(param.menu_music, -1); } void CSplashScreen::Loop(double timestep) { - Music.Update (); - check_gl_error(); - ClearRenderContext (); + Music.Update(); + ClearRenderContext(); ScopedRenderMode rm(GUI); - SetupGuiDisplay (); - Trans.LoadLanguages (); - Trans.LoadTranslations (param.language); // Before first texts are being displayed + SetupGuiDisplay(); + Trans.LoadTranslations(param.language); // Before first texts are being displayed - Tex.Draw (TEXLOGO, CENTER, 60, Winsys.scale); - FT.SetColor (colDYell); - FT.AutoSizeN (6); - int top = AutoYPosN (60); int dist = FT.AutoDistanceN (3); - FT.DrawString (CENTER, top, Trans.Text(67)); - FT.DrawString (CENTER, top+dist, Trans.Text(68)); + Tex.Draw(TEXLOGO, CENTER, 60, Winsys.scale/2.0); + FT.SetColor(colDYell); + FT.AutoSizeN(6); + int top = AutoYPosN(60); + int dist = FT.AutoDistanceN(3); + FT.DrawString(CENTER, top, Trans.Text(67)); + FT.DrawString(CENTER, top+dist, Trans.Text(68)); Winsys.SwapBuffers(); - Course.MakeStandardPolyhedrons (); - Sound.LoadSoundList (); - Credits.LoadCreditList (); - Char.LoadCharacterList (); - Course.LoadObjectTypes (); - Course.LoadTerrainTypes (); - Env.LoadEnvironmentList (); - Course.LoadCourseList (); - Score.LoadHighScore (); // after LoadCourseList !!! - Events.LoadEventList (); - Players.LoadAvatars (); // before LoadPlayers !!! - Players.LoadPlayers (); + init_ui_snow(); - State::manager.RequestEnterState (Regist); + Course.MakeStandardPolyhedrons(); + Sound.LoadSoundList(); + Char.LoadCharacterList(); + Course.LoadObjectTypes(); + Course.LoadTerrainTypes(); + Env.LoadEnvironmentList(); + Course.LoadCourseList(); + Score.LoadHighScore(); // after LoadCourseList !!! + Events.LoadEventList(); + Players.LoadAvatars(); // before LoadPlayers !!! + Players.LoadPlayers(); + + State::manager.RequestEnterState(Regist); } diff --git a/src/spx.cpp b/src/spx.cpp index 9d827cf..cd4f6e8 100644 --- a/src/spx.cpp +++ b/src/spx.cpp @@ -32,70 +32,70 @@ const string errorString = "error"; // elementary string functions // -------------------------------------------------------------------- -string MakePathStr (const string& src, const string& add) { +string MakePathStr(const string& src, const string& add) { string res = src; res += SEP; res += add; return res; } -void SInsertN (string &s, size_t pos, const string& ins) { +void SInsertN(string &s, size_t pos, const string& ins) { if (pos > s.size()) pos = s.size(); - s.insert (pos, ins); + s.insert(pos, ins); } -void SDeleteN (string &s, size_t pos, size_t count) { +void SDeleteN(string &s, size_t pos, size_t count) { if (pos > s.size()) pos = s.size(); - s.erase (pos, count); + s.erase(pos, count); } -size_t SPosN (const string &s, const string& find) { - return s.find (find); +size_t SPosN(const string &s, const string& find) { + return s.find(find); } -void STrimLeftN (string &s) { +void STrimLeftN(string &s) { size_t i = s.find_first_not_of(" \t"); if (i > 0) - SDeleteN (s, 0, i); + SDeleteN(s, 0, i); } -void STrimRightN (string &s) { +void STrimRightN(string &s) { size_t i = s.find_last_not_of(" \t"); if (i != s.size()-1) - s.erase (i+1); + s.erase(i+1); } -void STrimN (string &s) { - STrimLeftN (s); - STrimRightN (s); +void STrimN(string &s) { + STrimLeftN(s); + STrimRightN(s); } // -------------------------------------------------------------------- // conversion functions // -------------------------------------------------------------------- -string Int_StrN (const int val) { +string Int_StrN(const int val) { ostringstream os; os << val; return os.str(); } -string Int_StrN (const int val, const streamsize count) { +string Int_StrN(const int val, const streamsize count) { ostringstream os; os << setw(count) << setfill('0') << val; return os.str(); } -string Float_StrN (const float val, const streamsize count) { +string Float_StrN(const float val, const streamsize count) { ostringstream os; os << setprecision(count) << fixed << val; return os.str(); } -string Vector_StrN (const TVector3d& v, const streamsize count) { - string res = Float_StrN (v.x, count); - res += ' ' + Float_StrN (v.y, count); - res += ' ' + Float_StrN (v.z, count); +string Vector_StrN(const TVector3d& v, const streamsize count) { + string res = Float_StrN(v.x, count); + res += ' ' + Float_StrN(v.y, count); + res += ' ' + Float_StrN(v.z, count); return res; } @@ -104,7 +104,7 @@ string Bool_StrN(const bool val) { else return "false"; } -int Str_IntN (const string &s, const int def) { +int Str_IntN(const string &s, const int def) { int val; istringstream is(s); is >> val; @@ -112,7 +112,7 @@ int Str_IntN (const string &s, const int def) { else return val; } -bool Str_BoolN (const string &s, const bool def) { +bool Str_BoolN(const string &s, const bool def) { if (s == "0" || s == "false") return false; if (s == "1" || s == "true") @@ -120,7 +120,7 @@ bool Str_BoolN (const string &s, const bool def) { return Str_IntN(s, (int)def) != 0; // Try to parse as int } -float Str_FloatN (const string &s, const float def) { +float Str_FloatN(const string &s, const float def) { float val; istringstream is(s); is >> val; @@ -162,7 +162,7 @@ template TVector4 Str_Vector4(const string &s, const TVector4 &d template TVector4 Str_Vector4(const string &s, const TVector4 &def); -TColor Str_ColorN (const string &s, const TColor &def) { +TColor Str_ColorN(const string &s, const TColor &def) { float r, g, b, a; istringstream is(s); is >> r >> g >> b >> a; @@ -170,7 +170,7 @@ TColor Str_ColorN (const string &s, const TColor &def) { else return TColor(r, g, b, a); } -TColor3 Str_Color3N (const string &s, const TColor3 &def) { +TColor3 Str_Color3N(const string &s, const TColor3 &def) { float r, g, b; istringstream is(s); is >> r >> g >> b; @@ -178,7 +178,7 @@ TColor3 Str_Color3N (const string &s, const TColor3 &def) { else return TColor3(r, g, b); } -void Str_ArrN (const string &s, float *arr, size_t count, float def) { +void Str_ArrN(const string &s, float *arr, size_t count, float def) { istringstream is(s); for (size_t i = 0; i < count; i++) is >> arr[i]; @@ -190,11 +190,11 @@ void Str_ArrN (const string &s, float *arr, size_t count, float def) { // SP functions for parsing lines // -------------------------------------------------------------------- -string SPItemN (const string &s, const string &tag) { +string SPItemN(const string &s, const string &tag) { if (s.empty() || tag.empty()) return ""; string tg = '[' + tag + ']'; - size_t i = SPosN (s, tg); + size_t i = SPosN(s, tg); if (i == string::npos) return ""; size_t ii = i + tg.size(); string item; @@ -205,30 +205,30 @@ string SPItemN (const string &s, const string &tag) { return item; } -string SPStrN (const string &s, const string &tag, const string& def) { - string item = SPItemN (s, tag); +string SPStrN(const string &s, const string &tag, const string& def) { + string item = SPItemN(s, tag); if (item.empty()) return def; - STrimN (item); + STrimN(item); return item; } -int SPIntN (const string &s, const string &tag, const int def) { - return (Str_IntN (SPItemN (s, tag), def)); +int SPIntN(const string &s, const string &tag, const int def) { + return (Str_IntN(SPItemN(s, tag), def)); } -bool SPBoolN (const string &s, const string &tag, const bool def) { - string item = SPItemN (s, tag); - STrimN (item); - return Str_BoolN (item, def); +bool SPBoolN(const string &s, const string &tag, const bool def) { + string item = SPItemN(s, tag); + STrimN(item); + return Str_BoolN(item, def); } -float SPFloatN (const string &s, const string &tag, const float def) { - return (Str_FloatN (SPItemN (s, tag), def)); +float SPFloatN(const string &s, const string &tag, const float def) { + return (Str_FloatN(SPItemN(s, tag), def)); } template -TVector2 SPVector2 (const string &s, const string &tag, const TVector2& def) { - return (Str_Vector2(SPItemN (s, tag), def)); +TVector2 SPVector2(const string &s, const string &tag, const TVector2& def) { + return (Str_Vector2(SPItemN(s, tag), def)); } template TVector2 SPVector2(const string &s, const string &tag, const TVector2& def); template TVector2 SPVector2(const string &s, const string &tag, const TVector2& def); @@ -247,69 +247,69 @@ TVector4 SPVector4(const string &s, const string &tag, const TVector4& def template TVector4 SPVector4(const string &s, const string &tag, const TVector4& def); template TVector4 SPVector4(const string &s, const string &tag, const TVector4& def); -TColor SPColorN (const string &s, const string &tag, const TColor& def) { - return (Str_ColorN (SPItemN (s, tag), def)); +TColor SPColorN(const string &s, const string &tag, const TColor& def) { + return (Str_ColorN(SPItemN(s, tag), def)); } -TColor3 SPColor3N (const string &s, const string &tag, const TColor3& def) { - return (Str_Color3N (SPItemN (s, tag), def)); +TColor3 SPColor3N(const string &s, const string &tag, const TColor3& def) { + return (Str_Color3N(SPItemN(s, tag), def)); } -void SPArrN (const string &s, const string &tag, float *arr, size_t count, float def) { - Str_ArrN (SPItemN (s, tag), arr, count, def); +void SPArrN(const string &s, const string &tag, float *arr, size_t count, float def) { + Str_ArrN(SPItemN(s, tag), arr, count, def); } -size_t SPPosN (const string &s, const string &tag) { +size_t SPPosN(const string &s, const string &tag) { string tg = '[' + tag + ']'; - return SPosN (s, tg); + return SPosN(s, tg); } // ------------------ add --------------------------------------------- -void SPAddIntN (string &s, const string &tag, const int val) { +void SPAddIntN(string &s, const string &tag, const int val) { s += '['; s += tag; s += ']'; - s += Int_StrN (val); + s += Int_StrN(val); } -void SPAddFloatN (string &s, const string &tag, const float val, size_t count) { +void SPAddFloatN(string &s, const string &tag, const float val, size_t count) { s += '['; s += tag; s += ']'; - s += Float_StrN (val, count); + s += Float_StrN(val, count); } -void SPAddStrN (string &s, const string &tag, const string &val) { +void SPAddStrN(string &s, const string &tag, const string &val) { s += '['; s += tag; s += ']'; s += val; } -void SPAddVec2N (string &s, const string &tag, const TVector2d &val, size_t count) { +void SPAddVec2N(string &s, const string &tag, const TVector2d &val, size_t count) { s += '['; s += tag; s += ']'; s += ' '; - s += Float_StrN (val.x, count); + s += Float_StrN(val.x, count); s += ' '; - s += Float_StrN (val.y, count); + s += Float_StrN(val.y, count); } -void SPAddVec3N (string &s, const string &tag, const TVector3d &val, size_t count) { +void SPAddVec3N(string &s, const string &tag, const TVector3d &val, size_t count) { s += '['; s += tag; s += ']'; s += ' '; - s += Float_StrN (val.x, count); + s += Float_StrN(val.x, count); s += ' '; - s += Float_StrN (val.y, count); + s += Float_StrN(val.y, count); s += ' '; - s += Float_StrN (val.z, count); + s += Float_StrN(val.z, count); } -void SPAddBoolN (string &s, const string &tag, const bool val) { +void SPAddBoolN(string &s, const string &tag, const bool val) { s += '['; s += tag; s += ']'; @@ -319,34 +319,34 @@ void SPAddBoolN (string &s, const string &tag, const bool val) { // -------------------------------------------------------------------- -void SPSetIntN (string &s, const string &tag, const int val) { - size_t pos = SPPosN (s, tag); +void SPSetIntN(string &s, const string &tag, const int val) { + size_t pos = SPPosN(s, tag); if (pos != string::npos) { size_t ipos = pos + tag.size() + 2; - string item = SPItemN (s, tag); - if (item.size() != string::npos) SDeleteN (s, ipos, item.size()); - SInsertN (s, ipos, Int_StrN (val)); - } else SPAddIntN (s, tag, val); + string item = SPItemN(s, tag); + if (item.size() != string::npos) SDeleteN(s, ipos, item.size()); + SInsertN(s, ipos, Int_StrN(val)); + } else SPAddIntN(s, tag, val); } -void SPSetFloatN (string &s, const string &tag, const float val, size_t count) { - size_t pos = SPPosN (s, tag); +void SPSetFloatN(string &s, const string &tag, const float val, size_t count) { + size_t pos = SPPosN(s, tag); if (pos != string::npos) { size_t ipos = pos + tag.size() + 2; - string item = SPItemN (s, tag); - if (item.size() != string::npos) SDeleteN (s, ipos, item.size()); - SInsertN (s, ipos, Float_StrN (val, count)); - } else SPAddFloatN (s, tag, val, count); + string item = SPItemN(s, tag); + if (item.size() != string::npos) SDeleteN(s, ipos, item.size()); + SInsertN(s, ipos, Float_StrN(val, count)); + } else SPAddFloatN(s, tag, val, count); } -void SPSetStrN (string &s, const string &tag, const string &val) { - size_t pos = SPPosN (s, tag); +void SPSetStrN(string &s, const string &tag, const string &val) { + size_t pos = SPPosN(s, tag); if (pos != string::npos) { size_t ipos = pos + tag.size() + 2; - string item = SPItemN (s, tag); - if (item.size() != string::npos) SDeleteN (s, ipos, item.size()); - SInsertN (s, ipos, val); - } else SPAddStrN (s, tag, val); + string item = SPItemN(s, tag); + if (item.size() != string::npos) SDeleteN(s, ipos, item.size()); + SInsertN(s, ipos, val); + } else SPAddStrN(s, tag, val); } // -------------------------------------------------------------------- @@ -354,52 +354,52 @@ void SPSetStrN (string &s, const string &tag, const string &val) { // -------------------------------------------------------------------- -CSPList::CSPList (size_t maxlines, bool newlineflag) { +CSPList::CSPList(size_t maxlines, bool newlineflag) { fmax = maxlines; fnewlineflag = newlineflag; } -const string& CSPList::Line (size_t idx) const { +const string& CSPList::Line(size_t idx) const { if (idx >= flines.size()) return emptyString; return flines[idx]; } -void CSPList::Add (const string& line) { +void CSPList::Add(const string& line) { if (flines.size() < fmax) { flines.push_back(line); } } -void CSPList::AddLine () { +void CSPList::AddLine() { if (flines.size() < fmax) { flines.push_back(emptyString); } } -void CSPList::Append (const string& line, size_t idx) { +void CSPList::Append(const string& line, size_t idx) { if (idx >= flines.size()) return; flines[idx] += line; } -void CSPList::Print () const { +void CSPList::Print() const { for (size_t i = 0; i < flines.size(); i++) cout << flines[i] << endl; } -bool CSPList::Load (const string &filepath) { +bool CSPList::Load(const string &filepath) { std::ifstream tempfile(filepath.c_str()); string line; if (!tempfile) { - Message ("CSPList::Load - unable to open " + filepath); + Message("CSPList::Load - unable to open " + filepath); return false; } else { bool backflag = false; while (getline(tempfile, line)) { // delete new line char if in string - size_t npos = line.rfind ('\n'); - if (npos != string::npos) SDeleteN (line, npos, 1); + size_t npos = line.rfind('\n'); + if (npos != string::npos) SDeleteN(line, npos, 1); bool valid = true; if (line.empty()) valid = false; // empty line @@ -408,24 +408,24 @@ bool CSPList::Load (const string &filepath) { if (valid) { if (flines.size() < fmax) { if (!fnewlineflag) { - if (line[0] == '*' || flines.empty()) Add (line); - else Append (line, flines.size()-1); + if (line[0] == '*' || flines.empty()) Add(line); + else Append(line, flines.size()-1); } else { bool fwdflag; if (line[line.length()-1] == '\\') { - SDeleteN (line, line.length()-1, 1); + SDeleteN(line, line.length()-1, 1); fwdflag = true; } else { fwdflag = false; } - if (backflag == false) Add (line); - else Append (line, flines.size()-1); + if (backflag == false) Add(line); + else Append(line, flines.size()-1); backflag = fwdflag; } } else { - Message ("CSPList::Load - not enough lines"); + Message("CSPList::Load - not enough lines"); return false; } } @@ -434,14 +434,14 @@ bool CSPList::Load (const string &filepath) { } } -bool CSPList::Load (const string& dir, const string& filename) { - return Load (dir + SEP + filename); +bool CSPList::Load(const string& dir, const string& filename) { + return Load(dir + SEP + filename); } -bool CSPList::Save (const string &filepath) const { +bool CSPList::Save(const string &filepath) const { std::ofstream tempfile(filepath.c_str()); if (!tempfile) { - Message ("CSPList::Save - unable to open " + filepath); + Message("CSPList::Save - unable to open " + filepath); return false; } else { for (size_t i=0; i& index, const string &tag) { +void CSPList::MakeIndex(map& index, const string &tag) { index.clear(); size_t idx = 0; for (size_t i=0; i TVector2 Str_Vector2(const string &s, const TVector2& def); @@ -51,17 +51,17 @@ template TVector3 Str_Vector3(const string &s, const TVector3& def); template TVector4 Str_Vector4(const string &s, const TVector4& def); -TColor Str_ColorN (const string &s, const TColor& def); -TColor3 Str_Color3N (const string &s, const TColor3& def); -void Str_ArrN (const string &s, float *arr, size_t count, float def); +TColor Str_ColorN(const string &s, const TColor& def); +TColor3 Str_Color3N(const string &s, const TColor3& def); +void Str_ArrN(const string &s, float *arr, size_t count, float def); // ----- SP functions for parsing lines -------------------------------- -size_t SPPosN (const string &s, const string &tag); +size_t SPPosN(const string &s, const string &tag); -string SPStrN (const string &s, const string &tag, const string& def = emptyString); -int SPIntN (const string &s, const string &tag, const int def); -bool SPBoolN (const string &s, const string &tag, const bool def); -float SPFloatN (const string &s, const string &tag, const float def); +string SPStrN(const string &s, const string &tag, const string& def = emptyString); +int SPIntN(const string &s, const string &tag, const int def); +bool SPBoolN(const string &s, const string &tag, const bool def); +float SPFloatN(const string &s, const string &tag, const float def); template TVector2 SPVector2(const string &s, const string &tag, const TVector2& def); static inline TVector2d SPVector2d(const string &s, const string &tag) { return SPVector2(s, tag, NullVec2); } @@ -74,22 +74,22 @@ template TVector4 SPVector4(const string &s, const string &tag, const TVector4& def); static inline TVector4d SPVector4d(const string &s, const string &tag) { return SPVector4(s, tag, NullVec4); } static inline TVector4i SPVector4i(const string &s, const string &tag) { return SPVector4(s, tag, NullVec4i); } -TColor SPColorN (const string &s, const string &tag, const TColor& def); -TColor3 SPColor3N (const string &s, const string &tag, const TColor3& def); -void SPArrN (const string &s, const string &tag, float *arr, size_t count, float def); +TColor SPColorN(const string &s, const string &tag, const TColor& def); +TColor3 SPColor3N(const string &s, const string &tag, const TColor3& def); +void SPArrN(const string &s, const string &tag, float *arr, size_t count, float def); // ----- making SP strings -------------------------------------------- -void SPAddIntN (string &s, const string &tag, const int val); -void SPAddFloatN (string &s, const string &tag, const float val, size_t count); -void SPAddStrN (string &s, const string &tag, const string &val); -void SPAddVec2N (string &s, const string &tag, const TVector2d& val, size_t count); -void SPAddVec3N (string &s, const string &tag, const TVector3d& val, size_t count); -void SPAddBoolN (string &s, const string &tag, const bool val); +void SPAddIntN(string &s, const string &tag, const int val); +void SPAddFloatN(string &s, const string &tag, const float val, size_t count); +void SPAddStrN(string &s, const string &tag, const string &val); +void SPAddVec2N(string &s, const string &tag, const TVector2d& val, size_t count); +void SPAddVec3N(string &s, const string &tag, const TVector3d& val, size_t count); +void SPAddBoolN(string &s, const string &tag, const bool val); // ----- manipulating SP strings -------------------------------------- -void SPSetIntN (string &s, const string &tag, const int val); -void SPSetFloatN (string &s, const string &tag, const float val, size_t count); -void SPSetStrN (string &s, const string &tag, const string &val); +void SPSetIntN(string &s, const string &tag, const int val); +void SPSetFloatN(string &s, const string &tag, const float val, size_t count); +void SPSetStrN(string &s, const string &tag, const string &val); // -------------------------------------------------------------------- // string list @@ -101,21 +101,21 @@ private: size_t fmax; bool fnewlineflag; public: - CSPList (size_t maxlines, bool newlineflag = false); + CSPList(size_t maxlines, bool newlineflag = false); - const string& Line (size_t idx) const; - size_t Count () const { return flines.size(); } - void Clear () { flines.clear(); } - void Add (const string& line); + const string& Line(size_t idx) const; + size_t Count() const { return flines.size(); } + void Clear() { flines.clear(); } + void Add(const string& line); void AddLine(); - void Append (const string& line, size_t idx); - void Print () const; - bool Load (const string &filepath); - bool Load (const string& dir, const string& filename); - bool Save (const string &filepath) const; - bool Save (const string& dir, const string& filename) const; + void Append(const string& line, size_t idx); + void Print() const; + bool Load(const string &filepath); + bool Load(const string& dir, const string& filename); + bool Save(const string &filepath) const; + bool Save(const string& dir, const string& filename) const; - void MakeIndex (map& index, const string &tag); + void MakeIndex(map& index, const string &tag); }; #endif diff --git a/src/states.cpp b/src/states.cpp index 1f85f12..0317872 100644 --- a/src/states.cpp +++ b/src/states.cpp @@ -66,7 +66,7 @@ void State::Manager::PollEvent() { unsigned int key; int x, y; - while (SDL_PollEvent (&event)) { + while (SDL_PollEvent(&event)) { if (!next) { switch (event.type) { case SDL_KEYDOWN: @@ -116,7 +116,7 @@ void State::Manager::PollEvent() { if (Winsys.resolution.width != event.resize.w || Winsys.resolution.height != event.resize.h) { Winsys.resolution.width = event.resize.w; Winsys.resolution.height = event.resize.h; - Winsys.SetupVideoMode (param.res_type); + Winsys.SetupVideoMode(param.res_type); Reshape(event.resize.w, event.resize.h); } break; @@ -130,6 +130,8 @@ void State::Manager::PollEvent() { } void State::Manager::CallLoopFunction() { + check_gl_error(); + float cur_time = SDL_GetTicks() * 1.e-3; g_game.time_step = cur_time - clock_time; if (g_game.time_step < 0.0001) g_game.time_step = 0.0001; diff --git a/src/textures.cpp b/src/textures.cpp index 9c031d1..466b681 100644 --- a/src/textures.cpp +++ b/src/textures.cpp @@ -41,7 +41,7 @@ static const GLshort fullsize_texture[] = { // class CImage // -------------------------------------------------------------------- -CImage::CImage () { +CImage::CImage() { data = NULL; nx = 0; ny = 0; @@ -49,22 +49,22 @@ CImage::CImage () { pitch = 0; } -CImage::~CImage () { - DisposeData (); +CImage::~CImage() { + DisposeData(); } -void CImage::DisposeData () { +void CImage::DisposeData() { delete[] data; data = NULL; } -bool CImage::LoadPng (const char *filepath, bool mirroring) { +bool CImage::LoadPng(const char *filepath, bool mirroring) { SDL_Surface *sdlImage; unsigned char *sdlData; - sdlImage = IMG_Load (filepath); + sdlImage = IMG_Load(filepath); if (sdlImage == 0) { - Message ("could not load image", filepath); + Message("could not load image", filepath); return false; } @@ -72,13 +72,13 @@ bool CImage::LoadPng (const char *filepath, bool mirroring) { ny = sdlImage->h; depth = sdlImage->format->BytesPerPixel; pitch = sdlImage->pitch; - DisposeData (); + DisposeData(); data = new unsigned char[pitch * ny]; - if (SDL_MUSTLOCK (sdlImage)) { - if (SDL_LockSurface (sdlImage) < 0) { - SDL_FreeSurface (sdlImage); - Message ("mustlock error"); + if (SDL_MUSTLOCK(sdlImage)) { + if (SDL_LockSurface(sdlImage) < 0) { + SDL_FreeSurface(sdlImage); + Message("mustlock error"); return false; }; } @@ -93,67 +93,67 @@ bool CImage::LoadPng (const char *filepath, bool mirroring) { memcpy(data, sdlData, ny*pitch); } - if (SDL_MUSTLOCK (sdlImage)) SDL_UnlockSurface (sdlImage); - SDL_FreeSurface (sdlImage); + if (SDL_MUSTLOCK(sdlImage)) SDL_UnlockSurface(sdlImage); + SDL_FreeSurface(sdlImage); return true; } -bool CImage::LoadPng (const char *dir, const char *filename, bool mirroring) { +bool CImage::LoadPng(const char *dir, const char *filename, bool mirroring) { string path = dir; path += SEP; path += filename; - return LoadPng (path.c_str(), mirroring); + return LoadPng(path.c_str(), mirroring); } // ------------------ read framebuffer -------------------------------- -bool CImage::ReadFrameBuffer_PPM () { +bool CImage::ReadFrameBuffer_PPM() { int viewport[4]; - glGetIntegerv (GL_VIEWPORT, viewport); + glGetIntegerv(GL_VIEWPORT, viewport); nx = viewport[2]; ny = viewport[3]; depth = 3; - DisposeData (); + DisposeData(); data = new unsigned char[nx * ny * depth]; - glReadBuffer (GL_FRONT); + glReadBuffer(GL_FRONT); for (int i=0; i 0) { - if (w < 1) glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &ww); - if (h < 1) glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &hh); + if (w < 1) glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &ww); + if (h < 1) glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &hh); glColor(col, 1.0); - glDisable (GL_TEXTURE_2D); + glDisable(GL_TEXTURE_2D); const GLint vtx [] = { xx - frame, yy - frame, xx + ww + frame, yy - frame, @@ -500,10 +500,10 @@ void TTexture::DrawFrame(int x, int y, double w, double h, int frame, const TCol glVertexPointer(2, GL_INT, 0, vtx); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glEnable (GL_TEXTURE_2D); + glEnable(GL_TEXTURE_2D); } - glColor4f (1.0, 1.0, 1.0, 1.0); + glColor4f(1.0, 1.0, 1.0, 1.0); const GLshort vtx[] = { xx, yy, @@ -526,115 +526,83 @@ void TTexture::DrawFrame(int x, int y, double w, double h, int frame, const TCol CTexture Tex; -CTexture::CTexture () { +CTexture::CTexture() { forientation = OR_TOP; } -CTexture::~CTexture () { +CTexture::~CTexture() { FreeTextureList(); } -void CTexture::LoadTextureList () { +void CTexture::LoadTextureList() { FreeTextureList(); - CSPList list (200); - if (list.Load (param.tex_dir, "textures.lst")) { + CSPList list(200); + if (list.Load(param.tex_dir, "textures.lst")) { for (size_t i=0; i= 0) { CommonTex[id] = new TTexture(); if (rep) CommonTex[id]->LoadMipmap(param.tex_dir, texfile, rep); else CommonTex[id]->Load(param.tex_dir, texfile); - - Index[name] = CommonTex[id]; - } else Message ("wrong texture id in textures.lst"); + } else Message("wrong texture id in textures.lst"); } - } else Message ("failed to load common textures"); + } else Message("failed to load common textures"); } -void CTexture::FreeTextureList () { +void CTexture::FreeTextureList() { for (size_t i=0; i= CommonTex.size()) return NULL; return CommonTex[idx]; } -TTexture* CTexture::GetTexture (const string& name) const { - return Index.at(name); -} - -bool CTexture::BindTex (size_t idx) { +bool CTexture::BindTex(size_t idx) { if (idx >= CommonTex.size()) return false; CommonTex[idx]->Bind(); return true; } -bool CTexture::BindTex (const string& name) { - try { - Index.at(name)->Bind(); - } catch (...) { - return false; - } - return true; -} - // ---------------------------- Draw ---------------------------------- -void CTexture::Draw (size_t idx) { +void CTexture::Draw(size_t idx) { if (CommonTex.size() > idx) CommonTex[idx]->Draw(); } -void CTexture::Draw (const string& name) { - Index[name]->Draw(); -} - -void CTexture::Draw (size_t idx, int x, int y, float size) { +void CTexture::Draw(size_t idx, int x, int y, float size) { if (CommonTex.size() > idx) CommonTex[idx]->Draw(x, y, size, forientation); } -void CTexture::Draw (const string& name, int x, int y, float size) { - Index[name]->Draw(x, y, size, forientation); -} - -void CTexture::Draw (size_t idx, int x, int y, int width, int height) { +void CTexture::Draw(size_t idx, int x, int y, int width, int height) { if (CommonTex.size() > idx) - CommonTex[idx]->Draw (x, y, width, height, forientation); + CommonTex[idx]->Draw(x, y, width, height, forientation); } -void CTexture::Draw (const string& name, int x, int y, int width, int height) { - Index[name]->Draw (x, y, width, height, forientation); -} - -void CTexture::DrawFrame (size_t idx, int x, int y, double w, double h, int frame, const TColor& col) { +void CTexture::DrawFrame(size_t idx, int x, int y, double w, double h, int frame, const TColor& col) { if (CommonTex.size() > idx) - CommonTex[idx]->DrawFrame (x, y, w, h, frame, col); + CommonTex[idx]->DrawFrame(x, y, w, h, frame, col); } -void CTexture::DrawFrame (const string& name, int x, int y, double w, double h, int frame, const TColor& col) { - Index[name]->DrawFrame (x, y, w, h, frame, col); -} - -void CTexture::SetOrientation (Orientation orientation) { +void CTexture::SetOrientation(Orientation orientation) { forientation = orientation; } // -------------------------- numeric strings ------------------------- -void CTexture::DrawNumChr (char c, int x, int y, int w, int h, const TColor& col) { +void CTexture::DrawNumChr(char c, int x, int y, int w, int h, const TColor& col) { int idx; if (isdigit(c)) { char chrname[2] = {c, '\0'}; @@ -669,13 +637,13 @@ void CTexture::DrawNumChr (char c, int x, int y, int w, int h, const TColor& col glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } -void CTexture::DrawNumStr (const string& s, int x, int y, float size, const TColor& col) { - if (!BindTex ("ziff032")) { - Message ("DrawNumStr: missing texture"); +void CTexture::DrawNumStr(const string& s, int x, int y, float size, const TColor& col) { + if (!BindTex(NUMERIC_FONT)) { + Message("DrawNumStr: missing texture"); return; } - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable (GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_TEXTURE_2D); int qw = (int)(22 * size); int qh = (int)(32 * size); @@ -683,7 +651,7 @@ void CTexture::DrawNumStr (const string& s, int x, int y, float size, const TCol glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); for (size_t i=0; i < s.size(); i++) { - DrawNumChr (s[i], x + (int)i*qw, y, qw, qh, col); + DrawNumChr(s[i], x + (int)i*qw, y, qw, qh, col); } glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); @@ -696,7 +664,7 @@ void CTexture::DrawNumStr (const string& s, int x, int y, float size, const TCol // 0 ppm, 1 tga, 2 bmp #define SCREENSHOT_PROC 2 -void ScreenshotN () { +void ScreenshotN() { CImage image; string path = param.screenshot_dir; path += SEP; @@ -708,18 +676,18 @@ void ScreenshotN () { switch (type) { case 0: path += ".ppm"; - image.ReadFrameBuffer_PPM (); - image.WritePPM (path.c_str()); + image.ReadFrameBuffer_PPM(); + image.WritePPM(path.c_str()); break; case 1: path += ".tga"; - image.ReadFrameBuffer_TGA (); - image.WriteTGA (path.c_str()); + image.ReadFrameBuffer_TGA(); + image.WriteTGA(path.c_str()); break; case 2: path += ".bmp"; - image.ReadFrameBuffer_BMP (); - image.WriteBMP (path.c_str()); + image.ReadFrameBuffer_BMP(); + image.WriteBMP(path.c_str()); break; } } diff --git a/src/textures.h b/src/textures.h index e01fd98..0220e89 100644 --- a/src/textures.h +++ b/src/textures.h @@ -20,7 +20,6 @@ GNU General Public License for more details. #include "bh.h" #include -#include #define TEXLOGO 0 #define SNOW_START 1 @@ -72,8 +71,8 @@ GNU General Public License for more details. class CImage { private: public: - CImage (); - ~CImage (); + CImage(); + ~CImage(); unsigned char *data; int nx; @@ -81,19 +80,19 @@ public: int depth; int pitch; - void DisposeData (); + void DisposeData(); // load: - bool LoadPng (const char *filepath, bool mirroring); - bool LoadPng (const char *dir, const char *filepath, bool mirroring); + bool LoadPng(const char *filepath, bool mirroring); + bool LoadPng(const char *dir, const char *filepath, bool mirroring); // write: - bool ReadFrameBuffer_PPM (); - void ReadFrameBuffer_TGA (); - void ReadFrameBuffer_BMP (); - void WritePPM (const char *filepath); - void WriteTGA (const char *filepath); - void WriteBMP (const char *filepath); + bool ReadFrameBuffer_PPM(); + void ReadFrameBuffer_TGA(); + void ReadFrameBuffer_BMP(); + void WritePPM(const char *filepath); + void WriteTGA(const char *filepath); + void WriteBMP(const char *filepath); }; // -------------------------------------------------------------------- @@ -124,40 +123,31 @@ public: class CTexture { private: vector CommonTex; - map Index; Orientation forientation; - void DrawNumChr (char c, int x, int y, int w, int h, const TColor& col); + void DrawNumChr(char c, int x, int y, int w, int h, const TColor& col); public: - CTexture (); - ~CTexture (); - void LoadTextureList (); - void FreeTextureList (); + CTexture(); + ~CTexture(); + void LoadTextureList(); + void FreeTextureList(); - TTexture* GetTexture (size_t idx) const; - TTexture* GetTexture (const string& name) const; - bool BindTex (size_t idx); - bool BindTex (const string& name); + TTexture* GetTexture(size_t idx) const; + bool BindTex(size_t idx); - void Draw (size_t idx); - void Draw (const string& name); + void Draw(size_t idx); + void Draw(size_t idx, int x, int y, float size); + void Draw(size_t idx, int x, int y, int width, int height); - void Draw (size_t idx, int x, int y, float size); - void Draw (const string& name, int x, int y, float size); + void DrawFrame(size_t idx, int x, int y, double w, double h, int frame, const TColor& col); - void Draw (size_t idx, int x, int y, int width, int height); - void Draw (const string& name, int x, int y, int width, int height); - - void DrawFrame (size_t idx, int x, int y, double w, double h, int frame, const TColor& col); - void DrawFrame (const string& name, int x, int y, double w, double h, int frame, const TColor& col); - - void SetOrientation (Orientation orientation); - void DrawNumStr (const string& s, int x, int y, float size, const TColor& col); + void SetOrientation(Orientation orientation); + void DrawNumStr(const string& s, int x, int y, float size, const TColor& col); }; extern CTexture Tex; -void ScreenshotN (); +void ScreenshotN(); #endif diff --git a/src/tool_char.cpp b/src/tool_char.cpp index 8f30a0c..88d0b7a 100644 --- a/src/tool_char.cpp +++ b/src/tool_char.cpp @@ -56,32 +56,32 @@ static bool rotactive = false; static bool moveactive = false; static int comp = 0; -void InitCharTools () { +void InitCharTools() { charbase = (int)((Winsys.resolution.height - 200) / 18); firstnode = 1; - lastnode = TestChar.GetNumNodes () -1; + lastnode = TestChar.GetNumNodes() -1; curr_node = firstnode; curr_act = firstact; - lastact = TestChar.GetNumActs (curr_node) -1; - action = TestChar.GetAction (curr_node); - StoreAction (action); + lastact = TestChar.GetNumActs(curr_node) -1; + action = TestChar.GetAction(curr_node); + StoreAction(action); } -void StoreAction (TCharAction *act) { +void StoreAction(TCharAction *act) { for (size_t i=0; i<=act->num; i++) { Undo.vec[i] = act->vec[i]; Undo.dval[i] = act->dval[i]; } } -void RecallAction (TCharAction *act) { +void RecallAction(TCharAction *act) { for (size_t i=0; i<=act->num; i++) { act->vec[i] = Undo.vec[i]; act->dval[i] = Undo.dval[i]; } } -void ChangeValue (int type, double fact) { +void ChangeValue(int type, double fact) { if (type == 0 || type == 4) { if (comp == 0) { action->vec[curr_act].x += 0.02 * fact; @@ -95,38 +95,38 @@ void ChangeValue (int type, double fact) { } else if (type == 5) { action->dval[curr_act] += 1 * fact; } - TestChar.RefreshNode (curr_node); - SetCharChanged (true); + TestChar.RefreshNode(curr_node); + SetCharChanged(true); } -void ChangeNode (int steps) { +void ChangeNode(int steps) { bool ch; if (steps > 0) ch = (curr_node + steps <= lastnode); else ch = (curr_node + steps >= firstnode); if (ch) { curr_node += steps; curr_act = firstact; - lastact = TestChar.GetNumActs (curr_node) -1; - action = TestChar.GetAction (curr_node); + lastact = TestChar.GetNumActs(curr_node) -1; + action = TestChar.GetAction(curr_node); if (action->num > 0 && action->type[0] == 4) comp = 0; else comp = 1; - StoreAction (action); + StoreAction(action); } } -void SetRotation (double x, double y, double z) { +void SetRotation(double x, double y, double z) { xrotation = x; yrotation = y; zrotation = z; } -void CharKeys (unsigned int key, bool special, bool release, int x, int y) { +void CharKeys(unsigned int key, bool special, bool release, int x, int y) { must_render = true; - if (ToolsFinalStage ()) { + if (ToolsFinalStage()) { if (key == SDLK_y || key == SDLK_j) { - SaveToolCharacter (); - SaveToolFrame (); + SaveToolCharacter(); + SaveToolFrame(); State::manager.RequestQuit(); } else if (key == SDLK_n) State::manager.RequestQuit(); return; @@ -141,20 +141,20 @@ void CharKeys (unsigned int key, bool special, bool release, int x, int y) { int type = action->type[curr_act]; switch (key) { case SDLK_TAB: - SetToolMode (1); + SetToolMode(1); break; case SDLK_ESCAPE: case SDLK_q: - QuitTool (); + QuitTool(); break; case SDLK_F10: - ScreenshotN (); + ScreenshotN(); break; case SDLK_s: - SaveToolCharacter (); + SaveToolCharacter(); break; case SDLK_c: - ScreenshotN (); + ScreenshotN(); break; case SDLK_m: TestChar.useMaterials = !TestChar.useMaterials; @@ -163,14 +163,14 @@ void CharKeys (unsigned int key, bool special, bool release, int x, int y) { TestChar.useHighlighting = !TestChar.useHighlighting; break; case SDLK_r: - TestChar.Reset (); - ReloadToolCharacter (); - Tools.Enter (); + TestChar.Reset(); + ReloadToolCharacter(); + Tools.Enter(); break; case SDLK_u: if (action != NULL) { - RecallAction (action); - TestChar.RefreshNode (curr_node); + RecallAction(action); + TestChar.RefreshNode(curr_node); } break; case SDLK_PLUS: @@ -185,30 +185,30 @@ void CharKeys (unsigned int key, bool special, bool release, int x, int y) { // set rotations for view case SDLK_1: - SetRotation (0, 0, 0); + SetRotation(0, 0, 0); break; case SDLK_2: - SetRotation (-50, 180, 15); + SetRotation(-50, 180, 15); break; case SDLK_3: - SetRotation (0, 180, 0); + SetRotation(0, 180, 0); break; case SDLK_4: - SetRotation (0, -80, 0); + SetRotation(0, -80, 0); break; // select node case SDLK_PAGEUP: - ChangeNode (-1); + ChangeNode(-1); break; case SDLK_PAGEDOWN: - ChangeNode (1); + ChangeNode(1); break; case SDLK_END: - ChangeNode (charbase); + ChangeNode(charbase); break; case SDLK_HOME: - ChangeNode (-charbase); + ChangeNode(-charbase); break; // select action @@ -223,10 +223,10 @@ void CharKeys (unsigned int key, bool special, bool release, int x, int y) { else comp = 1; break; case SDLK_LEFT: - ChangeValue (type, -1); + ChangeValue(type, -1); break; case SDLK_RIGHT: - ChangeValue (type, 1); + ChangeValue(type, 1); break; // select value @@ -242,9 +242,9 @@ void CharKeys (unsigned int key, bool special, bool release, int x, int y) { } } -void CharMouse (int button, int state, int x, int y) { +void CharMouse(int button, int state, int x, int y) { must_render = true; - if (ToolsFinalStage ()) return; + if (ToolsFinalStage()) return; if (state<1) { rotactive = false; @@ -272,7 +272,7 @@ void CharMouse (int button, int state, int x, int y) { } } -void CharMotion (int x, int y) { +void CharMotion(int x, int y) { must_render = true; if (rotactive) { int diffx = cursor_pos.x - startx; @@ -282,93 +282,92 @@ void CharMotion (int x, int y) { } if (moveactive) { float diffposx = (float)(cursor_pos.x - startx) / 200; - float diffposy = (float) (cursor_pos.y - starty) / 200; + float diffposy = (float)(cursor_pos.y - starty) / 200; yposition = startposy - diffposy; xposition = startposx + diffposx; } } -void DrawActionVec (size_t nr, const string& s, int y, const TVector3d& v) { - FT.SetColor (colLGrey); - FT.DrawString (20, y, s); +void DrawActionVec(size_t nr, const string& s, int y, const TVector3d& v) { + FT.SetColor(colLGrey); + FT.DrawString(20, y, s); if (nr == curr_act) { if (comp == 0) { - FT.SetColor (colYellow); - FT.DrawString (100, y, Float_StrN (v.x, 2)); - FT.DrawString (150, y, Float_StrN (v.y, 2)); - FT.DrawString (200, y, Float_StrN (v.z, 2)); + FT.SetColor(colYellow); + FT.DrawString(100, y, Float_StrN(v.x, 2)); + FT.DrawString(150, y, Float_StrN(v.y, 2)); + FT.DrawString(200, y, Float_StrN(v.z, 2)); } else { - if (comp == 1) FT.SetColor (colYellow); - else FT.SetColor (colLGrey); - FT.DrawString (100, y, Float_StrN (v.x, 2)); - if (comp == 2) FT.SetColor (colYellow); - else FT.SetColor (colLGrey); - FT.DrawString (150, y, Float_StrN (v.y, 2)); - if (comp == 3) FT.SetColor (colYellow); - else FT.SetColor (colLGrey); - FT.DrawString (200, y, Float_StrN (v.z, 2)); + if (comp == 1) FT.SetColor(colYellow); + else FT.SetColor(colLGrey); + FT.DrawString(100, y, Float_StrN(v.x, 2)); + if (comp == 2) FT.SetColor(colYellow); + else FT.SetColor(colLGrey); + FT.DrawString(150, y, Float_StrN(v.y, 2)); + if (comp == 3) FT.SetColor(colYellow); + else FT.SetColor(colLGrey); + FT.DrawString(200, y, Float_StrN(v.z, 2)); } } else { - FT.DrawString (100, y, Float_StrN (v.x, 2)); - FT.DrawString (150, y, Float_StrN (v.y, 2)); - FT.DrawString (200, y, Float_StrN (v.z, 2)); + FT.DrawString(100, y, Float_StrN(v.x, 2)); + FT.DrawString(150, y, Float_StrN(v.y, 2)); + FT.DrawString(200, y, Float_StrN(v.z, 2)); } } -void DrawActionFloat (size_t nr, const string& s, int y, float f) { - FT.SetColor (colLGrey); - FT.DrawString (20, y, s); - if (nr == curr_act) FT.SetColor (colYellow); - else FT.SetColor (colLGrey); - FT.DrawString (100, y, Float_StrN (f, 2)); +void DrawActionFloat(size_t nr, const string& s, int y, float f) { + FT.SetColor(colLGrey); + FT.DrawString(20, y, s); + if (nr == curr_act) FT.SetColor(colYellow); + else FT.SetColor(colLGrey); + FT.DrawString(100, y, Float_StrN(f, 2)); } -void RenderChar (double timestep) { +void RenderChar(double timestep) { if (!must_render) return; bool is_visible = false; - check_gl_error(); // ------------- 3d scenery --------------------------------------- ScopedRenderMode rm1(TUX); - ClearRenderContext (colDDBackgr); - TestChar.highlight_node = TestChar.GetNodeName (curr_node); + ClearRenderContext(colDDBackgr); + TestChar.highlight_node = TestChar.GetNodeName(curr_node); - glLoadIdentity (); - glPushMatrix (); - SetToolLight (); + glLoadIdentity(); + glPushMatrix(); + SetToolLight(); - TestChar.ResetRoot (); - TestChar.ResetJoints (); - glTranslatef (xposition, yposition, zposition); - glRotatef (xrotation, 1, 0, 0); - glRotatef (yrotation, 0, 1, 0); - glRotatef (zrotation, 0, 0, 1); + TestChar.ResetRoot(); + TestChar.ResetJoints(); + glTranslatef(xposition, yposition, zposition); + glRotatef(xrotation, 1, 0, 0); + glRotatef(yrotation, 0, 1, 0); + glRotatef(zrotation, 0, 0, 1); - if (drawcount > 0) TestChar.Draw (); - glPopMatrix (); + if (drawcount > 0) TestChar.Draw(); + glPopMatrix(); drawcount++; // --------------- 2d screen -------------------------------------- - SetupGuiDisplay (); + SetupGuiDisplay(); ScopedRenderMode rm2(TEXFONT); FT.SetProps("bold", 20, colYellow); - FT.DrawString (-1, 10, "Edit mode"); + FT.DrawString(-1, 10, "Edit mode"); - if (CharHasChanged ()) DrawChanged (); + if (CharHasChanged()) DrawChanged(); - FT.SetSize (16); + FT.SetSize(16); for (size_t i=0; i<=lastnode; i++) { if (i != curr_node) { - FT.SetColor (colLGrey); - FT.SetFont ("normal"); + FT.SetColor(colLGrey); + FT.SetFont("normal"); } else { - FT.SetColor (colYellow); - FT.SetFont ("bold"); + FT.SetColor(colYellow); + FT.SetFont("bold"); } - int xl = ITrunc ((int)i, charbase) * 100 + 20; - int yt = IFrac ((int)i, charbase) * 18 + 60; - FT.DrawString (xl, yt, TestChar.GetNodeJoint (i)); + int xl = ITrunc((int)i, charbase) * 100 + 20; + int yt = IFrac((int)i, charbase) * 18 + 60; + FT.DrawString(xl, yt, TestChar.GetNodeJoint(i)); } size_t num = action->num; @@ -380,22 +379,22 @@ void RenderChar (double timestep) { int yt = Winsys.resolution.height - 120 + (int)i * 18; switch (type) { case 0: - DrawActionVec (i, "trans", yt, action->vec[i]); + DrawActionVec(i, "trans", yt, action->vec[i]); break; case 1: - DrawActionFloat (i, "x-rot", yt, action->dval[i]); + DrawActionFloat(i, "x-rot", yt, action->dval[i]); break; case 2: - DrawActionFloat (i, "y-rot", yt, action->dval[i]); + DrawActionFloat(i, "y-rot", yt, action->dval[i]); break; case 3: - DrawActionFloat (i, "z-rot", yt, action->dval[i]); + DrawActionFloat(i, "z-rot", yt, action->dval[i]); break; case 4: - DrawActionVec (i, "scale", yt, action->vec[i]); + DrawActionVec(i, "scale", yt, action->vec[i]); break; case 5: - DrawActionFloat (i, "vis", yt, action->dval[i]); + DrawActionFloat(i, "vis", yt, action->dval[i]); is_visible = true; break; default: @@ -405,17 +404,17 @@ void RenderChar (double timestep) { } FT.SetFont("normal"); - if (is_visible) FT.SetColor (colYellow); - else FT.SetColor (colLGrey); - FT.DrawString (20, 20, action->name); + if (is_visible) FT.SetColor(colYellow); + else FT.SetColor(colLGrey); + FT.DrawString(20, 20, action->name); - if (ToolsFinalStage ()) { - FT.SetSize (20); - FT.SetColor (colYellow); - FT.DrawString (-1, Winsys.resolution.height - 50, "Quit program. Save character list (y/n)"); + if (ToolsFinalStage()) { + FT.SetSize(20); + FT.SetColor(colYellow); + FT.DrawString(-1, Winsys.resolution.height - 50, "Quit program. Save character list (y/n)"); } - Reshape (Winsys.resolution.width, Winsys.resolution.height); - Winsys.SwapBuffers (); + Reshape(Winsys.resolution.width, Winsys.resolution.height); + Winsys.SwapBuffers(); if (drawcount > 3) must_render = false; } diff --git a/src/tool_char.h b/src/tool_char.h index ee9ac6b..6be174b 100644 --- a/src/tool_char.h +++ b/src/tool_char.h @@ -22,12 +22,12 @@ GNU General Public License for more details. struct TCharAction; -void InitCharTools (); -void CharKeys (unsigned int key, bool special, bool release, int x, int y); -void CharMouse (int button, int state, int x, int y); -void CharMotion (int x, int y); -void RenderChar (double timestep); -void StoreAction (TCharAction *act); +void InitCharTools(); +void CharKeys(unsigned int key, bool special, bool release, int x, int y); +void CharMouse(int button, int state, int x, int y); +void CharMotion(int x, int y); +void RenderChar(double timestep); +void StoreAction(TCharAction *act); #endif diff --git a/src/tool_frame.cpp b/src/tool_frame.cpp index 690bc6f..2fb787e 100644 --- a/src/tool_frame.cpp +++ b/src/tool_frame.cpp @@ -42,19 +42,19 @@ static bool alt = false; static bool lastframe = 0; static bool keyrun = false; -void InitFrameTools () { +void InitFrameTools() { framebase = (int)((Winsys.resolution.height - 350) / 18); - if (TestFrame.numFrames() < 1) TestFrame.AddFrame (); + if (TestFrame.numFrames() < 1) TestFrame.AddFrame(); curr_joint = 0; - last_joint = TestFrame.GetNumJoints () -1; + last_joint = TestFrame.GetNumJoints() -1; } -void SingleFrameKeys (unsigned int key, bool special, bool release, int x, int y) { +void SingleFrameKeys(unsigned int key, bool special, bool release, int x, int y) { //PrintInt (key); must_render = true; int keyfact; lastframe = TestFrame.numFrames() != 1; - TKeyframe *frame = TestFrame.GetFrame (curr_frame); + TKeyframe *frame = TestFrame.GetFrame(curr_frame); // setting the camera change state if (key == SDLK_F1) {GluCamera.turnright = !release; return;} @@ -74,38 +74,38 @@ void SingleFrameKeys (unsigned int key, bool special, bool release, int x, int y switch (key) { case SDLK_y: case SDLK_j: - if (ToolsFinalStage ()) { - SaveToolCharacter (); - SaveToolFrame (); + if (ToolsFinalStage()) { + SaveToolCharacter(); + SaveToolFrame(); State::manager.RequestQuit(); } break; case SDLK_n: - if (ToolsFinalStage ()) State::manager.RequestQuit(); + if (ToolsFinalStage()) State::manager.RequestQuit(); break; case SDLK_ESCAPE: case SDLK_q: - QuitTool (); + QuitTool(); break; case SDLK_s: - SaveToolFrame (); + SaveToolFrame(); break; case SDLK_TAB: - SetToolMode (0); + SetToolMode(0); break; case SDLK_a: - TestFrame.AddFrame (); - SetFrameChanged (true); + TestFrame.AddFrame(); + SetFrameChanged(true); break; case SDLK_INSERT: - TestFrame.InsertFrame (curr_frame); - SetFrameChanged (true); + TestFrame.InsertFrame(curr_frame); + SetFrameChanged(true); break; case SDLK_DELETE: - curr_frame = TestFrame.DeleteFrame (curr_frame); - SetFrameChanged (true); + curr_frame = TestFrame.DeleteFrame(curr_frame); + SetFrameChanged(true); break; case SDLK_PAGEDOWN: if (curr_frame < TestFrame.numFrames()-1) curr_frame++; @@ -122,26 +122,26 @@ void SingleFrameKeys (unsigned int key, bool special, bool release, int x, int y case SDLK_RIGHT: if (curr_joint < 4) frame->val[curr_joint] += 0.05; else frame->val[curr_joint] += 1; - SetFrameChanged (true); + SetFrameChanged(true); break; case SDLK_LEFT: if (curr_joint < 4) frame->val[curr_joint] -= 0.05; else frame->val[curr_joint] -= 1; - SetFrameChanged (true); + SetFrameChanged(true); break; case SDLK_0: frame->val[curr_joint] = 0.0; - SetFrameChanged (true); + SetFrameChanged(true); break; case SDLK_SPACE: if (curr_joint < 4) frame->val[curr_joint] += 0.05 * keyfact; else frame->val[curr_joint] += 1 * keyfact; - SetFrameChanged (true); + SetFrameChanged(true); break; case SDLK_RETURN: - TestFrame.InitTest (ref_position, &TestChar); - SetToolMode (2); + TestFrame.InitTest(ref_position, &TestChar); + SetToolMode(2); must_render = true; break; @@ -152,20 +152,20 @@ void SingleFrameKeys (unsigned int key, bool special, bool release, int x, int y TestChar.useHighlighting = !TestChar.useHighlighting; break; case SDLK_c: - if (control) TestFrame.CopyToClipboard (curr_frame); - else TestFrame.ClearFrame (curr_frame); - SetFrameChanged (true); + if (control) TestFrame.CopyToClipboard(curr_frame); + else TestFrame.ClearFrame(curr_frame); + SetFrameChanged(true); break; case SDLK_v: - if (control) TestFrame.PasteFromClipboard (curr_frame); - SetFrameChanged (true); + if (control) TestFrame.PasteFromClipboard(curr_frame); + SetFrameChanged(true); break; case SDLK_p: if (curr_frame>0) - TestFrame.CopyFrame (curr_frame-1, curr_frame); + TestFrame.CopyFrame(curr_frame-1, curr_frame); break; case SDLK_F10: - ScreenshotN (); + ScreenshotN(); break; case SDLK_1: @@ -195,9 +195,9 @@ void SingleFrameKeys (unsigned int key, bool special, bool release, int x, int y } } -void SingleFrameMouse (int button, int state, int x, int y) { +void SingleFrameMouse(int button, int state, int x, int y) { must_render = true; - if (ToolsFinalStage ()) return; + if (ToolsFinalStage()) return; if (button == 4) { GluCamera.distance += 0.1; @@ -206,78 +206,77 @@ void SingleFrameMouse (int button, int state, int x, int y) { } } -void SingleFrameMotion (int x, int y) { +void SingleFrameMotion(int x, int y) { } -void PrintFrameParams (int ytop, TKeyframe *frame) { +void PrintFrameParams(int ytop, TKeyframe *frame) { int offs = 18; for (int i=0; i<=last_joint; i++) { - if (i == curr_joint) FT.SetColor (colYellow); - else FT.SetColor (colLGrey); + if (i == curr_joint) FT.SetColor(colYellow); + else FT.SetColor(colLGrey); - int x = ITrunc (i, jointbase) * 140 + 20; - int y = IFrac (i, jointbase) * offs + ytop; + int x = ITrunc(i, jointbase) * 140 + 20; + int y = IFrac(i, jointbase) * offs + ytop; - FT.DrawString (x, y, TestFrame.GetJointName(i)); - if (i < 4) FT.DrawString (x+80, y, Float_StrN (frame->val[i], 2)); - else FT.DrawString (x+80, y, Float_StrN (frame->val[i], 0)); + FT.DrawString(x, y, TestFrame.GetJointName(i)); + if (i < 4) FT.DrawString(x+80, y, Float_StrN(frame->val[i], 2)); + else FT.DrawString(x+80, y, Float_StrN(frame->val[i], 0)); } } -void RenderSingleFrame (double timestep) { +void RenderSingleFrame(double timestep) { if (!must_render) return; - check_gl_error (); // ------------------ 3d scenery ---------------------------------- ScopedRenderMode rm1(TUX); - ClearRenderContext (colDDBackgr); + ClearRenderContext(colDDBackgr); - const string& hlname = TestFrame.GetHighlightName (curr_joint); - TestChar.highlight_node = TestChar.GetNodeName (hlname); + const string& hlname = TestFrame.GetHighlightName(curr_joint); + TestChar.highlight_node = TestChar.GetNodeName(hlname); - glPushMatrix (); - SetToolLight (); - GluCamera.Update (timestep); + glPushMatrix(); + SetToolLight(); + GluCamera.Update(timestep); - TestFrame.CalcKeyframe (curr_frame, &TestChar, ref_position); - TestChar.Draw (); - glPopMatrix (); + TestFrame.CalcKeyframe(curr_frame, &TestChar, ref_position); + TestChar.Draw(); + glPopMatrix(); // ----------------- 2d screen ------------------------------------ - SetupGuiDisplay (); + SetupGuiDisplay(); ScopedRenderMode rm2(TEXFONT); - if (FrameHasChanged ()) DrawChanged (); + if (FrameHasChanged()) DrawChanged(); FT.SetProps("bold", 20, colYellow); - FT.DrawString (-1, 10, "Keyframe mode"); + FT.DrawString(-1, 10, "Keyframe mode"); FT.SetProps("normal", 16); for (size_t i=0; i 2) tool_mode = 0; else tool_mode = newmode; @@ -183,35 +183,35 @@ void SetToolMode (int newmode) { } } -bool CharHasChanged () {return charchanged;} -bool FrameHasChanged () {return framechanged;} +bool CharHasChanged() {return charchanged;} +bool FrameHasChanged() {return framechanged;} -bool ToolsFinalStage () { +bool ToolsFinalStage() { return finalstage; } -void SetCharChanged (bool val) { +void SetCharChanged(bool val) { charchanged = val; } -void SetFrameChanged (bool val) { +void SetFrameChanged(bool val) { framechanged = val; } -void SaveToolCharacter () { +void SaveToolCharacter() { if (!charchanged) return; - TestChar.SaveCharNodes (char_dir, char_file); + TestChar.SaveCharNodes(char_dir, char_file); charchanged = false; } -void ReloadToolCharacter () { - TestChar.Load (char_dir, char_file, true); +void ReloadToolCharacter() { + TestChar.Load(char_dir, char_file, true); charchanged = false; } -void SaveToolFrame () { +void SaveToolFrame() { if (!framechanged) return; - TestFrame.SaveTest (char_dir, frame_file); + TestFrame.SaveTest(char_dir, frame_file); framechanged = false; } @@ -222,33 +222,33 @@ void CTools::SetParameter(const string& dir, const string& file) { } void CTools::Enter() { - if (TestChar.Load (char_dir, char_file, true) == false) { - Message ("could not load 'shape.lst'"); + if (TestChar.Load(char_dir, char_file, true) == false) { + Message("could not load 'shape.lst'"); Winsys.Terminate(); } - if (TestFrame.Load (char_dir, frame_file) == false) { - Message ("could not load 'frame.lst'"); + if (TestFrame.Load(char_dir, frame_file) == false) { + Message("could not load 'frame.lst'"); Winsys.Terminate(); } charchanged = false; framechanged = false; - InitCharTools (); - InitFrameTools (); + InitCharTools(); + InitFrameTools(); - Winsys.KeyRepeat (true); + Winsys.KeyRepeat(true); } void CTools::Keyb(unsigned int key, bool special, bool release, int x, int y) { switch (tool_mode) { case 0: - CharKeys (key, special, release, x, y); + CharKeys(key, special, release, x, y); break; case 1: - SingleFrameKeys (key, special, release, x, y); + SingleFrameKeys(key, special, release, x, y); break; case 2: - SequenceKeys (key, special, release, x, y); + SequenceKeys(key, special, release, x, y); break; } } @@ -256,13 +256,13 @@ void CTools::Keyb(unsigned int key, bool special, bool release, int x, int y) { void CTools::Mouse(int button, int state, int x, int y) { switch (tool_mode) { case 0: - CharMouse (button, state, x, y); + CharMouse(button, state, x, y); break; case 1: - SingleFrameMouse (button, state, x, y); + SingleFrameMouse(button, state, x, y); break; case 2: - SequenceMouse (button, state, x, y); + SequenceMouse(button, state, x, y); break; } } @@ -270,13 +270,13 @@ void CTools::Mouse(int button, int state, int x, int y) { void CTools::Motion(int x, int y) { switch (tool_mode) { case 0: - CharMotion (x, y); + CharMotion(x, y); break; case 1: - SingleFrameMotion (x, y); + SingleFrameMotion(x, y); break; case 2: - SequenceMotion (x, y); + SequenceMotion(x, y); break; } } @@ -284,13 +284,13 @@ void CTools::Motion(int x, int y) { void CTools::Loop(double timestep) { switch (tool_mode) { case 0: - RenderChar (timestep); + RenderChar(timestep); break; case 1: - RenderSingleFrame (timestep); + RenderSingleFrame(timestep); break; case 2: - RenderSequence (timestep); + RenderSequence(timestep); break; } } diff --git a/src/tools.h b/src/tools.h index 1fd238b..7b79464 100644 --- a/src/tools.h +++ b/src/tools.h @@ -29,13 +29,13 @@ private: GLfloat vhead; // heading - Rundumsicht GLfloat vpitch; // pitch - Drehung nach oben/unten - void XMove (GLfloat step); - void YMove (GLfloat step); - void ZMove (GLfloat step); - void RotateHead (GLfloat step); - void RotatePitch (GLfloat step); + void XMove(GLfloat step); + void YMove(GLfloat step); + void ZMove(GLfloat step); + void RotateHead(GLfloat step); + void RotatePitch(GLfloat step); public: - CCamera (); + CCamera(); bool fore; bool back; @@ -47,7 +47,7 @@ public: bool headright; bool pitchup; bool pitchdown; - void Update (float timestep); + void Update(float timestep); }; // --------------------------------------------------------------- @@ -57,10 +57,10 @@ public: class CGluCamera { private: public: - CGluCamera (); + CGluCamera(); double distance; double angle; - void Update (double timestep); + void Update(double timestep); bool turnright; bool turnleft; @@ -72,18 +72,18 @@ extern CGluCamera GluCamera; // -------------------------------------------------------------------- -void SetToolLight (); -void QuitTool (); -void SetToolMode (int newmode); -bool ToolsFinalStage (); -void SetCharChanged (bool val); -void SetFrameChanged (bool val); -bool CharHasChanged (); -bool FrameHasChanged (); -void SaveToolCharacter (); -void SaveToolFrame (); -void ReloadToolCharacter (); -void DrawChanged (); +void SetToolLight(); +void QuitTool(); +void SetToolMode(int newmode); +bool ToolsFinalStage(); +void SetCharChanged(bool val); +void SetFrameChanged(bool val); +bool CharHasChanged(); +bool FrameHasChanged(); +void SaveToolCharacter(); +void SaveToolFrame(); +void ReloadToolCharacter(); +void DrawChanged(); class CTools : public State { diff --git a/src/track_marks.cpp b/src/track_marks.cpp index 95a0f21..3d347f6 100644 --- a/src/track_marks.cpp +++ b/src/track_marks.cpp @@ -105,15 +105,15 @@ void DrawTrackmarks() { TColor track_colour = colWhite; ScopedRenderMode rm(TRACK_MARKS); - textures[TRACK_HEAD] = Tex.GetTexture (trackid1); - textures[TRACK_MARK] = Tex.GetTexture (trackid2); - textures[TRACK_TAIL] = Tex.GetTexture (trackid3); + textures[TRACK_HEAD] = Tex.GetTexture(trackid1); + textures[TRACK_MARK] = Tex.GetTexture(trackid2); + textures[TRACK_TAIL] = Tex.GetTexture(trackid3); - glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); for (list::const_iterator q = track_marks.quads.begin(); q != track_marks.quads.end(); ++q) { track_colour.a = q->alpha; - set_material (track_colour, colBlack, 1.0); + set_material(track_colour, colBlack, 1.0); textures[q->track_type]->Bind(); if ((q->track_type == TRACK_HEAD) || (q->track_type == TRACK_TAIL)) { @@ -160,7 +160,7 @@ void DrawTrackmarks() { while (qnext != track_marks.quads.end() && qnext->track_type != TRACK_TAIL) { q = qnext; track_colour.a = q->alpha; - set_material (track_colour, colBlack, 1.0); + set_material(track_colour, colBlack, 1.0); glNormal3(q->n4); glTexCoord2(q->t4); @@ -203,7 +203,7 @@ void add_track_mark(const CControl *ctrl, int *id) { TTerrType *TerrList = &Course.TerrList[0]; - *id = Course.GetTerrainIdx (ctrl->cpos.x, ctrl->cpos.z, 0.5); + *id = Course.GetTerrainIdx(ctrl->cpos.x, ctrl->cpos.z, 0.5); if (*id < 1) { break_track_marks(); return; @@ -220,7 +220,7 @@ void add_track_mark(const CControl *ctrl, int *id) { return; } - TVector3d width_vector = CrossProduct (ctrl->cdirection, TVector3d (0, 1, 0)); + TVector3d width_vector = CrossProduct(ctrl->cdirection, TVector3d(0, 1, 0)); double magnitude = width_vector.Norm(); if (magnitude == 0) { break_track_marks(); @@ -231,16 +231,16 @@ void add_track_mark(const CControl *ctrl, int *id) { TVector3d right_vector = -TRACK_WIDTH/2.0 * width_vector; TVector3d left_wing = ctrl->cpos - left_vector; TVector3d right_wing = ctrl->cpos - right_vector; - double left_y = Course.FindYCoord (left_wing.x, left_wing.z); - double right_y = Course.FindYCoord (right_wing.x, right_wing.z); + double left_y = Course.FindYCoord(left_wing.x, left_wing.z); + double right_y = Course.FindYCoord(right_wing.x, right_wing.z); if (fabs(left_y-right_y) > MAX_TRACK_DEPTH) { break_track_marks(); return; } - TPlane surf_plane = Course.GetLocalCoursePlane (ctrl->cpos); - double dist_from_surface = DistanceToPlane (surf_plane, ctrl->cpos); + TPlane surf_plane = Course.GetLocalCoursePlane(ctrl->cpos); + double dist_from_surface = DistanceToPlane(surf_plane, ctrl->cpos); // comp_depth = get_compression_depth(Snow); double comp_depth = 0.1; if (dist_from_surface >= (2 * comp_depth)) { @@ -259,12 +259,12 @@ void add_track_mark(const CControl *ctrl, int *id) { if (!continuing_track) { q->track_type = TRACK_HEAD; - q->v1 = TVector3d (left_wing.x, left_y + TRACK_HEIGHT, left_wing.z); - q->v2 = TVector3d (right_wing.x, right_y + TRACK_HEIGHT, right_wing.z); - q->v3 = TVector3d (left_wing.x, left_y + TRACK_HEIGHT, left_wing.z); - q->v4 = TVector3d (right_wing.x, right_y + TRACK_HEIGHT, right_wing.z); - q->n1 = Course.FindCourseNormal (q->v1.x, q->v1.z); - q->n2 = Course.FindCourseNormal (q->v2.x, q->v2.z); + q->v1 = TVector3d(left_wing.x, left_y + TRACK_HEIGHT, left_wing.z); + q->v2 = TVector3d(right_wing.x, right_y + TRACK_HEIGHT, right_wing.z); + q->v3 = TVector3d(left_wing.x, left_y + TRACK_HEIGHT, left_wing.z); + q->v4 = TVector3d(right_wing.x, right_y + TRACK_HEIGHT, right_wing.z); + q->n1 = Course.FindCourseNormal(q->v1.x, q->v1.z); + q->n2 = Course.FindCourseNormal(q->v2.x, q->v2.z); q->t1 = TVector2d(0.0, 0.0); q->t2 = TVector2d(1.0, 0.0); } else { @@ -278,20 +278,20 @@ void add_track_mark(const CControl *ctrl, int *id) { q->t2 = qprev->t4; if (qprev->track_type == TRACK_TAIL) qprev->track_type = TRACK_MARK; } - q->v3 = TVector3d (left_wing.x, left_y + TRACK_HEIGHT, left_wing.z); - q->v4 = TVector3d (right_wing.x, right_y + TRACK_HEIGHT, right_wing.z); - q->n3 = Course.FindCourseNormal (q->v3.x, q->v3.z); - q->n4 = Course.FindCourseNormal (q->v4.x, q->v4.z); + q->v3 = TVector3d(left_wing.x, left_y + TRACK_HEIGHT, left_wing.z); + q->v4 = TVector3d(right_wing.x, right_y + TRACK_HEIGHT, right_wing.z); + q->n3 = Course.FindCourseNormal(q->v3.x, q->v3.z); + q->n4 = Course.FindCourseNormal(q->v4.x, q->v4.z); double tex_end = speed*g_game.time_step/TRACK_WIDTH; if (q->track_type == TRACK_HEAD) { - q->t3= TVector2d (0.0, 1.0); - q->t4= TVector2d (1.0, 1.0); + q->t3= TVector2d(0.0, 1.0); + q->t4= TVector2d(1.0, 1.0); } else { - q->t3 = TVector2d (0.0, q->t1.y + tex_end); - q->t4 = TVector2d (1.0, q->t2.y + tex_end); + q->t3 = TVector2d(0.0, q->t1.y + tex_end); + q->t4 = TVector2d(1.0, q->t2.y + tex_end); } } - q->alpha = min ((2*comp_depth-dist_from_surface)/(4*comp_depth), 1.0); + q->alpha = min((2*comp_depth-dist_from_surface)/(4*comp_depth), 1.0); continuing_track = true; } @@ -302,10 +302,10 @@ void UpdateTrackmarks(const CControl *ctrl) { int trackid; TTerrType *TerrList = &Course.TerrList[0]; - add_track_mark (ctrl, &trackid); + add_track_mark(ctrl, &trackid); if (trackid >= 0 && TerrList[trackid].trackmarks) { - SetTrackIDs (TerrList[trackid].starttex, - TerrList[trackid].tracktex, - TerrList[trackid].stoptex); + SetTrackIDs(TerrList[trackid].starttex, + TerrList[trackid].tracktex, + TerrList[trackid].stoptex); } } diff --git a/src/translation.cpp b/src/translation.cpp index c930737..94f4221 100644 --- a/src/translation.cpp +++ b/src/translation.cpp @@ -26,7 +26,7 @@ CTranslation Trans; // if anything is wrong with an translation, the program will fall back // to these defaults (only the wrong items) -void CTranslation::SetDefaultTranslations () { +void CTranslation::SetDefaultTranslations() { texts[0] = "Press any key to start"; texts[1] = "Enter an event"; texts[2] = "Practice"; @@ -125,20 +125,25 @@ void CTranslation::SetDefaultTranslations () { texts[83] = "Randomize settings"; - texts[84] = "Fullscreen setting has changed,"; - texts[85] = "You need to restart the game"; + texts[84] = "Score"; + texts[85] = "Herring"; + texts[86] = "Time"; + texts[87] = "Path length"; + texts[88] = "Average speed"; + texts[89] = "Position"; + texts[90] = "in highscore list"; } -const string& CTranslation::Text (size_t idx) const { +const string& CTranslation::Text(size_t idx) const { if (idx >= NUM_COMMON_TEXTS) return emptyString; return texts[idx]; } -void CTranslation::LoadLanguages () { - CSPList list (MAX_LANGUAGES); +void CTranslation::LoadLanguages() { + CSPList list(MAX_LANGUAGES); - if (!list.Load (param.trans_dir, "languages.lst")) { - Message ("could not load language list"); + if (!list.Load(param.trans_dir, "languages.lst")) { + Message("could not load language list"); return; } @@ -147,44 +152,35 @@ void CTranslation::LoadLanguages () { languages[0].language = "English"; for (size_t i=1; i= languages.size()) return errorString; return languages[idx].language; } -const string& CTranslation::GetLanguage (const string& lang) const { - return GetLanguage (GetLangIdx (lang)); -} - -void CTranslation::LoadTranslations (size_t langidx) { - SetDefaultTranslations (); +void CTranslation::LoadTranslations(size_t langidx) { + SetDefaultTranslations(); if (langidx == 0 || langidx >= languages.size()) return; CSPList list(MAX_COMMON_TEXT_LINES); string filename = languages[langidx].lang + ".lst"; - if (!list.Load (param.trans_dir, filename)) { - Message ("could not load translations list:", filename); + if (!list.Load(param.trans_dir, filename)) { + Message("could not load translations list:", filename); return; } for (size_t i=0; i= 0 && idx < NUM_COMMON_TEXTS) { - texts[idx] = SPStrN (line, "trans", texts[idx]); + texts[idx] = SPStrN(line, "trans", texts[idx]); } } } @@ -205,9 +201,13 @@ string CTranslation::GetSystemDefaultLang() { } size_t CTranslation::GetSystemDefaultLangIdx() const { - try { - return GetLangIdx(GetSystemDefaultLang()); - } catch (...) { - return 0; - } + std::string name = GetSystemDefaultLang(); + return GetLangIdx(name); +} + +size_t CTranslation::GetLangIdx(const string& lang) const { + for (size_t i = 0; i < languages.size(); i++) + if (languages[i].lang == lang) + return i; + return 0; } diff --git a/src/translation.h b/src/translation.h index ec14dac..dff1533 100644 --- a/src/translation.h +++ b/src/translation.h @@ -24,11 +24,10 @@ An name convention: #define TRANSLATION_H #include "bh.h" -#include #include #define MAX_LANGUAGES 32 -#define NUM_COMMON_TEXTS 86 +#define NUM_COMMON_TEXTS 93 #define MAX_COMMON_TEXT_LINES NUM_COMMON_TEXTS*2 @@ -40,19 +39,17 @@ struct TLang { class CTranslation { private: string texts[NUM_COMMON_TEXTS]; - map LangIndex; public: vector languages; - void LoadLanguages (); - size_t GetLangIdx (const string& lang) const; - const string& GetLanguage (size_t idx) const; - const string& GetLanguage (const string& lang) const; - void SetDefaultTranslations (); - const string& Text (size_t idx) const; - void LoadTranslations (size_t langidx); + void LoadLanguages(); + const string& GetLanguage(size_t idx) const; + void SetDefaultTranslations(); + const string& Text(size_t idx) const; + void LoadTranslations(size_t langidx); static string GetSystemDefaultLang(); size_t GetSystemDefaultLangIdx() const; + size_t GetLangIdx(const string& lang) const; }; extern CTranslation Trans; diff --git a/src/tux.cpp b/src/tux.cpp index 255a0fc..f4d5359 100644 --- a/src/tux.cpp +++ b/src/tux.cpp @@ -52,7 +52,7 @@ static const TCharMaterial TuxDefMat = {TColor(0.5, 0.5, 0.5, 1.0), TColor(0.0, static const TCharMaterial Highlight = {TColor(0.8, 0.15, 0.15, 1.0), TColor(0.0, 0.0, 0.0, 1.0), 0.0}; CCharShape TestChar; -CCharShape::CCharShape () { +CCharShape::CCharShape() { for (int i=0; i= MAX_CHAR_NODES) return -1; return Index[node_name]; } -TCharNode *CCharShape::GetNode (size_t node_name) { - size_t idx = GetNodeIdx (node_name); +TCharNode *CCharShape::GetNode(size_t node_name) { + size_t idx = GetNodeIdx(node_name); if (idx >= numNodes) return NULL; return Nodes[idx]; } -void CCharShape::CreateRootNode () { +void CCharShape::CreateRootNode() { TCharNode *node = new TCharNode; node->node_name = 0; node->parent = NULL; @@ -116,9 +116,9 @@ void CCharShape::CreateRootNode () { } bool CCharShape::CreateCharNode(int parent_name, size_t node_name, const string& joint, const string& name, const string& order, bool shadow) { - TCharNode *parent = GetNode (parent_name); + TCharNode *parent = GetNode(parent_name); if (parent == NULL) { - Message ("wrong parent node"); + Message("wrong parent node"); return false; } TCharNode *node = new TCharNode; @@ -167,8 +167,8 @@ bool CCharShape::CreateCharNode(int parent_name, size_t node_name, const string& return true; } -void CCharShape::AddAction (size_t node_name, int type, const TVector3d& vec, double val) { - size_t idx = GetNodeIdx (node_name); +void CCharShape::AddAction(size_t node_name, int type, const TVector3d& vec, double val) { + size_t idx = GetNodeIdx(node_name); TCharAction *act = Nodes[idx]->action; act->type[act->num] = type; act->vec[act->num] = vec; @@ -176,8 +176,8 @@ void CCharShape::AddAction (size_t node_name, int type, const TVector3d& vec, do act->num++; } -bool CCharShape::TranslateNode (size_t node_name, const TVector3d& vec) { - TCharNode *node = GetNode (node_name); +bool CCharShape::TranslateNode(size_t node_name, const TVector3d& vec) { + TCharNode *node = GetNode(node_name); if (node == NULL) return false; TMatrix<4, 4> TransMatrix; @@ -187,12 +187,12 @@ bool CCharShape::TranslateNode (size_t node_name, const TVector3d& vec) { TransMatrix.SetTranslationMatrix(-vec.x, -vec.y, -vec.z); node->invtrans = TransMatrix * node->invtrans; - if (newActions && useActions) AddAction (node_name, 0, vec, 0); + if (newActions && useActions) AddAction(node_name, 0, vec, 0); return true; } -bool CCharShape::RotateNode (size_t node_name, int axis, double angle) { - TCharNode *node = GetNode (node_name); +bool CCharShape::RotateNode(size_t node_name, int axis, double angle) { + TCharNode *node = GetNode(node_name); if (node == NULL) return false; if (axis > 3) return false; @@ -216,17 +216,17 @@ bool CCharShape::RotateNode (size_t node_name, int axis, double angle) { rotMatrix.SetRotationMatrix(-angle, caxis); node->invtrans = rotMatrix * node->invtrans; - if (newActions && useActions) AddAction (node_name, axis, NullVec3, angle); + if (newActions && useActions) AddAction(node_name, axis, NullVec3, angle); return true; } -bool CCharShape::RotateNode (const string& node_trivialname, int axis, double angle) { +bool CCharShape::RotateNode(const string& node_trivialname, int axis, double angle) { map::const_iterator i = NodeIndex.find(node_trivialname); if (i == NodeIndex.end()) return false; - return RotateNode (i->second, axis, angle); + return RotateNode(i->second, axis, angle); } -void CCharShape::ScaleNode (size_t node_name, const TVector3d& vec) { +void CCharShape::ScaleNode(size_t node_name, const TVector3d& vec) { TCharNode *node = GetNode(node_name); if (node == NULL) return; @@ -237,10 +237,10 @@ void CCharShape::ScaleNode (size_t node_name, const TVector3d& vec) { matrix.SetScalingMatrix(1.0 / vec.x, 1.0 / vec.y, 1.0 / vec.z); node->invtrans = matrix * node->invtrans; - if (newActions && useActions) AddAction (node_name, 4, vec, 0); + if (newActions && useActions) AddAction(node_name, 4, vec, 0); } -bool CCharShape::VisibleNode (size_t node_name, float level) { +bool CCharShape::VisibleNode(size_t node_name, float level) { TCharNode *node = GetNode(node_name); if (node == NULL) return false; @@ -248,14 +248,14 @@ bool CCharShape::VisibleNode (size_t node_name, float level) { if (node->visible) { node->divisions = - clamp (MIN_SPHERE_DIV, ROUND_TO_NEAREST (param.tux_sphere_divisions * level / 10), MAX_SPHERE_DIV); + clamp(MIN_SPHERE_DIV, ROUND_TO_NEAREST(param.tux_sphere_divisions * level / 10), MAX_SPHERE_DIV); node->radius = 1.0; } - if (newActions && useActions) AddAction (node_name, 5, NullVec3, level); + if (newActions && useActions) AddAction(node_name, 5, NullVec3, level); return true; } -bool CCharShape::MaterialNode (size_t node_name, const string& mat_name) { +bool CCharShape::MaterialNode(size_t node_name, const string& mat_name) { TCharNode *node = GetNode(node_name); if (node == NULL) return false; TCharMaterial *mat = GetMaterial(mat_name); @@ -265,7 +265,7 @@ bool CCharShape::MaterialNode (size_t node_name, const string& mat_name) { return true; } -bool CCharShape::ResetNode (size_t node_name) { +bool CCharShape::ResetNode(size_t node_name) { TCharNode *node = GetNode(node_name); if (node == NULL) return false; @@ -274,10 +274,10 @@ bool CCharShape::ResetNode (size_t node_name) { return true; } -bool CCharShape::ResetNode (const string& node_trivialname) { +bool CCharShape::ResetNode(const string& node_trivialname) { map::const_iterator i = NodeIndex.find(node_trivialname); if (i == NodeIndex.end()) return false; - return ResetNode (i->second); + return ResetNode(i->second); } bool CCharShape::TransformNode(size_t node_name, const TMatrix<4, 4>& mat, const TMatrix<4, 4>& invmat) { @@ -289,21 +289,21 @@ bool CCharShape::TransformNode(size_t node_name, const TMatrix<4, 4>& mat, const return true; } -void CCharShape::ResetJoints () { - ResetNode ("left_shldr"); - ResetNode ("right_shldr"); - ResetNode ("left_hip"); - ResetNode ("right_hip"); - ResetNode ("left_knee"); - ResetNode ("right_knee"); - ResetNode ("left_ankle"); - ResetNode ("right_ankle"); - ResetNode ("tail"); - ResetNode ("neck"); - ResetNode ("head"); +void CCharShape::ResetJoints() { + ResetNode("left_shldr"); + ResetNode("right_shldr"); + ResetNode("left_hip"); + ResetNode("right_hip"); + ResetNode("left_knee"); + ResetNode("right_knee"); + ResetNode("left_ankle"); + ResetNode("right_ankle"); + ResetNode("tail"); + ResetNode("neck"); + ResetNode("head"); } -void CCharShape::Reset () { +void CCharShape::Reset() { for (int i=0; iaction; @@ -329,7 +329,7 @@ void CCharShape::Reset () { // materials // -------------------------------------------------------------------- -TCharMaterial* CCharShape::GetMaterial (const string& mat_name) { +TCharMaterial* CCharShape::GetMaterial(const string& mat_name) { map::const_iterator i = MaterialIndex.find(mat_name); if (i != MaterialIndex.end() && i->second < Materials.size()) { return &Materials[i->second]; @@ -337,10 +337,10 @@ TCharMaterial* CCharShape::GetMaterial (const string& mat_name) { return NULL; } -void CCharShape::CreateMaterial (const string& line) { +void CCharShape::CreateMaterial(const string& line) { TVector3d diff = SPVector3d(line, "diff"); TVector3d spec = SPVector3d(line, "spec"); - float exp = SPFloatN (line, "exp", 50); + float exp = SPFloatN(line, "exp", 50); std::string mat = SPStrN(line, "mat"); Materials.push_back(TCharMaterial()); @@ -363,16 +363,16 @@ void CCharShape::CreateMaterial (const string& line) { // drawing // -------------------------------------------------------------------- -void CCharShape::DrawCharSphere (int num_divisions) { +void CCharShape::DrawCharSphere(int num_divisions) { GLUquadricObj *qobj = gluNewQuadric(); - gluQuadricDrawStyle (qobj, GLU_FILL); - gluQuadricOrientation (qobj, GLU_OUTSIDE); - gluQuadricNormals (qobj, GLU_SMOOTH); - gluSphere (qobj, 1.0, (GLint)2.0 * num_divisions, num_divisions); - gluDeleteQuadric (qobj); + gluQuadricDrawStyle(qobj, GLU_FILL); + gluQuadricOrientation(qobj, GLU_OUTSIDE); + gluQuadricNormals(qobj, GLU_SMOOTH); + gluSphere(qobj, 1.0, (GLint)2.0 * num_divisions, num_divisions); + gluDeleteQuadric(qobj); } -void CCharShape::DrawNodes (const TCharNode *node) { +void CCharShape::DrawNodes(const TCharNode *node) { glPushMatrix(); glMultMatrix(node->trans); @@ -386,14 +386,14 @@ void CCharShape::DrawNodes (const TCharNode *node) { } if (node->visible == true) { - set_material (mat->diffuse, mat->specular, mat->exp); + set_material(mat->diffuse, mat->specular, mat->exp); - DrawCharSphere (node->divisions); + DrawCharSphere(node->divisions); } // -------------- recursive loop ------------------------------------- TCharNode *child = node->child; while (child != NULL) { - DrawNodes (child); + DrawNodes(child); if (child->node_name == highlight_node) highlighted = false; child = child->next; } @@ -401,80 +401,80 @@ void CCharShape::DrawNodes (const TCharNode *node) { glPopMatrix(); } -void CCharShape::Draw () { +void CCharShape::Draw() { static const float dummy_color[] = {0.0, 0.0, 0.0, 1.0}; - glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dummy_color); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dummy_color); ScopedRenderMode rm(TUX); - glEnable (GL_NORMALIZE); + glEnable(GL_NORMALIZE); TCharNode *node = GetNode(0); if (node == NULL) return; - DrawNodes (node); - glDisable (GL_NORMALIZE); - if (param.perf_level > 2 && g_game.argument == 0) DrawShadow (); + DrawNodes(node); + glDisable(GL_NORMALIZE); + if (param.perf_level > 2 && g_game.argument == 0) DrawShadow(); highlighted = false; } // -------------------------------------------------------------------- -bool CCharShape::Load (const string& dir, const string& filename, bool with_actions) { - CSPList list (500); +bool CCharShape::Load(const string& dir, const string& filename, bool with_actions) { + CSPList list(500); useActions = with_actions; - CreateRootNode (); + CreateRootNode(); newActions = true; - if (!list.Load (dir, filename)) { - Message ("could not load character", filename); + if (!list.Load(dir, filename)) { + Message("could not load character", filename); return false; } for (size_t i=0; i 0) { - CreateMaterial (line); + if (SPIntN(line, "material", 0) > 0) { + CreateMaterial(line); } else { - float visible = SPFloatN (line, "vis", -1.0); - bool shadow = SPBoolN (line, "shad", false); - string order = SPStrN (line, "order"); - CreateCharNode (parent_name, node_name, name, fullname, order, shadow); + float visible = SPFloatN(line, "vis", -1.0); + bool shadow = SPBoolN(line, "shad", false); + string order = SPStrN(line, "order"); + CreateCharNode(parent_name, node_name, name, fullname, order, shadow); TVector3d rot = SPVector3d(line, "rot"); - MaterialNode (node_name, mat_name); + MaterialNode(node_name, mat_name); for (size_t ii = 0; ii < order.size(); ii++) { int act = order[ii]-48; switch (act) { case 0: { TVector3d trans = SPVector3d(line, "trans"); - TranslateNode (node_name, trans); + TranslateNode(node_name, trans); break; } case 1: - RotateNode (node_name, 1, rot.x); + RotateNode(node_name, 1, rot.x); break; case 2: - RotateNode (node_name, 2, rot.y); + RotateNode(node_name, 2, rot.y); break; case 3: - RotateNode (node_name, 3, rot.z); + RotateNode(node_name, 3, rot.z); break; case 4: { TVector3d scale = SPVector3(line, "scale", TVector3d(1, 1, 1)); - ScaleNode (node_name, scale); + ScaleNode(node_name, scale); break; } case 5: - VisibleNode (node_name, visible); + VisibleNode(node_name, visible); break; case 9: - RotateNode (node_name, 2, rot.z); + RotateNode(node_name, 2, rot.z); break; default: break; @@ -486,20 +486,20 @@ bool CCharShape::Load (const string& dir, const string& filename, bool with_acti return true; } -TVector3d CCharShape::AdjustRollvector (const CControl *ctrl, const TVector3d& vel_, const TVector3d& zvec) { +TVector3d CCharShape::AdjustRollvector(const CControl *ctrl, const TVector3d& vel_, const TVector3d& zvec) { TMatrix<4, 4> rot_mat; TVector3d vel = ProjectToPlane(zvec, vel_); vel.Norm(); if (ctrl->is_braking) { - rot_mat = RotateAboutVectorMatrix (vel, ctrl->turn_fact * BRAKING_ROLL_ANGLE); + rot_mat = RotateAboutVectorMatrix(vel, ctrl->turn_fact * BRAKING_ROLL_ANGLE); } else { - rot_mat = RotateAboutVectorMatrix (vel, ctrl->turn_fact * MAX_ROLL_ANGLE); + rot_mat = RotateAboutVectorMatrix(vel, ctrl->turn_fact * MAX_ROLL_ANGLE); } - return TransformVector (rot_mat, zvec); + return TransformVector(rot_mat, zvec); } -void CCharShape::AdjustOrientation (CControl *ctrl, double dtime, - double dist_from_surface, const TVector3d& surf_nml) { +void CCharShape::AdjustOrientation(CControl *ctrl, double dtime, + double dist_from_surface, const TVector3d& surf_nml) { TVector3d new_y, new_z; static const TVector3d minus_z_vec(0, 0, -1); static const TVector3d y_vec(0, 1, 0); @@ -507,19 +507,19 @@ void CCharShape::AdjustOrientation (CControl *ctrl, double dtime, if (dist_from_surface > 0) { new_y = ctrl->cvel; new_y.Norm(); - new_z = ProjectToPlane (new_y, TVector3d(0, -1, 0)); + new_z = ProjectToPlane(new_y, TVector3d(0, -1, 0)); new_z.Norm(); - new_z = AdjustRollvector (ctrl, ctrl->cvel, new_z); + new_z = AdjustRollvector(ctrl, ctrl->cvel, new_z); } else { new_z = -1.0 * surf_nml; - new_z = AdjustRollvector (ctrl, ctrl->cvel, new_z); - new_y = ProjectToPlane (surf_nml, ctrl->cvel); + new_z = AdjustRollvector(ctrl, ctrl->cvel, new_z); + new_y = ProjectToPlane(surf_nml, ctrl->cvel); new_y.Norm(); } - TVector3d new_x = CrossProduct (new_y, new_z); + TVector3d new_x = CrossProduct(new_y, new_z); TMatrix<4, 4> cob_mat(new_x, new_y, new_z); - TQuaternion new_orient = MakeQuaternionFromMatrix (cob_mat); + TQuaternion new_orient = MakeQuaternionFromMatrix(cob_mat); if (!ctrl->orientation_initialized) { ctrl->orientation_initialized = true; @@ -528,28 +528,28 @@ void CCharShape::AdjustOrientation (CControl *ctrl, double dtime, double time_constant = dist_from_surface > 0 ? TO_AIR_TIME : TO_TIME; - ctrl->corientation = InterpolateQuaternions ( + ctrl->corientation = InterpolateQuaternions( ctrl->corientation, new_orient, - min (dtime / time_constant, 1.0)); + min(dtime / time_constant, 1.0)); - ctrl->plane_nml = RotateVector (ctrl->corientation, minus_z_vec); - ctrl->cdirection = RotateVector (ctrl->corientation, y_vec); + ctrl->plane_nml = RotateVector(ctrl->corientation, minus_z_vec); + ctrl->cdirection = RotateVector(ctrl->corientation, y_vec); cob_mat = MakeMatrixFromQuaternion(ctrl->corientation); // Trick rotations - new_y = TVector3d (cob_mat[1][0], cob_mat[1][1], cob_mat[1][2]); + new_y = TVector3d(cob_mat[1][0], cob_mat[1][1], cob_mat[1][2]); TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(new_y, (ctrl->roll_factor * 360)); cob_mat = rot_mat * cob_mat; - new_x = TVector3d (cob_mat[0][0], cob_mat[0][1], cob_mat[0][2]); - rot_mat = RotateAboutVectorMatrix (new_x, ctrl->flip_factor * 360); + new_x = TVector3d(cob_mat[0][0], cob_mat[0][1], cob_mat[0][2]); + rot_mat = RotateAboutVectorMatrix(new_x, ctrl->flip_factor * 360); cob_mat = rot_mat * cob_mat; - TransformNode (0, cob_mat, cob_mat.GetTransposed()); + TransformNode(0, cob_mat, cob_mat.GetTransposed()); } -void CCharShape::AdjustJoints (double turnFact, bool isBraking, - double paddling_factor, double speed, - const TVector3d& net_force, double flap_factor) { +void CCharShape::AdjustJoints(double turnFact, bool isBraking, + double paddling_factor, double speed, + const TVector3d& net_force, double flap_factor) { double turning_angle[2]; double paddling_angle = 0; double ext_paddling_angle = 0; @@ -567,33 +567,33 @@ void CCharShape::AdjustJoints (double turnFact, bool isBraking, turning_angle[0] = max(-turnFact,0.0) * MAX_ARM_ANGLE2; turning_angle[1] = max(turnFact,0.0) * MAX_ARM_ANGLE2; - flap_angle = MAX_ARM_ANGLE2 * (0.5 + 0.5 * sin (M_PI * flap_factor * 6 - M_PI / 2)); - force_angle = clamp (-20.0, -net_force.z / 300.0, 20.0); + flap_angle = MAX_ARM_ANGLE2 * (0.5 + 0.5 * sin(M_PI * flap_factor * 6 - M_PI / 2)); + force_angle = clamp(-20.0, -net_force.z / 300.0, 20.0); turn_leg_angle = turnFact * 10; - ResetJoints (); + ResetJoints(); - RotateNode ("left_shldr", 3, - min (braking_angle + paddling_angle + turning_angle[0], MAX_ARM_ANGLE2) + flap_angle); - RotateNode ("right_shldr", 3, - min (braking_angle + paddling_angle + turning_angle[1], MAX_ARM_ANGLE2) + flap_angle); + RotateNode("left_shldr", 3, + min(braking_angle + paddling_angle + turning_angle[0], MAX_ARM_ANGLE2) + flap_angle); + RotateNode("right_shldr", 3, + min(braking_angle + paddling_angle + turning_angle[1], MAX_ARM_ANGLE2) + flap_angle); - RotateNode ("left_shldr", 2, -ext_paddling_angle); - RotateNode ("right_shldr", 2, ext_paddling_angle); - RotateNode ("left_hip", 3, -20 + turn_leg_angle + force_angle); - RotateNode ("right_hip", 3, -20 - turn_leg_angle + force_angle); + RotateNode("left_shldr", 2, -ext_paddling_angle); + RotateNode("right_shldr", 2, ext_paddling_angle); + RotateNode("left_hip", 3, -20 + turn_leg_angle + force_angle); + RotateNode("right_hip", 3, -20 - turn_leg_angle + force_angle); - RotateNode ("left_knee", 3, - -10 + turn_leg_angle - min (35.0, speed) + kick_paddling_angle + force_angle); - RotateNode ("right_knee", 3, - -10 - turn_leg_angle - min (35.0, speed) - kick_paddling_angle + force_angle); + RotateNode("left_knee", 3, + -10 + turn_leg_angle - min(35.0, speed) + kick_paddling_angle + force_angle); + RotateNode("right_knee", 3, + -10 - turn_leg_angle - min(35.0, speed) - kick_paddling_angle + force_angle); - RotateNode ("left_ankle", 3, -20 + min (50.0, speed)); - RotateNode ("right_ankle", 3, -20 + min (50.0, speed)); - RotateNode ("tail", 3, turnFact * 20); - RotateNode ("neck", 3, -50); - RotateNode ("head", 3, -30); - RotateNode ("head", 2, -turnFact * 70); + RotateNode("left_ankle", 3, -20 + min(50.0, speed)); + RotateNode("right_ankle", 3, -20 + min(50.0, speed)); + RotateNode("tail", 3, turnFact * 20); + RotateNode("neck", 3, -50); + RotateNode("head", 3, -30); + RotateNode("head", 2, -turnFact * 70); } // -------------------------------------------------------------------- @@ -609,31 +609,31 @@ bool CCharShape::CheckPolyhedronCollision(const TCharNode *node, const TMatrix<4 if (node->visible) { TPolyhedron newph = ph; - TransPolyhedron (newInvModelMatrix, newph); - hit = IntersectPolyhedron (newph); + TransPolyhedron(newInvModelMatrix, newph); + hit = IntersectPolyhedron(newph); } if (hit == true) return hit; const TCharNode *child = node->child; while (child != NULL) { - hit = CheckPolyhedronCollision (child, newModelMatrix, newInvModelMatrix, ph); + hit = CheckPolyhedronCollision(child, newModelMatrix, newInvModelMatrix, ph); if (hit == true) return hit; child = child->next; } return false; } -bool CCharShape::CheckCollision (const TPolyhedron& ph) { +bool CCharShape::CheckCollision(const TPolyhedron& ph) { TCharNode *node = GetNode(0); if (node == NULL) return false; const TMatrix<4, 4>& identity = TMatrix<4, 4>::getIdentity(); return CheckPolyhedronCollision(node, identity, identity, ph); } -bool CCharShape::Collision (const TVector3d& pos, const TPolyhedron& ph) { - ResetNode (0); - TranslateNode (0, TVector3d (pos.x, pos.y, pos.z)); - return CheckCollision (ph); +bool CCharShape::Collision(const TVector3d& pos, const TPolyhedron& ph) { + ResetNode(0); + TranslateNode(0, TVector3d(pos.x, pos.y, pos.z)); + return CheckCollision(ph); } // -------------------------------------------------------------------- @@ -642,10 +642,10 @@ bool CCharShape::Collision (const TVector3d& pos, const TPolyhedron& ph) { void CCharShape::DrawShadowVertex(double x, double y, double z, const TMatrix<4, 4>& mat) { TVector3d pt(x, y, z); - pt = TransformPoint (mat, pt); + pt = TransformPoint(mat, pt); double old_y = pt.y; - TVector3d nml = Course.FindCourseNormal (pt.x, pt.z); - pt.y = Course.FindYCoord (pt.x, pt.z) + SHADOW_HEIGHT; + TVector3d nml = Course.FindCourseNormal(pt.x, pt.z); + pt.y = Course.FindYCoord(pt.x, pt.z) + SHADOW_HEIGHT; if (pt.y > old_y) pt.y = old_y; glNormal3(nml); glVertex3(pt); @@ -665,68 +665,68 @@ void CCharShape::DrawShadowSphere(const TMatrix<4, 4>& mat) { double sin_phi, cos_phi; double sin_phi_d_phi, cos_phi_d_phi; - sin_phi = sin (phi); - cos_phi = cos (phi); - sin_phi_d_phi = sin (phi + d_phi); - cos_phi_d_phi = cos (phi + d_phi); + sin_phi = sin(phi); + cos_phi = cos(phi); + sin_phi_d_phi = sin(phi + d_phi); + cos_phi_d_phi = cos(phi + d_phi); if (phi <= eps) { - glBegin (GL_TRIANGLE_FAN); - DrawShadowVertex (0., 0., 1., mat); + glBegin(GL_TRIANGLE_FAN); + DrawShadowVertex(0., 0., 1., mat); for (theta = 0.0; theta + eps < twopi; theta += d_theta) { - sin_theta = sin (theta); - cos_theta = cos (theta); + sin_theta = sin(theta); + cos_theta = cos(theta); x = cos_theta * sin_phi_d_phi; y = sin_theta * sin_phi_d_phi; z = cos_phi_d_phi; - DrawShadowVertex (x, y, z, mat); + DrawShadowVertex(x, y, z, mat); } x = sin_phi_d_phi; y = 0.0; z = cos_phi_d_phi; - DrawShadowVertex (x, y, z, mat); + DrawShadowVertex(x, y, z, mat); glEnd(); } else if (phi + d_phi + eps >= M_PI) { - glBegin (GL_TRIANGLE_FAN); - DrawShadowVertex (0., 0., -1., mat); + glBegin(GL_TRIANGLE_FAN); + DrawShadowVertex(0., 0., -1., mat); for (theta = twopi; theta - eps > 0; theta -= d_theta) { - sin_theta = sin (theta); - cos_theta = cos (theta); + sin_theta = sin(theta); + cos_theta = cos(theta); x = cos_theta * sin_phi; y = sin_theta * sin_phi; z = cos_phi; - DrawShadowVertex (x, y, z, mat); + DrawShadowVertex(x, y, z, mat); } x = sin_phi; y = 0.0; z = cos_phi; - DrawShadowVertex (x, y, z, mat); + DrawShadowVertex(x, y, z, mat); glEnd(); } else { - glBegin (GL_TRIANGLE_STRIP); + glBegin(GL_TRIANGLE_STRIP); for (theta = 0.0; theta + eps < twopi; theta += d_theta) { - sin_theta = sin (theta); - cos_theta = cos (theta); + sin_theta = sin(theta); + cos_theta = cos(theta); x = cos_theta * sin_phi; y = sin_theta * sin_phi; z = cos_phi; - DrawShadowVertex (x, y, z, mat); + DrawShadowVertex(x, y, z, mat); x = cos_theta * sin_phi_d_phi; y = sin_theta * sin_phi_d_phi; z = cos_phi_d_phi; - DrawShadowVertex (x, y, z, mat); + DrawShadowVertex(x, y, z, mat); } x = sin_phi; y = 0.0; z = cos_phi; - DrawShadowVertex (x, y, z, mat); + DrawShadowVertex(x, y, z, mat); x = sin_phi_d_phi; y = 0.0; z = cos_phi_d_phi; - DrawShadowVertex (x, y, z, mat); + DrawShadowVertex(x, y, z, mat); glEnd(); } } @@ -735,16 +735,16 @@ void CCharShape::DrawShadowSphere(const TMatrix<4, 4>& mat) { void CCharShape::TraverseDagForShadow(const TCharNode *node, const TMatrix<4, 4>& mat) { TMatrix<4, 4> new_matrix = mat * node->trans; if (node->visible && node->render_shadow) - DrawShadowSphere (new_matrix); + DrawShadowSphere(new_matrix); TCharNode* child = node->child; while (child != NULL) { - TraverseDagForShadow (child, new_matrix); + TraverseDagForShadow(child, new_matrix); child = child->next; } } -void CCharShape::DrawShadow () { +void CCharShape::DrawShadow() { if (g_game.light_id == 1 || g_game.light_id == 3) return; ScopedRenderMode rm(TUX_SHADOW); @@ -752,7 +752,7 @@ void CCharShape::DrawShadow () { TCharNode *node = GetNode(0); if (node == NULL) { - Message ("couldn't find tux's root node"); + Message("couldn't find tux's root node"); return; } TraverseDagForShadow(node, TMatrix<4, 4>::getIdentity()); @@ -762,25 +762,25 @@ void CCharShape::DrawShadow () { // testing and tools // -------------------------------------------------------------------- -string CCharShape::GetNodeJoint (size_t idx) const { +string CCharShape::GetNodeJoint(size_t idx) const { if (idx >= numNodes) return ""; TCharNode *node = Nodes[idx]; if (node == NULL) return ""; if (!node->joint.empty()) return node->joint; - else return Int_StrN ((int)node->node_name); + else return Int_StrN((int)node->node_name); } -size_t CCharShape::GetNodeName (size_t idx) const { +size_t CCharShape::GetNodeName(size_t idx) const { if (idx >= numNodes) return -1; return Nodes[idx]->node_name; } -size_t CCharShape::GetNodeName (const string& node_trivialname) const { +size_t CCharShape::GetNodeName(const string& node_trivialname) const { return NodeIndex.at(node_trivialname); } -void CCharShape::RefreshNode (size_t idx) { +void CCharShape::RefreshNode(size_t idx) { if (idx >= numNodes) return; TMatrix<4, 4> TempMatrix; char caxis; @@ -837,7 +837,7 @@ void CCharShape::RefreshNode (size_t idx) { node->invtrans = TempMatrix * node->invtrans; break; case 5: - VisibleNode (node->node_name, dval); + VisibleNode(node->node_name, dval); break; default: break; @@ -845,60 +845,60 @@ void CCharShape::RefreshNode (size_t idx) { } } -const string& CCharShape::GetNodeFullname (size_t idx) const { +const string& CCharShape::GetNodeFullname(size_t idx) const { if (idx >= numNodes) return emptyString; return Nodes[idx]->action->name; } -size_t CCharShape::GetNumActs (size_t idx) const { +size_t CCharShape::GetNumActs(size_t idx) const { if (idx >= numNodes) return -1; return Nodes[idx]->action->num; } -TCharAction *CCharShape::GetAction (size_t idx) const { +TCharAction *CCharShape::GetAction(size_t idx) const { if (idx >= numNodes) return NULL; return Nodes[idx]->action; } -void CCharShape::PrintAction (size_t idx) const { +void CCharShape::PrintAction(size_t idx) const { if (idx >= numNodes) return; TCharAction *act = Nodes[idx]->action; - PrintInt ((int)act->num); + PrintInt((int)act->num); for (size_t i=0; inum; i++) { - PrintInt (act->type[i]); - PrintDouble (act->dval[i]); - PrintVector (act->vec[i]); + PrintInt(act->type[i]); + PrintDouble(act->dval[i]); + PrintVector(act->vec[i]); } } -void CCharShape::PrintNode (size_t idx) const { +void CCharShape::PrintNode(size_t idx) const { TCharNode *node = Nodes[idx]; - PrintInt ("node: ", (int)node->node_name); - PrintInt ("parent: ", (int)node->parent_name); - PrintInt ("child: ", (int)node->child_name); - PrintInt ("next: ", (int)node->next_name); + PrintInt("node: ", (int)node->node_name); + PrintInt("parent: ", (int)node->parent_name); + PrintInt("child: ", (int)node->child_name); + PrintInt("next: ", (int)node->next_name); } -void CCharShape::SaveCharNodes (const string& dir, const string& filename) { - CSPList list (MAX_CHAR_NODES + 10); +void CCharShape::SaveCharNodes(const string& dir, const string& filename) { + CSPList list(MAX_CHAR_NODES + 10); - list.Add ("# Generated by Tuxracer tools"); - list.AddLine (); + list.Add("# Generated by Tuxracer tools"); + list.AddLine(); if (!Materials.empty()) { - list.Add ("# Materials:"); + list.Add("# Materials:"); for (size_t i=0; iaction; - if (node->parent_name >= node->node_name) Message ("wrong parent index"); - string line = "*[node] " + Int_StrN ((int)node->node_name); - line += " [par] " + Int_StrN ((int)node->parent_name); + if (node->parent_name >= node->node_name) Message("wrong parent index"); + string line = "*[node] " + Int_StrN((int)node->node_name); + line += " [par] " + Int_StrN((int)node->parent_name); if (!act->order.empty()) { bool rotflag = false; @@ -908,10 +908,10 @@ void CCharShape::SaveCharNodes (const string& dir, const string& filename) { int aa = act->order[ii]-48; switch (aa) { case 0: - line += " [trans] " + Vector_StrN (act->vec[ii], 2); + line += " [trans] " + Vector_StrN(act->vec[ii], 2); break; case 4: - line += " [scale] " + Vector_StrN (act->vec[ii], 2); + line += " [scale] " + Vector_StrN(act->vec[ii], 2); break; case 1: rotation.x = act->dval[ii]; @@ -926,7 +926,7 @@ void CCharShape::SaveCharNodes (const string& dir, const string& filename) { rotflag = true; break; case 5: - line += " [vis] " + Float_StrN (act->dval[ii], 0); + line += " [vis] " + Float_StrN(act->dval[ii], 0); break; case 9: rotation.z = act->dval[ii]; @@ -934,19 +934,19 @@ void CCharShape::SaveCharNodes (const string& dir, const string& filename) { break; } } - if (rotflag) line += " [rot] " + Vector_StrN (rotation, 2); + if (rotflag) line += " [rot] " + Vector_StrN(rotation, 2); } if (!act->mat.empty()) line += " [mat] " + act->mat; if (!node->joint.empty()) line += " [joint] " + node->joint; if (!act->name.empty()) line += " [name] " + act->name; if (node->render_shadow) line += " [shad] 1"; - list.Add (line); + list.Add(line); if (ivisible && !Nodes[i+1]->visible) list.AddLine (); + if (node->visible && !Nodes[i+1]->visible) list.AddLine(); const string& joint = Nodes[i+2]->joint; - if (joint.empty()) list.Add ("# " + joint); + if (joint.empty()) list.Add("# " + joint); } } - list.Save (dir, filename); + list.Save(dir, filename); } diff --git a/src/tux.h b/src/tux.h index 8dba779..3e99478 100644 --- a/src/tux.h +++ b/src/tux.h @@ -81,29 +81,29 @@ private: map MaterialIndex; // nodes - size_t GetNodeIdx (size_t node_name) const; - TCharNode *GetNode (size_t node_name); - void CreateRootNode (); + size_t GetNodeIdx(size_t node_name) const; + TCharNode *GetNode(size_t node_name); + void CreateRootNode(); bool CreateCharNode (int parent_name, size_t node_name, const string& joint, const string& name, const string& order, bool shadow); - bool VisibleNode (size_t node_name, float level); - bool MaterialNode (size_t node_name, const string& mat_name); + bool VisibleNode(size_t node_name, float level); + bool MaterialNode(size_t node_name, const string& mat_name); bool TransformNode(size_t node_name, const TMatrix<4, 4>& mat, const TMatrix<4, 4>& invmat); // material - TCharMaterial* GetMaterial (const string& mat_name); - void CreateMaterial (const string& line); + TCharMaterial* GetMaterial(const string& mat_name); + void CreateMaterial(const string& line); // drawing - void DrawCharSphere (int num_divisions); - void DrawNodes (const TCharNode *node); - TVector3d AdjustRollvector (const CControl *ctrl, const TVector3d& vel, const TVector3d& zvec); + void DrawCharSphere(int num_divisions); + void DrawNodes(const TCharNode *node); + TVector3d AdjustRollvector(const CControl *ctrl, const TVector3d& vel, const TVector3d& zvec); // collision bool CheckPolyhedronCollision(const TCharNode *node, const TMatrix<4, 4>& modelMatrix, const TMatrix<4, 4>& invModelMatrix, const TPolyhedron& ph); - bool CheckCollision (const TPolyhedron& ph); + bool CheckCollision(const TPolyhedron& ph); // shadow void DrawShadowVertex(double x, double y, double z, const TMatrix<4, 4>& mat); @@ -111,52 +111,52 @@ private: void TraverseDagForShadow(const TCharNode *node, const TMatrix<4, 4>& mat); // testing and developing - void AddAction (size_t node_name, int type, const TVector3d& vec, double val); + void AddAction(size_t node_name, int type, const TVector3d& vec, double val); public: - CCharShape (); + CCharShape(); ~CCharShape(); bool useMaterials; bool useHighlighting; map NodeIndex; // nodes - bool ResetNode (size_t node_name); - bool ResetNode (const string& node_trivialname); - bool TranslateNode (size_t node_name, const TVector3d& vec); - bool RotateNode (size_t node_name, int axis, double angle); - bool RotateNode (const string& node_trivialname, int axis, double angle); - void ScaleNode (size_t node_name, const TVector3d& vec); - void ResetRoot () { ResetNode (0); } - void ResetJoints (); + bool ResetNode(size_t node_name); + bool ResetNode(const string& node_trivialname); + bool TranslateNode(size_t node_name, const TVector3d& vec); + bool RotateNode(size_t node_name, int axis, double angle); + bool RotateNode(const string& node_trivialname, int axis, double angle); + void ScaleNode(size_t node_name, const TVector3d& vec); + void ResetRoot() { ResetNode(0); } + void ResetJoints(); // global functions - void Reset (); - void Draw (); - void DrawShadow (); - bool Load (const string& dir, const string& filename, bool with_actions); + void Reset(); + void Draw(); + void DrawShadow(); + bool Load(const string& dir, const string& filename, bool with_actions); - void AdjustOrientation (CControl *ctrl, double dtime, - double dist_from_surface, const TVector3d& surf_nml); - void AdjustJoints (double turnFact, bool isBraking, - double paddling_factor, double speed, - const TVector3d& net_force, double flap_factor); - bool Collision (const TVector3d& pos, const TPolyhedron& ph); + void AdjustOrientation(CControl *ctrl, double dtime, + double dist_from_surface, const TVector3d& surf_nml); + void AdjustJoints(double turnFact, bool isBraking, + double paddling_factor, double speed, + const TVector3d& net_force, double flap_factor); + bool Collision(const TVector3d& pos, const TPolyhedron& ph); // testing and tools bool highlighted; size_t highlight_node; - size_t GetNodeName (size_t idx) const; - size_t GetNodeName (const string& node_trivialname) const; - string GetNodeJoint (size_t idx) const; - size_t GetNumNodes () const { return numNodes; } - const string& GetNodeFullname (size_t idx) const; - size_t GetNumActs (size_t idx) const; - TCharAction *GetAction (size_t idx) const; - void PrintAction (size_t idx) const; - void PrintNode (size_t idx) const; - void RefreshNode (size_t idx); - void SaveCharNodes (const string& dir, const string& filename); + size_t GetNodeName(size_t idx) const; + size_t GetNodeName(const string& node_trivialname) const; + string GetNodeJoint(size_t idx) const; + size_t GetNumNodes() const { return numNodes; } + const string& GetNodeFullname(size_t idx) const; + size_t GetNumActs(size_t idx) const; + TCharAction *GetAction(size_t idx) const; + void PrintAction(size_t idx) const; + void PrintNode(size_t idx) const; + void RefreshNode(size_t idx); + void SaveCharNodes(const string& dir, const string& filename); }; // only for char tools, the characters for playing are in diff --git a/src/vectors.h b/src/vectors.h index ed60096..64a8628 100644 --- a/src/vectors.h +++ b/src/vectors.h @@ -55,24 +55,24 @@ struct TVector3 : public TVector2 { : TVector2(_x, _y), z(_z) {} double Length() const { - return sqrt(static_cast(TVector2::x*TVector2::x + - TVector2::y*TVector2::y + z*z)); + return sqrt(static_cast(TVector2::x*TVector2::x + + TVector2::y*TVector2::y + z*z)); } double Norm(); TVector3& operator*=(T f) { - TVector2::x *= f; + TVector2::x *= f; TVector2::y *= f; z *= f; return *this; } TVector3& operator+=(const TVector3& v) { - TVector2::x += v.x; + TVector2::x += v.x; TVector2::y += v.y; z += v.z; return *this; } TVector3& operator-=(const TVector3& v) { - TVector2::x -= v.x; + TVector2::x -= v.x; TVector2::y -= v.y; z -= v.z; return *this; @@ -86,13 +86,13 @@ struct TVector4 : public TVector3 { : TVector3(_x, _y, _z), w(_w) {} double Length() const { - return sqrt(static_cast(TVector2::x*TVector2::x + - TVector2::y*TVector2::y + - TVector3::z*TVector3::z + w*w)); + return sqrt(static_cast(TVector2::x*TVector2::x + + TVector2::y*TVector2::y + + TVector3::z*TVector3::z + w*w)); } double Norm(); TVector4& operator*=(T f) { - TVector2::x *= f; + TVector2::x *= f; TVector2::y *= f; TVector3::z *= f; w *= f; diff --git a/src/view.cpp b/src/view.cpp index b9e57bc..8a1aaac 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -43,7 +43,7 @@ static TMatrix<4, 4> stationary_matrix; static bool is_stationary = false; static bool shall_stationary = false; -void SetStationaryCamera (bool stat) { +void SetStationaryCamera(bool stat) { if (stat == false) { is_stationary = false; shall_stationary = false; @@ -53,20 +53,20 @@ void SetStationaryCamera (bool stat) { } static double camera_distance = 4.0; -void IncCameraDistance (double timestep) { +void IncCameraDistance(double timestep) { camera_distance += timestep * CAMERA_DISTANCE_INCREMENT; } -void SetCameraDistance (double val) {camera_distance = val;} +void SetCameraDistance(double val) {camera_distance = val;} -void set_view_mode (CControl *ctrl, TViewMode mode) {ctrl->viewmode = mode;} +void set_view_mode(CControl *ctrl, TViewMode mode) {ctrl->viewmode = mode;} -TVector3d interpolate_view_pos (const TVector3d& ctrl_pos1, const TVector3d& ctrl_pos2, - double max_vec_angle, - const TVector3d& pos1, const TVector3d& pos2, - double dist, double dt, - double time_constant) { +TVector3d interpolate_view_pos(const TVector3d& ctrl_pos1, const TVector3d& ctrl_pos2, + double max_vec_angle, + const TVector3d& pos1, const TVector3d& pos2, + double dist, double dt, + double time_constant) { static TVector3d y_vec(0.0, 1.0, 0.0); TVector3d vec1 = pos1 - ctrl_pos1; @@ -75,43 +75,43 @@ TVector3d interpolate_view_pos (const TVector3d& ctrl_pos1, const TVector3d& ctr vec1.Norm(); vec2.Norm(); - TQuaternion q1 = MakeRotationQuaternion (y_vec, vec1); - TQuaternion q2 = MakeRotationQuaternion (y_vec, vec2); - double alpha = min (MAX_INTERPOLATION_VALUE, 1.0 - exp (-dt / time_constant)); - q2 = InterpolateQuaternions (q1, q2, alpha); + TQuaternion q1 = MakeRotationQuaternion(y_vec, vec1); + TQuaternion q2 = MakeRotationQuaternion(y_vec, vec2); + double alpha = min(MAX_INTERPOLATION_VALUE, 1.0 - exp(-dt / time_constant)); + q2 = InterpolateQuaternions(q1, q2, alpha); - vec2 = RotateVector (q2, y_vec); - double theta = RADIANS_TO_ANGLES (M_PI/2 - acos (DotProduct (vec2, y_vec))); + vec2 = RotateVector(q2, y_vec); + double theta = RADIANS_TO_ANGLES(M_PI/2 - acos(DotProduct(vec2, y_vec))); if (theta > max_vec_angle) { - TVector3d axis = CrossProduct (y_vec, vec2); + TVector3d axis = CrossProduct(y_vec, vec2); axis.Norm(); TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(axis, theta - max_vec_angle); - vec2 = TransformVector (rot_mat, vec2); + vec2 = TransformVector(rot_mat, vec2); } return ctrl_pos2 + dist * vec2; } -void interpolate_view_frame (const TVector3d& up1, const TVector3d& dir1, - TVector3d *p_up2, TVector3d *p_dir2, - double dt, double time_constant) { +void interpolate_view_frame(const TVector3d& up1, const TVector3d& dir1, + TVector3d *p_up2, TVector3d *p_dir2, + double dt, double time_constant) { TVector3d z1 = -1.0 * dir1; z1.Norm(); - TVector3d y1 = ProjectToPlane (z1, up1); + TVector3d y1 = ProjectToPlane(z1, up1); y1.Norm(); - TVector3d x1 = CrossProduct (y1, z1); + TVector3d x1 = CrossProduct(y1, z1); TMatrix<4, 4> cob_mat1(x1, y1, z1); - TQuaternion q1 = MakeQuaternionFromMatrix (cob_mat1); + TQuaternion q1 = MakeQuaternionFromMatrix(cob_mat1); TVector3d z2 = -1.0 * *p_dir2; z2.Norm(); - TVector3d y2 = ProjectToPlane (z2, *p_up2); + TVector3d y2 = ProjectToPlane(z2, *p_up2); y2.Norm(); - TVector3d x2 = CrossProduct (y2, z2); + TVector3d x2 = CrossProduct(y2, z2); TMatrix<4, 4> cob_mat2(x2, y2, z2); - TQuaternion q2 = MakeQuaternionFromMatrix (cob_mat2); - double alpha = min (MAX_INTERPOLATION_VALUE, 1.0 - exp (-dt / time_constant)); - q2 = InterpolateQuaternions (q1, q2, alpha); + TQuaternion q2 = MakeQuaternionFromMatrix(cob_mat2); + double alpha = min(MAX_INTERPOLATION_VALUE, 1.0 - exp(-dt / time_constant)); + q2 = InterpolateQuaternions(q1, q2, alpha); cob_mat2 = MakeMatrixFromQuaternion(q2); p_up2->x = cob_mat2[1][0]; @@ -123,10 +123,10 @@ void interpolate_view_frame (const TVector3d& up1, const TVector3d& dir1, p_dir2->z = -cob_mat2[2][2]; } -void setup_view_matrix (CControl *ctrl, bool save_mat) { +void setup_view_matrix(CControl *ctrl, bool save_mat) { TVector3d view_z = -1.0 * ctrl->viewdir; - TVector3d view_x = CrossProduct (ctrl->viewup, view_z); - TVector3d view_y = CrossProduct (view_z, view_x); + TVector3d view_x = CrossProduct(ctrl->viewup, view_z); + TVector3d view_y = CrossProduct(view_z, view_x); view_z.Norm(); view_x.Norm(); view_y.Norm(); @@ -143,7 +143,7 @@ void setup_view_matrix (CControl *ctrl, bool save_mat) { view_mat[1][3] = 0; view_mat[2][3] = 0; - TVector3d viewpt_in_view_frame = TransformPoint (view_mat, ctrl->viewpos); + TVector3d viewpt_in_view_frame = TransformPoint(view_mat, ctrl->viewpos); view_mat[3][0] = -viewpt_in_view_frame.x; view_mat[3][1] = -viewpt_in_view_frame.y; @@ -152,13 +152,12 @@ void setup_view_matrix (CControl *ctrl, bool save_mat) { if (save_mat) { stationary_matrix = view_mat; } - glLoadIdentity(); - glMultMatrix(view_mat); + glLoadMatrix(view_mat); } -TVector3d MakeViewVector () { +TVector3d MakeViewVector() { double course_angle = Course.GetCourseAngle(); - double rad = ANGLES_TO_RADIANS ( + double rad = ANGLES_TO_RADIANS( course_angle - CAMERA_ANGLE_ABOVE_SLOPE + PLAYER_ANGLE_IN_CAMERA); @@ -166,10 +165,9 @@ TVector3d MakeViewVector () { return camera_distance * res; } -void update_view (CControl *ctrl, double dt) { +void update_view(CControl *ctrl, double dt) { if (is_stationary) { - glLoadIdentity(); - glMultMatrix(stationary_matrix); + glLoadMatrix(stationary_matrix); return; } @@ -181,9 +179,9 @@ void update_view (CControl *ctrl, double dt) { double speed = ctrl->cvel.Length(); double time_constant_mult = 1.0 / - clamp (0.0, - (speed - NO_INTERPOLATION_SPEED) / (BASELINE_INTERPOLATION_SPEED - NO_INTERPOLATION_SPEED), - 1.0); + clamp(0.0, + (speed - NO_INTERPOLATION_SPEED) / (BASELINE_INTERPOLATION_SPEED - NO_INTERPOLATION_SPEED), + 1.0); TVector3d vel_dir = ctrl->cvel; vel_dir.Norm(); @@ -192,12 +190,12 @@ void update_view (CControl *ctrl, double dt) { switch (ctrl->viewmode) { case BEHIND: { - TVector3d vel_proj = ProjectToPlane (y_vec, vel_dir); + TVector3d vel_proj = ProjectToPlane(y_vec, vel_dir); vel_proj.Norm(); - TQuaternion rot_quat = MakeRotationQuaternion (mz_vec, vel_proj); - view_vec = RotateVector (rot_quat, view_vec); + TQuaternion rot_quat = MakeRotationQuaternion(mz_vec, vel_proj); + view_vec = RotateVector(rot_quat, view_vec); view_pt = ctrl->cpos + view_vec; - double ycoord = Course.FindYCoord (view_pt.x, view_pt.z); + double ycoord = Course.FindYCoord(view_pt.x, view_pt.z); if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) { view_pt.y = ycoord + MIN_CAMERA_HEIGHT; @@ -205,73 +203,73 @@ void update_view (CControl *ctrl, double dt) { if (ctrl->view_init) { for (int i=0; i<2; i++) { - view_pt = interpolate_view_pos (ctrl->cpos, ctrl->cpos, - MAX_CAMERA_PITCH, ctrl->viewpos, - view_pt, camera_distance, dt, - BEHIND_ORBIT_TIME_CONSTANT * - time_constant_mult); + view_pt = interpolate_view_pos(ctrl->cpos, ctrl->cpos, + MAX_CAMERA_PITCH, ctrl->viewpos, + view_pt, camera_distance, dt, + BEHIND_ORBIT_TIME_CONSTANT * + time_constant_mult); } } - ycoord = Course.FindYCoord (view_pt.x, view_pt.z); + ycoord = Course.FindYCoord(view_pt.x, view_pt.z); if (view_pt.y < ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT) { view_pt.y = ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT; } view_vec = view_pt - ctrl->cpos; - TVector3d axis = CrossProduct (y_vec, view_vec); + TVector3d axis = CrossProduct(y_vec, view_vec); axis.Norm(); TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(axis, PLAYER_ANGLE_IN_CAMERA); - view_dir = -1.0 * TransformVector (rot_mat, view_vec); + view_dir = -1.0 * TransformVector(rot_mat, view_vec); if (ctrl->view_init) { for (int i=0; i<2; i++) { TVector3d up_dir(0, 1, 0); - interpolate_view_frame (ctrl->viewup, ctrl->viewdir, - &up_dir, &view_dir, dt, - BEHIND_ORIENT_TIME_CONSTANT); + interpolate_view_frame(ctrl->viewup, ctrl->viewdir, + &up_dir, &view_dir, dt, + BEHIND_ORIENT_TIME_CONSTANT); } } break; } case FOLLOW: { // normale Einstellung - TVector3d vel_proj = ProjectToPlane (y_vec, vel_dir); + TVector3d vel_proj = ProjectToPlane(y_vec, vel_dir); vel_proj.Norm(); - TQuaternion rot_quat = MakeRotationQuaternion (mz_vec, vel_proj); - view_vec = RotateVector (rot_quat, view_vec); + TQuaternion rot_quat = MakeRotationQuaternion(mz_vec, vel_proj); + view_vec = RotateVector(rot_quat, view_vec); view_pt = ctrl->cpos + view_vec; - double ycoord = Course.FindYCoord (view_pt.x, view_pt.z); + double ycoord = Course.FindYCoord(view_pt.x, view_pt.z); if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) { view_pt.y = ycoord + MIN_CAMERA_HEIGHT; } if (ctrl->view_init) { for (int i=0; i<2; i++) { - view_pt = interpolate_view_pos (ctrl->plyr_pos, ctrl->cpos, - MAX_CAMERA_PITCH, ctrl->viewpos, - view_pt, camera_distance, dt, - FOLLOW_ORBIT_TIME_CONSTANT * - time_constant_mult); + view_pt = interpolate_view_pos(ctrl->plyr_pos, ctrl->cpos, + MAX_CAMERA_PITCH, ctrl->viewpos, + view_pt, camera_distance, dt, + FOLLOW_ORBIT_TIME_CONSTANT * + time_constant_mult); } } - ycoord = Course.FindYCoord (view_pt.x, view_pt.z); + ycoord = Course.FindYCoord(view_pt.x, view_pt.z); if (view_pt.y < ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT) { view_pt.y = ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT; } view_vec = view_pt - ctrl->cpos; - TVector3d axis = CrossProduct (y_vec, view_vec); + TVector3d axis = CrossProduct(y_vec, view_vec); axis.Norm(); TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(axis, PLAYER_ANGLE_IN_CAMERA); - view_dir = -1.0 * TransformVector (rot_mat, view_vec); + view_dir = -1.0 * TransformVector(rot_mat, view_vec); if (ctrl->view_init) { for (int i=0; i<2; i++) { TVector3d up_dir(0, 1, 0); - interpolate_view_frame (ctrl->viewup, ctrl->viewdir, - &up_dir, &view_dir, dt, - FOLLOW_ORIENT_TIME_CONSTANT); + interpolate_view_frame(ctrl->viewup, ctrl->viewdir, + &up_dir, &view_dir, dt, + FOLLOW_ORIENT_TIME_CONSTANT); } } break; @@ -279,7 +277,7 @@ void update_view (CControl *ctrl, double dt) { case ABOVE: { view_pt = ctrl->cpos + view_vec; - double ycoord = Course.FindYCoord (view_pt.x, view_pt.z); + double ycoord = Course.FindYCoord(view_pt.x, view_pt.z); if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) { view_pt.y = ycoord + MIN_CAMERA_HEIGHT; } @@ -287,12 +285,12 @@ void update_view (CControl *ctrl, double dt) { view_vec = view_pt - ctrl->cpos; TMatrix<4, 4> rot_mat; rot_mat.SetRotationMatrix(PLAYER_ANGLE_IN_CAMERA, 'x'); - view_dir = -1.0 * TransformVector (rot_mat, view_vec); + view_dir = -1.0 * TransformVector(rot_mat, view_vec); break; } default: - Message ("code not reached"); + Message("code not reached"); return; } @@ -304,10 +302,10 @@ void update_view (CControl *ctrl, double dt) { ctrl->view_init = true; if (shall_stationary) { - setup_view_matrix (ctrl, true); + setup_view_matrix(ctrl, true); is_stationary = true; } else { - setup_view_matrix (ctrl, false); + setup_view_matrix(ctrl, false); } } @@ -320,14 +318,14 @@ static TPlane frustum_planes[6]; static char p_vertex_code[6]; -void SetupViewFrustum (const CControl *ctrl) { +void SetupViewFrustum(const CControl *ctrl) { double aspect = (double) Winsys.resolution.width /Winsys.resolution.height; double near_dist = NEAR_CLIP_DIST; double far_dist = param.forward_clip_distance; TVector3d origin(0., 0., 0.); - double half_fov = ANGLES_TO_RADIANS (param.fov * 0.5); - double half_fov_horiz = atan (tan (half_fov) * aspect); + double half_fov = ANGLES_TO_RADIANS(param.fov * 0.5); + double half_fov_horiz = atan(tan(half_fov) * aspect); frustum_planes[0] = TPlane(0, 0, 1, near_dist); frustum_planes[1] = TPlane(0, 0, -1, -far_dist); @@ -341,13 +339,13 @@ void SetupViewFrustum (const CControl *ctrl) { = TPlane(0, -cos(half_fov), sin(half_fov), 0); for (int i=0; i<6; i++) { - TVector3d pt = TransformPoint (ctrl->view_mat, - origin + -frustum_planes[i].d * frustum_planes[i].nml); + TVector3d pt = TransformPoint(ctrl->view_mat, + origin + -frustum_planes[i].d * frustum_planes[i].nml); - frustum_planes[i].nml = TransformVector ( + frustum_planes[i].nml = TransformVector( ctrl->view_mat, frustum_planes[i].nml); - frustum_planes[i].d = -DotProduct ( + frustum_planes[i].d = -DotProduct( frustum_planes[i].nml, pt - origin); } @@ -361,7 +359,7 @@ void SetupViewFrustum (const CControl *ctrl) { } } -clip_result_t clip_aabb_to_view_frustum (const TVector3d& min, const TVector3d& max) { +clip_result_t clip_aabb_to_view_frustum(const TVector3d& min, const TVector3d& max) { bool intersect = false; for (int i=0; i<6; i++) { @@ -383,11 +381,11 @@ clip_result_t clip_aabb_to_view_frustum (const TVector3d& min, const TVector3d& n.z = min.z; } - if (DotProduct (n, frustum_planes[i].nml) + frustum_planes[i].d > 0) { + if (DotProduct(n, frustum_planes[i].nml) + frustum_planes[i].d > 0) { return NotVisible; } - if (DotProduct (p, frustum_planes[i].nml) + frustum_planes[i].d > 0) { + if (DotProduct(p, frustum_planes[i].nml) + frustum_planes[i].d > 0) { intersect = true; } } diff --git a/src/view.h b/src/view.h index c30de1d..b180cd6 100644 --- a/src/view.h +++ b/src/view.h @@ -21,12 +21,12 @@ GNU General Public License for more details. #include "bh.h" #include "mathlib.h" -void set_view_mode (CControl *ctrl, TViewMode mode); -void update_view (CControl *ctrl, double dt); +void set_view_mode(CControl *ctrl, TViewMode mode); +void update_view(CControl *ctrl, double dt); -void SetStationaryCamera (bool stat); // 0 follow, 1 stationary -void IncCameraDistance (double timestep); -void SetCameraDistance (double val); +void SetStationaryCamera(bool stat); // 0 follow, 1 stationary +void IncCameraDistance(double timestep); +void SetCameraDistance(double val); // ------------- viewfrustum ------------------------------------------ @@ -36,8 +36,8 @@ enum clip_result_t { NotVisible }; -void SetupViewFrustum (const CControl *ctrl); -clip_result_t clip_aabb_to_view_frustum (const TVector3d& min, const TVector3d& max); +void SetupViewFrustum(const CControl *ctrl); +clip_result_t clip_aabb_to_view_frustum(const TVector3d& min, const TVector3d& max); const TPlane& get_far_clip_plane(); const TPlane& get_left_clip_plane(); diff --git a/src/winsys.cpp b/src/winsys.cpp index 1949050..20dd06a 100644 --- a/src/winsys.cpp +++ b/src/winsys.cpp @@ -37,7 +37,7 @@ TVector2i cursor_pos(0, 0); CWinsys Winsys; -CWinsys::CWinsys () +CWinsys::CWinsys() : auto_resolution(800, 600) { screen = NULL; @@ -57,26 +57,26 @@ CWinsys::CWinsys () resolutions[9] = TScreenRes(1680, 1050); } -const TScreenRes& CWinsys::GetResolution (size_t idx) const { +const TScreenRes& CWinsys::GetResolution(size_t idx) const { if (idx >= NUM_RESOLUTIONS || (idx == 0 && !param.fullscreen)) return auto_resolution; return resolutions[idx]; } -string CWinsys::GetResName (size_t idx) const { +string CWinsys::GetResName(size_t idx) const { if (idx >= NUM_RESOLUTIONS) return "800 x 600"; if (idx == 0) return ("auto"); - string line = Int_StrN (resolutions[idx].width); - line += " x " + Int_StrN (resolutions[idx].height); + string line = Int_StrN(resolutions[idx].width); + line += " x " + Int_StrN(resolutions[idx].height); return line; } -double CWinsys::CalcScreenScale () const { +double CWinsys::CalcScreenScale() const { if (resolution.height < 768) return 0.78; else if (resolution.height == 768) return 1.0; else return (resolution.height / 768); } -void CWinsys::SetupVideoMode (const TScreenRes& resolution_) { +void CWinsys::SetupVideoMode(const TScreenRes& resolution_) { int bpp = 0; Uint32 video_flags = SDL_OPENGL; if (param.fullscreen) video_flags |= SDL_FULLSCREEN; @@ -107,11 +107,11 @@ void CWinsys::SetupVideoMode (const TScreenRes& resolution_) { if ((screen = SDL_SetVideoMode (resolution_.width, resolution_.height, bpp, video_flags)) == NULL) { - Message ("couldn't initialize video", SDL_GetError()); - Message ("set to 800 x 600"); - screen = SDL_SetVideoMode (800, 600, bpp, video_flags); + Message("couldn't initialize video", SDL_GetError()); + Message("set to 800 x 600"); + screen = SDL_SetVideoMode(800, 600, bpp, video_flags); param.res_type = 1; - SaveConfigFile (); + SaveConfigFile(); } #ifdef _WIN32 @@ -121,107 +121,98 @@ void CWinsys::SetupVideoMode (const TScreenRes& resolution_) { wglDeleteContext(tempRC); #endif - SDL_Surface *surf = SDL_GetVideoSurface (); + SDL_Surface *surf = SDL_GetVideoSurface(); resolution.width = surf->w; resolution.height = surf->h; if (resolution.width == 0 && resolution.height == 0) { auto_resolution = resolution; } - scale = CalcScreenScale (); - if (param.use_quad_scale) scale = sqrt (scale); + scale = CalcScreenScale(); + if (param.use_quad_scale) scale = sqrt(scale); } -void CWinsys::SetupVideoMode (size_t idx) { - SetupVideoMode (GetResolution(idx)); +void CWinsys::SetupVideoMode(size_t idx) { + SetupVideoMode(GetResolution(idx)); } -void CWinsys::SetupVideoMode (int width, int height) { - SetupVideoMode (TScreenRes(width, height)); +void CWinsys::SetupVideoMode(int width, int height) { + SetupVideoMode(TScreenRes(width, height)); } -void CWinsys::InitJoystick () { - if (SDL_InitSubSystem (SDL_INIT_JOYSTICK) < 0) { - Message ("Could not initialize SDL_joystick: %s", SDL_GetError()); +void CWinsys::InitJoystick() { + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { + Message("Could not initialize SDL_joystick: %s", SDL_GetError()); return; } - numJoysticks = SDL_NumJoysticks (); + numJoysticks = SDL_NumJoysticks(); if (numJoysticks < 1) { joystick = NULL; return; } - SDL_JoystickEventState (SDL_ENABLE); - joystick = SDL_JoystickOpen (0); // first stick with number 0 + SDL_JoystickEventState(SDL_ENABLE); + joystick = SDL_JoystickOpen(0); // first stick with number 0 if (joystick == NULL) { - Message ("Cannot open joystick %s", SDL_GetError ()); + Message("Cannot open joystick %s", SDL_GetError()); return; } joystick_active = true; } -void CWinsys::Init () { +void CWinsys::Init() { Uint32 sdl_flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER; - if (SDL_Init (sdl_flags) < 0) Message ("Could not initialize SDL"); - SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); + if (SDL_Init(sdl_flags) < 0) Message("Could not initialize SDL"); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); #if defined (USE_STENCIL_BUFFER) - SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); #endif - SetupVideoMode (GetResolution (param.res_type)); - Reshape (resolution.width, resolution.height); + SetupVideoMode(GetResolution(param.res_type)); + Reshape(resolution.width, resolution.height); - SDL_WM_SetCaption (WINDOW_TITLE, WINDOW_TITLE); - KeyRepeat (false); - if (USE_JOYSTICK) InitJoystick (); + SDL_WM_SetCaption(WINDOW_TITLE, WINDOW_TITLE); + KeyRepeat(false); + if (USE_JOYSTICK) InitJoystick(); // SDL_EnableUNICODE (1); } -void CWinsys::KeyRepeat (bool repeat) { +void CWinsys::KeyRepeat(bool repeat) { if (repeat) - SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - else SDL_EnableKeyRepeat (0, 0); + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + else SDL_EnableKeyRepeat(0, 0); } -void CWinsys::SetFonttype () { - if (param.use_papercut_font > 0) { - FT.SetFont ("pc20"); - } else { - FT.SetFont ("bold"); - } +void CWinsys::CloseJoystick() { + if (joystick_active) SDL_JoystickClose(joystick); } -void CWinsys::CloseJoystick () { - if (joystick_active) SDL_JoystickClose (joystick); +void CWinsys::Quit() { + CloseJoystick(); + Score.SaveHighScore(); + SaveMessages(); + Audio.Close(); // frees music and sound as well + if (g_game.argument < 1) Players.SavePlayers(); + SDL_Quit(); } -void CWinsys::Quit () { - CloseJoystick (); - Score.SaveHighScore (); - SaveMessages (); - Audio.Close (); // frees music and sound as well - FT.Clear (); - if (g_game.argument < 1) Players.SavePlayers (); - SDL_Quit (); -} - -void CWinsys::Terminate () { +void CWinsys::Terminate() { Quit(); exit(0); } -void CWinsys::PrintJoystickInfo () const { +void CWinsys::PrintJoystickInfo() const { if (joystick_active == false) { - Message ("No joystick found"); + Message("No joystick found"); return; } - PrintStr (""); - PrintStr (SDL_JoystickName (0)); - int num_buttons = SDL_JoystickNumButtons (joystick); + PrintStr(""); + PrintStr(SDL_JoystickName(0)); + int num_buttons = SDL_JoystickNumButtons(joystick); cout << "Joystick has " << num_buttons << " button" << (num_buttons == 1 ? "" : "s") << '\n'; - int num_axes = SDL_JoystickNumAxes (joystick); + int num_axes = SDL_JoystickNumAxes(joystick); cout << "Joystick has " << num_axes << " ax" << (num_axes == 1 ? "i" : "e") << "s\n\n"; } -unsigned char *CWinsys::GetSurfaceData () const { +unsigned char *CWinsys::GetSurfaceData() const { return (unsigned char*)screen->pixels; } diff --git a/src/winsys.h b/src/winsys.h index c90404f..9fb82c5 100644 --- a/src/winsys.h +++ b/src/winsys.h @@ -41,32 +41,31 @@ private: TScreenRes resolutions[NUM_RESOLUTIONS]; TScreenRes auto_resolution; SDL_Surface *screen; - double CalcScreenScale () const; + double CalcScreenScale() const; public: TScreenRes resolution; double scale; // scale factor for screen, see 'use_quad_scale' - CWinsys (); + CWinsys(); // sdl window - const TScreenRes& GetResolution (size_t idx) const; - string GetResName (size_t idx) const; - void Init (); - void SetupVideoMode (const TScreenRes& resolution); - void SetupVideoMode (size_t idx); - void SetupVideoMode (int width, int height); - void KeyRepeat (bool repeat); - void SetFonttype (); - void PrintJoystickInfo () const; - void ShowCursor (bool visible) {SDL_ShowCursor (visible);} - void SwapBuffers () {SDL_GL_SwapBuffers ();} - void Quit (); - void Terminate (); - void InitJoystick (); - void CloseJoystick (); + const TScreenRes& GetResolution(size_t idx) const; + string GetResName(size_t idx) const; + void Init(); + void SetupVideoMode(const TScreenRes& resolution); + void SetupVideoMode(size_t idx); + void SetupVideoMode(int width, int height); + void KeyRepeat(bool repeat); + void PrintJoystickInfo() const; + void ShowCursor(bool visible) {SDL_ShowCursor(visible);} + void SwapBuffers() {SDL_GL_SwapBuffers();} + void Quit(); + void Terminate(); + void InitJoystick(); + void CloseJoystick(); bool joystick_isActive() const { return joystick_active; } - double ClockTime () const {return SDL_GetTicks() * 1.e-3; } - unsigned char *GetSurfaceData () const; + double ClockTime() const {return SDL_GetTicks() * 1.e-3; } + unsigned char *GetSurfaceData() const; }; extern CWinsys Winsys;