-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
it appears to actually be working; still quite a hack though!
- Loading branch information
Showing
13 changed files
with
237 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "asset_stream.hpp" | ||
|
||
//Note, based in part on tchow Rainbow's "GameData.cpp" | ||
|
||
#if __ANDROID__ | ||
#include <sstream> | ||
#include <cassert> | ||
|
||
#include <android/native_activity.h> | ||
extern ANativeActivity *activity; | ||
#else | ||
#include <fstream> | ||
#endif | ||
|
||
std::unique_ptr< std::istream > asset_stream(std::string const &filename) { | ||
#ifdef __ANDROID__ | ||
assert(activity); //DEBUG | ||
|
||
AAsset *asset = AAssetManager_open(activity->assetManager, filename.c_str(), AASSET_MODE_STREAMING); | ||
|
||
if (asset == NULL) { | ||
throw std::runtime_error("Can't open asset '" + filename + "'."); | ||
} | ||
|
||
off64_t size = AAsset_getLength64(asset); | ||
void const *buffer = AAsset_getBuffer(asset); | ||
|
||
if (buffer == NULL) { | ||
throw std::runtime_error("Failed to get pointer to entire contents of asset '" + filename + "'."); | ||
} | ||
|
||
//copy buffer into a string wrapped in a string stream: | ||
std::unique_ptr< std::istringstream > ret(new std::istringstream(std::string(reinterpret_cast< const char * >(buffer), size))); | ||
|
||
AAsset_close(asset); | ||
|
||
return ret; | ||
#else //__ANDROID__ | ||
return std::make_unique< std::ifstream >(filename, std::ios::binary); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include <istream> | ||
|
||
//work-around for asset loading on android where assets don't actually have filenames! | ||
|
||
std::unique_ptr< std::istream > asset_stream(std::string const &filename); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.