1) Changed queue and addon vector to use SynchronisedVector in order
to hide more pthread calls. 2) Started to work on screen layout. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7401 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
9c0dd7c079
commit
dbe6395c1e
@ -1,27 +1,22 @@
|
||||
<stkgui>
|
||||
|
||||
<div x="5%" y="0%" width="90%" height="80%" layout="horizontal-row" >
|
||||
<div width="50%" height="90%" layout="vertical-row" >
|
||||
<spacer height="22%" />
|
||||
<div x="5%" width="90%" height="90%" layout="vertical-row">
|
||||
<label x="0" width="100%" id="name" align="center" width="100%" text="Name:" proportion="1" />
|
||||
<div x="5%" y="0%" width="90%" height="80%" layout="horizontal-row" >
|
||||
<div width="50%" height="100%" layout="vertical-row" >
|
||||
<icon id="icon" align="center" proportion="8" width="100%" icon="gui/loading.png"/>
|
||||
<spacer proportion="1" />
|
||||
<button id="install" width="70%" I18N="Addons" text="Install" align="center"/>
|
||||
</div>
|
||||
<div width="50%" height="90%" layout="vertical-row" >
|
||||
<label id="name" width="100%" text="Name:" proportion="1" />
|
||||
<spacer proportion="1" />
|
||||
<div width="50%" height="100%" layout="vertical-row" >
|
||||
<label word_wrap="true" id="description" width="100%" text="Description:" proportion="1" />
|
||||
<label id="version" width="100%" text="Version:" proportion="1" />
|
||||
|
||||
<spacer proportion="1" />
|
||||
<button id="cancel" width="70%" I18N="Addons" text="Back" align="center"/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div x="5%" y="80%" width="40%" height="10%" layout="horizontal-row">
|
||||
<spacer proportion="1" />
|
||||
<button id="cancel" width="70%" I18N="Addons" text="Back" align="center"/>
|
||||
<spacer proportion="1" />
|
||||
</div>
|
||||
<div x="50%" y="80%" width="40%" height="10%" layout="horizontal-row" >
|
||||
<spacer proportion="1" />
|
||||
<button id="install" width="70%" I18N="Addons" text="Install" align="center"/>
|
||||
<spacer proportion="1" />
|
||||
</div>
|
||||
<spacer proportion="1" />
|
||||
<progressbar id="progress" width="100%" height="35"/>
|
||||
</div>
|
||||
</stkgui>
|
||||
|
@ -28,11 +28,12 @@
|
||||
#include "io/xml_node.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
Addon::Addon(const XMLNode &xml, bool installed)
|
||||
Addon::Addon(const XMLNode &xml)
|
||||
{
|
||||
m_installed = installed;
|
||||
m_installed_version = 0;
|
||||
m_name = "";
|
||||
m_id = "";
|
||||
m_installed = false;
|
||||
m_installed_version = 0;
|
||||
m_version = 0 ;
|
||||
m_zip_file = "";
|
||||
m_description = "";
|
||||
@ -40,27 +41,19 @@ Addon::Addon(const XMLNode &xml, bool installed)
|
||||
m_icon_basename = "";
|
||||
m_icon_version = 0;
|
||||
m_icon_ready = false;
|
||||
m_id = "";
|
||||
m_type = xml.getName();
|
||||
|
||||
xml.get("name", &m_name);
|
||||
if(m_installed)
|
||||
{
|
||||
xml.get("installed-version", &m_installed_version);
|
||||
xml.get("id", &m_id );
|
||||
xml.get("icon-version", &m_icon_version );
|
||||
}
|
||||
else // not installed
|
||||
{
|
||||
xml.get("file", &m_zip_file );
|
||||
xml.get("description", &m_description);
|
||||
xml.get("icon", &m_icon_url );
|
||||
xml.get("version", &m_version );
|
||||
// The online list has a numeric id, which is not used.
|
||||
// So ignore it.
|
||||
m_id = StringUtils::toLowerCase(m_name);
|
||||
m_icon_basename = StringUtils::getBasename(m_icon_url);
|
||||
} // if installed
|
||||
|
||||
xml.get("name", &m_name );
|
||||
m_id = StringUtils::toLowerCase(m_name);
|
||||
xml.get("id", &m_id);
|
||||
xml.get("installed", &m_installed );
|
||||
xml.get("installed-version", &m_installed_version);
|
||||
xml.get("version", &m_version );
|
||||
xml.get("file", &m_zip_file );
|
||||
xml.get("description", &m_description );
|
||||
xml.get("icon", &m_icon_url );
|
||||
xml.get("icon-version", &m_icon_version );
|
||||
m_icon_basename = StringUtils::getBasename(m_icon_url);
|
||||
}; // Addon(const XML&)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
|
||||
Addon() {};
|
||||
/** Initialises the object from an XML node. */
|
||||
Addon(const XMLNode &xml, bool installed=false);
|
||||
Addon(const XMLNode &xml);
|
||||
// ------------------------------------------------------------------------
|
||||
void writeXML(std::ofstream *out_stram);
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -45,10 +45,12 @@ AddonsManager* addons_manager = 0;
|
||||
* the list of already installed addons). The online component is initialised
|
||||
* later from a separate thread in network_http (once network_http is setup).
|
||||
*/
|
||||
AddonsManager::AddonsManager() : m_state(STATE_INIT)
|
||||
AddonsManager::AddonsManager() : m_state(STATE_INIT),
|
||||
m_icon_queue(std::vector<std::string>() ),
|
||||
m_addons_list(std::vector<Addon>() )
|
||||
{
|
||||
m_file_installed = file_manager->getAddonsFile("addons_installed.xml");
|
||||
loadInstalledAddons();
|
||||
|
||||
} // AddonsManager
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -61,6 +63,10 @@ AddonsManager::AddonsManager() : m_state(STATE_INIT)
|
||||
*/
|
||||
void AddonsManager::initOnline(const XMLNode *xml)
|
||||
{
|
||||
m_addons_list.lock();
|
||||
loadInstalledAddons();
|
||||
m_addons_list.unlock();
|
||||
|
||||
for(unsigned int i=0; i<xml->getNumNodes(); i++)
|
||||
{
|
||||
const XMLNode *node = xml->getNode(i);
|
||||
@ -105,13 +111,15 @@ void AddonsManager::initOnline(const XMLNode *xml)
|
||||
continue;
|
||||
}
|
||||
|
||||
m_addons_list.lock();
|
||||
if(index>=0)
|
||||
m_addons_list[index].copyInstallData(addon);
|
||||
m_addons_list.getData()[index].copyInstallData(addon);
|
||||
else
|
||||
{
|
||||
m_addons_list.push_back(addon);
|
||||
index = m_addons_list.size()-1;
|
||||
m_addons_list.getData().push_back(addon);
|
||||
index = m_addons_list.getData().size()-1;
|
||||
}
|
||||
m_addons_list.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -125,8 +133,6 @@ void AddonsManager::initOnline(const XMLNode *xml)
|
||||
|
||||
m_state.set(STATE_READY);
|
||||
|
||||
pthread_mutex_init(&m_mutex_icon, NULL);
|
||||
|
||||
pthread_t id;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
@ -141,42 +147,44 @@ void AddonsManager::initOnline(const XMLNode *xml)
|
||||
void *AddonsManager::downloadIcons(void *obj)
|
||||
{
|
||||
AddonsManager *me=(AddonsManager*)obj;
|
||||
me->m_icon_queue.lock();
|
||||
me->m_icon_queue.getData().clear();
|
||||
me->m_icon_queue.unlock();
|
||||
|
||||
me->m_icon_queue.clear();
|
||||
|
||||
for(unsigned int i=0; i<me->m_addons_list.size(); i++)
|
||||
for(unsigned int i=0; i<me->m_addons_list.getData().size(); i++)
|
||||
{
|
||||
const Addon &addon = me->m_addons_list[i];
|
||||
const Addon &addon = me->m_addons_list.getData()[i];
|
||||
const std::string &icon = addon.getIconBasename();
|
||||
if(addon.iconNeedsUpdate())
|
||||
{
|
||||
pthread_mutex_lock(&(me->m_mutex_icon));
|
||||
me->m_icon_queue.push_back(addon.getId());
|
||||
pthread_mutex_unlock(&(me->m_mutex_icon));
|
||||
me->m_icon_queue.lock();
|
||||
me->m_icon_queue.getData().push_back(addon.getId());
|
||||
me->m_icon_queue.unlock();
|
||||
continue;
|
||||
}
|
||||
std::string icon_path=file_manager->getAddonsFile("icons/"+icon);
|
||||
if(!file_manager->fileExists(icon_path))
|
||||
{
|
||||
pthread_mutex_lock(&(me->m_mutex_icon));
|
||||
me->m_icon_queue.push_back(addon.getId());
|
||||
pthread_mutex_unlock(&(me->m_mutex_icon));
|
||||
me->m_icon_queue.lock();
|
||||
me->m_icon_queue.getData().push_back(addon.getId());
|
||||
me->m_icon_queue.unlock();
|
||||
continue;
|
||||
}
|
||||
me->m_addons_list[i].setIconReady();
|
||||
me->m_addons_list.getData()[i].setIconReady();
|
||||
} // for i<m_addons_list.size()
|
||||
|
||||
pthread_mutex_lock(&(me->m_mutex_icon));
|
||||
int count = me->m_icon_queue.size();
|
||||
pthread_mutex_unlock(&(me->m_mutex_icon));
|
||||
me->m_icon_queue.lock();
|
||||
int count = me->m_icon_queue.getData().size();
|
||||
me->m_icon_queue.unlock();
|
||||
while(count!=0)
|
||||
{
|
||||
pthread_mutex_lock(&(me->m_mutex_icon));
|
||||
unsigned int indx = me->getAddonIndex(me->m_icon_queue[0]);
|
||||
Addon *addon = &(me->m_addons_list[indx]);
|
||||
me->m_icon_queue.erase(me->m_icon_queue.begin());
|
||||
me->m_icon_queue.lock();
|
||||
std::vector<std::string> &icon_queue = me->m_icon_queue.getData();
|
||||
unsigned int indx = me->getAddonIndex(icon_queue[0]);
|
||||
Addon *addon = &(me->m_addons_list.getData()[indx]);
|
||||
icon_queue.erase(icon_queue.begin());
|
||||
count --;
|
||||
pthread_mutex_unlock(&(me->m_mutex_icon));
|
||||
me->m_icon_queue.unlock();
|
||||
|
||||
const std::string &url = addon->getIconURL();
|
||||
const std::string &icon = addon->getIconBasename();
|
||||
@ -191,10 +199,14 @@ void *AddonsManager::downloadIcons(void *obj)
|
||||
icon.c_str(), url.c_str());
|
||||
}
|
||||
} // while count!=0
|
||||
for(unsigned int i=0; i<me->m_addons_list.size(); i++)
|
||||
|
||||
// Now check if we have any entries in m_addons_list, that is not
|
||||
// in the online list anymore
|
||||
for(unsigned int i=0; i<me->m_addons_list.getData().size(); i++)
|
||||
{
|
||||
if(!me->m_addons_list[i].iconReady())
|
||||
printf("No icon for '%s'.\n", me->m_addons_list[i].getId().c_str());
|
||||
if(!me->m_addons_list.getData()[i].iconReady())
|
||||
printf("No icon for '%s'.\n",
|
||||
me->m_addons_list.getData()[i].getId().c_str());
|
||||
}
|
||||
me->saveInstalled();
|
||||
return NULL;
|
||||
@ -230,8 +242,8 @@ void AddonsManager::loadInstalledAddons()
|
||||
if(node->getName()=="kart" ||
|
||||
node->getName()=="track" )
|
||||
{
|
||||
Addon addon(*node, /*installed*/ true);
|
||||
m_addons_list.push_back(addon);
|
||||
Addon addon(*node);
|
||||
m_addons_list.getData().push_back(addon);
|
||||
}
|
||||
} // for i <= xml->getNumNodes()
|
||||
|
||||
@ -246,15 +258,15 @@ void AddonsManager::loadInstalledAddons()
|
||||
const Addon* AddonsManager::getAddon(const std::string &id) const
|
||||
{
|
||||
int i = getAddonIndex(id);
|
||||
return (i<0) ? NULL : &(m_addons_list[i]);
|
||||
return (i<0) ? NULL : &(m_addons_list.getData()[i]);
|
||||
} // getAddon
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int AddonsManager::getAddonIndex(const std::string &id) const
|
||||
{
|
||||
for(unsigned int i = 0; i < m_addons_list.size(); i++)
|
||||
for(unsigned int i = 0; i < m_addons_list.getData().size(); i++)
|
||||
{
|
||||
if(m_addons_list[i].getId()== id)
|
||||
if(m_addons_list.getData()[i].getId()== id)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@ -285,8 +297,8 @@ void AddonsManager::install(const Addon &addon)
|
||||
}
|
||||
|
||||
int index = getAddonIndex(addon.getId());
|
||||
assert(index>=0 && index < (int)m_addons_list.size());
|
||||
m_addons_list[index].setInstalled(true);
|
||||
assert(index>=0 && index < (int)m_addons_list.getData().size());
|
||||
m_addons_list.getData()[index].setInstalled(true);
|
||||
|
||||
if(addon.getType()=="kart")
|
||||
{
|
||||
@ -319,11 +331,11 @@ void AddonsManager::saveInstalled(const std::string &type)
|
||||
xml_installed << "<addons xmlns='http://stkaddons.tuxfamily.org/'>"
|
||||
<< std::endl;
|
||||
|
||||
for(unsigned int i = 0; i < m_addons_list.size(); i++)
|
||||
for(unsigned int i = 0; i < m_addons_list.getData().size(); i++)
|
||||
{
|
||||
//if(m_addons_list[i].m_installed)
|
||||
{
|
||||
m_addons_list[i].writeXML(&xml_installed);
|
||||
m_addons_list.getData()[i].writeXML(&xml_installed);
|
||||
}
|
||||
}
|
||||
xml_installed << "</addons>" << std::endl;
|
||||
@ -346,8 +358,8 @@ void AddonsManager::uninstall(const Addon &addon)
|
||||
// addon is a const reference, and to avoid removing the const, we
|
||||
// find the proper index again to modify the installed state
|
||||
int index = getAddonIndex(addon.getId());
|
||||
assert(index>=0 && index < (int)m_addons_list.size());
|
||||
m_addons_list[index].setInstalled(false);
|
||||
assert(index>=0 && index < (int)m_addons_list.getData().size());
|
||||
m_addons_list.getData()[index].setInstalled(false);
|
||||
|
||||
//write the xml file with the informations about installed karts
|
||||
std::string name=addon.getType()+"s/"+addon.getId();
|
||||
|
@ -24,8 +24,6 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "addons/addon.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "utils/synchronised.hpp"
|
||||
@ -33,22 +31,21 @@
|
||||
class AddonsManager
|
||||
{
|
||||
private:
|
||||
std::vector<Addon> m_addons_list;
|
||||
std::string m_file_installed;
|
||||
void saveInstalled(const std::string &type="");
|
||||
void loadInstalledAddons();
|
||||
std::string m_type;
|
||||
int m_download_state;
|
||||
/** The list of all addons - installed or uninstalled. The list is
|
||||
* combined from the addons_installed.xml file first, then information
|
||||
* from the downloaded list of items is merged/added to that. */
|
||||
Synchronised<std::vector<Addon> > m_addons_list;
|
||||
/** Full filename of the addons_installed.xml file. */
|
||||
std::string m_file_installed;
|
||||
std::string m_type;
|
||||
int m_download_state;
|
||||
|
||||
/** List of loaded icons. */
|
||||
std::vector<std::string> m_icon_list;
|
||||
|
||||
/** Queue of icons to download. This queue is used by the
|
||||
* GUI to increase priority of icons that are needed now. */
|
||||
std::vector<std::string> m_icon_queue;
|
||||
|
||||
/** Mutex to protect access to icon_list. */
|
||||
pthread_mutex_t m_mutex_icon;
|
||||
Synchronised<std::vector<std::string> > m_icon_queue;
|
||||
|
||||
/** Which state the addons manager is:
|
||||
* INIT: Waiting to download the list of addons.
|
||||
@ -58,6 +55,8 @@ private:
|
||||
// Synchronise the state between threads (e.g. GUI and update thread)
|
||||
Synchronised<STATE_TYPE> m_state;
|
||||
|
||||
void saveInstalled(const std::string &type="");
|
||||
void loadInstalledAddons();
|
||||
static void *downloadIcons(void *obj);
|
||||
|
||||
public:
|
||||
@ -68,10 +67,13 @@ public:
|
||||
void setErrorState() { m_state.set(STATE_ERROR); }
|
||||
|
||||
/** Returns the list of addons (installed and uninstalled). */
|
||||
unsigned int getNumAddons() const { return m_addons_list.size(); }
|
||||
unsigned int getNumAddons() const
|
||||
{
|
||||
return m_addons_list.getData().size();
|
||||
}
|
||||
|
||||
/** Returns the i-th addons. */
|
||||
const Addon& getAddon(unsigned int i) { return m_addons_list[i];}
|
||||
const Addon& getAddon(unsigned int i) { return m_addons_list.getData()[i];}
|
||||
const Addon* getAddon(const std::string &id) const;
|
||||
int getAddonIndex(const std::string &id) const;
|
||||
|
||||
|
@ -42,13 +42,13 @@ AddonsLoading::AddonsLoading(const float w, const float h,
|
||||
{
|
||||
loadFromFile("addons_view_dialog.stkgui");
|
||||
m_addon = *(addons_manager->getAddon(id));
|
||||
m_progress = NULL;
|
||||
m_can_install = false;
|
||||
m_percent_update = false;
|
||||
m_icon_shown = false;
|
||||
|
||||
/*Init the icon here to be able to load a single image*/
|
||||
m_icon = getWidget<IconButtonWidget>("icon");
|
||||
m_icon = getWidget<IconButtonWidget>("icon");
|
||||
m_progress = getWidget<ProgressBarWidget>("progress");
|
||||
if(m_progress)
|
||||
m_progress->setVisible(false);
|
||||
|
||||
if(m_addon.isInstalled())
|
||||
{
|
||||
@ -88,16 +88,8 @@ GUIEngine::EventPropagation
|
||||
// not uninstalling an addon.
|
||||
if(!m_addon.isInstalled() || m_addon.needsUpdate())
|
||||
{
|
||||
assert(m_progress==NULL);
|
||||
m_progress = new ProgressBarWidget();
|
||||
m_progress->m_x = 180;
|
||||
m_progress->m_y = m_area.getHeight()-45;
|
||||
m_progress->m_w = 250;
|
||||
m_progress->m_h = 35;
|
||||
m_progress->setParent(m_irrlicht_window);
|
||||
|
||||
m_widgets.push_back(m_progress);
|
||||
m_progress->add();
|
||||
m_progress->setValue(0);
|
||||
m_progress->setVisible(true);
|
||||
|
||||
/*This widget will show some text as "downloading..." or "installing".*/
|
||||
m_state = new LabelWidget();
|
||||
@ -112,9 +104,7 @@ GUIEngine::EventPropagation
|
||||
m_widgets.push_back(m_state);
|
||||
m_state->add();
|
||||
|
||||
getWidget<ButtonWidget>("cancel")->setDeactivated();
|
||||
getWidget<ButtonWidget>("install")->setDeactivated();
|
||||
m_percent_update = true;
|
||||
startDownload();
|
||||
}
|
||||
else // uninstall
|
||||
@ -129,7 +119,7 @@ GUIEngine::EventPropagation
|
||||
// ----------------------------------------------------------------------------
|
||||
void AddonsLoading::onUpdate(float delta)
|
||||
{
|
||||
if(m_progress)
|
||||
if(m_progress->isVisible())
|
||||
{
|
||||
float progress = network_http->getProgress();
|
||||
m_progress->setValue((int)(progress*100.0f));
|
||||
|
@ -47,13 +47,6 @@ private:
|
||||
void startDownload();
|
||||
void doInstall();
|
||||
|
||||
/* These three bool are some flags.
|
||||
* m_can_install : when the installation is finidhed, onUpdate close the
|
||||
* dialog.
|
||||
* m_percent_update : to reload the download percent */
|
||||
bool m_can_install;
|
||||
bool m_percent_update;
|
||||
|
||||
/** True if the icon is being displayed. */
|
||||
bool m_icon_shown;
|
||||
|
||||
@ -66,8 +59,8 @@ public:
|
||||
GUIEngine::EventPropagation processEvent(const std::string& event_source);
|
||||
|
||||
/** This function is called by the GUI, all the frame (or somthing like
|
||||
* that). It checks the flags (m_can_install, m_can_load_icon and
|
||||
* m_percent_update) and do the necessary.
|
||||
* that). It checks the flags (m_can_load_icon and
|
||||
* and do the necessary.
|
||||
* */
|
||||
void onUpdate(float delta);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user