int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { bool fullscreen = false; Core::log.Init("log.htm", true); File::c_file settings("settings.ini"); if (!settings.is_open()) { return -1; } std::string str = settings.getline(); while (!str.empty()) { std::string name, value; if (utils::ReadNvp(str, name, value)) { if (name == "path") { File::cd(value); } else if (name == "fullscreen") { fullscreen = utils::lexical_cast<bool>(value); } } str = settings.getline(); } HWND hWnd = ::FindWindow(MYWINDOW_CLASS_NAME, MYAPPLICATION_NAME); if (hWnd == NULL) { if (CheckDXVersion()) { MyApplication application(hInstance, nCmdShow, fullscreen); application.enableCustomCursor = false; application.showFps = true; application.maxFps = 0; application.SETTINGS_REG_KEY = MYSETTINGS_REG_KEY; application.APPLICATION_NAME = MYAPPLICATION_NAME; application.WINDOW_CLASS_NAME = MYWINDOW_CLASS_NAME; application.Init(true); application.Start(); application.ShutDown(); } } else { ::SetForegroundWindow(hWnd); ::SetFocus(hWnd); ::UpdateWindow(hWnd); } return 0; }
void golgotha_app::init() { sw32 i; for (i=0; i<(int)argc; i++) { if (argv[i] == "-max_memory") { i++; i4_const_str::iterator p(argv[i].begin()); _max_memory = (w32)p.read_number(); } } char buf[300]; #ifdef _WINDOWS LoadString(i4_win32_instance,IDS_INITIALISATION,buf,300); #else printf("Starting initialisation sequence\n"); strcpy(buf,"Initialisation, please wait..."); #endif i4_status_class * status=i4_create_status(buf,0); status->update(0.01f); r1_truncate_texture_file(); i4_file_class * inittest=i4_open("resource.res",I4_READ|I4_NO_BUFFER); if (!inittest) { //i4_error("_FATAL: resource.res not found in the current directory. " // "Check that the current directory is the directory the exe-file " // "resides in."); #ifdef _WINDOWS MessageBox(0,"FATAL: resource.res not found in the current directory. " "Check that the current directory is the directory the exe-file " "resides in.","Golgotha: Wrong startup directory",0); #else printf("FATAL: resource.res not found in the current directory. \n" "Check that the current directory is the directory the executable file \n" "resides in."); #endif exit(89); } delete inittest; memory_init(); //calls init__init::i4_init() to init all i4_init_classes status->update(0.1f); i4_endianesstest end; end.anint=0x0ff; #pragma warning (disable:4127) // Conditional expression is constant if (end.chars[0]==0xff) { i4_warning("Detected architecture is little endian."); if (i4_litend!=1) { i4_error("FATAL: Golgotha was compiled for a big-endian system. " "Please rebuild Golgotha with the correct endianness setting in arch.h"); exit(92); } } else { i4_warning("Detected architecture is big endian."); if (i4_litend!=0) { i4_error("FATAL: Golgotha was compiled for a little-endian system. " "Please rebuild Golgotha with the correct endianness setting in arch.h"); exit(92); } } #pragma warning(1:4127) i4_warning("Loading resource Manager..."); resource_init("resource.res",0); strcpy(first_level, "test.level"); //Hardcoded first level li_add_function("set_default_level", g1_set_default_level); i4_warning("Executing scheme/start.scm"); li_load("scheme/start.scm"); i4_mkdir("savegame"); //create the savegame directory if it doesn't exist #ifdef _WINDOWS CheckDXVersion(); #endif status->update(0.2f); display_init(); status->update(0.23f); printf("Display initialisation ok.\n"); i4_image_class * im=i4_load_image("bitmaps/comic1.jpg"); printf("If this line is drawn, the jpg loader is ok.\n"); status->update(0.25f); #ifdef _WINDOWS cwnd.Attach(current_window_handle); g1_sound_man.poll(i4_T); // update sound effects (play next narative sfx) do_poll_sound_man=i4_T; i4_add_thread((i4_thread_func_type)Thread_Sound_Man_Poller,1000,NULL); g1_sound_man.loop_current_song=i4_T; #else //All sound is currently disabled under linux and the thread synchronization //code isn't complete either do_poll_sound_man=i4_F; g1_sound_man.loop_current_song=i4_F; #endif //wm is the window-manager wm->set_background_color(0); if (im) //Im is the Cartoon image { loading_window=new i4_image_window_class(im, i4_T, i4_F); wm->add_child(wm->width()/2-loading_window->width()/2, wm->height()/2-loading_window->height()/2, loading_window.get()); } refresh(); // show something right away status->update(0.3f); char * font_fname=li_get_string(li_get_value("font"),0); i4_image_class * fim=i4_load_image(font_fname); if (!fim) { i4_error("image load failed : %s", font_fname); } i4_current_app->get_style()->font_hint->normal_font=new i4_anti_proportional_font_class(fim); delete fim; status->update(0.4f); choice_first_level(); //Attempt to initialize a rendering api suitable for the current display. g1_render.r_api = r1_create_api(display); i4_warning("Render api created successfully: %s.",g1_render.r_api->name()); refresh(); status->update(0.5f); //init the renderer! if (!g1_render.r_api) { /* MessageBox(NULL,"Could not initialize a rendering device. \n" "Possible Causes:\n-You tried to run the game in a window " "with your desktop color depth not equal to 16Bit.\n" "-There's not enough video memory available for this mode.\n" "-Your DirectX installation is invalid.\n" "-Well, err...","DirectX initialisation failed", MB_OK+MB_ICONSTOP+MB_APPLMODAL);*/ #ifdef _WINDOWS char * s=(char *)malloc(1000); LoadString(AfxGetResourceHandle(),IDS_RENDERINITFAILED,s,999); MessageBox(NULL,s,"DirectX",MB_OK+MB_ICONSTOP+MB_APPLMODAL); free(s); FatalExit(99); #else printf("FATAL ERROR: Initialisation of renderer failed. Quitting.\n"); exit(99); #endif } g1_input.init(); g1_resources.load(); li_load("scheme/preferences.scm"); status->update(0.6f); i4_bool movie_time = i4_F; for (i=0; i<(int)argc; i++) { if (argv[i] == i4gets("movie_option")) { movie_time = i4_T; } } if (g1_render.r_api->get_render_device_flags() & R1_SOFTWARE) { //setup a timer and decide whether or not to do double pixel //default is high res mode int processor_speed = i4_get_clocks_per_second(); g1_resources.render_window_expand_mode = R1_COPY_1x1; /* if (processor_speed > 170000000) g1_resources.render_window_expand_mode = R1_COPY_1x1; else if (processor_speed > 140000000) g1_resources.render_window_expand_mode = R1_COPY_1x1_SCANLINE_SKIP; else g1_resources.render_window_expand_mode = R1_COPY_2x2; g1_resources.radius_mode = g1_resource_class::VIEW_LOW; */ if (movie_time) { g1_resources.radius_mode = g1_resource_class::VIEW_FAR; } } else { //hardware rasterizer, view distance = far by default g1_resources.radius_mode = g1_resource_class::VIEW_FAR; } s1_load(); g1_load_images(); status->update(0.7f); g1_player_man.init_colors(&display->get_screen()->get_pal()->source, g1_render.r_api); protocol=i4_get_first_protocol(); i4_graphical_style_class * style=wm->get_style(); /* style->color_hint->button.active.bright=(135<<8)|64; style->color_hint->button.active.medium=(114<<8)|49; style->color_hint->button.active.dark=(88<<8)|38; style->color_hint->button.passive.bright=(120<<8)|64; style->color_hint->button.passive.medium=(100<<8)|49; style->color_hint->button.passive.dark=(70<<8)|38; */ if (!g1_cwin_man) { g1_cwin_man=new g1_cwin_man_class; } status->update(0.8f); g1_cwin_man->init(wm, style, display->get_screen(), display, wm); if (m1_maxtool_man) { m1_maxtool_man->init(wm,style,display->get_screen(),display,wm); } li_add_function("Pause", g1_pause); li_add_function("ForcePause", g1_force_pause); li_add_function("is_paused",g1_is_paused); status->update(1.0f); hide_main_menu(); main_menu=new g1_help_screen_class(wm->width(), wm->height(), wm->get_style(), i4gets("startup_screen"), G1_PLOT_SCREEN); wm->add_child(0,0,main_menu); delete status; status=0; i4_kernel.request_events(this, i4_device_class::FLAG_DO_COMMAND | i4_device_class::FLAG_END_COMMAND| i4_device_class::FLAG_DISPLAY_CHANGE); do_main_menu(); if (start_in_editor) { g1_cwin_man->set_edit_mode(i4_T); } //start game with startup screens //if (!movie_time) //{ // help_screen("startup_screen", G1_START_HELP_SCREEN); //} //else //{ // start_new_game(); //} }