- added initial work to better manage rendering (but not yet enabled)
- added new commandline parameter: --version - some thread cleanup to try adjusted timings when threads shutdown
This commit is contained in:
parent
5356a3de23
commit
c7c9e69567
|
@ -26,7 +26,7 @@ using namespace Shared::Platform;
|
|||
namespace Glest{ namespace Game{
|
||||
|
||||
const string mailString= "contact_game@glest.org";
|
||||
const string glestVersionString= "v3.3.5-beta7";
|
||||
const string glestVersionString= "v3.3.5-beta7.1";
|
||||
|
||||
string getCrashDumpFileName(){
|
||||
return "glest" + glestVersionString + ".dmp";
|
||||
|
|
|
@ -33,7 +33,7 @@ using namespace Shared::Platform;
|
|||
namespace Glest{ namespace Game{
|
||||
|
||||
// if FPS is less than this we start to skip 3D renders
|
||||
int MIN_RENDER_FPS_ALLOWED = 15;
|
||||
//int MIN_RENDER_FPS_ALLOWED = 15;
|
||||
|
||||
Game *thisGamePtr = NULL;
|
||||
|
||||
|
@ -54,9 +54,9 @@ Game::Game(Program *program, const GameSettings *gameSettings):
|
|||
this->gameSettings= *gameSettings;
|
||||
scrollSpeed = Config::getInstance().getFloat("UiScrollSpeed","1.5");
|
||||
|
||||
MIN_RENDER_FPS_ALLOWED = Config::getInstance().getInt("MIN_RENDER_FPS_ALLOWED",intToStr(MIN_RENDER_FPS_ALLOWED).c_str());
|
||||
//MIN_RENDER_FPS_ALLOWED = Config::getInstance().getInt("MIN_RENDER_FPS_ALLOWED",intToStr(MIN_RENDER_FPS_ALLOWED).c_str());
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] MIN_RENDER_FPS_ALLOWED = %d\n",__FILE__,__FUNCTION__,__LINE__,MIN_RENDER_FPS_ALLOWED);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] MIN_RENDER_FPS_ALLOWED = %d\n",__FILE__,__FUNCTION__,__LINE__,MIN_RENDER_FPS_ALLOWED);
|
||||
|
||||
mouseX=0;
|
||||
mouseY=0;
|
||||
|
@ -169,7 +169,7 @@ void Game::load(){
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
if(loadingImageUsed == false){
|
||||
// try to use a faction related loading screen
|
||||
|
@ -249,7 +249,7 @@ void Game::load(){
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
@ -265,7 +265,7 @@ void Game::load(){
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
@ -274,7 +274,7 @@ void Game::load(){
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
@ -286,7 +286,7 @@ void Game::load(){
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
|
||||
|
@ -315,19 +315,19 @@ void Game::init()
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
world.init(this, gameSettings.getDefaultUnits());
|
||||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
gui.init(this);
|
||||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
chatManager.init(&console, world.getThisTeamIndex());
|
||||
console.clearStoredLines();
|
||||
|
@ -337,7 +337,7 @@ void Game::init()
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
scriptManager.init(&world, &gameCamera);
|
||||
|
||||
|
@ -360,7 +360,7 @@ void Game::init()
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
//wheather particle systems
|
||||
if(world.getTileset()->getWeather() == wRainy){
|
||||
|
@ -388,7 +388,7 @@ void Game::init()
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
//sounds
|
||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||
|
@ -442,6 +442,8 @@ void Game::update(){
|
|||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
try {
|
||||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
// a) Updates non dependent on speed
|
||||
|
||||
|
@ -459,6 +461,8 @@ void Game::update(){
|
|||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||
//update
|
||||
for(int i=0; i<updateLoops; ++i){
|
||||
|
@ -475,18 +479,22 @@ void Game::update(){
|
|||
}
|
||||
}
|
||||
}
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//World
|
||||
world.update();
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
// Commander
|
||||
commander.updateNetwork();
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//Gui
|
||||
gui.update();
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//Particle systems
|
||||
|
@ -496,6 +504,7 @@ void Game::update(){
|
|||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
renderer.updateParticleManager(rsGame);
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
@ -552,9 +561,9 @@ void Game::renderWorker() {
|
|||
//program->getWindow()->makeCurrentGl();
|
||||
|
||||
//renderFps++;
|
||||
if(renderFps >= MIN_RENDER_FPS_ALLOWED) {
|
||||
//if(renderFps >= MIN_RENDER_FPS_ALLOWED) {
|
||||
render3d();
|
||||
}
|
||||
//}
|
||||
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
@ -1048,7 +1057,7 @@ void Game::render3d(){
|
|||
//shadow map
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
chrono.start();
|
||||
renderer.renderShadowsToTexture();
|
||||
renderer.renderShadowsToTexture(renderFps);
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||
|
||||
//clear buffers
|
||||
|
@ -1072,13 +1081,13 @@ void Game::render3d(){
|
|||
//units
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
chrono.start();
|
||||
renderer.renderUnits();
|
||||
renderer.renderUnits(renderFps,world.getFrameCount());
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||
|
||||
//objects
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
chrono.start();
|
||||
renderer.renderObjects();
|
||||
renderer.renderObjects(renderFps,world.getFrameCount());
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d renderFps = %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
|
||||
|
||||
//water
|
||||
|
@ -1165,6 +1174,36 @@ void Game::render2d(){
|
|||
str+= "\n";
|
||||
str+= "Visible quad area: " + floatToStr(visibleQuad.area()) +"\n";
|
||||
|
||||
int visibleUnitCount = 0;
|
||||
for(int i=0; i< world.getFactionCount(); ++i){
|
||||
for(int j=0; j< world.getFaction(i)->getUnitCount(); ++j){
|
||||
Unit *unit = world.getFaction(i)->getUnit(j);
|
||||
if(world.toRenderUnit(unit, visibleQuad)) {
|
||||
visibleUnitCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
str+= "Visible unit count: " + intToStr(visibleUnitCount) +"\n";
|
||||
|
||||
int visibleObjectCount = 0;
|
||||
Map *map= world.getMap();
|
||||
int thisTeamIndex= world.getThisTeamIndex();
|
||||
PosQuadIterator pqi(map, visibleQuad, Map::cellScale);
|
||||
while(pqi.next()){
|
||||
const Vec2i &pos= pqi.getPos();
|
||||
bool isPosVisible = map->isInside(pos.x, pos.y);
|
||||
if(isPosVisible == true) {
|
||||
Vec2i mapPos = Map::toSurfCoords(pos);
|
||||
SurfaceCell *sc= map->getSurfaceCell(mapPos.x, mapPos.y);
|
||||
Object *o= sc->getObject();
|
||||
bool isExplored = (sc->isExplored(thisTeamIndex) && o!=NULL);
|
||||
if(isExplored == true) {
|
||||
visibleObjectCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
str+= "Visible object count: " + intToStr(visibleObjectCount) +"\n";
|
||||
|
||||
// resources
|
||||
for(int i=0; i<world.getFactionCount(); ++i){
|
||||
str+= "Player "+intToStr(i)+" res: ";
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "faction.h"
|
||||
#include "factory_repository.h"
|
||||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
|
@ -40,6 +41,24 @@ namespace Glest { namespace Game{
|
|||
|
||||
bool MeshCallbackTeamColor::noTeamColors = false;
|
||||
|
||||
// if FPS is less than this we start to skip 3D renders
|
||||
int MIN_RENDER_FPS_ALLOWED = -1;
|
||||
int MIN_RENDER_LAG_ALLOWED = 1;
|
||||
int MAX_RENDER_LAG_ITEMCOUNT_ALLOWED = 60;
|
||||
|
||||
bool RenderEntity::operator<(const RenderEntity &rhs) const {
|
||||
if(this->type == retUnit || this->type == retUnitFast) {
|
||||
return(this->unit->getLastRenderFrame() < rhs.unit->getLastRenderFrame());
|
||||
}
|
||||
else {
|
||||
return(this->o->getLastRenderFrame() < rhs.o->getLastRenderFrame());
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderEntity::operator()(const RenderEntity &lhs,const RenderEntity &rhs) const {
|
||||
return lhs < lhs;
|
||||
}
|
||||
|
||||
void MeshCallbackTeamColor::execute(const Mesh *mesh){
|
||||
|
||||
//team color
|
||||
|
@ -1244,7 +1263,11 @@ void Renderer::renderSurface(){
|
|||
assertGl();
|
||||
}
|
||||
|
||||
void Renderer::renderObjects() {
|
||||
void Renderer::renderObjects(const int renderFps, const int worldFrameCount) {
|
||||
if(renderFps < MIN_RENDER_FPS_ALLOWED) {
|
||||
renderObjectsFast();
|
||||
}
|
||||
else {
|
||||
const World *world= game->getWorld();
|
||||
const Map *map= world->getMap();
|
||||
|
||||
|
@ -1284,56 +1307,56 @@ void Renderer::renderObjects() {
|
|||
Object *o= sc->getObject();
|
||||
bool isExplored = (sc->isExplored(thisTeamIndex) && o!=NULL);
|
||||
if(isExplored == true) {
|
||||
|
||||
/*
|
||||
const Model *objModel= o->getModel();
|
||||
const Vec3f &v= o->getConstPos();
|
||||
|
||||
//ambient and diffuse color is taken from cell color
|
||||
//float fowFactor= fowTex->getPixmap()->getPixelf(pos.x/Map::cellScale, pos.y/Map::cellScale);
|
||||
float fowFactor= fowTex->getPixmap()->getPixelf(mapPos.x,mapPos.y);
|
||||
|
||||
Vec4f color= Vec4f(Vec3f(fowFactor), 1.f);
|
||||
glColor4fv(color.ptr());
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (color*ambFactor).ptr());
|
||||
glFogfv(GL_FOG_COLOR, (baseFogColor*fowFactor).ptr());
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glTranslatef(v.x, v.y, v.z);
|
||||
glRotatef(o->getRotation(), 0.f, 1.f, 0.f);
|
||||
|
||||
objModel->updateInterpolationData(0.f, true);
|
||||
|
||||
modelRenderer->render(objModel);
|
||||
|
||||
triangleCount+= objModel->getTriangleCount();
|
||||
pointCount+= objModel->getVertexCount();
|
||||
|
||||
glPopMatrix();
|
||||
*/
|
||||
|
||||
if(renderFps < MIN_RENDER_FPS_ALLOWED) {
|
||||
int renderLag = worldFrameCount - o->getLastRenderFrame();
|
||||
if(renderLag > MIN_RENDER_LAG_ALLOWED) {
|
||||
vctEntity.push_back(RenderEntity(retObject,o,mapPos,NULL));
|
||||
}
|
||||
}
|
||||
else {
|
||||
*/
|
||||
vctEntity.push_back(RenderEntity(retObject,o,mapPos,NULL));
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
modelRenderer->begin(true, true, false);
|
||||
renderObjectList(vctEntity,baseFogColor);
|
||||
renderObjectList(vctEntity,baseFogColor,renderFps, worldFrameCount);
|
||||
modelRenderer->end();
|
||||
|
||||
//restore
|
||||
static_cast<ModelRendererGl*>(modelRenderer)->setDuplicateTexCoords(true);
|
||||
glPopAttrib();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::renderObjectList(std::vector<RenderEntity> &vctEntity,const Vec3f &baseFogColor) {
|
||||
void Renderer::renderObjectList(std::vector<RenderEntity> &vctEntity,const Vec3f &baseFogColor,const int renderFps, const int worldFrameCount) {
|
||||
// Need to do something to manage bad FPS
|
||||
/*
|
||||
if(renderFps < MIN_RENDER_FPS_ALLOWED) {
|
||||
// Oldest rendered objects go to top
|
||||
std::sort(vctEntity.begin(), vctEntity.end());
|
||||
for(int idx=0; idx < vctEntity.size(); ++idx) {
|
||||
RenderEntity &entity = vctEntity[idx];
|
||||
prepareObjectForRender(entity);
|
||||
renderObject(entity,baseFogColor);
|
||||
renderObject(entity,baseFogColor,renderFps, worldFrameCount);
|
||||
|
||||
if(idx >= MAX_RENDER_LAG_ITEMCOUNT_ALLOWED) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
*/
|
||||
for(int idx=0; idx < vctEntity.size(); ++idx) {
|
||||
RenderEntity &entity = vctEntity[idx];
|
||||
prepareObjectForRender(entity);
|
||||
renderObject(entity,baseFogColor,renderFps, worldFrameCount);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
void Renderer::prepareObjectForRender(RenderEntity &entity) {
|
||||
Object *o = entity.o;
|
||||
|
@ -1346,7 +1369,7 @@ void Renderer::prepareObjectForRender(RenderEntity &entity) {
|
|||
entity.setState(resInterpolated);
|
||||
}
|
||||
|
||||
void Renderer::renderObject(RenderEntity &entity,const Vec3f &baseFogColor) {
|
||||
void Renderer::renderObject(RenderEntity &entity,const Vec3f &baseFogColor,const int renderFps, const int worldFrameCount) {
|
||||
Object *o = entity.o;
|
||||
Vec2i &mapPos = entity.mapPos;
|
||||
if(o != NULL) {
|
||||
|
@ -1374,6 +1397,7 @@ void Renderer::renderObject(RenderEntity &entity,const Vec3f &baseFogColor) {
|
|||
//objModel->updateInterpolationData(0.f, true);
|
||||
|
||||
modelRenderer->render(objModel);
|
||||
o->setLastRenderFrame(worldFrameCount);
|
||||
|
||||
triangleCount+= objModel->getTriangleCount();
|
||||
pointCount+= objModel->getVertexCount();
|
||||
|
@ -1510,8 +1534,7 @@ void Renderer::renderWater(){
|
|||
assertGl();
|
||||
}
|
||||
|
||||
void Renderer::renderUnits(){
|
||||
Unit *unit;
|
||||
void Renderer::renderUnits(const int renderFps, const int worldFrameCount) {
|
||||
const World *world= game->getWorld();
|
||||
MeshCallbackTeamColor meshCallbackTeamColor;
|
||||
|
||||
|
@ -1535,58 +1558,27 @@ void Renderer::renderUnits(){
|
|||
std::vector<RenderEntity> vctEntity;
|
||||
|
||||
for(int i=0; i<world->getFactionCount(); ++i){
|
||||
// meshCallbackTeamColor.setTeamTexture(world->getFaction(i)->getTexture());
|
||||
for(int j=0; j<world->getFaction(i)->getUnitCount(); ++j){
|
||||
unit= world->getFaction(i)->getUnit(j);
|
||||
Unit *unit = world->getFaction(i)->getUnit(j);
|
||||
if(world->toRenderUnit(unit, visibleQuad)) {
|
||||
|
||||
/*
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
//translate
|
||||
Vec3f currVec= unit->getCurrVectorFlat();
|
||||
glTranslatef(currVec.x, currVec.y, currVec.z);
|
||||
|
||||
//rotate
|
||||
glRotatef(unit->getRotation(), 0.f, 1.f, 0.f);
|
||||
glRotatef(unit->getVerticalRotation(), 1.f, 0.f, 0.f);
|
||||
|
||||
//dead alpha
|
||||
float alpha= 1.0f;
|
||||
const SkillType *st= unit->getCurrSkill();
|
||||
if(st->getClass()==scDie && static_cast<const DieSkillType*>(st)->getFade()){
|
||||
alpha= 1.0f-unit->getAnimProgress();
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, Vec4f(1.0f, 1.0f, 1.0f, alpha).ptr());
|
||||
}
|
||||
else{
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
}
|
||||
|
||||
//render
|
||||
const Model *model= unit->getCurrentModel();
|
||||
model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive());
|
||||
|
||||
modelRenderer->render(model);
|
||||
triangleCount+= model->getTriangleCount();
|
||||
pointCount+= model->getVertexCount();
|
||||
|
||||
glPopMatrix();
|
||||
unit->setVisible(true);
|
||||
*/
|
||||
|
||||
if(renderFps < MIN_RENDER_FPS_ALLOWED) {
|
||||
int unitRenderLag = worldFrameCount - unit->getLastRenderFrame();
|
||||
if(unitRenderLag > MIN_RENDER_LAG_ALLOWED) {
|
||||
vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit,world->getFaction(i)->getTexture()));
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else {
|
||||
vctEntity.push_back(RenderEntity(retUnit,NULL,Vec2i(),unit,world->getFaction(i)->getTexture()));
|
||||
}
|
||||
}
|
||||
else if(unit->getVisible() == true){
|
||||
unit->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
modelRenderer->begin(true, true, true, &meshCallbackTeamColor);
|
||||
renderUnitList(vctEntity,&meshCallbackTeamColor);
|
||||
renderUnitList(vctEntity,&meshCallbackTeamColor,renderFps, worldFrameCount);
|
||||
modelRenderer->end();
|
||||
|
||||
//restore
|
||||
|
@ -1597,15 +1589,31 @@ void Renderer::renderUnits(){
|
|||
assertGl();
|
||||
}
|
||||
|
||||
void Renderer::renderUnitList(std::vector<RenderEntity> &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor) {
|
||||
void Renderer::renderUnitList(std::vector<RenderEntity> &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor,const int renderFps, const int worldFrameCount) {
|
||||
// Need to do something to manage bad FPS
|
||||
if(renderFps < MIN_RENDER_FPS_ALLOWED) {
|
||||
// Oldest rendered units go to top
|
||||
std::sort(vctEntity.begin(), vctEntity.end());
|
||||
for(int idx=0; idx < vctEntity.size(); ++idx) {
|
||||
RenderEntity &entity = vctEntity[idx];
|
||||
prepareUnitForRender(entity);
|
||||
renderUnit(entity,meshCallbackTeamColor);
|
||||
renderUnit(entity,meshCallbackTeamColor,renderFps, worldFrameCount);
|
||||
|
||||
if(idx >= MAX_RENDER_LAG_ITEMCOUNT_ALLOWED) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(int idx=0; idx < vctEntity.size(); ++idx) {
|
||||
RenderEntity &entity = vctEntity[idx];
|
||||
prepareUnitForRender(entity);
|
||||
renderUnit(entity,meshCallbackTeamColor,renderFps, worldFrameCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor) {
|
||||
void Renderer::renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor,const int renderFps, const int worldFrameCount) {
|
||||
Unit *unit = entity.unit;
|
||||
if(unit != NULL) {
|
||||
if(meshCallbackTeamColor != NULL) {
|
||||
|
@ -1640,11 +1648,13 @@ void Renderer::renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallba
|
|||
//model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive());
|
||||
|
||||
modelRenderer->render(model);
|
||||
unit->setLastRenderFrame(worldFrameCount);
|
||||
triangleCount+= model->getTriangleCount();
|
||||
pointCount+= model->getVertexCount();
|
||||
|
||||
glPopMatrix();
|
||||
unit->setVisible(true);
|
||||
|
||||
if(allowRenderUnitTitles == true) {
|
||||
// Add to the pending render unit title list
|
||||
renderUnitTitleList.push_back(std::pair<Unit *,Vec3f>(unit,computeScreenPosition(unit->getCurrVectorFlat())) );
|
||||
|
@ -2295,10 +2305,11 @@ void Renderer::computeSelected(Selection::UnitContainer &units, const Vec2i &pos
|
|||
|
||||
// ==================== shadows ====================
|
||||
|
||||
void Renderer::renderShadowsToTexture(){
|
||||
void Renderer::renderShadowsToTexture(const int renderFps){
|
||||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
if(renderFps >= MIN_RENDER_FPS_ALLOWED) {
|
||||
if(shadows==sProjected || shadows==sShadowMapping){
|
||||
|
||||
shadowMapFrame= (shadowMapFrame + 1) % (shadowFrameSkip + 1);
|
||||
|
@ -2454,6 +2465,7 @@ void Renderer::renderShadowsToTexture(){
|
|||
chrono.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
}
|
||||
|
|
|
@ -144,6 +144,8 @@ public:
|
|||
CopyAll(obj);
|
||||
return *this;
|
||||
}
|
||||
bool operator<(const RenderEntity &rhs) const;
|
||||
bool operator()(const RenderEntity &lhs,const RenderEntity &rhs) const;
|
||||
|
||||
RenderEntityType type;
|
||||
Object *o;
|
||||
|
@ -332,16 +334,16 @@ public:
|
|||
|
||||
//complex rendering
|
||||
void renderSurface();
|
||||
void renderObjects();
|
||||
void renderObject(RenderEntity &entity,const Vec3f &baseFogColor);
|
||||
void renderObjects(const int renderFps, const int worldFrameCount);
|
||||
void renderObject(RenderEntity &entity,const Vec3f &baseFogColor,const int renderFps, const int worldFrameCount);
|
||||
void prepareObjectForRender(RenderEntity &entity);
|
||||
void renderObjectList(std::vector<RenderEntity> &vctEntity,const Vec3f &baseFogColor);
|
||||
void renderObjectList(std::vector<RenderEntity> &vctEntity,const Vec3f &baseFogColor,const int renderFps, const int worldFrameCount);
|
||||
|
||||
void renderWater();
|
||||
void renderUnits();
|
||||
void renderUnits(const int renderFps, const int worldFrameCount);
|
||||
void prepareUnitForRender(RenderEntity &entity);
|
||||
void renderUnitList(std::vector<RenderEntity> &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor);
|
||||
void renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor);
|
||||
void renderUnitList(std::vector<RenderEntity> &vctEntity,MeshCallbackTeamColor *meshCallbackTeamColor,const int renderFps, const int worldFrameCount);
|
||||
void renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallbackTeamColor,const int renderFps, const int worldFrameCount);
|
||||
|
||||
void renderSelectionEffects();
|
||||
void renderWaterEffects();
|
||||
|
@ -363,7 +365,7 @@ public:
|
|||
void clearZBuffer();
|
||||
|
||||
//shadows
|
||||
void renderShadowsToTexture();
|
||||
void renderShadowsToTexture(const int renderFps);
|
||||
|
||||
//misc
|
||||
void loadConfig();
|
||||
|
|
|
@ -265,6 +265,18 @@ void MainWindow::setProgram(Program *program) {
|
|||
// =====================================================
|
||||
SystemFlags debugger;
|
||||
|
||||
bool hasCommandArgument(int argc, char** argv,string argName) {
|
||||
bool result = false;
|
||||
|
||||
for(int idx = 1; idx < argc; idx++) {
|
||||
if(stricmp(argName.c_str(),argv[idx]) == 0) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int glestMain(int argc, char** argv){
|
||||
|
||||
#ifdef SL_LEAK_DUMP
|
||||
|
@ -279,6 +291,10 @@ int glestMain(int argc, char** argv){
|
|||
printf("%s, STREFLOP NOT enabled.\n",getNetworkVersionString().c_str());
|
||||
#endif
|
||||
|
||||
if(hasCommandArgument(argc, argv,"--version") == true) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SystemFlags::init();
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled = true;
|
||||
SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled = true;
|
||||
|
|
|
@ -34,7 +34,7 @@ Object::Object(ObjectType *objectType, const Vec3f &pos){
|
|||
RandomGen random;
|
||||
|
||||
random.init(static_cast<int>(pos.x*pos.z));
|
||||
|
||||
this->lastRenderFrame = 0;
|
||||
this->objectType= objectType;
|
||||
resource= NULL;
|
||||
this->pos= pos + Vec3f(random.randRange(-0.6f, 0.6f), 0.0f, random.randRange(-0.6f, 0.6f));
|
||||
|
|
|
@ -37,6 +37,7 @@ private:
|
|||
Vec3f pos;
|
||||
float rotation;
|
||||
int variation;
|
||||
int lastRenderFrame;
|
||||
|
||||
public:
|
||||
Object(ObjectType *objectType, const Vec3f &pos);
|
||||
|
@ -53,6 +54,10 @@ public:
|
|||
bool getWalkable() const;
|
||||
|
||||
void setResource(const ResourceType *resourceType, const Vec2i &pos);
|
||||
|
||||
int getLastRenderFrame() const { return lastRenderFrame; }
|
||||
void setLastRenderFrame(int value) { lastRenderFrame = value; }
|
||||
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -147,6 +147,8 @@ Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map
|
|||
this->targetField = fLand;
|
||||
this->targetVec = Vec3f(0.0);
|
||||
this->targetPos = Vec2i(0);
|
||||
this->lastRenderFrame = 0;
|
||||
this->visible = true;
|
||||
|
||||
level= NULL;
|
||||
loadType= NULL;
|
||||
|
@ -545,6 +547,8 @@ void Unit::setTargetPos(const Vec2i &targetPos){
|
|||
}
|
||||
|
||||
void Unit::setVisible(const bool visible) {
|
||||
this->visible = visible;
|
||||
|
||||
for(UnitParticleSystems::iterator it= unitParticleSystems.begin(); it!=unitParticleSystems.end(); ++it){
|
||||
(*it)->setVisible(visible);
|
||||
}
|
||||
|
|
|
@ -197,6 +197,8 @@ private:
|
|||
CardinalDir modelFacing;
|
||||
|
||||
std::string lastSynchDataString;
|
||||
int lastRenderFrame;
|
||||
bool visible;
|
||||
|
||||
public:
|
||||
Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
|
||||
|
@ -270,6 +272,7 @@ public:
|
|||
void setTargetVec(const Vec3f &targetVec);
|
||||
void setMeetingPos(const Vec2i &meetingPos);
|
||||
void setVisible(const bool visible);
|
||||
bool getVisible() const { return visible; }
|
||||
|
||||
//render related
|
||||
const Model *getCurrentModel() const;
|
||||
|
@ -317,6 +320,9 @@ public:
|
|||
|
||||
bool isMeetingPointSettable() const;
|
||||
|
||||
int getLastRenderFrame() const { return lastRenderFrame; }
|
||||
void setLastRenderFrame(int value) { lastRenderFrame = value; }
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -68,7 +68,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
//load tech tree xml info
|
||||
try{
|
||||
|
@ -91,7 +91,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
//armor types
|
||||
const XmlNode *armorTypesNode= techTreeNode->getChild("armor-types");
|
||||
|
@ -119,7 +119,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
//load factions
|
||||
str= dir+"/factions/*.";
|
||||
|
@ -139,7 +139,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
|
|||
|
||||
// give CPU time to update other things to avoid apperance of hanging
|
||||
sleep(0);
|
||||
SDL_PumpEvents();
|
||||
//SDL_PumpEvents();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,14 +178,18 @@ void World::loadScenario(const string &path, Checksum *checksum){
|
|||
// ==================== misc ====================
|
||||
|
||||
void World::update(){
|
||||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
++frameCount;
|
||||
|
||||
//time
|
||||
timeFlow.update();
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//water effects
|
||||
waterEffects.update();
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//units
|
||||
for(int i=0; i<getFactionCount(); ++i){
|
||||
|
@ -193,6 +197,7 @@ void World::update(){
|
|||
unitUpdater.updateUnit(getFaction(i)->getUnit(j));
|
||||
}
|
||||
}
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//undertake the dead
|
||||
for(int i=0; i<getFactionCount(); ++i){
|
||||
|
@ -206,6 +211,7 @@ void World::update(){
|
|||
}
|
||||
}
|
||||
}
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//food costs
|
||||
for(int i=0; i<techTree->getResourceTypeCount(); ++i){
|
||||
|
@ -216,18 +222,21 @@ void World::update(){
|
|||
}
|
||||
}
|
||||
}
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//fow smoothing
|
||||
if(fogOfWarSmoothing && ((frameCount+1) % (fogOfWarSmoothingFrameSkip+1))==0){
|
||||
float fogFactor= static_cast<float>(frameCount%GameConstants::updateFps)/GameConstants::updateFps;
|
||||
minimap.updateFowTex(clamp(fogFactor, 0.f, 1.f));
|
||||
}
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
//tick
|
||||
if(frameCount%GameConstants::updateFps==0){
|
||||
computeFow();
|
||||
tick();
|
||||
}
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
}
|
||||
|
||||
void World::tick(){
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#define MAIN_FUNCTION(X) int main(int argc, char **argv) \
|
||||
{ std::cout << "About to init SDL..." << "\n"; \
|
||||
{ \
|
||||
if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { \
|
||||
std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n"; \
|
||||
return 1; \
|
||||
|
|
|
@ -97,11 +97,13 @@ void BaseThread::shutdownAndWait(BaseThread *pThread) {
|
|||
if(pThread->getRunningStatus() == false) {
|
||||
break;
|
||||
}
|
||||
sleep(0);
|
||||
sleep(1);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
sleep(1);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
sleep(0);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
|
|
|
@ -152,9 +152,8 @@ SystemFlags::~SystemFlags() {
|
|||
}
|
||||
|
||||
void SystemFlags::Close() {
|
||||
printf("START Closing logfiles\n");
|
||||
|
||||
if(SystemFlags::debugLogFileList.size() > 0) {
|
||||
printf("START Closing logfiles\n");
|
||||
for(std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType>::iterator iterMap = SystemFlags::debugLogFileList.begin();
|
||||
iterMap != SystemFlags::debugLogFileList.end(); iterMap++) {
|
||||
SystemFlags::SystemFlagsType ¤tDebugLog = iterMap->second;
|
||||
|
@ -176,8 +175,10 @@ void SystemFlags::Close() {
|
|||
}
|
||||
}
|
||||
|
||||
if(SystemFlags::debugLogFileList.size() > 0) {
|
||||
printf("END Closing logfiles\n");
|
||||
}
|
||||
}
|
||||
|
||||
void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) {
|
||||
if(SystemFlags::debugLogFileList.size() == 0) {
|
||||
|
|
Loading…
Reference in New Issue