git @ Cat's Eye Technologies linapple / 900b95b
Redo how assets are loaded/managed This is a first pass at centralizing the asset management. Probably all or nearly all of these surfaces are intended to be loaded from disk, converted to screen pixel format, the disk format surface freed, and the converted format saved. That'd make a good second pass. It doesn't even bother me that this sounds like something that should be in the video handling code because SDL 2.0 doesn't care. The thing is, this needs to be done after SDL_SetVideoMode, and right now it isn't. So pass #2 will have to wait a bit. T. Joseph Carter 3 years ago
7 changed file(s) with 168 addition(s) and 74 deletion(s). Raw diff Collapse all Expand all
0 /*
1 asset.h - LinApple asset management
2 Copyright (C) 2018 T. Joseph Carter
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #ifndef __asset_h
20 #define __asset_h
21
22 typedef struct {
23 char *basepath;
24 SDL_Surface *icon;
25 SDL_Surface *font;
26 SDL_Surface *charset40;
27 SDL_Surface *splash;
28 } assets_t;
29
30 extern assets_t assets;
31
32 bool Asset_Init(void);
33 void Asset_Quit(void);
34
35 #endif // __asset_h
+0
-13
inc/assets.h less more
0 /* assets.h -- configures locations of asset files that linapple loads on startup */
1
2 #ifndef __assets_h
3 #define __assets_h
4
5 #define ASSET_ICON_BMP "icon.bmp"
6 #define ASSET_SPLASH_BMP "splash.bmp"
7 #define ASSET_CHARSET40_BMP "charset40.bmp"
8 #define ASSET_FONT_BMP "font.bmp"
9
10 extern char *asset_basepath;
11
12 #endif // __assets_h
4545 #include <sys/stat.h>
4646 #include <fcntl.h>
4747
48 #include "asset.h"
4849 #include "config.h"
4950
5051 #ifdef __APPLE__
785786
786787 FILE *spMono, *spStereo;
787788
788 char *asset_basepath;
789
790789 //---------------------------------------------------------------------------
791790
792791 int main(int argc, char * lpCmdLine[])
793792 {
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 }
793 Asset_Init();
799794
800795 // GPH: The very first thing we do is attempt to grab the needed configuration files and put them in the user's folder.
801796 Config config;
11101105 curl_easy_cleanup(g_curl);
11111106 curl_global_cleanup();
11121107 //
1113 SDL_free(asset_basepath);
1108 Asset_Quit();
11141109 printf("Linapple: successfully exited!\n");
11151110 return 0;
11161111 }
3131
3232 // for usleep
3333 #include <unistd.h>
34 #include "assets.h"
34
3535 #include "stdafx.h"
36
37 #include "asset.h"
3638 //#pragma hdrstop
3739 #include "MouseInterface.h"
3840 //#include "..\resource\resource.h"
4345 #include <iostream>
4446
4547 #define ENABLE_MENU 0
46
47 SDL_Surface *apple_icon; // icon
4848
4949 SDL_Surface * screen; // our main screen
5050 // rects for screen stretch if needed
563563
564564 rectangle(screen, 1, 1, /*SCREEN_WIDTH*/g_ScreenWidth - 2, (Help_TopX - 8), SDL_MapRGB(screen->format, 255, 255, 0));
565565
566 if(apple_icon != NULL) { // display Apple logo
567 tempSurface = SDL_DisplayFormat(apple_icon);
566 if(assets.icon != NULL) { // display Apple logo
567 tempSurface = SDL_DisplayFormat(assets.icon);
568568 SDL_Rect logo, scrr;
569569 logo.x = logo.y = 0;
570570 logo.w = tempSurface->w;
12321232
12331233 int InitSDL()
12341234 {
1235 char *path;
12361235 // initialize SDL subsystems, return 0 if all OK, else return 1
12371236 if(SDL_Init(SDL_INIT_EVERYTHING) != 0){
12381237 fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
12421241 // SDL ref: Icon should be set *before* the first call to SDL_SetVideoMode.
12431242 // Uint32 colorkey;
12441243
1245 /* apple_icon = SDL_CreateRGBSurfaceFrom((void*)Apple_icon, 32, 32, 8, 32, 0, 0, 0, 0);
1246 Uint32 colorkey = SDL_MapRGB(apple_icon->format, 0, 0, 0);
1247 SDL_SetColorKey(apple_icon, SDL_SRCCOLORKEY, colorkey);
1248 SDL_WM_SetIcon(apple_icon, NULL);
1249 printf("Icon was set! Width=%d, height=%d\n", apple_icon->w, apple_icon->h);*/
1250
1251 asprintf(&path, "%s%s", asset_basepath, ASSET_ICON_BMP);
1252 apple_icon = SDL_LoadBMP(path);
1253 free(path);
1254 if(apple_icon != NULL) {
1255 Uint32 colorkey = SDL_MapRGB(apple_icon->format, 0, 0, 0);
1256 SDL_SetColorKey(apple_icon, SDL_SRCCOLORKEY, colorkey);
1257 SDL_WM_SetIcon(apple_icon, NULL);
1258 // printf("Icon was set! Width=%d, height=%d\n", apple_icon->w, apple_icon->h);
1244 /* assets.icon = SDL_CreateRGBSurfaceFrom((void*)Apple_icon, 32, 32, 8, 32, 0, 0, 0, 0);
1245 Uint32 colorkey = SDL_MapRGB(assets.icon->format, 0, 0, 0);
1246 SDL_SetColorKey(assets.icon, SDL_SRCCOLORKEY, colorkey);
1247 SDL_WM_SetIcon(assets.icon, NULL);
1248 printf("Icon was set! Width=%d, height=%d\n", assets.icon->w, assets.icon->h);*/
1249
1250 if(assets.icon != NULL) {
1251 Uint32 colorkey = SDL_MapRGB(assets.icon->format, 0, 0, 0);
1252 SDL_SetColorKey(assets.icon, SDL_SRCCOLORKEY, colorkey);
1253 SDL_WM_SetIcon(assets.icon, NULL);
1254 // printf("Icon was set! Width=%d, height=%d\n", assets.icon->w, assets.icon->h);
12591255 }
12601256 //////////////////////////////////////////////////////////////////////
12611257 return 0;
2727
2828 /* Adaptation for SDL and POSIX (l) by beom beotiger, Nov-Dec 2007 */
2929
30 #include "assets.h"
3130 #include "stdafx.h"
31
32 #include "asset.h"
3233 #include "wwrapper.h"
3334 #include "config.h"
3435 #include <iostream>
18851886
18861887 //===========================================================================
18871888 void VideoInitialize () {
1888 char *path;
18891889 Config config;
18901890 config.ChangeToUserDirectory();
18911891
1892
1893 SDL_Surface * tmp_surface;
18941892 // CREATE A BUFFER FOR AN IMAGE OF THE LAST DRAWN MEMORY
18951893 vidlastmem = (LPBYTE)VirtualAlloc(NULL,0x10000,MEM_COMMIT,PAGE_READWRITE);
18961894 ZeroMemory(vidlastmem,0x10000);
18971895
18981896 // LOAD THE splash screen
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 }
1907 SDL_FreeSurface(tmp_surface);
1897 g_hLogoBitmap = SDL_DisplayFormat(assets.splash);
19081898
19091899 // LOAD APPLE CHARSET40
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 }
1918 SDL_FreeSurface(tmp_surface);
1900 charset40 = SDL_DisplayFormat(assets.charset40);
19191901
19201902 // CREATE AN IDENTITY PALETTE AND FILL IN THE CORRESPONDING COLORS IN
19211903 // THE BITMAPINFO STRUCTURE
0 /*
1 asset.cpp - LinApple asset management
2 <one line to give the program's name and a brief idea of what it does.>
3 Copyright (C) 2018 T. Joseph Carter
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <sys/param.h>
21 #include <SDL.h>
22
23 #include "asset.h"
24 #include "shim.h" // SDL_GetBasePath()
25
26 #define ASSET_ICON_BMP "icon.bmp"
27 #define ASSET_SPLASH_BMP "splash.bmp"
28 #define ASSET_CHARSET40_BMP "charset40.bmp"
29 #define ASSET_FONT_BMP "font.bmp"
30
31 assets_t assets;
32
33 bool Asset_Init(void)
34 {
35 char *path = (char *)SDL_malloc(sizeof(char[PATH_MAX]));
36
37 assets.basepath = SDL_GetBasePath();
38 if (NULL != assets.basepath) {
39 fprintf(stderr, "SDL_GetBasePath() returned NULL, using current directory.\n");
40 assets.basepath = SDL_strdup("./");
41 }
42 assets.icon = NULL;
43 assets.font = NULL;
44 assets.charset40 = NULL;
45 assets.splash = NULL;
46
47 snprintf(path, PATH_MAX, "%s%s", assets.basepath, ASSET_ICON_BMP);
48 assets.icon = SDL_LoadBMP(path);
49 if (NULL == assets.icon) {
50 fprintf(stderr, "Unable to locate required asset " ASSET_ICON_BMP "\n");
51 return false;
52 }
53
54 snprintf(path, PATH_MAX, "%s%s", assets.basepath, ASSET_FONT_BMP);
55 assets.font = SDL_LoadBMP(path);
56 if (NULL == assets.font) {
57 fprintf(stderr, "Unable to locate required asset " ASSET_FONT_BMP "\n");
58 return false;
59 }
60
61 snprintf(path, PATH_MAX, "%s%s", assets.basepath, ASSET_CHARSET40_BMP);
62 assets.charset40 = SDL_LoadBMP(path);
63 if (NULL == assets.charset40) {
64 fprintf(stderr, "Unable to locate required asset " ASSET_CHARSET40_BMP "\n");
65 return false;
66 }
67
68 snprintf(path, PATH_MAX, "%s%s", assets.basepath, ASSET_SPLASH_BMP);
69 assets.splash = SDL_LoadBMP(path);
70 if (NULL == assets.splash) {
71 fprintf(stderr, "Unable to locate required asset " ASSET_SPLASH_BMP "\n");
72 return false;
73 }
74
75 free(path);
76 return true;
77 }
78
79 void Asset_Quit(void)
80 {
81 if (NULL != assets.icon) {
82 SDL_FreeSurface(assets.icon);
83 assets.icon = NULL;
84 }
85
86 if (NULL != assets.font) {
87 SDL_FreeSurface(assets.font);
88 assets.font = NULL;
89 }
90
91 if (NULL != assets.charset40) {
92 SDL_FreeSurface(assets.charset40);
93 assets.charset40 = NULL;
94 }
95
96 if (NULL != assets.splash) {
97 SDL_FreeSurface(assets.splash);
98 assets.splash = NULL;
99 }
100
101 SDL_free(assets.basepath);
102 }
3333
3434 //static unsigned char copy_row[4096];
3535
36 #include "assets.h"
3736 #include "stdafx.h"
3837
38 #include "asset.h"
3939
4040 #define DEFINE_COPY_ROW(name, type) \
4141 void name(type *src, int src_w, type *dst, int dst_w) \
447447
448448 bool fonts_initialization(void)
449449 {
450 char *path;
451 SDL_Surface *temp_surface;
452
453 asprintf(&path, "%s%s", asset_basepath, ASSET_FONT_BMP);
454 temp_surface = SDL_LoadBMP(path);
455 free(path);
456 if(!temp_surface) return false;
457 font_sfc = SDL_DisplayFormat(temp_surface);
458
459 SDL_FreeSurface(temp_surface);
450 if(!assets.font) {
451 return false;
452 }
453 font_sfc = SDL_DisplayFormat(assets.font);
454
460455 /* Transparant color is BLACK: */
461456 SDL_SetColorKey(font_sfc,SDL_SRCCOLORKEY,SDL_MapRGB(font_sfc->format,0,0,0));
462457