void Sdl2Application::exit() {
    #ifndef CORRADE_TARGET_EMSCRIPTEN
    _flags |= Flag::Exit;
    #else
    emscripten_cancel_main_loop();
    #endif
}
Beispiel #2
0
static void HandleErrorOutput(const std::string& err) {
#ifdef EMSCRIPTEN
	// Do not execute any game logic after an error happened
	emscripten_cancel_main_loop();
#endif

	// Drawing directly on the screen because message_overlay is not visible
	// when faded out
	BitmapRef surface = DisplayUi->GetDisplaySurface();
	surface->FillRect(surface->GetRect(), Color(255, 0, 0, 128));

	std::string error = "Error:\n";
	error += err;

	error += "\n\nEasyRPG Player will close now.\nPress [ENTER] key to exit...";

	Text::Draw(*surface, 11, 11, Color(0, 0, 0, 255), Font::Default(), error);
	Text::Draw(*surface, 10, 10, Color(255, 255, 255, 255), Font::Default(), error);
	DisplayUi->UpdateDisplay();

	if (ignore_pause) { return; }

	Input::ResetKeys();
	while (!Input::IsAnyPressed()) {
		DisplayUi->Sleep(1);
		DisplayUi->ProcessEvents();

		if (Player::exit_flag) break;

		Input::Update();
	}
}
void
fv_error_message(const char *format, ...)
{
        struct fv_buffer buffer;
        va_list ap;

        /* Stop drawing or processing any further events */
        SDL_SetEventFilter(NULL, NULL);
        emscripten_cancel_main_loop();

        va_start(ap, format);

        fv_buffer_init(&buffer);
        fv_buffer_append_vprintf(&buffer, format, ap);

        va_end(ap);

        EM_ASM_({
                        console.error(Module.Pointer_stringify($0));
                        var canvas = document.getElementById("canvas");
                        canvas.style.display = "none";
                        var errorMessage =
                                document.getElementById("error-message");
                        errorMessage.style.display = "block";
                },
Beispiel #4
0
void
loop()
{
    SDL_Event event;
    /* Check for events */
    /*SDL_WaitEvent(&event); emscripten does not like waiting*/

    while (SDL_PollEvent(&event)) {
        switch (event.type) {
        case SDL_KEYDOWN:
        case SDL_KEYUP:
		    PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
            break;
        case SDL_TEXTEDITING:
            PrintText("EDIT", event.text.text);
            break;
        case SDL_TEXTINPUT:
            PrintText("INPUT", event.text.text);
            break;
        case SDL_MOUSEBUTTONDOWN:
            /* Any button press quits the app... */
        case SDL_QUIT:
            done = 1;
            break;
        default:
            break;
        }
    }
#ifdef __EMSCRIPTEN__
    if (done) {
        emscripten_cancel_main_loop();
    }
#endif
}
Beispiel #5
0
void esLoop() {
	if (userInterrupt(esContextInt) == GL_TRUE) {
		emscripten_cancel_main_loop();
		return;
	}
	
  gettimeofday(&t2, &tz);
  deltatime = (float)(t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec) * 1e-6);
  t1 = t2;

  if (esContextInt->updateFunc != NULL)
    esContextInt->updateFunc(esContextInt, deltatime);
  if (esContextInt->drawFunc != NULL)
    esContextInt->drawFunc(esContextInt);

  eglSwapBuffers(esContextInt->eglDisplay, esContextInt->eglSurface);

  totaltime += deltatime;
  frames++;
	
  if (totaltime >  2.0f) {
    printf("%4d frames rendered in %1.4f seconds -> FPS=%3.4f\n", frames, totaltime, frames/totaltime);
    totaltime -= 2.0f;
    frames = 0;
  }
}
Beispiel #6
0
void
loop()
{
    int i;
    SDL_Event event;

    /* Check for events */
    while (SDL_PollEvent(&event)) {
        SDLTest_CommonEvent(state, &event, &done);
    }
    for (i = 0; i < state->num_windows; ++i) {
        SDL_Renderer *renderer = state->renderers[i];
        if (state->windows[i] == NULL)
            continue;
        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
        SDL_RenderClear(renderer);

        DrawRects(renderer);
        DrawLines(renderer);
        DrawPoints(renderer);

        SDL_RenderPresent(renderer);
    }
#ifdef __EMSCRIPTEN__
    if (done) {
        emscripten_cancel_main_loop();
    }
#endif
}
Beispiel #7
0
void wait_https() {
	if (num_request == 0) {
		printf("End of all download ... %fs\n",(emscripten_get_now() - time_elapsed) / 1000.f);
		emscripten_cancel_main_loop();
    REPORT_RESULT(0);
	}
}
Beispiel #8
0
void
loop()
{
    SDL_Event event;
        /* Check for events */
        while (SDL_PollEvent(&event)) {
            SDLTest_CommonEvent(state, &event, &done);

            if (event.type == SDL_WINDOWEVENT) {
                if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
                    if (window) {
                        SDL_Log("Window %d resized to %dx%d\n",
                            event.window.windowID,
                            event.window.data1,
                            event.window.data2);
                    }
                }
                if (event.window.event == SDL_WINDOWEVENT_MOVED) {
                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
                    if (window) {
                        SDL_Log("Window %d moved to %d,%d (display %s)\n",
                            event.window.windowID,
                            event.window.data1,
                            event.window.data2,
                            SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
                    }
                }
            }
            if (event.type == SDL_KEYUP) {
                SDL_bool updateCursor = SDL_FALSE;

                if (event.key.keysym.sym == SDLK_LEFT) {
                    --system_cursor;
                    if (system_cursor < 0) {
                        system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
                    }
                    updateCursor = SDL_TRUE;
                } else if (event.key.keysym.sym == SDLK_RIGHT) {
                    ++system_cursor;
                    if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
                        system_cursor = 0;
                    }
                    updateCursor = SDL_TRUE;
                }
                if (updateCursor) {
                    SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
                    SDL_FreeCursor(cursor);
                    cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
                    SDL_SetCursor(cursor);
                }
            }
        }
#ifdef __EMSCRIPTEN__
    if (done) {
        emscripten_cancel_main_loop();
    }
#endif
}
Beispiel #9
0
SDLApplication::SDLApplication () {

    if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) != 0) {

        printf ("Could not initialize SDL: %s.\n", SDL_GetError ());

    }

    currentApplication = this;

    framePeriod = 1000.0 / 60.0;

#ifdef EMSCRIPTEN
    emscripten_cancel_main_loop ();
    emscripten_set_main_loop (UpdateFrame, 0, 0);
    emscripten_set_main_loop_timing (EM_TIMING_RAF, 1);
#endif

    currentUpdate = 0;
    lastUpdate = 0;
    nextUpdate = 0;

    ApplicationEvent applicationEvent;
    GamepadEvent gamepadEvent;
    KeyEvent keyEvent;
    MouseEvent mouseEvent;
    RenderEvent renderEvent;
    SensorEvent sensorEvent;
    TextEvent textEvent;
    TouchEvent touchEvent;
    WindowEvent windowEvent;

#if defined(IOS) || defined(ANDROID)
    for (int i = 0; i < SDL_NumJoysticks (); i++) {

        if (strstr (SDL_JoystickNameForIndex (i), "Accelerometer")) {

            accelerometer = SDL_JoystickOpen (i);
            accelerometerID = SDL_JoystickInstanceID (accelerometer);

        }

    }
#endif

#ifdef HX_MACOS
    CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL (CFBundleGetMainBundle ());
    char path[PATH_MAX];

    if (CFURLGetFileSystemRepresentation (resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) {

        chdir (path);

    }

    CFRelease (resourcesURL);
#endif

}
Beispiel #10
0
void
loop()
{
    if(done)
        emscripten_cancel_main_loop();
    else
        iteration();
}
Beispiel #11
0
void draw_same(void)
{
  disp_beginUpdate(&buf_graf, &buf_graf_stride, &wpar.width, &wpar.height);
  emscripten_call_worker(worker, "draw", (char *)&wpar, sizeof(wpar),
                         worker_callback, NULL);
  /* Worker callback will restart main loop */
  emscripten_cancel_main_loop();
}
Beispiel #12
0
extern C_LINKAGE int main(int argc, char *argv[]) {
	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
		SDL_Log("SDL_Init failed: %s\n", SDL_GetError());
		return 1;
	}

    ::hope::entry::onInitialize();

	emscripten_set_main_loop(do_nothing, 0, 0);

	::hope::asset::load();

	int w_width = 1024, w_height = 768;

	if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2) != 0) {
		SDL_Log("SDL_GL_SetAttribute SDL_GL_CONTEXT_MAJOR_VERSION failed: %s\n", SDL_GetError());
		return 1;
	}
	if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0) != 0) {
		SDL_Log("SDL_GL_SetAttribute SDL_GL_CONTEXT_MINOR_VERSION failed: %s\n", SDL_GetError());
		return 1;
	}

	if (SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1) != 0) {
		SDL_Log("SDL_GL_SetAttribute SDL_GL_STENCIL_SIZE failed: %s\n", SDL_GetError());
		return 1;
	}

	window = SDL_CreateWindow("OpenGL Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w_width, w_height, SDL_WINDOW_OPENGL);
	if (!window) {
		SDL_Log("SDL_CreateWindow failed: %s\n", SDL_GetError());
		return 1;
	}

	context = SDL_GL_CreateContext(window);
	if (!context) {
		SDL_Log("SDL_GL_CreateContext failed: %s\n", SDL_GetError());
	}

    ::hope::entry::onGLInitialize();

    ::hope::entry::onResize(w_width, w_height);

    emscripten_cancel_main_loop();
	emscripten_set_main_loop(do_loop, 0, 1);

    ::hope::entry::onGLRelease();

    SDL_GL_DeleteContext(context);  
    SDL_DestroyWindow(window);

    ::hope::entry::onRelease();

    SDL_Quit();

    return 0;
}
Beispiel #13
0
void
loop()
{
    SDL_Event event;

    while (SDL_PollEvent(&event)) {
        switch (event.type) {
        case SDL_WINDOWEVENT:
            if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
                SDL_RenderSetViewport(renderer, NULL);
                displayrect.w = window_w = event.window.data1;
                displayrect.h = window_h = event.window.data2;
            }
            break;
        case SDL_MOUSEBUTTONDOWN:
            displayrect.x = event.button.x - window_w / 2;
            displayrect.y = event.button.y - window_h / 2;
            break;
        case SDL_MOUSEMOTION:
            if (event.motion.state) {
                displayrect.x = event.motion.x - window_w / 2;
                displayrect.y = event.motion.y - window_h / 2;
            }
            break;
        case SDL_KEYDOWN:
            if (event.key.keysym.sym == SDLK_SPACE) {
                paused = !paused;
                break;
            }
            if (event.key.keysym.sym != SDLK_ESCAPE) {
                break;
            }
        case SDL_QUIT:
            done = SDL_TRUE;
            break;
        }
    }

#ifndef __EMSCRIPTEN__
    SDL_Delay(fpsdelay);
#endif

    if (!paused) {
        i = (i + 1) % MOOSEFRAMES_COUNT;

        SDL_UpdateTexture(MooseTexture, NULL, MooseFrame[i], MOOSEPIC_W*SDL_BYTESPERPIXEL(pixel_format));
    }
    SDL_RenderClear(renderer);
    SDL_RenderCopy(renderer, MooseTexture, NULL, &displayrect);
    SDL_RenderPresent(renderer);

#ifdef __EMSCRIPTEN__
    if (done) {
        emscripten_cancel_main_loop();
    }
#endif
}
Beispiel #14
0
void loop()
{
    SDL_Event event;
    int i;
    int status;

    /* Check for events */
    ++frames;
    while (SDL_PollEvent(&event) && !done) {
        switch (event.type) {
        case SDL_WINDOWEVENT:
            switch (event.window.event) {
                case SDL_WINDOWEVENT_RESIZED:
                    for (i = 0; i < state->num_windows; ++i) {
                        if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
                            int w, h;
                            status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
                            if (status) {
                                SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
                                break;
                            }
                            /* Change view port to the new window dimensions */
                            SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
                            glViewport(0, 0, w, h);
                            state->window_w = event.window.data1;
                            state->window_h = event.window.data2;
                            /* Update window content */
                            Render(event.window.data1, event.window.data2, &datas[i]);
                            SDL_GL_SwapWindow(state->windows[i]);
                            break;
                        }
                    }
                    break;
            }
        }
        SDLTest_CommonEvent(state, &event, &done);
    }
    if (!done) {
      for (i = 0; i < state->num_windows; ++i) {
          status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
          if (status) {
              SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());

              /* Continue for next window */
              continue;
          }
          Render(state->window_w, state->window_h, &datas[i]);
          SDL_GL_SwapWindow(state->windows[i]);
      }
    }
#ifdef __EMSCRIPTEN__
    else {
        emscripten_cancel_main_loop();
    }
#endif
}
void argey(void* arg) {
  static int counter = 0;
  assert((int)arg == 17);
  counter++;
  printf("argey: %d\n", counter);
  if (counter == 5) {
    emscripten_cancel_main_loop();
    int result = 1;
    REPORT_RESULT();
  }
}
Beispiel #16
0
	SDLApplication::SDLApplication () {
		
		if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) != 0) {
			
			printf ("Could not initialize SDL: %s.\n", SDL_GetError ());
			
		}
		
		SDL_LogSetPriority (SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN);
		
		currentApplication = this;
		
		framePeriod = 1000.0 / 60.0;
		
		#ifdef EMSCRIPTEN
		emscripten_cancel_main_loop ();
		emscripten_set_main_loop (UpdateFrame, 0, 0);
		emscripten_set_main_loop_timing (EM_TIMING_RAF, 1);
		#endif
		
		currentUpdate = 0;
		lastUpdate = 0;
		nextUpdate = 0;
		
		ApplicationEvent applicationEvent;
		DropEvent dropEvent;
		GamepadEvent gamepadEvent;
		JoystickEvent joystickEvent;
		KeyEvent keyEvent;
		MouseEvent mouseEvent;
		RenderEvent renderEvent;
		SensorEvent sensorEvent;
		TextEvent textEvent;
		TouchEvent touchEvent;
		WindowEvent windowEvent;
		
		SDL_EventState (SDL_DROPFILE, SDL_ENABLE);
		SDLJoystick::Init ();
		
		#ifdef HX_MACOS
		CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL (CFBundleGetMainBundle ());
		char path[PATH_MAX];
		
		if (CFURLGetFileSystemRepresentation (resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) {
			
			chdir (path);
			
		}
		
		CFRelease (resourcesURL);
		#endif
		
	}
Beispiel #17
0
void
loop()
{
    if(cbd[0].done) {
#ifdef __EMSCRIPTEN__
        emscripten_cancel_main_loop();
#endif
        SDL_PauseAudioDevice(cbd[0].dev, 1);
        SDL_CloseAudioDevice(cbd[0].dev);
        SDL_FreeWAV(sound);
        SDL_Quit();
    }
}
Beispiel #18
0
void
loop()
{
    for (int i = 0; i < devcount; i++) {
      if ((!cbd[i].dev) || (cbd[i].done)) {
        emscripten_cancel_main_loop();
        SDL_PauseAudioDevice(cbd[0].dev, 1);
        SDL_CloseAudioDevice(cbd[0].dev);
        SDL_FreeWAV(sound);
        SDL_Quit();
      }
    }
}
Beispiel #19
0
 void trampoline()
 {
     if(instance != nullptr)
     {
         if(!instance->shuttingDown())
             instance->loop();
         else
         {
             instance->destroy();
             instance = nullptr;
             emscripten_cancel_main_loop();
         }
     }
 }
Beispiel #20
0
void loop(void) {
  emscripten_sleep(1);
  loops++;
  printf("loop:  mains, inners, nevers, loops: %d, %d, %d, %d\n", mains, inners, nevers, loops);
  if (loops > 5) {
    printf("done looping\n");
    emscripten_cancel_main_loop();
    assert(mains == 1); // never re-enter main
    assert(inners == 1); // never re-enter inner
    assert(nevers == 0); // never reach never
    int result = 1;
    REPORT_RESULT();
    return;
  }
}
Beispiel #21
0
void
loop()
{
#ifdef __EMSCRIPTEN__
    /* Avoid using delays */
    if(SDL_GetTicks() - wait_start < 1000)
        return;
    wait_start = SDL_GetTicks();
#endif
    SDL_Event event;
    int i;
    /* Check for events */
    while (SDL_PollEvent(&event)) {
        SDLTest_CommonEvent(state, &event, &done);
    }

    /* Move a viewport box in steps around the screen */
    viewport.x = j * 100;
    viewport.y = viewport.x;
    viewport.w = 100 + j * 50;
    viewport.h = 100 + j * 50;
    j = (j + 1) % 4;
    SDL_Log("Current Viewport x=%i y=%i w=%i h=%i", viewport.x, viewport.y, viewport.w, viewport.h);

    for (i = 0; i < state->num_windows; ++i) {
        if (state->windows[i] == NULL)
            continue;

        /* Draw using viewport */
        DrawOnViewport(state->renderers[i], viewport);

        /* Update the screen! */
        if (use_target) {
            SDL_SetRenderTarget(state->renderers[i], NULL);
            SDL_RenderCopy(state->renderers[i], state->targets[i], NULL, NULL);
            SDL_RenderPresent(state->renderers[i]);
            SDL_SetRenderTarget(state->renderers[i], state->targets[i]);
        } else {
            SDL_RenderPresent(state->renderers[i]);
        }
    }

#ifdef __EMSCRIPTEN__
    if (done) {
        emscripten_cancel_main_loop();
    }
#endif
}
Beispiel #22
0
void main_loop() {
  static int counter = 0;
#if EMSCRIPTEN
  counter++;
#endif
  if (counter == 100) {
    printf("stop!\n");
#if EMSCRIPTEN
    emscripten_cancel_main_loop();
#endif
    return;
  }

  ENetEvent event;
//printf("enet host?\n");
  if (enet_host_service (host, & event, 0) == 0) return;
printf("enet host, got event of type %d\n", event.type);
  switch (event.type)
  {
    case ENET_EVENT_TYPE_CONNECT:
      printf ("A new client connected from %x:%u.\n",
              event.peer -> address.host,
              event.peer -> address.port);
      /* Store any relevant client information here. */
      event.peer -> data = "Client information";

      send_msg(event.peer);

      break;
    case ENET_EVENT_TYPE_RECEIVE:
      printf ("A packet of length %u containing %s was received from %s on channel %u.\n",
              event.packet -> dataLength,
              event.packet -> data,
              event.peer -> data,
              event.channelID);
      /* Clean up the packet now that we're done using it. */
      enet_packet_destroy (event.packet);
      break;
    case ENET_EVENT_TYPE_DISCONNECT:
      printf ("%s disconected.\n", event.peer -> data);
      /* Reset the peer's client information. */
      event.peer -> data = NULL;
      enet_host_destroy(host);
      break;
    default:
      printf("whaaa? %d\n", event.type);
  }
}
void iter(void *arg) {  
  static char readbuf[1024];
  static int readPos = 0;
  
  fd_set sett;
  FD_ZERO(&sett);
  FD_SET(SocketFD, &sett);
  
  if( readPos < 7 ){
    // still reading
    int selectRes = select(64, &sett, NULL, NULL, NULL);
    
    if( selectRes == 0 )
      return;
    
    if( selectRes == -1 ){
      perror( "Connection to websocket server failed" );
      exit(EXIT_FAILURE);
    }
    if( selectRes > 0 ){
      assert(FD_ISSET(SocketFD, &sett));
      
      int bytesRead = recv( SocketFD, readbuf+readPos, 7-readPos, 0 );
      readPos += bytesRead;
    }
  } else {
    // here the server should have closed the connection
    int selectRes = select(64, &sett, NULL, NULL, NULL);
    
    if( selectRes == 0 )
      return;
    
    if( selectRes == -1 ){
      perror( "Connection to websocket server failed as expected" );
      int result = 266;
      REPORT_RESULT();
      emscripten_cancel_main_loop();
      done = 1;
    } 
    
    if( selectRes > 0 ){
      printf( "Error: socket should not show up on select call anymore.\n" );
      exit(EXIT_FAILURE);
    }     
  }
  
  return;
}
Beispiel #24
0
static void emscripten_mainloop(void) {
	if (!loop_run) {
		esMusic_halt();
		if (emscripten_exit) emscripten_exit();
		emscripten_cancel_main_loop();
		return;
	}

	Uint32 current = SDL_GetTicks();
	float pass = 0.001f * (float) (current - emscripten_last_frame);
	emscripten_last_frame = current;

	events();
	if (!loop_run) return;
	emscripten_frame(pass);
}
Beispiel #25
0
void loop()
{
    SDL_Event event;

    /* Check for events */
    while (SDL_PollEvent(&event)) {
        if (event.type == SDL_QUIT || event.type == SDL_KEYDOWN) {
            done = 1;
        }
    }
    MoveSprites(renderer, sprite);
#ifdef __EMSCRIPTEN__
    if (done) {
        emscripten_cancel_main_loop();
    }
#endif
}
void loop_iter()
{
    clock_t time = clock();
    double delta = (double)(time - last_time)/(CLOCKS_PER_SEC/1000.0);
    last_time = time;

    reset_input_state();
    update_input();

    update_world(delta);

#ifdef __EMSCRIPTEN__
    if (done) {
 	        emscripten_cancel_main_loop();
 	    }
#endif
}
Beispiel #27
0
void main_loop() {
#ifdef __EMSCRIPTEN__
  static int counter = 0;
  counter++;
  if (counter == 100) {
    printf("stop!\n");
    emscripten_cancel_main_loop();
    return;
  }
#endif

  ENetEvent event;
  if (enet_host_service (host, & event, 0) == 0) return;
  switch (event.type)
  {
    case ENET_EVENT_TYPE_CONNECT:
      printf ("Connection succeeded!\n");

      break;
    case ENET_EVENT_TYPE_RECEIVE:
      printf ("A packet of length %u containing %s was received from %s on channel %u.\n",
              event.packet -> dataLength,
              event.packet -> data,
              event.peer -> data,
              event.channelID);

      int result = strcmp("packetfoo", event.packet->data);
#ifdef __EMSCRIPTEN__
      REPORT_RESULT(result);
#else
      exit(EXIT_SUCCESS);
#endif

      /* Clean up the packet now that we're done using it. */
      enet_packet_destroy (event.packet);
      break;
    case ENET_EVENT_TYPE_DISCONNECT:
      printf ("%s disconected.\n", event.peer -> data);
      /* Reset the peer's client information. */
      event.peer -> data = NULL;
      enet_host_destroy(host);
      break;
    default:
      printf("whaaa? %d\n", event.type);
  }
}
Beispiel #28
0
void
loop()
{
    SDL_Event event;
    /* Check for events */
    /*SDL_WaitEvent(&event); emscripten does not like waiting*/

    while (SDL_PollEvent(&event)) {
        switch (event.type) {
        case SDL_KEYDOWN:
        case SDL_KEYUP:
            PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
            break;
        case SDL_TEXTEDITING:
            PrintText("EDIT", event.text.text);
            break;
        case SDL_TEXTINPUT:
            PrintText("INPUT", event.text.text);
            break;
        case SDL_MOUSEBUTTONDOWN:
            /* Left button quits the app, other buttons toggles text input */
            if (event.button.button == SDL_BUTTON_LEFT) {
                done = 1;
            } else {
                if (SDL_IsTextInputActive()) {
                    SDL_Log("Stopping text input\n");
                    SDL_StopTextInput();
                } else {
                    SDL_Log("Starting text input\n");
                    SDL_StartTextInput();
                }
            }
            break;
        case SDL_QUIT:
            done = 1;
            break;
        default:
            break;
        }
    }
#ifdef __EMSCRIPTEN__
    if (done) {
        emscripten_cancel_main_loop();
    }
#endif
}
Beispiel #29
0
	SDLApplication::SDLApplication () {
		
		if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) != 0) {
			
			printf ("Could not initialize SDL: %s.\n", SDL_GetError ());
			
		}
		
		currentApplication = this;
		
		framePeriod = 1000.0 / 60.0;
		
		#ifdef EMSCRIPTEN
		emscripten_cancel_main_loop ();
		emscripten_set_main_loop (UpdateFrame, 0, 0);
		emscripten_set_main_loop_timing (EM_TIMING_RAF, 1);
		#endif
		
		currentUpdate = 0;
		lastUpdate = 0;
		nextUpdate = 0;
		
		GamepadEvent gamepadEvent;
		KeyEvent keyEvent;
		MouseEvent mouseEvent;
		RenderEvent renderEvent;
		TextEvent textEvent;
		TouchEvent touchEvent;
		UpdateEvent updateEvent;
		WindowEvent windowEvent;
		
		#ifdef HX_MACOS
		CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL (CFBundleGetMainBundle ());
		char path[PATH_MAX];
		
		if (CFURLGetFileSystemRepresentation (resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) {
			
			chdir (path);
			
		}
		
		CFRelease (resourcesURL);
		#endif
		
	}
void mainey() {
  static int counter = 0;
  printf("mainey: %d\n", counter++);
  if (counter == 20) {
    emscripten_pause_main_loop();
    emscripten_async_call(five, (void*)55, 1000);
  } else if (counter == 22) { // very soon after 20, so without pausing we fail
    assert(fived);
    emscripten_push_main_loop_blocker(pre1, (void*)123);
    emscripten_push_main_loop_blocker(pre2, (void*)98);
  } else if (counter == 23) {
    assert(pre1ed);
    assert(pre2ed);
    printf("Good!\n");
    emscripten_cancel_main_loop();
    emscripten_set_main_loop_arg(argey, (void*)17, 0, 0);
  }
}