⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 3 页
字号:
//                         shape->skins[j]->primitives.size(),
//                         shape->skins[j]->indices.size());
//       }
//    }
// }
#endif

ConsoleFunction( getControlObjectAltitude, const char*, 1, 1, "Get distance from bottom of controlled object to terrain.")
{
   GameConnection* connection = GameConnection::getConnectionToServer();
   if (connection) {
      ShapeBase* pSB = connection->getControlObject();
      if (pSB != NULL && pSB->isClientObject())
      {
         Point3F pos(0.f, 0.f, 0.f);

         // if this object is mounted, then get the bottom position of the mount's bbox
         if(pSB->getObjectMount())
         {
            static Point3F BoxPnts[] = {
               Point3F(0,0,0),
               Point3F(0,0,1),
               Point3F(0,1,0),
               Point3F(0,1,1),
               Point3F(1,0,0),
               Point3F(1,0,1),
               Point3F(1,1,0),
               Point3F(1,1,1)
            };

            ShapeBase * mount = pSB->getObjectMount();
            Box3F box = mount->getObjBox();
            MatrixF mat = mount->getTransform();
            VectorF scale = mount->getScale();

            Point3F projPnts[8];
            F32 minZ = 1e30;

            for(U32 i = 0; i < 8; i++)
            {
               Point3F pnt(BoxPnts[i].x ? box.max.x : box.min.x,
                           BoxPnts[i].y ? box.max.y : box.min.y,
                           BoxPnts[i].z ? box.max.z : box.min.z);

               pnt.convolve(scale);
               mat.mulP(pnt, &projPnts[i]);

               if(projPnts[i].z < minZ)
                  pos = projPnts[i];
            }
         }
         else
            pSB->getTransform().getColumn(3, &pos);

         TerrainBlock* pBlock = gClientSceneGraph->getCurrentTerrain();
         if (pBlock != NULL) {
            Point3F terrPos = pos;
            pBlock->getWorldTransform().mulP(terrPos);
            terrPos.convolveInverse(pBlock->getScale());

            F32 height;
            if (pBlock->getHeight(Point2F(terrPos.x, terrPos.y), &height) == true) {
               terrPos.z = height;
               terrPos.convolve(pBlock->getScale());
               pBlock->getTransform().mulP(terrPos);

               pos.z -= terrPos.z;
            }
         }

         char* retBuf = Con::getReturnBuffer(128);
         dSprintf(retBuf, 128, "%g", mFloor(getMax(pos.z, 0.f)));
         return retBuf;
      }
   }

   return "0";
}

ConsoleFunction( getControlObjectSpeed, const char*, 1, 1, "Get speed (but not velocity) of controlled object.")
{
   GameConnection* connection = GameConnection::getConnectionToServer();
   if (connection)
   {
      ShapeBase* pSB = connection->getControlObject();
      if (pSB != NULL && pSB->isClientObject()) {
         Point3F vel = pSB->getVelocity();
         F32 speed = vel.len();

         // We're going to force the formating to be what we want...
         F32 intPart = mFloor(speed);
         speed -= intPart;
         speed *= 10;
         speed  = mFloor(speed);

         char* retBuf = Con::getReturnBuffer(128);
         dSprintf(retBuf, 128, "%g.%g", intPart, speed);
         return retBuf;
      }
   }

   return "0";
}

//--------------------------------------------------------------------------
ConsoleFunction( panoramaScreenShot, void, 3, 3, "(string file, string format)"
                "Take a panoramic screenshot.\n\n"
                "@param format This is either JPEG or PNG.")
{
   S32 numShots = 3;
   if (argc == 3)
      numShots = dAtoi(argv[2]);

   CameraQuery query;
   if (!GameProcessCameraQuery( &query ))
      return;

   SceneObject *object = dynamic_cast<SceneObject*>(query.object);
   if (!object)
      return;

   F32 rotInc = query.fov * 0.75f;

   FileStream fStream;
   GBitmap bitmap;
   Point2I extent = Canvas->getExtent();
   bitmap.allocateBitmap(U32(extent.x), U32(extent.y));
   U8 * pixels = new U8[extent.x * extent.y * 3];


   S32 start = -(numShots/2);
   for (S32 i=0; i<numShots; i++, start++)
   {
      char buffer[256];

      MatrixF rot( EulerF(0.0f, 0.0f, rotInc * F32(start)) );
      MatrixF result;
      result.mul(query.cameraMatrix, rot);

      object->setTransform( result );
      Canvas->renderFrame(false);
      dSprintf(buffer, sizeof(buffer), "%s-%d.png", argv[1], i);

      glReadBuffer(GL_FRONT);
      glReadPixels(0, 0, extent.x, extent.y, GL_RGB, GL_UNSIGNED_BYTE, pixels);

      if(!fStream.open(buffer, FileStream::Write))
      {
         Con::printf("Failed to open file '%s'.", buffer);
         break;
      }

      // flip the rows
      for(U32 y = 0; y < extent.y; y++)
         dMemcpy(bitmap.getAddress(0, extent.y - y - 1), pixels + y * extent.x * 3, U32(extent.x * 3));

	  if ( dStrcmp( argv[2], "JPEG" ) == 0 )
		  bitmap.writeJPEG(fStream);
	  else if( dStrcmp( argv[2], "PNG" ) == 0)
		  bitmap.writePNG(fStream);
	  else
		  bitmap.writePNG(fStream);

      fStream.close();
   }

   delete [] pixels;
}

ConsoleFunctionGroupEnd( GameFunctions );

//------------------------------------------------------------------------------
void GameInit()
{
   // Make sure the exporter draws from the correct directories...
   //
   Con::addVariable("movementSpeed", TypeF32, &gMovementSpeed);
   Con::addVariable("$pref::OpenGL::disableEXTPalettedTexture",     TypeBool, &gOpenGLDisablePT);
   Con::addVariable("$pref::OpenGL::disableEXTCompiledVertexArray", TypeBool, &gOpenGLDisableCVA);
   Con::addVariable("$pref::OpenGL::disableARBMultitexture",        TypeBool, &gOpenGLDisableARBMT);
   Con::addVariable("$pref::OpenGL::disableEXTFogCoord",            TypeBool, &gOpenGLDisableFC);
   Con::addVariable("$pref::OpenGL::disableEXTTexEnvCombine",       TypeBool, &gOpenGLDisableTEC);
   Con::addVariable("$pref::OpenGL::disableARBTextureCompression",  TypeBool, &gOpenGLDisableTCompress);
   Con::addVariable("$pref::OpenGL::noEnvColor",		              TypeBool, &gOpenGLNoEnvColor);
   Con::addVariable("$pref::OpenGL::gammaCorrection",               TypeF32,  &gOpenGLGammaCorrection);	
	Con::addVariable("$pref::OpenGL::noDrawArraysAlpha",				  TypeBool, &gOpenGLNoDrawArraysAlpha);
#if defined(TORQUE_OS_MAC)
   gOpenGLDisableFC = true;
#else
   Con::addVariable("$pref::OpenGL::disableEXTFogCoord", TypeBool, &gOpenGLDisableFC);
#endif

   Con::addVariable("$pref::TS::autoDetail", TypeF32, &DetailManager::smDetailScale);
   Con::addVariable("$pref::visibleDistanceMod", TypeF32, &SceneGraph::smVisibleDistanceMod);

   // updated every frame
   Con::addVariable("cameraFov", TypeF32, &sConsoleCameraFov);

   // Initialize the collision testing script stuff.
   collisionTest.consoleInit();
}

const U32 AudioUpdatePeriod = 125;  ///< milliseconds between audio updates.



#ifdef TGE_RPG
bool RPGProcess(U32 timeDelta)
{
	//RPG::RPGEngine::Process(timeDelta);
	return RPG::g_RPGProcess.AdvanceTime(timeDelta);
}

#endif

bool clientProcess(U32 timeDelta)
{
   ShowTSShape::advanceTime(timeDelta);
   ITickable::advanceTime(timeDelta);

   bool ret = gClientProcessList.advanceClientTime(timeDelta);

   // Run the collision test and update the Audio system
   // by checking the controlObject
   MatrixF mat;
   Point3F velocity;

   if (GameGetCameraTransform(&mat, &velocity))
   {
      alxListenerMatrixF(&mat);
//      alxListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);
      collisionTest.collide(mat);
   }

   // determine if were lagging
   GameConnection* connection = GameConnection::getConnectionToServer();
   if(connection)
      connection->detectLag();

   // alxUpdate is somewhat expensive and does not need to be updated constantly,
   // though it does need to be updated in real time
   static U32 lastAudioUpdate = 0;
   U32 realTime = Platform::getRealMilliseconds();
   if((realTime - lastAudioUpdate) >= AudioUpdatePeriod)
   {
      alxUpdate();
      gAmbientAudioManager.update();
      lastAudioUpdate = realTime;
   }
   return ret;
}

bool serverProcess(U32 timeDelta)
{
   return gServerProcessList.advanceServerTime(timeDelta);
}

static ColorF cubeColors[8] = {
   ColorF(0, 0, 0),
   ColorF(1, 0, 0),
   ColorF(0, 1, 0),
   ColorF(0, 0, 1),
   ColorF(1, 1, 0),
   ColorF(1, 0, 1),
   ColorF(0, 1, 1),
   ColorF(1, 1, 1)
};

static Point3F cubePoints[8] = {
   Point3F(-1, -1, -1),
   Point3F(-1, -1,  1),
   Point3F(-1,  1, -1),
   Point3F(-1,  1,  1),
   Point3F( 1, -1, -1),
   Point3F( 1, -1,  1),
   Point3F( 1,  1, -1),
   Point3F( 1,  1,  1)
};

static U32 cubeFaces[6][4] = {
   { 0, 2, 6, 4 },
   { 0, 2, 3, 1 },
   { 0, 1, 5, 4 },
   { 3, 2, 6, 7 },
   { 7, 6, 4, 5 },
   { 3, 7, 5, 1 }
};

void wireCube(F32 size, Point3F pos)
{
   glDisable(GL_CULL_FACE);

   for (S32 i = 0; i < 6; i++)
   {
      glBegin(GL_LINE_LOOP);
      for(S32 vert = 0; vert < 4; vert++)
      {
         U32 idx = cubeFaces[i][vert];
         glColor3f(cubeColors[idx].red, cubeColors[idx].green, cubeColors[idx].blue);
         glVertex3f(cubePoints[idx].x * size + pos.x, cubePoints[idx].y * size + pos.y, cubePoints[idx].z * size + pos.z);
      }
      glEnd();
   }
}

bool GameProcessCameraQuery(CameraQuery *query)
{
   GameConnection* connection = GameConnection::getConnectionToServer();
   
   if (connection && connection->getControlCameraTransform(0.032f, &query->cameraMatrix))
   {
      query->object = connection->getControlObject();
      query->nearPlane = 0.1f;

      Sky* pSky = gClientSceneGraph->getCurrentSky();

      if (pSky)
         query->farPlane = pSky->getVisibleDistance();
      else
         query->farPlane = 1000.0f;

      F32 cameraFov;
      if(!connection->getControlCameraFov(&cameraFov))
         return false;

      query->fov = mDegToRad(cameraFov);
      query->ortho = false;
      return true;
   }

   return false;
}


struct OutputPoint
{
   Point3F point;
   U8      color[4];
   Point2F texCoord;
   Point2F fogCoord;
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -