MountImage with mount point for T3D1.1b3
by Vince Gee · 11/15/2010 (10:37 pm) · 2 comments
This is based on Xavier "eXoDuS" Amado 's resource:
http://www.torquepowered.com/community/resources/view/5677
and
weihua resource:
http://www.torquepowered.com/community/resources/view/20189
This fixes some issues that T3D Beta 3 brought in. Works over network as well.
usage:
player.mountimage(shapebaseimage,slot,mountpoint);
Warning, it will only go up to the 7th mount point.
Also, you can only bind the shapebaseimage to one mount point, so if you want to duel wield a weapon.... you still need 2 datablocks one for each bind point. If anyone finds a work around for this please let me know.
To implement it, Just add or remove the code between the
.
.
Vince
shapeBase.cpp
Around line 3184
Around line 3920
Around line 707
http://www.torquepowered.com/community/resources/view/5677
and
weihua resource:
http://www.torquepowered.com/community/resources/view/20189
This fixes some issues that T3D Beta 3 brought in. Works over network as well.
usage:
player.mountimage(shapebaseimage,slot,mountpoint);
Warning, it will only go up to the 7th mount point.
Also, you can only bind the shapebaseimage to one mount point, so if you want to duel wield a weapon.... you still need 2 datablocks one for each bind point. If anyone finds a work around for this please let me know.
To implement it, Just add or remove the code between the
//http://www.torquepowered.com/community/resources/view/20189.
.
.
//************************
Vince
shapeBase.cpp
Around line 3184
if (stream->writeFlag(mask & ImageMask)) {
for (int i = 0; i < MaxMountedImages; i++)
if (stream->writeFlag(mask & (ImageMaskN << i))) {
MountedImage& image = mMountedImageList[i];
if (stream->writeFlag(image.dataBlock))
stream->writeInt(image.dataBlock->getId() - DataBlockObjectIdFirst,
DataBlockObjectIdBitSize);
//http://www.torquepowered.com/community/resources/view/20189
stream->writeInt(image.mountPoint, 3);
Con::printf("ShapeBase::packUpdate: Sending mount point of %d",image.mountPoint);
//************************
con->packNetStringHandleU(stream, image.skinNameHandle);
stream->writeFlag(image.wet);
stream->writeFlag(image.ammo);
stream->writeFlag(image.loaded);
stream->writeFlag(image.target);
stream->writeFlag(image.triggerDown);
stream->writeFlag(image.altTriggerDown);
stream->writeInt(image.fireCount,3);
stream->writeFlag(isImageFiring(i));
}Around line 3320for (int i = 0; i < MaxMountedImages; i++) {
if (stream->readFlag()) {
MountedImage& image = mMountedImageList[i];
ShapeBaseImageData* imageData = 0;
if (stream->readFlag()) {
SimObjectId id = stream->readInt(DataBlockObjectIdBitSize) +
DataBlockObjectIdFirst;
if (!Sim::findObject(id,imageData)) {
con->setLastError("Invalid packet (mounted images).");
return;
}
}
//http://www.torquepowered.com/community/resources/view/20189
image.mountPoint = stream->readInt(3);
Con::printf("ShapeBase::unpackUpdate: Mount Point is %d", image.mountPoint);
//************************
NetStringHandle skinDesiredNameHandle = con->unpackNetStringHandleU(stream);
image.wet = stream->readFlag(); Around line 3920
//----------------------------------------------------------------------------
//http://www.torquepowered.com/community/resources/view/20189
//DefineEngineMethod( ShapeBase, mountImage, bool,
// ( ShapeBaseImageData* image, S32 slot, bool loaded, const char* skinTag ), ( true, "" ),
// "Mount a new Image.n"
// "@param image the Image to mountn"
// "@param slot Image slot to mount into (valid range is 0 - 3)n"
// "@param loaded initial loaded state for the Imagen"
// "@param skinTag tagged string to reskin the mounted Imagen"
// "@return true if successful, false if failednn"
// "@tsexamplen"
// "%player.mountImage( PistolImage, 1 );n"
// "%player.mountImage( CrossbowImage, 0, false );n"
// "%player.mountImage( RocketLauncherImage, 0, true, 'blue' );n"
// "@endtsexamplen" )
//{
// if (image && slot >= 0 && slot < ShapeBase::MaxMountedImages) {
//
// NetStringHandle team;
// if (skinTag[0] == StringTagPrefixByte)
// team = NetStringHandle(U32(dAtoi(skinTag+1)));
//
// object->mountImage( image, slot, loaded, team );
// }
// return false;
//}
DefineEngineMethod( ShapeBase, mountImage, bool,
( ShapeBaseImageData* image, S32 slot, S32 mount, bool loaded, const char* skinTag ), ( 0, -1, true, "" ),
"Mount a new Image.n"
"@param image the Image to mountn"
"@param slot Image slot to mount into (valid range is 0 - 3)n"
"@param loaded initial loaded state for the Imagen"
"@param skinTag tagged string to reskin the mounted Imagen"
"@return true if successful, false if failednn"
"@tsexamplen"
"%player.mountImage( PistolImage, 1 );n"
"%player.mountImage( CrossbowImage, 0, false );n"
"%player.mountImage( RocketLauncherImage, 0, true, 'blue' );n"
"@endtsexamplen" )
{
if (image && slot >= 0 && slot < ShapeBase::MaxMountedImages) {
NetStringHandle team;
if (skinTag[0] == StringTagPrefixByte)
team = NetStringHandle(U32(dAtoi(skinTag+1)));
//object->mountImage( image, slot, loaded, team );
object->mountImage( image, slot, mount, loaded, team );
}
return false;
}
//************************ShapeBase.hAround line 707
NetStringHandle nextSkinNameHandle;
String appliedSkinName;
//http://www.torquepowered.com/community/resources/view/20189
S32 mountPoint;
//************************
/// @name StateAround line 1297/// @name Mounted Images
/// @{
/// Mount an image (ShapeBaseImage) onto an image slot
/// @param image ShapeBaseImage to mount
/// @param imageSlot Image mount point
/// @param loaded True if weapon is loaded (it assumes it's a weapon)
/// @param skinNameHandle Skin name for object
//http://www.torquepowered.com/community/resources/view/20189
//virtual bool mountImage(ShapeBaseImageData* image,U32 imageSlot,bool loaded, NetStringHandle &skinNameHandle);
virtual bool mountImage(ShapeBaseImageData* imageData,U32 imageSlot, S32 mount, bool loaded, NetStringHandle &skinNameHandle);
//************************
/// Unmount an image from a slot
/// @param imageSlot Mount point
virtual bool unmountImage(U32 imageSlot);
[code]
ShapeImage.cpp
Around line 898
[code]
ShapeBase::MountedImage::MountedImage()
{
shapeInstance = 0;
state = 0;
dataBlock = 0;
//http://www.torquepowered.com/community/resources/view/20189
mountPoint = -1;
//************************
nextImage = InvalidImagePtr;
delayTime = 0;
ammo = false;
target = false;
Around line 976
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Any item with an item image is selectable
//http://www.torquepowered.com/community/resources/view/20189
//bool ShapeBase::mountImage(ShapeBaseImageData* imageData,U32 imageSlot,bool loaded,NetStringHandle &skinNameHandle)
//{
// AssertFatal(imageSlot<MaxMountedImages,"Out of range image slot");
//
// MountedImage& image = mMountedImageList[imageSlot];
// if (image.dataBlock) {
// if ((image.dataBlock == imageData) && (image.skinNameHandle == skinNameHandle)) {
// // Image already loaded
// image.nextImage = InvalidImagePtr;
// return true;
// }
// }
// //
// setImage(imageSlot,imageData,skinNameHandle,loaded);
//
// return true;
//}
bool ShapeBase::mountImage(ShapeBaseImageData* imageData,U32 imageSlot, S32 mount, bool loaded, NetStringHandle &skinNameHandle)
{
AssertFatal(imageSlot<MaxMountedImages,"Out of range image slot");
Con::printf("ShapeBase::mountImage: puting imagedata %s imageslot %d mount %d", imageData->getClassName(),imageSlot,mount);
MountedImage& image = mMountedImageList[imageSlot];
// If no mount point was specified get the value from the datablock.
Con::printf("ShapeBase::mountImage: puting item in mount %d", mount);
if( mount == -1 )
{
Con::printf("ShapeBase::mountImage no mountpoint specified");
mount = imageData->mountPoint;
}
if (image.dataBlock) {
if ((image.dataBlock == imageData) && (image.skinNameHandle == skinNameHandle && image.mountPoint == mount)) {
// Image already loaded
image.nextImage = InvalidImagePtr;
Con::printf("ShapeBase::exiting prior to setting mountpoint");
return true;
}
}
Con::printf("ShapeBase::mountImage setting mountpoint %d", mount);
imageData->mountPoint = mount;
Con::printf("ShapeBase::checking mountImage setting mountpoint %d", mount);
//
setImage(imageSlot,imageData,skinNameHandle,loaded);
setMaskBits(ImageMaskN << imageSlot);
return true;
}Around line 1382MatrixF nmat;
if ( !noEyeOffset && data.useEyeOffset && isFirstPerson() )
{
getRenderEyeTransform(&nmat);
mat->mul(nmat,data.eyeOffset);
}
else
{
//http://www.torquepowered.com/community/resources/view/20189
//getRenderMountTransform( 0.0f, data.mountPoint, MatrixF::Identity, &nmat );
getRenderMountTransform( 0.0f, image.mountPoint, MatrixF::Identity, &nmat );
Con::printf("ShapeBase::getRenderImageTransform: Mount Point is %d", image.mountPoint);
//************************
mat->mul(nmat,data.mountTransform);
}
}Around line 1611// Otherwise, init the new shape.
image.dataBlock = imageData;
//http://www.torquepowered.com/community/resources/view/20189
if (!isGhost()) {
image.mountPoint=imageData->mountPoint;
}
else
{
imageData->mountPoint =image.mountPoint;
}
//*****************About the author
www.winterleafentertainment.com

Torque Owner Szzg007
super pig-head Studio