static unsigned char * handle_resolve_attr (fs_backend *be, fs_segment segment, unsigned int length, unsigned char *content) { unsigned int count = length / sizeof(fs_rid); if (segment > be->segments) { fs_error(LOG_ERR, "invalid segment number: %d", segment); return fsp_error_new(segment, "invalid segment number"); } if (length < sizeof(fs_rid)) { fs_error(LOG_ERR, "resolve_attr(%d) too short", segment); return fsp_error_new(segment, "too short"); } unsigned char *reply; fs_rid_vector v; fs_resource resources[count]; v.size = v.length = count; v.data = (fs_rid *) content; fs_resolve(be, segment, &v, resources); unsigned int k, serial_length = 0; for (k = 0; k < count; ++k) { if (resources[k].lex) { serial_length+= ((28 + strlen(resources[k].lex)) / 8); } else { serial_length+= 3; } } reply = message_new(FS_RESOURCE_ATTR_LIST, segment, 8 * serial_length); unsigned char *record = reply + FS_HEADER; for (k = 0; k < count; ++k) { unsigned int one_length; if (resources[k].lex) { one_length = ((28 + strlen(resources[k].lex)) / 8) * 8; } else { one_length = 24; } memcpy(record, &(resources[k].rid), sizeof (fs_rid)); memcpy(record + 8, &(resources[k].attr), sizeof (fs_rid)); memcpy(record + 16, &one_length, sizeof(one_length)); /* ASCII NUL is used to terminate strings on the wire */ if (resources[k].lex) { strcpy((char *) record + 20, resources[k].lex); } else { *(record + 20) = '\0'; } record += one_length; } return reply; }
int main(int argc, char *argv[]) { int camera = 0; SDL_Joystick *joy = NULL; if (!fs_init(argv[0])) { fprintf(stderr, "Failure to initialize virtual file system: %s\n", fs_error()); return 1; } srand((int) time(NULL)); lang_init("neverball"); opt_parse(argc, argv); config_paths(opt_data); fs_mkdir("Screenshots"); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0) { config_init(); config_load(); /* Cache Neverball's camera setting. */ camera = config_get_d(CONFIG_CAMERA); /* Initialize the joystick. */ if (config_get_d(CONFIG_JOYSTICK) && SDL_NumJoysticks() > 0) { joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE)); if (joy) { SDL_JoystickEventState(SDL_ENABLE); set_joystick(joy); } } /* Initialize the audio. */ audio_init(); /* Initialize the video. */ if (video_init(TITLE, ICON)) { int t1, t0 = SDL_GetTicks(); /* Run the main game loop. */ init_state(&st_null); if (opt_hole) { const char *path = fs_resolve(opt_hole); int loaded = 0; if (path) { hole_init(NULL); if (hole_load(0, path) && hole_load(1, path) && hole_goto(1, 1)) { goto_state(&st_next); loaded = 1; } } if (!loaded) goto_state(&st_title); } else goto_state(&st_title); while (loop()) if ((t1 = SDL_GetTicks()) > t0) { st_timer((t1 - t0) / 1000.f); st_paint(0.001f * t1); shot_take(); SDL_GL_SwapWindow(video_get_window()); t0 = t1; if (config_get_d(CONFIG_NICE)) SDL_Delay(1); } } /* Restore Neverball's camera setting. */ config_set_d(CONFIG_CAMERA, camera); config_save(); SDL_Quit(); } else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError()); return 0; }
int main(int argc, char *argv[]) { SDL_Joystick *joy = NULL; int t1, t0; if (!fs_init(argv[0])) { fprintf(stderr, "Failure to initialize virtual file system (%s)\n", fs_error()); return 1; } opt_parse(argc, argv); config_paths(opt_data); log_init("Neverball", "neverball.log"); make_dirs_and_migrate(); /* Initialize SDL. */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == -1) { log_printf("Failure to initialize SDL (%s)\n", SDL_GetError()); return 1; } /* Intitialize configuration. */ config_init(); config_load(); /* Initialize localization. */ lang_init(); /* Initialize joystick. */ if (config_get_d(CONFIG_JOYSTICK) && SDL_NumJoysticks() > 0) { joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE)); if (joy) SDL_JoystickEventState(SDL_ENABLE); } /* Initialize audio. */ audio_init(); tilt_init(); /* Initialize video. */ if (!video_init()) return 1; /* Material system. */ mtrl_init(); /* Screen states. */ init_state(&st_null); /* Initialize demo playback or load the level. */ if (opt_replay && fs_add_path(dir_name(opt_replay)) && progress_replay(base_name(opt_replay))) { demo_play_goto(1); goto_state(&st_demo_play); } else if (opt_level) { const char *path = fs_resolve(opt_level); int loaded = 0; if (path) { /* HACK: must be around for the duration of the game. */ static struct level level; if (level_load(path, &level)) { progress_init(MODE_STANDALONE); if (progress_play(&level)) { goto_state(&st_level); loaded = 1; } } } else log_printf("File %s is not in game path\n", opt_level); if (!loaded) goto_state(&st_title); } else goto_state(&st_title); /* Run the main game loop. */ t0 = SDL_GetTicks(); while (loop()) { if ((t1 = SDL_GetTicks()) > t0) { /* Step the game state. */ st_timer(0.001f * (t1 - t0)); t0 = t1; /* Render. */ hmd_step(); st_paint(0.001f * t0); video_swap(); if (config_get_d(CONFIG_NICE)) SDL_Delay(1); } } config_save(); mtrl_quit(); if (joy) SDL_JoystickClose(joy); tilt_free(); hmd_free(); SDL_Quit(); return 0; }
int main(int argc, char *argv[]) { int camera = 0; SDL_Joystick *joy = NULL; if (!fs_init(argv[0])) { fprintf(stderr, "Failure to initialize virtual file system (%s)\n", fs_error()); return 1; } srand((int) time(NULL)); opt_parse(argc, argv); config_paths(opt_data); log_init("Neverputt", "neverputt.log"); fs_mkdir("Screenshots"); /* Request backlight stay on (ubuntu touch) */ int dispreq = -1; DBusError err; dbus_error_init(&err); DBusConnection *conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err); if (dbus_error_is_set(&err)) { log_printf("Failed to get system bus\n"); dbus_error_free(&err); if (conn) { dbus_connection_unref(conn); conn = NULL; } } else { dbus_connection_set_exit_on_disconnect(conn, 0); DBusMessage *msg = dbus_message_new_method_call("com.canonical.Unity.Screen", "/com/canonical/Unity/Screen", "com.canonical.Unity.Screen", "keepDisplayOn"); if (msg != NULL) { DBusMessage *reply = dbus_connection_send_with_reply_and_block(conn, msg, 300, NULL); if (reply) { if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_INT32, &dispreq, DBUS_TYPE_INVALID)) dispreq = -1; dbus_message_unref(reply); } dbus_message_unref(msg); } if (dispreq == -1) log_printf("Failed to request backlight stay on\n"); } if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0) { config_init(); config_load(); /* Initialize localization. */ lang_init(); /* Cache Neverball's camera setting. */ camera = config_get_d(CONFIG_CAMERA); /* Initialize the joystick. */ if (config_get_d(CONFIG_JOYSTICK) && SDL_NumJoysticks() > 0) { joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE)); if (joy) { SDL_JoystickEventState(SDL_ENABLE); set_joystick(joy); } } /* Initialize the audio. */ audio_init(); /* Initialize the video. */ if (video_init()) { int t1, t0 = SDL_GetTicks(); /* Material system. */ mtrl_init(); /* Run the main game loop. */ init_state(&st_null); if (opt_hole) { const char *path = fs_resolve(opt_hole); int loaded = 0; if (path) { hole_init(NULL); if (hole_load(0, path) && hole_load(1, path) && hole_goto(1, 1)) { goto_state(&st_next); loaded = 1; } } if (!loaded) goto_state(&st_title); } else goto_state(&st_title); while (loop()) if ((t1 = SDL_GetTicks()) > t0) { st_timer((t1 - t0) / 1000.f); hmd_step(); st_paint(0.001f * t1); video_swap(); t0 = t1; if (config_get_d(CONFIG_NICE)) SDL_Delay(1); } mtrl_quit(); } /* Restore Neverball's camera setting. */ config_set_d(CONFIG_CAMERA, camera); config_save(); /* Remove backlight request (ubuntu touch) */ if (conn) { if (dispreq != -1) { DBusMessage *msg = dbus_message_new_method_call("com.canonical.Unity.Screen", "/com/canonical/Unity/Screen", "com.canonical.Unity.Screen", "removeDisplayOnRequest"); dbus_message_append_args(msg, DBUS_TYPE_INT32, &dispreq, DBUS_TYPE_INVALID); if (msg != NULL) { if (dbus_connection_send(conn, msg, NULL)) dbus_connection_flush(conn); dbus_message_unref(msg); } } dbus_connection_close(conn); dbus_connection_unref(conn); dbus_shutdown(); } SDL_Quit(); } else log_printf("Failure to initialize SDL (%s)\n", SDL_GetError()); return 0; }