Пример #1
0
player::player() :
    m_force_realtime_framerate(false),
    m_log_bitmap_info(false)
{
    m_global = new as_object(this);

    action_init();

    if (s_player_count == 0)
    {
        // timer should be inited only once
        tu_timer::init_timer();

        standard_method_map_init();
    }

    ++s_player_count;

    // set startup random position
    Uint64 t = tu_timer::get_systime();
    t &= 0xFF;	// truncate
    for (unsigned int i = 0; i < t; i++)
    {
        tu_random::next_random();
    }

}
Пример #2
0
int main(int argc, const char ** argv) {
  struct timeval start_time, end_time;
  struct timespec tspec = {0, 0};
  struct timespec left = {0, 0};
  int error;
  long long elapsed;
  float cam_center_x, cam_center_y;

  if (swiftsure_log_init() < 0) {
    printf("Bad times, we couldn't open our log file =(\n");
    return -1;
  }

  rendering_init();

  if (input_init() < 0) {
    printf("Bad times, we couldn't initialize the input subsystem\n");
    return -1;
  }
  action_init();

  world.width = WORLD_SIZE;
  world.height = WORLD_SIZE;

  world_init(&world, 1);
  game_init();

  swiftsure_log(INFO, "Startin engines\n");

  frame = 0;
  elapsed = 16666;

  while (1) {
    gettimeofday(&start_time, NULL);

    game_get_avg_pos(&cam_center_x, &cam_center_y);
    render_set_camera(-cam_center_x, -cam_center_y, 4);

    handle_events();
    action_perform();
    render_start_frame();
    render_world(&world);
    game_render_players();
    render_end_frame();
    ++frame;

    physics_tick(&world, 10. / elapsed);

    //Rate limiting
    gettimeofday(&end_time, NULL);
    elapsed = (end_time.tv_sec - start_time.tv_sec) * 1000000 + (end_time.tv_usec - start_time.tv_usec);
    if (elapsed < 16666) {
      tspec.tv_nsec = (16666 - elapsed) * 1000;
      error = nanosleep(&tspec, &left);
      if (error < 0) {
        swiftsure_log(DEBUG, "We had %d seconds and %d nanoseconds left to sleep, errno %d\n", left.tv_sec, left.tv_nsec, errno);
      }
    }
  }
}
Пример #3
0
CreateNetworkAction* createnetwork_new(GString* name, guint64 bandwidthdown,
		guint64 bandwidthup, gdouble packetloss) {
	g_assert(name);
	CreateNetworkAction* action = g_new0(CreateNetworkAction, 1);
	MAGIC_INIT(action);

	action_init(&(action->super), &createnetwork_functions);

	action->id = g_quark_from_string((const gchar*)name->str);
	action->bandwidthdown = bandwidthdown;
	action->bandwidthup = bandwidthup;
	action->packetloss = packetloss;

	return action;
}
Пример #4
0
GenerateCDFAction* generatecdf_new(GString* name, guint64 center, guint64 width,
		guint64 tail)
{
	utility_assert(name);
	GenerateCDFAction* action = g_new0(GenerateCDFAction, 1);
	MAGIC_INIT(action);

	action_init(&(action->super), &generatecdf_functions);

	action->id = g_quark_from_string((const gchar*)name->str);
	action->center = center;
	action->width = width;
	action->tail = tail;

	return action;
}
Пример #5
0
LoadTopologyAction* loadtopology_new(GString* path, GString* text) {
	utility_assert(path || text);
	LoadTopologyAction* action = g_new0(LoadTopologyAction, 1);
	MAGIC_INIT(action);

	action_init(&(action->super), &loadtopology_functions);

	if(path) {
		action->path = g_string_new(path->str);
	}
	if(text) {
		action->text = g_string_new(text->str);
	}

	return action;
}
Пример #6
0
void user_init(void) {
	stdout_init();
	io_init();
	dht_init(SENSORTYPE, POOLTIME);

	// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
	// where image is written in flash that is defined in Makefile.
#ifdef ESPFS_POS
	espFsInit((void*)(0x40200000 + ESPFS_POS));
#else
	espFsInit((void*)(webpages_espfs_start));
#endif
	httpdInit(builtInUrls, 80);

        wifi_init();
	config_init();	
        action_init();
	os_printf("\nESP Ready\n");
}
Пример #7
0
ConnectNetworkAction* connectnetwork_new(GString* startCluster, GString* endCluster,
        guint64 latency, guint64 jitter, gdouble packetloss,
        guint64 latencymin, guint64 latencyQ1, guint64 latencymean, guint64 latencyQ3, guint64 latencymax) {
    g_assert(startCluster && endCluster);
    ConnectNetworkAction* action = g_new0(ConnectNetworkAction, 1);
    MAGIC_INIT(action);

    action_init(&(action->super), &connectnetwork_functions);

    action->sourceClusterID = g_quark_from_string(startCluster->str);
    action->destinationClusterID = g_quark_from_string(endCluster->str);

    /* copy the other network properties */
    action->latency = latency;
    action->jitter = jitter;
    action->packetloss = packetloss;
    action->latencymin = latencymin;
    action->latencyQ1 = latencyQ1;
    action->latencymean = latencymean;
    action->latencyQ3 = latencyQ3;
    action->latencymax = latencymax;

    return action;
}
Пример #8
0
static void _clone_rs_action(Reference *ref, BMapAction *action_set, Nonterminal *nt, int key, Action *action)
{
	Symbol *sb = ref->symbol;
	// Empty transitions should not be cloned.
	// They should be followed recursively to get the whole follow set,
	// otherwise me might loose reductions.

	// Always reduce?
	int clone_type = ACTION_REDUCE;

	Action *col = state_get_transition(nt->end, key);

	// TODO: Unify collision detection, skipping and merging with the ones
	// used in the state functions.
	if(col) {
		if(!action_compare(*action, *col)) {
			trace_op(
				"collision",
				nt->end,
				action,
				key,
				"skip duplicate",
				0
			);
			goto end;
		}

		//Collision: redefine actions in order to disambiguate.
		trace_op(
			"collision",
			nt->end,
			col,
			key,
			"unhandled return set collision",
			0
		);

		// TODO: sentinel?
	} else {

		//No collision detected, clone the action an add it.
		Action clone;
		action_init(&clone, clone_type, sb->id, NULL, action->flags, action->end_symbol);

		// TODO: Empty transitions should not be cloned.
		// They should be followed recursively to get the whole
		// follow set.
		// This happens when:
		// * A nonterminal is invoked at the end of a repetition and
		//   the repetition is within a group. An empty transition
		//   will be created between the repetition and the group,
		//   when the nonterminal is solved the empty transition will
		//   be found in the follow-set.

		trace_op(
			"add",
			nt->end,
			&clone,
			key,
			"return-set",
			0
		);

		bmap_action_m_append(action_set, key, clone);
	}
end:
	return;
}
Пример #9
0
static int _clone_fs_action(BMapAction *action_set, Reference *ref, int key, Action *action)
{
	int result = REF_RESULT_SOLVED;
	//TODO: Make type for clone a parameter, do not override by
	// default.

	// When a symbol is present, assume nonterminal invocation
	int clone_type;

	if(ref->type == REF_TYPE_DEFAULT) {
		// It could happen when merging loops in final states
		// that action->type == ACTION_REDUCE
		clone_type = action->type;
	} else if(ref->type == REF_TYPE_SHIFT) {
		if (action->type == ACTION_REDUCE) {
			// This could happen when the start state of a
			// nonterminal is also an end state.
			trace_op(
				"skip",
				ref->state,
				action,
				key,
				"reduction on first-set",
				0
			);
			goto end;
		}
		clone_type = ACTION_SHIFT;
	} else if(ref->type == REF_TYPE_START) {
		if (action->type == ACTION_REDUCE || action->type == ACTION_ACCEPT) {
			trace_op(
				"skip",
				ref->state,
				action,
				key,
				"reduction on first-set",
				0
			);
			goto end;
		}
		clone_type = ACTION_START;
	}

	//TODO: Detect collision for ranges (only testing `key` for now)
	Action *col = state_get_transition(ref->state, key);

	// TODO: Unify collision detection, skipping and merging with the ones
	// used in the state functions.
	if(col && ref->strategy == REF_STRATEGY_MERGE) {
		if(!action_compare(*action, *col)) {
			trace_op(
				"collision",
				ref->state,
				action,
				key,
				"skip duplicate",
				0
			);
			goto end;
		}

		if(col->state == NULL || action->state == NULL) {
			trace_op(
				"collision",
				ref->state,
				action,
				key,
				"unhandled",
				0
			);
			goto end;
		}

		//Collision: redefine actions in order to disambiguate.
		trace_op(
			"collision",
			ref->state,
			col,
			key,
			"deambiguate state",
			0
		);

		//TODO: should only merge if actions are identical
		//TODO: Make this work with ranges.
		State *merge = malloc(sizeof(State));
		state_init(merge);

		//Merge first set for the actions continuations.
		state_add_reference(merge, REF_TYPE_DEFAULT, REF_STRATEGY_MERGE, NULL, col->state);
		state_add_reference(merge, REF_TYPE_DEFAULT, REF_STRATEGY_MERGE, NULL, action->state);

		//Create unified action pointing to merged state.
		action_init(col, clone_type, col->reduction, merge, col->flags, col->end_symbol);

		result = REF_RESULT_CHANGED;
	} else {

		//No collision detected, clone the action an add it.
		Action clone;
		action_init(&clone, clone_type, action->reduction, action->state, action->flags, action->end_symbol);

		trace_op(
			"add",
			ref->state,
			&clone,
			key,
			"first-set",
			0
		);

		bmap_action_m_append(action_set, key, clone);
	}
end:
	return result;
}
Пример #10
0
gint main(gint argc, gchar *argv[])
{
	GtkWidget *window;
	GtkWidget *vbox;

	GtkWidget *menubar;
	GtkWidget *subMenu;
	GtkWidget *menuitem;

	GtkWidget *toolbar;

	GtkActionGroup* actiongroup;
	GtkUIManager* ui_manager;//主界面,包含了待建立的界面和相关的动作

	gtk_init(&argc, &argv);

	/**********初始化主界面$$$$$$$$**********{*/
	/*初始化主界面相关动作信息*/
	action_init(&actiongroup, &ui_manager);
	/*初始华主界面具体界面信息*/
	ui_init(&actiongroup, &ui_manager);
	/**********初始化主界面$$$$$$$$**********}*/

	/*window*/
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(window, "destroy"
			, G_CALLBACK(gtk_main_quit), NULL);
	/*添加快捷键*/
	gtk_window_add_accel_group(GTK_WINDOW(window),
			gtk_ui_manager_get_accel_group(ui_manager));

	/*vbox*/
	vbox = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(window), vbox);

	/***********使用、设置主界面中的元素$$$$$$******{*/
	/*从主界面获取一个部件的方法,便于添加到窗口中为什么这里有一个警告?*/
	menubar = gtk_ui_manager_get_widget(ui_manager, "/menubar");
	gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);

	/*从主界面获取一个菜单项的方法,获取之后设置其属性*/
	menuitem = gtk_ui_manager_get_widget(ui_manager, "/menubar/Menu1/menuitem1.1");
	/*从主界面把本来可以点击的菜单按钮设置为无法点击,非激活状态,工具栏上面仍然可以点*/
	gtk_widget_set_sensitive(GTK_WIDGET(menuitem),
			FALSE);

	/*从主界面获取一个子菜单的方法,获取之后添加一个额外不属于主界面的菜单*/
	subMenu = gtk_menu_item_get_submenu(
			GTK_MENU_ITEM(gtk_ui_manager_get_widget(ui_manager, "/menubar/Menu2")));
	/*可以添加2个额外的分割线*/
	menuitem = gtk_separator_menu_item_new();
	gtk_menu_shell_append(GTK_MENU_SHELL(subMenu), menuitem);
	menuitem = gtk_separator_menu_item_new();
	gtk_menu_shell_append(GTK_MENU_SHELL(subMenu), menuitem);
	menuitem = gtk_menu_item_new_with_label("added out the Ui");
	gtk_menu_shell_append(GTK_MENU_SHELL(subMenu), menuitem);
	gtk_widget_show_all(GTK_WIDGET(subMenu));//此处如果不写,那么即使后面有window的show_all那也没法显示这个菜单.

	/*从主界面获取工具栏的部件*/
	toolbar = gtk_ui_manager_get_widget(ui_manager, "/toolbar_navigation");
	gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), 0);
	gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);

	g_object_unref(ui_manager);
	/***********使用、设置主界面中的元素$$$$$$******}*/

	gtk_widget_show_all(window);
	gtk_main();
	return 0;
}