Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode rendering #47

Merged
merged 33 commits into from
Jan 31, 2020
Merged

Unicode rendering #47

merged 33 commits into from
Jan 31, 2020

Conversation

leo60228
Copy link
Contributor

@leo60228 leo60228 commented Jan 12, 2020

Legal Stuff:

By submitting this pull request, I confirm that...

  • My changes may be used in a future commercial release of VVVVVV (for
    example, a 2.3 update on Steam for Windows/macOS/Linux)
  • I will be credited in a CONTRIBUTORS file for all of said releases, but
    will NOT be compensated for these changes

Changes:

If font.png is more than 128px tall, it is assumed to be the .png version of the Space Station font. Compatibility with the original font is preserved.

All characters outside ASCII have a width of 8.

The Space Station font (font.png) was created by Matt 'Stelpjo' Aaldenberg.

utfcpp is by @nemtrif. It does not require attribution in binary releases.

@leo60228 leo60228 changed the title Utf8 Unicode rendering Jan 12, 2020
Copy link
Collaborator

@flibitijibibo flibitijibibo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is an extremely massive patch that is undocumented, seems to have irrelevant changes, and adds both a software dependency and even a third-party content dependency. That’s pretty much three strikes right away.

A proper system for localization is a good idea, but this isn’t a good start. It would be good to start with text data first, then unicode support with the existing bitmap (knowing that basically all the chars would be ‘?’ at first), then we can start modifying the stock content to support the new text data. Stapling a random font and shoving it in by force with a megacommit doesn’t help the code’s current quality.

desktop_version/src/FileSystemUtils.cpp Outdated Show resolved Hide resolved
desktop_version/tinyxml/tinyxml.h Outdated Show resolved Hide resolved
desktop_version/CMakeLists.txt Outdated Show resolved Hide resolved
desktop_version/src/main.cpp Outdated Show resolved Hide resolved
@leo60228
Copy link
Contributor Author

For what it's worth, over 2/3 of tinyxml is documentation and tests.

@leo60228
Copy link
Contributor Author

utfcpp I mean, not tinyxml...

@flibitijibibo
Copy link
Collaborator

If it’s not needed to build we can remove it (aside from the license). This still seems like a very large dependency for what is essentially a single function.

@flibitijibibo
Copy link
Collaborator

Still have some dot files, but WOW that repo must be pretty bloated. 3000+ lines to almost less than 500 is quite dramatic, no?

@flibitijibibo
Copy link
Collaborator

Right, so that covers the dependency issue... I am definitely more okay with a dependency that’s ~400 lines, rather than 10 times that(!!!).

I do still think the changes need to be designed differently, however - try to aim for the absolute minimum C++ standard possible (if you can get away with it, write it as basically C). We have to support some very old compilers, so there’s no room to be overly fancy.

The char list in particular is pretty extreme - if there’s a way to determine the font information at load time instead of every lookup, and with a... slightly less hardcoded charset, that will make maintaining the font a lot easier in the long run.

@flibitijibibo
Copy link
Collaborator

Possible route towards fixing the mega array: should we have a font.txt next to the PNG to provide the list of supported chars? This would allow for a default charset with the current font.png (when no txt is found) and allow for custom fonts, including the one you’ve made and other font updates in the future.

(Sidenote: We’ll probably not include the custom font in the repo, that can be a content mod until Terry decides to update the font officially.)

@leo60228
Copy link
Contributor Author

That sounds good to me.

@leo60228
Copy link
Contributor Author

My keyboard broke midway through this commit and my only spare is super difficult to type on. I'm gonna work on this some more tomorrow.

Copy link
Collaborator

@flibitijibibo flibitijibibo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a bit to do (and a boatload to test) but this is already a huge improvement.

@JayFoxRox does this at least compile and not crash when the mod is absent? If not, we’ll need to figure out a safe way to support this (maybe a text interface with UTF8 and ASCII backends?).

desktop_version/src/Graphics.cpp Outdated Show resolved Hide resolved
desktop_version/src/Graphics.cpp Outdated Show resolved Hide resolved
desktop_version/src/Graphics.cpp Outdated Show resolved Hide resolved
desktop_version/font.txt Outdated Show resolved Hide resolved
@JayFoxRox
Copy link

JayFoxRox commented Jan 12, 2020

@JayFoxRox does this at least compile and not crash when the mod is absent? If not, we’ll need to figure out a safe way to support this (maybe a text interface with UTF8 and ASCII backends?).

Not sure which mod you mean (mod[ification] = changes in this PR?).

Before commenting earlier I didn't try compiling this PR. I actually did compile it now and found another issue (with utfcpp): dependency on C++ exceptions.

Our toolchain does not currently support those:

VVVVVV/desktop_version/utfcpp/source/utf8/checked.h:81:17: error: cannot use 'throw' with exceptions disabled
                throw not_enough_room();
[...]

There doesn't seem to be a way to disable them with utfcpp?

This explanation about my ongoing port is offtopic, so I'll fold this (click here for more information)

My port (to original Xbox) is currently blocked by issues in our SDL2 port and a lot of stupid changes required for PhysFS. It still compiles though. But even the VVVVVV master revision does not work correctly on original Xbox (crashes in sound initialization), yet. As we don't have a debugger in our toolchain it will take some time to understand the crashes I'm getting. See JayFoxRox#1.

However, I know that our original Xbox toolchain doesn't (currently?) support unicode in winapi (selfmade winapi abstraction for Xbox NT kernel) and also doesn't support wchar in our libc (pdclib). We use LLVM libcxx for C++, but it was only upstreamed a week ago and I wasn't involved with it (not sure if that supports UTF / unicode in our port).
Even if compiling with stubs in the libc / libcxx might work, then I'd expect issues at runtime.

I assume similar issues, weak UTF / unicode and exception support, for other homebrew SDKs for smaller platforms (PS2? PSP? Event badges?). At least original Xbox has a modern compiler (LLVM clang) - I heard that some PS2 SDKs use an ancient gcc (not sure if Sony SDK or homebrew SDK).


I don't really understand why VVVVVV has to process strings itself anyway - most of it are probably constant texts or very simple formatting operations. So I'm not sure if the code would really need to understand UTF / Unicode - one could just map symbols to glyphs from data files.

Localization is obviously a great feature that I'd also want to use in the future. A lightweight or optional implementation of Unicode is totally fine with me.

Alternatively, you could also make the decision to drop support for niche platforms to focus on code quality / simplicity - which is also fine if it is communicated correctly, although it would be a bit disappointing.

@flibitijibibo
Copy link
Collaborator

If we can remove the exceptions that’d be great - we don’t even handle them anyway so it’d be nice to make those optional (and submit the changes upstream of course).

I think the problem with data processing is the editor, we may have to worry about custom scripts and levels. Maybe not though, if it’s easy to read/write the correct format (presumably we’d write this format for the static data anyhow).

@leo60228
Copy link
Contributor Author

The main purpose of this was so custom levels could be written in foreign languages.

@leo60228
Copy link
Contributor Author

@JayFoxRox Does your toolchain just not have throwing std functions, or do they abort instead of throwing? Should I avoid using them?

@leo60228
Copy link
Contributor Author

I'm not catching the exceptions, for what it's worth.

@leo60228
Copy link
Contributor Author

Also, for what it's worth, no UTF-8 strings ever get passed to libc or std functions that handle them specially. std::string is encoding-agnostic to any 8-bit encoding (which is why utfcpp is necessary in the first place).

#include <cstdlib>

//#define UTF_CPP_THROW(X) throw (X);
#define UTF_CPP_THROW(X) (printf("UTF-8 error: %s", (X).what()), exit(1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory I don’t mind this, but we should ask the utfcpp maintainer about this first. We may also meed to define UTF_CPP_CPLUSPLUS to fix some of the exception keywords and includes in both files. @JayFoxRox, would you be able to help with this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I can't help with this; I have many projects to maintain myself.

@JayFoxRox
Copy link

JayFoxRox commented Jan 12, 2020

Thanks for taking the time to respect demands of limited platforms 👍

@JayFoxRox Does your toolchain just not have throwing std functions, or do they abort instead of throwing? Should I avoid using them?

It wouldn't even build, because the compiler will depend on features in our libc/libcxx/compiler-rt. Small teams (like us hobbyists) don't have the capacity to support these features easily (it's easy to have a "functional" port of a libc/libcxx, but harder to have complete port which depends on proper stack unwinding and other platform / ABI dependent features).

Basically there are some non-essential C++ features that are "harder" to port; so for custom platforms these typically aren't implemented or very low priority. We also still lack RTTI (XboxDev/nxdk#237).
I should note, that I assume that this makes our toolchain non-standard compliant. So wether VVVVVV respects such "incomplete" platforms has to be decided.

This usually isn't an issue as software from scratch can respect those limitations. Games typically don't use these features either - especially those which are suitable for even running on 20 year old hardware (low memory, slow CPU, limited resolution, no full blown OS, ..).

If I were to remove -fno-exceptions from our Makefile, then our toolchain causes this during linking:

lld: error: undefined symbol: ___std_terminate
lld: error: undefined symbol: ___CxxFrameHandler3
...

As our toolchain improves we'll probably add support for these features.

I'm not catching the exceptions, for what it's worth.

Exactly. Ideally software that doesn't use these features shouldn't require them in the first place for portability sake (not just for our toolchain, but also other potential stakeholders which depend on non-FOSS toolchains which are impossible to update).

Also, for what it's worth, no UTF-8 strings ever get passed to libc or std functions that handle them specially.

Sounds good, that shouldn't be an issue then 👍

@@ -93,7 +93,7 @@ void KeyPoll::Poll()

if (textentrymode)
{
if (evt.key.keysym.sym == SDLK_BACKSPACE)
if (evt.key.keysym.sym == SDLK_BACKSPACE && keybuffer.size() > 0)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pardon me, I am just curious. Would it be better to use here keybuffer.empty instead of keybuffer.size?

@leo60228
Copy link
Contributor Author

@voct Probably, yes.

@leo60228
Copy link
Contributor Author

@Vest

@Fussmatte
Copy link
Contributor

What's the situation on this right now? I'm really looking forward to UTF-8 support in VVVVVV.

@flibitijibibo
Copy link
Collaborator

We need to write (and ideally upstream) some patches to make the C++ exceptions optional. That's the only serious blocker I remember, tbh.

@leo60228
Copy link
Contributor Author

Those are already in the PR. I haven't tried to upstream them, though.

@leo60228
Copy link
Contributor Author

Just rebased.

@flibitijibibo
Copy link
Collaborator

As a reminder, we're still not hosting the custom fonts - that will only be in the CE repo. Will let the buildbots do the rest of the talking...

@leo60228
Copy link
Contributor Author

@flibitijibibo In VVVVVV-CE, I use FriBidi to handle bidirectional text. FriBidi is a very heavy library, but I wasn't able to find something more lightweight. Do you have any suggestions on this?

Copy link
Collaborator

@flibitijibibo flibitijibibo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joking aside, this looks really good now! Just need tabbing cleanup and this can be squashed in.

desktop_version/src/KeyPoll.cpp Outdated Show resolved Hide resolved
desktop_version/src/Graphics.h Outdated Show resolved Hide resolved
desktop_version/src/Graphics.h Outdated Show resolved Hide resolved
desktop_version/src/Graphics.cpp Outdated Show resolved Hide resolved
@leo60228
Copy link
Contributor Author

I wasn't aware of #118 when I removed stelpjo, but it turns out they were in CONTRIBUTORS.txt twice after rebasing anyway.

@flibitijibibo
Copy link
Collaborator

flibitijibibo commented Jan 31, 2020

Looks like Graphics.cpp got pretty thrashed in the last update - the only way I can really see all the mismatches now is to Ctrl+F exactly four spaces (GitHub please stop ruining my whitespace the irony is not funny) and Highlight All. Still a lot of mixing and matching going on for some reason. All the other files seem okay.

@leo60228
Copy link
Contributor Author

@flibitijibibo I reindented every function I could recall changing. Should I just reindent the whole file with tabs?

@leo60228
Copy link
Contributor Author

I'm not sure what was already indented with spaces, so I've only reindented what was mentioned in the review.

@flibitijibibo flibitijibibo merged commit 6a17625 into TerryCavanagh:master Jan 31, 2020
@flibitijibibo
Copy link
Collaborator

Squashed into upstream, thanks for all the work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants