| 1 | // ============================================================== |
|---|
| 2 | // This file is part of Glest (www.glest.org) |
|---|
| 3 | // |
|---|
| 4 | // Copyright (C) 2001-2008 Martiño Figueroa |
|---|
| 5 | // |
|---|
| 6 | // You can redistribute this code and/or modify it under |
|---|
| 7 | // the terms of the GNU General Public License as published |
|---|
| 8 | // by the Free Software Foundation; either version 2 of the |
|---|
| 9 | // License, or (at your option) any later version |
|---|
| 10 | // ============================================================== |
|---|
| 11 | |
|---|
| 12 | #include "pch.h" |
|---|
| 13 | |
|---|
| 14 | #include "core_data.h" |
|---|
| 15 | |
|---|
| 16 | #include "logger.h" |
|---|
| 17 | #include "renderer.h" |
|---|
| 18 | #include "graphics_interface.h" |
|---|
| 19 | #include "config.h" |
|---|
| 20 | #include "util.h" |
|---|
| 21 | |
|---|
| 22 | #include "leak_dumper.h" |
|---|
| 23 | #include "profiler.h" |
|---|
| 24 | |
|---|
| 25 | using Glest::Util::Logger; |
|---|
| 26 | using namespace Shared::Sound; |
|---|
| 27 | using namespace Shared::Graphics; |
|---|
| 28 | using namespace Shared::Util; |
|---|
| 29 | using namespace Glest::Graphics; |
|---|
| 30 | |
|---|
| 31 | namespace Glest { namespace Global { |
|---|
| 32 | |
|---|
| 33 | // ===================================================== |
|---|
| 34 | // class CoreData |
|---|
| 35 | // ===================================================== |
|---|
| 36 | |
|---|
| 37 | // ===================== PUBLIC ======================== |
|---|
| 38 | |
|---|
| 39 | CoreData &CoreData::getInstance(){ |
|---|
| 40 | static CoreData coreData; |
|---|
| 41 | return coreData; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | CoreData::~CoreData(){ |
|---|
| 45 | deleteValues(waterSounds.getSounds().begin(), waterSounds.getSounds().end()); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | Texture2D* loadTexture(const string &path, bool mipmap = false) { |
|---|
| 49 | Texture2D *tex = g_renderer.newTexture2D(ResourceScope::GLOBAL); |
|---|
| 50 | tex->setMipmap(mipmap); |
|---|
| 51 | tex->getPixmap()->load(path); |
|---|
| 52 | return tex; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | Texture2D* loadAlphaTexture(const string &path, bool mipmap = false) { |
|---|
| 56 | Texture2D *tex = g_renderer.newTexture2D(ResourceScope::GLOBAL); |
|---|
| 57 | tex->setMipmap(mipmap); |
|---|
| 58 | tex->setFormat(Texture::fAlpha); |
|---|
| 59 | tex->getPixmap()->init(1); |
|---|
| 60 | tex->getPixmap()->load(path); |
|---|
| 61 | return tex; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | Font* loadFreeTypeFont(string path, int size) { |
|---|
| 65 | Font *font = g_renderer.newFreeTypeFont(ResourceScope::GLOBAL); |
|---|
| 66 | font->setType(path); |
|---|
| 67 | font->setSize(size); |
|---|
| 68 | return font; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | bool CoreData::load() { |
|---|
| 72 | g_logger.add("Core data"); |
|---|
| 73 | |
|---|
| 74 | const string dir = "data/core"; |
|---|
| 75 | |
|---|
| 76 | // textures |
|---|
| 77 | try { |
|---|
| 78 | backgroundTexture = loadTexture(dir + "/menu/textures/back.tga"); |
|---|
| 79 | fireTexture = loadAlphaTexture(dir + "/misc_textures/fire_particle.tga"); |
|---|
| 80 | snowTexture = loadAlphaTexture(dir + "/misc_textures/snow_particle.tga"); |
|---|
| 81 | customTexture = loadTexture(dir + "/menu/textures/custom_texture.tga"); |
|---|
| 82 | logoTexture = loadTexture(dir + "/menu/textures/logo.tga"); |
|---|
| 83 | gplTexture = loadTexture(dir + "/menu/textures/gplv3.tga"); |
|---|
| 84 | gaeSplashTexture = loadTexture(dir + "/menu/textures/gaesplash.tga"); |
|---|
| 85 | checkBoxCrossTexture = loadTexture(dir + "/menu/textures/button_small_unchecked.tga"); |
|---|
| 86 | checkBoxTickTexture = loadTexture(dir + "/menu/textures/button_small_checked.tga"); |
|---|
| 87 | vertScrollUpTexture = loadTexture(dir + "/menu/textures/button_small_up.tga"); |
|---|
| 88 | vertScrollDownTexture = loadTexture(dir + "/menu/textures/button_small_down.tga"); |
|---|
| 89 | vertScrollUpHoverTex = loadTexture(dir + "/menu/textures/button_small_up_hover.tga"); |
|---|
| 90 | vertScrollDownHoverTex = loadTexture(dir + "/menu/textures/button_small_down_hover.tga"); |
|---|
| 91 | waterSplashTexture = loadAlphaTexture(dir + "/misc_textures/water_splash.tga", true); |
|---|
| 92 | buttonSmallTexture = loadTexture(dir + "/menu/textures/button_small.tga", true); |
|---|
| 93 | buttonBigTexture = loadTexture(dir + "/menu/textures/button_big.tga", true); |
|---|
| 94 | textEntryTexture = loadTexture(dir + "/menu/textures/textentry.tga", true); |
|---|
| 95 | greenTickOverlay = loadTexture(dir + "/menu/textures/green_tick.png"); |
|---|
| 96 | orangeQuestionOverlay = loadTexture(dir + "/menu/textures/orange_question.png"); |
|---|
| 97 | redCrossOverlay = loadTexture(dir + "/menu/textures/red_cross.png"); |
|---|
| 98 | mouseTexture = loadTexture(dir + "/misc_textures/mouse.png"); |
|---|
| 99 | } catch (runtime_error &e) { |
|---|
| 100 | g_errorLog.add(string("Error loading core data.\n") + e.what()); |
|---|
| 101 | return false; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | // Display/Console font |
|---|
| 105 | m_FTDisplay = loadFreeTypeFont(dir + "/menu/fonts/TinDog.ttf", computeFontSize(10)); |
|---|
| 106 | m_FTDisplayBig = loadFreeTypeFont(dir + "/menu/fonts/TinDog.ttf", computeFontSize(12)); |
|---|
| 107 | |
|---|
| 108 | // Misc fonts |
|---|
| 109 | advancedEngineFontSmall = loadFreeTypeFont(dir + "/menu/fonts/dum1.ttf", computeFontSize(24)); |
|---|
| 110 | advancedEngineFontBig = loadFreeTypeFont(dir + "/menu/fonts/dum1wide.ttf", computeFontSize(36)); |
|---|
| 111 | |
|---|
| 112 | // Menu fonts... |
|---|
| 113 | m_FTMenuFontNormal = loadFreeTypeFont(dir + "/menu/fonts/TinDog.ttf", computeFontSize(18)); |
|---|
| 114 | m_FTMenuFontSmall = loadFreeTypeFont(dir + "/menu/fonts/TinDog.ttf", computeFontSize(14)); |
|---|
| 115 | m_FTMenuFontBig = loadFreeTypeFont(dir + "/menu/fonts/TinDog.ttf", computeFontSize(22)); |
|---|
| 116 | m_FTMenuFontVeryBig = loadFreeTypeFont(dir + "/menu/fonts/TinDog.ttf", computeFontSize(26)); |
|---|
| 117 | |
|---|
| 118 | //sounds |
|---|
| 119 | try { |
|---|
| 120 | clickSoundA.load(dir + "/menu/sound/click_a.wav"); |
|---|
| 121 | clickSoundB.load(dir + "/menu/sound/click_b.wav"); |
|---|
| 122 | clickSoundC.load(dir + "/menu/sound/click_c.wav"); |
|---|
| 123 | introMusic.open(dir + "/menu/music/intro_music.ogg"); |
|---|
| 124 | introMusic.setNext(&menuMusic); |
|---|
| 125 | menuMusic.open(dir + "/menu/music/menu_music.ogg"); |
|---|
| 126 | menuMusic.setNext(&menuMusic); |
|---|
| 127 | waterSounds.resize(6); |
|---|
| 128 | for (int i = 0; i < 6; ++i) { |
|---|
| 129 | waterSounds[i]= new StaticSound(); |
|---|
| 130 | waterSounds[i]->load(dir + "/water_sounds/water" + intToStr(i) + ".wav"); |
|---|
| 131 | } |
|---|
| 132 | } catch (runtime_error &e) { |
|---|
| 133 | g_errorLog.add(string("Error loading core data.\n") + e.what()); |
|---|
| 134 | return false; |
|---|
| 135 | } |
|---|
| 136 | return true; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | void CoreData::closeSounds(){ |
|---|
| 140 | introMusic.close(); |
|---|
| 141 | menuMusic.close(); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | int CoreData::computeFontSize(int size) { |
|---|
| 145 | int screenH = g_config.getDisplayHeight(); |
|---|
| 146 | int rs= int(g_config.getRenderFontScaler() * size * float(screenH) / 768.f); |
|---|
| 147 | if (rs < 12) { |
|---|
| 148 | rs = 12; |
|---|
| 149 | } |
|---|
| 150 | return rs; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | // ================== PRIVATE ======================== |
|---|
| 154 | |
|---|
| 155 | }}//end namespace |
|---|