Skip to content

Commit

Permalink
revert update: 32-bit screen. 8-bit and 16-bit modes dropped
Browse files Browse the repository at this point in the history
it breaks psp ver
  • Loading branch information
White Dragon committed Feb 19, 2018
1 parent 85e5c6c commit f9b4117
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 74 deletions.
182 changes: 148 additions & 34 deletions engine/openbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3946,8 +3946,8 @@ int load_colourmap(s_model *model, char *image1, char *image2)

model->colourmap[k] = map;
return 1;
}

}
//PIXEL_x8
// This function is used to enable remap command in 24bit mode
// So old mods can still run under 16/24/32bit color system
Expand All @@ -3959,7 +3959,7 @@ int convert_map_to_palette(s_model *model, unsigned mapflag[])
int i, c;
unsigned char *newmap, *oldmap;
unsigned char *p1, *p2;
unsigned pb = pixelbytes[(int)PIXEL_32];
unsigned pb = pixelbytes[(int)screenformat];
if(model->palette == NULL)
{
return 0;
Expand Down Expand Up @@ -3994,6 +3994,31 @@ int convert_map_to_palette(s_model *model, unsigned mapflag[])
return 1;
}

static int _load_palette16(unsigned char *palette, char *filename)
{
int handle, i;
unsigned char tp[3];
handle = openpackfile(filename, packfile);
if(handle < 0)
{
return 0;
}
memset(palette, 0, MAX_PAL_SIZE / 2);
for(i = 0; i < MAX_PAL_SIZE / 4; i++)
{
if(readpackfile(handle, tp, 3) != 3)
{
closepackfile(handle);
return 0;
}
((unsigned short *)palette)[i] = colour16(tp[0], tp[1], tp[2]);
}
closepackfile(handle);
*(unsigned short *)palette = 0;

return 1;
}

static int _load_palette32(unsigned char *palette, char *filename)
{
int handle, i;
Expand Down Expand Up @@ -4025,7 +4050,30 @@ static int _load_palette32(unsigned char *palette, char *filename)
//load a 256 colors' palette
int load_palette(unsigned char *palette, char *filename)
{
return _load_palette32(palette, filename);
int handle;
if(screenformat == PIXEL_32)
{
return _load_palette32(palette, filename);
}
else if(screenformat == PIXEL_16)
{
return _load_palette16(palette, filename);
}

handle = openpackfile(filename, packfile);
if(handle < 0)
{
return 0;
}
if(readpackfile(handle, palette, 768) != 768)
{
closepackfile(handle);
return 0;
}
closepackfile(handle);
palette[0] = palette[1] = palette[2] = 0;

return 1;
}

// create blending tables for the palette
Expand Down Expand Up @@ -4062,12 +4110,18 @@ void create_blend_tables_x8(unsigned char *tables[])
int i;
for(i = 0; i < MAX_BLENDINGS; i++)
{
tables[i] = blending_table_functions32[i] ? (blending_table_functions32[i])() : NULL;
switch(screenformat)
{
case PIXEL_16:
tables[i] = blending_table_functions16[i] ? (blending_table_functions16[i])() : NULL;
break;
case PIXEL_32:
tables[i] = blending_table_functions32[i] ? (blending_table_functions32[i])() : NULL;
break;
}
}

}


//change system palette by index
void change_system_palette(int palindex)
{
Expand All @@ -4081,10 +4135,20 @@ void change_system_palette(int palindex)
if(!level || palindex == 0 || palindex > level->numpalettes)
{
current_palette = 0;
if(screenformat == PIXEL_8)
{
palette_set_corrected(pal, savedata.gamma, savedata.gamma, savedata.gamma, savedata.brightness, savedata.brightness, savedata.brightness);
set_blendtables(blendings); // set global blending tables
}
}
else if(level)
{
current_palette = palindex;
if(screenformat == PIXEL_8)
{
palette_set_corrected(level->palettes[palindex - 1], savedata.gamma, savedata.gamma, savedata.gamma, savedata.brightness, savedata.brightness, savedata.brightness);
set_blendtables(level->blendings[palindex - 1]);
}
}
}

Expand Down Expand Up @@ -4120,10 +4184,18 @@ void unload_background()
}
}


int _makecolour(int r, int g, int b)
{
return colour32(r, g, b);
switch(screenformat)
{
case PIXEL_8:
return palette_find(pal, r, g, b);
case PIXEL_16:
return colour16(r, g, b);
case PIXEL_32:
return colour32(r, g, b);
}
return 0;
}

// parses a color string in the format "R_G_B" or as a raw integer
Expand Down Expand Up @@ -4293,34 +4365,38 @@ void init_colourtable()

void load_background(char *filename, int createtables)
{
// Clean up any previous background.
//if(pixelformat!=PIXEL_8) createtables = 0;
unload_background();

// Attempt to load 8bit color depth background. If it fails,
// then attempt to load 24bit color depth background. If THAT
// fails, something is wrong and we better shut down to avoid
// a crash.
if(!loadscreen(filename, packfile, NULL, PIXEL_x8, &background))
if(pixelformat == PIXEL_8)
{
if (loadscreen32(filename, packfile, &background))
if(!loadscreen(filename, packfile, pal, PIXEL_8, &background))
{
printf("Loaded 32-bit background '%s'\n", filename);
shutdown(1, "Error loading background (PIXEL_8) file '%s'", filename);
}
else
}
else if(pixelformat == PIXEL_x8)
{
if(!loadscreen(filename, packfile, NULL, PIXEL_x8, &background))
{
if (screenformat == PIXEL_32)
{
if (loadscreen32(filename, packfile, &background)) printf("Loaded 32-bit background '%s'\n", filename);
else shutdown(1, "Error loading background (PIXEL_x8/PIXEL_32) file '%s'", filename);
}
else shutdown(1, "Error loading background (PIXEL_x8) file '%s'", filename);
}
if (background->pixelformat == PIXEL_x8)
{
shutdown(1, "Error loading background (PIXEL_x8/PIXEL_32) file '%s'", filename);
memcpy(pal, background->palette, PAL_BYTES);
memcpy(neontable, pal, PAL_BYTES);
}
}

// If background is 8bit color depth, use its color
// table to populate the global and global neon palettes.
if (background->pixelformat == PIXEL_x8)
else
{
memcpy(pal, background->palette, PAL_BYTES);
memcpy(neontable, pal, PAL_BYTES);
shutdown(1, "Error loading background, Unknown Pixel Format!\n");
}


if(createtables)
{
standard_palette(0);
Expand Down Expand Up @@ -4490,7 +4566,7 @@ void cache_background(char *filename)
{
if(!loadscreen(filename, packfile, NULL, pixelformat, &bg))
{
if(!loadscreen32(filename, packfile, &bg))
if (!(screenformat == PIXEL_32 && loadscreen32(filename, packfile, &bg)))
{
freescreen(&bg);
bg = NULL;
Expand Down Expand Up @@ -11675,12 +11751,14 @@ s_model *load_cached_model(char *name, char *owner, char unload)
}
}

// we need to convert 8bit colourmap into 32bit palette
// we need to convert 8bit colourmap into 24bit palette
if(pixelformat == PIXEL_x8)
{
convert_map_to_palette(newchar, mapflag);
}

printf("Loading '%s' from %s\n", newchar->name, filename);

lCleanup:

if(buf != NULL)
Expand Down Expand Up @@ -15605,7 +15683,7 @@ void goto_mainmenu(int flag)
void static backto_mainmenu()
{
int i = 0;
s_screen *pausebuffer = allocscreen(videomodes.hRes, videomodes.vRes, PIXEL_32);
s_screen *pausebuffer = allocscreen(videomodes.hRes, videomodes.vRes, screenformat);

copyscreen(pausebuffer, vscreen);
spriteq_draw(pausebuffer, 0, MIN_INT, MAX_INT, 0, 0);
Expand Down Expand Up @@ -15645,7 +15723,7 @@ void pausemenu()
int controlp = 0, i;
int newkeys;
s_set_entry *set = levelsets + current_set;
s_screen *pausebuffer = allocscreen(videomodes.hRes, videomodes.vRes, PIXEL_32);
s_screen *pausebuffer = allocscreen(videomodes.hRes, videomodes.vRes, screenformat);

copyscreen(pausebuffer, vscreen);
spriteq_draw(pausebuffer, 0, MIN_INT, MAX_INT, 0, 0);
Expand Down Expand Up @@ -31682,7 +31760,7 @@ void update_scrolled_bg()
2, 2, 3, 3, 2, 2, 3, 3,
2, 2, 3, 3, 2, 3, 2, 3,
}; // fast, constant rumbling, like in/on a van or trailer
int pb = pixelbytes[(int)PIXEL_32];
int pb = pixelbytes[(int)screenformat];

// Time to update neon and screen all flag false?
if(time >= neon_time && !freezeall)
Expand Down Expand Up @@ -32600,7 +32678,15 @@ int set_color_correction(int gm, int br)
video_set_color_correction(gm, br);
return 1;
#else
return 0;
if(screenformat == PIXEL_8)
{
palette_set_corrected(pal, savedata.gamma, savedata.gamma, savedata.gamma, savedata.brightness, savedata.brightness, savedata.brightness);
return 1;
}
else
{
return 0;
}
#endif
}

Expand Down Expand Up @@ -33281,6 +33367,10 @@ int playgif(char *filename, int x, int y, int noskip)
if(info->frame == 0)
{
vga_vwait();
if(screenformat == PIXEL_8)
{
palette_set_corrected(backbuffer->palette, savedata.gamma, savedata.gamma, savedata.gamma, savedata.brightness, savedata.brightness, savedata.brightness);
}
update(0, 0);
}
else
Expand Down Expand Up @@ -35124,7 +35214,31 @@ void init_videomodes(int log)
}
else if(stricmp(command, "colourdepth") == 0)
{
printf("\nColordepth is depreciated. All modules are displayed with a 32bit color screen.\n\n");
pixelformat = PIXEL_x8;
value = GET_ARG(1);
if(stricmp(value, "8bit") == 0)
{
screenformat = PIXEL_8;
pixelformat = PIXEL_x8;
}
else if(stricmp(value, "16bit") == 0)
{
screenformat = PIXEL_16;
bits = 16;
}
else if(stricmp(value, "32bit") == 0)
{
screenformat = PIXEL_32;
bits = 32;
}
else if(value[0] == 0)
{
screenformat = PIXEL_32;
}
else
{
shutdown(1, "Screen colour depth can only be either 8bit, 16bit or 32bit.");
}
}
else if(stricmp(command, "forcemode") == 0) {}
else if(command && command[0])
Expand Down Expand Up @@ -35276,7 +35390,7 @@ void init_videomodes(int log)
video_stretch(savedata.stretch);
#endif

if((vscreen = allocscreen(videomodes.hRes, videomodes.vRes, PIXEL_32)) == NULL)
if((vscreen = allocscreen(videomodes.hRes, videomodes.vRes, screenformat)) == NULL)
{
shutdown(1, "Not enough memory!\n");
}
Expand Down
2 changes: 1 addition & 1 deletion engine/openborscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -12069,7 +12069,7 @@ HRESULT openbor_allocscreen(ScriptVariant **varlist , ScriptVariant **pretvar, i


ScriptVariant_ChangeType(*pretvar, VT_PTR);
screen = allocscreen((int)w, (int)h, PIXEL_32);
screen = allocscreen((int)w, (int)h, screenformat);
if(screen)
{
clearscreen(screen);
Expand Down
11 changes: 7 additions & 4 deletions engine/sdl/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,11 @@ static void initMenu(int type)
isWide = (float)nativeHeight/(float)nativeWidth < 3.0f/4.0f;
isFull = 1;
bpp = 32;
savedata.hwscale = 0.0f;
savedata.hwscale = 0.0f;
screenformat = PIXEL_32;
#endif


screenformat = bpp==32?PIXEL_32:PIXEL_16;
pixelformat = PIXEL_x8;

savedata.fullscreen = isFull;
Expand All @@ -460,7 +462,7 @@ static void initMenu(int type)
savedata.hwscale = 2.0f;
savedata.hwfilter = 1;
#endif
vscreen = allocscreen(videomodes.hRes, videomodes.vRes, PIXEL_32);
vscreen = allocscreen(videomodes.hRes, videomodes.vRes, screenformat);

video_set_mode(videomodes);

Expand Down Expand Up @@ -757,7 +759,8 @@ void Menu()
getBasePath(packfile, filelist[dListCurrentPosition+dListScrollPosition].filename, 1);
free(filelist);

// Restore pixelformat default value.
// Restore screenformat and pixelformat to their default values
screenformat = PIXEL_8;
pixelformat = PIXEL_x8;
}

0 comments on commit f9b4117

Please sign in to comment.