forked from InfiniteRasa/Game-Server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entityMgr.cpp
107 lines (90 loc) · 2.54 KB
/
entityMgr.cpp
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
#include"Global.h"
sint32 ceid_player = 0;
sint32 ceid_client = 0;
sint32 ceid_object = 0;
sint32 ceid_item = 0;
sint32 ceid_npc = 0;
sint32 ceid_creature = 0;
TMutex csEntityMgr;
#define ENTITYID_BASE 0x1000
unsigned long long entityMgr_getFreeEntityIdForClient()
{
Thread::LockMutex(&csEntityMgr);
unsigned long long eid = ENTITYID_BASE + ceid_client*16 + ENTITYTYPE_CLIENT;
ceid_client++;
Thread::UnlockMutex(&csEntityMgr);
return eid;
}
unsigned long long entityMgr_getFreeEntityIdForPlayer()
{
Thread::LockMutex(&csEntityMgr);
unsigned long long eid = ENTITYID_BASE + ceid_player*16 + ENTITYTYPE_PLAYER;
ceid_player++;
Thread::UnlockMutex(&csEntityMgr);
return eid;
}
unsigned long long entityMgr_getFreeEntityIdForItem()
{
Thread::LockMutex(&csEntityMgr);
unsigned long long eid = ENTITYID_BASE + ceid_item*16 + ENTITYTYPE_ITEM;
ceid_item++;
Thread::UnlockMutex(&csEntityMgr);
return eid;
}
unsigned long long entityMgr_getFreeEntityIdForObject()
{
Thread::LockMutex(&csEntityMgr);
unsigned long long eid = ENTITYID_BASE + ceid_object*16 + ENTITYTYPE_OBJECT;
ceid_object++;
Thread::UnlockMutex(&csEntityMgr);
return eid;
}
unsigned long long entityMgr_getFreeEntityIdForCreature()
{
Thread::LockMutex(&csEntityMgr);
unsigned long long eid = ENTITYID_BASE + ceid_creature*16 + ENTITYTYPE_CREATURE;
ceid_creature++;
Thread::UnlockMutex(&csEntityMgr);
return eid;
}
uint8 entityMgr_getEntityType(unsigned long long entityId)
{
return entityId & 0xF;
}
hashTable_t ht_entityTable;
void entityMgr_registerEntity(unsigned long long entityId, void *entity)
{
Thread::LockMutex(&csEntityMgr);
hashTable_set(&ht_entityTable, entityId, entity);
Thread::UnlockMutex(&csEntityMgr);
}
void entityMgr_unregisterEntity(unsigned long long entityId)
{
Thread::LockMutex(&csEntityMgr);
hashTable_set(&ht_entityTable, entityId, NULL);
Thread::UnlockMutex(&csEntityMgr);
}
void *entityMgr_get(unsigned long long entityId)
{
void *v = NULL;
Thread::LockMutex(&csEntityMgr);
v = hashTable_get(&ht_entityTable, entityId);
Thread::UnlockMutex(&csEntityMgr);
return v;
}
void entityMgr_init()
{
Thread::InitMutex(&csEntityMgr);
hashTable_init(&ht_entityTable, 512);
// get current npc
unsigned long long npceid = DataInterface_NPC_getLastNPCEntityID();
if( npceid < ENTITYID_BASE )
npceid = ENTITYID_BASE;
// ceid_npc
npceid = (npceid - ENTITYID_BASE) / 16;
npceid++;
//npceid += 16;
//npceid &= ~0xF;
//npceid += ENTITYTYPE_NPC;
ceid_npc = npceid;
}