Strictly speaking, all data is binary data (as FZammetti pointed out). However, the data of an ascii file (or .txt file if you may) is encoded according to the ASCII standard where 1 (one) is 49 and not 1, or in binary code (hexadecimal) 0x31 and not 0x01.
So, the question is not how to represent binary data but how to represent the data. A good representation can save you a lot of work, and it all depends on the situation.
But, if you want my advice, STAY AWAY FROM EVERYTHING THAT IS MFC!! because it requires your application to link to the MFC library and you don't want that because its large and slow (generally speaking). How can you tell something is MFC? The classes begin with a C (like CByteArray that you mentioned).
Once you've figured out a nice structure for your program data you can begin to worry about how to save and load it from file. There are a lot of different ways to do this, depending on the application. But say for instance that you want to save a bunch of numbers, indicating the tiles of your map where the first number is the tile ID of the first tile of the map (upper-left or something). If you want several maps in the same file you can either enforce that each map has the same size (which makes it easy to just move the filepointer) or that they begin (and possibly end) with a special marker.
Ok.. So much for file structure. Like I said, this is just one way of doing it. But how do I read (and write) the file in binary mode you ask? Simple, you supply a 'b' when you open the file, like this:
- Code:
//Open file for reading only, text mode
FILE* fptr = fopen("filename.txt","rt");
// Open file for writing, binary mode
FILE* fptr = fopen("filename.bin","wb");
// Open file for writing at the end of the file (append), binary mode
FILE* fptr = fopen("filename.bin","ab");
And so on... See the reference for fopen() for more info. The file needs to be present or the open-for-reading method will fail, returning a NULL pointer (you should check what fopen returns even if I didn't do it in this tiny example). The file will be created if not present by the open-for-writing and open-for-append methods.
Once you have opened a file, you just read/write the data from/to the file to/from your data structure using some of the file reading/writing functions. For example:
- Code:
//Assuming you have the data stored as an array
int tiles[50][50];
//read in the data from file (assuming you are at the right position, or only have one map per file))
for (int i=0; i<50; i++)
fread(tiles,sizeof(int),50,fptr);
//write the data to file (same assumption as above)
for (int i=0; i<50; i++)
fwrite(tiles,sizeof(int),50,fptr);
Simple, isn't it. You could also have done it like this:
- Code:
for (int i=0; i<50; i++)
fread(tiles,sizeof(tiles),1,fptr);
and you can even read a whole class this way
- Code:
MyClass* myClass;
fread(myClass,sizeof(MyClass),1,fptr);
but remember that it will only work for local types (char, int, struct, etc) and NOT for pointers as you could imagine.
Ok.. this should get you started. I havn't tested the code so I won't guarantee that it will work. Take a look at stdio.h reference to learn more about file IO. The correct way of doing this in C++ (stdio is C by the way) is to use iostreams, but since they are not available for WinCE you don't have much choise. (Slight correction, you can use MFC classes but like I said before, you don't want to do this).
And finally, limiting game speed should (could/would) work just like FZammetti said. First limit the framerate, then limit the speed of your sprites according to the framerate. All good games allow the user to adjust the game speed so it's not that big a deal if it's to fast or to slow on some devices as long as it's not TO SLOW and there is nothing one can do about it.
You could work with a timer for the rendering also if you like. But, you could also try to lower the FPS limit to 24 (like most movies). The following quote is taken from the link below that explains the difference and importance of FPS.
Do we need 30+ fps for enjoyable gameplay ... no... most people are happy with much lower framerates but since the huge hyping of 30+ fps a lot of people think or are influenced by the counter to think that 30 is a minimum... the only minimum is what you feel is unplayable... keep in mind that software engines are often running at between 10 and 20 fps and they are playable too... so framerate numbers are nice for benchmarking but not for judging playability.
http://www.ping.be/powervr/fps_discus.htm