/
Zamar_Terrier
/
TigorEngineWeb2
Обзор
Документация
Войти
/
Zamar_Terrier
/
TigorEngineWeb2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/TigorEngine.c
323 строки
9 KB
Ilia Zamaruev
wasi delete and make local mini stb lib
17 фев 2026, 16:41
17 фев 2026, 16:41
f5863af
Код
Авторство
О чём код?
#include "TigorEngine.h" #include "e_memory.h" #include "e_camera.h" //#include <time.h> #include "window_manager.h" #include "string.h" #include "gameObject2D.h" #include "e_window.h" #include "e_texture_variables.h" TEngine engine; //extern GUIManager gui; extern void _wManagerPoolEventWeb(wManagerWindow *window);//, SDL_Event event); //extern void EntryWidgetCharacterCallback(void* arg, uint32_t codepoint); //extern void EntryWidgetKeyCallback(void* arg, int key, int scancode, int action, int mods); //extern void WidgetMouseCallback(wManagerWindow *window, int button, int action, int mods); //extern void WidgetFingerCallback(wManagerWindow *window, int fingerId, int action); void EngineCharacterCallback(wManagerWindow* window, uint32_t codepoint) { //EntryWidgetCharacterCallback(window, codepoint); for(int i=0; i < engine.func.charCallbackSize;i++) engine.func.charCallbacks[i](window, codepoint); } void EngineKeyCallback(wManagerWindow *window, int key, int scancode, int action, int mods) { //EntryWidgetKeyCallback(window, key, scancode, action, mods); for(int i=0; i < engine.func.keyCallbackSize;i++) engine.func.keyCallbacks[i](window, key, scancode, action, mods); } void EngineFingerCallback(wManagerWindow *window, int fingerId, int action){ //WidgetFingerCallback(window, fingerId, action); for(int i=0; i < engine.func.fingerKeyCallbackSize;i++) engine.func.fingerKeyCallbacks[i](window, fingerId, action); } void EngineMouseKeyCallback(wManagerWindow *window, int button, int action, int mods){ //WidgetMouseCallback(window, button, action, mods); for(int i=0; i < engine.func.mouseKeyCallbackSize;i++) engine.func.mouseKeyCallbacks[i](window, button, action, mods); } void TEngineSetResizeWidow(int width, int height){ engine.width = width; engine.height = height; engine.framebufferResized = true; engine.framebufferwasResized = false; } extern uint32_t GetTime(); void main_loop() { //if(!engine.activeRender) // return; // //float want_fps = 60; // //TWindow *window = (TWindow *)engine.window; // ////SDL_GL_MakeCurrent(window->instance, engine.gl_context); // //uint32_t tick_time = GetTime(); //deltaTime = 1.0f - (tick_time - last_tick_time) / 1000.0f; //last_tick_time = tick_time; // //if (deltaTime > 1.0f) // deltaTime = 1.0f; // ///*SDL_Event event; //while(SDL_PollEvent(&event)) //{ // switch (event.type) // { // case SDL_QUIT: // emscripten_cancel_main_loop(); // break; // case SDL_WINDOWEVENT: // if (event.window.event == SDL_WINDOWEVENT_RESIZED) // { // //update_screen_size(event.window.data1, event.window.data2); // #ifndef NDEBUG // consoleLog("Resize window Engine!\n"); // #endif // // } // break; // default: // break; // } // _wManagerPoolEventWeb(window->e_window, event); //}*/ // //if(engine.Updater != NULL) // engine.Updater(deltaTime ); // ////if(GUIManagerIsInit()) //// GUIManagerUpdate(); // //// render //// ------ //glClearColor( 0.3, 0.01f, 0.01f, 1.0f); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // //if(engine.Drawer != NULL) // engine.Drawer(); // ////SDL_GL_SwapWindow(window->instance); // ////if(GUIManagerIsInit()){ //// GUIManagerClear(); ////} // //if(!engine.framebufferwasResized){ // engine.framebufferResized = false; // engine.framebufferwasResized = true; //} // //// int time_to_sleep = (1.f/want_fps - deltaTime); // //// if (time_to_sleep > 0) { //// async_sleep(time_to_sleep); //// } } void EngineInit(){ engine.window = AllocateMemory(1, sizeof(TWindow)); TWindow *window = (TWindow *)engine.window; int result = wManagerInit(); /*window->instance = SDL_CreateWindow(engine.app_name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, engine.width, engine.height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetSwapInterval(1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); engine.gl_context = SDL_GL_CreateContext(window->instance);*/ } void TEngineInitSystem(int width, int height, const char* name){ TWindow *window = (TWindow *)engine.window; memset(&engine, 0, sizeof(TEngine)); //memset(&gui, 0, sizeof(GUIManager)); //strcpy(engine.app_name, name); engine.present = true; engine.width = width; engine.height = height; engine.diffSize = vec2_f( 1.0f, 1.0f ); engine.viewSize.x = engine.width; engine.viewSize.y = engine.height; engine.e_var_current_entry = NULL; engine.activeRender = true; engine.MAX_FRAMES_IN_FLIGHT = 3; engine.DataR.e_var_images = AllocateMemoryP(MAX_IMAGES, sizeof(engine_buffered_image), &engine); EngineInit(); wManagerSetCharCallback(window->e_window, EngineCharacterCallback); wManagerSetKeyCallback(window->e_window, EngineKeyCallback); //GUIManagerInit(true); // memcpy(images[engine.DataR.e_var_num_images].path, text, strlen(text)); // engine.DataR.e_var_num_images ++; } int TEngineGetMousePress(int Key){ TWindow *window = (TWindow *)engine.window; int state = wManagerGetMouseButton(window->e_window, Key); return state; } void TEngineGetCursorPos(double *xpos, double *ypos){ TWindow *window = (TWindow *)engine.window; wManagerGetCursorPos(window->e_window, xpos, ypos); } void TEngineSetCursorPos(float xpos, float ypos){ TWindow *window = (TWindow *)engine.window; wManagerSetCursorPos(window->e_window, xpos, ypos); } int TEngineGetKeyPress(int Key){ TWindow *window = (TWindow *)engine.window; int state = wManagerGetKey(window->e_window, Key); return state; } const char *TEngineGetClipBoardString(){ TWindow *window = (TWindow *)engine.window; return wManagerGetClipboardString(window->e_window); } void TEngineSetClipBoardString(const char *string){ TWindow *window = (TWindow *)engine.window; wManagerSetClipboardString(window->e_window, string); } void TEngineSetKeyCallback(SomeKeyCallbackFunc callback){ engine.func.keyCallbackSize ++; engine.func.keyCallbacks = (e_keyCallback *)realloc(engine.func.keyCallbacks, engine.func.keyCallbackSize * sizeof(e_keyCallback)); engine.func.keyCallbacks[engine.func.keyCallbackSize - 1] = (e_keyCallback)callback; } void TEngineSetMouseKeyCallback(SomeMouseKeyCallbackFunc callback){ engine.func.mouseKeyCallbackSize ++; engine.func.mouseKeyCallbacks = (e_mouseKeyCallback *)realloc(engine.func.mouseKeyCallbacks, engine.func.mouseKeyCallbackSize * sizeof(e_mouseKeyCallback)); engine.func.mouseKeyCallbacks[engine.func.mouseKeyCallbackSize - 1] = (e_mouseKeyCallback)callback; } void TEngineSetFingerCallback(SomeFingerKeyCallbackFunc callback){ engine.func.fingerKeyCallbackSize ++; engine.func.fingerKeyCallbacks = (e_fingerKeyCallback *)realloc(engine.func.fingerKeyCallbacks, engine.func.fingerKeyCallbackSize * sizeof(e_fingerKeyCallback)); engine.func.fingerKeyCallbacks[engine.func.fingerKeyCallbackSize - 1] = (e_fingerKeyCallback)callback; } void TEngineSetCursorPosCallback(void * callback){ TWindow *window = (TWindow *)engine.window; wManagerSetCursorPosCallback(window->e_window, callback); } void TEngineRenderGUI(){ //if(GUIManagerIsInit()){ // GUIManagerDraw(); // GUIManagerClear(); //} } void TEngineSetUpdater(EngineUpdateFunc update){ engine.Updater = update; } void TEngineSetDrawer(EngineDrawFunc draw){ engine.Drawer = draw; } void TEngineGetWindowSize(int *width, int *height){ *width = engine.width; *height = engine.height; } extern int _wManagerGetMousePressState(wManagerWindow *window); extern WebFinger *_wManagerGetFingerPressState(wManagerWindow *window); int TEngineGetMousePressState(){ TWindow *window = (TWindow *)engine.window; return _wManagerGetMousePressState(window->e_window); } void *TEngineGetFingerPressState(){ TWindow *window = (TWindow *)engine.window; return _wManagerGetFingerPressState(window->e_window); } void TEngineStartRender(){ #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(main_loop, 0, true); #else while(true) main_loop(); #endif } void TEngineStopRender(){ engine.activeRender = false; } void TEngineResumeRender(){ engine.activeRender = true; } bool TEngineDeviceIsMobile(){ return engine.device_type & TIGOR_DEVICE_TYPE_MOBILE; } bool TEngineDeviceIsPC(){ return engine.device_type & TIGOR_DEVICE_TYPE_DESKTOP; }