From 4d3ba6509ebda346d7611103c6d44656d059c5a4 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@mgail.com> Date: Mon, 3 Feb 2014 14:31:08 +1100 Subject: [PATCH 01/68] Added first script to find unused files in STK. --- tools/find_unused.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 tools/find_unused.sh diff --git a/tools/find_unused.sh b/tools/find_unused.sh new file mode 100755 index 000000000..fd9385edc --- /dev/null +++ b/tools/find_unused.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +echo "Searching for unused stkgui files" +echo "---------------------------------" +cd data/gui +l="" +for i in $(find . -iname "*.stkgui"); do + s=$(basename $i) + x=$(find ../../src/states_screens -exec grep -H $s \{} \; | wc -l) + echo -n "." + if [ $x == "0" ]; then + l="$l $i" + fi +done +echo + +for i in $l; do + echo "$i appears to be not used." +done + +echo "done" + + + From 62d46b7ec0768e717a9d8229816c67b93333a75d Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Wed, 5 Feb 2014 08:22:38 +1100 Subject: [PATCH 02/68] Renamed XMLWriter to UTFWriter (which is the correcter name). --- src/achievements/achievement_info.cpp | 2 - src/achievements/achievements_manager.cpp | 1 - src/achievements/achievements_slot.cpp | 3 +- src/challenges/unlock_manager.cpp | 3 +- src/config/user_config.cpp | 47 ++++++++-------- src/config/user_config.hpp | 25 ++++----- src/io/{xml_writer.cpp => utf_writer.cpp} | 67 +++++------------------ src/io/{xml_writer.hpp => utf_writer.hpp} | 14 ++--- src/race/highscore_manager.cpp | 4 +- src/race/highscores.cpp | 10 ++-- src/race/highscores.hpp | 4 +- 11 files changed, 69 insertions(+), 111 deletions(-) rename src/io/{xml_writer.cpp => utf_writer.cpp} (52%) rename src/io/{xml_writer.hpp => utf_writer.hpp} (85%) diff --git a/src/achievements/achievement_info.cpp b/src/achievements/achievement_info.cpp index eda7b4c73..6000205a1 100644 --- a/src/achievements/achievement_info.cpp +++ b/src/achievements/achievement_info.cpp @@ -20,8 +20,6 @@ #include "utils/log.hpp" #include "utils/translation.hpp" -#include "io/xml_writer.hpp" - #include <sstream> #include <stdlib.h> diff --git a/src/achievements/achievements_manager.cpp b/src/achievements/achievements_manager.cpp index db24f23dc..661c31a98 100644 --- a/src/achievements/achievements_manager.cpp +++ b/src/achievements/achievements_manager.cpp @@ -21,7 +21,6 @@ #include "utils/log.hpp" #include "utils/translation.hpp" #include "io/file_manager.hpp" -#include "io/xml_writer.hpp" #include "config/player.hpp" #include "config/user_config.hpp" #include "online/current_user.hpp" diff --git a/src/achievements/achievements_slot.cpp b/src/achievements/achievements_slot.cpp index 931c4164c..ec36d8771 100644 --- a/src/achievements/achievements_slot.cpp +++ b/src/achievements/achievements_slot.cpp @@ -24,12 +24,13 @@ #include "utils/log.hpp" #include "utils/ptr_vector.hpp" #include "utils/translation.hpp" -#include "io/xml_writer.hpp" #include "online/current_user.hpp" #include <sstream> +#include <fstream> #include <stdlib.h> #include <assert.h> + // ============================================================================ AchievementsSlot::AchievementsSlot(const XMLNode * input) { diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index 247b627a0..47099068e 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -27,11 +27,10 @@ #include "achievements/achievements_manager.hpp" #include "audio/sfx_base.hpp" #include "audio/sfx_manager.hpp" +#include "challenges/challenge_data.hpp" #include "config/player.hpp" #include "config/user_config.hpp" -#include "challenges/challenge_data.hpp" #include "io/file_manager.hpp" -#include "io/xml_writer.hpp" #include "karts/kart_properties_manager.hpp" #include "race/race_manager.hpp" #include "tracks/track_manager.hpp" diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index 9f36ee033..c37edfc77 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -18,34 +18,33 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include <iostream> -#include <string> -#include <stdlib.h> -#include <fstream> -#include <vector> -#include "io/xml_writer.hpp" -#include "utils/ptr_vector.hpp" - -class UserConfigParam; -static PtrVector<UserConfigParam, REF> all_params; - - // X-macros #define PARAM_PREFIX #define PARAM_DEFAULT(X) = X #include "config/user_config.hpp" -#include "config/saved_grand_prix.hpp" #include "config/player.hpp" +#include "config/saved_grand_prix.hpp" #include "config/stk_config.hpp" #include "guiengine/engine.hpp" #include "io/file_manager.hpp" +#include "io/utf_writer.hpp" #include "io/xml_node.hpp" #include "race/race_manager.hpp" #include "utils/ptr_vector.hpp" #include "utils/string_utils.hpp" #include "utils/translation.hpp" +#include <fstream> +#include <iostream> +#include <stdlib.h> +#include <string> +#include <vector> + +class UserConfigParam; +static PtrVector<UserConfigParam, REF> all_params; + + const int UserConfig::m_current_config_version = 8; @@ -60,7 +59,7 @@ UserConfigParam::~UserConfigParam() * \param stream the xml writer. * \param level determines indentation level. */ -void UserConfigParam::writeInner(XMLWriter& stream, int level) const +void UserConfigParam::writeInner(UTFWriter& stream, int level) const { std::string tab(level * 4,' '); stream << L" " << tab.c_str() << m_param_name.c_str() << L"=\"" @@ -87,7 +86,7 @@ GroupUserConfigParam::GroupUserConfigParam(const char* group_name, } // GroupUserConfigParam // ---------------------------------------------------------------------------- -void GroupUserConfigParam::write(XMLWriter& stream) const +void GroupUserConfigParam::write(UTFWriter& stream) const { const int attr_amount = m_attributes.size(); @@ -117,7 +116,7 @@ void GroupUserConfigParam::write(XMLWriter& stream) const } // write // ---------------------------------------------------------------------------- -void GroupUserConfigParam::writeInner(XMLWriter& stream, int level) const +void GroupUserConfigParam::writeInner(UTFWriter& stream, int level) const { std::string tab(level * 4,' '); for(int i = 0; i < level; i++) tab =+ " "; @@ -244,7 +243,7 @@ ListUserConfigParam<T, U>::ListUserConfigParam(const char* param_name, // ---------------------------------------------------------------------------- template<typename T, typename U> -void ListUserConfigParam<T, U>::write(XMLWriter& stream) const +void ListUserConfigParam<T, U>::write(UTFWriter& stream) const { const int elts_amount = m_elements.size(); @@ -350,7 +349,7 @@ IntUserConfigParam::IntUserConfigParam(int default_value, } // IntUserConfigParam // ---------------------------------------------------------------------------- -void IntUserConfigParam::write(XMLWriter& stream) const +void IntUserConfigParam::write(UTFWriter& stream) const { if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str() << L" -->\n"; @@ -412,7 +411,7 @@ TimeUserConfigParam::TimeUserConfigParam(StkTime::TimeType default_value, } // TimeUserConfigParam // ---------------------------------------------------------------------------- -void TimeUserConfigParam::write(XMLWriter& stream) const +void TimeUserConfigParam::write(UTFWriter& stream) const { if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str() << L" -->\n"; @@ -483,7 +482,7 @@ StringUserConfigParam::StringUserConfigParam(const char* default_value, } // StringUserConfigParam // ---------------------------------------------------------------------------- -void StringUserConfigParam::write(XMLWriter& stream) const +void StringUserConfigParam::write(UTFWriter& stream) const { if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str() << L" -->\n"; @@ -535,7 +534,7 @@ WStringUserConfigParam::WStringUserConfigParam(const core::stringw& default_valu } // WStringUserConfigParam // ---------------------------------------------------------------------------- -void WStringUserConfigParam::write(XMLWriter& stream) const +void WStringUserConfigParam::write(UTFWriter& stream) const { if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str() << L" -->\n"; @@ -586,7 +585,7 @@ BoolUserConfigParam::BoolUserConfigParam(bool default_value, // ---------------------------------------------------------------------------- -void BoolUserConfigParam::write(XMLWriter& stream) const +void BoolUserConfigParam::write(UTFWriter& stream) const { if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str() << L" -->\n"; @@ -673,7 +672,7 @@ FloatUserConfigParam::FloatUserConfigParam(float default_value, } // FloatUserConfigParam // ---------------------------------------------------------------------------- -void FloatUserConfigParam::write(XMLWriter& stream) const +void FloatUserConfigParam::write(UTFWriter& stream) const { if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str() << L" -->\n"; @@ -878,7 +877,7 @@ void UserConfig::saveConfig() try { - XMLWriter configfile(filename.c_str()); + UTFWriter configfile(filename.c_str()); configfile << L"<?xml version=\"1.0\"?>\n"; configfile << L"<stkconfig version=\"" << m_current_config_version diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 34fb11666..c01ce58df 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -46,7 +46,6 @@ using irr::core::stringc; using irr::core::stringw; -#include "io/xml_writer.hpp" #include "utils/constants.hpp" #include "utils/no_copy.hpp" #include "utils/ptr_vector.hpp" @@ -55,7 +54,7 @@ using irr::core::stringw; class PlayerProfile; class SavedGrandPrix; class XMLNode; -class XMLWriter; +class UTFWriter; /** * The base of a set of small utilities to enable quickly adding/removing @@ -69,8 +68,8 @@ protected: std::string m_comment; public: virtual ~UserConfigParam(); - virtual void write(XMLWriter& stream) const = 0; - virtual void writeInner(XMLWriter& stream, int level = 0) const; + virtual void write(UTFWriter& stream) const = 0; + virtual void writeInner(UTFWriter& stream, int level = 0) const; virtual void findYourDataInAChildOf(const XMLNode* node) = 0; virtual void findYourDataInAnAttributeOf(const XMLNode* node) = 0; virtual irr::core::stringw toString() const = 0; @@ -86,8 +85,8 @@ public: GroupUserConfigParam(const char* param_name, GroupUserConfigParam* group, const char* comment = NULL); - void write(XMLWriter& stream) const; - void writeInner(XMLWriter& stream, int level = 0) const; + void write(UTFWriter& stream) const; + void writeInner(UTFWriter& stream, int level = 0) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); @@ -120,7 +119,7 @@ public: int nb_elts, ...); - void write(XMLWriter& stream) const; + void write(UTFWriter& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); @@ -151,7 +150,7 @@ public: GroupUserConfigParam* group, const char* comment = NULL); - void write(XMLWriter& stream) const; + void write(UTFWriter& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); @@ -178,7 +177,7 @@ public: TimeUserConfigParam(StkTime::TimeType default_value, const char* param_name, GroupUserConfigParam* group, const char* comment=NULL); - void write(XMLWriter& stream) const; + void write(UTFWriter& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); @@ -205,7 +204,7 @@ public: GroupUserConfigParam* group, const char* comment = NULL); - void write(XMLWriter& stream) const; + void write(UTFWriter& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); @@ -240,7 +239,7 @@ public: GroupUserConfigParam* group, const char* comment = NULL); - void write(XMLWriter& stream) const; + void write(UTFWriter& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); @@ -267,7 +266,7 @@ public: BoolUserConfigParam(bool default_value, const char* param_name, GroupUserConfigParam* group, const char* comment = NULL); - void write(XMLWriter& stream) const; + void write(UTFWriter& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); @@ -293,7 +292,7 @@ public: GroupUserConfigParam* group, const char* comment = NULL); - void write(XMLWriter& stream) const; + void write(UTFWriter& stream) const; void findYourDataInAChildOf(const XMLNode* node); void findYourDataInAnAttributeOf(const XMLNode* node); diff --git a/src/io/xml_writer.cpp b/src/io/utf_writer.cpp similarity index 52% rename from src/io/xml_writer.cpp rename to src/io/utf_writer.cpp index bc9443414..aab7dbbc6 100644 --- a/src/io/xml_writer.cpp +++ b/src/io/utf_writer.cpp @@ -16,90 +16,53 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "io/xml_writer.hpp" +#include "io/utf_writer.hpp" + #include <wchar.h> #include <string> #include <stdexcept> using namespace irr; -#if IRRLICHT_VERSION_MAJOR > 1 || (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR >= 8) - // ---------------------------------------------------------------------------- -XMLWriter::XMLWriter(const char* dest) : m_base(dest, std::ios::out | std::ios::binary) +UTFWriter::UTFWriter(const char* dest) + : m_base(dest, std::ios::out | std::ios::binary) { if (!m_base.is_open()) { - throw std::runtime_error("Failed to open file for writing : " + std::string(dest)); + throw std::runtime_error("Failed to open file for writing : " + + std::string(dest)); } // FIXME: make sure to properly handle endianness - wchar_t BOM = 0xFEFF; // UTF-16 BOM is 0xFEFF; UTF-32 BOM is 0x0000FEFF. So this works in either case + // UTF-16 BOM is 0xFEFF; UTF-32 BOM is 0x0000FEFF. So this works in either case + wchar_t BOM = 0xFEFF; m_base.write((char *) &BOM, sizeof(wchar_t)); -} +} // UTFWriter // ---------------------------------------------------------------------------- -XMLWriter& XMLWriter::operator<< (const irr::core::stringw& txt) +UTFWriter& UTFWriter::operator<< (const irr::core::stringw& txt) { m_base.write((char *) txt.c_str(), txt.size() * sizeof(wchar_t)); return *this; -} +} // operator<< (stringw) // ---------------------------------------------------------------------------- -XMLWriter& XMLWriter::operator<< (const wchar_t*txt) +UTFWriter& UTFWriter::operator<< (const wchar_t*txt) { m_base.write((char *) txt, wcslen(txt) * sizeof(wchar_t)); return *this; -} +} // operator<< (wchar_t) // ---------------------------------------------------------------------------- -void XMLWriter::close() +void UTFWriter::close() { m_base.close(); -} - -// ---------------------------------------------------------------------------- -// ---------------------------------------------------------------------------- - -#else // Non-unicode version for irrlicht 1.7 and before - -XMLWriter::XMLWriter(const char* dest) : m_base(dest, std::ios::out | std::ios::binary) -{ - if (!m_base.is_open()) - { - throw std::runtime_error("Failed to open file for writing : " + std::string(dest)); - } -} +} // close // ---------------------------------------------------------------------------- -XMLWriter& XMLWriter::operator<< (const irr::core::stringw& txt) -{ - core::stringc s( txt.c_str() ); - m_base.write((char *) s.c_str(), s.size()); - return *this; -} - -// ---------------------------------------------------------------------------- - -XMLWriter& XMLWriter::operator<< (const wchar_t*txt) -{ - core::stringc s( txt ); - m_base.write((char *) s.c_str(), s.size()); - return *this; -} - -// ---------------------------------------------------------------------------- - -void XMLWriter::close() -{ - m_base.close(); -} - -// ---------------------------------------------------------------------------- - -#endif diff --git a/src/io/xml_writer.hpp b/src/io/utf_writer.hpp similarity index 85% rename from src/io/xml_writer.hpp rename to src/io/utf_writer.hpp index 3fcb9132b..25d447cd0 100644 --- a/src/io/xml_writer.hpp +++ b/src/io/utf_writer.hpp @@ -16,8 +16,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_XML_WRITER_HPP -#define HEADER_XML_WRITER_HPP +#ifndef HEADER_UTF_WRITER_HPP +#define HEADER_UTF_WRITER_HPP #include <fstream> #include <irrString.h> @@ -28,18 +28,18 @@ * we only want to accept arrays of wchar_t to make sure we get reasonable files out * \ingroup io */ -class XMLWriter +class UTFWriter { std::ofstream m_base; public: - XMLWriter(const char* dest); + UTFWriter(const char* dest); - XMLWriter& operator<< (const irr::core::stringw& txt); - XMLWriter& operator<< (const wchar_t* txt); + UTFWriter& operator<< (const irr::core::stringw& txt); + UTFWriter& operator<< (const wchar_t* txt); template<typename T> - XMLWriter& operator<< (const T t) + UTFWriter& operator<< (const T t) { irr::core::stringw tmp; tmp += t; diff --git a/src/race/highscore_manager.cpp b/src/race/highscore_manager.cpp index 58a4d38b4..d65d7162e 100644 --- a/src/race/highscore_manager.cpp +++ b/src/race/highscore_manager.cpp @@ -23,7 +23,7 @@ #include "config/user_config.hpp" #include "io/file_manager.hpp" -#include "io/xml_writer.hpp" +#include "io/utf_writer.hpp" #include "race/race_manager.hpp" #include "utils/constants.hpp" #include "utils/string_utils.hpp" @@ -149,7 +149,7 @@ void HighscoreManager::saveHighscores() try { - XMLWriter highscore_file(m_filename.c_str()); + UTFWriter highscore_file(m_filename.c_str()); highscore_file << L"<?xml version=\"1.0\"?>\n"; highscore_file << L"<highscores version=\"" << CURRENT_HSCORE_FILE_VERSION << "\">\n"; diff --git a/src/race/highscores.cpp b/src/race/highscores.cpp index 034ca8a87..f00fd036a 100644 --- a/src/race/highscores.cpp +++ b/src/race/highscores.cpp @@ -18,13 +18,13 @@ #include "race/highscores.hpp" +#include "io/utf_writer.hpp" +#include "io/xml_node.hpp" +#include "race/race_manager.hpp" + #include <stdexcept> #include <fstream> -#include "io/xml_node.hpp" -#include "io/xml_writer.hpp" -#include "race/race_manager.hpp" - // ----------------------------------------------------------------------------- Highscores::Highscores(const HighscoreType highscore_type, int num_karts, @@ -105,7 +105,7 @@ void Highscores::readEntry(const XMLNode &node) * resulting in empty entries here. * \param writer The file stream to write the data to. */ -void Highscores::writeEntry(XMLWriter &writer) +void Highscores::writeEntry(UTFWriter &writer) { // Only bool one_is_set = false; diff --git a/src/race/highscores.hpp b/src/race/highscores.hpp index b713bc7f0..a321f9d9e 100644 --- a/src/race/highscores.hpp +++ b/src/race/highscores.hpp @@ -27,7 +27,7 @@ #include <irrString.h> class XMLNode; -class XMLWriter; +class UTFWriter; /** * Represents one highscore entry, i.e. the (atm up to three) highscores @@ -62,7 +62,7 @@ public: Highscores (const XMLNode &node); void readEntry (const XMLNode &node); - void writeEntry(XMLWriter &writer); + void writeEntry(UTFWriter &writer); int matches (HighscoreType highscore_type, int num_karts, const RaceManager::Difficulty difficulty, const std::string track, const int number_of_laps, From 78b73aa3c83bf3543b8ffb0c3f7fad85e97461ec Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Thu, 6 Feb 2014 14:43:47 +1100 Subject: [PATCH 03/68] Added new player manager, and started to replace the saved data from user_config with player manager. --- sources.cmake | 6 +- src/achievements/achievements_manager.cpp | 8 +- src/achievements/achievements_manager.hpp | 4 +- src/achievements/achievements_slot.cpp | 8 +- src/achievements/achievements_slot.hpp | 10 +- src/challenges/game_slot.cpp | 3 +- src/challenges/game_slot.hpp | 16 +- src/challenges/unlock_manager.cpp | 16 +- src/challenges/unlock_manager.hpp | 8 +- src/config/player.cpp | 93 +++++------- src/config/player.hpp | 55 +++---- src/config/player_manager.cpp | 141 ++++++++++++++++++ src/config/player_manager.hpp | 78 ++++++++++ src/config/saved_grand_prix.cpp | 7 +- src/config/saved_grand_prix.hpp | 8 +- src/config/user_config.cpp | 32 ---- src/config/user_config.hpp | 1 - src/main.cpp | 12 +- src/modes/easter_egg_hunt.hpp | 0 .../dialogs/enter_player_name_dialog.cpp | 14 +- src/states_screens/options_screen_players.cpp | 2 +- 21 files changed, 345 insertions(+), 177 deletions(-) create mode 100644 src/config/player_manager.cpp create mode 100644 src/config/player_manager.hpp mode change 100755 => 100644 src/modes/easter_egg_hunt.hpp diff --git a/sources.cmake b/sources.cmake index 71097b569..d499bfebd 100644 --- a/sources.cmake +++ b/sources.cmake @@ -23,6 +23,7 @@ src/challenges/game_slot.cpp src/challenges/unlock_manager.cpp src/config/device_config.cpp src/config/player.cpp +src/config/player_manager.cpp src/config/saved_grand_prix.cpp src/config/stk_config.cpp src/config/user_config.cpp @@ -101,8 +102,8 @@ src/input/input_manager.cpp src/input/wiimote.cpp src/input/wiimote_manager.cpp src/io/file_manager.cpp +src/io/utf_writer.cpp src/io/xml_node.cpp -src/io/xml_writer.cpp src/items/attachment.cpp src/items/attachment_manager.cpp src/items/bowling.cpp @@ -351,6 +352,7 @@ src/challenges/game_slot.hpp src/challenges/unlock_manager.hpp src/config/device_config.hpp src/config/player.hpp +src/config/player_manager.hpp src/config/saved_grand_prix.hpp src/config/stk_config.hpp src/config/user_config.hpp @@ -428,8 +430,8 @@ src/input/input_manager.hpp src/input/wiimote.hpp src/input/wiimote_manager.hpp src/io/file_manager.hpp +src/io/utf_writer.hpp src/io/xml_node.hpp -src/io/xml_writer.hpp src/items/attachment.hpp src/items/attachment_manager.hpp src/items/attachment_plugin.hpp diff --git a/src/achievements/achievements_manager.cpp b/src/achievements/achievements_manager.cpp index 661c31a98..7fb1345f3 100644 --- a/src/achievements/achievements_manager.cpp +++ b/src/achievements/achievements_manager.cpp @@ -138,7 +138,7 @@ void AchievementsManager::parseUserConfigFile() } // load -AchievementsSlot * AchievementsManager::createNewSlot(std::string id, bool online) +AchievementsSlot * AchievementsManager::createNewSlot(unsigned int id, bool online) { AchievementsSlot* slot = new AchievementsSlot(id, online); m_slots.push_back(slot); @@ -207,7 +207,7 @@ void AchievementsManager::onRaceEnd() } // ============================================================================ -AchievementsSlot * AchievementsManager::getSlot(const std::string & id, bool online) +AchievementsSlot * AchievementsManager::getSlot(unsigned int id, bool online) { for(unsigned int i = 0; i < m_slots.size(); i++) { @@ -224,10 +224,10 @@ void AchievementsManager::updateCurrentPlayer() { if(Online::CurrentUser::get()->isRegisteredUser()) { - m_active_slot = getSlot(StringUtils::toString(Online::CurrentUser::get()->getID()), true); + m_active_slot = getSlot(Online::CurrentUser::get()->getID(), true); if(m_active_slot == NULL) { - m_active_slot = createNewSlot(StringUtils::toString(Online::CurrentUser::get()->getID()), true); + m_active_slot = createNewSlot(Online::CurrentUser::get()->getID(), true); save(); } } diff --git a/src/achievements/achievements_manager.hpp b/src/achievements/achievements_manager.hpp index 8181ba531..9886fe5e3 100644 --- a/src/achievements/achievements_manager.hpp +++ b/src/achievements/achievements_manager.hpp @@ -45,7 +45,7 @@ private : std::map<uint32_t, AchievementInfo *> m_achievements_info; AchievementsManager (); ~AchievementsManager (); - AchievementsSlot * createNewSlot(std::string id, bool online); + AchievementsSlot * createNewSlot(unsigned int id, bool online); void parseAssetFile(); void parseUserConfigFile(); @@ -59,7 +59,7 @@ public: void onRaceEnd(); void updateCurrentPlayer(); AchievementsSlot * getActive() const { return m_active_slot; } - AchievementsSlot * getSlot(const std::string & id, bool online); + AchievementsSlot * getSlot(unsigned int id, bool online); void createSlotsIfNeeded(); AchievementInfo * getAchievementInfo(uint32_t id); const std::map<uint32_t, AchievementInfo *> & getAllInfo() { return m_achievements_info;} diff --git a/src/achievements/achievements_slot.cpp b/src/achievements/achievements_slot.cpp index ec36d8771..b970d5dfb 100644 --- a/src/achievements/achievements_slot.cpp +++ b/src/achievements/achievements_slot.cpp @@ -63,11 +63,11 @@ AchievementsSlot::AchievementsSlot(const XMLNode * input) } // ============================================================================ -AchievementsSlot::AchievementsSlot(std::string id, bool online) +AchievementsSlot::AchievementsSlot(unsigned int id, bool online) { - m_valid = true; + m_valid = true; m_online = online; - m_id = id; + m_id = id; createFreshSlot(); } @@ -112,7 +112,7 @@ void AchievementsSlot::createFreshSlot() // ============================================================================ void AchievementsSlot::save(std::ofstream & out) { - out << " <slot user_id=\"" << m_id.c_str() + out << " <slot user_id=\"" << m_id << "\" online=\"" << StringUtils::toString(m_online) << "\"> \n"; std::map<uint32_t, Achievement*>::const_iterator i; diff --git a/src/achievements/achievements_slot.hpp b/src/achievements/achievements_slot.hpp index cfb73ab07..21fb10c0b 100644 --- a/src/achievements/achievements_slot.hpp +++ b/src/achievements/achievements_slot.hpp @@ -33,9 +33,9 @@ class AchievementsSlot { private: std::map<uint32_t, Achievement *> m_achievements; - bool m_online; - bool m_valid; - std::string m_id; + bool m_online; + bool m_valid; + unsigned int m_id; void createFreshSlot(); void deleteAchievements(); @@ -48,14 +48,14 @@ private: public : AchievementsSlot(const XMLNode * input); - AchievementsSlot(std::string id, bool online); + AchievementsSlot(unsigned int id, bool online); ~AchievementsSlot(); bool isValid() const { return m_valid;} void save(std::ofstream & out); bool isOnline() const {return m_online;} void sync(const std::vector<uint32_t> & achieved_ids); void onRaceEnd(); - const std::string & getID() const {return m_id;} + unsigned int getID() const {return m_id;} const std::map<uint32_t, Achievement *> & getAllAchievements() {return m_achievements;} Achievement * getAchievement(uint32_t id); }; diff --git a/src/challenges/game_slot.cpp b/src/challenges/game_slot.cpp index 2ac0449ac..469e05964 100644 --- a/src/challenges/game_slot.cpp +++ b/src/challenges/game_slot.cpp @@ -22,7 +22,6 @@ #include "challenges/challenge.hpp" #include "challenges/challenge_data.hpp" #include "challenges/unlock_manager.hpp" -#include "io/xml_writer.hpp" //----------------------------------------------------------------------------- GameSlot::~GameSlot() @@ -238,7 +237,7 @@ void GameSlot::grandPrixFinished() void GameSlot::save(std::ofstream& out, const std::string& name) { - out << " <gameslot playerID=\"" << m_player_unique_id.c_str() + out << " <gameslot playerID=\"" << m_player_unique_id << "\" kart=\"" << m_kart_ident.c_str() << "\" firstTime=\"" << (m_first_time ? "true" : "false") << "\"> <!-- " << name.c_str() << " -->\n"; diff --git a/src/challenges/game_slot.hpp b/src/challenges/game_slot.hpp index 11dedf407..b8319b9eb 100644 --- a/src/challenges/game_slot.hpp +++ b/src/challenges/game_slot.hpp @@ -46,7 +46,7 @@ class GameSlot * are done everywhere, assign a unique ID to each profiler. * Will save much headaches. */ - std::string m_player_unique_id; + unsigned int m_player_unique_id; /** Contains whether each feature of the challenge is locked or unlocked */ std::map<std::string, bool> m_locked_features; @@ -79,19 +79,19 @@ public: // do NOT attempt to pass 'player_unique_id' by reference here. I don't // know why (compiler bug maybe?) but this screws up everything. Better // pass by copy. - GameSlot(std::string player_unique_id) + GameSlot(unsigned int player_unique_id) { - m_player_unique_id = player_unique_id; - m_points = 0; - m_first_time = true; - m_easy_challenges = 0; + m_player_unique_id = player_unique_id; + m_points = 0; + m_first_time = true; + m_easy_challenges = 0; m_medium_challenges = 0; - m_hard_challenges = 0; + m_hard_challenges = 0; m_current_challenge = NULL; } ~GameSlot(); - const std::string& getPlayerID() const { return m_player_unique_id; } + unsigned int getPlayerID() const { return m_player_unique_id; } const std::string& getKartIdent () const { return m_kart_ident; } void setKartIdent(const std::string& kart_ident) { diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index 47099068e..317242ec4 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -47,7 +47,7 @@ UnlockManager::UnlockManager() // in main). unlock_manager = this; - m_current_game_slot = ""; + m_current_game_slot = 0; m_locked_sound = sfx_manager->createSoundSource("locked"); @@ -94,7 +94,7 @@ UnlockManager::~UnlockManager() } - std::map<std::string, GameSlot*>::iterator it; + std::map<unsigned int, GameSlot*>::iterator it; for (it = m_game_slots.begin(); it != m_game_slots.end(); it++) { delete it->second; @@ -222,7 +222,7 @@ void UnlockManager::load() root->getNodes("gameslot", xml_game_slots); for (unsigned int n=0; n<xml_game_slots.size(); n++) { - std::string player_id; + unsigned int player_id; if (!xml_game_slots[n]->get("playerID", &player_id)) { Log::warn("unlock_manager", "Found game slot without " @@ -279,7 +279,7 @@ void UnlockManager::save() challenge_file << "<?xml version=\"1.0\"?>\n"; challenge_file << "<challenges>\n"; - std::map<std::string, GameSlot*>::iterator it; + std::map<unsigned int, GameSlot*>::iterator it; for (it = m_game_slots.begin(); it != m_game_slots.end(); it++) { std::string name = "unknown player"; @@ -313,7 +313,7 @@ bool UnlockManager::createSlotsIfNeeded() { bool exists = false; - std::map<std::string, GameSlot*>::iterator it; + std::map<unsigned int, GameSlot*>::iterator it; for (it = m_game_slots.begin(); it != m_game_slots.end(); it++) { GameSlot* curr_slot = it->second; @@ -351,7 +351,7 @@ bool UnlockManager::createSlotsIfNeeded() bool UnlockManager::deleteSlotsIfNeeded() { bool changed = false; - std::map<std::string, GameSlot*>::iterator it = m_game_slots.begin(); + std::map<unsigned int, GameSlot*>::iterator it = m_game_slots.begin(); while (it != m_game_slots.end()) { bool found = false; @@ -370,7 +370,7 @@ bool UnlockManager::deleteSlotsIfNeeded() { #ifdef DEBUG printf("Deleting gameslot %s, no player found.\n", - it->second->getPlayerID().c_str()); + it->second->getPlayerID()); #endif // Iterators aren't invalidated this way m_game_slots.erase(it++); @@ -424,7 +424,7 @@ void UnlockManager::updateActiveChallengeList() //----------------------------------------------------------------------------- -void UnlockManager::setCurrentSlot(std::string slotid) +void UnlockManager::setCurrentSlot(unsigned int slotid) { m_current_game_slot = slotid; AchievementsManager::get()->updateCurrentPlayer(); diff --git a/src/challenges/unlock_manager.hpp b/src/challenges/unlock_manager.hpp index 093efcc29..dbd630cda 100644 --- a/src/challenges/unlock_manager.hpp +++ b/src/challenges/unlock_manager.hpp @@ -48,12 +48,12 @@ private: typedef std::map<std::string, ChallengeData*> AllChallengesType; AllChallengesType m_all_challenges; - std::map<std::string, GameSlot*> m_game_slots; + std::map<unsigned int , GameSlot*> m_game_slots; void readAllChallengesInDirs(const std::vector<std::string>* all_dirs); /** ID of the active player */ - std::string m_current_game_slot; + unsigned int m_current_game_slot; friend class GameSlot; @@ -73,7 +73,7 @@ public: /** Eye- (or rather ear-) candy. Play a sound when user tries to access a locked area */ void playLockSound() const; - const std::string& getCurrentSlotID() const { return m_current_game_slot; } + unsigned int getCurrentSlotID() const { return m_current_game_slot; } GameSlot* getCurrentSlot() { @@ -82,7 +82,7 @@ public: } /** \param slotid name of the player */ - void setCurrentSlot(std::string slotid); + void setCurrentSlot(unsigned int slotid); void findWhatWasUnlocked(int pointsBefore, int pointsNow, std::vector<std::string>& tracks, std::vector<std::string>& gps); diff --git a/src/config/player.cpp b/src/config/player.cpp index a58ca09cf..37c67eb7c 100644 --- a/src/config/player.cpp +++ b/src/config/player.cpp @@ -16,77 +16,66 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "config/player.hpp" + +#include "config/player_manager.hpp" +#include "io/xml_node.hpp" +#include "io/utf_writer.hpp" +#include "utils/string_utils.hpp" + +#include <sstream> #include <stdlib.h> -#include "config/player.hpp" -#include "utils/string_utils.hpp" -#include <sstream> - - //------------------------------------------------------------------------------ -PlayerProfile::PlayerProfile(const core::stringw& name) : - m_player_group("Player", "Represents one human player"), - m_name(name, "name", &m_player_group), - m_is_guest_account(false, "guest", &m_player_group), - m_use_frequency(0, "use_frequency", &m_player_group), - m_unique_id("", "unique_id", &m_player_group) +/** Constructor to create a new player that didn't exist before. + * \param name Name of the player. + * \param is_guest True if this is a guest account. +*/ +PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest) { #ifdef DEBUG m_magic_number = 0xABCD1234; #endif - int64_t unique_id = generateUniqueId(core::stringc(name.c_str()).c_str()); + m_name = name; + m_is_guest_account = is_guest; + m_use_frequency = 0; + m_unique_id = PlayerManager::get()->getUniqueId(); - std::ostringstream to_string; - to_string << std::hex << unique_id; - m_unique_id = to_string.str(); -} +} // PlayerProfile //------------------------------------------------------------------------------ -PlayerProfile::PlayerProfile(const XMLNode* node) : - m_player_group("Player", "Represents one human player"), - m_name("-", "name", &m_player_group), - m_is_guest_account(false, "guest", &m_player_group), - m_use_frequency(0, "use_frequency", &m_player_group), - m_unique_id("", "unique_id", &m_player_group) +/** Constructor to deserialize a player that was saved to a XML file. + * \param node The XML node representing this player. +*/ +PlayerProfile::PlayerProfile(const XMLNode* node) { - //m_player_group.findYourDataInAChildOf(node); - m_name.findYourDataInAnAttributeOf(node); - m_is_guest_account.findYourDataInAnAttributeOf(node); - m_use_frequency.findYourDataInAnAttributeOf(node); - m_unique_id.findYourDataInAnAttributeOf(node); - - if ((std::string)m_unique_id == "") - { - fprintf(stderr, "** WARNING: Player has no unique ID, probably it is from an older STK version\n"); - int64_t unique_id = generateUniqueId(core::stringc(m_name.c_str()).c_str()); - std::ostringstream tostring; - tostring << std::hex << unique_id; - m_unique_id = tostring.str(); - } - + node->get("name", &m_name ); + node->get("guest", &m_is_guest_account); + node->get("use-frequency", &m_use_frequency ); + node->get("unique-id", &m_unique_id ); #ifdef DEBUG m_magic_number = 0xABCD1234; #endif } // PlayerProfile //------------------------------------------------------------------------------ +/** Writes the data for this player to the specified UTFWriter. + * \param out The utf writer to write the data to. + */ +void PlayerProfile::save(UTFWriter &out) +{ + out << L" <player name=\"" << m_name << L"\"\n"; + out << L" guest=\"" << m_is_guest_account << L"\"\n"; + out << L" use-frequency=\""<< m_use_frequency << L"\"\n"; + out << L" unique-id=\"" << m_unique_id << L"\"\n"; + out << L" />\n"; +} // save + +//------------------------------------------------------------------------------ +/** Increments how often that account was used. Guest accounts are not counted. + */ void PlayerProfile::incrementUseFrequency() { if (m_is_guest_account) m_use_frequency = -1; else m_use_frequency++; } // incrementUseFrequency - -//------------------------------------------------------------------------------ -int64_t PlayerProfile::generateUniqueId(const char* player_name) -{ - // First create a simple hash based on he player name - int hash = 0; - for (int n=0; player_name[n] != 0; n++) - { - hash += (hash << (hash & 0xF)) ^ player_name[n]; - } - - return ((int64_t)(StkTime::getTimeSinceEpoch()) << 32) | - ((rand() << 16) & 0xFFFF0000) | - hash; -} // generateUniqueId diff --git a/src/config/player.hpp b/src/config/player.hpp index b94d8136e..30f8b16f7 100644 --- a/src/config/player.hpp +++ b/src/config/player.hpp @@ -19,13 +19,17 @@ #ifndef HEADER_PLAYER_HPP #define HEADER_PLAYER_HPP -#include <string> #include "config/user_config.hpp" #include "utils/no_copy.hpp" #include "utils/types.hpp" + #include <irrString.h> using namespace irr; +#include <string> + +class UTFWriter; + /** * \brief Class for managing player profiles (name, control configuration, etc.) * A list of all possible players is stored as PlayerProfiles in the user config. @@ -36,43 +40,31 @@ class PlayerProfile : public NoCopy { protected: - /** - * For saving to config file. - * WARNING : m_player_group has to be declared before the other userconfigparams! - */ - GroupUserConfigParam m_player_group; + /** The name of the player (wide string, so it can be in native + * language). */ + core::stringw m_name; - WStringUserConfigParam m_name; - - BoolUserConfigParam m_is_guest_account; + /** True if this account is a guest account. */ + bool m_is_guest_account; #ifdef DEBUG unsigned int m_magic_number; #endif - IntUserConfigParam m_use_frequency; + /** Counts how often this player was used. */ + unsigned int m_use_frequency; - /** Profile names can change, so rather than try to make sure all renames are done everywhere, - * assign a unique ID to each profiler. Will save much headaches. - */ - StringUserConfigParam m_unique_id; - - int64_t generateUniqueId(const char* playerName); + /** A unique number for this player, used to link it to challenges etc. */ + unsigned int m_unique_id; public: - /** - * Constructor to create a new player that didn't exist before - */ - PlayerProfile(const core::stringw& name); + PlayerProfile(const core::stringw& name, bool is_guest = false); - /** - * Constructor to deserialize a player that was saved to a XML file - * (...UserConfigParam classes will automagically take care of serializing all - * create players to the user's config file) - */ PlayerProfile(const XMLNode* node); + void save(UTFWriter &out); + void incrementUseFrequency(); ~PlayerProfile() { @@ -112,15 +104,12 @@ public: } - void incrementUseFrequency(); - // please do NOT try to optimise this to return a reference, I don't know why, - // maybe compiler bug, but hell breaks loose when you do that - std::string getUniqueID() const - { - return m_unique_id; - } -}; + // ------------------------------------------------------------------------ + /** Returns the unique id of this player. */ + unsigned int getUniqueID() const { return m_unique_id; } + +}; // class PlayerProfile #endif diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp new file mode 100644 index 000000000..b0cbba275 --- /dev/null +++ b/src/config/player_manager.cpp @@ -0,0 +1,141 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2012-2014 Joerg Henrichs +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "config/player_manager.hpp" + +#include "config/player.hpp" +#include "io/file_manager.hpp" +#include "io/utf_writer.hpp" +#include "io/xml_node.hpp" +#include "utils/log.hpp" +#include "utils/translation.hpp" + +PlayerManager *PlayerManager::m_player_manager = NULL; + +/** Constructor. + */ +PlayerManager::PlayerManager() +{ +} // PlayerManager + +// ---------------------------------------------------------------------------- +/** Destructor. + */ +PlayerManager::~PlayerManager() +{ + save(); +} // ~PlayerManager + +// ---------------------------------------------------------------------------- + +void PlayerManager::load() +{ + std::string filename = file_manager->getUserConfigFile("players.xml"); + + const XMLNode *players = file_manager->createXMLTree(filename); + if(!players || players->getName()!="players") + { + Log::info("player_manager", "The players.xml file is invalid."); + return; + } + + for(unsigned int i=0; i<players->getNumNodes(); i++) + { + const XMLNode *player_xml = players->getNode(i); + PlayerProfile *profile = new PlayerProfile(player_xml); + m_all_players.push_back(profile); + } +} // load + +// ---------------------------------------------------------------------------- +void PlayerManager::save() +{ + std::string filename = file_manager->getUserConfigFile("players.xml"); + try + { + UTFWriter players_file(filename.c_str()); + + players_file << L"<?xml version=\"1.0\"?>\n"; + players_file << L"<players version=\"1\" >\n"; + + PlayerProfile *player; + for_in(player, m_all_players) + { + player->save(players_file); + } + players_file << L"</players>\n"; + players_file.close(); + } + catch (std::runtime_error& e) + { + Log::error("PlayerManager", "Failed to write config to %s.", + filename.c_str()); + Log::error("PlayerManager", "Error: %s", e.what()); + } + + +} // save + +// ---------------------------------------------------------------------------- +/** Adds a new player to the list of all players. + * \param name Name of the new player. + */ +void PlayerManager::addNewPlayer(const core::stringw& name) +{ + m_all_players.push_back( new PlayerProfile(name) ); +} // addNewPlayer + +// ---------------------------------------------------------------------------- +void PlayerManager::addDefaultPlayer() +{ + std::string username = "unnamed player"; + + if(getenv("USERNAME")!=NULL) // for windows + username = getenv("USERNAME"); + else if(getenv("USER")!=NULL) // Linux, Macs + username = getenv("USER"); + else if(getenv("LOGNAME")!=NULL) // Linux, Macs + username = getenv("LOGNAME"); + + // Set the name as the default name for all players. + m_all_players.push_back(new PlayerProfile(username.c_str()) ); + + // add default guest player + m_all_players.push_back( new PlayerProfile(_LTR("Guest")) ); + + +} // addDefaultPlayer + +// ---------------------------------------------------------------------------- +/** This returns a unique id. This is 1 + larger id so far used. + */ +unsigned int PlayerManager::getUniqueId() const +{ + unsigned int max_id=0; + const PlayerProfile *player; + for_in(player, m_all_players) + { + if(player->getUniqueID()>max_id) + max_id = player->getUniqueID(); + } + return max_id+1; +} // getUniqueId + +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- diff --git a/src/config/player_manager.hpp b/src/config/player_manager.hpp new file mode 100644 index 000000000..9b2d06580 --- /dev/null +++ b/src/config/player_manager.hpp @@ -0,0 +1,78 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2010-2014 Joerg Henrichs +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_PLAYER_CONFIG_HPP +#define HEADER_PLAYER_CONFIG_HPP + +#include "utils/no_copy.hpp" +#include "utils/ptr_vector.hpp" + +#include <irrString.h> + +#include <cstddef> // NULL + +class PlayerProfile; + +/** A special class that manages all local player accounts. + */ +class PlayerManager : public NoCopy +{ +private: + static PlayerManager* m_player_manager; + + PtrVector<PlayerProfile> m_all_players; + + + PlayerManager(); + ~PlayerManager(); + + +public: + /** Static singleton get function. */ + static PlayerManager* get() + { + if(!m_player_manager) + m_player_manager = new PlayerManager(); + return m_player_manager; + } // get + // ------------------------------------------------------------------------ + static void destroy() + { + delete m_player_manager; + m_player_manager = NULL; + } // destroy + // ------------------------------------------------------------------------ + + void load(); + void save(); + unsigned int getUniqueId() const; + void addDefaultPlayer(); + void addNewPlayer(const irr::core::stringw& name); + // ------------------------------------------------------------------------ + /** Returns the number of players in the config file.*/ + unsigned int getNumPlayers() const { return m_all_players.size(); } + // ------------------------------------------------------------------------ + /** Returns a player with a given unique id. */ + const PlayerProfile &getPlayer(unsigned int n) { return m_all_players[n];} + // ------------------------------------------------------------------------ +}; // PlayerManager + + +#endif + +/*EOF*/ diff --git a/src/config/saved_grand_prix.cpp b/src/config/saved_grand_prix.cpp index 5e43b3255..3805457da 100644 --- a/src/config/saved_grand_prix.cpp +++ b/src/config/saved_grand_prix.cpp @@ -63,7 +63,7 @@ SavedGrandPrix::SavedGPKart::SavedGPKart(GroupUserConfigParam * group, } // SavedGPKart // ============================================================================ -SavedGrandPrix::SavedGrandPrix(const std::string &player_id, +SavedGrandPrix::SavedGrandPrix(unsigned int player_id, const std::string &gp_id, RaceManager::Difficulty difficulty, int player_karts, @@ -71,7 +71,7 @@ SavedGrandPrix::SavedGrandPrix(const std::string &player_id, const std::vector<RaceManager::KartStatus> &kart_list) : m_savedgp_group("SavedGP", "Represents the saved state of a GP"), - m_player_id(player_id.c_str(), "player_id", &m_savedgp_group), + m_player_id(player_id), m_gp_id(gp_id.c_str(), "gp_id", &m_savedgp_group), m_difficulty((int)difficulty,"difficulty", &m_savedgp_group), m_player_karts(player_karts,"player_karts", &m_savedgp_group), @@ -94,14 +94,13 @@ SavedGrandPrix::SavedGrandPrix(const std::string &player_id, SavedGrandPrix::SavedGrandPrix(const XMLNode* node) : m_savedgp_group("SavedGP", "Represents the saved state of a GP"), - m_player_id("-", "player_id", &m_savedgp_group), + m_player_id(0), m_gp_id("-", "gp_id", &m_savedgp_group), m_difficulty(0,"difficulty", &m_savedgp_group), m_player_karts(0,"player_karts", &m_savedgp_group), m_next_track(0,"last_track", &m_savedgp_group) { //m_player_group.findYourDataInAChildOf(node); - m_player_id.findYourDataInAnAttributeOf(node); m_gp_id.findYourDataInAnAttributeOf(node); m_difficulty.findYourDataInAnAttributeOf(node); m_player_karts.findYourDataInAnAttributeOf(node); diff --git a/src/config/saved_grand_prix.hpp b/src/config/saved_grand_prix.hpp index bc5f52eb5..e8aa32217 100644 --- a/src/config/saved_grand_prix.hpp +++ b/src/config/saved_grand_prix.hpp @@ -60,7 +60,7 @@ protected: * WARNING : m_savedgp_group has to be declared before the other userconfigparams! */ GroupUserConfigParam m_savedgp_group; - StringUserConfigParam m_player_id; + unsigned int m_player_id; /** Identifier of this GP. */ StringUserConfigParam m_gp_id; @@ -81,7 +81,7 @@ public: /** * Constructor to create a new entry. */ - SavedGrandPrix(const std::string &player_id, + SavedGrandPrix(unsigned int player_id, const std::string &gp_id, RaceManager::Difficulty difficulty, int player_karts, @@ -98,7 +98,7 @@ public: // ------------------------------------------------------------------------ /** Returns the player id for this saved GP. */ - const std::string getPlayerID() const { return m_player_id; } + unsigned int getPlayerID() const { return m_player_id; } // ------------------------------------------------------------------------ /** Returns the grand prix id. */ @@ -137,7 +137,7 @@ public: /** Finds the right SavedGrandPrix given the specified data, or * NULL if no matching GP was found. */ - static SavedGrandPrix* getSavedGP(const std::string &player, + static SavedGrandPrix* getSavedGP(unsigned int player, const std::string &gpid, int difficulty, int total_karts, int player_karts) diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index c37edfc77..184edc59b 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -728,38 +728,6 @@ UserConfig::~UserConfig() UserConfigParams::m_saved_grand_prix_list.clearAndDeleteAll(); } // ~UserConfig -// ----------------------------------------------------------------------------- -void UserConfig::addDefaultPlayer() -{ - - std::string username = "unnamed player"; - - if(getenv("USERNAME")!=NULL) // for windows - username = getenv("USERNAME"); - else if(getenv("USER")!=NULL) // Linux, Macs - username = getenv("USER"); - else if(getenv("LOGNAME")!=NULL) // Linux, Macs - username = getenv("LOGNAME"); - - - class GuestPlayerProfile : public PlayerProfile - { - public: - GuestPlayerProfile() : PlayerProfile(_LTR("Guest")) - { - m_is_guest_account = true; - } - }; - - // add default guest player - UserConfigParams::m_all_players.push_back( new GuestPlayerProfile() ); - - // Set the name as the default name for all players. - UserConfigParams::m_all_players.push_back( - new PlayerProfile(username.c_str()) ); - -} // addDefaultPlayer - // ----------------------------------------------------------------------------- /** Comparison used to sort players. Most frequent players should be diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index c01ce58df..547987682 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -826,7 +826,6 @@ public: void resetWarning() { m_warning=""; } void setWarning(irr::core::stringw& warning) { m_warning=warning; } void postLoadInit(); - void addDefaultPlayer(); }; // UserConfig diff --git a/src/main.cpp b/src/main.cpp index 643f1fae4..e9baab93b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -149,6 +149,7 @@ #include "config/stk_config.hpp" #include "config/user_config.hpp" #include "config/player.hpp" +#include "config/player_manager.hpp" #include "graphics/hardware_skinning.hpp" #include "graphics/irr_driver.hpp" #include "graphics/material_manager.hpp" @@ -680,8 +681,7 @@ int handleCmdLine() if(CommandLine::has("--kart", &s)) { - unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0] - .getUniqueID() ); + unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0).getUniqueID()); if (!unlock_manager->getCurrentSlot()->isLocked(s)) { @@ -972,6 +972,7 @@ void initUserConfig() { irr_driver = new IrrDriver(); file_manager = new FileManager(); + PlayerManager::get()->load(); user_config = new UserConfig(); // needs file_manager const bool config_ok = user_config->loadConfig(); if (UserConfigParams::m_language.toString() != "system") @@ -989,10 +990,10 @@ void initUserConfig() stk_config = new STKConfig(); // in case of --stk-config // command line parameters user_config->postLoadInit(); - if (!config_ok || UserConfigParams::m_all_players.size() == 0) + if (!config_ok || PlayerManager::get()->getNumPlayers() == 0) { - user_config->addDefaultPlayer(); - user_config->saveConfig(); + PlayerManager::get()->addDefaultPlayer(); + PlayerManager::get()->save(); } } // initUserConfig @@ -1113,6 +1114,7 @@ static void cleanSuperTuxKart() delete ParticleKindManager::get(); if(stk_config) delete stk_config; if(user_config) delete user_config; + PlayerManager::destroy(); if(unlock_manager) delete unlock_manager; if(translations) delete translations; if(file_manager) delete file_manager; diff --git a/src/modes/easter_egg_hunt.hpp b/src/modes/easter_egg_hunt.hpp old mode 100755 new mode 100644 diff --git a/src/states_screens/dialogs/enter_player_name_dialog.cpp b/src/states_screens/dialogs/enter_player_name_dialog.cpp index 1f234d675..341b5a3fb 100644 --- a/src/states_screens/dialogs/enter_player_name_dialog.cpp +++ b/src/states_screens/dialogs/enter_player_name_dialog.cpp @@ -22,6 +22,7 @@ #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" #include "config/player.hpp" +#include "config/player_manager.hpp" #include "guiengine/engine.hpp" #include "guiengine/widgets/button_widget.hpp" #include "guiengine/widgets/label_widget.hpp" @@ -102,14 +103,14 @@ void EnterPlayerNameDialog::onEnterPressedInternal() // ---- Otherwise, see if we can accept the new name TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield"); - stringw playerName = textCtrl->getText().trim(); - if (StringUtils::notEmpty(playerName)) + stringw player_name = textCtrl->getText().trim(); + if (StringUtils::notEmpty(player_name)) { // check for duplicates const int amount = UserConfigParams::m_all_players.size(); for (int n=0; n<amount; n++) { - if (UserConfigParams::m_all_players[n].getName() == playerName) + if (UserConfigParams::m_all_players[n].getName() == player_name) { LabelWidget* label = getWidget<LabelWidget>("title"); label->setText(_("Cannot add a player with this name."), false); @@ -119,7 +120,8 @@ void EnterPlayerNameDialog::onEnterPressedInternal() } // Finally, add the new player. - UserConfigParams::m_all_players.push_back( new PlayerProfile(playerName) ); + PlayerManager::get()->addNewPlayer(player_name); + UserConfigParams::m_all_players.push_back( new PlayerProfile(player_name)); bool created = unlock_manager->createSlotsIfNeeded(); if (created) unlock_manager->save(); user_config->saveConfig(); @@ -144,7 +146,7 @@ void EnterPlayerNameDialog::onUpdate(float dt) if (m_self_destroy) { TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield"); - stringw playerName = textCtrl->getText().trim(); + stringw player_name = textCtrl->getText().trim(); // irrLicht is too stupid to remove focus from deleted widgets // so do it by hand @@ -158,6 +160,6 @@ void EnterPlayerNameDialog::onUpdate(float dt) ModalDialog::dismiss(); - if (listener != NULL) listener->onNewPlayerWithName( playerName ); + if (listener != NULL) listener->onNewPlayerWithName( player_name ); } } diff --git a/src/states_screens/options_screen_players.cpp b/src/states_screens/options_screen_players.cpp index 5f7ca3832..7cc5c2cc4 100644 --- a/src/states_screens/options_screen_players.cpp +++ b/src/states_screens/options_screen_players.cpp @@ -78,7 +78,7 @@ void OptionsScreenPlayers::init() refreshPlayerList(); ButtonWidget* you = getWidget<ButtonWidget>("playername"); - const std::string& playerID = unlock_manager->getCurrentSlot()->getPlayerID(); + unsigned int playerID = unlock_manager->getCurrentSlot()->getPlayerID(); core::stringw playerName = L"-"; PlayerProfile* curr; for_in (curr, UserConfigParams::m_all_players) From dd860f46f9b2118d6d5a6374764a379016f43f07 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@mgail.com> Date: Thu, 6 Feb 2014 15:56:41 +1100 Subject: [PATCH 04/68] Fixed linux compilation. --- src/achievements/achievement.cpp | 4 ++-- src/challenges/challenge.cpp | 1 - src/challenges/unlock_manager.cpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/achievements/achievement.cpp b/src/achievements/achievement.cpp index be439a8ed..447ed2770 100644 --- a/src/achievements/achievement.cpp +++ b/src/achievements/achievement.cpp @@ -22,14 +22,14 @@ #include "achievements/achievement_info.hpp" #include "guiengine/dialog_queue.hpp" #include "states_screens/dialogs/notification_dialog.hpp" -#include "io/xml_writer.hpp" #include "utils/log.hpp" #include "utils/translation.hpp" +#include <assert.h> +#include <fstream> #include <sstream> #include <stdlib.h> -#include <assert.h> // ============================================================================ Achievement::Achievement(const AchievementInfo * info) diff --git a/src/challenges/challenge.cpp b/src/challenges/challenge.cpp index ea2badca6..05ef8270a 100644 --- a/src/challenges/challenge.cpp +++ b/src/challenges/challenge.cpp @@ -22,7 +22,6 @@ #include "challenges/challenge_data.hpp" #include "io/xml_node.hpp" -#include "io/xml_writer.hpp" #include "karts/kart_properties_manager.hpp" #include "karts/kart_properties.hpp" #include "race/grand_prix_manager.hpp" diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index 317242ec4..e9d8ce72b 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -369,7 +369,7 @@ bool UnlockManager::deleteSlotsIfNeeded() if (!found) { #ifdef DEBUG - printf("Deleting gameslot %s, no player found.\n", + printf("Deleting gameslot %d, no player found.\n", it->second->getPlayerID()); #endif // Iterators aren't invalidated this way From 045bfeaf13eb574110d28f05761df195c14bd416 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Thu, 6 Feb 2014 23:08:55 +1100 Subject: [PATCH 05/68] Removed m_all_players from UserConfigParams (though there are stil bugs in the new code). --- src/achievements/achievements_manager.cpp | 19 ++--- src/challenges/unlock_manager.cpp | 43 ++++++----- src/config/player.cpp | 21 +++++ src/config/player.hpp | 3 + src/config/player_manager.cpp | 33 ++++++++ src/config/player_manager.hpp | 12 ++- src/config/user_config.cpp | 51 ------------ src/config/user_config.hpp | 3 - src/main.cpp | 31 ++++---- src/modes/demo_world.cpp | 3 +- .../dialogs/enter_player_name_dialog.cpp | 5 +- .../dialogs/player_info_dialog.cpp | 10 ++- src/states_screens/kart_selection.cpp | 36 +++++---- src/states_screens/options_screen_players.cpp | 40 +++++----- src/states_screens/story_mode_lobby.cpp | 77 ++++++++----------- 15 files changed, 196 insertions(+), 191 deletions(-) diff --git a/src/achievements/achievements_manager.cpp b/src/achievements/achievements_manager.cpp index 7fb1345f3..c0fb4b218 100644 --- a/src/achievements/achievements_manager.cpp +++ b/src/achievements/achievements_manager.cpp @@ -18,13 +18,14 @@ #include "achievements/achievements_manager.hpp" +#include "challenges/unlock_manager.hpp" +#include "config/player.hpp" +#include "config/player_manager.hpp" +#include "config/user_config.hpp" +#include "io/file_manager.hpp" +#include "online/current_user.hpp" #include "utils/log.hpp" #include "utils/translation.hpp" -#include "io/file_manager.hpp" -#include "config/player.hpp" -#include "config/user_config.hpp" -#include "online/current_user.hpp" -#include "challenges/unlock_manager.hpp" #include <sstream> #include <stdlib.h> @@ -155,12 +156,12 @@ void AchievementsManager::createSlotsIfNeeded() bool something_changed = false; // make sure all players have at least one game slot associated - PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players; - for (unsigned int n=0; n<players.size(); n++) + for (unsigned int i=0; i<PlayerManager::get()->getNumPlayers(); i++) { - if (getSlot(players[n].getUniqueID(), false) == NULL ) + const PlayerProfile *player = PlayerManager::get()->getPlayer(i); + if (getSlot(player->getUniqueID(), false) == NULL ) { - createNewSlot(players[n].getUniqueID(), false); + createNewSlot(player->getUniqueID(), false); something_changed = true; } } diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index 317242ec4..6aba4a90d 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -18,17 +18,13 @@ #include "challenges/unlock_manager.hpp" -#include <set> -#include <string> -#include <vector> -#include <stdio.h> -#include <iostream> #include "achievements/achievements_manager.hpp" #include "audio/sfx_base.hpp" #include "audio/sfx_manager.hpp" #include "challenges/challenge_data.hpp" #include "config/player.hpp" +#include "config/player_manager.hpp" #include "config/user_config.hpp" #include "io/file_manager.hpp" #include "karts/kart_properties_manager.hpp" @@ -37,6 +33,12 @@ #include "utils/log.hpp" #include "utils/string_utils.hpp" +#include <set> +#include <string> +#include <vector> +#include <stdio.h> +#include <iostream> + UnlockManager* unlock_manager=0; //----------------------------------------------------------------------------- @@ -283,11 +285,12 @@ void UnlockManager::save() for (it = m_game_slots.begin(); it != m_game_slots.end(); it++) { std::string name = "unknown player"; - for (unsigned int i = 0; i < UserConfigParams::m_all_players.size(); i++) + for (unsigned int i = 0; i < PlayerManager::get()->getNumPlayers(); i++) { - if (UserConfigParams::m_all_players[i].getUniqueID() == it->second->getPlayerID()) + const PlayerProfile *player = PlayerManager::get()->getPlayer(i); + if (player->getUniqueID() == it->second->getPlayerID()) { - name = core::stringc(UserConfigParams::m_all_players[i].getName().c_str()).c_str(); + name = core::stringc(player->getName().c_str()).c_str(); break; } } @@ -308,25 +311,25 @@ bool UnlockManager::createSlotsIfNeeded() bool something_changed = false; // make sure all players have at least one game slot associated - PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players; - for (unsigned int n=0; n<players.size(); n++) + for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++) { bool exists = false; + const PlayerProfile *profile = PlayerManager::get()->getPlayer(n); std::map<unsigned int, GameSlot*>::iterator it; for (it = m_game_slots.begin(); it != m_game_slots.end(); it++) { GameSlot* curr_slot = it->second; - if (curr_slot->getPlayerID() == players[n].getUniqueID()) + if (curr_slot->getPlayerID() == profile->getUniqueID()) { exists = true; break; } - } + } // for it in m_game_slots if (!exists) { - GameSlot* slot = new GameSlot(players[n].getUniqueID()); + GameSlot* slot = new GameSlot(profile->getUniqueID()); for(AllChallengesType::iterator i = m_all_challenges.begin(); i!=m_all_challenges.end(); i++) { @@ -335,7 +338,7 @@ bool UnlockManager::createSlotsIfNeeded() } slot->computeActive(); - m_game_slots[players[n].getUniqueID()] = slot; + m_game_slots[profile->getUniqueID()] = slot; something_changed = true; } @@ -355,11 +358,11 @@ bool UnlockManager::deleteSlotsIfNeeded() while (it != m_game_slots.end()) { bool found = false; - const int playerAmount = UserConfigParams::m_all_players.size(); - for (int i = 0; i < playerAmount; i++) + const int player_amount = PlayerManager::get()->getNumPlayers(); + for (int i = 0; i < player_amount; i++) { if (it->second->getPlayerID() == - UserConfigParams::m_all_players[i].getUniqueID()) + PlayerManager::get()->getPlayer(i)->getUniqueID()) { found = true; break; @@ -407,10 +410,10 @@ bool UnlockManager::isSupportedVersion(const ChallengeData &challenge) PlayerProfile* UnlockManager::getCurrentPlayer() { - PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players; - for (unsigned int n=0; n<players.size(); n++) + for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++) { - if (players[n].getUniqueID() == m_current_game_slot) return players.get(n); + PlayerProfile* player = PlayerManager::get()->getPlayer(n); + if (player->getUniqueID() == m_current_game_slot) return player; } return NULL; } diff --git a/src/config/player.cpp b/src/config/player.cpp index 37c67eb7c..c83dc7656 100644 --- a/src/config/player.cpp +++ b/src/config/player.cpp @@ -79,3 +79,24 @@ void PlayerProfile::incrementUseFrequency() if (m_is_guest_account) m_use_frequency = -1; else m_use_frequency++; } // incrementUseFrequency + +//------------------------------------------------------------------------------ +/** Comparison used to sort players. Most frequent players should be + * listed first, so a<b actually means that + * a.m_use_frequency > b.m_use_frequency + * This way we get a reversed sorted list. + */ +bool PlayerProfile::operator<(const PlayerProfile &other) +{ + return getUseFrequency() > other.getUseFrequency(); +} // operator< + +// ----------------------------------------------------------------------------- +/** \brief Needed for toggling sort order **/ +bool PlayerProfile::operator>(const PlayerProfile &other) +{ + return getUseFrequency() < other.getUseFrequency(); +} // operator> + +// ----------------------------------------------------------------------------- + diff --git a/src/config/player.hpp b/src/config/player.hpp index 30f8b16f7..1ea3df21d 100644 --- a/src/config/player.hpp +++ b/src/config/player.hpp @@ -65,6 +65,9 @@ public: void save(UTFWriter &out); void incrementUseFrequency(); + bool operator<(const PlayerProfile &other); + bool operator>(const PlayerProfile &other); + ~PlayerProfile() { diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index b0cbba275..c89f7578e 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -58,8 +58,13 @@ void PlayerManager::load() { const XMLNode *player_xml = players->getNode(i); PlayerProfile *profile = new PlayerProfile(player_xml); + + if(profile->isGuestAccount()) + profile->setName(_LTR("Guest")); + m_all_players.push_back(profile); } + m_all_players.insertionSort(); } // load // ---------------------------------------------------------------------------- @@ -100,6 +105,12 @@ void PlayerManager::addNewPlayer(const core::stringw& name) m_all_players.push_back( new PlayerProfile(name) ); } // addNewPlayer +// ---------------------------------------------------------------------------- +void PlayerManager::deletePlayer(PlayerProfile *player) +{ + m_all_players.erase(player); +} // deletePlayer + // ---------------------------------------------------------------------------- void PlayerManager::addDefaultPlayer() { @@ -137,5 +148,27 @@ unsigned int PlayerManager::getUniqueId() const } // getUniqueId // ---------------------------------------------------------------------------- +const PlayerProfile *PlayerManager::getPlayerById(unsigned int id) +{ + const PlayerProfile *player; + for_in(player, m_all_players) + { + if(player->getUniqueID()==id) + return player; + } + return NULL; +} // getPlayerById + +// ---------------------------------------------------------------------------- +PlayerProfile *PlayerManager::getPlayer(const irr::core::stringw &name) +{ + PlayerProfile *player; + for_in(player, m_all_players) + { + if(player->getName()==name) + return player; + } + return NULL; +} // getPlayer // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- diff --git a/src/config/player_manager.hpp b/src/config/player_manager.hpp index 9b2d06580..03311df4e 100644 --- a/src/config/player_manager.hpp +++ b/src/config/player_manager.hpp @@ -63,12 +63,22 @@ public: unsigned int getUniqueId() const; void addDefaultPlayer(); void addNewPlayer(const irr::core::stringw& name); + void deletePlayer(PlayerProfile *player); + const PlayerProfile *getPlayerById(unsigned int id); + // ------------------------------------------------------------------------ + PlayerProfile *getPlayer(const irr::core::stringw &name); // ------------------------------------------------------------------------ /** Returns the number of players in the config file.*/ unsigned int getNumPlayers() const { return m_all_players.size(); } // ------------------------------------------------------------------------ /** Returns a player with a given unique id. */ - const PlayerProfile &getPlayer(unsigned int n) { return m_all_players[n];} + const PlayerProfile *getPlayer(unsigned int n) const + { + return &m_all_players[n]; + } // getPlayer + // ------------------------------------------------------------------------ + /** Returns a player with a given unique id. */ + PlayerProfile *getPlayer(unsigned int n) { return &m_all_players[n];} // ------------------------------------------------------------------------ }; // PlayerManager diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index 184edc59b..4e2eceb63 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -724,29 +724,9 @@ UserConfig::UserConfig() // ----------------------------------------------------------------------------- UserConfig::~UserConfig() { - UserConfigParams::m_all_players.clearAndDeleteAll(); UserConfigParams::m_saved_grand_prix_list.clearAndDeleteAll(); } // ~UserConfig -// ----------------------------------------------------------------------------- - -/** Comparison used to sort players. Most frequent players should be - * listed first, so a<b actually means that - * a.m_use_frequency > b.m_use_frequency - * This way we get a reversed sorted list. - */ -bool operator<(const PlayerProfile &a, const PlayerProfile &b) -{ - return a.getUseFrequency() > b.getUseFrequency(); -} // operator< - -// ----------------------------------------------------------------------------- -/** \brief Needed for toggling sort order **/ -bool operator>(const PlayerProfile &a, const PlayerProfile &b) -{ - return a.getUseFrequency() < b.getUseFrequency(); -} // operator> - // ----------------------------------------------------------------------------- /** Load configuration values from file. */ bool UserConfig::loadConfig() @@ -791,26 +771,6 @@ bool UserConfig::loadConfig() } - // ---- Read players - // we create those AFTER other values are being read simply because we have many Player - // nodes that all bear the same name, so the generic loading code won't work here - UserConfigParams::m_all_players.clearAndDeleteAll(); - - std::vector<XMLNode*> players; - root->getNodes("Player", players); - const int amount = players.size(); - for (int i=0; i<amount; i++) - { - //std::string name; - //players[i]->get("name", &name); - UserConfigParams::m_all_players.push_back( - new PlayerProfile(players[i]) ); - } - - // sort players by frequency of use - UserConfigParams::m_all_players.insertionSort(); - - // ---- Read Saved GP's UserConfigParams::m_saved_grand_prix_list.clearAndDeleteAll(); std::vector<XMLNode*> saved_gps; @@ -826,17 +786,6 @@ bool UserConfig::loadConfig() return true; } // loadConfig -// ---------------------------------------------------------------------------- - -void UserConfig::postLoadInit() -{ - for (unsigned int i = 0; i < UserConfigParams::m_all_players.size(); i++) - { - PlayerProfile* player = UserConfigParams::m_all_players.get(i); - if (player->isGuestAccount()) player->setName(_LTR("Guest")); - } -} - // ---------------------------------------------------------------------------- /** Write settings to config file. */ void UserConfig::saveConfig() diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 547987682..09bbbe14e 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -769,8 +769,6 @@ namespace UserConfigParams // TODO? implement blacklist for new irrlicht device and GUI PARAM_PREFIX std::vector<std::string> m_blacklist_res; - PARAM_PREFIX PtrVector<PlayerProfile> m_all_players; - /** List of all saved GPs. */ PARAM_PREFIX PtrVector<SavedGrandPrix> m_saved_grand_prix_list; @@ -825,7 +823,6 @@ public: const irr::core::stringw& getWarning() { return m_warning; } void resetWarning() { m_warning=""; } void setWarning(irr::core::stringw& warning) { m_warning=warning; } - void postLoadInit(); }; // UserConfig diff --git a/src/main.cpp b/src/main.cpp index e9baab93b..a79957acc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,10 +146,10 @@ #include "audio/music_manager.hpp" #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" -#include "config/stk_config.hpp" -#include "config/user_config.hpp" #include "config/player.hpp" #include "config/player_manager.hpp" +#include "config/stk_config.hpp" +#include "config/user_config.hpp" #include "graphics/hardware_skinning.hpp" #include "graphics/irr_driver.hpp" #include "graphics/material_manager.hpp" @@ -681,7 +681,8 @@ int handleCmdLine() if(CommandLine::has("--kart", &s)) { - unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0).getUniqueID()); + unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0) + ->getUniqueID()); if (!unlock_manager->getCurrentSlot()->isLocked(s)) { @@ -750,8 +751,8 @@ int handleCmdLine() if(CommandLine::has("--track", &s) || CommandLine::has("-t", &s)) { - unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0] - .getUniqueID() ); + unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0) + ->getUniqueID()); if (!unlock_manager->getCurrentSlot()->isLocked(s)) { race_manager->setTrack(s); @@ -898,8 +899,8 @@ int handleCmdLine() // Demo mode if(CommandLine::has("--demo-mode", &s)) { - unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0] - .getUniqueID() ); + unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0) + ->getUniqueID()); float t; StringUtils::fromString(s, t); DemoWorld::enableDemoMode(t); @@ -941,8 +942,8 @@ int handleCmdLine() CommandLine::reportInvalidParameters(); if(UserConfigParams::m_no_start_screen) - unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0] - .getUniqueID() ); + unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0) + ->getUniqueID()); if(ProfileWorld::isProfileMode()) { UserConfigParams::m_sfx = false; // Disable sound effects @@ -989,7 +990,6 @@ void initUserConfig() translations = new Translations(); // needs file_manager stk_config = new STKConfig(); // in case of --stk-config // command line parameters - user_config->postLoadInit(); if (!config_ok || PlayerManager::get()->getNumPlayers() == 0) { PlayerManager::get()->addDefaultPlayer(); @@ -1257,12 +1257,11 @@ int main(int argc, char *argv[] ) // no graphics, and no profile mode if (ProfileWorld::isNoGraphics() && !ProfileWorld::isProfileMode()) { + core::stringw name = UserConfigParams::m_default_player.toString(); + PlayerProfile *player = PlayerManager::get()->getPlayer(name); // hack to have a running game slot : - PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players; - if (UserConfigParams::m_default_player.toString().size() > 0) - for (unsigned int n=0; n<players.size(); n++) - if (players[n].getName() == UserConfigParams::m_default_player.toString()) - unlock_manager->setCurrentSlot(players[n].getUniqueID()); + if(player) + unlock_manager->setCurrentSlot(player->getUniqueID()); } else if(!UserConfigParams::m_no_start_screen) @@ -1316,7 +1315,7 @@ int main(int argc, char *argv[] ) // Create player and associate player with keyboard StateManager::get()->createActivePlayer( - UserConfigParams::m_all_players.get(0), device, NULL); + PlayerManager::get()->getPlayer(0), device, NULL); if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL) { diff --git a/src/modes/demo_world.cpp b/src/modes/demo_world.cpp index c78c1abd9..6f0fbdf10 100644 --- a/src/modes/demo_world.cpp +++ b/src/modes/demo_world.cpp @@ -18,6 +18,7 @@ #include "modes/demo_world.hpp" +#include "config/player_manager.hpp" #include "guiengine/modaldialog.hpp" #include "input/device_manager.hpp" #include "input/input_manager.hpp" @@ -140,7 +141,7 @@ bool DemoWorld::updateIdleTimeAndStartDemo(float dt) // Use keyboard 0 by default in --no-start-screen device = input_manager->getDeviceList()->getKeyboard(0); StateManager::get()->createActivePlayer( - UserConfigParams::m_all_players.get(0), device , NULL); + PlayerManager::get()->getPlayer(0), device , NULL); // ASSIGN should make sure that only input from assigned devices // is read. input_manager->getDeviceList()->setAssignMode(ASSIGN); diff --git a/src/states_screens/dialogs/enter_player_name_dialog.cpp b/src/states_screens/dialogs/enter_player_name_dialog.cpp index 341b5a3fb..1749e7a58 100644 --- a/src/states_screens/dialogs/enter_player_name_dialog.cpp +++ b/src/states_screens/dialogs/enter_player_name_dialog.cpp @@ -107,10 +107,10 @@ void EnterPlayerNameDialog::onEnterPressedInternal() if (StringUtils::notEmpty(player_name)) { // check for duplicates - const int amount = UserConfigParams::m_all_players.size(); + const int amount = PlayerManager::get()->getNumPlayers(); for (int n=0; n<amount; n++) { - if (UserConfigParams::m_all_players[n].getName() == player_name) + if (PlayerManager::get()->getPlayer(n)->getName() == player_name) { LabelWidget* label = getWidget<LabelWidget>("title"); label->setText(_("Cannot add a player with this name."), false); @@ -121,7 +121,6 @@ void EnterPlayerNameDialog::onEnterPressedInternal() // Finally, add the new player. PlayerManager::get()->addNewPlayer(player_name); - UserConfigParams::m_all_players.push_back( new PlayerProfile(player_name)); bool created = unlock_manager->createSlotsIfNeeded(); if (created) unlock_manager->save(); user_config->saveConfig(); diff --git a/src/states_screens/dialogs/player_info_dialog.cpp b/src/states_screens/dialogs/player_info_dialog.cpp index c28b3b7e1..0f08be165 100644 --- a/src/states_screens/dialogs/player_info_dialog.cpp +++ b/src/states_screens/dialogs/player_info_dialog.cpp @@ -23,6 +23,7 @@ #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" #include "config/player.hpp" +#include "config/player_manager.hpp" #include "guiengine/engine.hpp" #include "guiengine/widgets/button_widget.hpp" #include "guiengine/widgets/label_widget.hpp" @@ -228,12 +229,13 @@ GUIEngine::EventPropagation PlayerInfoDialog::processEvent(const std::string& ev // accept entered name stringw playerName = textCtrl->getText().trim(); - const int playerAmount = UserConfigParams::m_all_players.size(); - for(int n=0; n<playerAmount; n++) + const int player_amount = PlayerManager::get()->getNumPlayers(); + for(int n=0; n<player_amount; n++) { - if (UserConfigParams::m_all_players.get(n) == m_player) continue; + const PlayerProfile *player = PlayerManager::get()->getPlayer(n); + if (player == m_player) continue; - if (UserConfigParams::m_all_players[n].getName() == playerName) + if (player->getName() == playerName) { ButtonWidget* label = getWidget<ButtonWidget>("renameplayer"); label->setBadge(BAD_BADGE); diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 255f33ee0..3b9056f8f 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -16,10 +16,12 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "states_screens/kart_selection.hpp" + #include "challenges/unlock_manager.hpp" #include "config/player.hpp" +#include "config/player_manager.hpp" #include "config/user_config.hpp" -#include "kart_selection.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/engine.hpp" #include "guiengine/screen.hpp" @@ -252,10 +254,10 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, m_player_ident_spinner->m_properties[PROP_ID] = spinnerID; if (parent->m_multiplayer) { - const int playerAmount = UserConfigParams::m_all_players.size(); + const int player_amount = PlayerManager::get()->getNumPlayers(); m_player_ident_spinner->m_properties[PROP_MIN_VALUE] = "0"; m_player_ident_spinner->m_properties[PROP_MAX_VALUE] = - StringUtils::toString(playerAmount-1); + StringUtils::toString(player_amount-1); m_player_ident_spinner->m_properties[PROP_WRAP_AROUND] = "true"; } else @@ -474,10 +476,10 @@ void PlayerKartWidget::add() if (m_parent_screen->m_multiplayer) { - const int playerAmount = UserConfigParams::m_all_players.size(); - for (int n=0; n<playerAmount; n++) + const int player_amount = PlayerManager::get()->getNumPlayers(); + for (int n=0; n<player_amount; n++) { - core::stringw name = UserConfigParams::m_all_players[n].getName(); + core::stringw name = PlayerManager::get()->getPlayer(n)->getName(); m_player_ident_spinner->addLabel( translations->fribidize(name) ); } @@ -700,7 +702,7 @@ GUIEngine::EventPropagation PlayerKartWidget::transmitEvent( if (m_parent_screen->m_multiplayer) { m_associatedPlayer->setPlayerProfile( - UserConfigParams::m_all_players.get(m_player_ident_spinner + PlayerManager::get()->getPlayer(m_player_ident_spinner ->getValue()) ); } } @@ -1097,16 +1099,17 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer) kartsAreaWidget->m_y + kartsAreaWidget->m_h); // ---- Create new active player - PlayerProfile* profileToUse = unlock_manager->getCurrentPlayer(); + PlayerProfile* profile_to_use = unlock_manager->getCurrentPlayer(); if (!firstPlayer) { - const int playerProfileCount = UserConfigParams::m_all_players.size(); - for (int n=0; n<playerProfileCount; n++) + const int player_profile_count = PlayerManager::get()->getNumPlayers(); + for (int i=0; i<player_profile_count; i++) { - if (UserConfigParams::m_all_players[n].isGuestAccount()) + PlayerProfile *player = PlayerManager::get()->getPlayer(i); + if (player->isGuestAccount()) { - profileToUse = UserConfigParams::m_all_players.get(n); + profile_to_use = player; break; } } @@ -1124,7 +1127,7 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer) } const int new_player_id = - StateManager::get()->createActivePlayer( profileToUse, device, NULL ); + StateManager::get()->createActivePlayer( profile_to_use, device, NULL ); StateManager::ActivePlayer* aplayer = StateManager::get()->getActivePlayer(new_player_id); @@ -1816,9 +1819,10 @@ bool KartSelectionScreen::validateIdentChoices() // verify internal consistency in debug mode if (m_multiplayer) { - assert( m_kart_widgets[n].getAssociatedPlayer()->getProfile() == - UserConfigParams::m_all_players.get(m_kart_widgets[n] - .m_player_ident_spinner->getValue()) ); + assert(m_kart_widgets[n].getAssociatedPlayer()->getProfile() == + PlayerManager::get()->getPlayer(m_kart_widgets[n] + .m_player_ident_spinner->getValue()) + ); } } } diff --git a/src/states_screens/options_screen_players.cpp b/src/states_screens/options_screen_players.cpp index 7cc5c2cc4..f096872d6 100644 --- a/src/states_screens/options_screen_players.cpp +++ b/src/states_screens/options_screen_players.cpp @@ -19,6 +19,7 @@ #include "challenges/unlock_manager.hpp" #include "config/player.hpp" +#include "config/player_manager.hpp" #include "config/device_config.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" @@ -79,17 +80,12 @@ void OptionsScreenPlayers::init() ButtonWidget* you = getWidget<ButtonWidget>("playername"); unsigned int playerID = unlock_manager->getCurrentSlot()->getPlayerID(); - core::stringw playerName = L"-"; - PlayerProfile* curr; - for_in (curr, UserConfigParams::m_all_players) - { - if (curr->getUniqueID() == playerID) - { - playerName = curr->getName(); - break; - } - } - you->setText( playerName ); + core::stringw player_name = L"-"; + const PlayerProfile* curr = PlayerManager::get()->getPlayerById(playerID); + if(curr) + player_name = curr->getName(); + + you->setText( player_name ); ((gui::IGUIButton*)you->getIrrlichtElement())->setOverrideFont( GUIEngine::getSmallFont() ); if (StateManager::get()->getGameState() == GUIEngine::INGAME_MENU) @@ -129,7 +125,7 @@ void OptionsScreenPlayers::onNewPlayerWithName(const stringw& newName) void OptionsScreenPlayers::deletePlayer(PlayerProfile* player) { - UserConfigParams::m_all_players.erase(player); + PlayerManager::get()->deletePlayer(player); refreshPlayerList(); } // deletePlayer @@ -174,14 +170,15 @@ void OptionsScreenPlayers::eventCallback(Widget* widget, const std::string& name assert(players != NULL); core::stringw selectedPlayer = players->getSelectionLabel(); - const int playerAmount = UserConfigParams::m_all_players.size(); - for (int n=0; n<playerAmount; n++) + const int player_amount = PlayerManager::get()->getNumPlayers(); + for (int i=0; i<player_amount; i++) { - if (selectedPlayer == translations->fribidize(UserConfigParams::m_all_players[n].getName())) + PlayerProfile *player = PlayerManager::get()->getPlayer(i); + if (selectedPlayer == translations->fribidize(player->getName())) { - if (!(UserConfigParams::m_all_players[n].isGuestAccount())) + if (!(player->isGuestAccount())) { - new PlayerInfoDialog( &UserConfigParams::m_all_players[n], 0.5f, 0.6f ); + new PlayerInfoDialog( player, 0.5f, 0.6f ); } return; } @@ -217,15 +214,16 @@ bool OptionsScreenPlayers::refreshPlayerList() // Get rid of previous players->clear(); // Rebuild it - const int playerAmount = UserConfigParams::m_all_players.size(); - for (int i = 0; i < playerAmount; i++) + const int player_amount = PlayerManager::get()->getNumPlayers(); + for (int i = 0; i < player_amount; i++) { // FIXME: Using a truncated ASCII string for internal ID. Let's cross // our fingers and hope no one enters two player names that, // when stripped down to ASCII, give the same identifier... + const PlayerProfile *player = PlayerManager::get()->getPlayer(i); players->addItem( - core::stringc(UserConfigParams::m_all_players[i].getName().c_str()).c_str(), - translations->fribidize(UserConfigParams::m_all_players[i].getName())); + core::stringc(player->getName().c_str()).c_str(), + translations->fribidize(player->getName())); } return true; diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index e2ff572bb..cdc68219f 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -18,6 +18,7 @@ #include "states_screens/story_mode_lobby.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "guiengine/widgets/check_box_widget.hpp" #include "guiengine/widgets/list_widget.hpp" #include "states_screens/dialogs/enter_player_name_dialog.hpp" @@ -53,29 +54,29 @@ void StoryModeLobbyScreen::init() ListWidget* list = getWidget<ListWidget>("gameslots"); list->clear(); - PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players; + core::stringw name = UserConfigParams::m_default_player.toString(); + if (UserConfigParams::m_default_player.toString().size() > 0) { - for (unsigned int n=0; n<players.size(); n++) + PlayerProfile *player = PlayerManager::get()->getPlayer(name); + if(player) { - if (players[n].getName() == UserConfigParams::m_default_player.toString()) - { - unlock_manager->setCurrentSlot(players[n].getUniqueID()); - StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); - return; - } + unlock_manager->setCurrentSlot(player->getUniqueID()); + StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); + return; } } - for (unsigned int n=0; n<players.size(); n++) + for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++) { - if (players[n].isGuestAccount()) continue; + const PlayerProfile *player = PlayerManager::get()->getPlayer(n); + if (player->isGuestAccount()) continue; // FIXME: we're using a trunacted ascii version of the player name as // identifier, let's hope this causes no issues... - list->addItem(core::stringc(players[n].getName().c_str()).c_str(), - players[n].getName() ); + list->addItem(core::stringc(player->getName().c_str()).c_str(), + player->getName() ); } list->setFocusForPlayer(PLAYER_ID_GAME_MASTER); @@ -110,32 +111,24 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, bool slot_found = false; - PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players; - for (unsigned int n=0; n<players.size(); n++) - { - if (list->getSelectionLabel() == players[n].getName()) - { - unlock_manager->setCurrentSlot(players[n].getUniqueID()); - unlock_manager->updateActiveChallengeList(); - slot_found = true; - break; - } - } - - if (!slot_found) - { - Log::error("StoryModeLobby", - "Cannot find player corresponding to slot '%s'.", - core::stringc(list->getSelectionLabel().c_str()).c_str()); - } - else + PlayerProfile *player = PlayerManager::get() + ->getPlayer(list->getSelectionLabel()); + if(player) { + unlock_manager->setCurrentSlot(player->getUniqueID()); + unlock_manager->updateActiveChallengeList(); CheckBoxWidget* cb = getWidget<CheckBoxWidget>("rememberme"); if (cb->getState()) { UserConfigParams::m_default_player = list->getSelectionLabel(); } } + else + { + Log::error("StoryModeLobby", + "Cannot find player corresponding to slot '%s'.", + core::stringc(list->getSelectionLabel().c_str()).c_str()); + } StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); } @@ -149,27 +142,19 @@ void StoryModeLobbyScreen::unloaded() // ---------------------------------------------------------------------------- -void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& newName) +void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& new_name) { - bool slot_found = false; - - PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players; - for (unsigned int n=0; n<players.size(); n++) + PlayerProfile *player = PlayerManager::get()->getPlayer(new_name); + if(player) { - if (players[n].getName() == newName) - { - unlock_manager->setCurrentSlot(players[n].getUniqueID()); - unlock_manager->updateActiveChallengeList(); - slot_found = true; - break; - } + unlock_manager->setCurrentSlot(player->getUniqueID()); + unlock_manager->updateActiveChallengeList(); } - - if (!slot_found) + else { Log::error("StoryModeLobbyScreen", "Cannot find player corresponding to slot '%s'.", - core::stringc(newName.c_str()).c_str()); + core::stringc(new_name.c_str()).c_str()); } StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); From 97be85777d7452e4d4f13a9d014b11a88c8ec177 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Sun, 9 Feb 2014 23:22:45 +1100 Subject: [PATCH 06/68] Started to move current player info from unlock manager into player_manager. --- src/challenges/challenge.cpp | 27 ++- src/challenges/challenge.hpp | 15 +- src/challenges/game_slot.cpp | 44 ++++- src/challenges/game_slot.hpp | 58 +++--- src/challenges/unlock_manager.cpp | 67 +++---- src/challenges/unlock_manager.hpp | 11 +- src/config/player.cpp | 20 ++- src/config/player.hpp | 76 +++++++- src/config/player_manager.cpp | 66 ++++++- src/config/player_manager.hpp | 18 +- src/io/utf_writer.cpp | 1 - src/io/utf_writer.hpp | 19 +- src/karts/kart_properties_manager.cpp | 19 +- src/main.cpp | 165 ++++++++---------- src/modes/world.cpp | 18 +- src/race/grand_prix_data.cpp | 4 +- src/race/race_manager.cpp | 3 +- src/states_screens/arenas_screen.cpp | 5 +- src/states_screens/dialogs/gp_info_dialog.cpp | 3 +- .../dialogs/select_challenge.cpp | 5 +- .../dialogs/track_info_dialog.cpp | 3 +- src/states_screens/easter_egg_screen.cpp | 8 +- src/states_screens/feature_unlocked.cpp | 12 +- src/states_screens/grand_prix_lose.cpp | 10 +- src/states_screens/grand_prix_win.cpp | 10 +- src/states_screens/main_menu_screen.cpp | 7 +- src/states_screens/options_screen_players.cpp | 2 +- src/states_screens/race_gui_overworld.cpp | 14 +- src/states_screens/race_result_gui.cpp | 10 +- src/states_screens/race_setup_screen.cpp | 13 +- src/states_screens/story_mode_lobby.cpp | 10 +- src/states_screens/tracks_screen.cpp | 10 +- src/tracks/track.cpp | 34 ++-- 33 files changed, 477 insertions(+), 310 deletions(-) diff --git a/src/challenges/challenge.cpp b/src/challenges/challenge.cpp index 05ef8270a..e300496e5 100644 --- a/src/challenges/challenge.cpp +++ b/src/challenges/challenge.cpp @@ -18,9 +18,8 @@ #include "challenges/challenge.hpp" -#include <fstream> - #include "challenges/challenge_data.hpp" +#include "io/utf_writer.hpp" #include "io/xml_node.hpp" #include "karts/kart_properties_manager.hpp" #include "karts/kart_properties.hpp" @@ -89,17 +88,17 @@ void Challenge::setSolved(RaceManager::Difficulty d) //----------------------------------------------------------------------------- -void Challenge::save(std::ofstream& writer) +void Challenge::save(UTFWriter& writer) { - writer << " <" << m_data->getId().c_str() << ">\n" - << " <easy solved=\"" - << StringUtils::toString(isSolved(RaceManager::DIFFICULTY_EASY)) - << "\"/>\n" - << " <medium solved=\"" - << StringUtils::toString(isSolved(RaceManager::DIFFICULTY_MEDIUM)) - << "\"/>\n" - << " <hard solved=\"" - << StringUtils::toString(isSolved(RaceManager::DIFFICULTY_HARD)) - << "\"/>\n" - << " </" << m_data->getId().c_str() << ">\n"; + writer << L" <"<< m_data->getId() << L">\n" + << L" <easy solved=\"" + << isSolved(RaceManager::DIFFICULTY_EASY) + << L"\"/>\n" + << L" <medium solved=\"" + << isSolved(RaceManager::DIFFICULTY_MEDIUM) + << L"\"/>\n" + << L" <hard solved=\"" + << isSolved(RaceManager::DIFFICULTY_HARD) + << L"\"/>\n" + << L" </" << m_data->getId() << L">\n"; } // save diff --git a/src/challenges/challenge.hpp b/src/challenges/challenge.hpp index 7d18c8f49..e6d3fa0e5 100644 --- a/src/challenges/challenge.hpp +++ b/src/challenges/challenge.hpp @@ -34,9 +34,9 @@ #include "utils/no_copy.hpp" #include "utils/translation.hpp" -class XMLNode; -class XMLWriter; class ChallengeData; +class UTFWriter; +class XMLNode; /** * \brief The state of a challenge for one player. @@ -53,10 +53,11 @@ private: CH_SOLVED} // challenge was solved m_state[RaceManager::DIFFICULTY_COUNT]; - ChallengeData* m_data; + /** Pointer to the original challenge data. */ + const ChallengeData* m_data; public: - Challenge(ChallengeData* data) + Challenge(const ChallengeData* data) { m_data = data; m_state[RaceManager::DIFFICULTY_EASY] = CH_INACTIVE; @@ -65,7 +66,7 @@ public: } virtual ~Challenge() {}; void load(const XMLNode* config); - void save(std::ofstream& writer); + void save(UTFWriter& writer); void setSolved(RaceManager::Difficulty d); // ------------------------------------------------------------------------ @@ -98,10 +99,6 @@ public: m_state[d] = CH_ACTIVE; } // setActive // ------------------------------------------------------------------------ - /** Returns a pointer to the actual Challenge data. - */ - ChallengeData* getData() { return m_data; } - // ------------------------------------------------------------------------ /** Returns a pointer to the actual Challenge data. */ const ChallengeData* getData() const { return m_data; } diff --git a/src/challenges/game_slot.cpp b/src/challenges/game_slot.cpp index 469e05964..2b918bbb5 100644 --- a/src/challenges/game_slot.cpp +++ b/src/challenges/game_slot.cpp @@ -22,6 +22,33 @@ #include "challenges/challenge.hpp" #include "challenges/challenge_data.hpp" #include "challenges/unlock_manager.hpp" +#include "io/utf_writer.hpp" +#include "io/xml_node.hpp" + +//----------------------------------------------------------------------------- +GameSlot::GameSlot(const XMLNode *node) +{ + m_kart_ident = ""; + m_points = 0; + m_first_time = true; + m_easy_challenges = 0; + m_medium_challenges = 0; + m_hard_challenges = 0; + m_current_challenge = NULL; + + // If there is saved data, load it + if(node) + { + node->get("kart", &m_kart_ident); + node->get("first-time", &m_first_time); + + for(unsigned int i=0; i<node->getNumNodes(); i++) + { + const XMLNode *challenge = node->getNode(i); + } // for i <getNumNodes + } // if node + +} // GameSlot //----------------------------------------------------------------------------- GameSlot::~GameSlot() @@ -234,13 +261,14 @@ void GameSlot::grandPrixFinished() } // grandPrixFinished //----------------------------------------------------------------------------- - -void GameSlot::save(std::ofstream& out, const std::string& name) +/** Writes the data of this GameSlot to the specified stream. + * \param out UTF stream to write to. + */ +void GameSlot::save(UTFWriter &out) { - out << " <gameslot playerID=\"" << m_player_unique_id - << "\" kart=\"" << m_kart_ident.c_str() - << "\" firstTime=\"" << (m_first_time ? "true" : "false") - << "\"> <!-- " << name.c_str() << " -->\n"; + out << L" <game-slot playerID=\"" << m_player_unique_id + << L"\" kart=\"" << m_kart_ident + << L"\" firstTime=\"" << m_first_time << L"\">\n"; std::map<std::string, Challenge*>::const_iterator i; for(i = m_challenges_state.begin(); i != m_challenges_state.end(); i++) @@ -248,5 +276,5 @@ void GameSlot::save(std::ofstream& out, const std::string& name) if (i->second != NULL) i->second->save(out); } - out << " </gameslot>\n"; -} + out << " </game-slot>\n"; +} // save diff --git a/src/challenges/game_slot.hpp b/src/challenges/game_slot.hpp index b8319b9eb..f1ff2d09a 100644 --- a/src/challenges/game_slot.hpp +++ b/src/challenges/game_slot.hpp @@ -19,17 +19,20 @@ #ifndef GAME_SLOT_HPP #define GAME_SLOT_HPP +#include "race/race_manager.hpp" + +#include <irrString.h> +using namespace irr; #include <string> #include <map> #include <vector> -#include <irrString.h> -#include "race/race_manager.hpp" -class ChallengeData; class Challenge; -class XMLWriter; +class ChallengeData; +class UTFWriter; +class XMLNode; const int CHALLENGE_POINTS[] = { 8, 9, 10 }; @@ -63,8 +66,6 @@ class GameSlot friend class UnlockManager; - void computeActive(); - int m_points; /** Set to false after the initial stuff (intro, select kart, etc.) */ @@ -76,50 +77,35 @@ class GameSlot public: - // do NOT attempt to pass 'player_unique_id' by reference here. I don't - // know why (compiler bug maybe?) but this screws up everything. Better - // pass by copy. - GameSlot(unsigned int player_unique_id) - { - m_player_unique_id = player_unique_id; - m_points = 0; - m_first_time = true; - m_easy_challenges = 0; - m_medium_challenges = 0; - m_hard_challenges = 0; - m_current_challenge = NULL; - } + GameSlot(const XMLNode *node=NULL); ~GameSlot(); unsigned int getPlayerID() const { return m_player_unique_id; } const std::string& getKartIdent () const { return m_kart_ident; } + void computeActive(); + bool isLocked (const std::string& feature); + void lockFeature (Challenge *challenge); + void unlockFeature (Challenge* c, RaceManager::Difficulty d, + bool do_save=true); + void raceFinished (); + void grandPrixFinished (); + void save (UTFWriter &out); + void setCurrentChallenge(const std::string &challenge_id); + + // ------------------------------------------------------------------------ void setKartIdent(const std::string& kart_ident) { m_kart_ident = kart_ident; } - - + // ------------------------------------------------------------------------ /** Returns the list of recently unlocked features (e.g. call at the end * of a race to know if any features were unlocked) */ const std::vector<const ChallengeData*> getRecentlyCompletedChallenges() {return m_unlocked_features;} - + // ------------------------------------------------------------------------ /** Clear the list of recently unlocked challenges */ void clearUnlocked () {m_unlocked_features.clear(); } - - bool isLocked (const std::string& feature); - - void lockFeature (Challenge *challenge); - - void unlockFeature (Challenge* c, RaceManager::Difficulty d, - bool do_save=true); - - void raceFinished (); - void grandPrixFinished (); - - void save (std::ofstream& file, const std::string& name); - void setCurrentChallenge(const std::string &challenge_id); - + // ------------------------------------------------------------------------ /** Returns the number of points accumulated. */ int getPoints () const { return m_points; } // ------------------------------------------------------------------------ diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index 3e490ced4..f04f1ff4c 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -156,7 +156,9 @@ void UnlockManager::readAllChallengesInDirs(const std::vector<std::string>* all_ void UnlockManager::addOrFreeChallenge(ChallengeData *c) { if(isSupportedVersion(*c)) + { m_all_challenges[c->getId()]=c; + } else { Log::warn("Challenge", "Challenge '%s' is not supported - ignored.", @@ -213,7 +215,7 @@ void UnlockManager::load() { Log::info("unlock_manager", "Challenge file '%s' will be created.", filename.c_str()); - createSlotsIfNeeded(); +// createSlotsIfNeeded(); save(); if (root) delete root; @@ -232,17 +234,10 @@ void UnlockManager::load() continue; } - GameSlot* slot = new GameSlot(player_id); - - std::string kart_id; - xml_game_slots[n]->get("kart", &kart_id); - slot->setKartIdent(kart_id); + GameSlot* slot = new GameSlot(NULL); m_game_slots[player_id] = slot; - bool first_time = true; - xml_game_slots[n]->get("firstTime", &first_time); - slot->setFirstTime(first_time); for(AllChallengesType::iterator i = m_all_challenges.begin(); i!=m_all_challenges.end(); i++) @@ -256,12 +251,38 @@ void UnlockManager::load() slot->computeActive(); } - bool something_changed = createSlotsIfNeeded(); - if (something_changed) save(); + // FIXME +// bool something_changed = createSlotsIfNeeded(); +// if (something_changed) save(); delete root; } // load +//----------------------------------------------------------------------------- +/** Creates a game slot. It initialises the game slot's status with the + * information in the xml node (if given), basically restoring the saved + * states for a player. + * \param node The XML game-slots node with all data for a player. + */ +GameSlot *UnlockManager::createGameSlot(const XMLNode *node) +{ + + GameSlot *slot = new GameSlot(node); + + for(AllChallengesType::iterator i = m_all_challenges.begin(); + i!=m_all_challenges.end(); i++) + { + ChallengeData* cd = i->second; + Challenge *challenge = new Challenge(cd); + if(node) + challenge->load(node); + slot->m_challenges_state[cd->getId()] = challenge; + } + + slot->computeActive(); + return slot; +} // createGameSlot + //----------------------------------------------------------------------------- void UnlockManager::save() @@ -295,7 +316,7 @@ void UnlockManager::save() } } - it->second->save(challenge_file, name); +//FIXME it->second->save(challenge_file, name); } challenge_file << "</challenges>\n\n"; @@ -329,7 +350,7 @@ bool UnlockManager::createSlotsIfNeeded() if (!exists) { - GameSlot* slot = new GameSlot(profile->getUniqueID()); + GameSlot* slot = new GameSlot(NULL); for(AllChallengesType::iterator i = m_all_challenges.begin(); i!=m_all_challenges.end(); i++) { @@ -418,22 +439,6 @@ PlayerProfile* UnlockManager::getCurrentPlayer() return NULL; } -//----------------------------------------------------------------------------- - -void UnlockManager::updateActiveChallengeList() -{ - getCurrentSlot()->computeActive(); -} - - -//----------------------------------------------------------------------------- -void UnlockManager::setCurrentSlot(unsigned int slotid) -{ - m_current_game_slot = slotid; - AchievementsManager::get()->updateCurrentPlayer(); -} - - //----------------------------------------------------------------------------- void UnlockManager::findWhatWasUnlocked(int points_before, int points_now, @@ -449,12 +454,12 @@ void UnlockManager::findWhatWasUnlocked(int points_before, int points_now, { if (c->getMode() == ChallengeData::CM_SINGLE_RACE && c->getTrackId() != "") { - if (!getCurrentSlot()->isLocked(c->getTrackId())) + if (!PlayerManager::get()->getCurrentPlayer()->isLocked(c->getTrackId())) tracks.push_back(c->getTrackId()); } else if (c->getMode() == ChallengeData::CM_GRAND_PRIX && c->getGPId() != "") { - if (!getCurrentSlot()->isLocked(c->getGPId())) + if (!PlayerManager::get()->getCurrentPlayer()->isLocked(c->getGPId())) gps.push_back(c->getGPId()); } } diff --git a/src/challenges/unlock_manager.hpp b/src/challenges/unlock_manager.hpp index dbd630cda..ae7ab658c 100644 --- a/src/challenges/unlock_manager.hpp +++ b/src/challenges/unlock_manager.hpp @@ -75,21 +75,12 @@ public: unsigned int getCurrentSlotID() const { return m_current_game_slot; } - GameSlot* getCurrentSlot() - { - assert(m_game_slots.find(m_current_game_slot) != m_game_slots.end()); - return m_game_slots[m_current_game_slot]; - } - - /** \param slotid name of the player */ - void setCurrentSlot(unsigned int slotid); void findWhatWasUnlocked(int pointsBefore, int pointsNow, std::vector<std::string>& tracks, std::vector<std::string>& gps); PlayerProfile* getCurrentPlayer(); - - void updateActiveChallengeList(); + GameSlot *createGameSlot(const XMLNode *node=NULL); }; // UnlockManager diff --git a/src/config/player.cpp b/src/config/player.cpp index c83dc7656..08f8c31a3 100644 --- a/src/config/player.cpp +++ b/src/config/player.cpp @@ -18,6 +18,8 @@ #include "config/player.hpp" +#include "challenges/game_slot.hpp" +#include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "io/xml_node.hpp" #include "io/utf_writer.hpp" @@ -40,6 +42,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest) m_is_guest_account = is_guest; m_use_frequency = 0; m_unique_id = PlayerManager::get()->getUniqueId(); + m_game_slot = unlock_manager->createGameSlot(); } // PlayerProfile @@ -53,9 +56,13 @@ PlayerProfile::PlayerProfile(const XMLNode* node) node->get("guest", &m_is_guest_account); node->get("use-frequency", &m_use_frequency ); node->get("unique-id", &m_unique_id ); + node->get("is-default", &m_is_default ); #ifdef DEBUG m_magic_number = 0xABCD1234; #endif + const XMLNode *xml_game_slot = node->getNode("game-slot"); + m_game_slot = unlock_manager->createGameSlot(xml_game_slot); + } // PlayerProfile //------------------------------------------------------------------------------ @@ -64,11 +71,14 @@ PlayerProfile::PlayerProfile(const XMLNode* node) */ void PlayerProfile::save(UTFWriter &out) { - out << L" <player name=\"" << m_name << L"\"\n"; - out << L" guest=\"" << m_is_guest_account << L"\"\n"; - out << L" use-frequency=\""<< m_use_frequency << L"\"\n"; - out << L" unique-id=\"" << m_unique_id << L"\"\n"; - out << L" />\n"; + out << L" <player name=\"" << m_name + << L"\" guest=\"" << m_is_guest_account + << L"\" use-frequency=\"" << m_use_frequency + << L"\" is-default=\"" << m_is_default + << L"\" unique-id=\"" << m_unique_id << L"\">\n"; + assert(m_game_slot); + m_game_slot->save(out); + out << L" </player>\n"; } // save //------------------------------------------------------------------------------ diff --git a/src/config/player.hpp b/src/config/player.hpp index 1ea3df21d..38e2f24b7 100644 --- a/src/config/player.hpp +++ b/src/config/player.hpp @@ -19,6 +19,8 @@ #ifndef HEADER_PLAYER_HPP #define HEADER_PLAYER_HPP +#include "challenges/game_slot.hpp" + #include "config/user_config.hpp" #include "utils/no_copy.hpp" #include "utils/types.hpp" @@ -28,6 +30,7 @@ using namespace irr; #include <string> +class GameSlot; class UTFWriter; /** @@ -38,7 +41,7 @@ class UTFWriter; */ class PlayerProfile : public NoCopy { -protected: +private: /** The name of the player (wide string, so it can be in native * language). */ @@ -57,6 +60,12 @@ protected: /** A unique number for this player, used to link it to challenges etc. */ unsigned int m_unique_id; + /** True if this is the default (last used) player. */ + bool m_is_default; + + /** The complete challenge state. */ + GameSlot *m_game_slot; + public: PlayerProfile(const core::stringw& name, bool is_guest = false); @@ -69,6 +78,7 @@ public: bool operator>(const PlayerProfile &other); + // ------------------------------------------------------------------------ ~PlayerProfile() { #ifdef DEBUG @@ -76,6 +86,7 @@ public: #endif } + // ------------------------------------------------------------------------ void setName(const core::stringw& name) { #ifdef DEBUG @@ -84,6 +95,7 @@ public: m_name = name; } + // ------------------------------------------------------------------------ core::stringw getName() const { #ifdef DEBUG @@ -92,6 +104,7 @@ public: return m_name.c_str(); } + // ------------------------------------------------------------------------ bool isGuestAccount() const { #ifdef DEBUG @@ -100,17 +113,74 @@ public: return m_is_guest_account; } + // ------------------------------------------------------------------------ int getUseFrequency() const { if (m_is_guest_account) return -1; else return m_use_frequency; } - - // ------------------------------------------------------------------------ /** Returns the unique id of this player. */ unsigned int getUniqueID() const { return m_unique_id; } + // ------------------------------------------------------------------------ + /** Returned if the feature (kart, track) is locked. */ + bool isLocked(const std::string &feature) const + { + return m_game_slot->isLocked(feature); + } // isLocked + // ------------------------------------------------------------------------ + /** Returns all active challenges. */ + void computeActive() { m_game_slot->computeActive(); } + // ------------------------------------------------------------------------ + std::vector<const ChallengeData*> getRecentlyCompletedChallenges() + { + return m_game_slot->getRecentlyCompletedChallenges(); + } // getRecently Completed Challenges + // ------------------------------------------------------------------------ + void setCurrentChallenge(const std::string &name) + { + m_game_slot->setCurrentChallenge(name); + } // setCurrentChallenge + // ------------------------------------------------------------------------ + /** Notification of a finished race, which can trigger fulfilling + * challenges. */ + void raceFinished() { m_game_slot->raceFinished(); } + // ------------------------------------------------------------------------ + void grandPrixFinished() { m_game_slot->grandPrixFinished(); } + // ------------------------------------------------------------------------ + unsigned int getPoints() const { return m_game_slot->getPoints(); } + // ------------------------------------------------------------------------ + bool isFirstTime() const { return m_game_slot->isFirstTime(); } + // ------------------------------------------------------------------------ + void clearUnlocked() { m_game_slot->clearUnlocked(); } + // ------------------------------------------------------------------------ + const Challenge* getChallenge(const std::string &id) + { + return m_game_slot->getChallenge(id); + } // getChallenge + // ------------------------------------------------------------------------ + unsigned int getNumEasyTrophies() const + { + return m_game_slot->getNumEasyTrophies(); + } // getNumEasyTrophies + // ------------------------------------------------------------------------ + unsigned int getNumMediumTrophies() const + { + return m_game_slot->getNumMediumTrophies(); + } // getNumEasyTrophies + // ----------------------------------------------------------------------- + unsigned int getNumHardTrophies() const + { + return m_game_slot->getNumHardTrophies(); + } // getNumHardTropies + // ----------------------------------------------------------------------- + /** Returns true if this is the default (last used) player. */ + bool isDefault() const { return m_is_default; } + // ------------------------------------------------------------------------ + /** Sets if this player is the default player or not. */ + void setDefault(bool is_default) { m_is_default = is_default; } + // ------------------------------------------------------------------------ }; // class PlayerProfile diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index c89f7578e..4a6b1473c 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -18,6 +18,7 @@ #include "config/player_manager.hpp" +#include "achievements/achievements_manager.hpp" #include "config/player.hpp" #include "io/file_manager.hpp" #include "io/utf_writer.hpp" @@ -27,10 +28,29 @@ PlayerManager *PlayerManager::m_player_manager = NULL; + +/** Create the instance of the player manager. + * Also make sure that at least one player is defined (and if not, + * create a default player and a guest player). + */ +void PlayerManager::create() +{ + assert(!m_player_manager); + m_player_manager = new PlayerManager(); + if(m_player_manager->getNumPlayers() == 0) + { + m_player_manager->addDefaultPlayer(); + m_player_manager->save(); + } + +} // create + +// ============================================================================ /** Constructor. */ PlayerManager::PlayerManager() { + load(); } // PlayerManager // ---------------------------------------------------------------------------- @@ -48,23 +68,44 @@ void PlayerManager::load() std::string filename = file_manager->getUserConfigFile("players.xml"); const XMLNode *players = file_manager->createXMLTree(filename); - if(!players || players->getName()!="players") + if(!players) + { + Log::info("player_manager", "A new players.xml file will be created."); + return; + } + else if(players->getName()!="players") { Log::info("player_manager", "The players.xml file is invalid."); return; } + m_current_player = NULL; for(unsigned int i=0; i<players->getNumNodes(); i++) { const XMLNode *player_xml = players->getNode(i); - PlayerProfile *profile = new PlayerProfile(player_xml); - - if(profile->isGuestAccount()) - profile->setName(_LTR("Guest")); - - m_all_players.push_back(profile); + PlayerProfile *player = new PlayerProfile(player_xml); + m_all_players.push_back(player); + if(player->isDefault()) + m_current_player = player; } m_all_players.insertionSort(); + + if(!m_current_player) + { + PlayerProfile *player; + for_in(player, m_all_players) + { + if(!player->isGuestAccount()) + { + m_current_player = player; + player->setDefault(true); + break; + } + } + } + if(!m_current_player) + Log::fatal("PlayerManager", "Can't find a default player."); + } // load // ---------------------------------------------------------------------------- @@ -93,7 +134,6 @@ void PlayerManager::save() Log::error("PlayerManager", "Error: %s", e.what()); } - } // save // ---------------------------------------------------------------------------- @@ -171,4 +211,14 @@ PlayerProfile *PlayerManager::getPlayer(const irr::core::stringw &name) return NULL; } // getPlayer // ---------------------------------------------------------------------------- +void PlayerManager::setCurrentPlayer(PlayerProfile *player) +{ + // Reset current default player + if(m_current_player) + m_current_player->setDefault(false); + m_current_player = player; + m_current_player->setDefault(true); + AchievementsManager::get()->updateCurrentPlayer(); +} // setCurrentPlayer + // ---------------------------------------------------------------------------- diff --git a/src/config/player_manager.hpp b/src/config/player_manager.hpp index 03311df4e..ca9914f70 100644 --- a/src/config/player_manager.hpp +++ b/src/config/player_manager.hpp @@ -16,8 +16,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_PLAYER_CONFIG_HPP -#define HEADER_PLAYER_CONFIG_HPP +#ifndef HEADER_PLAYER_MANAGER_HPP +#define HEADER_PLAYER_MANAGER_HPP #include "utils/no_copy.hpp" #include "utils/ptr_vector.hpp" @@ -37,35 +37,43 @@ private: PtrVector<PlayerProfile> m_all_players; + /** A pointer to the current player. */ + PlayerProfile* m_current_player; + void load(); PlayerManager(); ~PlayerManager(); public: + static void create(); + // ------------------------------------------------------------------------ /** Static singleton get function. */ static PlayerManager* get() { - if(!m_player_manager) - m_player_manager = new PlayerManager(); + assert(m_player_manager); return m_player_manager; } // get // ------------------------------------------------------------------------ static void destroy() { + assert(m_player_manager); delete m_player_manager; m_player_manager = NULL; } // destroy // ------------------------------------------------------------------------ - void load(); void save(); unsigned int getUniqueId() const; void addDefaultPlayer(); void addNewPlayer(const irr::core::stringw& name); void deletePlayer(PlayerProfile *player); + void setCurrentPlayer(PlayerProfile *player); const PlayerProfile *getPlayerById(unsigned int id); // ------------------------------------------------------------------------ + /** Returns the current player. */ + PlayerProfile* getCurrentPlayer() { return m_current_player; } + // ------------------------------------------------------------------------ PlayerProfile *getPlayer(const irr::core::stringw &name); // ------------------------------------------------------------------------ /** Returns the number of players in the config file.*/ diff --git a/src/io/utf_writer.cpp b/src/io/utf_writer.cpp index aab7dbbc6..a4a13b1d5 100644 --- a/src/io/utf_writer.cpp +++ b/src/io/utf_writer.cpp @@ -58,7 +58,6 @@ UTFWriter& UTFWriter::operator<< (const wchar_t*txt) } // operator<< (wchar_t) // ---------------------------------------------------------------------------- - void UTFWriter::close() { m_base.close(); diff --git a/src/io/utf_writer.hpp b/src/io/utf_writer.hpp index 25d447cd0..df51af9c2 100644 --- a/src/io/utf_writer.hpp +++ b/src/io/utf_writer.hpp @@ -34,10 +34,21 @@ class UTFWriter public: UTFWriter(const char* dest); + void close(); UTFWriter& operator<< (const irr::core::stringw& txt); UTFWriter& operator<< (const wchar_t* txt); - + // ------------------------------------------------------------------------ + UTFWriter& operator<< (const char *txt) + { + return operator<<(irr::core::stringw(txt)); + } // operator<<(char*) + // ------------------------------------------------------------------------ + UTFWriter& operator<< (const std::string &txt) + { + return operator<< (irr::core::stringw(txt.c_str())); + } // operator<<(std::string) + // ------------------------------------------------------------------------ template<typename T> UTFWriter& operator<< (const T t) { @@ -45,10 +56,8 @@ public: tmp += t; (*this) << tmp; return *this; - } - - void close(); - + } // operator<< (template) + // ------------------------------------------------------------------------ bool is_open() { return m_base.is_open(); } }; diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index f6e14978a..5b07afbee 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -19,13 +19,9 @@ #include "karts/kart_properties_manager.hpp" -#include <algorithm> -#include <ctime> -#include <stdio.h> -#include <stdexcept> -#include <iostream> - #include "challenges/unlock_manager.hpp" +#include "config/player.hpp" +#include "config/player_manager.hpp" #include "config/stk_config.hpp" #include "config/user_config.hpp" #include "graphics/irr_driver.hpp" @@ -35,6 +31,12 @@ #include "utils/log.hpp" #include "utils/string_utils.hpp" +#include <algorithm> +#include <ctime> +#include <stdio.h> +#include <stdexcept> +#include <iostream> + KartPropertiesManager *kart_properties_manager=0; std::vector<std::string> KartPropertiesManager::m_kart_search_path; @@ -353,7 +355,8 @@ bool KartPropertiesManager::kartAvailable(int kartid) if ( kartid == *it) return false; } const KartProperties *kartprop = getKartById(kartid); - if(unlock_manager->getCurrentSlot()->isLocked(kartprop->getIdent())) return false; + if( PlayerManager::get()->getCurrentPlayer()->isLocked(kartprop->getIdent()) ) + return false; return true; } // kartAvailable @@ -465,7 +468,7 @@ void KartPropertiesManager::getRandomKartList(int count, const KartProperties &kp=m_karts_properties[karts_in_group[i]]; if (!used[karts_in_group[i]] && m_kart_available[karts_in_group[i]] && - !unlock_manager->getCurrentSlot()->isLocked(kp.getIdent()) ) + !PlayerManager::get()->getCurrentPlayer()->isLocked(kp.getIdent()) ) { random_kart_queue.push_back(kp.getIdent()); } diff --git a/src/main.cpp b/src/main.cpp index a79957acc..6dd58c7f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -681,10 +681,9 @@ int handleCmdLine() if(CommandLine::has("--kart", &s)) { - unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0) - ->getUniqueID()); + const PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); - if (!unlock_manager->getCurrentSlot()->isLocked(s)) + if(!player->isLocked(s)) { const KartProperties *prop = kart_properties_manager->getKart(s); @@ -751,9 +750,8 @@ int handleCmdLine() if(CommandLine::has("--track", &s) || CommandLine::has("-t", &s)) { - unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0) - ->getUniqueID()); - if (!unlock_manager->getCurrentSlot()->isLocked(s)) + const PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + if (!player->isLocked(s)) { race_manager->setTrack(s); Log::verbose("main", "You choose to start in track '%s'.", @@ -899,8 +897,6 @@ int handleCmdLine() // Demo mode if(CommandLine::has("--demo-mode", &s)) { - unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0) - ->getUniqueID()); float t; StringUtils::fromString(s, t); DemoWorld::enableDemoMode(t); @@ -941,9 +937,6 @@ int handleCmdLine() CommandLine::reportInvalidParameters(); - if(UserConfigParams::m_no_start_screen) - unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0) - ->getUniqueID()); if(ProfileWorld::isProfileMode()) { UserConfigParams::m_sfx = false; // Disable sound effects @@ -973,9 +966,8 @@ void initUserConfig() { irr_driver = new IrrDriver(); file_manager = new FileManager(); - PlayerManager::get()->load(); user_config = new UserConfig(); // needs file_manager - const bool config_ok = user_config->loadConfig(); + user_config->loadConfig(); if (UserConfigParams::m_language.toString() != "system") { #ifdef WIN32 @@ -990,11 +982,6 @@ void initUserConfig() translations = new Translations(); // needs file_manager stk_config = new STKConfig(); // in case of --stk-config // command line parameters - if (!config_ok || PlayerManager::get()->getNumPlayers() == 0) - { - PlayerManager::get()->addDefaultPlayer(); - PlayerManager::get()->save(); - } } // initUserConfig @@ -1026,7 +1013,6 @@ void initRest() Online::RequestManager::get()->startNetworkThread(); NewsManager::get(); // this will create the news manager - AchievementsManager::get()->init(); music_manager = new MusicManager(); sfx_manager = new SFXManager(); // The order here can be important, e.g. KartPropertiesManager needs @@ -1069,61 +1055,6 @@ void initRest() } // initRest -//============================================================================= -/** Frees all manager and their associated memory. - */ -static void cleanSuperTuxKart() -{ - - delete main_loop; - - irr_driver->updateConfigIfRelevant(); - - if(Online::RequestManager::isRunning()) - Online::RequestManager::get()->stopNetworkThread(); - - //delete in reverse order of what they were created in. - //see InitTuxkart() - Online::RequestManager::deallocate(); - Online::ServersManager::deallocate(); - Online::ProfileManager::deallocate(); - AchievementsManager::deallocate(); - Online::CurrentUser::deallocate(); - GUIEngine::DialogQueue::deallocate(); - - Referee::cleanup(); - if(ReplayPlay::get()) ReplayPlay::destroy(); - if(race_manager) delete race_manager; - NewsManager::deallocate(); - if(addons_manager) delete addons_manager; - NetworkManager::kill(); - - if(grand_prix_manager) delete grand_prix_manager; - if(highscore_manager) delete highscore_manager; - if(attachment_manager) delete attachment_manager; - ItemManager::removeTextures(); - if(powerup_manager) delete powerup_manager; - if(projectile_manager) delete projectile_manager; - if(kart_properties_manager) delete kart_properties_manager; - if(track_manager) delete track_manager; - if(material_manager) delete material_manager; - if(history) delete history; - ReplayRecorder::destroy(); - if(sfx_manager) delete sfx_manager; - if(music_manager) delete music_manager; - delete ParticleKindManager::get(); - if(stk_config) delete stk_config; - if(user_config) delete user_config; - PlayerManager::destroy(); - if(unlock_manager) delete unlock_manager; - if(translations) delete translations; - if(file_manager) delete file_manager; - if(irr_driver) delete irr_driver; - - StateManager::deallocate(); - GUIEngine::EventHandler::deallocate(); -} // cleanSuperTuxKart - //============================================================================= #ifdef BREAKPAD bool ShowDumpResults(const wchar_t* dump_path, @@ -1191,10 +1122,19 @@ int main(int argc, char *argv[] ) "options_video.png")); kart_properties_manager -> loadAllKarts (); handleXmasMode(); - unlock_manager = new UnlockManager(); + + // Needs the kart and track directories to load potential challenges + // in those dirs. + unlock_manager = new UnlockManager(); + // Needs the unlock manager to initialise the game slots of all players + PlayerManager::create(); + + // Needs the player manager + AchievementsManager::get()->init(); + GUIEngine::addLoadingIcon( irr_driver->getTexture(FileManager::GUI, "gui_lock.png" ) ); - projectile_manager -> loadData (); + projectile_manager->loadData(); // Both item_manager and powerup_manager load models and therefore // textures from the model directory. To avoid reading the @@ -1220,7 +1160,7 @@ int main(int argc, char *argv[] ) file_manager->popTextureSearchPath(); - attachment_manager -> loadModels (); + attachment_manager->loadModels(); GUIEngine::addLoadingIcon( irr_driver->getTexture(FileManager::GUI, "banana.png") ); @@ -1253,17 +1193,6 @@ int main(int argc, char *argv[] ) addons_manager->initAddons(xml); } } - - // no graphics, and no profile mode - if (ProfileWorld::isNoGraphics() && !ProfileWorld::isProfileMode()) - { - core::stringw name = UserConfigParams::m_default_player.toString(); - PlayerProfile *player = PlayerManager::get()->getPlayer(name); - // hack to have a running game slot : - if(player) - unlock_manager->setCurrentSlot(player->getUniqueID()); - - } else if(!UserConfigParams::m_no_start_screen) { StateManager::get()->pushScreen(StoryModeLobbyScreen::getInstance()); @@ -1436,10 +1365,68 @@ int main(int argc, char *argv[] ) return 0 ; } // main +// ============================================================================ #ifdef WIN32 //routine for running under windows -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + LPTSTR lpCmdLine, int nCmdShow) { return main(__argc, __argv); } #endif + +//============================================================================= +/** Frees all manager and their associated memory. + */ +static void cleanSuperTuxKart() +{ + + delete main_loop; + + irr_driver->updateConfigIfRelevant(); + + if(Online::RequestManager::isRunning()) + Online::RequestManager::get()->stopNetworkThread(); + + //delete in reverse order of what they were created in. + //see InitTuxkart() + Online::RequestManager::deallocate(); + Online::ServersManager::deallocate(); + Online::ProfileManager::deallocate(); + AchievementsManager::deallocate(); + Online::CurrentUser::deallocate(); + GUIEngine::DialogQueue::deallocate(); + + Referee::cleanup(); + if(ReplayPlay::get()) ReplayPlay::destroy(); + if(race_manager) delete race_manager; + NewsManager::deallocate(); + if(addons_manager) delete addons_manager; + NetworkManager::kill(); + + if(grand_prix_manager) delete grand_prix_manager; + if(highscore_manager) delete highscore_manager; + if(attachment_manager) delete attachment_manager; + ItemManager::removeTextures(); + if(powerup_manager) delete powerup_manager; + if(projectile_manager) delete projectile_manager; + if(kart_properties_manager) delete kart_properties_manager; + if(track_manager) delete track_manager; + if(material_manager) delete material_manager; + if(history) delete history; + ReplayRecorder::destroy(); + if(sfx_manager) delete sfx_manager; + if(music_manager) delete music_manager; + delete ParticleKindManager::get(); + if(stk_config) delete stk_config; + if(user_config) delete user_config; + PlayerManager::destroy(); + if(unlock_manager) delete unlock_manager; + if(translations) delete translations; + if(file_manager) delete file_manager; + if(irr_driver) delete irr_driver; + + StateManager::deallocate(); + GUIEngine::EventHandler::deallocate(); +} // cleanSuperTuxKart + diff --git a/src/modes/world.cpp b/src/modes/world.cpp index ae98fbb16..b3a18c07b 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -18,16 +18,11 @@ #include "modes/world.hpp" -#include <assert.h> -#include <sstream> -#include <stdexcept> -#include <algorithm> -#include <ctime> - #include "achievements/achievements_manager.hpp" #include "audio/music_manager.hpp" #include "audio/sfx_base.hpp" #include "audio/sfx_manager.hpp" +#include "config/player_manager.hpp" #include "challenges/unlock_manager.hpp" #include "config/user_config.hpp" #include "graphics/camera.hpp" @@ -65,6 +60,13 @@ #include "utils/translation.hpp" #include "utils/string_utils.hpp" +#include <algorithm> +#include <assert.h> +#include <ctime> +#include <sstream> +#include <stdexcept> + + World* World::m_world = NULL; /** The main world class is used to handle the track and the karts. @@ -441,10 +443,10 @@ void World::terminateRace() { updateHighscores(&best_highscore_rank, &best_finish_time, &highscore_who, &best_player); - unlock_manager->getCurrentSlot()->raceFinished(); + PlayerManager::get()->getCurrentPlayer()->raceFinished(); } - unlock_manager->getCurrentSlot()->raceFinished(); + PlayerManager::get()->getCurrentPlayer()->raceFinished(); ((MapAchievement *) AchievementsManager::get()->getActive()->getAchievement(1))->increase(getTrack()->getIdent(), 1); AchievementsManager::get()->onRaceEnd(); diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index c76ca676c..21ccd8824 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -19,7 +19,9 @@ #include "race/grand_prix_data.hpp" +#include "config/player.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "io/file_manager.hpp" #include "tracks/track_manager.hpp" #include "tracks/track.hpp" @@ -157,7 +159,7 @@ bool GrandPrixData::checkConsistency(bool chatty) const bool GrandPrixData::isTrackAvailable(const std::string &id) const { return id!="fortmagma" || - !unlock_manager->getCurrentSlot()->isLocked("fortmagma"); + !PlayerManager::get()->getCurrentPlayer()->isLocked("fortmagma"); } // isTrackAvailable // ---------------------------------------------------------------------------- diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index 6405771b5..2355d02f2 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -22,6 +22,7 @@ #include <algorithm> #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "config/saved_grand_prix.hpp" #include "config/stk_config.hpp" #include "config/user_config.hpp" @@ -630,7 +631,7 @@ void RaceManager::exitRace(bool delete_world) // were finished, and not when a race is aborted. if (m_major_mode==MAJOR_MODE_GRAND_PRIX && m_track_number==(int)m_tracks.size()) { - unlock_manager->getCurrentSlot()->grandPrixFinished(); + PlayerManager::get()->getCurrentPlayer()->grandPrixFinished(); if(m_major_mode==MAJOR_MODE_GRAND_PRIX&& !NetworkWorld::getInstance()->isRunning()) { //Delete saved GP diff --git a/src/states_screens/arenas_screen.cpp b/src/states_screens/arenas_screen.cpp index 8d0cb6f2c..a42931009 100644 --- a/src/states_screens/arenas_screen.cpp +++ b/src/states_screens/arenas_screen.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/widget.hpp" #include "guiengine/widgets/dynamic_ribbon_widget.hpp" @@ -234,7 +235,7 @@ void ArenasScreen::buildTrackList() if(!curr->isArena()) continue; } - if (unlock_manager->getCurrentSlot()->isLocked(curr->getIdent())) + if (PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) { w->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE ); @@ -264,7 +265,7 @@ void ArenasScreen::buildTrackList() if(!curr->isArena()) continue; } - if (unlock_manager->getCurrentSlot()->isLocked(curr->getIdent())) + if (PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) { w->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE ); diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index 82c406802..73b0f8475 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -19,6 +19,7 @@ #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "config/saved_grand_prix.hpp" #include "guiengine/engine.hpp" #include "guiengine/screen.hpp" @@ -219,7 +220,7 @@ void GPInfoDialog::onEnterPressedInternal() std::string gp_id = m_gp_ident; ModalDialog::dismiss(); // Disable accidentally unlocking of a challenge - unlock_manager->getCurrentSlot()->setCurrentChallenge(""); + PlayerManager::get()->getCurrentPlayer()->setCurrentChallenge(""); race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, false); } diff --git a/src/states_screens/dialogs/select_challenge.cpp b/src/states_screens/dialogs/select_challenge.cpp index 70710101f..6cd18ad07 100644 --- a/src/states_screens/dialogs/select_challenge.cpp +++ b/src/states_screens/dialogs/select_challenge.cpp @@ -16,6 +16,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "config/user_config.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/engine.hpp" @@ -92,7 +93,7 @@ SelectChallengeDialog::SelectChallengeDialog(const float percentWidth, break; } - const Challenge* c = unlock_manager->getCurrentSlot()->getChallenge(challenge_id); + const Challenge* c = PlayerManager::get()->getCurrentPlayer()->getChallenge(challenge_id); if (c->isSolved(RaceManager::DIFFICULTY_EASY)) { @@ -169,7 +170,7 @@ GUIEngine::EventPropagation SelectChallengeDialog::processEvent(const std::strin return GUIEngine::EVENT_LET; } - unlock_manager->getCurrentSlot()->setCurrentChallenge(m_challenge_id); + PlayerManager::get()->getCurrentPlayer()->setCurrentChallenge(m_challenge_id); ModalDialog::dismiss(); diff --git a/src/states_screens/dialogs/track_info_dialog.cpp b/src/states_screens/dialogs/track_info_dialog.cpp index da9ab9815..a74f1cb23 100644 --- a/src/states_screens/dialogs/track_info_dialog.cpp +++ b/src/states_screens/dialogs/track_info_dialog.cpp @@ -18,6 +18,7 @@ #include "states_screens/dialogs/track_info_dialog.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/engine.hpp" #include "guiengine/screen.hpp" @@ -250,7 +251,7 @@ void TrackInfoDialog::onEnterPressedInternal() race_manager->setReverseTrack(reverse_track); std::string track_ident = m_track_ident; // Disable accidentally unlocking of a challenge - unlock_manager->getCurrentSlot()->setCurrentChallenge(""); + PlayerManager::get()->getCurrentPlayer()->setCurrentChallenge(""); ModalDialog::dismiss(); race_manager->startSingleRace(track_ident, num_laps, false); diff --git a/src/states_screens/easter_egg_screen.cpp b/src/states_screens/easter_egg_screen.cpp index b107fe5bf..c58534520 100644 --- a/src/states_screens/easter_egg_screen.cpp +++ b/src/states_screens/easter_egg_screen.cpp @@ -15,14 +15,16 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "states_screens/easter_egg_screen.hpp" + #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/widget.hpp" #include "guiengine/widgets/dynamic_ribbon_widget.hpp" #include "guiengine/widgets/icon_button_widget.hpp" #include "io/file_manager.hpp" #include "states_screens/state_manager.hpp" -#include "states_screens/easter_egg_screen.hpp" #include "states_screens/dialogs/track_info_dialog.hpp" #include "tracks/track.hpp" #include "tracks/track_manager.hpp" @@ -233,7 +235,7 @@ void EasterEggScreen::buildTrackList() if (curr->isArena() || curr->isSoccer()) continue; if (curr->isInternal()) continue; - if (unlock_manager->getCurrentSlot()->isLocked(curr->getIdent())) + if (PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) { tracks_widget->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE, @@ -264,7 +266,7 @@ void EasterEggScreen::buildTrackList() if (curr->isSoccer()) continue; if (curr->isInternal()) continue; - if (unlock_manager->getCurrentSlot()->isLocked(curr->getIdent())) + if (PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) { tracks_widget->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE, diff --git a/src/states_screens/feature_unlocked.cpp b/src/states_screens/feature_unlocked.cpp index 988840ec0..bdeb22146 100644 --- a/src/states_screens/feature_unlocked.cpp +++ b/src/states_screens/feature_unlocked.cpp @@ -24,6 +24,7 @@ #include "challenges/challenge_data.hpp" #include "challenges/game_slot.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" #include "io/file_manager.hpp" @@ -144,14 +145,15 @@ void FeatureUnlockedCutScene::loadedFromFile() void FeatureUnlockedCutScene::findWhatWasUnlocked(RaceManager::Difficulty difficulty) { - int pointsBefore = unlock_manager->getCurrentSlot()->getPoints(); - int pointsNow = pointsBefore + CHALLENGE_POINTS[difficulty]; + PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + int points_before = player->getPoints(); + int points_now = points_before + CHALLENGE_POINTS[difficulty]; std::vector<std::string> tracks; std::vector<std::string> gps; - unlock_manager->updateActiveChallengeList(); - unlock_manager->findWhatWasUnlocked(pointsBefore, pointsNow, tracks, gps); + player->computeActive(); + unlock_manager->findWhatWasUnlocked(points_before, points_now, tracks, gps); for (unsigned int i = 0; i < tracks.size(); i++) { @@ -409,7 +411,7 @@ void FeatureUnlockedCutScene::tearDown() m_all_kart_models.clearAndDeleteAll(); // update point count and the list of locked/unlocked stuff - unlock_manager->updateActiveChallengeList(); + PlayerManager::get()->getCurrentPlayer()->computeActive(); } // tearDown // ---------------------------------------------------------------------------- diff --git a/src/states_screens/grand_prix_lose.cpp b/src/states_screens/grand_prix_lose.cpp index 6dd6ba284..9d74d95c1 100644 --- a/src/states_screens/grand_prix_lose.cpp +++ b/src/states_screens/grand_prix_lose.cpp @@ -22,6 +22,7 @@ #include "audio/music_manager.hpp" #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" @@ -276,20 +277,19 @@ void GrandPrixLose::eventCallback(GUIEngine::Widget* widget, // un-set the GP mode so that after unlocking, it doesn't try to continue the GP race_manager->setMajorMode (RaceManager::MAJOR_MODE_SINGLE); - if (unlock_manager->getCurrentSlot()->getRecentlyCompletedChallenges().size() > 0) + std::vector<const ChallengeData*> unlocked = + PlayerManager::get()->getCurrentPlayer()->getRecentlyCompletedChallenges(); + if (unlocked.size() > 0) { - std::vector<const ChallengeData*> unlocked = - unlock_manager->getCurrentSlot()->getRecentlyCompletedChallenges(); - unlock_manager->getCurrentSlot()->clearUnlocked(); FeatureUnlockedCutScene* scene = FeatureUnlockedCutScene::getInstance(); - assert(unlocked.size() > 0); scene->addTrophy(race_manager->getDifficulty()); scene->findWhatWasUnlocked(race_manager->getDifficulty()); StateManager::get()->replaceTopMostScreen(scene); + PlayerManager::get()->getCurrentPlayer()->clearUnlocked(); } else { diff --git a/src/states_screens/grand_prix_win.cpp b/src/states_screens/grand_prix_win.cpp index 99c7f09d9..ca40a0f3b 100644 --- a/src/states_screens/grand_prix_win.cpp +++ b/src/states_screens/grand_prix_win.cpp @@ -24,6 +24,7 @@ #include "audio/music_manager.hpp" #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" @@ -97,7 +98,7 @@ void GrandPrixWin::loadedFromFile() void GrandPrixWin::init() { Screen::init(); - if (unlock_manager->getCurrentSlot()->getRecentlyCompletedChallenges().size() > 0) + if (PlayerManager::get()->getCurrentPlayer()->getRecentlyCompletedChallenges().size() > 0) { const core::dimension2d<u32>& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize(); @@ -405,11 +406,12 @@ void GrandPrixWin::eventCallback(GUIEngine::Widget* widget, // un-set the GP mode so that after unlocking, it doesn't try to continue the GP race_manager->setMajorMode (RaceManager::MAJOR_MODE_SINGLE); - if (unlock_manager->getCurrentSlot()->getRecentlyCompletedChallenges().size() > 0) + if (PlayerManager::get()->getCurrentPlayer() + ->getRecentlyCompletedChallenges().size() > 0) { std::vector<const ChallengeData*> unlocked = - unlock_manager->getCurrentSlot()->getRecentlyCompletedChallenges(); - unlock_manager->getCurrentSlot()->clearUnlocked(); + PlayerManager::get()->getCurrentPlayer()->getRecentlyCompletedChallenges(); + PlayerManager::get()->getCurrentPlayer()->clearUnlocked(); FeatureUnlockedCutScene* scene = FeatureUnlockedCutScene::getInstance(); diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 7ded0250f..c4c8c4158 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -23,6 +23,7 @@ #include "challenges/game_slot.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/scalable_font.hpp" #include "guiengine/widgets/label_widget.hpp" @@ -362,8 +363,8 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, } else if (selection == "story") { - GameSlot* slot = unlock_manager->getCurrentSlot(); - if (slot->isFirstTime()) + PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + if (player->isFirstTime()) { StateManager::get()->enterGameState(); race_manager->setMinorMode(RaceManager::MINOR_MODE_CUTSCENE); @@ -382,7 +383,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, else { const std::string default_kart = UserConfigParams::m_default_kart; - if (slot->isLocked(default_kart)) + if (player->isLocked(default_kart)) { KartSelectionScreen *next = OfflineKartSelectionScreen::getInstance(); next->setGoToOverworldNext(); diff --git a/src/states_screens/options_screen_players.cpp b/src/states_screens/options_screen_players.cpp index f096872d6..945916eba 100644 --- a/src/states_screens/options_screen_players.cpp +++ b/src/states_screens/options_screen_players.cpp @@ -79,7 +79,7 @@ void OptionsScreenPlayers::init() refreshPlayerList(); ButtonWidget* you = getWidget<ButtonWidget>("playername"); - unsigned int playerID = unlock_manager->getCurrentSlot()->getPlayerID(); + unsigned int playerID = PlayerManager::get()->getCurrentPlayer()->getUniqueID(); core::stringw player_name = L"-"; const PlayerProfile* curr = PlayerManager::get()->getPlayerById(playerID); if(curr) diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index 6c4fda878..88c85b8d7 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -24,6 +24,7 @@ using namespace irr; #include <algorithm> #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "config/user_config.hpp" #include "graphics/camera.hpp" #include "graphics/glwrap.hpp" @@ -206,8 +207,8 @@ void RaceGUIOverworld::renderPlayerView(const Camera *camera, float dt) */ void RaceGUIOverworld::drawTrophyPoints() { - GameSlot* slot = unlock_manager->getCurrentSlot(); - const int points = slot->getPoints(); + PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + const int points = player->getPoints(); std::string s = StringUtils::toString(points); core::stringw sw(s.c_str()); @@ -238,7 +239,7 @@ void RaceGUIOverworld::drawTrophyPoints() } dest += core::position2di((int)(size*1.5f), 0); - std::string easyTrophies = StringUtils::toString(slot->getNumEasyTrophies()); + std::string easyTrophies = StringUtils::toString(player->getNumEasyTrophies()); core::stringw easyTrophiesW(easyTrophies.c_str()); if (!m_close_to_a_challenge) { @@ -253,7 +254,7 @@ void RaceGUIOverworld::drawTrophyPoints() } dest += core::position2di((int)(size*1.5f), 0); - std::string mediumTrophies = StringUtils::toString(slot->getNumMediumTrophies()); + std::string mediumTrophies = StringUtils::toString(player->getNumMediumTrophies()); core::stringw mediumTrophiesW(mediumTrophies.c_str()); if (!m_close_to_a_challenge) { @@ -267,7 +268,7 @@ void RaceGUIOverworld::drawTrophyPoints() NULL, true /* alpha */); } dest += core::position2di((int)(size*1.5f), 0); - std::string hardTrophies = StringUtils::toString(slot->getNumHardTrophies()); + std::string hardTrophies = StringUtils::toString(player->getNumHardTrophies()); core::stringw hardTrophiesW(hardTrophies.c_str()); if (!m_close_to_a_challenge) { @@ -397,7 +398,8 @@ void RaceGUIOverworld::drawGlobalMiniMap() // bool locked = (m_locked_challenges.find(c) != m_locked_challenges.end()); int state = (challenges[n].getForceField().m_is_locked ? LOCKED : OPEN); - const Challenge* c = unlock_manager->getCurrentSlot()->getChallenge(challenges[n].m_challenge_id); + const Challenge* c = PlayerManager::get()->getCurrentPlayer() + ->getChallenge(challenges[n].m_challenge_id); if (c->isSolved(RaceManager::DIFFICULTY_HARD)) state = COMPLETED_HARD; else if (c->isSolved(RaceManager::DIFFICULTY_MEDIUM)) state = COMPLETED_MEDIUM; else if (c->isSolved(RaceManager::DIFFICULTY_EASY)) state = COMPLETED_EASY; diff --git a/src/states_screens/race_result_gui.cpp b/src/states_screens/race_result_gui.cpp index f0306bff2..814c3267a 100644 --- a/src/states_screens/race_result_gui.cpp +++ b/src/states_screens/race_result_gui.cpp @@ -21,6 +21,7 @@ #include "audio/music_manager.hpp" #include "audio/sfx_base.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "graphics/glwrap.hpp" #include "graphics/material.hpp" #include "guiengine/engine.hpp" @@ -130,7 +131,7 @@ void RaceResultGUI::enableAllButtons() // If something was unlocked // ------------------------- - int n = unlock_manager->getCurrentSlot()->getRecentlyCompletedChallenges().size(); + int n = PlayerManager::get()->getCurrentPlayer()->getRecentlyCompletedChallenges().size(); if(n>0) { top->setText(n==1 ? _("You completed a challenge!") @@ -185,7 +186,8 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget, // If something was unlocked, the 'continue' button was // actually used to display "Show unlocked feature(s)" text. // --------------------------------------------------------- - int n = unlock_manager->getCurrentSlot()->getRecentlyCompletedChallenges().size(); + int n = PlayerManager::get()->getCurrentPlayer() + ->getRecentlyCompletedChallenges().size(); if(n>0) { if(name=="top") @@ -196,7 +198,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget, } std::vector<const ChallengeData*> unlocked = - unlock_manager->getCurrentSlot()->getRecentlyCompletedChallenges(); + PlayerManager::get()->getCurrentPlayer()->getRecentlyCompletedChallenges(); bool gameCompleted = false; for (unsigned int n = 0; n < unlocked.size(); n++) @@ -208,7 +210,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget, } } - unlock_manager->getCurrentSlot()->clearUnlocked(); + PlayerManager::get()->getCurrentPlayer()->clearUnlocked(); if (gameCompleted) { diff --git a/src/states_screens/race_setup_screen.cpp b/src/states_screens/race_setup_screen.cpp index a0add043a..8fbcb282d 100644 --- a/src/states_screens/race_setup_screen.cpp +++ b/src/states_screens/race_setup_screen.cpp @@ -15,7 +15,10 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "states_screens/race_setup_screen.hpp" + #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "guiengine/widgets/dynamic_ribbon_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp" #include "guiengine/widgets/spinner_widget.hpp" @@ -29,8 +32,6 @@ #include "states_screens/tracks_screen.hpp" #include "utils/translation.hpp" -#include "states_screens/race_setup_screen.hpp" - #define ENABLE_SOCCER_MODE const int CONFIG_CODE_NORMAL = 0; @@ -178,7 +179,7 @@ void RaceSetupScreen::assignDifficulty() } else if (difficultySelection == "best") { - if (unlock_manager->getCurrentSlot()->isLocked("difficulty_best")) + if (PlayerManager::get()->getCurrentPlayer()->isLocked("difficulty_best")) { unlock_manager->playLockSound(); UserConfigParams::m_difficulty = RaceManager::DIFFICULTY_HARD; @@ -229,7 +230,7 @@ void RaceSetupScreen::init() assert( w != NULL ); if (UserConfigParams::m_difficulty == RaceManager::DIFFICULTY_BEST && - unlock_manager->getCurrentSlot()->isLocked("difficulty_best")) + PlayerManager::get()->getCurrentPlayer()->isLocked("difficulty_best")) { w->setSelection(RaceManager::DIFFICULTY_HARD, PLAYER_ID_GAME_MASTER); } @@ -267,7 +268,7 @@ void RaceSetupScreen::init() name2 += _("Contains no powerups, so only your driving skills matter!"); w2->addItem( name2, IDENT_TTRIAL, RaceManager::getIconOf(RaceManager::MINOR_MODE_TIME_TRIAL)); - if (unlock_manager->getCurrentSlot()->isLocked(IDENT_FTL)) + if (PlayerManager::get()->getCurrentPlayer()->isLocked(IDENT_FTL)) { w2->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", RaceManager::getIconOf(RaceManager::MINOR_MODE_FOLLOW_LEADER), true); @@ -343,7 +344,7 @@ void RaceSetupScreen::init() w2->registerHoverListener(m_mode_listener); - if (unlock_manager->getCurrentSlot()->isLocked("difficulty_best")) + if (PlayerManager::get()->getCurrentPlayer()->isLocked("difficulty_best")) { RibbonWidget* w = getWidget<RibbonWidget>("difficulty"); assert(w != NULL); diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index cdc68219f..131fe0644 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -62,7 +62,7 @@ void StoryModeLobbyScreen::init() PlayerProfile *player = PlayerManager::get()->getPlayer(name); if(player) { - unlock_manager->setCurrentSlot(player->getUniqueID()); + PlayerManager::get()->setCurrentPlayer(player); StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); return; } @@ -115,8 +115,8 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, ->getPlayer(list->getSelectionLabel()); if(player) { - unlock_manager->setCurrentSlot(player->getUniqueID()); - unlock_manager->updateActiveChallengeList(); + PlayerManager::get()->setCurrentPlayer(player); + player->computeActive(); CheckBoxWidget* cb = getWidget<CheckBoxWidget>("rememberme"); if (cb->getState()) { @@ -147,8 +147,8 @@ void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& new_name) PlayerProfile *player = PlayerManager::get()->getPlayer(new_name); if(player) { - unlock_manager->setCurrentSlot(player->getUniqueID()); - unlock_manager->updateActiveChallengeList(); + PlayerManager::get()->setCurrentPlayer(player); + player->computeActive(); } else { diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index 1eca14476..f03e85ce7 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -15,7 +15,10 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "states_screens/tracks_screen.hpp" + #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/widget.hpp" #include "guiengine/widgets/dynamic_ribbon_widget.hpp" @@ -24,7 +27,6 @@ #include "race/grand_prix_data.hpp" #include "race/grand_prix_manager.hpp" #include "states_screens/state_manager.hpp" -#include "states_screens/tracks_screen.hpp" #include "states_screens/dialogs/gp_info_dialog.hpp" #include "states_screens/dialogs/track_info_dialog.hpp" #include "tracks/track.hpp" @@ -235,7 +237,7 @@ void TracksScreen::init() sshot_files.push_back("gui/main_help.png"); } - if (unlock_manager->getCurrentSlot()->isLocked(gp->getId())) + if (PlayerManager::get()->getCurrentPlayer()->isLocked(gp->getId())) { gps_widget->addAnimatedItem(_("Locked!"), "locked", sshot_files, 1.5f, LOCKED_BADGE | TROPHY_BADGE, @@ -300,7 +302,7 @@ void TracksScreen::buildTrackList() if (curr->isArena() || curr->isSoccer()) continue; if (curr->isInternal()) continue; - if (unlock_manager->getCurrentSlot()->isLocked(curr->getIdent())) + if(PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) { tracks_widget->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE, @@ -331,7 +333,7 @@ void TracksScreen::buildTrackList() if (curr->isSoccer()) continue; if (curr->isInternal()) continue; - if (unlock_manager->getCurrentSlot()->isLocked(curr->getIdent())) + if (PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) { tracks_widget->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE, diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 1d893051f..0ee428a24 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -19,17 +19,11 @@ #include "tracks/track.hpp" -#include <iostream> -#include <stdexcept> -#include <sstream> -#include <IBillboardTextSceneNode.h> - -using namespace irr; - #include "addons/addon.hpp" #include "audio/music_manager.hpp" #include "challenges/challenge.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "config/stk_config.hpp" #include "config/user_config.hpp" #include "graphics/camera.hpp" @@ -68,11 +62,19 @@ using namespace irr; #include "utils/string_utils.hpp" #include "utils/translation.hpp" -#include <ISceneManager.h> -#include <IMeshSceneNode.h> -#include <IMeshManipulator.h> +#include <IBillboardTextSceneNode.h> #include <ILightSceneNode.h> #include <IMeshCache.h> +#include <IMeshManipulator.h> +#include <IMeshSceneNode.h> +#include <ISceneManager.h> + +#include <iostream> +#include <stdexcept> +#include <sstream> + +using namespace irr; + const float Track::NOHIT = -99999.9f; @@ -931,8 +933,8 @@ bool Track::loadMainTrack(const XMLNode &root) continue; } - const int val = challenge->getNumTrophies(); - bool shown = (unlock_manager->getCurrentSlot()->getPoints() < val); + const unsigned int val = challenge->getNumTrophies(); + bool shown = (PlayerManager::get()->getCurrentPlayer()->getPoints() < val); m_force_fields.push_back(OverworldForceField(xyz, shown, val)); m_challenges[closest_challenge_id].setForceField( @@ -962,7 +964,7 @@ bool Track::loadMainTrack(const XMLNode &root) else if (condition == "allchallenges") { unsigned int unlocked_challenges = 0; - GameSlot* slot = unlock_manager->getCurrentSlot(); + PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); for (unsigned int c=0; c<m_challenges.size(); c++) { if (m_challenges[c].m_challenge_id == "tutorial") @@ -970,7 +972,7 @@ bool Track::loadMainTrack(const XMLNode &root) unlocked_challenges++; continue; } - if (slot->getChallenge(m_challenges[c].m_challenge_id) + if (player->getChallenge(m_challenges[c].m_challenge_id) ->isSolvedAtAnyDifficulty()) { unlocked_challenges++; @@ -994,7 +996,7 @@ bool Track::loadMainTrack(const XMLNode &root) else if (neg_condition == "allchallenges") { unsigned int unlocked_challenges = 0; - GameSlot* slot = unlock_manager->getCurrentSlot(); + PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); for (unsigned int c=0; c<m_challenges.size(); c++) { if (m_challenges[c].m_challenge_id == "tutorial") @@ -1002,7 +1004,7 @@ bool Track::loadMainTrack(const XMLNode &root) unlocked_challenges++; continue; } - if (slot->getChallenge(m_challenges[c].m_challenge_id) + if (player->getChallenge(m_challenges[c].m_challenge_id) ->isSolvedAtAnyDifficulty()) { unlocked_challenges++; From f0ef8e9913399162008750692878a5dd2d514ee2 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Sun, 9 Feb 2014 17:47:11 +0100 Subject: [PATCH 07/68] Shadow: reenable shadows It's just plain basic shadowmaps, a lot of tweak is still necessary but it gives a way to see how light values are affected in some places. (cave in chocolate for instance) --- data/shaders/sunlightshadow.frag | 130 +++++++++++++++++-------------- src/graphics/irr_driver.hpp | 10 ++- src/graphics/post_processing.cpp | 42 +++++++++- src/graphics/post_processing.hpp | 2 + src/graphics/render.cpp | 58 +++++++------- src/graphics/rtts.cpp | 2 +- src/graphics/shaders.cpp | 54 ++++++++++++- src/graphics/shaders.hpp | 22 ++++++ src/graphics/stkanimatedmesh.cpp | 18 ++++- src/graphics/stkanimatedmesh.hpp | 1 + src/graphics/stkmesh.cpp | 25 ++++++ src/graphics/stkmesh.hpp | 2 + 12 files changed, 273 insertions(+), 93 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 3151cfb7e..db96b7855 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -1,95 +1,107 @@ #version 130 uniform sampler2D ntex; uniform sampler2D dtex; -uniform sampler2D cloudtex; uniform sampler2D shadowtex; -uniform sampler2D warpx; -uniform sampler2D warpy; +//uniform sampler2D warpx; +///uniform sampler2D warpy; -uniform vec3 center; +uniform vec3 direction; uniform vec3 col; uniform vec2 screen; -uniform mat4 invprojview; +uniform mat4 invproj; uniform mat4 shadowmat; -uniform int hasclouds; -uniform vec2 wind; -uniform float shadowoffset; +//uniform int hasclouds; +//uniform vec2 wind; +//uniform float shadowoffset; -out vec4 FragColor; -out vec4 OtherOutput; +in vec2 uv; +out vec4 Diff; +out vec4 Spec; +out vec4 SpecularMap; -float decdepth(vec4 rgba) { - return dot(rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/16581375.0)); +const float tolerance_z = 0.001; + +vec3 DecodeNormal(vec2 n) +{ + float z = dot(n, n) * 2. - 1.; + vec2 xy = normalize(n) * sqrt(1. - z * z); + return vec3(xy,z); } void main() { - - vec2 texc = gl_FragCoord.xy / screen; - vec4 depthread = texture(dtex, texc); - float z = decdepth(vec4(depthread.xyz, 0.0)); + float z = texture(dtex, uv).x; + vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0; + xpos = invproj * xpos; + xpos.xyz /= xpos.w; if (z < 0.03) { // Skyboxes are fully lit - FragColor = vec4(1.0); - OtherOutput = vec4(0.0); + Diff = vec4(1.0); + Spec = vec4(1.0); return; } - vec3 norm = texture(ntex, texc).xyz; - norm = (norm - 0.5) * 2.0; + vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.)); // Normalized on the cpu - vec3 L = center; + vec3 L = direction; float NdotL = max(0.0, dot(norm, L)); - if (NdotL < 0.01) discard; + vec3 R = reflect(L, norm); + float RdotE = max(0.0, dot(R, normalize(xpos.xyz))); + float Specular = pow(RdotE, 200); vec3 outcol = NdotL * col; - // World-space position - vec3 tmp = vec3(texc, z); - tmp = tmp * 2.0 - 1.0; +// if (hasclouds == 1) +// { +// vec2 cloudcoord = (xpos.xz * 0.00833333) + wind; +// float cloud = texture(cloudtex, cloudcoord).x; +// //float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y); - vec4 xpos = vec4(tmp, 1.0); - xpos = invprojview * xpos; - xpos.xyz /= xpos.w; - - if (hasclouds == 1) - { - vec2 cloudcoord = (xpos.xz * 0.00833333) + wind; - float cloud = texture(cloudtex, cloudcoord).x; - //float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y); - - outcol *= cloud; - } +// outcol *= cloud; +// } // Shadows - vec3 shadowcoord = (shadowmat * vec4(xpos.xyz, 1.0)).xyz; - shadowcoord = (shadowcoord * 0.5) + vec3(0.5); + vec4 shadowcoord = (shadowmat * vec4(xpos.xyz, 1.0)); + shadowcoord /= shadowcoord.w; + vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; +// shadowcoord = (shadowcoord * 0.5) + vec3(0.5); - float movex = decdepth(texture(warpx, shadowcoord.xy)); - float movey = decdepth(texture(warpy, shadowcoord.xy)); - float dx = movex * 2.0 - 1.0; - float dy = movey * 2.0 - 1.0; - shadowcoord.xy += vec2(dx, dy); +// float movex = decdepth(texture(warpx, shadowcoord.xy)); +// float movey = decdepth(texture(warpy, shadowcoord.xy)); +// float dx = movex * 2.0 - 1.0; +// float dy = movey * 2.0 - 1.0; +// shadowcoord.xy += vec2(dx, dy);*/ - vec4 shadowread = texture(shadowtex, shadowcoord.xy); - float shadowmapz = decdepth(vec4(shadowread.xyz, 0.0)); + float shadowmapz = 2. * texture(shadowtex, shadowtexcoord).x - 1.; - float moved = (abs(dx) + abs(dy)) * 0.5; + if (shadowmapz > shadowcoord.z - tolerance_z) + { + Diff = vec4(NdotL * col, 1.); + Spec = vec4(Specular * col, 1.); + } + else + { + Diff = vec4(0., 0., 0., 1.); + Spec = vec4(0., 0., 0., 1.); + } + SpecularMap = vec4(1.0); + return; + +// float moved = (abs(dx) + abs(dy)) * 0.5; -/* - float bias = 0.002 * tan(acos(NdotL)); // According to the slope - bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping - bias = clamp(bias, 0.001, 0.014); -*/ -/* - float avi = 0.002; - float abi = 0.0025; */ - float avi = 0.0018; +// float bias = 0.002 * tan(acos(NdotL)); // According to the slope +// bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping +// bias = clamp(bias, 0.001, 0.014); + +// float avi = 0.002; +// float abi = 0.0025; + +/* float avi = 0.0018; float abi = 0.002; float bias = avi * tan(acos(NdotL)); // According to the slope @@ -113,11 +125,11 @@ void main() { float shadowed = step(shadowmapz + bias, shadowcoord.z); float dist = (shadowcoord.z / shadowmapz) - 1.0; float penumbra = dist * softness / gl_FragCoord.z; - penumbra *= shadowed; + penumbra *= shadowed;*/ /* outcol.r = (shadowcoord.z - shadowmapz) * 50.0; outcol.g = moved;*/ - FragColor = vec4(outcol, 0.05); - OtherOutput = vec4(shadowed, penumbra, shadowed, shadowed); +// FragColor = vec4(outcol, 0.05); +// OtherOutput = vec4(shadowed, penumbra, shadowed, shadowed); } diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 5d9fe4615..9a2fbda5c 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -102,6 +102,7 @@ private: RTT *m_rtts; /** Shadow importance. */ ShadowImportance *m_shadow_importance; + core::matrix4 sun_ortho_matrix; /** Additional details to be shown in case that a texture is not found. * This is used to specify details like: "while loading kart '...'" */ @@ -111,7 +112,7 @@ private: core::array<video::IRenderTarget> m_mrt; /** Matrixes used in several places stored here to avoid recomputation. */ - core::matrix4 m_ViewMatrix, m_ProjMatrix, m_InvProjMatrix, m_ProjViewMatrix, m_InvProjViewMatrix; + core::matrix4 m_ViewMatrix, m_InvViewMatrix, m_ProjMatrix, m_InvProjMatrix, m_ProjViewMatrix, m_InvProjViewMatrix; std::vector<video::ITexture *> SkyboxTextures; @@ -203,9 +204,9 @@ private: void renderFixed(float dt); void renderGLSL(float dt); - void renderShadows(ShadowImportanceProvider * const sicb, + void renderShadows(//ShadowImportanceProvider * const sicb, scene::ICameraSceneNode * const camnode, - video::SOverrideMaterial &overridemat, + //video::SOverrideMaterial &overridemat, Camera * const camera); void renderGlow(video::SOverrideMaterial &overridemat, std::vector<GlowData>& glows, @@ -492,8 +493,9 @@ public: // ------------------------------------------------------------------------ scene::IMeshSceneNode *getSunInterposer() { return m_sun_interposer; } // ------------------------------------------------------------------------ - void setViewMatrix(core::matrix4 matrix) { m_ViewMatrix = matrix; } + void setViewMatrix(core::matrix4 matrix) { m_ViewMatrix = matrix; matrix.getInverse(m_InvViewMatrix); } const core::matrix4 &getViewMatrix() const { return m_ViewMatrix; } + const core::matrix4 &getInvViewMatrix() const { return m_InvViewMatrix; } void setProjMatrix(core::matrix4 matrix) { m_ProjMatrix = matrix; matrix.getInverse(m_InvProjMatrix); } const core::matrix4 &getProjMatrix() const { return m_ProjMatrix; } const core::matrix4 &getInvProjMatrix() const { return m_InvProjMatrix; } diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 019332efe..8d0727034 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -346,6 +346,25 @@ void PostProcessing::renderSunlight() glBindVertexArray(0); } +void PostProcessing::renderShadowedSunlight(const core::matrix4 &sun_ortho_matrix) +{ + SunLightProvider * const cb = (SunLightProvider *)irr_driver->getCallback(ES_SUNLIGHT); + + glEnable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glBlendFunc(GL_ONE, GL_ONE); + glBlendEquation(GL_FUNC_ADD); + + glUseProgram(FullScreenShader::ShadowedSunLightShader::Program); + glBindVertexArray(FullScreenShader::ShadowedSunLightShader::vao); + setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); + setTexture(2, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); + FullScreenShader::ShadowedSunLightShader::setUniforms(sun_ortho_matrix, cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); +} + void PostProcessing::renderGaussian3Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height) { @@ -448,6 +467,27 @@ void PostProcessing::renderPassThrough(ITexture *tex) glDisable(GL_BLEND); } +void PostProcessing::renderPassThrough(GLuint tex) +{ + glDisable(GL_DEPTH_TEST); + + glUseProgram(FullScreenShader::PassThroughShader::Program); + glBindVertexArray(FullScreenShader::PassThroughShader::vao); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glUniform1i(FullScreenShader::PassThroughShader::uniform_texture, 0); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glEnable(GL_DEPTH_TEST); + glDisable(GL_BLEND); +} + void PostProcessing::renderGlow(ITexture *tex) { glDisable(GL_DEPTH_TEST); @@ -807,7 +847,7 @@ void PostProcessing::render() else if (irr_driver->getSSAOViz()) renderPassThrough(irr_driver->getRTT(RTT_SSAO)); else if (irr_driver->getShadowViz()) - renderPassThrough(irr_driver->getRTT(RTT_SHADOW)); + renderPassThrough(static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW))->DepthBufferTexture); else renderColorLevel(in); } diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index 7dc59600e..b6c83a792 100644 --- a/src/graphics/post_processing.hpp +++ b/src/graphics/post_processing.hpp @@ -75,6 +75,7 @@ public: /** Generate diffuse and specular map */ void renderPointlight(const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy); void renderSunlight(); + void renderShadowedSunlight(const core::matrix4 &sun_ortho_matrix); void renderFog(const core::matrix4 &ipvmat); void renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm); @@ -85,6 +86,7 @@ public: /** Render tex. Used for blit/texture resize */ void renderPassThrough(video::ITexture *tex); + void renderPassThrough(unsigned tex); void renderGlow(video::ITexture *tex); diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index aeb3b087c..c219b72a6 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -215,10 +215,10 @@ void IrrDriver::renderGLSL(float dt) const core::aabbox3df cambox = camnode->getViewFrustum()->getBoundingBox(); // Shadows - if (!m_mipviz && !m_wireframe && UserConfigParams::m_shadows && - World::getWorld()->getTrack()->hasShadows()) + if (!m_mipviz && !m_wireframe && UserConfigParams::m_shadows) + //&& World::getWorld()->getTrack()->hasShadows()) { - //renderShadows(sicb, camnode, overridemat, camera); + renderShadows(camnode, camera); } @@ -464,9 +464,9 @@ void IrrDriver::renderFixed(float dt) // ---------------------------------------------------------------------------- -void IrrDriver::renderShadows(ShadowImportanceProvider * const sicb, +void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, scene::ICameraSceneNode * const camnode, - video::SOverrideMaterial &overridemat, + //video::SOverrideMaterial &overridemat, Camera * const camera) { m_scene_manager->setCurrentRendertime(scene::ESNRP_SOLID); @@ -486,7 +486,6 @@ void IrrDriver::renderShadows(ShadowImportanceProvider * const sicb, camnode->render(); // Set up a nice ortho projection that contains our camera frustum - core::matrix4 ortho; core::aabbox3df box = smallcambox; box = box.intersect(trackbox); @@ -518,16 +517,16 @@ void IrrDriver::renderShadows(ShadowImportanceProvider * const sicb, if (up == down) down += 0.1f; if (z == 30) z += 0.1f; - ortho.buildProjectionMatrixOrthoLH(left, right, + sun_ortho_matrix.buildProjectionMatrixOrthoLH(left, right, up, down, 30, z); - m_suncam->setProjectionMatrix(ortho, true); + m_suncam->setProjectionMatrix(sun_ortho_matrix, true); m_scene_manager->setActiveCamera(m_suncam); m_suncam->render(); - ortho *= m_suncam->getViewMatrix(); - ((SunLightProvider *) m_shaders->m_callbacks[ES_SUNLIGHT])->setShadowMatrix(ortho); + //sun_ortho_matrix *= m_suncam->getViewMatrix(); +/* ((SunLightProvider *) m_shaders->m_callbacks[ES_SUNLIGHT])->setShadowMatrix(ortho); sicb->setShadowMatrix(ortho); overridemat.Enabled = 0; @@ -563,7 +562,7 @@ void IrrDriver::renderShadows(ShadowImportanceProvider * const sicb, m_rtts->getRTT(RTT_WARPV)->getSize().Height, m_rtts->getRTT(RTT_WARPV)->getSize().Height); -/* sq.setMaterialType(m_shaders->getShader(ES_GAUSSIAN6H)); + sq.setMaterialType(m_shaders->getShader(ES_GAUSSIAN6H)); sq.setTexture(m_rtts->getRTT(RTT_WARPH)); sq.render(m_rtts->getRTT(curh)); @@ -577,7 +576,7 @@ void IrrDriver::renderShadows(ShadowImportanceProvider * const sicb, // calculating the min, max, and total, it's several hundred us // faster to do that than to do it once in a separate shader // (shader switch overhead, measured). - colcb->setResolution(m_rtts->getRTT(RTT_WARPV)->getSize().Height, + /*colcb->setResolution(m_rtts->getRTT(RTT_WARPV)->getSize().Height, m_rtts->getRTT(RTT_WARPV)->getSize().Height); sq.setMaterialType(m_shaders->getShader(ES_SHADOW_WARPH)); @@ -586,11 +585,12 @@ void IrrDriver::renderShadows(ShadowImportanceProvider * const sicb, sq.setMaterialType(m_shaders->getShader(ES_SHADOW_WARPV)); sq.setTexture(m_rtts->getRTT(curv)); - sq.render(m_rtts->getRTT(RTT_WARPV)); + sq.render(m_rtts->getRTT(RTT_WARPV));*/ // Actual shadow map - m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_SHADOW), true, true); - overridemat.Material.MaterialType = m_shaders->getShader(ES_SHADOWPASS); + + +/* overridemat.Material.MaterialType = m_shaders->getShader(ES_SHADOWPASS); overridemat.EnableFlags = video::EMF_MATERIAL_TYPE | video::EMF_TEXTURE1 | video::EMF_TEXTURE2; overridemat.EnablePasses = scene::ESNRP_SOLID; @@ -607,18 +607,20 @@ void IrrDriver::renderShadows(ShadowImportanceProvider * const sicb, overridemat.Material.TextureLayer[1].AnisotropicFilter = overridemat.Material.TextureLayer[2].AnisotropicFilter = 0; overridemat.Material.Wireframe = 1; - overridemat.Enabled = true; - + overridemat.Enabled = true;*/ + sun_ortho_matrix = getVideoDriver()->getTransform(video::ETS_PROJECTION); + sun_ortho_matrix *= getVideoDriver()->getTransform(video::ETS_VIEW); + irr_driver->setPhase(SHADOW_PASS); + glDisable(GL_BLEND); + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_SHADOW), true, true); + glDrawBuffer(GL_NONE); m_scene_manager->drawAll(scene::ESNRP_SOLID); + glCullFace(GL_BACK); - if (m_shadowviz) - { - overridemat.EnableFlags |= video::EMF_WIREFRAME; - m_scene_manager->drawAll(scene::ESNRP_SOLID); - } - - overridemat.EnablePasses = 0; - overridemat.Enabled = false; +// overridemat.EnablePasses = 0; +// overridemat.Enabled = false; camera->activate(); tick++; @@ -728,6 +730,7 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox, video::SOverrideMaterial &overridemat, int cam, float dt) { + sun_ortho_matrix *= getInvViewMatrix(); core::array<video::IRenderTarget> rtts; // Diffuse rtts.push_back(m_rtts->getRTT(RTT_TMP1)); @@ -749,7 +752,10 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox, if (!m_lights[i]->isPointLight()) { m_lights[i]->render(); - m_post_processing->renderSunlight(); + if (UserConfigParams::m_shadows) + m_post_processing->renderShadowedSunlight(sun_ortho_matrix); + else + m_post_processing->renderSunlight(); continue; } const core::vector3df &lightpos = (m_lights[i]->getAbsolutePosition() - campos); diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 2696bebb7..288dc63b6 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -36,7 +36,7 @@ RTT::RTT() const dimension2du ssaosize = UserConfigParams::m_ssao == 2 ? res : quarter; - const u16 shadowside = UserConfigParams::m_shadows == 2 ? 2048 : 512; + const u16 shadowside = 8192; const dimension2du shadowsize(shadowside, shadowside); const dimension2du warpvsize(1, 512); const dimension2du warphsize(512, 1); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 7eb378ce3..df76d13f4 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -154,7 +154,7 @@ void Shaders::loadShaders() m_shaders[ES_OBJECTPASS_RIMLIT] = glsl_noinput(dir + "objectpass_rimlit.vert", dir + "objectpass_rimlit.frag"); m_shaders[ES_SUNLIGHT] = glsl_noinput(std::string(""), dir + "sunlight.frag"); - m_shaders[ES_SUNLIGHT_SHADOW] = glsl_noinput(dir + "pass.vert", dir + "sunlightshadow.frag"); + m_shaders[ES_SUNLIGHT_SHADOW] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_MLAA_COLOR1] = glsl(dir + "mlaa_offset.vert", dir + "mlaa_color1.frag", m_callbacks[ES_MLAA_COLOR1]); @@ -238,6 +238,7 @@ void Shaders::loadShaders() FullScreenShader::PPDisplaceShader::init(); FullScreenShader::SSAOShader::init(); FullScreenShader::SunLightShader::init(); + FullScreenShader::ShadowedSunLightShader::init(); MeshShader::ColorizeShader::init(); MeshShader::NormalMapShader::init(); MeshShader::ObjectPass1Shader::init(); @@ -257,6 +258,7 @@ void Shaders::loadShaders() MeshShader::TransparentFogShader::init(); MeshShader::BillboardShader::init(); MeshShader::DisplaceShader::init(); + MeshShader::ShadowShader::init(); ParticleShader::FlipParticleRender::init(); ParticleShader::HeightmapSimulationShader::init(); ParticleShader::SimpleParticleRender::init(); @@ -873,6 +875,22 @@ namespace MeshShader glUniform3f(uniform_col, r, g, b); } + GLuint ShadowShader::Program; + GLuint ShadowShader::attrib_position; + GLuint ShadowShader::uniform_MVP; + + void ShadowShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/white.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + } + + void ShadowShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + } + GLuint DisplaceShader::Program; GLuint DisplaceShader::attrib_position; GLuint DisplaceShader::attrib_texcoord; @@ -1219,6 +1237,40 @@ namespace FullScreenShader glUniform1i(uniform_dtex, TU_dtex); } + GLuint ShadowedSunLightShader::Program; + GLuint ShadowedSunLightShader::uniform_ntex; + GLuint ShadowedSunLightShader::uniform_dtex; + GLuint ShadowedSunLightShader::uniform_shadowtex; + GLuint ShadowedSunLightShader::uniform_shadowmat; + GLuint ShadowedSunLightShader::uniform_direction; + GLuint ShadowedSunLightShader::uniform_col; + GLuint ShadowedSunLightShader::uniform_invproj; + GLuint ShadowedSunLightShader::vao; + + void ShadowedSunLightShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/sunlightshadow.frag").c_str()); + uniform_ntex = glGetUniformLocation(Program, "ntex"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); + uniform_shadowtex = glGetUniformLocation(Program, "shadowtex"); + uniform_shadowmat = glGetUniformLocation(Program, "shadowmat"), + uniform_direction = glGetUniformLocation(Program, "direction"); + uniform_col = glGetUniformLocation(Program, "col"); + uniform_invproj = glGetUniformLocation(Program, "invproj"); + vao = createVAO(Program); + } + + void ShadowedSunLightShader::setUniforms(const core::matrix4 &shadowmat, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex) + { + glUniformMatrix4fv(uniform_shadowmat, 1, GL_FALSE, shadowmat.pointer()); + glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); + glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z); + glUniform3f(uniform_col, r, g, b); + glUniform1i(uniform_ntex, TU_ntex); + glUniform1i(uniform_dtex, TU_dtex); + glUniform1i(uniform_shadowtex, TU_shadowtex); + } + GLuint Gaussian6HBlurShader::Program; GLuint Gaussian6HBlurShader::uniform_tex; GLuint Gaussian6HBlurShader::uniform_pixel; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 3f0a9dda6..83788766e 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -225,6 +225,17 @@ public: static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, float r, float g, float b); }; +class ShadowShader +{ +public: + static GLuint Program; + static GLuint attrib_position; + static GLuint uniform_MVP; + + static void init(); + static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); +}; + class DisplaceShader { public: @@ -352,6 +363,17 @@ public: static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex); }; +class ShadowedSunLightShader +{ +public: + static GLuint Program; + static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex, uniform_shadowmat, uniform_direction, uniform_col, uniform_invproj; + static GLuint vao; + + static void init(); + static void setUniforms(const core::matrix4 &shadowmat, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex); +}; + class Gaussian6HBlurShader { public: diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index d0e3c14c5..07bb167bc 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -94,6 +94,20 @@ isObjectPass(video::E_MATERIAL_TYPE type) return false; } +void STKAnimatedMesh::drawShadow(const GLMesh &mesh) +{ + GLenum ptype = mesh.PrimitiveType; + GLenum itype = mesh.IndexType; + size_t count = mesh.IndexCount; + assert(irr_driver->getPhase() == SHADOW_PASS); + core::matrix4 ShadowMVP; + computeMVP(ShadowMVP); + glUseProgram(MeshShader::ShadowShader::Program); + MeshShader::ShadowShader::setUniforms(ShadowMVP); + glBindVertexArray(mesh.vao_shadow_pass); + glDrawElements(ptype, count, itype, 0); +} + void STKAnimatedMesh::render() { video::IVideoDriver* driver = SceneManager->getVideoDriver(); @@ -151,7 +165,9 @@ void STKAnimatedMesh::render() glBindBuffer(GL_ARRAY_BUFFER, GLmeshes[i].vertex_buffer); glBufferSubData(GL_ARRAY_BUFFER, 0, mb->getVertexCount() * GLmeshes[i].Stride, mb->getVertices()); } - if (isTransparentPass) + if (irr_driver->getPhase() == SHADOW_PASS) + drawShadow(GLmeshes[i]); + else if (isTransparentPass) drawTransparent(GLmeshes[i], material.MaterialType); else drawSolid(GLmeshes[i], material.MaterialType); diff --git a/src/graphics/stkanimatedmesh.hpp b/src/graphics/stkanimatedmesh.hpp index e97a30215..1df7fc005 100644 --- a/src/graphics/stkanimatedmesh.hpp +++ b/src/graphics/stkanimatedmesh.hpp @@ -15,6 +15,7 @@ protected: core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView; void drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type); void drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type); + void drawShadow(const GLMesh &mesh); public: STKAnimatedMesh(irr::scene::IAnimatedMesh* mesh, irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id, diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 7a989b6c4..a3881ef3a 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -723,6 +723,21 @@ void STKMesh::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type) return; } +void STKMesh::drawShadow(const GLMesh &mesh) +{ + GLenum ptype = mesh.PrimitiveType; + GLenum itype = mesh.IndexType; + size_t count = mesh.IndexCount; + assert(irr_driver->getPhase() == SHADOW_PASS); + + core::matrix4 ShadowMVP; + computeMVP(ShadowMVP); + glUseProgram(MeshShader::ShadowShader::Program); + MeshShader::ShadowShader::setUniforms(ShadowMVP); + glBindVertexArray(mesh.vao_shadow_pass); + glDrawElements(ptype, count, itype, 0); +} + void STKMesh::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type) { switch (irr_driver->getPhase()) @@ -910,6 +925,11 @@ void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type) return; mesh.vao_displace_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::DisplaceShader::attrib_position, MeshShader::DisplaceShader::attrib_texcoord, MeshShader::DisplaceShader::attrib_second_texcoord, -1, -1, -1, -1, mesh.Stride); return; + case SHADOW_PASS: + if (mesh.vao_shadow_pass) + return; + mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); + return; } } @@ -961,6 +981,11 @@ void STKMesh::render() initvaostate(GLmeshes[i], material.MaterialType); drawGlow(GLmeshes[i]); } + else if (irr_driver->getPhase() == SHADOW_PASS) + { + initvaostate(GLmeshes[i], material.MaterialType); + drawShadow(GLmeshes[i]); + } else { irr_driver->IncreaseObjectCount(); diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index d36b58fce..199c1e0b0 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -13,6 +13,7 @@ struct GLMesh { GLuint vao_second_pass; GLuint vao_glow_pass; GLuint vao_displace_pass; + GLuint vao_shadow_pass; GLuint vertex_buffer; GLuint index_buffer; GLuint textures[6]; @@ -62,6 +63,7 @@ protected: // Misc passes shaders (glow, displace...) void drawGlow(const GLMesh &mesh); void drawDisplace(const GLMesh &mesh); + void drawShadow(const GLMesh &mesh); void createGLMeshes(); void cleanGLMeshes(); public: From 63db565fd7703b926d6fb185c1d6e833cd58aab0 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Sun, 9 Feb 2014 19:42:22 +0100 Subject: [PATCH 08/68] Shadow: Better bias. --- data/shaders/sunlightshadow.frag | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index db96b7855..418bfa59e 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -19,8 +19,6 @@ out vec4 Diff; out vec4 Spec; out vec4 SpecularMap; -const float tolerance_z = 0.001; - vec3 DecodeNormal(vec2 n) { float z = dot(n, n) * 2. - 1.; @@ -76,8 +74,11 @@ void main() { // shadowcoord.xy += vec2(dx, dy);*/ float shadowmapz = 2. * texture(shadowtex, shadowtexcoord).x - 1.; + float bias = 0.002 * tan(acos(NdotL)); // According to the slope + // bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping + bias = clamp(bias, 0.001, 0.014); - if (shadowmapz > shadowcoord.z - tolerance_z) + if (shadowmapz > shadowcoord.z + bias) { Diff = vec4(NdotL * col, 1.); Spec = vec4(Specular * col, 1.); @@ -92,12 +93,6 @@ void main() { // float moved = (abs(dx) + abs(dy)) * 0.5; - - -// float bias = 0.002 * tan(acos(NdotL)); // According to the slope -// bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping -// bias = clamp(bias, 0.001, 0.014); - // float avi = 0.002; // float abi = 0.0025; From 5d5ac34648cc52c7e208c5be268b62df146160a4 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Sun, 9 Feb 2014 20:03:54 +0100 Subject: [PATCH 09/68] Shadow: soften edge a little --- data/shaders/sunlightshadow.frag | 17 +++++------------ src/graphics/post_processing.cpp | 4 +++- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 418bfa59e..f192b297b 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -1,7 +1,7 @@ #version 130 uniform sampler2D ntex; uniform sampler2D dtex; -uniform sampler2D shadowtex; +uniform sampler2DShadow shadowtex; //uniform sampler2D warpx; ///uniform sampler2D warpy; @@ -73,21 +73,14 @@ void main() { // float dy = movey * 2.0 - 1.0; // shadowcoord.xy += vec2(dx, dy);*/ - float shadowmapz = 2. * texture(shadowtex, shadowtexcoord).x - 1.; + //float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.; float bias = 0.002 * tan(acos(NdotL)); // According to the slope // bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping bias = clamp(bias, 0.001, 0.014); + float factor = texture(shadowtex, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias) + 0.5)); - if (shadowmapz > shadowcoord.z + bias) - { - Diff = vec4(NdotL * col, 1.); - Spec = vec4(Specular * col, 1.); - } - else - { - Diff = vec4(0., 0., 0., 1.); - Spec = vec4(0., 0., 0., 1.); - } + Diff = vec4(factor * NdotL * col, 1.); + Spec = vec4(factor * Specular * col, 1.); SpecularMap = vec4(1.0); return; diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 8d0727034..27415cbf2 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -359,7 +359,9 @@ void PostProcessing::renderShadowedSunlight(const core::matrix4 &sun_ortho_matri glBindVertexArray(FullScreenShader::ShadowedSunLightShader::vao); setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); - setTexture(2, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); + setTexture(2, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW))->DepthBufferTexture, GL_LINEAR, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); FullScreenShader::ShadowedSunLightShader::setUniforms(sun_ortho_matrix, cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindVertexArray(0); From 1c510881a710624afed2584afe71457455a0bba8 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Sun, 9 Feb 2014 21:16:16 +0100 Subject: [PATCH 10/68] Shadow: Fix broken specular with shadows enabled. --- src/graphics/render.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index c219b72a6..b937b4cfd 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -622,6 +622,7 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, // overridemat.EnablePasses = 0; // overridemat.Enabled = false; camera->activate(); + m_scene_manager->drawAll(scene::ESNRP_CAMERA); tick++; tick %= 2; From 19d490a26d248d6a194d62376718e44e5c4cef23 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Sun, 9 Feb 2014 21:18:15 +0100 Subject: [PATCH 11/68] Lights: Remove unused export value. --- data/shaders/sunlight.frag | 2 -- data/shaders/sunlightshadow.frag | 3 --- 2 files changed, 5 deletions(-) diff --git a/data/shaders/sunlight.frag b/data/shaders/sunlight.frag index faedb9d61..c6519c5d9 100644 --- a/data/shaders/sunlight.frag +++ b/data/shaders/sunlight.frag @@ -12,7 +12,6 @@ uniform mat4 invproj; in vec2 uv; out vec4 Diff; out vec4 Spec; -out vec4 SpecularMap; vec3 DecodeNormal(vec2 n) { @@ -58,5 +57,4 @@ void main() { Diff = vec4(NdotL * col, 1.); Spec = vec4(Specular * col, 1.); - SpecularMap = vec4(1.0); } diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index f192b297b..4fe0f9313 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -7,7 +7,6 @@ uniform sampler2DShadow shadowtex; uniform vec3 direction; uniform vec3 col; -uniform vec2 screen; uniform mat4 invproj; uniform mat4 shadowmat; //uniform int hasclouds; @@ -17,7 +16,6 @@ uniform mat4 shadowmat; in vec2 uv; out vec4 Diff; out vec4 Spec; -out vec4 SpecularMap; vec3 DecodeNormal(vec2 n) { @@ -81,7 +79,6 @@ void main() { Diff = vec4(factor * NdotL * col, 1.); Spec = vec4(factor * Specular * col, 1.); - SpecularMap = vec4(1.0); return; // float moved = (abs(dx) + abs(dy)) * 0.5; From 5acf3e16813ff2348cdbd87ed00e8141d1c9d0d9 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 10 Feb 2014 08:41:54 +1100 Subject: [PATCH 12/68] Various compilation fixes, some cosmetic changes. --- src/achievements/achievements_manager.cpp | 5 +- src/config/player.hpp | 8 ++ src/karts/kart.cpp | 5 +- src/main.cpp | 3 +- src/modes/cutscene_world.cpp | 16 ++-- src/states_screens/kart_selection.cpp | 99 ++++++++++++----------- src/states_screens/kart_selection.hpp | 26 +++--- 7 files changed, 88 insertions(+), 74 deletions(-) diff --git a/src/achievements/achievements_manager.cpp b/src/achievements/achievements_manager.cpp index c0fb4b218..64e6b540a 100644 --- a/src/achievements/achievements_manager.cpp +++ b/src/achievements/achievements_manager.cpp @@ -18,7 +18,6 @@ #include "achievements/achievements_manager.hpp" -#include "challenges/unlock_manager.hpp" #include "config/player.hpp" #include "config/player_manager.hpp" #include "config/user_config.hpp" @@ -234,10 +233,10 @@ void AchievementsManager::updateCurrentPlayer() } else { - m_active_slot = getSlot(unlock_manager->getCurrentPlayer()->getUniqueID(), false); + m_active_slot = getSlot(PlayerManager::get()->getCurrentPlayer()->getUniqueID(), false); if(m_active_slot == NULL) { - m_active_slot = createNewSlot(unlock_manager->getCurrentPlayer()->getUniqueID(), false); + m_active_slot = createNewSlot(PlayerManager::get()->getCurrentPlayer()->getUniqueID(), false); save(); } } diff --git a/src/config/player.hpp b/src/config/player.hpp index 38e2f24b7..10f51b3c9 100644 --- a/src/config/player.hpp +++ b/src/config/player.hpp @@ -151,10 +151,18 @@ public: // ------------------------------------------------------------------------ unsigned int getPoints() const { return m_game_slot->getPoints(); } // ------------------------------------------------------------------------ + void setFirstTime(bool b) { m_game_slot->setFirstTime(b); } + // ------------------------------------------------------------------------ bool isFirstTime() const { return m_game_slot->isFirstTime(); } // ------------------------------------------------------------------------ void clearUnlocked() { m_game_slot->clearUnlocked(); } // ------------------------------------------------------------------------ + /** Returns the current challenge for this player. */ + const Challenge* getCurrentChallenge() const + { + return m_game_slot->getCurrentChallenge(); + } // getCurrentChallenge + // ------------------------------------------------------------------------ const Challenge* getChallenge(const std::string &id) { return m_game_slot->getChallenge(id); diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 03250a70b..7be299fb0 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -30,6 +30,7 @@ #include "audio/sfx_manager.hpp" #include "audio/sfx_base.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "config/user_config.hpp" #include "graphics/camera.hpp" #include "graphics/explosion.hpp" @@ -804,8 +805,8 @@ void Kart::finishedRace(float time) m_controller)); if (m_controller->isPlayerController()) // if player is on this computer { - GameSlot *slot = unlock_manager->getCurrentSlot(); - const Challenge *challenge = slot->getCurrentChallenge(); + PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + const Challenge *challenge = player->getCurrentChallenge(); // In case of a GP challenge don't make the end animation depend // on if the challenge is fulfilled if(challenge && !challenge->getData()->isGrandPrix()) diff --git a/src/main.cpp b/src/main.cpp index 6dd58c7f2..b0162be09 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1193,7 +1193,8 @@ int main(int argc, char *argv[] ) addons_manager->initAddons(xml); } } - else if(!UserConfigParams::m_no_start_screen) + + if(!UserConfigParams::m_no_start_screen) { StateManager::get()->pushScreen(StoryModeLobbyScreen::getInstance()); #ifdef ENABLE_WIIUSE diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index ea01df566..196658230 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -17,15 +17,12 @@ #include "modes/cutscene_world.hpp" -#include <string> -#include <IMeshSceneNode.h> -#include <ISceneManager.h> - #include "animations/animation_base.hpp" #include "animations/three_d_animation.hpp" #include "audio/music_manager.hpp" #include "challenges/game_slot.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "io/file_manager.hpp" #include "karts/abstract_kart.hpp" @@ -43,6 +40,11 @@ #include "utils/constants.hpp" #include "utils/ptr_vector.hpp" +#include <IMeshSceneNode.h> +#include <ISceneManager.h> + +#include <string> + //----------------------------------------------------------------------------- /** Constructor. Sets up the clock mode etc. */ @@ -376,13 +378,13 @@ void CutsceneWorld::enterRaceOverState() else if (race_manager->getTrackName() == "introcutscene" || race_manager->getTrackName() == "introcutscene2") { - GameSlot* slot = unlock_manager->getCurrentSlot(); - if (slot->isFirstTime()) + PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + if (player->isFirstTime()) { race_manager->exitRace(); StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); - slot->setFirstTime(false); + player->setFirstTime(false); unlock_manager->save(); KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance(); s->setMultiplayer(false); diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 3b9056f8f..4f97c0339 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -126,17 +126,18 @@ static FocusDispatcher* g_dispatcher = NULL; /** A small extension to the spinner widget to add features like player ID * management or badging */ -PlayerNameSpinner::PlayerNameSpinner(KartSelectionScreen* parent, const int playerID) +PlayerNameSpinner::PlayerNameSpinner(KartSelectionScreen* parent, + const int player_id) { - m_playerID = playerID; + m_player_id = player_id; m_incorrect = false; m_red_mark_widget = NULL; m_parent = parent; } // PlayerNameSpinner // ------------------------------------------------------------------------ -void PlayerNameSpinner::setID(const int m_playerID) +void PlayerNameSpinner::setID(const int m_player_id) { - PlayerNameSpinner::m_playerID = m_playerID; + PlayerNameSpinner::m_player_id = m_player_id; } // setID // ------------------------------------------------------------------------ /** Add a red mark on the spinner to mean "invalid choice" */ @@ -184,22 +185,22 @@ void PlayerNameSpinner::markAsCorrect() * number, name, the kart view, the kart's name) */ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, - StateManager::ActivePlayer* associatedPlayer, - Online::Profile* associatedUser, - core::recti area, const int playerID, - std::string kartGroup, - const int irrlichtWidgetID) : Widget(WTYPE_DIV) + StateManager::ActivePlayer* associated_player, + Online::Profile* associated_user, + core::recti area, const int player_id, + std::string kart_group, + const int irrlicht_widget_id) : Widget(WTYPE_DIV) { #ifdef DEBUG - if (associatedPlayer) - assert(associatedPlayer->ok()); + if (associated_player) + assert(associated_player->ok()); m_magic_number = 0x33445566; #endif m_ready_text = NULL; m_parent_screen = parent; - m_associated_user = associatedUser; - m_associatedPlayer = associatedPlayer; + m_associated_user = associated_user; + m_associated_player = associated_player; x_speed = 1.0f; y_speed = 1.0f; w_speed = 1.0f; @@ -207,10 +208,10 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, m_ready = false; m_not_updated_yet = true; - m_irrlicht_widget_ID = irrlichtWidgetID; + m_irrlicht_widget_id = irrlicht_widget_id; - m_playerID = playerID; - m_properties[PROP_ID] = StringUtils::insertValues("@p%i", m_playerID); + m_player_id = player_id; + m_properties[PROP_ID] = StringUtils::insertValues("@p%i", m_player_id); setSize(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, area.getWidth(), area.getHeight() ); @@ -222,19 +223,19 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, // ---- Player identity spinner m_player_ident_spinner = NULL; - m_player_ident_spinner = new PlayerNameSpinner(parent, m_playerID); + m_player_ident_spinner = new PlayerNameSpinner(parent, m_player_id); m_player_ident_spinner->m_x = player_name_x; m_player_ident_spinner->m_y = player_name_y; m_player_ident_spinner->m_w = player_name_w; m_player_ident_spinner->m_h = player_name_h; - if (parent->m_multiplayer && associatedPlayer) + if (parent->m_multiplayer && associated_player) { - if (associatedPlayer->getDevice()->getType() == DT_KEYBOARD) + if (associated_player->getDevice()->getType() == DT_KEYBOARD) { m_player_ident_spinner->setBadge(KEYBOARD_BADGE); } - else if (associatedPlayer->getDevice()->getType() == DT_GAMEPAD) + else if (associated_player->getDevice()->getType() == DT_GAMEPAD) { m_player_ident_spinner->setBadge(GAMEPAD_BADGE); } @@ -244,12 +245,12 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, m_player_ident_spinner->setBadge(OK_BADGE); } - if (irrlichtWidgetID == -1) + if (irrlicht_widget_id == -1) { m_player_ident_spinner->m_tab_down_root = g_root_id; } - spinnerID = StringUtils::insertValues("@p%i_spinner", m_playerID); + spinnerID = StringUtils::insertValues("@p%i_spinner", m_player_id); m_player_ident_spinner->m_properties[PROP_ID] = spinnerID; if (parent->m_multiplayer) @@ -278,7 +279,7 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, m_model_view->m_w = model_w; m_model_view->m_h = model_h; m_model_view->m_properties[PROP_ID] = - StringUtils::insertValues("@p%i_model", m_playerID); + StringUtils::insertValues("@p%i_model", m_player_id); //m_model_view->setParent(this); m_children.push_back(m_model_view); @@ -293,7 +294,7 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, // kart was used, but the addon package was removed), use the // first kart as a default. This way we don't have to hardcode // any kart names. - int id = kart_properties_manager->getKartByGroup(kartGroup, 0); + int id = kart_properties_manager->getKartByGroup(kart_group, 0); if (id == -1) { props = kart_properties_manager->getKartById(0); @@ -340,7 +341,7 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, m_kart_name->setText(props->getName(), false); m_kart_name->m_properties[PROP_TEXT_ALIGN] = "center"; m_kart_name->m_properties[PROP_ID] = - StringUtils::insertValues("@p%i_kartname", m_playerID); + StringUtils::insertValues("@p%i_kartname", m_player_id); m_kart_name->m_x = kart_name_x; m_kart_name->m_y = kart_name_y; m_kart_name->m_w = kart_name_w; @@ -352,9 +353,9 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent, PlayerKartWidget::~PlayerKartWidget() { - if (GUIEngine::getFocusForPlayer(m_playerID) == this) + if (GUIEngine::getFocusForPlayer(m_player_id) == this) { - GUIEngine::focusNothingForPlayer(m_playerID); + GUIEngine::focusNothingForPlayer(m_player_id); } //if (m_player_ID_label->getIrrlichtElement() != NULL) @@ -390,30 +391,30 @@ void PlayerKartWidget::setPlayerID(const int newPlayerID) assert(m_magic_number == 0x33445566); if (StateManager::get()->getActivePlayer(newPlayerID) - != m_associatedPlayer) + != m_associated_player) { std::cerr << "[KartSelectionScreen] WARNING: Internal " "inconsistency, PlayerKartWidget has IDs and " "pointers that do not correspond to one player\n"; fprintf(stderr, - " Player: %p - Index: %d - m_associatedPlayer: %p\n", + " Player: %p - Index: %d - m_associated_player: %p\n", StateManager::get()->getActivePlayer(newPlayerID), - newPlayerID, m_associatedPlayer); + newPlayerID, m_associated_player); assert(false); } // Remove current focus, but rembmer it - Widget* focus = GUIEngine::getFocusForPlayer(m_playerID); - GUIEngine::focusNothingForPlayer(m_playerID); + Widget* focus = GUIEngine::getFocusForPlayer(m_player_id); + GUIEngine::focusNothingForPlayer(m_player_id); // Change the player ID - m_playerID = newPlayerID; + m_player_id = newPlayerID; // restore previous focus, but with new player ID - if (focus != NULL) focus->setFocusForPlayer(m_playerID); + if (focus != NULL) focus->setFocusForPlayer(m_player_id); if (m_player_ident_spinner != NULL) - m_player_ident_spinner->setID(m_playerID); + m_player_ident_spinner->setID(m_player_id); } // setPlayerID // ------------------------------------------------------------------------ @@ -421,7 +422,7 @@ void PlayerKartWidget::setPlayerID(const int newPlayerID) int PlayerKartWidget::getPlayerID() const { assert(m_magic_number == 0x33445566); - return m_playerID; + return m_player_id; } // getPlayerID // ------------------------------------------------------------------------ @@ -432,7 +433,7 @@ void PlayerKartWidget::add() assert(KartSelectionScreen::getRunningInstance() ->m_kart_widgets.contains(this)); - if (m_associatedPlayer) // if player is local + if (m_associated_player) // if player is local { bool mineInList = false; for (unsigned int p=0; p<StateManager::get()->activePlayerCount(); p++) @@ -440,7 +441,7 @@ void PlayerKartWidget::add() #ifdef DEBUG assert(StateManager::get()->getActivePlayer(p)->ok()); #endif - if (StateManager::get()->getActivePlayer(p) == m_associatedPlayer) + if (StateManager::get()->getActivePlayer(p) == m_associated_player) { mineInList = true; } @@ -452,8 +453,8 @@ void PlayerKartWidget::add() // the first player will have an ID of its own to allow for keyboard // navigation despite this widget being added last - if (m_irrlicht_widget_ID != -1) - m_player_ident_spinner->m_reserved_id = m_irrlicht_widget_ID; + if (m_irrlicht_widget_id != -1) + m_player_ident_spinner->m_reserved_id = m_irrlicht_widget_id; else m_player_ident_spinner->m_reserved_id = Widget::getNewNoFocusID(); @@ -469,8 +470,8 @@ void PlayerKartWidget::add() m_player_ident_spinner->clearLabels(); irr::core::stringw name; // name of the player - if (m_associatedPlayer) - name = m_associatedPlayer->getProfile()->getName(); + if (m_associated_player) + name = m_associated_player->getProfile()->getName(); if (m_associated_user) name = m_associated_user->getUserName(); @@ -500,7 +501,7 @@ void PlayerKartWidget::add() StateManager::ActivePlayer* PlayerKartWidget::getAssociatedPlayer() { assert(m_magic_number == 0x33445566); - return m_associatedPlayer; + return m_associated_player; } // getAssociatedPlayer // ------------------------------------------------------------------------ @@ -672,7 +673,7 @@ void PlayerKartWidget::onUpdate(float delta) GUIEngine::EventPropagation PlayerKartWidget::transmitEvent( Widget* w, const std::string& originator, - const int m_playerID) + const int m_player_id) { assert(m_magic_number == 0x33445566); // if it's declared ready, there is really nothing to process @@ -692,7 +693,7 @@ GUIEngine::EventPropagation PlayerKartWidget::transmitEvent( if(UserConfigParams::logGUI()) { std::cout << "[KartSelectionScreen] Identity changed " - "for player " << m_playerID + "for player " << m_player_id << " : " << irr::core::stringc( m_player_ident_spinner->getStringValue() .c_str()).c_str() @@ -701,7 +702,7 @@ GUIEngine::EventPropagation PlayerKartWidget::transmitEvent( if (m_parent_screen->m_multiplayer) { - m_associatedPlayer->setPlayerProfile( + m_associated_player->setPlayerProfile( PlayerManager::get()->getPlayer(m_player_ident_spinner ->getValue()) ); } @@ -783,7 +784,7 @@ const std::string& PlayerKartWidget::getKartInternalName() const /** \brief Event callback from ISpinnerConfirmListener */ EventPropagation PlayerKartWidget::onSpinnerConfirmed() { - KartSelectionScreen::getRunningInstance()->playerConfirm(m_playerID); + KartSelectionScreen::getRunningInstance()->playerConfirm(m_player_id); return EVENT_BLOCK; } // onSpinnerConfirmed @@ -2014,7 +2015,7 @@ void KartSelectionScreen::setKartsFromCurrentGroup() { const KartProperties* prop = kart_properties_manager->getKartById(n); - if (unlock_manager->getCurrentSlot()->isLocked(prop->getIdent())) + if (PlayerManager::get()->getCurrentPlayer()->isLocked(prop->getIdent())) { w->addItem( _("Locked : solve active challenges to gain access " @@ -2046,7 +2047,7 @@ void KartSelectionScreen::setKartsFromCurrentGroup() kart_properties_manager->getKartById(group[n]); const std::string &icon_path = prop->getAbsoluteIconFile(); - if (unlock_manager->getCurrentSlot()->isLocked(prop->getIdent())) + if (PlayerManager::get()->getCurrentPlayer()->isLocked(prop->getIdent())) { w->addItem( _("Locked : solve active challenges to gain access " diff --git a/src/states_screens/kart_selection.hpp b/src/states_screens/kart_selection.hpp index 5c31f0a35..13f0be8f7 100644 --- a/src/states_screens/kart_selection.hpp +++ b/src/states_screens/kart_selection.hpp @@ -199,7 +199,7 @@ public: * management or badging */ class PlayerNameSpinner : public GUIEngine::SpinnerWidget { - int m_playerID; + int m_player_id; bool m_incorrect; irr::gui::IGUIImage* m_red_mark_widget; KartSelectionScreen* m_parent; @@ -235,16 +235,19 @@ class PlayerKartWidget : public GUIEngine::Widget, /** A reserved ID for this widget if any, -1 otherwise. (If no ID is * reserved, widget will not be in the regular tabbing order */ - int m_irrlicht_widget_ID; + int m_irrlicht_widget_id; /** For animation purposes (see method 'move') */ int target_x, target_y, target_w, target_h; float x_speed, y_speed, w_speed, h_speed; /** Object representing this player */ - StateManager::ActivePlayer* m_associatedPlayer; // local info - int m_playerID; - Online::Profile* m_associated_user; // network info + /** Local info about the player. */ + StateManager::ActivePlayer* m_associated_player; + int m_player_id; + + /** Network info about the user. */ + Online::Profile* m_associated_user; /** Internal name of the spinner; useful to interpret spinner events, * which contain the name of the activated object */ @@ -259,7 +262,6 @@ public: LEAK_CHECK() /** Sub-widgets created by this widget */ - //LabelWidget* m_player_ID_label; PlayerNameSpinner* m_player_ident_spinner; GUIEngine::ModelViewWidget* m_model_view; GUIEngine::LabelWidget* m_kart_name; @@ -275,11 +277,11 @@ public: bool m_not_updated_yet; PlayerKartWidget(KartSelectionScreen* parent, - StateManager::ActivePlayer* associatedPlayer, - Online::Profile* associatedUser, - core::recti area, const int playerID, - std::string kartGroup, - const int irrlichtWidgetID=-1); + StateManager::ActivePlayer* associated_player, + Online::Profile* associated_user, + core::recti area, const int player_id, + std::string kart_group, + const int irrlicht_idget_id=-1); // ------------------------------------------------------------------------ ~PlayerKartWidget(); @@ -322,7 +324,7 @@ public: virtual GUIEngine::EventPropagation transmitEvent( GUIEngine::Widget* w, const std::string& originator, - const int m_playerID); + const int m_player_id); // ------------------------------------------------------------------------- /** Sets the size of the widget as a whole, and placed children widgets From 18896ff95e1b9666563fbd3575c681d11468f24b Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Sun, 9 Feb 2014 22:56:50 +0100 Subject: [PATCH 13/68] Shadow: Support for alpha tested meshes. --- src/graphics/shaders.cpp | 22 ++++++++++++++++++++++ src/graphics/shaders.hpp | 11 +++++++++++ src/graphics/stkmesh.cpp | 30 ++++++++++++++++++++++++------ src/graphics/stkmesh.hpp | 2 +- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index df76d13f4..d6a284d79 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -259,6 +259,7 @@ void Shaders::loadShaders() MeshShader::BillboardShader::init(); MeshShader::DisplaceShader::init(); MeshShader::ShadowShader::init(); + MeshShader::RefShadowShader::init(); ParticleShader::FlipParticleRender::init(); ParticleShader::HeightmapSimulationShader::init(); ParticleShader::SimpleParticleRender::init(); @@ -891,6 +892,27 @@ namespace MeshShader glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); } + GLuint RefShadowShader::Program; + GLuint RefShadowShader::attrib_position; + GLuint RefShadowShader::attrib_texcoord; + GLuint RefShadowShader::uniform_MVP; + GLuint RefShadowShader::uniform_tex; + + void RefShadowShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/object_unlit.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_tex = glGetUniformLocation(Program, "tex"); + } + + void RefShadowShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniform1i(uniform_tex, TU_tex); + } + GLuint DisplaceShader::Program; GLuint DisplaceShader::attrib_position; GLuint DisplaceShader::attrib_texcoord; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 83788766e..09e370a63 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -236,6 +236,17 @@ public: static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); }; +class RefShadowShader +{ +public: + static GLuint Program; + static GLuint attrib_position, attrib_texcoord; + static GLuint uniform_MVP, uniform_tex; + + static void init(); + static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex); +}; + class DisplaceShader { public: diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index a3881ef3a..1d7a2bcc2 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -723,17 +723,28 @@ void STKMesh::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type) return; } -void STKMesh::drawShadow(const GLMesh &mesh) +void STKMesh::drawShadow(const GLMesh &mesh, video::E_MATERIAL_TYPE type) { + GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - assert(irr_driver->getPhase() == SHADOW_PASS); + core::matrix4 ShadowMVP; computeMVP(ShadowMVP); - glUseProgram(MeshShader::ShadowShader::Program); - MeshShader::ShadowShader::setUniforms(ShadowMVP); + + if (type == irr_driver->getShader(ES_OBJECTPASS_REF)) + { + setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + glUseProgram(MeshShader::RefShadowShader::Program); + MeshShader::RefShadowShader::setUniforms(ShadowMVP, 0); + } + else + { + glUseProgram(MeshShader::ShadowShader::Program); + MeshShader::ShadowShader::setUniforms(ShadowMVP); + } glBindVertexArray(mesh.vao_shadow_pass); glDrawElements(ptype, count, itype, 0); } @@ -928,7 +939,14 @@ void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type) case SHADOW_PASS: if (mesh.vao_shadow_pass) return; - mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); + if (type == irr_driver->getShader(ES_OBJECTPASS_REF)) + { + mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::RefShadowShader::attrib_position, MeshShader::RefShadowShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + } + else + { + mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); + } return; } } @@ -984,7 +1002,7 @@ void STKMesh::render() else if (irr_driver->getPhase() == SHADOW_PASS) { initvaostate(GLmeshes[i], material.MaterialType); - drawShadow(GLmeshes[i]); + drawShadow(GLmeshes[i], material.MaterialType); } else { diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 199c1e0b0..74cde2358 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -63,7 +63,7 @@ protected: // Misc passes shaders (glow, displace...) void drawGlow(const GLMesh &mesh); void drawDisplace(const GLMesh &mesh); - void drawShadow(const GLMesh &mesh); + void drawShadow(const GLMesh &mesh, video::E_MATERIAL_TYPE type); void createGLMeshes(); void cleanGLMeshes(); public: From 8d1591b260b70cd96eafeb75a72174475e5bf706 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 10 Feb 2014 08:57:16 +1100 Subject: [PATCH 14/68] Removed all references to current user/slot from unlock manager. --- src/challenges/unlock_manager.cpp | 14 -------------- src/challenges/unlock_manager.hpp | 6 ------ src/modes/overworld.cpp | 3 ++- src/modes/world.cpp | 2 +- src/network/protocols/start_game_protocol.cpp | 7 ++++--- src/states_screens/dialogs/player_info_dialog.cpp | 4 ++-- src/states_screens/help_screen_1.cpp | 3 ++- src/states_screens/kart_selection.cpp | 2 +- src/states_screens/main_menu_screen.cpp | 2 +- 9 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index f04f1ff4c..dbc1d50c7 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -49,8 +49,6 @@ UnlockManager::UnlockManager() // in main). unlock_manager = this; - m_current_game_slot = 0; - m_locked_sound = sfx_manager->createSoundSource("locked"); @@ -427,18 +425,6 @@ bool UnlockManager::isSupportedVersion(const ChallengeData &challenge) } // isSupportedVersion -//----------------------------------------------------------------------------- - -PlayerProfile* UnlockManager::getCurrentPlayer() -{ - for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++) - { - PlayerProfile* player = PlayerManager::get()->getPlayer(n); - if (player->getUniqueID() == m_current_game_slot) return player; - } - return NULL; -} - //----------------------------------------------------------------------------- void UnlockManager::findWhatWasUnlocked(int points_before, int points_now, diff --git a/src/challenges/unlock_manager.hpp b/src/challenges/unlock_manager.hpp index ae7ab658c..85b6db79b 100644 --- a/src/challenges/unlock_manager.hpp +++ b/src/challenges/unlock_manager.hpp @@ -52,9 +52,6 @@ private: void readAllChallengesInDirs(const std::vector<std::string>* all_dirs); - /** ID of the active player */ - unsigned int m_current_game_slot; - friend class GameSlot; public: @@ -73,13 +70,10 @@ public: /** Eye- (or rather ear-) candy. Play a sound when user tries to access a locked area */ void playLockSound() const; - unsigned int getCurrentSlotID() const { return m_current_game_slot; } - void findWhatWasUnlocked(int pointsBefore, int pointsNow, std::vector<std::string>& tracks, std::vector<std::string>& gps); - PlayerProfile* getCurrentPlayer(); GameSlot *createGameSlot(const XMLNode *node=NULL); }; // UnlockManager diff --git a/src/modes/overworld.cpp b/src/modes/overworld.cpp index 5064e254b..6ac263001 100644 --- a/src/modes/overworld.cpp +++ b/src/modes/overworld.cpp @@ -17,6 +17,7 @@ #include "audio/music_manager.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" #include "input/device_manager.hpp" #include "input/input.hpp" @@ -63,7 +64,7 @@ void OverWorld::enterOverWorld() InputDevice* device = input_manager->getDeviceList()->getKeyboard(0); // Create player and associate player with keyboard - StateManager::get()->createActivePlayer(unlock_manager->getCurrentPlayer(), + StateManager::get()->createActivePlayer(PlayerManager::get()->getCurrentPlayer(), device, NULL); if (!kart_properties_manager->getKart(UserConfigParams::m_default_kart)) diff --git a/src/modes/world.cpp b/src/modes/world.cpp index b3a18c07b..a2ae337c6 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -752,7 +752,7 @@ void World::updateWorld(float dt) InputDevice* device = input_manager->getDeviceList()->getKeyboard(0); // Create player and associate player with keyboard - StateManager::get()->createActivePlayer(unlock_manager->getCurrentPlayer(), + StateManager::get()->createActivePlayer(PlayerManager::get()->getCurrentPlayer(), device, NULL); if (!kart_properties_manager->getKart(UserConfigParams::m_default_kart)) diff --git a/src/network/protocols/start_game_protocol.cpp b/src/network/protocols/start_game_protocol.cpp index bbf478cd5..1700f18e6 100644 --- a/src/network/protocols/start_game_protocol.cpp +++ b/src/network/protocols/start_game_protocol.cpp @@ -1,5 +1,6 @@ #include "network/protocols/start_game_protocol.hpp" +#include "config/player_manager.hpp" #include "input/device_manager.hpp" #include "input/input_manager.hpp" #include "challenges/unlock_manager.hpp" @@ -113,14 +114,14 @@ void StartGameProtocol::update() rki.setGlobalPlayerId(profile->race_id); rki.setLocalPlayerId(is_me?0:1); rki.setHostId(profile->race_id); - PlayerProfile* profileToUse = unlock_manager->getCurrentPlayer(); - assert(profileToUse); + PlayerProfile* profile_to_use = PlayerManager::get()->getCurrentPlayer(); + assert(profile_to_use); InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice(); int new_player_id = 0; if (StateManager::get()->getActivePlayers().size() >= 1) // more than one player, we're the first new_player_id = 0; else - new_player_id = StateManager::get()->createActivePlayer( profileToUse, device , players[i]->user_profile); + new_player_id = StateManager::get()->createActivePlayer( profile_to_use, device , players[i]->user_profile); device->setPlayer(StateManager::get()->getActivePlayer(new_player_id)); input_manager->getDeviceList()->setSinglePlayer(StateManager::get()->getActivePlayer(new_player_id)); diff --git a/src/states_screens/dialogs/player_info_dialog.cpp b/src/states_screens/dialogs/player_info_dialog.cpp index 0f08be165..4f0f2709c 100644 --- a/src/states_screens/dialogs/player_info_dialog.cpp +++ b/src/states_screens/dialogs/player_info_dialog.cpp @@ -156,7 +156,7 @@ void PlayerInfoDialog::showConfirmDialog() _("Do you really want to delete player '%s' ?", m_player->getName()); - if (unlock_manager->getCurrentSlotID() == m_player->getUniqueID()) + if (PlayerManager::get()->getCurrentPlayer() == m_player) { message = _("You cannot delete this player because it is currently in use."); } @@ -171,7 +171,7 @@ void PlayerInfoDialog::showConfirmDialog() m_irrlicht_window); a->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); - if (unlock_manager->getCurrentSlotID() != m_player->getUniqueID()) + if (PlayerManager::get()->getCurrentPlayer() != m_player) { ButtonWidget* widget = new ButtonWidget(); widget->m_properties[PROP_ID] = "confirmremove"; diff --git a/src/states_screens/help_screen_1.cpp b/src/states_screens/help_screen_1.cpp index a75d43286..d8ca787b7 100644 --- a/src/states_screens/help_screen_1.cpp +++ b/src/states_screens/help_screen_1.cpp @@ -18,6 +18,7 @@ #include "states_screens/help_screen_1.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "guiengine/widget.hpp" #include "guiengine/widgets/list_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp" @@ -64,7 +65,7 @@ void HelpScreen1::eventCallback(Widget* widget, const std::string& name, const i InputDevice* device = input_manager->getDeviceList()->getKeyboard(0); // Create player and associate player with keyboard - StateManager::get()->createActivePlayer(unlock_manager->getCurrentPlayer(), + StateManager::get()->createActivePlayer(PlayerManager::get()->getCurrentPlayer(), device, NULL); if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL) diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 4f97c0339..8f9e06c8b 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -1100,7 +1100,7 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer) kartsAreaWidget->m_y + kartsAreaWidget->m_h); // ---- Create new active player - PlayerProfile* profile_to_use = unlock_manager->getCurrentPlayer(); + PlayerProfile* profile_to_use = PlayerManager::get()->getCurrentPlayer(); if (!firstPlayer) { diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index c4c8c4158..5ffba1630 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -340,7 +340,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, InputDevice* device = input_manager->getDeviceList()->getKeyboard(0); // Create player and associate player with keyboard - StateManager::get()->createActivePlayer(unlock_manager->getCurrentPlayer(), + StateManager::get()->createActivePlayer(PlayerManager::get()->getCurrentPlayer(), device, NULL); if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL) From 4fd130b2acab16908134069667bea5c2eeb984c4 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Sun, 9 Feb 2014 23:24:01 +0100 Subject: [PATCH 15/68] Shadow: Grass now cast shadows. --- src/graphics/shaders.cpp | 27 +++++++++++++++++++++++++++ src/graphics/shaders.hpp | 11 +++++++++++ src/graphics/stkmesh.cpp | 10 ++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index d6a284d79..7ab06e31e 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -260,6 +260,7 @@ void Shaders::loadShaders() MeshShader::DisplaceShader::init(); MeshShader::ShadowShader::init(); MeshShader::RefShadowShader::init(); + MeshShader::GrassShadowShader::init(); ParticleShader::FlipParticleRender::init(); ParticleShader::HeightmapSimulationShader::init(); ParticleShader::SimpleParticleRender::init(); @@ -913,6 +914,32 @@ namespace MeshShader glUniform1i(uniform_tex, TU_tex); } + GLuint GrassShadowShader::Program; + GLuint GrassShadowShader::attrib_position; + GLuint GrassShadowShader::attrib_texcoord; + GLuint GrassShadowShader::attrib_color; + GLuint GrassShadowShader::uniform_MVP; + GLuint GrassShadowShader::uniform_tex; + GLuint GrassShadowShader::uniform_windDir; + + void GrassShadowShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/grass_pass2.vert").c_str(), file_manager->getAsset("shaders/object_unlit.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_tex = glGetUniformLocation(Program, "tex"); + attrib_color = glGetAttribLocation(Program, "Color"); + uniform_windDir = glGetUniformLocation(Program, "windDir"); + } + + void GrassShadowShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection, unsigned TU_tex) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniform1i(uniform_tex, TU_tex); + glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z); + } + GLuint DisplaceShader::Program; GLuint DisplaceShader::attrib_position; GLuint DisplaceShader::attrib_texcoord; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 09e370a63..75172cd6e 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -247,6 +247,17 @@ public: static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex); }; +class GrassShadowShader +{ +public: + static GLuint Program; + static GLuint attrib_position, attrib_texcoord, attrib_color; + static GLuint uniform_MVP, uniform_tex, uniform_windDir; + + static void init(); + static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection, unsigned TU_tex); +}; + class DisplaceShader { public: diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 1d7a2bcc2..34dfc14d8 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -740,6 +740,12 @@ void STKMesh::drawShadow(const GLMesh &mesh, video::E_MATERIAL_TYPE type) glUseProgram(MeshShader::RefShadowShader::Program); MeshShader::RefShadowShader::setUniforms(ShadowMVP, 0); } + else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF)) + { + setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + glUseProgram(MeshShader::GrassShadowShader::Program); + MeshShader::GrassShadowShader::setUniforms(ShadowMVP, windDir, 0); + } else { glUseProgram(MeshShader::ShadowShader::Program); @@ -943,6 +949,10 @@ void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type) { mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::RefShadowShader::attrib_position, MeshShader::RefShadowShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); } + else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF)) + { + mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::GrassShadowShader::attrib_position, MeshShader::GrassShadowShader::attrib_texcoord, -1, -1, -1, -1, MeshShader::GrassShadowShader::attrib_color, mesh.Stride); + } else { mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); From 16521fce5a580d3aa2abefc1268e830d6cb7b834 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@mgail.com> Date: Mon, 10 Feb 2014 15:28:13 +1100 Subject: [PATCH 16/68] Removed loading and saving of challenge.xml file. --- src/challenges/unlock_manager.cpp | 184 ------------------ src/challenges/unlock_manager.hpp | 5 - src/states_screens/options_screen_players.cpp | 3 - 3 files changed, 192 deletions(-) diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index dbc1d50c7..d602d937d 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -76,8 +76,6 @@ UnlockManager::UnlockManager() // Hard coded challenges can be added here. - load(); - } // UnlockManager //----------------------------------------------------------------------------- @@ -85,8 +83,6 @@ UnlockManager::UnlockManager() */ UnlockManager::~UnlockManager() { - save(); - for(AllChallengesType::iterator i =m_all_challenges.begin(); i!=m_all_challenges.end(); i++) { @@ -202,60 +198,6 @@ const ChallengeData* UnlockManager::getChallenge(const std::string& id) return it->second; } // getChallenge -//----------------------------------------------------------------------------- -/** This is called from user_config when reading the config file -*/ -void UnlockManager::load() -{ - const std::string filename=file_manager->getUserConfigFile("challenges.xml"); - XMLNode* root = file_manager->createXMLTree(filename); - if(!root || root->getName() != "challenges") - { - Log::info("unlock_manager", "Challenge file '%s' will be created.", - filename.c_str()); -// createSlotsIfNeeded(); - save(); - - if (root) delete root; - return; - } - - std::vector<XMLNode*> xml_game_slots; - root->getNodes("gameslot", xml_game_slots); - for (unsigned int n=0; n<xml_game_slots.size(); n++) - { - unsigned int player_id; - if (!xml_game_slots[n]->get("playerID", &player_id)) - { - Log::warn("unlock_manager", "Found game slot without " - "a player ID attached. Discarding it."); - continue; - } - - GameSlot* slot = new GameSlot(NULL); - - m_game_slots[player_id] = slot; - - - for(AllChallengesType::iterator i = m_all_challenges.begin(); - i!=m_all_challenges.end(); i++) - { - ChallengeData* curr = i->second; - Challenge* state = new Challenge(curr); - - slot->m_challenges_state[curr->getId()] = state; - state->load(xml_game_slots[n]); - } - slot->computeActive(); - } - - // FIXME -// bool something_changed = createSlotsIfNeeded(); -// if (something_changed) save(); - - delete root; -} // load - //----------------------------------------------------------------------------- /** Creates a game slot. It initialises the game slot's status with the * information in the xml node (if given), basically restoring the saved @@ -281,132 +223,6 @@ GameSlot *UnlockManager::createGameSlot(const XMLNode *node) return slot; } // createGameSlot -//----------------------------------------------------------------------------- - -void UnlockManager::save() -{ - std::string filename = file_manager->getUserConfigFile("challenges.xml"); - - std::ofstream challenge_file(filename.c_str(), std::ios::out); - - if (!challenge_file.is_open()) - { - Log::warn("unlock_manager", - "Failed to open '%s' for writing, challenges won't be saved\n", - filename.c_str()); - return; - } - - challenge_file << "<?xml version=\"1.0\"?>\n"; - challenge_file << "<challenges>\n"; - - std::map<unsigned int, GameSlot*>::iterator it; - for (it = m_game_slots.begin(); it != m_game_slots.end(); it++) - { - std::string name = "unknown player"; - for (unsigned int i = 0; i < PlayerManager::get()->getNumPlayers(); i++) - { - const PlayerProfile *player = PlayerManager::get()->getPlayer(i); - if (player->getUniqueID() == it->second->getPlayerID()) - { - name = core::stringc(player->getName().c_str()).c_str(); - break; - } - } - -//FIXME it->second->save(challenge_file, name); - } - - challenge_file << "</challenges>\n\n"; - challenge_file.close(); -} // save - -//----------------------------------------------------------------------------- -/** Creates a gameslot for players that don't have one yet - * \return true if any were created - */ -bool UnlockManager::createSlotsIfNeeded() -{ - bool something_changed = false; - - // make sure all players have at least one game slot associated - for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++) - { - bool exists = false; - - const PlayerProfile *profile = PlayerManager::get()->getPlayer(n); - std::map<unsigned int, GameSlot*>::iterator it; - for (it = m_game_slots.begin(); it != m_game_slots.end(); it++) - { - GameSlot* curr_slot = it->second; - if (curr_slot->getPlayerID() == profile->getUniqueID()) - { - exists = true; - break; - } - } // for it in m_game_slots - - if (!exists) - { - GameSlot* slot = new GameSlot(NULL); - for(AllChallengesType::iterator i = m_all_challenges.begin(); - i!=m_all_challenges.end(); i++) - { - ChallengeData* cd = i->second; - slot->m_challenges_state[cd->getId()] = new Challenge(cd); - } - slot->computeActive(); - - m_game_slots[profile->getUniqueID()] = slot; - - something_changed = true; - } - } - - return something_changed; -} // UnlockManager::createSlotsIfNeeded - -//----------------------------------------------------------------------------- -/** Removes gameslots that refer to a non-existing player. - * \return true if any were removed - */ -bool UnlockManager::deleteSlotsIfNeeded() -{ - bool changed = false; - std::map<unsigned int, GameSlot*>::iterator it = m_game_slots.begin(); - while (it != m_game_slots.end()) - { - bool found = false; - const int player_amount = PlayerManager::get()->getNumPlayers(); - for (int i = 0; i < player_amount; i++) - { - if (it->second->getPlayerID() == - PlayerManager::get()->getPlayer(i)->getUniqueID()) - { - found = true; - break; - } - } // for players - - if (!found) - { -#ifdef DEBUG - printf("Deleting gameslot %d, no player found.\n", - it->second->getPlayerID()); -#endif - // Iterators aren't invalidated this way - m_game_slots.erase(it++); - changed = true; - } - else - { - ++it; - } - } // for gameslots - - return changed; -} // UnlockManager::deleteSlotsIfNeeded - //----------------------------------------------------------------------------- void UnlockManager::playLockSound() const { diff --git a/src/challenges/unlock_manager.hpp b/src/challenges/unlock_manager.hpp index 85b6db79b..dd4c54987 100644 --- a/src/challenges/unlock_manager.hpp +++ b/src/challenges/unlock_manager.hpp @@ -43,8 +43,6 @@ class UnlockManager : public NoCopy private: SFXBase *m_locked_sound; - void load (); - typedef std::map<std::string, ChallengeData*> AllChallengesType; AllChallengesType m_all_challenges; @@ -59,9 +57,6 @@ public: ~UnlockManager (); void addOrFreeChallenge(ChallengeData *c); void addChallenge (const std::string& filename); - void save (); - bool createSlotsIfNeeded(); - bool deleteSlotsIfNeeded(); const ChallengeData *getChallenge (const std::string& id); diff --git a/src/states_screens/options_screen_players.cpp b/src/states_screens/options_screen_players.cpp index 945916eba..c1bf7264a 100644 --- a/src/states_screens/options_screen_players.cpp +++ b/src/states_screens/options_screen_players.cpp @@ -136,9 +136,6 @@ void OptionsScreenPlayers::tearDown() { Screen::tearDown(); user_config->saveConfig(); - bool created = unlock_manager->createSlotsIfNeeded(); - bool removed = unlock_manager->deleteSlotsIfNeeded(); - if (created || removed) unlock_manager->save(); } // tearDown // ----------------------------------------------------------------------------- From 230e1789f20fcfce422f208437e0a558a944ea61 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 10 Feb 2014 16:54:31 +1100 Subject: [PATCH 17/68] Made sorting of players descending (instead of using > in operator<), removed kart and unique id from game slot, replaced some forgotten calls to unlock_manager with calls to PlayerManager. --- src/challenges/game_slot.cpp | 8 +++----- src/challenges/game_slot.hpp | 9 --------- src/config/player.cpp | 9 +++------ src/config/player_manager.cpp | 2 +- src/io/utf_writer.hpp | 5 +---- src/modes/cutscene_world.cpp | 2 +- src/states_screens/dialogs/enter_player_name_dialog.cpp | 4 +--- 7 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/challenges/game_slot.cpp b/src/challenges/game_slot.cpp index 2b918bbb5..63c529ff7 100644 --- a/src/challenges/game_slot.cpp +++ b/src/challenges/game_slot.cpp @@ -22,13 +22,13 @@ #include "challenges/challenge.hpp" #include "challenges/challenge_data.hpp" #include "challenges/unlock_manager.hpp" +#include "config/player_manager.hpp" #include "io/utf_writer.hpp" #include "io/xml_node.hpp" //----------------------------------------------------------------------------- GameSlot::GameSlot(const XMLNode *node) { - m_kart_ident = ""; m_points = 0; m_first_time = true; m_easy_challenges = 0; @@ -39,7 +39,6 @@ GameSlot::GameSlot(const XMLNode *node) // If there is saved data, load it if(node) { - node->get("kart", &m_kart_ident); node->get("first-time", &m_first_time); for(unsigned int i=0; i<node->getNumNodes(); i++) @@ -201,7 +200,7 @@ void GameSlot::unlockFeature(Challenge* c, RaceManager::Difficulty d, if (p == m_locked_features.end()) { c->setSolved(d); - if(do_save) unlock_manager->save(); + if(do_save) PlayerManager::get()->save(); return; } m_locked_features.erase(p); @@ -212,7 +211,7 @@ void GameSlot::unlockFeature(Challenge* c, RaceManager::Difficulty d, c->setSolved(d); // reset isActive flag // Save the new unlock information - if (do_save) unlock_manager->save(); + if (do_save) PlayerManager::get()->save(); } // unlockFeature //----------------------------------------------------------------------------- @@ -267,7 +266,6 @@ void GameSlot::grandPrixFinished() void GameSlot::save(UTFWriter &out) { out << L" <game-slot playerID=\"" << m_player_unique_id - << L"\" kart=\"" << m_kart_ident << L"\" firstTime=\"" << m_first_time << L"\">\n"; std::map<std::string, Challenge*>::const_iterator i; for(i = m_challenges_state.begin(); diff --git a/src/challenges/game_slot.hpp b/src/challenges/game_slot.hpp index f1ff2d09a..586b2a80a 100644 --- a/src/challenges/game_slot.hpp +++ b/src/challenges/game_slot.hpp @@ -43,8 +43,6 @@ const int CHALLENGE_POINTS[] = { 8, 9, 10 }; class GameSlot { - std::string m_kart_ident; - /** Profile names can change, so rather than try to make sure all renames * are done everywhere, assign a unique ID to each profiler. * Will save much headaches. @@ -80,8 +78,6 @@ public: GameSlot(const XMLNode *node=NULL); ~GameSlot(); - unsigned int getPlayerID() const { return m_player_unique_id; } - const std::string& getKartIdent () const { return m_kart_ident; } void computeActive(); bool isLocked (const std::string& feature); void lockFeature (Challenge *challenge); @@ -92,11 +88,6 @@ public: void save (UTFWriter &out); void setCurrentChallenge(const std::string &challenge_id); - // ------------------------------------------------------------------------ - void setKartIdent(const std::string& kart_ident) - { - m_kart_ident = kart_ident; - } // ------------------------------------------------------------------------ /** Returns the list of recently unlocked features (e.g. call at the end * of a race to know if any features were unlocked) */ diff --git a/src/config/player.cpp b/src/config/player.cpp index 08f8c31a3..c93469134 100644 --- a/src/config/player.cpp +++ b/src/config/player.cpp @@ -91,21 +91,18 @@ void PlayerProfile::incrementUseFrequency() } // incrementUseFrequency //------------------------------------------------------------------------------ -/** Comparison used to sort players. Most frequent players should be - * listed first, so a<b actually means that - * a.m_use_frequency > b.m_use_frequency - * This way we get a reversed sorted list. +/** Comparison used to sort players. */ bool PlayerProfile::operator<(const PlayerProfile &other) { - return getUseFrequency() > other.getUseFrequency(); + return getUseFrequency() < other.getUseFrequency(); } // operator< // ----------------------------------------------------------------------------- /** \brief Needed for toggling sort order **/ bool PlayerProfile::operator>(const PlayerProfile &other) { - return getUseFrequency() < other.getUseFrequency(); + return getUseFrequency() > other.getUseFrequency(); } // operator> // ----------------------------------------------------------------------------- diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index 4a6b1473c..de7cc84c7 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -88,7 +88,7 @@ void PlayerManager::load() if(player->isDefault()) m_current_player = player; } - m_all_players.insertionSort(); + m_all_players.insertionSort(/*start*/0, /*desc*/true); if(!m_current_player) { diff --git a/src/io/utf_writer.hpp b/src/io/utf_writer.hpp index df51af9c2..399eb1095 100644 --- a/src/io/utf_writer.hpp +++ b/src/io/utf_writer.hpp @@ -52,10 +52,7 @@ public: template<typename T> UTFWriter& operator<< (const T t) { - irr::core::stringw tmp; - tmp += t; - (*this) << tmp; - return *this; + return operator<<(StringUtils::toString<T>(t)); } // operator<< (template) // ------------------------------------------------------------------------ bool is_open() { return m_base.is_open(); } diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index 196658230..4213caaf8 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -385,7 +385,7 @@ void CutsceneWorld::enterRaceOverState() StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); player->setFirstTime(false); - unlock_manager->save(); + PlayerManager::get()->save(); KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance(); s->setMultiplayer(false); s->setGoToOverworldNext(); diff --git a/src/states_screens/dialogs/enter_player_name_dialog.cpp b/src/states_screens/dialogs/enter_player_name_dialog.cpp index 1749e7a58..6df6ec015 100644 --- a/src/states_screens/dialogs/enter_player_name_dialog.cpp +++ b/src/states_screens/dialogs/enter_player_name_dialog.cpp @@ -121,9 +121,7 @@ void EnterPlayerNameDialog::onEnterPressedInternal() // Finally, add the new player. PlayerManager::get()->addNewPlayer(player_name); - bool created = unlock_manager->createSlotsIfNeeded(); - if (created) unlock_manager->save(); - user_config->saveConfig(); + PlayerManager::get()->save(); // It's unsafe to delete from inside the event handler so we do it // in onUpdate (which checks for m_self_destroy) From 748dcf1e15e1a33100f90a615e546765307fdf58 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 10 Feb 2014 21:35:13 +1100 Subject: [PATCH 18/68] Fixed running on hd3000 (8192 was too big for my system, not sure what values should be used best, I used the previous code here). --- src/graphics/rtts.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 288dc63b6..a5bab022b 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -37,7 +37,7 @@ RTT::RTT() const dimension2du ssaosize = UserConfigParams::m_ssao == 2 ? res : quarter; const u16 shadowside = 8192; - const dimension2du shadowsize(shadowside, shadowside); + dimension2du shadowsize(shadowside, shadowside); const dimension2du warpvsize(1, 512); const dimension2du warphsize(512, 1); @@ -88,6 +88,12 @@ RTT::RTT() rtts[RTT_SSAO] = drv->addRenderTargetTexture(ssaosize, "rtt.ssao", ECF_R8, stencil); rtts[RTT_SHADOW] = drv->addRenderTargetTexture(shadowsize, "rtt.shadow", ECF_A8R8G8B8, stencil); + if(!rtts[RTT_SHADOW]) + { + int n = UserConfigParams::m_shadows == 2 ? 2048 : 512; + shadowsize.set(n, n); + rtts[RTT_SHADOW] = drv->addRenderTargetTexture(shadowsize, "rtt.shadow", ECF_A8R8G8B8, stencil); + } rtts[RTT_WARPV] = drv->addRenderTargetTexture(warpvsize, "rtt.warpv", ECF_A8R8G8B8, stencil); rtts[RTT_WARPH] = drv->addRenderTargetTexture(warphsize, "rtt.warph", ECF_A8R8G8B8, stencil); From ad2dcff431a3260b0b0f88b7236577c787939d02 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Mon, 10 Feb 2014 15:39:52 +0100 Subject: [PATCH 19/68] Revert "Fixed running on hd3000 (8192 was too big for my system, not sure" This reverts commit 748dcf1e15e1a33100f90a615e546765307fdf58. --- src/graphics/rtts.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index a5bab022b..288dc63b6 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -37,7 +37,7 @@ RTT::RTT() const dimension2du ssaosize = UserConfigParams::m_ssao == 2 ? res : quarter; const u16 shadowside = 8192; - dimension2du shadowsize(shadowside, shadowside); + const dimension2du shadowsize(shadowside, shadowside); const dimension2du warpvsize(1, 512); const dimension2du warphsize(512, 1); @@ -88,12 +88,6 @@ RTT::RTT() rtts[RTT_SSAO] = drv->addRenderTargetTexture(ssaosize, "rtt.ssao", ECF_R8, stencil); rtts[RTT_SHADOW] = drv->addRenderTargetTexture(shadowsize, "rtt.shadow", ECF_A8R8G8B8, stencil); - if(!rtts[RTT_SHADOW]) - { - int n = UserConfigParams::m_shadows == 2 ? 2048 : 512; - shadowsize.set(n, n); - rtts[RTT_SHADOW] = drv->addRenderTargetTexture(shadowsize, "rtt.shadow", ECF_A8R8G8B8, stencil); - } rtts[RTT_WARPV] = drv->addRenderTargetTexture(warpvsize, "rtt.warpv", ECF_A8R8G8B8, stencil); rtts[RTT_WARPH] = drv->addRenderTargetTexture(warphsize, "rtt.warph", ECF_A8R8G8B8, stencil); From 515bcbc7508894249ab88477d033c612f84c7de9 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Mon, 10 Feb 2014 14:20:09 +0100 Subject: [PATCH 20/68] Shadow: very crude csm support --- data/shaders/sunlightshadow.frag | 67 ++++++++----- src/graphics/callbacks.cpp | 4 +- src/graphics/irr_driver.hpp | 2 +- src/graphics/post_processing.cpp | 14 ++- src/graphics/post_processing.hpp | 2 +- src/graphics/render.cpp | 164 +++++++++++++++++++------------ src/graphics/rtts.cpp | 14 ++- src/graphics/rtts.hpp | 4 +- src/graphics/shaders.cpp | 26 +++-- src/graphics/shaders.hpp | 4 +- src/graphics/sun.cpp | 2 +- 11 files changed, 191 insertions(+), 112 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 4fe0f9313..88e4173e6 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -1,14 +1,18 @@ #version 130 uniform sampler2D ntex; uniform sampler2D dtex; -uniform sampler2DShadow shadowtex; +uniform sampler2DShadow shadowtex0; +uniform sampler2DShadow shadowtex1; +uniform sampler2DShadow shadowtex2; //uniform sampler2D warpx; ///uniform sampler2D warpy; uniform vec3 direction; uniform vec3 col; uniform mat4 invproj; -uniform mat4 shadowmat; +uniform mat4 shadowmat0; +uniform mat4 shadowmat1; +uniform mat4 shadowmat2; //uniform int hasclouds; //uniform vec2 wind; //uniform float shadowoffset; @@ -24,20 +28,47 @@ vec3 DecodeNormal(vec2 n) return vec3(xy,z); } +float getShadowFactor(vec3 pos, float bias) +{ + if (pos.z < 10.) + { + vec4 shadowcoord = (shadowmat0 * vec4(pos, 1.0)); + shadowcoord /= shadowcoord.w; + vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; +// shadowcoord = (shadowcoord * 0.5) + vec3(0.5); + +// float movex = decdepth(texture(warpx, shadowcoord.xy)); +// float movey = decdepth(texture(warpy, shadowcoord.xy)); +// float dx = movex * 2.0 - 1.0; +// float dy = movey * 2.0 - 1.0; +// shadowcoord.xy += vec2(dx, dy);*/ + + //float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.; + // bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping + return texture(shadowtex0, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias) + 0.5)); + } + else if (pos.z < 60) + { + vec4 shadowcoord = (shadowmat1 * vec4(pos, 1.0)); + shadowcoord /= shadowcoord.w; + vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; + return texture(shadowtex1, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias) + 0.5)); + } + else + { + vec4 shadowcoord = (shadowmat2 * vec4(pos, 1.0)); + shadowcoord /= shadowcoord.w; + vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; + return texture(shadowtex2, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias) + 0.5)); + } +} + void main() { float z = texture(dtex, uv).x; vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0; xpos = invproj * xpos; xpos.xyz /= xpos.w; - if (z < 0.03) - { - // Skyboxes are fully lit - Diff = vec4(1.0); - Spec = vec4(1.0); - return; - } - vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.)); // Normalized on the cpu @@ -60,23 +91,9 @@ void main() { // } // Shadows - vec4 shadowcoord = (shadowmat * vec4(xpos.xyz, 1.0)); - shadowcoord /= shadowcoord.w; - vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; -// shadowcoord = (shadowcoord * 0.5) + vec3(0.5); - -// float movex = decdepth(texture(warpx, shadowcoord.xy)); -// float movey = decdepth(texture(warpy, shadowcoord.xy)); -// float dx = movex * 2.0 - 1.0; -// float dy = movey * 2.0 - 1.0; -// shadowcoord.xy += vec2(dx, dy);*/ - - //float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.; float bias = 0.002 * tan(acos(NdotL)); // According to the slope - // bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping bias = clamp(bias, 0.001, 0.014); - float factor = texture(shadowtex, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias) + 0.5)); - + float factor = getShadowFactor(xpos.xyz, bias); Diff = vec4(factor * NdotL * col, 1.); Spec = vec4(factor * Specular * col, 1.); return; diff --git a/src/graphics/callbacks.cpp b/src/graphics/callbacks.cpp index 889a75517..1b61deba6 100644 --- a/src/graphics/callbacks.cpp +++ b/src/graphics/callbacks.cpp @@ -335,8 +335,8 @@ void SunLightProvider::OnSetConstants(IMaterialRendererServices *srv, int) tex = 5; srv->setVertexShaderConstant("warpy", &tex, 1); - const float shadowoffset = 1.0f / irr_driver->getRTT(RTT_SHADOW)->getSize().Width; - srv->setVertexShaderConstant("shadowoffset", &shadowoffset, 1); +// const float shadowoffset = 1.0f / irr_driver->getRTT(RTT_SHADOW)->getSize().Width; +// srv->setVertexShaderConstant("shadowoffset", &shadowoffset, 1); firstdone = true; } diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 9a2fbda5c..f0e2e3b0c 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -102,7 +102,7 @@ private: RTT *m_rtts; /** Shadow importance. */ ShadowImportance *m_shadow_importance; - core::matrix4 sun_ortho_matrix; + core::matrix4 sun_ortho_matrix[3]; /** Additional details to be shown in case that a texture is not found. * This is used to specify details like: "while loading kart '...'" */ diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 27415cbf2..bf4dbff00 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -346,7 +346,7 @@ void PostProcessing::renderSunlight() glBindVertexArray(0); } -void PostProcessing::renderShadowedSunlight(const core::matrix4 &sun_ortho_matrix) +void PostProcessing::renderShadowedSunlight(const core::matrix4 &sun_ortho_matrix0, const core::matrix4 &sun_ortho_matrix1, const core::matrix4 &sun_ortho_matrix2) { SunLightProvider * const cb = (SunLightProvider *)irr_driver->getCallback(ES_SUNLIGHT); @@ -359,10 +359,16 @@ void PostProcessing::renderShadowedSunlight(const core::matrix4 &sun_ortho_matri glBindVertexArray(FullScreenShader::ShadowedSunLightShader::vao); setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); - setTexture(2, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW))->DepthBufferTexture, GL_LINEAR, GL_LINEAR); + setTexture(2, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW0))->DepthBufferTexture, GL_LINEAR, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - FullScreenShader::ShadowedSunLightShader::setUniforms(sun_ortho_matrix, cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2); + setTexture(3, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW1))->DepthBufferTexture, GL_LINEAR, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + setTexture(4, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW2))->DepthBufferTexture, GL_LINEAR, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + FullScreenShader::ShadowedSunLightShader::setUniforms(sun_ortho_matrix0, sun_ortho_matrix1, sun_ortho_matrix2, cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2, 3, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindVertexArray(0); } @@ -849,7 +855,7 @@ void PostProcessing::render() else if (irr_driver->getSSAOViz()) renderPassThrough(irr_driver->getRTT(RTT_SSAO)); else if (irr_driver->getShadowViz()) - renderPassThrough(static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW))->DepthBufferTexture); + renderPassThrough(static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW0))->DepthBufferTexture); else renderColorLevel(in); } diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index b6c83a792..db2c680bc 100644 --- a/src/graphics/post_processing.hpp +++ b/src/graphics/post_processing.hpp @@ -75,7 +75,7 @@ public: /** Generate diffuse and specular map */ void renderPointlight(const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy); void renderSunlight(); - void renderShadowedSunlight(const core::matrix4 &sun_ortho_matrix); + void renderShadowedSunlight(const core::matrix4 &sun_ortho_matrix0, const core::matrix4 &sun_ortho_matrix1, const core::matrix4 &sun_ortho_matrix2); void renderFog(const core::matrix4 &ipvmat); void renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm); diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index b937b4cfd..54c216227 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -470,60 +470,112 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, Camera * const camera) { m_scene_manager->setCurrentRendertime(scene::ESNRP_SOLID); - static u8 tick = 0; const Vec3 *vmin, *vmax; World::getWorld()->getTrack()->getAABB(&vmin, &vmax); - core::aabbox3df trackbox(vmin->toIrrVector(), vmax->toIrrVector() - - core::vector3df(0, 30, 0)); + + ITexture *ShadowRTT[] = { + m_rtts->getRTT(RTT_SHADOW0), + m_rtts->getRTT(RTT_SHADOW1), + m_rtts->getRTT(RTT_SHADOW2) + }; + + unsigned rtt_size[] = { + 2048, + 1024, + 512, + }; const float oldfar = camnode->getFarValue(); - camnode->setFarValue(std::min(100.0f, oldfar)); - camnode->render(); - const core::aabbox3df smallcambox = camnode-> - getViewFrustum()->getBoundingBox(); + const float oldnear = camnode->getNearValue(); + float FarValues[] = + { + 10., + 60., + oldfar, + }; + float NearValues[] = + { + oldnear, + 10., + 60., + }; + + const core::matrix4 &SunCamViewMatrix = m_suncam->getViewMatrix(); + + // Build the 3 ortho projection (for the 3 shadow resolution levels) + for (unsigned i = 0; i < 3; i++) + { + camnode->setFarValue(FarValues[i]); + camnode->setNearValue(NearValues[i]); + camnode->render(); + const core::aabbox3df smallcambox = camnode-> + getViewFrustum()->getBoundingBox(); + core::aabbox3df trackbox(vmin->toIrrVector(), vmax->toIrrVector() - + core::vector3df(0, 30, 0)); + + + // Set up a nice ortho projection that contains our camera frustum + core::aabbox3df box = smallcambox; + box = box.intersect(trackbox); + + + SunCamViewMatrix.transformBoxEx(trackbox); + SunCamViewMatrix.transformBoxEx(box); + + core::vector3df extent = trackbox.getExtent(); + const float w = fabsf(extent.X); + const float h = fabsf(extent.Y); + float z = box.MaxEdge.Z; + + // Snap to texels + const float units_per_w = w / rtt_size[i]; + const float units_per_h = h / rtt_size[i]; + + float left = box.MinEdge.X; + float right = box.MaxEdge.X; + float up = box.MaxEdge.Y; + float down = box.MinEdge.Y; + + left -= fmodf(left, units_per_w); + right -= fmodf(right, units_per_w); + up -= fmodf(up, units_per_h); + down -= fmodf(down, units_per_h); + z -= fmodf(z, 0.5f); + + // FIXME: quick and dirt (and wrong) workaround to avoid division by zero + if (left == right) right += 0.1f; + if (up == down) down += 0.1f; + if (z == 30) z += 0.1f; + + core::matrix4 tmp_matrix; + + tmp_matrix.buildProjectionMatrixOrthoLH(left, right, + up, down, + 30, z); + m_suncam->setProjectionMatrix(tmp_matrix, true); + m_scene_manager->setActiveCamera(m_suncam); + m_suncam->render(); + + sun_ortho_matrix[i] = getVideoDriver()->getTransform(video::ETS_PROJECTION); + sun_ortho_matrix[i] *= getVideoDriver()->getTransform(video::ETS_VIEW); + sun_ortho_matrix[i] *= getInvViewMatrix(); + irr_driver->setPhase(SHADOW_PASS); + glDisable(GL_BLEND); + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + m_video_driver->setRenderTarget(ShadowRTT[i], true, true); + glDrawBuffer(GL_NONE); + m_scene_manager->drawAll(scene::ESNRP_SOLID); + glCullFace(GL_BACK); + } + + camnode->setNearValue(oldnear); camnode->setFarValue(oldfar); camnode->render(); + camera->activate(); + m_scene_manager->drawAll(scene::ESNRP_CAMERA); - // Set up a nice ortho projection that contains our camera frustum - core::aabbox3df box = smallcambox; - box = box.intersect(trackbox); - - m_suncam->getViewMatrix().transformBoxEx(box); - m_suncam->getViewMatrix().transformBoxEx(trackbox); - - core::vector3df extent = trackbox.getExtent(); - const float w = fabsf(extent.X); - const float h = fabsf(extent.Y); - float z = box.MaxEdge.Z; - - // Snap to texels - const float units_per_w = w / m_rtts->getRTT(RTT_SHADOW)->getSize().Width; - const float units_per_h = h / m_rtts->getRTT(RTT_SHADOW)->getSize().Height; - - float left = box.MinEdge.X; - float right = box.MaxEdge.X; - float up = box.MaxEdge.Y; - float down = box.MinEdge.Y; - - left -= fmodf(left, units_per_w); - right -= fmodf(right, units_per_w); - up -= fmodf(up, units_per_h); - down -= fmodf(down, units_per_h); - z -= fmodf(z, 0.5f); - - // FIXME: quick and dirt (and wrong) workaround to avoid division by zero - if (left == right) right += 0.1f; - if (up == down) down += 0.1f; - if (z == 30) z += 0.1f; - - sun_ortho_matrix.buildProjectionMatrixOrthoLH(left, right, - up, down, - 30, z); - - m_suncam->setProjectionMatrix(sun_ortho_matrix, true); - m_scene_manager->setActiveCamera(m_suncam); - m_suncam->render(); //sun_ortho_matrix *= m_suncam->getViewMatrix(); /* ((SunLightProvider *) m_shaders->m_callbacks[ES_SUNLIGHT])->setShadowMatrix(ortho); @@ -608,24 +660,11 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, overridemat.Material.TextureLayer[2].AnisotropicFilter = 0; overridemat.Material.Wireframe = 1; overridemat.Enabled = true;*/ - sun_ortho_matrix = getVideoDriver()->getTransform(video::ETS_PROJECTION); - sun_ortho_matrix *= getVideoDriver()->getTransform(video::ETS_VIEW); - irr_driver->setPhase(SHADOW_PASS); - glDisable(GL_BLEND); - glEnable(GL_CULL_FACE); - glCullFace(GL_FRONT); - m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_SHADOW), true, true); - glDrawBuffer(GL_NONE); - m_scene_manager->drawAll(scene::ESNRP_SOLID); - glCullFace(GL_BACK); + + // overridemat.EnablePasses = 0; // overridemat.Enabled = false; - camera->activate(); - m_scene_manager->drawAll(scene::ESNRP_CAMERA); - - tick++; - tick %= 2; } // ---------------------------------------------------------------------------- @@ -731,7 +770,6 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox, video::SOverrideMaterial &overridemat, int cam, float dt) { - sun_ortho_matrix *= getInvViewMatrix(); core::array<video::IRenderTarget> rtts; // Diffuse rtts.push_back(m_rtts->getRTT(RTT_TMP1)); @@ -754,7 +792,7 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox, { m_lights[i]->render(); if (UserConfigParams::m_shadows) - m_post_processing->renderShadowedSunlight(sun_ortho_matrix); + m_post_processing->renderShadowedSunlight(sun_ortho_matrix[0], sun_ortho_matrix[1], sun_ortho_matrix[2]); else m_post_processing->renderSunlight(); continue; diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 288dc63b6..676f544f0 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -36,8 +36,10 @@ RTT::RTT() const dimension2du ssaosize = UserConfigParams::m_ssao == 2 ? res : quarter; - const u16 shadowside = 8192; - const dimension2du shadowsize(shadowside, shadowside); + const u16 shadowside = 2048; + const dimension2du shadowsize0(shadowside, shadowside); + const dimension2du shadowsize1(shadowside / 2, shadowside / 2); + const dimension2du shadowsize2(shadowside / 4, shadowside / 4); const dimension2du warpvsize(1, 512); const dimension2du warphsize(512, 1); @@ -87,7 +89,9 @@ RTT::RTT() rtts[RTT_SSAO] = drv->addRenderTargetTexture(ssaosize, "rtt.ssao", ECF_R8, stencil); - rtts[RTT_SHADOW] = drv->addRenderTargetTexture(shadowsize, "rtt.shadow", ECF_A8R8G8B8, stencil); + rtts[RTT_SHADOW0] = drv->addRenderTargetTexture(shadowsize0, "rtt.shadow0", ECF_A8R8G8B8, stencil); + rtts[RTT_SHADOW1] = drv->addRenderTargetTexture(shadowsize1, "rtt.shadow1", ECF_A8R8G8B8, stencil); + rtts[RTT_SHADOW2] = drv->addRenderTargetTexture(shadowsize2, "rtt.shadow2", ECF_A8R8G8B8, stencil); rtts[RTT_WARPV] = drv->addRenderTargetTexture(warpvsize, "rtt.warpv", ECF_A8R8G8B8, stencil); rtts[RTT_WARPH] = drv->addRenderTargetTexture(warphsize, "rtt.warph", ECF_A8R8G8B8, stencil); @@ -96,7 +100,7 @@ RTT::RTT() if (((COpenGLDriver *) drv)->queryOpenGLFeature(COpenGLDriver::IRR_ARB_texture_rg)) { // Use optimized formats if supported - rtts[RTT_COLLAPSE] = drv->addRenderTargetTexture(shadowsize, "rtt.collapse", ECF_R8, stencil); + rtts[RTT_COLLAPSE] = drv->addRenderTargetTexture(shadowsize0, "rtt.collapse", ECF_R8, stencil); rtts[RTT_COLLAPSEV] = drv->addRenderTargetTexture(warpvsize, "rtt.collapsev", ECF_R8, stencil); rtts[RTT_COLLAPSEH] = drv->addRenderTargetTexture(warphsize, "rtt.collapseh", ECF_R8, stencil); @@ -106,7 +110,7 @@ RTT::RTT() rtts[RTT_HALF_SOFT] = drv->addRenderTargetTexture(half, "rtt.halfsoft", ECF_R8, stencil); } else { - rtts[RTT_COLLAPSE] = drv->addRenderTargetTexture(shadowsize, "rtt.collapse", ECF_A8R8G8B8, stencil); + rtts[RTT_COLLAPSE] = drv->addRenderTargetTexture(shadowsize0, "rtt.collapse", ECF_A8R8G8B8, stencil); rtts[RTT_COLLAPSEV] = drv->addRenderTargetTexture(warpvsize, "rtt.collapsev", ECF_A8R8G8B8, stencil); rtts[RTT_COLLAPSEH] = drv->addRenderTargetTexture(warphsize, "rtt.collapseh", ECF_A8R8G8B8, stencil); diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index 7ad8c3d7e..87f4c7bab 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -51,7 +51,9 @@ enum TypeRTT RTT_SSAO, - RTT_SHADOW, + RTT_SHADOW0, + RTT_SHADOW1, + RTT_SHADOW2, RTT_COLLAPSE, RTT_COLLAPSEH, RTT_COLLAPSEV, diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 7ab06e31e..47c95a935 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1289,8 +1289,12 @@ namespace FullScreenShader GLuint ShadowedSunLightShader::Program; GLuint ShadowedSunLightShader::uniform_ntex; GLuint ShadowedSunLightShader::uniform_dtex; - GLuint ShadowedSunLightShader::uniform_shadowtex; - GLuint ShadowedSunLightShader::uniform_shadowmat; + GLuint ShadowedSunLightShader::uniform_shadowtex0; + GLuint ShadowedSunLightShader::uniform_shadowmat0; + GLuint ShadowedSunLightShader::uniform_shadowtex1; + GLuint ShadowedSunLightShader::uniform_shadowmat1; + GLuint ShadowedSunLightShader::uniform_shadowtex2; + GLuint ShadowedSunLightShader::uniform_shadowmat2; GLuint ShadowedSunLightShader::uniform_direction; GLuint ShadowedSunLightShader::uniform_col; GLuint ShadowedSunLightShader::uniform_invproj; @@ -1301,23 +1305,31 @@ namespace FullScreenShader Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/sunlightshadow.frag").c_str()); uniform_ntex = glGetUniformLocation(Program, "ntex"); uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_shadowtex = glGetUniformLocation(Program, "shadowtex"); - uniform_shadowmat = glGetUniformLocation(Program, "shadowmat"), + uniform_shadowtex0 = glGetUniformLocation(Program, "shadowtex0"); + uniform_shadowmat0 = glGetUniformLocation(Program, "shadowmat0"); + uniform_shadowtex1 = glGetUniformLocation(Program, "shadowtex1"); + uniform_shadowmat1 = glGetUniformLocation(Program, "shadowmat1"); + uniform_shadowtex2 = glGetUniformLocation(Program, "shadowtex2"); + uniform_shadowmat2 = glGetUniformLocation(Program, "shadowmat2"); uniform_direction = glGetUniformLocation(Program, "direction"); uniform_col = glGetUniformLocation(Program, "col"); uniform_invproj = glGetUniformLocation(Program, "invproj"); vao = createVAO(Program); } - void ShadowedSunLightShader::setUniforms(const core::matrix4 &shadowmat, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex) + void ShadowedSunLightShader::setUniforms(const core::matrix4 &shadowmat0, const core::matrix4 &shadowmat1, const core::matrix4 &shadowmat2, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex0, unsigned TU_shadowtex1, unsigned TU_shadowtex2) { - glUniformMatrix4fv(uniform_shadowmat, 1, GL_FALSE, shadowmat.pointer()); + glUniformMatrix4fv(uniform_shadowmat0, 1, GL_FALSE, shadowmat0.pointer()); + glUniformMatrix4fv(uniform_shadowmat1, 1, GL_FALSE, shadowmat1.pointer()); + glUniformMatrix4fv(uniform_shadowmat2, 1, GL_FALSE, shadowmat2.pointer()); glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z); glUniform3f(uniform_col, r, g, b); glUniform1i(uniform_ntex, TU_ntex); glUniform1i(uniform_dtex, TU_dtex); - glUniform1i(uniform_shadowtex, TU_shadowtex); + glUniform1i(uniform_shadowtex0, TU_shadowtex0); + glUniform1i(uniform_shadowtex1, TU_shadowtex1); + glUniform1i(uniform_shadowtex2, TU_shadowtex2); } GLuint Gaussian6HBlurShader::Program; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 75172cd6e..0c7608c3b 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -389,11 +389,11 @@ class ShadowedSunLightShader { public: static GLuint Program; - static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex, uniform_shadowmat, uniform_direction, uniform_col, uniform_invproj; + static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex0, uniform_shadowmat0, uniform_shadowtex1, uniform_shadowmat1, uniform_shadowtex2, uniform_shadowmat2, uniform_direction, uniform_col, uniform_invproj; static GLuint vao; static void init(); - static void setUniforms(const core::matrix4 &shadowmat, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex); + static void setUniforms(const core::matrix4 &shadowmat0, const core::matrix4 &shadowmat1, const core::matrix4 &shadowmat2, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex0, unsigned TU_shadowtex1, unsigned TU_shadowtex2); }; class Gaussian6HBlurShader diff --git a/src/graphics/sun.cpp b/src/graphics/sun.cpp index 1013762ad..e18fb8796 100644 --- a/src/graphics/sun.cpp +++ b/src/graphics/sun.cpp @@ -50,7 +50,7 @@ SunNode::SunNode(scene::ISceneManager* mgr, scene::ISceneNode* parent, float r, if (UserConfigParams::m_shadows) { - m.setTexture(3, irr_driver->getRTT(RTT_SHADOW)); +// m.setTexture(3, irr_driver->getRTT(RTT_SHADOW)); m.setTexture(4, irr_driver->getRTT(RTT_WARPH)); m.setTexture(5, irr_driver->getRTT(RTT_WARPV)); From c8844486fabef5f8109801bd953ad156bcd4b8dc Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Mon, 10 Feb 2014 15:58:09 +0100 Subject: [PATCH 21/68] Shadow: Tweak bias --- data/shaders/sunlightshadow.frag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 88e4173e6..e29828785 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -45,14 +45,14 @@ float getShadowFactor(vec3 pos, float bias) //float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.; // bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping - return texture(shadowtex0, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias) + 0.5)); + return texture(shadowtex0, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); } else if (pos.z < 60) { vec4 shadowcoord = (shadowmat1 * vec4(pos, 1.0)); shadowcoord /= shadowcoord.w; vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; - return texture(shadowtex1, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias) + 0.5)); + return texture(shadowtex1, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); } else { From da6e6daeaaaeded86bc5986f3b9471921a16576d Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Mon, 10 Feb 2014 19:01:24 +0100 Subject: [PATCH 22/68] Create a BO with texture_2d_array for shadows. --- src/graphics/glwrap.cpp | 10 ++++++++++ src/graphics/glwrap.hpp | 5 +++++ src/graphics/rtts.cpp | 14 ++++++++++++++ src/graphics/rtts.hpp | 1 + 4 files changed, 30 insertions(+) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index ec6b0226c..96dde5c16 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -54,6 +54,11 @@ PFNGLTEXBUFFERPROC glTexBuffer; PFNGLBUFFERSUBDATAPROC glBufferSubData; PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB; +PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; +PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; +PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; +PFNGLTEXIMAGE3DPROC glTexImage3D; +PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; #endif static bool is_gl_init = false; @@ -177,6 +182,11 @@ void initGL() glUniform4fv = (PFNGLUNIFORM4FVPROC)IRR_OGL_LOAD_EXTENSION("glUniform4fv"); glBufferSubData = (PFNGLBUFFERSUBDATAPROC)IRR_OGL_LOAD_EXTENSION("glBufferSubData"); glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC)IRR_OGL_LOAD_EXTENSION("glVertexAttribIPointer"); + glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)IRR_OGL_LOAD_EXTENSION("glGenFramebuffers"); + glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)IRR_OGL_LOAD_EXTENSION("glBindFramebuffer"); + glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)IRR_OGL_LOAD_EXTENSION("glFramebufferTexture"); + glTexImage3D = (PFNGLTEXIMAGE3DPROC)IRR_OGL_LOAD_EXTENSION("glTexImage3D"); + glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)IRR_OGL_LOAD_EXTENSION("glCheckFramebufferStatus"); #ifdef DEBUG glDebugMessageCallbackARB = (PFNGLDEBUGMESSAGECALLBACKARBPROC)IRR_OGL_LOAD_EXTENSION("glDebugMessageCallbackARB"); #endif diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 0a78d12e1..09be8a4ac 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -75,6 +75,11 @@ extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays; extern PFNGLTEXBUFFERPROC glTexBuffer; extern PFNGLBUFFERSUBDATAPROC glBufferSubData; extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; +extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; +extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; +extern PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture; +extern PFNGLTEXIMAGE3DPROC glTexImage3D; +extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus; #ifdef DEBUG extern PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB; #endif diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 676f544f0..0b8089759 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -24,6 +24,7 @@ RTT::RTT() { + initGL(); using namespace video; using namespace core; @@ -140,6 +141,19 @@ RTT::RTT() drv->setRenderTarget(0, false, false); drv->endScene(); + glGenFramebuffers(1, &shadowFBO); + glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO); + glGenTextures(1, &shadowColorTex); + glBindTexture(GL_TEXTURE_2D_ARRAY, shadowColorTex); + glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_R8, 1024, 1024, 3, 0, GL_RED, GL_UNSIGNED_BYTE, 0); + glGenTextures(1, &shadowDepthTex); + glBindTexture(GL_TEXTURE_2D_ARRAY, shadowDepthTex); + glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT24, 1024, 1024, 3, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, shadowColorTex, 0); + glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowDepthTex, 0); + GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER); + assert(result == GL_FRAMEBUFFER_COMPLETE_EXT); + glBindFramebuffer(GL_FRAMEBUFFER, 0); } RTT::~RTT() diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index 87f4c7bab..9cc0c566f 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -79,6 +79,7 @@ public: private: ITexture *rtts[RTT_COUNT]; + unsigned shadowFBO, shadowColorTex, shadowDepthTex; }; #endif From 0228b82ef4048036b8ed960f2ae85ed7c5134165 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Tue, 11 Feb 2014 07:41:35 +1100 Subject: [PATCH 23/68] Fixed incomplete merge. --- src/tracks/track.cpp | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index f5d7a525f..d28d2526a 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -156,7 +156,7 @@ Track::~Track() unsigned int Track::getNumOfCompletedChallenges() { unsigned int unlocked_challenges = 0; - GameSlot* slot = unlock_manager->getCurrentSlot(); + PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); for (unsigned int i=0; i<m_challenges.size(); i++) { if (m_challenges[i].m_challenge_id == "tutorial") @@ -164,7 +164,7 @@ unsigned int Track::getNumOfCompletedChallenges() unlocked_challenges++; continue; } - if (slot->getChallenge(m_challenges[i].m_challenge_id) + if (player->getChallenge(m_challenges[i].m_challenge_id) ->isSolvedAtAnyDifficulty()) { unlocked_challenges++; @@ -986,25 +986,6 @@ bool Track::loadMainTrack(const XMLNode &root) } else if (condition == "allchallenges") { -<<<<<<< HEAD - unsigned int unlocked_challenges = 0; - PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); - for (unsigned int c=0; c<m_challenges.size(); c++) - { - if (m_challenges[c].m_challenge_id == "tutorial") - { - unlocked_challenges++; - continue; - } - if (player->getChallenge(m_challenges[c].m_challenge_id) - ->isSolvedAtAnyDifficulty()) - { - unlocked_challenges++; - } - } - -======= ->>>>>>> upstream/master // allow ONE unsolved challenge : the last one if (getNumOfCompletedChallenges() < m_challenges.size() - 1) continue; @@ -1022,25 +1003,6 @@ bool Track::loadMainTrack(const XMLNode &root) } else if (neg_condition == "allchallenges") { -<<<<<<< HEAD - unsigned int unlocked_challenges = 0; - PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); - for (unsigned int c=0; c<m_challenges.size(); c++) - { - if (m_challenges[c].m_challenge_id == "tutorial") - { - unlocked_challenges++; - continue; - } - if (player->getChallenge(m_challenges[c].m_challenge_id) - ->isSolvedAtAnyDifficulty()) - { - unlocked_challenges++; - } - } - -======= ->>>>>>> upstream/master // allow ONE unsolved challenge : the last one if (getNumOfCompletedChallenges() >= m_challenges.size() - 1) continue; From 810c536d43fc79311d6c91c3e84c973729d86b93 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Tue, 11 Feb 2014 08:12:10 +1100 Subject: [PATCH 24/68] Fixed various minor bugs. --- src/challenges/challenge.cpp | 2 ++ src/challenges/game_slot.cpp | 6 ++--- src/config/player.cpp | 6 ++--- src/config/player.hpp | 41 +++++++++++++++++------------------ src/config/player_manager.cpp | 3 ++- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/challenges/challenge.cpp b/src/challenges/challenge.cpp index e300496e5..5b5b010bc 100644 --- a/src/challenges/challenge.cpp +++ b/src/challenges/challenge.cpp @@ -35,6 +35,8 @@ */ void Challenge::load(const XMLNode* challengesNode) { + if(m_data->getId()=="olivermath") + printf(""); const XMLNode* node = challengesNode->getNode( m_data->getId() ); if(node == NULL) { diff --git a/src/challenges/game_slot.cpp b/src/challenges/game_slot.cpp index f5e8c2f7e..5eaa2c5e4 100644 --- a/src/challenges/game_slot.cpp +++ b/src/challenges/game_slot.cpp @@ -265,10 +265,8 @@ void GameSlot::grandPrixFinished() */ void GameSlot::save(UTFWriter &out) { - out << " <gameslot playerID=\"" << m_player_unique_id.c_str() - << "\" kart=\"" << m_kart_ident.c_str() - << "\" firstTime=\"" << StringUtils::toString(m_first_time) - << "\"> <!-- " << name.c_str() << " -->\n"; + out << " <game-slot playerID=\"" << m_player_unique_id + << "\" firstTime=\"" << m_first_time << L"\">\n"; std::map<std::string, Challenge*>::const_iterator i; for(i = m_challenges_state.begin(); i != m_challenges_state.end(); i++) diff --git a/src/config/player.cpp b/src/config/player.cpp index c93469134..0c8c6f225 100644 --- a/src/config/player.cpp +++ b/src/config/player.cpp @@ -40,7 +40,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest) #endif m_name = name; m_is_guest_account = is_guest; - m_use_frequency = 0; + m_use_frequency = is_guest ? -1 : 0; m_unique_id = PlayerManager::get()->getUniqueId(); m_game_slot = unlock_manager->createGameSlot(); @@ -95,14 +95,14 @@ void PlayerProfile::incrementUseFrequency() */ bool PlayerProfile::operator<(const PlayerProfile &other) { - return getUseFrequency() < other.getUseFrequency(); + return m_use_frequency < other.m_use_frequency; } // operator< // ----------------------------------------------------------------------------- /** \brief Needed for toggling sort order **/ bool PlayerProfile::operator>(const PlayerProfile &other) { - return getUseFrequency() > other.getUseFrequency(); + return m_use_frequency > other.m_use_frequency; } // operator> // ----------------------------------------------------------------------------- diff --git a/src/config/player.hpp b/src/config/player.hpp index 10f51b3c9..03e5223a3 100644 --- a/src/config/player.hpp +++ b/src/config/player.hpp @@ -54,8 +54,8 @@ private: unsigned int m_magic_number; #endif - /** Counts how often this player was used. */ - unsigned int m_use_frequency; + /** Counts how often this player was used (always -1 for guests). */ + int m_use_frequency; /** A unique number for this player, used to link it to challenges etc. */ unsigned int m_unique_id; @@ -84,47 +84,49 @@ public: #ifdef DEBUG m_magic_number = 0xDEADBEEF; #endif - } + } // ~PlayerProfile // ------------------------------------------------------------------------ + /** Sets the name of this player. */ void setName(const core::stringw& name) { #ifdef DEBUG assert(m_magic_number == 0xABCD1234); #endif m_name = name; - } + } // setName // ------------------------------------------------------------------------ + /** Returns the name of this player. */ core::stringw getName() const { #ifdef DEBUG assert(m_magic_number == 0xABCD1234); #endif return m_name.c_str(); - } + } // getName // ------------------------------------------------------------------------ + /** Returns true if this player is a guest account. */ bool isGuestAccount() const { #ifdef DEBUG assert(m_magic_number == 0xABCD1234); #endif return m_is_guest_account; - } - - // ------------------------------------------------------------------------ - int getUseFrequency() const - { - if (m_is_guest_account) return -1; - else return m_use_frequency; - } + } // isGuestAccount // ------------------------------------------------------------------------ /** Returns the unique id of this player. */ unsigned int getUniqueID() const { return m_unique_id; } + // ----------------------------------------------------------------------- + /** Returns true if this is the default (last used) player. */ + bool isDefault() const { return m_is_default; } // ------------------------------------------------------------------------ - /** Returned if the feature (kart, track) is locked. */ + /** Sets if this player is the default player or not. */ + void setDefault(bool is_default) { m_is_default = is_default; } + // ------------------------------------------------------------------------ + /** Returnes if the feature (kart, track) is locked. */ bool isLocked(const std::string &feature) const { return m_game_slot->isLocked(feature); @@ -133,11 +135,13 @@ public: /** Returns all active challenges. */ void computeActive() { m_game_slot->computeActive(); } // ------------------------------------------------------------------------ + /** Returns the list of recently completed challenges. */ std::vector<const ChallengeData*> getRecentlyCompletedChallenges() { return m_game_slot->getRecentlyCompletedChallenges(); } // getRecently Completed Challenges // ------------------------------------------------------------------------ + /** Sets the currently active challenge. */ void setCurrentChallenge(const std::string &name) { m_game_slot->setCurrentChallenge(name); @@ -147,6 +151,8 @@ public: * challenges. */ void raceFinished() { m_game_slot->raceFinished(); } // ------------------------------------------------------------------------ + /** Callback when a GP is finished (to test if a challenge was + * fulfilled). */ void grandPrixFinished() { m_game_slot->grandPrixFinished(); } // ------------------------------------------------------------------------ unsigned int getPoints() const { return m_game_slot->getPoints(); } @@ -182,13 +188,6 @@ public: { return m_game_slot->getNumHardTrophies(); } // getNumHardTropies - // ----------------------------------------------------------------------- - /** Returns true if this is the default (last used) player. */ - bool isDefault() const { return m_is_default; } - // ------------------------------------------------------------------------ - /** Sets if this player is the default player or not. */ - void setDefault(bool is_default) { m_is_default = is_default; } - // ------------------------------------------------------------------------ }; // class PlayerProfile diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index de7cc84c7..9b4e518c0 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -50,6 +50,7 @@ void PlayerManager::create() */ PlayerManager::PlayerManager() { + m_current_player = NULL; load(); } // PlayerManager @@ -167,7 +168,7 @@ void PlayerManager::addDefaultPlayer() m_all_players.push_back(new PlayerProfile(username.c_str()) ); // add default guest player - m_all_players.push_back( new PlayerProfile(_LTR("Guest")) ); + m_all_players.push_back( new PlayerProfile(_LTR("Guest"), /*guest*/true) ); } // addDefaultPlayer From 83bc8c83e68cd8ec2032306b3b0e567f64416813 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Tue, 11 Feb 2014 08:54:44 +1100 Subject: [PATCH 25/68] Fixed empty user config.xml files. --- src/config/user_config.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index 4e2eceb63..d1740acaa 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -18,6 +18,14 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "utils/ptr_vector.hpp" + +// The order here is important. If all_params is declared later (e.g. after +// the #includes), all elements will be added to all_params, and then +// all_params will be initialised, i.e. cleared! +class UserConfigParam; +static PtrVector<UserConfigParam, REF> all_params; + // X-macros #define PARAM_PREFIX #define PARAM_DEFAULT(X) = X @@ -31,7 +39,6 @@ #include "io/utf_writer.hpp" #include "io/xml_node.hpp" #include "race/race_manager.hpp" -#include "utils/ptr_vector.hpp" #include "utils/string_utils.hpp" #include "utils/translation.hpp" @@ -41,10 +48,6 @@ #include <string> #include <vector> -class UserConfigParam; -static PtrVector<UserConfigParam, REF> all_params; - - const int UserConfig::m_current_config_version = 8; From 2fe21fc3b234ca0b84a6186b304f9dd8bdbe338e Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Tue, 11 Feb 2014 09:52:46 +1100 Subject: [PATCH 26/68] Added operator<<(const bool&), to get proper true/false written instead of 0/1 - but it doesn't work yet :( --- src/io/utf_writer.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/io/utf_writer.hpp b/src/io/utf_writer.hpp index 399eb1095..cc7ef30a0 100644 --- a/src/io/utf_writer.hpp +++ b/src/io/utf_writer.hpp @@ -19,9 +19,12 @@ #ifndef HEADER_UTF_WRITER_HPP #define HEADER_UTF_WRITER_HPP -#include <fstream> +#include "utils/string_utils.hpp" + #include <irrString.h> +#include <fstream> + /** * \brief utility class used to write wide (UTF-16 or UTF-32, depending of size of wchar_t) XML files * \note the inner base class (ofstream) is not public because it will take in any kind of data, and @@ -49,8 +52,13 @@ public: return operator<< (irr::core::stringw(txt.c_str())); } // operator<<(std::string) // ------------------------------------------------------------------------ + UTFWriter& operator<< (const bool &b) + { + return operator<<(StringUtils::toString(b)); + } + // ------------------------------------------------------------------------ template<typename T> - UTFWriter& operator<< (const T t) + UTFWriter& operator<< (const T &t) { return operator<<(StringUtils::toString<T>(t)); } // operator<< (template) From 7b45db42e7b16b592c026289fef5e2fe65a8b49c Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@mgail.com> Date: Tue, 11 Feb 2014 10:13:23 +1100 Subject: [PATCH 27/68] Removed debug print. --- src/challenges/challenge.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/challenges/challenge.cpp b/src/challenges/challenge.cpp index 5b5b010bc..e300496e5 100644 --- a/src/challenges/challenge.cpp +++ b/src/challenges/challenge.cpp @@ -35,8 +35,6 @@ */ void Challenge::load(const XMLNode* challengesNode) { - if(m_data->getId()=="olivermath") - printf(""); const XMLNode* node = challengesNode->getNode( m_data->getId() ); if(node == NULL) { From 5b50f6431088f2609d05d66932cdc4154a6a0ba1 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@mgail.com> Date: Tue, 11 Feb 2014 13:41:16 +1100 Subject: [PATCH 28/68] Ignore emacs backup files (*~). --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 39664e356..434806ad0 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ data/.svn *.vcxproj *.vcxproj.filters *.vcxproj.user +*~ packets_log.txt history.dat From 7bba1ae478523b61733524a19f4a22ba4fb2790a Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Tue, 11 Feb 2014 22:28:41 +1100 Subject: [PATCH 29/68] Fixed saving first-time use of the story mode. --- src/challenges/game_slot.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/challenges/game_slot.cpp b/src/challenges/game_slot.cpp index 5eaa2c5e4..89e223257 100644 --- a/src/challenges/game_slot.cpp +++ b/src/challenges/game_slot.cpp @@ -40,11 +40,6 @@ GameSlot::GameSlot(const XMLNode *node) if(node) { node->get("first-time", &m_first_time); - - for(unsigned int i=0; i<node->getNumNodes(); i++) - { - const XMLNode *challenge = node->getNode(i); - } // for i <getNumNodes } // if node } // GameSlot @@ -266,7 +261,7 @@ void GameSlot::grandPrixFinished() void GameSlot::save(UTFWriter &out) { out << " <game-slot playerID=\"" << m_player_unique_id - << "\" firstTime=\"" << m_first_time << L"\">\n"; + << "\" first-time=\"" << m_first_time << L"\">\n"; std::map<std::string, Challenge*>::const_iterator i; for(i = m_challenges_state.begin(); i != m_challenges_state.end(); i++) From ff585e4c7310e181eb237fa8a117c0a3273667fc Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Tue, 11 Feb 2014 22:35:23 +1100 Subject: [PATCH 30/68] Automatically compute active challenges when changing the current player. --- src/config/player_manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index 9b4e518c0..595e27d24 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -219,6 +219,7 @@ void PlayerManager::setCurrentPlayer(PlayerProfile *player) m_current_player->setDefault(false); m_current_player = player; m_current_player->setDefault(true); + m_current_player->computeActive(); AchievementsManager::get()->updateCurrentPlayer(); } // setCurrentPlayer From 934d1f10b8c700201d46f7c059474ca54fcdd91d Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Mon, 10 Feb 2014 19:28:02 +0100 Subject: [PATCH 31/68] Shadow: Use Geometry Shader for better perfs. The 3 cascades are now rendered in a single pass, using 2D array texture and a GS to do the dispatch ("layered rendering"). It's possible to use instancing instead but it requires the AMD_vertex_shader_layer extension which is oddly part of opengl 4.2. --- data/shaders/shadow.geom | 24 ++++++++++++++ data/shaders/shadow.vert | 14 ++++++++ data/shaders/sunlightshadow.frag | 20 +++++------ data/shaders/white.frag | 2 +- src/graphics/glwrap.cpp | 29 ++++++++++++++++ src/graphics/glwrap.hpp | 1 + src/graphics/irr_driver.hpp | 6 +++- src/graphics/post_processing.cpp | 21 ++++++------ src/graphics/post_processing.hpp | 2 +- src/graphics/render.cpp | 40 +++++++++++----------- src/graphics/rtts.cpp | 2 +- src/graphics/rtts.hpp | 2 ++ src/graphics/shaders.cpp | 57 ++++++++++++++++++-------------- src/graphics/shaders.hpp | 8 ++--- src/graphics/stkanimatedmesh.cpp | 5 +-- src/graphics/stkmesh.cpp | 13 ++++---- 16 files changed, 162 insertions(+), 84 deletions(-) create mode 100644 data/shaders/shadow.geom create mode 100644 data/shaders/shadow.vert diff --git a/data/shaders/shadow.geom b/data/shaders/shadow.geom new file mode 100644 index 000000000..7ef0a1c6d --- /dev/null +++ b/data/shaders/shadow.geom @@ -0,0 +1,24 @@ +#version 330 core +uniform mat4 ModelViewProjectionMatrix[3]; + +layout(triangles) in; +layout(triangle_strip, max_vertices=9) out; + +in vec2 tc[3]; + +out vec2 uv; + +void main(void) +{ + for (int j = 0; j<3; j++) + { + gl_Layer = j; + for(int i=0; i<3; i++) + { + uv = tc[i]; + gl_Position = ModelViewProjectionMatrix[j] * gl_in[i].gl_Position; + EmitVertex(); + } + EndPrimitive(); + } +} diff --git a/data/shaders/shadow.vert b/data/shaders/shadow.vert new file mode 100644 index 000000000..5dbf07048 --- /dev/null +++ b/data/shaders/shadow.vert @@ -0,0 +1,14 @@ +#version 330 core + +in vec3 Position; +in vec2 Texcoord; + + +out vec2 tc; + + +void main(void) +{ + tc = Texcoord; + gl_Position = vec4(Position, 1.); +} diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index e29828785..40c6bd7a7 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -1,18 +1,14 @@ #version 130 uniform sampler2D ntex; uniform sampler2D dtex; -uniform sampler2DShadow shadowtex0; -uniform sampler2DShadow shadowtex1; -uniform sampler2DShadow shadowtex2; +uniform sampler2DArrayShadow shadowtex; //uniform sampler2D warpx; ///uniform sampler2D warpy; uniform vec3 direction; uniform vec3 col; uniform mat4 invproj; -uniform mat4 shadowmat0; -uniform mat4 shadowmat1; -uniform mat4 shadowmat2; +uniform mat4 shadowmat[3]; //uniform int hasclouds; //uniform vec2 wind; //uniform float shadowoffset; @@ -32,7 +28,7 @@ float getShadowFactor(vec3 pos, float bias) { if (pos.z < 10.) { - vec4 shadowcoord = (shadowmat0 * vec4(pos, 1.0)); + vec4 shadowcoord = (shadowmat[0] * vec4(pos, 1.0)); shadowcoord /= shadowcoord.w; vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; // shadowcoord = (shadowcoord * 0.5) + vec3(0.5); @@ -45,21 +41,21 @@ float getShadowFactor(vec3 pos, float bias) //float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.; // bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping - return texture(shadowtex0, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); + return texture(shadowtex, vec4(shadowtexcoord, 0., 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); } else if (pos.z < 60) { - vec4 shadowcoord = (shadowmat1 * vec4(pos, 1.0)); + vec4 shadowcoord = (shadowmat[1] * vec4(pos, 1.0)); shadowcoord /= shadowcoord.w; vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; - return texture(shadowtex1, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); + return texture(shadowtex, vec4(shadowtexcoord, 1., 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); } else { - vec4 shadowcoord = (shadowmat2 * vec4(pos, 1.0)); + vec4 shadowcoord = (shadowmat[2] * vec4(pos, 1.0)); shadowcoord /= shadowcoord.w; vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; - return texture(shadowtex2, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias) + 0.5)); + return texture(shadowtex, vec4(shadowtexcoord, 2., 0.5 * (shadowcoord.z + bias) + 0.5)); } } diff --git a/data/shaders/white.frag b/data/shaders/white.frag index a22a4a9a4..3017ace18 100644 --- a/data/shaders/white.frag +++ b/data/shaders/white.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 out vec4 FragColor; void main() { diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 96dde5c16..2669d5125 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -255,6 +255,35 @@ GLuint LoadProgram(const char * vertex_file_path, const char * fragment_file_pat return ProgramID; } +GLuint LoadProgram(const char * vertex_file_path, const char * geometry_file_path, const char * fragment_file_path) { + GLuint VertexShaderID = LoadShader(vertex_file_path, GL_VERTEX_SHADER); + GLuint FragmentShaderID = LoadShader(fragment_file_path, GL_FRAGMENT_SHADER); + GLuint GeometryShaderID = LoadShader(geometry_file_path, GL_GEOMETRY_SHADER); + + GLuint ProgramID = glCreateProgram(); + glAttachShader(ProgramID, VertexShaderID); + glAttachShader(ProgramID, GeometryShaderID); + glAttachShader(ProgramID, FragmentShaderID); + glLinkProgram(ProgramID); + + GLint Result = GL_FALSE; + int InfoLogLength; + glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result); + if (Result == GL_FALSE) { + glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength); + char *ErrorMessage = new char[InfoLogLength]; + glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, ErrorMessage); + printf(ErrorMessage); + delete[] ErrorMessage; + } + + glDeleteShader(VertexShaderID); + glDeleteShader(GeometryShaderID); + glDeleteShader(FragmentShaderID); + + return ProgramID; +} + GLuint LoadTFBProgram(const char * vertex_file_path, const char **varyings, unsigned varyingscount) { GLuint Shader = LoadShader(vertex_file_path, GL_VERTEX_SHADER); GLuint Program = glCreateProgram(); diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 09be8a4ac..6d8bb49bc 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -20,6 +20,7 @@ void initGL(); GLuint LoadProgram(const char * vertex_file_path, const char * fragment_file_path); +GLuint LoadProgram(const char * vertex_file_path, const char * geometry_file_path, const char * fragment_file_path); GLuint LoadTFBProgram(const char * vertex_file_path, const char **varyings, unsigned varyingscount); void bindUniformToTextureUnit(GLuint location, GLuint texid, unsigned textureUnit); void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter, bool allowAF = false); diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index f0e2e3b0c..dba63df2c 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -102,7 +102,7 @@ private: RTT *m_rtts; /** Shadow importance. */ ShadowImportance *m_shadow_importance; - core::matrix4 sun_ortho_matrix[3]; + std::vector<core::matrix4> sun_ortho_matrix; /** Additional details to be shown in case that a texture is not found. * This is used to specify details like: "while loading kart '...'" */ @@ -227,6 +227,10 @@ public: void reset(); void setPhase(STKRenderingPass); STKRenderingPass getPhase() const; + const std::vector<core::matrix4> &getShadowViewProj() const + { + return sun_ortho_matrix; + } void IncreaseObjectCount(); core::array<video::IRenderTarget> &getMainSetup(); void updateConfigIfRelevant(); diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index bf4dbff00..1602eb97d 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -346,7 +346,7 @@ void PostProcessing::renderSunlight() glBindVertexArray(0); } -void PostProcessing::renderShadowedSunlight(const core::matrix4 &sun_ortho_matrix0, const core::matrix4 &sun_ortho_matrix1, const core::matrix4 &sun_ortho_matrix2) +void PostProcessing::renderShadowedSunlight(const std::vector<core::matrix4> &sun_ortho_matrix, GLuint depthtex) { SunLightProvider * const cb = (SunLightProvider *)irr_driver->getCallback(ES_SUNLIGHT); @@ -359,16 +359,15 @@ void PostProcessing::renderShadowedSunlight(const core::matrix4 &sun_ortho_matri glBindVertexArray(FullScreenShader::ShadowedSunLightShader::vao); setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); - setTexture(2, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW0))->DepthBufferTexture, GL_LINEAR, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - setTexture(3, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW1))->DepthBufferTexture, GL_LINEAR, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - setTexture(4, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW2))->DepthBufferTexture, GL_LINEAR, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - FullScreenShader::ShadowedSunLightShader::setUniforms(sun_ortho_matrix0, sun_ortho_matrix1, sun_ortho_matrix2, cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2, 3, 4); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D_ARRAY, depthtex); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); + glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + FullScreenShader::ShadowedSunLightShader::setUniforms(sun_ortho_matrix, cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1, 2); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindVertexArray(0); } diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index db2c680bc..2df83d21e 100644 --- a/src/graphics/post_processing.hpp +++ b/src/graphics/post_processing.hpp @@ -75,7 +75,7 @@ public: /** Generate diffuse and specular map */ void renderPointlight(const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy); void renderSunlight(); - void renderShadowedSunlight(const core::matrix4 &sun_ortho_matrix0, const core::matrix4 &sun_ortho_matrix1, const core::matrix4 &sun_ortho_matrix2); + void renderShadowedSunlight(const std::vector<core::matrix4> &sun_ortho_matrix, unsigned depthtex); void renderFog(const core::matrix4 &ipvmat); void renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm); diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 54c216227..19212b9da 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -480,12 +480,6 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, m_rtts->getRTT(RTT_SHADOW2) }; - unsigned rtt_size[] = { - 2048, - 1024, - 512, - }; - const float oldfar = camnode->getFarValue(); const float oldnear = camnode->getNearValue(); float FarValues[] = @@ -502,6 +496,7 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, }; const core::matrix4 &SunCamViewMatrix = m_suncam->getViewMatrix(); + sun_ortho_matrix.clear(); // Build the 3 ortho projection (for the 3 shadow resolution levels) for (unsigned i = 0; i < 3; i++) @@ -529,8 +524,8 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, float z = box.MaxEdge.Z; // Snap to texels - const float units_per_w = w / rtt_size[i]; - const float units_per_h = h / rtt_size[i]; + const float units_per_w = w / 1024; + const float units_per_h = h / 1024; float left = box.MinEdge.X; float right = box.MaxEdge.X; @@ -557,18 +552,21 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, m_scene_manager->setActiveCamera(m_suncam); m_suncam->render(); - sun_ortho_matrix[i] = getVideoDriver()->getTransform(video::ETS_PROJECTION); - sun_ortho_matrix[i] *= getVideoDriver()->getTransform(video::ETS_VIEW); - sun_ortho_matrix[i] *= getInvViewMatrix(); - irr_driver->setPhase(SHADOW_PASS); - glDisable(GL_BLEND); - glEnable(GL_CULL_FACE); - glCullFace(GL_FRONT); - m_video_driver->setRenderTarget(ShadowRTT[i], true, true); - glDrawBuffer(GL_NONE); - m_scene_manager->drawAll(scene::ESNRP_SOLID); - glCullFace(GL_BACK); + sun_ortho_matrix.push_back(getVideoDriver()->getTransform(video::ETS_PROJECTION) * getVideoDriver()->getTransform(video::ETS_VIEW)); } + assert(sun_ortho_matrix.size() == 3); + + irr_driver->setPhase(SHADOW_PASS); + glDisable(GL_BLEND); + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); +// m_video_driver->setRenderTarget(ShadowRTT[0], true, true); + glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getShadowFBO()); + glViewport(0, 0, 1024, 1024); + glClear(GL_DEPTH_BUFFER_BIT); + glDrawBuffer(GL_NONE); + m_scene_manager->drawAll(scene::ESNRP_SOLID); + glCullFace(GL_BACK); camnode->setNearValue(oldnear); camnode->setFarValue(oldfar); @@ -770,6 +768,8 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox, video::SOverrideMaterial &overridemat, int cam, float dt) { + for (unsigned i = 0; i < sun_ortho_matrix.size(); i++) + sun_ortho_matrix[i] *= getInvViewMatrix(); core::array<video::IRenderTarget> rtts; // Diffuse rtts.push_back(m_rtts->getRTT(RTT_TMP1)); @@ -792,7 +792,7 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox, { m_lights[i]->render(); if (UserConfigParams::m_shadows) - m_post_processing->renderShadowedSunlight(sun_ortho_matrix[0], sun_ortho_matrix[1], sun_ortho_matrix[2]); + m_post_processing->renderShadowedSunlight(sun_ortho_matrix, m_rtts->getShadowDepthTex()); else m_post_processing->renderSunlight(); continue; diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 0b8089759..0caf069fa 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -37,7 +37,7 @@ RTT::RTT() const dimension2du ssaosize = UserConfigParams::m_ssao == 2 ? res : quarter; - const u16 shadowside = 2048; + const u16 shadowside = 1024; const dimension2du shadowsize0(shadowside, shadowside); const dimension2du shadowsize1(shadowside / 2, shadowside / 2); const dimension2du shadowsize2(shadowside / 4, shadowside / 4); diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index 9cc0c566f..813fc084a 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -76,6 +76,8 @@ public: ~RTT(); ITexture *getRTT(TypeRTT which); + unsigned getShadowFBO() const { return shadowFBO; } + unsigned getShadowDepthTex() const { return shadowDepthTex; } private: ITexture *rtts[RTT_COUNT]; diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 47c95a935..9f50109cb 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -883,14 +883,20 @@ namespace MeshShader void ShadowShader::init() { - Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/white.frag").c_str()); + Program = LoadProgram(file_manager->getAsset("shaders/shadow.vert").c_str(), file_manager->getAsset("shaders/shadow.geom").c_str(), file_manager->getAsset("shaders/white.frag").c_str()); attrib_position = glGetAttribLocation(Program, "Position"); uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); } - void ShadowShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) + void ShadowShader::setUniforms(const std::vector<core::matrix4> &ModelViewProjectionMatrix) { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + size_t size = ModelViewProjectionMatrix.size(); + float *tmp = new float[16 * size]; + for (unsigned i = 0; i < size; i++) { + memcpy(&tmp[16 * i], ModelViewProjectionMatrix[i].pointer(), 16 * sizeof(float)); + } + glUniformMatrix4fv(uniform_MVP, size, GL_FALSE, tmp); + delete[] tmp; } GLuint RefShadowShader::Program; @@ -901,17 +907,23 @@ namespace MeshShader void RefShadowShader::init() { - Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/object_unlit.frag").c_str()); + Program = LoadProgram(file_manager->getAsset("shaders/shadow.vert").c_str(), file_manager->getAsset("shaders/shadow.geom").c_str(), file_manager->getAsset("shaders/object_unlit.frag").c_str()); attrib_position = glGetAttribLocation(Program, "Position"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); } - void RefShadowShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex) + void RefShadowShader::setUniforms(const std::vector<core::matrix4> &ModelViewProjectionMatrix, unsigned TU_tex) { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + size_t size = ModelViewProjectionMatrix.size(); + float *tmp = new float[16 * size]; + for (unsigned i = 0; i < size; i++) { + memcpy(&tmp[16 * i], ModelViewProjectionMatrix[i].pointer(), 16 * sizeof(float)); + } + glUniformMatrix4fv(uniform_MVP, size, GL_FALSE, tmp); glUniform1i(uniform_tex, TU_tex); + delete[] tmp; } GLuint GrassShadowShader::Program; @@ -1289,12 +1301,8 @@ namespace FullScreenShader GLuint ShadowedSunLightShader::Program; GLuint ShadowedSunLightShader::uniform_ntex; GLuint ShadowedSunLightShader::uniform_dtex; - GLuint ShadowedSunLightShader::uniform_shadowtex0; - GLuint ShadowedSunLightShader::uniform_shadowmat0; - GLuint ShadowedSunLightShader::uniform_shadowtex1; - GLuint ShadowedSunLightShader::uniform_shadowmat1; - GLuint ShadowedSunLightShader::uniform_shadowtex2; - GLuint ShadowedSunLightShader::uniform_shadowmat2; + GLuint ShadowedSunLightShader::uniform_shadowtex; + GLuint ShadowedSunLightShader::uniform_shadowmat; GLuint ShadowedSunLightShader::uniform_direction; GLuint ShadowedSunLightShader::uniform_col; GLuint ShadowedSunLightShader::uniform_invproj; @@ -1305,31 +1313,30 @@ namespace FullScreenShader Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/sunlightshadow.frag").c_str()); uniform_ntex = glGetUniformLocation(Program, "ntex"); uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_shadowtex0 = glGetUniformLocation(Program, "shadowtex0"); - uniform_shadowmat0 = glGetUniformLocation(Program, "shadowmat0"); - uniform_shadowtex1 = glGetUniformLocation(Program, "shadowtex1"); - uniform_shadowmat1 = glGetUniformLocation(Program, "shadowmat1"); - uniform_shadowtex2 = glGetUniformLocation(Program, "shadowtex2"); - uniform_shadowmat2 = glGetUniformLocation(Program, "shadowmat2"); + uniform_shadowtex = glGetUniformLocation(Program, "shadowtex"); + uniform_shadowmat = glGetUniformLocation(Program, "shadowmat[0]"); uniform_direction = glGetUniformLocation(Program, "direction"); uniform_col = glGetUniformLocation(Program, "col"); uniform_invproj = glGetUniformLocation(Program, "invproj"); vao = createVAO(Program); } - void ShadowedSunLightShader::setUniforms(const core::matrix4 &shadowmat0, const core::matrix4 &shadowmat1, const core::matrix4 &shadowmat2, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex0, unsigned TU_shadowtex1, unsigned TU_shadowtex2) + void ShadowedSunLightShader::setUniforms(const std::vector<core::matrix4> &shadowmat, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex) { - glUniformMatrix4fv(uniform_shadowmat0, 1, GL_FALSE, shadowmat0.pointer()); - glUniformMatrix4fv(uniform_shadowmat1, 1, GL_FALSE, shadowmat1.pointer()); - glUniformMatrix4fv(uniform_shadowmat2, 1, GL_FALSE, shadowmat2.pointer()); + size_t size = shadowmat.size(); + float *tmp = new float[16 * size]; + for (unsigned i = 0; i < size; i++) { + memcpy(&tmp[16 * i], shadowmat[i].pointer(), 16 * sizeof(float)); + } + + glUniformMatrix4fv(uniform_shadowmat, size, GL_FALSE, tmp); glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z); glUniform3f(uniform_col, r, g, b); glUniform1i(uniform_ntex, TU_ntex); glUniform1i(uniform_dtex, TU_dtex); - glUniform1i(uniform_shadowtex0, TU_shadowtex0); - glUniform1i(uniform_shadowtex1, TU_shadowtex1); - glUniform1i(uniform_shadowtex2, TU_shadowtex2); + glUniform1i(uniform_shadowtex, TU_shadowtex); + delete[] tmp; } GLuint Gaussian6HBlurShader::Program; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 0c7608c3b..c00c5c5b9 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -233,7 +233,7 @@ public: static GLuint uniform_MVP; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); + static void setUniforms(const std::vector<core::matrix4> &ModelViewProjectionMatrix); }; class RefShadowShader @@ -244,7 +244,7 @@ public: static GLuint uniform_MVP, uniform_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex); + static void setUniforms(const std::vector<core::matrix4> &ModelViewProjectionMatrix, unsigned TU_tex); }; class GrassShadowShader @@ -389,11 +389,11 @@ class ShadowedSunLightShader { public: static GLuint Program; - static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex0, uniform_shadowmat0, uniform_shadowtex1, uniform_shadowmat1, uniform_shadowtex2, uniform_shadowmat2, uniform_direction, uniform_col, uniform_invproj; + static GLuint uniform_ntex, uniform_dtex, uniform_shadowtex, uniform_shadowmat, uniform_direction, uniform_col, uniform_invproj; static GLuint vao; static void init(); - static void setUniforms(const core::matrix4 &shadowmat0, const core::matrix4 &shadowmat1, const core::matrix4 &shadowmat2, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex0, unsigned TU_shadowtex1, unsigned TU_shadowtex2); + static void setUniforms(const std::vector<core::matrix4> &shadowmat, const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_shadowtex); }; class Gaussian6HBlurShader diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index 07bb167bc..c7b6641c2 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -100,8 +100,9 @@ void STKAnimatedMesh::drawShadow(const GLMesh &mesh) GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; assert(irr_driver->getPhase() == SHADOW_PASS); - core::matrix4 ShadowMVP; - computeMVP(ShadowMVP); + std::vector<core::matrix4> ShadowMVP(irr_driver->getShadowViewProj()); + for (unsigned i = 0; i < ShadowMVP.size(); i++) + ShadowMVP[i] *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD); glUseProgram(MeshShader::ShadowShader::Program); MeshShader::ShadowShader::setUniforms(ShadowMVP); glBindVertexArray(mesh.vao_shadow_pass); diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 34dfc14d8..554faa97e 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -731,8 +731,9 @@ void STKMesh::drawShadow(const GLMesh &mesh, video::E_MATERIAL_TYPE type) size_t count = mesh.IndexCount; - core::matrix4 ShadowMVP; - computeMVP(ShadowMVP); + std::vector<core::matrix4> ShadowMVP(irr_driver->getShadowViewProj()); + for (unsigned i = 0; i < ShadowMVP.size(); i++) + ShadowMVP[i] *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD); if (type == irr_driver->getShader(ES_OBJECTPASS_REF)) { @@ -740,12 +741,12 @@ void STKMesh::drawShadow(const GLMesh &mesh, video::E_MATERIAL_TYPE type) glUseProgram(MeshShader::RefShadowShader::Program); MeshShader::RefShadowShader::setUniforms(ShadowMVP, 0); } - else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF)) +/* else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF)) { setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); glUseProgram(MeshShader::GrassShadowShader::Program); MeshShader::GrassShadowShader::setUniforms(ShadowMVP, windDir, 0); - } + }*/ else { glUseProgram(MeshShader::ShadowShader::Program); @@ -949,10 +950,10 @@ void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type) { mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::RefShadowShader::attrib_position, MeshShader::RefShadowShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); } - else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF)) + /*else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF)) { mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::GrassShadowShader::attrib_position, MeshShader::GrassShadowShader::attrib_texcoord, -1, -1, -1, -1, MeshShader::GrassShadowShader::attrib_color, mesh.Stride); - } + }*/ else { mesh.vao_shadow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ShadowShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride); From 70f89a8bce8e0332bdcae6b9b4795fc9acbdc5d2 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Tue, 11 Feb 2014 21:49:46 +0100 Subject: [PATCH 32/68] Shadow: Use 4 cascades. Now that we use GS and textures array it's easier to add a cascade. 4 is still not optimal but I'd like to avoid cascade count inflation as much as possible ; 4 x 1024x1024 has the bandwidth requirement of the single 2048x2048 shadowmaps we previously had. --- data/shaders/shadow.geom | 6 +++--- data/shaders/sunlightshadow.frag | 17 ++++++++++++----- src/graphics/render.cpp | 10 ++++++---- src/graphics/rtts.cpp | 4 ++-- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/data/shaders/shadow.geom b/data/shaders/shadow.geom index 7ef0a1c6d..9dc5cbe93 100644 --- a/data/shaders/shadow.geom +++ b/data/shaders/shadow.geom @@ -1,8 +1,8 @@ #version 330 core -uniform mat4 ModelViewProjectionMatrix[3]; +uniform mat4 ModelViewProjectionMatrix[4]; layout(triangles) in; -layout(triangle_strip, max_vertices=9) out; +layout(triangle_strip, max_vertices=12) out; in vec2 tc[3]; @@ -10,7 +10,7 @@ out vec2 uv; void main(void) { - for (int j = 0; j<3; j++) + for (int j = 0; j<4; j++) { gl_Layer = j; for(int i=0; i<3; i++) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 40c6bd7a7..df53c2bf7 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -8,7 +8,7 @@ uniform sampler2DArrayShadow shadowtex; uniform vec3 direction; uniform vec3 col; uniform mat4 invproj; -uniform mat4 shadowmat[3]; +uniform mat4 shadowmat[4]; //uniform int hasclouds; //uniform vec2 wind; //uniform float shadowoffset; @@ -26,7 +26,7 @@ vec3 DecodeNormal(vec2 n) float getShadowFactor(vec3 pos, float bias) { - if (pos.z < 10.) + if (pos.z < 5.) { vec4 shadowcoord = (shadowmat[0] * vec4(pos, 1.0)); shadowcoord /= shadowcoord.w; @@ -43,19 +43,26 @@ float getShadowFactor(vec3 pos, float bias) // bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping return texture(shadowtex, vec4(shadowtexcoord, 0., 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); } - else if (pos.z < 60) + else if (pos.z < 10.) { vec4 shadowcoord = (shadowmat[1] * vec4(pos, 1.0)); shadowcoord /= shadowcoord.w; vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; return texture(shadowtex, vec4(shadowtexcoord, 1., 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); } - else + else if (pos.z < 75.) { vec4 shadowcoord = (shadowmat[2] * vec4(pos, 1.0)); shadowcoord /= shadowcoord.w; vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; - return texture(shadowtex, vec4(shadowtexcoord, 2., 0.5 * (shadowcoord.z + bias) + 0.5)); + return texture(shadowtex, vec4(shadowtexcoord, 2., 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); + } + else + { + vec4 shadowcoord = (shadowmat[3] * vec4(pos, 1.0)); + shadowcoord /= shadowcoord.w; + vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; + return texture(shadowtex, vec4(shadowtexcoord, 3., 0.5 * (shadowcoord.z + bias) + 0.5)); } } diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 19212b9da..04ab62daf 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -484,22 +484,24 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, const float oldnear = camnode->getNearValue(); float FarValues[] = { + 5., 10., - 60., + 75., oldfar, }; float NearValues[] = { oldnear, + 5., 10., - 60., + 75., }; const core::matrix4 &SunCamViewMatrix = m_suncam->getViewMatrix(); sun_ortho_matrix.clear(); // Build the 3 ortho projection (for the 3 shadow resolution levels) - for (unsigned i = 0; i < 3; i++) + for (unsigned i = 0; i < 4; i++) { camnode->setFarValue(FarValues[i]); camnode->setNearValue(NearValues[i]); @@ -554,7 +556,7 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, sun_ortho_matrix.push_back(getVideoDriver()->getTransform(video::ETS_PROJECTION) * getVideoDriver()->getTransform(video::ETS_VIEW)); } - assert(sun_ortho_matrix.size() == 3); + assert(sun_ortho_matrix.size() == 4); irr_driver->setPhase(SHADOW_PASS); glDisable(GL_BLEND); diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 0caf069fa..0489a41b5 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -145,10 +145,10 @@ RTT::RTT() glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO); glGenTextures(1, &shadowColorTex); glBindTexture(GL_TEXTURE_2D_ARRAY, shadowColorTex); - glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_R8, 1024, 1024, 3, 0, GL_RED, GL_UNSIGNED_BYTE, 0); + glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_R8, 1024, 1024, 4, 0, GL_RED, GL_UNSIGNED_BYTE, 0); glGenTextures(1, &shadowDepthTex); glBindTexture(GL_TEXTURE_2D_ARRAY, shadowDepthTex); - glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT24, 1024, 1024, 3, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); + glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT24, 1024, 1024, 4, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, shadowColorTex, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowDepthTex, 0); GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER); From 56656b581d8c799af3407d8526f3090818fbda2d Mon Sep 17 00:00:00 2001 From: Sachith Hasaranga Seneviratne <sachith500@gmail.com> Date: Wed, 12 Feb 2014 22:04:21 +0530 Subject: [PATCH 33/68] Bugfix for 1118 Hide countdown as soon as race ends to prevent the drawGlobalTimer() method in race_gui from checking for failed challenges. https://sourceforge.net/apps/trac/supertuxkart/ticket/1118 Signed-off-by: Sachith Hasaranga Seneviratne <sachith500@gmail.com> --- src/states_screens/race_gui.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 34f2cd3ae..460aa1b44 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -170,7 +170,10 @@ void RaceGUI::renderGlobal(float dt) if (!m_is_tutorial) { - drawGlobalTimer(); + //stop displaying timer as soon as race is over + if (world->getPhase()<WorldStatus::DELAY_FINISH_PHASE) + drawGlobalTimer(); + if(world->getPhase() == WorldStatus::GO_PHASE || world->getPhase() == WorldStatus::MUSIC_PHASE) { From 0cf6e4266a7d00c9dfec579f24716647187ffc5c Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Wed, 12 Feb 2014 17:24:37 +0100 Subject: [PATCH 34/68] Graphics: Clean some dead code. Still leave some shadow related code as comment, I will need later to port cand's work on penumbra shadow. --- src/graphics/gpuparticles.cpp | 7 ---- src/graphics/gpuparticles.hpp | 1 - src/graphics/post_processing.cpp | 2 -- src/graphics/render.cpp | 55 -------------------------------- src/graphics/rtts.cpp | 3 -- src/graphics/rtts.hpp | 3 -- src/graphics/shaders.cpp | 3 -- src/graphics/shaders.hpp | 2 -- src/graphics/sun.cpp | 37 ++------------------- 9 files changed, 2 insertions(+), 111 deletions(-) diff --git a/src/graphics/gpuparticles.cpp b/src/graphics/gpuparticles.cpp index 9f9894e6f..01487e970 100644 --- a/src/graphics/gpuparticles.cpp +++ b/src/graphics/gpuparticles.cpp @@ -65,13 +65,6 @@ ParticleSystemProxy::ParticleSystemProxy(bool createDefaultEmitter, const core::vector3df& position, const core::vector3df& rotation, const core::vector3df& scale) : CParticleSystemSceneNode(createDefaultEmitter, parent, mgr, id, position, rotation, scale), m_alpha_additive(false) { - fakemat.Lighting = false; - fakemat.ZWriteEnable = false; - fakemat.MaterialType = irr_driver->getShader(ES_RAIN); - fakemat.setTexture(0, getMaterial(0).getTexture(0)); - fakemat.BlendOperation = video::EBO_NONE; - fakemat.FrontfaceCulling = false; - fakemat.BackfaceCulling = false; glGenBuffers(1, &initial_values_buffer); glGenBuffers(2, tfb_buffers); glGenBuffers(1, &quaternionsbuffer); diff --git a/src/graphics/gpuparticles.hpp b/src/graphics/gpuparticles.hpp index 5228ed0e1..bb43ff84b 100644 --- a/src/graphics/gpuparticles.hpp +++ b/src/graphics/gpuparticles.hpp @@ -26,7 +26,6 @@ public: class ParticleSystemProxy : public scene::CParticleSystemSceneNode { protected: - video::SMaterial fakemat; GLuint tfb_buffers[2], initial_values_buffer, heighmapbuffer, heightmaptexture, quaternionsbuffer; GLuint current_simulation_vao, non_current_simulation_vao; GLuint current_hm_simulation_vao, non_currenthm__simulation_vao; diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 1602eb97d..655cee47c 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -853,8 +853,6 @@ void PostProcessing::render() renderPassThrough(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); else if (irr_driver->getSSAOViz()) renderPassThrough(irr_driver->getRTT(RTT_SSAO)); - else if (irr_driver->getShadowViz()) - renderPassThrough(static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_SHADOW0))->DepthBufferTexture); else renderColorLevel(in); } diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 04ab62daf..e34370e77 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -474,12 +474,6 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, const Vec3 *vmin, *vmax; World::getWorld()->getTrack()->getAABB(&vmin, &vmax); - ITexture *ShadowRTT[] = { - m_rtts->getRTT(RTT_SHADOW0), - m_rtts->getRTT(RTT_SHADOW1), - m_rtts->getRTT(RTT_SHADOW2) - }; - const float oldfar = camnode->getFarValue(); const float oldnear = camnode->getNearValue(); float FarValues[] = @@ -562,7 +556,6 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, glDisable(GL_BLEND); glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); -// m_video_driver->setRenderTarget(ShadowRTT[0], true, true); glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getShadowFBO()); glViewport(0, 0, 1024, 1024); glClear(GL_DEPTH_BUFFER_BIT); @@ -682,11 +675,6 @@ void IrrDriver::renderGlow(video::SOverrideMaterial &overridemat, const u32 glowcount = glows.size(); ColorizeProvider * const cb = (ColorizeProvider *) m_shaders->m_callbacks[ES_COLORIZE]; -/* overridemat.Material.MaterialType = m_shaders->getShader(ES_COLORIZE); - overridemat.EnableFlags = video::EMF_MATERIAL_TYPE; - overridemat.EnablePasses = scene::ESNRP_SOLID; - overridemat.Enabled = true;*/ - glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilFunc(GL_ALWAYS, 1, ~0); glEnable(GL_STENCIL_TEST); @@ -710,25 +698,6 @@ void IrrDriver::renderGlow(video::SOverrideMaterial &overridemat, cur->render(); } - // Second round for transparents; it's a no-op for solids -/* m_scene_manager->setCurrentRendertime(scene::ESNRP_TRANSPARENT); - overridemat.Material.MaterialType = m_shaders->getShader(ES_COLORIZE_REF); - for (u32 i = 0; i < glowcount; i++) - { - const GlowData &dat = glows[i]; - scene::ISceneNode * const cur = dat.node; - - // Quick box-based culling - const core::aabbox3df nodebox = cur->getTransformedBoundingBox(); - if (!nodebox.intersectsWithBox(cambox)) - continue; - - cb->setColor(dat.r, dat.g, dat.b); - cur->render(); - } - overridemat.Enabled = false; - overridemat.EnablePasses = 0;*/ - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glDisable(GL_STENCIL_TEST); @@ -984,18 +953,6 @@ void IrrDriver::renderDisplacement(video::SOverrideMaterial &overridemat, glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); - overridemat.Enabled = 1; - overridemat.EnableFlags = video::EMF_MATERIAL_TYPE | video::EMF_TEXTURE0; - overridemat.Material.MaterialType = m_shaders->getShader(ES_DISPLACE); - - overridemat.Material.TextureLayer[0].Texture = - irr_driver->getTexture(FileManager::TEXTURE, "displace.png"); - overridemat.Material.TextureLayer[0].BilinearFilter = - overridemat.Material.TextureLayer[0].TrilinearFilter = true; - overridemat.Material.TextureLayer[0].AnisotropicFilter = 0; - overridemat.Material.TextureLayer[0].TextureWrapU = - overridemat.Material.TextureLayer[0].TextureWrapV = video::ETC_REPEAT; - DisplaceProvider * const cb = (DisplaceProvider *)irr_driver->getCallback(ES_DISPLACE); cb->update(); @@ -1008,7 +965,6 @@ void IrrDriver::renderDisplacement(video::SOverrideMaterial &overridemat, for (int i = 0; i < displacingcount; i++) { - m_scene_manager->setCurrentRendertime(scene::ESNRP_SOLID); m_displacing[i]->render(); @@ -1016,18 +972,7 @@ void IrrDriver::renderDisplacement(video::SOverrideMaterial &overridemat, m_displacing[i]->render(); } - overridemat.Enabled = 0; - // Blur it - video::SMaterial minimat; - minimat.Lighting = false; - minimat.ZWriteEnable = false; - minimat.ZBuffer = video::ECFN_ALWAYS; - minimat.setFlag(video::EMF_TRILINEAR_FILTER, true); - - minimat.TextureLayer[0].TextureWrapU = - minimat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; - m_post_processing->renderGaussian3Blur(m_rtts->getRTT(RTT_DISPLACE), m_rtts->getRTT(RTT_TMP2), 1.f / UserConfigParams::m_width, 1.f / UserConfigParams::m_height); m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, false); diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 0489a41b5..077dc6fdf 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -90,9 +90,6 @@ RTT::RTT() rtts[RTT_SSAO] = drv->addRenderTargetTexture(ssaosize, "rtt.ssao", ECF_R8, stencil); - rtts[RTT_SHADOW0] = drv->addRenderTargetTexture(shadowsize0, "rtt.shadow0", ECF_A8R8G8B8, stencil); - rtts[RTT_SHADOW1] = drv->addRenderTargetTexture(shadowsize1, "rtt.shadow1", ECF_A8R8G8B8, stencil); - rtts[RTT_SHADOW2] = drv->addRenderTargetTexture(shadowsize2, "rtt.shadow2", ECF_A8R8G8B8, stencil); rtts[RTT_WARPV] = drv->addRenderTargetTexture(warpvsize, "rtt.warpv", ECF_A8R8G8B8, stencil); rtts[RTT_WARPH] = drv->addRenderTargetTexture(warphsize, "rtt.warph", ECF_A8R8G8B8, stencil); diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index 813fc084a..9282f885e 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -51,9 +51,6 @@ enum TypeRTT RTT_SSAO, - RTT_SHADOW0, - RTT_SHADOW1, - RTT_SHADOW2, RTT_COLLAPSE, RTT_COLLAPSEH, RTT_COLLAPSEV, diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 9f50109cb..9a82c7e55 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -145,8 +145,6 @@ void Shaders::loadShaders() m_shaders[ES_COLORIZE] = glslmat(std::string(""), dir + "colorize.frag", m_callbacks[ES_COLORIZE], EMT_SOLID); - m_shaders[ES_COLORIZE_REF] = glslmat(std::string(""), dir + "colorize_ref.frag", - m_callbacks[ES_COLORIZE], EMT_SOLID); m_shaders[ES_OBJECTPASS] = glsl_noinput(dir + "objectpass.vert", dir + "objectpass.frag"); m_shaders[ES_OBJECT_UNLIT] = glsl_noinput(dir + "objectpass.vert", dir + "objectpass.frag"); @@ -154,7 +152,6 @@ void Shaders::loadShaders() m_shaders[ES_OBJECTPASS_RIMLIT] = glsl_noinput(dir + "objectpass_rimlit.vert", dir + "objectpass_rimlit.frag"); m_shaders[ES_SUNLIGHT] = glsl_noinput(std::string(""), dir + "sunlight.frag"); - m_shaders[ES_SUNLIGHT_SHADOW] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_MLAA_COLOR1] = glsl(dir + "mlaa_offset.vert", dir + "mlaa_color1.frag", m_callbacks[ES_MLAA_COLOR1]); diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index c00c5c5b9..c0b8352e7 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -538,12 +538,10 @@ public: ACT(ES_GAUSSIAN3V) \ ACT(ES_MIPVIZ) \ ACT(ES_COLORIZE) \ - ACT(ES_COLORIZE_REF) \ ACT(ES_OBJECT_UNLIT) \ ACT(ES_OBJECTPASS) \ ACT(ES_OBJECTPASS_REF) \ ACT(ES_SUNLIGHT) \ - ACT(ES_SUNLIGHT_SHADOW) \ ACT(ES_OBJECTPASS_RIMLIT) \ ACT(ES_MLAA_COLOR1) \ ACT(ES_MLAA_BLEND2) \ diff --git a/src/graphics/sun.cpp b/src/graphics/sun.cpp index e18fb8796..dd20a74b4 100644 --- a/src/graphics/sun.cpp +++ b/src/graphics/sun.cpp @@ -37,39 +37,6 @@ using namespace core; SunNode::SunNode(scene::ISceneManager* mgr, scene::ISceneNode* parent, float r, float g, float b): LightNode(mgr, parent, 0., r, g, b) { - sq = new ScreenQuad(irr_driver->getVideoDriver()); - - SMaterial &m = sq->getMaterial(); - - m.MaterialType = irr_driver->getShader(ES_SUNLIGHT); - m.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); - m.setTexture(2, irr_driver->getTexture(file_manager->getAsset(FileManager::TEXTURE,"cloudshadow.png"))); - m.setFlag(EMF_BILINEAR_FILTER, false); - m.MaterialTypeParam = pack_textureBlendFunc(EBF_ONE, EBF_ONE); - m.BlendOperation = EBO_ADD; - - if (UserConfigParams::m_shadows) - { -// m.setTexture(3, irr_driver->getRTT(RTT_SHADOW)); - m.setTexture(4, irr_driver->getRTT(RTT_WARPH)); - m.setTexture(5, irr_driver->getRTT(RTT_WARPV)); - - m.TextureLayer[4].BilinearFilter = - m.TextureLayer[5].BilinearFilter = true; - - m.MaterialType = irr_driver->getShader(ES_SUNLIGHT_SHADOW); - } - - for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; i++) - { - m.TextureLayer[i].TextureWrapU = m.TextureLayer[i].TextureWrapV = - ETC_CLAMP_TO_EDGE; - } - - m.TextureLayer[2].TextureWrapU = m.TextureLayer[2].TextureWrapV = ETC_REPEAT; - - m.TextureLayer[2].TrilinearFilter = true; - m_color[0] = r; m_color[1] = g; m_color[2] = b; @@ -89,7 +56,7 @@ void SunNode::render() cb->setPosition(pos.X, pos.Y, pos.Z); return; - array<IRenderTarget> mrt; +/* array<IRenderTarget> mrt; mrt.reallocate(2); mrt.push_back(irr_driver->getRTT(RTT_TMP2)); mrt.push_back(irr_driver->getRTT(RTT_TMP3)); @@ -151,5 +118,5 @@ void SunNode::render() tmpsq.getMaterial().BlendOperation = EBO_ADD; irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_TMP1), false, false); - tmpsq.render(false); + tmpsq.render(false);*/ } From bff22089478aef83b8d4935de8ac93217bed688a Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Wed, 12 Feb 2014 17:46:44 +0100 Subject: [PATCH 35/68] Remove rain effect. Rain enabled map crashes with non glsl codepath, and having a particle effect handled separatly from others effect made it unmaintainable. Rain must be implemented using gfx file with eventually a custom property. --- src/graphics/gpuparticles.cpp | 130 +--------------------------------- src/graphics/gpuparticles.hpp | 32 --------- src/graphics/rain.cpp | 14 ++-- 3 files changed, 8 insertions(+), 168 deletions(-) diff --git a/src/graphics/gpuparticles.cpp b/src/graphics/gpuparticles.cpp index 01487e970..7bda836b2 100644 --- a/src/graphics/gpuparticles.cpp +++ b/src/graphics/gpuparticles.cpp @@ -12,35 +12,6 @@ GLuint getTextureGLuint(irr::video::ITexture *tex) { #define COMPONENTCOUNT 8 -GPUParticle::GPUParticle(scene::ISceneNode *parent, scene::ISceneManager* mgr, ITexture *tex) -: scene::ISceneNode(parent, mgr, -1) { - fakemat.Lighting = false; - fakemat.ZWriteEnable = false; - fakemat.MaterialType = irr_driver->getShader(ES_RAIN); - fakemat.Thickness = 200; - fakemat.setTexture(0, tex); - fakemat.BlendOperation = video::EBO_NONE; - setAutomaticCulling(0); -} - -void GPUParticle::render() { - simulate(); - draw(); - // We need to force irrlicht to update its internal states - irr::video::IVideoDriver * const drv = irr_driver->getVideoDriver(); - drv->setMaterial(fakemat); - static_cast<irr::video::COpenGLDriver*>(drv)->setRenderStates3DMode(); -} - -void GPUParticle::OnRegisterSceneNode() { - if ( - (irr_driver->getRenderPass() & irr::scene::ESNRP_TRANSPARENT) == irr::scene::ESNRP_TRANSPARENT) - { - SceneManager->registerNodeForRendering(this, irr::scene::ESNRP_TRANSPARENT); - } - ISceneNode::OnRegisterSceneNode(); -} - scene::IParticleSystemSceneNode *ParticleSystemProxy::addParticleNode( bool withDefaultEmitter, ISceneNode* parent, s32 id, const core::vector3df& position, @@ -600,103 +571,4 @@ void ParticleSystemProxy::OnRegisterSceneNode() SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT_EFFECT); ISceneNode::OnRegisterSceneNode(); } -} - -RainNode::RainNode(scene::ISceneManager* mgr, ITexture *tex) -: GPUParticle(0, mgr, tex) -{ - RenderProgram = LoadProgram(file_manager->getAsset("shaders/rain.vert").c_str(), file_manager->getAsset("shaders/rain.frag").c_str()); - loc_screenw = glGetUniformLocation(RenderProgram, "screenw"); - loc_screen = glGetUniformLocation(RenderProgram, "screen"); - loc_invproj = glGetUniformLocation(RenderProgram, "invproj"); - texloc_tex = glGetUniformLocation(RenderProgram, "tex"); - texloc_normal_and_depths = glGetUniformLocation(RenderProgram, "normals_and_depth"); - - const char *varyings[] = { "currentPosition" }; - SimulationProgram = LoadTFBProgram(file_manager->getAsset("shaders/rainsim.vert").c_str(), varyings, 1); - loc_campos = glGetUniformLocation(SimulationProgram, "campos"); - loc_viewm = glGetUniformLocation(SimulationProgram, "viewm"); - loc_time = glGetUniformLocation(SimulationProgram, "time"); - count = 2500; - area = 3500; - - u32 i; - float x, y, z, vertices[7500]; - for (i = 0; i < count; i++) - { - x = ((rand() % area) - area / 2) / 100.0f; - y = ((rand() % 2400)) / 100.0f; - z = ((rand() % area) - area / 2) / 100.0f; - - vertices[3 * i] = x; - vertices[3 * i + 1] = y; - vertices[3 * i + 2] = z; - } - - texture = getTextureGLuint(tex); - normal_and_depth = getTextureGLuint(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)); - glGenBuffers(2, tfb_vertex_buffer); - glBindBuffer(GL_ARRAY_BUFFER, tfb_vertex_buffer[0]); - glBufferData(GL_ARRAY_BUFFER, 3 * count * sizeof(float), vertices, GL_STREAM_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, tfb_vertex_buffer[1]); - glBufferData(GL_ARRAY_BUFFER, 3 * count * sizeof(float), 0, GL_STREAM_DRAW); - - box.addInternalPoint(vector3df((float)(-area / 2))); - box.addInternalPoint(vector3df((float)(area / 2))); -} - -void RainNode::simulate() { - glUseProgram(SimulationProgram); - const float time = irr_driver->getDevice()->getTimer()->getTime() / 90.0f; - const irr::core::matrix4 viewm = irr_driver->getVideoDriver()->getTransform(irr::video::ETS_VIEW); - const irr::core::vector3df campos = irr_driver->getSceneManager()->getActiveCamera()->getPosition(); - - glEnable(GL_RASTERIZER_DISCARD); - glEnableVertexAttribArray(0); - glBindBuffer(GL_ARRAY_BUFFER, tfb_vertex_buffer[0]); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); - glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfb_vertex_buffer[1]); - - glUniformMatrix4fv(loc_viewm, 1, GL_FALSE, viewm.pointer()); - glUniform1f(loc_time, time); - glUniform3f(loc_campos, campos.X, campos.Y, campos.Z); - glBeginTransformFeedback(GL_POINTS); - glDrawArrays(GL_POINTS, 0, count); - glEndTransformFeedback(); - glDisable(GL_RASTERIZER_DISCARD); -} - -void RainNode::draw() { - const float screenw = (float)UserConfigParams::m_width; - - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); - glEnable(GL_POINT_SPRITE); - glUseProgram(RenderProgram); - glEnableVertexAttribArray(0); - glBindBuffer(GL_ARRAY_BUFFER, tfb_vertex_buffer[1]); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); - - float screen[2] = { - (float)UserConfigParams::m_width, - (float)UserConfigParams::m_height - }; - irr::core::matrix4 invproj = irr_driver->getVideoDriver()->getTransform(irr::video::ETS_PROJECTION); - invproj.makeInverse(); - - bindUniformToTextureUnit(texloc_tex, texture, 0); - bindUniformToTextureUnit(texloc_normal_and_depths, normal_and_depth, 1); - - glUniformMatrix4fv(loc_invproj, 1, GL_FALSE, invproj.pointer()); - glUniform2f(loc_screen, screen[0], screen[1]); - glUniform1f(loc_screenw, screenw); - glDrawArrays(GL_POINTS, 0, count); - glDisableVertexAttribArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glActiveTexture(GL_TEXTURE0); - glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); -} - -const core::aabbox3d<f32>& RainNode::getBoundingBox() const -{ - return box; -} +} \ No newline at end of file diff --git a/src/graphics/gpuparticles.hpp b/src/graphics/gpuparticles.hpp index bb43ff84b..62714d4bc 100644 --- a/src/graphics/gpuparticles.hpp +++ b/src/graphics/gpuparticles.hpp @@ -11,19 +11,6 @@ namespace irr { namespace video{ class ITexture; } } GLuint getTextureGLuint(irr::video::ITexture *tex); -class GPUParticle : public scene::ISceneNode -{ -protected: - video::SMaterial fakemat; - virtual void simulate() = 0; - virtual void draw() = 0; -public: - GPUParticle(scene::ISceneNode *parent, scene::ISceneManager* mgr, - video::ITexture *tex); - virtual void render(); - virtual void OnRegisterSceneNode(); -}; - class ParticleSystemProxy : public scene::CParticleSystemSceneNode { protected: GLuint tfb_buffers[2], initial_values_buffer, heighmapbuffer, heightmaptexture, quaternionsbuffer; @@ -75,23 +62,4 @@ public: void setFlip(); }; -class RainNode : public GPUParticle -{ -protected: - GLuint SimulationProgram, RenderProgram, tfb_vertex_buffer[2]; - unsigned count; - GLuint texture, normal_and_depth; - GLuint loc_campos, loc_viewm, loc_time; - GLuint loc_screenw, loc_screen, loc_invproj, texloc_tex, texloc_normal_and_depths; - s32 area; - core::aabbox3d<f32> box; - - virtual void simulate(); - virtual void draw(); -public: - RainNode(scene::ISceneManager* mgr, video::ITexture *tex); - virtual const core::aabbox3d<f32>& getBoundingBox() const; - virtual u32 getMaterialCount() const { return 1; } -}; - #endif // GPUPARTICLES_H diff --git a/src/graphics/rain.cpp b/src/graphics/rain.cpp index f71d2f956..3c9a75bd2 100644 --- a/src/graphics/rain.cpp +++ b/src/graphics/rain.cpp @@ -55,17 +55,17 @@ Rain::Rain(Camera *camera, irr::scene::ISceneNode* parent) : m_thunder_sound(0) RandomGenerator g; m_next_lightning = (float)g.get(35); - RainNode *node = new RainNode(irr_driver->getSceneManager(), m->getTexture()); - m_node = irr_driver->addPerCameraNode(node, camera->getCameraSceneNode(), parent); - m_node->setAutomaticCulling(0); +// RainNode *node = new RainNode(irr_driver->getSceneManager(), m->getTexture()); +// m_node = irr_driver->addPerCameraNode(node, camera->getCameraSceneNode(), parent); +// m_node->setAutomaticCulling(0); } // Rain // ---------------------------------------------------------------------------- Rain::~Rain() { - m_node->drop(); // drop STK's reference - m_node->remove(); // Then remove it from the scene graph. +// m_node->drop(); // drop STK's reference +// m_node->remove(); // Then remove it from the scene graph. if (m_lightning && m_thunder_sound != NULL) sfx_manager->deleteSFX(m_thunder_sound); } @@ -98,12 +98,12 @@ void Rain::update(float dt) void Rain::setPosition(const core::vector3df& position) { - m_node->getChild()->setPosition(position); +// m_node->getChild()->setPosition(position); } // setPosition // ---------------------------------------------------------------------------- void Rain::setCamera(scene::ICameraSceneNode* camera) { - m_node->setCamera(camera); +// m_node->setCamera(camera); } From 8c5a5b9b206b3e11810eaa73c7a3afc4e570264c Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Wed, 12 Feb 2014 18:31:21 +0100 Subject: [PATCH 36/68] STKMesh: Force readonly materials. We never changed materials on the fly but better safe than sorry. --- src/graphics/stkmesh.cpp | 12 ++++++++++-- src/graphics/stkmesh.hpp | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 554faa97e..1bd5c177c 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -150,7 +150,7 @@ STKMesh::STKMesh(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::IScene const irr::core::vector3df& scale) : CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale) { - createGLMeshes(); + setMesh(mesh); } void STKMesh::createGLMeshes() @@ -185,11 +185,18 @@ void STKMesh::cleanGLMeshes() void STKMesh::setMesh(irr::scene::IMesh* mesh) { + CMeshSceneNode::setReadOnlyMaterials(true); CMeshSceneNode::setMesh(mesh); cleanGLMeshes(); createGLMeshes(); } +void STKMesh::setReadOnlyMaterials(bool readonly) +{ + if (!readonly) + Log::error("STKMesh", "Cannot set non read only material, use setMesh instead"); +} + STKMesh::~STKMesh() { cleanGLMeshes(); @@ -982,7 +989,8 @@ void STKMesh::render() scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i); if (mb) { - const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i]; + assert(isReadOnlyMaterials()); + const video::SMaterial& material = Materials[i]; video::IMaterialRenderer* rnd = driver->getMaterialRenderer(material.MaterialType); bool transparent = (rnd && rnd->isTransparent()); diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 74cde2358..98c2d8ca0 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -73,6 +73,7 @@ public: const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f)); virtual void render(); virtual void setMesh(irr::scene::IMesh* mesh); + void setReadOnlyMaterials(bool readonly); ~STKMesh(); }; From 3d61056b812dd67130d0eac920f1674c4b6b797b Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Wed, 12 Feb 2014 18:46:28 +0100 Subject: [PATCH 37/68] Revert "STKMesh: Force readonly materials." This reverts commit 8c5a5b9b206b3e11810eaa73c7a3afc4e570264c. --- src/graphics/stkmesh.cpp | 12 ++---------- src/graphics/stkmesh.hpp | 1 - 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 1bd5c177c..554faa97e 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -150,7 +150,7 @@ STKMesh::STKMesh(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::IScene const irr::core::vector3df& scale) : CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale) { - setMesh(mesh); + createGLMeshes(); } void STKMesh::createGLMeshes() @@ -185,18 +185,11 @@ void STKMesh::cleanGLMeshes() void STKMesh::setMesh(irr::scene::IMesh* mesh) { - CMeshSceneNode::setReadOnlyMaterials(true); CMeshSceneNode::setMesh(mesh); cleanGLMeshes(); createGLMeshes(); } -void STKMesh::setReadOnlyMaterials(bool readonly) -{ - if (!readonly) - Log::error("STKMesh", "Cannot set non read only material, use setMesh instead"); -} - STKMesh::~STKMesh() { cleanGLMeshes(); @@ -989,8 +982,7 @@ void STKMesh::render() scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i); if (mb) { - assert(isReadOnlyMaterials()); - const video::SMaterial& material = Materials[i]; + const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i]; video::IMaterialRenderer* rnd = driver->getMaterialRenderer(material.MaterialType); bool transparent = (rnd && rnd->isTransparent()); diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 98c2d8ca0..74cde2358 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -73,7 +73,6 @@ public: const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f)); virtual void render(); virtual void setMesh(irr::scene::IMesh* mesh); - void setReadOnlyMaterials(bool readonly); ~STKMesh(); }; From 0243546e4d7d9c2ea72569a9577bf739ac91804e Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Wed, 12 Feb 2014 22:16:10 +0100 Subject: [PATCH 38/68] Use an openGL 3.3 compatibility context when available. --- data/shaders/billboard.frag | 2 +- data/shaders/billboard.vert | 2 +- data/shaders/bloom.frag | 2 +- data/shaders/bloomblend.frag | 2 +- data/shaders/bloompower.frag | 2 +- data/shaders/bubble.frag | 2 +- data/shaders/bubble.vert | 2 +- data/shaders/caustics.frag | 2 +- data/shaders/collapse.frag | 2 +- data/shaders/color_levels.frag | 2 +- data/shaders/coloredquad.frag | 2 +- data/shaders/coloredquad.vert | 2 +- data/shaders/colorize.frag | 2 +- data/shaders/colortexturedquad.frag | 2 +- data/shaders/colortexturedquad.vert | 2 +- data/shaders/detailledobject_pass2.frag | 2 +- data/shaders/displace.frag | 2 +- data/shaders/displace.vert | 2 +- data/shaders/farplane.vert | 2 +- data/shaders/flipparticle.vert | 2 +- data/shaders/fog.frag | 2 +- data/shaders/gaussian3h.frag | 2 +- data/shaders/gaussian3v.frag | 2 +- data/shaders/gaussian6h.frag | 2 +- data/shaders/gaussian6v.frag | 2 +- data/shaders/glow.frag | 2 +- data/shaders/godfade.frag | 2 +- data/shaders/godray.frag | 2 +- data/shaders/grass_pass1.vert | 2 +- data/shaders/grass_pass2.vert | 2 +- data/shaders/mipviz.frag | 2 +- data/shaders/mlaa_blend2.frag | 2 +- data/shaders/mlaa_color1.frag | 2 +- data/shaders/mlaa_neigh3.frag | 2 +- data/shaders/mlaa_offset.vert | 2 +- data/shaders/motion_blur.frag | 2 +- data/shaders/motion_blur.vert | 2 +- data/shaders/multiply.frag | 2 +- data/shaders/normalmap.frag | 2 +- data/shaders/normalmap.vert | 2 +- data/shaders/object_pass1.frag | 2 +- data/shaders/object_pass1.vert | 2 +- data/shaders/object_pass2.frag | 2 +- data/shaders/object_pass2.vert | 2 +- data/shaders/object_unlit.frag | 2 +- data/shaders/objectpass.frag | 2 +- data/shaders/objectpass.vert | 2 +- data/shaders/objectpass_ref.frag | 2 +- data/shaders/objectpass_rimlit.frag | 2 +- data/shaders/objectpass_rimlit.vert | 2 +- data/shaders/objectpass_spheremap.frag | 2 +- data/shaders/objectref_pass1.frag | 2 +- data/shaders/objectref_pass1.vert | 2 +- data/shaders/objectref_pass2.frag | 2 +- data/shaders/particle.frag | 2 +- data/shaders/particle.vert | 2 +- data/shaders/particlesimheightmap.vert | 2 +- data/shaders/pass.frag | 2 +- data/shaders/pass.vert | 2 +- data/shaders/penumbrah.frag | 2 +- data/shaders/penumbrav.frag | 2 +- data/shaders/pointemitter.vert | 2 +- data/shaders/pointlight.frag | 2 +- data/shaders/ppdisplace.frag | 2 +- data/shaders/rain.frag | 2 +- data/shaders/rain.vert | 2 +- data/shaders/rainsim.vert | 2 +- data/shaders/screenquad.vert | 2 +- data/shaders/shadow.geom | 2 +- data/shaders/shadow.vert | 2 +- data/shaders/shadowgen.frag | 2 +- data/shaders/shadowimportance.frag | 2 +- data/shaders/shadowimportance.vert | 2 +- data/shaders/shadowpass.frag | 2 +- data/shaders/shadowpass.vert | 2 +- data/shaders/shadowwarph.frag | 2 +- data/shaders/shadowwarpv.frag | 2 +- data/shaders/skinning.vert | 2 +- data/shaders/skybox.frag | 2 +- data/shaders/skybox.vert | 2 +- data/shaders/splatting.frag | 2 +- data/shaders/splatting.vert | 2 +- data/shaders/ssao.frag | 2 +- data/shaders/sunlight.frag | 2 +- data/shaders/sunlightshadow.frag | 2 +- data/shaders/texturedquad.frag | 2 +- data/shaders/texturedquad.vert | 2 +- data/shaders/transparent.frag | 2 +- data/shaders/transparent.vert | 2 +- data/shaders/transparentfog.frag | 2 +- data/shaders/untextured_object.frag | 2 +- data/shaders/untextured_object.vert | 2 +- data/shaders/water.frag | 2 +- data/shaders/water.vert | 2 +- lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp | 5 ++--- lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp | 4 ++-- 96 files changed, 98 insertions(+), 99 deletions(-) diff --git a/data/shaders/billboard.frag b/data/shaders/billboard.frag index d43518c6f..80a4942eb 100644 --- a/data/shaders/billboard.frag +++ b/data/shaders/billboard.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; in vec2 uv; diff --git a/data/shaders/billboard.vert b/data/shaders/billboard.vert index 9a9f34d28..c707ab548 100644 --- a/data/shaders/billboard.vert +++ b/data/shaders/billboard.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ModelViewMatrix; uniform mat4 ProjectionMatrix; uniform vec3 Position; diff --git a/data/shaders/bloom.frag b/data/shaders/bloom.frag index 886b49ea0..5025f23aa 100644 --- a/data/shaders/bloom.frag +++ b/data/shaders/bloom.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform float low; diff --git a/data/shaders/bloomblend.frag b/data/shaders/bloomblend.frag index 8e4031fa6..edcac3f31 100644 --- a/data/shaders/bloomblend.frag +++ b/data/shaders/bloomblend.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; in vec2 uv; diff --git a/data/shaders/bloompower.frag b/data/shaders/bloompower.frag index f7d4ce4d3..0c29ce9b2 100644 --- a/data/shaders/bloompower.frag +++ b/data/shaders/bloompower.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform float power; uniform sampler2D tex; diff --git a/data/shaders/bubble.frag b/data/shaders/bubble.frag index d344c64ed..0e1f2d4f9 100644 --- a/data/shaders/bubble.frag +++ b/data/shaders/bubble.frag @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#version 130 +#version 330 uniform sampler2D tex; uniform float transparency; in vec2 uv; diff --git a/data/shaders/bubble.vert b/data/shaders/bubble.vert index f26f0a246..6e9981bfb 100644 --- a/data/shaders/bubble.vert +++ b/data/shaders/bubble.vert @@ -17,7 +17,7 @@ // Creates a bubble (wave) effect by distorting the texture depending on time -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; uniform float time; diff --git a/data/shaders/caustics.frag b/data/shaders/caustics.frag index 5e976a3c8..e92e03a8c 100644 --- a/data/shaders/caustics.frag +++ b/data/shaders/caustics.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform sampler2D caustictex; uniform vec2 dir; diff --git a/data/shaders/collapse.frag b/data/shaders/collapse.frag index 3a7957a68..573631f9a 100644 --- a/data/shaders/collapse.frag +++ b/data/shaders/collapse.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform sampler2D oldtex; uniform vec2 pixel; diff --git a/data/shaders/color_levels.frag b/data/shaders/color_levels.frag index 33bca9d06..58ccee832 100644 --- a/data/shaders/color_levels.frag +++ b/data/shaders/color_levels.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform vec3 inlevel; uniform vec2 outlevel; diff --git a/data/shaders/coloredquad.frag b/data/shaders/coloredquad.frag index 6afba1d06..9216e0503 100644 --- a/data/shaders/coloredquad.frag +++ b/data/shaders/coloredquad.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform ivec4 color; out vec4 FragColor; diff --git a/data/shaders/coloredquad.vert b/data/shaders/coloredquad.vert index 647155235..31c2a0db1 100644 --- a/data/shaders/coloredquad.vert +++ b/data/shaders/coloredquad.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform vec2 center; uniform vec2 size; diff --git a/data/shaders/colorize.frag b/data/shaders/colorize.frag index 160fa4362..b82462c1f 100644 --- a/data/shaders/colorize.frag +++ b/data/shaders/colorize.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform vec3 col; out vec4 FragColor; diff --git a/data/shaders/colortexturedquad.frag b/data/shaders/colortexturedquad.frag index ec885322b..1e14e5985 100644 --- a/data/shaders/colortexturedquad.frag +++ b/data/shaders/colortexturedquad.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; in vec2 uv; diff --git a/data/shaders/colortexturedquad.vert b/data/shaders/colortexturedquad.vert index b5827a64a..4489e9cbf 100644 --- a/data/shaders/colortexturedquad.vert +++ b/data/shaders/colortexturedquad.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform vec2 center; uniform vec2 size; uniform vec2 texcenter; diff --git a/data/shaders/detailledobject_pass2.frag b/data/shaders/detailledobject_pass2.frag index bc2de52a1..7afaee691 100644 --- a/data/shaders/detailledobject_pass2.frag +++ b/data/shaders/detailledobject_pass2.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D Albedo; uniform sampler2D Detail; uniform sampler2D DiffuseMap; diff --git a/data/shaders/displace.frag b/data/shaders/displace.frag index 1bd731a71..1c22fd42e 100644 --- a/data/shaders/displace.frag +++ b/data/shaders/displace.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform vec2 dir; uniform vec2 dir2; diff --git a/data/shaders/displace.vert b/data/shaders/displace.vert index a59c56656..7c811d4aa 100644 --- a/data/shaders/displace.vert +++ b/data/shaders/displace.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelViewMatrix; diff --git a/data/shaders/farplane.vert b/data/shaders/farplane.vert index 1f7bc1fb9..eea0eeede 100644 --- a/data/shaders/farplane.vert +++ b/data/shaders/farplane.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform mat4 ModelViewProjectionMatrix; void main() { diff --git a/data/shaders/flipparticle.vert b/data/shaders/flipparticle.vert index d834b7ee9..24ce2773a 100644 --- a/data/shaders/flipparticle.vert +++ b/data/shaders/flipparticle.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ProjectionMatrix; uniform mat4 ViewMatrix; diff --git a/data/shaders/fog.frag b/data/shaders/fog.frag index 120f5734e..60dd7dcf0 100644 --- a/data/shaders/fog.frag +++ b/data/shaders/fog.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform float fogmax; diff --git a/data/shaders/gaussian3h.frag b/data/shaders/gaussian3h.frag index 4e3e3f54d..07f4d4092 100644 --- a/data/shaders/gaussian3h.frag +++ b/data/shaders/gaussian3h.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform vec2 pixel; diff --git a/data/shaders/gaussian3v.frag b/data/shaders/gaussian3v.frag index f5617c9b7..365e25678 100644 --- a/data/shaders/gaussian3v.frag +++ b/data/shaders/gaussian3v.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform vec2 pixel; diff --git a/data/shaders/gaussian6h.frag b/data/shaders/gaussian6h.frag index 6530a9a1a..a2ee0eb26 100644 --- a/data/shaders/gaussian6h.frag +++ b/data/shaders/gaussian6h.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform vec2 pixel; diff --git a/data/shaders/gaussian6v.frag b/data/shaders/gaussian6v.frag index 7a66dfe8c..8150cbbf6 100644 --- a/data/shaders/gaussian6v.frag +++ b/data/shaders/gaussian6v.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform vec2 pixel; diff --git a/data/shaders/glow.frag b/data/shaders/glow.frag index ebf944a31..0821b420a 100644 --- a/data/shaders/glow.frag +++ b/data/shaders/glow.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; in vec2 uv; diff --git a/data/shaders/godfade.frag b/data/shaders/godfade.frag index f8166b1a6..e44fdec04 100644 --- a/data/shaders/godfade.frag +++ b/data/shaders/godfade.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform vec3 col; out vec4 FragColor; diff --git a/data/shaders/godray.frag b/data/shaders/godray.frag index 3e1c5aad6..83422eb9c 100644 --- a/data/shaders/godray.frag +++ b/data/shaders/godray.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform vec2 sunpos; diff --git a/data/shaders/grass_pass1.vert b/data/shaders/grass_pass1.vert index 49d6859c7..4d38b4f0a 100644 --- a/data/shaders/grass_pass1.vert +++ b/data/shaders/grass_pass1.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform vec3 windDir; uniform mat4 ModelViewProjectionMatrix; uniform mat4 TransposeInverseModelView; diff --git a/data/shaders/grass_pass2.vert b/data/shaders/grass_pass2.vert index 607caa7d0..0d60826ea 100644 --- a/data/shaders/grass_pass2.vert +++ b/data/shaders/grass_pass2.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform vec3 windDir; uniform mat4 ModelViewProjectionMatrix; diff --git a/data/shaders/mipviz.frag b/data/shaders/mipviz.frag index b329a49dc..e63ca8158 100644 --- a/data/shaders/mipviz.frag +++ b/data/shaders/mipviz.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform vec2 texsize; diff --git a/data/shaders/mlaa_blend2.frag b/data/shaders/mlaa_blend2.frag index 3ef21ca57..9514f2e2a 100644 --- a/data/shaders/mlaa_blend2.frag +++ b/data/shaders/mlaa_blend2.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility #define MAX_SEARCH_STEPS 8.0 #define MAX_DISTANCE 33.0 diff --git a/data/shaders/mlaa_color1.frag b/data/shaders/mlaa_color1.frag index 49828738b..0b8a80141 100644 --- a/data/shaders/mlaa_color1.frag +++ b/data/shaders/mlaa_color1.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility in vec4 offset[2]; in vec2 uv; diff --git a/data/shaders/mlaa_neigh3.frag b/data/shaders/mlaa_neigh3.frag index 5bf5fdc22..68929c321 100644 --- a/data/shaders/mlaa_neigh3.frag +++ b/data/shaders/mlaa_neigh3.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility in vec4 offset[2]; in vec2 uv; out vec4 FragColor; diff --git a/data/shaders/mlaa_offset.vert b/data/shaders/mlaa_offset.vert index 6725e19e6..d1c36cd99 100644 --- a/data/shaders/mlaa_offset.vert +++ b/data/shaders/mlaa_offset.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform vec2 PIXEL_SIZE; uniform mat4 ModelViewProjectionMatrix; diff --git a/data/shaders/motion_blur.frag b/data/shaders/motion_blur.frag index 9521814ad..c12fee1c8 100644 --- a/data/shaders/motion_blur.frag +++ b/data/shaders/motion_blur.frag @@ -21,7 +21,7 @@ // The actual boost amount (which linearly scales the blur to be shown). // should be in the range [0.0, 1.0], though a larger value might make // the blurring too string. Atm we are using [0, 0.5]. -#version 130 +#version 330 compatibility uniform float boost_amount; // The color buffer to use. diff --git a/data/shaders/motion_blur.vert b/data/shaders/motion_blur.vert index 608115086..5c02f2bd3 100644 --- a/data/shaders/motion_blur.vert +++ b/data/shaders/motion_blur.vert @@ -17,7 +17,7 @@ // motion_blur.vert -#version 130 +#version 330 compatibility void main() { diff --git a/data/shaders/multiply.frag b/data/shaders/multiply.frag index ca9cbd8fa..1e9303bf1 100644 --- a/data/shaders/multiply.frag +++ b/data/shaders/multiply.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex1; uniform sampler2D tex2; diff --git a/data/shaders/normalmap.frag b/data/shaders/normalmap.frag index f977e5e46..00410d916 100644 --- a/data/shaders/normalmap.frag +++ b/data/shaders/normalmap.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D normalMap; noperspective in vec3 tangent; diff --git a/data/shaders/normalmap.vert b/data/shaders/normalmap.vert index 13b53645e..b7f74865d 100644 --- a/data/shaders/normalmap.vert +++ b/data/shaders/normalmap.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; uniform mat4 TransposeInverseModelView; diff --git a/data/shaders/object_pass1.frag b/data/shaders/object_pass1.frag index 5c47fafc7..ff55a147d 100644 --- a/data/shaders/object_pass1.frag +++ b/data/shaders/object_pass1.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 noperspective in vec3 nor; out vec2 EncodedNormal; diff --git a/data/shaders/object_pass1.vert b/data/shaders/object_pass1.vert index 649dd13dc..edf27d885 100644 --- a/data/shaders/object_pass1.vert +++ b/data/shaders/object_pass1.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; uniform mat4 TransposeInverseModelView; diff --git a/data/shaders/object_pass2.frag b/data/shaders/object_pass2.frag index fbcd05641..7d4d81c27 100644 --- a/data/shaders/object_pass2.frag +++ b/data/shaders/object_pass2.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D Albedo; uniform sampler2D DiffuseMap; uniform sampler2D SpecularMap; diff --git a/data/shaders/object_pass2.vert b/data/shaders/object_pass2.vert index 4ac051f76..b20eeac18 100644 --- a/data/shaders/object_pass2.vert +++ b/data/shaders/object_pass2.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; in vec3 Position; diff --git a/data/shaders/object_unlit.frag b/data/shaders/object_unlit.frag index d5874242b..3677baae3 100644 --- a/data/shaders/object_unlit.frag +++ b/data/shaders/object_unlit.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; in vec2 uv; out vec4 FragColor; diff --git a/data/shaders/objectpass.frag b/data/shaders/objectpass.frag index 3ecc698ba..436679563 100644 --- a/data/shaders/objectpass.frag +++ b/data/shaders/objectpass.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform sampler2D lighttex; uniform int hastex; diff --git a/data/shaders/objectpass.vert b/data/shaders/objectpass.vert index f40e32215..877192df0 100644 --- a/data/shaders/objectpass.vert +++ b/data/shaders/objectpass.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; uniform mat4 TransposeInverseModelView; uniform mat4 TextureMatrix0; diff --git a/data/shaders/objectpass_ref.frag b/data/shaders/objectpass_ref.frag index 43915ee90..38b42a644 100644 --- a/data/shaders/objectpass_ref.frag +++ b/data/shaders/objectpass_ref.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform int hastex; uniform float objectid; diff --git a/data/shaders/objectpass_rimlit.frag b/data/shaders/objectpass_rimlit.frag index 7e701338d..a17f533b9 100644 --- a/data/shaders/objectpass_rimlit.frag +++ b/data/shaders/objectpass_rimlit.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D Albedo; uniform sampler2D DiffuseMap; uniform sampler2D SpecularMap; diff --git a/data/shaders/objectpass_rimlit.vert b/data/shaders/objectpass_rimlit.vert index adf0c9477..7910ebb75 100644 --- a/data/shaders/objectpass_rimlit.vert +++ b/data/shaders/objectpass_rimlit.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; uniform mat4 TransposeInverseModelView; diff --git a/data/shaders/objectpass_spheremap.frag b/data/shaders/objectpass_spheremap.frag index b46610199..9d726b99a 100644 --- a/data/shaders/objectpass_spheremap.frag +++ b/data/shaders/objectpass_spheremap.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; noperspective in vec3 nor; diff --git a/data/shaders/objectref_pass1.frag b/data/shaders/objectref_pass1.frag index 8c5500dbd..06c8c413e 100644 --- a/data/shaders/objectref_pass1.frag +++ b/data/shaders/objectref_pass1.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; noperspective in vec3 nor; diff --git a/data/shaders/objectref_pass1.vert b/data/shaders/objectref_pass1.vert index e75896eeb..462efa8ab 100644 --- a/data/shaders/objectref_pass1.vert +++ b/data/shaders/objectref_pass1.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; uniform mat4 TransposeInverseModelView; diff --git a/data/shaders/objectref_pass2.frag b/data/shaders/objectref_pass2.frag index 5c1589f98..e48755946 100644 --- a/data/shaders/objectref_pass2.frag +++ b/data/shaders/objectref_pass2.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D Albedo; uniform sampler2D DiffuseMap; uniform sampler2D SpecularMap; diff --git a/data/shaders/particle.frag b/data/shaders/particle.frag index 0c841cf5b..1b6c5f200 100644 --- a/data/shaders/particle.frag +++ b/data/shaders/particle.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform sampler2D dtex; uniform mat4 invproj; diff --git a/data/shaders/particle.vert b/data/shaders/particle.vert index fcfc3af0d..73b0dd8de 100644 --- a/data/shaders/particle.vert +++ b/data/shaders/particle.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ProjectionMatrix; uniform mat4 ViewMatrix; diff --git a/data/shaders/particlesimheightmap.vert b/data/shaders/particlesimheightmap.vert index c731612db..09fa55a98 100644 --- a/data/shaders/particlesimheightmap.vert +++ b/data/shaders/particlesimheightmap.vert @@ -1,4 +1,4 @@ -#version 140 +#version 330 uniform int dt; uniform mat4 sourcematrix; uniform int level; diff --git a/data/shaders/pass.frag b/data/shaders/pass.frag index e736e2326..327fcdffc 100644 --- a/data/shaders/pass.frag +++ b/data/shaders/pass.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; out vec4 FragColor; diff --git a/data/shaders/pass.vert b/data/shaders/pass.vert index 8911049be..f2003abef 100644 --- a/data/shaders/pass.vert +++ b/data/shaders/pass.vert @@ -1,5 +1,5 @@ // Passthrough shader for drawQuad() -#version 130 +#version 330 compatibility out vec2 uv; diff --git a/data/shaders/penumbrah.frag b/data/shaders/penumbrah.frag index 4f18e8f5a..ab8888c29 100644 --- a/data/shaders/penumbrah.frag +++ b/data/shaders/penumbrah.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform vec2 pixel; diff --git a/data/shaders/penumbrav.frag b/data/shaders/penumbrav.frag index 790b86d02..229fa6e20 100644 --- a/data/shaders/penumbrav.frag +++ b/data/shaders/penumbrav.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform vec2 pixel; diff --git a/data/shaders/pointemitter.vert b/data/shaders/pointemitter.vert index ea29258b7..64a498dc7 100644 --- a/data/shaders/pointemitter.vert +++ b/data/shaders/pointemitter.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform int dt; uniform mat4 sourcematrix; uniform int level; diff --git a/data/shaders/pointlight.frag b/data/shaders/pointlight.frag index 06a2552f3..f21f49492 100644 --- a/data/shaders/pointlight.frag +++ b/data/shaders/pointlight.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D ntex; uniform sampler2D dtex; diff --git a/data/shaders/ppdisplace.frag b/data/shaders/ppdisplace.frag index 4b2d13248..717f77881 100644 --- a/data/shaders/ppdisplace.frag +++ b/data/shaders/ppdisplace.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform sampler2D dtex; diff --git a/data/shaders/rain.frag b/data/shaders/rain.frag index 493a63f6a..4fb5ad597 100644 --- a/data/shaders/rain.frag +++ b/data/shaders/rain.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform sampler2D normals_and_depth; uniform mat4 invproj; diff --git a/data/shaders/rain.vert b/data/shaders/rain.vert index 77832bfd5..7ac11bc00 100644 --- a/data/shaders/rain.vert +++ b/data/shaders/rain.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform float screenw; void main() diff --git a/data/shaders/rainsim.vert b/data/shaders/rainsim.vert index 4c7a29d98..0a57b8671 100644 --- a/data/shaders/rainsim.vert +++ b/data/shaders/rainsim.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform float time; uniform vec3 campos; uniform mat4 viewm; diff --git a/data/shaders/screenquad.vert b/data/shaders/screenquad.vert index ac88dba7a..1ba822b26 100644 --- a/data/shaders/screenquad.vert +++ b/data/shaders/screenquad.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 in vec2 Position; in vec2 Texcoord; diff --git a/data/shaders/shadow.geom b/data/shaders/shadow.geom index 9dc5cbe93..17754b677 100644 --- a/data/shaders/shadow.geom +++ b/data/shaders/shadow.geom @@ -1,4 +1,4 @@ -#version 330 core +#version 330 uniform mat4 ModelViewProjectionMatrix[4]; layout(triangles) in; diff --git a/data/shaders/shadow.vert b/data/shaders/shadow.vert index 5dbf07048..0bff7c743 100644 --- a/data/shaders/shadow.vert +++ b/data/shaders/shadow.vert @@ -1,4 +1,4 @@ -#version 330 core +#version 330 in vec3 Position; in vec2 Texcoord; diff --git a/data/shaders/shadowgen.frag b/data/shaders/shadowgen.frag index 5ee4a2a93..9cef0fbd6 100644 --- a/data/shaders/shadowgen.frag +++ b/data/shaders/shadowgen.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D halft; // half is a reserved word uniform sampler2D quarter; uniform sampler2D eighth; diff --git a/data/shaders/shadowimportance.frag b/data/shaders/shadowimportance.frag index 50b2edc25..1bcc21cd0 100644 --- a/data/shaders/shadowimportance.frag +++ b/data/shaders/shadowimportance.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D ntex; uniform sampler2D ctex; uniform vec3 campos; diff --git a/data/shaders/shadowimportance.vert b/data/shaders/shadowimportance.vert index 938aeabe9..bb3a8b4b9 100644 --- a/data/shaders/shadowimportance.vert +++ b/data/shaders/shadowimportance.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D dtex; uniform mat4 ipvmat; uniform mat4 shadowmat; diff --git a/data/shaders/shadowpass.frag b/data/shaders/shadowpass.frag index a6bb31048..bcec0ee01 100644 --- a/data/shaders/shadowpass.frag +++ b/data/shaders/shadowpass.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform int hastex; uniform int viz; diff --git a/data/shaders/shadowpass.vert b/data/shaders/shadowpass.vert index 7233ab0d1..009f4b295 100644 --- a/data/shaders/shadowpass.vert +++ b/data/shaders/shadowpass.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D warpx; uniform sampler2D warpy; diff --git a/data/shaders/shadowwarph.frag b/data/shaders/shadowwarph.frag index 820c24d41..38d46dd89 100644 --- a/data/shaders/shadowwarph.frag +++ b/data/shaders/shadowwarph.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform int size; uniform vec2 pixel; diff --git a/data/shaders/shadowwarpv.frag b/data/shaders/shadowwarpv.frag index fb3a0b0fd..5491d8f21 100644 --- a/data/shaders/shadowwarpv.frag +++ b/data/shaders/shadowwarpv.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform int size; uniform vec2 pixel; diff --git a/data/shaders/skinning.vert b/data/shaders/skinning.vert index 2f2e0d083..e9d4dd144 100644 --- a/data/shaders/skinning.vert +++ b/data/shaders/skinning.vert @@ -16,7 +16,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // skinning.vert -#version 130 +#version 330 compatibility #define MAX_JOINT_NUM 36 #define MAX_LIGHT_NUM 8 diff --git a/data/shaders/skybox.frag b/data/shaders/skybox.frag index ab9eda8f5..1d150e975 100644 --- a/data/shaders/skybox.frag +++ b/data/shaders/skybox.frag @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#version 130 +#version 330 compatibility uniform sampler2D tex; uniform sampler2D glow_tex; uniform float transparency; diff --git a/data/shaders/skybox.vert b/data/shaders/skybox.vert index 1db3a3480..7d3097ca5 100644 --- a/data/shaders/skybox.vert +++ b/data/shaders/skybox.vert @@ -17,7 +17,7 @@ // Creates a bubble (wave) effect by distorting the texture depending on time -#version 130 +#version 330 compatibility uniform mat4 ModelViewProjectionMatrix; uniform float time; diff --git a/data/shaders/splatting.frag b/data/shaders/splatting.frag index 31bf34f71..38a8e9631 100644 --- a/data/shaders/splatting.frag +++ b/data/shaders/splatting.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex_layout; uniform sampler2D tex_detail0; uniform sampler2D tex_detail1; diff --git a/data/shaders/splatting.vert b/data/shaders/splatting.vert index 772b957f3..c1a779ef1 100644 --- a/data/shaders/splatting.vert +++ b/data/shaders/splatting.vert @@ -15,7 +15,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; uniform mat4 TransposeInverseModelView; diff --git a/data/shaders/ssao.frag b/data/shaders/ssao.frag index 5af8b3819..1ae1cba7d 100644 --- a/data/shaders/ssao.frag +++ b/data/shaders/ssao.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D ntex; uniform sampler2D dtex; uniform sampler2D noise_texture; diff --git a/data/shaders/sunlight.frag b/data/shaders/sunlight.frag index c6519c5d9..68c1049ed 100644 --- a/data/shaders/sunlight.frag +++ b/data/shaders/sunlight.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D ntex; uniform sampler2D dtex; //uniform sampler2D cloudtex; diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index df53c2bf7..d2b2df054 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D ntex; uniform sampler2D dtex; uniform sampler2DArrayShadow shadowtex; diff --git a/data/shaders/texturedquad.frag b/data/shaders/texturedquad.frag index 6a83ac1fe..48f7335b7 100644 --- a/data/shaders/texturedquad.frag +++ b/data/shaders/texturedquad.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; in vec2 uv; diff --git a/data/shaders/texturedquad.vert b/data/shaders/texturedquad.vert index 668c52eb5..e8a73d3b8 100644 --- a/data/shaders/texturedquad.vert +++ b/data/shaders/texturedquad.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform vec2 center; uniform vec2 size; uniform vec2 texcenter; diff --git a/data/shaders/transparent.frag b/data/shaders/transparent.frag index b891b6f92..e5b1e7c69 100644 --- a/data/shaders/transparent.frag +++ b/data/shaders/transparent.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; in vec2 uv; diff --git a/data/shaders/transparent.vert b/data/shaders/transparent.vert index 9b841a47f..b6ac8f61a 100644 --- a/data/shaders/transparent.vert +++ b/data/shaders/transparent.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; in vec3 Position; diff --git a/data/shaders/transparentfog.frag b/data/shaders/transparentfog.frag index f5365d011..545587044 100644 --- a/data/shaders/transparentfog.frag +++ b/data/shaders/transparentfog.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D tex; uniform float fogmax; diff --git a/data/shaders/untextured_object.frag b/data/shaders/untextured_object.frag index ccbc54ab9..24f4a54be 100644 --- a/data/shaders/untextured_object.frag +++ b/data/shaders/untextured_object.frag @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform sampler2D DiffuseMap; uniform sampler2D SpecularMap; uniform sampler2D SSAO; diff --git a/data/shaders/untextured_object.vert b/data/shaders/untextured_object.vert index 3ef97ca4b..5f0f91cf7 100644 --- a/data/shaders/untextured_object.vert +++ b/data/shaders/untextured_object.vert @@ -1,4 +1,4 @@ -#version 130 +#version 330 uniform mat4 ModelViewProjectionMatrix; in vec3 Position; diff --git a/data/shaders/water.frag b/data/shaders/water.frag index fc106fb29..1e9d434b3 100644 --- a/data/shaders/water.frag +++ b/data/shaders/water.frag @@ -1,6 +1,6 @@ // Shader based on work by Fabien Sanglard // Released under the terms of CC-BY 3.0 -#version 130 +#version 330 compatibility uniform sampler2D BumpTex1; // Normal map 1 uniform sampler2D BumpTex2; // Normal map 2 uniform sampler2D DecalTex; //The texture diff --git a/data/shaders/water.vert b/data/shaders/water.vert index ab1d05c5b..78a1fe5c5 100644 --- a/data/shaders/water.vert +++ b/data/shaders/water.vert @@ -1,6 +1,6 @@ // Shader based on work by Fabien Sanglard // Released under the terms of CC-BY 3.0 -#version 130 +#version 330 compatibility uniform float speed; uniform float height; uniform float waveLength; diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp index de2c76d61..4829cf72c 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp @@ -744,9 +744,8 @@ bool CIrrDeviceLinux::createWindow() int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, - GLX_CONTEXT_MINOR_VERSION_ARB, 0, - // Uncomment to discard deprecated features - //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, + GLX_CONTEXT_MINOR_VERSION_ARB, 3, + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, //GLX_CONTEXT_CORE_PROFILE_BIT_ARB GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, None }; diff --git a/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp b/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp index 50076bf1a..9db511551 100644 --- a/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp +++ b/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp @@ -412,9 +412,9 @@ bool COpenGLDriver::initDriver(CIrrDeviceWin32* device) int iAttribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, - WGL_CONTEXT_MINOR_VERSION_ARB, 1, - //WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, + WGL_CONTEXT_MINOR_VERSION_ARB, 3, WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, //WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0 }; hrc=wglCreateContextAttribs_ARB(HDc, 0, iAttribs); From 3d3333905d0d7d1ab651f3de6b96f76b3d1301b9 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Wed, 12 Feb 2014 22:41:32 +0100 Subject: [PATCH 39/68] Some factorization. --- src/graphics/glwrap.cpp | 11 ++++---- src/graphics/glwrap.hpp | 4 ++- src/graphics/gpuparticles.cpp | 4 --- src/graphics/gpuparticles.hpp | 2 -- src/graphics/post_processing.cpp | 42 ++++++++++++++--------------- src/graphics/stkbillboard.cpp | 2 +- src/graphics/stkmesh.cpp | 46 ++++++++++++++++---------------- 7 files changed, 54 insertions(+), 57 deletions(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 2669d5125..cb539f66b 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -305,12 +305,13 @@ GLuint LoadTFBProgram(const char * vertex_file_path, const char **varyings, unsi return Program; } +GLuint getTextureGLuint(irr::video::ITexture *tex) { + return static_cast<irr::video::COpenGLTexture*>(tex)->getOpenGLTextureName(); +} - -void bindUniformToTextureUnit(GLuint location, GLuint texid, unsigned textureUnit) { - glActiveTexture(GL_TEXTURE0 + textureUnit); - glBindTexture(GL_TEXTURE_2D, texid); - glUniform1i(location, textureUnit); +GLuint getDepthTexture(irr::video::ITexture *tex) { + assert(tex->isRenderTarget()); + return static_cast<irr::video::COpenGLFBOTexture*>(tex)->DepthBufferTexture; } void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter, bool allowAF) diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 6d8bb49bc..1ad758d59 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -22,7 +22,6 @@ void initGL(); GLuint LoadProgram(const char * vertex_file_path, const char * fragment_file_path); GLuint LoadProgram(const char * vertex_file_path, const char * geometry_file_path, const char * fragment_file_path); GLuint LoadTFBProgram(const char * vertex_file_path, const char **varyings, unsigned varyingscount); -void bindUniformToTextureUnit(GLuint location, GLuint texid, unsigned textureUnit); void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter, bool allowAF = false); // already includes glext.h, which defines useful GL constants. @@ -91,6 +90,9 @@ extern PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB; #include <rect.h> #include "utils/vec3.hpp" +GLuint getTextureGLuint(irr::video::ITexture *tex); +GLuint getDepthTexture(irr::video::ITexture *tex); + void draw2DImage(const irr::video::ITexture* texture, const irr::core::rect<s32>& destRect, const irr::core::rect<s32>& sourceRect, const irr::core::rect<s32>* clipRect, const irr::video::SColor* const colors, bool useAlphaChannelOfTexture); diff --git a/src/graphics/gpuparticles.cpp b/src/graphics/gpuparticles.cpp index 7bda836b2..b67b2fa7e 100644 --- a/src/graphics/gpuparticles.cpp +++ b/src/graphics/gpuparticles.cpp @@ -6,10 +6,6 @@ #include <IParticleSystemSceneNode.h> #include "guiengine/engine.hpp" -GLuint getTextureGLuint(irr::video::ITexture *tex) { - return static_cast<irr::video::COpenGLTexture*>(tex)->getOpenGLTextureName(); -} - #define COMPONENTCOUNT 8 scene::IParticleSystemSceneNode *ParticleSystemProxy::addParticleNode( diff --git a/src/graphics/gpuparticles.hpp b/src/graphics/gpuparticles.hpp index 62714d4bc..7a79ebb46 100644 --- a/src/graphics/gpuparticles.hpp +++ b/src/graphics/gpuparticles.hpp @@ -9,8 +9,6 @@ namespace irr { namespace video{ class ITexture; } } -GLuint getTextureGLuint(irr::video::ITexture *tex); - class ParticleSystemProxy : public scene::CParticleSystemSceneNode { protected: GLuint tfb_buffers[2], initial_values_buffer, heighmapbuffer, heightmaptexture, quaternionsbuffer; diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 655cee47c..a8938a3bb 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -212,7 +212,7 @@ void renderBloom(ITexture *in) glUniform1f(FullScreenShader::BloomShader::uniform_low, threshold); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glUniform1i(FullScreenShader::BloomShader::uniform_texture, 0); @@ -235,7 +235,7 @@ void renderBloomBlend(ITexture *in) glBindVertexArray(FullScreenShader::BloomBlendShader::vao); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glUniform1i(FullScreenShader::BloomBlendShader::uniform_texture, 0); @@ -261,11 +261,11 @@ void renderPPDisplace(ITexture *in) glUniform1i(FullScreenShader::PPDisplaceShader::uniform_viz, irr_driver->getDistortViz()); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in)); glUniform1i(FullScreenShader::PPDisplaceShader::uniform_tex, 0); glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_DISPLACE))->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(irr_driver->getRTT(RTT_DISPLACE))); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glUniform1i(FullScreenShader::PPDisplaceShader::uniform_dtex, 1); @@ -294,7 +294,7 @@ void renderColorLevel(ITexture *in) glUniform2f(FullScreenShader::ColorLevelShader::uniform_outlevel, m_outlevel.X, m_outlevel.Y); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glUniform1i(FullScreenShader::ColorLevelShader::uniform_tex, 0); @@ -316,8 +316,8 @@ void PostProcessing::renderPointlight(const std::vector<float> &positions, const glUseProgram(FullScreenShader::PointLightShader::Program); glBindVertexArray(FullScreenShader::PointLightShader::vao); - setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); + setTexture(0, getTextureGLuint(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST); + setTexture(1, getDepthTexture(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST); FullScreenShader::PointLightShader::setUniforms(irr_driver->getInvProjMatrix(), irr_driver->getViewMatrix(), positions, colors, energy, 200, 0, 1); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); @@ -339,8 +339,8 @@ void PostProcessing::renderSunlight() glUseProgram(FullScreenShader::SunLightShader::Program); glBindVertexArray(FullScreenShader::SunLightShader::vao); - setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); + setTexture(0, getTextureGLuint(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST); + setTexture(1, getDepthTexture(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST); FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindVertexArray(0); @@ -357,8 +357,8 @@ void PostProcessing::renderShadowedSunlight(const std::vector<core::matrix4> &su glUseProgram(FullScreenShader::ShadowedSunLightShader::Program); glBindVertexArray(FullScreenShader::ShadowedSunLightShader::vao); - setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); + setTexture(0, getTextureGLuint(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST); + setTexture(1, getDepthTexture(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D_ARRAY, depthtex); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -385,7 +385,7 @@ void PostProcessing::renderGaussian3Blur(video::ITexture *in, video::ITexture *t glUniform2f(FullScreenShader::Gaussian3VBlurShader::uniform_pixel, inv_width, inv_height); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glUniform1i(FullScreenShader::Gaussian3VBlurShader::uniform_tex, 0); @@ -400,7 +400,7 @@ void PostProcessing::renderGaussian3Blur(video::ITexture *in, video::ITexture *t glUniform2f(FullScreenShader::Gaussian3HBlurShader::uniform_pixel, inv_width, inv_height); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(temprtt)->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(temprtt)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glUniform1i(FullScreenShader::Gaussian3HBlurShader::uniform_tex, 0); @@ -425,7 +425,7 @@ void PostProcessing::renderGaussian6Blur(video::ITexture *in, video::ITexture *t glUniform2f(FullScreenShader::Gaussian6VBlurShader::uniform_pixel, inv_width, inv_height); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(in)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glUniform1i(FullScreenShader::Gaussian6VBlurShader::uniform_tex, 0); @@ -440,7 +440,7 @@ void PostProcessing::renderGaussian6Blur(video::ITexture *in, video::ITexture *t glUniform2f(FullScreenShader::Gaussian6HBlurShader::uniform_pixel, inv_width, inv_height); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(temprtt)->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(temprtt)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glUniform1i(FullScreenShader::Gaussian6HBlurShader::uniform_tex, 0); @@ -461,7 +461,7 @@ void PostProcessing::renderPassThrough(ITexture *tex) glBindVertexArray(FullScreenShader::PassThroughShader::vao); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(tex)->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(tex)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glUniform1i(FullScreenShader::PassThroughShader::uniform_texture, 0); @@ -503,7 +503,7 @@ void PostProcessing::renderGlow(ITexture *tex) glBindVertexArray(FullScreenShader::GlowShader::vao); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(tex)->getOpenGLTextureName()); + glBindTexture(GL_TEXTURE_2D, getTextureGLuint(tex)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glUniform1i(FullScreenShader::GlowShader::uniform_tex, 0); @@ -529,9 +529,9 @@ void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matri glUseProgram(FullScreenShader::SSAOShader::Program); glBindVertexArray(FullScreenShader::SSAOShader::vao); - setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_LINEAR, GL_LINEAR); - setTexture(2, static_cast<irr::video::COpenGLTexture*>(noise_tex)->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(0, getTextureGLuint(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST); + setTexture(1, getDepthTexture(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_LINEAR, GL_LINEAR); + setTexture(2, getTextureGLuint(noise_tex), GL_NEAREST, GL_NEAREST); FullScreenShader::SSAOShader::setUniforms(projm, invprojm, 0, 1, 2); @@ -567,7 +567,7 @@ void PostProcessing::renderFog(const core::matrix4 &ipvmat) glUseProgram(FullScreenShader::FogShader::Program); glBindVertexArray(FullScreenShader::FogShader::vao); - setTexture(0, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); + setTexture(0, getDepthTexture(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH)), GL_NEAREST, GL_NEAREST); FullScreenShader::FogShader::setUniforms(ipvmat, fogmax, startH, endH, start, end, col, 0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); diff --git a/src/graphics/stkbillboard.cpp b/src/graphics/stkbillboard.cpp index 0fb70a599..ee24b1270 100644 --- a/src/graphics/stkbillboard.cpp +++ b/src/graphics/stkbillboard.cpp @@ -42,7 +42,7 @@ void STKBillboard::render() { core::vector3df pos = getAbsolutePosition(); glBindVertexArray(billboardvao); - GLuint texid = static_cast<irr::video::COpenGLTexture*>(Material.getTexture(0))->getOpenGLTextureName(); + GLuint texid = getTextureGLuint(Material.getTexture(0)); setTexture(0, texid, GL_LINEAR, GL_LINEAR); glUseProgram(MeshShader::BillboardShader::Program); MeshShader::BillboardShader::setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(), pos, Size, 0); diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 554faa97e..c9e78d663 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -137,7 +137,7 @@ GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb) { tex = mb->getMaterial().getTexture(i); if (tex) - result.textures[i] = static_cast<irr::video::COpenGLTexture*>(tex)->getOpenGLTextureName(); + result.textures[i] = getTextureGLuint(tex); else result.textures[i] = 0; } @@ -370,13 +370,13 @@ void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionM glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } // Diffuse - setTexture(5, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(5, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); // Specular - setTexture(6, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(6, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); // SSAO - setTexture(7, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(7, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE}; @@ -408,9 +408,9 @@ void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjec GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } - setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); + setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); + setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE}; @@ -442,9 +442,9 @@ void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio GLint swizzleMask[] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } - setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); + setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); + setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE}; @@ -464,9 +464,9 @@ void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProj GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(0, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); + setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); + setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE}; @@ -499,9 +499,9 @@ void drawObjectRimLimit(const GLMesh &mesh, const core::matrix4 &ModelViewProjec glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } - setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); + setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); + setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; @@ -561,9 +561,9 @@ void drawDetailledObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelView setTexture(1, mesh.textures[1], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(4, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); + setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); + setTexture(4, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE}; @@ -595,9 +595,9 @@ void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectio glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } - setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); - setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); + setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); + setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); if (!UserConfigParams::m_ssao) { GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; @@ -700,7 +700,7 @@ void STKMesh::drawDisplace(const GLMesh &mesh) computeMVP(ModelViewProjectionMatrix); core::matrix4 ModelViewMatrix = irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW); ModelViewMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD); - setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getTexture(FileManager::TEXTURE, "displace.png"))->getOpenGLTextureName(), GL_LINEAR, GL_LINEAR, true); + setTexture(0, getTextureGLuint(irr_driver->getTexture(FileManager::TEXTURE, "displace.png")), GL_LINEAR, GL_LINEAR, true); glUseProgram(MeshShader::DisplaceShader::Program); MeshShader::DisplaceShader::setUniforms(ModelViewProjectionMatrix, ModelViewMatrix, cb->getDirX(), cb->getDirY(), cb->getDir2X(), cb->getDir2Y(), 0); From 57079cbff5f0ae4a1b2adffcdf00f3134d741361 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Wed, 12 Feb 2014 23:32:18 +0100 Subject: [PATCH 40/68] Shaders: Declare penumbraH/V and shadowgen --- data/shaders/penumbrah.frag | 7 +++-- data/shaders/penumbrav.frag | 7 +++-- data/shaders/shadowgen.frag | 10 ++++--- src/graphics/shaders.cpp | 59 +++++++++++++++++++++++++++++++++++++ src/graphics/shaders.hpp | 33 +++++++++++++++++++++ 5 files changed, 106 insertions(+), 10 deletions(-) diff --git a/data/shaders/penumbrah.frag b/data/shaders/penumbrah.frag index ab8888c29..481db2dc8 100644 --- a/data/shaders/penumbrah.frag +++ b/data/shaders/penumbrah.frag @@ -1,7 +1,8 @@ -#version 330 compatibility +#version 330 uniform sampler2D tex; uniform vec2 pixel; +in vec2 uv; out vec4 FragColor; // Separated penumbra, horizontal @@ -9,8 +10,8 @@ void main() { float sum = 0.0; vec4 tmp; - float X = gl_TexCoord[0].x; - float Y = gl_TexCoord[0].y; + float X = uv.x; + float Y = uv.y; float width = 0.0; float zsum = 0.00001; diff --git a/data/shaders/penumbrav.frag b/data/shaders/penumbrav.frag index 229fa6e20..7afc88173 100644 --- a/data/shaders/penumbrav.frag +++ b/data/shaders/penumbrav.frag @@ -1,7 +1,8 @@ -#version 330 compatibility +#version 330 uniform sampler2D tex; uniform vec2 pixel; +in vec2 uv; out vec4 FragColor; // Separated penumbra, vertical @@ -10,8 +11,8 @@ void main() { float sum = 0.0; vec4 tmp; - float X = gl_TexCoord[0].x; - float Y = gl_TexCoord[0].y; + float X = uv.x; + float Y = uv.y; float width = 0.0; float zsum = 0.00001; diff --git a/data/shaders/shadowgen.frag b/data/shaders/shadowgen.frag index 9cef0fbd6..2a44707de 100644 --- a/data/shaders/shadowgen.frag +++ b/data/shaders/shadowgen.frag @@ -1,15 +1,17 @@ -#version 330 compatibility +#version 330 uniform sampler2D halft; // half is a reserved word uniform sampler2D quarter; uniform sampler2D eighth; + +in vec2 uv; out vec4 FragColor; void main() { vec3 val[3]; - val[0] = texture(halft, gl_TexCoord[0].xy).xyz; - val[1] = texture(quarter, gl_TexCoord[0].xy).xyz; - val[2] = texture(eighth, gl_TexCoord[0].xy).xyz; + val[0] = texture(halft, uv).xyz; + val[1] = texture(quarter, uv).xyz; + val[2] = texture(eighth, uv).xyz; // Find the first level with a penumbra value int i; diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 9a82c7e55..f9fe82420 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -229,6 +229,8 @@ void Shaders::loadShaders() FullScreenShader::Gaussian3VBlurShader::init(); FullScreenShader::Gaussian6HBlurShader::init(); FullScreenShader::Gaussian6VBlurShader::init(); + FullScreenShader::PenumbraHShader::init(); + FullScreenShader::PenumbraVShader::init(); FullScreenShader::GlowShader::init(); FullScreenShader::PassThroughShader::init(); FullScreenShader::PointLightShader::init(); @@ -1384,6 +1386,63 @@ namespace FullScreenShader vao = createVAO(Program); } + GLuint PenumbraHShader::Program; + GLuint PenumbraHShader::uniform_tex; + GLuint PenumbraHShader::uniform_pixel; + GLuint PenumbraHShader::vao; + void PenumbraHShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/penumbrah.frag").c_str()); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + vao = createVAO(Program); + } + + void PenumbraHShader::setUniforms(const core::vector2df &pixels, GLuint TU_tex) + { + glUniform2f(uniform_pixel, pixels.X, pixels.Y); + glUniform1i(uniform_tex, TU_tex); + } + + GLuint PenumbraVShader::Program; + GLuint PenumbraVShader::uniform_tex; + GLuint PenumbraVShader::uniform_pixel; + GLuint PenumbraVShader::vao; + void PenumbraVShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/penumbrav.frag").c_str()); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + vao = createVAO(Program); + } + + void PenumbraVShader::setUniforms(const core::vector2df &pixels, GLuint TU_tex) + { + glUniform2f(uniform_pixel, pixels.X, pixels.Y); + glUniform1i(uniform_tex, TU_tex); + } + + GLuint ShadowGenShader::Program; + GLuint ShadowGenShader::uniform_halft; + GLuint ShadowGenShader::uniform_quarter; + GLuint ShadowGenShader::uniform_height; + GLuint ShadowGenShader::vao; + void ShadowGenShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/shadowgen.frag").c_str()); + uniform_halft = glGetUniformLocation(Program, "halft"); + uniform_quarter = glGetUniformLocation(Program, "quarter"); + uniform_height = glGetUniformLocation(Program, "height"); + vao = createVAO(Program); + } + + void ShadowGenShader::setUniforms(GLuint TU_halft, GLuint TU_quarter, GLuint TU_height) + { + glUniform1i(uniform_halft, TU_halft); + glUniform1i(uniform_quarter, TU_quarter); + glUniform1i(uniform_height, TU_height); + } + GLuint PassThroughShader::Program; GLuint PassThroughShader::uniform_texture; GLuint PassThroughShader::vao; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index c0b8352e7..c888e1f7d 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -436,6 +436,39 @@ public: static void init(); }; +class PenumbraHShader +{ +public: + static GLuint Program; + static GLuint uniform_tex, uniform_pixel; + static GLuint vao; + + static void init(); + static void setUniforms(const core::vector2df &pixels, GLuint TU_tex); +}; + +class PenumbraVShader +{ +public: + static GLuint Program; + static GLuint uniform_tex, uniform_pixel; + static GLuint vao; + + static void init(); + static void setUniforms(const core::vector2df &pixels, GLuint TU_tex); +}; + +class ShadowGenShader +{ +public: + static GLuint Program; + static GLuint uniform_halft, uniform_quarter, uniform_height; + static GLuint vao; + + static void init(); + static void setUniforms(GLuint TU_halft, GLuint TU_quarter, GLuint TU_height); +}; + class PassThroughShader { public: From 8227e1c0924ccd7535ac93f37044873ea08a3af5 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon <auria.mg@gmail.com> Date: Wed, 12 Feb 2014 21:06:12 -0500 Subject: [PATCH 41/68] Add first rudimentary way to dump profiler measurements to CSV. More work to do! --- src/utils/debug.cpp | 8 ++++++ src/utils/profiler.cpp | 58 +++++++++++++++++++++++++++++++++++++++--- src/utils/profiler.hpp | 44 ++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 4 deletions(-) diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp index 871c4ae9a..1f01875bd 100644 --- a/src/utils/debug.cpp +++ b/src/utils/debug.cpp @@ -29,6 +29,7 @@ #include "main_loop.hpp" #include "replay/replay_recorder.hpp" #include "utils/log.hpp" +#include "utils/profiler.hpp" #include <IGUIEnvironment.h> #include <IGUIContextMenu.h> using namespace irr; @@ -57,6 +58,7 @@ enum DebugMenuCommand DEBUG_GRAPHICS_BULLET_1, DEBUG_GRAPHICS_BULLET_2, DEBUG_PROFILER, + DEBUG_PROFILER_GENERATE_REPORT, DEBUG_FPS, DEBUG_SAVE_REPLAY, DEBUG_SAVE_HISTORY, @@ -135,6 +137,8 @@ bool onEvent(const SEvent &event) sub->addItem(L"Nitro", DEBUG_POWERUP_NITRO ); mnu->addItem(L"Profiler",DEBUG_PROFILER); + if (UserConfigParams::m_profiler_enabled) + mnu->addItem(L"Toggle capture profiler report", DEBUG_PROFILER_GENERATE_REPORT); mnu->addItem(L"Do not limit FPS", DEBUG_THROTTLE_FPS); mnu->addItem(L"FPS",DEBUG_FPS); mnu->addItem(L"Save replay", DEBUG_SAVE_REPLAY); @@ -254,6 +258,10 @@ bool onEvent(const SEvent &event) UserConfigParams::m_profiler_enabled = !UserConfigParams::m_profiler_enabled; } + else if (cmdID == DEBUG_PROFILER_GENERATE_REPORT) + { + profiler.setCaptureReport(!profiler.getCaptureReport()); + } else if (cmdID == DEBUG_THROTTLE_FPS) { main_loop->setThrottleFPS(false); diff --git a/src/utils/profiler.cpp b/src/utils/profiler.cpp index b9fc0b4fe..2f8b5bcc6 100644 --- a/src/utils/profiler.cpp +++ b/src/utils/profiler.cpp @@ -21,6 +21,7 @@ #include "guiengine/event_handler.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" +#include "io/xml_writer.hpp" #include <assert.h> #include <stack> #include <sstream> @@ -71,6 +72,9 @@ Profiler::Profiler() m_time_last_sync = _getTimeMilliseconds(); m_time_between_sync = 0.0; m_freeze_state = UNFROZEN; + m_capture_report = false; + m_first_capture_sweep = true; + m_capture_report_buffer = NULL; } //----------------------------------------------------------------------------- @@ -78,6 +82,31 @@ Profiler::~Profiler() { } +//----------------------------------------------------------------------------- + +void Profiler::setCaptureReport(bool captureReport) +{ + if (!m_capture_report && captureReport) + { + m_capture_report = true; + m_first_capture_sweep = true; + // TODO: a 20 MB hardcoded buffer for now. That should amply suffice for + // all reasonable purposes. But it's not too clean to hardcode + m_capture_report_buffer = new StringBuffer(20 * 1024 * 1024); + } + else if (m_capture_report && !captureReport) + { + // when disabling capture to file, flush captured data to a file + { + XMLWriter writer(file_manager->getUserConfigFile("profiling.csv").c_str()); + writer << m_capture_report_buffer->getRawBuffer(); + } + m_capture_report = false; + delete m_capture_report_buffer; + m_capture_report_buffer = NULL; + } +} + //----------------------------------------------------------------------------- /// Push a new marker that starts now void Profiler::pushCpuMarker(const char* name, const video::SColor& color) @@ -194,7 +223,7 @@ void Profiler::draw() // Force to show the pointer irr_driver->showPointer(); - int read_id = !m_write_id; + int read_id = (m_freeze_state == FROZEN ? !m_write_id : m_write_id); // Compute some values for drawing (unit: pixels, but we keep floats for reducing errors accumulation) core::dimension2d<u32> screen_size = driver->getScreenSize(); @@ -232,19 +261,34 @@ void Profiler::draw() core::vector2di mouse_pos = GUIEngine::EventHandler::get()->getMousePos(); // For each thread: - for(size_t i=0 ; i < nb_thread_infos ; i++) + for (size_t i = 0; i < nb_thread_infos; i++) { // Draw all markers MarkerList& markers = m_thread_infos[i].markers_done[read_id]; - if(markers.empty()) + if (markers.empty()) continue; + if (m_capture_report) + { + if (m_first_capture_sweep) + m_capture_report_buffer->getStdStream() << "\"Thread\";"; + else + m_capture_report_buffer->getStdStream() << i << ";"; + } MarkerList::const_iterator it_end = markers.end(); - for(MarkerList::const_iterator it = markers.begin() ; it != it_end ; it++) + for (MarkerList::const_iterator it = markers.begin(); it != it_end; it++) { const Marker& m = *it; assert(m.end >= 0.0); + + if (m_capture_report) + { + if (m_first_capture_sweep) + m_capture_report_buffer->getStdStream() << "\"" << m.name << "\";"; + else + m_capture_report_buffer->getStdStream() << (int)std::round((m.end - m.start) * 1000) << ";"; + } core::rect<s32> pos((s32)( x_offset + factor*m.start ), (s32)( y_offset + i*line_height ), (s32)( x_offset + factor*m.end ), @@ -260,6 +304,12 @@ void Profiler::draw() if(pos.isPointInside(mouse_pos)) hovered_markers.push(m); } + + if (m_capture_report) + { + m_capture_report_buffer->getStdStream() << "\n"; + m_first_capture_sweep = false; + } } // Draw the end of the frame diff --git a/src/utils/profiler.hpp b/src/utils/profiler.hpp index 738e2e633..99759413e 100644 --- a/src/utils/profiler.hpp +++ b/src/utils/profiler.hpp @@ -23,6 +23,8 @@ #include <vector> #include <stack> #include <string> +#include <streambuf> + class Profiler; extern Profiler profiler; @@ -50,6 +52,41 @@ extern Profiler profiler; using namespace irr; +/** For profiling reports, we need a custom strijng stream that writes to a large + pre-allocated buffer, to avoid allocating as much as possible durign profiling */ +template <typename char_type> +struct ostreambuf : public std::basic_streambuf<char_type, std::char_traits<char_type> > +{ + ostreambuf(char_type* buffer, std::streamsize bufferLength) + { + // set the "put" pointer the start of the buffer and record it's length. + setp(buffer, buffer + bufferLength); + } +}; + +class StringBuffer +{ +private: + char* m_buffer; + ostreambuf<char> ostreamBuffer; + std::ostream messageStream; + +public: + + StringBuffer(unsigned int size) : m_buffer(new char[size]), ostreamBuffer(m_buffer, size), messageStream(&ostreamBuffer) + { + } + + ~StringBuffer() + { + delete[] m_buffer; + } + + std::ostream& getStdStream() { return messageStream; } + + char* getRawBuffer() { return m_buffer; } +}; + /** * \brief class that allows run-time graphical profiling through the use of markers * \ingroup utils @@ -104,6 +141,10 @@ private: FreezeState m_freeze_state; + bool m_capture_report; + bool m_first_capture_sweep; + StringBuffer* m_capture_report_buffer; + public: Profiler(); virtual ~Profiler(); @@ -116,10 +157,13 @@ public: void onClick(const core::vector2di& mouse_pos); + bool getCaptureReport() const { return m_capture_report; } + void setCaptureReport(bool captureReport); protected: // TODO: detect on which thread this is called to support multithreading ThreadInfo& getThreadInfo() { return m_thread_infos[0]; } void drawBackground(); + }; #endif // PROFILER_HPP From fd8496ffbac76fd027e2ae14f97c828f43047bd4 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon <auria.mg@gmail.com> Date: Thu, 13 Feb 2014 18:57:51 -0500 Subject: [PATCH 42/68] Fix linux/gcc compilation --- src/utils/profiler.cpp | 2 +- src/utils/profiler.hpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/profiler.cpp b/src/utils/profiler.cpp index 2f8b5bcc6..cb273d910 100644 --- a/src/utils/profiler.cpp +++ b/src/utils/profiler.cpp @@ -287,7 +287,7 @@ void Profiler::draw() if (m_first_capture_sweep) m_capture_report_buffer->getStdStream() << "\"" << m.name << "\";"; else - m_capture_report_buffer->getStdStream() << (int)std::round((m.end - m.start) * 1000) << ";"; + m_capture_report_buffer->getStdStream() << (int)round((m.end - m.start) * 1000) << ";"; } core::rect<s32> pos((s32)( x_offset + factor*m.start ), (s32)( y_offset + i*line_height ), diff --git a/src/utils/profiler.hpp b/src/utils/profiler.hpp index 99759413e..11d41a93c 100644 --- a/src/utils/profiler.hpp +++ b/src/utils/profiler.hpp @@ -24,6 +24,8 @@ #include <stack> #include <string> #include <streambuf> +#include <ostream> +#include <iostream> class Profiler; @@ -60,7 +62,7 @@ struct ostreambuf : public std::basic_streambuf<char_type, std::char_traits<char ostreambuf(char_type* buffer, std::streamsize bufferLength) { // set the "put" pointer the start of the buffer and record it's length. - setp(buffer, buffer + bufferLength); + this->setp(buffer, buffer + bufferLength); } }; From d5d57bbae0618ddcb65b11a4e19d9eebd006ffbc Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Sat, 15 Feb 2014 20:45:47 +0100 Subject: [PATCH 43/68] Shadows: Softer edge and smoother cascade transitions --- data/shaders/sunlightshadow.frag | 71 ++++++++++++++++++-------------- src/graphics/render.cpp | 12 +++--- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index d2b2df054..6789613d1 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -24,13 +24,18 @@ vec3 DecodeNormal(vec2 n) return vec3(xy,z); } -float getShadowFactor(vec3 pos, float bias) +float getShadowFactor(vec3 pos, float bias, int index) { - if (pos.z < 5.) - { - vec4 shadowcoord = (shadowmat[0] * vec4(pos, 1.0)); - shadowcoord /= shadowcoord.w; - vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; + const vec2 shadowoffset[] = { + vec2(-1., -1.), + vec2(-1., 1.), + vec2(1., -1.), + vec2(1., 1.) + }; + + vec4 shadowcoord = (shadowmat[index] * vec4(pos, 1.0)); + shadowcoord /= shadowcoord.w; + vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; // shadowcoord = (shadowcoord * 0.5) + vec3(0.5); // float movex = decdepth(texture(warpx, shadowcoord.xy)); @@ -39,31 +44,14 @@ float getShadowFactor(vec3 pos, float bias) // float dy = movey * 2.0 - 1.0; // shadowcoord.xy += vec2(dx, dy);*/ - //float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.; - // bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping - return texture(shadowtex, vec4(shadowtexcoord, 0., 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); - } - else if (pos.z < 10.) +//float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.; +// bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping + float sum = 0.; + for (int i = 0; i < 4; i++) { - vec4 shadowcoord = (shadowmat[1] * vec4(pos, 1.0)); - shadowcoord /= shadowcoord.w; - vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; - return texture(shadowtex, vec4(shadowtexcoord, 1., 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); - } - else if (pos.z < 75.) - { - vec4 shadowcoord = (shadowmat[2] * vec4(pos, 1.0)); - shadowcoord /= shadowcoord.w; - vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; - return texture(shadowtex, vec4(shadowtexcoord, 2., 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); - } - else - { - vec4 shadowcoord = (shadowmat[3] * vec4(pos, 1.0)); - shadowcoord /= shadowcoord.w; - vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5; - return texture(shadowtex, vec4(shadowtexcoord, 3., 0.5 * (shadowcoord.z + bias) + 0.5)); + sum += texture(shadowtex, vec4(shadowtexcoord + 0.0005 * shadowoffset[i], float(index), 0.5 * (shadowcoord.z + bias * 0.001) + 0.5)); } + return sum / 4.; } void main() { @@ -96,7 +84,30 @@ void main() { // Shadows float bias = 0.002 * tan(acos(NdotL)); // According to the slope bias = clamp(bias, 0.001, 0.014); - float factor = getShadowFactor(xpos.xyz, bias); + float factor; + if (xpos.z < 20.) + factor = getShadowFactor(xpos.xyz, bias, 0); + else if (xpos.z < 25.) + { + float a = getShadowFactor(xpos.xyz, bias, 0), b = getShadowFactor(xpos.xyz, bias, 1); + factor = mix(a, b, (xpos.z - 20.) / 5.); + } + else if (xpos.z < 50.) + factor = getShadowFactor(xpos.xyz, bias, 1); + else if (xpos.z < 60.) + { + float a = getShadowFactor(xpos.xyz, bias, 1), b = getShadowFactor(xpos.xyz, bias, 2); + factor = mix(a, b, (xpos.z - 50.) / 10.); + } + else if (xpos.z < 100.) + factor = getShadowFactor(xpos.xyz, bias, 2); + else if (xpos.z < 120.) + { + float a = getShadowFactor(xpos.xyz, bias, 2), b = getShadowFactor(xpos.xyz, bias, 3); + factor = mix(a, b, (xpos.z - 100.) / 20.); + } + else + factor = getShadowFactor(xpos.xyz, bias, 3); Diff = vec4(factor * NdotL * col, 1.); Spec = vec4(factor * Specular * col, 1.); return; diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index e34370e77..8d4cba5df 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -478,17 +478,17 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, const float oldnear = camnode->getNearValue(); float FarValues[] = { - 5., - 10., - 75., + 20., + 50., + 100., oldfar, }; float NearValues[] = { oldnear, - 5., - 10., - 75., + 20., + 50., + 100., }; const core::matrix4 &SunCamViewMatrix = m_suncam->getViewMatrix(); From 7b993cd2108f70bdf342e25b7d5332c652bab116 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Sun, 16 Feb 2014 21:31:41 +1100 Subject: [PATCH 44/68] Fixed VS compilation. --- src/utils/profiler.cpp | 2 ++ src/utils/vs.hpp | 1 + 2 files changed, 3 insertions(+) diff --git a/src/utils/profiler.cpp b/src/utils/profiler.cpp index cb273d910..49eec4f61 100644 --- a/src/utils/profiler.cpp +++ b/src/utils/profiler.cpp @@ -22,6 +22,8 @@ #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" #include "io/xml_writer.hpp" +#include "utils/vs.hpp" + #include <assert.h> #include <stack> #include <sstream> diff --git a/src/utils/vs.hpp b/src/utils/vs.hpp index b97a6a4f4..5937202c1 100644 --- a/src/utils/vs.hpp +++ b/src/utils/vs.hpp @@ -8,5 +8,6 @@ # define isnan _isnan # define roundf(x) (floorf(x + 0.5f)) +# define round(x) (floorf(x + 0.5)) #endif From c32257924811f61c095a58921c979dd82cdb9a48 Mon Sep 17 00:00:00 2001 From: lurk26 <lurk26@gmail.com> Date: Sun, 16 Feb 2014 18:29:30 +0530 Subject: [PATCH 45/68] Update README.md Updated compiling instructions for Windows. --- README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1b202c23b..146aca2e1 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,16 @@ Hope you enjoy the game. ##Compiling SuperTuxKart ###Windows -A project file for Visual Studio 9 (e.g. the free 2008 express -edition) is included in the sources in `src/ide/vc9`. A separate -dependency package is available on SuperTuxKart's sourceforge -page, which includes all necessary libraries, header files, -and dlls to compile and run the source code. +1. Install VS 2012 or later. The free express versions work fine. +2. Download and install a source package - either a released package or from our [git/svn repositories](http://supertuxkart.sourceforge.net/Source_control) +3. Download the latest dependency package depdendencies_for_0.8.2.zip from [here](https://sourceforge.net/projects/supertuxkart/files/SuperTuxKart%20Dependencies/Windows/). Unzip it in the root directory, so that the dependencies directory is next to the src and data directory (if you are updating from a previous dependency package, you can delete the .dll files in the root directory, they are not needed anymore). +4. Download cmake and install it. Then start cmake-gui and select the STK root directory as 'Where is the source code', and a new directory in the root directory (next to src, data etc) as build directory (for now I assume that this directory is called bld). +5. Click on configure. You will be asked to create the directory (yes), then for your VS version. Make sure to select the right version (be aware of the easy to confuse version numbers: VS 2012 = version 11; VS 2013 = version 12). Click on configure, then generate. This will create the directory 'bld', and a VS solution in that directory. +6. In Visual Studio open the project file generated in the 'bld' folder +7. Right click on the supertuxkart project in the solution explorer, and select "Set as StartUp Project". +8. Select Build->Build Solution (or press F7) to compile. -While compilation with cygwin is not officially supported, +Compilation with cygwin is not officially supported, but this has been done (check with the forum for details). ###Mac OS X From 10db4d6c2c96c50348f8ff14b5da623a9038cd50 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 17 Feb 2014 07:47:01 +1100 Subject: [PATCH 46/68] Removed unused variable. --- src/challenges/unlock_manager.cpp | 9 --------- src/challenges/unlock_manager.hpp | 2 -- 2 files changed, 11 deletions(-) diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index d602d937d..ae0e208e8 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -89,15 +89,6 @@ UnlockManager::~UnlockManager() delete i->second; } - - std::map<unsigned int, GameSlot*>::iterator it; - for (it = m_game_slots.begin(); it != m_game_slots.end(); it++) - { - delete it->second; - } - - // sfx_manager is destroyed before UnlockManager is, so SFX will be already deleted - // sfx_manager->deleteSFX(m_locked_sound); } // ~UnlockManager //----------------------------------------------------------------------------- diff --git a/src/challenges/unlock_manager.hpp b/src/challenges/unlock_manager.hpp index dd4c54987..70a5fd1f6 100644 --- a/src/challenges/unlock_manager.hpp +++ b/src/challenges/unlock_manager.hpp @@ -46,8 +46,6 @@ private: typedef std::map<std::string, ChallengeData*> AllChallengesType; AllChallengesType m_all_challenges; - std::map<unsigned int , GameSlot*> m_game_slots; - void readAllChallengesInDirs(const std::vector<std::string>* all_dirs); friend class GameSlot; From 8cccc72b9ad8e692de91780141c64403d9c015af Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 17 Feb 2014 07:48:18 +1100 Subject: [PATCH 47/68] Fixed merge from upstream. --- src/utils/profiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/profiler.cpp b/src/utils/profiler.cpp index cb273d910..6997bfe12 100644 --- a/src/utils/profiler.cpp +++ b/src/utils/profiler.cpp @@ -21,7 +21,7 @@ #include "guiengine/event_handler.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" -#include "io/xml_writer.hpp" +#include "io/utf_writer.hpp" #include <assert.h> #include <stack> #include <sstream> @@ -98,7 +98,7 @@ void Profiler::setCaptureReport(bool captureReport) { // when disabling capture to file, flush captured data to a file { - XMLWriter writer(file_manager->getUserConfigFile("profiling.csv").c_str()); + UTFWriter writer(file_manager->getUserConfigFile("profiling.csv").c_str()); writer << m_capture_report_buffer->getRawBuffer(); } m_capture_report = false; From 289505d909c07ec95602ad7e4fe17eadb7a30ee9 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon <auria.mg@gmail.com> Date: Sun, 16 Feb 2014 17:42:06 -0500 Subject: [PATCH 48/68] Add missing profiler --- src/graphics/render.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 8d4cba5df..cc472de0f 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -214,13 +214,14 @@ void IrrDriver::renderGLSL(float dt) // Used to cull glowing items & lights const core::aabbox3df cambox = camnode->getViewFrustum()->getBoundingBox(); + PROFILER_PUSH_CPU_MARKER("- Shadow", 0x30, 0x6F, 0x90); // Shadows if (!m_mipviz && !m_wireframe && UserConfigParams::m_shadows) //&& World::getWorld()->getTrack()->hasShadows()) { renderShadows(camnode, camera); } - + PROFILER_POP_CPU_MARKER(); PROFILER_PUSH_CPU_MARKER("- Light", 0x00, 0xFF, 0x00); From 1e8c2ff5232f164724c1da3f4e31ee5a926ad2e9 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon <auria.mg@gmail.com> Date: Sun, 16 Feb 2014 18:10:29 -0500 Subject: [PATCH 49/68] Use plain ofstream to write profiler CSV --- src/utils/profiler.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/profiler.cpp b/src/utils/profiler.cpp index 49eec4f61..7f817dd29 100644 --- a/src/utils/profiler.cpp +++ b/src/utils/profiler.cpp @@ -21,13 +21,13 @@ #include "guiengine/event_handler.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" -#include "io/xml_writer.hpp" #include "utils/vs.hpp" #include <assert.h> #include <stack> #include <sstream> #include <algorithm> +#include <fstream> Profiler profiler; @@ -100,8 +100,9 @@ void Profiler::setCaptureReport(bool captureReport) { // when disabling capture to file, flush captured data to a file { - XMLWriter writer(file_manager->getUserConfigFile("profiling.csv").c_str()); - writer << m_capture_report_buffer->getRawBuffer(); + std::ofstream filewriter(file_manager->getUserConfigFile("profiling.csv").c_str(), std::ios::out | std::ios::binary); + const char* str = m_capture_report_buffer->getRawBuffer(); + filewriter.write(str, strlen(str)); } m_capture_report = false; delete m_capture_report_buffer; From c84264a44efed7c07037764887cf2d52157eab40 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@mgail.com> Date: Mon, 17 Feb 2014 10:57:40 +1100 Subject: [PATCH 50/68] Fixed linux compilation bug. --- src/race/highscore_manager.cpp | 1 + src/race/highscore_manager.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/race/highscore_manager.cpp b/src/race/highscore_manager.cpp index d65d7162e..2af1a2582 100644 --- a/src/race/highscore_manager.cpp +++ b/src/race/highscore_manager.cpp @@ -30,6 +30,7 @@ #include "utils/translation.hpp" HighscoreManager* highscore_manager=0; +const unsigned int HighscoreManager::CURRENT_HSCORE_FILE_VERSION = 3; HighscoreManager::HighscoreManager() { diff --git a/src/race/highscore_manager.hpp b/src/race/highscore_manager.hpp index 913357245..72dad36d8 100644 --- a/src/race/highscore_manager.hpp +++ b/src/race/highscore_manager.hpp @@ -35,7 +35,7 @@ class HighscoreManager { public: private: - static const unsigned int CURRENT_HSCORE_FILE_VERSION = 3; + static const unsigned int CURRENT_HSCORE_FILE_VERSION; typedef std::vector<Highscores*> type_all_scores; type_all_scores m_all_scores; From 148ab7deb33fbfe7ec750fe24fec2df4fac162fa Mon Sep 17 00:00:00 2001 From: Marianne Gagnon <auria.mg@gmail.com> Date: Sun, 16 Feb 2014 19:05:30 -0500 Subject: [PATCH 51/68] Improve profiler to CSV export --- src/utils/profiler.cpp | 5 +++++ src/utils/profiler.hpp | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils/profiler.cpp b/src/utils/profiler.cpp index 7f817dd29..e80859d59 100644 --- a/src/utils/profiler.cpp +++ b/src/utils/profiler.cpp @@ -344,6 +344,11 @@ void Profiler::draw() } font->draw(text, MARKERS_NAMES_POS, video::SColor(0xFF, 0xFF, 0x00, 0x00)); } + + if (m_capture_report) + { + font->draw("Capturing profiler report...", MARKERS_NAMES_POS, video::SColor(0xFF, 0x00, 0x90, 0x00)); + } } //----------------------------------------------------------------------------- diff --git a/src/utils/profiler.hpp b/src/utils/profiler.hpp index 11d41a93c..0221a3eb2 100644 --- a/src/utils/profiler.hpp +++ b/src/utils/profiler.hpp @@ -66,6 +66,7 @@ struct ostreambuf : public std::basic_streambuf<char_type, std::char_traits<char } }; + class StringBuffer { private: @@ -75,13 +76,13 @@ private: public: - StringBuffer(unsigned int size) : m_buffer(new char[size]), ostreamBuffer(m_buffer, size), messageStream(&ostreamBuffer) + StringBuffer(unsigned int size) : m_buffer((char*)calloc(size, 1)), ostreamBuffer(m_buffer, size), messageStream(&ostreamBuffer) { } ~StringBuffer() { - delete[] m_buffer; + free(m_buffer); } std::ostream& getStdStream() { return messageStream; } From 2595d31eba4092bc65feca8a4f0ec707c571a6a4 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 17 Feb 2014 16:52:40 +1100 Subject: [PATCH 52/68] Implemented crude work around for drivers that do not support opengl 3.3. --- lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp b/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp index 9db511551..0d48f8048 100644 --- a/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp +++ b/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp @@ -417,8 +417,15 @@ bool COpenGLDriver::initDriver(CIrrDeviceWin32* device) WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, //WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0 }; - hrc=wglCreateContextAttribs_ARB(HDc, 0, iAttribs); - } + // hd3000 only provides 3.1, so try all minor versions backwards, to find one that works. + for (int minor = 3; minor >= 0; minor--) + { + iAttribs[3] = minor; + hrc = wglCreateContextAttribs_ARB(HDc, 0, iAttribs); + if (hrc) + break; + } + } else #endif hrc=wglCreateContext(HDc); From 6685966616f904ffa66f9797e5f758524a994faa Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 17 Feb 2014 17:00:11 +1100 Subject: [PATCH 53/68] Fixed flying. --- src/karts/kart.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 1e249ad60..bbd5fbf7a 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -1222,10 +1222,13 @@ void Kart::update(float dt) const Material* material=m_terrain_info->getMaterial(); if (!material) // kart falling off the track { - Vec3 gravity(0, -9.8f, 0); - btRigidBody *body = getVehicle()->getRigidBody(); - body->setGravity(gravity); - + if (!m_flying) + { + float g = World::getWorld()->getTrack()->getGravity(); + Vec3 gravity(0, -g, 0); + btRigidBody *body = getVehicle()->getRigidBody(); + body->setGravity(gravity); + } // let kart fall a bit before rescuing const Vec3 *min, *max; World::getWorld()->getTrack()->getAABB(&min, &max); @@ -1235,16 +1238,19 @@ void Kart::update(float dt) } else { - Vec3 gravity(0.0f, -9.8f, 0.0f); - btRigidBody *body = getVehicle()->getRigidBody(); - // If the material should overwrite the gravity, - if(material->hasGravity()) + if (!m_flying) { - Vec3 normal = m_terrain_info->getNormal(); - gravity = normal * -9.8f; - } - body->setGravity(gravity); - + float g = World::getWorld()->getTrack()->getGravity(); + Vec3 gravity(0.0f, -g, 0.0f); + btRigidBody *body = getVehicle()->getRigidBody(); + // If the material should overwrite the gravity, + if (material->hasGravity()) + { + Vec3 normal = m_terrain_info->getNormal(); + gravity = normal * -g; + } + body->setGravity(gravity); + } // if !flying handleMaterialSFX(material); if (material->isDriveReset() && isOnGround()) new RescueAnimation(this); From 2b4729a145ddf10e8b68b46fcfcb031977139cbb Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 17 Feb 2014 20:10:29 +1100 Subject: [PATCH 54/68] Renamed player.?pp to player_profile.?pp (to follow our style guide); removed unnecessary #includes. --- sources.cmake | 4 ++-- src/achievements/achievements_manager.cpp | 2 +- src/challenges/unlock_manager.cpp | 2 +- src/config/player_manager.cpp | 2 +- src/config/{player.cpp => player_profile.cpp} | 2 +- src/config/{player.hpp => player_profile.hpp} | 0 src/config/user_config.cpp | 2 +- src/input/device_manager.cpp | 1 - src/karts/controller/network_player_controller.cpp | 1 - src/karts/controller/player_controller.cpp | 1 - src/karts/controller/player_controller.hpp | 1 - src/karts/kart_properties_manager.cpp | 2 +- src/main.cpp | 2 +- src/race/grand_prix_data.cpp | 2 +- src/states_screens/cutscene_gui.cpp | 1 + src/states_screens/cutscene_gui.hpp | 1 - src/states_screens/dialogs/add_device_dialog.cpp | 1 - src/states_screens/dialogs/add_device_dialog.hpp | 1 - src/states_screens/dialogs/change_password_dialog.cpp | 1 - src/states_screens/dialogs/confirm_resolution_dialog.hpp | 1 - src/states_screens/dialogs/enter_player_name_dialog.cpp | 2 +- src/states_screens/dialogs/message_dialog.hpp | 1 - src/states_screens/dialogs/player_info_dialog.cpp | 2 +- src/states_screens/dialogs/player_info_dialog.hpp | 3 ++- src/states_screens/dialogs/recovery_dialog.cpp | 1 - src/states_screens/dialogs/registration_dialog.cpp | 1 - src/states_screens/dialogs/server_info_dialog.cpp | 1 - src/states_screens/dialogs/tutorial_message_dialog.hpp | 1 - src/states_screens/kart_selection.cpp | 2 +- src/states_screens/options_screen_players.cpp | 2 +- src/states_screens/race_gui.hpp | 1 - src/states_screens/race_gui_overworld.hpp | 1 - src/states_screens/state_manager.hpp | 2 +- 33 files changed, 18 insertions(+), 32 deletions(-) rename src/config/{player.cpp => player_profile.cpp} (99%) rename src/config/{player.hpp => player_profile.hpp} (100%) diff --git a/sources.cmake b/sources.cmake index 00250cd3a..0c5e06da6 100644 --- a/sources.cmake +++ b/sources.cmake @@ -22,8 +22,8 @@ src/challenges/challenge_data.cpp src/challenges/game_slot.cpp src/challenges/unlock_manager.cpp src/config/device_config.cpp -src/config/player.cpp src/config/player_manager.cpp +src/config/player_profile.cpp src/config/saved_grand_prix.cpp src/config/stk_config.cpp src/config/user_config.cpp @@ -351,8 +351,8 @@ src/challenges/challenge_data.hpp src/challenges/game_slot.hpp src/challenges/unlock_manager.hpp src/config/device_config.hpp -src/config/player.hpp src/config/player_manager.hpp +src/config/player_profile.hpp src/config/saved_grand_prix.hpp src/config/stk_config.hpp src/config/user_config.hpp diff --git a/src/achievements/achievements_manager.cpp b/src/achievements/achievements_manager.cpp index 64e6b540a..6fb6bc2ba 100644 --- a/src/achievements/achievements_manager.cpp +++ b/src/achievements/achievements_manager.cpp @@ -18,8 +18,8 @@ #include "achievements/achievements_manager.hpp" -#include "config/player.hpp" #include "config/player_manager.hpp" +#include "config/player_profile.hpp" #include "config/user_config.hpp" #include "io/file_manager.hpp" #include "online/current_user.hpp" diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index ae0e208e8..e6324b568 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -23,8 +23,8 @@ #include "audio/sfx_base.hpp" #include "audio/sfx_manager.hpp" #include "challenges/challenge_data.hpp" -#include "config/player.hpp" #include "config/player_manager.hpp" +#include "config/player_profile.hpp" #include "config/user_config.hpp" #include "io/file_manager.hpp" #include "karts/kart_properties_manager.hpp" diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index 595e27d24..b4ebed864 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -19,7 +19,7 @@ #include "config/player_manager.hpp" #include "achievements/achievements_manager.hpp" -#include "config/player.hpp" +#include "config/player_profile.hpp" #include "io/file_manager.hpp" #include "io/utf_writer.hpp" #include "io/xml_node.hpp" diff --git a/src/config/player.cpp b/src/config/player_profile.cpp similarity index 99% rename from src/config/player.cpp rename to src/config/player_profile.cpp index 0c8c6f225..b1323b16a 100644 --- a/src/config/player.cpp +++ b/src/config/player_profile.cpp @@ -16,7 +16,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "config/player.hpp" +#include "config/player_profile.hpp" #include "challenges/game_slot.hpp" #include "challenges/unlock_manager.hpp" diff --git a/src/config/player.hpp b/src/config/player_profile.hpp similarity index 100% rename from src/config/player.hpp rename to src/config/player_profile.hpp diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index d1740acaa..a2e4db058 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -31,7 +31,7 @@ static PtrVector<UserConfigParam, REF> all_params; #define PARAM_DEFAULT(X) = X #include "config/user_config.hpp" -#include "config/player.hpp" +#include "config/player_profile.hpp" #include "config/saved_grand_prix.hpp" #include "config/stk_config.hpp" #include "guiengine/engine.hpp" diff --git a/src/input/device_manager.cpp b/src/input/device_manager.cpp index b0330a97a..dc1dca670 100644 --- a/src/input/device_manager.cpp +++ b/src/input/device_manager.cpp @@ -21,7 +21,6 @@ #include <iostream> #include <fstream> -#include "config/player.hpp" #include "config/user_config.hpp" #include "graphics/irr_driver.hpp" #include "input/wiimote_manager.hpp" diff --git a/src/karts/controller/network_player_controller.cpp b/src/karts/controller/network_player_controller.cpp index 84ebc105e..c82e59d08 100644 --- a/src/karts/controller/network_player_controller.cpp +++ b/src/karts/controller/network_player_controller.cpp @@ -1,6 +1,5 @@ #include "karts/controller/network_player_controller.hpp" -#include "config/player.hpp" #include "graphics/irr_driver.hpp" #include "graphics/post_processing.hpp" #include "input/input_manager.hpp" diff --git a/src/karts/controller/player_controller.cpp b/src/karts/controller/player_controller.cpp index 776db3b81..74e9c88aa 100644 --- a/src/karts/controller/player_controller.cpp +++ b/src/karts/controller/player_controller.cpp @@ -21,7 +21,6 @@ #include "audio/sfx_base.hpp" #include "audio/sfx_manager.hpp" -#include "config/player.hpp" #include "config/stk_config.hpp" #include "graphics/camera.hpp" #include "graphics/irr_driver.hpp" diff --git a/src/karts/controller/player_controller.hpp b/src/karts/controller/player_controller.hpp index 5839c5992..56c44e292 100644 --- a/src/karts/controller/player_controller.hpp +++ b/src/karts/controller/player_controller.hpp @@ -21,7 +21,6 @@ #ifndef HEADER_PLAYERKART_HPP #define HEADER_PLAYERKART_HPP -#include "config/player.hpp" #include "karts/controller/controller.hpp" class AbstractKart; diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index 8381e10ac..e573d9504 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -20,8 +20,8 @@ #include "karts/kart_properties_manager.hpp" #include "challenges/unlock_manager.hpp" -#include "config/player.hpp" #include "config/player_manager.hpp" +#include "config/player_profile.hpp" #include "config/stk_config.hpp" #include "config/user_config.hpp" #include "graphics/irr_driver.hpp" diff --git a/src/main.cpp b/src/main.cpp index b0162be09..440cd1c9b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,8 +146,8 @@ #include "audio/music_manager.hpp" #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" -#include "config/player.hpp" #include "config/player_manager.hpp" +#include "config/player_profile.hpp" #include "config/stk_config.hpp" #include "config/user_config.hpp" #include "graphics/hardware_skinning.hpp" diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index 21ccd8824..def7b336d 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -19,7 +19,7 @@ #include "race/grand_prix_data.hpp" -#include "config/player.hpp" +#include "config/player_profile.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "io/file_manager.hpp" diff --git a/src/states_screens/cutscene_gui.cpp b/src/states_screens/cutscene_gui.cpp index 5f8ee6a05..ac9c7b681 100644 --- a/src/states_screens/cutscene_gui.cpp +++ b/src/states_screens/cutscene_gui.cpp @@ -16,6 +16,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "config/user_config.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" #include "graphics/irr_driver.hpp" diff --git a/src/states_screens/cutscene_gui.hpp b/src/states_screens/cutscene_gui.hpp index 64deaa0aa..6a9703bc5 100644 --- a/src/states_screens/cutscene_gui.hpp +++ b/src/states_screens/cutscene_gui.hpp @@ -25,7 +25,6 @@ #include <irrString.h> using namespace irr; -#include "config/player.hpp" #include "states_screens/race_gui_base.hpp" #include "utils/cpp2011.h" diff --git a/src/states_screens/dialogs/add_device_dialog.cpp b/src/states_screens/dialogs/add_device_dialog.cpp index eb8752dd9..fc272d11a 100644 --- a/src/states_screens/dialogs/add_device_dialog.cpp +++ b/src/states_screens/dialogs/add_device_dialog.cpp @@ -17,7 +17,6 @@ #include "states_screens/dialogs/add_device_dialog.hpp" -#include "config/player.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" #include "guiengine/widget.hpp" diff --git a/src/states_screens/dialogs/add_device_dialog.hpp b/src/states_screens/dialogs/add_device_dialog.hpp index 033d6cc9f..8bac559ff 100644 --- a/src/states_screens/dialogs/add_device_dialog.hpp +++ b/src/states_screens/dialogs/add_device_dialog.hpp @@ -19,7 +19,6 @@ #ifndef HEADER_ADD_DEVICE_DIALOG_HPP #define HEADER_ADD_DEVICE_DIALOG_HPP -#include "config/player.hpp" #include "guiengine/modaldialog.hpp" /** diff --git a/src/states_screens/dialogs/change_password_dialog.cpp b/src/states_screens/dialogs/change_password_dialog.cpp index dd42330c4..cdaceb40f 100644 --- a/src/states_screens/dialogs/change_password_dialog.cpp +++ b/src/states_screens/dialogs/change_password_dialog.cpp @@ -20,7 +20,6 @@ #include <IGUIEnvironment.h> #include "audio/sfx_manager.hpp" -#include "config/player.hpp" #include "guiengine/engine.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" diff --git a/src/states_screens/dialogs/confirm_resolution_dialog.hpp b/src/states_screens/dialogs/confirm_resolution_dialog.hpp index d4a9e01e5..5a03bfc72 100644 --- a/src/states_screens/dialogs/confirm_resolution_dialog.hpp +++ b/src/states_screens/dialogs/confirm_resolution_dialog.hpp @@ -19,7 +19,6 @@ #ifndef HEADER_CONFIRM_RES_DIALOG_HPP #define HEADER_CONFIRM_RES_DIALOG_HPP -#include "config/player.hpp" #include "guiengine/modaldialog.hpp" /** diff --git a/src/states_screens/dialogs/enter_player_name_dialog.cpp b/src/states_screens/dialogs/enter_player_name_dialog.cpp index 6df6ec015..0647a5cbf 100644 --- a/src/states_screens/dialogs/enter_player_name_dialog.cpp +++ b/src/states_screens/dialogs/enter_player_name_dialog.cpp @@ -21,8 +21,8 @@ #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" -#include "config/player.hpp" #include "config/player_manager.hpp" +#include "config/player_profile.hpp" #include "guiengine/engine.hpp" #include "guiengine/widgets/button_widget.hpp" #include "guiengine/widgets/label_widget.hpp" diff --git a/src/states_screens/dialogs/message_dialog.hpp b/src/states_screens/dialogs/message_dialog.hpp index 6bc952b7d..3b56cc8f6 100644 --- a/src/states_screens/dialogs/message_dialog.hpp +++ b/src/states_screens/dialogs/message_dialog.hpp @@ -19,7 +19,6 @@ #ifndef HEADER_CONFIRM_DIALOG_HPP #define HEADER_CONFIRM_DIALOG_HPP -#include "config/player.hpp" #include "guiengine/modaldialog.hpp" #include "utils/leak_check.hpp" diff --git a/src/states_screens/dialogs/player_info_dialog.cpp b/src/states_screens/dialogs/player_info_dialog.cpp index 4f0f2709c..b8f5b991a 100644 --- a/src/states_screens/dialogs/player_info_dialog.cpp +++ b/src/states_screens/dialogs/player_info_dialog.cpp @@ -22,8 +22,8 @@ #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" -#include "config/player.hpp" #include "config/player_manager.hpp" +#include "config/player_profile.hpp" #include "guiengine/engine.hpp" #include "guiengine/widgets/button_widget.hpp" #include "guiengine/widgets/label_widget.hpp" diff --git a/src/states_screens/dialogs/player_info_dialog.hpp b/src/states_screens/dialogs/player_info_dialog.hpp index a4820f236..63c7077c2 100644 --- a/src/states_screens/dialogs/player_info_dialog.hpp +++ b/src/states_screens/dialogs/player_info_dialog.hpp @@ -19,9 +19,10 @@ #ifndef HEADER_PLAYERINFO_DIALOG_HPP #define HEADER_PLAYERINFO_DIALOG_HPP -#include "config/player.hpp" #include "guiengine/modaldialog.hpp" +class PlayerProfile; + namespace GUIEngine { class TextBoxWidget; diff --git a/src/states_screens/dialogs/recovery_dialog.cpp b/src/states_screens/dialogs/recovery_dialog.cpp index 8d4eb9f1e..f0275f779 100644 --- a/src/states_screens/dialogs/recovery_dialog.cpp +++ b/src/states_screens/dialogs/recovery_dialog.cpp @@ -20,7 +20,6 @@ #include <IGUIEnvironment.h> #include "audio/sfx_manager.hpp" -#include "config/player.hpp" #include "guiengine/engine.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" diff --git a/src/states_screens/dialogs/registration_dialog.cpp b/src/states_screens/dialogs/registration_dialog.cpp index f1e9626c8..aaf65ff56 100644 --- a/src/states_screens/dialogs/registration_dialog.cpp +++ b/src/states_screens/dialogs/registration_dialog.cpp @@ -20,7 +20,6 @@ #include <IGUIEnvironment.h> #include "audio/sfx_manager.hpp" -#include "config/player.hpp" #include "guiengine/engine.hpp" #include "states_screens/state_manager.hpp" #include "states_screens/register_screen.hpp" diff --git a/src/states_screens/dialogs/server_info_dialog.cpp b/src/states_screens/dialogs/server_info_dialog.cpp index 124f99b25..3cc42f6c9 100644 --- a/src/states_screens/dialogs/server_info_dialog.cpp +++ b/src/states_screens/dialogs/server_info_dialog.cpp @@ -20,7 +20,6 @@ #include <IGUIEnvironment.h> #include "audio/sfx_manager.hpp" -#include "config/player.hpp" #include "guiengine/engine.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" diff --git a/src/states_screens/dialogs/tutorial_message_dialog.hpp b/src/states_screens/dialogs/tutorial_message_dialog.hpp index cd10d0712..d8468788c 100644 --- a/src/states_screens/dialogs/tutorial_message_dialog.hpp +++ b/src/states_screens/dialogs/tutorial_message_dialog.hpp @@ -19,7 +19,6 @@ #ifndef HEADER_TUTORIAL_DIALOG_HPP #define HEADER_TUTORIAL_DIALOG_HPP -#include "config/player.hpp" #include "guiengine/modaldialog.hpp" #include "utils/cpp2011.h" #include "utils/leak_check.hpp" diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 6b71448e0..d777f3ede 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -19,8 +19,8 @@ #include "states_screens/kart_selection.hpp" #include "challenges/unlock_manager.hpp" -#include "config/player.hpp" #include "config/player_manager.hpp" +#include "config/player_profile.hpp" #include "config/user_config.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/engine.hpp" diff --git a/src/states_screens/options_screen_players.cpp b/src/states_screens/options_screen_players.cpp index c1bf7264a..f89501d10 100644 --- a/src/states_screens/options_screen_players.cpp +++ b/src/states_screens/options_screen_players.cpp @@ -18,8 +18,8 @@ #include "states_screens/options_screen_players.hpp" #include "challenges/unlock_manager.hpp" -#include "config/player.hpp" #include "config/player_manager.hpp" +#include "config/player_profile.hpp" #include "config/device_config.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" diff --git a/src/states_screens/race_gui.hpp b/src/states_screens/race_gui.hpp index 12142b1eb..2a76ed23a 100644 --- a/src/states_screens/race_gui.hpp +++ b/src/states_screens/race_gui.hpp @@ -26,7 +26,6 @@ #include <irrString.h> using namespace irr; -#include "config/player.hpp" #include "states_screens/race_gui_base.hpp" class AbstractKart; diff --git a/src/states_screens/race_gui_overworld.hpp b/src/states_screens/race_gui_overworld.hpp index a2901b52e..beed1b9c2 100644 --- a/src/states_screens/race_gui_overworld.hpp +++ b/src/states_screens/race_gui_overworld.hpp @@ -27,7 +27,6 @@ #include <irrString.h> using namespace irr; -#include "config/player.hpp" #include "states_screens/race_gui_base.hpp" class AbstractKart; diff --git a/src/states_screens/state_manager.hpp b/src/states_screens/state_manager.hpp index 2b3559bdc..fff7bd61a 100644 --- a/src/states_screens/state_manager.hpp +++ b/src/states_screens/state_manager.hpp @@ -27,7 +27,7 @@ #include <string> -#include "config/player.hpp" +#include "config/player_profile.hpp" #include "guiengine/abstract_state_manager.hpp" #include "utils/ptr_vector.hpp" From 1f7028f997d3798ff48c64a9a2c205199bc4a5f7 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 17 Feb 2014 20:12:15 +1100 Subject: [PATCH 55/68] Ignore all bld* directories. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 434806ad0..ca74f1c42 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -bld/ +bld*/ build/ build-32/ build-64/ From f2e6126f8db50df0ddefa28bba170340c9cf144d Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 17 Feb 2014 22:20:23 +1100 Subject: [PATCH 56/68] Renamed Challenge to ChallengeStatus (to better describe what this class is doing). --- sources.cmake | 4 ++-- src/challenges/challenge_data.hpp | 2 +- .../{challenge.cpp => challenge_status.cpp} | 12 +++++----- .../{challenge.hpp => challenge_status.hpp} | 22 ++++++++++++------- src/challenges/game_slot.cpp | 20 ++++++++--------- src/challenges/game_slot.hpp | 22 ++++++++++--------- src/challenges/unlock_manager.cpp | 8 +++---- src/config/player_profile.hpp | 12 +++++----- src/karts/kart.cpp | 16 +++++++------- .../dialogs/select_challenge.cpp | 7 ++++-- src/states_screens/race_gui_overworld.cpp | 14 ++++++------ src/tracks/track.cpp | 4 ++-- 12 files changed, 77 insertions(+), 66 deletions(-) rename src/challenges/{challenge.cpp => challenge_status.cpp} (89%) rename src/challenges/{challenge.hpp => challenge_status.hpp} (81%) diff --git a/sources.cmake b/sources.cmake index 0c5e06da6..a03343490 100644 --- a/sources.cmake +++ b/sources.cmake @@ -17,8 +17,8 @@ src/audio/music_ogg.cpp src/audio/sfx_buffer.cpp src/audio/sfx_manager.cpp src/audio/sfx_openal.cpp -src/challenges/challenge.cpp src/challenges/challenge_data.cpp +src/challenges/challenge_status.cpp src/challenges/game_slot.cpp src/challenges/unlock_manager.cpp src/config/device_config.cpp @@ -346,8 +346,8 @@ src/audio/sfx_base.hpp src/audio/sfx_buffer.hpp src/audio/sfx_manager.hpp src/audio/sfx_openal.hpp -src/challenges/challenge.hpp src/challenges/challenge_data.hpp +src/challenges/challenge_status.hpp src/challenges/game_slot.hpp src/challenges/unlock_manager.hpp src/config/device_config.hpp diff --git a/src/challenges/challenge_data.hpp b/src/challenges/challenge_data.hpp index ba3bff33e..e55215b1c 100644 --- a/src/challenges/challenge_data.hpp +++ b/src/challenges/challenge_data.hpp @@ -24,7 +24,7 @@ #include <stdio.h> #include <stdexcept> -#include "challenges/challenge.hpp" + #include "race/race_manager.hpp" /** diff --git a/src/challenges/challenge.cpp b/src/challenges/challenge_status.cpp similarity index 89% rename from src/challenges/challenge.cpp rename to src/challenges/challenge_status.cpp index e300496e5..423f0a14a 100644 --- a/src/challenges/challenge.cpp +++ b/src/challenges/challenge_status.cpp @@ -16,7 +16,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "challenges/challenge.hpp" +#include "challenges/challenge_status.hpp" #include "challenges/challenge_data.hpp" #include "io/utf_writer.hpp" @@ -33,12 +33,12 @@ //----------------------------------------------------------------------------- /** Loads the state for a challenge object (esp. m_state) */ -void Challenge::load(const XMLNode* challengesNode) +void ChallengeStatus::load(const XMLNode* challenges_node) { - const XMLNode* node = challengesNode->getNode( m_data->getId() ); + const XMLNode* node = challenges_node->getNode( m_data->getId() ); if(node == NULL) { - Log::info("Challenge", "Couldn't find node <%s> in challenge list." + Log::info("ChallengeStatus", "Couldn't find node <%s> in challenge list." "(If this is the first time you play this is normal)\n", m_data->getId().c_str()); return; @@ -76,7 +76,7 @@ void Challenge::load(const XMLNode* challengesNode) //----------------------------------------------------------------------------- -void Challenge::setSolved(RaceManager::Difficulty d) +void ChallengeStatus::setSolved(RaceManager::Difficulty d) { // solve not only the current difficulty but all those before // e.g. if you solved hard then you also get easy @@ -88,7 +88,7 @@ void Challenge::setSolved(RaceManager::Difficulty d) //----------------------------------------------------------------------------- -void Challenge::save(UTFWriter& writer) +void ChallengeStatus::save(UTFWriter& writer) { writer << L" <"<< m_data->getId() << L">\n" << L" <easy solved=\"" diff --git a/src/challenges/challenge.hpp b/src/challenges/challenge_status.hpp similarity index 81% rename from src/challenges/challenge.hpp rename to src/challenges/challenge_status.hpp index e6d3fa0e5..04f966507 100644 --- a/src/challenges/challenge.hpp +++ b/src/challenges/challenge_status.hpp @@ -16,8 +16,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_CHALLENGE_HPP -#define HEADER_CHALLENGE_HPP +#ifndef HEADER_CHALLENGE_STATUS_HPP +#define HEADER_CHALLENGE_STATUS_HPP /** * \defgroup challenges @@ -40,14 +40,20 @@ class XMLNode; /** * \brief The state of a challenge for one player. - * Each Challenge has one ChallengeData associcated, which stores - * the actual data about the challenge. + * Each ChallengeStatus has one ChallengeData associcated, which stores + * the actual data about the challenge. The ChallengeStatus stores if the + * challenge is not possible yet (inactive), active (i.e. user can try to + * solve it), or solved. This status is stored for each difficulty level. + * This data is saved to and loaded from the player.xml file. + * A PlayerProfile will store an array of ChallengeStatuses, one for each + * Challenge in STK. * * \ingroup challenges */ -class Challenge : public NoCopy +class ChallengeStatus : public NoCopy { private: + /** The different states the challenge can be in. */ enum {CH_INACTIVE, // challenge not yet possible CH_ACTIVE, // challenge possible, but not yet solved CH_SOLVED} // challenge was solved @@ -57,14 +63,14 @@ private: const ChallengeData* m_data; public: - Challenge(const ChallengeData* data) + ChallengeStatus(const ChallengeData* data) { m_data = data; m_state[RaceManager::DIFFICULTY_EASY] = CH_INACTIVE; m_state[RaceManager::DIFFICULTY_MEDIUM] = CH_INACTIVE; m_state[RaceManager::DIFFICULTY_HARD] = CH_INACTIVE; } - virtual ~Challenge() {}; + virtual ~ChallengeStatus() {}; void load(const XMLNode* config); void save(UTFWriter& writer); void setSolved(RaceManager::Difficulty d); @@ -102,5 +108,5 @@ public: /** Returns a pointer to the actual Challenge data. */ const ChallengeData* getData() const { return m_data; } -}; // Challenge +}; // ChallengeStatus #endif diff --git a/src/challenges/game_slot.cpp b/src/challenges/game_slot.cpp index 89e223257..d5d80334f 100644 --- a/src/challenges/game_slot.cpp +++ b/src/challenges/game_slot.cpp @@ -19,7 +19,7 @@ #include "challenges/game_slot.hpp" -#include "challenges/challenge.hpp" +#include "challenges/challenge_status.hpp" #include "challenges/challenge_data.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" @@ -47,7 +47,7 @@ GameSlot::GameSlot(const XMLNode *node) //----------------------------------------------------------------------------- GameSlot::~GameSlot() { - std::map<std::string, Challenge*>::iterator it; + std::map<std::string, ChallengeStatus*>::iterator it; for (it = m_challenges_state.begin();it != m_challenges_state.end();it++) { delete it->second; @@ -69,7 +69,7 @@ void GameSlot::computeActive() m_locked_features.clear(); // start afresh - std::map<std::string, Challenge*>::const_iterator i; + std::map<std::string, ChallengeStatus*>::const_iterator i; for(i = m_challenges_state.begin(); i != m_challenges_state.end(); i++) { @@ -166,10 +166,10 @@ void GameSlot::computeActive() //----------------------------------------------------------------------------- -void GameSlot::lockFeature(Challenge *challenge) +void GameSlot::lockFeature(ChallengeStatus *challenge_status) { const std::vector<ChallengeData::UnlockableFeature>& features = - challenge->getData()->getFeatures(); + challenge_status->getData()->getFeatures(); const unsigned int amount = (unsigned int)features.size(); for (unsigned int n=0; n<amount; n++) @@ -184,7 +184,7 @@ void GameSlot::lockFeature(Challenge *challenge) * \param d Difficulty at which the challenge was solved. * \param do_save If true update the challenge file on disk. */ -void GameSlot::unlockFeature(Challenge* c, RaceManager::Difficulty d, +void GameSlot::unlockFeature(ChallengeStatus* c, RaceManager::Difficulty d, bool do_save) { const unsigned int amount=(unsigned int)c->getData()->getFeatures().size(); @@ -216,7 +216,7 @@ void GameSlot::unlockFeature(Challenge* c, RaceManager::Difficulty d, void GameSlot::setCurrentChallenge(const std::string &challenge_id) { m_current_challenge = challenge_id=="" ? NULL - : getChallenge(challenge_id); + : getChallengeStatus(challenge_id); } // setCurrentChallenge //----------------------------------------------------------------------------- @@ -232,7 +232,7 @@ void GameSlot::raceFinished() // cast const away so that the challenge can be set to fulfilled. // The 'clean' implementation would involve searching the challenge // in m_challenges_state, which is a bit of an overkill - unlockFeature(const_cast<Challenge*>(m_current_challenge), + unlockFeature(const_cast<ChallengeStatus*>(m_current_challenge), race_manager->getDifficulty()); } // if isActive && challenge solved } // raceFinished @@ -247,7 +247,7 @@ void GameSlot::grandPrixFinished() m_current_challenge->isActive(race_manager->getDifficulty()) && m_current_challenge->getData()->isGPFulfilled() ) { - unlockFeature(const_cast<Challenge*>(m_current_challenge), + unlockFeature(const_cast<ChallengeStatus*>(m_current_challenge), race_manager->getDifficulty()); } // if isActive && challenge solved @@ -262,7 +262,7 @@ void GameSlot::save(UTFWriter &out) { out << " <game-slot playerID=\"" << m_player_unique_id << "\" first-time=\"" << m_first_time << L"\">\n"; - std::map<std::string, Challenge*>::const_iterator i; + std::map<std::string, ChallengeStatus*>::const_iterator i; for(i = m_challenges_state.begin(); i != m_challenges_state.end(); i++) { diff --git a/src/challenges/game_slot.hpp b/src/challenges/game_slot.hpp index 586b2a80a..459a1cf95 100644 --- a/src/challenges/game_slot.hpp +++ b/src/challenges/game_slot.hpp @@ -28,9 +28,8 @@ using namespace irr; #include <map> #include <vector> - -class Challenge; class ChallengeData; +class ChallengeStatus; class UTFWriter; class XMLNode; @@ -56,11 +55,11 @@ class GameSlot * until they are shown to the user) */ std::vector<const ChallengeData*> m_unlocked_features; - std::map<std::string, Challenge*> m_challenges_state; + std::map<std::string, ChallengeStatus*> m_challenges_state; /** A pointer to the current challenge, or NULL * if no challenge is active. */ - const Challenge *m_current_challenge; + const ChallengeStatus *m_current_challenge; friend class UnlockManager; @@ -80,8 +79,8 @@ public: void computeActive(); bool isLocked (const std::string& feature); - void lockFeature (Challenge *challenge); - void unlockFeature (Challenge* c, RaceManager::Difficulty d, + void lockFeature (ChallengeStatus *challenge); + void unlockFeature (ChallengeStatus* c, RaceManager::Difficulty d, bool do_save=true); void raceFinished (); void grandPrixFinished (); @@ -115,17 +114,20 @@ public: /** Returns if this is the first time the intro is shown. */ bool isFirstTime() const { return m_first_time; } // ------------------------------------------------------------------------ - const Challenge *getCurrentChallenge() const { return m_current_challenge; } + const ChallengeStatus *getCurrentChallengeStatus() const + { + return m_current_challenge; + } // getCurrentChallengeStatus // ------------------------------------------------------------------------ /** Returns a challenge given the challenge id. */ - const Challenge* getChallenge(const std::string& id) const + const ChallengeStatus* getChallengeStatus(const std::string& id) const { - std::map<std::string, Challenge*>::const_iterator it = + std::map<std::string, ChallengeStatus*>::const_iterator it = m_challenges_state.find(id); assert(it!=m_challenges_state.end()); return it->second; - } // getChallenge + } // getChallengeStatus }; // GameSlot #endif diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index e6324b568..fba554ccf 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -18,11 +18,11 @@ #include "challenges/unlock_manager.hpp" - #include "achievements/achievements_manager.hpp" #include "audio/sfx_base.hpp" #include "audio/sfx_manager.hpp" #include "challenges/challenge_data.hpp" +#include "challenges/challenge_status.hpp" #include "config/player_manager.hpp" #include "config/player_profile.hpp" #include "config/user_config.hpp" @@ -204,10 +204,10 @@ GameSlot *UnlockManager::createGameSlot(const XMLNode *node) i!=m_all_challenges.end(); i++) { ChallengeData* cd = i->second; - Challenge *challenge = new Challenge(cd); + ChallengeStatus *challenge_status = new ChallengeStatus(cd); if(node) - challenge->load(node); - slot->m_challenges_state[cd->getId()] = challenge; + challenge_status->load(node); + slot->m_challenges_state[cd->getId()] = challenge_status; } slot->computeActive(); diff --git a/src/config/player_profile.hpp b/src/config/player_profile.hpp index 03e5223a3..25856005b 100644 --- a/src/config/player_profile.hpp +++ b/src/config/player_profile.hpp @@ -164,15 +164,15 @@ public: void clearUnlocked() { m_game_slot->clearUnlocked(); } // ------------------------------------------------------------------------ /** Returns the current challenge for this player. */ - const Challenge* getCurrentChallenge() const + const ChallengeStatus* getCurrentChallengeStatus() const { - return m_game_slot->getCurrentChallenge(); - } // getCurrentChallenge + return m_game_slot->getCurrentChallengeStatus(); + } // getCurrentChallengeStatus // ------------------------------------------------------------------------ - const Challenge* getChallenge(const std::string &id) + const ChallengeStatus* getChallengeStatus(const std::string &id) { - return m_game_slot->getChallenge(id); - } // getChallenge + return m_game_slot->getChallengeStatus(id); + } // getChallengeStatus // ------------------------------------------------------------------------ unsigned int getNumEasyTrophies() const { diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index bbd5fbf7a..76483fa46 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -19,16 +19,10 @@ #include "karts/kart.hpp" -#include <math.h> -#include <iostream> -#include <algorithm> // for min and max - -#include <ICameraSceneNode.h> -#include <ISceneManager.h> - #include "audio/music_manager.hpp" #include "audio/sfx_manager.hpp" #include "audio/sfx_base.hpp" +#include "challenges/challenge_status.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "config/user_config.hpp" @@ -73,6 +67,12 @@ #include "utils/log.hpp" //TODO: remove after debugging is done #include "utils/vs.hpp" +#include <ICameraSceneNode.h> +#include <ISceneManager.h> + +#include <algorithm> // for min and max +#include <iostream> +#include <math.h> #if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__) @@ -806,7 +806,7 @@ void Kart::finishedRace(float time) if (m_controller->isPlayerController()) // if player is on this computer { PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); - const Challenge *challenge = player->getCurrentChallenge(); + const ChallengeStatus *challenge = player->getCurrentChallengeStatus(); // In case of a GP challenge don't make the end animation depend // on if the challenge is fulfilled if(challenge && !challenge->getData()->isGrandPrix()) diff --git a/src/states_screens/dialogs/select_challenge.cpp b/src/states_screens/dialogs/select_challenge.cpp index 6cd18ad07..7839ca6ed 100644 --- a/src/states_screens/dialogs/select_challenge.cpp +++ b/src/states_screens/dialogs/select_challenge.cpp @@ -15,6 +15,9 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "states_screens/dialogs/select_challenge.hpp" + +#include "challenges/challenge_status.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "config/user_config.hpp" @@ -29,7 +32,6 @@ #include "network/network_manager.hpp" #include "race/grand_prix_manager.hpp" #include "race/race_manager.hpp" -#include "states_screens/dialogs/select_challenge.hpp" #include "tracks/track_manager.hpp" #include "tracks/track.hpp" #include "utils/log.hpp" @@ -93,7 +95,8 @@ SelectChallengeDialog::SelectChallengeDialog(const float percentWidth, break; } - const Challenge* c = PlayerManager::get()->getCurrentPlayer()->getChallenge(challenge_id); + const ChallengeStatus* c = PlayerManager::get()->getCurrentPlayer() + ->getChallengeStatus(challenge_id); if (c->isSolved(RaceManager::DIFFICULTY_EASY)) { diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index f906d612e..2b1fd0e34 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -19,10 +19,7 @@ #include "states_screens/race_gui_overworld.hpp" -using namespace irr; - -#include <algorithm> - +#include "challenges/challenge_status.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "config/user_config.hpp" @@ -54,6 +51,9 @@ using namespace irr; #include <ISceneCollisionManager.h> #include <ISceneManager.h> +using namespace irr; + +#include <algorithm> const int LOCKED = 0; const int OPEN = 1; @@ -398,9 +398,9 @@ void RaceGUIOverworld::drawGlobalMiniMap() // bool locked = (m_locked_challenges.find(c) != m_locked_challenges.end()); int state = (challenges[n].getForceField().m_is_locked ? LOCKED : OPEN); - const Challenge* c = PlayerManager::get()->getCurrentPlayer() - ->getChallenge(challenges[n].m_challenge_id); - if (c->isSolved(RaceManager::DIFFICULTY_HARD)) state = COMPLETED_HARD; + const ChallengeStatus* c = PlayerManager::get()->getCurrentPlayer() + ->getChallengeStatus(challenges[n].m_challenge_id); + if (c->isSolved(RaceManager::DIFFICULTY_HARD)) state = COMPLETED_HARD; else if (c->isSolved(RaceManager::DIFFICULTY_MEDIUM)) state = COMPLETED_MEDIUM; else if (c->isSolved(RaceManager::DIFFICULTY_EASY)) state = COMPLETED_EASY; diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index d28d2526a..bdf139d1f 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -21,7 +21,7 @@ #include "addons/addon.hpp" #include "audio/music_manager.hpp" -#include "challenges/challenge.hpp" +#include "challenges/challenge_status.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "config/stk_config.hpp" @@ -164,7 +164,7 @@ unsigned int Track::getNumOfCompletedChallenges() unlocked_challenges++; continue; } - if (player->getChallenge(m_challenges[i].m_challenge_id) + if (player->getChallengeStatus(m_challenges[i].m_challenge_id) ->isSolvedAtAnyDifficulty()) { unlocked_challenges++; From 94da45238c20e8d4413be3c7c5a9d1817f5dfe2d Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Mon, 17 Feb 2014 23:16:53 +1100 Subject: [PATCH 57/68] Renamed GameSlot to StoryModeStatus to better describe its function. --- sources.cmake | 4 +- .../{game_slot.cpp => story_mode_status.cpp} | 28 ++++++------- .../{game_slot.hpp => story_mode_status.hpp} | 8 ++-- src/challenges/unlock_manager.cpp | 16 ++++---- src/challenges/unlock_manager.hpp | 8 ++-- src/config/player_profile.cpp | 17 ++++---- src/config/player_profile.hpp | 40 +++++++++---------- src/modes/cutscene_world.cpp | 1 - src/states_screens/create_server_screen.cpp | 1 - .../dialogs/select_challenge.cpp | 2 +- src/states_screens/feature_unlocked.cpp | 1 - src/states_screens/main_menu_screen.cpp | 13 +++--- src/states_screens/networking_lobby.cpp | 1 - src/states_screens/race_gui_overworld.cpp | 3 +- src/tracks/track.cpp | 4 +- 15 files changed, 69 insertions(+), 78 deletions(-) rename src/challenges/{game_slot.cpp => story_mode_status.cpp} (93%) rename src/challenges/{game_slot.hpp => story_mode_status.hpp} (97%) diff --git a/sources.cmake b/sources.cmake index a03343490..d20d394ac 100644 --- a/sources.cmake +++ b/sources.cmake @@ -19,7 +19,7 @@ src/audio/sfx_manager.cpp src/audio/sfx_openal.cpp src/challenges/challenge_data.cpp src/challenges/challenge_status.cpp -src/challenges/game_slot.cpp +src/challenges/story_mode_status.cpp src/challenges/unlock_manager.cpp src/config/device_config.cpp src/config/player_manager.cpp @@ -348,7 +348,7 @@ src/audio/sfx_manager.hpp src/audio/sfx_openal.hpp src/challenges/challenge_data.hpp src/challenges/challenge_status.hpp -src/challenges/game_slot.hpp +src/challenges/story_mode_status.hpp src/challenges/unlock_manager.hpp src/config/device_config.hpp src/config/player_manager.hpp diff --git a/src/challenges/game_slot.cpp b/src/challenges/story_mode_status.cpp similarity index 93% rename from src/challenges/game_slot.cpp rename to src/challenges/story_mode_status.cpp index d5d80334f..8ee1c7e2a 100644 --- a/src/challenges/game_slot.cpp +++ b/src/challenges/story_mode_status.cpp @@ -17,7 +17,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "challenges/game_slot.hpp" +#include "challenges/story_mode_status.hpp" #include "challenges/challenge_status.hpp" #include "challenges/challenge_data.hpp" @@ -27,7 +27,7 @@ #include "io/xml_node.hpp" //----------------------------------------------------------------------------- -GameSlot::GameSlot(const XMLNode *node) +StoryModeStatus::StoryModeStatus(const XMLNode *node) { m_points = 0; m_first_time = true; @@ -42,25 +42,25 @@ GameSlot::GameSlot(const XMLNode *node) node->get("first-time", &m_first_time); } // if node -} // GameSlot +} // StoryModeStatus //----------------------------------------------------------------------------- -GameSlot::~GameSlot() +StoryModeStatus::~StoryModeStatus() { std::map<std::string, ChallengeStatus*>::iterator it; for (it = m_challenges_state.begin();it != m_challenges_state.end();it++) { delete it->second; } -} // ~GameSlot +} // ~StoryModeStatus //----------------------------------------------------------------------------- -bool GameSlot::isLocked(const std::string& feature) +bool StoryModeStatus::isLocked(const std::string& feature) { return m_locked_features.find(feature)!=m_locked_features.end(); } // featureIsLocked //----------------------------------------------------------------------------- -void GameSlot::computeActive() +void StoryModeStatus::computeActive() { m_points = 0; m_easy_challenges = 0; @@ -166,7 +166,7 @@ void GameSlot::computeActive() //----------------------------------------------------------------------------- -void GameSlot::lockFeature(ChallengeStatus *challenge_status) +void StoryModeStatus::lockFeature(ChallengeStatus *challenge_status) { const std::vector<ChallengeData::UnlockableFeature>& features = challenge_status->getData()->getFeatures(); @@ -184,7 +184,7 @@ void GameSlot::lockFeature(ChallengeStatus *challenge_status) * \param d Difficulty at which the challenge was solved. * \param do_save If true update the challenge file on disk. */ -void GameSlot::unlockFeature(ChallengeStatus* c, RaceManager::Difficulty d, +void StoryModeStatus::unlockFeature(ChallengeStatus* c, RaceManager::Difficulty d, bool do_save) { const unsigned int amount=(unsigned int)c->getData()->getFeatures().size(); @@ -213,7 +213,7 @@ void GameSlot::unlockFeature(ChallengeStatus* c, RaceManager::Difficulty d, /** Set the current challenge (or NULL if no challenge is done). * \param challenge Pointer to the challenge (or NULL) */ -void GameSlot::setCurrentChallenge(const std::string &challenge_id) +void StoryModeStatus::setCurrentChallenge(const std::string &challenge_id) { m_current_challenge = challenge_id=="" ? NULL : getChallengeStatus(challenge_id); @@ -223,7 +223,7 @@ void GameSlot::setCurrentChallenge(const std::string &challenge_id) /** This is called when a race is finished. See if there is an active * challenge that was fulfilled. */ -void GameSlot::raceFinished() +void StoryModeStatus::raceFinished() { if(m_current_challenge && m_current_challenge->isActive(race_manager->getDifficulty()) && @@ -241,7 +241,7 @@ void GameSlot::raceFinished() /** This is called when a GP is finished. See if there is an active * challenge that was fulfilled. */ -void GameSlot::grandPrixFinished() +void StoryModeStatus::grandPrixFinished() { if(m_current_challenge && m_current_challenge->isActive(race_manager->getDifficulty()) && @@ -255,10 +255,10 @@ void GameSlot::grandPrixFinished() } // grandPrixFinished //----------------------------------------------------------------------------- -/** Writes the data of this GameSlot to the specified stream. +/** Writes the data of this StoryModeStatus to the specified stream. * \param out UTF stream to write to. */ -void GameSlot::save(UTFWriter &out) +void StoryModeStatus::save(UTFWriter &out) { out << " <game-slot playerID=\"" << m_player_unique_id << "\" first-time=\"" << m_first_time << L"\">\n"; diff --git a/src/challenges/game_slot.hpp b/src/challenges/story_mode_status.hpp similarity index 97% rename from src/challenges/game_slot.hpp rename to src/challenges/story_mode_status.hpp index 459a1cf95..93bc585c6 100644 --- a/src/challenges/game_slot.hpp +++ b/src/challenges/story_mode_status.hpp @@ -40,7 +40,7 @@ const int CHALLENGE_POINTS[] = { 8, 9, 10 }; * This class contains the progression through challenges for one game slot */ -class GameSlot +class StoryModeStatus { /** Profile names can change, so rather than try to make sure all renames * are done everywhere, assign a unique ID to each profiler. @@ -74,8 +74,8 @@ class GameSlot public: - GameSlot(const XMLNode *node=NULL); - ~GameSlot(); + StoryModeStatus(const XMLNode *node=NULL); + ~StoryModeStatus(); void computeActive(); bool isLocked (const std::string& feature); @@ -128,6 +128,6 @@ public: assert(it!=m_challenges_state.end()); return it->second; } // getChallengeStatus -}; // GameSlot +}; // StoryModeStatus #endif diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index fba554ccf..3182e2852 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -182,12 +182,12 @@ void UnlockManager::addChallenge(const std::string& filename) * challenge exist. * \param id Id of the challenge. */ -const ChallengeData* UnlockManager::getChallenge(const std::string& id) +const ChallengeData* UnlockManager::getChallengeData(const std::string& id) { AllChallengesType::const_iterator it = m_all_challenges.find(id); if(it==m_all_challenges.end()) return NULL; return it->second; -} // getChallenge +} // getChallengeData //----------------------------------------------------------------------------- /** Creates a game slot. It initialises the game slot's status with the @@ -195,10 +195,10 @@ const ChallengeData* UnlockManager::getChallenge(const std::string& id) * states for a player. * \param node The XML game-slots node with all data for a player. */ -GameSlot *UnlockManager::createGameSlot(const XMLNode *node) +StoryModeStatus* UnlockManager::createStoryModeStatus(const XMLNode *node) { - GameSlot *slot = new GameSlot(node); + StoryModeStatus *status = new StoryModeStatus(node); for(AllChallengesType::iterator i = m_all_challenges.begin(); i!=m_all_challenges.end(); i++) @@ -207,12 +207,12 @@ GameSlot *UnlockManager::createGameSlot(const XMLNode *node) ChallengeStatus *challenge_status = new ChallengeStatus(cd); if(node) challenge_status->load(node); - slot->m_challenges_state[cd->getId()] = challenge_status; + status->m_challenges_state[cd->getId()] = challenge_status; } - slot->computeActive(); - return slot; -} // createGameSlot + status->computeActive(); + return status; +} // createStoryModeStatus //----------------------------------------------------------------------------- void UnlockManager::playLockSound() const diff --git a/src/challenges/unlock_manager.hpp b/src/challenges/unlock_manager.hpp index 70a5fd1f6..093079389 100644 --- a/src/challenges/unlock_manager.hpp +++ b/src/challenges/unlock_manager.hpp @@ -24,7 +24,7 @@ #include "config/user_config.hpp" #include "challenges/challenge_data.hpp" -#include "challenges/game_slot.hpp" +#include "challenges/story_mode_status.hpp" #include "utils/no_copy.hpp" #include "utils/ptr_vector.hpp" @@ -48,15 +48,13 @@ private: void readAllChallengesInDirs(const std::vector<std::string>* all_dirs); - friend class GameSlot; - public: UnlockManager (); ~UnlockManager (); void addOrFreeChallenge(ChallengeData *c); void addChallenge (const std::string& filename); - const ChallengeData *getChallenge (const std::string& id); + const ChallengeData *getChallengeData(const std::string& id); bool isSupportedVersion(const ChallengeData &challenge); @@ -67,7 +65,7 @@ public: std::vector<std::string>& tracks, std::vector<std::string>& gps); - GameSlot *createGameSlot(const XMLNode *node=NULL); + StoryModeStatus *createStoryModeStatus(const XMLNode *node=NULL); }; // UnlockManager diff --git a/src/config/player_profile.cpp b/src/config/player_profile.cpp index b1323b16a..537acb956 100644 --- a/src/config/player_profile.cpp +++ b/src/config/player_profile.cpp @@ -18,7 +18,6 @@ #include "config/player_profile.hpp" -#include "challenges/game_slot.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "io/xml_node.hpp" @@ -38,11 +37,11 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest) #ifdef DEBUG m_magic_number = 0xABCD1234; #endif - m_name = name; - m_is_guest_account = is_guest; - m_use_frequency = is_guest ? -1 : 0; - m_unique_id = PlayerManager::get()->getUniqueId(); - m_game_slot = unlock_manager->createGameSlot(); + m_name = name; + m_is_guest_account = is_guest; + m_use_frequency = is_guest ? -1 : 0; + m_unique_id = PlayerManager::get()->getUniqueId(); + m_story_mode_status = unlock_manager->createStoryModeStatus(); } // PlayerProfile @@ -61,7 +60,7 @@ PlayerProfile::PlayerProfile(const XMLNode* node) m_magic_number = 0xABCD1234; #endif const XMLNode *xml_game_slot = node->getNode("game-slot"); - m_game_slot = unlock_manager->createGameSlot(xml_game_slot); + m_story_mode_status = unlock_manager->createStoryModeStatus(xml_game_slot); } // PlayerProfile @@ -76,8 +75,8 @@ void PlayerProfile::save(UTFWriter &out) << L"\" use-frequency=\"" << m_use_frequency << L"\" is-default=\"" << m_is_default << L"\" unique-id=\"" << m_unique_id << L"\">\n"; - assert(m_game_slot); - m_game_slot->save(out); + assert(m_story_mode_status); + m_story_mode_status->save(out); out << L" </player>\n"; } // save diff --git a/src/config/player_profile.hpp b/src/config/player_profile.hpp index 25856005b..1a8ce792d 100644 --- a/src/config/player_profile.hpp +++ b/src/config/player_profile.hpp @@ -16,11 +16,10 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_PLAYER_HPP -#define HEADER_PLAYER_HPP - -#include "challenges/game_slot.hpp" +#ifndef HEADER_PLAYER_PROFILE_HPP +#define HEADER_PLAYER_PROFILE_HPP +#include "challenges/story_mode_status.hpp" #include "config/user_config.hpp" #include "utils/no_copy.hpp" #include "utils/types.hpp" @@ -30,7 +29,6 @@ using namespace irr; #include <string> -class GameSlot; class UTFWriter; /** @@ -64,7 +62,7 @@ private: bool m_is_default; /** The complete challenge state. */ - GameSlot *m_game_slot; + StoryModeStatus *m_story_mode_status; public: @@ -129,64 +127,64 @@ public: /** Returnes if the feature (kart, track) is locked. */ bool isLocked(const std::string &feature) const { - return m_game_slot->isLocked(feature); + return m_story_mode_status->isLocked(feature); } // isLocked // ------------------------------------------------------------------------ /** Returns all active challenges. */ - void computeActive() { m_game_slot->computeActive(); } + void computeActive() { m_story_mode_status->computeActive(); } // ------------------------------------------------------------------------ /** Returns the list of recently completed challenges. */ std::vector<const ChallengeData*> getRecentlyCompletedChallenges() { - return m_game_slot->getRecentlyCompletedChallenges(); + return m_story_mode_status->getRecentlyCompletedChallenges(); } // getRecently Completed Challenges // ------------------------------------------------------------------------ /** Sets the currently active challenge. */ void setCurrentChallenge(const std::string &name) { - m_game_slot->setCurrentChallenge(name); + m_story_mode_status->setCurrentChallenge(name); } // setCurrentChallenge // ------------------------------------------------------------------------ /** Notification of a finished race, which can trigger fulfilling * challenges. */ - void raceFinished() { m_game_slot->raceFinished(); } + void raceFinished() { m_story_mode_status->raceFinished(); } // ------------------------------------------------------------------------ /** Callback when a GP is finished (to test if a challenge was * fulfilled). */ - void grandPrixFinished() { m_game_slot->grandPrixFinished(); } + void grandPrixFinished() { m_story_mode_status->grandPrixFinished(); } // ------------------------------------------------------------------------ - unsigned int getPoints() const { return m_game_slot->getPoints(); } + unsigned int getPoints() const { return m_story_mode_status->getPoints(); } // ------------------------------------------------------------------------ - void setFirstTime(bool b) { m_game_slot->setFirstTime(b); } + void setFirstTime(bool b) { m_story_mode_status->setFirstTime(b); } // ------------------------------------------------------------------------ - bool isFirstTime() const { return m_game_slot->isFirstTime(); } + bool isFirstTime() const { return m_story_mode_status->isFirstTime(); } // ------------------------------------------------------------------------ - void clearUnlocked() { m_game_slot->clearUnlocked(); } + void clearUnlocked() { m_story_mode_status->clearUnlocked(); } // ------------------------------------------------------------------------ /** Returns the current challenge for this player. */ const ChallengeStatus* getCurrentChallengeStatus() const { - return m_game_slot->getCurrentChallengeStatus(); + return m_story_mode_status->getCurrentChallengeStatus(); } // getCurrentChallengeStatus // ------------------------------------------------------------------------ const ChallengeStatus* getChallengeStatus(const std::string &id) { - return m_game_slot->getChallengeStatus(id); + return m_story_mode_status->getChallengeStatus(id); } // getChallengeStatus // ------------------------------------------------------------------------ unsigned int getNumEasyTrophies() const { - return m_game_slot->getNumEasyTrophies(); + return m_story_mode_status->getNumEasyTrophies(); } // getNumEasyTrophies // ------------------------------------------------------------------------ unsigned int getNumMediumTrophies() const { - return m_game_slot->getNumMediumTrophies(); + return m_story_mode_status->getNumMediumTrophies(); } // getNumEasyTrophies // ----------------------------------------------------------------------- unsigned int getNumHardTrophies() const { - return m_game_slot->getNumHardTrophies(); + return m_story_mode_status->getNumHardTrophies(); } // getNumHardTropies }; // class PlayerProfile diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index 6ba63c3b1..e394f0670 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -20,7 +20,6 @@ #include "animations/animation_base.hpp" #include "animations/three_d_animation.hpp" #include "audio/music_manager.hpp" -#include "challenges/game_slot.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" diff --git a/src/states_screens/create_server_screen.cpp b/src/states_screens/create_server_screen.cpp index a2edf6a9c..64952f816 100644 --- a/src/states_screens/create_server_screen.cpp +++ b/src/states_screens/create_server_screen.cpp @@ -22,7 +22,6 @@ #include <string> #include <iostream> -#include "challenges/game_slot.hpp" #include "challenges/unlock_manager.hpp" #include "audio/sfx_manager.hpp" #include "states_screens/online_screen.hpp" diff --git a/src/states_screens/dialogs/select_challenge.cpp b/src/states_screens/dialogs/select_challenge.cpp index 7839ca6ed..883f385e6 100644 --- a/src/states_screens/dialogs/select_challenge.cpp +++ b/src/states_screens/dialogs/select_challenge.cpp @@ -164,7 +164,7 @@ GUIEngine::EventPropagation SelectChallengeDialog::processEvent(const std::strin if (eventSource == "novice" || eventSource == "intermediate" || eventSource == "expert") { - const ChallengeData* challenge = unlock_manager->getChallenge(m_challenge_id); + const ChallengeData* challenge = unlock_manager->getChallengeData(m_challenge_id); if (challenge == NULL) { diff --git a/src/states_screens/feature_unlocked.cpp b/src/states_screens/feature_unlocked.cpp index bdeb22146..f726dbd1d 100644 --- a/src/states_screens/feature_unlocked.cpp +++ b/src/states_screens/feature_unlocked.cpp @@ -22,7 +22,6 @@ #include "audio/music_manager.hpp" #include "challenges/challenge_data.hpp" -#include "challenges/game_slot.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "guiengine/engine.hpp" diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 5ffba1630..c2ed26403 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -19,9 +19,7 @@ #include "states_screens/main_menu_screen.hpp" -#include <string> - -#include "challenges/game_slot.hpp" +#include "addons/news_manager.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "graphics/irr_driver.hpp" @@ -46,20 +44,21 @@ #include "states_screens/online_screen.hpp" #include "states_screens/options_screen_video.hpp" #include "states_screens/state_manager.hpp" - #if DEBUG_MENU_ITEM #include "states_screens/feature_unlocked.hpp" #include "states_screens/grand_prix_lose.hpp" #include "states_screens/grand_prix_win.hpp" #endif - #include "states_screens/dialogs/message_dialog.hpp" - -#include "addons/news_manager.hpp" #include "tracks/track_manager.hpp" #include "tracks/track.hpp" #include "utils/string_utils.hpp" + + +#include <string> + + using namespace GUIEngine; using namespace Online; diff --git a/src/states_screens/networking_lobby.cpp b/src/states_screens/networking_lobby.cpp index 3f04b57dd..37ed2a886 100644 --- a/src/states_screens/networking_lobby.cpp +++ b/src/states_screens/networking_lobby.cpp @@ -22,7 +22,6 @@ #include <string> #include <iostream> -#include "challenges/game_slot.hpp" #include "challenges/unlock_manager.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/scalable_font.hpp" diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index 2b1fd0e34..d2233d6b7 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -460,7 +460,8 @@ void RaceGUIOverworld::drawGlobalMiniMap() continue; } - const ChallengeData* challenge = unlock_manager->getChallenge(challenges[n].m_challenge_id); + const ChallengeData* challenge = + unlock_manager->getChallengeData(challenges[n].m_challenge_id); if (challenge == NULL) { diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index bdf139d1f..eca974607 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -947,7 +947,7 @@ bool Track::loadMainTrack(const XMLNode &root) assert(closest_challenge_id < (int)m_challenges.size()); const std::string &s = m_challenges[closest_challenge_id].m_challenge_id; - const ChallengeData* challenge = unlock_manager->getChallenge(s); + const ChallengeData* challenge = unlock_manager->getChallengeData(s); if (challenge == NULL) { if (s != "tutorial") @@ -1126,7 +1126,7 @@ bool Track::loadMainTrack(const XMLNode &root) if (challenge != "tutorial") { - c = unlock_manager->getChallenge(challenge); + c = unlock_manager->getChallengeData(challenge); if (c == NULL) { Log::error("track", "Cannot find challenge named <%s>\n", From e5a174d85b8f8e30004741f2133eac24e0ac8eea Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Mon, 17 Feb 2014 15:34:57 +0100 Subject: [PATCH 58/68] Add compatibility keyword on and remove some unused shaders --- data/shaders/objectpass.frag | 32 -------------------------------- data/shaders/objectpass.vert | 19 ------------------- data/shaders/rain.frag | 2 +- data/shaders/rain.vert | 2 +- data/shaders/rainsim.vert | 2 +- src/graphics/shaders.cpp | 10 +++++----- 6 files changed, 8 insertions(+), 59 deletions(-) delete mode 100644 data/shaders/objectpass.frag delete mode 100644 data/shaders/objectpass.vert diff --git a/data/shaders/objectpass.frag b/data/shaders/objectpass.frag deleted file mode 100644 index 436679563..000000000 --- a/data/shaders/objectpass.frag +++ /dev/null @@ -1,32 +0,0 @@ -#version 330 -uniform sampler2D tex; -uniform sampler2D lighttex; -uniform int hastex; -uniform int haslightmap; - -noperspective in vec3 nor; -in vec4 color; -in vec2 uv0; -in vec2 uv1; -out vec4 Albedo; -out vec4 NormalDepth; -out vec4 Specular; - -void main() { - vec4 light = vec4(1.0); - vec4 col; - - if (haslightmap != 0) { - light = texture(lighttex, uv1); - } - - if (hastex != 0) - col = texture(tex, uv0) * light; - else - col = color; - - Albedo = vec4(col.xyz, 1.); - NormalDepth = vec4(0.5 * normalize(nor) + 0.5, gl_FragCoord.z); - Specular = vec4(1. - col.a); -} - diff --git a/data/shaders/objectpass.vert b/data/shaders/objectpass.vert deleted file mode 100644 index 877192df0..000000000 --- a/data/shaders/objectpass.vert +++ /dev/null @@ -1,19 +0,0 @@ -#version 330 -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 TransposeInverseModelView; -uniform mat4 TextureMatrix0; -uniform mat4 TextureMatrix1; - -noperspective out vec3 nor; -out vec4 color; -out vec2 uv0; -out vec2 uv1; - -void main() { - - nor = (TransposeInverseModelView * vec4(gl_Normal, 1.)).xyz; - uv0 = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st; - uv1 = (gl_TextureMatrix[1] * gl_MultiTexCoord1).st; - gl_Position = ModelViewProjectionMatrix * gl_Vertex; - color = gl_Color; -} diff --git a/data/shaders/rain.frag b/data/shaders/rain.frag index 4fb5ad597..66af66dd3 100644 --- a/data/shaders/rain.frag +++ b/data/shaders/rain.frag @@ -1,4 +1,4 @@ -#version 330 +#version 330 compatibility uniform sampler2D tex; uniform sampler2D normals_and_depth; uniform mat4 invproj; diff --git a/data/shaders/rain.vert b/data/shaders/rain.vert index 7ac11bc00..e20bf80f3 100644 --- a/data/shaders/rain.vert +++ b/data/shaders/rain.vert @@ -1,4 +1,4 @@ -#version 330 +#version 330 compatibility uniform float screenw; void main() diff --git a/data/shaders/rainsim.vert b/data/shaders/rainsim.vert index 0a57b8671..dca63e1bf 100644 --- a/data/shaders/rainsim.vert +++ b/data/shaders/rainsim.vert @@ -1,4 +1,4 @@ -#version 330 +#version 330 compatibility uniform float time; uniform vec3 campos; uniform mat4 viewm; diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index f9fe82420..7e3c041a8 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -119,7 +119,7 @@ void Shaders::loadShaders() m_shaders[ES_WATER_SURFACE] = glsl(dir + "water.vert", dir + "pass.frag", m_callbacks[ES_WATER]); - m_shaders[ES_SPHERE_MAP] = glsl_noinput(dir + "objectpass.vert", dir + "objectpass_spheremap.frag"); + m_shaders[ES_SPHERE_MAP] = glsl_noinput(std::string(""), dir + "objectpass_spheremap.frag"); m_shaders[ES_GRASS] = glslmat(std::string(""), dir + "pass.frag", m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL); @@ -146,10 +146,10 @@ void Shaders::loadShaders() m_shaders[ES_COLORIZE] = glslmat(std::string(""), dir + "colorize.frag", m_callbacks[ES_COLORIZE], EMT_SOLID); - m_shaders[ES_OBJECTPASS] = glsl_noinput(dir + "objectpass.vert", dir + "objectpass.frag"); - m_shaders[ES_OBJECT_UNLIT] = glsl_noinput(dir + "objectpass.vert", dir + "objectpass.frag"); - m_shaders[ES_OBJECTPASS_REF] = glsl_noinput(dir + "objectpass.vert", dir + "objectpass_ref.frag"); - m_shaders[ES_OBJECTPASS_RIMLIT] = glsl_noinput(dir + "objectpass_rimlit.vert", dir + "objectpass_rimlit.frag"); + m_shaders[ES_OBJECTPASS] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); + m_shaders[ES_OBJECT_UNLIT] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); + m_shaders[ES_OBJECTPASS_REF] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); + m_shaders[ES_OBJECTPASS_RIMLIT] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_SUNLIGHT] = glsl_noinput(std::string(""), dir + "sunlight.frag"); From 8cd1e2e4919efdade87563c205dfdf9d0a1ec33c Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Tue, 18 Feb 2014 07:38:44 +1100 Subject: [PATCH 59/68] Renamed the node name in the player.xml file to better describe what it is, removed unused variable. --- src/challenges/story_mode_status.cpp | 5 ++--- src/challenges/story_mode_status.hpp | 8 +------- src/config/player_profile.cpp | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/challenges/story_mode_status.cpp b/src/challenges/story_mode_status.cpp index 8ee1c7e2a..fea933fdf 100644 --- a/src/challenges/story_mode_status.cpp +++ b/src/challenges/story_mode_status.cpp @@ -260,8 +260,7 @@ void StoryModeStatus::grandPrixFinished() */ void StoryModeStatus::save(UTFWriter &out) { - out << " <game-slot playerID=\"" << m_player_unique_id - << "\" first-time=\"" << m_first_time << L"\">\n"; + out << " <story-mode first-time=\"" << m_first_time << L"\">\n"; std::map<std::string, ChallengeStatus*>::const_iterator i; for(i = m_challenges_state.begin(); i != m_challenges_state.end(); i++) @@ -269,5 +268,5 @@ void StoryModeStatus::save(UTFWriter &out) if (i->second != NULL) i->second->save(out); } - out << " </game-slot>\n"; + out << " </story-mode>\n"; } // save diff --git a/src/challenges/story_mode_status.hpp b/src/challenges/story_mode_status.hpp index 93bc585c6..9f48bcc7a 100644 --- a/src/challenges/story_mode_status.hpp +++ b/src/challenges/story_mode_status.hpp @@ -37,17 +37,11 @@ const int CHALLENGE_POINTS[] = { 8, 9, 10 }; /** * \ingroup challenges - * This class contains the progression through challenges for one game slot + * This class contains the progression through challenges for the story mode. */ class StoryModeStatus { - /** Profile names can change, so rather than try to make sure all renames - * are done everywhere, assign a unique ID to each profiler. - * Will save much headaches. - */ - unsigned int m_player_unique_id; - /** Contains whether each feature of the challenge is locked or unlocked */ std::map<std::string, bool> m_locked_features; diff --git a/src/config/player_profile.cpp b/src/config/player_profile.cpp index 537acb956..42ef9443d 100644 --- a/src/config/player_profile.cpp +++ b/src/config/player_profile.cpp @@ -59,7 +59,7 @@ PlayerProfile::PlayerProfile(const XMLNode* node) #ifdef DEBUG m_magic_number = 0xABCD1234; #endif - const XMLNode *xml_game_slot = node->getNode("game-slot"); + const XMLNode *xml_game_slot = node->getNode("story-mode"); m_story_mode_status = unlock_manager->createStoryModeStatus(xml_game_slot); } // PlayerProfile From 23301d822adc3a3eceeee05c4094ae157853df29 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Tue, 18 Feb 2014 08:18:33 +1100 Subject: [PATCH 60/68] Experimentally adjust camera up vector depending on kart roll, which means the camera will now follow the gravity changes. --- src/graphics/camera.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index f58b43941..814f3371e 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -533,7 +533,10 @@ void Camera::positionCamera(float dt, float above_kart, float cam_angle, wanted_target - m_camera->getPosition()); } } - + + // Rotate the up vector (0,1,0) by the rotation ... which is just column 1 + Vec3 up = m_kart->getTrans().getBasis().getColumn(1); + m_camera->setUpVector(up.toIrrVector()); } // positionCamera // ---------------------------------------------------------------------------- From 073a049389604bff29e79938fcc75da563369d4a Mon Sep 17 00:00:00 2001 From: samuncle <samuncle06@gmail.com> Date: Mon, 17 Feb 2014 22:36:00 +0100 Subject: [PATCH 61/68] Correction of a syntax error --- data/shaders/sunlightshadow.frag | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/data/shaders/sunlightshadow.frag b/data/shaders/sunlightshadow.frag index 6789613d1..66c617afb 100644 --- a/data/shaders/sunlightshadow.frag +++ b/data/shaders/sunlightshadow.frag @@ -26,12 +26,14 @@ vec3 DecodeNormal(vec2 n) float getShadowFactor(vec3 pos, float bias, int index) { - const vec2 shadowoffset[] = { + //float a[5] = float[](3.4, 4.2, 5.0, 5.2, 1.1); + + const vec2 shadowoffset[4] = vec2[]( vec2(-1., -1.), vec2(-1., 1.), vec2(1., -1.), vec2(1., 1.) - }; + ); vec4 shadowcoord = (shadowmat[index] * vec4(pos, 1.0)); shadowcoord /= shadowcoord.w; From fb1c73718ae3f0c6d42a9147e4571761c46b9ec4 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Tue, 18 Feb 2014 08:51:03 +1100 Subject: [PATCH 62/68] Try to remove shaking of camera somewhat. --- src/graphics/camera.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 814f3371e..8e9c989d5 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -536,7 +536,9 @@ void Camera::positionCamera(float dt, float above_kart, float cam_angle, // Rotate the up vector (0,1,0) by the rotation ... which is just column 1 Vec3 up = m_kart->getTrans().getBasis().getColumn(1); - m_camera->setUpVector(up.toIrrVector()); + float f = 0.05f; // weight for new up vector to reduce shaking + m_camera->setUpVector( f * up.toIrrVector() + + (1.0f-f) * m_camera->getUpVector() ); } // positionCamera // ---------------------------------------------------------------------------- From e3f85ba41b86cdc9387a7b4021f5f9ce09c4cf21 Mon Sep 17 00:00:00 2001 From: samuncle <samuncle06@gmail.com> Date: Mon, 17 Feb 2014 23:47:07 +0100 Subject: [PATCH 63/68] Tweak the cam tilt --- src/graphics/camera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 8e9c989d5..57e128ca3 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -536,7 +536,7 @@ void Camera::positionCamera(float dt, float above_kart, float cam_angle, // Rotate the up vector (0,1,0) by the rotation ... which is just column 1 Vec3 up = m_kart->getTrans().getBasis().getColumn(1); - float f = 0.05f; // weight for new up vector to reduce shaking + float f = 0.04f; // weight for new up vector to reduce shaking m_camera->setUpVector( f * up.toIrrVector() + (1.0f-f) * m_camera->getUpVector() ); } // positionCamera From b0b9712fb92793fcb56da3eee8b902abe0fe365f Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@gmail.com> Date: Thu, 20 Feb 2014 08:44:57 +1100 Subject: [PATCH 64/68] Removed friend relation between StoryModeStatus and UnlockManager. --- src/challenges/story_mode_status.cpp | 11 +++++++++++ src/challenges/story_mode_status.hpp | 4 ++-- src/challenges/unlock_manager.cpp | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/challenges/story_mode_status.cpp b/src/challenges/story_mode_status.cpp index fea933fdf..3d2be3184 100644 --- a/src/challenges/story_mode_status.cpp +++ b/src/challenges/story_mode_status.cpp @@ -53,6 +53,17 @@ StoryModeStatus::~StoryModeStatus() delete it->second; } } // ~StoryModeStatus + +//----------------------------------------------------------------------------- +/** Adds a ChallengeStatus with the specified id to the set of all statuses + * of this object. + * \param cs The challenge status. + */ +void StoryModeStatus::addStatus(ChallengeStatus *cs) +{ + m_challenges_state[cs->getData()->getId()] = cs; +} // addStatus + //----------------------------------------------------------------------------- bool StoryModeStatus::isLocked(const std::string& feature) { diff --git a/src/challenges/story_mode_status.hpp b/src/challenges/story_mode_status.hpp index 9f48bcc7a..1a3fbc131 100644 --- a/src/challenges/story_mode_status.hpp +++ b/src/challenges/story_mode_status.hpp @@ -42,6 +42,7 @@ const int CHALLENGE_POINTS[] = { 8, 9, 10 }; class StoryModeStatus { +private: /** Contains whether each feature of the challenge is locked or unlocked */ std::map<std::string, bool> m_locked_features; @@ -55,8 +56,6 @@ class StoryModeStatus * if no challenge is active. */ const ChallengeStatus *m_current_challenge; - friend class UnlockManager; - int m_points; /** Set to false after the initial stuff (intro, select kart, etc.) */ @@ -79,6 +78,7 @@ public: void raceFinished (); void grandPrixFinished (); void save (UTFWriter &out); + void addStatus(ChallengeStatus *cs); void setCurrentChallenge(const std::string &challenge_id); // ------------------------------------------------------------------------ diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index 3182e2852..53755122b 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -207,7 +207,7 @@ StoryModeStatus* UnlockManager::createStoryModeStatus(const XMLNode *node) ChallengeStatus *challenge_status = new ChallengeStatus(cd); if(node) challenge_status->load(node); - status->m_challenges_state[cd->getId()] = challenge_status; + status->addStatus(challenge_status); } status->computeActive(); From 55665e21a36215c5c7ff622a4319a054f0266f26 Mon Sep 17 00:00:00 2001 From: hiker <henrichsjoerg@mgail.com> Date: Thu, 20 Feb 2014 08:55:35 +1100 Subject: [PATCH 65/68] Removed some compiler warnings. --- src/karts/kart.cpp | 4 ++-- src/states_screens/race_gui.cpp | 1 - src/states_screens/story_mode_lobby.cpp | 2 -- src/tracks/track.cpp | 4 ++-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 76483fa46..2edf614ff 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -2591,12 +2591,12 @@ btQuaternion Kart::getVisualRotation() const void Kart::setOnScreenText(const wchar_t *text) { core::dimension2d<u32> textsize = GUIEngine::getFont()->getDimension(text); - scene::ISceneManager* sm = irr_driver->getSceneManager(); // FIXME: Titlefont is the only font guaranteed to be loaded if STK // is started without splash screen (since "Loading" is shown even in this // case). A smaller font would be better // TODO: Add support in the engine for BillboardText or find a replacement - /*sm->addBillboardTextSceneNode(GUIEngine::getFont() ? GUIEngine::getFont() + /*scene::ISceneManager* sm = irr_driver->getSceneManager(); + sm->addBillboardTextSceneNode(GUIEngine::getFont() ? GUIEngine::getFont() : GUIEngine::getTitleFont(), text, getNode(), diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 460aa1b44..36d0ec87b 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -610,7 +610,6 @@ void RaceGUI::drawSpeedAndEnergy(const AbstractKart* kart, offset.X = (float)(viewport.LowerRightCorner.X-meter_width) - 24.0f*scaling.X; offset.Y = viewport.LowerRightCorner.Y-10.0f*scaling.Y; - video::IVideoDriver *video = irr_driver->getVideoDriver(); const core::rect<s32> meter_pos((int)offset.X, (int)(offset.Y-meter_height), (int)(offset.X+meter_width), diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index 131fe0644..a3ecedabb 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -109,8 +109,6 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, { ListWidget* list = getWidget<ListWidget>("gameslots"); - bool slot_found = false; - PlayerProfile *player = PlayerManager::get() ->getPlayer(list->getSelectionLabel()); if(player) diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index eca974607..4fa477b5c 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -966,12 +966,12 @@ bool Track::loadMainTrack(const XMLNode &root) core::stringw msg = StringUtils::toWString(val); core::dimension2d<u32> textsize = GUIEngine::getHighresDigitFont() ->getDimension(msg.c_str()); - scene::ISceneManager* sm = irr_driver->getSceneManager(); assert(GUIEngine::getHighresDigitFont() != NULL); // TODO: Add support in the engine for BillboardText or find a replacement -/* scene::ISceneNode* sn = +/* scene::ISceneManager* sm = irr_driver->getSceneManager(); + scene::ISceneNode* sn = sm->addBillboardTextSceneNode(GUIEngine::getHighresDigitFont(), msg.c_str(), NULL, From 40c4155bd2b56eadb442589eaa727d4a782a2436 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Thu, 20 Feb 2014 00:01:02 +0100 Subject: [PATCH 66/68] STKMesh: Support for (non ref) moving texture --- data/shaders/movingtexture.frag | 22 ++++++++++++ data/shaders/movingtexture.vert | 16 +++++++++ src/graphics/shaders.cpp | 41 ++++++++++++++++++++++ src/graphics/shaders.hpp | 11 ++++++ src/graphics/stkanimatedmesh.cpp | 2 +- src/graphics/stkmesh.cpp | 60 +++++++++++++++++++++++++++----- src/graphics/stkmesh.hpp | 6 ++-- 7 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 data/shaders/movingtexture.frag create mode 100644 data/shaders/movingtexture.vert diff --git a/data/shaders/movingtexture.frag b/data/shaders/movingtexture.frag new file mode 100644 index 000000000..7d4d81c27 --- /dev/null +++ b/data/shaders/movingtexture.frag @@ -0,0 +1,22 @@ +#version 330 +uniform sampler2D Albedo; +uniform sampler2D DiffuseMap; +uniform sampler2D SpecularMap; +uniform sampler2D SSAO; +uniform vec2 screen; +uniform vec3 ambient; + +in vec2 uv; +out vec4 FragColor; + +void main(void) +{ + vec2 tc = gl_FragCoord.xy / screen; + vec4 color = texture(Albedo, uv); + vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz; + vec3 SpecularComponent = texture(SpecularMap, tc).xyz; + float ao = texture(SSAO, tc).x; + vec3 LightFactor = ao * ambient + DiffuseComponent + SpecularComponent * (1. - color.a); + FragColor = vec4(color.xyz * LightFactor * (0.4 + ao*0.6), 1.); + //FragColor = vec4(color.xyz * LightFactor, 1.); +} diff --git a/data/shaders/movingtexture.vert b/data/shaders/movingtexture.vert new file mode 100644 index 000000000..87f40d795 --- /dev/null +++ b/data/shaders/movingtexture.vert @@ -0,0 +1,16 @@ +#version 330 +uniform mat4 ModelViewProjectionMatrix; +uniform mat4 TextureMatrix; + +in vec3 Position; +in vec2 Texcoord; +in vec2 SecondTexcoord; +out vec2 uv; +out vec2 uv_bis; + +void main(void) +{ + uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; + uv_bis = SecondTexcoord; + gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); +} diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 7e3c041a8..ecdc57902 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -243,6 +243,7 @@ void Shaders::loadShaders() MeshShader::ObjectPass1Shader::init(); MeshShader::ObjectRefPass1Shader::init(); MeshShader::ObjectPass2Shader::init(); + MeshShader::MovingTextureShader::init(); MeshShader::DetailledObjectPass2Shader::init(); MeshShader::ObjectRimLimitShader::init(); MeshShader::UntexturedObjectShader::init(); @@ -381,6 +382,46 @@ namespace MeshShader glUniform3f(uniform_ambient, s.r, s.g, s.b); } + GLuint MovingTextureShader::Program; + GLuint MovingTextureShader::attrib_position; + GLuint MovingTextureShader::attrib_texcoord; + GLuint MovingTextureShader::uniform_MVP; + GLuint MovingTextureShader::uniform_TM; + GLuint MovingTextureShader::uniform_Albedo; + GLuint MovingTextureShader::uniform_DiffuseMap; + GLuint MovingTextureShader::uniform_SpecularMap; + GLuint MovingTextureShader::uniform_SSAO; + GLuint MovingTextureShader::uniform_screen; + GLuint MovingTextureShader::uniform_ambient; + + void MovingTextureShader::init() + { + Program = LoadProgram(file_manager->getAsset("shaders/movingtexture.vert").c_str(), file_manager->getAsset("shaders/movingtexture.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); + uniform_Albedo = glGetUniformLocation(Program, "Albedo"); + uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); + uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); + uniform_SSAO = glGetUniformLocation(Program, "SSAO"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + } + + void MovingTextureShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); + glUniform1i(uniform_Albedo, TU_Albedo); + glUniform1i(uniform_DiffuseMap, TU_DiffuseMap); + glUniform1i(uniform_SpecularMap, TU_SpecularMap); + glUniform1i(uniform_SSAO, TU_SSAO); + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } + GLuint DetailledObjectPass2Shader::Program; GLuint DetailledObjectPass2Shader::attrib_position; GLuint DetailledObjectPass2Shader::attrib_texcoord; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index c888e1f7d..a7c627e89 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -59,6 +59,17 @@ public: static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO); }; +class MovingTextureShader +{ +public: + static GLuint Program; + static GLuint attrib_position, attrib_texcoord; + static GLuint uniform_MVP, uniform_TM, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient; + + static void init(); + static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO); +}; + class DetailledObjectPass2Shader { public: diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index c7b6641c2..f24b16c9a 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -159,7 +159,7 @@ void STKAnimatedMesh::render() if (isObjectPass(material.MaterialType)) { irr_driver->IncreaseObjectCount(); - initvaostate(GLmeshes[i], material.MaterialType); + initvaostate(GLmeshes[i], material.MaterialType, false); if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS) { glBindVertexArray(0); diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index c9e78d663..b6e5bbff6 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -611,6 +611,42 @@ void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectio glDrawElements(ptype, count, itype, 0); } +void drawMovingTexture(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix) +{ + GLenum ptype = mesh.PrimitiveType; + GLenum itype = mesh.IndexType; + size_t count = mesh.IndexCount; + + setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + if (irr_driver->getLightViz()) + { + GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } + else + { + GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } + + setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST); + setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST); + setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST); + if (!UserConfigParams::m_ssao) + { + GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } + const float *tmp = TextureMatrix.pointer(); + printf("TMat : \n %f %f %f %f\n %f %f %f %f\n %f %f %f %f\n %f %f %f %f\n", tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7], tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14], tmp[15]); + + glUseProgram(MeshShader::MovingTextureShader::Program); + MeshShader::MovingTextureShader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, 0, 1, 2, 3); + + glBindVertexArray(mesh.vao_second_pass); + glDrawElements(ptype, count, itype, 0); +} + void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix) { GLenum ptype = mesh.PrimitiveType; @@ -793,8 +829,10 @@ void STKMesh::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type) drawObjectUnlit(mesh, ModelViewProjectionMatrix); else if (mesh.textures[1] && type != irr_driver->getShader(ES_NORMAL_MAP)) drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix); - else if (!mesh.textures[0]) - drawUntexturedObject(mesh, ModelViewProjectionMatrix); + else if (!mesh.textures[0]) + drawUntexturedObject(mesh, ModelViewProjectionMatrix); + else if (!TextureMatrix.isIdentity()) + drawMovingTexture(mesh, ModelViewProjectionMatrix, TextureMatrix); else drawObjectPass2(mesh, ModelViewProjectionMatrix); break; @@ -837,7 +875,7 @@ static bool isObject(video::E_MATERIAL_TYPE type) return false; } -void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type) +void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type, bool MovingTexture) { switch (irr_driver->getPhase()) { @@ -908,6 +946,11 @@ void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type) mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::UntexturedObjectShader::attrib_position, -1, -1, -1, -1, -1, MeshShader::UntexturedObjectShader::attrib_color, mesh.Stride); } + else if (MovingTexture) + { + mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, + MeshShader::MovingTextureShader::attrib_position, MeshShader::MovingTextureShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride); + } else { mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, @@ -982,7 +1025,8 @@ void STKMesh::render() scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i); if (mb) { - const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i]; + TextureMatrix = getMaterial(i).getTextureMatrix(0); + const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i]; video::IMaterialRenderer* rnd = driver->getMaterialRenderer(material.MaterialType); bool transparent = (rnd && rnd->isTransparent()); @@ -991,7 +1035,7 @@ void STKMesh::render() continue; if (irr_driver->getPhase() == DISPLACEMENT_PASS) { - initvaostate(GLmeshes[i], material.MaterialType); + initvaostate(GLmeshes[i], material.MaterialType, false); drawDisplace(GLmeshes[i]); continue; } @@ -1007,18 +1051,18 @@ void STKMesh::render() // and solid only in solid pass if (irr_driver->getPhase() == GLOW_PASS) { - initvaostate(GLmeshes[i], material.MaterialType); + initvaostate(GLmeshes[i], material.MaterialType, TextureMatrix.isIdentity()); drawGlow(GLmeshes[i]); } else if (irr_driver->getPhase() == SHADOW_PASS) { - initvaostate(GLmeshes[i], material.MaterialType); + initvaostate(GLmeshes[i], material.MaterialType, TextureMatrix.isIdentity()); drawShadow(GLmeshes[i], material.MaterialType); } else { irr_driver->IncreaseObjectCount(); - initvaostate(GLmeshes[i], material.MaterialType); + initvaostate(GLmeshes[i], material.MaterialType, TextureMatrix.isIdentity()); if (transparent) drawTransparent(GLmeshes[i], material.MaterialType); else diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 74cde2358..2b251a0a2 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -25,7 +25,7 @@ struct GLMesh { GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_texcoord, GLuint attrib_second_texcoord, GLuint attrib_normal, GLuint attrib_tangent, GLuint attrib_bitangent, GLuint attrib_color, size_t stride); GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb); -void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type); +void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type, bool moving_texture); void computeMVP(core::matrix4 &ModelViewProjectionMatrix); void computeTIMV(core::matrix4 &TransposeInverseModelView); @@ -38,6 +38,7 @@ void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio // Pass 2 shader (ie shaders that outputs final color) void drawDetailledObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); +void drawMovingTexture(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix); void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView); @@ -55,7 +56,7 @@ class STKMesh : public irr::scene::CMeshSceneNode { protected: std::vector<GLMesh> GLmeshes; - core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView; + core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix; core::vector3df windDir; void drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type); void drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type); @@ -73,6 +74,7 @@ public: const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f)); virtual void render(); virtual void setMesh(irr::scene::IMesh* mesh); + void MovingTexture(unsigned, unsigned); ~STKMesh(); }; From 8ba0fcb8e0245ae3630a00ba306094c078f900d7 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Thu, 20 Feb 2014 18:31:00 +0100 Subject: [PATCH 67/68] STKMesh: Transparent texture can move now. --- data/shaders/transparent.vert | 3 ++- src/graphics/shaders.cpp | 12 +++++++++--- src/graphics/shaders.hpp | 12 ++++++------ src/graphics/stkanimatedmesh.cpp | 4 ++-- src/graphics/stkmesh.cpp | 14 ++++++-------- src/graphics/stkmesh.hpp | 4 ++-- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/data/shaders/transparent.vert b/data/shaders/transparent.vert index b6ac8f61a..b5451f0a5 100644 --- a/data/shaders/transparent.vert +++ b/data/shaders/transparent.vert @@ -1,5 +1,6 @@ #version 330 uniform mat4 ModelViewProjectionMatrix; +uniform mat4 TextureMatrix; in vec3 Position; in vec2 Texcoord; @@ -7,6 +8,6 @@ out vec2 uv; void main() { - uv = Texcoord; + uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index ecdc57902..7dbff13ef 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -794,7 +794,7 @@ namespace MeshShader uniform_time = glGetUniformLocation(Program, "time"); uniform_transparency = glGetUniformLocation(Program, "transparency"); } - void BubbleShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex, float time, float transparency) + void BubbleShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex, float time, float transparency) { glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); glUniform1i(uniform_tex, TU_tex); @@ -806,6 +806,7 @@ namespace MeshShader GLuint TransparentShader::attrib_position; GLuint TransparentShader::attrib_texcoord; GLuint TransparentShader::uniform_MVP; + GLuint TransparentShader::uniform_TM; GLuint TransparentShader::uniform_tex; void TransparentShader::init() @@ -814,12 +815,14 @@ namespace MeshShader attrib_position = glGetAttribLocation(Program, "Position"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); } - void TransparentShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex) + void TransparentShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex) { glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); glUniform1i(uniform_tex, TU_tex); } @@ -827,6 +830,7 @@ namespace MeshShader GLuint TransparentFogShader::attrib_position; GLuint TransparentFogShader::attrib_texcoord; GLuint TransparentFogShader::uniform_MVP; + GLuint TransparentFogShader::uniform_TM; GLuint TransparentFogShader::uniform_tex; GLuint TransparentFogShader::uniform_fogmax; GLuint TransparentFogShader::uniform_startH; @@ -843,6 +847,7 @@ namespace MeshShader attrib_position = glGetAttribLocation(Program, "Position"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); uniform_fogmax = glGetUniformLocation(Program, "fogmax"); uniform_startH = glGetUniformLocation(Program, "startH"); @@ -854,9 +859,10 @@ namespace MeshShader uniform_ipvmat = glGetUniformLocation(Program, "ipvmat"); } - void TransparentFogShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex) + void TransparentFogShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex) { glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); glUniform1f(uniform_fogmax, fogmax); glUniform1f(uniform_startH, startH); glUniform1f(uniform_endH, endH); diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index a7c627e89..320dd8c26 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -185,10 +185,10 @@ class BubbleShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord; - static GLuint uniform_MVP, uniform_tex, uniform_time, uniform_transparency; + static GLuint uniform_MVP, uniform_tex, uniform_time, uniform_transparency; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex, float time, float transparency); + static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex, float time, float transparency); }; class TransparentShader @@ -196,10 +196,10 @@ class TransparentShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord; - static GLuint uniform_MVP, uniform_tex; + static GLuint uniform_MVP, uniform_TM, uniform_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex); + static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex); }; class TransparentFogShader @@ -207,10 +207,10 @@ class TransparentFogShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord; - static GLuint uniform_MVP, uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col, uniform_screen, uniform_ipvmat; + static GLuint uniform_MVP, uniform_TM, uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col, uniform_screen, uniform_ipvmat; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex); + static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex); }; class BillboardShader diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index f24b16c9a..3173ceaa5 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -33,9 +33,9 @@ void STKAnimatedMesh::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE computeMVP(ModelViewProjectionMatrix); if (World::getWorld()->getTrack()->isFogEnabled()) - drawTransparentFogObject(mesh, ModelViewProjectionMatrix); + drawTransparentFogObject(mesh, ModelViewProjectionMatrix, core::matrix4::EM4CONST_IDENTITY); else - drawTransparentObject(mesh, ModelViewProjectionMatrix); + drawTransparentObject(mesh, ModelViewProjectionMatrix, core::matrix4::EM4CONST_IDENTITY); return; } diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index b6e5bbff6..a1993026e 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -637,8 +637,6 @@ void drawMovingTexture(const GLMesh &mesh, const core::matrix4 &ModelViewProject GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } - const float *tmp = TextureMatrix.pointer(); - printf("TMat : \n %f %f %f %f\n %f %f %f %f\n %f %f %f %f\n %f %f %f %f\n", tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7], tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14], tmp[15]); glUseProgram(MeshShader::MovingTextureShader::Program); MeshShader::MovingTextureShader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, 0, 1, 2, 3); @@ -647,7 +645,7 @@ void drawMovingTexture(const GLMesh &mesh, const core::matrix4 &ModelViewProject glDrawElements(ptype, count, itype, 0); } -void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix) +void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix) { GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; @@ -656,13 +654,13 @@ void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewPro setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); glUseProgram(MeshShader::TransparentShader::Program); - MeshShader::TransparentShader::setUniforms(ModelViewProjectionMatrix, 0); + MeshShader::TransparentShader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, 0); glBindVertexArray(mesh.vao_first_pass); glDrawElements(ptype, count, itype, 0); } -void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix) +void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix) { GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; @@ -685,7 +683,7 @@ void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelView setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); glUseProgram(MeshShader::TransparentFogShader::Program); - MeshShader::TransparentFogShader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvProjMatrix(), fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition(), 0); + MeshShader::TransparentFogShader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, irr_driver->getInvProjMatrix(), fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition(), 0); glBindVertexArray(mesh.vao_first_pass); glDrawElements(ptype, count, itype, 0); @@ -753,9 +751,9 @@ void STKMesh::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type) if (type == irr_driver->getShader(ES_BUBBLES)) drawBubble(mesh, ModelViewProjectionMatrix); else if (World::getWorld()->getTrack()->isFogEnabled()) - drawTransparentFogObject(mesh, ModelViewProjectionMatrix); + drawTransparentFogObject(mesh, ModelViewProjectionMatrix, TextureMatrix); else - drawTransparentObject(mesh, ModelViewProjectionMatrix); + drawTransparentObject(mesh, ModelViewProjectionMatrix, TextureMatrix); return; } diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 2b251a0a2..ab619a360 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -48,8 +48,8 @@ void drawObjectRimLimit(const GLMesh &mesh, const core::matrix4 &ModelViewProjec void drawObjectUnlit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); // Forward pass (for transparents meshes) -void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); -void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); +void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix); +void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix); void drawBubble(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); class STKMesh : public irr::scene::CMeshSceneNode From 1325fa7940a8a5dac12a82422c0c03ed5bc97213 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune <vljn@ovi.com> Date: Thu, 20 Feb 2014 18:43:51 +0100 Subject: [PATCH 68/68] Fix UI clipping. --- src/graphics/glwrap.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index cb539f66b..466594ec0 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -424,12 +424,24 @@ void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect { glDisable(GL_BLEND); } + if (clipRect) + { + if (!clipRect->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + const core::dimension2d<u32>& renderTargetSize = irr_driver->getVideoDriver()->getCurrentRenderTargetSize(); + glScissor(clipRect->UpperLeftCorner.X, renderTargetSize.Height - clipRect->LowerRightCorner.Y, + clipRect->getWidth(), clipRect->getHeight()); + } if (colors) drawTexColoredQuad(texture, colors, width, height, center_pos_x, center_pos_y, tex_center_pos_x, tex_center_pos_y, tex_width, tex_height); else drawTexQuad(texture, width, height, center_pos_x, center_pos_y, tex_center_pos_x, tex_center_pos_y, tex_width, tex_height); + if (clipRect) + glDisable(GL_SCISSOR_TEST); glUseProgram(0); } @@ -468,6 +480,17 @@ void GL32_draw2DRectangle(video::SColor color, const core::rect<s32>& position, glDisable(GL_BLEND); } + if (clip) + { + if (!clip->isValid()) + return; + + glEnable(GL_SCISSOR_TEST); + const core::dimension2d<u32>& renderTargetSize = irr_driver->getVideoDriver()->getCurrentRenderTargetSize(); + glScissor(clip->UpperLeftCorner.X, renderTargetSize.Height - clip->LowerRightCorner.Y, + clip->getWidth(), clip->getHeight()); + } + glUseProgram(UIShader::ColoredRectShader::Program); glBindVertexArray(UIShader::ColoredRectShader::vao); UIShader::ColoredRectShader::setUniforms(center_pos_x, center_pos_y, width, height, color); @@ -475,5 +498,7 @@ void GL32_draw2DRectangle(video::SColor color, const core::rect<s32>& position, glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); + if (clip) + glDisable(GL_SCISSOR_TEST); glUseProgram(0); }