Esempio n. 1
0
/**
 * @brief Constructs a new shadow atlas.
 * @details This constructs a new shadow atlas with the given size and tile size.
 *
 *   The size determines the total size of the atlas in pixels. It should be a
 *   power-of-two to favour the GPU.
 *
 *   The tile_size determines the smallest unit of tiles the atlas can store.
 *   If, for example, a tile_size of 32 is used, then every entry stored must
 *   have a resolution of 32 or greater, and the resolution must be a multiple
 *   of 32. This is to optimize the search in the atlas, so the atlas does not
 *   have to check every pixel, and instead can just check whole tiles.
 *
 *   If you want to disable the use of tiles, set the tile_size to 1, which
 *   will make the shadow atlas use pixels instead of tiles.
 *
 * @param size Atlas-size in pixels
 * @param tile_size tile-size in pixels, or 1 to use no tiles.
 */
ShadowAtlas::ShadowAtlas(size_t size, size_t tile_size) {
    nassertv(size > 1 && tile_size >= 1);
    nassertv(tile_size < size && size % tile_size == 0);
    _size = size;
    _tile_size = tile_size;
    _num_used_tiles = 0;
    init_tiles();
}
Esempio n. 2
0
/* create_sample is our game state's initialization function
 * and will return a fully ready instance of struct state for us
 * to work with in each frame.
 */
static void* create_sample(void)
{
    struct state* state = malloc(sizeof(struct state));
    state->space = cpSpaceNew();
    state->tile_img = create_image("res/particle.png");
    state->mouse_body = cpBodyNewKinematic();
    init_tiles(state);
    init_walls(state);
    return state;
}
Esempio n. 3
0
File: 2048.c Progetto: theta43/2048
int
main (void)
{
	bool win_condition = false;
	int ret, ch;

	puts ("Playing 2048 " VERSION " in ASCII mode");

	init_tiles (&game);

	ch = ret = 0;
	do {
		draw_game ();
		printf ("move [wasd]: ");
		fflush (NULL);

		if (ch == 0)
			continue;

		enum tile_dir dir = -1;

		switch (ch) {
		case 'W': dir = UP;	break;
		case 'A': dir = LEFT;	break;
		case 'S': dir = DOWN;	break;
		case 'D': dir = RIGHT;	break;
		default: continue;
		}

		if (move_tiles (&game, dir) == -1)
			break;

		if (game.max_tile == 2048 && !win_condition) {
			win_condition = 1;
			if (!ask_yn ("You won! Do you wish to continue? [Y/n]"))
				break;
		}

	} while ((ch = toupper(getchar())) != EOF);

	destroy_tiles (&game);

	printf ("\nScore: %d\n", game.score);
	if (game.max_tile < 2048) {
		puts ("You lost. Better luck next time\n");
		return 1;
	}

	return 0;
}
Esempio n. 4
0
int fpga_build_model(struct fpga_model* model, int fpga_rows,
	const char* columns, const char* left_wiring, const char* right_wiring)
{
	int rc;

	memset(model, 0, sizeof(*model));
	model->cfg_rows = fpga_rows;
	strncpy(model->cfg_columns, columns, sizeof(model->cfg_columns)-1);
	strncpy(model->cfg_left_wiring, left_wiring,
		sizeof(model->cfg_left_wiring)-1);
	strncpy(model->cfg_right_wiring, right_wiring,
		sizeof(model->cfg_right_wiring)-1);
	strarray_init(&model->str, STRIDX_64K);
	rc = get_xc6_routing_bitpos(&model->sw_bitpos, &model->num_bitpos);
	if (rc) FAIL(rc);

	// The order of tiles, then devices, then ports, then
	// connections and finally switches is important so
	// that the codes can build upon each other.

	rc = init_tiles(model);
	if (rc) FAIL(rc);

	rc = init_devices(model);
	if (rc) FAIL(rc);

	if (s_high_speed_replicate) {
		rc = replicate_routing_switches(model);
		if (rc) FAIL(rc);
	}

	// todo: compare.ports only works if other switches and conns
	//       are disabled, as long as not all connections are supported
	rc = init_ports(model, /*dup_warn*/ !s_high_speed_replicate);
	if (rc) FAIL(rc);

	rc = init_conns(model);
	if (rc) FAIL(rc);

	rc = init_switches(model, /*routing_sw*/ !s_high_speed_replicate);
	if (rc) FAIL(rc);
	return 0;
fail:
	return rc;
}
Esempio n. 5
0
/**
 * @brief Initializes image container
 *
 * @param container Malloc'ed type_image to be initialized.
 * @param image_bip Image properties.
 */
void init_bip_image(type_image *container, type_image_hyper *image_bip, type_parameters *param)
{
	println_start(INFO);
	container->height = 1;
	container->width = image_bip->num_bands;
	container->depth = (image_bip->data_type == 1 ? 8 : 16) * image_bip->num_bands;
	container->num_components = image_bip->num_lines * image_bip->num_samples;
	container->num_range_bits = container->depth / image_bip->num_bands;
	printf("%d %d %d %d %d\n", container->height, container->width, container->depth, container->num_components, container->num_range_bits);

	/* TODO: check if origin data was signed? */
	container->sign = SIGNED;
	container->num_dlvls = param->param_tile_comp_dlvls;

	/* Set coding parameters */
	set_coding_parameters(container, param);
	init_tiles(&container, param);
}
Esempio n. 6
0
/** used in client thread */
void sdl_user::init()
{
    main_config = new config("Lineage.ini");
    if (!main_config->config_ok())
    {
        delete main_config;
        main_config = 0;
        throw "ERROR Loading configuration file.\n";
    }
    char *test;
    test = (char*)getfiles->load_file("Sprite00.idx", 0, FILE_REGULAR1, 0);
    if (test == 0)
    {
        throw "Lineage Data not found";
    }
    delete [] test;
    lineage_font.init("Font/eng.fnt", this);	//TODO : make a client specific version of the font

    unsigned char *sprite_data;
    int sprite_dlength;
    sprite_data = (unsigned char*)getfiles->load_file("sprite_table.txt", &sprite_dlength, FILE_REGULAR2, 0);
    if (sprite_data == 0)
    {
        printf("sprite_table.txt not found\n");
    }
    else
    {
        int offset = 1;
        int sprnum = 0;
        printf("The first number is %d\n", atoi((char*)&sprite_data[offset]));
        while (isdigit(sprite_data[offset])) {
            offset++;
        }
        if (sprite_data[offset] == '=')
        {
            offset += 1;
            int alias = atoi((char*)&sprite_data[offset]);
            printf("Alias of %d found\n", alias);
            while (isdigit(sprite_data[offset])) {
                offset++;
            }
            while (!isdigit(sprite_data[offset])) {
                offset++;
            }
        }
        char value = atoi((char*)&sprite_data[offset]);
        while (isdigit(sprite_data[offset])) {
            offset++;
        }
        int temp;
        switch (value)
        {
        case 100:	//switches
            //read a value, then read 4 times that many values
            temp = atoi((char*)&sprite_data[offset]);
            while (isdigit(sprite_data[offset])) {
                offset++;
            }
            for (int i = 0; i < temp; i++)
            {
                atoi((char*)&sprite_data[offset]);
                while (isdigit(sprite_data[offset])) {
                    offset++;
                }
                atoi((char*)&sprite_data[offset]);
                while (isdigit(sprite_data[offset])) {
                    offset++;
                }
                atoi((char*)&sprite_data[offset]);
                while (isdigit(sprite_data[offset])) {
                    offset++;
                }
                atoi((char*)&sprite_data[offset]);
                while (isdigit(sprite_data[offset])) {
                    offset++;
                }
            }
            break;
        case 101: //shadow
            //read one value
            break;
        case 102: //objType
            //read one value
            break;
        case 103: //altAttack
            //read one value
            break;
        case 104: //attr
            //read one value
            break;
        case 105: //clothing
            //read a value
            //read 0 or that value of numbers, whichever is higher
            break;
        case 106: //weapons
            //?
            break;
        case 107: //size
            //read 2 numbers
            break;
        case 108: //flyingType
            //read one number
            break;
        case 109: //immaterial
            //read two numbers
            break;
        case 110:
            //read a number and modify the stack with it
            break;
        case 111: //stride
            //read one number
            break;
        case 112: //furniture
            //read one number
            break;
        case 113: //morphEffect
            //read one number
            break;
        case 114: //furnitureSize
            //read one number
            break;
        default:
            printf("?(%d)\n", value);
            break;
        }



        while (offset < sprite_dlength)
        {

            offset++;
        }
    }

    DesKeyInit("~!@#%^$<");	//TODO : move this code to a class and use an object
    init_packs();
    init_tiles();

    change_drawmode(DRAWMODE_LOADING);

    while (!are_you_ready())
    {
        check_requests();
    }
    draw_loading *load;
    int what_server;
    load = (draw_loading*)get_drawmode(false);

    //wait for the user to pick a server
    do
    {
        what_server = load->get_server_pick();
        check_requests();
    } while (what_server == -1);

    server_name = new char[strlen(main_config->get_name(what_server)) + 1];
    strcpy(server_name, main_config->get_name(what_server));

    server = new connection(main_config, what_server);
    proc = new packet(server, this);
    if (get_updates(server, load) > 0)
    {
    }

    //check for custom opcodes
    unsigned char *copcodes;
    copcodes = (unsigned char*)getfiles->load_file("opcodes.txt", 0, FILE_REGULAR3, 0);
    if (copcodes != 0)
    {   //there are custom opcodes for this server
        printf("This server has custom opcodes\n");
        int offset;
        char *data = (char*)copcodes;
        for (int i = 0; i < 256; i++)
        {
            char *p;
            p = strtok(data, "\n");
            if (data != NULL)
                data = NULL;
            int temp;
            sscanf(p, "%d", &temp);
            convert_client_packets[i] = (unsigned char)temp;
        }
        for (int i = 0; i < 256; i++)
        {
            char *p;
            p = strtok(data, "\n");
            if (data != NULL)
                data = NULL;
            int temp;
            sscanf(p, "%d", &temp);
            convert_server_packets[i] = (unsigned char)temp;
        }
        delete [] copcodes;
        copcodes = 0;
    }

    //begin game portion of client
//	if (server->connection_ok() == 1)
    {
        if (server->change() != 1)
        {
            throw "Failed to connect to game server\n";
        }
    }

    init_codepage(0);
    init_math_tables();
//	printf("STUB Load player config\n");
//	printf("STUB Initialize emblem cache\n");
    init_strings();
    load->load_done();
}
Esempio n. 7
0
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
 int argc = __argc;
 char **argv = __argv;
#else
int main(int argc, char *argv[])
{
#endif
#ifdef ENABLE_LOGGING
  setupDebug();
#endif
 int seed = time(NULL);

// set locale to system default
 setlocale(LC_ALL, "");
#ifdef LOCALIZE
 bindtextdomain("cataclysm-dda", "lang/mo");
 bind_textdomain_codeset("cataclysm-dda", "UTF-8");
 textdomain("cataclysm-dda");
#endif

//args: world seeding only.
 argc--; argv++;
 while (argc){
  if(std::string(argv[0]) == "--seed"){
   argc--; argv++;
   if(argc){
    seed = djb2_hash((unsigned char*)argv[0]);
    argc--; argv++;
   }
  }
  else // ignore unknown args.
   argc--; argv++;
 }

// ncurses stuff
 initOptions();
 load_options(); // For getting size options
 initscr(); // Initialize ncurses
 #ifdef SDLTILES
 init_tiles();
 #endif // SDLTILES
 noecho();  // Don't echo keypresses
 cbreak();  // C-style breaks (e.g. ^C to SIGINT)
 keypad(stdscr, true); // Numpad is numbers
 init_colors(); // See color.cpp
// curs_set(0); // Invisible cursor
 set_escdelay(10); // Make escape actually responsive

 std::srand(seed);

 bool quit_game = false;
 g = new game;
 g->init_data();
 if(g->game_error())
  exit_handler(-999);
 g->init_ui();
 MAPBUFFER.set_game(g);
 if(g->game_error())
  exit_handler(-999);

 curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone

 #if (!(defined _WIN32 || defined WINDOWS))
  struct sigaction sigIntHandler;
  sigIntHandler.sa_handler = exit_handler;
  sigemptyset(&sigIntHandler.sa_mask);
  sigIntHandler.sa_flags = 0;
  sigaction(SIGINT, &sigIntHandler, NULL);
 #endif

 do {
  if(!g->opening_screen()) {
     quit_game = true;
  }
  while (!g->do_turn()) ;
  if (g->game_quit() || g->game_error())
   quit_game = true;
 } while (!quit_game);


 exit_handler(-999);

 return 0;
}