Making your own filetypes

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Making your own filetypes

Post by monkeycracks »

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.
CodeDog
Posts: 106
Joined: Sat Oct 07, 2006 8:00 pm
Location: CA. USA
Contact:

Post by CodeDog »

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;
}
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

ah yes, but I mean how would you convert it to your own file type (lets say .datatype) and then still be able to read it?
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Anyone?
Dibalo
Posts: 30
Joined: Sat Aug 12, 2006 2:31 pm
Location: Finland
Contact:

Post by Dibalo »

You have to make some kind of structure into your file. Very simple example:

Code: Select all

// myConfig.myFile

playerId = 23
playerStartHp = 100
enemyCount = 77
maxEnemies = 500
enemyHp = 30
etc...
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

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!!
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

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-

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;
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
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Yes, I don't really want to use XML because users will be able to read/change the contents. I'll try the other methods though.
CodeDog
Posts: 106
Joined: Sat Oct 07, 2006 8:00 pm
Location: CA. USA
Contact:

Post by CodeDog »

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.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

what if the server is also in the hands of the enemy?

how is it normally done?

there is no way to stop hackers?
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Midnight, this post was last year.
The server is in my hands, and I hope I'm not my own enemy.
Post Reply