-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPkSessionManager.java
More file actions
86 lines (86 loc) · 2.99 KB
/
Copy pathPkSessionManager.java
File metadata and controls
86 lines (86 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//package SyncFrame;
//
//import org.apache.logging.log4j.LogManager;
//import org.apache.logging.log4j.Logger;
//
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.*;
//
//public class PkSessionManager {
//
// public static PkSessionManager manager = new PkSessionManager();
//
// private static Logger log = LogManager.getLogger("PkSessionManager");
// /**
// * 单线程定时驱动
// */
// private ScheduledExecutorService sec = Executors.newSingleThreadScheduledExecutor();
// /**
// * 处理帧逻辑的线程池
// */
// private ExecutorService es = Executors.newFixedThreadPool(30);
//
// private Map<Integer, PkSession> pkSessionMap = new ConcurrentHashMap<Integer, PkSession>();
//
// {
// sec.scheduleAtFixedRate(new Runnable() {
// @Override
// public void run() {
// try {
// runFrame();
// } catch (Throwable th) {
// log.error("pkSessionManager.runFrame|error", th);
// }
//
// }
// }, 33000, 33000, TimeUnit.MICROSECONDS);// 每秒30帧驱动,客户端也设置相同帧率
// }
//
// /**
// * 对所有战斗会话进行服务器帧驱动
// */
// private void runFrame() {
// final long now = System.currentTimeMillis();
// for (final PkSession pkSession : pkSessionMap.values()) {
// es.submit(new Runnable() {
// @Override
// public void run() {
// try {
// // 一场战斗不可能超过20分钟
// if (now - pkSession.getCreateTime() > 1000L * 60 * 30) {
// pkSessionMap.remove(pkSession.getSessionId());
// log.warn("pkSession|timeout|for|" + pkSession);
// }
// pkSession.runFrame();
// } catch (Throwable th) {
// log.error("pkSession.runFrame|error|sessionId"+pkSession.getSessionId(), th);
// }
// }
// });
// }
// }
//
// public PkSession startPkSession(List<PkPlayer> pkPlayers) {
// //TODO 根据自己的规则生成sessionId,这里为了演示随便生成一个
// int sessionId = (int)System.currentTimeMillis();
// PkSession pkSession = new PkSession(sessionId);
// pkSession.setPkPlayers(pkPlayers);
// pkSessionMap.put(pkSession.getSessionId(), pkSession);
// log.info("startPkSession|" + sessionId + "|" + pkSession);
// return pkSession;
// }
//
// public boolean stopPkSession(int sessionId) {
// PkSession pkSession = getPkSession(sessionId);
// if (pkSession != null) {
// pkSession.stopSession();
// pkSessionMap.remove(sessionId);
// }
// return false;
// }
//
// public PkSession getPkSession(int sessionId) {
// return pkSessionMap.get(sessionId);
// }
//}