Torque 3D Source Study Advice
by Dark Tengu · in Torque 3D Professional · 03/07/2010 (11:57 pm) · 4 replies
I'm digging through TorqueScript right now, trying to learn the ins and outs of Torque from the scripting standpoint. I believe that TorqueScript will probably get me 95% of the way to a complete game. Looking through the source, there is a massive amount of information. I was just wondering what areas of the source I should study to be most effective. My game will be an online shooter. So far I'm think that DLL/Source Files/Engine/T3D would maybe be the best part for practical purposes. Any advice would be VERY appreciated.
#2
03/08/2010 (10:07 am)
Thanks for the advice. Any areas in the source code that I should focus on?
#3
I can't really give you anything too specific -- it's best that you come up with ideas for things you want to change or implement, then figure out which code to explore from that -- but I'll highlight some bits you're likely to be interested in for a shooter.
If I mention a .cpp file you should generally assume there's a .h file that goes with it.
-Shapebase.cpp: One of the mid-level object types. Most complex game objects (ie, Players and Vehicles) come from the ShapeBase Class. If you start editing, for example, the Player Class and wonder why health and energy aren't found there, take a look at ShapeBase.
-Player.cpp: The actual Player Class is in this file. Includes things like animation picking and Player physics. See Player::UpdateMove to get started looking at how user input gets converted into actual motion on the Player Object.
-Projectile.cpp: The object type used to represent bullets, grenades, and so on. If you need to projectiles to operate differently from the standard rules (say, have grenades explode on timeout instead of only on impact) you'll want to start looking around in here.
-ShapeImage.cpp: The "Image" system is how weapons are built (though you could use it for other things in theory). A ShapeImage is a sort of state machine that can execute sound effects, animations, and script callbacks in response to user input. If you want to alter how weapon objects behave beyond what's exposed to script, look here.
-Item.cpp: The class for items in the world, static (respawning) or dynamic (dropped).
-AIPlayer.cpp: A basic class extending Player into a simple AI bot. You can do a lot to the AI with scripting, but you may also wish to alter core behaviors here (for example, I removed the bots ability to "insta-aim" to a set aim point).
Additionally:
/T3D/fps/ contains some basic GUI elements for FPS games, like the crosshair and healthbar. These are great simple examples of GUI rendering code, and can easily be extended for more advanced functions (for example, a Counter-Strike style scaling crosshair linked to accuracy).
T3D/vehicles/ contains code for the Vehicle Class and its subclasses. Core code in vehicle.cpp relates to all vehicle types, and the other files are pretty self-explanitory.
That should be enough to get you started. If you have specific questions about where to find code functionality, people on the forums are generally very willing to help out.
*Edit: I should also mention the networking code more specifically since you're doing a multiplayer game. Each object type that's networked will generally have 4 functions that handle sending and receiving data.
First some terms and concepts:
Ghost: the client-side copy of a server object
Control Object: The object the user is actually operating (ie, your player, a vehicle you are driving).
Mask: When you want to update something to clients, you set a "mask bit" that represents it. For example, the MoveMask. When it comes time to send an update, the function checks if this bit is set. If it is, the update that goes with it gets sent (in this case, obviously a movement event). If the packet makes it through, the bit gets cleared. If the packet fails (dropped, whatever) the bit stays set and the pack/write function will try again next time.
You should always use mask bits to determine if an update should be sent unless it goes out every packet, because any other system (ie using a bool flag in the class) can result in data not making it through when packets are getting dropped. To add new mask bits to an object, open its .h file and search for "enum MaskBits"
Here are the functions that send/receive the data:
packUpdate -- write an update to non-controlobject ghosts.
unpackUpdate -- read that update on the client.
writePacketData -- write a packet to a controlobject ghost.
readPacketData -- read that packet.
pack/unpackUpdate is generally for updates that clients need about objects they DO NOT control, ie other players. write/readPacketData is generally reserved for sending updates to control objects. IE, sending a user updates about his Player Object or the Vehicle it is controlling.
03/08/2010 (11:54 am)
You're correct that most game functionality is in the /T3D directory. Additionally, the "DLL" portion of the solution is the area you want to stick to for the most part; it contains everything that makes the engine work except lower-level support code you likely won't want to modify.I can't really give you anything too specific -- it's best that you come up with ideas for things you want to change or implement, then figure out which code to explore from that -- but I'll highlight some bits you're likely to be interested in for a shooter.
If I mention a .cpp file you should generally assume there's a .h file that goes with it.
-Shapebase.cpp: One of the mid-level object types. Most complex game objects (ie, Players and Vehicles) come from the ShapeBase Class. If you start editing, for example, the Player Class and wonder why health and energy aren't found there, take a look at ShapeBase.
-Player.cpp: The actual Player Class is in this file. Includes things like animation picking and Player physics. See Player::UpdateMove to get started looking at how user input gets converted into actual motion on the Player Object.
-Projectile.cpp: The object type used to represent bullets, grenades, and so on. If you need to projectiles to operate differently from the standard rules (say, have grenades explode on timeout instead of only on impact) you'll want to start looking around in here.
-ShapeImage.cpp: The "Image" system is how weapons are built (though you could use it for other things in theory). A ShapeImage is a sort of state machine that can execute sound effects, animations, and script callbacks in response to user input. If you want to alter how weapon objects behave beyond what's exposed to script, look here.
-Item.cpp: The class for items in the world, static (respawning) or dynamic (dropped).
-AIPlayer.cpp: A basic class extending Player into a simple AI bot. You can do a lot to the AI with scripting, but you may also wish to alter core behaviors here (for example, I removed the bots ability to "insta-aim" to a set aim point).
Additionally:
/T3D/fps/ contains some basic GUI elements for FPS games, like the crosshair and healthbar. These are great simple examples of GUI rendering code, and can easily be extended for more advanced functions (for example, a Counter-Strike style scaling crosshair linked to accuracy).
T3D/vehicles/ contains code for the Vehicle Class and its subclasses. Core code in vehicle.cpp relates to all vehicle types, and the other files are pretty self-explanitory.
That should be enough to get you started. If you have specific questions about where to find code functionality, people on the forums are generally very willing to help out.
*Edit: I should also mention the networking code more specifically since you're doing a multiplayer game. Each object type that's networked will generally have 4 functions that handle sending and receiving data.
First some terms and concepts:
Ghost: the client-side copy of a server object
Control Object: The object the user is actually operating (ie, your player, a vehicle you are driving).
Mask: When you want to update something to clients, you set a "mask bit" that represents it. For example, the MoveMask. When it comes time to send an update, the function checks if this bit is set. If it is, the update that goes with it gets sent (in this case, obviously a movement event). If the packet makes it through, the bit gets cleared. If the packet fails (dropped, whatever) the bit stays set and the pack/write function will try again next time.
You should always use mask bits to determine if an update should be sent unless it goes out every packet, because any other system (ie using a bool flag in the class) can result in data not making it through when packets are getting dropped. To add new mask bits to an object, open its .h file and search for "enum MaskBits"
Here are the functions that send/receive the data:
packUpdate -- write an update to non-controlobject ghosts.
unpackUpdate -- read that update on the client.
writePacketData -- write a packet to a controlobject ghost.
readPacketData -- read that packet.
pack/unpackUpdate is generally for updates that clients need about objects they DO NOT control, ie other players. write/readPacketData is generally reserved for sending updates to control objects. IE, sending a user updates about his Player Object or the Vehicle it is controlling.
#4
03/08/2010 (11:59 am)
@Henry - Thanks for the help. I'll take a look through those today.
Torque Owner Javier Canon