Page 1 of 1

Experiments with stand-alone games

Posted: Mon May 07, 2012 7:21 pm
by T-Bone
Yes, I know that stand-alone games are of low-priority right now, but I was curious and started to play around a bit. In LoveLauncher.java, I saw that when you click on a .love file in the list, if calls

Code: Select all

Intent i = new Intent(LoveLauncher.this, LoveNative.class);
i.setData(Uri.parse("file://" + (String) (parent.getAdapter().getItem(position))));
startActivity(i);
which seems to start up the game. So I thought, what the hell, I should simply be able to add something like this to public void onCreate(...), and it should start up my game straight away. So I made it like this:

Code: Select all

public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.launcher);
		
		Intent i = new Intent(LoveLauncher.this, LoveNative.class);
		i.setData(Uri.parse("android.resource://net.schattenkind.nativelove/" + R.raw.game));
		startActivity(i);
}
and I place my game, named game.love, inside net.schattenkind.nativelove/res/raw/, and tried it. It started LÖVE straight away, but it showed the no-game screen instead of my game. I think I'm referring to the file correctly. At least this is how I've learned to refer to local files inside the app.

Do any of you know what's wrong? I know love-native-android isn't quite ready yet, but it is getting there, and I'd love to play around a bit :neko:

Re: Experiments with stand-alone games

Posted: Mon May 07, 2012 9:03 pm
by bartbes
Does it work when you point it at an external file, rather than a resource?

Re: Experiments with stand-alone games

Posted: Mon May 07, 2012 9:30 pm
by Moe
T-Bone wrote:Do any of you know what's wrong? I know love-native-android isn't quite ready yet, but it is getting there, and I'd love to play around a bit :neko:
and I place my game, named game.love, inside net.schattenkind.nativelove/res/raw/
Awesome, a reply but rearranging your post. :awesome:
Background: All data in the res folder is put into the apk. So if you want to access the data from the native layer, you have to provide a way to access the data within the apk. In our case, it would make sense to open it by physfs, so that you can actually access a real file. Seems a bit clumsy since we will get a physfs (.love) within a physfs(.apk), there might be an JNI-powered access or you can extract the apk to memory. In any case there will not be a simple way like fopen.

Re: Experiments with stand-alone games

Posted: Tue May 08, 2012 6:15 am
by T-Bone
There has to be a simple way to access the contents from the apk from within JNI. Otherwise JNI would be kind of useless for designing, you know, apps and games.

Perhaps this could be of help? http://www.anddev.org/ndk_opengl_-_load ... 11978.html

Re: Experiments with stand-alone games

Posted: Tue May 08, 2012 6:38 am
by bartbes
The problem isn't that android doesn't provide access, the problem is physfs can't deal with archives within archives. Maybe you could try a folder in the resources?

Re: Experiments with stand-alone games

Posted: Tue May 08, 2012 6:40 am
by T-Bone
Oh, if that's the problem, then that can easily be solved. There is no need for it to be packed into a .love, if it can load a folder then that would be perfect. How would I refer to the folder in that case?

Re: Experiments with stand-alone games

Posted: Tue May 08, 2012 3:01 pm
by kalle2990
T-Bone wrote:Yes, I know that stand-alone games are of low-priority right now, but I was curious and started to play around a bit. In LoveLauncher.java, I saw that when you click on a .love file in the list, if calls

Code: Select all

Intent i = new Intent(LoveLauncher.this, LoveNative.class);
i.setData(Uri.parse("file://" + (String) (parent.getAdapter().getItem(position))));
startActivity(i);
which seems to start up the game. So I thought, what the hell, I should simply be able to add something like this to public void onCreate(...), and it should start up my game straight away. So I made it like this:

Code: Select all

public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.launcher);
		
		Intent i = new Intent(LoveLauncher.this, LoveNative.class);
		i.setData(Uri.parse("android.resource://net.schattenkind.nativelove/" + R.raw.game));
		startActivity(i);
}
I'm not completely sure on how to link it from ./res/raw, but I'm quite sure R.raw.game points to an integer value. However, you could place it inside ./assets instead. This would look something like this file:///android_asset/game.love, I have tried this with a HTML file just recently and this is the easiest method I found ;)

Re: Experiments with stand-alone games

Posted: Tue May 08, 2012 5:55 pm
by bartbes
kalle2990 wrote:but I'm quite sure R.raw.game points to an integer value
That is correct and intended, the uri contains the id.

Re: Experiments with stand-alone games

Posted: Tue May 08, 2012 6:13 pm
by T-Bone
Can confirm that using the "assets" folder does not work, at least not the way I'm doing it, which is

Code: Select all

Intent i = new Intent(LoveLauncher.this, LoveNative.class);
i.setData(Uri.parse("file:///android_asset/game"));
startActivity(i);
and

Code: Select all

Intent i = new Intent(LoveLauncher.this, LoveNative.class);
i.setData(Uri.parse("file:///android_asset/game.love"));
startActivity(i);
with folder and .love respectively.

Re: Experiments with stand-alone games

Posted: Tue May 08, 2012 10:41 pm
by Moe
T-Bone wrote:There has to be a simple way to access the contents from the apk from within JNI. Otherwise JNI would be kind of useless for designing, you know, apps and games.
Most games use JNI as few as possible, most likely they will pass events and loop triggers for the render loop.
Anyway, you can pass a file handle by JNI or something similar. I will take a look for a solution when I have some spare time. Meanwhile, you can extract the love file from the apk on the first run.