Game Development Community

dev|Pro Game Development Curriculum

WheeledVehicle & Player DataBlock Editors

by Zachary McMaster · 06/18/2002 (2:26 pm) · 11 comments

Download Code File

to install:

Get the 1 zip file..
read the textfiles in each zip to install.

enjoy...:)

About the author

Recent Blogs

• FMod for torque

#1
06/18/2002 (9:20 pm)
VERY NICE indeed
#2
06/26/2002 (11:59 am)
excellent job, but I seem to have a problem... when editing a wheeled Vehicle datablock the spring and tire sections always show empty box's. If I put values it there, apply, close the editor and reopen it, it is blank again. Is this a bug or something I'm missing. I've updated to the latest head and even tried the defaultCar datablock with the same results.
#3
06/28/2002 (7:31 pm)
oops
I forgot the WheeledVehicleData stuff in
WheeledVehicle.h

WheeledVehicleData class :

WheeledVehicleTire * defaultTire;
WheeledVehicleSpring * defaultSpring;
WheeledVehicleSpring * getSpring(){return defaultSpring;}
WheeledVehicleTire * getTire(){return defaultTire;}

----

WheeledVehicle class:
public:
static void consoleInit();

-----
WheeledVehicle.cc

static int cGetSpringDataBlock(SimObject *obj, S32, const char **)
{
WheeledVehicle* ptr = static_cast(obj);
return ptr->getSpring(0)? ptr->getSpring(0)->getId(): 0;
}

static int cGetTireDataBlock(SimObject *obj, S32, const char **)
{
WheeledVehicle* ptr = static_cast(obj);
return ptr->getTire(0)? ptr->getTire(0)->getId(): 0;
}

//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Console Methods
//----------------------------------------------------------------------------
void WheeledVehicle::consoleInit()
{
Con::addCommand("WheeledVehicle", "getSpringDataBlock", cGetSpringDataBlock, "obj.getSpringDataBlock()", 2, 2);
Con::addCommand("WheeledVehicle", "getTireDataBlock", cGetTireDataBlock, "obj.getTireDataBlock()", 2, 2);

}
//----------------------------------------------------------------------------

ConsoleMethod(WheeledVehicle, setWheelTire, bool, 4, 4, "obj.setWheelTire(wheel#,tire)")
{
WheeledVehicle* wv = static_cast(object);
WheeledVehicleTire* tire;
if (Sim::findObject(argv[3],tire)) {
S32 wheel = dAtoi(argv[2]);
if (wheel >= 0 && wheel < wv->getWheelCount()) {
wv->setWheelTire(wheel,tire);
return true;
}
else
Con::warnf("setWheelTire: wheel index out of bounds, vehicle has %d hubs",
argv[3],wv->getWheelCount());
}
else
Con::warnf("setWheelTire: %s datablock does not exist (or is not a tire)",argv[3]);
return false;
}

ConsoleMethod(WheeledVehicle, setWheelSpring, bool, 4, 4, "obj.setWheelSpring(wheel#,spring)")
{
WheeledVehicle* wv = static_cast(object);
WheeledVehicleSpring* spring;
if (Sim::findObject(argv[3],spring)) {
S32 wheel = dAtoi(argv[2]);
if (wheel >= 0 && wheel < wv->getWheelCount()) {
wv->setWheelSpring(wheel,spring);
return true;
}
else
Con::warnf("setWheelSpring: wheel index out of bounds, vehicle has %d hubs",
argv[3],wv->getWheelCount());
}
else
Con::warnf("setWheelSpring: %s datablock does not exist (or is not a spring)",argv[3]);
return false;
}

think thats it...:)
#4
07/04/2002 (11:27 am)
Kevin, did u get it to work?
#5
07/08/2002 (4:18 pm)
I've been caught up with a bunch of other things, but I'm going to give it a go tonight... Thanks for the help.
#6
07/09/2002 (11:25 am)
No luck, I think it's just because of my lacking C++ skills, but I can't get it to compile. Do I need to add all this to the files, or are these just changes that need to be made?
#7
07/12/2002 (2:15 pm)
great work, thank you Zachary. To get the spring and tire sections work, I needed to modify a bit.

add this to wheeledVehicle.h in class Wheeled Vehicle
public:
   WheeledVehicleTire* getTire(S32 wheel);
   WheeledVehicleSpring* getSpring(S32 wheel);

add this to wheeledVehicle.cc
WheeledVehicleTire* WheeledVehicle::getTire(S32 wheel)
{
   return mWheel[wheel].tire;
}

WheeledVehicleSpring* WheeledVehicle::getSpring(S32 wheel)
{
   return mWheel[wheel].spring;
}
#8
07/13/2002 (11:56 pm)
Alexander:
yep that sould do it but u also need to export the functions to the datablock.

i assume u did that also to get it working..?
or is there another way?

Kevin:
whats the error say?
#9
07/22/2002 (8:14 am)
Is the zip updated?
#10
07/22/2002 (6:13 pm)
hehehe.... I made something like this about a year ago... :)

The idea here is just to let you tweak datablock values in real-time, right?

Well, here's how I did it (It's quite a bit simpler):
1. Open up whatever datablock you want to edit.
2. Open up some .cs file with lots of lines that have "$preff::" on them, like defaults.cs or something.
3. Copy and paste the data from the datablock into the preffs file.
4. Add "$preff::" before each (without the quotes obviously)
5. Go back to the datablock, and replace all of the actual data with $preff:NameOfVariable For example, instead of PlayerSpeed = 1 you would have PlayerSpeed = $preff::PlayerSpeed
6. Make a gui that has a whole bunch of text edit fields. Assign a $preff:: to each.
7. Put a button on the gui and link it to a function that simply has:
exec("whatever the datablock and correct path is"); This will re-read all of those nice things in the datablock, which redirects the program to the appropriate pref, which you changed by editing the text field.

Obviously, this wont work over the net, but I dont think you want to be doing that anyway.

I hope someone finds this useful, if they ever want to edit any other datablocks or whatever. Its kind of hackish, but hey, it works, and you will only use it for tweaking and debugging anyway, so why not? :)
#11
01/07/2008 (7:28 am)
@josh
Thanks for the tip. :)