static ssize_t dnr_param_store(struct device *dev, struct device_attribute *attr, const char *buff, size_t count) { int i = 0, vaule = 0; char *parm[2] = {NULL}, *buf_orig; buf_orig = kstrdup(buff, GFP_KERNEL); parse_cmd_params(buf_orig, (char **)(&parm)); for (i = 0; dnr_params[i].addr; i++) { if (!strcmp(parm[0], dnr_params[i].name)) { vaule = kstrtol(parm[1], 10, NULL); *(dnr_params[i].addr) = vaule; pr_info("%s=%d.\n", dnr_params[i].name, *(dnr_params[i].addr)); } } return count; }
/** * ANSI main entry point */ int main(int argc, char* argv[]) { unsigned long lvl_id; level::size lvl_sz; bool lvl_wrap; if (parse_cmd_params(argc, argv, lvl_id, lvl_sz, lvl_wrap)) return 0; //Help or version was shown //Initialization if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) != 0) { fprintf(stderr, "Critical error\nSDL_Init failed: %s\n", SDL_GetError()); return 1; } #ifdef USE_OPENGLES if (EGL_Open()){ fprintf(stderr, "Critical error\nUnable to open egl\n"); return 1; } #endif //Let's get some video information const SDL_VideoInfo* vinfo = SDL_GetVideoInfo(); if (!vinfo) { fprintf(stderr, "Critical error\nUnable to get video information: %s\n", SDL_GetError()); return 1; } //Save desktop size const int desktop_width = vinfo->current_w; const int desktop_height = vinfo->current_h; //Calculate minimum window sizes const int wnd_min_width = PW_SCREEN_WIDTH / 3; const int wnd_min_height = PW_SCREEN_HEIGHT / 3; //Create window #if USE_OPENGLES if (!SDL_SetVideoMode(800, 480, 0, SDL_FULLSCREEN)) { fprintf(stderr, "Critical error\nUnable to set video mode: %s\n", SDL_GetError()); return 1; } int prevcursorstate=SDL_ShowCursor(SDL_QUERY); SDL_ShowCursor(SDL_DISABLE); EGL_Init(); #else if (!SDL_SetVideoMode(PW_SCREEN_WIDTH, PW_SCREEN_HEIGHT, 0, SDL_OPENGL | SDL_RESIZABLE)) { fprintf(stderr, "Critical error\nUnable to set video mode: %s\n", SDL_GetError()); return 1; } #endif SDL_WM_SetCaption(PACKAGE_NAME, PACKAGE_NAME); image wnd_icon; if (wnd_icon.load_XPM(pipewalker_xpm, sizeof(pipewalker_xpm) / sizeof(pipewalker_xpm[0]))) SDL_WM_SetIcon(wnd_icon.get_surface(), NULL); game& game_instance = game::instance(); if (!game_instance.initialize(lvl_id, lvl_sz, lvl_wrap)) return 1; //Timer - about 25 fps SDL_SetTimer(40, &timer_callback); #ifdef WIN32 SDL_SysWMinfo wmi; SDL_VERSION(&wmi.version); if (SDL_GetWMInfo(&wmi)) { //Set own window procedure sdl_wnd_proc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(wmi.window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&pw_win32_wnd_proc))); //Set normal icon static HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(0)); if (icon) SetClassLongPtr(wmi.window, GCL_HICON, reinterpret_cast<LONG>(icon)); } #endif // WIN32 bool done = false; Uint8 last_mouse_state = 0; while (!done) { SDL_Event event; if (SDL_WaitEvent(&event) == 0) { fprintf(stderr, "Critical error\nSDL_WaitEvent failed: %s\n", SDL_GetError()); return 1; } switch (event.type) { case SDL_MOUSEMOTION: { Sint32 x, y; SDL_GetMouseState(&x, &y); game_instance.on_mouse_move(x, y); } break; case SDL_MOUSEBUTTONDOWN: //We need to save buttons state - in the SDL_MOUSEBUTTONUP event doesn't have this information last_mouse_state = SDL_GetMouseState(NULL, NULL); break; case SDL_MOUSEBUTTONUP: if (last_mouse_state) { game_instance.on_mouse_click(last_mouse_state); last_mouse_state = 0; } break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_F4 && (SDL_GetModState() == KMOD_LALT || SDL_GetModState() == KMOD_RALT)) done = true; //Alt+F4 pressed else done = game_instance.on_key_press(event.key.keysym.sym); break; case SDL_QUIT: done = true; break; case SDL_VIDEOEXPOSE: game_instance.draw_scene(); break; case SDL_VIDEORESIZE: if (event.resize.w && event.resize.h) { int wnd_width = event.resize.w; int wnd_height = event.resize.h; //Set correct aspect ratio if (wnd_width != desktop_width && wnd_height != desktop_height) { if (wnd_height != vinfo->current_h) wnd_width = static_cast<int>(static_cast<float>(wnd_height) / PW_ASPECT_RATIO); else if (wnd_width != vinfo->current_w) wnd_height = static_cast<int>(static_cast<float>(wnd_width) * PW_ASPECT_RATIO); if (wnd_width < wnd_min_width || wnd_height < wnd_min_height) { //Set minimum window size wnd_width = wnd_min_width; wnd_height = wnd_min_height; } } SDL_SetVideoMode(wnd_width, wnd_height, 0, SDL_OPENGL | SDL_RESIZABLE); game_instance.on_window_resize(wnd_width, wnd_height); SDL_Event expose_event; expose_event.type = SDL_VIDEOEXPOSE; SDL_PushEvent(&expose_event); } break; } } game_instance.finalize(); #if USE_OPENGLES EGL_Close(); SDL_ShowCursor(prevcursorstate); #endif SDL_Quit(); return 0; }