This commit is contained in:
deve
2014-09-25 11:56:28 +02:00
14 changed files with 146 additions and 78 deletions

View File

@@ -57,28 +57,31 @@ NewsManager::~NewsManager()
*/
void NewsManager::init(bool force_refresh)
{
// The rest (which potentially involves downloading news.xml) is handled
// in a separate thread, so that the GUI remains responsive.
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
// Should be the default, but just in case:
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
//pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
m_force_refresh = force_refresh;
pthread_t thread_id;
int error = pthread_create(&thread_id, &attr,
&NewsManager::downloadNews, this);
if(error)
// The rest (which potentially involves downloading news.xml) is handled
// in a separate thread, so that the GUI remains responsive. It is only
// started if internet access is enabled, else nothing is done in the
// thread anyway (and the addons menu is disabled as a result).
if(UserConfigParams::m_internet_status==RequestManager::IPERM_ALLOWED)
{
Log::warn("news", "Could not create thread, error=%d", error);
// In this case just execute the downloading code with this thread
downloadNews(this);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
// Should be the default, but just in case:
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
//pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
pthread_t thread_id;
int error = pthread_create(&thread_id, &attr,
&NewsManager::downloadNews, this);
if (error)
{
Log::warn("news", "Could not create thread, error=%d", error);
// In this case just execute the downloading code with this thread
downloadNews(this);
}
pthread_attr_destroy(&attr);
}
pthread_attr_destroy(&attr);
} //init
@@ -232,6 +235,16 @@ void NewsManager::checkRedirect(const XMLNode *xml)
UserConfigParams::m_server_hw_report = hw_report_server;
}
float polling;
if(xml->get("menu-polling-interval", &polling))
{
RequestManager::get()->setMenuPollingInterval(polling);
}
if(xml->get("game-polling-interval", &polling))
{
RequestManager::get()->setGamePollingInterval(polling);
}
} // checkRedirect
// ----------------------------------------------------------------------------

View File

@@ -178,11 +178,9 @@ void reportHardwareStats()
if(nr_procs>0)
json.add("cpu_numprocs", nr_procs);
// Too long for debugging atm
//json.add("GL_EXTENSIONS", getGLExtensions());
json.add("GL_EXTENSIONS", getGLExtensions());
getGLLimits(&json);
json.finish();
Log::verbose("json", "'%s'", json.toString().c_str());
// ------------------------------------------------------------------------
/** A small class which sends the HW report to the STK server. On
@@ -235,8 +233,7 @@ void reportHardwareStats()
request->addParameter("data", json.toString());
request->setURL((std::string)UserConfigParams::m_server_hw_report+"/upload/v1/");
//request->setURL("http://127.0.0.1:8000/upload/v1/");
// FIXME: For now: don't submit
//request->queue();
request->queue();
} // reportHardwareStats

View File

@@ -693,7 +693,7 @@ namespace UserConfigParams
"A random number to avoid duplicated reports.") );
PARAM_PREFIX StringUserConfigParam m_server_hw_report
PARAM_DEFAULT( StringUserConfigParam( "http://stats.supertuxkart.net",
PARAM_DEFAULT( StringUserConfigParam( "http://104.131.193.44:8080",
"hw-report-server",
&m_hw_report_group,
"The server used for reporting statistics to."));

View File

@@ -145,6 +145,8 @@ GLuint LoadShader(const char * file, unsigned type)
char versionString[20];
sprintf(versionString, "#version %d\n", irr_driver->getGLSLVersion());
std::string Code = versionString;
if (irr_driver->hasVSLayerExtension())
Code += "#extension GL_AMD_vertex_shader_layer : enable\n";
if (UserConfigParams::m_azdo)
Code += "#extension GL_ARB_bindless_texture : enable\n";
else

View File

@@ -351,20 +351,22 @@ void IrrDriver::initDevice()
core::dimension2d<u32> res = core::dimension2du(UserConfigParams::m_width,
UserConfigParams::m_height);
if (modes->getVideoModeCount() > 0)
if (UserConfigParams::m_fullscreen)
{
res = modes->getVideoModeResolution(res, res);
UserConfigParams::m_width = res.Width;
UserConfigParams::m_height = res.Height;
}
else
{
Log::verbose("irr_driver", "Cannot get information about "
"resolutions. Try to use the default one.");
UserConfigParams::m_width = MIN_SUPPORTED_WIDTH;
UserConfigParams::m_height = MIN_SUPPORTED_HEIGHT;
if (modes->getVideoModeCount() > 0)
{
res = modes->getVideoModeResolution(res, res);
UserConfigParams::m_width = res.Width;
UserConfigParams::m_height = res.Height;
}
else
{
Log::verbose("irr_driver", "Cannot get information about "
"resolutions. Try to use the default one.");
UserConfigParams::m_width = MIN_SUPPORTED_WIDTH;
UserConfigParams::m_height = MIN_SUPPORTED_HEIGHT;
}
}
m_device->closeDevice();

View File

@@ -301,7 +301,10 @@ static void
SetTexture(GLMesh &mesh, unsigned i, bool isSrgb)
{
if (!mesh.textures[i])
Log::fatal("STKMesh", "Missing texture");
{
Log::warn("STKMesh", "Missing texture");
return;
}
compressTexture(mesh.textures[i], isSrgb);
if (UserConfigParams::m_azdo)
{

View File

@@ -813,7 +813,8 @@ void FileManager::checkAndCreateConfigDir()
if(m_user_config_dir.size()>0 && *m_user_config_dir.rbegin()!='/')
m_user_config_dir += "/";
if(!checkAndCreateDirectory(m_user_config_dir))
m_user_config_dir +="0.8.2/";
if(!checkAndCreateDirectoryP(m_user_config_dir))
{
Log::warn("FileManager", "Can not create config dir '%s', "
"falling back to '.'.", m_user_config_dir.c_str());
@@ -830,7 +831,7 @@ void FileManager::checkAndCreateConfigDir()
void FileManager::checkAndCreateAddonsDir()
{
#if defined(WIN32) || defined(__CYGWIN__)
m_addons_dir = m_user_config_dir+"addons/";
m_addons_dir = m_user_config_dir+"../addons/";
#elif defined(__APPLE__)
m_addons_dir = getenv("HOME");
m_addons_dir += "/Library/Application Support/SuperTuxKart/Addons/";

View File

@@ -1127,8 +1127,17 @@ void askForInternetPermission()
public:
virtual void onConfirm()
{
// Typically internet is disabled here (just better safe
// than sorry). If internet should be allowed, the news
// manager needs to be started (which in turn activates
// the addons manager).
bool need_to_start_news_manager =
UserConfigParams::m_internet_status!=
Online::RequestManager::IPERM_ALLOWED;
UserConfigParams::m_internet_status =
Online::RequestManager::IPERM_ALLOWED;
if(need_to_start_news_manager)
NewsManager::get()->init(false);
GUIEngine::ModalDialog::dismiss();
} // onConfirm
// --------------------------------------------------------

View File

@@ -79,7 +79,9 @@ void NetworkManager::reset()
void NetworkManager::abort()
{
m_localhost->stopListening();
reset();
// FIXME: Why a reset here? This creates a new stk_host, which will open
// a new packet_log file (and therefore delete the previous file)???
// reset();
ProtocolManager::getInstance()->abort();
}

View File

@@ -19,6 +19,7 @@
#include "network/stk_host.hpp"
#include "config/user_config.hpp"
#include "io/file_manager.hpp"
#include "network/network_manager.hpp"
#include "utils/log.hpp"
#include "utils/time.hpp"
@@ -90,13 +91,17 @@ void* STKHost::receive_data(void* self)
STKHost::STKHost()
{
m_host = NULL;
m_host = NULL;
m_listening_thread = NULL;
m_log_file = NULL;
m_log_file = NULL;
pthread_mutex_init(&m_exit_mutex, NULL);
pthread_mutex_init(&m_log_mutex, NULL);
if (UserConfigParams::m_packets_log_filename.toString() != "")
m_log_file = fopen(UserConfigParams::m_packets_log_filename.c_str(), "w+");
{
std::string s =
file_manager->getUserConfigFile(UserConfigParams::m_packets_log_filename);
m_log_file = fopen(s.c_str(), "w+");
}
if (!m_log_file)
Log::warn("STKHost", "Network packets won't be logged: no file.");
}

View File

@@ -324,6 +324,11 @@ namespace Online
if (!PlayerManager::getCurrentPlayer()->isLoggedIn())
return;
float f;
if(getXMLData()->get("menu-polling-interval", &f))
RequestManager::get()->setMenuPollingInterval(f);
if(getXMLData()->get("game-polling-interval", &f))
RequestManager::get()->setGamePollingInterval(f);
if (PlayerManager::getCurrentPlayer()->getProfile()->hasFetchedFriends())
{

View File

@@ -40,30 +40,17 @@ using namespace Online;
namespace Online
{
#define MENU_POLLING_INTERVAL 10.0f
#define GAME_POLLING_INTERVAL 15.0f
static RequestManager * http_singleton = NULL;
// ------------------------------------------------------------------------
RequestManager* RequestManager::get()
{
if (http_singleton == NULL)
{
http_singleton = new RequestManager();
}
return http_singleton;
} // get
RequestManager * RequestManager::m_request_manager = NULL;
// ------------------------------------------------------------------------
/** Deletes the http manager.
*/
void RequestManager::deallocate()
{
if (http_singleton != NULL)
if (m_request_manager!= NULL)
{
delete http_singleton;
http_singleton = NULL;
delete m_request_manager;
m_request_manager = NULL;
}
} // deallocate
@@ -72,17 +59,20 @@ namespace Online
*/
bool RequestManager::isRunning()
{
return http_singleton != NULL;
return m_request_manager != NULL;
} // isRunning
// ------------------------------------------------------------------------
/** Constructor. It only initialised values, it does not start the actual
* thread.
*/
RequestManager::RequestManager()
{
m_menu_polling_interval = 60; // Default polling: every 60 seconds.
m_game_polling_interval = 60; // same for game polling
m_time_since_poll = m_menu_polling_interval;
curl_global_init(CURL_GLOBAL_DEFAULT);
pthread_cond_init(&m_cond_request, NULL);
m_abort.setAtomic(false);
m_time_since_poll = MENU_POLLING_INTERVAL * 0.9;
} // RequestManager
// ------------------------------------------------------------------------
@@ -305,9 +295,9 @@ namespace Online
return;
m_time_since_poll += dt;
float interval = GAME_POLLING_INTERVAL;
float interval = m_game_polling_interval;
if (StateManager::get()->getGameState() == GUIEngine::MENU)
interval = MENU_POLLING_INTERVAL;
interval = m_menu_polling_interval;
if (m_time_since_poll > interval)
{

View File

@@ -90,7 +90,7 @@ namespace Online
IPERM_ALLOWED = 1,
IPERM_NOT_ALLOWED = 2
};
protected:
private:
/** Time passed since the last poll request. */
float m_time_since_poll;
@@ -103,10 +103,17 @@ namespace Online
/** Signal an abort in case that a download is still happening. */
Synchronised<bool> m_abort;
/** The polling interval while a game is running. */
float m_game_polling_interval;
/** The polling interval while the menu is shown. */
float m_menu_polling_interval;
/** Thread id of the thread running in this object. */
Synchronised<pthread_t *> m_thread_id;
/** The list of pointers to all requests that still need to be handled. */
/** The list of pointers to all requests that still need to be
* handled. */
Synchronised< std::priority_queue <
Online::Request*,
std::vector<Online::Request*>,
@@ -114,7 +121,9 @@ namespace Online
>
> m_request_queue;
/** The list of pointers to all requests that are already executed by the networking thread, but still need to be processed by the main thread. */
/** The list of pointers to all requests that are already executed
* by the networking thread, but still need to be processed by the
* main thread. */
Synchronised< std::queue<Online::Request*> > m_result_queue;
void addResult(Online::Request *request);
@@ -124,12 +133,25 @@ namespace Online
RequestManager(); //const std::string &url
~RequestManager();
static RequestManager * m_request_manager;
public:
static const int HTTP_MAX_PRIORITY = 9999;
// singleton
static RequestManager* get();
// ----------------------------------------------------------------
/** Singleton access function. Creates the RequestManager if
* necessary. */
static RequestManager* get()
{
if (m_request_manager == NULL)
{
m_request_manager = new RequestManager();
}
return m_request_manager;
} // get
// ----------------------------------------------------------------
static void deallocate();
static bool isRunning();
@@ -140,6 +162,23 @@ namespace Online
bool getAbort(){ return m_abort.getAtomic(); }
void update(float dt);
// ----------------------------------------------------------------
/** Sets the interval with which poll requests are send to the
* server. This can happen from the news manager (i.e. info
* contained in the news.xml file), or a poll request. */
void setMenuPollingInterval(float polling_interval)
{
m_menu_polling_interval = polling_interval;
} // setPollingInterval
// ----------------------------------------------------------------
/** Sets the interval with which poll requests are send to the
* server. This can happen from the news manager (i.e. info
* contained in the news.xml file), or a poll request. */
void setGamePollingInterval(float polling_interval)
{
m_game_polling_interval = polling_interval;
} // setPollingInterval
}; //class RequestManager
} // namespace Online
#endif // request_manager_HPP

View File

@@ -439,31 +439,31 @@ bool onEvent(const SEvent &event)
{
#if !defined(__APPLE__)
DebugSliderDialog *dsd = new DebugSliderDialog();
dsd->setSliderHook( "red_slider", 0, 255, [](){ return irr_driver->getAmbientLight().r * 255.f; },
dsd->setSliderHook( "red_slider", 0, 255, [](){ return int(irr_driver->getAmbientLight().r * 255.f); },
[](int v){
video::SColorf ambient = irr_driver->getAmbientLight();
ambient.setColorComponentValue(0, v / 255.f);
irr_driver->setAmbientLight(ambient); }
);
dsd->setSliderHook("green_slider", 0, 255, [](){ return irr_driver->getAmbientLight().g * 255.f; },
dsd->setSliderHook("green_slider", 0, 255, [](){ return int(irr_driver->getAmbientLight().g * 255.f); },
[](int v){
video::SColorf ambient = irr_driver->getAmbientLight();
ambient.setColorComponentValue(1, v / 255.f);
irr_driver->setAmbientLight(ambient); }
);
dsd->setSliderHook("blue_slider", 0, 255, [](){ return irr_driver->getAmbientLight().b * 255.f; },
dsd->setSliderHook("blue_slider", 0, 255, [](){ return int(irr_driver->getAmbientLight().b * 255.f); },
[](int v){
video::SColorf ambient = irr_driver->getAmbientLight();
ambient.setColorComponentValue(2, v / 255.f);
irr_driver->setAmbientLight(ambient); }
);
dsd->setSliderHook("ssao_radius", 0, 100, [](){ return irr_driver->getSSAORadius() * 10.f; },
dsd->setSliderHook("ssao_radius", 0, 100, [](){ return int(irr_driver->getSSAORadius() * 10.f); },
[](int v){irr_driver->setSSAORadius(v / 10.f); }
);
dsd->setSliderHook("ssao_k", 0, 100, [](){ return irr_driver->getSSAOK() * 10.f; },
dsd->setSliderHook("ssao_k", 0, 100, [](){ return int(irr_driver->getSSAOK() * 10.f); },
[](int v){irr_driver->setSSAOK(v / 10.f); }
);
dsd->setSliderHook("ssao_sigma", 0, 100, [](){ return irr_driver->getSSAOSigma() * 10.f; },
dsd->setSliderHook("ssao_sigma", 0, 100, [](){ return int(irr_driver->getSSAOSigma() * 10.f); },
[](int v){irr_driver->setSSAOSigma(v / 10.f); }
);
#endif