Skip to content

Commit

Permalink
Refactor|World|libdoomsday: Moved EntityDatabase/Def, World::map() to…
Browse files Browse the repository at this point in the history
… libdoomsday

Continuing the work of cleaning up the architecture: moved basic
basic common components to libdoomsday.
  • Loading branch information
skyjake committed Jan 20, 2016
1 parent 7581276 commit 4e8f185
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 103 deletions.
6 changes: 1 addition & 5 deletions doomsday/apps/client/include/m_nodepile.h
@@ -1,4 +1,4 @@
/** @file
/** @file m_nodepile.h Specialized Node Allocation
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2009-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,10 +17,6 @@
* http://www.gnu.org/licenses</small>
*/

/*
* m_nodepile.h: Specialized Node Allocation
*/

#ifndef __DOOMSDAY_NODEPILE_H__
#define __DOOMSDAY_NODEPILE_H__

Expand Down
7 changes: 0 additions & 7 deletions doomsday/apps/client/include/world/clientserverworld.h
Expand Up @@ -79,15 +79,8 @@ class ClientServerWorld : public World
*/
void update();

/**
* Returns @c true if a map is currently loaded.
*/
bool hasMap() const;

/**
* Provides access to the currently loaded map.
*
* @see hasMap()
*/
de::Map &map() const;

Expand Down
6 changes: 0 additions & 6 deletions doomsday/apps/client/include/world/map.h
Expand Up @@ -67,7 +67,6 @@ class BiasTracker;
namespace de {

class Blockmap;
class EntityDatabase;
#ifdef __CLIENT__
class LightGrid;
#endif
Expand Down Expand Up @@ -626,11 +625,6 @@ class Map : public world::Map

public: // Data structures -------------------------------------------------------

/**
* Provides access to the entity database.
*/
EntityDatabase &entityDatabase() const;

/**
* Provides access to the primary @ref Mesh geometry owned by the map. Note that
* further meshes may be assigned to individual elements of the map should their
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -62,6 +62,7 @@
#include <doomsday/help.h>
#include <doomsday/paths.h>
#include <doomsday/library.h>
#include <doomsday/world/entitydef.h>

#ifdef __CLIENT__
# include "clientapp.h"
Expand All @@ -78,7 +79,6 @@
#include "gl/svg.h"

#include "world/clientserverworld.h"
#include "world/entitydef.h"
#include "world/map.h"
#include "world/p_players.h"

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/world/api_map.cpp
Expand Up @@ -30,12 +30,12 @@
#include <de/memoryzone.h>
#include <doomsday/filesys/fs_main.h>
#include <doomsday/resource/mapmanifest.h>
#include <doomsday/EntityDatabase>

#include "network/net_main.h"

#include "world/blockmap.h"
#include "world/dmuargs.h"
#include "world/entitydatabase.h"
#include "world/linesighttest.h"
#include "world/maputil.h"
#include "world/p_players.h"
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/world/api_mapedit.cpp
Expand Up @@ -25,15 +25,15 @@
#include <de/Error>
#include <de/Log>
#include <de/StringPool>
#include "dd_main.h"
#include <doomsday/world/entitydef.h>
#include <doomsday/EntityDatabase>

#include "world/entitydatabase.h"
#include "dd_main.h"
#include "world/map.h"
#include "world/polyobjdata.h"
#include "Plane"
#include "Sector"
#include "Surface"

#include "edit_map.h"

using namespace de;
Expand Down
44 changes: 22 additions & 22 deletions doomsday/apps/client/src/world/clientserverworld.cpp
Expand Up @@ -303,8 +303,6 @@ DENG2_PIMPL(ClientServerWorld)
{
Binder binder; ///< Doomsday Script bindings for the World.
Record worldModule;

Map *map = nullptr; ///< Current map.
Record fallbackMapInfo; ///< Used when no effective MapInfo definition.

timespan_t time = 0; ///< World-wide time.
Expand Down Expand Up @@ -452,10 +450,10 @@ DENG2_PIMPL(ClientServerWorld)
/**
* Replace the current map with @a map.
*/
void makeCurrent(Map *newMap)
void makeCurrent(Map *map)
{
// This is now the current map (if any).
map = newMap;
self.setMap(map);
if(!map) return;

// We cannot make an editable map current.
Expand Down Expand Up @@ -688,6 +686,8 @@ DENG2_PIMPL(ClientServerWorld)
/// @todo Split this into subtasks (load, make current, cache assets).
bool changeMap(res::MapManifest *mapManifest = nullptr)
{
Map *map = self.mapPtr();

#ifdef __CLIENT__
if(map)
{
Expand All @@ -706,7 +706,9 @@ DENG2_PIMPL(ClientServerWorld)
#ifdef __CLIENT__
R_DestroyContactLists();
#endif
delete map; map = nullptr;
delete map;
self.setMap(nullptr);

Z_FreeTags(PU_MAP, PU_PURGELEVEL - 1);

// Are we just unloading the current map?
Expand Down Expand Up @@ -744,13 +746,13 @@ DENG2_PIMPL(ClientServerWorld)
// Output a human-readable report of any issues encountered during conversion.
reporter.writeLog();

return map != nullptr;
return self.hasMap();
}

#ifdef __CLIENT__
void updateHandOrigin()
{
DENG2_ASSERT(hand != nullptr && map != nullptr);
DENG2_ASSERT(hand != nullptr && self.hasMap());

viewdata_t const *viewData = &::viewPlayer->viewport();
hand->setOrigin(viewData->current.origin + viewData->frontVec.xzy() * handDistance);
Expand All @@ -771,16 +773,14 @@ ClientServerWorld::ClientServerWorld()
, d(new Instance(this))
{}

bool ClientServerWorld::hasMap() const
{
return d->map != nullptr;
}

Map &ClientServerWorld::map() const
{
if(d->map) return *d->map;
/// @throw MapError Attempted with no map loaded.
throw MapError("ClientServerWorld::map", "No map is currently loaded");
if(!hasMap())
{
/// @throw MapError Attempted with no map loaded.
throw MapError("ClientServerWorld::map", "No map is currently loaded");
}
return World::map().as<de::Map>();
}

bool ClientServerWorld::changeMap(de::Uri const &mapUri)
Expand Down Expand Up @@ -838,9 +838,9 @@ void ClientServerWorld::update()
});

// Update the current map, also.
if(d->map)
if(hasMap())
{
d->map->update();
map().update();
}
}

Expand Down Expand Up @@ -876,13 +876,13 @@ timespan_t ClientServerWorld::time() const
void ClientServerWorld::tick(timespan_t elapsed)
{
#ifdef __CLIENT__
if(d->map)
if(hasMap())
{
d->map->skyAnimator().advanceTime(elapsed);
map().skyAnimator().advanceTime(elapsed);

if(DD_IsSharpTick())
{
d->map->thinkers().forAll(reinterpret_cast<thinkfunc_t>(gx.MobjThinker), 0x1, [] (thinker_t *th)
map().thinkers().forAll(reinterpret_cast<thinkfunc_t>(gx.MobjThinker), 0x1, [] (thinker_t *th)
{
Mobj_AnimateHaloOcclussion(*reinterpret_cast<mobj_t *>(th));
return LoopContinue;
Expand All @@ -902,7 +902,7 @@ Hand &ClientServerWorld::hand(coord_t *distance) const
{
d->hand.reset(new Hand());
audienceForFrameEnd() += *d->hand;
if(d->map)
if(hasMap())
{
d->updateHandOrigin();
}
Expand All @@ -922,7 +922,7 @@ void ClientServerWorld::beginFrame(bool resetNextViewer)

void ClientServerWorld::endFrame()
{
if(d->map && d->hand)
if(hasMap() && d->hand)
{
d->updateHandOrigin();

Expand Down
8 changes: 1 addition & 7 deletions doomsday/apps/client/src/world/map.cpp
Expand Up @@ -35,6 +35,7 @@
#include <de/Rectangle>
#include <doomsday/defs/mapinfo.h>
#include <doomsday/defs/sky.h>
#include <doomsday/EntityDatabase>

#ifdef __CLIENT__
# include "clientapp.h"
Expand All @@ -51,7 +52,6 @@
#include "world/clientserverworld.h" // ddMapSetup, validCount
#include "world/blockmap.h"
#include "world/lineblockmap.h"
#include "world/entitydatabase.h"
#include "world/lineowner.h"
#include "world/p_object.h"
#include "world/polyobjdata.h"
Expand Down Expand Up @@ -164,7 +164,6 @@ DENG2_PIMPL(Map)
//
std::unique_ptr<Thinkers> thinkers;
Sky sky;
EntityDatabase entityDatabase;

std::unique_ptr<Blockmap> mobjBlockmap;
std::unique_ptr<Blockmap> polyobjBlockmap;
Expand Down Expand Up @@ -2395,11 +2394,6 @@ bool Map::identifySoundEmitter(SoundEmitter const &emitter, Sector **sector,
return (*sector != 0 || *poly != 0|| *plane != 0|| *surface != 0);
}

EntityDatabase &Map::entityDatabase() const
{
return d->entityDatabase;
}

void Map::initNodePiles()
{
LOG_AS("Map");
Expand Down
File renamed without changes.
Expand Up @@ -17,17 +17,15 @@
* 02110-1301 USA</small>
*/

#ifndef DENG_WORLD_ENTITYDATABASE_H
#define DENG_WORLD_ENTITYDATABASE_H
#ifndef LIBDOOMSDAY_WORLD_ENTITYDATABASE_H
#define LIBDOOMSDAY_WORLD_ENTITYDATABASE_H

#include <de/libcore.h>
#include <de/Error>

#include "api_mapedit.h" // valuetype_t
#include "world/entitydef.h"
#include "world/propertyvalue.h"

namespace de {
#include "valuetype.h"
#include "entitydef.h"
#include "propertyvalue.h"

/**
* An EntityDatabase is used in the process of transferring mobj spawn spot
Expand Down Expand Up @@ -87,6 +85,4 @@ class EntityDatabase
DENG2_PRIVATE(d)
};

} // namespace de

#endif // DENG_WORLD_ENTITYDATABASE_H
#endif // LIBDOOMSDAY_WORLD_ENTITYDATABASE_H
Expand Up @@ -18,12 +18,11 @@
* 02110-1301 USA</small>
*/

#ifndef DENG_WORLD_ENTITYDEF_H
#define DENG_WORLD_ENTITYDEF_H
#ifndef LIBDOOMSDAY_WORLD_ENTITYDEF_H
#define LIBDOOMSDAY_WORLD_ENTITYDEF_H

#include "dd_share.h"
#include "api_mapedit.h"
#include "m_nodepile.h"
#include <de/binangle.h>
#include <de/vector1.h>

Expand Down Expand Up @@ -130,4 +129,4 @@ void P_ShutdownMapEntityDefs();
} // extern "C"
#endif

#endif // DENG_WORLD_ENTITYDEF_H
#endif // LIBDOOMSDAY_WORLD_ENTITYDEF_H
9 changes: 9 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/world/map.h
Expand Up @@ -24,6 +24,8 @@
#include <de/Error>
#include <de/Observers>

class EntityDatabase;

namespace world {

/**
Expand Down Expand Up @@ -65,6 +67,13 @@ class LIBDOOMSDAY_PUBLIC Map
*/
void setManifest(res::MapManifest *newManifest);

/**
* Provides access to the entity database.
*/
EntityDatabase &entityDatabase() const;

DENG2_AS_IS_METHODS()

public:
/// Notified when the map is about to be deleted.
DENG2_DEFINE_AUDIENCE2(Deletion, void mapBeingDeleted(Map const &map))
Expand Down
Expand Up @@ -22,10 +22,12 @@
* 02110-1301 USA</small>
*/

#ifndef DENG_DATA_PROPERTYVALUE_H
#define DENG_DATA_PROPERTYVALUE_H
#ifndef LIBDOOMSDAY_WORLD_PROPERTYVALUE_H
#define LIBDOOMSDAY_WORLD_PROPERTYVALUE_H

#include "de_base.h"
#include "valuetype.h"
#include <de/types.h>
#include <de/fixedpoint.h>

class PropertyValue
{
Expand Down Expand Up @@ -179,4 +181,4 @@ class PropertyFloatValue : public PropertyValue
*/
PropertyValue* BuildPropertyValue(valuetype_t type, void* valueAdr);

#endif // DENG_DATA_PROPERTYVALUE_H
#endif // LIBDOOMSDAY_WORLD_PROPERTYVALUE_H
17 changes: 17 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/world/world.h
Expand Up @@ -24,6 +24,8 @@
#include <de/Observers>
#include <de/System>

namespace world { class Map; }

/**
* Base class for the game world.
*
Expand All @@ -39,9 +41,24 @@ class LIBDOOMSDAY_PUBLIC World : public de::System

virtual void reset();

/**
* Returns @c true if a map is currently loaded.
*/
bool hasMap() const;

/**
* Provides access to the currently loaded map.
*
* @see hasMap()
*/
world::Map &map() const;

// Systems observe the passage of time.
void timeChanged(de::Clock const &) override;

protected:
void setMap(world::Map *map);

public:
/// Notified whenever the "current" map changes.
DENG2_DEFINE_AUDIENCE2(MapChange, void worldMapChanged())
Expand Down

0 comments on commit 4e8f185

Please sign in to comment.