Yes, I can reproduce the problem with the SDK tutorials. I tried using the World with Character tutorial. I modified it to use a third person camera so I can follow the character around and I also increased the player's speed to 10, just so I can run around a bit quicker. You also need to comment out the line that switches v-sync on to get the true frame rate. Finally I added some text in the corner to display the fps and the state draw time.
I then just created a flat 4x4 area world, randomly painted 5 textures across and added the player character to it. I then changed the tutorial to load that world instead of the sample world... and start running around.
Here is the complete code.
Code:
/******************************************************************************/
#include "stdafx.h"
#include "../../../../../data/enum/_enums.h"
/******************************************************************************
In this tutorial is presented how to combine extending base classes with World Manager usage
/******************************************************************************/
STRUCT(Player , Game::Chr) // extend character structure by defining a player class based on the character
//{
Memx<Game::Item> items; // here is the characters inventory, a container of items
virtual Memx<Game::Obj>* itemContainer() {Memx<Game::Obj> &items=T.items; return &items;} // override default method of character, to return proper item container
void updateItems(); // update items actions
virtual Bool update (); // here we'll update the player
};
/******************************************************************************/
Game::ObjMemx<Game::Static> Statics; // container for static objects
Game::ObjMemx<Game::Item > Items ; // container for item objects
Game::ObjMemx< Player> Players; // container for player objects
/******************************************************************************/
void Player::updateItems()
{
if(Kb.bp(KB_1)) // try to pickup an item
if(Items.elms()) // if world items container has some elements
itemPickUp(Items[0]); // pick up the first valid item
if(Kb.bp(KB_2)) // try to drop down an item
if(items.elms()) // if inventory has some items
itemDropDown(items[0]); // drop down the first item
if(!Kb.alt())grabStop();else // if don't want to grab
{
if(grab.is()) // if already grabbing
{
Vec pos;
SinCos(pos.z,pos.x,angle.x+PI_2); // set direction according to player angle
pos *=ctrl.radius()+0.5; // set radius according to player controller radius
pos.y=ctrl.height()*0.4; // set vertical position
pos +=T.pos();
grab.pos(pos); // set desired grab position
}else
if(Items.elms()) // if isn't grabbing anything check for presence of world items
{
grabStart(Items[0]); // grab first present
}
}
}
/******************************************************************************/
Bool Player::update()
{
if(action)
{
if(Kb.b(KB_W) || Kb.b(KB_S) || Kb.b(KB_A) || Kb.b(KB_D) || Kb.b(KB_Q) || Kb.b(KB_E))actionBreak();
}
if(!action)
{
// turn & move
input.anglei.x=Kb.b(KB_Q)-Kb.b(KB_E);
input.anglei.y=Kb.b(KB_T)-Kb.b(KB_G);
input.diri .x=Kb.b(KB_D)-Kb.b(KB_A);
input.diri .z=Kb.b(KB_W)-Kb.b(KB_S);
input.diri .y=Kb.b(KB_SPACE)-Kb.b(KB_LSHIFT);
// dodge, crouch, walk, jump
input.dodge = Kb.bd(KB_D)-Kb.bd(KB_A);
input.crouch= Kb.b (KB_LSHIFT);
input.walk = Kb.b (KB_LCTRL );
input.jump =(Kb.bp(KB_SPACE ) ? 3.5 : 0);
// mouse turn
Flt max=DegToRad(900)*Time.d(),
dx =Ms.dir_ds.x*1.7,
dy =Ms.dir_ds.y*1.7*Ms.inv();
angle.x-=Mid(dx,-max,max);
angle.y+=Mid(dy,-max,max);
// ready stance change
ready^=Kb.bp(KB_R);
}
speed = 10;
updateItems();
return __super::update();
}
/******************************************************************************/
void InitPre()
{
App.name("World with Character");
App.flag=APP_MS_EXCLUSIVE|APP_FULL_TOGGLE;
IOPath("../data");
Paks.add("engine.pak");
}
/******************************************************************************/
Bool Init()
{
Text_ds.scale*=0.8;
Physics.create(CSS_NONE,true,"../Installation/PhysX");
Sun.image=Images("gfx/sky/sun.gfx");
Sky.atmospheric();
// create the world
Game::World.init()
.setObjType(Statics,OBJ_STATIC)
.setObjType(Players,OBJ_PLAYER) // please note that here we'll use 'Players' memory container for 'OBJ_PLAYER' objects
.setObjType(Items ,OBJ_ITEM )
.New("world/test6.world");
return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Update()
{
if(Kb.bp(KB_ESC))return false;
Game::World.update(Cam.at); // update world to given position
Cam.dist=Max(1.0f,Cam.dist*ScaleFactor(Ms.wheel()*-0.1)); // update camera distance according to mouse wheel
Cam.setSpherical(Players[0].pos()+Vec(0,0.5,0), Players[0].angle.x, Players[0].angle.y, 0, Cam.dist); // set spherical camera looking at player position with given player angles
// after setting camera position and angles:
Cam.updateVelocities().set(); // update camera velocities and activate it
return true;
}
/******************************************************************************/
void Render()
{
Game::World.draw();
}
void Draw()
{
Renderer(Render);
D.text(0,0.9,"Press WSAD keys to move, 1/2 to pick up/drop item, Alt to grab");
if(Players.elms())D.text(0,0.8,S+"Items in inventory : "+Players[0].items.elms());
D.text(D.w()-0.2,-D.h()+0.15,S+"Draw "+Time.stateDrawTime());
D.text(D.w()-0.2,-D.h()+0.05,S+Time.fps());
}
/******************************************************************************/
In testing this further, I've noticed another intersting point. The "random" slow downs appear to be happening when moving through certain spots in the world. I'm wondering if it is happening because some spots have move textures blended across them than others (as a result of me randomly painting the terrain).
My frame rate will fluctuate between 900fps and 80fps. When it drops down low there is some slight stuttering (i.e. character movement is not smooth). This isn't really a problem when running around with a character and if the fps display wasn't there, you probably wouldn't notice the issue. However when trying to drive a vehicle around, controlled by physics, which is very sensitive to these fluctuations, it becomes a real problem.
I remember years ago working on a racing car game and we had a similar problem to this when using Physx. We solved the problem with the help of this article. Specifically the section under "The final touch." You're probably already doing this, but just thought I'd throw it out there just in case.
http://gafferongames.com/game-physics/fi...-timestep/
What helped us massively back then, was taking multiple physx simulation steps per frame at a lower time step/precision, rather than a single simulation step at a higher time step.