Пример #1
0
int main(int argc, char *argv[])
{
	UNUSED(argc); UNUSED(argv);
	int exit_status = EXIT_FAILURE;
	bit quit = 0;
	SDL_Event e;

	INIT_SDL();

	font1 = TTF_OPENFONT("sdl/OpenSans-Regular.ttf", 28);
	font2 = TTF_OPENFONT("sdl/OpenSans-Regular.ttf", 100);
	text1 = TEXTURE_FROM_TEXT(font1, "Press S to start / stop, P to pause / unpause.", (SDL_Color){0xFF, 0xFF, 0xFF, 0xFF});
	text3 = TEXTURE_FROM_TEXT(font2, "BOGOMETER", (SDL_Color){0xFF, 0x7F, 0x3F, 0xFF});

	while (!quit) {
		DRAW();
		if (SDL_PollEvent(&e)) {
			if (e.type == SDL_QUIT)
				quit = 1;
			else if (e.type == SDL_KEYDOWN)
				key_down(e.key.keysym.sym);
		}
	}

	exit_status = EXIT_SUCCESS;
error:
	SDL_DestroyTexture(text1);
	SDL_DestroyTexture(text3);
	TTF_CloseFont(font1);
	TTF_CloseFont(font2);
	close_sdl();
	exit(exit_status);
}
Пример #2
0
int main(int argc, char *argv[])
{
	UNUSED(argc); UNUSED(argv);
	int exit_status = EXIT_FAILURE;
	bit quit = 0;
	SDL_Event e;

	INIT_SDL();

	back = LOAD_TEXTURE("sdl/back.png");
	sprite_sheet = LOAD_TEXTURE("sdl/animation.png");

	while (!quit) {
		while (SDL_PollEvent(&e)) {
			if (e.type == SDL_QUIT)
				quit = 1;
		}
		input();
		DRAW();
	}

	exit_status = EXIT_SUCCESS;
error:
	SDL_DestroyTexture(back);
	SDL_DestroyTexture(sprite_sheet);
	close_sdl();
	exit(exit_status);
}
Пример #3
0
int main(int argc, char *argv[])
{
	UNUSED(argc); UNUSED(argv);
	int exit_status = EXIT_FAILURE;
	bit quit = 0;
	SDL_Event e;

	INIT_SDL();

	sprite_sheet = LOAD_TEXTURE("sdl/sprite_sheet.png");

	DRAW();
	while (!quit) {
		SDL_WAITEVENT(&e);
		if (e.type == SDL_QUIT)
			quit = 1;
		else if (e.type == SDL_KEYDOWN) {
			key_down(e.key.keysym.sym);
			DRAW();
		}
	}

	exit_status = EXIT_SUCCESS;
error:
	SDL_DestroyTexture(sprite_sheet);
	close_sdl();
	exit(exit_status);
}
Пример #4
0
int main(int argc, char *argv[])
{
	UNUSED(argc); UNUSED(argv);
	int exit_status = EXIT_FAILURE;
	bit quit = 0;
	SDL_Event e;

	INIT_SDLGL();

	while (!quit) {
		while (SDL_PollEvent(&e)) {
			if (e.type == SDL_QUIT)
				quit = 1;
			if (e.type == SDL_KEYDOWN)
				key_down(e.key.keysym.sym);
		}

		draw();
		SDL_GL_SwapWindow(window);
		GL_CHECK("GL Frame");
	}

	exit_status = EXIT_SUCCESS;
error:
	close_sdl();
	exit(exit_status);
}
Пример #5
0
int main(int argc, char *argv[])
{
	UNUSED(argc); UNUSED(argv);
	int exit_status = EXIT_FAILURE;
	bit quit = 0;
	SDL_Event e;

	INIT_SDL();

	while (!quit) {
		if (SDL_PollEvent(&e))
			if (e.type == SDL_QUIT)
				quit = 1;
		DRAW();
		a += 1;
	}

	exit_status = EXIT_SUCCESS;
error:
	close_sdl();
	exit(exit_status);
}
int main(int argc, char *argv[])
{
	UNUSED(argc); UNUSED(argv);
	int exit_status = EXIT_FAILURE;
	bit quit = 0;
	SDL_Event e;

	INIT_SDL();

	image = LOAD_IMAGE("sdl/logo.png", screen);
	DRAW();

	while (!quit) {
		SDL_WAITEVENT(&e);
		if (e.type == SDL_QUIT)
			quit = 1;
	}

	exit_status = EXIT_SUCCESS;
error:
	SDL_FreeSurface(image);
	close_sdl();
	exit(exit_status);
}
Пример #7
0
int
main(int argc, char *argv[])
{
	int quit = 0;
	/* event handler */
	SDL_Event event;
	/* modulation components */
	Uint8 r = 255;
	Uint8 g = 255;
	Uint8 b = 255;

	/* starts up SDL and create window */
	if (init_sdl() == -1) {
		fprintf(stderr, "Failed to initialize SDL!\n");
		return -1;
	}

	/* load media */
	if (load_media() == -1) {
		fprintf(stderr, "Failed to load media!\n");
		return -2;
	}

	/* main loop */
	while (quit == 0) {
		/* handle events on queue */
		while (SDL_PollEvent(&event) != 0) {
			/* users request quit */
			if (event.type == SDL_QUIT)
				quit = 1;

			/* on key press change rgb values */
			else if (event.type == SDL_KEYDOWN) {
				switch (event.key.keysym.sym) {
				case SDLK_q:	/* increase red */
					r += 32;
					break;
				case SDLK_w:	/* increase green */
					g += 32;
					break;
				case SDLK_e:	/* increase blue */
					b += 32;
					break;
				case SDLK_a:	/* decrease red */
					r -= 32;
					break;
				case SDLK_s:	/* decrease green */
					g -= 32;
					break;
				case SDLK_d:	/* decrease blue */
					b -= 32;
					break;
				}
			}
		}

		/* clear screen */
		SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
		SDL_RenderClear(gRenderer);

		/* modulate and render texture */
		gModulatedTexture.setColor(r, g, b);
		gModulatedTexture.render(0, 0);


		/* update screen */
		SDL_RenderPresent(gRenderer);
	}

	/* free resources and close */
	close_sdl();

	return 0;
}
Пример #8
0
int
main(int argc, char *argv[])
{
	int quit = 0;
	/* event handler */
	SDL_Event event;
	/* modulation components */
	Uint8 alpha = 255;


	/* starts up SDL and create window */
	if (init_sdl() == -1) {
		fprintf(stderr, "Failed to initialize SDL!\n");
		return -1;
	}

	/* load media */
	if (load_media() == -1) {
		fprintf(stderr, "Failed to load media!\n");
		return -2;
	}

	/* main loop */
	while (quit == 0) {
		/* handle events on queue */
		while (SDL_PollEvent(&event) != 0) {
			/* users request quit */
			if (event.type == SDL_QUIT)
				quit = 1;

			/* on key press change alpha values */
			else if (event.type == SDL_KEYDOWN) {
				/* increase alpha on w */
				if (event.key.keysym.sym == SDLK_w) {
					if (alpha + 32 > 255)
						alpha = 255;
					else
						alpha += 32;

				/* decrease alpha on s */
				} else if (event.key.keysym.sym == SDLK_s) {
					if (alpha - 32 < 0)
						alpha = 0;
					else
						alpha -= 32;
				}
			}
		}

		/* clear screen */
		SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
		SDL_RenderClear(gRenderer);

		/* render background */
		gBackgroundTexture.render(0, 0);

		/* render front blended */
		gModulatedTexture.setAlpha(alpha);
		gModulatedTexture.render(0, 0);


		/* update screen */
		SDL_RenderPresent(gRenderer);
	}

	/* free resources and close */
	close_sdl();

	return 0;
}
Пример #9
0
int
main(int argc, char *argv[])
{
	int quit = 0;
	/* event handler */
	SDL_Event event;

	/* the dot that will be moving around the screen */
	Dot dot;

	/* set the wall */
	SDL_Rect wall;
	wall.x = 300;
	wall.y = 40;
	wall.w = 40;
	wall.h = 400;

	/* starts up SDL and create window */
	if (init_sdl() == -1) {
		fprintf(stderr, "Failed to initialize SDL!\n");
		return -1;
	}

	/* load media */
	if (load_media() == -1) {
		fprintf(stderr, "Failed to load media!\n");
		return -2;
	}


	/* main loop */
	while (quit == 0) {
		/* handle events on queue */
		while (SDL_PollEvent(&event) != 0) {
			/* users request quit */
			if (event.type == SDL_QUIT)
				quit = 1;

			/* handle user key press */
			dot.handleEvent(event);
		}

		/* move the dot and check collision */
		dot.move(wall);


		/* clear screen */
		SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
		SDL_RenderClear(gRenderer);

		/* render wall */
		SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
		SDL_RenderDrawRect(gRenderer, &wall);

		/* render dot */
		dot.render();

		/* update screen */
		SDL_RenderPresent(gRenderer);
	}

	/* free resources and close */
	close_sdl();

	return 0;
}
Пример #10
0
void loop(NES nesSystem, const char * fileLoc) {

    if (!init_sdl(fileLoc)) {
        std::cerr << "SDL did not initialize, quitting" << std::endl;
        return;
    }

    Debugger debugger(&nesSystem);

    //game loop variables
    double frequency = SDL_GetPerformanceFrequency();
    uintmax_t startTime = SDL_GetPerformanceCounter();

    bool paused = true;

    SDL_Event event;

    for (int x = 0; x < 256 * 240; x++) localPixels[x] = 0;
    draw(nesSystem.m_nesCPU.m_nesPPU.m_pixels);       //draw screen black
    SDL_PauseAudioDevice(sdlAudioDevice, 0);    //unpause audio

    for (;;) {

        //1 process events
        if (!process_events(&event, &nesSystem.m_nesCPU.m_controllerByte, &paused)) {
            break;
        }

        //2 logic
        if (!paused) {
            do {

                enum DebuggerEventStatus debugEventStatus = debugger.pre_instr_events();
                if (debugEventStatus == BREAK_HIT || debugEventStatus == CRASH_IMMINENT) {
                    paused = true;
                    break;
                } else if (debugEventStatus == DONE_LOGGED_EXECUTION) {
                    paused = true;
                }

                //execute one cpu opcode
                nesSystem.m_nesCPU.execute_next_opcode();

                debugger.post_instr_events();



                //ppu catches up
                nesSystem.m_nesCPU.m_nesPPU.tick(&nesSystem.m_nesCPU.m_NMI, &nesSystem.m_nesCPU.m_cpuClock);
            } while (!nesSystem.m_nesCPU.m_nesPPU.m_draw && !paused);

            //3.1 audio
            nesSystem.m_nesCPU.m_nesAPU.fill_buffer(&nesSystem, &nesSystem.m_nesCPU.m_IRQ);
            if (SDL_GetQueuedAudioSize(sdlAudioDevice) > (unsigned int) nesSystem.m_nesCPU.m_nesAPU.m_audioBufferSize * 10) {
                //prevents audio from becoming too out of sync
                SDL_ClearQueuedAudio(sdlAudioDevice);
            }
            SDL_QueueAudio(sdlAudioDevice, (void *) nesSystem.m_nesCPU.m_nesAPU.m_audioBuffer, nesSystem.m_nesCPU.m_nesAPU.m_audioBufferSize);
            
        } else {

            enum DebuggerCommandStatus commandStatus;

            do {
                commandStatus = debugger.cmd();
            } while (commandStatus == CONTINUE_DEBUG);

            //SDL_FlushEvents(SDL_USEREVENT, SDL_LASTEVENT);

            if (commandStatus == RUN_NO_FOCUS) {
                paused = false;
            } else if (commandStatus == QUIT) {
                break;
            } else if (commandStatus == RUN_RETURN_FOCUS) {
                paused = false;
                SDL_RaiseWindow(window);
            } else {
                break;
            }
        }

        //3.2 video
        draw(nesSystem.m_nesCPU.m_nesPPU.m_pixels);
        
        //4 sync framerate
        double delay = MILLISECONDS_PER_FRAME - (((SDL_GetPerformanceCounter() - startTime) / frequency) * 1000) - 0.5;
        if (delay > 0) {
            std::this_thread::sleep_for(std::chrono::microseconds((int) (delay * 1000)));
        }
        while ((((SDL_GetPerformanceCounter() - startTime) / frequency) * 1000)  < MILLISECONDS_PER_FRAME) {

        }
        startTime = SDL_GetPerformanceCounter();
    }

    SDL_PauseAudioDevice(sdlAudioDevice, 1);    //pause
    SDL_ClearQueuedAudio(sdlAudioDevice);       //clear audio queue
    close_sdl();

    return;
}
Пример #11
0
int
main(int argc, char *argv[])
{
	int quit = 0;
	/* event handler */
	SDL_Event event;

	/* set text color as black */
	SDL_Color textColor = { 0, 0, 0, 255 };
	/* current time start time */
	Uint32 startTime = 0;
	char timeText[128];

	/* starts up SDL and create window */
	if (init_sdl() == -1) {
		fprintf(stderr, "Failed to initialize SDL!\n");
		return -1;
	}

	/* load media */
	if (load_media() == -1) {
		fprintf(stderr, "Failed to load media!\n");
		return -2;
	}

	/* main loop */
	while (quit == 0) {
		/* handle events on queue */
		while (SDL_PollEvent(&event) != 0) {
			/* users request quit */
			if (event.type == SDL_QUIT)
				quit = 1;

			/* reset start time on return key press */
			else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) {
				startTime = SDL_GetTicks();
			}
		}

		/* set text to be rendered */
		snprintf(timeText, sizeof(timeText), "%d", SDL_GetTicks() - startTime);

		/* render text */
		if (gTimeTextTexture.loadFromRenderedText(timeText, textColor) == -1)
			fprintf(stderr, "Unable to render time texture!\n");


		/* clear screen */
		SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
		SDL_RenderClear(gRenderer);

		/* render texture */
		gPromptTexture.render((SCREEN_WIDTH - gPromptTexture.getWidth()) / 2, 0);
		gTimeTextTexture.render((SCREEN_WIDTH - gTimeTextTexture.getWidth()) / 2,
			(SCREEN_HEIGHT - gTimeTextTexture.getHeight()) / 2);


		/* update screen */
		SDL_RenderPresent(gRenderer);
	}

	/* free resources and close */
	close_sdl();

	return 0;
}