Game Development Community

Rts Port To Tgea

by Johnathan Moore · in RTS Starter Kit · 05/06/2006 (2:45 pm) · 62 replies

Hey, I have tried to port the rts starter kit over to the latest TSE. I have solved nearly all the errors apart from lot of files need a file dgl/dgl.h. It either stands for somthing to do with open gl or dynamic game lighting(could someone clear that up) either way this hasnt been intergrated into TSE yet. So has anyone managed to port the RTS kit to TSE yet?, or all but the selection circles on atlas.

the other errors I get are
#include <d3d9.h>
&
#include <dinput.h>

but that may be because I am using vc2005

Edit: after installing the directx sdk propally I am left with only the dgl error
Page «Previous 1 2 3 4 Last »
#1
05/06/2006 (5:52 pm)
On my system I find the file referenced 2x in the default
install and about 20 others with my svn and additional directories

C:\Torque\SDK\engine\dgl
C:\Torque\RTSStarterKit\engine\dgl


seems like you have either no dgl.h in the directory C:\Torque\SDK\engine\dgl

file stats 12.5 KB (12,816 bytes) size on disk ; 16.0 KB (16,384 bytes)

created Wednesday, November 23, 2005, 1:54:43 AM
modified Wednesday, November 23, 2005, 1:54:43 AM

or ..
you have a support file .cc .rc or .h that calls for the file and has the path wrong

open compiler and load solution
clean the build of torqueDemo (torqueDemo_Debug.exe)
then build again
find the error in the output log
find the last refenced file (not the .obj) in the list before
the error/warning
open that file if using Microsoft Visual C++ 2005 Express Edition
just double click on the line with dgl.h error in it should open for edit
do a ctrl+f (insert dgl.h) for text and search (F3 will keep searching for next)
you should I expect find a refence #include line near top of file with wrong dir

IN dgl.cc there is this reference and its correct
#include "dgl/dgl.h"

however not ALL references will be with C:\Torque\SDK\engine\ as the default path
so #include "dgl/dgl.h" if the base path is C:\Torque\SDK\example\common
wont find the file (header file) when needed

I hope this helps if not post the exact text for the block that produces the error
should actually be fairly easy to locate the source
#2
05/07/2006 (2:09 am)
There is no dgl.h in TSE. Have a look in gfxdevice.h for the things you are probably seeking.

For example. Instead of:

dglDrawLine( x1, y1, x2, y2, colour );

you now do:

GFX->drawLine( x1, y1, x2, y2, colour );
#3
05/07/2006 (2:12 am)
Ok thanks
#4
05/19/2006 (4:01 am)
Will there be a RTS TSE port when it has been released?
#5
05/19/2006 (4:22 am)
Ok here is what you have to change the dgl namespace to

glDisable(GL_LIGHTING);
GFX->setLightingEnable(false);

glPushMatrix();
GFX->pushWorldMatrix();

dglMultMatrix(&getRenderTransform());
GFX->multWorld(getRenderTransform());

glDisable(GL_DEPTH_TEST);
GFX->setZEnable(false);

glColor3f(1, 1, 1);
wireCube(Point3F(0.1,0.1,0.1),mDataBlock->massCenter);
GFX->drawWireCube(Point3F(0.1,0.1,0.1),mDataBlock->massCenter, ColorI(255, 255, 255));

glPopMatrix();
GFX->popWorldMatrix();

dglMultMatrix(-----);
GFX->multWorld( const MatrixF &mat )

dglProjectRadius
GFX->projectRadius

dglDrawLine( x1, y1, x2, y2, colour );
GFX->drawLine( x1, y1, x2, y2, colour );
#6
05/24/2006 (10:10 am)
I ported the RTS pack over to TSE the other day. I'm still working on some things, there are no target circles at the moment, though I'm not sure I want them. There is also no map, I'm looking into rigging that up with some map code I wrote for an FPS project a few months ago.

If your having problems with a specific function feel free to poke me and I'll post code.

On a sidenote I haven't yet gotten it working with Atlas terrain, only with legacy terrain under TSE. Will figure it out, but at the moment it's crashing when you click Atlas terrain.
#7
05/26/2006 (11:47 am)
At the moment all the RTS files rendering code is basically trash, I tried just replacing the dgl functions with gfx ones but that doesnt seem to work. This may be a useful or useless peice of knowledge but it may be somthing like atlas doesnt work with the getterrainheight command.

I have problems with:

A file named splash with the identifier TextureHandle (Unknown Identifier)

RTSUnit::Renderimage function, could you please send me yours?

RTSPathDebug::RenderObject, could you please send?

RTSBuilding - Texturehandle and setoveride texture

RTSBuilding::RenderObject

GuiRTSTSCtrl::onRender

GuiRTSTSCtrl::drawDamage

more texture handle stuff...

GuiMapHud::onRender

GuiMapHud::rebuildMapOld()

GuiMapHud::setupRender

more texture handle stuff...

could you please help..
#8
05/26/2006 (9:12 pm)
TextureHandle = GFXTexhandle

RTSUnit::RenderImage

GFX->pushWorldMatrix();

   MatrixF mat = getRenderTransform();
   mat.scale( mObjScale );
   GFX->setWorldMatrix( mat );

   mShapeInstance->animate();
   mShapeInstance->render();


   GFX->popWorldMatrix();

RTSPathDebug: I simply removed this whole area it is for drawing lines to destinations, we didn't need it and it saved time.

RTSBuilding::RenderObject

MatrixF proj = GFX->getProjectionMatrix();

   RectI viewport = GFX->getViewport();


   // hack until new scenegraph in place
   MatrixF world = GFX->getWorldMatrix();
   TSMesh::setCamTrans( world );
   TSMesh::setSceneState( state );
   TSMesh::setGlow( image->glow );
   TSMesh::setRefract( image->sortType == SceneRenderImage::Refraction );


      // render mesh
      GFX->pushWorldMatrix();

      MatrixF mat = getRenderTransform();
      mat.scale( mObjScale );
      GFX->setWorldMatrix( mat );

      mShapeInstance->animate();
      mShapeInstance->render();

      GFX->popWorldMatrix();


   GFX->setProjectionMatrix( proj );
   GFX->setViewport( viewport );

RTSTSCtrl::OnRender

Parent::onRender(offset, updateRect);

   RTSConnection* conn = dynamic_cast<RTSConnection*>(NetConnection::getConnectionToServer());

   if(!conn)
      return;

   // setup GL for selection info rendering
   GFX->setClipRect(updateRect);
//   dglSetClipRect(updateRect);
//   glDisable     (GL_CULL_FACE);
//   glEnable      (GL_BLEND);
//   glBlendFunc   (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   GFX->setCullMode( GFXCullNone );
   GFX->setAlphaBlendEnable(true);
   GFX->setSrcBlend(GFXBlendSrcAlpha);
   GFX->setDestBlend(GFXBlendInvSrcAlpha);
//   glLineWidth(4.f);	// not sure what to chang ethis too or if needed

   // highlight selected objects
   for(S32 i=0; i<getSelectionSize(); i++)
   {
      if(mDragSelected.objInSet(mSelected[i]) || (const SceneObject *)mHitObject == mSelected[i])
         continue;

      drawDamage(mSelected[i]);
   }

   if(bool(mHitObject))
   {
      drawDamage(mHitObject);
   }

   // change gl states back
 //  glLineWidth(1.f);
   GFX->setCullMode (GFXCullCW);
   GFX->setAlphaBlendEnable(false);
//   glDisable( GL_BLEND );
//   glEnable(GL_CULL_FACE);

   // drag selection update based on worldEditor
   //   defined in engine/editor/worldEditor line 2379
   if(mDragSelect)
   {
      // Draw drag selection box
      //dglDrawRect(mDragRect, mDragRectColor);
		GFX->drawRect(mDragRect, mDragRectColor);

      Con::executef(this, 1, "dragClearSelection");

      Vector<SceneObject *> objects;
      gClientContainer.findObjects(0xFFFFFFFF, findObjectsCallback, &objects);
      for(S32 i = 0; i < objects.size(); i++)
      {
         SceneObject * obj = objects[i];

         // -- PROBLEM IS RIGHT HERE -pw

         Box3F box = obj->getObjBox();
         RTSConnection* conn = (RTSConnection*)NetConnection::getConnectionToServer();
         RTSCamera* camera = dynamic_cast<RTSCamera*>( conn->getControlObject() );
         F32 dist = camera->getCurrHeight();
         F32 radius = getMax( box.max.x - box.min.x, box.max.y - box.min.y );
//         F32 renderRadius = dglProjectRadius( dist, radius ) / 3.f;
         F32 renderRadius = GFX->projectRadius( dist, radius ) / 3.f;
		 RectI modifiedRect( mDragRect.point.x - renderRadius, mDragRect.point.y - renderRadius,
                             mDragRect.extent.x + renderRadius * 2, mDragRect.extent.y + renderRadius * 2 );

         //dglDrawRect( modifiedRect, ColorI( 255, 0, 0 ) );

         Point3F wPos;
         obj->getTransform().getColumn(3, &wPos);

//         dglProjectRadius( dist, radius );
		 GFX->projectRadius( dist, radius);

         Point3F sPos;
         if(project(wPos, &sPos))
            if(mDragSelect && modifiedRect.pointInRect(Point2I((S32)sPos.x, (S32)sPos.y)))
                  Con::executef(this,
                     2,
                     "updateDragSelect",
                     obj->getIdString());
      }

      // Clean up from rubber band box.
 //     glDisable(GL_BLEND);
 //     glEnable(GL_TEXTURE_2D);
	  GFX->setAlphaBlendEnable(false);
//	  I think that becomes
	   GFX->setTextureStageColorOp(0, GFXTOPModulate);
	   GFX->setTextureStageColorOp(1, GFXTOPDisable);

   }


   renderChildControls(offset, updateRect);

RTSTSCtrl::drawdamage:

Point3F res;
   const SphereF wSph = obj->getWorldSphere();
   Point3F objPos = obj->getPosition();
   objPos.z += obj->getObjBox().max.z - obj->getObjBox().min.z;

   if(project(objPos, &res))
   {
      // Get distance to object from camera
      Point3F camPos, objPos;

      objPos = wSph.center;
      unproject( Point3F( 0, 0, 0), &camPos);

      F32 dist   = (camPos - objPos).len();
//      F32 width = dglProjectRadius(dist, wSph.radius) + 5;
	    F32 width = GFX->projectRadius(dist, wSph.radius) + 5;
//      Point2I offset(res.x - width / 2,(S32)(res.y - (2*dglProjectRadius(dist, wSph.radius))));
      Point2I offset(res.x - width / 2,(S32)(res.y - (2*GFX->projectRadius(dist, wSph.radius))));

      // Damage should be 0->1 (0 being no damage,or healthy), but
      // we'll just make sure here as we flip it.
      if(ShapeBase *object = dynamic_cast<ShapeBase*>(obj))
      {
         //don't draw if dead
         if (object->getDamageState() != Player::Enabled)
            return;

         F32 damage = mClampF(1 - object->getDamageValue(), 0, 1);

         // Center the bar
         RectI rect(offset, Point2I(width, mDamageRectSize.y));
         //rect.point.x -= mDamageRectSize.x / 2;

         // Draw the border
//         dglDrawRect(rect, mDamageFrameColor);
		 GFX->drawRect(rect, mDamageFrameColor);

         // Draw the damage % fill
         rect.point += Point2I(1, 1);
         rect.extent -= Point2I(1, 1);
         rect.extent.x = (S32)(rect.extent.x * damage);
         if (rect.extent.x == 1)
            rect.extent.x = 2;
         if (rect.extent.x > 0)
//            dglDrawRectFill(rect, mDamageFillColor);
				GFX->drawRectFill(rect, mDamageFillColor);
      }
   }

GUIMapHud: This stuff doesn't port easily to TSE, I removed all map hud stuff and will be replacing it with a custom solution when I find some time.

Also to note on the texturehandle stuff you will get an error, but I forget what it is. Post the error and I'll tell you how to fix it if you can't figure out. Basically the format changed slightly on the calls using it, you can find that information in the GFX files, if you can't figure it out though, post the erorr. You get one or two of them.
#9
05/27/2006 (2:06 pm)
Thanks!, your a legand, im adding it in right now
#10
05/28/2006 (1:37 am)
Thanks i've got it all to work apart from the GFXTexhandle texture handle still doesnt exist aparently and

Error 11 error C3861: 'bit': identifier not found c:\doa engine\engine\game\rts\guirtstsctrl.h 49

enum PanEdge {
EdgeNone = bit(0),
EdgeLeft = bit(1),
EdgeRight = bit(2),
EdgeTop = bit(3),
EdgeBottom = bit(4)
};
#11
05/28/2006 (4:31 am)
On the BIT stuff just change the bit to BIT (make them uppercase) and that will compile fine.

I noticed that I commented out the:

mPingTexture = TextureHandle(mPingTextureName, BitmapTexture);

in GuiMapHud.cpp to get it to compile, since I wasn't using the GuiMapHud anyway.

For mOverrideTex I changed the setOverrideTexture function in RTSBuildingMarker to look ilke:

void setOverrideTexture(StringTableEntry f)
   {
      mOverrideFile = f;
      mOverrideTex.set(mOverrideFile,&GFXDefaultStaticDiffuseProfile);
   }

And I think that should be all of it. Wish I had kept better track when I was doing it, but was just a spur of the moment thing and didn't think about it until afterward.

After you get it to compile your going to have to make some script changes to get things to work also, I'm not sure all of those I made. I just did a DIFF of the starter.fps for TSE and the starter.rts and merged how I saw necessary. You will need to add some new files in from TSE, and the shaders directory. It wasn't too hard though, took about an hour total.
#12
05/28/2006 (5:48 am)
You also need to change NetConnection::getConnectionToServer() to NetConnection::getServerConnection()
#13
05/28/2006 (5:51 am)
Everything works now apart from the GFXTexhandle

Error 1 error C2146: syntax error : missing ';' before identifier 'textureHandle' c:\doa engine\engine\game\fx\splash.h 102
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\doa engine\engine\game\fx\splash.h 102
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\doa engine\engine\game\fx\splash.h 102

GFXTexhandle     textureHandle[NUM_TEX];

edit
dont worry grrr case sensitive its supposed to be GFXTexHandle


edit2

only this doesnt work for some reason:

F32              mTransVal;
   StringTableEntry mOverrideFile;
   GFXTexHandle    mOverrideTex;
   TSThread *mThread;

Error 1 error C2146: syntax error : missing ';' before identifier 'mOverrideTex' c:\doa engine\engine\game\rts\rtsbuilding.h 31
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\doa engine\engine\game\rts\rtsbuilding.h 31
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\doa engine\engine\game\rts\rtsbuilding.h 31
Error 4 error C2065: 'mOverrideTex' : undeclared identifier c:\doa engine\engine\game\rts\rtsbuilding.h 58
Error 5 error C2228: left of '.set' must have class/struct/union c:\doa engine\engine\game\rts\rtsbuilding.h 58
Error 6 error C2065: 'GFXDefaultStaticDiffuseProfile' : undeclared identifier c:\doa engine\engine\game\rts\rtsbuilding.h 58
Error 7 error C2371: 'GFXDefaultStaticDiffuseProfile' : redefinition; different basic types c:\doa engine\engine\gfx\gfxtextureprofile.h 142
#14
05/28/2006 (6:51 am)
Ah that was because I didnt include #include "gfx/gfxTextureHandle.h"

Yep it now works apart from the features left out. I had a bit of trouble with a missing directx file for a while
#15
06/14/2006 (3:13 am)
How are you doing with the terrain?, did you change anything in terrselect.cc for the legacy terrain?
#16
07/29/2006 (4:22 am)
Oooppsss... I missed this thread :)
@Josh and J.C. : I'm near to have a solution. But Atlas Terrain is really different of Legacy Terrain.
* The second one uses "standard" tris, against "error metrics" tris
* UV calculation is different
* Atlas uses many chunks to render terrain (against legacy which use one datasource)
* Material rendering optimisation is really important with TSE.
* and many other small stuffs...

But I think I'm near to have a solution :)
#17
07/30/2006 (10:25 am)
I haven't had any time to toy with the RTS kit in a couple of months, been tied up. That's good news though, look forward to that and HTC+. =)
#18
08/01/2006 (9:17 am)
So for terrain, I here is a solution to select Atlas Triangles and make a render on it with a material.

First, into atlas/resource/atlasGeomChunk.cpp, add :
F32 calcUV(PlaneF plane, Point3F point, F32 mr)
{
	F32 UV = ((plane.distToPlane(point) / mr) + 1.0) / 2.0;
	// Argh!!! How to ignore UVs outside [0..1] ???
//	while (UV>1.0) 
//	{UV = UV-1.0;}
	return UV;
}


AtlasDiscreteMesh *AtlasGeomChunk::BuildTris(TerrSelectionInfo Sel)
{
   AtlasDiscreteMesh *adm = new AtlasDiscreteMesh;

   // Copy indices.
   adm->mIndexCount = mIndexCount;
   adm->mIndex = new U16[mIndexCount];
   dMemcpy(adm->mIndex, mIndex, sizeof(U16)*mIndexCount);

   // Prep vertices...
   adm->mVertexCount = mVertCount;
   adm->mPos = new Point3F[mVertCount];
   adm->mTex = new Point2F[mVertCount];
   adm->mHasMorphData = false;

   AtlasDiscreteMesh *bdm = new AtlasDiscreteMesh;
   AtlasDiscreteMesh *cdm = new AtlasDiscreteMesh;
   bdm->mIndexCount = mVertCount;
   bdm->mIndex = new U16[mIndexCount];
   bdm->mVertexCount = mVertCount;
   bdm->mPos = new Point3F[mVertCount];
   bdm->mTex = new Point2F[mVertCount];

   U32 mSelVerCount = 0;
	Point3F pmin;
	Point3F pmax;
	pmin.x = Sel.pos.x-Sel.radius;
	pmin.y = Sel.pos.y-Sel.radius;
	pmin.z = Sel.pos.z-Sel.radius;
	pmax.x = Sel.pos.x+Sel.radius;
	pmax.y = Sel.pos.y+Sel.radius;
	pmax.z = Sel.pos.z+Sel.radius;

   // And swizzle vertices out...
	for(S32 i=0; i<(mIndexCount - mSkirtSkipCount) - 1; i+=3)
    {
		// Reject anything degenerate...
        if(mIndex[i+0] == mIndex[i+1] || mIndex[i+1] == mIndex[i+2] || mIndex[i+2] == mIndex[i+0])
               continue;
		// Get the plane normal
		Point3F point1 = mVert[mIndex[i+0]].point;
		Point3F point2 = mVert[mIndex[i+1]].point;
		Point3F point3 = mVert[mIndex[i+2]].point;
		
		Box3F box(pmin.x,pmin.y,pmin.z,pmax.x,pmax.y,pmax.z);
		if (!triBoxOverlap(box,point1,point2,point3)) {continue;}
		Point3F normal;
		mCross((point1 - point2), (point3 - point2), &normal);
		if (normal.lenSquared() < 1e-7)
		{
			//pTri->flags = 0;
			continue;
		}
		PlaneF plane(point2, normal);  // Assumes that mPlane.h normalizes incoming point
		Point3F centerPoint;
		F32 d = plane.distToPlane(Sel.pos);
		d = mFabs(d);
		if (d >= Sel.radius) {
			continue;
		}

		centerPoint = Sel.pos - plane * d;

		F32 mr = mSqrt(Sel.radiusSquared - d*d);

		Point3F normalS;
		Point3F normalT;
		mCross(plane, Point3F(1, 0, 0), &normalS);
		mCross(plane, normalS, &normalT);
		PlaneF splane(centerPoint, normalS); // Assumes that mPlane.h normalizes incoming point
		PlaneF tplane(centerPoint, normalT); // Assumes that mPlane.h normalizes incoming point
		   
		bdm->mIndex[mSelVerCount+0] = mSelVerCount+0;
		bdm->mIndex[mSelVerCount+1] = mSelVerCount+1;
		bdm->mIndex[mSelVerCount+2] = mSelVerCount+2;
		bdm->mPos[mSelVerCount+0] = point1;
		bdm->mPos[mSelVerCount+1] = point2;
		bdm->mPos[mSelVerCount+2] = point3;
// Add Z Offset to make it appear above the terrain (there is probably a better solution)
		bdm->mPos[mSelVerCount+0].z+=0.01;
		bdm->mPos[mSelVerCount+1].z+=0.01;
		bdm->mPos[mSelVerCount+2].z+=0.01;

		bdm->mTex[mSelVerCount+0].set(calcUV(splane,point1,mr),
									  calcUV(tplane,point1,mr));
		bdm->mTex[mSelVerCount+1].set(calcUV(splane,point2,mr),
									  calcUV(tplane,point2,mr));
		bdm->mTex[mSelVerCount+2].set(calcUV(splane,point3,mr),
									  calcUV(tplane,point3,mr));


		mSelVerCount = mSelVerCount+3;


   }

   // Copy indices.
   cdm->mIndexCount = mSelVerCount;
   cdm->mIndex = new U16[mSelVerCount];

   // Prep vertices...
   cdm->mVertexCount = mSelVerCount;
   cdm->mPos = new Point3F[mSelVerCount];
   cdm->mTex = new Point2F[mSelVerCount];
   cdm->mHasMorphData = false;

	for (int ii=0;ii<mSelVerCount;ii++)
	{
		cdm->mIndex[ii] = bdm->mIndex[ii];
		cdm->mPos[ii] = bdm->mPos[ii];
		cdm->mTex[ii] = bdm->mTex[ii];
	}
	delete adm;
	delete bdm;
   // All done.
   return cdm;
}

in atlas/resource/atlasGeomChunk.h, add (just after *copyToDiscreteMesh();) :
AtlasDiscreteMesh *BuildTris(TerrSelectionInfo Sel);
#19
08/01/2006 (9:22 am)
Second, in atlas/runtime/atlasInstanceGeomTOC.cpp, add :
AtlasDiscreteMesh *AtlasInstanceGeomTOC::BuildTris(TerrSelectionInfo Sel)
{
   PROFILE_START(AtlasInstanceGeomTOC_BuildTris);

   // We need a stack...
   FrameAllocatorMarker fm;
   StackNode *stack = (StackNode*)fm.alloc(sizeof(StackNode) * (mTreeDepth * 4 + 1));
   U32 stackDepth=0;
   AtlasDiscreteMesh *list;
   // Push the root stub into the stack.
   stack[stackDepth].stub = getStub(0, Point2I(0,0));
   stack[stackDepth].clipMask = FrustrumCuller::AllClipPlanes;
   stackDepth++;

   while(stackDepth)
   {
      // Pop top item from the stack.
      const StackNode snode = stack[--stackDepth];
      StubType *s = snode.stub;

      // Do our clipping.
      const S32 newMask = mCuller.testBoxVisibility(s->mBounds, snode.clipMask, 1.f);

      if(newMask == -1)
      {
         // Not seen, so skip this one.
         continue;
      }

      // Draw ourselves. :)
      if(getResourceStub(s)->mChunk && !s->isSplit())
      {
	
		Box3F bounds = getResourceStub(s)->mChunk->getBounds();
		 if (bounds.isContained(Sel.pos)) {
			list = getResourceStub(s)->mChunk->BuildTris(Sel);
		}
      }

      // If I'm not maxed out on LOD, don't draw me.
      if(!s->isSplit())
         continue;

      // Recurse.
      if(s->hasChildren())
      {
         for(S32 i=0; i<4; i++)
         {
            stack[stackDepth].stub = s->mChildren[i];
            stack[stackDepth].clipMask = newMask;
            stackDepth++;
         }
      }
   }
   PROFILE_END();
   return list;
}

in atlas/runtime/atlasInstanceGeomTOC.h, add (just after void renderGeometry();) :
AtlasDiscreteMesh *BuildTris(TerrSelectionInfo Sel);
#20
08/01/2006 (9:24 am)
Thrid, in atlas/runtime/atlasInstance2.h, add :
struct TerrSelectionInfo
{
   Point3F pos;       ///< world position
   F32 radius;        ///< radius of the light
   F32 radiusSquared; ///< radius^2
   F32 r, g, b;

   F32 distSquared; // distance to camera
};
Page «Previous 1 2 3 4 Last »