Tuesday, April 17, 2012

Underscores in JNI method names

They say you can use javah to find out the proper C name that corresponds to your Java native method. But I'm not sure how to get that to work, as I'm using Android and javah doesn't recognize the Android symbols such as android.graphics.Bitmap.

Luckily, you don't really need javah because the name is predictable. For example, the Java code
package com.foo;
public MyCode {
public static native int staticFunc(int x, int y);
public native void nonStaticFunc(int x, int y);
}
Requires C functions like these:
JNIEXPORT int JNICALL Java_com_foo_MyCode_staticFunc(JNIEnv *env, jclass jClass, int x, int y)
{ ... }
JNIEXPORT void JNICALL Java_com_foo_MyCode_nonStaticFunc(JNIEnv *env, jobject self, int x, int y)
{ ... }

I noticed one caveat. If your Java function is declared with an underscore, then the underscore must become "_1" on the C side. Weird eh? It's like this:
public static native int static_func(int x, int y);
JNIEXPORT int JNICALL Java_com_foo_MyCode_static_1func(JNIEnv *env, jclass jClass, int x, int y)
Probably this means you just won't use underscores. This and other weird rules are described here.

I heard a rumor that Android used to require you to define a JNI_OnLoad function which provides a list of your JNI functions. Luckily, this is no longer required.

Wednesday, April 04, 2012

Changing the FOV in Mass Effect 3

The default field-of-view in Mass Effect 3 is so narrow that you can get motion sickness, you won't see weapon upgrades that are right in front of you on the ground, and perhaps most importantly, you'll miss a lot of eye candy! Have a look at this screenshot that uses the default FOV, which is 70:



You're basically looking just at the Reaper's legs, and only if you look upward--if you're looking at the ground to see where you're going, you won't see much of the Reaper at all. Now check out my preferred FOV of 100 degrees:



You'll only want to use 100 if you're sitting in front of a fairly large screen, more than 23 inches. Otherwise 90 might be better.

Have you ever taken a picture of a natural vista that you thought was breathtaking--the grand canyon or a snow-capped mountain? But you take out your camera, snap a photo and look at it on the camera, and it's boring; the picture just looks like a bunch of rocks! Typically, the problem is that your camera only takes a little piece of that glorious vista, because it has a very narrow field-of-view. If you use a wide-angle lens or make a panorama, you can get much better results.

It's the same thing in Mass Effect 3. Some of the game's environments look gorgeous if you simply increase the field-of-view to let you see more. That's why it's fun sometimes to temporarily increase your FOV beyond the default. Here's the same scene at 120 degrees:



Now you can see not only the Reaper but also the buildings beside the harbour. When you add all this peripheral vision, some of the environments in ME3 look truly epic. However, you probably wouldn't want to use an FOV this high most of the time, because it would hide the small details that are also fun to look at, and in motion it doesn't look quite right unless you are sitting close to a very large screen (like our 112" stereoscopic 3D projector screen*.)

Now have a look at the Turian homeworld of Palaven, burning from the Reaper invasion, as seen from its moon:


Above: default FOV.

Above: FOV = 100 degrees.

Above: FOV = 120 degrees (a bit too high, but now you can see a Reaper too)

IMO 100 is far better. It's so cool to be fighting husks and brutes while seeing Palaven burn, or a Reaper reaping, in the background. Okay, that might sound slightly sadistic, but what I mean is that it's a beautiful game and if you leave the FOV at the default, you're not seeing as much of it as you should.

Besides that, if you use a narrow FOV then enemies will be surprising you all the time--you often won't notice them just because you aren't looking directly at them. If you have peripheral vision, you'll be more likely to see them coming.

So how can you get this nice FOV for yourself? Simple, you have to modify a configuration file called Coalesced.bin. But, it's a bit different than Mass Effect 2 because the Coalesced.bin file is no longer human-readable. You must therefore use a special editor, such as the ME3 Coalesced Editor, to modify it.

There's just one thing you should know before we begin. Just as in Mass Effect 2, the FOV command always overrides the game's normal FOV, which is unfortunate during conversations and cutscenes. During cutscenes the game wants to use a variety of FOV settings, and in particular, most often the game zooms in very close in order to fill the screen with characters' faces. When you use a custom FOV you are overriding this behavior, and so conversations and cutscenes will often look strange, for example some characters or body parts may not be fully animated during a cutscene because it was expected that those people or body parts would be off-screen.

To overcome this problem, we will prepare a key that you can press to disable your custom FOV. Then you should press this key when you start a conversation or cutscene. A little annoying, I know, but a better FOV is worth the trouble in my opinion.

Now, on my computer, Coalesced.bin is located at the following path:

C:\Program Files (x86)\Origin Games\Mass Effect 3\BIOGame\CookedPCConsole\Coalesced.bin

After you download and start the ME3 Coalesced Editor, you need to
  1. Open that file (File | Open).

  2. Expand "bioinput.ini" in the tree view. Then expand "sfxgame", then "sfxgamemodebase", then click "bindings".

  3. On the right-hand side, a list of "Name" lines appears. Scroll to the bottom of that list and you'll see a blank line. Click that blank line and paste the following text:

       ( Name="NumPadZero", Command="FOV 0" )

    this line tells Mass Effect 3 to restore the default FOV when you press "0" on your keyboard's number pad.

  4. Each time you paste in a command, a new blank line appears below it. Please paste the following six lines one-by-one:

       ( Name="NumPadOne", Command="FOV 70" )
       ( Name="NumPadTwo", Command="FOV 80" )
       ( Name="NumPadThree", Command="FOV 90" )
       ( Name="NumPadFour", Command="FOV 100" )
       ( Name="NumPadFive", Command="FOV 110" )
       ( Name="NumPadSix", Command="FOV 120" )

    These commands will let you try six fields of view from 70 (very narrow, which is the default) up to 120 (very wide-angle).

  5. Now, as I said, the FOV command overrides your FOV in all situations, so when you right-click to zoom in with your weapon, it won't zoom in at all. But not to worry! You can fix this problem. To allow zoom-in when you right-click, look for the line that starts with Name="Shared_Aim". Originally it looks like this:

       ( Name="Shared_Aim", Command="SwapWeaponIfEmpty | TightAim | OnRelease StopTightAim" )

    Change this line by adding "| FOV 0 | OnRelease FOV 90" before OnRelease. The line will look like this after you modify it:

       ( Name="Shared_Aim", Command="SwapWeaponIfEmpty | TightAim | FOV 0 | OnRelease FOV 90 | OnRelease StopTightAim" )

    One more thing! You have to decide whether you want the default FOV to be 90, 100, or something else. 90 is probably better for smaller screens, 100 for larger screens (as long as you are sitting close to the screen). The command above specifies which FOV to "return to" when you release the right mouse button. I've written 90 above; simply change that to 100 if you prefer.
That's it! Now just save changes, start your game and enjoy the epic journey!

* P.S. You can also play ME3 in Stereoscopic 3D Vision, which is awesome. Unfortunately, ME3 wasn't designed for 3D and doesn't work very well with it out-of-the-box; fortunately you can use the ME3 module for Helix Mod to make ME3 look great in 3D. But beware, for some reason NVidia completely screwed up 3D vision for ME3 in their latest driver (released 2012-03-13). We were able to get 3D to work properly by rolling back to the previous driver that was installed earlier.