- attempt to fix light sources handling as reported by tomreyn

- allow speed up / slow down for network game as long as no-one is connected
This commit is contained in:
Mark Vejvoda 2013-02-26 20:48:20 +00:00
parent 45b8cf21a4
commit 13665d58f1
4 changed files with 84 additions and 19 deletions

View File

@ -91,7 +91,7 @@ Game::Game() : ProgramState(NULL) {
camRightButtonDown=false;
camUpButtonDown=false;
camDownButtonDown=false;
speed=1;
this->speed=1;
weatherParticleSystem=NULL;
isFirstRender=false;
quitTriggeredIndicator=false;
@ -237,7 +237,7 @@ void Game::resetMembers() {
pauseStateChanged=false;
gameOver= false;
renderNetworkStatus= false;
speed= 1;
this->speed= 1;
showFullConsole= false;
setMarker = false;
camLeftButtonDown=false;
@ -2074,6 +2074,8 @@ void Game::update() {
//server->setStartInGameConnectionLaunch(false);
this->speed = 1;
Lang &lang= Lang::getInstance();
bool pauseAndSaveGameForNewClient = false;
for(int i = 0; i < world.getFactionCount(); ++i) {
@ -2151,6 +2153,7 @@ void Game::update() {
else if(server->getUnPauseForInGameConnection() == true && paused == true) {
//printf("^^^ getUnPauseForInGameConnection triggered!\n");
this->speed = 1;
for(int i = 0; i < world.getFactionCount(); ++i) {
Faction *faction = world.getFaction(i);
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
@ -4277,7 +4280,7 @@ void Game::keyDown(SDL_KeyboardEvent key) {
//increment speed
//else if(key == configKeys.getCharKey("GameSpeedIncrease")) {
else if(isKeyPressed(configKeys.getSDLKey("GameSpeedIncrease"),key, false) == true) {
bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGame();
bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGameWithConnectedClients();
if(speedChangesAllowed){
incSpeed();
}
@ -4285,7 +4288,7 @@ void Game::keyDown(SDL_KeyboardEvent key) {
//decrement speed
//else if(key == configKeys.getCharKey("GameSpeedDecrease")) {
else if(isKeyPressed(configKeys.getSDLKey("GameSpeedDecrease"),key, false) == true) {
bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGame();
bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGameWithConnectedClients();
if(speedChangesAllowed){
decSpeed();
}
@ -5325,24 +5328,22 @@ bool Game::hasBuilding(const Faction *faction) {
void Game::incSpeed() {
Lang &lang= Lang::getInstance();
if(speed < Config::getInstance().getInt("FastSpeedLoops"))
{
if(speed==0)
{
speed=1;
if(this->speed < Config::getInstance().getInt("FastSpeedLoops")) {
if(this->speed == 0) {
this->speed = 1;
}
else
speed++;
console.addLine(lang.get("GameSpeedSet")+" "+((speed==0)?lang.get("Slow"):(speed==1)?lang.get("Normal"):"x"+intToStr(speed)));
else {
this->speed++;
}
console.addLine(lang.get("GameSpeedSet")+" "+((this->speed == 0)?lang.get("Slow") : (this->speed == 1)?lang.get("Normal"):"x"+intToStr(this->speed)));
}
}
void Game::decSpeed() {
Lang &lang= Lang::getInstance();
if(speed > 0)
{
speed--;
console.addLine(lang.get("GameSpeedSet")+" "+((speed==0)?lang.get("Slow"):(speed==1)?lang.get("Normal"):"x"+intToStr(speed)));
if(this->speed > 0) {
this->speed--;
console.addLine(lang.get("GameSpeedSet")+" "+((this->speed == 0)?lang.get("Slow") : (this->speed == 1)?lang.get("Normal"):"x"+intToStr(this->speed)));
}
}
@ -5411,11 +5412,11 @@ int Game::getUpdateLoops() {
if(getPaused()) {
return 0;
}
else if(speed == 0) {
else if(this->speed == 0) {
return updateFps % 2 == 0? 1: 0;
}
else
return speed;
return this->speed;
}
void Game::showLoseMessageBox() {

View File

@ -1017,6 +1017,46 @@ void Renderer::setupLighting() {
}
//unit lights (not projectiles)
if(timeFlow->isTotalNight()) {
VisibleQuadContainerCache &qCache = getQuadCache();
if(qCache.visibleQuadUnitList.empty() == false) {
bool modelRenderStarted = false;
for(int visibleUnitIndex = 0;
visibleUnitIndex < qCache.visibleQuadUnitList.size() && lightCount < maxLights;
++visibleUnitIndex) {
Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex];
if(world->toRenderUnit(unit) &&
unit->getCurrVector().dist(gameCamera->getPos()) < maxLightDist &&
unit->getType()->getLight() && unit->isOperative()) {
//printf("$$$ Show light for faction: %s # %d / %d for Unit [%d - %s]\n",world->getFaction(i)->getType()->getName().c_str(),lightCount,maxLights,unit->getId(),unit->getFullName().c_str());
Vec4f pos= Vec4f(unit->getCurrVector());
pos.y+=4.f;
GLenum lightEnum= GL_LIGHT0 + lightCount;
glEnable(lightEnum);
glLightfv(lightEnum, GL_POSITION, pos.ptr());
glLightfv(lightEnum, GL_AMBIENT, Vec4f(unit->getType()->getLightColor()).ptr());
glLightfv(lightEnum, GL_DIFFUSE, Vec4f(unit->getType()->getLightColor()).ptr());
glLightfv(lightEnum, GL_SPECULAR, Vec4f(unit->getType()->getLightColor()*0.3f).ptr());
glLightf(lightEnum, GL_QUADRATIC_ATTENUATION, 0.05f);
++lightCount;
const GameCamera *gameCamera= game->getGameCamera();
if(Vec3f(pos).dist(gameCamera->getPos())<Vec3f(nearestLightPos).dist(gameCamera->getPos())){
nearestLightPos= pos;
}
}
}
}
}
/*
if(timeFlow->isTotalNight()) {
for(int i = 0; i < world->getFactionCount() && lightCount < maxLights; ++i) {
for(int j = 0; j < world->getFaction(i)->getUnitCount() && lightCount < maxLights; ++j) {
@ -1024,7 +1064,7 @@ void Renderer::setupLighting() {
if(world->toRenderUnit(unit) &&
unit->getCurrVector().dist(gameCamera->getPos()) < maxLightDist &&
unit->getType()->getLight() && unit->isOperative()){
//printf("$$$ Show light # %d / %d for Unit [%d - %s]\n",lightCount,maxLights,unit->getId(),unit->getFullName().c_str());
//printf("$$$ Show light for faction: %s # %d / %d for Unit [%d - %s]\n",world->getFaction(i)->getType()->getName().c_str(),lightCount,maxLights,unit->getId(),unit->getFullName().c_str());
Vec4f pos= Vec4f(unit->getCurrVector());
pos.y+=4.f;
@ -1049,6 +1089,24 @@ void Renderer::setupLighting() {
}
}
}
*/
// else {
// for(int i = 0; i < world->getFactionCount() && lightCount < maxLights; ++i) {
// for(int j = 0; j < world->getFaction(i)->getUnitCount() && lightCount < maxLights; ++j) {
// Unit *unit= world->getFaction(i)->getUnit(j);
// if(world->toRenderUnit(unit) == true) {
// float dist = unit->getCurrVector().dist(gameCamera->getPos());
// bool showUnitLight = dist < maxLightDist &&
// unit->getType()->getLight() && unit->isOperative();
//
// if(showUnitLight == false && unit->getType()->getLight() == true) {
// printf("$$$ Show light for faction: %s # %d / %d for Unit [%d - %s] showUnitLight = %d dist = %f [%f] unit->getType()->getLight() = %d unit->isOperative() = %d\n",world->getFaction(i)->getType()->getName().c_str(),lightCount,maxLights,unit->getId(),unit->getFullName().c_str(),showUnitLight,dist,maxLightDist,unit->getType()->getLight(),unit->isOperative());
// }
// }
// }
// }
// }
assertGl();
}

View File

@ -82,6 +82,10 @@ bool NetworkManager::isNetworkGame() {
return networkRole==nrClient || (networkRole==nrServer && getServerInterface()->getSlotCount() > 0);
}
bool NetworkManager::isNetworkGameWithConnectedClients() {
return networkRole==nrClient || (networkRole==nrServer && getServerInterface()->getConnectedSlotCount(true) > 0);
}
GameNetworkInterface* NetworkManager::getGameNetworkInterface(bool throwErrorOnNull) {
if(throwErrorOnNull) {
//assert(gameNetworkInterface!=NULL);

View File

@ -41,6 +41,8 @@ public:
void update();
bool isNetworkGame();
bool isNetworkGameWithConnectedClients();
GameNetworkInterface* getGameNetworkInterface(bool throwErrorOnNull=true);
ServerInterface* getServerInterface(bool throwErrorOnNull=true);
ClientInterface* getClientInterface(bool throwErrorOnNull=true);