Skip to content

Commit

Permalink
Fix C variable declaration order stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusikkala committed May 25, 2023
1 parent e5444c9 commit e8c6704
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 55 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Welcome to PDCursesMod!
=======================

Public Domain Curses (Modified), aka PDCursesMod, is an implementation of X/Open curses for multiple platforms. As the name suggests, it is a modified version of the ['official' PDCurses project](https://www.github.com/wmcbrine/PDCurses), adding a variety of improvements, such as Windows GUI, VT-like console, Linux/*BSD framebuffer, DOSVGA, and Plan 9 "flavors" of Curses. It expands many of the capabilities of the flavors inherited from PDCurses (SDL1, SDL2, X11, Win32 console, OS/2, and DOS). Some details and screen shots are at
Public Domain Curses (Modified), aka PDCursesMod, is an implementation of X/Open curses for multiple platforms. As the name suggests, it is a modified version of the ['official' PDCurses project](https://www.github.com/wmcbrine/PDCurses), adding a variety of improvements, such as Windows GUI, VT-like console, Linux/*BSD framebuffer, DOSVGA, OpenGL, and Plan 9 "flavors" of Curses. It expands many of the capabilities of the flavors inherited from PDCurses (SDL1, SDL2, X11, Win32 console, OS/2, and DOS). Some details and screen shots are at

https://www.projectpluto.com/win32a.htm

Expand Down Expand Up @@ -34,6 +34,7 @@ Build instructions are in the README file for each platform:
- [WinGUI](wingui/README.md) for use on Windows Graphics Mode
- [X11](x11/README.md) (also called XCurses) for use as separate X11 window
- [VT](vt/README.md) for use on terminal
- [OpenGL](gl/README.md) for use as separate window with OpenGL rendering

Distribution Status
-------------------
Expand Down
4 changes: 2 additions & 2 deletions curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ a fourth bit is reserved.
Default chtypes have enough character bits to support the full range of
Unicode, all attributes, and 2^20 = 1048576 color pairs. Note, though,
that as of 2022 Jun 17, only WinGUI, VT, X11, Linux framebuffer, and
SDLn have COLOR_PAIRS = 1048576. Other platforms (DOSVGA, Plan9, WinCon)
that as of 2022 Jun 17, only WinGUI, VT, X11, Linux framebuffer, OpenGL,
and SDLn have COLOR_PAIRS = 1048576. Other platforms (DOSVGA, Plan9, WinCon)
may join them. Some (DOS, OS/2) simply do not have full-color
capability.
Expand Down
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Also consult the README for each specific platform you'll be using:
- [Windows in console mode (WinCon)]
- [Windows in graphical mode (WinGUI)]
- [X11]
- [OpenGL]

Building
--------
Expand Down Expand Up @@ -47,3 +48,4 @@ The files in this directory are released to the public domain.
[Windows console]: ../wincon/README.md
[Windows graphical]: ../wingui/README.md
[X11]: ../x11/README.md
[OpenGL]: ../gl/README.md
84 changes: 50 additions & 34 deletions gl/pdcdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ static void enlarge_glyph_cache()
else
{
bool* visited = calloc(grid_w * grid_h * grid_layers, sizeof(bool));
int attr;

/* If we're here, it's not possible to enlarge the texture, so we have
* to evict everything that's not needed out of the texture. This can
Expand All @@ -178,13 +179,14 @@ static void enlarge_glyph_cache()
for(i = 0; i < pdc_glyph_row_capacity; ++i)
pdc_glyph_start_col[i] = 0;

for(int attr = 0; attr < 4; ++attr)
for(attr = 0; attr < 4; ++attr)
for(i = 0; i < pdc_glyph_cache_size[attr]; ++i)
{
Uint32* cached_glyph = pdc_glyph_cache[attr]+i;
Uint32 old_glyph = *cached_glyph;
bool used = FALSE;
int w = old_glyph >> 30;
int row;
if(old_glyph == 0)
continue;

Expand All @@ -206,7 +208,7 @@ static void enlarge_glyph_cache()
continue;

/* Used glyphs are given a new index and copied over. */
for(int row = 0; row < pdc_glyph_row_capacity; ++row)
for(row = 0; row < pdc_glyph_row_capacity; ++row)
{
int *col = &pdc_glyph_start_col[row];
if(*col + w <= pdc_glyph_col_capacity)
Expand Down Expand Up @@ -258,8 +260,9 @@ static Uint32 alloc_glyph_cache(int w)
/* Keep trying until we succeed. */
for(;;)
{
int row;
/* We try to fill the glyph cache in rows, from bottom to top. */
for(int row = 0; row < pdc_glyph_row_capacity; ++row)
for(row = 0; row < pdc_glyph_row_capacity; ++row)
{
int *col = &pdc_glyph_start_col[row];
if(*col+w <= pdc_glyph_col_capacity)
Expand Down Expand Up @@ -392,13 +395,13 @@ static Uint32 get_pdc_color( const int color_idx)

static Uint32 get_glyph_texture_index(Uint32 ch32)
{
/* Fullwidth dummy char! 0 makes it stop existing! */
if(ch32 == 0x110000) return 0;

SDL_Color white = {255,255,255,255};
int *cache_size = &pdc_glyph_cache_size[cache_attr_index];
Uint32 **cache = &pdc_glyph_cache[cache_attr_index];

/* Fullwidth dummy char! 0 makes it stop existing! */
if(ch32 == 0x110000) return 0;

#ifndef PDC_SDL_SUPPLEMENTARY_PLANES_SUPPORT
/* no support for supplementary planes */
if (ch32 > 0xffff)
Expand All @@ -413,6 +416,8 @@ static Uint32 get_glyph_texture_index(Uint32 ch32)
else
{
/* Here we need to render the character, it's not cached. */
int w = 0;
Uint32 index;
SDL_Surface* surf = NULL;

#ifdef PDC_SDL_SUPPLEMENTARY_PLANES_SUPPORT
Expand All @@ -424,8 +429,8 @@ static Uint32 get_glyph_texture_index(Uint32 ch32)
/* Kind-of-fullwidthness-but-not-really: Italics can also overstep
* and cause w = 2, which should still render completely fine.
*/
int w = (surf->w + pdc_fwidth-1)/pdc_fwidth;
Uint32 index = alloc_glyph_cache(w);
w = (surf->w + pdc_fwidth-1)/pdc_fwidth;
index = alloc_glyph_cache(w);
/* The SDL_Surface pitch may not match with the width, so we use this
* to get glTexSubImage2D to deal with the proper pitch.
*/
Expand Down Expand Up @@ -469,7 +474,7 @@ static Uint32 get_glyph_texture_index(Uint32 ch32)
}

#ifdef USING_COMBINING_CHARACTER_SCHEME
int PDC_expand_combined_characters( const cchar_t c, cchar_t *added); /* addch.c */
int PDC_expand_combined_characters( const cchar_t c, cchar_t *added);
#endif

static void draw_glyph(
Expand All @@ -478,20 +483,22 @@ static void draw_glyph(
Uint32 foreground
){
struct color_data* cd;
#ifdef USING_COMBINING_CHARACTER_SCHEME
int layer = 0;
#endif
int i = x + y * SP->cols;
if(y < 0 || y >= SP->lines || x < 0 || x >= SP->cols)
return;

ensure_glyph_grid(1);
cd = &color_grid[i];
cd->bg_color = background;
Uint32 gl_attrs =
((attr & A_UNDERLINE) ? 1<<2 : 0) |
((attr & A_OVERLINE) ? 1<<3 : 0) |
((attr & A_STRIKEOUT) ? 1<<4 : 0) |
((attr & A_LEFT) ? 1<<5 : 0) |
((attr & A_RIGHT) ? 1<<6 : 0);
if(y < 0 || y >= SP->lines || x < 0 || x >= SP->cols)
return;

ensure_glyph_grid(1);
cd = &color_grid[i];
cd->bg_color = background;
cd->fg_color = foreground | (gl_attrs << 24);

#ifdef USING_COMBINING_CHARACTER_SCHEME
Expand Down Expand Up @@ -529,12 +536,12 @@ static void draw_glyph(
static void draw_cursor(int y, int x, int visibility)
{
struct color_data* cd;
Uint32 gl_attrs = visibility >= 0 && visibility <= 2 ? visibility : 0;
if(y < 0 || y >= SP->lines || x < 0 || x >= SP->cols)
return;

ensure_glyph_grid(1);
cd = &color_grid[x + y * SP->cols];
Uint32 gl_attrs = visibility >= 0 && visibility <= 2 ? visibility : 0;
cd->fg_color |= gl_attrs << 24;
}

Expand Down Expand Up @@ -717,6 +724,14 @@ void PDC_blink_text(void)

void PDC_doupdate(void)
{
int w, h;
SDL_Rect viewport = PDC_get_viewport();
bool use_render_target = pdc_interpolation_mode == PDC_GL_INTERPOLATE_BILINEAR &&
pdc_resize_mode != PDC_GL_RESIZE_NORMAL;
int u_screen_size, u_glyph_size, u_fthick, u_line_color;
short hcol = SP->line_color;
int layer;

ensure_glyph_grid(1);

/* Upload grid buffers at the start, before we queue the commands that need
Expand All @@ -737,35 +752,29 @@ void PDC_doupdate(void)
GL_STREAM_DRAW
);

int w, h;
SDL_GetWindowSize(pdc_window, &w, &h);

glViewport(0, 0, w, h);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT);

SDL_Rect viewport = PDC_get_viewport();
bool use_render_target =
pdc_interpolation_mode == PDC_GL_INTERPOLATE_BILINEAR &&
pdc_resize_mode != PDC_GL_RESIZE_NORMAL;

if(use_render_target)
{
/* For bilinear interpolation, we unfortunately need a temporary render
* target. If we tried to do interpolation on the glyphs in the shader,
* their edges would still appear sharp, as they could not blend
* between cell edges.
*/
int content_w = SP->cols * pdc_fwidth;
int content_h = SP->lines * pdc_fheight;

if(!pdc_render_target_texture)
{
/* Need to allocate the render target texture. */
glGenTextures(1, &pdc_render_target_texture);
cur_render_target_w = cur_render_target_h = 0;
}

int content_w = SP->cols * pdc_fwidth;
int content_h = SP->lines * pdc_fheight;

if(cur_render_target_w != content_w || cur_render_target_h != content_h)
{
/* Need to resize the render target texture. */
Expand Down Expand Up @@ -815,28 +824,33 @@ void PDC_doupdate(void)

/* Draw background colors */
glUseProgram(pdc_background_shader_program);
int u_screen_size = glGetUniformLocation(pdc_background_shader_program, "screen_size");
u_screen_size = glGetUniformLocation(
pdc_background_shader_program, "screen_size");
glUniform2i(u_screen_size, SP->cols, SP->lines);

int u_glyph_size = glGetUniformLocation(pdc_background_shader_program, "glyph_size");
u_glyph_size = glGetUniformLocation(
pdc_background_shader_program, "glyph_size");
glUniform2i(u_glyph_size, pdc_fwidth, pdc_fheight);

glDrawArraysInstanced(GL_TRIANGLES, 0, 6, SP->lines * SP->cols);

/* Prepare for drawing foreground glyphs. */
glUseProgram(pdc_foreground_shader_program);

u_screen_size = glGetUniformLocation(pdc_foreground_shader_program, "screen_size");
u_screen_size = glGetUniformLocation(
pdc_foreground_shader_program, "screen_size");
glUniform2i(u_screen_size, SP->cols, SP->lines);

u_glyph_size = glGetUniformLocation(pdc_foreground_shader_program, "glyph_size");
u_glyph_size = glGetUniformLocation(
pdc_foreground_shader_program, "glyph_size");
glUniform2i(u_glyph_size, pdc_fwidth, pdc_fheight);

int u_fthick = glGetUniformLocation(pdc_foreground_shader_program, "fthick");
u_fthick = glGetUniformLocation(pdc_foreground_shader_program, "fthick");
glUniform1i(u_fthick, pdc_fthick);

int u_line_color = glGetUniformLocation(pdc_foreground_shader_program, "line_color");
short hcol = SP->line_color;
u_line_color = glGetUniformLocation(
pdc_foreground_shader_program, "line_color");
hcol = SP->line_color;
if(hcol >= 0)
{
PACKED_RGB rgb = PDC_get_palette_entry(hcol);
Expand All @@ -849,7 +863,7 @@ void PDC_doupdate(void)
else glUniform3f(u_line_color, -1, -1, -1);

/* Draw foreground colors, layer by layer. */
for(int layer = 0; layer < grid_layers; ++layer)
for(layer = 0; layer < grid_layers; ++layer)
{
if(layer != 0)
{
Expand Down Expand Up @@ -898,7 +912,9 @@ void PDC_pump_and_peep(void)
{
SDL_Event event;

if(SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0)
int res = SDL_PeepEvents(
&event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
if(res > 0)
{
if (SDL_WINDOWEVENT == event.type &&
(SDL_WINDOWEVENT_RESTORED == event.window.event ||
Expand Down
9 changes: 5 additions & 4 deletions gl/pdckbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ static int _process_mouse_event(void)
short shift_flags = 0;
int wheel_x = 0, wheel_y = 0;
int mouse_x = 0, mouse_y = 0;
SDL_Rect viewport = PDC_get_viewport();

memset(&SP->mouse_status, 0, sizeof(MOUSE_STATUS));

Expand All @@ -356,8 +357,6 @@ static int _process_mouse_event(void)
SDL_GetMouseState( &event.motion.x, &event.motion.y);
}

SDL_Rect viewport = PDC_get_viewport();

if(viewport.w == 0) viewport.w = 1;
if(viewport.h == 0) viewport.h = 1;
mouse_x = (event.motion.x-viewport.x) * SP->cols / viewport.w;
Expand Down Expand Up @@ -461,8 +460,10 @@ int PDC_get_key(void)
}
return PDC_get_function_key( FUNCTION_KEY_SHUT_DOWN);
case SDL_WINDOWEVENT:
if (SDL_WINDOWEVENT_SIZE_CHANGED == event.window.event || SDL_WINDOWEVENT_RESIZED == event.window.event)
{
if(
SDL_WINDOWEVENT_SIZE_CHANGED == event.window.event ||
SDL_WINDOWEVENT_RESIZED == event.window.event
){
if(pdc_resize_mode == PDC_GL_RESIZE_NORMAL)
{
pdc_sheight = event.window.data2;
Expand Down
Loading

0 comments on commit e8c6704

Please sign in to comment.