Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
sprite.c File Reference
#include "internal.h"
#include "visual-details.h"
#include <stdatomic.h>
Include dependency graph for sprite.c:

Go to the source code of this file.

Functions

void sprixel_debug (const sprixel *s, FILE *out)
 
void sprixel_free (sprixel *s)
 
sprixelsprixel_recycle (ncplane *n)
 
void sprixel_movefrom (sprixel *s, int y, int x)
 
void sprixel_hide (sprixel *s)
 
void sprixel_invalidate (sprixel *s, int y, int x)
 
sprixelsprixel_alloc (ncplane *n, int dimy, int dimx)
 
int sprixel_load (sprixel *spx, fbuf *f, unsigned pixy, unsigned pixx, int parse_start, sprixel_e state)
 
int sprite_wipe (const notcurses *nc, sprixel *s, int ycell, int xcell)
 
int sprite_clear_all (const tinfo *t, fbuf *f)
 
int sprite_init (tinfo *t, int fd)
 
int sprixel_rescale (sprixel *spx, unsigned ncellpxy, unsigned ncellpxx)
 

Function Documentation

◆ sprite_clear_all()

int sprite_clear_all ( const tinfo t,
fbuf f 
)

Definition at line 204 of file sprite.c.

204 {
205 if(t->pixel_clear_all == NULL){
206 return 0;
207 }
208 return t->pixel_clear_all(f);
209}
int(* pixel_clear_all)(fbuf *f)
Definition termdesc.h:153
return NULL
Definition termdesc.h:229
Here is the caller graph for this function:

◆ sprite_init()

int sprite_init ( tinfo t,
int  fd 
)

Definition at line 214 of file sprite.c.

214 {
215 struct timeval tv;
216 gettimeofday(&tv, NULL);
217 int stir = (tv.tv_sec >> 3) ^ tv.tv_usec;
218 sprixelid_nonce = (rand() ^ stir) % 0xffffffu;
219 if(t->pixel_init == NULL){
220 return 0;
221 }
222 return t->pixel_init(t, fd);
223}
int(* pixel_init)(struct tinfo *ti, int fd)
Definition termdesc.h:146

◆ sprite_wipe()

int sprite_wipe ( const notcurses nc,
sprixel s,
int  ycell,
int  xcell 
)

Definition at line 170 of file sprite.c.

170 {
171 assert(s->n);
172 int idx = s->dimx * ycell + xcell;
173 if(s->n->tam[idx].state == SPRIXCELL_TRANSPARENT){
174 // need to make a transparent auxvec, because a reload will force us to
175 // update said auxvec, but needn't actually change the glyph. auxvec will
176 // be entirely 0s coming from pixel_trans_auxvec().
177 if(s->n->tam[idx].auxvector == NULL){
179 s->n->tam[idx].auxvector = nc->tcache.pixel_trans_auxvec(ncplane_pile(s->n));
180 if(s->n->tam[idx].auxvector == NULL){
181 return -1;
182 }
183 }
184 }
185 // no need to update to INVALIDATED; no redraw is necessary
187 return 1;
188 }
191//fprintf(stderr, "CACHED WIPE %d %d/%d\n", s->id, ycell, xcell);
192 return 0;
193 }
194 logdebug("wiping %p %d %d/%d", s->n->tam, idx, ycell, xcell);
195 int r = nc->tcache.pixel_wipe(s, ycell, xcell);
196//fprintf(stderr, "WIPED %d %d/%d ret=%d\n", s->id, ycell, xcell, r);
197 // mark the cell as annihilated whether we actually scrubbed it or not,
198 // so that we use this fact should we move to another frame
200 assert(s->n->tam[idx].auxvector);
201 return r;
202}
assert(false)
uint32_t idx
Definition egcpool.h:298
int r
Definition fbuf.h:226
#define logdebug(fmt,...)
Definition logging.h:52
@ SPRIXCELL_ANNIHILATED
Definition sprite.h:120
@ SPRIXCELL_TRANSPARENT
Definition sprite.h:115
@ SPRIXCELL_ANNIHILATED_TRANS
Definition sprite.h:121
tament * tam
Definition internal.h:106
tinfo tcache
Definition internal.h:360
unsigned dimx
Definition sprite.h:146
struct ncplane * n
Definition sprite.h:142
void * auxvector
Definition sprite.h:128
sprixcell_e state
Definition sprite.h:127
int(* pixel_wipe)(struct sprixel *s, int y, int x)
Definition termdesc.h:138
uint8_t *(* pixel_trans_auxvec)(const struct ncpile *p)
Definition termdesc.h:159
Here is the call graph for this function:

◆ sprixel_alloc()

sprixel * sprixel_alloc ( ncplane n,
int  dimy,
int  dimx 
)

Definition at line 117 of file sprite.c.

117 {
118 sprixel* ret = malloc(sizeof(sprixel));
119 if(ret == NULL){
120 return NULL;
121 }
122 memset(ret, 0, sizeof(*ret));
123 if(fbuf_init(&ret->glyph)){
124 free(ret);
125 return NULL;
126 }
127 ret->n = n;
128 ret->dimy = dimy;
129 ret->dimx = dimx;
130 ret->id = ++sprixelid_nonce;
131 ret->needs_refresh = NULL;
132 if(ret->id >= 0x1000000){
133 ret->id = 1;
134 sprixelid_nonce = 1;
135 }
136//fprintf(stderr, "LOOKING AT %p (p->n = %p)\n", ret, ret->n);
137 if(ncplane_pile(ret->n)){ // rendered mode
138 ncpile* np = ncplane_pile(ret->n);
139 if( (ret->next = np->sprixelcache) ){
140 ret->next->prev = ret;
141 }
142 np->sprixelcache = ret;
143 ret->prev = NULL;
144//fprintf(stderr, "%p %p %p\n", nc->sprixelcache, ret, nc->sprixelcache->next);
145 }else{ // ncdirect case
146 ret->next = ret->prev = NULL;
147 }
148 return ret;
149}
free(duplicated)
vopts n
Definition notcurses.h:3502
sprixel * sprixelcache
Definition internal.h:328
struct sprixel * prev
Definition sprite.h:145
unsigned dimy
Definition sprite.h:146
fbuf glyph
Definition sprite.h:138
struct sprixel * next
Definition sprite.h:144
unsigned char * needs_refresh
Definition sprite.h:156
uint32_t id
Definition sprite.h:139
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sprixel_debug()

void sprixel_debug ( const sprixel s,
FILE *  out 
)

Definition at line 7 of file sprite.c.

7 {
8 fprintf(out, "sprixel %d (%p) %" PRIu64 "B %dx%d (%dx%d) @%d/%d state: %d\n",
9 s->id, s, s->glyph.used, s->dimy, s->dimx, s->pixy, s->pixx,
10 s->n ? s->n->absy : 0, s->n ? s->n->absx : 0,
11 s->invalidated);
12 if(s->n){
13 int idx = 0;
14 for(unsigned y = 0 ; y < s->dimy ; ++y){
15 for(unsigned x = 0 ; x < s->dimx ; ++x){
16 fprintf(out, "%d", s->n->tam[idx].state);
17 ++idx;
18 }
19 fprintf(out, "\n");
20 }
21 idx = 0;
22 for(unsigned y = 0 ; y < s->dimy ; ++y){
23 for(unsigned x = 0 ; x < s->dimx ; ++x){
25 if(s->n->tam[idx].auxvector){
26 fprintf(out, "%03d] %p\n", idx, s->n->tam[idx].auxvector);
27 }else{
28 fprintf(out, "%03d] missing!\n", idx);
29 }
30 }
31 ++idx;
32 }
33 }
34 }
35}
int y
Definition notcurses.h:1905
int int x
Definition notcurses.h:1905
uint64_t used
Definition fbuf.h:27
int absy
Definition internal.h:83
int pixx
Definition sprite.h:147
int pixy
Definition sprite.h:147

◆ sprixel_free()

void sprixel_free ( sprixel s)

Definition at line 38 of file sprite.c.

38 {
39 if(s){
40 loginfo("destroying sprixel %u", s->id);
41 if(s->n){
42 s->n->sprite = NULL;
43 }
46 fbuf_free(&s->glyph);
47 free(s);
48 }
49}
void sixelmap_free(struct sixelmap *s)
Definition sixel.c:216
#define loginfo(fmt,...)
Definition logging.h:42
sprixel * sprite
Definition internal.h:105
struct sixelmap * smap
Definition sprite.h:157
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sprixel_hide()

void sprixel_hide ( sprixel s)

Definition at line 83 of file sprite.c.

83 {
84 if(ncplane_pile(s->n) == NULL){ // ncdirect case; destroy now
85 sprixel_free(s);
86 return;
87 }
88 // otherwise, it'll be killed in the next rendering cycle.
89 if(s->invalidated != SPRIXEL_HIDE){
90 loginfo("marking sprixel %u hidden", s->id);
92 s->movedfromy = ncplane_abs_y(s->n);
93 s->movedfromx = ncplane_abs_x(s->n);
94 // guard; might have already been replaced
95 if(s->n){
96 s->n->sprite = NULL;
97 s->n = NULL;
98 }
99 }
100}
int ncplane_abs_x(const ncplane *n)
Definition notcurses.c:2638
int ncplane_abs_y(const ncplane *n)
Definition notcurses.c:2634
void sprixel_free(sprixel *s)
Definition sprite.c:38
@ SPRIXEL_HIDE
Definition sprite.h:25
int movedfromx
Definition sprite.h:151
int movedfromy
Definition sprite.h:150
sprixel_e invalidated
Definition sprite.h:143
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sprixel_invalidate()

void sprixel_invalidate ( sprixel s,
int  y,
int  x 
)

Definition at line 103 of file sprite.c.

103 {
104//fprintf(stderr, "INVALIDATING AT %d/%d\n", y, x);
105 if(s->invalidated == SPRIXEL_QUIESCENT && s->n){
106 int localy = y - s->n->absy;
107 int localx = x - s->n->absx;
108//fprintf(stderr, "INVALIDATING AT %d/%d (%d/%d) TAM: %d\n", y, x, localy, localx, s->n->tam[localy * s->dimx + localx].state);
109 if(s->n->tam[localy * s->dimx + localx].state != SPRIXCELL_TRANSPARENT &&
110 s->n->tam[localy * s->dimx + localx].state != SPRIXCELL_ANNIHILATED &&
111 s->n->tam[localy * s->dimx + localx].state != SPRIXCELL_ANNIHILATED_TRANS){
113 }
114 }
115}
@ SPRIXEL_QUIESCENT
Definition sprite.h:21
@ SPRIXEL_INVALIDATED
Definition sprite.h:24
int absx
Definition internal.h:83
Here is the caller graph for this function:

◆ sprixel_load()

int sprixel_load ( sprixel spx,
fbuf f,
unsigned  pixy,
unsigned  pixx,
int  parse_start,
sprixel_e  state 
)

Definition at line 154 of file sprite.c.

155 {
156 assert(spx->n);
157 if(&spx->glyph != f){
158 fbuf_free(&spx->glyph);
159 memcpy(&spx->glyph, f, sizeof(*f));
160 }
161 spx->invalidated = state;
162 spx->pixx = pixx;
163 spx->pixy = pixy;
164 spx->parse_start = parse_start;
165 return 0;
166}
int parse_start
Definition sprite.h:153
Here is the call graph for this function:

◆ sprixel_movefrom()

void sprixel_movefrom ( sprixel s,
int  y,
int  x 
)

Definition at line 68 of file sprite.c.

68 {
70 if(s->invalidated != SPRIXEL_MOVED){
71 // FIXME if we're Sixel, we need to effect any wipes that were run
72 // (we normally don't because redisplaying sixel doesn't change
73 // what's there--you can't "write transparency"). this is probably
74 // best done by conditionally reblitting the sixel(?).
75//fprintf(stderr, "SETTING TO MOVE: %d/%d was: %d\n", y, x, s->invalidated);
77 s->movedfromy = y;
78 s->movedfromx = x;
79 }
80 }
81}
@ SPRIXEL_UNSEEN
Definition sprite.h:22
@ SPRIXEL_MOVED
Definition sprite.h:26
Here is the caller graph for this function:

◆ sprixel_recycle()

sprixel * sprixel_recycle ( ncplane n)

Definition at line 51 of file sprite.c.

51 {
52 assert(n->sprite);
55 sprixel* hides = n->sprite;
56 int dimy = hides->dimy;
57 int dimx = hides->dimx;
58 sprixel_hide(hides);
59 return sprixel_alloc(n, dimy, dimx);
60 }
61 sixelmap_free(n->sprite->smap);
62 n->sprite->smap = NULL;
63 return n->sprite;
64}
const notcurses * ncplane_notcurses_const(const ncplane *n)
Definition notcurses.c:2630
@ NCPIXEL_KITTY_STATIC
Definition notcurses.h:1680
void sprixel_hide(sprixel *s)
Definition sprite.c:83
sprixel * sprixel_alloc(ncplane *n, int dimy, int dimx)
Definition sprite.c:117
ncpixelimpl_e pixel_implementation
Definition termdesc.h:134
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sprixel_rescale()

int sprixel_rescale ( sprixel spx,
unsigned  ncellpxy,
unsigned  ncellpxx 
)

Definition at line 225 of file sprite.c.

225 {
226 assert(spx->n);
227 loginfo("rescaling -> %ux%u", ncellpxy, ncellpxx);
228 // FIXME need adjust for sixel (scale_height)
229 int nrows = (spx->pixy + (ncellpxy - 1)) / ncellpxy;
230 int ncols = (spx->pixx + (ncellpxx - 1)) / ncellpxx;
231 tament* ntam = create_tam(nrows, ncols);
232 if(ntam == NULL){
233 return -1;
234 }
235 for(unsigned y = 0 ; y < spx->dimy ; ++y){
236 for(unsigned x = 0 ; x < spx->dimx ; ++x){
237 sprite_rebuild(ncplane_notcurses(spx->n), spx, y, x);
238 }
239 }
240 ncplane* ncopy = spx->n;
241 destroy_tam(spx->n);
242 // spx->n->tam has been reset, so it will not be resized herein
243 ncplane_resize_simple(spx->n, nrows, ncols);
244 spx->n = ncopy;
245 spx->n->sprite = spx;
246 spx->n->tam = ntam;
247 spx->dimy = nrows;
248 spx->dimx = ncols;
249 return 0;
250}
notcurses * ncplane_notcurses(const ncplane *n)
Definition notcurses.c:2626
Here is the call graph for this function:
Here is the caller graph for this function: