Exemplo n.º 1
0
bool graphics_init(gfx_t* gfx)
{
    memset(gfx, 0, sizeof *gfx);

    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
        return false;
    }

    if (!window_init(&gfx->window, "Spielbub", SCREEN_WIDTH, SCREEN_HEIGHT)) {
        return false;
    }

    gfx->background = create_surface();
    gfx->sprites_bg = create_surface();
    gfx->sprites_fg = create_surface();

    if (!gfx->background || !gfx->sprites_bg || ! gfx->sprites_fg) {
        goto error;
    }

    gfx->layers[0] = gfx->background;
    gfx->layers[1] = gfx->sprites_bg;
    gfx->layers[2] = gfx->sprites_fg;
    gfx->state = OAM;

    window_clear(&gfx->window);
    window_draw(&gfx->window);

    return true;

    error: {
        graphics_destroy(gfx);
        return false;
    }
}
Exemplo n.º 2
0
bool bbruntime_destroy(){
	runtime_glfw3_destroy();
	graphics_destroy();
	blitz2d_destroy();
	pixmap_destroy();
	userlibs_destroy();
	audio_fmod_destroy();
	audio_destroy();
	input_directinput8_destroy();
	input_destroy();
	timer_windows_destroy();
	filesystem_windows_destroy();
	filesystem_destroy();
	system_windows_destroy();
	bank_destroy();
	system_destroy();
	runtime_destroy();
	enet_destroy();
	sockets_destroy();
	stream_destroy();
	stdio_destroy();
	string_destroy();
	math_destroy();
	event_destroy();
	hook_destroy();
	blitz_destroy();
	return true;
}
Exemplo n.º 3
0
bool bbruntime_create(){
	if( blitz_create() ){
				if( hook_create() ){
						if( event_create() ){
								if( math_create() ){
										if( string_create() ){
												if( stdio_create() ){
														if( stream_create() ){
																if( sockets_create() ){
																		if( enet_create() ){
																				if( runtime_create() ){
																						if( system_create() ){
																								if( bank_create() ){
																										if( system_windows_create() ){
																												if( filesystem_create() ){
																														if( filesystem_windows_create() ){
																																if( timer_windows_create() ){
																																		if( input_create() ){
																																				if( input_directinput8_create() ){
																																						if( audio_create() ){
																																								if( audio_fmod_create() ){
																																										if( userlibs_create() ){
																																												if( pixmap_create() ){
																																														if( blitz2d_create() ){
																																																if( graphics_create() ){
																																																		if( runtime_glfw3_create() ){
																																																				return true;
																									}else sue( "runtime_glfw3_create failed" );
																									graphics_destroy();
																								}else sue( "graphics_create failed" );
																								blitz2d_destroy();
																							}else sue( "blitz2d_create failed" );
																							pixmap_destroy();
																						}else sue( "pixmap_create failed" );
																						userlibs_destroy();
																					}else sue( "userlibs_create failed" );
																					audio_fmod_destroy();
																				}else sue( "audio_fmod_create failed" );
																				audio_destroy();
																			}else sue( "audio_create failed" );
																			input_directinput8_destroy();
																		}else sue( "input_directinput8_create failed" );
																		input_destroy();
																	}else sue( "input_create failed" );
																	timer_windows_destroy();
																}else sue( "timer_windows_create failed" );
																filesystem_windows_destroy();
															}else sue( "filesystem_windows_create failed" );
															filesystem_destroy();
														}else sue( "filesystem_create failed" );
														system_windows_destroy();
													}else sue( "system_windows_create failed" );
													bank_destroy();
												}else sue( "bank_create failed" );
												system_destroy();
											}else sue( "system_create failed" );
											runtime_destroy();
										}else sue( "runtime_create failed" );
										enet_destroy();
									}else sue( "enet_create failed" );
									sockets_destroy();
								}else sue( "sockets_create failed" );
								stream_destroy();
							}else sue( "stream_create failed" );
							stdio_destroy();
						}else sue( "stdio_create failed" );
						string_destroy();
					}else sue( "string_create failed" );
					math_destroy();
				}else sue( "math_create failed" );
				event_destroy();
			}else sue( "event_create failed" );
			hook_destroy();
		}else sue( "hook_create failed" );
		blitz_destroy();
	}else sue( "blitz_create failed" );
	return false;
}
Exemplo n.º 4
0
int main(int argc, char** args)
{
	srand(time(NULL));

	int error;
	c_cpu_handle cpu;
	
	printf("Cuilien cell simulation.\n");

	printf("Initializing VM...\n");
	cpu = c_cpu_init();
	if(c_error_last)
	{
		c_error_print(c_error_last);
		return 1;
	}
	
	printf("Disabling a few opcodes...\n");
	c_instruction_vector[C_INSTR_PUTC] = NULL;
	c_instruction_vector[C_INSTR_GETC] = NULL;
	c_instruction_vector[C_INSTR_SHOW] = NULL;

	printf("Initializing IVT...\n");
	cpu->ivt = build_ivt();

	printf("Loading seed...\n");
	c_mem_handle seed = c_mem_init(MAX_CELL_MEMORY);
	c_mem_load_file(seed, "seed2.cx", 12);

	printf("Setting up graphics...\n");
	if((error = graphics_init()))
	{
		// TODO: handle error
		return 1;
	}
	
	printf("Creating world...\n");
	world_load(&world, "terrain3.bmp");
	graphics_init_world_image(world);

	printf("Spawning inital cells...\n");
	cells_init();

	champion_cell = cell_spawn(c_mem_copy(seed), 1, 0x00ff00, 5, 180, 200);
	champion_cell->save = true;

	cell_spawn(c_mem_copy(seed), 1, 0xff0000, 5, 1000, 200);
	// cell_spawn(c_mem_copy(seed), 0x0000ff, 5, 180, 600);
	// cell_spawn(c_mem_copy(seed), 0xffff00, 5, 1000, 600);
	
	printf("Ready.\n");
	
	while(!graphics_update() && cells_get_count())
	{
		world_update_waste(world);

		// simulate and render cells
		/* this turned out messier than I had envisioned it */
		int i = 0;
		while((current_cell = cell_next(&i)))
		{
			cpu->context = &current_cell->process.context;

			assert(cpu->context != NULL);
			assert(cpu->context->memory != NULL);

			int step;
			for(step = 0; step < 100 && current_cell->alive; ++step)
			{
				c_cpu_step(cpu);
			}

			if(current_cell->mass)
			{
				/* mass decay */
				--current_cell->mass;
			
				/* produce waste */
				tile_t* tile = world_get_tile(world, current_cell->x, current_cell->y);
				if(tile->waste != 255)
				{
					++tile->waste;
					graphics_update_world_image(current_cell->x, current_cell->y, tile);
				}
			}

			graphics_render_cell(current_cell);

			if(current_cell != champion_cell &&
					cell_lifetime(current_cell) >= cell_lifetime(champion_cell))
			{
				champion_cell->save = false;
				if(!champion_cell->alive)
					cell_kill(champion_cell);

				current_cell->save = true;
				champion_cell = current_cell;
			}

			if(current_cell->mass == 0 ||
					cell_lifetime(current_cell) > 1000) /* test death by age */
				cell_kill(current_cell);
		}

		++cycle;
	}

	printf("Champion: \n");
	printf(" * Color: %06X\n", champion_cell->color);
	printf(" * Generation: %d\n", champion_cell->generation);
	printf(" * Times split: %d\n", champion_cell->times_split);
	printf(" * Cycles lived: %d\n", cell_lifetime(champion_cell));
	printf(" * Time of birth: %d\n", champion_cell->birth);
	if(champion_cell->alive)
		printf(" * Time of death: ALIVE\n");
	else
		printf(" * Time of death: %d\n", champion_cell->death);
	printf(" * Place of death: %d, %d\n", champion_cell->x, champion_cell->y);
	c_mem_dump_to_file(champion_cell->process.context.memory, "champion.dump");
	printf("Memory dumped to champion.dump.\n");
	
	printf("Freeing memory...\n");
	cells_free();
	c_mem_free(seed);
	
	printf("Destroying graphics...\n");
	if((error = graphics_destroy()))
	{
		// TODO: handle error
		return 1;
	}

	printf("Freeing VM...\n");
	c_cpu_free(cpu);
	
	printf("Good bye!\n");
}