mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-15 18:56:41 -04:00
new filters, cztable, fix crash in enemy drawing
This commit is contained in:
parent
83933755df
commit
a8556070ad
10 changed files with 176 additions and 98 deletions
|
@ -31,12 +31,14 @@ char game_display_init(const INI_CONFIG_SECTION *display_section, const char *ti
|
|||
cfg.scale_quality = ini_get_string(display_section, "scale_quality", "auto");
|
||||
cfg.window_height = ini_get_int(display_section, "window_height", 480);
|
||||
cfg.window_width = ini_get_int(display_section, "window_width", 640);
|
||||
cfg.crt_filter = ini_get_boolean(display_section, "crt_filter", 1) == 1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const char *filter = ini_get_string(display_section, "crt_filter", "auto");
|
||||
if (stricmp(filter,"none") == 0) cfg.crt_filter = SDLContext::CrtFilterType::none;
|
||||
else if (stricmp(filter,"scanlines") == 0) cfg.crt_filter = SDLContext::CrtFilterType::scanlines;
|
||||
else if (stricmp(filter,"scanlines_2") == 0) cfg.crt_filter = SDLContext::CrtFilterType::scanlines_2;
|
||||
else if (stricmp(filter,"rgbmatrix_2") == 0) cfg.crt_filter = SDLContext::CrtFilterType::rgb_matrix_2;
|
||||
else if (stricmp(filter,"rgbmatrix_3") == 0) cfg.crt_filter = SDLContext::CrtFilterType::rgb_matrix_3;
|
||||
else cfg.crt_filter = SDLContext::CrtFilterType::autoselect;
|
||||
|
||||
|
||||
screen_pitch = 640;
|
||||
|
|
|
@ -38,7 +38,7 @@ protected:
|
|||
constexpr auto sdl_keycode_map = KeyCodeMap({
|
||||
{SDL_SCANCODE_A, 0x1E61, 0x1E41, 0x1E01},
|
||||
{SDL_SCANCODE_B,0x3062,0x3042,0x3002},
|
||||
{SDL_SCANCODE_C,0x2E63,0x2E42,0x2E03},
|
||||
{SDL_SCANCODE_C,0x2E63,0x2E43,0x2E03},
|
||||
{SDL_SCANCODE_D,0x2064,0x2044,0x2004},
|
||||
{SDL_SCANCODE_E,0x1265,0x1245,0x1205},
|
||||
{SDL_SCANCODE_F,0x2166,0x2146,0x2106},
|
||||
|
|
|
@ -53,8 +53,18 @@ SDLContext::SDLContext() {
|
|||
|
||||
}
|
||||
|
||||
void SDLContext::generateCRTTexture(SDL_Renderer* renderer, SDL_Texture** texture, int width, int height) {
|
||||
|
||||
void SDLContext::generateCRTTexture(SDL_Renderer* renderer, SDL_Texture** texture, int width, int height, CrtFilterType type) {
|
||||
|
||||
if (type == CrtFilterType::autoselect) {
|
||||
if (height > 1680) type = CrtFilterType::rgb_matrix_3;
|
||||
else if (height >= 1200) type = CrtFilterType::scanlines_2;
|
||||
else type = CrtFilterType::scanlines;
|
||||
}
|
||||
|
||||
if (type == CrtFilterType::scanlines || type == CrtFilterType::scanlines_2) {
|
||||
width = 32;
|
||||
}
|
||||
// Vytvoř novou texturu ve správné velikosti
|
||||
*texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||
SDL_SetTextureBlendMode(*texture, SDL_BLENDMODE_MUL);
|
||||
|
@ -65,19 +75,67 @@ void SDLContext::generateCRTTexture(SDL_Renderer* renderer, SDL_Texture** textur
|
|||
int pitch;
|
||||
SDL_LockTexture(*texture, nullptr, &pixels, &pitch);
|
||||
|
||||
bool wider_lines = height > 1350;
|
||||
|
||||
Uint32* pixelArray = (Uint32*)pixels;
|
||||
Uint32 darkPixel = wider_lines?0x808080FF:0xA0A0A0FF;
|
||||
Uint32 transparentPixel = wider_lines ?0xFFFFFFE0:0xFFFFFFC0;
|
||||
int step = wider_lines ?3:2;
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
Uint32 color = (y % step == 0) ? darkPixel : transparentPixel;
|
||||
for (int x = 0; x < width; x++) {
|
||||
pixelArray[y * (pitch / 4) + x] = color;
|
||||
if (type == CrtFilterType::scanlines) {
|
||||
|
||||
|
||||
|
||||
Uint32 darkPixel = 0xA0A0A0FF;
|
||||
Uint32 transparentPixel = 0xFFFFFFC0;
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
Uint32 color = ((y & 1)== 0) ? darkPixel : transparentPixel;
|
||||
for (int x = 0; x < width; x++) {
|
||||
pixelArray[y * (pitch / 4) + x] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == CrtFilterType::scanlines_2) {
|
||||
|
||||
|
||||
Uint32 darkPixel = 0x808080FF;
|
||||
Uint32 transparentPixel = 0xFFFFFFE0;
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
Uint32 color = (y % 3== 2) ? darkPixel : transparentPixel;
|
||||
for (int x = 0; x < width; x++) {
|
||||
pixelArray[y * (pitch / 4) + x] = color;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
static Uint32 red_pixel = 0xFF8080A0;
|
||||
static Uint32 green_pixel = 0x80FF80A0;
|
||||
static Uint32 blue_pixel = 0x8080FFA0;
|
||||
static Uint32 dark_pixel = 0x000000C0;
|
||||
for (int y = 2; y < height; y++) {
|
||||
if (type == CrtFilterType::rgb_matrix_2) {
|
||||
for (int x = 2; x < width; x+=3) {
|
||||
Uint32 *pos = pixelArray+y*(pitch/4)+x-2;
|
||||
if ((y % 3) == 2) {
|
||||
pos[0] = pos[1] = pos[2] = dark_pixel;
|
||||
} else {
|
||||
pos[0] = red_pixel;
|
||||
pos[1] = green_pixel;
|
||||
pos[2] = blue_pixel;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int x = 2; x < width; x+=3) {
|
||||
Uint32 *pos = pixelArray+y*(pitch/4)+x-2;
|
||||
if ((y & 3) == 3) {
|
||||
pos[0] = pos[1] = pos[2] = dark_pixel;
|
||||
} else {
|
||||
pos[0] = red_pixel;
|
||||
pos[1] = green_pixel;
|
||||
pos[2] = blue_pixel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Odemkni texturu
|
||||
SDL_UnlockTexture(*texture);
|
||||
|
@ -97,7 +155,7 @@ void SDLContext::init_video(const VideoConfig &config, const char *title) {
|
|||
int height = config.window_height;
|
||||
aspect_x = config.aspect_x;
|
||||
aspect_y = config.aspect_y;
|
||||
crt_filter_enabled = config.crt_filter;
|
||||
_crt_filter = config.crt_filter ;
|
||||
|
||||
|
||||
_fullscreen_mode = config.fullscreen;
|
||||
|
@ -370,10 +428,10 @@ void SDLContext::update_screen() {
|
|||
SDL_SetTextureAlphaMod(_visible_texture, 255);
|
||||
SDL_RenderCopy(_renderer.get(), _visible_texture, NULL, &winrc);
|
||||
}
|
||||
if (winrc.h > 900 && crt_filter_enabled) {
|
||||
if (winrc.h >= 720 && _crt_filter != CrtFilterType::none) {
|
||||
if (!_crt_effect) {
|
||||
SDL_Texture *txt;
|
||||
generateCRTTexture(_renderer.get(), &txt, 128, std::min<int>(1440, winrc.h));
|
||||
generateCRTTexture(_renderer.get(), &txt, winrc.w, winrc.h, _crt_filter);
|
||||
_crt_effect.reset(txt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,10 +15,20 @@ public:
|
|||
|
||||
SDLContext();
|
||||
|
||||
enum class CrtFilterType {
|
||||
none,
|
||||
autoselect,
|
||||
scanlines,
|
||||
scanlines_2,
|
||||
rgb_matrix_2,
|
||||
rgb_matrix_3
|
||||
|
||||
};
|
||||
|
||||
struct VideoConfig {
|
||||
int window_width;
|
||||
int window_height;
|
||||
bool crt_filter;
|
||||
CrtFilterType crt_filter;
|
||||
int composer;
|
||||
const char *scale_quality;
|
||||
bool fullscreen;
|
||||
|
@ -121,7 +131,7 @@ protected:
|
|||
mutable std::mutex _mx;
|
||||
int aspect_x = 4;
|
||||
int aspect_y = 3;
|
||||
bool crt_filter_enabled = false;
|
||||
CrtFilterType _crt_filter= CrtFilterType::autoselect;
|
||||
std::function<void()> _quit_callback;
|
||||
|
||||
std::unique_ptr<SDL_Window, SDL_Deleter> _window;
|
||||
|
@ -173,7 +183,7 @@ protected:
|
|||
static SDL_Point to_source_point(const SDL_Rect &win_rec, const SDL_Point &win_pt) ;
|
||||
static SDL_Rect transition_rect(const SDL_Rect &beg, const SDL_Rect &end, float phase);
|
||||
static int transition_int(int beg, int end, float phase);
|
||||
void generateCRTTexture(SDL_Renderer* renderer, SDL_Texture** texture, int width, int height);
|
||||
void generateCRTTexture(SDL_Renderer* renderer, SDL_Texture** texture, int width, int height, CrtFilterType type);
|
||||
void signal_push();
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue