Thanks to bill Iam, I went on a reading spree and referred back to the
system socket.ijs source, it unpacks the result of calling getsockopt as
follows
r=. getsockoptJ s;lev;name;(,_1);,4
if. 0~:res r do. 0;~sdsockerror'' return. end.
d=. ''$>4{r

So I was -close- but not close enough for tobacco fuelled product
acquisition.
I can see that the > will unpack the -array- and I have experimented and
seen that ''$ is a reshape but what is the idiom?
How do I 'read'. that, ''$ .. reshape as scalar ?
applying ''$rh yields 1024 in my case which is perfect but what is the
natural J way to turn
'rw rh'=:2}.sdl_getrendereroutputsize appr;(,_1);(,_1)

into two unboxed un-arrayed values or, as I rather suspect, is it down to
me to be more aware as a J coder and realise these things!!

The good news is I have SOLVED my issue like this:

'ww1 wh1'=.2}.sdl_getwindowsize appw;(,_1);(,_1)
'rw1 rh1'=.2}.sdl_getrendereroutputsize appr;(,_1);(,_1)
ww=:''$ww1
wh=:''$wh1
rw=:''$rw1
rh=:''$rh1

however that feels like I could do better by applying that by bonding and
using each...so I now have this:

'ww wh'=. ''&$ each 2}.sdl_getwindowsize appw;(,_1);(,_1)
'rw rh'=. ''&$ each 2}.sdl_getrendereroutputsize appr;(,_1);(,_1)

which works perfectly, the surface is created and my application begins to
run, however, trying harder to generalise it as this is n't the only place
where I am going to need such actions I have devised this:
NB. Dropped Multiple Variable Assign
dmva =: 3 : 0
2 dmva y
:
''&$ each x}.y
)

I could have used _2 and gone from the other end but every C call is a law
unto itself so I didn't bother, just wrote enough to cover the most common
case so far. It now means that the final code is:

'ww wh'=. dmva sdl_getwindowsize appw;(,_1);(,_1)
'rw rh'=. dmva sdl_getrendereroutputsize appr;(,_1);(,_1)

And all is right with the world once again. Thanks bill Iam for nudging me!
--this-- is the reason I still love software development after 44 years of
starting it.
I now feel confident to emulate an 'sdcheck' (sockets.ijs) for myself to
catch errors from the API. Excellent stuff is J for sure.
Thanks all,
Back to the hack....
Sean.



On Fri, 27 Nov 2020 at 13:05, bill lam <bbill....@gmail.com> wrote:

> probably your width and height are not scalar but singleton array. you can
> check them with monad $ .
>
> On Fri, Nov 27, 2020, 8:00 PM emacstheviking <obji...@gmail.com> wrote:
>
> > Given these working external function declarations:
> >
> > SDL_GetWindowSize n x *i *i
> > SDL_GetRendererOutputSize n x *i *i
> > SDL_CreateRGBSurface > x i i i i i i i i
> >
> > then these two calls:
> >
> > 'ww wh'=:2}.sdl_getwindowsize appw;(,_1);(,_1)
> > 'rw rh'=:2}.sdl_getrendereroutputsize appr;(,_1);(,_1)
> >
> > work and produce values of 1024 for ww and rw, and 768 for wh and rh
> > respectively, as expected.
> > However, when creating the rgb surface it raises a domain error and I
> have
> > been tearing my hair out to understand why.
> > I have posted the full code at the end of this plea for help and
> > enlightenment.
> >
> > args=.0;width;height;32;16bff0000;16bff00;16bff;16bff000000
> > smoutput args
> > sfc=: sdl_creatergbsurface args
> >
> > cder''
> > 6 1
> >
> > yet calling it with literals or even the extracted 'y' value (a boxed
> > dimension):
> > args=.0;1024;768;32;16bff0000;16bff00;16bff;16bff000000. NB. works
> > args=.0;width;height;32;16bff0000;16bff00;16bff;16bff000000. NB. works
> >
> > I have used 3!:0 to examine the type, it is 4 (integer) in all cases
> > (ww,wh,rw,rh,width,height), ruling out those errors.
> > Thanks,
> > Sean. :|
> >
> > -- full code ---
> >
> > ugo =: 3 : 0
> > NB. testing out domain errors around sdl_creatergbsurface...
> > args =. SCREEN_X_MAX;SCREEN_Y_MAX
> > scrw =. SCREEN_X_MAX
> > scrh =. SCREEN_Y_MAX
> > sdlprep scrw;scrh
> > cairoprep''
> > urun''
> > uend^:y ''
> > )
> >
> > sdlprep =: 3 : 0
> > 'width height'=. y
> > sdl_init SDL_INIT_EVERYTHING
> > appw=:sdl_createwindow 'test window';0;0
> > ;width;height;SDL_WINDOW_SHOWN+SDL_WINDOW_ALLOW_HIGHDPI
> > appr=:sdl_createrenderer appw;_1
> > ;SDL_RENDERER_ACCELERATED+SDL_RENDERER_PRESENTVSYNC
> > 'ww wh'=:2}.sdl_getwindowsize appw;(,_1);(,_1)
> > 'rw rh'=:2}.sdl_getrendereroutputsize appr;(,_1);(,_1)
> > cxm=: rw % ww
> > cym=: rh % wh
> > smoutput 'window: ', (":appw), 'renderer:', (":appr)
> > smoutput 'requested width:',(":width),' height:',(":height)
> > smoutput 'render width: ',(":rw),' height:',(":rh)
> > smoutput 'window width: ',(":ww),' height:',(":wh)
> > smoutput 'x/y multipliers:',(":cxm),'/',(":cym)
> > NB. This needs to be endian-aware at some point
> > smoutput (": (width = rw))
> > args=.0;width;height;32;16bff0000;16bff00;16bff;16bff000000
> > smoutput args
> > sfc=: sdl_creatergbsurface args
> > NB. Practice structures. PACKING!!! Show printable format name
> > pFormat=._3 ic memr (sfc+8),0,8 NB. sdl_surface->format
> > format=._2 ic memr pFormat,0,4 NB. sdl_surface->format->format
> > smoutput 'pixel format:',(psz sdl_getpixelformatname format)
> > EMPTY
> > )
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to