MCPcopy Create free account
hub / github.com/DFHack/dfhack / init

Method init

library/modules/DFSDL.cpp:74–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72const char* (*g_SDL_GetKeyName)(SDL_Keycode key) = nullptr;
73
74bool DFSDL::init(color_ostream &out) {
75 for (auto &lib_str : SDL_LIBS) {
76 if ((g_sdl_handle = OpenPlugin(lib_str.c_str())))
77 break;
78 }
79 if (!g_sdl_handle) {
80 out.printerr("DFHack could not find SDL\n");
81 return false;
82 }
83
84 for (auto &lib_str : SDL_IMAGE_LIBS) {
85 if ((g_sdl_image_handle = OpenPlugin(lib_str.c_str())))
86 break;
87 }
88 if (!g_sdl_image_handle) {
89 out.printerr("DFHack could not find SDL_image\n");
90 return false;
91 }
92
93 #define bind(handle, name) \
94 g_##name = (decltype(g_##name))LookupPlugin(handle, #name); \
95 if (!g_##name) { \
96 out.printerr("DFHack could not find: " #name "\n"); \
97 return false; \
98 }
99
100 bind(g_sdl_image_handle, IMG_Load);
101 bind(g_sdl_handle, SDL_CreateRGBSurface);
102 bind(g_sdl_handle, SDL_CreateRGBSurfaceFrom);
103 bind(g_sdl_handle, SDL_UpperBlit);
104 bind(g_sdl_handle, SDL_ConvertSurface);
105 bind(g_sdl_handle, SDL_FreeSurface);
106 // bind(g_sdl_handle, SDL_SemWait);
107 // bind(g_sdl_handle, SDL_SemPost);
108 bind(g_sdl_handle, SDL_PushEvent);
109 bind(g_sdl_handle, SDL_HasClipboardText);
110 bind(g_sdl_handle, SDL_SetClipboardText);
111 bind(g_sdl_handle, SDL_GetClipboardText);
112 bind(g_sdl_handle, SDL_free);
113 bind(g_sdl_handle, SDL_AllocFormat);
114 bind(g_sdl_handle, SDL_CreateRGBSurfaceWithFormat);
115 bind(g_sdl_handle, SDL_ShowSimpleMessageBox);
116 bind(g_sdl_handle, SDL_GetPrefPath);
117 bind(g_sdl_handle, SDL_GetBasePath);
118 bind(g_sdl_handle, SDL_GetKeyFromName);
119 bind(g_sdl_handle, SDL_GetKeyName);
120 bind(g_sdl_handle, SDL_GetMouseState);
121 bind(g_sdl_handle, SDL_RenderWindowToLogical);
122 bind(g_sdl_handle, SDL_RenderLogicalToWindow);
123#undef bind
124
125 DEBUG(dfsdl,out).print("sdl successfully loaded\n");
126 return true;
127}
128
129// It's ok to leave NULLs in the raws list (according to usage in g_src)
130void DFSDL::cleanup() {

Callers 1

generateNameMethod · 0.45

Calls 3

OpenPluginFunction · 0.85
c_strMethod · 0.80
printMethod · 0.45

Tested by

no test coverage detected