cleaned up code based on feedback from cppcheck

This commit is contained in:
Mark Vejvoda 2013-10-25 05:45:54 +00:00
parent 24cfc243eb
commit ad0fb1d6f7
26 changed files with 87 additions and 114 deletions

View File

@ -3,6 +3,22 @@ MEGAGLEST CHANGELOG
To see a timeline of detail changes please visit:
http://sourceforge.net/apps/trac/megaglest/timeline
v3.8.0-beta1
- Greater ability to translate game content into your native language. (including techtrees)
- Added Hebrew, Arabic, Vietnamese.
- better network game performance / management to handle slower clients.
- performance improvements.
- Enhanced AI behaviour.
- new game content including maps and tilesets.
- many bugfixes discovered in 3.7.1
- added ability for stand alone mod's to customize more of the engine like about screen.
- animated tileset object support.
- easier ability to download game content from host.
- many new lua functions for scenario modders.
- addition of google-breakpad to better track down bugs.
- color picking is now the default selection mode
-
v3.7.1
- bugfixes reported in the bugs forum since 3.7.0

View File

@ -123,7 +123,7 @@ void AiInterfaceThread::execute() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ****************** STARTING worker thread this = %p\n",__FILE__,__FUNCTION__,__LINE__,this);
bool minorDebugPerformance = false;
//bool minorDebugPerformance = false;
Chrono chrono;
//unsigned int idx = 0;

View File

@ -1327,7 +1327,6 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
int lowestCommandCount=1000000;
int currentProducerIndex=backupProducers[randomstart];
int bestIndex=-1;
int currentCommandCount=0;
for(unsigned int i=randomstart; i<backupProducers.size()+randomstart; i++) {
int prIndex = i;
if(i >= backupProducers.size()) {
@ -1349,7 +1348,7 @@ void AiRuleProduce::produceSpecific(const ProduceTask *pt){
throw megaglest_runtime_error(szBuf);
}
currentCommandCount=aiInterface->getMyUnit(currentProducerIndex)->getCommandSize();
int currentCommandCount=aiInterface->getMyUnit(currentProducerIndex)->getCommandSize();
if( currentCommandCount==1 &&
aiInterface->getMyUnit(currentProducerIndex)->getCurrCommand()->getCommandType()->getClass()==ccStop)
{// special for non buildings

View File

@ -1599,7 +1599,6 @@ bool PathFinder::unitCannotMove(Unit *unit) {
bool unitImmediatelyBlocked = false;
// First check if unit currently blocked all around them, if so don't try to pathfind
const bool showConsoleDebugInfo = Config::getInstance().getBool("EnablePathfinderDistanceOutput","false");
const Vec2i unitPos = unit->getPos();
int failureCount = 0;
int cellCount = 0;

View File

@ -2045,13 +2045,12 @@ void Game::update() {
if(hasAIPlayer == true) {
//sleep(0);
bool workThreadsFinished = false;
Chrono chronoAI;
chronoAI.start();
const int MAX_FACTION_THREAD_WAIT_MILLISECONDS = 20000;
for(;chronoAI.getMillis() < MAX_FACTION_THREAD_WAIT_MILLISECONDS;) {
workThreadsFinished = true;
bool workThreadsFinished = true;
for(int j = 0; j < world.getFactionCount(); ++j) {
Faction *faction = world.getFaction(j);
if(faction == NULL) {

View File

@ -30,10 +30,8 @@ ScriptManagerMessage::ScriptManagerMessage() : text(""), header("") {
this->teamIndex=-1;
}
ScriptManagerMessage::ScriptManagerMessage(string text, string header,
int factionIndex,int teamIndex) {
this->text = text;
this->header = header;
ScriptManagerMessage::ScriptManagerMessage(string textIn, string headerIn,
int factionIndex,int teamIndex) : text(textIn), header(headerIn) {
this->factionIndex = factionIndex;
this->teamIndex = teamIndex;
}

View File

@ -2090,8 +2090,9 @@ void Renderer::renderConsole(const Console *console,const bool showFullConsole,
int x= console->getXPos()-5;
int y= console->getYPos()-5;
int h= console->getLineHeight()*console->getStoredLineCount();
int w= 1000;
if(h>0){
if(h > 0) {
int w= 1000;
//background
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
glEnable(GL_BLEND);
@ -4312,8 +4313,6 @@ void Renderer::renderSurface(const int renderFps) {
}
else {
int lastSurfaceDataIndex = -1;
const bool useVBOs = false;
const bool useSurfaceCache = false;
@ -4349,6 +4348,7 @@ void Renderer::renderSurface(const int renderFps) {
}
surface->reserve(qCache.visibleScaledCellList.size());
int lastSurfaceDataIndex = -1;
for(int visibleIndex = 0;
visibleIndex < qCache.visibleScaledCellList.size(); ++visibleIndex) {
Vec2i &pos = qCache.visibleScaledCellList[visibleIndex];
@ -4429,22 +4429,12 @@ void Renderer::renderSurface(const int renderFps) {
cellData->normals.push_back(tc10->getNormal());
cellData->bufferCount++;
}
/*
if(useSurfaceCache == true) {
std::pair<Chrono, std::vector<SurfaceData> > &surfaceCacheEntity = mapSurfaceData[snapshotOfvisibleQuad.getString()];
surfaceCacheEntity.first.start();
}
*/
}
//printf("\nsurface.size() = %d vs qCache.visibleScaledCellList.size() = %d snapshotOfvisibleQuad [%s]\n",surface.size(),qCache.visibleScaledCellList.size(),snapshotOfvisibleQuad.getString().c_str());
std::vector<SurfaceData> *surface = &surfaceData;
if(useSurfaceCache == true) {
std::pair<Chrono, std::vector<SurfaceData> > &surfaceCacheEntity = mapSurfaceData[snapshotOfvisibleQuad.getString()];
surface = &surfaceCacheEntity.second;
//printf("Surface Cache Size for Rendering using VA's = " MG_SIZE_T_SPECIFIER "\n",mapSurfaceData.size());
}
glEnableClientState(GL_VERTEX_ARRAY);

View File

@ -667,8 +667,6 @@ void Intro::render() {
return;
}
int difTime=0;
canRender();
incrementFps();
@ -686,7 +684,7 @@ void Intro::render() {
for(int i = 0; i < texts.size(); ++i) {
Text *text= texts[i];
difTime= 1000 * timer / GameConstants::updateFps - text->getTime();
int difTime= 1000 * timer / GameConstants::updateFps - text->getTime();
if(difTime > 0 && difTime < appearTime + showTime + disapearTime) {
float alpha= 1.f;

View File

@ -466,7 +466,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
labelTeam.setFont(CoreData::getInstance().getMenuFontBig());
labelTeam.setFont3D(CoreData::getInstance().getMenuFontBig3D());
xoffset=100;
//xoffset=100;
//texts
buttonClearBlockedPlayers.setText(lang.get("BlockPlayerClear"));

View File

@ -353,14 +353,11 @@ void MenuStateLoadGame::mouseUp(int x, int y, const MouseButton mouseButton){
}
}
void MenuStateLoadGame::deleteSlot(int i){
if(selectedButton==slots[i]){
selectedButton=NULL;
}
// buttonToDelete=slots[i];
// slots.erase(i);
// slotsGB.erase(i);
}
//void MenuStateLoadGame::deleteSlot(int i){
// if(selectedButton==slots[i]){
// selectedButton=NULL;
// }
//}
void MenuStateLoadGame::mouseMove(int x, int y, const MouseState *ms){

View File

@ -67,7 +67,7 @@ public:
private:
void clearSlots();
void deleteSlot(int i);
//void deleteSlot(int i);
void listFiles();
void showMessageBox(const string &text, const string &header, bool toggle);

View File

@ -301,20 +301,20 @@ void MenuStateOptionsNetwork::reloadUI() {
GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName);
}
void MenuStateOptionsNetwork::showMessageBox(const string &text, const string &header, bool toggle){
if(!toggle){
mainMessageBox.setEnabled(false);
}
if(!mainMessageBox.getEnabled()){
mainMessageBox.setText(text);
mainMessageBox.setHeader(header);
mainMessageBox.setEnabled(true);
}
else{
mainMessageBox.setEnabled(false);
}
}
//void MenuStateOptionsNetwork::showMessageBox(const string &text, const string &header, bool toggle){
// if(!toggle){
// mainMessageBox.setEnabled(false);
// }
//
// if(!mainMessageBox.getEnabled()){
// mainMessageBox.setText(text);
// mainMessageBox.setHeader(header);
// mainMessageBox.setEnabled(true);
// }
// else{
// mainMessageBox.setEnabled(false);
// }
//}
void MenuStateOptionsNetwork::mouseClick(int x, int y, MouseButton mouseButton){

View File

@ -82,7 +82,7 @@ public:
private:
void saveConfig();
void setActiveInputLable(GraphicLabel* newLable);
void showMessageBox(const string &text, const string &header, bool toggle);
//void showMessageBox(const string &text, const string &header, bool toggle);
};
}}//end namespace

View File

@ -230,20 +230,20 @@ void MenuStateOptionsSound::reloadUI() {
void MenuStateOptionsSound::showMessageBox(const string &text, const string &header, bool toggle){
if(!toggle){
mainMessageBox.setEnabled(false);
}
if(!mainMessageBox.getEnabled()){
mainMessageBox.setText(text);
mainMessageBox.setHeader(header);
mainMessageBox.setEnabled(true);
}
else{
mainMessageBox.setEnabled(false);
}
}
//void MenuStateOptionsSound::showMessageBox(const string &text, const string &header, bool toggle){
// if(!toggle){
// mainMessageBox.setEnabled(false);
// }
//
// if(!mainMessageBox.getEnabled()){
// mainMessageBox.setText(text);
// mainMessageBox.setHeader(header);
// mainMessageBox.setEnabled(true);
// }
// else{
// mainMessageBox.setEnabled(false);
// }
//}
void MenuStateOptionsSound::mouseClick(int x, int y, MouseButton mouseButton){

View File

@ -66,7 +66,7 @@ public:
private:
void saveConfig();
void setActiveInputLable(GraphicLabel* newLable);
void showMessageBox(const string &text, const string &header, bool toggle);
//void showMessageBox(const string &text, const string &header, bool toggle);
};
}}//end namespace

View File

@ -77,7 +77,7 @@ void ClientInterfaceThread::execute() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ****************** STARTING worker thread this = %p\n",__FILE__,__FUNCTION__,__LINE__,this);
bool minorDebugPerformance = false;
//bool minorDebugPerformance = false;
Chrono chrono;
// Set socket to blocking
@ -1044,7 +1044,6 @@ void ClientInterface::updateFrame(int *checkFrame) {
case nmtCommandList:
{
int waitCount = 0;
//make sure we read the message
time_t receiveTimeElapsed = time(NULL);
NetworkMessageCommandList networkMessageCommandList;
@ -1060,13 +1059,7 @@ void ClientInterface::updateFrame(int *checkFrame) {
throw megaglest_runtime_error("error retrieving nmtCommandList returned false!");
}
// while(receiveMessage(&networkMessageCommandList) == false &&
// isConnected() == true &&
// difftime(time(NULL),receiveTimeElapsed) <= (messageWaitTimeout / 2000)) {
// waitCount++;
// }
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] receiveMessage took %lld msecs, waitCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),waitCount);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] receiveMessage took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
MutexSafeWrapper safeMutex(networkCommandListThreadAccessor,CODE_AT_LINE);

View File

@ -23,6 +23,7 @@ TilesetModelType::TilesetModelType() {
height = 0;
rotationAllowed = false;
smoothTwoFrameAnim = false;
randomPositionEnabled = false;
animSpeed = 0;
}

View File

@ -499,9 +499,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
}
}
}
else{
if(f) fclose(f);
else {
throw megaglest_runtime_error("Can't open file");
}
fclose(f);

View File

@ -633,13 +633,12 @@ void World::updateAllFactionUnits() {
perfList.push_back(perfBuf);
}
bool workThreadsFinished = false;
Chrono chrono;
chrono.start();
const int MAX_FACTION_THREAD_WAIT_MILLISECONDS = 20000;
for(;chrono.getMillis() < MAX_FACTION_THREAD_WAIT_MILLISECONDS;) {
workThreadsFinished = true;
bool workThreadsFinished = true;
for(int i = 0; i < factionCount; ++i) {
Faction *faction = getFaction(i);
if(faction->isWorkerThreadSignalCompleted(frameCount) == false) {

View File

@ -153,13 +153,13 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
//std::cout << "output width and height: " << cinfo.output_width <<" pixels and " << cinfo.output_height <<" pixels." << std::endl;
/* now actually read the jpeg into the raw buffer */
row_pointer[0] = new unsigned char[cinfo.output_width*cinfo.num_components];
size_t location = 0; //Current pixel
/* read one scan line at a time */
/* Again you need to invert the lines unfortunately*/
while( cinfo.output_scanline < cinfo.output_height )
{
jpeg_read_scanlines( &cinfo, row_pointer, 1 );
location = (cinfo.output_height - cinfo.output_scanline)*cinfo.output_width*picComponents;
//Current pixel
size_t location = (cinfo.output_height - cinfo.output_scanline) * cinfo.output_width * picComponents;
if (picComponents == cinfo.num_components) {
memcpy(pixels+location,row_pointer[0],cinfo.output_width*cinfo.num_components);
} else {

View File

@ -438,14 +438,14 @@ bool fileExists(const string &path) {
fclose(file);
return true;
}
else {
// else {
//int fileErrno = errno;
#ifdef WIN32
int fileErrno = errno;
DWORD error = GetLastError();
string strError = "[#6] Could not open file, result: " + intToStr(error) + " - " + intToStr(fileErrno) + " " + strerror(fileErrno) + " [" + path + "]";
#endif
}
//#ifdef WIN32
//int fileErrno = errno;
//DWORD error = GetLastError();
//string strError = "[#6] Could not open file, result: " + intToStr(error) + " - " + intToStr(fileErrno) + " " + strerror(fileErrno) + " [" + path + "]";
//#endif
// }
return false;
}
@ -699,7 +699,7 @@ pair<bool,time_t> hasCachedFileCRCValue(string crcCacheFile, uint32 &value) {
char gameVer[500]="";
char svnVer[500]="";
char actualFilePath[8096]="";
int readbytes = fscanf(fp,"%20ld,%20u,%20ld\n%s\n%s\n%s",
int readbytes = fscanf(fp,"%20ld,%20u,%20ld\n%499s\n%499s\n%8095s",
&refreshDate,
&crcValue,
&lastUpdateDate,

View File

@ -96,9 +96,8 @@ void FileCRCPreCacheThread::execute() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] techsPerWorker = %u, MAX_FileCRCPreCacheThread_WORKER_THREADS = %d, techPaths.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,techsPerWorker,MAX_FileCRCPreCacheThread_WORKER_THREADS,(int)techPaths.size());
unsigned int consumedWorkers = 0;
try {
unsigned int consumedWorkers = 0;
for(unsigned int workerIdx = 0; workerIdx < MAX_FileCRCPreCacheThread_WORKER_THREADS; ++workerIdx) {
if(getQuitStatus() == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -162,9 +161,9 @@ void FileCRCPreCacheThread::execute() {
sleep(0);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Waiting for Spawned CRC threads to complete, preCacheWorkerThreadList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,(int)preCacheWorkerThreadList.size());
bool hasRunningWorkerThread = true;
try {
bool hasRunningWorkerThread = true;
for(;hasRunningWorkerThread == true;) {
hasRunningWorkerThread = false;
for(unsigned int idx = 0; idx < preCacheWorkerThreadList.size(); idx++) {

View File

@ -236,8 +236,6 @@ void event_privmsg (irc_session_t * session, const char * event, const char * or
}
void dcc_recv_callback (irc_session_t * session, irc_dcc_t id, int status, void * ctx, const char * data, unsigned int length) {
static int count = 1;
char buf[12]="";
switch (status)
{
@ -252,6 +250,9 @@ void dcc_recv_callback (irc_session_t * session, irc_dcc_t id, int status, void
}
else {
if(SystemFlags::VERBOSE_MODE_ENABLED || IRCThread::debugEnabled) printf ("DCC %d: %s\n", id, data);
static int count = 1;
char buf[12]="";
sprintf (buf, "DCC [%d]: %d", id, count++);
irc_dcc_msg (session, id, buf);
}

View File

@ -272,7 +272,7 @@ void Thread::queueAutoCleanThread() {
if(Thread::getEnableVerboseMode()) printf("In Thread::shutdownThreads Line: %d\n",__LINE__);
BaseThread *base_thread = dynamic_cast<BaseThread *>(this);
ThreadGarbageCollector *garbage_collector = dynamic_cast<ThreadGarbageCollector *>(this);
//ThreadGarbageCollector *garbage_collector = dynamic_cast<ThreadGarbageCollector *>(this);
if(Thread::getEnableVerboseMode()) printf("In Thread::shutdownThreads Line: %d thread = %p base_thread = %p [%s]\n",__LINE__,this,base_thread,(base_thread != NULL ? base_thread->getUniqueID().c_str() : "n/a"));
MutexSafeWrapper safeMutex(cleanupThreadMutex.get());

View File

@ -179,7 +179,6 @@ void Properties::load(const string &path, bool clearCurrentProperties) {
string getUserHomeFromGLIBC() {
string home_folder = "";
char dateiname[512];
const char *homedir = getenv("HOME");
if (!homedir) {
#if _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED

View File

@ -833,31 +833,17 @@ bool checkVersionComptability(string clientVersionString, string serverVersionSt
if(SystemFlags::VERBOSE_MODE_ENABLED) {
// debug version strings
for(unsigned int i = 0; i < tokensServer.size(); ++i) {
printf("Server version index = %d str [%s] IsNumeric = %d\n",i,tokensServer[i].c_str(),IsNumeric(tokensServer[i].c_str(),false));
printf("Server version index = %u str [%s] IsNumeric = %d\n",i,tokensServer[i].c_str(),IsNumeric(tokensServer[i].c_str(),false));
}
for(unsigned int i = 0; i < tokens.size(); ++i) {
printf("Client version index = %d str [%s] IsNumeric = %d\n",i,tokens[i].c_str(),IsNumeric(tokens[i].c_str(),false));
printf("Client version index = %u str [%s] IsNumeric = %d\n",i,tokens[i].c_str(),IsNumeric(tokens[i].c_str(),false));
}
}
// **NOTE:
// after of 3.7.0 we go to 2 digi version compatibility, check if both
// client and server are at least 3.7
bool compatiblePost3_7_0_Check = false;
bool compatiblePre3_7_0_1_Check = true;
// if(tokens.size() >= 3 && tokensServer.size() >= 3 &&
// tokensServer[0] != "" && IsNumeric(tokensServer[0].c_str(),false) && strToInt(tokensServer[0]) == 3 &&
// tokensServer[1] != "" && IsNumeric(tokensServer[1].c_str(),false) && strToInt(tokensServer[1]) == 7 &&
// (tokensServer[2][0] == '0' || tokensServer[2][0] == '1') &&
// tokens[0] != "" && IsNumeric(tokens[0].c_str(),false) && strToInt(tokens[0]) == 3 &&
// tokens[1] != "" && IsNumeric(tokens[1].c_str(),false) && strToInt(tokens[1]) == 7 &&
// (tokens[2][0] == '0' || tokens[2][0] == '1')) {
//
// compatiblePost3_7_0_Check = false;
// compatiblePre3_7_0_1_Check = false;
// compatible = true;
// }
// else if(tokens.size() >= 2 && tokensServer.size() >= 2) {
if(tokens.size() >= 2 && tokensServer.size() >= 2) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
@ -869,6 +855,7 @@ bool checkVersionComptability(string clientVersionString, string serverVersionSt
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
bool compatiblePost3_7_0_Check = false;
// Both are at least 3.7.0, now check if both are > 3.7.0
if(tokens.size() >= 3 && tokensServer.size() >= 3) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);