Difference between revisions of "Link"
Line 11: | Line 11: | ||
#ifdef WIN32 | #ifdef WIN32 | ||
UINT32 uiVersion; | UINT32 uiVersion; | ||
− | DWORD | + | DWORD uiTick; |
#else | #else | ||
uint32_t uiVersion; | uint32_t uiVersion; | ||
− | + | uint32_t uiTick; | |
#endif | #endif | ||
float fPosition[3]; | float fPosition[3]; | ||
Line 61: | Line 61: | ||
<pre> | <pre> | ||
+ | |||
+ | #ifndef WIN32 | ||
+ | static const int32_t GetTickCount() { | ||
+ | struct timeval tv; | ||
+ | gettimeofday(&tv,NULL); | ||
+ | |||
+ | return tv.tv_usec / 1000 + tv.tv_sec * 1000; | ||
+ | } | ||
+ | #endif | ||
+ | |||
void updateMumble() { | void updateMumble() { | ||
if (! lm) | if (! lm) | ||
Line 68: | Line 78: | ||
lm->uiVersion = 1; | lm->uiVersion = 1; | ||
− | + | lm->uiTick = GetTickCount(); | |
− | lm-> | ||
− | |||
− | |||
− | |||
} | } | ||
</pre> | </pre> |
Revision as of 17:27, 5 April 2008
Linking a game to Mumble
The "best" way to link a game to mumble is to write your own plugin. However, that may be a lot of work, so we have an alternative method.
Initialization
Somewhere in your game initalization, add these lines of code:
struct LinkedMem { #ifdef WIN32 UINT32 uiVersion; DWORD uiTick; #else uint32_t uiVersion; uint32_t uiTick; #endif float fPosition[3]; float fFront[3]; float fTop[3]; wchar_t name[256]; }; LinkedMem *lm = NULL; #ifdef WIN32 static HANDLE hMapObject = NULL; void initMumble() { hMapObject = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, L"MumbleLink"); if (hMapObject == NULL) return; lm = (LinkedMem *) MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(LinkedMem)); if (lm == NULL) { CloseHandle(hMapObject); hMapObject = NULL; return; } wcscpy_s(lm->name, 256, L"MyGameName"); } #else static int shmfd = -1; void initMumble() { shmfd = shm_open("/MumbleLink", O_RDWR, S_IRUSR | S_IWUSR); if(shmfd < 0) { return; } lm = (LinkedMem *) (mmap(NULL, sizeof(struct LinkedMem), PROT_READ | PROT_WRITE, MAP_SHARED, shmfd,0)); if (lm == (void *) (-1)) { lm = NULL; } } #endif
Then, for each frame, do the following:
#ifndef WIN32 static const int32_t GetTickCount() { struct timeval tv; gettimeofday(&tv,NULL); return tv.tv_usec / 1000 + tv.tv_sec * 1000; } #endif void updateMumble() { if (! lm) return; // Fill lm->fPosition, fTop and fFront lm->uiVersion = 1; lm->uiTick = GetTickCount(); }
fPosition should be the player position in 3D space. fTop and fFront should be the orientation. The coordinate system is a left-handed one, and the units are in meters.
Mumble fetches these values 50 times a second, so please update them every frame.