summaryrefslogtreecommitdiff
path: root/src/protect.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-27 16:46:09 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-06-27 16:46:09 +0000
commita0f73cf7421e55e84b61065b4eb7ed13b05ce055 (patch)
treedbbc9e1d9250d85ce2e596841b0aea9cd477c016 /src/protect.c
parente528950ac7a2d23512be2a06378525b00be74185 (diff)
- šetřit možnosti podvádění – rychlost pohybu
- delObjectFromSpace ma casovu narocnost log(2,n) pri odstraneni objetu zo zonamu objektov ( btw. z hladiska programovania su veci pre 0.20 hotove ) git-svn-id: http://opensvn.csie.org/tuxanci_ng@75 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/protect.c')
-rw-r--r--src/protect.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/protect.c b/src/protect.c
new file mode 100644
index 0000000..fe9d29d
--- /dev/null
+++ b/src/protect.c
@@ -0,0 +1,88 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "main.h"
+#include "myTimer.h"
+#include "protect.h"
+
+protect_t* newProtect()
+{
+ protect_t *new;
+
+ new = malloc( sizeof(protect_t) );
+ new->lastMove = getMyTime();
+ new->lastPing = getMyTime();
+ new->avarage = 0;
+ new->count = 0;
+ new->isDown = FALSE;
+ return new;
+}
+
+void refreshLastMove(protect_t *p)
+{
+ my_time_t currentTime;
+ my_time_t interval;
+
+ currentTime = getMyTime();
+
+ interval = currentTime - p->lastMove;
+ p->lastMove = getMyTime();
+
+ p->avarage += interval;
+ p->count++;
+
+ if( p->count == PROTECT_SPEED_AVARAGE )
+ {
+ int index;
+
+ index = p->avarage/PROTECT_SPEED_AVARAGE;
+ p->avarage = 0;
+ p->count = 0;
+
+ if( index < PROTECT_SPEED_INTERVAL_TIMEOUT )
+ {
+ p->isDown = TRUE;
+ }
+
+ //printf("speed index = %d\n", index);
+ }
+}
+
+void rereshLastPing(protect_t *p)
+{
+ //my_time_t currentTime;
+ //my_time_t interval;
+
+ //currentTime = getMyTime();
+
+ //interval = currentTime - p->lastPing;
+ p->lastPing = getMyTime();
+
+ //printf("interval = %d\n", interval);
+}
+
+bool_t isDown(protect_t *p)
+{
+ my_time_t currentTime;
+ my_time_t interval;
+
+ currentTime = getMyTime();
+
+ interval = currentTime - p->lastPing;
+
+ if( interval > PROTECT_PING_INTERVAL_TIMEOUT )
+ {
+ p->isDown = TRUE;
+ }
+
+ return p->isDown;
+}
+
+void destroyProtect(protect_t *p)
+{
+ assert( p != NULL );
+ free(p);
+}