mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
android: load prc files from assets. Move assets to /android_asset
This commit is contained in:
parent
8dea93bf38
commit
95eee0cab2
@ -7525,9 +7525,10 @@ def MakeInstallerAndroid():
|
|||||||
continue
|
continue
|
||||||
copy_library(source, base)
|
copy_library(source, base)
|
||||||
|
|
||||||
# Copy the models as well.
|
# Copy the models and config files to the virtual assets filesystem.
|
||||||
oscmd("mkdir apkroot/assets")
|
oscmd("mkdir apkroot/assets")
|
||||||
oscmd("cp -R %s apkroot/assets/models" % (os.path.join(GetOutputDir(), "models")))
|
oscmd("cp -R %s apkroot/assets/models" % (os.path.join(GetOutputDir(), "models")))
|
||||||
|
oscmd("cp -R %s apkroot/assets/etc" % (os.path.join(GetOutputDir(), "etc")))
|
||||||
|
|
||||||
# Make an empty res folder. It's needed for the apk to be installable, apparently.
|
# Make an empty res folder. It's needed for the apk to be installable, apparently.
|
||||||
oscmd("mkdir apkroot/res")
|
oscmd("mkdir apkroot/res")
|
||||||
|
@ -133,7 +133,8 @@ void android_main(struct android_app* app) {
|
|||||||
asset_mount = new VirtualFileMountAndroidAsset(app->activity->assetManager, apk_fn);
|
asset_mount = new VirtualFileMountAndroidAsset(app->activity->assetManager, apk_fn);
|
||||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||||
|
|
||||||
Filename asset_dir(apk_fn.get_dirname(), "assets");
|
//Filename asset_dir(apk_fn.get_dirname(), "assets");
|
||||||
|
Filename asset_dir("/android_asset");
|
||||||
vfs->mount(asset_mount, asset_dir, 0);
|
vfs->mount(asset_mount, asset_dir, 0);
|
||||||
|
|
||||||
// Release the apk_path.
|
// Release the apk_path.
|
||||||
@ -143,6 +144,33 @@ void android_main(struct android_app* app) {
|
|||||||
//TODO: prevent it from adding the directory multiple times.
|
//TODO: prevent it from adding the directory multiple times.
|
||||||
get_model_path().append_directory(asset_dir);
|
get_model_path().append_directory(asset_dir);
|
||||||
|
|
||||||
|
// Now load the configuration files.
|
||||||
|
vector<ConfigPage *> pages;
|
||||||
|
ConfigPageManager *cp_mgr;
|
||||||
|
AAssetDir *etc = AAssetManager_openDir(app->activity->assetManager, "etc");
|
||||||
|
if (etc != nullptr) {
|
||||||
|
cp_mgr = ConfigPageManager::get_global_ptr();
|
||||||
|
const char *filename = AAssetDir_getNextFileName(etc);
|
||||||
|
while (filename != nullptr) {
|
||||||
|
// Does it match any of the configured prc patterns?
|
||||||
|
for (size_t i = 0; i < cp_mgr->get_num_prc_patterns(); ++i) {
|
||||||
|
GlobPattern pattern = cp_mgr->get_prc_pattern(i);
|
||||||
|
if (pattern.matches(filename)) {
|
||||||
|
Filename prc_fn("etc", filename);
|
||||||
|
istream *in = asset_mount->open_read_file(prc_fn);
|
||||||
|
if (in != nullptr) {
|
||||||
|
ConfigPage *page = cp_mgr->make_explicit_page(Filename("/android_asset", prc_fn));
|
||||||
|
page->read_prc(*in);
|
||||||
|
pages.push_back(page);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filename = AAssetDir_getNextFileName(etc);
|
||||||
|
}
|
||||||
|
AAssetDir_close(etc);
|
||||||
|
}
|
||||||
|
|
||||||
// Also read the intent filename.
|
// Also read the intent filename.
|
||||||
methodID = env->GetMethodID(activity_class, "getIntentDataPath", "()Ljava/lang/String;");
|
methodID = env->GetMethodID(activity_class, "getIntentDataPath", "()Ljava/lang/String;");
|
||||||
jstring filename = (jstring) env->CallObjectMethod(activity->clazz, methodID);
|
jstring filename = (jstring) env->CallObjectMethod(activity->clazz, methodID);
|
||||||
@ -229,6 +257,11 @@ void android_main(struct android_app* app) {
|
|||||||
|
|
||||||
android_cat.info() << "Destroy requested, exiting from android_main\n";
|
android_cat.info() << "Destroy requested, exiting from android_main\n";
|
||||||
|
|
||||||
|
for (ConfigPage *page : pages) {
|
||||||
|
cp_mgr->delete_explicit_page(page);
|
||||||
|
}
|
||||||
|
vfs->unmount(asset_mount);
|
||||||
|
|
||||||
if (filename_str != nullptr) {
|
if (filename_str != nullptr) {
|
||||||
env->ReleaseStringUTFChars(filename, filename_str);
|
env->ReleaseStringUTFChars(filename, filename_str);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user