#include <stdio.h>
#include <SocketHandler.h>
#include <StdoutLog.h>
#include <Uid.h>
#include <ListenSocket.h>
#include "Robot.h"
#include "Map.h"
#include "Base.h"
#include "InjectSocket.h"
#include "RowoHandler.h"
Include dependency graph for robotworld.cpp:
Go to the source code of this file.
Functions | |
std::string | GetMyUid () |
int | main (int argc, char *argv[]) |
std::string GetMyUid | ( | ) |
Definition at line 13 of file robotworld.cpp.
References fil.
00014 { 00015 std::string myuid; 00016 FILE *fil; 00017 if ((fil = fopen("myuid.txt","rt")) != NULL) 00018 { 00019 char slask[1000]; 00020 fgets(slask,1000,fil); 00021 slask[strlen(slask) - 1] = 0; 00022 fclose(fil); 00023 myuid = slask; 00024 } 00025 else 00026 { 00027 Uid uid; 00028 myuid = uid.GetUid(); 00029 fil = fopen("myuid.txt","wt"); 00030 fprintf(fil,"%s\n",myuid.c_str()); 00031 fclose(fil); 00032 } 00033 return myuid; 00034 }
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 37 of file robotworld.cpp.
References Map::AddObject(), GetMyUid(), Map::IncreaseTime(), Map::objects_in_map(), RowoHandler::SetMap(), Map::SetMax(), RowoHandler::SetMyUid(), and Map::SpawnRandom().
00038 { 00039 RowoHandler h; 00040 StdoutLog log; 00041 h.RegStdLog(&log); 00042 ListenSocket<InjectSocket> ll(h); 00043 std::string myuid = GetMyUid(); 00044 Map map; 00045 Base home(map); 00046 bool quit = false; 00047 struct timeval tvo; 00048 struct timezone tz; 00049 00050 if (ll.Bind("localhost",32766) == -1) 00051 { 00052 exit(-1); 00053 } 00054 h.Add(&ll); 00055 00056 // init handler, etc.. 00057 h.SetMyUid(myuid); 00058 h.SetMap(&map); 00059 map.SetMax(1000, 1000); 00060 map.AddObject(&home, false); 00061 00062 gettimeofday(&tvo,&tz); 00063 while (!quit) 00064 { 00065 h.Select(0,100000); // 10 ... 00066 struct timeval tv; 00067 gettimeofday(&tv,&tz); 00068 long diff = tv.tv_usec - tvo.tv_usec; 00069 if (diff < 0) 00070 { 00071 diff += 1000000; 00072 } 00073 if (tv.tv_sec != tvo.tv_sec) 00074 { 00075 if (map.objects_in_map() < 1000) 00076 { 00077 map.SpawnRandom(); 00078 } 00079 } 00080 if (diff >= 50000) // ... 20 times/sec 00081 { 00082 map.IncreaseTime( diff ); 00083 tvo = tv; 00084 } 00085 } 00086 }