Making your own filetypes
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Making your own filetypes
How would you make your own filetype? Like IrrEdit can do XML or .irr
Max has 3ds, max, etc
I just want something similar to a text/xml file.
Max has 3ds, max, etc
I just want something similar to a text/xml file.
It's C++, you can use the same binary or text output to file routines you would use in any C++ application.
Code: Select all
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
You have to make some kind of structure into your file. Very simple example:
First argument is your variable and second (after = operator) is value. Then you have to make your own config-file reading and writing functions. Simple example based on objects:
Code: Select all
// myConfig.myFile
playerId = 23
playerStartHp = 100
enemyCount = 77
maxEnemies = 500
enemyHp = 30
etc...
Code: Select all
ConfigReader file("myConfig.myFile");
try
{
int playerHp = file.search("playerStartHp");
int enemyHp = file.search("enemyHp");
}
catch(OwnExeption& e)
{
// handle problem, if you didn´t find variables named "playerStartHp" or "enemyHp"
...
}
Dattebayo!!
file extentions are nothing to do with the "data type", they are just the letters at the end of the file name.
The traditional way to make your own data type was like so-
then write out all the structs to disk in binary mode. when you read the file header back in, you check to see if your "magic number" matches. if it does, the data inside the file is probably the same.
since we're not living in 1980, i'd recommend using xml (edit: Dibalo's way works too of course) as the carrier for your data. it might take up more disk space, but disk space is cheap and man-hours are expensive. just write it out using Irrlicht's XML writer, and read it using the XML reader
The traditional way to make your own data type was like so-
Code: Select all
struct my_file_header
{
long MagicNumber;
// file options and stuff
} filehead;
struct my_mesh_struct
{
int number_of_verts;
int number_of_indices;
} mesh1;
...
filehead.MagicNumber = 0x1337;
since we're not living in 1980, i'd recommend using xml (edit: Dibalo's way works too of course) as the carrier for your data. it might take up more disk space, but disk space is cheap and man-hours are expensive. just write it out using Irrlicht's XML writer, and read it using the XML reader
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Users will be able to change the contents no matter what file type you use.
Encryption will slow them down but not stop them.
Most users can edit text files.
Some users will know enough to edit binary files and those users will make programs to edit the binary files which they will give to the rest of the users to use.
Just remember, ANYTHING client side is in the hands of the enemy.
Store ALL important game info server side.
Encryption will slow them down but not stop them.
Most users can edit text files.
Some users will know enough to edit binary files and those users will make programs to edit the binary files which they will give to the rest of the users to use.
Just remember, ANYTHING client side is in the hands of the enemy.
Store ALL important game info server side.
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact: