Esempio n. 1
0
void golgotha_app::receive_event(i4_event * ev)
{
	switch (ev->type())
	{
		case i4_event::DISPLAY_CHANGE:
			{
				CAST_PTR(dev, i4_display_change_event_class, ev);
				if (dev->change==i4_display_change_event_class::SIZE_CHANGE)
				{
					get_root_window()->resize(get_display()->width(),get_display()->height());
				}

			} break;
		case i4_event::DO_COMMAND:
			{
				fo_sym.get();

				g1_cwin_man->receive_event(ev);
				char * cmd=((i4_do_command_event_class *)ev)->command;
				li_symbol * s=li_get_symbol(cmd);
				if (li_get_fun(s,0))
				{
					li_call(s);
				}

				g1_input.receive_event(ev);
			} break;

		case i4_event::END_COMMAND:
			{
				g1_cwin_man->receive_event(ev);
				char cmd[200];
				sprintf(cmd, "-%s",((i4_do_command_event_class *)ev)->command);
				li_symbol * s=li_get_symbol(cmd);
				if (li_get_fun(s,0))
				{
					li_call(cmd);
				}
				g1_input.receive_event(ev);
			} break;

		case i4_event::USER_MESSAGE:
			{
				CAST_PTR(uev,i4_user_message_event_class,ev);
				switch (uev->sub_type)
				{
					case G1_MAIN_MENU:
						do_main_menu();
						break;

					case G1_NETWORK_MENU:
						network_menu();
						break;
					case G1_SERVER_MENU:
						server_menu();
						break;
					case G1_CLIENT_JOINED_MENU:
						client_wait_menu();
						break;

					case G1_YOU_LOSE:
						help_screen("youlose_screen", G1_MAIN_MENU);
						break;

					case G1_YOU_WIN:
						{
							CAST_PTR(fptr,i4_file_open_message_class,uev);
							win_screen("youwin_screen", fptr->filename);
						}
						break;

					case G1_HELP_SCREEN:
						help_screen("help_screen", G1_RETURN_TO_GAME);
						break;

					case G1_START_HELP_SCREEN:
						help_screen("help_screen", G1_START_NEW_GAME);
						break;

					case G1_PLOT_SCREEN:
						plot_screen();
						break;

					case G1_START_NEW_GAME:
						start_new_game();
						break;

					case G1_RETURN_TO_GAME:
						return_to_game();
						break;

					case G1_SAVEGAME_SAVE:
						save_savegame();
						break;

					case G1_SAVEGAME_SAVE_OK:
						save_savegame_ok(uev); //Saving a savegame must not change
						//the map's filename.
						break;

					case G1_SAVEGAME_LOAD_OK:
						start_saved_game(uev);
						break;

					case G1_SAVEGAME_LOAD:
						open_savegame();
						break;

					case G1_OPTIONS:
						do_options();
						break;

					case G1_QUIT:
						quit();
						break;
					case G1_ESCAPE:
						do_main_menu();
						break;

					case G1_MAP_CHANGED:
						map_changed();
						break;

					case G1_GET_ROOT_IMAGE:
						{
							CAST_PTR(get, g1_get_root_image_event, ev);
							get->result=display->get_screen();
						} break;


					case G1_REDRAW_LATER:
						{
							redraw_later.waiting=i4_F;
							li_call("redraw_all");
						} break;

					case G1_PLAY_MOVIE:
						if (g1_map_is_loaded())
						{
							pre_play_save();

							if (g1_get_map()->start_movie())
							{
								playing_movie=i4_T;
								g1_resources.paused=i4_F;
							}

						}
						break;

					case G1_STOP_MOVIE:
						{
							if (playing_movie)
							{
								if (g1_map_is_loaded())
								{
									g1_get_map()->stop_movie();

									post_play_load();
								}

								playing_movie=i4_F;

								if (g1_current_controller.get() &&
									g1_current_controller->view.get_view_mode()==G1_CAMERA_MODE)
								{
									g1_current_controller->view.suggest_camera_mode(G1_ACTION_MODE);
								}
							}

						} break;

					case G1_GET_CURRENT_MOVIE:
						{
							if (g1_map_is_loaded())
							{
								CAST_PTR(mev, g1_get_current_movie_event, ev);
								mev->mflow=g1_get_map()->current_movie;
							}

						} break;

					case G1_INTERLACE_PIXEL:
						{
							g1_cwin_man->destroy_views();
							g1_resources.render_window_expand_mode = R1_COPY_1x1_SCANLINE_SKIP;
							g1_cwin_man->create_views();
						} break;

					case G1_DOUBLE_PIXEL:
						{
							g1_cwin_man->destroy_views();
							g1_resources.render_window_expand_mode = R1_COPY_2x2;
							g1_cwin_man->create_views();
						} break;

					case G1_NORMAL_PIXEL:
						{
							g1_cwin_man->destroy_views();
							g1_resources.render_window_expand_mode = R1_COPY_1x1;
							g1_cwin_man->create_views();
						} break;

				}
			} break;

		default:
			i4_application_class::receive_event(ev);
	}
}
Esempio n. 2
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();
	//}

}
Esempio n. 3
0
enum plugin_status
plugin_start (const void *parameter)
{
    int btn;

    rb->mkdir (DEFAULT_SAVE_DIR);

    global_setup ();

#ifdef GBN_TEST
    run_tests ();
    return PLUGIN_OK;
#endif

    if (!(parameter && load_game (parameter)))
    {
        if (parameter)
        {
            rb->splashf (2 * HZ, "Loading %s failed.", (char *) parameter);
        }

        if (!load_game (DEFAULT_SAVE))
        {
            rb->strcpy (save_file, DEFAULT_SAVE);

            if (!setup_game (MAX_BOARD_SIZE, MAX_BOARD_SIZE, 0, 0))
            {
                return PLUGIN_ERROR;
            }
        }
    }
    else
    {
        /* game loaded */
        if (rb->strcmp (save_file, DEFAULT_SAVE))
        {
            /* delete the scratch file if we loaded a game and it wasn't
             * from the scratch file
             */
            rb->remove (DEFAULT_SAVE);
        }
    }

    draw_screen_display ();

    autosave_counter = 0;
    for (;;)
    {
        btn = rb->button_get_w_tmo (HZ * 30);

        if (disable_shutdown)
        {
            /* tell rockbox we're not idle */
            rb->reset_poweroff_timer ();
        }

        bool is_idle = false;

        switch (btn)
        {

#if defined(GBN_BUTTON_NAV_MODE)
        case GBN_BUTTON_NAV_MODE:
        case GBN_BUTTON_NAV_MODE | BUTTON_REPEAT:
            if (nav_mode == NAV_MODE_TREE)
            {
                nav_mode = NAV_MODE_BOARD;
                rb->splash (2 * HZ / 3, "board navigation mode");
                draw_screen_display ();
            }
            else
            {
                nav_mode = NAV_MODE_TREE;
                rb->splash (2 * HZ / 3, "tree navigation mode");
                draw_screen_display ();
            }
            break;
#endif

#if defined(GBN_BUTTON_ADVANCE)
        case GBN_BUTTON_ADVANCE:
        case GBN_BUTTON_ADVANCE | BUTTON_REPEAT:
            if (has_more_nodes_sgf ())
            {
                if (!redo_node_sgf ())
                {
                    rb->splash (2 * HZ, "redo failed");
                }
                draw_screen_display ();
            }
            break;
#endif

#if defined(GBN_BUTTON_RETREAT)
        case GBN_BUTTON_RETREAT:
        case GBN_BUTTON_RETREAT | BUTTON_REPEAT:
            if (has_prev_nodes_sgf ())
            {
                if (!undo_node_sgf ())
                {
                    rb->splash (3 * HZ / 2, "Undo Failed");
                }
                draw_screen_display ();
            }
            break;
#endif

        case GBN_BUTTON_PLAY:
            if (play_mode == MODE_PLAY || play_mode == MODE_FORCE_PLAY)
            {
                if (!play_move_sgf (cursor_pos, current_player))
                {
                    rb->splash (HZ / 3, "Illegal Move");
                }
            }
            else if (play_mode == MODE_ADD_BLACK)
            {
                if (!add_stone_sgf (cursor_pos, BLACK))
                {
                    rb->splash (HZ / 3, "Illegal");
                }
            }
            else if (play_mode == MODE_ADD_WHITE)
            {
                if (!add_stone_sgf (cursor_pos, WHITE))
                {
                    rb->splash (HZ / 3, "Illegal");
                }
            }
            else if (play_mode == MODE_REMOVE)
            {
                if (!add_stone_sgf (cursor_pos, EMPTY))
                {
                    rb->splash (HZ / 3, "Illegal");
                }
            }
            else if (play_mode == MODE_MARK)
            {
                if (!add_mark_sgf (cursor_pos, PROP_MARK))
                {
                    rb->splash (HZ / 3, "Couldn't Mark");
                }
            }
            else if (play_mode == MODE_CIRCLE)
            {
                if (!add_mark_sgf (cursor_pos, PROP_CIRCLE))
                {
                    rb->splash (HZ / 3, "Couldn't Mark");
                }
            }
            else if (play_mode == MODE_SQUARE)
            {
                if (!add_mark_sgf (cursor_pos, PROP_SQUARE))
                {
                    rb->splash (HZ / 3, "Couldn't Mark");
                }
            }
            else if (play_mode == MODE_TRIANGLE)
            {
                if (!add_mark_sgf (cursor_pos, PROP_TRIANGLE))
                {
                    rb->splash (HZ / 3, "Couldn't Mark");
                }
            }
            else if (play_mode == MODE_LABEL)
            {
                if (!add_mark_sgf (cursor_pos, PROP_LABEL))
                {
                    rb->splash (HZ / 3, "Couldn't Label");
                }
            }
            else
            {
                rb->splash (HZ, "mode not implemented");
            }

            draw_screen_display ();
            break;

        case GBN_BUTTON_RIGHT:
        case GBN_BUTTON_RIGHT | BUTTON_REPEAT:
#if defined(GBN_BUTTON_NAV_MODE)
            if (nav_mode == NAV_MODE_TREE)
            {
                if (has_more_nodes_sgf ())
                {
                    if (!redo_node_sgf ())
                    {
                        rb->splash (2 * HZ, "Redo Failed");
                    }
                    draw_screen_display ();
                }
            }
            else
            {
#endif
                cursor_pos = WRAP (EAST (cursor_pos));
                draw_screen_display ();
#if defined(GBN_BUTTON_NAV_MODE)
            }
#endif
            break;

        case GBN_BUTTON_LEFT:
        case GBN_BUTTON_LEFT | BUTTON_REPEAT:
#if defined(GBN_BUTTON_NAV_MODE)
            if (nav_mode == NAV_MODE_TREE)
            {
                if (has_prev_nodes_sgf ())
                {
                    if (!undo_node_sgf ())
                    {
                        rb->splash (2 * HZ, "Undo Failed");
                    }
                    draw_screen_display ();
                }
            }
            else
            {
#endif
                cursor_pos = WRAP (WEST (cursor_pos));
                draw_screen_display ();
#if defined(GBN_BUTTON_NAV_MODE)
            }
#endif
            break;

        case GBN_BUTTON_DOWN:
        case GBN_BUTTON_DOWN | BUTTON_REPEAT:
            cursor_pos = WRAP (SOUTH (cursor_pos));
            draw_screen_display ();
            break;

        case GBN_BUTTON_UP:
        case GBN_BUTTON_UP | BUTTON_REPEAT:
            cursor_pos = WRAP (NORTH (cursor_pos));
            draw_screen_display ();
            break;

        case GBN_BUTTON_MENU:
            if (do_main_menu ())
            {
                save_game (DEFAULT_SAVE);

                global_cleanup ();
                return PLUGIN_OK;
            }

            draw_screen_display ();
            break;

#if defined(GBN_BUTTON_CONTEXT)
        case GBN_BUTTON_CONTEXT:
            do_context_menu ();
            draw_screen_display ();
            break;
#endif

#if defined(GBN_BUTTON_NEXT_VAR)
        case GBN_BUTTON_NEXT_VAR:
        case GBN_BUTTON_NEXT_VAR | BUTTON_REPEAT:
        {
            int temp;
            if ((temp = next_variation_sgf ()) >= 0)
            {
                draw_screen_display ();
                rb->splashf (2 * HZ / 3, "%d of %d", temp,
                             num_variations_sgf ());
                draw_screen_display ();
            }
            else
            {
                if (num_variations_sgf () > 1)
                {
                    rb->splashf (HZ, "Error %d in next_variation_sgf", temp);
                }
                draw_screen_display ();
            }
            break;
        }
#endif

        case BUTTON_NONE:
            is_idle = true;
        default:
            if (rb->default_event_handler (btn) == SYS_USB_CONNECTED)
            {
                return PLUGIN_USB_CONNECTED;
            }
            break;
        };

        if (is_idle && autosave_dirty)
        {
            ++autosave_counter;

            if (autosave_time != 0 &&
                autosave_counter / 2 >= autosave_time)
                /* counter is in 30 second increments, autosave_time is in
                 * minutes
                 */
            {
                DEBUGF("autosaving\n");
                rb->splash(HZ / 4, "Autosaving...");
                save_game(DEFAULT_SAVE);
                draw_screen_display();
                autosave_counter = 0;
            }
        }
        else
        {
            autosave_counter = 0;
        }
    }

    return PLUGIN_OK;
}