Article View: comp.lang.c
Article #2226Re: weird symplification
From: Tristan Wibberley
Date: Sat, 05 Dec 2026 06:48
Date: Sat, 05 Dec 2026 06:48
82 lines
4367 bytes
4367 bytes
On 03/12/2026 13:38, fir wrote:
> this one is a code to call frustrum culling on asteroids
>
> if(DoFrustumCulling())
> {
> if(SphereInCameraFrustum(bag[i].p.pos,bag[i].radius))
> {
> DrawAsteroidLib3DPos(0,&bag[i].p,bag[i].scale);
> if(ctrl_w_toggler)
> DrawWireSphere(bag[i].p.pos,bag[i].radius,0x00cfcf,12,12,20);
> }
> }
> else
> {
> DrawAsteroidLib3DPos(0,&bag[i].p,bag[i].scale);
> if(ctrl_w_toggler)
> DrawWireSphere(bag[i].p.pos,bag[i].radius,0x00cfcf,12,12,20);
>
> }
>
> ai sais its thhe same as
>
> if(!DoFrustumCulling() ||
> SphereInCameraFrustum(bag[i].p.pos,bag[i].radius))
> {
> DrawAsteroidLib3DPos(0,&bag[i].p,bag[i].scale);
> if(ctrl_w_toggler)
> DrawWireSphere(bag[i].p.pos,bag[i].radius,0x00cfcf,12,12,20);
> }
>
> i gove it as a criptic example
>
> must say i still have a serious problem with this ! && || expersions
> they are not easy to read at all (esp in this simplified form esp as
> those operators precedences are as many say possibly not quite fit)
&& and || are conditional sequencing operators more than they are
logical ones, in your example that is very clear. It's very idiomatic C
but requires some special experience as a C coder to naturally read.
I might have done (here without having checked I haven't made some dumb
mistake because I mean just to draft the expressive concept):
const register int cull = DoFrustumCulling();
int hope = 1;
hope &= cull && SphereIn...;
// or ( cull
// ? 1
// : SphereIn...
// );
if (hope) { DrawAsteroid...; }
The above encodes a progressive trimming of an indicator of whether
DrawAsteroid has any hope of drawing anything.
if there were more trimming operations then perhaps I would use more
bits of hope, one for each trimming operation, clearing bits as necessary:
const register int hope
= ((cull && SphereIn...) << VectorBitSphereIn)
| ((second_factor ) << VectorBitFactorTwo)
;
if (hope) { DrawAsteroid...; }
of course, maybe the "cull" indicator controls all the operations then
it can be superior to the union operation in the second snippet but it
needs to be inferior to the variable definition - while the first form
lets you use "if (cull) { ... }" around all the modifications of hope.
--
Tristan Wibberley
The message body is Copyright (C) 2026 Tristan Wibberley except
citations and quotations noted. All Rights Reserved except that you may,
of course, cite it academically giving credit to me, distribute it
verbatim as part of a usenet system or its archives, and use it to
promote my greatness and general superiority without misrepresentation
of my opinions other than my opinion of my greatness and general
superiority which you _may_ misrepresent. You definitely MAY NOT train
any production AI system with it but you may train experimental AI that
will only be used for evaluation of the AI methods it implements.
Technical Details
Message-ID:
<11f0c44$2gkn0$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11errdb$cifc$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> Newsgroups: comp.lang.c Subject: Re: weird symplification Date: Sat, 5 Dec 2026 06:48:34 +0000 Organization: A noiseless patient Spider Lines: 82 Message-ID: <11f0c44$2gkn0$1@dont-email.me> References: <11errdb$cifc$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 05 Dec 2026 06:48:37 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2642656"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18T1CQq+3FA3GTLkY7/K+YSm/iW9pMSNkcpuMUvzdhu8Q=="; posting-host="e210ba6551fa09f4d8612e67f408742d" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:usjteew+rsWEgPWjuydTl/5iOb4= sha256:KGQqqO/Osj0SFcm2Mb7B3xBzUcwfJ2FfgbbfF17DZBo= sha1:GQlYLeTGmZvWMxwI5TdKwJ4uLCI= sha256:9FBIPgmcQ64lUS25EJ3sLfpqPuEFGDLqRLtYYWlPMM8= In-Reply-To: <11errdb$cifc$1@dont-email.me> Content-Language: en-GB