Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/skyjake/Doomsday-Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 13, 2014
2 parents 55b8674 + c7c1ded commit 1a7dcc2
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 53 deletions.
8 changes: 7 additions & 1 deletion doomsday/client/include/ui/widgets/gamefilterwidget.h
Expand Up @@ -43,6 +43,12 @@ class GameFilterWidget : public de::GuiWidget, public de::IPersistent
};
Q_DECLARE_FLAGS(Filter, FilterFlag)

enum FilterMode
{
UserChangeable,
Permanent
};

enum SortOrder
{
SortByTitle,
Expand All @@ -53,7 +59,7 @@ class GameFilterWidget : public de::GuiWidget, public de::IPersistent
GameFilterWidget(de::String const &name = "gamefilter");

void useInvertedStyle();
void setFilter(Filter flt);
void setFilter(Filter flt, FilterMode mode = UserChangeable);

Filter filter() const;
SortOrder sortOrder() const;
Expand Down
17 changes: 6 additions & 11 deletions doomsday/client/src/client/cl_main.cpp
Expand Up @@ -29,6 +29,7 @@

#include "con_main.h"

#include "audio/s_main.h"
#include "network/net_demo.h"

#include "world/map.h"
Expand Down Expand Up @@ -95,19 +96,13 @@ void Cl_CleanUp()
clientPaused = false;
handshakeReceived = false;

if(App_WorldSystem().hasMap())
{
Cl_ResetFrame();
App_WorldSystem().map().clearClMobjs();
}
S_Reset();

Cl_InitPlayers();
Cl_ResetTransTables();
// Reset the local world state.
App_WorldSystem().reset();

if(App_WorldSystem().hasMap())
{
App_WorldSystem().map().clearClMovers();
}
// Discard the translation tables for the server we've just left.
Cl_ResetTransTables();

GL_SetFilter(false);
}
Expand Down
29 changes: 24 additions & 5 deletions doomsday/client/src/dd_plugin.cpp
Expand Up @@ -59,7 +59,16 @@ struct ThreadState
pluginid_t currentPlugin;
ThreadState() : currentPlugin(0) {}
};

#ifndef DENG2_QT_4_8_OR_NEWER // Qt 4.7 requires a pointer as the local data type
#define DENG_LOCAL_DATA_POINTER
static QThreadStorage<ThreadState *> pluginState; ///< Thread-local plugin state.
static void initLocalData() {
if(!pluginState.hasLocalData()) pluginState.setLocalData(new ThreadState);
}
#else
static QThreadStorage<ThreadState> pluginState; ///< Thread-local plugin state.
#endif

static PluginHandle* findFirstUnusedPluginHandle(void)
{
Expand Down Expand Up @@ -243,7 +252,22 @@ DENG_EXTERN_C int Plug_CheckForHook(int hookType)

void DD_SetActivePluginId(pluginid_t id)
{
#ifdef DENG_LOCAL_DATA_POINTER
initLocalData();
pluginState.localData()->currentPlugin = id;
#else
pluginState.localData().currentPlugin = id;
#endif
}

pluginid_t DD_ActivePluginId(void)
{
#ifdef DENG_LOCAL_DATA_POINTER
initLocalData();
return pluginState.localData()->currentPlugin;
#else
return pluginState.localData().currentPlugin;
#endif
}

int DD_CallHooks(int hookType, int parm, void *data)
Expand Down Expand Up @@ -279,11 +303,6 @@ int DD_CallHooks(int hookType, int parm, void *data)
return ret;
}

pluginid_t DD_ActivePluginId(void)
{
return pluginState.localData().currentPlugin;
}

void* DD_FindEntryPoint(pluginid_t pluginId, const char* fn)
{
void* addr = 0;
Expand Down
4 changes: 4 additions & 0 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -288,12 +288,16 @@ DENG2_PIMPL(ClientWindow)
//game->hide();
background->show();
gameSelMenu->show();

gameSelMenu->restoreState();
}
else
{
//game->show();
background->hide();
gameSelMenu->hide();

gameSelMenu->saveState();
}

// Check with Style if blurring is allowed.
Expand Down
9 changes: 5 additions & 4 deletions doomsday/client/src/ui/dialogs/gamesdialog.cpp
Expand Up @@ -59,16 +59,17 @@ GamesDialog::GamesDialog(Mode mode, String const &name)
d->gameSel->filter().rule().setInput(Rule::Width, d->gameSel->rule().width());
layout << d->gameSel->filter();

d->gameSel->filter().setFilter(GameFilterWidget::AllGames);
// Disallow changing the filter.
d->gameSel->filter().setFilter(GameFilterWidget::AllGames, GameFilterWidget::Permanent);
}
else
{
// Select a suitable view as the user can't change the filter.
// Disallow changing the filter.
d->gameSel->filter().hide();
d->gameSel->filter().enableStateSerialization(false);
d->gameSel->filter().setFilter(d->mode == ShowSingleplayerOnly?
GameFilterWidget::Singleplayer :
GameFilterWidget::Multiplayer);
GameFilterWidget::Multiplayer,
GameFilterWidget::Permanent);

switch(d->mode)
{
Expand Down
25 changes: 19 additions & 6 deletions doomsday/client/src/ui/widgets/gamefilterwidget.cpp
Expand Up @@ -33,8 +33,11 @@ DENG2_PIMPL(GameFilterWidget)
LabelWidget *sortLabel;
ChoiceWidget *sortBy;
DialogContentStylist stylist;
FilterMode filterMode;

Instance(Public *i) : Base(i)
Instance(Public *i)
: Base(i)
, filterMode(UserChangeable)
{
stylist.setContainer(self);

Expand Down Expand Up @@ -86,13 +89,19 @@ void GameFilterWidget::useInvertedStyle()
d->sortBy->useInfoStyle();
}

void GameFilterWidget::setFilter(Filter flt)
void GameFilterWidget::setFilter(Filter flt, FilterMode mode)
{
ui::DataPos pos = d->tabs->items().findData(duint(flt));
if(pos != ui::Data::InvalidPos)
{
d->tabs->setCurrent(pos);
}
d->filterMode = mode;

if(d->filterMode == Permanent)
{
d->tabs->disable();
}
}

GameFilterWidget::Filter GameFilterWidget::filter() const
Expand All @@ -108,15 +117,19 @@ GameFilterWidget::SortOrder GameFilterWidget::sortOrder() const
void GameFilterWidget::operator >> (PersistentState &toState) const
{
Record &st = toState.names();

st.set(d->persistId("filter"), dint(filter()));
if(d->filterMode != Permanent)
{
st.set(d->persistId("filter"), dint(filter()));
}
st.set(d->persistId("order"), dint(sortOrder()));
}

void GameFilterWidget::operator << (PersistentState const &fromState)
{
Record const &st = fromState.names();

d->tabs->setCurrent (d->tabs->items() .findData(int(st[d->persistId("filter")])));
if(d->filterMode != Permanent)
{
d->tabs->setCurrent(d->tabs->items().findData(int(st[d->persistId("filter")])));
}
d->sortBy->setSelected(d->sortBy->items().findData(int(st[d->persistId("order" )])));
}
2 changes: 2 additions & 0 deletions doomsday/client/src/ui/widgets/gameselectionwidget.cpp
Expand Up @@ -231,6 +231,8 @@ DENG_GUI_PIMPL(GameSelectionWidget)

~Instance()
{
foreach(SubsetWidget *sub, subsets) sub->menu->setFilter(0);

App::app().audienceForGameChange() -= this;
}

Expand Down
5 changes: 4 additions & 1 deletion doomsday/client/src/ui/widgets/sessionmenuwidget.cpp
Expand Up @@ -113,7 +113,10 @@ void SessionMenuWidget::setColumns(int numberOfColumns)

void SessionMenuWidget::sort()
{
d->sortSessions();
if(d->filter)
{
d->sortSessions();
}
}

//--------------------------------------------------------------------------------------
Expand Down
Expand Up @@ -31,6 +31,7 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)
, DENG2_OBSERVES(Games, Addition)
, DENG2_OBSERVES(Loop, Iteration) // deferred updates
, DENG2_OBSERVES(App, StartupComplete)
, DENG2_OBSERVES(App, GameChange)
{
/// ActionItem with a Game member, for loading a particular game.
struct GameItem : public ui::ImageItem,
Expand Down Expand Up @@ -71,6 +72,7 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)
Instance(Public *i) : Base(i)
{
App_Games().audienceForAddition() += this;
App::app().audienceForGameChange() += this;
App::app().audienceForStartupComplete() += this;
}

Expand All @@ -79,6 +81,7 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)
Loop::appLoop().audienceForIteration() -= this;

App_Games().audienceForAddition() -= this;
App::app().audienceForGameChange() -= this;
App::app().audienceForStartupComplete() -= this;
}

Expand Down Expand Up @@ -110,6 +113,7 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)
{
Loop::appLoop().audienceForIteration() -= this;
addPendingGames();
updateGameAvailability();
}

void addPendingGames()
Expand Down Expand Up @@ -173,6 +177,11 @@ DENG_GUI_PIMPL(SingleplayerSessionMenuWidget)
{
updateGameAvailability();
}

void currentGameChanged(game::Game const &)
{
Loop::appLoop().audienceForIteration() += this;
}
};

SingleplayerSessionMenuWidget::SingleplayerSessionMenuWidget(Mode mode, String const &name)
Expand Down
12 changes: 12 additions & 0 deletions doomsday/libappfw/include/de/framework/guiwidget.h
Expand Up @@ -261,6 +261,18 @@ class LIBAPPFW_PUBLIC GuiWidget : public QObject, public Widget
*/
void enableStateSerialization(bool enabled = true);

/**
* Save the state of the widget and all its children (those who support state
* serialization).
*/
void saveState();

/**
* Restore the state of the widget and all its children (those who support state
* serialization).
*/
void restoreState();

// Events.
void initialize();
void deinitialize();
Expand Down
38 changes: 34 additions & 4 deletions doomsday/libappfw/src/guiwidget.cpp
Expand Up @@ -321,7 +321,6 @@ DENG2_PIMPL(GuiWidget)

void restoreState()
{
if(!stateSerializationEnabled) return;
try
{
if(IPersistent *po = self.maybeAs<IPersistent>())
Expand All @@ -339,7 +338,6 @@ DENG2_PIMPL(GuiWidget)

void saveState()
{
if(!stateSerializationEnabled) return;
try
{
if(IPersistent *po = self.maybeAs<IPersistent>())
Expand Down Expand Up @@ -548,6 +546,32 @@ void GuiWidget::enableStateSerialization(bool enabled)
d->stateSerializationEnabled = enabled;
}

void GuiWidget::saveState()
{
d->saveState();

foreach(Widget *child, childWidgets())
{
if(GuiWidget *widget = child->maybeAs<GuiWidget>())
{
widget->saveState();
}
}
}

void GuiWidget::restoreState()
{
d->restoreState();

foreach(Widget *child, childWidgets())
{
if(GuiWidget *widget = child->maybeAs<GuiWidget>())
{
widget->restoreState();
}
}
}

void GuiWidget::initialize()
{
if(d->inited) return;
Expand All @@ -557,7 +581,10 @@ void GuiWidget::initialize()
d->inited = true;
glInit();

d->restoreState();
if(d->stateSerializationEnabled)
{
d->restoreState();
}
}
catch(Error const &er)
{
Expand All @@ -572,7 +599,10 @@ void GuiWidget::deinitialize()

try
{
d->saveState();
if(d->stateSerializationEnabled)
{
d->saveState();
}

d->inited = false;
d->deinitBlur();
Expand Down
6 changes: 6 additions & 0 deletions doomsday/plugins/common/include/p_mapsetup.h
Expand Up @@ -46,6 +46,12 @@ void P_FinalizeMapChange(Uri const *uri);
*/
void P_SetupMap(Uri const *uri);

/**
* To be called to reset the local world state (e.g., when leaving a networked game).
* Note that @ref P_SetupMap() calls this automatically when the current map changes.
*/
void P_ResetWorldState();

/**
* @param mapUri Identifier of the map to lookup the author of. Can be @c 0 in which
* case the author for the @em current map will be returned (if set).
Expand Down

0 comments on commit 1a7dcc2

Please sign in to comment.