Example #1
0
static void
initialize(int argc, char *argv[])
{
	srand(time(NULL));
	initialize_sdl();
	initialize_opengl();
	initialize_gameplay_data();
	initialize_mainmenu_data();
}
Example #2
0
static int initialize_sdl_video()
{
	if (initialize_sdl())
		return -1;
	if (SDL_InitSubSystem(SDL_INIT_VIDEO)) {
		log_e("%s", SDL_GetError());
		return -1;
	}
	if (get_console_fullscreen()) {
		SDL_ShowCursor(SDL_DISABLE);
		flags |= SDL_WINDOW_FULLSCREEN;
	} else
		flags &= ~SDL_WINDOW_FULLSCREEN;
	return 0;
}
Example #3
0
int main(int argc, const char * argv[])
{
    if(2 != argc) {
        printf("Usage: ./chip8 filename\n");
        return 1;
    }

    // This should be the file to load
    const char* filename = argv[1];

    // Init the system
    chip8* cpu = (chip8 *) malloc(sizeof(chip8));
    initialize(cpu);
    initialize_sdl();

    SDL_Window* window;
    SDL_Renderer* renderer;
    if(SDL_CreateWindowAndRenderer(640, 320, SDL_WINDOW_SHOWN, &window, &renderer) == -1) {
        printf("Failed to generate SDL video, %s", SDL_GetError());
        SDL_Quit();
    }

    // Load the specified game
    load_game(cpu, filename);

    int quit = 0;
    Uint32 delay = 2;
    while(!quit) {
        Uint32 timeout = SDL_GetTicks() + 16;
        while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {

            // Debugging to dump the state of the emulator
            dump_state(cpu);

            SDL_Event event;
            // Consume key queue
            while (SDL_PollEvent(&event) != 0) {
                //User requests quit
                if (event.type == SDL_QUIT) {
                    quit = 1;
                } else if(event.type == SDL_KEYDOWN) {
                    switch(event.key.keysym.sym) {
                        case SDLK_RIGHT:
                            delay += 10;
                            break;
                        case SDLK_LEFT:
                            if(delay<11) {
                                delay = 1;
                            } else {
                                delay-=10;
                            }
                            break;
                        default:
                            break;
                    }
                }
            }

            process_delayRegister(cpu);
            process_soundRegister(cpu);

            // Execute the next instruction
            uint16_t opcode = fetch(cpu);
            execute(cpu, opcode);

            SDL_Delay(delay);
            printf("Delay=%d\n", delay);
        }

        // Draw the state of the world
        if(cpu->shouldDraw) {
            render(cpu, window, renderer);
            cpu->shouldDraw = false;
        }

    }

    deinitialize_sdl();

    return 0;
}
Example #4
0
int main()
{
    START_TIMER(program);
    // INITIALIZE SDL
    START_TIMER(sdl_initialization);
    initialize_sdl();
    SDL_Surface *input = load_image("assets/komona-small.png");
    SDL_Surface *output = load_image("assets/komona-small.png");
    SDL_Texture *texture = SDL_CreateTexture(renderer, input->format->format, SDL_TEXTUREACCESS_STREAMING, input->w, input->h);
    SDL_Rect fillRect = {0, 0, output->w, output->h};
    SDL_FillRect(output, &fillRect, 0x00000000);

    SDL_Rect updateRect = {0, 0, input->w, input->h};
    if(texture == NULL){
       printf("Failed to create texture: %s\n", SDL_GetError());
       exit(EXIT_FAILURE);
    }
    STOP_TIMER_AND_PRINT(sdl_initialization);


    // INITIALIZE CROSSCL
    // load cpu-side function pointer from filters/identity.so
    std::string filter_base = "threshold";
    std::string filterSource = "../CrossCL/example-filters/" + filter_base + ".filter";
    std::string filterLibrary = "../CrossCL-build/example-filters/lib" + filter_base + ".so";


    float content = 0.25;


    START_TIMER(compute_initialization);

    CrossCL::DeviceManager devManager = CrossCL::DeviceManager(loadLibrary, loadSymbol);
    std::vector<CrossCL::Device*> devices = devManager.getDevices(CrossCL::CPU_ACCELERATOR |  /*CrossCL::GPU_ACCELERATOR |*/ CrossCL::SOFTWARE);
    for(CrossCL::Device *dev: devices){
        std::cout << "Found device: " << dev->name() << std::endl;
    }
    CrossCL::Device *dev = devices[0];
    std::cout << "Selected device: " << dev->name() << std::endl;
    if(!dev->initialize()){
        std::cout << "device failed to initialize\n";
        exit(1);
    }

    CrossCL::Surface inputSurface;
    inputSurface.w = input->w;
    inputSurface.h = input->h;
    inputSurface.pitch = input->pitch;
    inputSurface.pixels = input->pixels;
    CrossCL::Surface outputSurface;
    outputSurface.w = output->w;
    outputSurface.h = output->h;
    outputSurface.pitch = output->pitch;
    outputSurface.pixels = output->pixels;
    START_TIMER(kernel_compile)
    CrossCL::Kernel *kernel = dev->createKernel(filterSource, filterLibrary, CrossCL::INPUT_STATIC);
    STOP_TIMER_AND_PRINT(kernel_compile);
    kernel->setParameter("in", &inputSurface);
    kernel->setParameter("out", &outputSurface);

    STOP_TIMER_AND_PRINT(compute_initialization);

    // MAIN LOOP
    SDL_Event e;
    bool quit = false;
    while(!quit){
        while (SDL_PollEvent(&e)){
            if (e.type == SDL_QUIT){
                quit = true;
            }
        }

        content = content + 0.005;
        //kernel->setParameter("threshold", content);

        // EXECUTE THE FILTER
        START_TIMER(filter);

        kernel->executeSync(outputSurface.w, outputSurface.h);

        STOP_TIMER_AND_PRINT(filter);

        // UPDATE THE TEXTURE
        SDL_UpdateTexture(texture, &updateRect, outputSurface.pixels, outputSurface.pitch);

        // RENDER
        SDL_RenderClear(renderer);
        SDL_RenderCopy(renderer, texture, NULL, NULL);

        SDL_RenderPresent(renderer);
    }
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(input);
    SDL_FreeSurface(output);
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    STOP_TIMER_AND_PRINT(program);
    return 0;
}