CGameInterface.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "stdafx.h"
  2. #include "CGameInterface.h"
  3. #include "CAdvmapInterface.h"
  4. #include "CMessage.h"
  5. #include "mapHandler.h"
  6. #include "SDL_Extensions.h"
  7. #include "SDL_framerate.h"
  8. #include "CCursorHandler.h"
  9. #include "CCallback.h"
  10. #include "SDL_Extensions.h"
  11. #include "hch/CLodHandler.h"
  12. #include "CPathfinder.h"
  13. #include <sstream>
  14. #include "hch/CHeroHandler.h"
  15. #include "SDL_framerate.h"
  16. #include "AI/EmptyAI/CEmptyAI.h"
  17. #ifdef _WIN32
  18. #include <windows.h> //for .dll libs
  19. #else
  20. #include <dlfcn.h>
  21. #endif
  22. using namespace CSDL_Ext;
  23. CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname)
  24. {
  25. char temp[50];
  26. dllname = "AI/"+dllname;
  27. CGlobalAI * ret=NULL;
  28. CGlobalAI*(*getAI)(); //TODO use me
  29. void(*getName)(char*); //TODO use me
  30. #ifdef _WIN32
  31. HINSTANCE dll = LoadLibraryA(dllname.c_str());
  32. if (!dll)
  33. {
  34. tlog1 << "Cannot open AI library ("<<dllname<<"). Throwing..."<<std::endl;
  35. throw new std::string("Cannot open AI library");
  36. }
  37. //int len = dllname.size()+1;
  38. getName = (void(*)(char*))GetProcAddress(dll,"GetAiName");
  39. getAI = (CGlobalAI*(*)())GetProcAddress(dll,"GetNewAI");
  40. #else
  41. void *dll = dlopen(dllname.c_str(), RTLD_LOCAL | RTLD_LAZY);
  42. getName = (void(*)(char*))dlsym(dll,"GetAiName");
  43. getAI = (CGlobalAI*(*)())dlsym(dll,"GetNewAI");
  44. ; //TODO: handle AI library on Linux
  45. #endif
  46. getName(temp);
  47. tlog0 << "Loaded .dll with AI named " << temp << std::endl;
  48. ret = getAI();
  49. return ret;
  50. }
  51. //CGlobalAI::CGlobalAI()
  52. //{
  53. //}