2020-05-23 01:11:46 +08:00
|
|
|
|
#include "include.h"
|
2020-05-24 05:24:13 +08:00
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <ctime>
|
2020-05-23 01:11:46 +08:00
|
|
|
|
|
|
|
|
|
void InitLuaEngine(lua_State* L)
|
|
|
|
|
{
|
|
|
|
|
InitEvent(L);
|
|
|
|
|
InitWindow(L);
|
|
|
|
|
InitRenderer(L);
|
|
|
|
|
InitFont(L);
|
|
|
|
|
InitMusic(L);
|
|
|
|
|
InitCommon(L);
|
|
|
|
|
InitTCPSocket(L);
|
2020-05-29 01:39:49 +08:00
|
|
|
|
InitUDPSocket(L);
|
|
|
|
|
InitNetwork(L);
|
2020-05-24 05:24:13 +08:00
|
|
|
|
InitSocketSelector(L);
|
2020-05-29 01:39:49 +08:00
|
|
|
|
InitThread(L);
|
2020-06-24 18:47:46 +08:00
|
|
|
|
InitChannel(L);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lua_State* CreateLuaEngine()
|
|
|
|
|
{
|
|
|
|
|
lua_State* L = luaL_newstate();
|
|
|
|
|
luaL_openlibs(L);
|
|
|
|
|
InitLuaEngine(L);
|
|
|
|
|
return L;
|
2020-05-23 01:11:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InitEngine()
|
|
|
|
|
{
|
|
|
|
|
SDL_Init(SDL_INIT_EVERYTHING);
|
|
|
|
|
IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
|
|
|
|
|
TTF_Init();
|
|
|
|
|
Mix_Init(MIX_INIT_MP3 | MIX_INIT_OGG);
|
|
|
|
|
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1)
|
|
|
|
|
{
|
|
|
|
|
SDL_Log("Mix_OpenAudio: %s\n", Mix_GetError());
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
2020-05-29 01:39:49 +08:00
|
|
|
|
Mix_AllocateChannels(16);
|
2020-05-23 01:11:46 +08:00
|
|
|
|
// Stop text input event
|
|
|
|
|
SDL_StopTextInput();
|
|
|
|
|
|
|
|
|
|
PlatInit();
|
2020-05-24 05:24:13 +08:00
|
|
|
|
srand(time(NULL));
|
2020-05-23 01:11:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CloseEngine()
|
|
|
|
|
{
|
|
|
|
|
Mix_CloseAudio();
|
|
|
|
|
Mix_Quit();
|
|
|
|
|
TTF_Quit();
|
|
|
|
|
IMG_Quit();
|
|
|
|
|
SDL_Quit();
|
|
|
|
|
}
|