ユーザ入力の処理ハンドラを追加
@@ -0,0 +1,90 @@ | ||
1 | +/*! | |
2 | + \file | |
3 | + \brief ユーザ入力の受け付け | |
4 | + | |
5 | + \author Satofumi KAMIMURA | |
6 | + | |
7 | + $Id$ | |
8 | +*/ | |
9 | + | |
10 | +#include "UserInput.h" | |
11 | +#include "TcpipSocket.h" | |
12 | + | |
13 | +using namespace qrk; | |
14 | + | |
15 | + | |
16 | +struct UserInput::pImpl | |
17 | +{ | |
18 | + TcpipSocket* socket_; | |
19 | + bool disconnected_; | |
20 | + | |
21 | + | |
22 | + pImpl(TcpipSocket* socket) : socket_(socket), disconnected_(false) | |
23 | + { | |
24 | + } | |
25 | +}; | |
26 | + | |
27 | + | |
28 | +UserInput::UserInput(TcpipSocket* socket) : pimpl(new pImpl(socket)) | |
29 | +{ | |
30 | +} | |
31 | + | |
32 | + | |
33 | +UserInput::~UserInput(void) | |
34 | +{ | |
35 | +} | |
36 | + | |
37 | + | |
38 | +bool UserInput::isChanged(void) | |
39 | +{ | |
40 | + // TcpipSocket を評価して、適切なデータを受信したら true を返す | |
41 | + enum { | |
42 | + BufferSize = 1024, | |
43 | + }; | |
44 | + char buffer[BufferSize]; | |
45 | + | |
46 | + int n = pimpl->socket_->receive(buffer, BufferSize, 0); | |
47 | + if (n < 0) { | |
48 | + pimpl->disconnected_ = true; | |
49 | + return true; | |
50 | + } | |
51 | + | |
52 | + // 受信データのパースと登録 | |
53 | + // !!! | |
54 | + | |
55 | + return false; | |
56 | +} | |
57 | + | |
58 | + | |
59 | +bool UserInput::disconnected(void) | |
60 | +{ | |
61 | + return pimpl->disconnected_; | |
62 | +} | |
63 | + | |
64 | + | |
65 | +void UserInput::command(const std::string& command) | |
66 | +{ | |
67 | + (void)command; | |
68 | + // !!! | |
69 | +} | |
70 | + | |
71 | + | |
72 | +void UserInput::moveTarget(const Point<long>& point) | |
73 | +{ | |
74 | + (void)point; | |
75 | + // !!! | |
76 | +} | |
77 | + | |
78 | + | |
79 | +void UserInput::attackTarget(const Point<long>& point) | |
80 | +{ | |
81 | + (void)point; | |
82 | + // !!! | |
83 | +} | |
84 | + | |
85 | + | |
86 | +void UserInput::chatMessage(const std::string& message) | |
87 | +{ | |
88 | + (void)message; | |
89 | + // !!! | |
90 | +} |
@@ -10,6 +10,7 @@ | ||
10 | 10 | $Id$ |
11 | 11 | */ |
12 | 12 | |
13 | + | |
13 | 14 | class Character |
14 | 15 | { |
15 | 16 | public: |
@@ -8,10 +8,87 @@ | ||
8 | 8 | */ |
9 | 9 | |
10 | 10 | #include "Users.h" |
11 | +#include "UserInput.h" | |
12 | +#include "TcpipAccepter.h" | |
13 | +#include <vector> | |
11 | 14 | |
15 | +using namespace qrk; | |
16 | +using namespace std; | |
12 | 17 | |
18 | + | |
19 | +typedef vector<UserInput*> UserInputs; | |
20 | + | |
21 | +struct Users::pImpl | |
22 | +{ | |
23 | + TcpipAccepter tcpip_accepter_; | |
24 | + UserInputs users_; | |
25 | + | |
26 | + | |
27 | + void acceptNewConnection(void) | |
28 | + { | |
29 | + TcpipSocket* socket = tcpip_accepter_.accept(); | |
30 | + if (! socket) { | |
31 | + // 新規接続なし | |
32 | + return; | |
33 | + } | |
34 | + | |
35 | + // !!! users_ 中に同じキャラクタ ID が自動操作で存在したら、 | |
36 | + // !!! そのキャラクタ ID を使うようにする | |
37 | + | |
38 | + // !!! キャラクタと操作を結びつける何かの設定 | |
39 | + | |
40 | + users_.push_back(new UserInput(socket)); | |
41 | + } | |
42 | +}; | |
43 | + | |
44 | + | |
45 | +Users::Users(void) : pimpl(new pImpl) | |
46 | +{ | |
47 | +} | |
48 | + | |
49 | + | |
50 | +Users::~Users(void) | |
51 | +{ | |
52 | +} | |
53 | + | |
54 | + | |
55 | +bool Users::acitvate(unsigned short port) | |
56 | +{ | |
57 | + return pimpl->tcpip_accepter_.activate(port); | |
58 | +} | |
59 | + | |
60 | + | |
13 | 61 | void Users::update(EventManager& event_manager) |
14 | 62 | { |
63 | + // 新規接続の追加 | |
64 | + pimpl->acceptNewConnection(); | |
65 | + | |
66 | + // 既存のユーザ処理 | |
67 | + for (UserInputs::iterator it = pimpl->users_.begin(); | |
68 | + it != pimpl->users_.end(); ++it) { | |
69 | + if (! (*it)->isChanged()) { | |
70 | + continue; | |
71 | + } | |
72 | + | |
73 | + if ((*it)->disconnected()) { | |
74 | + if (0) { | |
75 | + // 手動操作のときは、キャラクタの帰宅するよう設定する | |
76 | + // !!! | |
77 | + } | |
78 | + | |
79 | + // ユーザ操作の切断処理 | |
80 | + swap(*it, pimpl->users_.back()); | |
81 | + pimpl->users_.pop_back(); | |
82 | + --it; | |
83 | + continue; | |
84 | + } | |
85 | + | |
86 | + // !!! - キャラクター作成まわり | |
87 | + // !!! - マップ内の移動 | |
88 | + // !!! - アイテムの売買 | |
89 | + } | |
90 | + | |
91 | + // イベントの更新 | |
15 | 92 | (void)event_manager; |
16 | 93 | // !!! |
17 | 94 | } |
@@ -0,0 +1,45 @@ | ||
1 | +#ifndef USER_INPUT_H | |
2 | +#define USER_INPUT_H | |
3 | + | |
4 | +/*! | |
5 | + \file | |
6 | + \brief ユーザ入力の受け付け | |
7 | + | |
8 | + \author Satofumi KAMIMURA | |
9 | + | |
10 | + $Id$ | |
11 | +*/ | |
12 | + | |
13 | +#include "Input.h" | |
14 | +#include <memory> | |
15 | + | |
16 | + | |
17 | +namespace qrk | |
18 | +{ | |
19 | + class TcpipSocket; | |
20 | +} | |
21 | + | |
22 | + | |
23 | +class UserInput : public Input | |
24 | +{ | |
25 | +public: | |
26 | + UserInput(qrk::TcpipSocket* socket); | |
27 | + ~UserInput(void); | |
28 | + | |
29 | + bool isChanged(void); | |
30 | + bool disconnected(void); | |
31 | + void command(const std::string& command); | |
32 | + void moveTarget(const qrk::Point<long>& point); | |
33 | + void attackTarget(const qrk::Point<long>& point); | |
34 | + void chatMessage(const std::string& message); | |
35 | + | |
36 | +private: | |
37 | + UserInput(void); | |
38 | + UserInput(const UserInput& rhs); | |
39 | + UserInput& operator = (const UserInput& rhs); | |
40 | + | |
41 | + struct pImpl; | |
42 | + std::auto_ptr<pImpl> pimpl; | |
43 | +}; | |
44 | + | |
45 | +#endif /* !USER_INPUT_H */ |
@@ -10,6 +10,10 @@ | ||
10 | 10 | $Id$ |
11 | 11 | */ |
12 | 12 | |
13 | +#include "Point.h" | |
14 | +#include <string> | |
15 | + | |
16 | + | |
13 | 17 | class Input |
14 | 18 | { |
15 | 19 | public: |
@@ -17,7 +21,17 @@ | ||
17 | 21 | { |
18 | 22 | } |
19 | 23 | |
20 | - // !!! | |
24 | + | |
25 | + virtual bool isChanged(void) = 0; | |
26 | + | |
27 | + virtual bool disconnected(void) = 0; | |
28 | + | |
29 | + virtual void command(const std::string& command) = 0; | |
30 | + | |
31 | + virtual void moveTarget(const qrk::Point<long>& point) = 0; | |
32 | + virtual void attackTarget(const qrk::Point<long>& point) = 0; | |
33 | + | |
34 | + virtual void chatMessage(const std::string& message) = 0; | |
21 | 35 | }; |
22 | 36 | |
23 | 37 | #endif /* !INPUT_H */ |
@@ -10,6 +10,8 @@ | ||
10 | 10 | $Id$ |
11 | 11 | */ |
12 | 12 | |
13 | +#include <memory> | |
14 | + | |
13 | 15 | class EventManager; |
14 | 16 | |
15 | 17 |
@@ -16,10 +18,20 @@ | ||
16 | 18 | class Users |
17 | 19 | { |
18 | 20 | public: |
19 | - // !!! | |
21 | + Users(void); | |
22 | + ~Users(void); | |
20 | 23 | |
24 | + bool acitvate(unsigned short port); | |
21 | 25 | |
22 | 26 | void update(EventManager& event_manager); |
27 | + | |
28 | + | |
29 | +private: | |
30 | + Users(const Users& rhs); | |
31 | + Users& operator = (const Users& rhs); | |
32 | + | |
33 | + struct pImpl; | |
34 | + std::auto_ptr<pImpl> pimpl; | |
23 | 35 | }; |
24 | 36 | |
25 | 37 | #endif /* !USERS_H */ |
@@ -22,7 +22,7 @@ | ||
22 | 22 | |
23 | 23 | namespace |
24 | 24 | { |
25 | - class Args | |
25 | + class ArgsInformation | |
26 | 26 | { |
27 | 27 | public: |
28 | 28 |
@@ -30,12 +30,12 @@ | ||
30 | 30 | }; |
31 | 31 | |
32 | 32 | |
33 | - Args parseArgs(int argc, char *argv[]) | |
33 | + ArgsInformation parseArgs(int argc, char *argv[]) | |
34 | 34 | { |
35 | 35 | (void)argc; |
36 | 36 | (void)argv; |
37 | 37 | |
38 | - Args args; | |
38 | + ArgsInformation args; | |
39 | 39 | // !!! |
40 | 40 | |
41 | 41 | return args; |
@@ -75,7 +75,7 @@ | ||
75 | 75 | |
76 | 76 | int main(int argc, char *argv[]) |
77 | 77 | { |
78 | - Args args = parseArgs(argc, argv); | |
78 | + ArgsInformation args = parseArgs(argc, argv); | |
79 | 79 | |
80 | 80 | WorldMap world_map; |
81 | 81 | if (! loadWorldMap(world_map)) { |
@@ -108,5 +108,6 @@ | ||
108 | 108 | } while (command_console.quit()); |
109 | 109 | |
110 | 110 | log_printf("Program exit normally."); |
111 | + | |
111 | 112 | return 0; |
112 | 113 | } |
@@ -22,6 +22,7 @@ | ||
22 | 22 | |
23 | 23 | void action(void); |
24 | 24 | |
25 | + | |
25 | 26 | private: |
26 | 27 | MoveEvent(const MoveEvent& rhs); |
27 | 28 | MoveEvent& operator = (const MoveEvent& rhs); |
@@ -17,6 +17,7 @@ | ||
17 | 17 | // !!! 種類毎の、破壊にかかるコスト |
18 | 18 | // !!! 破壊が指定されたときに表示されるメッセージ |
19 | 19 | |
20 | + | |
20 | 21 | GroundObject(void) |
21 | 22 | { |
22 | 23 | } |
@@ -4,9 +4,9 @@ | ||
4 | 4 | |
5 | 5 | CC = g++ |
6 | 6 | CXXFLAGS = -g -O0 -Wall -W -Werror $(INCLUDES) |
7 | -INCLUDES = -I$(LIB_DIR)/system | |
7 | +INCLUDES = -I$(LIB_DIR)/system -I$(LIB_DIR)/geometry -I$(LIB_DIR)/connection | |
8 | 8 | LDFLAGS = |
9 | -LDLIBS = `sdl-config --libs` | |
9 | +LDLIBS = `sdl-config --libs` -lSDL_net | |
10 | 10 | |
11 | 11 | |
12 | 12 | TARGET = mhack_server |
@@ -21,8 +21,8 @@ | ||
21 | 21 | |
22 | 22 | .PHONY : all clean depend |
23 | 23 | ###################################################################### |
24 | -OBJS = EventManager.o MoveEvent.o Users.o CommandConsole.o | |
25 | -REQUIRE_LIBS = $(LIB_DIR)/system/system.a $(LIB_DIR)/system/sdl/system_sdl.a | |
24 | +OBJS = EventManager.o MoveEvent.o Users.o UserInput.o CommandConsole.o | |
25 | +REQUIRE_LIBS = $(LIB_DIR)/connection/sdl/connection_sdl.a $(LIB_DIR)/system/system.a $(LIB_DIR)/system/sdl/system_sdl.a | |
26 | 26 | |
27 | 27 | $(REQUIRE_LIBS) : |
28 | 28 | cd $(@D)/ && $(MAKE) $(@F) |
@@ -35,12 +35,18 @@ | ||
35 | 35 | Dungeon.o: Floor.h GroundTile.h GroundObject.h Item.h |
36 | 36 | Floor.o: GroundTile.h GroundObject.h Item.h |
37 | 37 | GroundTile.o: GroundObject.h Item.h |
38 | +Input.o: ../../../libs/geometry/Point.h | |
38 | 39 | MoveEvent.o: Event.h |
40 | +UserInput.o: Input.h ../../../libs/geometry/Point.h | |
39 | 41 | WorldMap.o: GroundTile.h GroundObject.h Item.h Dungeon.h Floor.h |
40 | 42 | CommandConsole.o: CommandConsole.h |
41 | 43 | EventManager.o: EventManager.h |
42 | 44 | MoveEvent.o: MoveEvent.h Event.h |
43 | -Users.o: Users.h | |
45 | +UserInput.o: UserInput.h Input.h ../../../libs/geometry/Point.h | |
46 | +UserInput.o: ../../../libs/connection/TcpipSocket.h | |
47 | +UserInput.o: ../../../libs/connection/Connection.h | |
48 | +Users.o: Users.h UserInput.h Input.h ../../../libs/geometry/Point.h | |
49 | +Users.o: ../../../libs/connection/TcpipAccepter.h | |
44 | 50 | mhack_server.o: WorldMap.h GroundTile.h GroundObject.h Item.h Dungeon.h |
45 | 51 | mhack_server.o: Floor.h Character.h EventManager.h Users.h CommandConsole.h |
46 | 52 | mhack_server.o: ../../../libs/system/CycleTimer.h |