From 9410830b5d317c3da4758c8c63f5e67b708b755c Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 22 Apr 2014 14:31:56 +1000 Subject: Move LuaSL source up one directory. --- LuaSL/LuaSL_utilities.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 LuaSL/LuaSL_utilities.c (limited to 'LuaSL/LuaSL_utilities.c') diff --git a/LuaSL/LuaSL_utilities.c b/LuaSL/LuaSL_utilities.c new file mode 100644 index 0000000..40263df --- /dev/null +++ b/LuaSL/LuaSL_utilities.c @@ -0,0 +1,60 @@ +#include "LuaSL.h" + + +void sendBack(gameGlobals *ourGlobals, Ecore_Con_Client *client, const char *SID, const char *message, ...) +{ + va_list args; + char buf[PATH_MAX]; + int length = strlen(SID); + + strncpy(buf, SID, length); + buf[length++] = '.'; + va_start(args, message); + length += vsprintf(&buf[length], message, args); + va_end(args); + buf[length++] = '\n'; + buf[length++] = '\0'; + ecore_con_client_send(client, buf, strlen(buf)); + ecore_con_client_flush(client); +} + +void sendForth(gameGlobals *ourGlobals, const char *SID, const char *message, ...) +{ + va_list args; + char buf[PATH_MAX]; + int length = strlen(SID); + + strncpy(buf, SID, length); + buf[length++] = '.'; + va_start(args, message); + length += vsprintf(&buf[length], message, args); + va_end(args); + buf[length++] = '\n'; + buf[length++] = '\0'; + ecore_con_server_send(ourGlobals->server, buf, strlen(buf)); + ecore_con_server_flush(ourGlobals->server); +} + +float timeDiff(struct timeval *now, struct timeval *then) +{ + if (0 == gettimeofday(now, 0)) + { + struct timeval thisTime = { 0, 0 }; + double result = 0.0; + + thisTime.tv_sec = now->tv_sec; + thisTime.tv_usec = now->tv_usec; + if (thisTime.tv_usec < then->tv_usec) + { + thisTime.tv_sec--; + thisTime.tv_usec += 1000000; + } + thisTime.tv_usec -= then->tv_usec; + thisTime.tv_sec -= then->tv_sec; + result = ((double) thisTime.tv_usec) / ((double) 1000000.0); + result += thisTime.tv_sec; + return result; + } + else + return 0.0; +} -- cgit v1.1