- 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!");
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//tileset
world.loadTileset(config.getPathListForType(ptTilesets,scenarioDir), tilesetName, &checksum);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
set<string> factions;
for ( int i=0; i < gameSettings.getFactionCount(); ++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
world.loadTech(config.getPathListForType(ptTechs,scenarioDir), techName, factions, &checksum);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//map
world.loadMap(Map::getMapPath(mapName,scenarioDir), &checksum);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//scenario
if(!scenarioName.empty()){
Lang::getInstance().loadScenarioStrings(gameSettings.getScenarioDir(), scenarioName);
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__);
}
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();
Logger &logger= Logger::getInstance();
@ -230,7 +241,7 @@ void Game::init()
Map *map= world.getMap();
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"));
//mesage box
@ -318,7 +329,7 @@ void Game::init()
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
void Game::update(){
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// a) Updates non dependant on speed
@ -336,14 +348,18 @@ void Game::update(){
//console
console.update();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// b) Updates depandant on speed
int updateLoops= getUpdateLoops();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//update
for(int i=0; i<updateLoops; ++i){
Renderer &renderer= Renderer::getInstance();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//AiInterface
for(int i=0; i<world.getFactionCount(); ++i){
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.update();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// Commander
commander.updateNetwork();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//Gui
gui.update();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//Particle systems
if(weatherParticleSystem != NULL){
weatherParticleSystem->setPos(gameCamera.getPos());
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.updateParticleManager(rsGame);
//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
chatManager.updateNetwork();
@ -381,6 +404,8 @@ void Game::update(){
if(Config::getInstance().getBool("AutoTest")){
AutoTest::getInstance().updateGame(this);
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void Game::updateCamera(){
@ -392,10 +417,20 @@ void Game::updateCamera(){
//render
void Game::render(){
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderFps++;
render3d();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
render2d();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer::getInstance().swapBuffers();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
// ==================== tick ====================
@ -785,41 +820,54 @@ void Game::quitGame(){
// ==================== render ====================
void Game::render3d(){
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer &renderer= Renderer::getInstance();
//init
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.reset3d();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.computeVisibleQuad();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.loadGameCameraMatrix();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.setupLighting();
//shadow map
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderShadowsToTexture();
//clear buffers
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.clearBuffers();
//surface
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderSurface();
//selection circles
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderSelectionEffects();
//units
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderUnits();
//objects
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderObjects();
//water
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderWater();
renderer.renderWaterEffects();
//particles
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderParticleManager(rsGame);
//mouse 3d
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
renderer.renderMouse3d();
}

View File

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

View File

@ -323,12 +323,12 @@ int glestMain(int argc, char** argv){
// 256 for English
// 30000 for Chinese
Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(256).c_str());
Font::fontTypeName = config.getString("FONT_TYPENAME","Times New Roman");
Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str());
Font::fontTypeName = config.getString("FONT_TYPENAME",Font::fontTypeName.c_str());
// Example values:
// DEFAULT_CHARSET (English) = 1
// 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);

View File

@ -183,17 +183,20 @@ void Program::keyPress(char c){
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
assert(programState != NULL);
programState->render();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//update camera
while(updateCameraTimer.isTime()){
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
while(updateTimer.isTime()){
@ -244,18 +247,18 @@ void Program::resize(SizeState sizeState){
void Program::setState(ProgramState *programState, bool cleanupOldState)
{
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) {
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;
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();
@ -265,7 +268,7 @@ void Program::setState(ProgramState *programState, bool cleanupOldState)
updateCameraTimer.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){
//exceptionMessage(e);
@ -365,7 +368,7 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
soundRenderer.init(window);
// Run sound streaming in a background thread if enabled
if(config.getBool("ThreadedSoundStream","true") == true) {
if(config.getBool("ThreadedSoundStream","false") == true) {
BaseThread::shutdownAndWait(soundThreadManager);
delete soundThreadManager;
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::setAllowDownloadDataSynch(Config::getInstance().getBool("AllowDownloadDataSynch","0"));
NetworkInterface::setAllowGameDataSynchCheck(Config::getInstance().getBool("AllowGameDataSynchCheck","false"));
NetworkInterface::setAllowDownloadDataSynch(Config::getInstance().getBool("AllowDownloadDataSynch","false"));
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)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -37,6 +37,7 @@ SoundRenderer::SoundRenderer(){
soundPlayer = NULL;
loadConfig();
runThreadSafe = false;
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();
FactoryRepository &fr= FactoryRepository::getInstance();
Config &config= Config::getInstance();
runThreadSafe = config.getBool("ThreadedSoundStream","false");
//if(soundPlayer == NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -85,7 +87,9 @@ SoundRenderer &SoundRenderer::getInstance(){
void SoundRenderer::update(){
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->updateStreams();
if(runThreadSafe == true) mutex.v();
}
}
@ -95,16 +99,20 @@ void SoundRenderer::playMusic(StrSound *strSound){
strSound->setVolume(musicVolume);
strSound->restart();
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(strSound);
if(runThreadSafe == true) mutex.v();
}
}
void SoundRenderer::stopMusic(StrSound *strSound){
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->stop(strSound);
if(strSound->getNext() != NULL) {
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){
float d= soundPos.dist(camPos);
if(d<audibleDist){
if(d < audibleDist){
float vol= (1.f-d/audibleDist)*fxVolume;
float correctedVol= log10(log10(vol*9+1)*9+1);
staticSound->setVolume(correctedVol);
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(staticSound);
if(runThreadSafe == true) mutex.v();
}
}
}
@ -130,7 +140,9 @@ void SoundRenderer::playFx(StaticSound *staticSound){
if(staticSound!=NULL){
staticSound->setVolume(fxVolume);
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(staticSound);
if(runThreadSafe == true) mutex.v();
}
}
}
@ -140,13 +152,17 @@ void SoundRenderer::playFx(StaticSound *staticSound){
void SoundRenderer::playAmbient(StrSound *strSound){
strSound->setVolume(ambientVolume);
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->play(strSound, ambientFade);
if(runThreadSafe == true) mutex.v();
}
}
void SoundRenderer::stopAmbient(StrSound *strSound){
if(soundPlayer != NULL) {
if(runThreadSafe == true) mutex.p();
soundPlayer->stop(strSound, ambientFade);
if(runThreadSafe == true) mutex.v();
}
}
@ -154,7 +170,9 @@ void SoundRenderer::stopAmbient(StrSound *strSound){
void SoundRenderer::stopAllSounds(){
if(soundPlayer != NULL) {
mutex.p();
soundPlayer->stopAllSounds();
mutex.v();
}
}

View File

@ -1,7 +1,7 @@
// ==============================================================
// 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
// the terms of the GNU General Public License as published
@ -45,6 +45,9 @@ private:
float musicVolume;
float ambientVolume;
Mutex mutex;
bool runThreadSafe;
private:
SoundRenderer();

View File

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

View File

@ -1,7 +1,7 @@
// ==============================================================
// 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
// 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) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string str;
vector<string> filenames;
@ -122,10 +123,12 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
catch(const exception &e){
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(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("Tech tree", true);
}
@ -133,8 +136,10 @@ TechTree::~TechTree(){
// ==================== get ====================
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){
if(factionTypes[i].getName()==name){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return &factionTypes[i];
}
}
@ -142,9 +147,9 @@ const FactionType *TechTree::getType(const string &name) const{
}
const ResourceType *TechTree::getTechResourceType(int i) const{
for(int j=0; j<getResourceTypeCount(); ++j){
const ResourceType *rt= getResourceType(j);
assert(rt != NULL);
if(rt->getResourceNumber()==i && rt->getClass()==rcTech)
return getResourceType(j);
}
@ -155,6 +160,7 @@ const ResourceType *TechTree::getTechResourceType(int i) const{
const ResourceType *TechTree::getFirstTechResourceType() const{
for(int i=0; i<getResourceTypeCount(); ++i){
const ResourceType *rt= getResourceType(i);
assert(rt != NULL);
if(rt->getResourceNumber()==1 && rt->getClass()==rcTech)
return getResourceType(i);
}

View File

@ -25,7 +25,6 @@
#include "game_util.h"
#include "leak_dumper.h"
#include "unit_particle_type.h"
//#include "socket.h"
using namespace Shared::Xml;
using namespace Shared::Graphics;
@ -91,7 +90,6 @@ UnitType::~UnitType(){
delete damageParticleSystemTypes.back();
damageParticleSystemTypes.pop_back();
}
}
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__);
string path = dir + "/" + name + ".xml";
this->id= id;
string path;
try{
Logger::getInstance().add("Unit type: " + formatString(name), true);
//file load
path= dir+"/"+name+".xml";
checksum->addFile(path);
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;
}
}
/*
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

View File

@ -21,6 +21,7 @@
#include "logger.h"
#include "sound_renderer.h"
#include "game_settings.h"
#include "cache_manager.h"
#include "leak_dumper.h"
using namespace Shared::Graphics;
@ -37,8 +38,10 @@ const float World::airHeight= 5.f;
// ===================== PUBLIC ========================
World::World(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Config &config= Config::getInstance();
techTree = NULL;
fogOfWarOverride = false;
fogOfWarSmoothing= config.getBool("FogOfWarSmoothing");
@ -51,9 +54,18 @@ World::World(){
this->game = NULL;
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(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("World", true);
for(int i= 0; i<factions.size(); ++i){
@ -61,6 +73,7 @@ void World::end(){
}
fogOfWarOverride = false;
//stats will be deleted by BattleEnd
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
// ========================== init ===============================================
@ -78,6 +91,8 @@ void World::setFogOfWar(bool value) {
void World::init(Game *game, bool createUnits){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
this->game = game;
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()
computeFow();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
//load tileset
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);
timeFlow.init(&tileset);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
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);
timeFlow.init(&tileset);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
//load tech
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
void World::loadMap(const string &path, Checksum *checksum){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
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
void World::loadScenario(const string &path, Checksum *checksum){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
checksum->addFile(path);
scenario.load(path);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
// ==================== misc ====================
@ -163,8 +203,8 @@ void World::update(){
}
//food costs
for(int i=0; i<techTree.getResourceTypeCount(); ++i){
const ResourceType *rt= techTree.getResourceType(i);
for(int i=0; i<techTree->getResourceTypeCount(); ++i){
const ResourceType *rt= techTree->getResourceType(i);
if(rt->getClass()==rcConsumable && frameCount % (rt->getInterval()*GameConstants::updateFps)==0){
for(int i=0; i<getFactionCount(); ++i){
getFaction(i)->applyCostsOnInterval();
@ -202,8 +242,8 @@ void World::tick(){
Faction *faction= getFaction(k);
//for each resource
for(int i=0; i<techTree.getResourceTypeCount(); ++i){
const ResourceType *rt= techTree.getResourceType(i);
for(int i=0; i<techTree->getResourceTypeCount(); ++i){
const ResourceType *rt= techTree->getResourceType(i);
//if consumable
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){
if(factionIndex<factions.size()){
Faction* faction= &factions[factionIndex];
const ResourceType* rt= techTree.getResourceType(resourceName);
const ResourceType* rt= techTree->getResourceType(resourceName);
faction->incResourceAmount(rt, amount);
}
else
@ -437,7 +477,7 @@ void World::giveUpgradeCommand(int unitId, const string &upgradeName){
int World::getResourceAmount(const string &resourceName, int factionIndex){
if(factionIndex<factions.size()){
Faction* faction= &factions[factionIndex];
const ResourceType* rt= techTree.getResourceType(resourceName);
const ResourceType* rt= techTree->getResourceType(resourceName);
return faction->getResource(rt)->getAmount();
}
else
@ -517,6 +557,7 @@ int World::getUnitCountOfType(int factionIndex, const string &typeName){
//init basic cell state
void World::initCells(bool fogOfWar){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("State cells", true);
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
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 j=0; j<map.getSurfaceH()-1; ++j){
Vec2f coord;
@ -556,10 +599,12 @@ void World::initSplattedTextures(){
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
void World::initFactionTypes(GameSettings *gs){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("Faction types", true);
if(gs->getFactionCount() > map.getMaxPlayers()){
@ -573,9 +618,9 @@ void World::initFactionTypes(GameSettings *gs){
this->thisFactionIndex= gs->getThisFactionIndex();
factions.resize(gs->getFactionCount());
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(
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());
stats.setTeam(i, gs->getTeam(i));
@ -584,16 +629,19 @@ void World::initFactionTypes(GameSettings *gs){
}
thisTeamIndex= getFaction(thisFactionIndex)->getTeam();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
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());
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
void World::initUnits(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Logger::getInstance().add("Generate elements", true);
//put starting units
@ -623,10 +671,13 @@ void World::initUnits(){
}
map.computeNormals();
map.computeInterpolatedHeights();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void World::initMap(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
map.init();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
// ==================== exploration ====================

View File

@ -1,7 +1,7 @@
// ==============================================================
// 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
// the terms of the GNU General Public License as published
@ -63,7 +63,8 @@ private:
Map map;
Tileset tileset;
TechTree techTree;
//TechTree techTree;
TechTree *techTree;
TimeFlow timeFlow;
Scenario scenario;
@ -93,6 +94,7 @@ private:
public:
World();
~World();
void end(); //to die before selection does
//get
@ -103,7 +105,7 @@ public:
int getFactionCount() const {return factions.size();}
const Map *getMap() const {return &map;}
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 TimeFlow *getTimeFlow() const {return &timeFlow;}
Tileset *getTileset() {return &tileset;}

View File

@ -64,7 +64,11 @@ public:
// Example values:
// DEFAULT_CHARSET (English) = 1
// GB2312_CHARSET (Chinese) = 134
#ifdef WIN32
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 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);
currentDebugLog.mutex->p();
currentDebugLog.mutex->p();
(*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n";
(*currentDebugLog.fileStream).flush();
@ -203,12 +203,12 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
assert(currentDebugLog.fileStream != NULL);
currentDebugLog.mutex->p();
//currentDebugLog.mutex->p();
(*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf;
(*currentDebugLog.fileStream).flush();
currentDebugLog.mutex->v();
//currentDebugLog.mutex->v();
}
// output to console
else {