Esempio n. 1
0
Screen::Screen() :
  sdl_init_{make_scoped_call(SDL_Init,
                             SDL_Quit,
                             SDL_INIT_TIMER |
                             SDL_INIT_AUDIO |
                             SDL_INIT_VIDEO |
                             SDL_INIT_EVENTS)},
  ttf_init_{make_scoped_call(TTF_Init, TTF_Quit)},
  img_init_{make_scoped_call(IMG_Init, IMG_Quit, 0 /* no special libraries */)},
  window_{make_resource(SDL_CreateWindow,
                         SDL_DestroyWindow,
                         "EGGS",
                         SDL_WINDOWPOS_UNDEFINED,
                         SDL_WINDOWPOS_UNDEFINED,
                         kStartWidth,
                         kStartHeight,
                         SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE)},
  renderer_{make_resource(SDL_CreateRenderer,
                          SDL_DestroyRenderer,
                          window_.get(),
                          -1 /* first available driver */,
                          SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)},
  font_{make_resource(TTF_OpenFont, TTF_CloseFont,
                      get_asset_path("DroidSansMono.ttf").c_str(),
                      kFontPtSize)}
{
	empty_.r = 255;
	empty_.g = 255;
	empty_.b = 255;
	empty_.a = 0;
	text_color_.r = 0;
	text_color_.g = 0;
	text_color_.b = 0;
	text_color_.a = 0;
}
Esempio n. 2
0
static duk_ret_t
js_new_Logger(duk_context* ctx)
{
	const char* filename = duk_get_string(ctx, 0);

	char* path = get_asset_path(filename, "logs", true);
	logger_t* logger = open_log_file(path);
	free(path);
	if (logger == NULL)
		duk_error_ni(ctx, -1, DUK_ERR_ERROR, "OpenLog(): Failed to open file for logging '%s'", filename);
	duk_push_sphere_obj(ctx, "Logger", logger);
	return 1;
}
Esempio n. 3
0
static duk_ret_t
js_LoadFont(duk_context* ctx)
{
	const char* filename = duk_require_string(ctx, 0);
	
	font_t* font;
	
	char* path = get_asset_path(filename, "fonts", false);
	font = load_font(path);
	free(path);
	if (font == NULL)
		duk_error_ni(ctx, -1, DUK_ERR_ERROR, "LoadFont(): Failed to load font file '%s'", filename);
	duk_push_sphere_font(ctx, font);
	free_font(font);
	return 1;
}
Esempio n. 4
0
static duk_ret_t
js_HashRawFile(duk_context* ctx)
{
	const char* filename = duk_require_string(ctx, 0);

	FILE* file;
	char* path;

	path = get_asset_path(filename, "other", false);
	file = fopen(path, "rb");
	free(path);
	if (file == NULL)
		duk_error_ni(ctx, -1, DUK_ERR_ERROR, "HashRawFile(): Failed to open file '%s' for reading");
	fclose(file);
	// TODO: implement raw file hashing
	duk_error_ni(ctx, -1, DUK_ERR_ERROR, "HashRawFile(): Function is not yet implemented");
}
Esempio n. 5
0
static duk_ret_t
js_new_RawFile(duk_context* ctx)
{
	int n_args = duk_get_top(ctx);
	const char* filename = duk_require_string(ctx, 0);
	bool writable = n_args >= 2 ? duk_require_boolean(ctx, 1) : false;

	FILE* file;
	char* path;

	path = get_asset_path(filename, "other", writable);
	file = fopen(path, writable ? "w+b" : "rb");
	free(path);
	if (file == NULL)
		duk_error_ni(ctx, -1, DUK_ERR_ERROR, "OpenRawFile(): Failed to open file '%s' for %s",
			filename, writable ? "writing" : "reading");
	duk_push_sphere_obj(ctx, "RawFile", file);
	return 1;
}
Esempio n. 6
0
static duk_ret_t
js_LoadSound(duk_context* ctx)
{
	duk_int_t n_args = duk_get_top(ctx);
	const char* filename = duk_require_string(ctx, 0);
	duk_bool_t is_stream = n_args >= 2 ? duk_require_boolean(ctx, 1) : true;

	sound_t* sound;
	char*    sound_path;

	sound_path = get_asset_path(filename, "sounds", false);
	sound = load_sound(sound_path, is_stream);
	free(sound_path);
	if (sound == NULL)
		duk_error_ni(ctx, -1, DUK_ERR_ERROR, "LoadSound(): Failed to load sound file '%s'", filename);
	duk_push_sphere_sound(ctx, sound);
	free_sound(sound);
	return 1;
}