SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GameCommandList.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2018 SEGS Team (see Authors.txt)
5  * This software is licensed! (See License.txt for details)
6  */
7 
8 #pragma once
9 
10 #include "MapEventTypes.h"
11 #include "MapLink.h"
12 
13 class QString;
14 //TODO: those must support chaining
16 {
17  const uint32_t m_type;
18 public:
19  GameCommand(uint32_t type) : m_type(type) {}
20 virtual ~GameCommand() = default;
21  uint32_t type() const {return m_type;}
22 virtual void serializeto(BitStream &bs) const = 0;
23 };
24 
26 {
27  std::vector<std::unique_ptr<GameCommand> > m_contents;
28 public:
29  PreUpdateCommand() : MapLinkEvent(MapEventTypes::evPreUpdateCommand) {}
30  template <typename... Commands>
31  PreUpdateCommand(Commands &&... items) : PreUpdateCommand()
32  {
33  std::unique_ptr<GameCommand> cmdArr[] = {std::unique_ptr<GameCommand>(std::move(items))...};
34  m_contents = std::vector<std::unique_ptr<GameCommand>>{std::make_move_iterator(std::begin(cmdArr)),
35  std::make_move_iterator(std::end(cmdArr))};
36  }
37 
38  void serializeto(BitStream &bs) const
39  {
40  bs.StorePackedBits(1, 13);
41  for(const auto &command : m_contents)
42  command->serializeto(bs);
43  bs.StorePackedBits(1,0); // finalize the command list
44  }
45  void serializefrom(BitStream &/*src*/)
46  {
47  assert(false);
48  // TODO: trouble, we need a second GameCommand Factory at this point !
49  //uint32_t game_command = src.GetPackedBits(1);
50  }
51 };
52 #include "Events/ChatMessage.h"
54 #include "Events/InfoMessageCmd.h"
55 #include "Events/FloatingDamage.h"
PreUpdateCommand(Commands &&...items)
Definition: GameCommandList.h:31
Definition: BitStream.h:30
void serializeto(BitStream &bs) const
Definition: GameCommandList.h:38
void StorePackedBits(uint32_t nBits, uint32_t dataBits)
Definition: BitStream.cpp:161
GameCommand(uint32_t type)
Definition: GameCommandList.h:19
uint32_t type() const
Definition: GameCommandList.h:21
virtual void serializeto(BitStream &bs) const =0
Definition: GameCommandList.h:25
Definition: GameCommandList.h:15
PreUpdateCommand()
Definition: GameCommandList.h:29
Definition: MapEventTypes.h:11
void serializefrom(BitStream &)
Definition: GameCommandList.h:45
virtual ~GameCommand()=default