File: LuaEventBatch.h

package info (click to toggle)
spring 88.0%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,524 kB
  • sloc: cpp: 343,114; ansic: 38,414; python: 12,257; java: 12,203; awk: 5,748; sh: 1,204; xml: 997; perl: 405; objc: 192; makefile: 181; php: 134; sed: 2
file content (353 lines) | stat: -rwxr-xr-x 8,203 bytes parent folder | download
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef LUA_EVENT_BATCH_H
#define LUA_EVENT_BATCH_H

#include "Rendering/GL/myGL.h"
#include "System/Platform/Synchro.h"
#include "Sim/Units/CommandAI/Command.h"
#include "Sim/Units/Unit.h"
#include "Sim/Features/Feature.h"
#include "Sim/Projectiles/Projectile.h"
#include "LuaConfig.h"

enum UnitEvent {
	UNIT_FINISHED,
	UNIT_CREATED,
	UNIT_FROM_FACTORY,
	UNIT_DESTROYED,
	UNIT_TAKEN,
	UNIT_GIVEN,
	UNIT_IDLE,
	UNIT_COMMAND,
	UNIT_CMD_DONE,
	UNIT_DAMAGED,
	UNIT_EXPERIENCE,
	UNIT_SEISMIC_PING,
	UNIT_ENTERED_RADAR,
	UNIT_ENTERED_LOS,
	UNIT_LEFT_RADAR,
	UNIT_LEFT_LOS,
	UNIT_LOADED,
	UNIT_UNLOADED,
	UNIT_ENTERED_WATER,
	UNIT_ENTERED_AIR,
	UNIT_LEFT_WATER,
	UNIT_LEFT_AIR,
	UNIT_CLOAKED,
	UNIT_DECLOAKED,
	UNIT_MOVE_FAILED,
	UNIT_EXPLOSION,
	UNIT_UNIT_COLLISION,
	UNIT_STOCKPILE_CHANGED
};

enum FeatEvent {
	FEAT_CREATED,
	FEAT_DESTROYED
};

enum ObjEvent {
	UNIT_FEAT_COLLISION
};

enum ProjEvent {
	PROJ_CREATED,
	PROJ_DESTROYED
};

enum LogEvent {
	ADD_CONSOLE_LINE
};

enum UIEvent {
	SHOCK_FRONT
};

struct LuaUnitEvent {
	LuaUnitEvent(UnitEvent i, const CUnit* u1)
		: id(i)
		, unit1(u1)
		, unit2(NULL)
		, bool1(false)
		, int1(0)
		, int2(0)
		, float1(0.0f)
		, pos1(ZeroVector)
	{}
	LuaUnitEvent(UnitEvent i, const CUnit* u1, const CUnit* u2)
		: id(i)
		, unit1(u1)
		, unit2(u2)
		, bool1(false)
		, int1(0)
		, int2(0)
		, float1(0.0f)
		, pos1(ZeroVector)
	{}
	LuaUnitEvent(UnitEvent i, const CUnit* u1, const CUnit* u2, bool b1)
		: id(i)
		, unit1(u1)
		, unit2(u2)
		, bool1(b1)
		, int1(0)
		, int2(0)
		, float1(0.0f)
		, pos1(ZeroVector)
	{}
	LuaUnitEvent(UnitEvent i, const CUnit* u1, int i1)
		: id(i)
		, unit1(u1)
		, unit2(NULL)
		, bool1(false)
		, int1(i1)
		, int2(0)
		, float1(0.0f)
		, pos1(ZeroVector)
	{}
	LuaUnitEvent(UnitEvent i, const CUnit* u1, const Command& c1)
		: id(i)
		, unit1(u1)
		, unit2(NULL)
		, bool1(false)
		, int1(0)
		, int2(0)
		, cmd1(c1)
		, float1(0.0f)
		, pos1(ZeroVector)
	{}
	LuaUnitEvent(UnitEvent i, const CUnit* u1, int i1, int i2)
		: id(i)
		, unit1(u1)
		, unit2(NULL)
		, bool1(false)
		, int1(i1)
		, int2(i2)
		, float1(0.0f)
		, pos1(ZeroVector)
	{}
	LuaUnitEvent(UnitEvent i, const CUnit* u1, const CUnit* u2, float f1, int i1, bool b1)
		: id(i)
		, unit1(u1)
		, unit2(u2)
		, bool1(b1)
		, int1(i1)
		, int2(0)
		, float1(f1)
		, pos1(ZeroVector)
	{}
	LuaUnitEvent(UnitEvent i, const CUnit* u1, float f1)
		: id(i)
		, unit1(u1)
		, unit2(NULL)
		, bool1(false)
		, int1(0)
		, int2(0)
		, float1(f1)
		, pos1(ZeroVector)
	{}
	LuaUnitEvent(UnitEvent i, const CUnit* u1, int i1, const float3& p1, float f1)
		: id(i)
		, unit1(u1)
		, unit2(NULL)
		, bool1(false)
		, int1(i1)
		, int2(0)
		, float1(f1)
		, pos1(p1)
	{}
	LuaUnitEvent(UnitEvent i, int i1, const float3& p1, const CUnit* u1)
		: id(i)
		, unit1(u1)
		, unit2(NULL)
		, bool1(false)
		, int1(i1)
		, int2(0)
		, float1(0.0f)
		, pos1(p1)
	{}
	LuaUnitEvent(UnitEvent i, const CUnit* u1, const CWeapon* u2, int i1)
		: id(i)
		, unit1(u1)
		, unit2((CUnit*)u2)
		, bool1(false)
		, int1(i1)
		, int2(0)
		, float1(0.0f)
		, pos1(ZeroVector)
	{}

	UnitEvent id;
	const CUnit* unit1;
	const CUnit* unit2;
	bool bool1;
	int int1;
	int int2;
	Command cmd1;
	float float1;
	float3 pos1;
};

struct LuaFeatEvent {
	LuaFeatEvent(FeatEvent i, const CFeature* f1)
		: id(i)
		, feat1(f1)
	{}

	FeatEvent id;
	const CFeature* feat1;
};

struct LuaObjEvent {
	LuaObjEvent(ObjEvent i, const CUnit* u, const CFeature* f)
		: id(i)
		, unit(u)
		, feat(f)
	{}

	ObjEvent id;
	const CUnit* unit;
	const CFeature* feat;
};

struct LuaProjEvent {
	LuaProjEvent(ProjEvent i, const CProjectile* p1)
		: id(i)
		, proj1(p1)
	{}

	ProjEvent id;
	const CProjectile* proj1;
};

struct LuaLogEvent {
	LuaLogEvent(LogEvent id, const std::string& msg, int level, const std::string& section)
		: id(id)
		, msg(msg)
		, level(level)
		, section(section)
	{}

	LogEvent id;
	std::string msg;
	int level;
	std::string section;
};

struct LuaUIEvent {
	LuaUIEvent(UIEvent i, const float f1, const float3& p1, const float f2, const float f3)
		: id(i)
		, flt1(f1)
		, flt2(f2)
		, flt3(f3)
		, pos1(p1)
	{}

	UIEvent id;
	float flt1;
	float flt2;
	float flt3;
	float3 pos1;
};

#if (LUA_MT_OPT & LUA_BATCH)
	#define LUA_UNIT_BATCH_PUSH(r,...)\
		if(UseEventBatch() && Threading::IsBatchThread()) {\
			GML_STDMUTEX_LOCK(ulbatch);\
			luaUnitEventBatch.push_back(LuaUnitEvent(__VA_ARGS__));\
			return r;\
		}
	#define LUA_FEAT_BATCH_PUSH(...)\
		if(UseEventBatch() && Threading::IsBatchThread()) {\
			GML_STDMUTEX_LOCK(flbatch);\
			luaFeatEventBatch.push_back(LuaFeatEvent(__VA_ARGS__));\
			return;\
		}
	#define LUA_OBJ_BATCH_PUSH(...)\
		if(UseEventBatch() && Threading::IsBatchThread()) {\
			GML_STDMUTEX_LOCK(olbatch);\
			luaObjEventBatch.push_back(LuaObjEvent(__VA_ARGS__));\
			return;\
		}
	#define LUA_PROJ_BATCH_PUSH(...)\
		if(UseEventBatch() && Threading::IsBatchThread()) {\
			GML_STDMUTEX_LOCK(plbatch);\
			luaProjEventBatch.push_back(LuaProjEvent(__VA_ARGS__));\
			return;\
		}
	#define LUA_FRAME_BATCH_PUSH(...)\
		if(UseEventBatch() && Threading::IsBatchThread()) {\
			GML_STDMUTEX_LOCK(glbatch);\
			luaFrameEventBatch.push_back(__VA_ARGS__);\
			return;\
		}
	#define LUA_LOG_BATCH_PUSH(r,...)\
		if(UseEventBatch() && Threading::IsBatchThread()) {\
			GML_STDMUTEX_LOCK(mlbatch);\
			luaLogEventBatch.push_back(LuaLogEvent(__VA_ARGS__));\
			return r;\
		}
	#define LUA_UI_BATCH_PUSH(...)\
		if(UseEventBatch() && Threading::IsBatchThread()) {\
			GML_STDMUTEX_LOCK(llbatch);\
			luaUIEventBatch.push_back(LuaUIEvent(__VA_ARGS__));\
			return;\
		}
#else
	#define LUA_UNIT_BATCH_PUSH(r,...)
	#define LUA_FEAT_BATCH_PUSH(...)
	#define LUA_OBJ_BATCH_PUSH(...)
	#define LUA_PROJ_BATCH_PUSH(...)
	#define LUA_FRAME_BATCH_PUSH(...)
	#define LUA_LOG_BATCH_PUSH(r,...)
	#define LUA_UI_BATCH_PUSH(...)
#endif

#if defined(USE_GML) && GML_ENABLE_SIM && GML_CALL_DEBUG
	#define GML_MEASURE_LOCK_TIME(lock) unsigned luatime = SDL_GetTicks(); lock; luatime = SDL_GetTicks() - luatime; if(luatime >= 1) gmlLockTime += luatime
#else
	#define GML_MEASURE_LOCK_TIME(lock) lock
#endif

#if (LUA_MT_OPT & LUA_STATE)
	#define BEGIN_ITERATE_LUA_STATES() lua_State* L_Cur = L_Sim; do { lua_State * const L = L_Cur
	#define END_ITERATE_LUA_STATES() if(SingleState() || L_Cur == L_Draw) break; L_Cur = L_Draw; } while(true)
	#ifndef LUA_SYNCED_ONLY
		#define SELECT_LUA_STATE() lua_State * const L = (SingleState() || Threading::IsSimThread()) ? L_Sim : L_Draw
		#define SELECT_UNSYNCED_LUA_STATE() lua_State * const L = SingleState() ? L_Sim : L_Draw
	#else
		#define SELECT_LUA_STATE()
		#define SELECT_UNSYNCED_LUA_STATE()
	#endif
	#if defined(USE_GML) && GML_ENABLE_SIM
		#if GML_DEBUG_MUTEX
			#define GML_LOCK_TEST(nme) { std::map<std::string, int>::iterator locki = lockmaps[GML::ThreadNumber()].find(#nme); if((lockmi==lockmmaps[GML::ThreadNumber()].end() || (*lockmi).second == 0) && locki!=lockmaps[GML::ThreadNumber()].end() && (*locki).second>0) while(1); }
			#define GML_DEBUG_LOCK(name) { GML_STDMUTEX_LOCK(lm); std::map<boost::recursive_mutex*, int>::iterator lockmi = lockmmaps[GML::ThreadNumber()].find(L->##name##mutex); GML_LOCK_TEST(sel); GML_LOCK_TEST(group); GML_LOCK_TEST(grpsel); GML_LOCK_TEST(gui); GML_LOCK_TEST(quad); GML_LOCK_TEST(qnum); }
		#else
			#define GML_DEBUG_LOCK(name)
		#endif
		#define GML_DRCMUTEX_LOCK(name) GML_DEBUG_LOCK(name); GML_MEASURE_LOCK_TIME(GML_OBJMUTEX_LOCK(name, GML_DRAW|GML_SIM, *L->))
	#else
		#define GML_DRCMUTEX_LOCK(name)
	#endif
#else
	#define BEGIN_ITERATE_LUA_STATES() lua_State * const L = L_Sim
	#define END_ITERATE_LUA_STATES()
	#ifndef LUA_SYNCED_ONLY
		#define SELECT_LUA_STATE() lua_State * const L = L_Sim
		#define SELECT_UNSYNCED_LUA_STATE() lua_State * const L = L_Sim
	#else
		#define SELECT_LUA_STATE()
		#define SELECT_UNSYNCED_LUA_STATE()
	#endif
	#define GML_DRCMUTEX_LOCK(name) GML_MEASURE_LOCK_TIME(GML_OBJMUTEX_LOCK(name, GML_DRAW|GML_SIM, *L->))
#endif

#if defined(USE_GML) && GML_ENABLE_SIM
	#define GML_SELECT_LUA_STATE() SELECT_LUA_STATE()
#else
	#define GML_SELECT_LUA_STATE()
#endif

#endif // LUA_EVENT_BATCH_H