Added:
/trunk/gunz/src/ChannelTraits.cpp
/trunk/gunz/src/MatchMaker.cpp
Deleted:
/trunk/gunz/src/Channel.cpp
/trunk/gunz/src/ChannelList.cpp
/trunk/include/gunz/Channel.h
/trunk/include/gunz/ChannelList.h
/trunk/include/gunz/Player.h
Modified:
/trunk/gunz/src/CMakeLists.txt
/trunk/include/gunz/simple_types.h
=======================================
--- /dev/null
+++ /trunk/gunz/src/ChannelTraits.cpp Mon Jun 28 16:57:36 2010
@@ -0,0 +1,62 @@
+#include <gunz/ChannelTraits.h>
+
+using namespace std;
+using namespace boost;
+
+namespace gunz {
+
+ChannelTraits::ChannelTraits()
+ : uid(0),
+ name("<<unnamed>>"),
+ maxPlayers(200),
+ rule(CR_ELITE),
+ type(CT_GENERAL),
+ minLevel(0),
+ maxLevel(255)
+{
+}
+
+ChannelTraits::ChannelTraits(
+ MUID _uid,
+ const string& _name,
+ uint32_t _maxPlayers,
+ ChannelRule _rule,
+ ChannelType _type,
+ uint8_t _minLevel,
+ uint8_t _maxLevel)
+ : uid(_uid),
+ name(_name),
+ maxPlayers(_maxPlayers),
+ rule(_rule),
+ type(_type),
+ minLevel(_minLevel),
+ maxLevel(_maxLevel)
+{
+}
+
+ChannelTraits::ChannelTraits(const ChannelTraits& other)
+ : uid(other.uid),
+ name(other.name),
+ maxPlayers(other.maxPlayers),
+ rule(other.rule),
+ type(other.type),
+ minLevel(other.minLevel),
+ maxLevel(other.maxLevel)
+{
+}
+
+bool ChannelTraits::operator<(const ChannelTraits& other) const
+{
+ return uid < other.uid;
+}
+
+bool ChannelTraits::operator==(const ChannelTraits& other) const
+{
+ return uid == other.uid;
+}
+
+ChannelTraits::~ChannelTraits()
+{
+}
+
+}
=======================================
--- /dev/null
+++ /trunk/gunz/src/MatchMaker.cpp Mon Jun 28 16:57:36 2010
@@ -0,0 +1,76 @@
+#include <gunz/MatchMaker.h>
+#include <gunz/ChannelTraits.h>
+#include <gunz/simple_types.h>
+
+#include <util/SmallVector.h>
+
+#include <cstddef>
+#include <cassert>
+#include <algorithm>
+
+#include <boost/thread/shared_mutex.hpp>
+
+using namespace std;
+using namespace boost;
+
+typedef lock_guard<shared_mutex> ExclusiveLock;
+typedef shared_lock<shared_mutex> SharedLock;
+
+namespace gunz {
+
+struct MatchMaker::Data
+{
+ // This mutex protects ALL accesses through MatchMaker. Use it wisely.
+ mutable shared_mutex lock;
+
+ SmallVector<ChannelTraits, 32> channels;
+ MUIDSanta* santa;
+};
+
+MatchMaker::MatchMaker(MUIDSanta* santa)
+ : d(new Data)
+{
+ assert(santa);
+ d->santa = santa;
+}
+
+void MatchMaker::add_channel(const ChannelTraits& traits)
+{
+ ExclusiveLock e(d->lock);
+ d->channels.push_back(traits);
+}
+
+void MatchMaker::remove_channel(MUID muid)
+{
+ ChannelTraits t;
+ t.uid = muid;
+
+ ChannelTraits* location = NULL;
+ ChannelTraits* end = NULL;
+ {
+ SharedLock s(d->lock);
+ location = find(d->channels.begin(), (end = d->channels.end()), t);
+ }
+
+ assert(location);
+ assert(end);
+
+ if(location == NULL || end == NULL || location == end)
+ return;
+
+ ExclusiveLock e(d->lock);
+ d->channels.erase(location);
+}
+
+vector<ChannelTraits> MatchMaker::get_channel_list() const
+{
+ SharedLock s(d->lock);
+ return vector<ChannelTraits>(d->channels.begin(), d->channels.end());
+}
+
+MatchMaker::~MatchMaker()
+{
+ delete d;
+}
+
+}
=======================================
--- /trunk/gunz/src/Channel.cpp Mon Jun 28 08:53:44 2010
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <gunz/Channel.h>
-
-namespace gunz {
-
-// TODO(Clark): Channel implementation.
-
-}
-
=======================================
--- /trunk/gunz/src/ChannelList.cpp Mon Jun 28 08:53:44 2010
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <gunz/ChannelList.h>
-
-using namespace std;
-using namespace boost;
-
-namespace gunz {
-
-vector<const Channel*> ChannelList::get_some(function<bool (const
Channel*)> predicate) const
-{
- vector<const Channel*> ret(activeChannels.size());
-
- for(CList::const_iterator i = activeChannels.begin(), end =
activeChannels.end(); i != end; ++i)
- {
- const Channel* current = &(*i); // That's right!
- if(predicate(current))
- ret.push_back(current);
- }
-
- return ret;
-}
-
-const vector<Channel*>* ChannelList::get_all() const
-{
- return &shortcut;
-}
-
-ChannelList::~ChannelList()
-{
-}
-
-}
=======================================
--- /trunk/include/gunz/Channel.h Mon Jun 28 08:53:44 2010
+++ /dev/null
@@ -1,60 +0,0 @@
-#pragma once
-#include <gunz/simple_types.h>
-
-namespace gunz {
-
-// TODO(Clark): Flesh this out.
-class Channel
-{
-public:
- /*
- NECESSARY METHODS:
- + void Join(Player*)
- - Adds the player to the current channel list, ensuring they
- recieve updates for chats.
-
- + void Leave(Player*)
- - Removes the player from the channel list. They will no longer
- recieve chat updates.
-
- + void Chat(Player* speaker, const char* message)
- - Sends a chat message to the whole channel, from "speaker".
-
- + ChannelRule GetRule() const
- - Returns the "rule" for the channel. I'm still not totally
- sure what this means. Talk to Jacob.
-
- + ChannelType GetType() const
- - Returns whether the channel is one of CT_GENERAL, CT_PRIVATE,
- CT_USER, or CT_CLAN.
-
- + std::vector<PlayerTraits> GetPlayerList() const
- - Returns a player list, return information on each player
- currently in the channel. The reason raw Player*s aren't used
- is that the answer to this question can't be answered:
- "What happens if a player disconnects and is deleted?"
-
- + Stage* CreateStage(Player* stageMaster, const std::string& name,
const std::string& password)
- - Creates a stage with the name and password. If the password
- is blank, the stage is considered open. A pointer to the
- newly created stage is then returned. stageMaster is
- automagically added to the stage as the stageMaster.
-
- + Stage* JoinStage(MUID stageID, const std::string& password)
- - Joins a stage with the requested name and password. Returns
- NULL if the stageID isn't valid, or the password doesn't
- match.
-
- + Stage* JoinRandomStage()
- - Returns a valid stage that the player will be placed in.
- Password-protected and full stages are skipped. If a valid
- stage cannot be found, NULL is returned.
-
- DEPENDENCIES:
- PlayerTraits
- Player
- Stage
- */
-};
-
-}
=======================================
--- /trunk/include/gunz/ChannelList.h Mon Jun 28 08:53:44 2010
+++ /dev/null
@@ -1,61 +0,0 @@
-#pragma once
-#include <gunz/Channel.h>
-
-#include <boost/noncopyable.hpp>
-#include <boost/function.hpp>
-
-#include <algorithm>
-#include <vector>
-
-#include <util/SmallVector.h>
-
-namespace gunz {
-
-class ChannelList : boost::noncopyable
-{
-private:
- typedef SmallVector<Channel, 16> CList;
- // By making this read-only, we remove our need for mutexing. The only
- // problem with this, though, is that each channel must now hold their own
- // mutex.
- CList activeChannels;
-
- // Provides a nice easy way to access all the channels in activeChannels,
- // without having to know how they're stored.
- std::vector<Channel*> shortcut;
-
-public:
- /**
- Constructs a channel list from a container of any type, by passing in
- that container's iterators. NOTE: It MUST be a container of Channel. I
- don't know why I have to explicitly mention that, but I like to think
- it's good to know.
- */
- template <typename IteratorType>
- ChannelList(const IteratorType& begin, const IteratorType& end)
- : activeChannels(begin, end)
- {
- shortcut.reserve(activeChannels.size());
- for(CList::iterator i = activeChannels.begin(), end =
activeChannels.end(); i != end; ++i)
- shortcut.push_back(&(*i));
- }
-
- /**
- Returns a vector of channels for every channel for which the predicate
- holds.
-
- @param predicate When this returns true, the parameter will be one of
- the returned channels.
-
- @return A full list of every channel for which the predicate held true.
- */
- std::vector<const Channel*> get_some(boost::function<bool (const
Channel*)> predicate) const;
-
- /// Returns pointers to every single channel. Please try to avoid using
- /// this function in favor of get() as much as possible.
- const std::vector<Channel*>* get_all() const;
-
- ~ChannelList();
-};
-
-}
=======================================
--- /trunk/include/gunz/Player.h Mon Jun 28 08:53:44 2010
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-#include <string>
-
-namespace gunz {
-
-class Player
-{
-public:
- virtual void HandleChannelMessage(const std::string& speaker, const
std::string& message) = 0;
- virtual void HandleGameMessage(const std::string& speaker, const
std::string& message) = 0;
-};
-
-}
=======================================
--- /trunk/gunz/src/CMakeLists.txt Sun Jun 27 09:06:30 2010
+++ /trunk/gunz/src/CMakeLists.txt Mon Jun 28 16:57:36 2010
@@ -1,10 +1,13 @@
set(GUNZ_SRC
- Channel.cpp
- ChannelList.cpp
+ ChannelTraits.cpp
+ MatchMaker.cpp
MUIDSanta.cpp
PlayerTraits.cpp
# More sources here!
)
add_library(gunz ${GUNZ_SRC})
-target_link_libraries(gunz ${Boost_LIBRARIES})
+target_link_libraries(gunz
+ util
+ ${Boost_LIBRARIES}
+)
=======================================
--- /trunk/include/gunz/simple_types.h Mon Jun 28 08:53:44 2010
+++ /trunk/include/gunz/simple_types.h Mon Jun 28 16:57:36 2010
@@ -66,8 +66,7 @@
CT_GENERAL,
CT_PRIVATE,
CT_USER,
- CT_CLAN,
- CT_NONE = 255
+ CT_CLAN
};
enum ChannelRule