git @ Cat's Eye Technologies linapple / b7a244c
Load assets (resources) from BasePath First, renamed RESOURCE_*_BMP to ASSET_*_BMP because resource tends to mean specific things on gooey OSes. Secondly, we now use SDL_GetBasePath() and store it in asset_basepath. This means we always know where the linapple binary is located, irrespective of where it's run from. And that means we can load all of our assets relative to that directory! (Fixes #10) Currently we just die if SDL_GetBasePath() fails. Theoretically we could fall back on checking . for those files. Should we? T. Joseph Carter 3 years ago
5 changed file(s) with 40 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
785785
786786 FILE *spMono, *spStereo;
787787
788 char *asset_basepath;
789
788790 //---------------------------------------------------------------------------
789791
790792 int main(int argc, char * lpCmdLine[])
791793 {
794 asset_basepath = SDL_GetBasePath();
795 if (asset_basepath == NULL) {
796 fprintf(stderr, "SDL_GetBasePath() returned NULL for some reason\n");
797 return 1;
798 }
799
792800 // GPH: The very first thing we do is attempt to grab the needed configuration files and put them in the user's folder.
793801 Config config;
794802 config.ValidateUserDirectory();
11021110 curl_easy_cleanup(g_curl);
11031111 curl_global_cleanup();
11041112 //
1113 SDL_free(asset_basepath);
11051114 printf("Linapple: successfully exited!\n");
11061115 return 0;
11071116 }
12321232
12331233 int InitSDL()
12341234 {
1235 char *path;
12351236 // initialize SDL subsystems, return 0 if all OK, else return 1
12361237 if(SDL_Init(SDL_INIT_EVERYTHING) != 0){
12371238 fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
12471248 SDL_WM_SetIcon(apple_icon, NULL);
12481249 printf("Icon was set! Width=%d, height=%d\n", apple_icon->w, apple_icon->h);*/
12491250
1250 apple_icon = SDL_LoadBMP(RESOURCE_ICON_BMP);
1251 asprintf(&path, "%s%s", asset_basepath, ASSET_ICON_BMP);
1252 apple_icon = SDL_LoadBMP(path);
1253 free(path);
12511254 if(apple_icon != NULL) {
12521255 Uint32 colorkey = SDL_MapRGB(apple_icon->format, 0, 0, 0);
12531256 SDL_SetColorKey(apple_icon, SDL_SRCCOLORKEY, colorkey);
00 /* Resources.h -- configures locations of resource files that linapple loads on startup */
11
2 #ifndef RESOURCE_DIR
3 #define RESOURCE_DIR "./"
4 #endif
2 #define ASSET_ICON_BMP "icon.bmp"
3 #define ASSET_SPLASH_BMP "splash.bmp"
4 #define ASSET_CHARSET40_BMP "charset40.bmp"
5 #define ASSET_FONT_BMP "font.bmp"
56
6 #define RESOURCE_ICON_BMP RESOURCE_DIR "icon.bmp"
7 #define RESOURCE_SPLASH_BMP RESOURCE_DIR "splash.bmp"
8 #define RESOURCE_CHARSET40_BMP RESOURCE_DIR "charset40.bmp"
9 #define RESOURCE_FONT_BMP RESOURCE_DIR "font.bmp"
7 extern char *asset_basepath;
18851885
18861886 //===========================================================================
18871887 void VideoInitialize () {
1888 char *path;
18881889 Config config;
18891890 config.ChangeToUserDirectory();
18901891
18951896 ZeroMemory(vidlastmem,0x10000);
18961897
18971898 // LOAD THE splash screen
1898 tmp_surface = SDL_LoadBMP(RESOURCE_SPLASH_BMP);
1899 if (tmp_surface != NULL) g_hLogoBitmap = SDL_DisplayFormat(tmp_surface);
1900 else fprintf(stderr, "Video: " RESOURCE_SPLASH_BMP " was not loaded\n");
1899 asprintf(&path, "%s%s", asset_basepath, ASSET_SPLASH_BMP);
1900 tmp_surface = SDL_LoadBMP(path);
1901 free(path);
1902 if (tmp_surface != NULL) {
1903 g_hLogoBitmap = SDL_DisplayFormat(tmp_surface);
1904 } else {
1905 fprintf(stderr, "Video: " ASSET_SPLASH_BMP " was not loaded\n");
1906 }
19011907 SDL_FreeSurface(tmp_surface);
19021908
19031909 // LOAD APPLE CHARSET40
1904 tmp_surface = SDL_LoadBMP(RESOURCE_CHARSET40_BMP);
1905 if(tmp_surface != NULL) charset40 = SDL_DisplayFormat(tmp_surface);
1906 else fprintf(stderr, "Video: Apple text is not available: " RESOURCE_CHARSET40_BMP " was not loaded\n");
1910 asprintf(&path, "%s%s", asset_basepath, ASSET_CHARSET40_BMP);
1911 tmp_surface = SDL_LoadBMP(path);
1912 free(path);
1913 if (tmp_surface != NULL) {
1914 charset40 = SDL_DisplayFormat(tmp_surface);
1915 } else {
1916 fprintf(stderr, "Video: Apple text is not available: " ASSET_CHARSET40_BMP " was not loaded\n");
1917 }
19071918 SDL_FreeSurface(tmp_surface);
19081919
19091920 // CREATE AN IDENTITY PALETTE AND FILL IN THE CORRESPONDING COLORS IN
447447
448448 bool fonts_initialization(void)
449449 {
450 char *path;
450451 SDL_Surface *temp_surface;
451 temp_surface = SDL_LoadBMP(RESOURCE_FONT_BMP);
452
453 asprintf(&path, asset_basepath, ASSET_FONT_BMP);
454 temp_surface = SDL_LoadBMP(path);
455 free(path);
452456 if(!temp_surface) return false;
453457 font_sfc = SDL_DisplayFormat(temp_surface);
454458