Skip to content

Commit

Permalink
libdeng2: Extracted game::Session base class from common::GameSession
Browse files Browse the repository at this point in the history
The game::Session base class grants the engine some limited visibility
of and access to the logical game side session and the associated save
game functionality.

The SavedSession index is owned (shared) by this base class, rather
than the ResourceSystem (the index functionality will me merged into
the file system at some point), allowing the removal of the temporary
Base API entrypoint for this.
  • Loading branch information
danij-deng committed Apr 4, 2014
1 parent 2981492 commit 2e79bb8
Show file tree
Hide file tree
Showing 18 changed files with 338 additions and 340 deletions.
7 changes: 0 additions & 7 deletions doomsday/api/api_base.h
Expand Up @@ -165,12 +165,6 @@ DENG_API_TYPEDEF(Base) // v2
* perform map setup once more.
*/
void (*SetupMap)(int mode, int flags);

/**
* Returns a pointer to the application's saved session repository.
* @todo Somewhat of a kludge...
*/
void *(*SavedSessionRepository)(void);
}
DENG_API_T(Base);

Expand All @@ -187,7 +181,6 @@ DENG_API_T(Base);
#define DD_IsSharpTick _api_Base.IsSharpTick
#define Net_SendPacket _api_Base.SendPacket
#define R_SetupMap _api_Base.SetupMap
#define DD_SavedSessionRepository _api_Base.SavedSessionRepository
#endif

#ifdef __DOOMSDAY__
Expand Down
6 changes: 0 additions & 6 deletions doomsday/client/include/resource/resourcesystem.h
Expand Up @@ -42,7 +42,6 @@
#include "resource/zip.h"
#include "uri.hh"
#include <de/Error>
#include <de/game/SavedSessionRepository>
#include <de/String>
#include <de/System>
#include <QList>
Expand Down Expand Up @@ -865,11 +864,6 @@ class ResourceSystem : public de::System

#endif // __CLIENT__

/**
* Returns the SavedSessionRepository.
*/
de::game::SavedSessionRepository &savedSessionRepository() const;

/**
* Returns the native path of the root of the saved session repository
*/
Expand Down
9 changes: 1 addition & 8 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -524,12 +524,6 @@ ResourceSystem &App_ResourceSystem()
throw Error("App_ResourceSystem", "App not yet initialized");
}

#undef DD_SavedSessionRepository
void *DD_SavedSessionRepository()
{
return &App_ResourceSystem().savedSessionRepository();
}

de::ResourceClass &App_ResourceClass(String className)
{
return App_ResourceSystem().resClass(className);
Expand Down Expand Up @@ -3017,6 +3011,5 @@ DENG_DECLARE_API(Base) =
DD_GameInfo,
DD_IsSharpTick,
Net_SendPacket,
R_SetupMap,
DD_SavedSessionRepository
R_SetupMap
};
11 changes: 3 additions & 8 deletions doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -65,6 +65,7 @@
#include <de/ByteRefArray>
#include <de/DirectoryFeed>
#include <de/game/SavedSession>
#include <de/game/Session>
#include <de/Log>
#include <de/Module>
#include <de/NativeFile>
Expand Down Expand Up @@ -339,7 +340,6 @@ DENG2_PIMPL(ResourceSystem)
SpriteGroups spriteGroups;

NativePath nativeSavePath;
game::SavedSessionRepository saveRepo;

Binder binder;
Record savedSessionModule; // SavedSession: manipulation, conversion, etc... (based on native class SavedSession)
Expand Down Expand Up @@ -1958,7 +1958,7 @@ DENG2_PIMPL(ResourceSystem)
{
if(game::SavedSession *session = i->second->maybeAs<game::SavedSession>())
{
saveRepo.add(*session);
game::Session::savedIndex().add(*session);
}
}
}
Expand Down Expand Up @@ -3918,11 +3918,6 @@ void ResourceSystem::cacheForCurrentMap()

#endif // __CLIENT__

game::SavedSessionRepository &ResourceSystem::savedSessionRepository() const
{
return d->saveRepo;
}

NativePath ResourceSystem::nativeSavePath()
{
return d->nativeSavePath;
Expand Down Expand Up @@ -3956,7 +3951,7 @@ bool ResourceSystem::convertLegacySavegame(String const &sourcePath, String cons
// Update the /home/savegames/<gameId> folder.
Folder &saveFolder = App::rootFolder().locate<Folder>(outputPath);
saveFolder.populate();
d->saveRepo.add(saveFolder.locate<game::SavedSession>(outputName));
game::Session::savedIndex().add(saveFolder.locate<game::SavedSession>(outputName));
return true;
}
catch(Folder::NotFoundError const &)
Expand Down
30 changes: 15 additions & 15 deletions doomsday/client/src/ui/widgets/savegameselectionwidget.cpp
Expand Up @@ -25,21 +25,22 @@
#include "con_main.h"

#include <de/charsymbols.h>
#include <de/game/Session>
#include <de/SignalAction>
#include <de/SequentialLayout>
#include <de/ChildWidgetOrganizer>
#include <de/DocumentPopupWidget>
#include <de/ui/Item>

using namespace de;
using de::game::Session;
using de::game::SavedSession;
using de::game::SavedSessionRepository;

DENG_GUI_PIMPL(SavegameSelectionWidget)
, DENG2_OBSERVES(App, StartupComplete)
, DENG2_OBSERVES(SavedSessionRepository, AvailabilityUpdate)
, DENG2_OBSERVES(ButtonWidget, Press)
, DENG2_OBSERVES(Loop, Iteration) // deferred refresh
, DENG2_OBSERVES(App, StartupComplete)
, DENG2_OBSERVES(Session::SavedIndex, AvailabilityUpdate)
, DENG2_OBSERVES(ButtonWidget, Press)
, DENG2_OBSERVES(Loop, Iteration) // deferred refresh
, public ChildWidgetOrganizer::IWidgetFactory
{
/**
Expand Down Expand Up @@ -121,13 +122,13 @@ DENG_GUI_PIMPL(SavegameSelectionWidget)
self.organizer().setWidgetFactory(*this);

App::app().audienceForStartupComplete() += this;
ClientApp::resourceSystem().savedSessionRepository().audienceForAvailabilityUpdate() += this;
game::Session::savedIndex().audienceForAvailabilityUpdate() += this;
}

~Instance()
{
App::app().audienceForStartupComplete() -= this;
ClientApp::resourceSystem().savedSessionRepository().audienceForAvailabilityUpdate() -= this;
game::Session::savedIndex().audienceForAvailabilityUpdate() -= this;
}

GuiWidget *makeItemWidget(ui::Item const & /*item*/, GuiWidget const *)
Expand Down Expand Up @@ -180,24 +181,23 @@ DENG_GUI_PIMPL(SavegameSelectionWidget)
}
}

void updateItemsFromRepository()
void updateItemsFromSavedIndex()
{
SavedSessionRepository const &repository = ClientApp::resourceSystem().savedSessionRepository();
bool changed = false;

// Remove obsolete entries.
for(ui::Data::Pos idx = 0; idx < self.items().size(); ++idx)
{
String const savePath = self.items().at(idx).data().toString();
if(!repository.find(savePath))
if(!Session::savedIndex().find(savePath))
{
self.items().remove(idx--);
changed = true;
}
}

// Add new entries.
DENG2_FOR_EACH_CONST(SavedSessionRepository::All, i, repository.all())
DENG2_FOR_EACH_CONST(Session::SavedIndex::All, i, Session::savedIndex().all())
{
ui::Data::Pos found = self.items().findData(i.key());
if(found == ui::Data::InvalidPos)
Expand All @@ -219,15 +219,15 @@ DENG_GUI_PIMPL(SavegameSelectionWidget)
}
}

void repositoryAvailabilityUpdate(SavedSessionRepository const &)
void savedIndexAvailabilityUpdate(Session::SavedIndex const &)
{
if(!App::inMainThread())
{
// We'll have to defer the update for now.
deferUpdate();
return;
}
updateItemsFromRepository();
updateItemsFromSavedIndex();
}

void deferUpdate()
Expand All @@ -238,15 +238,15 @@ DENG_GUI_PIMPL(SavegameSelectionWidget)
void loopIteration()
{
Loop::appLoop().audienceForIteration() -= this;
updateItemsFromRepository();
updateItemsFromSavedIndex();
}
};

SavegameSelectionWidget::SavegameSelectionWidget()
: MenuWidget("savegame-selection"), d(new Instance(this))
{
setGridSize(3, ui::Filled, 0, ui::Expand);
d->updateItemsFromRepository();
d->updateItemsFromSavedIndex();
}

void SavegameSelectionWidget::setLoadGameWhenSelected(bool enableLoad)
Expand Down
6 changes: 3 additions & 3 deletions doomsday/libdeng2/game.pri
@@ -1,14 +1,14 @@
publicHeaders(game, \
include/de/game/Game \
include/de/game/SavedSession \
include/de/game/SavedSessionRepository \
include/de/game/Session \
\
include/de/game/game.h \
include/de/game/savedsession.h \
include/de/game/savedsessionrepository.h \
include/de/game/session.h \
)

SOURCES += \
src/game/game.cpp \
src/game/savedsession.cpp \
src/game/savedsessionrepository.cpp
src/game/session.cpp
1 change: 0 additions & 1 deletion doomsday/libdeng2/include/de/game/SavedSessionRepository

This file was deleted.

1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/game/Session
@@ -0,0 +1 @@
#include "session.h"
85 changes: 0 additions & 85 deletions doomsday/libdeng2/include/de/game/savedsessionrepository.h

This file was deleted.

0 comments on commit 2e79bb8

Please sign in to comment.