- updates to Chinese font support so Linux will compile

- added more debugging and NULL guards
This commit is contained in:
Mark Vejvoda 2010-05-03 06:25:54 +00:00
parent c3793d0cfb
commit 1efc2dc0a6
13 changed files with 207 additions and 62 deletions

View File

@ -196,32 +196,43 @@ void Game::load(){
//throw runtime_error("Test!"); //throw runtime_error("Test!");
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//tileset //tileset
world.loadTileset(config.getPathListForType(ptTilesets,scenarioDir), tilesetName, &checksum); world.loadTileset(config.getPathListForType(ptTilesets,scenarioDir), tilesetName, &checksum);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
set<string> factions; set<string> factions;
for ( int i=0; i < gameSettings.getFactionCount(); ++i ) { for ( int i=0; i < gameSettings.getFactionCount(); ++i ) {
factions.insert(gameSettings.getFactionTypeName(i)); factions.insert(gameSettings.getFactionTypeName(i));
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//tech, load before map because of resources //tech, load before map because of resources
world.loadTech(config.getPathListForType(ptTechs,scenarioDir), techName, factions, &checksum); world.loadTech(config.getPathListForType(ptTechs,scenarioDir), techName, factions, &checksum);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//map //map
world.loadMap(Map::getMapPath(mapName,scenarioDir), &checksum); world.loadMap(Map::getMapPath(mapName,scenarioDir), &checksum);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//scenario //scenario
if(!scenarioName.empty()){ if(!scenarioName.empty()){
Lang::getInstance().loadScenarioStrings(gameSettings.getScenarioDir(), scenarioName); Lang::getInstance().loadScenarioStrings(gameSettings.getScenarioDir(), scenarioName);
world.loadScenario(gameSettings.getScenarioDir(), &checksum); world.loadScenario(gameSettings.getScenarioDir(), &checksum);
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__); //good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
} }
void Game::init() void Game::init()
{ {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Lang &lang= Lang::getInstance(); Lang &lang= Lang::getInstance();
Logger &logger= Logger::getInstance(); Logger &logger= Logger::getInstance();
@ -230,7 +241,7 @@ void Game::init()
Map *map= world.getMap(); Map *map= world.getMap();
NetworkManager &networkManager= NetworkManager::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Initializing\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
logger.setState(lang.get("Initializing")); logger.setState(lang.get("Initializing"));
//mesage box //mesage box
@ -318,7 +329,7 @@ void Game::init()
logger.add("Launching game"); logger.add("Launching game");
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
@ -326,6 +337,7 @@ void Game::init()
//update //update
void Game::update(){ void Game::update(){
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// a) Updates non dependant on speed // a) Updates non dependant on speed
@ -336,14 +348,18 @@ void Game::update(){
//console //console
console.update(); console.update();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// b) Updates depandant on speed // b) Updates depandant on speed
int updateLoops= getUpdateLoops(); int updateLoops= getUpdateLoops();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//update //update
for(int i=0; i<updateLoops; ++i){ for(int i=0; i<updateLoops; ++i){
Renderer &renderer= Renderer::getInstance(); Renderer &renderer= Renderer::getInstance();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//AiInterface //AiInterface
for(int i=0; i<world.getFactionCount(); ++i){ for(int i=0; i<world.getFactionCount(); ++i){
if(world.getFaction(i)->getCpuControl() && scriptManager.getPlayerModifiers(i)->getAiEnabled()){ if(world.getFaction(i)->getCpuControl() && scriptManager.getPlayerModifiers(i)->getAiEnabled()){
@ -351,24 +367,31 @@ void Game::update(){
} }
} }
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//World //World
world.update(); world.update();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// Commander // Commander
commander.updateNetwork(); commander.updateNetwork();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//Gui //Gui
gui.update(); gui.update();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//Particle systems //Particle systems
if(weatherParticleSystem != NULL){ if(weatherParticleSystem != NULL){
weatherParticleSystem->setPos(gameCamera.getPos()); weatherParticleSystem->setPos(gameCamera.getPos());
} }
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.updateParticleManager(rsGame); renderer.updateParticleManager(rsGame);
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__); //good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
} }
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//call the chat manager //call the chat manager
chatManager.updateNetwork(); chatManager.updateNetwork();
@ -381,6 +404,8 @@ void Game::update(){
if(Config::getInstance().getBool("AutoTest")){ if(Config::getInstance().getBool("AutoTest")){
AutoTest::getInstance().updateGame(this); AutoTest::getInstance().updateGame(this);
} }
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
void Game::updateCamera(){ void Game::updateCamera(){
@ -392,10 +417,20 @@ void Game::updateCamera(){
//render //render
void Game::render(){ void Game::render(){
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderFps++; renderFps++;
render3d(); render3d();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
render2d(); render2d();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer::getInstance().swapBuffers(); Renderer::getInstance().swapBuffers();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
// ==================== tick ==================== // ==================== tick ====================
@ -785,41 +820,54 @@ void Game::quitGame(){
// ==================== render ==================== // ==================== render ====================
void Game::render3d(){ void Game::render3d(){
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer &renderer= Renderer::getInstance(); Renderer &renderer= Renderer::getInstance();
//init //init
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.reset3d(); renderer.reset3d();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.computeVisibleQuad(); renderer.computeVisibleQuad();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.loadGameCameraMatrix(); renderer.loadGameCameraMatrix();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.setupLighting(); renderer.setupLighting();
//shadow map //shadow map
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderShadowsToTexture(); renderer.renderShadowsToTexture();
//clear buffers //clear buffers
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.clearBuffers(); renderer.clearBuffers();
//surface //surface
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderSurface(); renderer.renderSurface();
//selection circles //selection circles
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderSelectionEffects(); renderer.renderSelectionEffects();
//units //units
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderUnits(); renderer.renderUnits();
//objects //objects
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderObjects(); renderer.renderObjects();
//water //water
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderWater(); renderer.renderWater();
renderer.renderWaterEffects(); renderer.renderWaterEffects();
//particles //particles
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderParticleManager(rsGame); renderer.renderParticleManager(rsGame);
//mouse 3d //mouse 3d
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderMouse3d(); renderer.renderMouse3d();
} }

View File

@ -2150,7 +2150,10 @@ void Renderer::renderShadowsToTexture(){
//directional light //directional light
//light pos //light pos
assert(game != NULL);
assert(game->getWorld() != NULL);
const TimeFlow *tf= game->getWorld()->getTimeFlow(); const TimeFlow *tf= game->getWorld()->getTimeFlow();
assert(tf != NULL);
float ang= tf->isDay()? computeSunAngle(tf->getTime()): computeMoonAngle(tf->getTime()); float ang= tf->isDay()? computeSunAngle(tf->getTime()): computeMoonAngle(tf->getTime());
ang= radToDeg(ang); ang= radToDeg(ang);
@ -2462,7 +2465,9 @@ Vec4f Renderer::computeWaterColor(float waterLevel, float cellHeight){
//render units for selection purposes //render units for selection purposes
void Renderer::renderUnitsFast(){ void Renderer::renderUnitsFast(){
assert(game != NULL);
const World *world= game->getWorld(); const World *world= game->getWorld();
assert(world != NULL);
assertGl(); assertGl();

View File

@ -323,12 +323,12 @@ int glestMain(int argc, char** argv){
// 256 for English // 256 for English
// 30000 for Chinese // 30000 for Chinese
Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(256).c_str()); Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str());
Font::fontTypeName = config.getString("FONT_TYPENAME","Times New Roman"); Font::fontTypeName = config.getString("FONT_TYPENAME",Font::fontTypeName.c_str());
// Example values: // Example values:
// DEFAULT_CHARSET (English) = 1 // DEFAULT_CHARSET (English) = 1
// GB2312_CHARSET (Chinese) = 134 // GB2312_CHARSET (Chinese) = 134
Shared::Platform::charSet = config.getInt("FONT_CHARSET",intToStr(DEFAULT_CHARSET).c_str()); Shared::Platform::charSet = config.getInt("FONT_CHARSET",intToStr(Shared::Platform::charSet).c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d\n",__FILE__,__FUNCTION__,__LINE__,Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d\n",__FILE__,__FUNCTION__,__LINE__,Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet);

View File

@ -183,17 +183,20 @@ void Program::keyPress(char c){
void Program::loop(){ void Program::loop(){
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//render //render
assert(programState != NULL);
programState->render(); programState->render();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//update camera //update camera
while(updateCameraTimer.isTime()){ while(updateCameraTimer.isTime()){
programState->updateCamera(); programState->updateCamera();
} }
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//update world //update world
while(updateTimer.isTime()){ while(updateTimer.isTime()){
@ -244,18 +247,18 @@ void Program::resize(SizeState sizeState){
void Program::setState(ProgramState *programState, bool cleanupOldState) void Program::setState(ProgramState *programState, bool cleanupOldState)
{ {
try { try {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
if(cleanupOldState == true) { if(cleanupOldState == true) {
delete this->programState; delete this->programState;
} }
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
this->programState= programState; this->programState= programState;
programState->load(); programState->load();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
programState->init(); programState->init();
@ -265,7 +268,7 @@ void Program::setState(ProgramState *programState, bool cleanupOldState)
updateCameraTimer.reset(); updateCameraTimer.reset();
fpsTimer.reset(); fpsTimer.reset();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
} }
catch(const exception &e){ catch(const exception &e){
//exceptionMessage(e); //exceptionMessage(e);
@ -365,7 +368,7 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
soundRenderer.init(window); soundRenderer.init(window);
// Run sound streaming in a background thread if enabled // Run sound streaming in a background thread if enabled
if(config.getBool("ThreadedSoundStream","true") == true) { if(config.getBool("ThreadedSoundStream","false") == true) {
BaseThread::shutdownAndWait(soundThreadManager); BaseThread::shutdownAndWait(soundThreadManager);
delete soundThreadManager; delete soundThreadManager;
soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,50); soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,50);
@ -373,8 +376,8 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
} }
} }
NetworkInterface::setAllowGameDataSynchCheck(Config::getInstance().getBool("AllowGameDataSynchCheck","0")); NetworkInterface::setAllowGameDataSynchCheck(Config::getInstance().getBool("AllowGameDataSynchCheck","false"));
NetworkInterface::setAllowDownloadDataSynch(Config::getInstance().getBool("AllowDownloadDataSynch","0")); NetworkInterface::setAllowDownloadDataSynch(Config::getInstance().getBool("AllowDownloadDataSynch","false"));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }

View File

@ -1,7 +1,7 @@
// ============================================================== // ==============================================================
// This file is part of Glest (www.glest.org) // This file is part of Glest (www.glest.org)
// //
// Copyright (C) 2001-2008 Martiño Figueroa // Copyright (C) 2001-2008 Martio Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // the terms of the GNU General Public License as published
@ -37,6 +37,7 @@ SoundRenderer::SoundRenderer(){
soundPlayer = NULL; soundPlayer = NULL;
loadConfig(); loadConfig();
runThreadSafe = false;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
@ -46,6 +47,7 @@ void SoundRenderer::init(Window *window){
SoundInterface &si= SoundInterface::getInstance(); SoundInterface &si= SoundInterface::getInstance();
FactoryRepository &fr= FactoryRepository::getInstance(); FactoryRepository &fr= FactoryRepository::getInstance();
Config &config= Config::getInstance(); Config &config= Config::getInstance();
runThreadSafe = config.getBool("ThreadedSoundStream","false");
//if(soundPlayer == NULL) { //if(soundPlayer == NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -85,7 +87,9 @@ SoundRenderer &SoundRenderer::getInstance(){
void SoundRenderer::update(){ void SoundRenderer::update(){
if(soundPlayer != NULL) { if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->updateStreams(); soundPlayer->updateStreams();
if(runThreadSafe == true) mutex.v();
} }
} }
@ -95,16 +99,20 @@ void SoundRenderer::playMusic(StrSound *strSound){
strSound->setVolume(musicVolume); strSound->setVolume(musicVolume);
strSound->restart(); strSound->restart();
if(soundPlayer != NULL) { if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(strSound); soundPlayer->play(strSound);
if(runThreadSafe == true) mutex.v();
} }
} }
void SoundRenderer::stopMusic(StrSound *strSound){ void SoundRenderer::stopMusic(StrSound *strSound){
if(soundPlayer != NULL) { if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->stop(strSound); soundPlayer->stop(strSound);
if(strSound->getNext() != NULL) { if(strSound->getNext() != NULL) {
soundPlayer->stop(strSound->getNext()); soundPlayer->stop(strSound->getNext());
} }
if(runThreadSafe == true) mutex.v();
} }
} }
@ -114,13 +122,15 @@ void SoundRenderer::playFx(StaticSound *staticSound, Vec3f soundPos, Vec3f camPo
if(staticSound!=NULL){ if(staticSound!=NULL){
float d= soundPos.dist(camPos); float d= soundPos.dist(camPos);
if(d<audibleDist){ if(d < audibleDist){
float vol= (1.f-d/audibleDist)*fxVolume; float vol= (1.f-d/audibleDist)*fxVolume;
float correctedVol= log10(log10(vol*9+1)*9+1); float correctedVol= log10(log10(vol*9+1)*9+1);
staticSound->setVolume(correctedVol); staticSound->setVolume(correctedVol);
if(soundPlayer != NULL) { if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(staticSound); soundPlayer->play(staticSound);
if(runThreadSafe == true) mutex.v();
} }
} }
} }
@ -130,7 +140,9 @@ void SoundRenderer::playFx(StaticSound *staticSound){
if(staticSound!=NULL){ if(staticSound!=NULL){
staticSound->setVolume(fxVolume); staticSound->setVolume(fxVolume);
if(soundPlayer != NULL) { if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(staticSound); soundPlayer->play(staticSound);
if(runThreadSafe == true) mutex.v();
} }
} }
} }
@ -140,13 +152,17 @@ void SoundRenderer::playFx(StaticSound *staticSound){
void SoundRenderer::playAmbient(StrSound *strSound){ void SoundRenderer::playAmbient(StrSound *strSound){
strSound->setVolume(ambientVolume); strSound->setVolume(ambientVolume);
if(soundPlayer != NULL) { if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(strSound, ambientFade); soundPlayer->play(strSound, ambientFade);
if(runThreadSafe == true) mutex.v();
} }
} }
void SoundRenderer::stopAmbient(StrSound *strSound){ void SoundRenderer::stopAmbient(StrSound *strSound){
if(soundPlayer != NULL) { if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->stop(strSound, ambientFade); soundPlayer->stop(strSound, ambientFade);
if(runThreadSafe == true) mutex.v();
} }
} }
@ -154,7 +170,9 @@ void SoundRenderer::stopAmbient(StrSound *strSound){
void SoundRenderer::stopAllSounds(){ void SoundRenderer::stopAllSounds(){
if(soundPlayer != NULL) { if(soundPlayer != NULL) {
mutex.p();
soundPlayer->stopAllSounds(); soundPlayer->stopAllSounds();
mutex.v();
} }
} }

View File

@ -1,7 +1,7 @@
// ============================================================== // ==============================================================
// This file is part of Glest (www.glest.org) // This file is part of Glest (www.glest.org)
// //
// Copyright (C) 2001-2008 Martiño Figueroa // Copyright (C) 2001-2008 Martio Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // the terms of the GNU General Public License as published
@ -45,6 +45,9 @@ private:
float musicVolume; float musicVolume;
float ambientVolume; float ambientVolume;
Mutex mutex;
bool runThreadSafe;
private: private:
SoundRenderer(); SoundRenderer();

View File

@ -35,6 +35,8 @@ void Faction::init(
const FactionType *factionType, ControlType control, TechTree *techTree, Game *game, const FactionType *factionType, ControlType control, TechTree *techTree, Game *game,
int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources) int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources)
{ {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
this->control= control; this->control= control;
this->factionType= factionType; this->factionType= factionType;
this->startLocationIndex= startLocationIndex; this->startLocationIndex= startLocationIndex;
@ -56,10 +58,14 @@ void Faction::init(
texture= Renderer::getInstance().newTexture2D(rsGame); texture= Renderer::getInstance().newTexture2D(rsGame);
texture->load("data/core/faction_textures/faction"+intToStr(index)+".tga"); texture->load("data/core/faction_textures/faction"+intToStr(index)+".tga");
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
void Faction::end(){ void Faction::end(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
deleteValues(units.begin(), units.end()); deleteValues(units.begin(), units.end());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
// ================== get ================== // ================== get ==================
@ -109,7 +115,7 @@ void Faction::finishUpgrade(const UpgradeType *ut){
//checks if all required units and upgrades are present //checks if all required units and upgrades are present
bool Faction::reqsOk(const RequirableType *rt) const{ bool Faction::reqsOk(const RequirableType *rt) const{
assert(rt != NULL);
//required units //required units
for(int i=0; i<rt->getUnitReqCount(); ++i){ for(int i=0; i<rt->getUnitReqCount(); ++i){
bool found=false; bool found=false;
@ -137,7 +143,7 @@ bool Faction::reqsOk(const RequirableType *rt) const{
} }
bool Faction::reqsOk(const CommandType *ct) const{ bool Faction::reqsOk(const CommandType *ct) const{
assert(ct != NULL);
if(ct->getProduced()!=NULL && !reqsOk(ct->getProduced())){ if(ct->getProduced()!=NULL && !reqsOk(ct->getProduced())){
return false; return false;
} }
@ -161,6 +167,7 @@ bool Faction::applyCosts(const ProducibleType *p){
return false; return false;
} }
assert(p != NULL);
//for each unit cost spend it //for each unit cost spend it
//pass 2, decrease resources, except negative static costs (ie: farms) //pass 2, decrease resources, except negative static costs (ie: farms)
for(int i=0; i<p->getCostCount(); ++i) for(int i=0; i<p->getCostCount(); ++i)
@ -179,10 +186,12 @@ bool Faction::applyCosts(const ProducibleType *p){
//apply discount (when a morph ends) //apply discount (when a morph ends)
void Faction::applyDiscount(const ProducibleType *p, int discount) void Faction::applyDiscount(const ProducibleType *p, int discount)
{ {
assert(p != NULL);
//increase resources //increase resources
for(int i=0; i<p->getCostCount(); ++i) for(int i=0; i<p->getCostCount(); ++i)
{ {
const ResourceType *rt= p->getCost(i)->getType(); const ResourceType *rt= p->getCost(i)->getType();
assert(rt != NULL);
int cost= p->getCost(i)->getAmount(); int cost= p->getCost(i)->getAmount();
if((cost > 0 || (rt->getClass() != rcStatic)) && rt->getClass() != rcConsumable) if((cost > 0 || (rt->getClass() != rcStatic)) && rt->getClass() != rcConsumable)
{ {
@ -194,10 +203,12 @@ void Faction::applyDiscount(const ProducibleType *p, int discount)
//apply static production (for starting units) //apply static production (for starting units)
void Faction::applyStaticCosts(const ProducibleType *p) void Faction::applyStaticCosts(const ProducibleType *p)
{ {
assert(p != NULL);
//decrease static resources //decrease static resources
for(int i=0; i<p->getCostCount(); ++i) for(int i=0; i<p->getCostCount(); ++i)
{ {
const ResourceType *rt= p->getCost(i)->getType(); const ResourceType *rt= p->getCost(i)->getType();
assert(rt != NULL);
if(rt->getClass() == rcStatic) if(rt->getClass() == rcStatic)
{ {
int cost= p->getCost(i)->getAmount(); int cost= p->getCost(i)->getAmount();
@ -212,10 +223,12 @@ void Faction::applyStaticCosts(const ProducibleType *p)
//apply static production (when a mana source is done) //apply static production (when a mana source is done)
void Faction::applyStaticProduction(const ProducibleType *p) void Faction::applyStaticProduction(const ProducibleType *p)
{ {
assert(p != NULL);
//decrease static resources //decrease static resources
for(int i=0; i<p->getCostCount(); ++i) for(int i=0; i<p->getCostCount(); ++i)
{ {
const ResourceType *rt= p->getCost(i)->getType(); const ResourceType *rt= p->getCost(i)->getType();
assert(rt != NULL);
if(rt->getClass() == rcStatic) if(rt->getClass() == rcStatic)
{ {
int cost= p->getCost(i)->getAmount(); int cost= p->getCost(i)->getAmount();
@ -230,10 +243,12 @@ void Faction::applyStaticProduction(const ProducibleType *p)
//deapply all costs except static production (usually when a building is cancelled) //deapply all costs except static production (usually when a building is cancelled)
void Faction::deApplyCosts(const ProducibleType *p) void Faction::deApplyCosts(const ProducibleType *p)
{ {
assert(p != NULL);
//increase resources //increase resources
for(int i=0; i<p->getCostCount(); ++i) for(int i=0; i<p->getCostCount(); ++i)
{ {
const ResourceType *rt= p->getCost(i)->getType(); const ResourceType *rt= p->getCost(i)->getType();
assert(rt != NULL);
int cost= p->getCost(i)->getAmount(); int cost= p->getCost(i)->getAmount();
if((cost > 0 || (rt->getClass() != rcStatic)) && rt->getClass() != rcConsumable) if((cost > 0 || (rt->getClass() != rcStatic)) && rt->getClass() != rcConsumable)
{ {
@ -246,10 +261,12 @@ void Faction::deApplyCosts(const ProducibleType *p)
//deapply static costs (usually when a unit dies) //deapply static costs (usually when a unit dies)
void Faction::deApplyStaticCosts(const ProducibleType *p) void Faction::deApplyStaticCosts(const ProducibleType *p)
{ {
assert(p != NULL);
//decrease resources //decrease resources
for(int i=0; i<p->getCostCount(); ++i) for(int i=0; i<p->getCostCount(); ++i)
{ {
const ResourceType *rt= p->getCost(i)->getType(); const ResourceType *rt= p->getCost(i)->getType();
assert(rt != NULL);
if(rt->getClass() == rcStatic) if(rt->getClass() == rcStatic)
{ {
if(rt->getRecoup_cost() == true) if(rt->getRecoup_cost() == true)
@ -264,10 +281,12 @@ void Faction::deApplyStaticCosts(const ProducibleType *p)
//deapply static costs, but not negative costs, for when building gets killed //deapply static costs, but not negative costs, for when building gets killed
void Faction::deApplyStaticConsumption(const ProducibleType *p) void Faction::deApplyStaticConsumption(const ProducibleType *p)
{ {
assert(p != NULL);
//decrease resources //decrease resources
for(int i=0; i<p->getCostCount(); ++i) for(int i=0; i<p->getCostCount(); ++i)
{ {
const ResourceType *rt= p->getCost(i)->getType(); const ResourceType *rt= p->getCost(i)->getType();
assert(rt != NULL);
if(rt->getClass() == rcStatic) if(rt->getClass() == rcStatic)
{ {
int cost= p->getCost(i)->getAmount(); int cost= p->getCost(i)->getAmount();
@ -329,14 +348,14 @@ void Faction::applyCostsOnInterval(){
} }
bool Faction::checkCosts(const ProducibleType *pt){ bool Faction::checkCosts(const ProducibleType *pt){
assert(pt != NULL);
//for each unit cost check if enough resources //for each unit cost check if enough resources
for(int i=0; i<pt->getCostCount(); ++i){ for(int i=0; i<pt->getCostCount(); ++i){
const ResourceType *rt= pt->getCost(i)->getType(); const ResourceType *rt= pt->getCost(i)->getType();
int cost= pt->getCost(i)->getAmount(); int cost= pt->getCost(i)->getAmount();
if(cost>0){ if(cost > 0) {
int available= getResource(rt)->getAmount(); int available= getResource(rt)->getAmount();
if(cost>available){ if(cost > available){
return false; return false;
} }
} }
@ -348,6 +367,7 @@ bool Faction::checkCosts(const ProducibleType *pt){
// ================== diplomacy ================== // ================== diplomacy ==================
bool Faction::isAlly(const Faction *faction){ bool Faction::isAlly(const Faction *faction){
assert(faction != NULL);
return teamIndex==faction->getTeam(); return teamIndex==faction->getTeam();
} }
@ -409,6 +429,7 @@ void Faction::removeUnit(Unit *unit){
} }
void Faction::addStore(const UnitType *unitType){ void Faction::addStore(const UnitType *unitType){
assert(unitType != NULL);
for(int i=0; i<unitType->getStoredResourceCount(); ++i){ for(int i=0; i<unitType->getStoredResourceCount(); ++i){
const Resource *r= unitType->getStoredResource(i); const Resource *r= unitType->getStoredResource(i);
for(int j=0; j<store.size(); ++j){ for(int j=0; j<store.size(); ++j){
@ -421,6 +442,7 @@ void Faction::addStore(const UnitType *unitType){
} }
void Faction::removeStore(const UnitType *unitType){ void Faction::removeStore(const UnitType *unitType){
assert(unitType != NULL);
for(int i=0; i<unitType->getStoredResourceCount(); ++i){ for(int i=0; i<unitType->getStoredResourceCount(); ++i){
const Resource *r= unitType->getStoredResource(i); const Resource *r= unitType->getStoredResource(i);
for(int j=0; j<store.size(); ++j){ for(int j=0; j<store.size(); ++j){

View File

@ -1,7 +1,7 @@
// ============================================================== // ==============================================================
// This file is part of Glest (www.glest.org) // This file is part of Glest (www.glest.org)
// //
// Copyright (C) 2001-2008 Martiño Figueroa // Copyright (C) 2001-2008 Martio Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // the terms of the GNU General Public License as published
@ -42,6 +42,7 @@ void TechTree::loadTech(const vector<string> pathList, const string &techName, s
} }
void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum) { void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string str; string str;
vector<string> filenames; vector<string> filenames;
@ -122,10 +123,12 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
catch(const exception &e){ catch(const exception &e){
throw runtime_error("Error loading Faction Types: "+ dir + "\n" + e.what()); throw runtime_error("Error loading Faction Types: "+ dir + "\n" + e.what());
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
TechTree::~TechTree(){ TechTree::~TechTree(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("Tech tree", true); Logger::getInstance().add("Tech tree", true);
} }
@ -133,8 +136,10 @@ TechTree::~TechTree(){
// ==================== get ==================== // ==================== get ====================
const FactionType *TechTree::getType(const string &name) const{ const FactionType *TechTree::getType(const string &name) const{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(int i=0; i<factionTypes.size(); ++i){ for(int i=0; i<factionTypes.size(); ++i){
if(factionTypes[i].getName()==name){ if(factionTypes[i].getName()==name){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return &factionTypes[i]; return &factionTypes[i];
} }
} }
@ -142,9 +147,9 @@ const FactionType *TechTree::getType(const string &name) const{
} }
const ResourceType *TechTree::getTechResourceType(int i) const{ const ResourceType *TechTree::getTechResourceType(int i) const{
for(int j=0; j<getResourceTypeCount(); ++j){ for(int j=0; j<getResourceTypeCount(); ++j){
const ResourceType *rt= getResourceType(j); const ResourceType *rt= getResourceType(j);
assert(rt != NULL);
if(rt->getResourceNumber()==i && rt->getClass()==rcTech) if(rt->getResourceNumber()==i && rt->getClass()==rcTech)
return getResourceType(j); return getResourceType(j);
} }
@ -155,6 +160,7 @@ const ResourceType *TechTree::getTechResourceType(int i) const{
const ResourceType *TechTree::getFirstTechResourceType() const{ const ResourceType *TechTree::getFirstTechResourceType() const{
for(int i=0; i<getResourceTypeCount(); ++i){ for(int i=0; i<getResourceTypeCount(); ++i){
const ResourceType *rt= getResourceType(i); const ResourceType *rt= getResourceType(i);
assert(rt != NULL);
if(rt->getResourceNumber()==1 && rt->getClass()==rcTech) if(rt->getResourceNumber()==1 && rt->getClass()==rcTech)
return getResourceType(i); return getResourceType(i);
} }

View File

@ -25,7 +25,6 @@
#include "game_util.h" #include "game_util.h"
#include "leak_dumper.h" #include "leak_dumper.h"
#include "unit_particle_type.h" #include "unit_particle_type.h"
//#include "socket.h"
using namespace Shared::Xml; using namespace Shared::Xml;
using namespace Shared::Graphics; using namespace Shared::Graphics;
@ -91,7 +90,6 @@ UnitType::~UnitType(){
delete damageParticleSystemTypes.back(); delete damageParticleSystemTypes.back();
damageParticleSystemTypes.pop_back(); damageParticleSystemTypes.pop_back();
} }
} }
void UnitType::preLoad(const string &dir){ void UnitType::preLoad(const string &dir){
@ -102,15 +100,15 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string path = dir + "/" + name + ".xml";
this->id= id; this->id= id;
string path;
try{ try{
Logger::getInstance().add("Unit type: " + formatString(name), true); Logger::getInstance().add("Unit type: " + formatString(name), true);
//file load //file load
path= dir+"/"+name+".xml";
checksum->addFile(path); checksum->addFile(path);
XmlTree xmlTree; XmlTree xmlTree;
@ -170,21 +168,6 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
cellMap[i*size+j]= row[j]=='0'? false: true; cellMap[i*size+j]= row[j]=='0'? false: true;
} }
} }
/*
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Original Unit cellmap matrix below [%s] [%s]:\n",__FILE__,__FUNCTION__,getName().c_str(),path.c_str());
for(int iRow = 0; iRow < size; ++iRow) {
const XmlNode *rowNode= cellMapNode->getChild("row", iRow);
string row= rowNode->getAttribute("value")->getRestrictedValue();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] row = %s\n",__FILE__,__FUNCTION__,row.c_str());
for(int iCol = 0; iCol < size; ++iCol) {
bool getCellResult = getCellMapCell(iCol, iRow);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] matrix [%d,%d] = %d\n",__FILE__,__FUNCTION__,iRow,iCol,getCellResult);
}
}
*/
} }
//levels //levels

View File

@ -21,6 +21,7 @@
#include "logger.h" #include "logger.h"
#include "sound_renderer.h" #include "sound_renderer.h"
#include "game_settings.h" #include "game_settings.h"
#include "cache_manager.h"
#include "leak_dumper.h" #include "leak_dumper.h"
using namespace Shared::Graphics; using namespace Shared::Graphics;
@ -37,8 +38,10 @@ const float World::airHeight= 5.f;
// ===================== PUBLIC ======================== // ===================== PUBLIC ========================
World::World(){ World::World(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Config &config= Config::getInstance(); Config &config= Config::getInstance();
techTree = NULL;
fogOfWarOverride = false; fogOfWarOverride = false;
fogOfWarSmoothing= config.getBool("FogOfWarSmoothing"); fogOfWarSmoothing= config.getBool("FogOfWarSmoothing");
@ -51,9 +54,18 @@ World::World(){
this->game = NULL; this->game = NULL;
allowRotateUnits = Config::getInstance().getBool("AllowRotateUnits","0"); allowRotateUnits = Config::getInstance().getBool("AllowRotateUnits","0");
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
World::~World() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete techTree;
techTree = NULL;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
void World::end(){ void World::end(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("World", true); Logger::getInstance().add("World", true);
for(int i= 0; i<factions.size(); ++i){ for(int i= 0; i<factions.size(); ++i){
@ -61,6 +73,7 @@ void World::end(){
} }
fogOfWarOverride = false; fogOfWarOverride = false;
//stats will be deleted by BattleEnd //stats will be deleted by BattleEnd
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
// ========================== init =============================================== // ========================== init ===============================================
@ -78,6 +91,8 @@ void World::setFogOfWar(bool value) {
void World::init(Game *game, bool createUnits){ void World::init(Game *game, bool createUnits){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
this->game = game; this->game = game;
scriptManager= game->getScriptManager(); scriptManager= game->getScriptManager();
@ -100,34 +115,59 @@ void World::init(Game *game, bool createUnits){
} }
//initExplorationState(); ... was only for !fog-of-war, now handled in initCells() //initExplorationState(); ... was only for !fog-of-war, now handled in initCells()
computeFow(); computeFow();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
//load tileset //load tileset
void World::loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum) { void World::loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
tileset.loadTileset(pathList, tilesetName, checksum); tileset.loadTileset(pathList, tilesetName, checksum);
timeFlow.init(&tileset); timeFlow.init(&tileset);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
void World::loadTileset(const string &dir, Checksum *checksum){ void World::loadTileset(const string &dir, Checksum *checksum){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
tileset.load(dir, checksum); tileset.load(dir, checksum);
timeFlow.init(&tileset); timeFlow.init(&tileset);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
//load tech //load tech
void World::loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum *checksum){ void World::loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum *checksum){
techTree.loadTech(pathList, techName, factions, checksum); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
/*
std::map<string,TechTree *> &techCache = Shared::PlatformCommon::CacheManager::getCachedItem< std::map<string,TechTree *> >("techCache");
if(techCache.find(techName) != techCache.end()) {
techTree = new TechTree();
*techTree = *techCache[techName];
return;
}
*/
techTree = new TechTree();
techTree->loadTech(pathList, techName, factions, checksum);
//techCache[techName] = techTree;
} }
//load map //load map
void World::loadMap(const string &path, Checksum *checksum){ void World::loadMap(const string &path, Checksum *checksum){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
checksum->addFile(path); checksum->addFile(path);
map.load(path, &techTree, &tileset); map.load(path, techTree, &tileset);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
//load map //load map
void World::loadScenario(const string &path, Checksum *checksum){ void World::loadScenario(const string &path, Checksum *checksum){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
checksum->addFile(path); checksum->addFile(path);
scenario.load(path); scenario.load(path);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
// ==================== misc ==================== // ==================== misc ====================
@ -163,8 +203,8 @@ void World::update(){
} }
//food costs //food costs
for(int i=0; i<techTree.getResourceTypeCount(); ++i){ for(int i=0; i<techTree->getResourceTypeCount(); ++i){
const ResourceType *rt= techTree.getResourceType(i); const ResourceType *rt= techTree->getResourceType(i);
if(rt->getClass()==rcConsumable && frameCount % (rt->getInterval()*GameConstants::updateFps)==0){ if(rt->getClass()==rcConsumable && frameCount % (rt->getInterval()*GameConstants::updateFps)==0){
for(int i=0; i<getFactionCount(); ++i){ for(int i=0; i<getFactionCount(); ++i){
getFaction(i)->applyCostsOnInterval(); getFaction(i)->applyCostsOnInterval();
@ -202,8 +242,8 @@ void World::tick(){
Faction *faction= getFaction(k); Faction *faction= getFaction(k);
//for each resource //for each resource
for(int i=0; i<techTree.getResourceTypeCount(); ++i){ for(int i=0; i<techTree->getResourceTypeCount(); ++i){
const ResourceType *rt= techTree.getResourceType(i); const ResourceType *rt= techTree->getResourceType(i);
//if consumable //if consumable
if(rt->getClass()==rcConsumable){ if(rt->getClass()==rcConsumable){
@ -361,7 +401,7 @@ void World::createUnit(const string &unitName, int factionIndex, const Vec2i &po
void World::giveResource(const string &resourceName, int factionIndex, int amount){ void World::giveResource(const string &resourceName, int factionIndex, int amount){
if(factionIndex<factions.size()){ if(factionIndex<factions.size()){
Faction* faction= &factions[factionIndex]; Faction* faction= &factions[factionIndex];
const ResourceType* rt= techTree.getResourceType(resourceName); const ResourceType* rt= techTree->getResourceType(resourceName);
faction->incResourceAmount(rt, amount); faction->incResourceAmount(rt, amount);
} }
else else
@ -437,7 +477,7 @@ void World::giveUpgradeCommand(int unitId, const string &upgradeName){
int World::getResourceAmount(const string &resourceName, int factionIndex){ int World::getResourceAmount(const string &resourceName, int factionIndex){
if(factionIndex<factions.size()){ if(factionIndex<factions.size()){
Faction* faction= &factions[factionIndex]; Faction* faction= &factions[factionIndex];
const ResourceType* rt= techTree.getResourceType(resourceName); const ResourceType* rt= techTree->getResourceType(resourceName);
return faction->getResource(rt)->getAmount(); return faction->getResource(rt)->getAmount();
} }
else else
@ -517,6 +557,7 @@ int World::getUnitCountOfType(int factionIndex, const string &typeName){
//init basic cell state //init basic cell state
void World::initCells(bool fogOfWar){ void World::initCells(bool fogOfWar){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("State cells", true); Logger::getInstance().add("State cells", true);
for(int i=0; i<map.getSurfaceW(); ++i){ for(int i=0; i<map.getSurfaceW(); ++i){
@ -534,10 +575,12 @@ void World::initCells(bool fogOfWar){
} }
} }
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
//init surface textures //init surface textures
void World::initSplattedTextures(){ void World::initSplattedTextures(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(int i=0; i<map.getSurfaceW()-1; ++i){ for(int i=0; i<map.getSurfaceW()-1; ++i){
for(int j=0; j<map.getSurfaceH()-1; ++j){ for(int j=0; j<map.getSurfaceH()-1; ++j){
Vec2f coord; Vec2f coord;
@ -556,10 +599,12 @@ void World::initSplattedTextures(){
sc00->setSurfaceTexture(texture); sc00->setSurfaceTexture(texture);
} }
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
//creates each faction looking at each faction name contained in GameSettings //creates each faction looking at each faction name contained in GameSettings
void World::initFactionTypes(GameSettings *gs){ void World::initFactionTypes(GameSettings *gs){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("Faction types", true); Logger::getInstance().add("Faction types", true);
if(gs->getFactionCount() > map.getMaxPlayers()){ if(gs->getFactionCount() > map.getMaxPlayers()){
@ -573,9 +618,9 @@ void World::initFactionTypes(GameSettings *gs){
this->thisFactionIndex= gs->getThisFactionIndex(); this->thisFactionIndex= gs->getThisFactionIndex();
factions.resize(gs->getFactionCount()); factions.resize(gs->getFactionCount());
for(int i=0; i<factions.size(); ++i){ for(int i=0; i<factions.size(); ++i){
const FactionType *ft= techTree.getType(gs->getFactionTypeName(i)); const FactionType *ft= techTree->getType(gs->getFactionTypeName(i));
factions[i].init( factions[i].init(
ft, gs->getFactionControl(i), &techTree, game, i, gs->getTeam(i), ft, gs->getFactionControl(i), techTree, game, i, gs->getTeam(i),
gs->getStartLocationIndex(i), i==thisFactionIndex, gs->getDefaultResources()); gs->getStartLocationIndex(i), i==thisFactionIndex, gs->getDefaultResources());
stats.setTeam(i, gs->getTeam(i)); stats.setTeam(i, gs->getTeam(i));
@ -584,16 +629,19 @@ void World::initFactionTypes(GameSettings *gs){
} }
thisTeamIndex= getFaction(thisFactionIndex)->getTeam(); thisTeamIndex= getFaction(thisFactionIndex)->getTeam();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
void World::initMinimap(){ void World::initMinimap(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
minimap.init(map.getW(), map.getH(), this, game->getGameSettings()->getFogOfWar()); minimap.init(map.getW(), map.getH(), this, game->getGameSettings()->getFogOfWar());
Logger::getInstance().add("Compute minimap surface", true); Logger::getInstance().add("Compute minimap surface", true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
//place units randomly aroud start location //place units randomly aroud start location
void World::initUnits(){ void World::initUnits(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("Generate elements", true); Logger::getInstance().add("Generate elements", true);
//put starting units //put starting units
@ -623,10 +671,13 @@ void World::initUnits(){
} }
map.computeNormals(); map.computeNormals();
map.computeInterpolatedHeights(); map.computeInterpolatedHeights();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
void World::initMap(){ void World::initMap(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
map.init(); map.init();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
// ==================== exploration ==================== // ==================== exploration ====================

View File

@ -1,7 +1,7 @@
// ============================================================== // ==============================================================
// This file is part of Glest (www.glest.org) // This file is part of Glest (www.glest.org)
// //
// Copyright (C) 2001-2008 Martiño Figueroa // Copyright (C) 2001-2008 Martio Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // the terms of the GNU General Public License as published
@ -63,7 +63,8 @@ private:
Map map; Map map;
Tileset tileset; Tileset tileset;
TechTree techTree; //TechTree techTree;
TechTree *techTree;
TimeFlow timeFlow; TimeFlow timeFlow;
Scenario scenario; Scenario scenario;
@ -93,6 +94,7 @@ private:
public: public:
World(); World();
~World();
void end(); //to die before selection does void end(); //to die before selection does
//get //get
@ -103,7 +105,7 @@ public:
int getFactionCount() const {return factions.size();} int getFactionCount() const {return factions.size();}
const Map *getMap() const {return &map;} const Map *getMap() const {return &map;}
const Tileset *getTileset() const {return &tileset;} const Tileset *getTileset() const {return &tileset;}
const TechTree *getTechTree() const {return &techTree;} const TechTree *getTechTree() const {return techTree;}
const Scenario *getScenario() const {return &scenario;} const Scenario *getScenario() const {return &scenario;}
const TimeFlow *getTimeFlow() const {return &timeFlow;} const TimeFlow *getTimeFlow() const {return &timeFlow;}
Tileset *getTileset() {return &tileset;} Tileset *getTileset() {return &tileset;}

View File

@ -64,7 +64,11 @@ public:
// Example values: // Example values:
// DEFAULT_CHARSET (English) = 1 // DEFAULT_CHARSET (English) = 1
// GB2312_CHARSET (Chinese) = 134 // GB2312_CHARSET (Chinese) = 134
#ifdef WIN32
static DWORD charSet = DEFAULT_CHARSET; static DWORD charSet = DEFAULT_CHARSET;
#else
static int charSet = 1;
#endif
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics); void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics);
void createGlFontOutlines(uint32 &base, const string &type, int width, float depth, int charCount, FontMetrics &metrics); void createGlFontOutlines(uint32 &base, const string &type, int width, float depth, int charCount, FontMetrics &metrics);

View File

@ -189,7 +189,7 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
printf("Opening logfile [%s] type = %d, currentDebugLog.fileStreamOwner = %d\n",debugLog.c_str(),type, currentDebugLog.fileStreamOwner); printf("Opening logfile [%s] type = %d, currentDebugLog.fileStreamOwner = %d\n",debugLog.c_str(),type, currentDebugLog.fileStreamOwner);
currentDebugLog.mutex->p(); currentDebugLog.mutex->p();
(*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n"; (*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n";
(*currentDebugLog.fileStream).flush(); (*currentDebugLog.fileStream).flush();
@ -203,12 +203,12 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
assert(currentDebugLog.fileStream != NULL); assert(currentDebugLog.fileStream != NULL);
currentDebugLog.mutex->p(); //currentDebugLog.mutex->p();
(*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf; (*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf;
(*currentDebugLog.fileStream).flush(); (*currentDebugLog.fileStream).flush();
currentDebugLog.mutex->v(); //currentDebugLog.mutex->v();
} }
// output to console // output to console
else { else {