Quite the mess I'm committing, but it's kind of a back up for the massive refactoring I'm about to do now. It will be great! (hope so)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13502 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
70bb8df317
commit
17b9479fce
@ -31,6 +31,7 @@
|
||||
#include "modes/world.hpp"
|
||||
#include "network/protocol_manager.hpp"
|
||||
#include "network/network_world.hpp"
|
||||
#include "online/database_polling.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/profiler.hpp"
|
||||
@ -153,6 +154,10 @@ void MainLoop::run()
|
||||
ProtocolManager::getInstance()->update();
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
||||
PROFILER_PUSH_CPU_MARKER("Database polling update", 0x00, 0x7F, 0x7F);
|
||||
DatabasePolling::getInstance()->update();
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
||||
PROFILER_SYNC_FRAME();
|
||||
}
|
||||
else if (!m_abort && ProfileWorld::isNoGraphics())
|
||||
|
99
src/online/database_polling.cpp
Normal file
99
src/online/database_polling.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Glenn De Jonghe
|
||||
//
|
||||
// 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 "online/database_polling.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <irrString.h>
|
||||
#include <assert.h>
|
||||
#include "utils/translation.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
|
||||
#define MENU_POLLING_INTERVAL 5.0f
|
||||
#define RACE_POLLING_INTERVAL 10.0f
|
||||
|
||||
namespace Online{
|
||||
|
||||
static DatabasePolling * database_polling_singleton(NULL);
|
||||
|
||||
DatabasePolling* DatabasePolling::get()
|
||||
{
|
||||
if (database_polling_singleton == NULL)
|
||||
database_polling_singleton = new DatabasePolling();
|
||||
return database_polling_singleton;
|
||||
}
|
||||
|
||||
void DatabasePolling::deallocate()
|
||||
{
|
||||
delete database_polling_singleton;
|
||||
database_polling_singleton = NULL;
|
||||
} // deallocate
|
||||
|
||||
// ============================================================================
|
||||
DatabasePolling::DatabasePolling(){
|
||||
m_time_since_poll = 0.0f;
|
||||
}
|
||||
|
||||
DatabasePolling::~DatabasePolling(){
|
||||
|
||||
}
|
||||
|
||||
void DatabasePolling::generateNewPollRequest(){
|
||||
|
||||
}
|
||||
|
||||
void DatabasePolling::addResult(Online::Request *request)
|
||||
{
|
||||
assert(request->isDone());
|
||||
m_result_queue.lock();
|
||||
m_result_queue.getData().push(request);
|
||||
m_result_queue.unlock();
|
||||
}
|
||||
|
||||
DatabasePolling::PollRequest * DatabasePolling::popResult()
|
||||
{
|
||||
PollRequest * request = NULL;
|
||||
m_result_queue.lock();
|
||||
if(!m_result_queue.getData().empty())
|
||||
{
|
||||
request = (PollRequest*) m_result_queue.getData().front();
|
||||
m_result_queue.getData().pop();
|
||||
}
|
||||
m_result_queue.unlock();
|
||||
return request;
|
||||
}
|
||||
|
||||
void DatabasePolling::update(float dt){
|
||||
if(!CurrentUser::get()->isRegisteredUser())
|
||||
return;
|
||||
PollRequest * request = popResult();
|
||||
if(request != NULL)
|
||||
request->onPollFetch();
|
||||
|
||||
m_time_since_poll += dt;
|
||||
float interval = MENU_POLLING_INTERVAL;
|
||||
if(m_time_since_poll > interval)
|
||||
{
|
||||
m_time_since_poll = 0;
|
||||
generateNewPollRequest();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace Online
|
78
src/online/database_polling.hpp
Normal file
78
src/online/database_polling.hpp
Normal file
@ -0,0 +1,78 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Glenn De Jonghe
|
||||
//
|
||||
// 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_DATABASE_POLLING_HPP
|
||||
#define HEADER_DATABASE_POLLING_HPP
|
||||
|
||||
#include "utils/types.hpp"
|
||||
#include "utils/synchronised.hpp"
|
||||
#include "http_manager.hpp"
|
||||
#include <queue>
|
||||
|
||||
|
||||
|
||||
namespace Online {
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* \ingroup online
|
||||
*/
|
||||
class DatabasePolling
|
||||
{
|
||||
class PollRequest : public XMLRequest
|
||||
{
|
||||
void callback ()
|
||||
{
|
||||
DatabasePolling::get()->addResult(this);
|
||||
}
|
||||
public:
|
||||
PollRequest() : XMLRequest() {}
|
||||
void onPollFetch() = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
DatabasePolling();
|
||||
~DatabasePolling();
|
||||
|
||||
float m_time_since_poll;
|
||||
|
||||
/** The list of pointers to all requests that are handled and needed to be put in the queue */
|
||||
Synchronised< std::queue<Online::Request*> > m_result_queue;
|
||||
|
||||
void addResult(Online::Request *request);
|
||||
PollRequest * popResult();
|
||||
void DatabasePolling::generateNewPollRequest();
|
||||
|
||||
public:
|
||||
// Singleton
|
||||
static DatabasePolling* get();
|
||||
static void deallocate();
|
||||
|
||||
void update(float dt);
|
||||
|
||||
|
||||
|
||||
}; // class DatabasePolling
|
||||
|
||||
|
||||
} // namespace Online
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*EOF*/
|
@ -157,6 +157,7 @@ namespace Online{
|
||||
m_request_queue.unlock();
|
||||
} // addRequest
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Immediately performs a request synchronously
|
||||
* \param request The pointer to the new request to insert.
|
||||
|
@ -42,12 +42,6 @@ namespace Online{
|
||||
private:
|
||||
ProfileManager ();
|
||||
|
||||
enum State
|
||||
{
|
||||
S_FETCHING = 1,
|
||||
S_READY
|
||||
};
|
||||
|
||||
typedef std::map<uint32_t, Profile*> ProfilesMap;
|
||||
|
||||
ProfilesMap m_profiles_cache;
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <curl/curl.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
|
||||
network_world
|
||||
namespace Online{
|
||||
|
||||
/**
|
||||
|
@ -37,16 +37,12 @@ namespace Online {
|
||||
class ServersManager
|
||||
{
|
||||
public:
|
||||
enum RequestType
|
||||
{
|
||||
RT_REFRESH = 1
|
||||
};
|
||||
|
||||
class RefreshRequest : public XMLRequest
|
||||
{
|
||||
virtual void callback ();
|
||||
public:
|
||||
RefreshRequest() : XMLRequest(RT_REFRESH) {}
|
||||
RefreshRequest() : XMLRequest() {}
|
||||
};
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user