hey Zaei. Im not a C++ genius and was wondering if u can quickly explain the try{}catch{} thing for error trapping for me. i think its best i use that or some system like it.
I dont have that class in my mail ox yet, i presuem it hasnt been sent.
Printable View
hey Zaei. Im not a C++ genius and was wondering if u can quickly explain the try{}catch{} thing for error trapping for me. i think its best i use that or some system like it.
I dont have that class in my mail ox yet, i presuem it hasnt been sent.
Your setup looks good. When you are ready, just send it to me, and I will figure out how to hook it in =).
try{}catch(){} is pretty simple stuff =). Take this code snippet for example:
Imagine that there is a whole bunch of code in between thsoe lines, and each one depends on the others succeding. Now, imagine that the third allocation fails:Code:char* p = new char[10];
...
char* p2 = new char[10];
...
char* p3 = new char[10];
Now we have a 20 byte memory leak. Not good. One way that you can do cleanup is by using labels:Code:if(!p3) return;
Unfortunately, labels are, to say the least, frowned upon. But, there is a better way =):Code:if(!p3) goto exit;
...
exit:
if(p) delete [] p;
if(p2) delete [] p2;
if(p3) delete [] p3;
return;
new will throw an exception (thats what this all is, exception handling) if there is not enough memory. The above code handles that situation by delete ing any allocated memory.Code:try
{
char* p = new char[10];
...
char* p2 = new char[10];
...
char* p3 = new char[10];
}
catch(...) // using the ... is legal in code. It means that this block
// should catch ANY type of error. You can also do catch
// (int x), for instance, that only catches integers.
{
if(p) delete [] p;
if(p2) delete [] p2;
if(p3) delete [] p3;
}
There are also other ways to use it. Consider:
Simple enough. When this function is called, it just throws a simple exception. You can throw anything, by the way. It could be "throw 'c';", or "throw 10;", or whatever. Now, take the following:Code:void x()
{
throw;
}
Now, when function x() is called, the throw in that function is caught by the surrounding try{}catch(){} block, and the function continues.Code:try
{
x();
}
catch(...)
{
return;
}
That is about all there is to it =).
Z.
Okay, for the website this is when I plan to have things done.
Admin - Tuesday or Wednesday
Downloads (database driven) - Thursday
News (database driven) - Friday
Knowledge Base, FAQ, Artwork - Sunday or Next Monday
Forums - Next Friday
Admin - Next Sunday
Which means the site will be complete in 2 weeks. I think I can do this.... :rolleyes:
I finally got my head around what I am going to do with the terrain, and surprisingly its going to change about 20 lines of the code I already have =). Basically my problem was that, for my texturing solution to work, I have to overlap the tiles that form the terrain. At the moment, the only way I could do that was to have each tile aware of the other 9 tiles that it overlapped. Bad plan, huh? Well, I finally realized that the tiles were NOT the terrain itself, only the medium that I am representing the terrain with. So, the new plan is to have an external (mod defined) IHeightMap object which has a single (at the moment) function, GetHeight(). So, I have a pointer to this object in each of my tiles, and each one uses it to get a height for a vertex. This allows seamless overlapping tiles, which is the objective, and also solves the problem of somehow allowing access to all terrain data through a non-modifiable method (the terrain DLL).
To wrap that all up, the terrain tiles are no long the terrain itself, but instead a method of representing the terrain provided from an outside source (the mod =).
I will also end up with an ITileSet object, which will define the textures to be used on each tile =).
Z.
I still wish we had a VBR grid :D
eh?
Z.
You know, different levels of detail for different parts of the map. You explained to me why it wouldn't work and I agree, but still... :D
It is more of an amount of work thing. I think that it would be far to much work to implement, in terms of texturing and such, that it isnt worth it.
Ive got most of the changes I was talking about finished up, and am now implementing the texturing =). If someone could whip up a couple of images for me, it would be great. Id like, for now, a simple grass texture, a snow texture, and a rock texture. If someone is feeling very abitious, I could also use a dirt and a water texture =). Square, at a resolution of 256x256 or 512x512 each should be fine =).
Z.
Hey, I just realized something. Sometime in the next week or so is the one year anniversary of the original Divinity engine =).
Z.
I will be glad to oblige!
*Opens up Wally and rips a few textures from HalfLife.wad*
Here you go! :D:D;):rolleyes::eek::)
Here's the first:
The second:
And the third.
And, in about 1 month, it's the 1 year anniversary of the team coming together!
No, sorry, 12 days, it's Sunday, April 14th!
Thanks, Sas, exactly what I wanted =). I should have texturing up and running by tomorrow night (i cant wait to see it =).
Z.
Cool :D
Does the throw go at the end of the function or begining. didnt really get that bit. do u have a good link to a tutorial ?
Zaei, i need that class if u want be to implement this into the engine !!
No, I dont have a tutorial. I leanred by experience =). throw is a command that you can use anywhere to throw an exception. For instance, say that you have a vector class that you are implementing. When it comes to writing the code to do out of bounds checking, you might have a statement like this:
Say there are only 10 elements. What do you do? You could return 0, but that might not always work. The best way to handle this is with a throw:Code:x = v[11];
This will cause the program to crash(gracefully) if the index is ouit of bounds, which means there is a bug somewhere. throw can be used anywhere you like.Code:template<class t>
vector::operator[](int index)
{
if(index > m_size-1) throw "Index Out of Bounds!";
}
I will email you the class the next time I get on =).
Z.
Here to say I'm still alive. Sorry, my work has been going REALLY slow. To much **** to do. Aspecially with school, grade 12 is a *****. Gotta work hard to graduate :D
I am still working on things, just not as fast. Also, I'm waiting for my keyboard to come in so I can do some funky shizel with the music.
Well, as promised, the texturing works. As proof, here is a nice screen shot =). In essence, it is a tile engine:
http://www.vbforums.com/attachment.php?s=&postid=904837
Psy, I am going to email the Core module to you. It is the entire project, and it is a DLL, but you should be able to get up and running almost immediatly. If you have any questions, just ask =).
Z.
Wow!!!
Excellent work there Zaei, now lets see some elevation changes!!
Hehe, just kidding. But if you can, even better!
Eventually. Those tiles are hardcoded, just as proof of concept. Next comes an actual manager, etc. Also, I have to figure out an algorithm to align tiles on triangle borders, or I get some ugly artifacts with the blending =). Then I have to come up with an editor for the tiles, and such =).
I also want to change the amount of overlap on the tiles, and maybe even vary it (so each tile is more like a puzzle piece =)).
Z.
That looks nice Zaei. Bit pixely but i guess thats the texture.
Hmm, looks like it cud take a while for me to implement the try catch thing. i will experiment a bit first to get used to using it.
Can i test to see if memory is leaking from my code in any way ?
Cheers for the core. now im trying to figure out where its gotta fit into it lol.
You can test for memory leaks by overloading new and delete, and storing the number of allocations and de-allocations.
Z.
I got logging implemented =)Code:
-= Divinity Networking Module =-
-------------------------------------
-Sockets Initialized
-Network Selected: DN_IP
-Network Initializing: DN_SERVER
-Server Version: 1.1
-Server Name: Times Of War
-Game Name: Crystal Rain Server
-Groups Created
-Connections Initialized
-Locked Server
-Max Clients: 10
-Network Initialized
-Network Starting
-Server Listening: 213.78.79.37:5600
-Core Thread Started
-Network Started
-Connection
-Address: 127.0.0.1:2357
-TCP Thread Started
-UDP Thread Started
-TCP HELO Command
-TCP VERS Command
-TCP USER Command
-TCP PASS Command
-TCP JOIN Command
-TCP EXIT Command
-UDP EXIT Command
-TCP Thread Stopped
-UDP Thread Stopped
-Network Stopping
-Core Thread Stopped
-Server Closed
-Network Stopped
-Network Terminating
-Groups Destroyed
-Network Terminated
-Sockets Terminated
Looks excellent Psy!
Nice =).
Z.
Well, I have some good news =). I have gotten the terrain working correctly, textured, etc, and I ahve implemented a TOW_Map class that contains the tiles and such. Now, I created a 10x10 tiled map, with tiles 6.0x6.0 meters, with 15x15 quads. Textured, and alpha blended, at a whopping 253 frames per second. On my card =). It looks excellent, and its nice and fast =).
Psy, something I noticed in the log above:
Is this right, or should it be switched?Code:-Server Name: Times Of War
-Game Name: Crystal Rain Server
On a different note, I will be going out of town in the morning, and i will be back home Sunday night.
Z.
Yea it should be switched. I havent really thought about the layout at the moment (variable) wise and so in the dn_session class username in a server is server name and name is gamename. i have to sort it out and change it around. Now i have the base code going i gotta think about how this would all work in reference to joining a game etc and re-do it.
heres what i have thought.
I think something like that is best and allows for expansion etc. and easy automation. Im expanding / changing the class now to allow for this.Code:
1) User selects to run as client.
2) Client class Initializes
3) They enter username, password and select a server/port/game from the list
4) If an OnConnect(DN_CLIENT) is received Join(gamename) is called.
5) If an OnJoin() is connected then a request to join the lobby is sent. if allowed OnLobby() is called.
6) When OnLobby() is called the engine can display the lobby screen in which users can now talk to each other.
7) Then when the host (server) clicks on RunGame the clients receive a OnGame() call in which the game starts running and data is passed through the UDP connnection.
Servers at the moment will have to be dedicated. Im thinking that when a server is started the lobby screen is shown which is where they can chat with the others / set options, then once they click OnGame the server, joins the game too (or can see whats going on) like a watcher (they dont play) until i can work out how to make it so theyre dedicated or not.
All of this will be working in seperate threads to allow for OnConnect() etc to be called and handled while the networking works on verifying the username/password etc.
Looking good, Psy =). Keep up the good work, and I will be back on Sunday.
Z.
Well, i have spent the last 3 hours re-writing 1,500 lines of code to get the networking how we want it. currently version 6, lol :D
I wont even bother versioning until we release the first set of binaries to the general public =).
Z.
Ok, I'm feeling ASP-dumb this week, and I can't seem to get anything right. As a result, the downloads and news pages will be automated tomorrow, but the site release is going to be set back.
It happens =). You have been doing great work!
Z.
Well i did it locally on my pc so that i can keep track of each re-write that i do. Yet it is still version 0.1
I got some code from flipcode for memory leak tracking although it uses STL which i dont know how to use so i gotta play around with it till i get it working.
I know the code you are talking about. You can pretty much ignore the STL sections of it, and just use the overloaded new and delete operators.
Z.
Well, i got it to work using STL. It shows no memory loss, although i cannot get it to work with new[] and delete[] only new and delete.
I have almost got the dll redone and will be working on some demo applications next.
Well, I spent the evening screwing around with the terrain rendering, and managed to drop the frames per second down to about 3 =). I will spend tomorrow fixing that up, and optimizing it a bit.
Z.
Okay, real sorry about the latent slowness around here lately. I've basically not been doing my end of the job and that will stop tomorrow. If possible I'm spending the full day on it.