Game Development Reference
In-Depth Information
Introduction
Files are the building blocks of any computer system. This chapter deals with portable
handling of read-only application resources, and provides recipes to store the application
data. We also use the code from Chapter 3 , Networking, to organize asynchronous loading
of resources from the .zip archives.
Let us briely consider the problems covered in this chapter. The irst one is the access to
application data iles. Often, application data for desktop operating systems resides in the
same folder as the executable ile. With Android, things get a little more complicated. The
application iles are packaged in the .apk ile, and we simply cannot use the standard
fopen() -like functions, or the std::ifstream and std::ofstream classes.
The second problem results from the different rules for the ilenames and paths. Windows and
Linux-based systems use different path separator characters, and provide different low-level
ile access APIs.
The third problem comes from the fact that ile I/O operations can easily become the slowest
part in the whole application. User experience can become problematic if interaction lags
are involved. To avoid delays, we should perform the I/O on a separate thread and handle
the results of the Read() operation on yet another thread. To implement this, we have all
the tools required, as discussed in Chapter 3 , Networking — worker threads, tasks, mutexes,
and asynchronous event queues.
We start with abstract I/O interfaces, implement a portable .zip archives handling approach,
and proceed to asynchronous resources loading.
Abstracting ile streams
File I/O APIs differ slightly between Windows and Android (POSIX) operating systems, and we
have to hide these differences behind a consistent set of C++ interfaces. All libraries we have
compiled in Chapter 2 , Porting Common Libraries use their own callbacks and interfaces. In
order to unify them, we shall write adapters in this and subsequent chapters.
Getting ready
Please make sure you are familiar with the UNIX concept of the ile and memory mapping.
Wikipedia may be a good start ( http://en.wikipedia.org/wiki/Memory-mapped_
file ).
 
Search WWH ::




Custom Search